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. dssdev->get_timings = taal_get_timings;
  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. #ifdef TAAL_USE_ESD_CHECK
  534. queue_delayed_work(td->esd_wq, &td->esd_work, TAAL_ESD_CHECK_PERIOD);
  535. #endif
  536. td->enabled = 1;
  537. if (!td->intro_printed) {
  538. dev_info(&dssdev->dev, "revision %02x.%02x.%02x\n",
  539. id1, id2, id3);
  540. if (td->cabc_broken)
  541. dev_info(&dssdev->dev,
  542. "old Taal version, CABC disabled\n");
  543. td->intro_printed = true;
  544. }
  545. omapdss_dsi_vc_enable_hs(TCH, true);
  546. dsi_bus_unlock();
  547. return 0;
  548. err:
  549. dsi_bus_unlock();
  550. omapdss_dsi_display_disable(dssdev);
  551. err0:
  552. if (dssdev->platform_disable)
  553. dssdev->platform_disable(dssdev);
  554. return r;
  555. }
  556. static void taal_power_off(struct omap_dss_device *dssdev)
  557. {
  558. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  559. dsi_bus_lock();
  560. cancel_delayed_work(&td->esd_work);
  561. taal_dcs_write_0(DCS_DISPLAY_OFF);
  562. taal_sleep_in(td);
  563. /* wait a bit so that the message goes through */
  564. msleep(10);
  565. omapdss_dsi_display_disable(dssdev);
  566. if (dssdev->platform_disable)
  567. dssdev->platform_disable(dssdev);
  568. td->enabled = 0;
  569. dsi_bus_unlock();
  570. }
  571. static int taal_enable(struct omap_dss_device *dssdev)
  572. {
  573. int r;
  574. dev_dbg(&dssdev->dev, "enable\n");
  575. if (dssdev->state != OMAP_DSS_DISPLAY_DISABLED)
  576. return -EINVAL;
  577. r = taal_power_on(dssdev);
  578. if (r)
  579. return r;
  580. dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
  581. return r;
  582. }
  583. static void taal_disable(struct omap_dss_device *dssdev)
  584. {
  585. dev_dbg(&dssdev->dev, "disable\n");
  586. if (dssdev->state == OMAP_DSS_DISPLAY_ACTIVE)
  587. taal_power_off(dssdev);
  588. dssdev->state = OMAP_DSS_DISPLAY_DISABLED;
  589. }
  590. static int taal_suspend(struct omap_dss_device *dssdev)
  591. {
  592. dev_dbg(&dssdev->dev, "suspend\n");
  593. if (dssdev->state != OMAP_DSS_DISPLAY_ACTIVE)
  594. return -EINVAL;
  595. taal_power_off(dssdev);
  596. dssdev->state = OMAP_DSS_DISPLAY_SUSPENDED;
  597. return 0;
  598. }
  599. static int taal_resume(struct omap_dss_device *dssdev)
  600. {
  601. int r;
  602. dev_dbg(&dssdev->dev, "resume\n");
  603. if (dssdev->state != OMAP_DSS_DISPLAY_SUSPENDED)
  604. return -EINVAL;
  605. r = taal_power_on(dssdev);
  606. dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
  607. return r;
  608. }
  609. static void taal_framedone_cb(int err, void *data)
  610. {
  611. struct omap_dss_device *dssdev = data;
  612. dev_dbg(&dssdev->dev, "framedone, err %d\n", err);
  613. dsi_bus_unlock();
  614. }
  615. static int taal_update(struct omap_dss_device *dssdev,
  616. u16 x, u16 y, u16 w, u16 h)
  617. {
  618. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  619. int r;
  620. dev_dbg(&dssdev->dev, "update %d, %d, %d x %d\n", x, y, w, h);
  621. dsi_bus_lock();
  622. if (!td->enabled) {
  623. r = 0;
  624. goto err;
  625. }
  626. r = omap_dsi_prepare_update(dssdev, &x, &y, &w, &h);
  627. if (r)
  628. goto err;
  629. r = taal_set_update_window(x, y, w, h);
  630. if (r)
  631. goto err;
  632. r = omap_dsi_update(dssdev, TCH, x, y, w, h,
  633. taal_framedone_cb, dssdev);
  634. if (r)
  635. goto err;
  636. /* note: no bus_unlock here. unlock is in framedone_cb */
  637. return 0;
  638. err:
  639. dsi_bus_unlock();
  640. return r;
  641. }
  642. static int taal_sync(struct omap_dss_device *dssdev)
  643. {
  644. dev_dbg(&dssdev->dev, "sync\n");
  645. dsi_bus_lock();
  646. dsi_bus_unlock();
  647. dev_dbg(&dssdev->dev, "sync done\n");
  648. return 0;
  649. }
  650. static int taal_enable_te(struct omap_dss_device *dssdev, bool enable)
  651. {
  652. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  653. int r;
  654. dsi_bus_lock();
  655. td->te_enabled = enable;
  656. if (enable)
  657. r = taal_dcs_write_1(DCS_TEAR_ON, 0);
  658. else
  659. r = taal_dcs_write_0(DCS_TEAR_OFF);
  660. omapdss_dsi_enable_te(dssdev, enable);
  661. /* XXX for some reason, DSI TE breaks if we don't wait here.
  662. * Panel bug? Needs more studying */
  663. msleep(100);
  664. dsi_bus_unlock();
  665. return r;
  666. }
  667. static int taal_get_te(struct omap_dss_device *dssdev)
  668. {
  669. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  670. return td->te_enabled;
  671. }
  672. static int taal_rotate(struct omap_dss_device *dssdev, u8 rotate)
  673. {
  674. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  675. int r;
  676. dev_dbg(&dssdev->dev, "rotate %d\n", rotate);
  677. dsi_bus_lock();
  678. if (td->enabled) {
  679. r = taal_set_addr_mode(rotate, td->mirror);
  680. if (r)
  681. goto err;
  682. }
  683. td->rotate = rotate;
  684. dsi_bus_unlock();
  685. return 0;
  686. err:
  687. dsi_bus_unlock();
  688. return r;
  689. }
  690. static u8 taal_get_rotate(struct omap_dss_device *dssdev)
  691. {
  692. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  693. return td->rotate;
  694. }
  695. static int taal_mirror(struct omap_dss_device *dssdev, bool enable)
  696. {
  697. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  698. int r;
  699. dev_dbg(&dssdev->dev, "mirror %d\n", enable);
  700. dsi_bus_lock();
  701. if (td->enabled) {
  702. r = taal_set_addr_mode(td->rotate, enable);
  703. if (r)
  704. goto err;
  705. }
  706. td->mirror = enable;
  707. dsi_bus_unlock();
  708. return 0;
  709. err:
  710. dsi_bus_unlock();
  711. return r;
  712. }
  713. static bool taal_get_mirror(struct omap_dss_device *dssdev)
  714. {
  715. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  716. return td->mirror;
  717. }
  718. static int taal_run_test(struct omap_dss_device *dssdev, int test_num)
  719. {
  720. u8 id1, id2, id3;
  721. int r;
  722. dsi_bus_lock();
  723. r = taal_dcs_read_1(DCS_GET_ID1, &id1);
  724. if (r)
  725. goto err;
  726. r = taal_dcs_read_1(DCS_GET_ID2, &id2);
  727. if (r)
  728. goto err;
  729. r = taal_dcs_read_1(DCS_GET_ID3, &id3);
  730. if (r)
  731. goto err;
  732. dsi_bus_unlock();
  733. return 0;
  734. err:
  735. dsi_bus_unlock();
  736. return r;
  737. }
  738. static int taal_memory_read(struct omap_dss_device *dssdev,
  739. void *buf, size_t size,
  740. u16 x, u16 y, u16 w, u16 h)
  741. {
  742. int r;
  743. int first = 1;
  744. int plen;
  745. unsigned buf_used = 0;
  746. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  747. if (!td->enabled)
  748. return -ENODEV;
  749. if (size < w * h * 3)
  750. return -ENOMEM;
  751. size = min(w * h * 3,
  752. dssdev->panel.timings.x_res *
  753. dssdev->panel.timings.y_res * 3);
  754. dsi_bus_lock();
  755. /* plen 1 or 2 goes into short packet. until checksum error is fixed,
  756. * use short packets. plen 32 works, but bigger packets seem to cause
  757. * an error. */
  758. if (size % 2)
  759. plen = 1;
  760. else
  761. plen = 2;
  762. taal_set_update_window(x, y, w, h);
  763. r = dsi_vc_set_max_rx_packet_size(TCH, plen);
  764. if (r)
  765. goto err0;
  766. while (buf_used < size) {
  767. u8 dcs_cmd = first ? 0x2e : 0x3e;
  768. first = 0;
  769. r = dsi_vc_dcs_read(TCH, dcs_cmd,
  770. buf + buf_used, size - buf_used);
  771. if (r < 0) {
  772. dev_err(&dssdev->dev, "read error\n");
  773. goto err;
  774. }
  775. buf_used += r;
  776. if (r < plen) {
  777. dev_err(&dssdev->dev, "short read\n");
  778. break;
  779. }
  780. if (signal_pending(current)) {
  781. dev_err(&dssdev->dev, "signal pending, "
  782. "aborting memory read\n");
  783. r = -ERESTARTSYS;
  784. goto err;
  785. }
  786. }
  787. r = buf_used;
  788. err:
  789. dsi_vc_set_max_rx_packet_size(TCH, 1);
  790. err0:
  791. dsi_bus_unlock();
  792. return r;
  793. }
  794. static void taal_esd_work(struct work_struct *work)
  795. {
  796. struct taal_data *td = container_of(work, struct taal_data,
  797. esd_work.work);
  798. struct omap_dss_device *dssdev = td->dssdev;
  799. u8 state1, state2;
  800. int r;
  801. if (!td->enabled)
  802. return;
  803. dsi_bus_lock();
  804. r = taal_dcs_read_1(DCS_RDDSDR, &state1);
  805. if (r) {
  806. dev_err(&dssdev->dev, "failed to read Taal status\n");
  807. goto err;
  808. }
  809. /* Run self diagnostics */
  810. r = taal_sleep_out(td);
  811. if (r) {
  812. dev_err(&dssdev->dev, "failed to run Taal self-diagnostics\n");
  813. goto err;
  814. }
  815. r = taal_dcs_read_1(DCS_RDDSDR, &state2);
  816. if (r) {
  817. dev_err(&dssdev->dev, "failed to read Taal status\n");
  818. goto err;
  819. }
  820. /* Each sleep out command will trigger a self diagnostic and flip
  821. * Bit6 if the test passes.
  822. */
  823. if (!((state1 ^ state2) & (1 << 6))) {
  824. dev_err(&dssdev->dev, "LCD self diagnostics failed\n");
  825. goto err;
  826. }
  827. /* Self-diagnostics result is also shown on TE GPIO line. We need
  828. * to re-enable TE after self diagnostics */
  829. if (td->use_ext_te && td->te_enabled)
  830. taal_enable_te(dssdev, true);
  831. dsi_bus_unlock();
  832. queue_delayed_work(td->esd_wq, &td->esd_work, TAAL_ESD_CHECK_PERIOD);
  833. return;
  834. err:
  835. dev_err(&dssdev->dev, "performing LCD reset\n");
  836. taal_disable(dssdev);
  837. taal_enable(dssdev);
  838. dsi_bus_unlock();
  839. queue_delayed_work(td->esd_wq, &td->esd_work, TAAL_ESD_CHECK_PERIOD);
  840. }
  841. static int taal_set_update_mode(struct omap_dss_device *dssdev,
  842. enum omap_dss_update_mode mode)
  843. {
  844. if (mode != OMAP_DSS_UPDATE_MANUAL)
  845. return -EINVAL;
  846. return 0;
  847. }
  848. static enum omap_dss_update_mode taal_get_update_mode(
  849. struct omap_dss_device *dssdev)
  850. {
  851. return OMAP_DSS_UPDATE_MANUAL;
  852. }
  853. static struct omap_dss_driver taal_driver = {
  854. .probe = taal_probe,
  855. .remove = taal_remove,
  856. .enable = taal_enable,
  857. .disable = taal_disable,
  858. .suspend = taal_suspend,
  859. .resume = taal_resume,
  860. .set_update_mode = taal_set_update_mode,
  861. .get_update_mode = taal_get_update_mode,
  862. .update = taal_update,
  863. .sync = taal_sync,
  864. .get_resolution = taal_get_resolution,
  865. .get_recommended_bpp = omapdss_default_get_recommended_bpp,
  866. .enable_te = taal_enable_te,
  867. .get_te = taal_get_te,
  868. .set_rotate = taal_rotate,
  869. .get_rotate = taal_get_rotate,
  870. .set_mirror = taal_mirror,
  871. .get_mirror = taal_get_mirror,
  872. .run_test = taal_run_test,
  873. .memory_read = taal_memory_read,
  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");