2 * Generic DSI Command Mode panel driver
4 * Copyright (C) 2013 Texas Instruments
5 * Author: Tomi Valkeinen <tomi.valkeinen@ti.com>
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License version 2 as published by
9 * the Free Software Foundation.
14 #include <linux/backlight.h>
15 #include <linux/delay.h>
17 #include <linux/gpio.h>
18 #include <linux/interrupt.h>
19 #include <linux/jiffies.h>
20 #include <linux/module.h>
21 #include <linux/platform_device.h>
22 #include <linux/sched/signal.h>
23 #include <linux/slab.h>
24 #include <linux/workqueue.h>
25 #include <linux/of_device.h>
26 #include <linux/of_gpio.h>
28 #include <video/omapfb_dss.h>
29 #include <video/mipi_display.h>
31 /* DSI Virtual channel. Hardcoded for now. */
34 #define DCS_READ_NUM_ERRORS 0x05
35 #define DCS_BRIGHTNESS 0x51
36 #define DCS_CTRL_DISPLAY 0x53
37 #define DCS_GET_ID1 0xda
38 #define DCS_GET_ID2 0xdb
39 #define DCS_GET_ID3 0xdc
41 struct panel_drv_data
{
42 struct omap_dss_device dssdev
;
43 struct omap_dss_device
*in
;
45 struct omap_video_timings timings
;
47 struct platform_device
*pdev
;
51 struct backlight_device
*bldev
;
53 unsigned long hw_guard_end
; /* next value of jiffies when we can
54 * issue the next sleep in/out command
56 unsigned long hw_guard_wait
; /* max guard time in jiffies */
58 /* panel HW configuration from DT or platform data */
62 bool use_dsi_backlight
;
64 struct omap_dsi_pin_config pin_config
;
66 /* runtime variables */
74 struct delayed_work te_timeout_work
;
79 unsigned ulps_timeout
;
80 struct delayed_work ulps_work
;
83 #define to_panel_data(p) container_of(p, struct panel_drv_data, dssdev)
85 static irqreturn_t
dsicm_te_isr(int irq
, void *data
);
86 static void dsicm_te_timeout_work_callback(struct work_struct
*work
);
87 static int _dsicm_enable_te(struct panel_drv_data
*ddata
, bool enable
);
89 static int dsicm_panel_reset(struct panel_drv_data
*ddata
);
91 static void dsicm_ulps_work(struct work_struct
*work
);
93 static void hw_guard_start(struct panel_drv_data
*ddata
, int guard_msec
)
95 ddata
->hw_guard_wait
= msecs_to_jiffies(guard_msec
);
96 ddata
->hw_guard_end
= jiffies
+ ddata
->hw_guard_wait
;
99 static void hw_guard_wait(struct panel_drv_data
*ddata
)
101 unsigned long wait
= ddata
->hw_guard_end
- jiffies
;
103 if ((long)wait
> 0 && time_before_eq(wait
, ddata
->hw_guard_wait
)) {
104 set_current_state(TASK_UNINTERRUPTIBLE
);
105 schedule_timeout(wait
);
109 static int dsicm_dcs_read_1(struct panel_drv_data
*ddata
, u8 dcs_cmd
, u8
*data
)
111 struct omap_dss_device
*in
= ddata
->in
;
115 r
= in
->ops
.dsi
->dcs_read(in
, ddata
->channel
, dcs_cmd
, buf
, 1);
125 static int dsicm_dcs_write_0(struct panel_drv_data
*ddata
, u8 dcs_cmd
)
127 struct omap_dss_device
*in
= ddata
->in
;
128 return in
->ops
.dsi
->dcs_write(in
, ddata
->channel
, &dcs_cmd
, 1);
131 static int dsicm_dcs_write_1(struct panel_drv_data
*ddata
, u8 dcs_cmd
, u8 param
)
133 struct omap_dss_device
*in
= ddata
->in
;
134 u8 buf
[2] = { dcs_cmd
, param
};
136 return in
->ops
.dsi
->dcs_write(in
, ddata
->channel
, buf
, 2);
139 static int dsicm_sleep_in(struct panel_drv_data
*ddata
)
142 struct omap_dss_device
*in
= ddata
->in
;
146 hw_guard_wait(ddata
);
148 cmd
= MIPI_DCS_ENTER_SLEEP_MODE
;
149 r
= in
->ops
.dsi
->dcs_write_nosync(in
, ddata
->channel
, &cmd
, 1);
153 hw_guard_start(ddata
, 120);
155 usleep_range(5000, 10000);
160 static int dsicm_sleep_out(struct panel_drv_data
*ddata
)
164 hw_guard_wait(ddata
);
166 r
= dsicm_dcs_write_0(ddata
, MIPI_DCS_EXIT_SLEEP_MODE
);
170 hw_guard_start(ddata
, 120);
172 usleep_range(5000, 10000);
177 static int dsicm_get_id(struct panel_drv_data
*ddata
, u8
*id1
, u8
*id2
, u8
*id3
)
181 r
= dsicm_dcs_read_1(ddata
, DCS_GET_ID1
, id1
);
184 r
= dsicm_dcs_read_1(ddata
, DCS_GET_ID2
, id2
);
187 r
= dsicm_dcs_read_1(ddata
, DCS_GET_ID3
, id3
);
194 static int dsicm_set_update_window(struct panel_drv_data
*ddata
,
195 u16 x
, u16 y
, u16 w
, u16 h
)
197 struct omap_dss_device
*in
= ddata
->in
;
205 buf
[0] = MIPI_DCS_SET_COLUMN_ADDRESS
;
206 buf
[1] = (x1
>> 8) & 0xff;
207 buf
[2] = (x1
>> 0) & 0xff;
208 buf
[3] = (x2
>> 8) & 0xff;
209 buf
[4] = (x2
>> 0) & 0xff;
211 r
= in
->ops
.dsi
->dcs_write_nosync(in
, ddata
->channel
, buf
, sizeof(buf
));
215 buf
[0] = MIPI_DCS_SET_PAGE_ADDRESS
;
216 buf
[1] = (y1
>> 8) & 0xff;
217 buf
[2] = (y1
>> 0) & 0xff;
218 buf
[3] = (y2
>> 8) & 0xff;
219 buf
[4] = (y2
>> 0) & 0xff;
221 r
= in
->ops
.dsi
->dcs_write_nosync(in
, ddata
->channel
, buf
, sizeof(buf
));
225 in
->ops
.dsi
->bta_sync(in
, ddata
->channel
);
230 static void dsicm_queue_ulps_work(struct panel_drv_data
*ddata
)
232 if (ddata
->ulps_timeout
> 0)
233 schedule_delayed_work(&ddata
->ulps_work
,
234 msecs_to_jiffies(ddata
->ulps_timeout
));
237 static void dsicm_cancel_ulps_work(struct panel_drv_data
*ddata
)
239 cancel_delayed_work(&ddata
->ulps_work
);
242 static int dsicm_enter_ulps(struct panel_drv_data
*ddata
)
244 struct omap_dss_device
*in
= ddata
->in
;
247 if (ddata
->ulps_enabled
)
250 dsicm_cancel_ulps_work(ddata
);
252 r
= _dsicm_enable_te(ddata
, false);
256 if (gpio_is_valid(ddata
->ext_te_gpio
))
257 disable_irq(gpio_to_irq(ddata
->ext_te_gpio
));
259 in
->ops
.dsi
->disable(in
, false, true);
261 ddata
->ulps_enabled
= true;
266 dev_err(&ddata
->pdev
->dev
, "enter ULPS failed");
267 dsicm_panel_reset(ddata
);
269 ddata
->ulps_enabled
= false;
271 dsicm_queue_ulps_work(ddata
);
276 static int dsicm_exit_ulps(struct panel_drv_data
*ddata
)
278 struct omap_dss_device
*in
= ddata
->in
;
281 if (!ddata
->ulps_enabled
)
284 r
= in
->ops
.dsi
->enable(in
);
286 dev_err(&ddata
->pdev
->dev
, "failed to enable DSI\n");
290 in
->ops
.dsi
->enable_hs(in
, ddata
->channel
, true);
292 r
= _dsicm_enable_te(ddata
, true);
294 dev_err(&ddata
->pdev
->dev
, "failed to re-enable TE");
298 if (gpio_is_valid(ddata
->ext_te_gpio
))
299 enable_irq(gpio_to_irq(ddata
->ext_te_gpio
));
301 dsicm_queue_ulps_work(ddata
);
303 ddata
->ulps_enabled
= false;
308 dev_err(&ddata
->pdev
->dev
, "failed to exit ULPS");
310 r
= dsicm_panel_reset(ddata
);
312 if (gpio_is_valid(ddata
->ext_te_gpio
))
313 enable_irq(gpio_to_irq(ddata
->ext_te_gpio
));
314 ddata
->ulps_enabled
= false;
317 dsicm_queue_ulps_work(ddata
);
322 static int dsicm_wake_up(struct panel_drv_data
*ddata
)
324 if (ddata
->ulps_enabled
)
325 return dsicm_exit_ulps(ddata
);
327 dsicm_cancel_ulps_work(ddata
);
328 dsicm_queue_ulps_work(ddata
);
332 static int dsicm_bl_update_status(struct backlight_device
*dev
)
334 struct panel_drv_data
*ddata
= dev_get_drvdata(&dev
->dev
);
335 struct omap_dss_device
*in
= ddata
->in
;
339 if (dev
->props
.fb_blank
== FB_BLANK_UNBLANK
&&
340 dev
->props
.power
== FB_BLANK_UNBLANK
)
341 level
= dev
->props
.brightness
;
345 dev_dbg(&ddata
->pdev
->dev
, "update brightness to %d\n", level
);
347 mutex_lock(&ddata
->lock
);
349 if (ddata
->enabled
) {
350 in
->ops
.dsi
->bus_lock(in
);
352 r
= dsicm_wake_up(ddata
);
354 r
= dsicm_dcs_write_1(ddata
, DCS_BRIGHTNESS
, level
);
356 in
->ops
.dsi
->bus_unlock(in
);
361 mutex_unlock(&ddata
->lock
);
366 static int dsicm_bl_get_intensity(struct backlight_device
*dev
)
368 if (dev
->props
.fb_blank
== FB_BLANK_UNBLANK
&&
369 dev
->props
.power
== FB_BLANK_UNBLANK
)
370 return dev
->props
.brightness
;
375 static const struct backlight_ops dsicm_bl_ops
= {
376 .get_brightness
= dsicm_bl_get_intensity
,
377 .update_status
= dsicm_bl_update_status
,
380 static void dsicm_get_resolution(struct omap_dss_device
*dssdev
,
381 u16
*xres
, u16
*yres
)
383 *xres
= dssdev
->panel
.timings
.x_res
;
384 *yres
= dssdev
->panel
.timings
.y_res
;
387 static ssize_t
dsicm_num_errors_show(struct device
*dev
,
388 struct device_attribute
*attr
, char *buf
)
390 struct panel_drv_data
*ddata
= dev_get_drvdata(dev
);
391 struct omap_dss_device
*in
= ddata
->in
;
395 mutex_lock(&ddata
->lock
);
397 if (ddata
->enabled
) {
398 in
->ops
.dsi
->bus_lock(in
);
400 r
= dsicm_wake_up(ddata
);
402 r
= dsicm_dcs_read_1(ddata
, DCS_READ_NUM_ERRORS
,
405 in
->ops
.dsi
->bus_unlock(in
);
410 mutex_unlock(&ddata
->lock
);
415 return snprintf(buf
, PAGE_SIZE
, "%d\n", errors
);
418 static ssize_t
dsicm_hw_revision_show(struct device
*dev
,
419 struct device_attribute
*attr
, char *buf
)
421 struct panel_drv_data
*ddata
= dev_get_drvdata(dev
);
422 struct omap_dss_device
*in
= ddata
->in
;
426 mutex_lock(&ddata
->lock
);
428 if (ddata
->enabled
) {
429 in
->ops
.dsi
->bus_lock(in
);
431 r
= dsicm_wake_up(ddata
);
433 r
= dsicm_get_id(ddata
, &id1
, &id2
, &id3
);
435 in
->ops
.dsi
->bus_unlock(in
);
440 mutex_unlock(&ddata
->lock
);
445 return snprintf(buf
, PAGE_SIZE
, "%02x.%02x.%02x\n", id1
, id2
, id3
);
448 static ssize_t
dsicm_store_ulps(struct device
*dev
,
449 struct device_attribute
*attr
,
450 const char *buf
, size_t count
)
452 struct panel_drv_data
*ddata
= dev_get_drvdata(dev
);
453 struct omap_dss_device
*in
= ddata
->in
;
457 r
= kstrtoul(buf
, 0, &t
);
461 mutex_lock(&ddata
->lock
);
463 if (ddata
->enabled
) {
464 in
->ops
.dsi
->bus_lock(in
);
467 r
= dsicm_enter_ulps(ddata
);
469 r
= dsicm_wake_up(ddata
);
471 in
->ops
.dsi
->bus_unlock(in
);
474 mutex_unlock(&ddata
->lock
);
482 static ssize_t
dsicm_show_ulps(struct device
*dev
,
483 struct device_attribute
*attr
,
486 struct panel_drv_data
*ddata
= dev_get_drvdata(dev
);
489 mutex_lock(&ddata
->lock
);
490 t
= ddata
->ulps_enabled
;
491 mutex_unlock(&ddata
->lock
);
493 return snprintf(buf
, PAGE_SIZE
, "%u\n", t
);
496 static ssize_t
dsicm_store_ulps_timeout(struct device
*dev
,
497 struct device_attribute
*attr
,
498 const char *buf
, size_t count
)
500 struct panel_drv_data
*ddata
= dev_get_drvdata(dev
);
501 struct omap_dss_device
*in
= ddata
->in
;
505 r
= kstrtoul(buf
, 0, &t
);
509 mutex_lock(&ddata
->lock
);
510 ddata
->ulps_timeout
= t
;
512 if (ddata
->enabled
) {
513 /* dsicm_wake_up will restart the timer */
514 in
->ops
.dsi
->bus_lock(in
);
515 r
= dsicm_wake_up(ddata
);
516 in
->ops
.dsi
->bus_unlock(in
);
519 mutex_unlock(&ddata
->lock
);
527 static ssize_t
dsicm_show_ulps_timeout(struct device
*dev
,
528 struct device_attribute
*attr
,
531 struct panel_drv_data
*ddata
= dev_get_drvdata(dev
);
534 mutex_lock(&ddata
->lock
);
535 t
= ddata
->ulps_timeout
;
536 mutex_unlock(&ddata
->lock
);
538 return snprintf(buf
, PAGE_SIZE
, "%u\n", t
);
541 static DEVICE_ATTR(num_dsi_errors
, S_IRUGO
, dsicm_num_errors_show
, NULL
);
542 static DEVICE_ATTR(hw_revision
, S_IRUGO
, dsicm_hw_revision_show
, NULL
);
543 static DEVICE_ATTR(ulps
, S_IRUGO
| S_IWUSR
,
544 dsicm_show_ulps
, dsicm_store_ulps
);
545 static DEVICE_ATTR(ulps_timeout
, S_IRUGO
| S_IWUSR
,
546 dsicm_show_ulps_timeout
, dsicm_store_ulps_timeout
);
548 static struct attribute
*dsicm_attrs
[] = {
549 &dev_attr_num_dsi_errors
.attr
,
550 &dev_attr_hw_revision
.attr
,
552 &dev_attr_ulps_timeout
.attr
,
556 static const struct attribute_group dsicm_attr_group
= {
557 .attrs
= dsicm_attrs
,
560 static void dsicm_hw_reset(struct panel_drv_data
*ddata
)
562 if (!gpio_is_valid(ddata
->reset_gpio
))
565 gpio_set_value(ddata
->reset_gpio
, 1);
567 /* reset the panel */
568 gpio_set_value(ddata
->reset_gpio
, 0);
571 gpio_set_value(ddata
->reset_gpio
, 1);
572 /* wait after releasing reset */
573 usleep_range(5000, 10000);
576 static int dsicm_power_on(struct panel_drv_data
*ddata
)
578 struct omap_dss_device
*in
= ddata
->in
;
581 struct omap_dss_dsi_config dsi_config
= {
582 .mode
= OMAP_DSS_DSI_CMD_MODE
,
583 .pixel_format
= OMAP_DSS_DSI_FMT_RGB888
,
584 .timings
= &ddata
->timings
,
585 .hs_clk_min
= 150000000,
586 .hs_clk_max
= 300000000,
587 .lp_clk_min
= 7000000,
588 .lp_clk_max
= 10000000,
591 if (ddata
->pin_config
.num_pins
> 0) {
592 r
= in
->ops
.dsi
->configure_pins(in
, &ddata
->pin_config
);
594 dev_err(&ddata
->pdev
->dev
,
595 "failed to configure DSI pins\n");
600 r
= in
->ops
.dsi
->set_config(in
, &dsi_config
);
602 dev_err(&ddata
->pdev
->dev
, "failed to configure DSI\n");
606 r
= in
->ops
.dsi
->enable(in
);
608 dev_err(&ddata
->pdev
->dev
, "failed to enable DSI\n");
612 dsicm_hw_reset(ddata
);
614 in
->ops
.dsi
->enable_hs(in
, ddata
->channel
, false);
616 r
= dsicm_sleep_out(ddata
);
620 r
= dsicm_get_id(ddata
, &id1
, &id2
, &id3
);
624 r
= dsicm_dcs_write_1(ddata
, DCS_BRIGHTNESS
, 0xff);
628 r
= dsicm_dcs_write_1(ddata
, DCS_CTRL_DISPLAY
,
629 (1<<2) | (1<<5)); /* BL | BCTRL */
633 r
= dsicm_dcs_write_1(ddata
, MIPI_DCS_SET_PIXEL_FORMAT
,
634 MIPI_DCS_PIXEL_FMT_24BIT
);
638 r
= dsicm_dcs_write_0(ddata
, MIPI_DCS_SET_DISPLAY_ON
);
642 r
= _dsicm_enable_te(ddata
, ddata
->te_enabled
);
646 r
= in
->ops
.dsi
->enable_video_output(in
, ddata
->channel
);
652 if (!ddata
->intro_printed
) {
653 dev_info(&ddata
->pdev
->dev
, "panel revision %02x.%02x.%02x\n",
655 ddata
->intro_printed
= true;
658 in
->ops
.dsi
->enable_hs(in
, ddata
->channel
, true);
662 dev_err(&ddata
->pdev
->dev
, "error while enabling panel, issuing HW reset\n");
664 dsicm_hw_reset(ddata
);
666 in
->ops
.dsi
->disable(in
, true, false);
671 static void dsicm_power_off(struct panel_drv_data
*ddata
)
673 struct omap_dss_device
*in
= ddata
->in
;
676 in
->ops
.dsi
->disable_video_output(in
, ddata
->channel
);
678 r
= dsicm_dcs_write_0(ddata
, MIPI_DCS_SET_DISPLAY_OFF
);
680 r
= dsicm_sleep_in(ddata
);
683 dev_err(&ddata
->pdev
->dev
,
684 "error disabling panel, issuing HW reset\n");
685 dsicm_hw_reset(ddata
);
688 in
->ops
.dsi
->disable(in
, true, false);
693 static int dsicm_panel_reset(struct panel_drv_data
*ddata
)
695 dev_err(&ddata
->pdev
->dev
, "performing LCD reset\n");
697 dsicm_power_off(ddata
);
698 dsicm_hw_reset(ddata
);
699 return dsicm_power_on(ddata
);
702 static int dsicm_connect(struct omap_dss_device
*dssdev
)
704 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
705 struct omap_dss_device
*in
= ddata
->in
;
706 struct device
*dev
= &ddata
->pdev
->dev
;
709 if (omapdss_device_is_connected(dssdev
))
712 r
= in
->ops
.dsi
->connect(in
, dssdev
);
714 dev_err(dev
, "Failed to connect to video source\n");
718 r
= in
->ops
.dsi
->request_vc(ddata
->in
, &ddata
->channel
);
720 dev_err(dev
, "failed to get virtual channel\n");
724 r
= in
->ops
.dsi
->set_vc_id(ddata
->in
, ddata
->channel
, TCH
);
726 dev_err(dev
, "failed to set VC_ID\n");
733 in
->ops
.dsi
->release_vc(ddata
->in
, ddata
->channel
);
735 in
->ops
.dsi
->disconnect(in
, dssdev
);
739 static void dsicm_disconnect(struct omap_dss_device
*dssdev
)
741 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
742 struct omap_dss_device
*in
= ddata
->in
;
744 if (!omapdss_device_is_connected(dssdev
))
747 in
->ops
.dsi
->release_vc(in
, ddata
->channel
);
748 in
->ops
.dsi
->disconnect(in
, dssdev
);
751 static int dsicm_enable(struct omap_dss_device
*dssdev
)
753 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
754 struct omap_dss_device
*in
= ddata
->in
;
757 dev_dbg(&ddata
->pdev
->dev
, "enable\n");
759 mutex_lock(&ddata
->lock
);
761 if (!omapdss_device_is_connected(dssdev
)) {
766 if (omapdss_device_is_enabled(dssdev
)) {
771 in
->ops
.dsi
->bus_lock(in
);
773 r
= dsicm_power_on(ddata
);
775 in
->ops
.dsi
->bus_unlock(in
);
780 dssdev
->state
= OMAP_DSS_DISPLAY_ACTIVE
;
782 mutex_unlock(&ddata
->lock
);
786 dev_dbg(&ddata
->pdev
->dev
, "enable failed\n");
787 mutex_unlock(&ddata
->lock
);
791 static void dsicm_disable(struct omap_dss_device
*dssdev
)
793 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
794 struct omap_dss_device
*in
= ddata
->in
;
797 dev_dbg(&ddata
->pdev
->dev
, "disable\n");
799 mutex_lock(&ddata
->lock
);
801 dsicm_cancel_ulps_work(ddata
);
803 in
->ops
.dsi
->bus_lock(in
);
805 if (omapdss_device_is_enabled(dssdev
)) {
806 r
= dsicm_wake_up(ddata
);
808 dsicm_power_off(ddata
);
811 in
->ops
.dsi
->bus_unlock(in
);
813 dssdev
->state
= OMAP_DSS_DISPLAY_DISABLED
;
815 mutex_unlock(&ddata
->lock
);
818 static void dsicm_framedone_cb(int err
, void *data
)
820 struct panel_drv_data
*ddata
= data
;
821 struct omap_dss_device
*in
= ddata
->in
;
823 dev_dbg(&ddata
->pdev
->dev
, "framedone, err %d\n", err
);
824 in
->ops
.dsi
->bus_unlock(ddata
->in
);
827 static irqreturn_t
dsicm_te_isr(int irq
, void *data
)
829 struct panel_drv_data
*ddata
= data
;
830 struct omap_dss_device
*in
= ddata
->in
;
834 old
= atomic_cmpxchg(&ddata
->do_update
, 1, 0);
837 cancel_delayed_work(&ddata
->te_timeout_work
);
839 r
= in
->ops
.dsi
->update(in
, ddata
->channel
, dsicm_framedone_cb
,
847 dev_err(&ddata
->pdev
->dev
, "start update failed\n");
848 in
->ops
.dsi
->bus_unlock(in
);
852 static void dsicm_te_timeout_work_callback(struct work_struct
*work
)
854 struct panel_drv_data
*ddata
= container_of(work
, struct panel_drv_data
,
855 te_timeout_work
.work
);
856 struct omap_dss_device
*in
= ddata
->in
;
858 dev_err(&ddata
->pdev
->dev
, "TE not received for 250ms!\n");
860 atomic_set(&ddata
->do_update
, 0);
861 in
->ops
.dsi
->bus_unlock(in
);
864 static int dsicm_update(struct omap_dss_device
*dssdev
,
865 u16 x
, u16 y
, u16 w
, u16 h
)
867 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
868 struct omap_dss_device
*in
= ddata
->in
;
871 dev_dbg(&ddata
->pdev
->dev
, "update %d, %d, %d x %d\n", x
, y
, w
, h
);
873 mutex_lock(&ddata
->lock
);
874 in
->ops
.dsi
->bus_lock(in
);
876 r
= dsicm_wake_up(ddata
);
880 if (!ddata
->enabled
) {
885 /* XXX no need to send this every frame, but dsi break if not done */
886 r
= dsicm_set_update_window(ddata
, 0, 0,
887 dssdev
->panel
.timings
.x_res
,
888 dssdev
->panel
.timings
.y_res
);
892 if (ddata
->te_enabled
&& gpio_is_valid(ddata
->ext_te_gpio
)) {
893 schedule_delayed_work(&ddata
->te_timeout_work
,
894 msecs_to_jiffies(250));
895 atomic_set(&ddata
->do_update
, 1);
897 r
= in
->ops
.dsi
->update(in
, ddata
->channel
, dsicm_framedone_cb
,
903 /* note: no bus_unlock here. unlock is in framedone_cb */
904 mutex_unlock(&ddata
->lock
);
907 in
->ops
.dsi
->bus_unlock(in
);
908 mutex_unlock(&ddata
->lock
);
912 static int dsicm_sync(struct omap_dss_device
*dssdev
)
914 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
915 struct omap_dss_device
*in
= ddata
->in
;
917 dev_dbg(&ddata
->pdev
->dev
, "sync\n");
919 mutex_lock(&ddata
->lock
);
920 in
->ops
.dsi
->bus_lock(in
);
921 in
->ops
.dsi
->bus_unlock(in
);
922 mutex_unlock(&ddata
->lock
);
924 dev_dbg(&ddata
->pdev
->dev
, "sync done\n");
929 static int _dsicm_enable_te(struct panel_drv_data
*ddata
, bool enable
)
931 struct omap_dss_device
*in
= ddata
->in
;
935 r
= dsicm_dcs_write_1(ddata
, MIPI_DCS_SET_TEAR_ON
, 0);
937 r
= dsicm_dcs_write_0(ddata
, MIPI_DCS_SET_TEAR_OFF
);
939 if (!gpio_is_valid(ddata
->ext_te_gpio
))
940 in
->ops
.dsi
->enable_te(in
, enable
);
942 /* possible panel bug */
948 static int dsicm_enable_te(struct omap_dss_device
*dssdev
, bool enable
)
950 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
951 struct omap_dss_device
*in
= ddata
->in
;
954 mutex_lock(&ddata
->lock
);
956 if (ddata
->te_enabled
== enable
)
959 in
->ops
.dsi
->bus_lock(in
);
961 if (ddata
->enabled
) {
962 r
= dsicm_wake_up(ddata
);
966 r
= _dsicm_enable_te(ddata
, enable
);
971 ddata
->te_enabled
= enable
;
973 in
->ops
.dsi
->bus_unlock(in
);
975 mutex_unlock(&ddata
->lock
);
979 in
->ops
.dsi
->bus_unlock(in
);
980 mutex_unlock(&ddata
->lock
);
985 static int dsicm_get_te(struct omap_dss_device
*dssdev
)
987 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
990 mutex_lock(&ddata
->lock
);
991 r
= ddata
->te_enabled
;
992 mutex_unlock(&ddata
->lock
);
997 static int dsicm_memory_read(struct omap_dss_device
*dssdev
,
998 void *buf
, size_t size
,
999 u16 x
, u16 y
, u16 w
, u16 h
)
1001 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
1002 struct omap_dss_device
*in
= ddata
->in
;
1006 unsigned buf_used
= 0;
1008 if (size
< w
* h
* 3)
1011 mutex_lock(&ddata
->lock
);
1013 if (!ddata
->enabled
) {
1018 size
= min(w
* h
* 3,
1019 dssdev
->panel
.timings
.x_res
*
1020 dssdev
->panel
.timings
.y_res
* 3);
1022 in
->ops
.dsi
->bus_lock(in
);
1024 r
= dsicm_wake_up(ddata
);
1028 /* plen 1 or 2 goes into short packet. until checksum error is fixed,
1029 * use short packets. plen 32 works, but bigger packets seem to cause
1036 dsicm_set_update_window(ddata
, x
, y
, w
, h
);
1038 r
= in
->ops
.dsi
->set_max_rx_packet_size(in
, ddata
->channel
, plen
);
1042 while (buf_used
< size
) {
1043 u8 dcs_cmd
= first
? 0x2e : 0x3e;
1046 r
= in
->ops
.dsi
->dcs_read(in
, ddata
->channel
, dcs_cmd
,
1047 buf
+ buf_used
, size
- buf_used
);
1050 dev_err(dssdev
->dev
, "read error\n");
1057 dev_err(&ddata
->pdev
->dev
, "short read\n");
1061 if (signal_pending(current
)) {
1062 dev_err(&ddata
->pdev
->dev
, "signal pending, "
1063 "aborting memory read\n");
1072 in
->ops
.dsi
->set_max_rx_packet_size(in
, ddata
->channel
, 1);
1074 in
->ops
.dsi
->bus_unlock(in
);
1076 mutex_unlock(&ddata
->lock
);
1080 static void dsicm_ulps_work(struct work_struct
*work
)
1082 struct panel_drv_data
*ddata
= container_of(work
, struct panel_drv_data
,
1084 struct omap_dss_device
*dssdev
= &ddata
->dssdev
;
1085 struct omap_dss_device
*in
= ddata
->in
;
1087 mutex_lock(&ddata
->lock
);
1089 if (dssdev
->state
!= OMAP_DSS_DISPLAY_ACTIVE
|| !ddata
->enabled
) {
1090 mutex_unlock(&ddata
->lock
);
1094 in
->ops
.dsi
->bus_lock(in
);
1096 dsicm_enter_ulps(ddata
);
1098 in
->ops
.dsi
->bus_unlock(in
);
1099 mutex_unlock(&ddata
->lock
);
1102 static struct omap_dss_driver dsicm_ops
= {
1103 .connect
= dsicm_connect
,
1104 .disconnect
= dsicm_disconnect
,
1106 .enable
= dsicm_enable
,
1107 .disable
= dsicm_disable
,
1109 .update
= dsicm_update
,
1112 .get_resolution
= dsicm_get_resolution
,
1113 .get_recommended_bpp
= omapdss_default_get_recommended_bpp
,
1115 .enable_te
= dsicm_enable_te
,
1116 .get_te
= dsicm_get_te
,
1118 .memory_read
= dsicm_memory_read
,
1121 static int dsicm_probe_of(struct platform_device
*pdev
)
1123 struct device_node
*node
= pdev
->dev
.of_node
;
1124 struct panel_drv_data
*ddata
= platform_get_drvdata(pdev
);
1125 struct omap_dss_device
*in
;
1128 gpio
= of_get_named_gpio(node
, "reset-gpios", 0);
1129 if (!gpio_is_valid(gpio
)) {
1130 dev_err(&pdev
->dev
, "failed to parse reset gpio\n");
1133 ddata
->reset_gpio
= gpio
;
1135 gpio
= of_get_named_gpio(node
, "te-gpios", 0);
1136 if (gpio_is_valid(gpio
) || gpio
== -ENOENT
) {
1137 ddata
->ext_te_gpio
= gpio
;
1139 dev_err(&pdev
->dev
, "failed to parse TE gpio\n");
1143 in
= omapdss_of_find_source_for_first_ep(node
);
1145 dev_err(&pdev
->dev
, "failed to find video source\n");
1151 /* TODO: ulps, backlight */
1156 static int dsicm_probe(struct platform_device
*pdev
)
1158 struct backlight_properties props
;
1159 struct panel_drv_data
*ddata
;
1160 struct backlight_device
*bldev
= NULL
;
1161 struct device
*dev
= &pdev
->dev
;
1162 struct omap_dss_device
*dssdev
;
1165 dev_dbg(dev
, "probe\n");
1167 if (!pdev
->dev
.of_node
)
1170 ddata
= devm_kzalloc(dev
, sizeof(*ddata
), GFP_KERNEL
);
1174 platform_set_drvdata(pdev
, ddata
);
1177 r
= dsicm_probe_of(pdev
);
1181 ddata
->timings
.x_res
= 864;
1182 ddata
->timings
.y_res
= 480;
1183 ddata
->timings
.pixelclock
= 864 * 480 * 60;
1185 dssdev
= &ddata
->dssdev
;
1187 dssdev
->driver
= &dsicm_ops
;
1188 dssdev
->panel
.timings
= ddata
->timings
;
1189 dssdev
->type
= OMAP_DISPLAY_TYPE_DSI
;
1190 dssdev
->owner
= THIS_MODULE
;
1192 dssdev
->panel
.dsi_pix_fmt
= OMAP_DSS_DSI_FMT_RGB888
;
1193 dssdev
->caps
= OMAP_DSS_DISPLAY_CAP_MANUAL_UPDATE
|
1194 OMAP_DSS_DISPLAY_CAP_TEAR_ELIM
;
1196 r
= omapdss_register_display(dssdev
);
1198 dev_err(dev
, "Failed to register panel\n");
1202 mutex_init(&ddata
->lock
);
1204 atomic_set(&ddata
->do_update
, 0);
1206 if (gpio_is_valid(ddata
->reset_gpio
)) {
1207 r
= devm_gpio_request_one(dev
, ddata
->reset_gpio
,
1208 GPIOF_OUT_INIT_LOW
, "taal rst");
1210 dev_err(dev
, "failed to request reset gpio\n");
1215 if (gpio_is_valid(ddata
->ext_te_gpio
)) {
1216 r
= devm_gpio_request_one(dev
, ddata
->ext_te_gpio
,
1217 GPIOF_IN
, "taal irq");
1219 dev_err(dev
, "GPIO request failed\n");
1223 r
= devm_request_irq(dev
, gpio_to_irq(ddata
->ext_te_gpio
),
1225 IRQF_TRIGGER_RISING
,
1226 "taal vsync", ddata
);
1229 dev_err(dev
, "IRQ request failed\n");
1233 INIT_DEFERRABLE_WORK(&ddata
->te_timeout_work
,
1234 dsicm_te_timeout_work_callback
);
1236 dev_dbg(dev
, "Using GPIO TE\n");
1239 INIT_DELAYED_WORK(&ddata
->ulps_work
, dsicm_ulps_work
);
1241 dsicm_hw_reset(ddata
);
1243 if (ddata
->use_dsi_backlight
) {
1244 memset(&props
, 0, sizeof(struct backlight_properties
));
1245 props
.max_brightness
= 255;
1247 props
.type
= BACKLIGHT_RAW
;
1248 bldev
= backlight_device_register(dev_name(dev
),
1249 dev
, ddata
, &dsicm_bl_ops
, &props
);
1250 if (IS_ERR(bldev
)) {
1255 ddata
->bldev
= bldev
;
1257 bldev
->props
.fb_blank
= FB_BLANK_UNBLANK
;
1258 bldev
->props
.power
= FB_BLANK_UNBLANK
;
1259 bldev
->props
.brightness
= 255;
1261 dsicm_bl_update_status(bldev
);
1264 r
= sysfs_create_group(&dev
->kobj
, &dsicm_attr_group
);
1266 dev_err(dev
, "failed to create sysfs files\n");
1267 goto err_sysfs_create
;
1274 backlight_device_unregister(bldev
);
1279 static int __exit
dsicm_remove(struct platform_device
*pdev
)
1281 struct panel_drv_data
*ddata
= platform_get_drvdata(pdev
);
1282 struct omap_dss_device
*dssdev
= &ddata
->dssdev
;
1283 struct backlight_device
*bldev
;
1285 dev_dbg(&pdev
->dev
, "remove\n");
1287 omapdss_unregister_display(dssdev
);
1289 dsicm_disable(dssdev
);
1290 dsicm_disconnect(dssdev
);
1292 sysfs_remove_group(&pdev
->dev
.kobj
, &dsicm_attr_group
);
1294 bldev
= ddata
->bldev
;
1295 if (bldev
!= NULL
) {
1296 bldev
->props
.power
= FB_BLANK_POWERDOWN
;
1297 dsicm_bl_update_status(bldev
);
1298 backlight_device_unregister(bldev
);
1301 omap_dss_put_device(ddata
->in
);
1303 dsicm_cancel_ulps_work(ddata
);
1305 /* reset, to be sure that the panel is in a valid state */
1306 dsicm_hw_reset(ddata
);
1311 static const struct of_device_id dsicm_of_match
[] = {
1312 { .compatible
= "omapdss,panel-dsi-cm", },
1316 MODULE_DEVICE_TABLE(of
, dsicm_of_match
);
1318 static struct platform_driver dsicm_driver
= {
1319 .probe
= dsicm_probe
,
1320 .remove
= __exit_p(dsicm_remove
),
1322 .name
= "panel-dsi-cm",
1323 .of_match_table
= dsicm_of_match
,
1324 .suppress_bind_attrs
= true,
1328 module_platform_driver(dsicm_driver
);
1330 MODULE_AUTHOR("Tomi Valkeinen <tomi.valkeinen@ti.com>");
1331 MODULE_DESCRIPTION("Generic DSI Command Mode Panel Driver");
1332 MODULE_LICENSE("GPL");