panel-taal.c 20 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003
  1. /*
  2. * Taal DSI command mode panel
  3. *
  4. * Copyright (C) 2009 Nokia Corporation
  5. * Author: Tomi Valkeinen <tomi.valkeinen@nokia.com>
  6. *
  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.
  10. *
  11. * This program is distributed in the hope that it will be useful, but WITHOUT
  12. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  14. * more details.
  15. *
  16. * You should have received a copy of the GNU General Public License along with
  17. * this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. /*#define DEBUG*/
  20. #include <linux/module.h>
  21. #include <linux/delay.h>
  22. #include <linux/err.h>
  23. #include <linux/jiffies.h>
  24. #include <linux/sched.h>
  25. #include <linux/backlight.h>
  26. #include <linux/fb.h>
  27. #include <linux/interrupt.h>
  28. #include <linux/gpio.h>
  29. #include <linux/completion.h>
  30. #include <linux/workqueue.h>
  31. #include <plat/display.h>
  32. /* DSI Virtual channel. Hardcoded for now. */
  33. #define TCH 0
  34. #define DCS_READ_NUM_ERRORS 0x05
  35. #define DCS_READ_POWER_MODE 0x0a
  36. #define DCS_READ_MADCTL 0x0b
  37. #define DCS_READ_PIXEL_FORMAT 0x0c
  38. #define DCS_RDDSDR 0x0f
  39. #define DCS_SLEEP_IN 0x10
  40. #define DCS_SLEEP_OUT 0x11
  41. #define DCS_DISPLAY_OFF 0x28
  42. #define DCS_DISPLAY_ON 0x29
  43. #define DCS_COLUMN_ADDR 0x2a
  44. #define DCS_PAGE_ADDR 0x2b
  45. #define DCS_MEMORY_WRITE 0x2c
  46. #define DCS_TEAR_OFF 0x34
  47. #define DCS_TEAR_ON 0x35
  48. #define DCS_MEM_ACC_CTRL 0x36
  49. #define DCS_PIXEL_FORMAT 0x3a
  50. #define DCS_BRIGHTNESS 0x51
  51. #define DCS_CTRL_DISPLAY 0x53
  52. #define DCS_WRITE_CABC 0x55
  53. #define DCS_READ_CABC 0x56
  54. #define DCS_GET_ID1 0xda
  55. #define DCS_GET_ID2 0xdb
  56. #define DCS_GET_ID3 0xdc
  57. /* #define TAAL_USE_ESD_CHECK */
  58. #define TAAL_ESD_CHECK_PERIOD msecs_to_jiffies(5000)
  59. struct taal_data {
  60. struct backlight_device *bldev;
  61. unsigned long hw_guard_end; /* next value of jiffies when we can
  62. * issue the next sleep in/out command
  63. */
  64. unsigned long hw_guard_wait; /* max guard time in jiffies */
  65. struct omap_dss_device *dssdev;
  66. bool enabled;
  67. u8 rotate;
  68. bool mirror;
  69. bool te_enabled;
  70. bool use_ext_te;
  71. struct completion te_completion;
  72. bool use_dsi_bl;
  73. bool cabc_broken;
  74. unsigned cabc_mode;
  75. bool intro_printed;
  76. struct workqueue_struct *esd_wq;
  77. struct delayed_work esd_work;
  78. };
  79. static void taal_esd_work(struct work_struct *work);
  80. static void hw_guard_start(struct taal_data *td, int guard_msec)
  81. {
  82. td->hw_guard_wait = msecs_to_jiffies(guard_msec);
  83. td->hw_guard_end = jiffies + td->hw_guard_wait;
  84. }
  85. static void hw_guard_wait(struct taal_data *td)
  86. {
  87. unsigned long wait = td->hw_guard_end - jiffies;
  88. if ((long)wait > 0 && wait <= td->hw_guard_wait) {
  89. set_current_state(TASK_UNINTERRUPTIBLE);
  90. schedule_timeout(wait);
  91. }
  92. }
  93. static int taal_dcs_read_1(u8 dcs_cmd, u8 *data)
  94. {
  95. int r;
  96. u8 buf[1];
  97. r = dsi_vc_dcs_read(TCH, dcs_cmd, buf, 1);
  98. if (r < 0)
  99. return r;
  100. *data = buf[0];
  101. return 0;
  102. }
  103. static int taal_dcs_write_0(u8 dcs_cmd)
  104. {
  105. return dsi_vc_dcs_write(TCH, &dcs_cmd, 1);
  106. }
  107. static int taal_dcs_write_1(u8 dcs_cmd, u8 param)
  108. {
  109. u8 buf[2];
  110. buf[0] = dcs_cmd;
  111. buf[1] = param;
  112. return dsi_vc_dcs_write(TCH, buf, 2);
  113. }
  114. static int taal_sleep_in(struct taal_data *td)
  115. {
  116. u8 cmd;
  117. int r;
  118. hw_guard_wait(td);
  119. cmd = DCS_SLEEP_IN;
  120. r = dsi_vc_dcs_write_nosync(TCH, &cmd, 1);
  121. if (r)
  122. return r;
  123. hw_guard_start(td, 120);
  124. msleep(5);
  125. return 0;
  126. }
  127. static int taal_sleep_out(struct taal_data *td)
  128. {
  129. int r;
  130. hw_guard_wait(td);
  131. r = taal_dcs_write_0(DCS_SLEEP_OUT);
  132. if (r)
  133. return r;
  134. hw_guard_start(td, 120);
  135. msleep(5);
  136. return 0;
  137. }
  138. static int taal_get_id(u8 *id1, u8 *id2, u8 *id3)
  139. {
  140. int r;
  141. r = taal_dcs_read_1(DCS_GET_ID1, id1);
  142. if (r)
  143. return r;
  144. r = taal_dcs_read_1(DCS_GET_ID2, id2);
  145. if (r)
  146. return r;
  147. r = taal_dcs_read_1(DCS_GET_ID3, id3);
  148. if (r)
  149. return r;
  150. return 0;
  151. }
  152. static int taal_set_addr_mode(u8 rotate, bool mirror)
  153. {
  154. int r;
  155. u8 mode;
  156. int b5, b6, b7;
  157. r = taal_dcs_read_1(DCS_READ_MADCTL, &mode);
  158. if (r)
  159. return r;
  160. switch (rotate) {
  161. default:
  162. case 0:
  163. b7 = 0;
  164. b6 = 0;
  165. b5 = 0;
  166. break;
  167. case 1:
  168. b7 = 0;
  169. b6 = 1;
  170. b5 = 1;
  171. break;
  172. case 2:
  173. b7 = 1;
  174. b6 = 1;
  175. b5 = 0;
  176. break;
  177. case 3:
  178. b7 = 1;
  179. b6 = 0;
  180. b5 = 1;
  181. break;
  182. }
  183. if (mirror)
  184. b6 = !b6;
  185. mode &= ~((1<<7) | (1<<6) | (1<<5));
  186. mode |= (b7 << 7) | (b6 << 6) | (b5 << 5);
  187. return taal_dcs_write_1(DCS_MEM_ACC_CTRL, mode);
  188. }
  189. static int taal_set_update_window(u16 x, u16 y, u16 w, u16 h)
  190. {
  191. int r;
  192. u16 x1 = x;
  193. u16 x2 = x + w - 1;
  194. u16 y1 = y;
  195. u16 y2 = y + h - 1;
  196. u8 buf[5];
  197. buf[0] = DCS_COLUMN_ADDR;
  198. buf[1] = (x1 >> 8) & 0xff;
  199. buf[2] = (x1 >> 0) & 0xff;
  200. buf[3] = (x2 >> 8) & 0xff;
  201. buf[4] = (x2 >> 0) & 0xff;
  202. r = dsi_vc_dcs_write_nosync(TCH, buf, sizeof(buf));
  203. if (r)
  204. return r;
  205. buf[0] = DCS_PAGE_ADDR;
  206. buf[1] = (y1 >> 8) & 0xff;
  207. buf[2] = (y1 >> 0) & 0xff;
  208. buf[3] = (y2 >> 8) & 0xff;
  209. buf[4] = (y2 >> 0) & 0xff;
  210. r = dsi_vc_dcs_write_nosync(TCH, buf, sizeof(buf));
  211. if (r)
  212. return r;
  213. dsi_vc_send_bta_sync(TCH);
  214. return r;
  215. }
  216. static int taal_bl_update_status(struct backlight_device *dev)
  217. {
  218. struct omap_dss_device *dssdev = dev_get_drvdata(&dev->dev);
  219. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  220. int r;
  221. int level;
  222. if (dev->props.fb_blank == FB_BLANK_UNBLANK &&
  223. dev->props.power == FB_BLANK_UNBLANK)
  224. level = dev->props.brightness;
  225. else
  226. level = 0;
  227. dev_dbg(&dssdev->dev, "update brightness to %d\n", level);
  228. if (td->use_dsi_bl) {
  229. if (td->enabled) {
  230. dsi_bus_lock();
  231. r = taal_dcs_write_1(DCS_BRIGHTNESS, level);
  232. dsi_bus_unlock();
  233. if (r)
  234. return r;
  235. }
  236. } else {
  237. if (!dssdev->set_backlight)
  238. return -EINVAL;
  239. r = dssdev->set_backlight(dssdev, level);
  240. if (r)
  241. return r;
  242. }
  243. return 0;
  244. }
  245. static int taal_bl_get_intensity(struct backlight_device *dev)
  246. {
  247. if (dev->props.fb_blank == FB_BLANK_UNBLANK &&
  248. dev->props.power == FB_BLANK_UNBLANK)
  249. return dev->props.brightness;
  250. return 0;
  251. }
  252. static struct backlight_ops taal_bl_ops = {
  253. .get_brightness = taal_bl_get_intensity,
  254. .update_status = taal_bl_update_status,
  255. };
  256. static void taal_get_timings(struct omap_dss_device *dssdev,
  257. struct omap_video_timings *timings)
  258. {
  259. *timings = dssdev->panel.timings;
  260. }
  261. static void taal_get_resolution(struct omap_dss_device *dssdev,
  262. u16 *xres, u16 *yres)
  263. {
  264. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  265. if (td->rotate == 0 || td->rotate == 2) {
  266. *xres = dssdev->panel.timings.x_res;
  267. *yres = dssdev->panel.timings.y_res;
  268. } else {
  269. *yres = dssdev->panel.timings.x_res;
  270. *xres = dssdev->panel.timings.y_res;
  271. }
  272. }
  273. static irqreturn_t taal_te_isr(int irq, void *data)
  274. {
  275. struct omap_dss_device *dssdev = data;
  276. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  277. complete_all(&td->te_completion);
  278. return IRQ_HANDLED;
  279. }
  280. static ssize_t taal_num_errors_show(struct device *dev,
  281. struct device_attribute *attr, char *buf)
  282. {
  283. struct omap_dss_device *dssdev = to_dss_device(dev);
  284. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  285. u8 errors;
  286. int r;
  287. if (td->enabled) {
  288. dsi_bus_lock();
  289. r = taal_dcs_read_1(DCS_READ_NUM_ERRORS, &errors);
  290. dsi_bus_unlock();
  291. } else {
  292. r = -ENODEV;
  293. }
  294. if (r)
  295. return r;
  296. return snprintf(buf, PAGE_SIZE, "%d\n", errors);
  297. }
  298. static ssize_t taal_hw_revision_show(struct device *dev,
  299. struct device_attribute *attr, char *buf)
  300. {
  301. struct omap_dss_device *dssdev = to_dss_device(dev);
  302. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  303. u8 id1, id2, id3;
  304. int r;
  305. if (td->enabled) {
  306. dsi_bus_lock();
  307. r = taal_get_id(&id1, &id2, &id3);
  308. dsi_bus_unlock();
  309. } else {
  310. r = -ENODEV;
  311. }
  312. if (r)
  313. return r;
  314. return snprintf(buf, PAGE_SIZE, "%02x.%02x.%02x\n", id1, id2, id3);
  315. }
  316. static const char *cabc_modes[] = {
  317. "off", /* used also always when CABC is not supported */
  318. "ui",
  319. "still-image",
  320. "moving-image",
  321. };
  322. static ssize_t show_cabc_mode(struct device *dev,
  323. struct device_attribute *attr,
  324. char *buf)
  325. {
  326. struct omap_dss_device *dssdev = to_dss_device(dev);
  327. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  328. const char *mode_str;
  329. int mode;
  330. int len;
  331. mode = td->cabc_mode;
  332. mode_str = "unknown";
  333. if (mode >= 0 && mode < ARRAY_SIZE(cabc_modes))
  334. mode_str = cabc_modes[mode];
  335. len = snprintf(buf, PAGE_SIZE, "%s\n", mode_str);
  336. return len < PAGE_SIZE - 1 ? len : PAGE_SIZE - 1;
  337. }
  338. static ssize_t store_cabc_mode(struct device *dev,
  339. struct device_attribute *attr,
  340. const char *buf, size_t count)
  341. {
  342. struct omap_dss_device *dssdev = to_dss_device(dev);
  343. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  344. int i;
  345. for (i = 0; i < ARRAY_SIZE(cabc_modes); i++) {
  346. if (sysfs_streq(cabc_modes[i], buf))
  347. break;
  348. }
  349. if (i == ARRAY_SIZE(cabc_modes))
  350. return -EINVAL;
  351. if (td->enabled) {
  352. dsi_bus_lock();
  353. if (!td->cabc_broken)
  354. taal_dcs_write_1(DCS_WRITE_CABC, i);
  355. dsi_bus_unlock();
  356. }
  357. td->cabc_mode = i;
  358. return count;
  359. }
  360. static ssize_t show_cabc_available_modes(struct device *dev,
  361. struct device_attribute *attr,
  362. char *buf)
  363. {
  364. int len;
  365. int i;
  366. for (i = 0, len = 0;
  367. len < PAGE_SIZE && i < ARRAY_SIZE(cabc_modes); i++)
  368. len += snprintf(&buf[len], PAGE_SIZE - len, "%s%s%s",
  369. i ? " " : "", cabc_modes[i],
  370. i == ARRAY_SIZE(cabc_modes) - 1 ? "\n" : "");
  371. return len < PAGE_SIZE ? len : PAGE_SIZE - 1;
  372. }
  373. static DEVICE_ATTR(num_dsi_errors, S_IRUGO, taal_num_errors_show, NULL);
  374. static DEVICE_ATTR(hw_revision, S_IRUGO, taal_hw_revision_show, NULL);
  375. static DEVICE_ATTR(cabc_mode, S_IRUGO | S_IWUSR,
  376. show_cabc_mode, store_cabc_mode);
  377. static DEVICE_ATTR(cabc_available_modes, S_IRUGO,
  378. show_cabc_available_modes, NULL);
  379. static struct attribute *taal_attrs[] = {
  380. &dev_attr_num_dsi_errors.attr,
  381. &dev_attr_hw_revision.attr,
  382. &dev_attr_cabc_mode.attr,
  383. &dev_attr_cabc_available_modes.attr,
  384. NULL,
  385. };
  386. static struct attribute_group taal_attr_group = {
  387. .attrs = taal_attrs,
  388. };
  389. static int taal_probe(struct omap_dss_device *dssdev)
  390. {
  391. struct taal_data *td;
  392. struct backlight_device *bldev;
  393. int r;
  394. const struct omap_video_timings taal_panel_timings = {
  395. .x_res = 864,
  396. .y_res = 480,
  397. };
  398. dev_dbg(&dssdev->dev, "probe\n");
  399. dssdev->panel.config = OMAP_DSS_LCD_TFT;
  400. dssdev->panel.timings = taal_panel_timings;
  401. dssdev->ctrl.pixel_size = 24;
  402. td = kzalloc(sizeof(*td), GFP_KERNEL);
  403. if (!td) {
  404. r = -ENOMEM;
  405. goto err0;
  406. }
  407. td->dssdev = dssdev;
  408. td->esd_wq = create_singlethread_workqueue("taal_esd");
  409. if (td->esd_wq == NULL) {
  410. dev_err(&dssdev->dev, "can't create ESD workqueue\n");
  411. r = -ENOMEM;
  412. goto err2;
  413. }
  414. INIT_DELAYED_WORK_DEFERRABLE(&td->esd_work, taal_esd_work);
  415. dev_set_drvdata(&dssdev->dev, td);
  416. dssdev->get_timings = taal_get_timings;
  417. dssdev->get_resolution = taal_get_resolution;
  418. /* if no platform set_backlight() defined, presume DSI backlight
  419. * control */
  420. if (!dssdev->set_backlight)
  421. td->use_dsi_bl = true;
  422. bldev = backlight_device_register("taal", &dssdev->dev, dssdev,
  423. &taal_bl_ops);
  424. if (IS_ERR(bldev)) {
  425. r = PTR_ERR(bldev);
  426. goto err1;
  427. }
  428. td->bldev = bldev;
  429. bldev->props.fb_blank = FB_BLANK_UNBLANK;
  430. bldev->props.power = FB_BLANK_UNBLANK;
  431. if (td->use_dsi_bl) {
  432. bldev->props.max_brightness = 255;
  433. bldev->props.brightness = 255;
  434. } else {
  435. bldev->props.max_brightness = 127;
  436. bldev->props.brightness = 127;
  437. }
  438. taal_bl_update_status(bldev);
  439. if (dssdev->phy.dsi.ext_te) {
  440. int gpio = dssdev->phy.dsi.ext_te_gpio;
  441. r = gpio_request(gpio, "taal irq");
  442. if (r) {
  443. dev_err(&dssdev->dev, "GPIO request failed\n");
  444. goto err3;
  445. }
  446. gpio_direction_input(gpio);
  447. r = request_irq(gpio_to_irq(gpio), taal_te_isr,
  448. IRQF_DISABLED | IRQF_TRIGGER_RISING,
  449. "taal vsync", dssdev);
  450. if (r) {
  451. dev_err(&dssdev->dev, "IRQ request failed\n");
  452. gpio_free(gpio);
  453. goto err3;
  454. }
  455. init_completion(&td->te_completion);
  456. td->use_ext_te = true;
  457. }
  458. r = sysfs_create_group(&dssdev->dev.kobj, &taal_attr_group);
  459. if (r) {
  460. dev_err(&dssdev->dev, "failed to create sysfs files\n");
  461. goto err4;
  462. }
  463. return 0;
  464. err4:
  465. if (td->use_ext_te) {
  466. int gpio = dssdev->phy.dsi.ext_te_gpio;
  467. free_irq(gpio_to_irq(gpio), dssdev);
  468. gpio_free(gpio);
  469. }
  470. err3:
  471. backlight_device_unregister(bldev);
  472. err2:
  473. cancel_delayed_work_sync(&td->esd_work);
  474. destroy_workqueue(td->esd_wq);
  475. err1:
  476. kfree(td);
  477. err0:
  478. return r;
  479. }
  480. static void taal_remove(struct omap_dss_device *dssdev)
  481. {
  482. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  483. struct backlight_device *bldev;
  484. dev_dbg(&dssdev->dev, "remove\n");
  485. sysfs_remove_group(&dssdev->dev.kobj, &taal_attr_group);
  486. if (td->use_ext_te) {
  487. int gpio = dssdev->phy.dsi.ext_te_gpio;
  488. free_irq(gpio_to_irq(gpio), dssdev);
  489. gpio_free(gpio);
  490. }
  491. bldev = td->bldev;
  492. bldev->props.power = FB_BLANK_POWERDOWN;
  493. taal_bl_update_status(bldev);
  494. backlight_device_unregister(bldev);
  495. cancel_delayed_work_sync(&td->esd_work);
  496. destroy_workqueue(td->esd_wq);
  497. kfree(td);
  498. }
  499. static int taal_enable(struct omap_dss_device *dssdev)
  500. {
  501. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  502. u8 id1, id2, id3;
  503. int r;
  504. dev_dbg(&dssdev->dev, "enable\n");
  505. if (dssdev->platform_enable) {
  506. r = dssdev->platform_enable(dssdev);
  507. if (r)
  508. return r;
  509. }
  510. /* it seems we have to wait a bit until taal is ready */
  511. msleep(5);
  512. r = taal_sleep_out(td);
  513. if (r)
  514. goto err;
  515. r = taal_get_id(&id1, &id2, &id3);
  516. if (r)
  517. goto err;
  518. /* on early revisions CABC is broken */
  519. if (id2 == 0x00 || id2 == 0xff || id2 == 0x81)
  520. td->cabc_broken = true;
  521. taal_dcs_write_1(DCS_BRIGHTNESS, 0xff);
  522. taal_dcs_write_1(DCS_CTRL_DISPLAY, (1<<2) | (1<<5)); /* BL | BCTRL */
  523. taal_dcs_write_1(DCS_PIXEL_FORMAT, 0x7); /* 24bit/pixel */
  524. taal_set_addr_mode(td->rotate, td->mirror);
  525. if (!td->cabc_broken)
  526. taal_dcs_write_1(DCS_WRITE_CABC, td->cabc_mode);
  527. taal_dcs_write_0(DCS_DISPLAY_ON);
  528. #ifdef TAAL_USE_ESD_CHECK
  529. queue_delayed_work(td->esd_wq, &td->esd_work, TAAL_ESD_CHECK_PERIOD);
  530. #endif
  531. td->enabled = 1;
  532. if (!td->intro_printed) {
  533. dev_info(&dssdev->dev, "revision %02x.%02x.%02x\n",
  534. id1, id2, id3);
  535. if (td->cabc_broken)
  536. dev_info(&dssdev->dev,
  537. "old Taal version, CABC disabled\n");
  538. td->intro_printed = true;
  539. }
  540. return 0;
  541. err:
  542. if (dssdev->platform_disable)
  543. dssdev->platform_disable(dssdev);
  544. return r;
  545. }
  546. static void taal_disable(struct omap_dss_device *dssdev)
  547. {
  548. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  549. dev_dbg(&dssdev->dev, "disable\n");
  550. cancel_delayed_work(&td->esd_work);
  551. taal_dcs_write_0(DCS_DISPLAY_OFF);
  552. taal_sleep_in(td);
  553. /* wait a bit so that the message goes through */
  554. msleep(10);
  555. if (dssdev->platform_disable)
  556. dssdev->platform_disable(dssdev);
  557. td->enabled = 0;
  558. }
  559. static int taal_suspend(struct omap_dss_device *dssdev)
  560. {
  561. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  562. struct backlight_device *bldev = td->bldev;
  563. bldev->props.power = FB_BLANK_POWERDOWN;
  564. taal_bl_update_status(bldev);
  565. return 0;
  566. }
  567. static int taal_resume(struct omap_dss_device *dssdev)
  568. {
  569. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  570. struct backlight_device *bldev = td->bldev;
  571. bldev->props.power = FB_BLANK_UNBLANK;
  572. taal_bl_update_status(bldev);
  573. return 0;
  574. }
  575. static void taal_setup_update(struct omap_dss_device *dssdev,
  576. u16 x, u16 y, u16 w, u16 h)
  577. {
  578. taal_set_update_window(x, y, w, h);
  579. }
  580. static int taal_enable_te(struct omap_dss_device *dssdev, bool enable)
  581. {
  582. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  583. int r;
  584. td->te_enabled = enable;
  585. if (enable)
  586. r = taal_dcs_write_1(DCS_TEAR_ON, 0);
  587. else
  588. r = taal_dcs_write_0(DCS_TEAR_OFF);
  589. return r;
  590. }
  591. static int taal_wait_te(struct omap_dss_device *dssdev)
  592. {
  593. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  594. long wait = msecs_to_jiffies(500);
  595. if (!td->use_ext_te || !td->te_enabled)
  596. return 0;
  597. INIT_COMPLETION(td->te_completion);
  598. wait = wait_for_completion_timeout(&td->te_completion, wait);
  599. if (wait == 0) {
  600. dev_err(&dssdev->dev, "timeout waiting TE\n");
  601. return -ETIME;
  602. }
  603. return 0;
  604. }
  605. static int taal_rotate(struct omap_dss_device *dssdev, u8 rotate)
  606. {
  607. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  608. int r;
  609. dev_dbg(&dssdev->dev, "rotate %d\n", rotate);
  610. if (td->enabled) {
  611. r = taal_set_addr_mode(rotate, td->mirror);
  612. if (r)
  613. return r;
  614. }
  615. td->rotate = rotate;
  616. return 0;
  617. }
  618. static u8 taal_get_rotate(struct omap_dss_device *dssdev)
  619. {
  620. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  621. return td->rotate;
  622. }
  623. static int taal_mirror(struct omap_dss_device *dssdev, bool enable)
  624. {
  625. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  626. int r;
  627. dev_dbg(&dssdev->dev, "mirror %d\n", enable);
  628. if (td->enabled) {
  629. r = taal_set_addr_mode(td->rotate, enable);
  630. if (r)
  631. return r;
  632. }
  633. td->mirror = enable;
  634. return 0;
  635. }
  636. static bool taal_get_mirror(struct omap_dss_device *dssdev)
  637. {
  638. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  639. return td->mirror;
  640. }
  641. static int taal_run_test(struct omap_dss_device *dssdev, int test_num)
  642. {
  643. u8 id1, id2, id3;
  644. int r;
  645. r = taal_dcs_read_1(DCS_GET_ID1, &id1);
  646. if (r)
  647. return r;
  648. r = taal_dcs_read_1(DCS_GET_ID2, &id2);
  649. if (r)
  650. return r;
  651. r = taal_dcs_read_1(DCS_GET_ID3, &id3);
  652. if (r)
  653. return r;
  654. return 0;
  655. }
  656. static int taal_memory_read(struct omap_dss_device *dssdev,
  657. void *buf, size_t size,
  658. u16 x, u16 y, u16 w, u16 h)
  659. {
  660. int r;
  661. int first = 1;
  662. int plen;
  663. unsigned buf_used = 0;
  664. if (size < w * h * 3)
  665. return -ENOMEM;
  666. size = min(w * h * 3,
  667. dssdev->panel.timings.x_res *
  668. dssdev->panel.timings.y_res * 3);
  669. /* plen 1 or 2 goes into short packet. until checksum error is fixed,
  670. * use short packets. plen 32 works, but bigger packets seem to cause
  671. * an error. */
  672. if (size % 2)
  673. plen = 1;
  674. else
  675. plen = 2;
  676. taal_setup_update(dssdev, x, y, w, h);
  677. r = dsi_vc_set_max_rx_packet_size(TCH, plen);
  678. if (r)
  679. return r;
  680. while (buf_used < size) {
  681. u8 dcs_cmd = first ? 0x2e : 0x3e;
  682. first = 0;
  683. r = dsi_vc_dcs_read(TCH, dcs_cmd,
  684. buf + buf_used, size - buf_used);
  685. if (r < 0) {
  686. dev_err(&dssdev->dev, "read error\n");
  687. goto err;
  688. }
  689. buf_used += r;
  690. if (r < plen) {
  691. dev_err(&dssdev->dev, "short read\n");
  692. break;
  693. }
  694. if (signal_pending(current)) {
  695. dev_err(&dssdev->dev, "signal pending, "
  696. "aborting memory read\n");
  697. r = -ERESTARTSYS;
  698. goto err;
  699. }
  700. }
  701. r = buf_used;
  702. err:
  703. dsi_vc_set_max_rx_packet_size(TCH, 1);
  704. return r;
  705. }
  706. static void taal_esd_work(struct work_struct *work)
  707. {
  708. struct taal_data *td = container_of(work, struct taal_data,
  709. esd_work.work);
  710. struct omap_dss_device *dssdev = td->dssdev;
  711. u8 state1, state2;
  712. int r;
  713. if (!td->enabled)
  714. return;
  715. dsi_bus_lock();
  716. r = taal_dcs_read_1(DCS_RDDSDR, &state1);
  717. if (r) {
  718. dev_err(&dssdev->dev, "failed to read Taal status\n");
  719. goto err;
  720. }
  721. /* Run self diagnostics */
  722. r = taal_sleep_out(td);
  723. if (r) {
  724. dev_err(&dssdev->dev, "failed to run Taal self-diagnostics\n");
  725. goto err;
  726. }
  727. r = taal_dcs_read_1(DCS_RDDSDR, &state2);
  728. if (r) {
  729. dev_err(&dssdev->dev, "failed to read Taal status\n");
  730. goto err;
  731. }
  732. /* Each sleep out command will trigger a self diagnostic and flip
  733. * Bit6 if the test passes.
  734. */
  735. if (!((state1 ^ state2) & (1 << 6))) {
  736. dev_err(&dssdev->dev, "LCD self diagnostics failed\n");
  737. goto err;
  738. }
  739. /* Self-diagnostics result is also shown on TE GPIO line. We need
  740. * to re-enable TE after self diagnostics */
  741. if (td->use_ext_te && td->te_enabled)
  742. taal_enable_te(dssdev, true);
  743. dsi_bus_unlock();
  744. queue_delayed_work(td->esd_wq, &td->esd_work, TAAL_ESD_CHECK_PERIOD);
  745. return;
  746. err:
  747. dev_err(&dssdev->dev, "performing LCD reset\n");
  748. taal_disable(dssdev);
  749. taal_enable(dssdev);
  750. dsi_bus_unlock();
  751. queue_delayed_work(td->esd_wq, &td->esd_work, TAAL_ESD_CHECK_PERIOD);
  752. }
  753. static struct omap_dss_driver taal_driver = {
  754. .probe = taal_probe,
  755. .remove = taal_remove,
  756. .enable = taal_enable,
  757. .disable = taal_disable,
  758. .suspend = taal_suspend,
  759. .resume = taal_resume,
  760. .setup_update = taal_setup_update,
  761. .enable_te = taal_enable_te,
  762. .wait_for_te = taal_wait_te,
  763. .set_rotate = taal_rotate,
  764. .get_rotate = taal_get_rotate,
  765. .set_mirror = taal_mirror,
  766. .get_mirror = taal_get_mirror,
  767. .run_test = taal_run_test,
  768. .memory_read = taal_memory_read,
  769. .driver = {
  770. .name = "taal",
  771. .owner = THIS_MODULE,
  772. },
  773. };
  774. static int __init taal_init(void)
  775. {
  776. omap_dss_register_driver(&taal_driver);
  777. return 0;
  778. }
  779. static void __exit taal_exit(void)
  780. {
  781. omap_dss_unregister_driver(&taal_driver);
  782. }
  783. module_init(taal_init);
  784. module_exit(taal_exit);
  785. MODULE_AUTHOR("Tomi Valkeinen <tomi.valkeinen@nokia.com>");
  786. MODULE_DESCRIPTION("Taal Driver");
  787. MODULE_LICENSE("GPL");