panel-taal.c 31 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546
  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/workqueue.h>
  30. #include <linux/slab.h>
  31. #include <linux/mutex.h>
  32. #include <video/omapdss.h>
  33. #include <video/omap-panel-nokia-dsi.h>
  34. #include <video/mipi_display.h>
  35. /* DSI Virtual channel. Hardcoded for now. */
  36. #define TCH 0
  37. #define DCS_READ_NUM_ERRORS 0x05
  38. #define DCS_BRIGHTNESS 0x51
  39. #define DCS_CTRL_DISPLAY 0x53
  40. #define DCS_WRITE_CABC 0x55
  41. #define DCS_READ_CABC 0x56
  42. #define DCS_GET_ID1 0xda
  43. #define DCS_GET_ID2 0xdb
  44. #define DCS_GET_ID3 0xdc
  45. static irqreturn_t taal_te_isr(int irq, void *data);
  46. static void taal_te_timeout_work_callback(struct work_struct *work);
  47. static int _taal_enable_te(struct omap_dss_device *dssdev, bool enable);
  48. static int taal_panel_reset(struct omap_dss_device *dssdev);
  49. struct taal_data {
  50. struct mutex lock;
  51. struct backlight_device *bldev;
  52. unsigned long hw_guard_end; /* next value of jiffies when we can
  53. * issue the next sleep in/out command
  54. */
  55. unsigned long hw_guard_wait; /* max guard time in jiffies */
  56. struct omap_dss_device *dssdev;
  57. /* panel HW configuration from DT or platform data */
  58. int reset_gpio;
  59. int ext_te_gpio;
  60. bool use_dsi_backlight;
  61. struct omap_dsi_pin_config pin_config;
  62. /* runtime variables */
  63. bool enabled;
  64. bool te_enabled;
  65. atomic_t do_update;
  66. int channel;
  67. struct delayed_work te_timeout_work;
  68. bool cabc_broken;
  69. unsigned cabc_mode;
  70. bool intro_printed;
  71. struct workqueue_struct *workqueue;
  72. struct delayed_work esd_work;
  73. unsigned esd_interval;
  74. bool ulps_enabled;
  75. unsigned ulps_timeout;
  76. struct delayed_work ulps_work;
  77. };
  78. static void taal_esd_work(struct work_struct *work);
  79. static void taal_ulps_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(struct taal_data *td, u8 dcs_cmd, u8 *data)
  94. {
  95. int r;
  96. u8 buf[1];
  97. r = dsi_vc_dcs_read(td->dssdev, td->channel, 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(struct taal_data *td, u8 dcs_cmd)
  104. {
  105. return dsi_vc_dcs_write(td->dssdev, td->channel, &dcs_cmd, 1);
  106. }
  107. static int taal_dcs_write_1(struct taal_data *td, 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(td->dssdev, td->channel, 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 = MIPI_DCS_ENTER_SLEEP_MODE;
  120. r = dsi_vc_dcs_write_nosync(td->dssdev, td->channel, &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(td, MIPI_DCS_EXIT_SLEEP_MODE);
  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(struct taal_data *td, u8 *id1, u8 *id2, u8 *id3)
  139. {
  140. int r;
  141. r = taal_dcs_read_1(td, DCS_GET_ID1, id1);
  142. if (r)
  143. return r;
  144. r = taal_dcs_read_1(td, DCS_GET_ID2, id2);
  145. if (r)
  146. return r;
  147. r = taal_dcs_read_1(td, DCS_GET_ID3, id3);
  148. if (r)
  149. return r;
  150. return 0;
  151. }
  152. static int taal_set_update_window(struct taal_data *td,
  153. u16 x, u16 y, u16 w, u16 h)
  154. {
  155. int r;
  156. u16 x1 = x;
  157. u16 x2 = x + w - 1;
  158. u16 y1 = y;
  159. u16 y2 = y + h - 1;
  160. u8 buf[5];
  161. buf[0] = MIPI_DCS_SET_COLUMN_ADDRESS;
  162. buf[1] = (x1 >> 8) & 0xff;
  163. buf[2] = (x1 >> 0) & 0xff;
  164. buf[3] = (x2 >> 8) & 0xff;
  165. buf[4] = (x2 >> 0) & 0xff;
  166. r = dsi_vc_dcs_write_nosync(td->dssdev, td->channel, buf, sizeof(buf));
  167. if (r)
  168. return r;
  169. buf[0] = MIPI_DCS_SET_PAGE_ADDRESS;
  170. buf[1] = (y1 >> 8) & 0xff;
  171. buf[2] = (y1 >> 0) & 0xff;
  172. buf[3] = (y2 >> 8) & 0xff;
  173. buf[4] = (y2 >> 0) & 0xff;
  174. r = dsi_vc_dcs_write_nosync(td->dssdev, td->channel, buf, sizeof(buf));
  175. if (r)
  176. return r;
  177. dsi_vc_send_bta_sync(td->dssdev, td->channel);
  178. return r;
  179. }
  180. static void taal_queue_esd_work(struct omap_dss_device *dssdev)
  181. {
  182. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  183. if (td->esd_interval > 0)
  184. queue_delayed_work(td->workqueue, &td->esd_work,
  185. msecs_to_jiffies(td->esd_interval));
  186. }
  187. static void taal_cancel_esd_work(struct omap_dss_device *dssdev)
  188. {
  189. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  190. cancel_delayed_work(&td->esd_work);
  191. }
  192. static void taal_queue_ulps_work(struct omap_dss_device *dssdev)
  193. {
  194. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  195. if (td->ulps_timeout > 0)
  196. queue_delayed_work(td->workqueue, &td->ulps_work,
  197. msecs_to_jiffies(td->ulps_timeout));
  198. }
  199. static void taal_cancel_ulps_work(struct omap_dss_device *dssdev)
  200. {
  201. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  202. cancel_delayed_work(&td->ulps_work);
  203. }
  204. static int taal_enter_ulps(struct omap_dss_device *dssdev)
  205. {
  206. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  207. int r;
  208. if (td->ulps_enabled)
  209. return 0;
  210. taal_cancel_ulps_work(dssdev);
  211. r = _taal_enable_te(dssdev, false);
  212. if (r)
  213. goto err;
  214. if (gpio_is_valid(td->ext_te_gpio))
  215. disable_irq(gpio_to_irq(td->ext_te_gpio));
  216. omapdss_dsi_display_disable(dssdev, false, true);
  217. td->ulps_enabled = true;
  218. return 0;
  219. err:
  220. dev_err(&dssdev->dev, "enter ULPS failed");
  221. taal_panel_reset(dssdev);
  222. td->ulps_enabled = false;
  223. taal_queue_ulps_work(dssdev);
  224. return r;
  225. }
  226. static int taal_exit_ulps(struct omap_dss_device *dssdev)
  227. {
  228. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  229. int r;
  230. if (!td->ulps_enabled)
  231. return 0;
  232. r = omapdss_dsi_display_enable(dssdev);
  233. if (r) {
  234. dev_err(&dssdev->dev, "failed to enable DSI\n");
  235. goto err1;
  236. }
  237. omapdss_dsi_vc_enable_hs(dssdev, td->channel, true);
  238. r = _taal_enable_te(dssdev, true);
  239. if (r) {
  240. dev_err(&dssdev->dev, "failed to re-enable TE");
  241. goto err2;
  242. }
  243. if (gpio_is_valid(td->ext_te_gpio))
  244. enable_irq(gpio_to_irq(td->ext_te_gpio));
  245. taal_queue_ulps_work(dssdev);
  246. td->ulps_enabled = false;
  247. return 0;
  248. err2:
  249. dev_err(&dssdev->dev, "failed to exit ULPS");
  250. r = taal_panel_reset(dssdev);
  251. if (!r) {
  252. if (gpio_is_valid(td->ext_te_gpio))
  253. enable_irq(gpio_to_irq(td->ext_te_gpio));
  254. td->ulps_enabled = false;
  255. }
  256. err1:
  257. taal_queue_ulps_work(dssdev);
  258. return r;
  259. }
  260. static int taal_wake_up(struct omap_dss_device *dssdev)
  261. {
  262. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  263. if (td->ulps_enabled)
  264. return taal_exit_ulps(dssdev);
  265. taal_cancel_ulps_work(dssdev);
  266. taal_queue_ulps_work(dssdev);
  267. return 0;
  268. }
  269. static int taal_bl_update_status(struct backlight_device *dev)
  270. {
  271. struct omap_dss_device *dssdev = dev_get_drvdata(&dev->dev);
  272. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  273. int r;
  274. int level;
  275. if (dev->props.fb_blank == FB_BLANK_UNBLANK &&
  276. dev->props.power == FB_BLANK_UNBLANK)
  277. level = dev->props.brightness;
  278. else
  279. level = 0;
  280. dev_dbg(&dssdev->dev, "update brightness to %d\n", level);
  281. mutex_lock(&td->lock);
  282. if (td->enabled) {
  283. dsi_bus_lock(dssdev);
  284. r = taal_wake_up(dssdev);
  285. if (!r)
  286. r = taal_dcs_write_1(td, DCS_BRIGHTNESS, level);
  287. dsi_bus_unlock(dssdev);
  288. } else {
  289. r = 0;
  290. }
  291. mutex_unlock(&td->lock);
  292. return r;
  293. }
  294. static int taal_bl_get_intensity(struct backlight_device *dev)
  295. {
  296. if (dev->props.fb_blank == FB_BLANK_UNBLANK &&
  297. dev->props.power == FB_BLANK_UNBLANK)
  298. return dev->props.brightness;
  299. return 0;
  300. }
  301. static const struct backlight_ops taal_bl_ops = {
  302. .get_brightness = taal_bl_get_intensity,
  303. .update_status = taal_bl_update_status,
  304. };
  305. static void taal_get_resolution(struct omap_dss_device *dssdev,
  306. u16 *xres, u16 *yres)
  307. {
  308. *xres = dssdev->panel.timings.x_res;
  309. *yres = dssdev->panel.timings.y_res;
  310. }
  311. static ssize_t taal_num_errors_show(struct device *dev,
  312. struct device_attribute *attr, char *buf)
  313. {
  314. struct omap_dss_device *dssdev = to_dss_device(dev);
  315. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  316. u8 errors = 0;
  317. int r;
  318. mutex_lock(&td->lock);
  319. if (td->enabled) {
  320. dsi_bus_lock(dssdev);
  321. r = taal_wake_up(dssdev);
  322. if (!r)
  323. r = taal_dcs_read_1(td, DCS_READ_NUM_ERRORS, &errors);
  324. dsi_bus_unlock(dssdev);
  325. } else {
  326. r = -ENODEV;
  327. }
  328. mutex_unlock(&td->lock);
  329. if (r)
  330. return r;
  331. return snprintf(buf, PAGE_SIZE, "%d\n", errors);
  332. }
  333. static ssize_t taal_hw_revision_show(struct device *dev,
  334. struct device_attribute *attr, char *buf)
  335. {
  336. struct omap_dss_device *dssdev = to_dss_device(dev);
  337. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  338. u8 id1, id2, id3;
  339. int r;
  340. mutex_lock(&td->lock);
  341. if (td->enabled) {
  342. dsi_bus_lock(dssdev);
  343. r = taal_wake_up(dssdev);
  344. if (!r)
  345. r = taal_get_id(td, &id1, &id2, &id3);
  346. dsi_bus_unlock(dssdev);
  347. } else {
  348. r = -ENODEV;
  349. }
  350. mutex_unlock(&td->lock);
  351. if (r)
  352. return r;
  353. return snprintf(buf, PAGE_SIZE, "%02x.%02x.%02x\n", id1, id2, id3);
  354. }
  355. static const char *cabc_modes[] = {
  356. "off", /* used also always when CABC is not supported */
  357. "ui",
  358. "still-image",
  359. "moving-image",
  360. };
  361. static ssize_t show_cabc_mode(struct device *dev,
  362. struct device_attribute *attr,
  363. char *buf)
  364. {
  365. struct omap_dss_device *dssdev = to_dss_device(dev);
  366. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  367. const char *mode_str;
  368. int mode;
  369. int len;
  370. mode = td->cabc_mode;
  371. mode_str = "unknown";
  372. if (mode >= 0 && mode < ARRAY_SIZE(cabc_modes))
  373. mode_str = cabc_modes[mode];
  374. len = snprintf(buf, PAGE_SIZE, "%s\n", mode_str);
  375. return len < PAGE_SIZE - 1 ? len : PAGE_SIZE - 1;
  376. }
  377. static ssize_t store_cabc_mode(struct device *dev,
  378. struct device_attribute *attr,
  379. const char *buf, size_t count)
  380. {
  381. struct omap_dss_device *dssdev = to_dss_device(dev);
  382. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  383. int i;
  384. int r;
  385. for (i = 0; i < ARRAY_SIZE(cabc_modes); i++) {
  386. if (sysfs_streq(cabc_modes[i], buf))
  387. break;
  388. }
  389. if (i == ARRAY_SIZE(cabc_modes))
  390. return -EINVAL;
  391. mutex_lock(&td->lock);
  392. if (td->enabled) {
  393. dsi_bus_lock(dssdev);
  394. if (!td->cabc_broken) {
  395. r = taal_wake_up(dssdev);
  396. if (r)
  397. goto err;
  398. r = taal_dcs_write_1(td, DCS_WRITE_CABC, i);
  399. if (r)
  400. goto err;
  401. }
  402. dsi_bus_unlock(dssdev);
  403. }
  404. td->cabc_mode = i;
  405. mutex_unlock(&td->lock);
  406. return count;
  407. err:
  408. dsi_bus_unlock(dssdev);
  409. mutex_unlock(&td->lock);
  410. return r;
  411. }
  412. static ssize_t show_cabc_available_modes(struct device *dev,
  413. struct device_attribute *attr,
  414. char *buf)
  415. {
  416. int len;
  417. int i;
  418. for (i = 0, len = 0;
  419. len < PAGE_SIZE && i < ARRAY_SIZE(cabc_modes); i++)
  420. len += snprintf(&buf[len], PAGE_SIZE - len, "%s%s%s",
  421. i ? " " : "", cabc_modes[i],
  422. i == ARRAY_SIZE(cabc_modes) - 1 ? "\n" : "");
  423. return len < PAGE_SIZE ? len : PAGE_SIZE - 1;
  424. }
  425. static ssize_t taal_store_esd_interval(struct device *dev,
  426. struct device_attribute *attr,
  427. const char *buf, size_t count)
  428. {
  429. struct omap_dss_device *dssdev = to_dss_device(dev);
  430. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  431. unsigned long t;
  432. int r;
  433. r = strict_strtoul(buf, 10, &t);
  434. if (r)
  435. return r;
  436. mutex_lock(&td->lock);
  437. taal_cancel_esd_work(dssdev);
  438. td->esd_interval = t;
  439. if (td->enabled)
  440. taal_queue_esd_work(dssdev);
  441. mutex_unlock(&td->lock);
  442. return count;
  443. }
  444. static ssize_t taal_show_esd_interval(struct device *dev,
  445. struct device_attribute *attr,
  446. char *buf)
  447. {
  448. struct omap_dss_device *dssdev = to_dss_device(dev);
  449. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  450. unsigned t;
  451. mutex_lock(&td->lock);
  452. t = td->esd_interval;
  453. mutex_unlock(&td->lock);
  454. return snprintf(buf, PAGE_SIZE, "%u\n", t);
  455. }
  456. static ssize_t taal_store_ulps(struct device *dev,
  457. struct device_attribute *attr,
  458. const char *buf, size_t count)
  459. {
  460. struct omap_dss_device *dssdev = to_dss_device(dev);
  461. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  462. unsigned long t;
  463. int r;
  464. r = strict_strtoul(buf, 10, &t);
  465. if (r)
  466. return r;
  467. mutex_lock(&td->lock);
  468. if (td->enabled) {
  469. dsi_bus_lock(dssdev);
  470. if (t)
  471. r = taal_enter_ulps(dssdev);
  472. else
  473. r = taal_wake_up(dssdev);
  474. dsi_bus_unlock(dssdev);
  475. }
  476. mutex_unlock(&td->lock);
  477. if (r)
  478. return r;
  479. return count;
  480. }
  481. static ssize_t taal_show_ulps(struct device *dev,
  482. struct device_attribute *attr,
  483. char *buf)
  484. {
  485. struct omap_dss_device *dssdev = to_dss_device(dev);
  486. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  487. unsigned t;
  488. mutex_lock(&td->lock);
  489. t = td->ulps_enabled;
  490. mutex_unlock(&td->lock);
  491. return snprintf(buf, PAGE_SIZE, "%u\n", t);
  492. }
  493. static ssize_t taal_store_ulps_timeout(struct device *dev,
  494. struct device_attribute *attr,
  495. const char *buf, size_t count)
  496. {
  497. struct omap_dss_device *dssdev = to_dss_device(dev);
  498. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  499. unsigned long t;
  500. int r;
  501. r = strict_strtoul(buf, 10, &t);
  502. if (r)
  503. return r;
  504. mutex_lock(&td->lock);
  505. td->ulps_timeout = t;
  506. if (td->enabled) {
  507. /* taal_wake_up will restart the timer */
  508. dsi_bus_lock(dssdev);
  509. r = taal_wake_up(dssdev);
  510. dsi_bus_unlock(dssdev);
  511. }
  512. mutex_unlock(&td->lock);
  513. if (r)
  514. return r;
  515. return count;
  516. }
  517. static ssize_t taal_show_ulps_timeout(struct device *dev,
  518. struct device_attribute *attr,
  519. char *buf)
  520. {
  521. struct omap_dss_device *dssdev = to_dss_device(dev);
  522. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  523. unsigned t;
  524. mutex_lock(&td->lock);
  525. t = td->ulps_timeout;
  526. mutex_unlock(&td->lock);
  527. return snprintf(buf, PAGE_SIZE, "%u\n", t);
  528. }
  529. static DEVICE_ATTR(num_dsi_errors, S_IRUGO, taal_num_errors_show, NULL);
  530. static DEVICE_ATTR(hw_revision, S_IRUGO, taal_hw_revision_show, NULL);
  531. static DEVICE_ATTR(cabc_mode, S_IRUGO | S_IWUSR,
  532. show_cabc_mode, store_cabc_mode);
  533. static DEVICE_ATTR(cabc_available_modes, S_IRUGO,
  534. show_cabc_available_modes, NULL);
  535. static DEVICE_ATTR(esd_interval, S_IRUGO | S_IWUSR,
  536. taal_show_esd_interval, taal_store_esd_interval);
  537. static DEVICE_ATTR(ulps, S_IRUGO | S_IWUSR,
  538. taal_show_ulps, taal_store_ulps);
  539. static DEVICE_ATTR(ulps_timeout, S_IRUGO | S_IWUSR,
  540. taal_show_ulps_timeout, taal_store_ulps_timeout);
  541. static struct attribute *taal_attrs[] = {
  542. &dev_attr_num_dsi_errors.attr,
  543. &dev_attr_hw_revision.attr,
  544. &dev_attr_cabc_mode.attr,
  545. &dev_attr_cabc_available_modes.attr,
  546. &dev_attr_esd_interval.attr,
  547. &dev_attr_ulps.attr,
  548. &dev_attr_ulps_timeout.attr,
  549. NULL,
  550. };
  551. static struct attribute_group taal_attr_group = {
  552. .attrs = taal_attrs,
  553. };
  554. static void taal_hw_reset(struct omap_dss_device *dssdev)
  555. {
  556. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  557. if (!gpio_is_valid(td->reset_gpio))
  558. return;
  559. gpio_set_value(td->reset_gpio, 1);
  560. udelay(10);
  561. /* reset the panel */
  562. gpio_set_value(td->reset_gpio, 0);
  563. /* assert reset */
  564. udelay(10);
  565. gpio_set_value(td->reset_gpio, 1);
  566. /* wait after releasing reset */
  567. msleep(5);
  568. }
  569. static void taal_probe_pdata(struct taal_data *td,
  570. const struct nokia_dsi_panel_data *pdata)
  571. {
  572. td->reset_gpio = pdata->reset_gpio;
  573. if (pdata->use_ext_te)
  574. td->ext_te_gpio = pdata->ext_te_gpio;
  575. else
  576. td->ext_te_gpio = -1;
  577. td->esd_interval = pdata->esd_interval;
  578. td->ulps_timeout = pdata->ulps_timeout;
  579. td->use_dsi_backlight = pdata->use_dsi_backlight;
  580. td->pin_config = pdata->pin_config;
  581. }
  582. static int taal_probe(struct omap_dss_device *dssdev)
  583. {
  584. struct backlight_properties props;
  585. struct taal_data *td;
  586. struct backlight_device *bldev = NULL;
  587. int r;
  588. dev_dbg(&dssdev->dev, "probe\n");
  589. td = devm_kzalloc(&dssdev->dev, sizeof(*td), GFP_KERNEL);
  590. if (!td)
  591. return -ENOMEM;
  592. dev_set_drvdata(&dssdev->dev, td);
  593. td->dssdev = dssdev;
  594. if (dssdev->data) {
  595. const struct nokia_dsi_panel_data *pdata = dssdev->data;
  596. taal_probe_pdata(td, pdata);
  597. } else {
  598. return -ENODEV;
  599. }
  600. dssdev->panel.timings.x_res = 864;
  601. dssdev->panel.timings.y_res = 480;
  602. dssdev->panel.dsi_pix_fmt = OMAP_DSS_DSI_FMT_RGB888;
  603. dssdev->caps = OMAP_DSS_DISPLAY_CAP_MANUAL_UPDATE |
  604. OMAP_DSS_DISPLAY_CAP_TEAR_ELIM;
  605. mutex_init(&td->lock);
  606. atomic_set(&td->do_update, 0);
  607. if (gpio_is_valid(td->reset_gpio)) {
  608. r = devm_gpio_request_one(&dssdev->dev, td->reset_gpio,
  609. GPIOF_OUT_INIT_LOW, "taal rst");
  610. if (r) {
  611. dev_err(&dssdev->dev, "failed to request reset gpio\n");
  612. return r;
  613. }
  614. }
  615. if (gpio_is_valid(td->ext_te_gpio)) {
  616. r = devm_gpio_request_one(&dssdev->dev, td->ext_te_gpio,
  617. GPIOF_IN, "taal irq");
  618. if (r) {
  619. dev_err(&dssdev->dev, "GPIO request failed\n");
  620. return r;
  621. }
  622. r = devm_request_irq(&dssdev->dev, gpio_to_irq(td->ext_te_gpio),
  623. taal_te_isr,
  624. IRQF_TRIGGER_RISING,
  625. "taal vsync", dssdev);
  626. if (r) {
  627. dev_err(&dssdev->dev, "IRQ request failed\n");
  628. return r;
  629. }
  630. INIT_DEFERRABLE_WORK(&td->te_timeout_work,
  631. taal_te_timeout_work_callback);
  632. dev_dbg(&dssdev->dev, "Using GPIO TE\n");
  633. }
  634. td->workqueue = create_singlethread_workqueue("taal_esd");
  635. if (td->workqueue == NULL) {
  636. dev_err(&dssdev->dev, "can't create ESD workqueue\n");
  637. return -ENOMEM;
  638. }
  639. INIT_DEFERRABLE_WORK(&td->esd_work, taal_esd_work);
  640. INIT_DELAYED_WORK(&td->ulps_work, taal_ulps_work);
  641. taal_hw_reset(dssdev);
  642. if (td->use_dsi_backlight) {
  643. memset(&props, 0, sizeof(struct backlight_properties));
  644. props.max_brightness = 255;
  645. props.type = BACKLIGHT_RAW;
  646. bldev = backlight_device_register(dev_name(&dssdev->dev),
  647. &dssdev->dev, dssdev, &taal_bl_ops, &props);
  648. if (IS_ERR(bldev)) {
  649. r = PTR_ERR(bldev);
  650. goto err_bl;
  651. }
  652. td->bldev = bldev;
  653. bldev->props.fb_blank = FB_BLANK_UNBLANK;
  654. bldev->props.power = FB_BLANK_UNBLANK;
  655. bldev->props.brightness = 255;
  656. taal_bl_update_status(bldev);
  657. }
  658. r = omap_dsi_request_vc(dssdev, &td->channel);
  659. if (r) {
  660. dev_err(&dssdev->dev, "failed to get virtual channel\n");
  661. goto err_req_vc;
  662. }
  663. r = omap_dsi_set_vc_id(dssdev, td->channel, TCH);
  664. if (r) {
  665. dev_err(&dssdev->dev, "failed to set VC_ID\n");
  666. goto err_vc_id;
  667. }
  668. r = sysfs_create_group(&dssdev->dev.kobj, &taal_attr_group);
  669. if (r) {
  670. dev_err(&dssdev->dev, "failed to create sysfs files\n");
  671. goto err_vc_id;
  672. }
  673. return 0;
  674. err_vc_id:
  675. omap_dsi_release_vc(dssdev, td->channel);
  676. err_req_vc:
  677. if (bldev != NULL)
  678. backlight_device_unregister(bldev);
  679. err_bl:
  680. destroy_workqueue(td->workqueue);
  681. return r;
  682. }
  683. static void __exit taal_remove(struct omap_dss_device *dssdev)
  684. {
  685. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  686. struct backlight_device *bldev;
  687. dev_dbg(&dssdev->dev, "remove\n");
  688. sysfs_remove_group(&dssdev->dev.kobj, &taal_attr_group);
  689. omap_dsi_release_vc(dssdev, td->channel);
  690. bldev = td->bldev;
  691. if (bldev != NULL) {
  692. bldev->props.power = FB_BLANK_POWERDOWN;
  693. taal_bl_update_status(bldev);
  694. backlight_device_unregister(bldev);
  695. }
  696. taal_cancel_ulps_work(dssdev);
  697. taal_cancel_esd_work(dssdev);
  698. destroy_workqueue(td->workqueue);
  699. /* reset, to be sure that the panel is in a valid state */
  700. taal_hw_reset(dssdev);
  701. }
  702. static int taal_power_on(struct omap_dss_device *dssdev)
  703. {
  704. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  705. u8 id1, id2, id3;
  706. int r;
  707. r = omapdss_dsi_configure_pins(dssdev, &td->pin_config);
  708. if (r) {
  709. dev_err(&dssdev->dev, "failed to configure DSI pins\n");
  710. goto err0;
  711. };
  712. omapdss_dsi_set_size(dssdev, dssdev->panel.timings.x_res,
  713. dssdev->panel.timings.y_res);
  714. omapdss_dsi_set_pixel_format(dssdev, OMAP_DSS_DSI_FMT_RGB888);
  715. omapdss_dsi_set_operation_mode(dssdev, OMAP_DSS_DSI_CMD_MODE);
  716. r = omapdss_dsi_set_clocks(dssdev, 216000000, 10000000);
  717. if (r) {
  718. dev_err(&dssdev->dev, "failed to set HS and LP clocks\n");
  719. goto err0;
  720. }
  721. r = omapdss_dsi_display_enable(dssdev);
  722. if (r) {
  723. dev_err(&dssdev->dev, "failed to enable DSI\n");
  724. goto err0;
  725. }
  726. taal_hw_reset(dssdev);
  727. omapdss_dsi_vc_enable_hs(dssdev, td->channel, false);
  728. r = taal_sleep_out(td);
  729. if (r)
  730. goto err;
  731. r = taal_get_id(td, &id1, &id2, &id3);
  732. if (r)
  733. goto err;
  734. /* on early Taal revisions CABC is broken */
  735. if (id2 == 0x00 || id2 == 0xff || id2 == 0x81)
  736. td->cabc_broken = true;
  737. r = taal_dcs_write_1(td, DCS_BRIGHTNESS, 0xff);
  738. if (r)
  739. goto err;
  740. r = taal_dcs_write_1(td, DCS_CTRL_DISPLAY,
  741. (1<<2) | (1<<5)); /* BL | BCTRL */
  742. if (r)
  743. goto err;
  744. r = taal_dcs_write_1(td, MIPI_DCS_SET_PIXEL_FORMAT,
  745. MIPI_DCS_PIXEL_FMT_24BIT);
  746. if (r)
  747. goto err;
  748. if (!td->cabc_broken) {
  749. r = taal_dcs_write_1(td, DCS_WRITE_CABC, td->cabc_mode);
  750. if (r)
  751. goto err;
  752. }
  753. r = taal_dcs_write_0(td, MIPI_DCS_SET_DISPLAY_ON);
  754. if (r)
  755. goto err;
  756. r = _taal_enable_te(dssdev, td->te_enabled);
  757. if (r)
  758. goto err;
  759. r = dsi_enable_video_output(dssdev, td->channel);
  760. if (r)
  761. goto err;
  762. td->enabled = 1;
  763. if (!td->intro_printed) {
  764. dev_info(&dssdev->dev, "panel revision %02x.%02x.%02x\n",
  765. id1, id2, id3);
  766. if (td->cabc_broken)
  767. dev_info(&dssdev->dev,
  768. "old Taal version, CABC disabled\n");
  769. td->intro_printed = true;
  770. }
  771. omapdss_dsi_vc_enable_hs(dssdev, td->channel, true);
  772. return 0;
  773. err:
  774. dev_err(&dssdev->dev, "error while enabling panel, issuing HW reset\n");
  775. taal_hw_reset(dssdev);
  776. omapdss_dsi_display_disable(dssdev, true, false);
  777. err0:
  778. return r;
  779. }
  780. static void taal_power_off(struct omap_dss_device *dssdev)
  781. {
  782. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  783. int r;
  784. dsi_disable_video_output(dssdev, td->channel);
  785. r = taal_dcs_write_0(td, MIPI_DCS_SET_DISPLAY_OFF);
  786. if (!r)
  787. r = taal_sleep_in(td);
  788. if (r) {
  789. dev_err(&dssdev->dev,
  790. "error disabling panel, issuing HW reset\n");
  791. taal_hw_reset(dssdev);
  792. }
  793. omapdss_dsi_display_disable(dssdev, true, false);
  794. td->enabled = 0;
  795. }
  796. static int taal_panel_reset(struct omap_dss_device *dssdev)
  797. {
  798. dev_err(&dssdev->dev, "performing LCD reset\n");
  799. taal_power_off(dssdev);
  800. taal_hw_reset(dssdev);
  801. return taal_power_on(dssdev);
  802. }
  803. static int taal_enable(struct omap_dss_device *dssdev)
  804. {
  805. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  806. int r;
  807. dev_dbg(&dssdev->dev, "enable\n");
  808. mutex_lock(&td->lock);
  809. if (dssdev->state != OMAP_DSS_DISPLAY_DISABLED) {
  810. r = -EINVAL;
  811. goto err;
  812. }
  813. dsi_bus_lock(dssdev);
  814. r = taal_power_on(dssdev);
  815. dsi_bus_unlock(dssdev);
  816. if (r)
  817. goto err;
  818. taal_queue_esd_work(dssdev);
  819. dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
  820. mutex_unlock(&td->lock);
  821. return 0;
  822. err:
  823. dev_dbg(&dssdev->dev, "enable failed\n");
  824. mutex_unlock(&td->lock);
  825. return r;
  826. }
  827. static void taal_disable(struct omap_dss_device *dssdev)
  828. {
  829. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  830. dev_dbg(&dssdev->dev, "disable\n");
  831. mutex_lock(&td->lock);
  832. taal_cancel_ulps_work(dssdev);
  833. taal_cancel_esd_work(dssdev);
  834. dsi_bus_lock(dssdev);
  835. if (dssdev->state == OMAP_DSS_DISPLAY_ACTIVE) {
  836. int r;
  837. r = taal_wake_up(dssdev);
  838. if (!r)
  839. taal_power_off(dssdev);
  840. }
  841. dsi_bus_unlock(dssdev);
  842. dssdev->state = OMAP_DSS_DISPLAY_DISABLED;
  843. mutex_unlock(&td->lock);
  844. }
  845. static void taal_framedone_cb(int err, void *data)
  846. {
  847. struct omap_dss_device *dssdev = data;
  848. dev_dbg(&dssdev->dev, "framedone, err %d\n", err);
  849. dsi_bus_unlock(dssdev);
  850. }
  851. static irqreturn_t taal_te_isr(int irq, void *data)
  852. {
  853. struct omap_dss_device *dssdev = data;
  854. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  855. int old;
  856. int r;
  857. old = atomic_cmpxchg(&td->do_update, 1, 0);
  858. if (old) {
  859. cancel_delayed_work(&td->te_timeout_work);
  860. r = omap_dsi_update(dssdev, td->channel, taal_framedone_cb,
  861. dssdev);
  862. if (r)
  863. goto err;
  864. }
  865. return IRQ_HANDLED;
  866. err:
  867. dev_err(&dssdev->dev, "start update failed\n");
  868. dsi_bus_unlock(dssdev);
  869. return IRQ_HANDLED;
  870. }
  871. static void taal_te_timeout_work_callback(struct work_struct *work)
  872. {
  873. struct taal_data *td = container_of(work, struct taal_data,
  874. te_timeout_work.work);
  875. struct omap_dss_device *dssdev = td->dssdev;
  876. dev_err(&dssdev->dev, "TE not received for 250ms!\n");
  877. atomic_set(&td->do_update, 0);
  878. dsi_bus_unlock(dssdev);
  879. }
  880. static int taal_update(struct omap_dss_device *dssdev,
  881. u16 x, u16 y, u16 w, u16 h)
  882. {
  883. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  884. int r;
  885. dev_dbg(&dssdev->dev, "update %d, %d, %d x %d\n", x, y, w, h);
  886. mutex_lock(&td->lock);
  887. dsi_bus_lock(dssdev);
  888. r = taal_wake_up(dssdev);
  889. if (r)
  890. goto err;
  891. if (!td->enabled) {
  892. r = 0;
  893. goto err;
  894. }
  895. /* XXX no need to send this every frame, but dsi break if not done */
  896. r = taal_set_update_window(td, 0, 0,
  897. dssdev->panel.timings.x_res,
  898. dssdev->panel.timings.y_res);
  899. if (r)
  900. goto err;
  901. if (td->te_enabled && gpio_is_valid(td->ext_te_gpio)) {
  902. schedule_delayed_work(&td->te_timeout_work,
  903. msecs_to_jiffies(250));
  904. atomic_set(&td->do_update, 1);
  905. } else {
  906. r = omap_dsi_update(dssdev, td->channel, taal_framedone_cb,
  907. dssdev);
  908. if (r)
  909. goto err;
  910. }
  911. /* note: no bus_unlock here. unlock is in framedone_cb */
  912. mutex_unlock(&td->lock);
  913. return 0;
  914. err:
  915. dsi_bus_unlock(dssdev);
  916. mutex_unlock(&td->lock);
  917. return r;
  918. }
  919. static int taal_sync(struct omap_dss_device *dssdev)
  920. {
  921. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  922. dev_dbg(&dssdev->dev, "sync\n");
  923. mutex_lock(&td->lock);
  924. dsi_bus_lock(dssdev);
  925. dsi_bus_unlock(dssdev);
  926. mutex_unlock(&td->lock);
  927. dev_dbg(&dssdev->dev, "sync done\n");
  928. return 0;
  929. }
  930. static int _taal_enable_te(struct omap_dss_device *dssdev, bool enable)
  931. {
  932. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  933. int r;
  934. if (enable)
  935. r = taal_dcs_write_1(td, MIPI_DCS_SET_TEAR_ON, 0);
  936. else
  937. r = taal_dcs_write_0(td, MIPI_DCS_SET_TEAR_OFF);
  938. if (!gpio_is_valid(td->ext_te_gpio))
  939. omapdss_dsi_enable_te(dssdev, enable);
  940. /* possible panel bug */
  941. msleep(100);
  942. return r;
  943. }
  944. static int taal_enable_te(struct omap_dss_device *dssdev, bool enable)
  945. {
  946. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  947. int r;
  948. mutex_lock(&td->lock);
  949. if (td->te_enabled == enable)
  950. goto end;
  951. dsi_bus_lock(dssdev);
  952. if (td->enabled) {
  953. r = taal_wake_up(dssdev);
  954. if (r)
  955. goto err;
  956. r = _taal_enable_te(dssdev, enable);
  957. if (r)
  958. goto err;
  959. }
  960. td->te_enabled = enable;
  961. dsi_bus_unlock(dssdev);
  962. end:
  963. mutex_unlock(&td->lock);
  964. return 0;
  965. err:
  966. dsi_bus_unlock(dssdev);
  967. mutex_unlock(&td->lock);
  968. return r;
  969. }
  970. static int taal_get_te(struct omap_dss_device *dssdev)
  971. {
  972. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  973. int r;
  974. mutex_lock(&td->lock);
  975. r = td->te_enabled;
  976. mutex_unlock(&td->lock);
  977. return r;
  978. }
  979. static int taal_run_test(struct omap_dss_device *dssdev, int test_num)
  980. {
  981. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  982. u8 id1, id2, id3;
  983. int r;
  984. mutex_lock(&td->lock);
  985. if (!td->enabled) {
  986. r = -ENODEV;
  987. goto err1;
  988. }
  989. dsi_bus_lock(dssdev);
  990. r = taal_wake_up(dssdev);
  991. if (r)
  992. goto err2;
  993. r = taal_dcs_read_1(td, DCS_GET_ID1, &id1);
  994. if (r)
  995. goto err2;
  996. r = taal_dcs_read_1(td, DCS_GET_ID2, &id2);
  997. if (r)
  998. goto err2;
  999. r = taal_dcs_read_1(td, DCS_GET_ID3, &id3);
  1000. if (r)
  1001. goto err2;
  1002. dsi_bus_unlock(dssdev);
  1003. mutex_unlock(&td->lock);
  1004. return 0;
  1005. err2:
  1006. dsi_bus_unlock(dssdev);
  1007. err1:
  1008. mutex_unlock(&td->lock);
  1009. return r;
  1010. }
  1011. static int taal_memory_read(struct omap_dss_device *dssdev,
  1012. void *buf, size_t size,
  1013. u16 x, u16 y, u16 w, u16 h)
  1014. {
  1015. int r;
  1016. int first = 1;
  1017. int plen;
  1018. unsigned buf_used = 0;
  1019. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  1020. if (size < w * h * 3)
  1021. return -ENOMEM;
  1022. mutex_lock(&td->lock);
  1023. if (!td->enabled) {
  1024. r = -ENODEV;
  1025. goto err1;
  1026. }
  1027. size = min(w * h * 3,
  1028. dssdev->panel.timings.x_res *
  1029. dssdev->panel.timings.y_res * 3);
  1030. dsi_bus_lock(dssdev);
  1031. r = taal_wake_up(dssdev);
  1032. if (r)
  1033. goto err2;
  1034. /* plen 1 or 2 goes into short packet. until checksum error is fixed,
  1035. * use short packets. plen 32 works, but bigger packets seem to cause
  1036. * an error. */
  1037. if (size % 2)
  1038. plen = 1;
  1039. else
  1040. plen = 2;
  1041. taal_set_update_window(td, x, y, w, h);
  1042. r = dsi_vc_set_max_rx_packet_size(dssdev, td->channel, plen);
  1043. if (r)
  1044. goto err2;
  1045. while (buf_used < size) {
  1046. u8 dcs_cmd = first ? 0x2e : 0x3e;
  1047. first = 0;
  1048. r = dsi_vc_dcs_read(dssdev, td->channel, dcs_cmd,
  1049. buf + buf_used, size - buf_used);
  1050. if (r < 0) {
  1051. dev_err(&dssdev->dev, "read error\n");
  1052. goto err3;
  1053. }
  1054. buf_used += r;
  1055. if (r < plen) {
  1056. dev_err(&dssdev->dev, "short read\n");
  1057. break;
  1058. }
  1059. if (signal_pending(current)) {
  1060. dev_err(&dssdev->dev, "signal pending, "
  1061. "aborting memory read\n");
  1062. r = -ERESTARTSYS;
  1063. goto err3;
  1064. }
  1065. }
  1066. r = buf_used;
  1067. err3:
  1068. dsi_vc_set_max_rx_packet_size(dssdev, td->channel, 1);
  1069. err2:
  1070. dsi_bus_unlock(dssdev);
  1071. err1:
  1072. mutex_unlock(&td->lock);
  1073. return r;
  1074. }
  1075. static void taal_ulps_work(struct work_struct *work)
  1076. {
  1077. struct taal_data *td = container_of(work, struct taal_data,
  1078. ulps_work.work);
  1079. struct omap_dss_device *dssdev = td->dssdev;
  1080. mutex_lock(&td->lock);
  1081. if (dssdev->state != OMAP_DSS_DISPLAY_ACTIVE || !td->enabled) {
  1082. mutex_unlock(&td->lock);
  1083. return;
  1084. }
  1085. dsi_bus_lock(dssdev);
  1086. taal_enter_ulps(dssdev);
  1087. dsi_bus_unlock(dssdev);
  1088. mutex_unlock(&td->lock);
  1089. }
  1090. static void taal_esd_work(struct work_struct *work)
  1091. {
  1092. struct taal_data *td = container_of(work, struct taal_data,
  1093. esd_work.work);
  1094. struct omap_dss_device *dssdev = td->dssdev;
  1095. u8 state1, state2;
  1096. int r;
  1097. mutex_lock(&td->lock);
  1098. if (!td->enabled) {
  1099. mutex_unlock(&td->lock);
  1100. return;
  1101. }
  1102. dsi_bus_lock(dssdev);
  1103. r = taal_wake_up(dssdev);
  1104. if (r) {
  1105. dev_err(&dssdev->dev, "failed to exit ULPS\n");
  1106. goto err;
  1107. }
  1108. r = taal_dcs_read_1(td, MIPI_DCS_GET_DIAGNOSTIC_RESULT, &state1);
  1109. if (r) {
  1110. dev_err(&dssdev->dev, "failed to read Taal status\n");
  1111. goto err;
  1112. }
  1113. /* Run self diagnostics */
  1114. r = taal_sleep_out(td);
  1115. if (r) {
  1116. dev_err(&dssdev->dev, "failed to run Taal self-diagnostics\n");
  1117. goto err;
  1118. }
  1119. r = taal_dcs_read_1(td, MIPI_DCS_GET_DIAGNOSTIC_RESULT, &state2);
  1120. if (r) {
  1121. dev_err(&dssdev->dev, "failed to read Taal status\n");
  1122. goto err;
  1123. }
  1124. /* Each sleep out command will trigger a self diagnostic and flip
  1125. * Bit6 if the test passes.
  1126. */
  1127. if (!((state1 ^ state2) & (1 << 6))) {
  1128. dev_err(&dssdev->dev, "LCD self diagnostics failed\n");
  1129. goto err;
  1130. }
  1131. /* Self-diagnostics result is also shown on TE GPIO line. We need
  1132. * to re-enable TE after self diagnostics */
  1133. if (td->te_enabled && gpio_is_valid(td->ext_te_gpio)) {
  1134. r = taal_dcs_write_1(td, MIPI_DCS_SET_TEAR_ON, 0);
  1135. if (r)
  1136. goto err;
  1137. }
  1138. dsi_bus_unlock(dssdev);
  1139. taal_queue_esd_work(dssdev);
  1140. mutex_unlock(&td->lock);
  1141. return;
  1142. err:
  1143. dev_err(&dssdev->dev, "performing LCD reset\n");
  1144. taal_panel_reset(dssdev);
  1145. dsi_bus_unlock(dssdev);
  1146. taal_queue_esd_work(dssdev);
  1147. mutex_unlock(&td->lock);
  1148. }
  1149. static struct omap_dss_driver taal_driver = {
  1150. .probe = taal_probe,
  1151. .remove = __exit_p(taal_remove),
  1152. .enable = taal_enable,
  1153. .disable = taal_disable,
  1154. .update = taal_update,
  1155. .sync = taal_sync,
  1156. .get_resolution = taal_get_resolution,
  1157. .get_recommended_bpp = omapdss_default_get_recommended_bpp,
  1158. .enable_te = taal_enable_te,
  1159. .get_te = taal_get_te,
  1160. .run_test = taal_run_test,
  1161. .memory_read = taal_memory_read,
  1162. .driver = {
  1163. .name = "taal",
  1164. .owner = THIS_MODULE,
  1165. },
  1166. };
  1167. static int __init taal_init(void)
  1168. {
  1169. omap_dss_register_driver(&taal_driver);
  1170. return 0;
  1171. }
  1172. static void __exit taal_exit(void)
  1173. {
  1174. omap_dss_unregister_driver(&taal_driver);
  1175. }
  1176. module_init(taal_init);
  1177. module_exit(taal_exit);
  1178. MODULE_AUTHOR("Tomi Valkeinen <tomi.valkeinen@nokia.com>");
  1179. MODULE_DESCRIPTION("Taal Driver");
  1180. MODULE_LICENSE("GPL");