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