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>
16 #include <linux/gpio/consumer.h>
17 #include <linux/interrupt.h>
18 #include <linux/jiffies.h>
19 #include <linux/module.h>
20 #include <linux/platform_device.h>
21 #include <linux/sched.h>
22 #include <linux/slab.h>
23 #include <linux/workqueue.h>
24 #include <linux/of_device.h>
25 #include <linux/of_gpio.h>
27 #include <video/mipi_display.h>
29 #include "../dss/omapdss.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;
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;
78 struct workqueue_struct *workqueue;
81 unsigned ulps_timeout;
82 struct delayed_work ulps_work;
85 #define to_panel_data(p) container_of(p, struct panel_drv_data, dssdev)
87 static irqreturn_t dsicm_te_isr(int irq, void *data);
88 static void dsicm_te_timeout_work_callback(struct work_struct *work);
89 static int _dsicm_enable_te(struct panel_drv_data *ddata, bool enable);
91 static int dsicm_panel_reset(struct panel_drv_data *ddata);
93 static void dsicm_ulps_work(struct work_struct *work);
95 static void hw_guard_start(struct panel_drv_data *ddata, int guard_msec)
97 ddata->hw_guard_wait = msecs_to_jiffies(guard_msec);
98 ddata->hw_guard_end = jiffies + ddata->hw_guard_wait;
101 static void hw_guard_wait(struct panel_drv_data *ddata)
103 unsigned long wait = ddata->hw_guard_end - jiffies;
105 if ((long)wait > 0 && wait <= ddata->hw_guard_wait) {
106 set_current_state(TASK_UNINTERRUPTIBLE);
107 schedule_timeout(wait);
111 static int dsicm_dcs_read_1(struct panel_drv_data *ddata, u8 dcs_cmd, u8 *data)
113 struct omap_dss_device *in = ddata->in;
117 r = in->ops.dsi->dcs_read(in, ddata->channel, dcs_cmd, buf, 1);
127 static int dsicm_dcs_write_0(struct panel_drv_data *ddata, u8 dcs_cmd)
129 struct omap_dss_device *in = ddata->in;
130 return in->ops.dsi->dcs_write(in, ddata->channel, &dcs_cmd, 1);
133 static int dsicm_dcs_write_1(struct panel_drv_data *ddata, u8 dcs_cmd, u8 param)
135 struct omap_dss_device *in = ddata->in;
136 u8 buf[2] = { dcs_cmd, param };
138 return in->ops.dsi->dcs_write(in, ddata->channel, buf, 2);
141 static int dsicm_sleep_in(struct panel_drv_data *ddata)
144 struct omap_dss_device *in = ddata->in;
148 hw_guard_wait(ddata);
150 cmd = MIPI_DCS_ENTER_SLEEP_MODE;
151 r = in->ops.dsi->dcs_write_nosync(in, ddata->channel, &cmd, 1);
155 hw_guard_start(ddata, 120);
157 usleep_range(5000, 10000);
162 static int dsicm_sleep_out(struct panel_drv_data *ddata)
166 hw_guard_wait(ddata);
168 r = dsicm_dcs_write_0(ddata, MIPI_DCS_EXIT_SLEEP_MODE);
172 hw_guard_start(ddata, 120);
174 usleep_range(5000, 10000);
179 static int dsicm_get_id(struct panel_drv_data *ddata, u8 *id1, u8 *id2, u8 *id3)
183 r = dsicm_dcs_read_1(ddata, DCS_GET_ID1, id1);
186 r = dsicm_dcs_read_1(ddata, DCS_GET_ID2, id2);
189 r = dsicm_dcs_read_1(ddata, DCS_GET_ID3, id3);
196 static int dsicm_set_update_window(struct panel_drv_data *ddata,
197 u16 x, u16 y, u16 w, u16 h)
199 struct omap_dss_device *in = ddata->in;
207 buf[0] = MIPI_DCS_SET_COLUMN_ADDRESS;
208 buf[1] = (x1 >> 8) & 0xff;
209 buf[2] = (x1 >> 0) & 0xff;
210 buf[3] = (x2 >> 8) & 0xff;
211 buf[4] = (x2 >> 0) & 0xff;
213 r = in->ops.dsi->dcs_write_nosync(in, ddata->channel, buf, sizeof(buf));
217 buf[0] = MIPI_DCS_SET_PAGE_ADDRESS;
218 buf[1] = (y1 >> 8) & 0xff;
219 buf[2] = (y1 >> 0) & 0xff;
220 buf[3] = (y2 >> 8) & 0xff;
221 buf[4] = (y2 >> 0) & 0xff;
223 r = in->ops.dsi->dcs_write_nosync(in, ddata->channel, buf, sizeof(buf));
227 in->ops.dsi->bta_sync(in, ddata->channel);
232 static void dsicm_queue_ulps_work(struct panel_drv_data *ddata)
234 if (ddata->ulps_timeout > 0)
235 queue_delayed_work(ddata->workqueue, &ddata->ulps_work,
236 msecs_to_jiffies(ddata->ulps_timeout));
239 static void dsicm_cancel_ulps_work(struct panel_drv_data *ddata)
241 cancel_delayed_work(&ddata->ulps_work);
244 static int dsicm_enter_ulps(struct panel_drv_data *ddata)
246 struct omap_dss_device *in = ddata->in;
249 if (ddata->ulps_enabled)
252 dsicm_cancel_ulps_work(ddata);
254 r = _dsicm_enable_te(ddata, false);
258 if (gpio_is_valid(ddata->ext_te_gpio))
259 disable_irq(gpio_to_irq(ddata->ext_te_gpio));
261 in->ops.dsi->disable(in, false, true);
263 ddata->ulps_enabled = true;
268 dev_err(&ddata->pdev->dev, "enter ULPS failed");
269 dsicm_panel_reset(ddata);
271 ddata->ulps_enabled = false;
273 dsicm_queue_ulps_work(ddata);
278 static int dsicm_exit_ulps(struct panel_drv_data *ddata)
280 struct omap_dss_device *in = ddata->in;
283 if (!ddata->ulps_enabled)
286 r = in->ops.dsi->enable(in);
288 dev_err(&ddata->pdev->dev, "failed to enable DSI\n");
292 in->ops.dsi->enable_hs(in, ddata->channel, true);
294 r = _dsicm_enable_te(ddata, true);
296 dev_err(&ddata->pdev->dev, "failed to re-enable TE");
300 if (gpio_is_valid(ddata->ext_te_gpio))
301 enable_irq(gpio_to_irq(ddata->ext_te_gpio));
303 dsicm_queue_ulps_work(ddata);
305 ddata->ulps_enabled = false;
310 dev_err(&ddata->pdev->dev, "failed to exit ULPS");
312 r = dsicm_panel_reset(ddata);
314 if (gpio_is_valid(ddata->ext_te_gpio))
315 enable_irq(gpio_to_irq(ddata->ext_te_gpio));
316 ddata->ulps_enabled = false;
319 dsicm_queue_ulps_work(ddata);
324 static int dsicm_wake_up(struct panel_drv_data *ddata)
326 if (ddata->ulps_enabled)
327 return dsicm_exit_ulps(ddata);
329 dsicm_cancel_ulps_work(ddata);
330 dsicm_queue_ulps_work(ddata);
334 static int dsicm_bl_update_status(struct backlight_device *dev)
336 struct panel_drv_data *ddata = dev_get_drvdata(&dev->dev);
337 struct omap_dss_device *in = ddata->in;
341 if (dev->props.fb_blank == FB_BLANK_UNBLANK &&
342 dev->props.power == FB_BLANK_UNBLANK)
343 level = dev->props.brightness;
347 dev_dbg(&ddata->pdev->dev, "update brightness to %d\n", level);
349 mutex_lock(&ddata->lock);
351 if (ddata->enabled) {
352 in->ops.dsi->bus_lock(in);
354 r = dsicm_wake_up(ddata);
356 r = dsicm_dcs_write_1(ddata, DCS_BRIGHTNESS, level);
358 in->ops.dsi->bus_unlock(in);
363 mutex_unlock(&ddata->lock);
368 static int dsicm_bl_get_intensity(struct backlight_device *dev)
370 if (dev->props.fb_blank == FB_BLANK_UNBLANK &&
371 dev->props.power == FB_BLANK_UNBLANK)
372 return dev->props.brightness;
377 static const struct backlight_ops dsicm_bl_ops = {
378 .get_brightness = dsicm_bl_get_intensity,
379 .update_status = dsicm_bl_update_status,
382 static void dsicm_get_resolution(struct omap_dss_device *dssdev,
383 u16 *xres, u16 *yres)
385 *xres = dssdev->panel.vm.hactive;
386 *yres = dssdev->panel.vm.vactive;
389 static ssize_t dsicm_num_errors_show(struct device *dev,
390 struct device_attribute *attr, char *buf)
392 struct platform_device *pdev = to_platform_device(dev);
393 struct panel_drv_data *ddata = platform_get_drvdata(pdev);
394 struct omap_dss_device *in = ddata->in;
398 mutex_lock(&ddata->lock);
400 if (ddata->enabled) {
401 in->ops.dsi->bus_lock(in);
403 r = dsicm_wake_up(ddata);
405 r = dsicm_dcs_read_1(ddata, DCS_READ_NUM_ERRORS,
408 in->ops.dsi->bus_unlock(in);
413 mutex_unlock(&ddata->lock);
418 return snprintf(buf, PAGE_SIZE, "%d\n", errors);
421 static ssize_t dsicm_hw_revision_show(struct device *dev,
422 struct device_attribute *attr, char *buf)
424 struct platform_device *pdev = to_platform_device(dev);
425 struct panel_drv_data *ddata = platform_get_drvdata(pdev);
426 struct omap_dss_device *in = ddata->in;
430 mutex_lock(&ddata->lock);
432 if (ddata->enabled) {
433 in->ops.dsi->bus_lock(in);
435 r = dsicm_wake_up(ddata);
437 r = dsicm_get_id(ddata, &id1, &id2, &id3);
439 in->ops.dsi->bus_unlock(in);
444 mutex_unlock(&ddata->lock);
449 return snprintf(buf, PAGE_SIZE, "%02x.%02x.%02x\n", id1, id2, id3);
452 static ssize_t dsicm_store_ulps(struct device *dev,
453 struct device_attribute *attr,
454 const char *buf, size_t count)
456 struct platform_device *pdev = to_platform_device(dev);
457 struct panel_drv_data *ddata = platform_get_drvdata(pdev);
458 struct omap_dss_device *in = ddata->in;
462 r = kstrtoul(buf, 0, &t);
466 mutex_lock(&ddata->lock);
468 if (ddata->enabled) {
469 in->ops.dsi->bus_lock(in);
472 r = dsicm_enter_ulps(ddata);
474 r = dsicm_wake_up(ddata);
476 in->ops.dsi->bus_unlock(in);
479 mutex_unlock(&ddata->lock);
487 static ssize_t dsicm_show_ulps(struct device *dev,
488 struct device_attribute *attr,
491 struct platform_device *pdev = to_platform_device(dev);
492 struct panel_drv_data *ddata = platform_get_drvdata(pdev);
495 mutex_lock(&ddata->lock);
496 t = ddata->ulps_enabled;
497 mutex_unlock(&ddata->lock);
499 return snprintf(buf, PAGE_SIZE, "%u\n", t);
502 static ssize_t dsicm_store_ulps_timeout(struct device *dev,
503 struct device_attribute *attr,
504 const char *buf, size_t count)
506 struct platform_device *pdev = to_platform_device(dev);
507 struct panel_drv_data *ddata = platform_get_drvdata(pdev);
508 struct omap_dss_device *in = ddata->in;
512 r = kstrtoul(buf, 0, &t);
516 mutex_lock(&ddata->lock);
517 ddata->ulps_timeout = t;
519 if (ddata->enabled) {
520 /* dsicm_wake_up will restart the timer */
521 in->ops.dsi->bus_lock(in);
522 r = dsicm_wake_up(ddata);
523 in->ops.dsi->bus_unlock(in);
526 mutex_unlock(&ddata->lock);
534 static ssize_t dsicm_show_ulps_timeout(struct device *dev,
535 struct device_attribute *attr,
538 struct platform_device *pdev = to_platform_device(dev);
539 struct panel_drv_data *ddata = platform_get_drvdata(pdev);
542 mutex_lock(&ddata->lock);
543 t = ddata->ulps_timeout;
544 mutex_unlock(&ddata->lock);
546 return snprintf(buf, PAGE_SIZE, "%u\n", t);
549 static DEVICE_ATTR(num_dsi_errors, S_IRUGO, dsicm_num_errors_show, NULL);
550 static DEVICE_ATTR(hw_revision, S_IRUGO, dsicm_hw_revision_show, NULL);
551 static DEVICE_ATTR(ulps, S_IRUGO | S_IWUSR,
552 dsicm_show_ulps, dsicm_store_ulps);
553 static DEVICE_ATTR(ulps_timeout, S_IRUGO | S_IWUSR,
554 dsicm_show_ulps_timeout, dsicm_store_ulps_timeout);
556 static struct attribute *dsicm_attrs[] = {
557 &dev_attr_num_dsi_errors.attr,
558 &dev_attr_hw_revision.attr,
560 &dev_attr_ulps_timeout.attr,
564 static struct attribute_group dsicm_attr_group = {
565 .attrs = dsicm_attrs,
568 static void dsicm_hw_reset(struct panel_drv_data *ddata)
570 if (!gpio_is_valid(ddata->reset_gpio))
573 gpio_set_value(ddata->reset_gpio, 1);
575 /* reset the panel */
576 gpio_set_value(ddata->reset_gpio, 0);
579 gpio_set_value(ddata->reset_gpio, 1);
580 /* wait after releasing reset */
581 usleep_range(5000, 10000);
584 static int dsicm_power_on(struct panel_drv_data *ddata)
586 struct omap_dss_device *in = ddata->in;
589 struct omap_dss_dsi_config dsi_config = {
590 .mode = OMAP_DSS_DSI_CMD_MODE,
591 .pixel_format = OMAP_DSS_DSI_FMT_RGB888,
593 .hs_clk_min = 150000000,
594 .hs_clk_max = 300000000,
595 .lp_clk_min = 7000000,
596 .lp_clk_max = 10000000,
599 if (ddata->pin_config.num_pins > 0) {
600 r = in->ops.dsi->configure_pins(in, &ddata->pin_config);
602 dev_err(&ddata->pdev->dev,
603 "failed to configure DSI pins\n");
608 r = in->ops.dsi->set_config(in, &dsi_config);
610 dev_err(&ddata->pdev->dev, "failed to configure DSI\n");
614 r = in->ops.dsi->enable(in);
616 dev_err(&ddata->pdev->dev, "failed to enable DSI\n");
620 dsicm_hw_reset(ddata);
622 in->ops.dsi->enable_hs(in, ddata->channel, false);
624 r = dsicm_sleep_out(ddata);
628 r = dsicm_get_id(ddata, &id1, &id2, &id3);
632 r = dsicm_dcs_write_1(ddata, DCS_BRIGHTNESS, 0xff);
636 r = dsicm_dcs_write_1(ddata, DCS_CTRL_DISPLAY,
637 (1<<2) | (1<<5)); /* BL | BCTRL */
641 r = dsicm_dcs_write_1(ddata, MIPI_DCS_SET_PIXEL_FORMAT,
642 MIPI_DCS_PIXEL_FMT_24BIT);
646 r = dsicm_dcs_write_0(ddata, MIPI_DCS_SET_DISPLAY_ON);
650 r = _dsicm_enable_te(ddata, ddata->te_enabled);
654 r = in->ops.dsi->enable_video_output(in, ddata->channel);
660 if (!ddata->intro_printed) {
661 dev_info(&ddata->pdev->dev, "panel revision %02x.%02x.%02x\n",
663 ddata->intro_printed = true;
666 in->ops.dsi->enable_hs(in, ddata->channel, true);
670 dev_err(&ddata->pdev->dev, "error while enabling panel, issuing HW reset\n");
672 dsicm_hw_reset(ddata);
674 in->ops.dsi->disable(in, true, false);
679 static void dsicm_power_off(struct panel_drv_data *ddata)
681 struct omap_dss_device *in = ddata->in;
684 in->ops.dsi->disable_video_output(in, ddata->channel);
686 r = dsicm_dcs_write_0(ddata, MIPI_DCS_SET_DISPLAY_OFF);
688 r = dsicm_sleep_in(ddata);
691 dev_err(&ddata->pdev->dev,
692 "error disabling panel, issuing HW reset\n");
693 dsicm_hw_reset(ddata);
696 in->ops.dsi->disable(in, true, false);
701 static int dsicm_panel_reset(struct panel_drv_data *ddata)
703 dev_err(&ddata->pdev->dev, "performing LCD reset\n");
705 dsicm_power_off(ddata);
706 dsicm_hw_reset(ddata);
707 return dsicm_power_on(ddata);
710 static int dsicm_connect(struct omap_dss_device *dssdev)
712 struct panel_drv_data *ddata = to_panel_data(dssdev);
713 struct omap_dss_device *in = ddata->in;
714 struct device *dev = &ddata->pdev->dev;
717 if (omapdss_device_is_connected(dssdev))
720 r = in->ops.dsi->connect(in, dssdev);
722 dev_err(dev, "Failed to connect to video source\n");
726 r = in->ops.dsi->request_vc(ddata->in, &ddata->channel);
728 dev_err(dev, "failed to get virtual channel\n");
732 r = in->ops.dsi->set_vc_id(ddata->in, ddata->channel, TCH);
734 dev_err(dev, "failed to set VC_ID\n");
741 in->ops.dsi->release_vc(ddata->in, ddata->channel);
743 in->ops.dsi->disconnect(in, dssdev);
747 static void dsicm_disconnect(struct omap_dss_device *dssdev)
749 struct panel_drv_data *ddata = to_panel_data(dssdev);
750 struct omap_dss_device *in = ddata->in;
752 if (!omapdss_device_is_connected(dssdev))
755 in->ops.dsi->release_vc(in, ddata->channel);
756 in->ops.dsi->disconnect(in, dssdev);
759 static int dsicm_enable(struct omap_dss_device *dssdev)
761 struct panel_drv_data *ddata = to_panel_data(dssdev);
762 struct omap_dss_device *in = ddata->in;
765 dev_dbg(&ddata->pdev->dev, "enable\n");
767 mutex_lock(&ddata->lock);
769 if (!omapdss_device_is_connected(dssdev)) {
774 if (omapdss_device_is_enabled(dssdev)) {
779 in->ops.dsi->bus_lock(in);
781 r = dsicm_power_on(ddata);
783 in->ops.dsi->bus_unlock(in);
788 dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
790 mutex_unlock(&ddata->lock);
794 dev_dbg(&ddata->pdev->dev, "enable failed\n");
795 mutex_unlock(&ddata->lock);
799 static void dsicm_disable(struct omap_dss_device *dssdev)
801 struct panel_drv_data *ddata = to_panel_data(dssdev);
802 struct omap_dss_device *in = ddata->in;
805 dev_dbg(&ddata->pdev->dev, "disable\n");
807 mutex_lock(&ddata->lock);
809 dsicm_cancel_ulps_work(ddata);
811 in->ops.dsi->bus_lock(in);
813 if (omapdss_device_is_enabled(dssdev)) {
814 r = dsicm_wake_up(ddata);
816 dsicm_power_off(ddata);
819 in->ops.dsi->bus_unlock(in);
821 dssdev->state = OMAP_DSS_DISPLAY_DISABLED;
823 mutex_unlock(&ddata->lock);
826 static void dsicm_framedone_cb(int err, void *data)
828 struct panel_drv_data *ddata = data;
829 struct omap_dss_device *in = ddata->in;
831 dev_dbg(&ddata->pdev->dev, "framedone, err %d\n", err);
832 in->ops.dsi->bus_unlock(ddata->in);
835 static irqreturn_t dsicm_te_isr(int irq, void *data)
837 struct panel_drv_data *ddata = data;
838 struct omap_dss_device *in = ddata->in;
842 old = atomic_cmpxchg(&ddata->do_update, 1, 0);
845 cancel_delayed_work(&ddata->te_timeout_work);
847 r = in->ops.dsi->update(in, ddata->channel, dsicm_framedone_cb,
855 dev_err(&ddata->pdev->dev, "start update failed\n");
856 in->ops.dsi->bus_unlock(in);
860 static void dsicm_te_timeout_work_callback(struct work_struct *work)
862 struct panel_drv_data *ddata = container_of(work, struct panel_drv_data,
863 te_timeout_work.work);
864 struct omap_dss_device *in = ddata->in;
866 dev_err(&ddata->pdev->dev, "TE not received for 250ms!\n");
868 atomic_set(&ddata->do_update, 0);
869 in->ops.dsi->bus_unlock(in);
872 static int dsicm_update(struct omap_dss_device *dssdev,
873 u16 x, u16 y, u16 w, u16 h)
875 struct panel_drv_data *ddata = to_panel_data(dssdev);
876 struct omap_dss_device *in = ddata->in;
879 dev_dbg(&ddata->pdev->dev, "update %d, %d, %d x %d\n", x, y, w, h);
881 mutex_lock(&ddata->lock);
882 in->ops.dsi->bus_lock(in);
884 r = dsicm_wake_up(ddata);
888 if (!ddata->enabled) {
893 /* XXX no need to send this every frame, but dsi break if not done */
894 r = dsicm_set_update_window(ddata, 0, 0,
895 dssdev->panel.vm.hactive,
896 dssdev->panel.vm.vactive);
900 if (ddata->te_enabled && gpio_is_valid(ddata->ext_te_gpio)) {
901 schedule_delayed_work(&ddata->te_timeout_work,
902 msecs_to_jiffies(250));
903 atomic_set(&ddata->do_update, 1);
905 r = in->ops.dsi->update(in, ddata->channel, dsicm_framedone_cb,
911 /* note: no bus_unlock here. unlock is in framedone_cb */
912 mutex_unlock(&ddata->lock);
915 in->ops.dsi->bus_unlock(in);
916 mutex_unlock(&ddata->lock);
920 static int dsicm_sync(struct omap_dss_device *dssdev)
922 struct panel_drv_data *ddata = to_panel_data(dssdev);
923 struct omap_dss_device *in = ddata->in;
925 dev_dbg(&ddata->pdev->dev, "sync\n");
927 mutex_lock(&ddata->lock);
928 in->ops.dsi->bus_lock(in);
929 in->ops.dsi->bus_unlock(in);
930 mutex_unlock(&ddata->lock);
932 dev_dbg(&ddata->pdev->dev, "sync done\n");
937 static int _dsicm_enable_te(struct panel_drv_data *ddata, bool enable)
939 struct omap_dss_device *in = ddata->in;
943 r = dsicm_dcs_write_1(ddata, MIPI_DCS_SET_TEAR_ON, 0);
945 r = dsicm_dcs_write_0(ddata, MIPI_DCS_SET_TEAR_OFF);
947 if (!gpio_is_valid(ddata->ext_te_gpio))
948 in->ops.dsi->enable_te(in, enable);
950 /* possible panel bug */
956 static int dsicm_enable_te(struct omap_dss_device *dssdev, bool enable)
958 struct panel_drv_data *ddata = to_panel_data(dssdev);
959 struct omap_dss_device *in = ddata->in;
962 mutex_lock(&ddata->lock);
964 if (ddata->te_enabled == enable)
967 in->ops.dsi->bus_lock(in);
969 if (ddata->enabled) {
970 r = dsicm_wake_up(ddata);
974 r = _dsicm_enable_te(ddata, enable);
979 ddata->te_enabled = enable;
981 in->ops.dsi->bus_unlock(in);
983 mutex_unlock(&ddata->lock);
987 in->ops.dsi->bus_unlock(in);
988 mutex_unlock(&ddata->lock);
993 static int dsicm_get_te(struct omap_dss_device *dssdev)
995 struct panel_drv_data *ddata = to_panel_data(dssdev);
998 mutex_lock(&ddata->lock);
999 r = ddata->te_enabled;
1000 mutex_unlock(&ddata->lock);
1005 static int dsicm_memory_read(struct omap_dss_device *dssdev,
1006 void *buf, size_t size,
1007 u16 x, u16 y, u16 w, u16 h)
1009 struct panel_drv_data *ddata = to_panel_data(dssdev);
1010 struct omap_dss_device *in = ddata->in;
1014 unsigned buf_used = 0;
1016 if (size < w * h * 3)
1019 mutex_lock(&ddata->lock);
1021 if (!ddata->enabled) {
1026 size = min((u32)w * h * 3,
1027 dssdev->panel.vm.hactive * dssdev->panel.vm.vactive * 3);
1029 in->ops.dsi->bus_lock(in);
1031 r = dsicm_wake_up(ddata);
1035 /* plen 1 or 2 goes into short packet. until checksum error is fixed,
1036 * use short packets. plen 32 works, but bigger packets seem to cause
1043 dsicm_set_update_window(ddata, x, y, w, h);
1045 r = in->ops.dsi->set_max_rx_packet_size(in, ddata->channel, plen);
1049 while (buf_used < size) {
1050 u8 dcs_cmd = first ? 0x2e : 0x3e;
1053 r = in->ops.dsi->dcs_read(in, ddata->channel, dcs_cmd,
1054 buf + buf_used, size - buf_used);
1057 dev_err(dssdev->dev, "read error\n");
1064 dev_err(&ddata->pdev->dev, "short read\n");
1068 if (signal_pending(current)) {
1069 dev_err(&ddata->pdev->dev, "signal pending, "
1070 "aborting memory read\n");
1079 in->ops.dsi->set_max_rx_packet_size(in, ddata->channel, 1);
1081 in->ops.dsi->bus_unlock(in);
1083 mutex_unlock(&ddata->lock);
1087 static void dsicm_ulps_work(struct work_struct *work)
1089 struct panel_drv_data *ddata = container_of(work, struct panel_drv_data,
1091 struct omap_dss_device *dssdev = &ddata->dssdev;
1092 struct omap_dss_device *in = ddata->in;
1094 mutex_lock(&ddata->lock);
1096 if (dssdev->state != OMAP_DSS_DISPLAY_ACTIVE || !ddata->enabled) {
1097 mutex_unlock(&ddata->lock);
1101 in->ops.dsi->bus_lock(in);
1103 dsicm_enter_ulps(ddata);
1105 in->ops.dsi->bus_unlock(in);
1106 mutex_unlock(&ddata->lock);
1109 static struct omap_dss_driver dsicm_ops = {
1110 .connect = dsicm_connect,
1111 .disconnect = dsicm_disconnect,
1113 .enable = dsicm_enable,
1114 .disable = dsicm_disable,
1116 .update = dsicm_update,
1119 .get_resolution = dsicm_get_resolution,
1120 .get_recommended_bpp = omapdss_default_get_recommended_bpp,
1122 .enable_te = dsicm_enable_te,
1123 .get_te = dsicm_get_te,
1125 .memory_read = dsicm_memory_read,
1128 static int dsicm_probe_of(struct platform_device *pdev)
1130 struct device_node *node = pdev->dev.of_node;
1131 struct panel_drv_data *ddata = platform_get_drvdata(pdev);
1132 struct omap_dss_device *in;
1135 gpio = of_get_named_gpio(node, "reset-gpios", 0);
1136 if (!gpio_is_valid(gpio)) {
1137 dev_err(&pdev->dev, "failed to parse reset gpio\n");
1140 ddata->reset_gpio = gpio;
1142 gpio = of_get_named_gpio(node, "te-gpios", 0);
1143 if (gpio_is_valid(gpio) || gpio == -ENOENT) {
1144 ddata->ext_te_gpio = gpio;
1146 dev_err(&pdev->dev, "failed to parse TE gpio\n");
1150 in = omapdss_of_find_source_for_first_ep(node);
1152 dev_err(&pdev->dev, "failed to find video source\n");
1158 /* TODO: ulps, backlight */
1163 static int dsicm_probe(struct platform_device *pdev)
1165 struct backlight_properties props;
1166 struct panel_drv_data *ddata;
1167 struct backlight_device *bldev = NULL;
1168 struct device *dev = &pdev->dev;
1169 struct omap_dss_device *dssdev;
1172 dev_dbg(dev, "probe\n");
1174 ddata = devm_kzalloc(dev, sizeof(*ddata), GFP_KERNEL);
1178 platform_set_drvdata(pdev, ddata);
1181 if (!pdev->dev.of_node)
1184 r = dsicm_probe_of(pdev);
1188 ddata->vm.hactive = 864;
1189 ddata->vm.vactive = 480;
1190 ddata->vm.pixelclock = 864 * 480 * 60;
1192 dssdev = &ddata->dssdev;
1194 dssdev->driver = &dsicm_ops;
1195 dssdev->panel.vm = ddata->vm;
1196 dssdev->type = OMAP_DISPLAY_TYPE_DSI;
1197 dssdev->owner = THIS_MODULE;
1199 dssdev->panel.dsi_pix_fmt = OMAP_DSS_DSI_FMT_RGB888;
1200 dssdev->caps = OMAP_DSS_DISPLAY_CAP_MANUAL_UPDATE |
1201 OMAP_DSS_DISPLAY_CAP_TEAR_ELIM;
1203 r = omapdss_register_display(dssdev);
1205 dev_err(dev, "Failed to register panel\n");
1209 mutex_init(&ddata->lock);
1211 atomic_set(&ddata->do_update, 0);
1213 if (gpio_is_valid(ddata->reset_gpio)) {
1214 r = devm_gpio_request_one(dev, ddata->reset_gpio,
1215 GPIOF_OUT_INIT_LOW, "taal rst");
1217 dev_err(dev, "failed to request reset gpio\n");
1222 if (gpio_is_valid(ddata->ext_te_gpio)) {
1223 r = devm_gpio_request_one(dev, ddata->ext_te_gpio,
1224 GPIOF_IN, "taal irq");
1226 dev_err(dev, "GPIO request failed\n");
1230 r = devm_request_irq(dev, gpio_to_irq(ddata->ext_te_gpio),
1232 IRQF_TRIGGER_RISING,
1233 "taal vsync", ddata);
1236 dev_err(dev, "IRQ request failed\n");
1240 INIT_DEFERRABLE_WORK(&ddata->te_timeout_work,
1241 dsicm_te_timeout_work_callback);
1243 dev_dbg(dev, "Using GPIO TE\n");
1246 ddata->workqueue = create_singlethread_workqueue("dsicm_wq");
1247 if (ddata->workqueue == NULL) {
1248 dev_err(dev, "can't create workqueue\n");
1251 INIT_DELAYED_WORK(&ddata->ulps_work, dsicm_ulps_work);
1253 dsicm_hw_reset(ddata);
1255 if (ddata->use_dsi_backlight) {
1256 memset(&props, 0, sizeof(props));
1257 props.max_brightness = 255;
1259 props.type = BACKLIGHT_RAW;
1260 bldev = backlight_device_register(dev_name(dev),
1261 dev, ddata, &dsicm_bl_ops, &props);
1262 if (IS_ERR(bldev)) {
1267 ddata->bldev = bldev;
1269 bldev->props.fb_blank = FB_BLANK_UNBLANK;
1270 bldev->props.power = FB_BLANK_UNBLANK;
1271 bldev->props.brightness = 255;
1273 dsicm_bl_update_status(bldev);
1276 r = sysfs_create_group(&dev->kobj, &dsicm_attr_group);
1278 dev_err(dev, "failed to create sysfs files\n");
1279 goto err_sysfs_create;
1285 backlight_device_unregister(bldev);
1287 destroy_workqueue(ddata->workqueue);
1292 static int __exit dsicm_remove(struct platform_device *pdev)
1294 struct panel_drv_data *ddata = platform_get_drvdata(pdev);
1295 struct omap_dss_device *dssdev = &ddata->dssdev;
1296 struct backlight_device *bldev;
1298 dev_dbg(&pdev->dev, "remove\n");
1300 omapdss_unregister_display(dssdev);
1302 dsicm_disable(dssdev);
1303 dsicm_disconnect(dssdev);
1305 sysfs_remove_group(&pdev->dev.kobj, &dsicm_attr_group);
1307 bldev = ddata->bldev;
1308 if (bldev != NULL) {
1309 bldev->props.power = FB_BLANK_POWERDOWN;
1310 dsicm_bl_update_status(bldev);
1311 backlight_device_unregister(bldev);
1314 omap_dss_put_device(ddata->in);
1316 dsicm_cancel_ulps_work(ddata);
1317 destroy_workqueue(ddata->workqueue);
1319 /* reset, to be sure that the panel is in a valid state */
1320 dsicm_hw_reset(ddata);
1325 static const struct of_device_id dsicm_of_match[] = {
1326 { .compatible = "omapdss,panel-dsi-cm", },
1330 MODULE_DEVICE_TABLE(of, dsicm_of_match);
1332 static struct platform_driver dsicm_driver = {
1333 .probe = dsicm_probe,
1334 .remove = __exit_p(dsicm_remove),
1336 .name = "panel-dsi-cm",
1337 .of_match_table = dsicm_of_match,
1338 .suppress_bind_attrs = true,
1342 module_platform_driver(dsicm_driver);
1344 MODULE_AUTHOR("Tomi Valkeinen <tomi.valkeinen@ti.com>");
1345 MODULE_DESCRIPTION("Generic DSI Command Mode Panel Driver");
1346 MODULE_LICENSE("GPL");