panel-taal.c 23 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162
  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. static int _taal_enable_te(struct omap_dss_device *dssdev, bool enable);
  60. struct taal_data {
  61. struct backlight_device *bldev;
  62. unsigned long hw_guard_end; /* next value of jiffies when we can
  63. * issue the next sleep in/out command
  64. */
  65. unsigned long hw_guard_wait; /* max guard time in jiffies */
  66. struct omap_dss_device *dssdev;
  67. bool enabled;
  68. u8 rotate;
  69. bool mirror;
  70. bool te_enabled;
  71. bool use_ext_te;
  72. struct completion te_completion;
  73. bool use_dsi_bl;
  74. bool cabc_broken;
  75. unsigned cabc_mode;
  76. bool intro_printed;
  77. struct workqueue_struct *esd_wq;
  78. struct delayed_work esd_work;
  79. };
  80. static void taal_esd_work(struct work_struct *work);
  81. static void hw_guard_start(struct taal_data *td, int guard_msec)
  82. {
  83. td->hw_guard_wait = msecs_to_jiffies(guard_msec);
  84. td->hw_guard_end = jiffies + td->hw_guard_wait;
  85. }
  86. static void hw_guard_wait(struct taal_data *td)
  87. {
  88. unsigned long wait = td->hw_guard_end - jiffies;
  89. if ((long)wait > 0 && wait <= td->hw_guard_wait) {
  90. set_current_state(TASK_UNINTERRUPTIBLE);
  91. schedule_timeout(wait);
  92. }
  93. }
  94. static int taal_dcs_read_1(u8 dcs_cmd, u8 *data)
  95. {
  96. int r;
  97. u8 buf[1];
  98. r = dsi_vc_dcs_read(TCH, dcs_cmd, buf, 1);
  99. if (r < 0)
  100. return r;
  101. *data = buf[0];
  102. return 0;
  103. }
  104. static int taal_dcs_write_0(u8 dcs_cmd)
  105. {
  106. return dsi_vc_dcs_write(TCH, &dcs_cmd, 1);
  107. }
  108. static int taal_dcs_write_1(u8 dcs_cmd, u8 param)
  109. {
  110. u8 buf[2];
  111. buf[0] = dcs_cmd;
  112. buf[1] = param;
  113. return dsi_vc_dcs_write(TCH, buf, 2);
  114. }
  115. static int taal_sleep_in(struct taal_data *td)
  116. {
  117. u8 cmd;
  118. int r;
  119. hw_guard_wait(td);
  120. cmd = DCS_SLEEP_IN;
  121. r = dsi_vc_dcs_write_nosync(TCH, &cmd, 1);
  122. if (r)
  123. return r;
  124. hw_guard_start(td, 120);
  125. msleep(5);
  126. return 0;
  127. }
  128. static int taal_sleep_out(struct taal_data *td)
  129. {
  130. int r;
  131. hw_guard_wait(td);
  132. r = taal_dcs_write_0(DCS_SLEEP_OUT);
  133. if (r)
  134. return r;
  135. hw_guard_start(td, 120);
  136. msleep(5);
  137. return 0;
  138. }
  139. static int taal_get_id(u8 *id1, u8 *id2, u8 *id3)
  140. {
  141. int r;
  142. r = taal_dcs_read_1(DCS_GET_ID1, id1);
  143. if (r)
  144. return r;
  145. r = taal_dcs_read_1(DCS_GET_ID2, id2);
  146. if (r)
  147. return r;
  148. r = taal_dcs_read_1(DCS_GET_ID3, id3);
  149. if (r)
  150. return r;
  151. return 0;
  152. }
  153. static int taal_set_addr_mode(u8 rotate, bool mirror)
  154. {
  155. int r;
  156. u8 mode;
  157. int b5, b6, b7;
  158. r = taal_dcs_read_1(DCS_READ_MADCTL, &mode);
  159. if (r)
  160. return r;
  161. switch (rotate) {
  162. default:
  163. case 0:
  164. b7 = 0;
  165. b6 = 0;
  166. b5 = 0;
  167. break;
  168. case 1:
  169. b7 = 0;
  170. b6 = 1;
  171. b5 = 1;
  172. break;
  173. case 2:
  174. b7 = 1;
  175. b6 = 1;
  176. b5 = 0;
  177. break;
  178. case 3:
  179. b7 = 1;
  180. b6 = 0;
  181. b5 = 1;
  182. break;
  183. }
  184. if (mirror)
  185. b6 = !b6;
  186. mode &= ~((1<<7) | (1<<6) | (1<<5));
  187. mode |= (b7 << 7) | (b6 << 6) | (b5 << 5);
  188. return taal_dcs_write_1(DCS_MEM_ACC_CTRL, mode);
  189. }
  190. static int taal_set_update_window(u16 x, u16 y, u16 w, u16 h)
  191. {
  192. int r;
  193. u16 x1 = x;
  194. u16 x2 = x + w - 1;
  195. u16 y1 = y;
  196. u16 y2 = y + h - 1;
  197. u8 buf[5];
  198. buf[0] = DCS_COLUMN_ADDR;
  199. buf[1] = (x1 >> 8) & 0xff;
  200. buf[2] = (x1 >> 0) & 0xff;
  201. buf[3] = (x2 >> 8) & 0xff;
  202. buf[4] = (x2 >> 0) & 0xff;
  203. r = dsi_vc_dcs_write_nosync(TCH, buf, sizeof(buf));
  204. if (r)
  205. return r;
  206. buf[0] = DCS_PAGE_ADDR;
  207. buf[1] = (y1 >> 8) & 0xff;
  208. buf[2] = (y1 >> 0) & 0xff;
  209. buf[3] = (y2 >> 8) & 0xff;
  210. buf[4] = (y2 >> 0) & 0xff;
  211. r = dsi_vc_dcs_write_nosync(TCH, buf, sizeof(buf));
  212. if (r)
  213. return r;
  214. dsi_vc_send_bta_sync(TCH);
  215. return r;
  216. }
  217. static int taal_bl_update_status(struct backlight_device *dev)
  218. {
  219. struct omap_dss_device *dssdev = dev_get_drvdata(&dev->dev);
  220. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  221. int r;
  222. int level;
  223. if (dev->props.fb_blank == FB_BLANK_UNBLANK &&
  224. dev->props.power == FB_BLANK_UNBLANK)
  225. level = dev->props.brightness;
  226. else
  227. level = 0;
  228. dev_dbg(&dssdev->dev, "update brightness to %d\n", level);
  229. if (td->use_dsi_bl) {
  230. if (td->enabled) {
  231. dsi_bus_lock();
  232. r = taal_dcs_write_1(DCS_BRIGHTNESS, level);
  233. dsi_bus_unlock();
  234. if (r)
  235. return r;
  236. }
  237. } else {
  238. if (!dssdev->set_backlight)
  239. return -EINVAL;
  240. r = dssdev->set_backlight(dssdev, level);
  241. if (r)
  242. return r;
  243. }
  244. return 0;
  245. }
  246. static int taal_bl_get_intensity(struct backlight_device *dev)
  247. {
  248. if (dev->props.fb_blank == FB_BLANK_UNBLANK &&
  249. dev->props.power == FB_BLANK_UNBLANK)
  250. return dev->props.brightness;
  251. return 0;
  252. }
  253. static struct backlight_ops taal_bl_ops = {
  254. .get_brightness = taal_bl_get_intensity,
  255. .update_status = taal_bl_update_status,
  256. };
  257. static void taal_get_timings(struct omap_dss_device *dssdev,
  258. struct omap_video_timings *timings)
  259. {
  260. *timings = dssdev->panel.timings;
  261. }
  262. static void taal_get_resolution(struct omap_dss_device *dssdev,
  263. u16 *xres, u16 *yres)
  264. {
  265. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  266. if (td->rotate == 0 || td->rotate == 2) {
  267. *xres = dssdev->panel.timings.x_res;
  268. *yres = dssdev->panel.timings.y_res;
  269. } else {
  270. *yres = dssdev->panel.timings.x_res;
  271. *xres = dssdev->panel.timings.y_res;
  272. }
  273. }
  274. static irqreturn_t taal_te_isr(int irq, void *data)
  275. {
  276. struct omap_dss_device *dssdev = data;
  277. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  278. complete_all(&td->te_completion);
  279. return IRQ_HANDLED;
  280. }
  281. static ssize_t taal_num_errors_show(struct device *dev,
  282. struct device_attribute *attr, char *buf)
  283. {
  284. struct omap_dss_device *dssdev = to_dss_device(dev);
  285. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  286. u8 errors;
  287. int r;
  288. if (td->enabled) {
  289. dsi_bus_lock();
  290. r = taal_dcs_read_1(DCS_READ_NUM_ERRORS, &errors);
  291. dsi_bus_unlock();
  292. } else {
  293. r = -ENODEV;
  294. }
  295. if (r)
  296. return r;
  297. return snprintf(buf, PAGE_SIZE, "%d\n", errors);
  298. }
  299. static ssize_t taal_hw_revision_show(struct device *dev,
  300. struct device_attribute *attr, char *buf)
  301. {
  302. struct omap_dss_device *dssdev = to_dss_device(dev);
  303. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  304. u8 id1, id2, id3;
  305. int r;
  306. if (td->enabled) {
  307. dsi_bus_lock();
  308. r = taal_get_id(&id1, &id2, &id3);
  309. dsi_bus_unlock();
  310. } else {
  311. r = -ENODEV;
  312. }
  313. if (r)
  314. return r;
  315. return snprintf(buf, PAGE_SIZE, "%02x.%02x.%02x\n", id1, id2, id3);
  316. }
  317. static const char *cabc_modes[] = {
  318. "off", /* used also always when CABC is not supported */
  319. "ui",
  320. "still-image",
  321. "moving-image",
  322. };
  323. static ssize_t show_cabc_mode(struct device *dev,
  324. struct device_attribute *attr,
  325. char *buf)
  326. {
  327. struct omap_dss_device *dssdev = to_dss_device(dev);
  328. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  329. const char *mode_str;
  330. int mode;
  331. int len;
  332. mode = td->cabc_mode;
  333. mode_str = "unknown";
  334. if (mode >= 0 && mode < ARRAY_SIZE(cabc_modes))
  335. mode_str = cabc_modes[mode];
  336. len = snprintf(buf, PAGE_SIZE, "%s\n", mode_str);
  337. return len < PAGE_SIZE - 1 ? len : PAGE_SIZE - 1;
  338. }
  339. static ssize_t store_cabc_mode(struct device *dev,
  340. struct device_attribute *attr,
  341. const char *buf, size_t count)
  342. {
  343. struct omap_dss_device *dssdev = to_dss_device(dev);
  344. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  345. int i;
  346. for (i = 0; i < ARRAY_SIZE(cabc_modes); i++) {
  347. if (sysfs_streq(cabc_modes[i], buf))
  348. break;
  349. }
  350. if (i == ARRAY_SIZE(cabc_modes))
  351. return -EINVAL;
  352. if (td->enabled) {
  353. dsi_bus_lock();
  354. if (!td->cabc_broken)
  355. taal_dcs_write_1(DCS_WRITE_CABC, i);
  356. dsi_bus_unlock();
  357. }
  358. td->cabc_mode = i;
  359. return count;
  360. }
  361. static ssize_t show_cabc_available_modes(struct device *dev,
  362. struct device_attribute *attr,
  363. char *buf)
  364. {
  365. int len;
  366. int i;
  367. for (i = 0, len = 0;
  368. len < PAGE_SIZE && i < ARRAY_SIZE(cabc_modes); i++)
  369. len += snprintf(&buf[len], PAGE_SIZE - len, "%s%s%s",
  370. i ? " " : "", cabc_modes[i],
  371. i == ARRAY_SIZE(cabc_modes) - 1 ? "\n" : "");
  372. return len < PAGE_SIZE ? len : PAGE_SIZE - 1;
  373. }
  374. static DEVICE_ATTR(num_dsi_errors, S_IRUGO, taal_num_errors_show, NULL);
  375. static DEVICE_ATTR(hw_revision, S_IRUGO, taal_hw_revision_show, NULL);
  376. static DEVICE_ATTR(cabc_mode, S_IRUGO | S_IWUSR,
  377. show_cabc_mode, store_cabc_mode);
  378. static DEVICE_ATTR(cabc_available_modes, S_IRUGO,
  379. show_cabc_available_modes, NULL);
  380. static struct attribute *taal_attrs[] = {
  381. &dev_attr_num_dsi_errors.attr,
  382. &dev_attr_hw_revision.attr,
  383. &dev_attr_cabc_mode.attr,
  384. &dev_attr_cabc_available_modes.attr,
  385. NULL,
  386. };
  387. static struct attribute_group taal_attr_group = {
  388. .attrs = taal_attrs,
  389. };
  390. static int taal_probe(struct omap_dss_device *dssdev)
  391. {
  392. struct taal_data *td;
  393. struct backlight_device *bldev;
  394. int r;
  395. const struct omap_video_timings taal_panel_timings = {
  396. .x_res = 864,
  397. .y_res = 480,
  398. };
  399. dev_dbg(&dssdev->dev, "probe\n");
  400. dssdev->panel.config = OMAP_DSS_LCD_TFT;
  401. dssdev->panel.timings = taal_panel_timings;
  402. dssdev->ctrl.pixel_size = 24;
  403. td = kzalloc(sizeof(*td), GFP_KERNEL);
  404. if (!td) {
  405. r = -ENOMEM;
  406. goto err0;
  407. }
  408. td->dssdev = dssdev;
  409. td->esd_wq = create_singlethread_workqueue("taal_esd");
  410. if (td->esd_wq == NULL) {
  411. dev_err(&dssdev->dev, "can't create ESD workqueue\n");
  412. r = -ENOMEM;
  413. goto err1;
  414. }
  415. INIT_DELAYED_WORK_DEFERRABLE(&td->esd_work, taal_esd_work);
  416. dev_set_drvdata(&dssdev->dev, td);
  417. /* if no platform set_backlight() defined, presume DSI backlight
  418. * control */
  419. if (!dssdev->set_backlight)
  420. td->use_dsi_bl = true;
  421. bldev = backlight_device_register("taal", &dssdev->dev, dssdev,
  422. &taal_bl_ops);
  423. if (IS_ERR(bldev)) {
  424. r = PTR_ERR(bldev);
  425. goto err2;
  426. }
  427. td->bldev = bldev;
  428. bldev->props.fb_blank = FB_BLANK_UNBLANK;
  429. bldev->props.power = FB_BLANK_UNBLANK;
  430. if (td->use_dsi_bl) {
  431. bldev->props.max_brightness = 255;
  432. bldev->props.brightness = 255;
  433. } else {
  434. bldev->props.max_brightness = 127;
  435. bldev->props.brightness = 127;
  436. }
  437. taal_bl_update_status(bldev);
  438. if (dssdev->phy.dsi.ext_te) {
  439. int gpio = dssdev->phy.dsi.ext_te_gpio;
  440. r = gpio_request(gpio, "taal irq");
  441. if (r) {
  442. dev_err(&dssdev->dev, "GPIO request failed\n");
  443. goto err3;
  444. }
  445. gpio_direction_input(gpio);
  446. r = request_irq(gpio_to_irq(gpio), taal_te_isr,
  447. IRQF_DISABLED | IRQF_TRIGGER_RISING,
  448. "taal vsync", dssdev);
  449. if (r) {
  450. dev_err(&dssdev->dev, "IRQ request failed\n");
  451. gpio_free(gpio);
  452. goto err3;
  453. }
  454. init_completion(&td->te_completion);
  455. td->use_ext_te = true;
  456. }
  457. r = sysfs_create_group(&dssdev->dev.kobj, &taal_attr_group);
  458. if (r) {
  459. dev_err(&dssdev->dev, "failed to create sysfs files\n");
  460. goto err4;
  461. }
  462. return 0;
  463. err4:
  464. if (td->use_ext_te) {
  465. int gpio = dssdev->phy.dsi.ext_te_gpio;
  466. free_irq(gpio_to_irq(gpio), dssdev);
  467. gpio_free(gpio);
  468. }
  469. err3:
  470. backlight_device_unregister(bldev);
  471. err2:
  472. cancel_delayed_work_sync(&td->esd_work);
  473. destroy_workqueue(td->esd_wq);
  474. err1:
  475. kfree(td);
  476. err0:
  477. return r;
  478. }
  479. static void taal_remove(struct omap_dss_device *dssdev)
  480. {
  481. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  482. struct backlight_device *bldev;
  483. dev_dbg(&dssdev->dev, "remove\n");
  484. sysfs_remove_group(&dssdev->dev.kobj, &taal_attr_group);
  485. if (td->use_ext_te) {
  486. int gpio = dssdev->phy.dsi.ext_te_gpio;
  487. free_irq(gpio_to_irq(gpio), dssdev);
  488. gpio_free(gpio);
  489. }
  490. bldev = td->bldev;
  491. bldev->props.power = FB_BLANK_POWERDOWN;
  492. taal_bl_update_status(bldev);
  493. backlight_device_unregister(bldev);
  494. cancel_delayed_work_sync(&td->esd_work);
  495. destroy_workqueue(td->esd_wq);
  496. kfree(td);
  497. }
  498. static int taal_power_on(struct omap_dss_device *dssdev)
  499. {
  500. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  501. u8 id1, id2, id3;
  502. int r;
  503. if (dssdev->platform_enable) {
  504. r = dssdev->platform_enable(dssdev);
  505. if (r)
  506. return r;
  507. }
  508. /* it seems we have to wait a bit until taal is ready */
  509. msleep(5);
  510. dsi_bus_lock();
  511. r = omapdss_dsi_display_enable(dssdev);
  512. if (r) {
  513. dev_err(&dssdev->dev, "failed to enable DSI\n");
  514. goto err0;
  515. }
  516. omapdss_dsi_vc_enable_hs(TCH, false);
  517. r = taal_sleep_out(td);
  518. if (r)
  519. goto err;
  520. r = taal_get_id(&id1, &id2, &id3);
  521. if (r)
  522. goto err;
  523. /* on early revisions CABC is broken */
  524. if (id2 == 0x00 || id2 == 0xff || id2 == 0x81)
  525. td->cabc_broken = true;
  526. taal_dcs_write_1(DCS_BRIGHTNESS, 0xff);
  527. taal_dcs_write_1(DCS_CTRL_DISPLAY, (1<<2) | (1<<5)); /* BL | BCTRL */
  528. taal_dcs_write_1(DCS_PIXEL_FORMAT, 0x7); /* 24bit/pixel */
  529. taal_set_addr_mode(td->rotate, td->mirror);
  530. if (!td->cabc_broken)
  531. taal_dcs_write_1(DCS_WRITE_CABC, td->cabc_mode);
  532. taal_dcs_write_0(DCS_DISPLAY_ON);
  533. r = _taal_enable_te(dssdev, td->te_enabled);
  534. if (r)
  535. goto err;
  536. #ifdef TAAL_USE_ESD_CHECK
  537. queue_delayed_work(td->esd_wq, &td->esd_work, TAAL_ESD_CHECK_PERIOD);
  538. #endif
  539. td->enabled = 1;
  540. if (!td->intro_printed) {
  541. dev_info(&dssdev->dev, "revision %02x.%02x.%02x\n",
  542. id1, id2, id3);
  543. if (td->cabc_broken)
  544. dev_info(&dssdev->dev,
  545. "old Taal version, CABC disabled\n");
  546. td->intro_printed = true;
  547. }
  548. omapdss_dsi_vc_enable_hs(TCH, true);
  549. dsi_bus_unlock();
  550. return 0;
  551. err:
  552. dsi_bus_unlock();
  553. omapdss_dsi_display_disable(dssdev);
  554. err0:
  555. if (dssdev->platform_disable)
  556. dssdev->platform_disable(dssdev);
  557. return r;
  558. }
  559. static void taal_power_off(struct omap_dss_device *dssdev)
  560. {
  561. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  562. dsi_bus_lock();
  563. cancel_delayed_work(&td->esd_work);
  564. taal_dcs_write_0(DCS_DISPLAY_OFF);
  565. taal_sleep_in(td);
  566. /* wait a bit so that the message goes through */
  567. msleep(10);
  568. omapdss_dsi_display_disable(dssdev);
  569. if (dssdev->platform_disable)
  570. dssdev->platform_disable(dssdev);
  571. td->enabled = 0;
  572. dsi_bus_unlock();
  573. }
  574. static int taal_enable(struct omap_dss_device *dssdev)
  575. {
  576. int r;
  577. dev_dbg(&dssdev->dev, "enable\n");
  578. if (dssdev->state != OMAP_DSS_DISPLAY_DISABLED)
  579. return -EINVAL;
  580. r = taal_power_on(dssdev);
  581. if (r)
  582. return r;
  583. dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
  584. return r;
  585. }
  586. static void taal_disable(struct omap_dss_device *dssdev)
  587. {
  588. dev_dbg(&dssdev->dev, "disable\n");
  589. if (dssdev->state == OMAP_DSS_DISPLAY_ACTIVE)
  590. taal_power_off(dssdev);
  591. dssdev->state = OMAP_DSS_DISPLAY_DISABLED;
  592. }
  593. static int taal_suspend(struct omap_dss_device *dssdev)
  594. {
  595. dev_dbg(&dssdev->dev, "suspend\n");
  596. if (dssdev->state != OMAP_DSS_DISPLAY_ACTIVE)
  597. return -EINVAL;
  598. taal_power_off(dssdev);
  599. dssdev->state = OMAP_DSS_DISPLAY_SUSPENDED;
  600. return 0;
  601. }
  602. static int taal_resume(struct omap_dss_device *dssdev)
  603. {
  604. int r;
  605. dev_dbg(&dssdev->dev, "resume\n");
  606. if (dssdev->state != OMAP_DSS_DISPLAY_SUSPENDED)
  607. return -EINVAL;
  608. r = taal_power_on(dssdev);
  609. dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
  610. return r;
  611. }
  612. static void taal_framedone_cb(int err, void *data)
  613. {
  614. struct omap_dss_device *dssdev = data;
  615. dev_dbg(&dssdev->dev, "framedone, err %d\n", err);
  616. dsi_bus_unlock();
  617. }
  618. static int taal_update(struct omap_dss_device *dssdev,
  619. u16 x, u16 y, u16 w, u16 h)
  620. {
  621. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  622. int r;
  623. dev_dbg(&dssdev->dev, "update %d, %d, %d x %d\n", x, y, w, h);
  624. dsi_bus_lock();
  625. if (!td->enabled) {
  626. r = 0;
  627. goto err;
  628. }
  629. r = omap_dsi_prepare_update(dssdev, &x, &y, &w, &h);
  630. if (r)
  631. goto err;
  632. r = taal_set_update_window(x, y, w, h);
  633. if (r)
  634. goto err;
  635. r = omap_dsi_update(dssdev, TCH, x, y, w, h,
  636. taal_framedone_cb, dssdev);
  637. if (r)
  638. goto err;
  639. /* note: no bus_unlock here. unlock is in framedone_cb */
  640. return 0;
  641. err:
  642. dsi_bus_unlock();
  643. return r;
  644. }
  645. static int taal_sync(struct omap_dss_device *dssdev)
  646. {
  647. dev_dbg(&dssdev->dev, "sync\n");
  648. dsi_bus_lock();
  649. dsi_bus_unlock();
  650. dev_dbg(&dssdev->dev, "sync done\n");
  651. return 0;
  652. }
  653. static int _taal_enable_te(struct omap_dss_device *dssdev, bool enable)
  654. {
  655. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  656. int r;
  657. td->te_enabled = enable;
  658. if (enable)
  659. r = taal_dcs_write_1(DCS_TEAR_ON, 0);
  660. else
  661. r = taal_dcs_write_0(DCS_TEAR_OFF);
  662. omapdss_dsi_enable_te(dssdev, enable);
  663. /* XXX for some reason, DSI TE breaks if we don't wait here.
  664. * Panel bug? Needs more studying */
  665. msleep(100);
  666. return r;
  667. }
  668. static int taal_enable_te(struct omap_dss_device *dssdev, bool enable)
  669. {
  670. int r;
  671. dsi_bus_lock();
  672. r = _taal_enable_te(dssdev, enable);
  673. dsi_bus_unlock();
  674. return r;
  675. }
  676. static int taal_get_te(struct omap_dss_device *dssdev)
  677. {
  678. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  679. return td->te_enabled;
  680. }
  681. static int taal_rotate(struct omap_dss_device *dssdev, u8 rotate)
  682. {
  683. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  684. int r;
  685. dev_dbg(&dssdev->dev, "rotate %d\n", rotate);
  686. dsi_bus_lock();
  687. if (td->enabled) {
  688. r = taal_set_addr_mode(rotate, td->mirror);
  689. if (r)
  690. goto err;
  691. }
  692. td->rotate = rotate;
  693. dsi_bus_unlock();
  694. return 0;
  695. err:
  696. dsi_bus_unlock();
  697. return r;
  698. }
  699. static u8 taal_get_rotate(struct omap_dss_device *dssdev)
  700. {
  701. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  702. return td->rotate;
  703. }
  704. static int taal_mirror(struct omap_dss_device *dssdev, bool enable)
  705. {
  706. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  707. int r;
  708. dev_dbg(&dssdev->dev, "mirror %d\n", enable);
  709. dsi_bus_lock();
  710. if (td->enabled) {
  711. r = taal_set_addr_mode(td->rotate, enable);
  712. if (r)
  713. goto err;
  714. }
  715. td->mirror = enable;
  716. dsi_bus_unlock();
  717. return 0;
  718. err:
  719. dsi_bus_unlock();
  720. return r;
  721. }
  722. static bool taal_get_mirror(struct omap_dss_device *dssdev)
  723. {
  724. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  725. return td->mirror;
  726. }
  727. static int taal_run_test(struct omap_dss_device *dssdev, int test_num)
  728. {
  729. u8 id1, id2, id3;
  730. int r;
  731. dsi_bus_lock();
  732. r = taal_dcs_read_1(DCS_GET_ID1, &id1);
  733. if (r)
  734. goto err;
  735. r = taal_dcs_read_1(DCS_GET_ID2, &id2);
  736. if (r)
  737. goto err;
  738. r = taal_dcs_read_1(DCS_GET_ID3, &id3);
  739. if (r)
  740. goto err;
  741. dsi_bus_unlock();
  742. return 0;
  743. err:
  744. dsi_bus_unlock();
  745. return r;
  746. }
  747. static int taal_memory_read(struct omap_dss_device *dssdev,
  748. void *buf, size_t size,
  749. u16 x, u16 y, u16 w, u16 h)
  750. {
  751. int r;
  752. int first = 1;
  753. int plen;
  754. unsigned buf_used = 0;
  755. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  756. if (!td->enabled)
  757. return -ENODEV;
  758. if (size < w * h * 3)
  759. return -ENOMEM;
  760. size = min(w * h * 3,
  761. dssdev->panel.timings.x_res *
  762. dssdev->panel.timings.y_res * 3);
  763. dsi_bus_lock();
  764. /* plen 1 or 2 goes into short packet. until checksum error is fixed,
  765. * use short packets. plen 32 works, but bigger packets seem to cause
  766. * an error. */
  767. if (size % 2)
  768. plen = 1;
  769. else
  770. plen = 2;
  771. taal_set_update_window(x, y, w, h);
  772. r = dsi_vc_set_max_rx_packet_size(TCH, plen);
  773. if (r)
  774. goto err0;
  775. while (buf_used < size) {
  776. u8 dcs_cmd = first ? 0x2e : 0x3e;
  777. first = 0;
  778. r = dsi_vc_dcs_read(TCH, dcs_cmd,
  779. buf + buf_used, size - buf_used);
  780. if (r < 0) {
  781. dev_err(&dssdev->dev, "read error\n");
  782. goto err;
  783. }
  784. buf_used += r;
  785. if (r < plen) {
  786. dev_err(&dssdev->dev, "short read\n");
  787. break;
  788. }
  789. if (signal_pending(current)) {
  790. dev_err(&dssdev->dev, "signal pending, "
  791. "aborting memory read\n");
  792. r = -ERESTARTSYS;
  793. goto err;
  794. }
  795. }
  796. r = buf_used;
  797. err:
  798. dsi_vc_set_max_rx_packet_size(TCH, 1);
  799. err0:
  800. dsi_bus_unlock();
  801. return r;
  802. }
  803. static void taal_esd_work(struct work_struct *work)
  804. {
  805. struct taal_data *td = container_of(work, struct taal_data,
  806. esd_work.work);
  807. struct omap_dss_device *dssdev = td->dssdev;
  808. u8 state1, state2;
  809. int r;
  810. if (!td->enabled)
  811. return;
  812. dsi_bus_lock();
  813. r = taal_dcs_read_1(DCS_RDDSDR, &state1);
  814. if (r) {
  815. dev_err(&dssdev->dev, "failed to read Taal status\n");
  816. goto err;
  817. }
  818. /* Run self diagnostics */
  819. r = taal_sleep_out(td);
  820. if (r) {
  821. dev_err(&dssdev->dev, "failed to run Taal self-diagnostics\n");
  822. goto err;
  823. }
  824. r = taal_dcs_read_1(DCS_RDDSDR, &state2);
  825. if (r) {
  826. dev_err(&dssdev->dev, "failed to read Taal status\n");
  827. goto err;
  828. }
  829. /* Each sleep out command will trigger a self diagnostic and flip
  830. * Bit6 if the test passes.
  831. */
  832. if (!((state1 ^ state2) & (1 << 6))) {
  833. dev_err(&dssdev->dev, "LCD self diagnostics failed\n");
  834. goto err;
  835. }
  836. /* Self-diagnostics result is also shown on TE GPIO line. We need
  837. * to re-enable TE after self diagnostics */
  838. if (td->use_ext_te && td->te_enabled) {
  839. r = taal_dcs_write_1(DCS_TEAR_ON, 0);
  840. if (r)
  841. goto err;
  842. }
  843. dsi_bus_unlock();
  844. queue_delayed_work(td->esd_wq, &td->esd_work, TAAL_ESD_CHECK_PERIOD);
  845. return;
  846. err:
  847. dev_err(&dssdev->dev, "performing LCD reset\n");
  848. taal_disable(dssdev);
  849. taal_enable(dssdev);
  850. dsi_bus_unlock();
  851. queue_delayed_work(td->esd_wq, &td->esd_work, TAAL_ESD_CHECK_PERIOD);
  852. }
  853. static int taal_set_update_mode(struct omap_dss_device *dssdev,
  854. enum omap_dss_update_mode mode)
  855. {
  856. if (mode != OMAP_DSS_UPDATE_MANUAL)
  857. return -EINVAL;
  858. return 0;
  859. }
  860. static enum omap_dss_update_mode taal_get_update_mode(
  861. struct omap_dss_device *dssdev)
  862. {
  863. return OMAP_DSS_UPDATE_MANUAL;
  864. }
  865. static struct omap_dss_driver taal_driver = {
  866. .probe = taal_probe,
  867. .remove = taal_remove,
  868. .enable = taal_enable,
  869. .disable = taal_disable,
  870. .suspend = taal_suspend,
  871. .resume = taal_resume,
  872. .set_update_mode = taal_set_update_mode,
  873. .get_update_mode = taal_get_update_mode,
  874. .update = taal_update,
  875. .sync = taal_sync,
  876. .get_resolution = taal_get_resolution,
  877. .get_recommended_bpp = omapdss_default_get_recommended_bpp,
  878. .enable_te = taal_enable_te,
  879. .get_te = taal_get_te,
  880. .set_rotate = taal_rotate,
  881. .get_rotate = taal_get_rotate,
  882. .set_mirror = taal_mirror,
  883. .get_mirror = taal_get_mirror,
  884. .run_test = taal_run_test,
  885. .memory_read = taal_memory_read,
  886. .get_timings = taal_get_timings,
  887. .driver = {
  888. .name = "taal",
  889. .owner = THIS_MODULE,
  890. },
  891. };
  892. static int __init taal_init(void)
  893. {
  894. omap_dss_register_driver(&taal_driver);
  895. return 0;
  896. }
  897. static void __exit taal_exit(void)
  898. {
  899. omap_dss_unregister_driver(&taal_driver);
  900. }
  901. module_init(taal_init);
  902. module_exit(taal_exit);
  903. MODULE_AUTHOR("Tomi Valkeinen <tomi.valkeinen@nokia.com>");
  904. MODULE_DESCRIPTION("Taal Driver");
  905. MODULE_LICENSE("GPL");