panel-taal.c 22 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144
  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 err1;
  413. }
  414. INIT_DELAYED_WORK_DEFERRABLE(&td->esd_work, taal_esd_work);
  415. dev_set_drvdata(&dssdev->dev, td);
  416. /* if no platform set_backlight() defined, presume DSI backlight
  417. * control */
  418. if (!dssdev->set_backlight)
  419. td->use_dsi_bl = true;
  420. bldev = backlight_device_register("taal", &dssdev->dev, dssdev,
  421. &taal_bl_ops);
  422. if (IS_ERR(bldev)) {
  423. r = PTR_ERR(bldev);
  424. goto err2;
  425. }
  426. td->bldev = bldev;
  427. bldev->props.fb_blank = FB_BLANK_UNBLANK;
  428. bldev->props.power = FB_BLANK_UNBLANK;
  429. if (td->use_dsi_bl) {
  430. bldev->props.max_brightness = 255;
  431. bldev->props.brightness = 255;
  432. } else {
  433. bldev->props.max_brightness = 127;
  434. bldev->props.brightness = 127;
  435. }
  436. taal_bl_update_status(bldev);
  437. if (dssdev->phy.dsi.ext_te) {
  438. int gpio = dssdev->phy.dsi.ext_te_gpio;
  439. r = gpio_request(gpio, "taal irq");
  440. if (r) {
  441. dev_err(&dssdev->dev, "GPIO request failed\n");
  442. goto err3;
  443. }
  444. gpio_direction_input(gpio);
  445. r = request_irq(gpio_to_irq(gpio), taal_te_isr,
  446. IRQF_DISABLED | IRQF_TRIGGER_RISING,
  447. "taal vsync", dssdev);
  448. if (r) {
  449. dev_err(&dssdev->dev, "IRQ request failed\n");
  450. gpio_free(gpio);
  451. goto err3;
  452. }
  453. init_completion(&td->te_completion);
  454. td->use_ext_te = true;
  455. }
  456. r = sysfs_create_group(&dssdev->dev.kobj, &taal_attr_group);
  457. if (r) {
  458. dev_err(&dssdev->dev, "failed to create sysfs files\n");
  459. goto err4;
  460. }
  461. return 0;
  462. err4:
  463. if (td->use_ext_te) {
  464. int gpio = dssdev->phy.dsi.ext_te_gpio;
  465. free_irq(gpio_to_irq(gpio), dssdev);
  466. gpio_free(gpio);
  467. }
  468. err3:
  469. backlight_device_unregister(bldev);
  470. err2:
  471. cancel_delayed_work_sync(&td->esd_work);
  472. destroy_workqueue(td->esd_wq);
  473. err1:
  474. kfree(td);
  475. err0:
  476. return r;
  477. }
  478. static void taal_remove(struct omap_dss_device *dssdev)
  479. {
  480. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  481. struct backlight_device *bldev;
  482. dev_dbg(&dssdev->dev, "remove\n");
  483. sysfs_remove_group(&dssdev->dev.kobj, &taal_attr_group);
  484. if (td->use_ext_te) {
  485. int gpio = dssdev->phy.dsi.ext_te_gpio;
  486. free_irq(gpio_to_irq(gpio), dssdev);
  487. gpio_free(gpio);
  488. }
  489. bldev = td->bldev;
  490. bldev->props.power = FB_BLANK_POWERDOWN;
  491. taal_bl_update_status(bldev);
  492. backlight_device_unregister(bldev);
  493. cancel_delayed_work_sync(&td->esd_work);
  494. destroy_workqueue(td->esd_wq);
  495. kfree(td);
  496. }
  497. static int taal_power_on(struct omap_dss_device *dssdev)
  498. {
  499. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  500. u8 id1, id2, id3;
  501. int r;
  502. if (dssdev->platform_enable) {
  503. r = dssdev->platform_enable(dssdev);
  504. if (r)
  505. return r;
  506. }
  507. /* it seems we have to wait a bit until taal is ready */
  508. msleep(5);
  509. dsi_bus_lock();
  510. r = omapdss_dsi_display_enable(dssdev);
  511. if (r) {
  512. dev_err(&dssdev->dev, "failed to enable DSI\n");
  513. goto err0;
  514. }
  515. omapdss_dsi_vc_enable_hs(TCH, false);
  516. r = taal_sleep_out(td);
  517. if (r)
  518. goto err;
  519. r = taal_get_id(&id1, &id2, &id3);
  520. if (r)
  521. goto err;
  522. /* on early revisions CABC is broken */
  523. if (id2 == 0x00 || id2 == 0xff || id2 == 0x81)
  524. td->cabc_broken = true;
  525. taal_dcs_write_1(DCS_BRIGHTNESS, 0xff);
  526. taal_dcs_write_1(DCS_CTRL_DISPLAY, (1<<2) | (1<<5)); /* BL | BCTRL */
  527. taal_dcs_write_1(DCS_PIXEL_FORMAT, 0x7); /* 24bit/pixel */
  528. taal_set_addr_mode(td->rotate, td->mirror);
  529. if (!td->cabc_broken)
  530. taal_dcs_write_1(DCS_WRITE_CABC, td->cabc_mode);
  531. taal_dcs_write_0(DCS_DISPLAY_ON);
  532. #ifdef TAAL_USE_ESD_CHECK
  533. queue_delayed_work(td->esd_wq, &td->esd_work, TAAL_ESD_CHECK_PERIOD);
  534. #endif
  535. td->enabled = 1;
  536. if (!td->intro_printed) {
  537. dev_info(&dssdev->dev, "revision %02x.%02x.%02x\n",
  538. id1, id2, id3);
  539. if (td->cabc_broken)
  540. dev_info(&dssdev->dev,
  541. "old Taal version, CABC disabled\n");
  542. td->intro_printed = true;
  543. }
  544. omapdss_dsi_vc_enable_hs(TCH, true);
  545. dsi_bus_unlock();
  546. return 0;
  547. err:
  548. dsi_bus_unlock();
  549. omapdss_dsi_display_disable(dssdev);
  550. err0:
  551. if (dssdev->platform_disable)
  552. dssdev->platform_disable(dssdev);
  553. return r;
  554. }
  555. static void taal_power_off(struct omap_dss_device *dssdev)
  556. {
  557. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  558. dsi_bus_lock();
  559. cancel_delayed_work(&td->esd_work);
  560. taal_dcs_write_0(DCS_DISPLAY_OFF);
  561. taal_sleep_in(td);
  562. /* wait a bit so that the message goes through */
  563. msleep(10);
  564. omapdss_dsi_display_disable(dssdev);
  565. if (dssdev->platform_disable)
  566. dssdev->platform_disable(dssdev);
  567. td->enabled = 0;
  568. dsi_bus_unlock();
  569. }
  570. static int taal_enable(struct omap_dss_device *dssdev)
  571. {
  572. int r;
  573. dev_dbg(&dssdev->dev, "enable\n");
  574. if (dssdev->state != OMAP_DSS_DISPLAY_DISABLED)
  575. return -EINVAL;
  576. r = taal_power_on(dssdev);
  577. if (r)
  578. return r;
  579. dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
  580. return r;
  581. }
  582. static void taal_disable(struct omap_dss_device *dssdev)
  583. {
  584. dev_dbg(&dssdev->dev, "disable\n");
  585. if (dssdev->state == OMAP_DSS_DISPLAY_ACTIVE)
  586. taal_power_off(dssdev);
  587. dssdev->state = OMAP_DSS_DISPLAY_DISABLED;
  588. }
  589. static int taal_suspend(struct omap_dss_device *dssdev)
  590. {
  591. dev_dbg(&dssdev->dev, "suspend\n");
  592. if (dssdev->state != OMAP_DSS_DISPLAY_ACTIVE)
  593. return -EINVAL;
  594. taal_power_off(dssdev);
  595. dssdev->state = OMAP_DSS_DISPLAY_SUSPENDED;
  596. return 0;
  597. }
  598. static int taal_resume(struct omap_dss_device *dssdev)
  599. {
  600. int r;
  601. dev_dbg(&dssdev->dev, "resume\n");
  602. if (dssdev->state != OMAP_DSS_DISPLAY_SUSPENDED)
  603. return -EINVAL;
  604. r = taal_power_on(dssdev);
  605. dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
  606. return r;
  607. }
  608. static void taal_framedone_cb(int err, void *data)
  609. {
  610. struct omap_dss_device *dssdev = data;
  611. dev_dbg(&dssdev->dev, "framedone, err %d\n", err);
  612. dsi_bus_unlock();
  613. }
  614. static int taal_update(struct omap_dss_device *dssdev,
  615. u16 x, u16 y, u16 w, u16 h)
  616. {
  617. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  618. int r;
  619. dev_dbg(&dssdev->dev, "update %d, %d, %d x %d\n", x, y, w, h);
  620. dsi_bus_lock();
  621. if (!td->enabled) {
  622. r = 0;
  623. goto err;
  624. }
  625. r = omap_dsi_prepare_update(dssdev, &x, &y, &w, &h);
  626. if (r)
  627. goto err;
  628. r = taal_set_update_window(x, y, w, h);
  629. if (r)
  630. goto err;
  631. r = omap_dsi_update(dssdev, TCH, x, y, w, h,
  632. taal_framedone_cb, dssdev);
  633. if (r)
  634. goto err;
  635. /* note: no bus_unlock here. unlock is in framedone_cb */
  636. return 0;
  637. err:
  638. dsi_bus_unlock();
  639. return r;
  640. }
  641. static int taal_sync(struct omap_dss_device *dssdev)
  642. {
  643. dev_dbg(&dssdev->dev, "sync\n");
  644. dsi_bus_lock();
  645. dsi_bus_unlock();
  646. dev_dbg(&dssdev->dev, "sync done\n");
  647. return 0;
  648. }
  649. static int taal_enable_te(struct omap_dss_device *dssdev, bool enable)
  650. {
  651. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  652. int r;
  653. dsi_bus_lock();
  654. td->te_enabled = enable;
  655. if (enable)
  656. r = taal_dcs_write_1(DCS_TEAR_ON, 0);
  657. else
  658. r = taal_dcs_write_0(DCS_TEAR_OFF);
  659. omapdss_dsi_enable_te(dssdev, enable);
  660. /* XXX for some reason, DSI TE breaks if we don't wait here.
  661. * Panel bug? Needs more studying */
  662. msleep(100);
  663. dsi_bus_unlock();
  664. return r;
  665. }
  666. static int taal_get_te(struct omap_dss_device *dssdev)
  667. {
  668. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  669. return td->te_enabled;
  670. }
  671. static int taal_rotate(struct omap_dss_device *dssdev, u8 rotate)
  672. {
  673. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  674. int r;
  675. dev_dbg(&dssdev->dev, "rotate %d\n", rotate);
  676. dsi_bus_lock();
  677. if (td->enabled) {
  678. r = taal_set_addr_mode(rotate, td->mirror);
  679. if (r)
  680. goto err;
  681. }
  682. td->rotate = rotate;
  683. dsi_bus_unlock();
  684. return 0;
  685. err:
  686. dsi_bus_unlock();
  687. return r;
  688. }
  689. static u8 taal_get_rotate(struct omap_dss_device *dssdev)
  690. {
  691. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  692. return td->rotate;
  693. }
  694. static int taal_mirror(struct omap_dss_device *dssdev, bool enable)
  695. {
  696. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  697. int r;
  698. dev_dbg(&dssdev->dev, "mirror %d\n", enable);
  699. dsi_bus_lock();
  700. if (td->enabled) {
  701. r = taal_set_addr_mode(td->rotate, enable);
  702. if (r)
  703. goto err;
  704. }
  705. td->mirror = enable;
  706. dsi_bus_unlock();
  707. return 0;
  708. err:
  709. dsi_bus_unlock();
  710. return r;
  711. }
  712. static bool taal_get_mirror(struct omap_dss_device *dssdev)
  713. {
  714. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  715. return td->mirror;
  716. }
  717. static int taal_run_test(struct omap_dss_device *dssdev, int test_num)
  718. {
  719. u8 id1, id2, id3;
  720. int r;
  721. dsi_bus_lock();
  722. r = taal_dcs_read_1(DCS_GET_ID1, &id1);
  723. if (r)
  724. goto err;
  725. r = taal_dcs_read_1(DCS_GET_ID2, &id2);
  726. if (r)
  727. goto err;
  728. r = taal_dcs_read_1(DCS_GET_ID3, &id3);
  729. if (r)
  730. goto err;
  731. dsi_bus_unlock();
  732. return 0;
  733. err:
  734. dsi_bus_unlock();
  735. return r;
  736. }
  737. static int taal_memory_read(struct omap_dss_device *dssdev,
  738. void *buf, size_t size,
  739. u16 x, u16 y, u16 w, u16 h)
  740. {
  741. int r;
  742. int first = 1;
  743. int plen;
  744. unsigned buf_used = 0;
  745. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  746. if (!td->enabled)
  747. return -ENODEV;
  748. if (size < w * h * 3)
  749. return -ENOMEM;
  750. size = min(w * h * 3,
  751. dssdev->panel.timings.x_res *
  752. dssdev->panel.timings.y_res * 3);
  753. dsi_bus_lock();
  754. /* plen 1 or 2 goes into short packet. until checksum error is fixed,
  755. * use short packets. plen 32 works, but bigger packets seem to cause
  756. * an error. */
  757. if (size % 2)
  758. plen = 1;
  759. else
  760. plen = 2;
  761. taal_set_update_window(x, y, w, h);
  762. r = dsi_vc_set_max_rx_packet_size(TCH, plen);
  763. if (r)
  764. goto err0;
  765. while (buf_used < size) {
  766. u8 dcs_cmd = first ? 0x2e : 0x3e;
  767. first = 0;
  768. r = dsi_vc_dcs_read(TCH, dcs_cmd,
  769. buf + buf_used, size - buf_used);
  770. if (r < 0) {
  771. dev_err(&dssdev->dev, "read error\n");
  772. goto err;
  773. }
  774. buf_used += r;
  775. if (r < plen) {
  776. dev_err(&dssdev->dev, "short read\n");
  777. break;
  778. }
  779. if (signal_pending(current)) {
  780. dev_err(&dssdev->dev, "signal pending, "
  781. "aborting memory read\n");
  782. r = -ERESTARTSYS;
  783. goto err;
  784. }
  785. }
  786. r = buf_used;
  787. err:
  788. dsi_vc_set_max_rx_packet_size(TCH, 1);
  789. err0:
  790. dsi_bus_unlock();
  791. return r;
  792. }
  793. static void taal_esd_work(struct work_struct *work)
  794. {
  795. struct taal_data *td = container_of(work, struct taal_data,
  796. esd_work.work);
  797. struct omap_dss_device *dssdev = td->dssdev;
  798. u8 state1, state2;
  799. int r;
  800. if (!td->enabled)
  801. return;
  802. dsi_bus_lock();
  803. r = taal_dcs_read_1(DCS_RDDSDR, &state1);
  804. if (r) {
  805. dev_err(&dssdev->dev, "failed to read Taal status\n");
  806. goto err;
  807. }
  808. /* Run self diagnostics */
  809. r = taal_sleep_out(td);
  810. if (r) {
  811. dev_err(&dssdev->dev, "failed to run Taal self-diagnostics\n");
  812. goto err;
  813. }
  814. r = taal_dcs_read_1(DCS_RDDSDR, &state2);
  815. if (r) {
  816. dev_err(&dssdev->dev, "failed to read Taal status\n");
  817. goto err;
  818. }
  819. /* Each sleep out command will trigger a self diagnostic and flip
  820. * Bit6 if the test passes.
  821. */
  822. if (!((state1 ^ state2) & (1 << 6))) {
  823. dev_err(&dssdev->dev, "LCD self diagnostics failed\n");
  824. goto err;
  825. }
  826. /* Self-diagnostics result is also shown on TE GPIO line. We need
  827. * to re-enable TE after self diagnostics */
  828. if (td->use_ext_te && td->te_enabled)
  829. taal_enable_te(dssdev, true);
  830. dsi_bus_unlock();
  831. queue_delayed_work(td->esd_wq, &td->esd_work, TAAL_ESD_CHECK_PERIOD);
  832. return;
  833. err:
  834. dev_err(&dssdev->dev, "performing LCD reset\n");
  835. taal_disable(dssdev);
  836. taal_enable(dssdev);
  837. dsi_bus_unlock();
  838. queue_delayed_work(td->esd_wq, &td->esd_work, TAAL_ESD_CHECK_PERIOD);
  839. }
  840. static int taal_set_update_mode(struct omap_dss_device *dssdev,
  841. enum omap_dss_update_mode mode)
  842. {
  843. if (mode != OMAP_DSS_UPDATE_MANUAL)
  844. return -EINVAL;
  845. return 0;
  846. }
  847. static enum omap_dss_update_mode taal_get_update_mode(
  848. struct omap_dss_device *dssdev)
  849. {
  850. return OMAP_DSS_UPDATE_MANUAL;
  851. }
  852. static struct omap_dss_driver taal_driver = {
  853. .probe = taal_probe,
  854. .remove = taal_remove,
  855. .enable = taal_enable,
  856. .disable = taal_disable,
  857. .suspend = taal_suspend,
  858. .resume = taal_resume,
  859. .set_update_mode = taal_set_update_mode,
  860. .get_update_mode = taal_get_update_mode,
  861. .update = taal_update,
  862. .sync = taal_sync,
  863. .get_resolution = taal_get_resolution,
  864. .get_recommended_bpp = omapdss_default_get_recommended_bpp,
  865. .enable_te = taal_enable_te,
  866. .get_te = taal_get_te,
  867. .set_rotate = taal_rotate,
  868. .get_rotate = taal_get_rotate,
  869. .set_mirror = taal_mirror,
  870. .get_mirror = taal_get_mirror,
  871. .run_test = taal_run_test,
  872. .memory_read = taal_memory_read,
  873. .get_timings = taal_get_timings,
  874. .driver = {
  875. .name = "taal",
  876. .owner = THIS_MODULE,
  877. },
  878. };
  879. static int __init taal_init(void)
  880. {
  881. omap_dss_register_driver(&taal_driver);
  882. return 0;
  883. }
  884. static void __exit taal_exit(void)
  885. {
  886. omap_dss_unregister_driver(&taal_driver);
  887. }
  888. module_init(taal_init);
  889. module_exit(taal_exit);
  890. MODULE_AUTHOR("Tomi Valkeinen <tomi.valkeinen@nokia.com>");
  891. MODULE_DESCRIPTION("Taal Driver");
  892. MODULE_LICENSE("GPL");