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