panel-taal.c 20 KB

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