forked from nemomobile/kernel-adaptation-n950-n9
-
Notifications
You must be signed in to change notification settings - Fork 5
/
ctrl-gf.c
2462 lines (1950 loc) · 48.3 KB
/
ctrl-gf.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* TC358710XBG "GF" DSI hub
*
* Copyright (C) 2009 Nokia Corporation
* Author: Tomi Valkeinen <tomi.valkeinen@nokia.com>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 as published by
* the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/
/*#define DEBUG*/
#include <linux/module.h>
#include <linux/delay.h>
#include <linux/err.h>
#include <linux/jiffies.h>
#include <linux/sched.h>
#include <linux/backlight.h>
#include <linux/fb.h>
#include <linux/interrupt.h>
#include <linux/gpio.h>
#include <linux/completion.h>
#include <linux/workqueue.h>
#include <linux/clk.h>
#include <linux/regulator/consumer.h>
#include <linux/semaphore.h>
#include <linux/hrtimer.h>
#include <plat/display.h>
#include <plat/ctrl-gf.h>
/* DSI Virtual channel. Hardcoded for now. */
#define VC_GF 3
#define VC_GFFB 2
#define VC_HIMALAYA 0
#define DCS_READ_NUM_ERRORS 0x05
#define DCS_READ_POWER_MODE 0x0a
#define DCS_READ_MADCTL 0x0b
#define DCS_READ_PIXEL_FORMAT 0x0c
#define DCS_RDDSDR 0x0f
#define DCS_SLEEP_IN 0x10
#define DCS_SLEEP_OUT 0x11
#define DCS_DISPLAY_OFF 0x28
#define DCS_DISPLAY_ON 0x29
#define DCS_COLUMN_ADDR 0x2a
#define DCS_PAGE_ADDR 0x2b
#define DCS_MEMORY_WRITE 0x2c
#define DCS_TEAR_OFF 0x34
#define DCS_TEAR_ON 0x35
#define DCS_MEM_ACC_CTRL 0x36
#define DCS_PIXEL_FORMAT 0x3a
#define DCS_BRIGHTNESS 0x51
#define DCS_CTRL_DISPLAY 0x53
#define DCS_WRITE_CABC 0x55
#define DCS_READ_CABC 0x56
#define DCS_GET_ID1 0xda
#define DCS_GET_ID2 0xdb
#define DCS_GET_ID3 0xdc
#define GF_RDSTAT 0x82
#define GF_REFCLKF 0x83
#define GF_SETPRIBR 0x84
#define GF_IFCLKSRC 0x86
#define GF_DSIHIFBR 0x87
#define GF_VCMAP 0x93
#define GF_DSILPTIM 0xa0
#define GF_DSILNCFG 0xa1
#define GF_DSILNIDLE 0xa2
#define GF_DSITXMODE 0xa3
#define GF_EXTCMDWR 0xfd
#define GF_ENPERPOR 0x80
#define GF_DISPERPOR 0x81
#define GF_FBGWRC 0x82
#define GF_FB1GC 0x83
#define GF_FB1CGM 0x84
#define GF_FB1CSC 0x85
#define GF_FB1PUA 0x86
#define GF_FB1WAT 0x87
#define GF_RS1GC 0x8d
#define GF_RS1RSC 0x8e
#define GF_RS1PRA 0x8f
#define GF_RS1VTC 0x90
#define GF_RS1TET 0x91
#define GF_RS1TED 0x92
#define GF_RS1USP 0x93
#define GF_RDDSIERR 0xa4
#define GF_TESRC 0xb0
#define GF_EXTALYWR 0xc0
#define GF_EXTALYRD 0xc1
/* EXT commands */
#define GF_EXT_RS1DCM 0x00
#define GF_FMT_STAT_STR_LEN 255
#define MEASURE_PERF
/*#define MEASURE_PERF_SHOW_ALWAYS*/
static irqreturn_t gf_te_isr(int irq, void *data);
static void gf_frame_timeout_work_callback(struct work_struct *work);
static enum hrtimer_restart gf_timer_handler(struct hrtimer *handle);
static void gf_calibrate_work_callback(struct work_struct *work);
enum gf_update_te {
GF_UPDATE_NO_TE,
GF_UPDATE_EXT_TE,
GF_UPDATE_DSI_TE,
};
enum gf_update_mode {
GF_UPDATE_NORMAL, /* update in one part */
GF_UPDATE_RL, /* right first, then left */
GF_UPDATE_LR, /* left first, then right */
GF_UPDATE_BT, /* bottom first, then top */
GF_UPDATE_TB, /* top first, then bottom */
};
enum gf_update_state {
GF_UPD_NONE,
GF_UPD_FRAME1_WAIT_START,
GF_UPD_FRAME1_ONGOING,
GF_UPD_FRAME2_WAIT_START,
GF_UPD_FRAME2_ONGOING,
};
struct gf_data {
struct semaphore lock;
struct backlight_device *bldev;
unsigned long hw_guard_end; /* next value of jiffies when we can
* issue the next sleep in/out command
*/
unsigned long hw_guard_wait; /* max guard time in jiffies */
struct omap_dss_device *dssdev;
bool enabled;
u8 rotate;
bool mirror;
bool te_enabled;
atomic_t upd_state;
struct {
u16 x;
u16 y;
u16 w;
u16 h;
} update_region;
struct delayed_work frame_timeout_work;
enum gf_update_te update_te;
enum gf_update_mode update_mode;
bool intro_printed;
bool panel_intro_printed;
unsigned cabc_mode;
struct clk *sysclk;
struct regulator *vpnl_reg;
struct regulator *vddi_reg;
struct hrtimer hrtimer;
u32 timer_us;
#ifdef MEASURE_PERF
struct {
ktime_t phase0; /* update */
ktime_t phase1; /* timer */
ktime_t phase2; /* cb1 */
ktime_t phase3; /* TE */
ktime_t phase4; /* cb2 */
} perf;
#endif
bool calibrating;
int num_calib_values;
ktime_t calib_values[30];
struct work_struct calibrate_work;
};
enum dsi_tx_mode {
DSI_TX_MODE_ALWAYS_LP = 0,
DSI_TX_MODE_ALWAYS_HS = 1,
DSI_TX_MODE_FOLLOW_HOST = 2,
};
static int _gf_enable_te(struct omap_dss_device *dssdev, bool enable);
static void hw_guard_start(struct gf_data *td, int guard_msec)
{
td->hw_guard_wait = msecs_to_jiffies(guard_msec);
td->hw_guard_end = jiffies + td->hw_guard_wait;
}
static void hw_guard_wait(struct gf_data *td)
{
unsigned long wait = td->hw_guard_end - jiffies;
if ((long)wait > 0 && wait <= td->hw_guard_wait) {
set_current_state(TASK_UNINTERRUPTIBLE);
schedule_timeout(wait);
}
}
static int gf_sleep_in(struct gf_data *td)
{
u8 cmd;
int r;
hw_guard_wait(td);
cmd = DCS_SLEEP_IN;
r = dsi_vc_dcs_write_nosync(VC_GF, &cmd, 1);
if (r)
return r;
hw_guard_start(td, 120);
/* wait for SLEEP_IN to complete */
msleep(5);
return 0;
}
static int gf_sleep_out(struct gf_data *td)
{
int r;
u8 buf[] = { DCS_SLEEP_OUT };
u8 diag;
hw_guard_wait(td);
r = dsi_vc_dcs_write_nosync(VC_GF, buf, sizeof(buf));
if (r)
return r;
hw_guard_start(td, 120);
/* wait for SLEEP_OUT to complete */
msleep(4);
r = dsi_vc_dcs_read_1(VC_GF, DCS_RDDSDR, &diag);
if (r)
return r;
if (!(diag & (1 << 6)))
return -EIO;
return 0;
}
static int dcs_get_id(int channel, u8 *id1, u8 *id2, u8 *id3)
{
int r;
r = dsi_vc_dcs_read_1(channel, DCS_GET_ID1, id1);
if (r)
return r;
r = dsi_vc_dcs_read_1(channel, DCS_GET_ID2, id2);
if (r)
return r;
r = dsi_vc_dcs_read_1(channel, DCS_GET_ID3, id3);
if (r)
return r;
return 0;
}
static int gf_read_status(struct omap_dss_device *dssdev, u16 *stat)
{
int r;
u8 b1, b2;
*stat = 0;
r = dsi_vc_dcs_read_2(VC_GF, GF_RDSTAT, &b1, &b2);
if (r)
return r;
*stat = (b1 << 8) | b2;
return 0;
}
static size_t gf_format_status(u16 stat, char *buf, size_t len)
{
if (len < GF_FMT_STAT_STR_LEN)
return -EINVAL;
buf[0] = 0;
if (stat & (1 << 0))
strcat(buf, "BUSY ");
if (stat & (1 << 1))
strcat(buf, "ETO ");
if (stat & (1 << 2))
strcat(buf, "EBIT ");
if (stat & (1 << 3))
strcat(buf, "EPER ");
if (stat & (1 << 4))
strcat(buf, "EHST ");
if (stat & (1 << 5))
strcat(buf, "EBUF ");
if (stat & (1 << 6))
strcat(buf, "(reserved) ");
if (stat & (1 << 7))
strcat(buf, "EDSI ");
if (stat & (1 << 8))
strcat(buf, "LCD1BUSY ");
if (stat & (1 << 9))
strcat(buf, "LCD2BUSY ");
if (stat & (1 << 10))
strcat(buf, "BFCBUSY ");
return strlen(buf);
}
static int gf_read_dsi_errors(struct omap_dss_device *dssdev,
u16 *stat1, u16 *stat2)
{
int r;
u8 buf[6];
r = dsi_vc_dcs_read(VC_GF, GF_RDDSIERR, buf, sizeof(buf));
if (r < 0)
return r;
*stat1 = (buf[0] << 8) | buf[1];
*stat2 = (buf[2] << 8) | buf[3];
return 0;
}
static void gf_get_timings(struct omap_dss_device *dssdev,
struct omap_video_timings *timings)
{
*timings = dssdev->panel.timings;
}
static void gf_get_resolution(struct omap_dss_device *dssdev,
u16 *xres, u16 *yres)
{
struct gf_data *data = dev_get_drvdata(&dssdev->dev);
int rotate = data->rotate;
/* HACK to get himalaya look like portrait scanned */
rotate = (rotate + 3) % 4;
if (rotate == 0 || rotate == 2) {
*xres = dssdev->panel.timings.x_res;
*yres = dssdev->panel.timings.y_res;
} else {
*yres = dssdev->panel.timings.x_res;
*xres = dssdev->panel.timings.y_res;
}
}
#define HIMALAYA_WIDTH 48960
#define HIMALAYA_HEIGHT 88128
static void gf_get_dimensions(struct omap_dss_device *dssdev,
u32 *width, u32 *height)
{
struct gf_data *td = dev_get_drvdata(&dssdev->dev);
if (td->rotate == 0 || td->rotate == 2) {
*width = HIMALAYA_WIDTH;
*height = HIMALAYA_HEIGHT;
} else {
*width = HIMALAYA_HEIGHT;
*height = HIMALAYA_WIDTH;
}
}
static ssize_t gf_hw_revision_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
struct omap_dss_device *dssdev = to_dss_device(dev);
struct gf_data *td = dev_get_drvdata(&dssdev->dev);
u8 id1, id2, id3;
int r;
down(&td->lock);
if (td->enabled) {
dsi_bus_lock();
r = dcs_get_id(VC_GF, &id1, &id2, &id3);
dsi_bus_unlock();
} else {
r = -ENODEV;
}
up(&td->lock);
if (r)
return r;
return snprintf(buf, PAGE_SIZE, "%02x.%02x.%02x\n", id1, id2, id3);
}
static ssize_t gf_panel_hw_revision_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
struct omap_dss_device *dssdev = to_dss_device(dev);
struct gf_data *td = dev_get_drvdata(&dssdev->dev);
u8 id1, id2, id3;
int r;
down(&td->lock);
if (!td->enabled) {
up(&td->lock);
return -ENODEV;
}
dsi_bus_lock();
r = dcs_get_id(VC_HIMALAYA, &id1, &id2, &id3);
if (r)
goto err;
dsi_bus_unlock();
up(&td->lock);
return snprintf(buf, PAGE_SIZE, "%02x.%02x.%02x\n", id1, id2, id3);
err:
dsi_bus_unlock();
up(&td->lock);
return r;
}
static ssize_t gf_status_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
struct omap_dss_device *dssdev = to_dss_device(dev);
struct gf_data *td = dev_get_drvdata(&dssdev->dev);
u16 stat;
int r;
char str[GF_FMT_STAT_STR_LEN];
size_t len;
down(&td->lock);
if (td->enabled) {
dsi_bus_lock();
r = gf_read_status(dssdev, &stat);
dsi_bus_unlock();
} else {
r = -ENODEV;
}
up(&td->lock);
if (r)
return r;
len = gf_format_status(stat, str, sizeof(str));
return snprintf(buf, PAGE_SIZE, "%s\n", str);
}
static ssize_t gf_dsi_err_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
struct omap_dss_device *dssdev = to_dss_device(dev);
struct gf_data *td = dev_get_drvdata(&dssdev->dev);
u16 stat1 = 0, stat2 = 0;
int r;
down(&td->lock);
if (td->enabled) {
dsi_bus_lock();
r = gf_read_dsi_errors(dssdev, &stat1, &stat2);
dsi_bus_unlock();
} else {
r = -ENODEV;
}
up(&td->lock);
if (r)
return r;
return snprintf(buf, PAGE_SIZE, "%x %x\n", stat1, stat2);
}
static const char *cabc_modes[] = {
"off", /* used also always when CABC is not supported */
"ui",
"still-image",
"moving-image",
};
static ssize_t show_cabc_mode(struct device *dev,
struct device_attribute *attr,
char *buf)
{
struct omap_dss_device *dssdev = to_dss_device(dev);
struct gf_data *td = dev_get_drvdata(&dssdev->dev);
const char *mode_str;
int mode;
int len;
down(&td->lock);
mode = td->cabc_mode;
up(&td->lock);
mode_str = "unknown";
if (mode >= 0 && mode < ARRAY_SIZE(cabc_modes))
mode_str = cabc_modes[mode];
len = snprintf(buf, PAGE_SIZE, "%s\n", mode_str);
return len < PAGE_SIZE - 1 ? len : PAGE_SIZE - 1;
}
static ssize_t store_cabc_mode(struct device *dev,
struct device_attribute *attr,
const char *buf, size_t count)
{
struct omap_dss_device *dssdev = to_dss_device(dev);
struct gf_data *td = dev_get_drvdata(&dssdev->dev);
int i;
for (i = 0; i < ARRAY_SIZE(cabc_modes); i++) {
if (sysfs_streq(cabc_modes[i], buf))
break;
}
if (i == ARRAY_SIZE(cabc_modes))
return -EINVAL;
down(&td->lock);
if (td->enabled) {
dsi_bus_lock();
dsi_vc_dcs_write_1(VC_HIMALAYA, DCS_WRITE_CABC, i);
dsi_bus_unlock();
}
td->cabc_mode = i;
up(&td->lock);
return count;
}
static ssize_t show_cabc_available_modes(struct device *dev,
struct device_attribute *attr,
char *buf)
{
int len;
int i;
for (i = 0, len = 0;
len < PAGE_SIZE && i < ARRAY_SIZE(cabc_modes); i++)
len += snprintf(&buf[len], PAGE_SIZE - len, "%s%s%s",
i ? " " : "", cabc_modes[i],
i == ARRAY_SIZE(cabc_modes) - 1 ? "\n" : "");
return len < PAGE_SIZE ? len : PAGE_SIZE - 1;
}
static DEVICE_ATTR(hw_revision, S_IRUGO, gf_hw_revision_show, NULL);
static DEVICE_ATTR(panel_hw_revision, S_IRUGO,
gf_panel_hw_revision_show, NULL);
static DEVICE_ATTR(status, S_IRUGO, gf_status_show, NULL);
static DEVICE_ATTR(dsi_err, S_IRUGO, gf_dsi_err_show, NULL);
static DEVICE_ATTR(cabc_mode, S_IRUGO | S_IWUSR,
show_cabc_mode, store_cabc_mode);
static DEVICE_ATTR(cabc_available_modes, S_IRUGO,
show_cabc_available_modes, NULL);
static struct attribute *gf_attrs[] = {
&dev_attr_hw_revision.attr,
&dev_attr_panel_hw_revision.attr,
&dev_attr_status.attr,
&dev_attr_dsi_err.attr,
&dev_attr_cabc_mode.attr,
&dev_attr_cabc_available_modes.attr,
NULL,
};
static struct attribute_group gf_attr_group = {
.attrs = gf_attrs,
};
static int gf_bl_update_status(struct backlight_device *dev)
{
struct omap_dss_device *dssdev = dev_get_drvdata(&dev->dev);
struct gf_data *td = dev_get_drvdata(&dssdev->dev);
int r;
int level;
if (dev->props.fb_blank == FB_BLANK_UNBLANK &&
dev->props.power == FB_BLANK_UNBLANK)
level = dev->props.brightness;
else
level = 0;
dev_dbg(&dssdev->dev, "update brightness to %d\n", level);
down(&td->lock);
r = 0;
if (td->enabled) {
dsi_bus_lock();
r = dsi_vc_dcs_write_1(VC_HIMALAYA, DCS_BRIGHTNESS, level);
dsi_bus_unlock();
}
up(&td->lock);
return r;
}
static int gf_bl_get_intensity(struct backlight_device *dev)
{
if (dev->props.fb_blank == FB_BLANK_UNBLANK &&
dev->props.power == FB_BLANK_UNBLANK)
return dev->props.brightness;
return 0;
}
static struct backlight_ops gf_bl_ops = {
.get_brightness = gf_bl_get_intensity,
.update_status = gf_bl_update_status,
};
static void gf_hw_reset(struct omap_dss_device *dssdev)
{
struct ctrl_gf_platform_data *pdata =
(struct ctrl_gf_platform_data *)dssdev->data;
struct gf_data *td = dev_get_drvdata(&dssdev->dev);
/* clk has to be enabled during reset */
clk_enable(td->sysclk);
/* ensure that clk has been on for a while */
msleep(1);
/* first set the reset high, so that GF notices the falling edge */
gpio_set_value(pdata->panel_gpio, 1);
udelay(10);
/* reset GF */
gpio_set_value(pdata->reset_gpio, 0);
/* keep reset 10us or more */
udelay(10);
gpio_set_value(pdata->reset_gpio, 1);
/* wait 2ms after reset */
msleep(2);
clk_disable(td->sysclk);
}
static void himalaya_hw_reset(struct omap_dss_device *dssdev)
{
struct ctrl_gf_platform_data *pdata =
(struct ctrl_gf_platform_data *)dssdev->data;
/* first set the reset high, so that himalaya notices the falling
* edge */
gpio_set_value(pdata->panel_gpio, 1);
udelay(10);
/* reset the panel */
gpio_set_value(pdata->panel_gpio, 0);
/* assert reset for at least 10us */
udelay(10);
gpio_set_value(pdata->panel_gpio, 1);
/* wait 5ms after releasing reset */
msleep(5);
}
static int gf_probe(struct omap_dss_device *dssdev)
{
struct gf_data *td;
struct ctrl_gf_platform_data *pdata =
(struct ctrl_gf_platform_data *)dssdev->data;
struct backlight_device *bldev;
int r;
int v;
const struct omap_video_timings gf_panel_timings = {
.x_res = 480,
.y_res = 864,
};
dev_dbg(&dssdev->dev, "probe\n");
dssdev->panel.config = OMAP_DSS_LCD_TFT;
dssdev->panel.timings = gf_panel_timings;
dssdev->ctrl.pixel_size = 24;
td = kzalloc(sizeof(*td), GFP_KERNEL);
if (!td) {
r = -ENOMEM;
goto err0;
}
td->dssdev = dssdev;
sema_init(&td->lock, 1);
dev_set_drvdata(&dssdev->dev, td);
r = sysfs_create_group(&dssdev->dev.kobj, &gf_attr_group);
if (r) {
dev_err(&dssdev->dev, "failed to create sysfs files\n");
goto err1;
}
r = gpio_request(pdata->pdx_gpio, "Grande Finale PDXx");
if (r < 0) {
dev_err(&dssdev->dev, "unable to get PDX GPIO\n");
goto err2;
}
/* initialize to deep sleep mode */
gpio_direction_output(pdata->pdx_gpio, 0);
r = gpio_request(pdata->reset_gpio, "Grande Finale RESX");
if (r < 0) {
dev_err(&dssdev->dev, "unable to get RESX GPIO\n");
goto err3;
}
/* initialize to non-reset state */
gpio_direction_output(pdata->reset_gpio, 1);
r = gpio_request(pdata->panel_gpio, "Himalaya RESX");
if (r < 0) {
dev_err(&dssdev->dev, "unable to get Himalaya RESX GPIO\n");
goto err4;
}
/* initialize to non-reset state */
gpio_direction_output(pdata->panel_gpio, 1);
td->calibrating = true;
td->num_calib_values = 0;
INIT_WORK(&td->calibrate_work, gf_calibrate_work_callback);
hrtimer_init(&td->hrtimer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
td->hrtimer.function = gf_timer_handler;
r = gpio_request(pdata->te_gpio, "gf irq");
if (r) {
dev_err(&dssdev->dev, "GPIO request failed\n");
goto err5;
}
gpio_direction_input(pdata->te_gpio);
r = request_irq(gpio_to_irq(pdata->te_gpio), gf_te_isr,
IRQF_DISABLED | IRQF_TRIGGER_RISING,
"gf vsync", dssdev);
if (r) {
dev_err(&dssdev->dev, "IRQ request failed\n");
gpio_free(pdata->te_gpio);
goto err5;
}
INIT_DELAYED_WORK_DEFERRABLE(&td->frame_timeout_work,
gf_frame_timeout_work_callback);
td->sysclk = clk_get(&dssdev->dev, pdata->sysclk_name);
if (IS_ERR(td->sysclk)) {
dev_err(&dssdev->dev, "can't get %s\n", pdata->sysclk_name);
r = PTR_ERR(td->sysclk);
td->sysclk = NULL;
goto err_te;
}
td->vpnl_reg = regulator_get(&dssdev->dev, "VPNL");
if (IS_ERR(td->vpnl_reg)) {
dev_err(&dssdev->dev, "failed to get VPNL regulator\n");
r = PTR_ERR(td->vpnl_reg);
goto err6;
}
v = regulator_get_voltage(td->vpnl_reg);
if (v < 2300000 || v > 4800000) {
r = regulator_set_voltage(td->vpnl_reg, 2300000, 4800000);
if (r) {
dev_err(&dssdev->dev, "failed to set VPNL voltage\n");
goto err7;
}
}
r = regulator_enable(td->vpnl_reg);
if (r) {
dev_err(&dssdev->dev, "failed to enable VPNL regulator\n");
goto err7;
}
td->vddi_reg = regulator_get(&dssdev->dev, "VDDI");
if (IS_ERR(td->vddi_reg)) {
dev_err(&dssdev->dev, "failed to get VDDI regulator\n");
r = PTR_ERR(td->vddi_reg);
goto err8;
}
v = regulator_get_voltage(td->vddi_reg);
if (v < 1650000 || v > 1950000) {
r = regulator_set_voltage(td->vddi_reg, 1650000, 1950000);
if (r) {
dev_err(&dssdev->dev, "failed to set VDDI voltage\n");
goto err8;
}
}
r = regulator_enable(td->vddi_reg);
if (r) {
dev_err(&dssdev->dev, "failed to enable VDDI regulator\n");
goto err9;
}
bldev = backlight_device_register("himalaya", &dssdev->dev, dssdev,
&gf_bl_ops);
if (IS_ERR(bldev)) {
r = PTR_ERR(bldev);
goto err10;
}
td->bldev = bldev;
bldev->props.fb_blank = FB_BLANK_UNBLANK;
bldev->props.power = FB_BLANK_UNBLANK;
bldev->props.max_brightness = 255;
bldev->props.brightness = 255;
gf_bl_update_status(bldev);
gf_hw_reset(dssdev);
himalaya_hw_reset(dssdev);
return 0;
err10:
regulator_disable(td->vddi_reg);
err9:
regulator_put(td->vddi_reg);
err8:
regulator_disable(td->vpnl_reg);
err7:
regulator_put(td->vpnl_reg);
err6:
clk_put(td->sysclk);
err_te:
free_irq(gpio_to_irq(pdata->te_gpio), dssdev);
gpio_free(pdata->te_gpio);
err5:
gpio_free(pdata->panel_gpio);
err4:
gpio_free(pdata->reset_gpio);
err3:
gpio_free(pdata->pdx_gpio);
err2:
sysfs_remove_group(&dssdev->dev.kobj, &gf_attr_group);
err1:
kfree(td);
err0:
return r;
}
static void gf_remove(struct omap_dss_device *dssdev)
{
struct gf_data *td = dev_get_drvdata(&dssdev->dev);
struct ctrl_gf_platform_data *pdata =
(struct ctrl_gf_platform_data *)dssdev->data;
struct backlight_device *bldev;
dev_dbg(&dssdev->dev, "remove\n");
bldev = td->bldev;
bldev->props.power = FB_BLANK_POWERDOWN;
gf_bl_update_status(bldev);
backlight_device_unregister(bldev);
regulator_disable(td->vddi_reg);
regulator_disable(td->vpnl_reg);
regulator_put(td->vddi_reg);
regulator_put(td->vpnl_reg);
clk_put(td->sysclk);
free_irq(gpio_to_irq(pdata->te_gpio), dssdev);
gpio_free(pdata->te_gpio);
gpio_free(pdata->panel_gpio);
gpio_free(pdata->reset_gpio);
gpio_free(pdata->pdx_gpio);
sysfs_remove_group(&dssdev->dev.kobj, &gf_attr_group);
kfree(td);
}
static void gf_deep_sleep_disable(struct omap_dss_device *dssdev)
{
struct ctrl_gf_platform_data *pdata =
(struct ctrl_gf_platform_data *)dssdev->data;
/* wake GF from deep sleep */
gpio_set_value(pdata->pdx_gpio, 1);
/* wait for GF to wake up */
msleep(5);
}
static void gf_deep_sleep_enable(struct omap_dss_device *dssdev)
{
struct ctrl_gf_platform_data *pdata =
(struct ctrl_gf_platform_data *)dssdev->data;
/* put GF to deep sleep */
gpio_set_value(pdata->pdx_gpio, 0);
/* wait for GF to go to sleep */
msleep(5);
}
static int gf_set_lane_conf(int lanes_a, int lanes_b, int lanes_c)
{
u8 buf[] = {
GF_DSILNCFG,
lanes_a | (lanes_b << 2) | (lanes_c << 4),
};
return dsi_vc_dcs_write(VC_GF, buf, sizeof(buf));
}
static int gf_set_transfer_mode(enum dsi_tx_mode mode_a,
enum dsi_tx_mode mode_b)
{
u8 buf[] = {
GF_DSITXMODE,
mode_a | (mode_b << 2)
};
return dsi_vc_dcs_write(VC_GF, buf, sizeof(buf));
}
static int gf_set_vcmap(int vc0, int out0, int vc1, int out1,
int vc2, int out2)
{
u8 buf[] = {
GF_VCMAP,
out0 | (vc0 << 2),
out1 | (vc1 << 2),
out2 | (vc2 << 2),
};
return dsi_vc_dcs_write(VC_GF, buf, sizeof(buf));
}
static int gf_set_lane_idle_state(int clk_a, int d0_a, int d1_a,
int clk_b, int d0_b, int d1_b)
{
u8 buf[] = {
GF_DSILNIDLE,
clk_a | (d0_a << 2) | (d1_a << 3),
clk_b | (d0_b << 2) | (d1_b << 3),
0,
};
return dsi_vc_dcs_write(VC_GF, buf, sizeof(buf));
}
static int gf_check_status(struct omap_dss_device *dssdev)
{
int r;
u16 stat;
char buf[GF_FMT_STAT_STR_LEN];
size_t len;
r = gf_read_status(dssdev, &stat);
if (r < 0)
return r;
if (stat == 0)
return 0;