fb: adv7393: off by one in probe function
[deliverable/linux.git] / drivers / gpu / drm / omapdrm / displays / panel-sony-acx565akm.c
1 /*
2 * Sony ACX565AKM LCD Panel driver
3 *
4 * Copyright (C) 2010 Nokia Corporation
5 *
6 * Original Driver Author: Imre Deak <imre.deak@nokia.com>
7 * Based on panel-generic.c by Tomi Valkeinen <tomi.valkeinen@nokia.com>
8 * Adapted to new DSS2 framework: Roger Quadros <roger.quadros@nokia.com>
9 *
10 * This program is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License version 2 as published by
12 * the Free Software Foundation.
13 *
14 * This program is distributed in the hope that it will be useful, but WITHOUT
15 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
17 * more details.
18 *
19 * You should have received a copy of the GNU General Public License along with
20 * this program. If not, see <http://www.gnu.org/licenses/>.
21 */
22
23 #include <linux/kernel.h>
24 #include <linux/module.h>
25 #include <linux/platform_device.h>
26 #include <linux/delay.h>
27 #include <linux/spi/spi.h>
28 #include <linux/jiffies.h>
29 #include <linux/sched.h>
30 #include <linux/backlight.h>
31 #include <linux/fb.h>
32 #include <linux/gpio/consumer.h>
33 #include <linux/of.h>
34 #include <linux/of_gpio.h>
35
36 #include <video/omap-panel-data.h>
37
38 #include "../dss/omapdss.h"
39
40 #define MIPID_CMD_READ_DISP_ID 0x04
41 #define MIPID_CMD_READ_RED 0x06
42 #define MIPID_CMD_READ_GREEN 0x07
43 #define MIPID_CMD_READ_BLUE 0x08
44 #define MIPID_CMD_READ_DISP_STATUS 0x09
45 #define MIPID_CMD_RDDSDR 0x0F
46 #define MIPID_CMD_SLEEP_IN 0x10
47 #define MIPID_CMD_SLEEP_OUT 0x11
48 #define MIPID_CMD_DISP_OFF 0x28
49 #define MIPID_CMD_DISP_ON 0x29
50 #define MIPID_CMD_WRITE_DISP_BRIGHTNESS 0x51
51 #define MIPID_CMD_READ_DISP_BRIGHTNESS 0x52
52 #define MIPID_CMD_WRITE_CTRL_DISP 0x53
53
54 #define CTRL_DISP_BRIGHTNESS_CTRL_ON (1 << 5)
55 #define CTRL_DISP_AMBIENT_LIGHT_CTRL_ON (1 << 4)
56 #define CTRL_DISP_BACKLIGHT_ON (1 << 2)
57 #define CTRL_DISP_AUTO_BRIGHTNESS_ON (1 << 1)
58
59 #define MIPID_CMD_READ_CTRL_DISP 0x54
60 #define MIPID_CMD_WRITE_CABC 0x55
61 #define MIPID_CMD_READ_CABC 0x56
62
63 #define MIPID_VER_LPH8923 3
64 #define MIPID_VER_LS041Y3 4
65 #define MIPID_VER_L4F00311 8
66 #define MIPID_VER_ACX565AKM 9
67
68 struct panel_drv_data {
69 struct omap_dss_device dssdev;
70 struct omap_dss_device *in;
71
72 int reset_gpio;
73 int datapairs;
74
75 struct omap_video_timings videomode;
76
77 char *name;
78 int enabled;
79 int model;
80 int revision;
81 u8 display_id[3];
82 unsigned has_bc:1;
83 unsigned has_cabc:1;
84 unsigned cabc_mode;
85 unsigned long hw_guard_end; /* next value of jiffies
86 when we can issue the
87 next sleep in/out command */
88 unsigned long hw_guard_wait; /* max guard time in jiffies */
89
90 struct spi_device *spi;
91 struct mutex mutex;
92
93 struct backlight_device *bl_dev;
94 };
95
96 static const struct omap_video_timings acx565akm_panel_timings = {
97 .x_res = 800,
98 .y_res = 480,
99 .pixelclock = 24000000,
100 .hfp = 28,
101 .hsw = 4,
102 .hbp = 24,
103 .vfp = 3,
104 .vsw = 3,
105 .vbp = 4,
106
107 .vsync_level = OMAPDSS_SIG_ACTIVE_LOW,
108 .hsync_level = OMAPDSS_SIG_ACTIVE_LOW,
109
110 .data_pclk_edge = OMAPDSS_DRIVE_SIG_RISING_EDGE,
111 .de_level = OMAPDSS_SIG_ACTIVE_HIGH,
112 .sync_pclk_edge = OMAPDSS_DRIVE_SIG_FALLING_EDGE,
113 };
114
115 #define to_panel_data(p) container_of(p, struct panel_drv_data, dssdev)
116
117 static void acx565akm_transfer(struct panel_drv_data *ddata, int cmd,
118 const u8 *wbuf, int wlen, u8 *rbuf, int rlen)
119 {
120 struct spi_message m;
121 struct spi_transfer *x, xfer[5];
122 int r;
123
124 BUG_ON(ddata->spi == NULL);
125
126 spi_message_init(&m);
127
128 memset(xfer, 0, sizeof(xfer));
129 x = &xfer[0];
130
131 cmd &= 0xff;
132 x->tx_buf = &cmd;
133 x->bits_per_word = 9;
134 x->len = 2;
135
136 if (rlen > 1 && wlen == 0) {
137 /*
138 * Between the command and the response data there is a
139 * dummy clock cycle. Add an extra bit after the command
140 * word to account for this.
141 */
142 x->bits_per_word = 10;
143 cmd <<= 1;
144 }
145 spi_message_add_tail(x, &m);
146
147 if (wlen) {
148 x++;
149 x->tx_buf = wbuf;
150 x->len = wlen;
151 x->bits_per_word = 9;
152 spi_message_add_tail(x, &m);
153 }
154
155 if (rlen) {
156 x++;
157 x->rx_buf = rbuf;
158 x->len = rlen;
159 spi_message_add_tail(x, &m);
160 }
161
162 r = spi_sync(ddata->spi, &m);
163 if (r < 0)
164 dev_dbg(&ddata->spi->dev, "spi_sync %d\n", r);
165 }
166
167 static inline void acx565akm_cmd(struct panel_drv_data *ddata, int cmd)
168 {
169 acx565akm_transfer(ddata, cmd, NULL, 0, NULL, 0);
170 }
171
172 static inline void acx565akm_write(struct panel_drv_data *ddata,
173 int reg, const u8 *buf, int len)
174 {
175 acx565akm_transfer(ddata, reg, buf, len, NULL, 0);
176 }
177
178 static inline void acx565akm_read(struct panel_drv_data *ddata,
179 int reg, u8 *buf, int len)
180 {
181 acx565akm_transfer(ddata, reg, NULL, 0, buf, len);
182 }
183
184 static void hw_guard_start(struct panel_drv_data *ddata, int guard_msec)
185 {
186 ddata->hw_guard_wait = msecs_to_jiffies(guard_msec);
187 ddata->hw_guard_end = jiffies + ddata->hw_guard_wait;
188 }
189
190 static void hw_guard_wait(struct panel_drv_data *ddata)
191 {
192 unsigned long wait = ddata->hw_guard_end - jiffies;
193
194 if ((long)wait > 0 && wait <= ddata->hw_guard_wait) {
195 set_current_state(TASK_UNINTERRUPTIBLE);
196 schedule_timeout(wait);
197 }
198 }
199
200 static void set_sleep_mode(struct panel_drv_data *ddata, int on)
201 {
202 int cmd;
203
204 if (on)
205 cmd = MIPID_CMD_SLEEP_IN;
206 else
207 cmd = MIPID_CMD_SLEEP_OUT;
208 /*
209 * We have to keep 120msec between sleep in/out commands.
210 * (8.2.15, 8.2.16).
211 */
212 hw_guard_wait(ddata);
213 acx565akm_cmd(ddata, cmd);
214 hw_guard_start(ddata, 120);
215 }
216
217 static void set_display_state(struct panel_drv_data *ddata, int enabled)
218 {
219 int cmd = enabled ? MIPID_CMD_DISP_ON : MIPID_CMD_DISP_OFF;
220
221 acx565akm_cmd(ddata, cmd);
222 }
223
224 static int panel_enabled(struct panel_drv_data *ddata)
225 {
226 u32 disp_status;
227 int enabled;
228
229 acx565akm_read(ddata, MIPID_CMD_READ_DISP_STATUS,
230 (u8 *)&disp_status, 4);
231 disp_status = __be32_to_cpu(disp_status);
232 enabled = (disp_status & (1 << 17)) && (disp_status & (1 << 10));
233 dev_dbg(&ddata->spi->dev,
234 "LCD panel %senabled by bootloader (status 0x%04x)\n",
235 enabled ? "" : "not ", disp_status);
236 return enabled;
237 }
238
239 static int panel_detect(struct panel_drv_data *ddata)
240 {
241 acx565akm_read(ddata, MIPID_CMD_READ_DISP_ID, ddata->display_id, 3);
242 dev_dbg(&ddata->spi->dev, "MIPI display ID: %02x%02x%02x\n",
243 ddata->display_id[0],
244 ddata->display_id[1],
245 ddata->display_id[2]);
246
247 switch (ddata->display_id[0]) {
248 case 0x10:
249 ddata->model = MIPID_VER_ACX565AKM;
250 ddata->name = "acx565akm";
251 ddata->has_bc = 1;
252 ddata->has_cabc = 1;
253 break;
254 case 0x29:
255 ddata->model = MIPID_VER_L4F00311;
256 ddata->name = "l4f00311";
257 break;
258 case 0x45:
259 ddata->model = MIPID_VER_LPH8923;
260 ddata->name = "lph8923";
261 break;
262 case 0x83:
263 ddata->model = MIPID_VER_LS041Y3;
264 ddata->name = "ls041y3";
265 break;
266 default:
267 ddata->name = "unknown";
268 dev_err(&ddata->spi->dev, "invalid display ID\n");
269 return -ENODEV;
270 }
271
272 ddata->revision = ddata->display_id[1];
273
274 dev_info(&ddata->spi->dev, "omapfb: %s rev %02x LCD detected\n",
275 ddata->name, ddata->revision);
276
277 return 0;
278 }
279
280 /*----------------------Backlight Control-------------------------*/
281
282 static void enable_backlight_ctrl(struct panel_drv_data *ddata, int enable)
283 {
284 u16 ctrl;
285
286 acx565akm_read(ddata, MIPID_CMD_READ_CTRL_DISP, (u8 *)&ctrl, 1);
287 if (enable) {
288 ctrl |= CTRL_DISP_BRIGHTNESS_CTRL_ON |
289 CTRL_DISP_BACKLIGHT_ON;
290 } else {
291 ctrl &= ~(CTRL_DISP_BRIGHTNESS_CTRL_ON |
292 CTRL_DISP_BACKLIGHT_ON);
293 }
294
295 ctrl |= 1 << 8;
296 acx565akm_write(ddata, MIPID_CMD_WRITE_CTRL_DISP, (u8 *)&ctrl, 2);
297 }
298
299 static void set_cabc_mode(struct panel_drv_data *ddata, unsigned mode)
300 {
301 u16 cabc_ctrl;
302
303 ddata->cabc_mode = mode;
304 if (!ddata->enabled)
305 return;
306 cabc_ctrl = 0;
307 acx565akm_read(ddata, MIPID_CMD_READ_CABC, (u8 *)&cabc_ctrl, 1);
308 cabc_ctrl &= ~3;
309 cabc_ctrl |= (1 << 8) | (mode & 3);
310 acx565akm_write(ddata, MIPID_CMD_WRITE_CABC, (u8 *)&cabc_ctrl, 2);
311 }
312
313 static unsigned get_cabc_mode(struct panel_drv_data *ddata)
314 {
315 return ddata->cabc_mode;
316 }
317
318 static unsigned get_hw_cabc_mode(struct panel_drv_data *ddata)
319 {
320 u8 cabc_ctrl;
321
322 acx565akm_read(ddata, MIPID_CMD_READ_CABC, &cabc_ctrl, 1);
323 return cabc_ctrl & 3;
324 }
325
326 static void acx565akm_set_brightness(struct panel_drv_data *ddata, int level)
327 {
328 int bv;
329
330 bv = level | (1 << 8);
331 acx565akm_write(ddata, MIPID_CMD_WRITE_DISP_BRIGHTNESS, (u8 *)&bv, 2);
332
333 if (level)
334 enable_backlight_ctrl(ddata, 1);
335 else
336 enable_backlight_ctrl(ddata, 0);
337 }
338
339 static int acx565akm_get_actual_brightness(struct panel_drv_data *ddata)
340 {
341 u8 bv;
342
343 acx565akm_read(ddata, MIPID_CMD_READ_DISP_BRIGHTNESS, &bv, 1);
344
345 return bv;
346 }
347
348
349 static int acx565akm_bl_update_status(struct backlight_device *dev)
350 {
351 struct panel_drv_data *ddata = dev_get_drvdata(&dev->dev);
352 int level;
353
354 dev_dbg(&ddata->spi->dev, "%s\n", __func__);
355
356 if (dev->props.fb_blank == FB_BLANK_UNBLANK &&
357 dev->props.power == FB_BLANK_UNBLANK)
358 level = dev->props.brightness;
359 else
360 level = 0;
361
362 if (ddata->has_bc)
363 acx565akm_set_brightness(ddata, level);
364 else
365 return -ENODEV;
366
367 return 0;
368 }
369
370 static int acx565akm_bl_get_intensity(struct backlight_device *dev)
371 {
372 struct panel_drv_data *ddata = dev_get_drvdata(&dev->dev);
373
374 dev_dbg(&dev->dev, "%s\n", __func__);
375
376 if (!ddata->has_bc)
377 return -ENODEV;
378
379 if (dev->props.fb_blank == FB_BLANK_UNBLANK &&
380 dev->props.power == FB_BLANK_UNBLANK) {
381 if (ddata->has_bc)
382 return acx565akm_get_actual_brightness(ddata);
383 else
384 return dev->props.brightness;
385 }
386
387 return 0;
388 }
389
390 static int acx565akm_bl_update_status_locked(struct backlight_device *dev)
391 {
392 struct panel_drv_data *ddata = dev_get_drvdata(&dev->dev);
393 int r;
394
395 mutex_lock(&ddata->mutex);
396 r = acx565akm_bl_update_status(dev);
397 mutex_unlock(&ddata->mutex);
398
399 return r;
400 }
401
402 static int acx565akm_bl_get_intensity_locked(struct backlight_device *dev)
403 {
404 struct panel_drv_data *ddata = dev_get_drvdata(&dev->dev);
405 int r;
406
407 mutex_lock(&ddata->mutex);
408 r = acx565akm_bl_get_intensity(dev);
409 mutex_unlock(&ddata->mutex);
410
411 return r;
412 }
413
414 static const struct backlight_ops acx565akm_bl_ops = {
415 .get_brightness = acx565akm_bl_get_intensity_locked,
416 .update_status = acx565akm_bl_update_status_locked,
417 };
418
419 /*--------------------Auto Brightness control via Sysfs---------------------*/
420
421 static const char * const cabc_modes[] = {
422 "off", /* always used when CABC is not supported */
423 "ui",
424 "still-image",
425 "moving-image",
426 };
427
428 static ssize_t show_cabc_mode(struct device *dev,
429 struct device_attribute *attr,
430 char *buf)
431 {
432 struct panel_drv_data *ddata = dev_get_drvdata(dev);
433 const char *mode_str;
434 int mode;
435 int len;
436
437 if (!ddata->has_cabc)
438 mode = 0;
439 else
440 mode = get_cabc_mode(ddata);
441 mode_str = "unknown";
442 if (mode >= 0 && mode < ARRAY_SIZE(cabc_modes))
443 mode_str = cabc_modes[mode];
444 len = snprintf(buf, PAGE_SIZE, "%s\n", mode_str);
445
446 return len < PAGE_SIZE - 1 ? len : PAGE_SIZE - 1;
447 }
448
449 static ssize_t store_cabc_mode(struct device *dev,
450 struct device_attribute *attr,
451 const char *buf, size_t count)
452 {
453 struct panel_drv_data *ddata = dev_get_drvdata(dev);
454 int i;
455
456 for (i = 0; i < ARRAY_SIZE(cabc_modes); i++) {
457 const char *mode_str = cabc_modes[i];
458 int cmp_len = strlen(mode_str);
459
460 if (count > 0 && buf[count - 1] == '\n')
461 count--;
462 if (count != cmp_len)
463 continue;
464
465 if (strncmp(buf, mode_str, cmp_len) == 0)
466 break;
467 }
468
469 if (i == ARRAY_SIZE(cabc_modes))
470 return -EINVAL;
471
472 if (!ddata->has_cabc && i != 0)
473 return -EINVAL;
474
475 mutex_lock(&ddata->mutex);
476 set_cabc_mode(ddata, i);
477 mutex_unlock(&ddata->mutex);
478
479 return count;
480 }
481
482 static ssize_t show_cabc_available_modes(struct device *dev,
483 struct device_attribute *attr,
484 char *buf)
485 {
486 struct panel_drv_data *ddata = dev_get_drvdata(dev);
487 int len;
488 int i;
489
490 if (!ddata->has_cabc)
491 return snprintf(buf, PAGE_SIZE, "%s\n", cabc_modes[0]);
492
493 for (i = 0, len = 0;
494 len < PAGE_SIZE && i < ARRAY_SIZE(cabc_modes); i++)
495 len += snprintf(&buf[len], PAGE_SIZE - len, "%s%s%s",
496 i ? " " : "", cabc_modes[i],
497 i == ARRAY_SIZE(cabc_modes) - 1 ? "\n" : "");
498
499 return len < PAGE_SIZE ? len : PAGE_SIZE - 1;
500 }
501
502 static DEVICE_ATTR(cabc_mode, S_IRUGO | S_IWUSR,
503 show_cabc_mode, store_cabc_mode);
504 static DEVICE_ATTR(cabc_available_modes, S_IRUGO,
505 show_cabc_available_modes, NULL);
506
507 static struct attribute *bldev_attrs[] = {
508 &dev_attr_cabc_mode.attr,
509 &dev_attr_cabc_available_modes.attr,
510 NULL,
511 };
512
513 static struct attribute_group bldev_attr_group = {
514 .attrs = bldev_attrs,
515 };
516
517 static int acx565akm_connect(struct omap_dss_device *dssdev)
518 {
519 struct panel_drv_data *ddata = to_panel_data(dssdev);
520 struct omap_dss_device *in = ddata->in;
521 int r;
522
523 if (omapdss_device_is_connected(dssdev))
524 return 0;
525
526 r = in->ops.sdi->connect(in, dssdev);
527 if (r)
528 return r;
529
530 return 0;
531 }
532
533 static void acx565akm_disconnect(struct omap_dss_device *dssdev)
534 {
535 struct panel_drv_data *ddata = to_panel_data(dssdev);
536 struct omap_dss_device *in = ddata->in;
537
538 if (!omapdss_device_is_connected(dssdev))
539 return;
540
541 in->ops.sdi->disconnect(in, dssdev);
542 }
543
544 static int acx565akm_panel_power_on(struct omap_dss_device *dssdev)
545 {
546 struct panel_drv_data *ddata = to_panel_data(dssdev);
547 struct omap_dss_device *in = ddata->in;
548 int r;
549
550 dev_dbg(&ddata->spi->dev, "%s\n", __func__);
551
552 in->ops.sdi->set_timings(in, &ddata->videomode);
553
554 if (ddata->datapairs > 0)
555 in->ops.sdi->set_datapairs(in, ddata->datapairs);
556
557 r = in->ops.sdi->enable(in);
558 if (r) {
559 pr_err("%s sdi enable failed\n", __func__);
560 return r;
561 }
562
563 /*FIXME tweak me */
564 msleep(50);
565
566 if (gpio_is_valid(ddata->reset_gpio))
567 gpio_set_value(ddata->reset_gpio, 1);
568
569 if (ddata->enabled) {
570 dev_dbg(&ddata->spi->dev, "panel already enabled\n");
571 return 0;
572 }
573
574 /*
575 * We have to meet all the following delay requirements:
576 * 1. tRW: reset pulse width 10usec (7.12.1)
577 * 2. tRT: reset cancel time 5msec (7.12.1)
578 * 3. Providing PCLK,HS,VS signals for 2 frames = ~50msec worst
579 * case (7.6.2)
580 * 4. 120msec before the sleep out command (7.12.1)
581 */
582 msleep(120);
583
584 set_sleep_mode(ddata, 0);
585 ddata->enabled = 1;
586
587 /* 5msec between sleep out and the next command. (8.2.16) */
588 usleep_range(5000, 10000);
589 set_display_state(ddata, 1);
590 set_cabc_mode(ddata, ddata->cabc_mode);
591
592 return acx565akm_bl_update_status(ddata->bl_dev);
593 }
594
595 static void acx565akm_panel_power_off(struct omap_dss_device *dssdev)
596 {
597 struct panel_drv_data *ddata = to_panel_data(dssdev);
598 struct omap_dss_device *in = ddata->in;
599
600 dev_dbg(dssdev->dev, "%s\n", __func__);
601
602 if (!ddata->enabled)
603 return;
604
605 set_display_state(ddata, 0);
606 set_sleep_mode(ddata, 1);
607 ddata->enabled = 0;
608 /*
609 * We have to provide PCLK,HS,VS signals for 2 frames (worst case
610 * ~50msec) after sending the sleep in command and asserting the
611 * reset signal. We probably could assert the reset w/o the delay
612 * but we still delay to avoid possible artifacts. (7.6.1)
613 */
614 msleep(50);
615
616 if (gpio_is_valid(ddata->reset_gpio))
617 gpio_set_value(ddata->reset_gpio, 0);
618
619 /* FIXME need to tweak this delay */
620 msleep(100);
621
622 in->ops.sdi->disable(in);
623 }
624
625 static int acx565akm_enable(struct omap_dss_device *dssdev)
626 {
627 struct panel_drv_data *ddata = to_panel_data(dssdev);
628 int r;
629
630 dev_dbg(dssdev->dev, "%s\n", __func__);
631
632 if (!omapdss_device_is_connected(dssdev))
633 return -ENODEV;
634
635 if (omapdss_device_is_enabled(dssdev))
636 return 0;
637
638 mutex_lock(&ddata->mutex);
639 r = acx565akm_panel_power_on(dssdev);
640 mutex_unlock(&ddata->mutex);
641 if (r)
642 return r;
643
644 dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
645
646 return 0;
647 }
648
649 static void acx565akm_disable(struct omap_dss_device *dssdev)
650 {
651 struct panel_drv_data *ddata = to_panel_data(dssdev);
652
653 dev_dbg(dssdev->dev, "%s\n", __func__);
654
655 if (!omapdss_device_is_enabled(dssdev))
656 return;
657
658 mutex_lock(&ddata->mutex);
659 acx565akm_panel_power_off(dssdev);
660 mutex_unlock(&ddata->mutex);
661
662 dssdev->state = OMAP_DSS_DISPLAY_DISABLED;
663 }
664
665 static void acx565akm_set_timings(struct omap_dss_device *dssdev,
666 struct omap_video_timings *timings)
667 {
668 struct panel_drv_data *ddata = to_panel_data(dssdev);
669 struct omap_dss_device *in = ddata->in;
670
671 ddata->videomode = *timings;
672 dssdev->panel.timings = *timings;
673
674 in->ops.sdi->set_timings(in, timings);
675 }
676
677 static void acx565akm_get_timings(struct omap_dss_device *dssdev,
678 struct omap_video_timings *timings)
679 {
680 struct panel_drv_data *ddata = to_panel_data(dssdev);
681
682 *timings = ddata->videomode;
683 }
684
685 static int acx565akm_check_timings(struct omap_dss_device *dssdev,
686 struct omap_video_timings *timings)
687 {
688 struct panel_drv_data *ddata = to_panel_data(dssdev);
689 struct omap_dss_device *in = ddata->in;
690
691 return in->ops.sdi->check_timings(in, timings);
692 }
693
694 static struct omap_dss_driver acx565akm_ops = {
695 .connect = acx565akm_connect,
696 .disconnect = acx565akm_disconnect,
697
698 .enable = acx565akm_enable,
699 .disable = acx565akm_disable,
700
701 .set_timings = acx565akm_set_timings,
702 .get_timings = acx565akm_get_timings,
703 .check_timings = acx565akm_check_timings,
704
705 .get_resolution = omapdss_default_get_resolution,
706 };
707
708 static int acx565akm_probe_pdata(struct spi_device *spi)
709 {
710 const struct panel_acx565akm_platform_data *pdata;
711 struct panel_drv_data *ddata = dev_get_drvdata(&spi->dev);
712 struct omap_dss_device *dssdev, *in;
713
714 pdata = dev_get_platdata(&spi->dev);
715
716 ddata->reset_gpio = pdata->reset_gpio;
717
718 in = omap_dss_find_output(pdata->source);
719 if (in == NULL) {
720 dev_err(&spi->dev, "failed to find video source '%s'\n",
721 pdata->source);
722 return -EPROBE_DEFER;
723 }
724 ddata->in = in;
725
726 ddata->datapairs = pdata->datapairs;
727
728 dssdev = &ddata->dssdev;
729 dssdev->name = pdata->name;
730
731 return 0;
732 }
733
734 static int acx565akm_probe_of(struct spi_device *spi)
735 {
736 struct panel_drv_data *ddata = dev_get_drvdata(&spi->dev);
737 struct device_node *np = spi->dev.of_node;
738
739 ddata->reset_gpio = of_get_named_gpio(np, "reset-gpios", 0);
740
741 ddata->in = omapdss_of_find_source_for_first_ep(np);
742 if (IS_ERR(ddata->in)) {
743 dev_err(&spi->dev, "failed to find video source\n");
744 return PTR_ERR(ddata->in);
745 }
746
747 return 0;
748 }
749
750 static int acx565akm_probe(struct spi_device *spi)
751 {
752 struct panel_drv_data *ddata;
753 struct omap_dss_device *dssdev;
754 struct backlight_device *bldev;
755 int max_brightness, brightness;
756 struct backlight_properties props;
757 int r;
758
759 dev_dbg(&spi->dev, "%s\n", __func__);
760
761 spi->mode = SPI_MODE_3;
762
763 ddata = devm_kzalloc(&spi->dev, sizeof(*ddata), GFP_KERNEL);
764 if (ddata == NULL)
765 return -ENOMEM;
766
767 dev_set_drvdata(&spi->dev, ddata);
768
769 ddata->spi = spi;
770
771 mutex_init(&ddata->mutex);
772
773 if (dev_get_platdata(&spi->dev)) {
774 r = acx565akm_probe_pdata(spi);
775 if (r)
776 return r;
777 } else if (spi->dev.of_node) {
778 r = acx565akm_probe_of(spi);
779 if (r)
780 return r;
781 } else {
782 dev_err(&spi->dev, "platform data missing!\n");
783 return -ENODEV;
784 }
785
786 if (gpio_is_valid(ddata->reset_gpio)) {
787 r = devm_gpio_request_one(&spi->dev, ddata->reset_gpio,
788 GPIOF_OUT_INIT_LOW, "lcd reset");
789 if (r)
790 goto err_gpio;
791 }
792
793 if (gpio_is_valid(ddata->reset_gpio))
794 gpio_set_value(ddata->reset_gpio, 1);
795
796 /*
797 * After reset we have to wait 5 msec before the first
798 * command can be sent.
799 */
800 usleep_range(5000, 10000);
801
802 ddata->enabled = panel_enabled(ddata);
803
804 r = panel_detect(ddata);
805
806 if (!ddata->enabled && gpio_is_valid(ddata->reset_gpio))
807 gpio_set_value(ddata->reset_gpio, 0);
808
809 if (r) {
810 dev_err(&spi->dev, "%s panel detect error\n", __func__);
811 goto err_detect;
812 }
813
814 memset(&props, 0, sizeof(props));
815 props.fb_blank = FB_BLANK_UNBLANK;
816 props.power = FB_BLANK_UNBLANK;
817 props.type = BACKLIGHT_RAW;
818
819 bldev = backlight_device_register("acx565akm", &ddata->spi->dev,
820 ddata, &acx565akm_bl_ops, &props);
821 if (IS_ERR(bldev)) {
822 r = PTR_ERR(bldev);
823 goto err_reg_bl;
824 }
825 ddata->bl_dev = bldev;
826 if (ddata->has_cabc) {
827 r = sysfs_create_group(&bldev->dev.kobj, &bldev_attr_group);
828 if (r) {
829 dev_err(&bldev->dev,
830 "%s failed to create sysfs files\n", __func__);
831 goto err_sysfs;
832 }
833 ddata->cabc_mode = get_hw_cabc_mode(ddata);
834 }
835
836 max_brightness = 255;
837
838 if (ddata->has_bc)
839 brightness = acx565akm_get_actual_brightness(ddata);
840 else
841 brightness = 0;
842
843 bldev->props.max_brightness = max_brightness;
844 bldev->props.brightness = brightness;
845
846 acx565akm_bl_update_status(bldev);
847
848
849 ddata->videomode = acx565akm_panel_timings;
850
851 dssdev = &ddata->dssdev;
852 dssdev->dev = &spi->dev;
853 dssdev->driver = &acx565akm_ops;
854 dssdev->type = OMAP_DISPLAY_TYPE_SDI;
855 dssdev->owner = THIS_MODULE;
856 dssdev->panel.timings = ddata->videomode;
857
858 r = omapdss_register_display(dssdev);
859 if (r) {
860 dev_err(&spi->dev, "Failed to register panel\n");
861 goto err_reg;
862 }
863
864 return 0;
865
866 err_reg:
867 sysfs_remove_group(&bldev->dev.kobj, &bldev_attr_group);
868 err_sysfs:
869 backlight_device_unregister(bldev);
870 err_reg_bl:
871 err_detect:
872 err_gpio:
873 omap_dss_put_device(ddata->in);
874 return r;
875 }
876
877 static int acx565akm_remove(struct spi_device *spi)
878 {
879 struct panel_drv_data *ddata = dev_get_drvdata(&spi->dev);
880 struct omap_dss_device *dssdev = &ddata->dssdev;
881 struct omap_dss_device *in = ddata->in;
882
883 dev_dbg(&ddata->spi->dev, "%s\n", __func__);
884
885 sysfs_remove_group(&ddata->bl_dev->dev.kobj, &bldev_attr_group);
886 backlight_device_unregister(ddata->bl_dev);
887
888 omapdss_unregister_display(dssdev);
889
890 acx565akm_disable(dssdev);
891 acx565akm_disconnect(dssdev);
892
893 omap_dss_put_device(in);
894
895 return 0;
896 }
897
898 static const struct of_device_id acx565akm_of_match[] = {
899 { .compatible = "omapdss,sony,acx565akm", },
900 {},
901 };
902 MODULE_DEVICE_TABLE(of, acx565akm_of_match);
903
904 static struct spi_driver acx565akm_driver = {
905 .driver = {
906 .name = "acx565akm",
907 .of_match_table = acx565akm_of_match,
908 .suppress_bind_attrs = true,
909 },
910 .probe = acx565akm_probe,
911 .remove = acx565akm_remove,
912 };
913
914 module_spi_driver(acx565akm_driver);
915
916 MODULE_AUTHOR("Nokia Corporation");
917 MODULE_DESCRIPTION("acx565akm LCD Driver");
918 MODULE_LICENSE("GPL");
This page took 0.052122 seconds and 5 git commands to generate.