panel-taal.c 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548
  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. struct omap_dss_dsi_config dsi_config = {
  708. .mode = OMAP_DSS_DSI_CMD_MODE,
  709. .pixel_format = OMAP_DSS_DSI_FMT_RGB888,
  710. .timings = &dssdev->panel.timings,
  711. .hs_clk = 216000000,
  712. .lp_clk = 10000000,
  713. };
  714. r = omapdss_dsi_configure_pins(dssdev, &td->pin_config);
  715. if (r) {
  716. dev_err(&dssdev->dev, "failed to configure DSI pins\n");
  717. goto err0;
  718. };
  719. r = omapdss_dsi_set_config(dssdev, &dsi_config);
  720. if (r) {
  721. dev_err(&dssdev->dev, "failed to configure DSI\n");
  722. goto err0;
  723. }
  724. r = omapdss_dsi_display_enable(dssdev);
  725. if (r) {
  726. dev_err(&dssdev->dev, "failed to enable DSI\n");
  727. goto err0;
  728. }
  729. taal_hw_reset(dssdev);
  730. omapdss_dsi_vc_enable_hs(dssdev, td->channel, false);
  731. r = taal_sleep_out(td);
  732. if (r)
  733. goto err;
  734. r = taal_get_id(td, &id1, &id2, &id3);
  735. if (r)
  736. goto err;
  737. /* on early Taal revisions CABC is broken */
  738. if (id2 == 0x00 || id2 == 0xff || id2 == 0x81)
  739. td->cabc_broken = true;
  740. r = taal_dcs_write_1(td, DCS_BRIGHTNESS, 0xff);
  741. if (r)
  742. goto err;
  743. r = taal_dcs_write_1(td, DCS_CTRL_DISPLAY,
  744. (1<<2) | (1<<5)); /* BL | BCTRL */
  745. if (r)
  746. goto err;
  747. r = taal_dcs_write_1(td, MIPI_DCS_SET_PIXEL_FORMAT,
  748. MIPI_DCS_PIXEL_FMT_24BIT);
  749. if (r)
  750. goto err;
  751. if (!td->cabc_broken) {
  752. r = taal_dcs_write_1(td, DCS_WRITE_CABC, td->cabc_mode);
  753. if (r)
  754. goto err;
  755. }
  756. r = taal_dcs_write_0(td, MIPI_DCS_SET_DISPLAY_ON);
  757. if (r)
  758. goto err;
  759. r = _taal_enable_te(dssdev, td->te_enabled);
  760. if (r)
  761. goto err;
  762. r = dsi_enable_video_output(dssdev, td->channel);
  763. if (r)
  764. goto err;
  765. td->enabled = 1;
  766. if (!td->intro_printed) {
  767. dev_info(&dssdev->dev, "panel revision %02x.%02x.%02x\n",
  768. id1, id2, id3);
  769. if (td->cabc_broken)
  770. dev_info(&dssdev->dev,
  771. "old Taal version, CABC disabled\n");
  772. td->intro_printed = true;
  773. }
  774. omapdss_dsi_vc_enable_hs(dssdev, td->channel, true);
  775. return 0;
  776. err:
  777. dev_err(&dssdev->dev, "error while enabling panel, issuing HW reset\n");
  778. taal_hw_reset(dssdev);
  779. omapdss_dsi_display_disable(dssdev, true, false);
  780. err0:
  781. return r;
  782. }
  783. static void taal_power_off(struct omap_dss_device *dssdev)
  784. {
  785. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  786. int r;
  787. dsi_disable_video_output(dssdev, td->channel);
  788. r = taal_dcs_write_0(td, MIPI_DCS_SET_DISPLAY_OFF);
  789. if (!r)
  790. r = taal_sleep_in(td);
  791. if (r) {
  792. dev_err(&dssdev->dev,
  793. "error disabling panel, issuing HW reset\n");
  794. taal_hw_reset(dssdev);
  795. }
  796. omapdss_dsi_display_disable(dssdev, true, false);
  797. td->enabled = 0;
  798. }
  799. static int taal_panel_reset(struct omap_dss_device *dssdev)
  800. {
  801. dev_err(&dssdev->dev, "performing LCD reset\n");
  802. taal_power_off(dssdev);
  803. taal_hw_reset(dssdev);
  804. return taal_power_on(dssdev);
  805. }
  806. static int taal_enable(struct omap_dss_device *dssdev)
  807. {
  808. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  809. int r;
  810. dev_dbg(&dssdev->dev, "enable\n");
  811. mutex_lock(&td->lock);
  812. if (dssdev->state != OMAP_DSS_DISPLAY_DISABLED) {
  813. r = -EINVAL;
  814. goto err;
  815. }
  816. dsi_bus_lock(dssdev);
  817. r = taal_power_on(dssdev);
  818. dsi_bus_unlock(dssdev);
  819. if (r)
  820. goto err;
  821. taal_queue_esd_work(dssdev);
  822. dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
  823. mutex_unlock(&td->lock);
  824. return 0;
  825. err:
  826. dev_dbg(&dssdev->dev, "enable failed\n");
  827. mutex_unlock(&td->lock);
  828. return r;
  829. }
  830. static void taal_disable(struct omap_dss_device *dssdev)
  831. {
  832. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  833. dev_dbg(&dssdev->dev, "disable\n");
  834. mutex_lock(&td->lock);
  835. taal_cancel_ulps_work(dssdev);
  836. taal_cancel_esd_work(dssdev);
  837. dsi_bus_lock(dssdev);
  838. if (dssdev->state == OMAP_DSS_DISPLAY_ACTIVE) {
  839. int r;
  840. r = taal_wake_up(dssdev);
  841. if (!r)
  842. taal_power_off(dssdev);
  843. }
  844. dsi_bus_unlock(dssdev);
  845. dssdev->state = OMAP_DSS_DISPLAY_DISABLED;
  846. mutex_unlock(&td->lock);
  847. }
  848. static void taal_framedone_cb(int err, void *data)
  849. {
  850. struct omap_dss_device *dssdev = data;
  851. dev_dbg(&dssdev->dev, "framedone, err %d\n", err);
  852. dsi_bus_unlock(dssdev);
  853. }
  854. static irqreturn_t taal_te_isr(int irq, void *data)
  855. {
  856. struct omap_dss_device *dssdev = data;
  857. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  858. int old;
  859. int r;
  860. old = atomic_cmpxchg(&td->do_update, 1, 0);
  861. if (old) {
  862. cancel_delayed_work(&td->te_timeout_work);
  863. r = omap_dsi_update(dssdev, td->channel, taal_framedone_cb,
  864. dssdev);
  865. if (r)
  866. goto err;
  867. }
  868. return IRQ_HANDLED;
  869. err:
  870. dev_err(&dssdev->dev, "start update failed\n");
  871. dsi_bus_unlock(dssdev);
  872. return IRQ_HANDLED;
  873. }
  874. static void taal_te_timeout_work_callback(struct work_struct *work)
  875. {
  876. struct taal_data *td = container_of(work, struct taal_data,
  877. te_timeout_work.work);
  878. struct omap_dss_device *dssdev = td->dssdev;
  879. dev_err(&dssdev->dev, "TE not received for 250ms!\n");
  880. atomic_set(&td->do_update, 0);
  881. dsi_bus_unlock(dssdev);
  882. }
  883. static int taal_update(struct omap_dss_device *dssdev,
  884. u16 x, u16 y, u16 w, u16 h)
  885. {
  886. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  887. int r;
  888. dev_dbg(&dssdev->dev, "update %d, %d, %d x %d\n", x, y, w, h);
  889. mutex_lock(&td->lock);
  890. dsi_bus_lock(dssdev);
  891. r = taal_wake_up(dssdev);
  892. if (r)
  893. goto err;
  894. if (!td->enabled) {
  895. r = 0;
  896. goto err;
  897. }
  898. /* XXX no need to send this every frame, but dsi break if not done */
  899. r = taal_set_update_window(td, 0, 0,
  900. dssdev->panel.timings.x_res,
  901. dssdev->panel.timings.y_res);
  902. if (r)
  903. goto err;
  904. if (td->te_enabled && gpio_is_valid(td->ext_te_gpio)) {
  905. schedule_delayed_work(&td->te_timeout_work,
  906. msecs_to_jiffies(250));
  907. atomic_set(&td->do_update, 1);
  908. } else {
  909. r = omap_dsi_update(dssdev, td->channel, taal_framedone_cb,
  910. dssdev);
  911. if (r)
  912. goto err;
  913. }
  914. /* note: no bus_unlock here. unlock is in framedone_cb */
  915. mutex_unlock(&td->lock);
  916. return 0;
  917. err:
  918. dsi_bus_unlock(dssdev);
  919. mutex_unlock(&td->lock);
  920. return r;
  921. }
  922. static int taal_sync(struct omap_dss_device *dssdev)
  923. {
  924. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  925. dev_dbg(&dssdev->dev, "sync\n");
  926. mutex_lock(&td->lock);
  927. dsi_bus_lock(dssdev);
  928. dsi_bus_unlock(dssdev);
  929. mutex_unlock(&td->lock);
  930. dev_dbg(&dssdev->dev, "sync done\n");
  931. return 0;
  932. }
  933. static int _taal_enable_te(struct omap_dss_device *dssdev, bool enable)
  934. {
  935. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  936. int r;
  937. if (enable)
  938. r = taal_dcs_write_1(td, MIPI_DCS_SET_TEAR_ON, 0);
  939. else
  940. r = taal_dcs_write_0(td, MIPI_DCS_SET_TEAR_OFF);
  941. if (!gpio_is_valid(td->ext_te_gpio))
  942. omapdss_dsi_enable_te(dssdev, enable);
  943. /* possible panel bug */
  944. msleep(100);
  945. return r;
  946. }
  947. static int taal_enable_te(struct omap_dss_device *dssdev, bool enable)
  948. {
  949. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  950. int r;
  951. mutex_lock(&td->lock);
  952. if (td->te_enabled == enable)
  953. goto end;
  954. dsi_bus_lock(dssdev);
  955. if (td->enabled) {
  956. r = taal_wake_up(dssdev);
  957. if (r)
  958. goto err;
  959. r = _taal_enable_te(dssdev, enable);
  960. if (r)
  961. goto err;
  962. }
  963. td->te_enabled = enable;
  964. dsi_bus_unlock(dssdev);
  965. end:
  966. mutex_unlock(&td->lock);
  967. return 0;
  968. err:
  969. dsi_bus_unlock(dssdev);
  970. mutex_unlock(&td->lock);
  971. return r;
  972. }
  973. static int taal_get_te(struct omap_dss_device *dssdev)
  974. {
  975. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  976. int r;
  977. mutex_lock(&td->lock);
  978. r = td->te_enabled;
  979. mutex_unlock(&td->lock);
  980. return r;
  981. }
  982. static int taal_run_test(struct omap_dss_device *dssdev, int test_num)
  983. {
  984. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  985. u8 id1, id2, id3;
  986. int r;
  987. mutex_lock(&td->lock);
  988. if (!td->enabled) {
  989. r = -ENODEV;
  990. goto err1;
  991. }
  992. dsi_bus_lock(dssdev);
  993. r = taal_wake_up(dssdev);
  994. if (r)
  995. goto err2;
  996. r = taal_dcs_read_1(td, DCS_GET_ID1, &id1);
  997. if (r)
  998. goto err2;
  999. r = taal_dcs_read_1(td, DCS_GET_ID2, &id2);
  1000. if (r)
  1001. goto err2;
  1002. r = taal_dcs_read_1(td, DCS_GET_ID3, &id3);
  1003. if (r)
  1004. goto err2;
  1005. dsi_bus_unlock(dssdev);
  1006. mutex_unlock(&td->lock);
  1007. return 0;
  1008. err2:
  1009. dsi_bus_unlock(dssdev);
  1010. err1:
  1011. mutex_unlock(&td->lock);
  1012. return r;
  1013. }
  1014. static int taal_memory_read(struct omap_dss_device *dssdev,
  1015. void *buf, size_t size,
  1016. u16 x, u16 y, u16 w, u16 h)
  1017. {
  1018. int r;
  1019. int first = 1;
  1020. int plen;
  1021. unsigned buf_used = 0;
  1022. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  1023. if (size < w * h * 3)
  1024. return -ENOMEM;
  1025. mutex_lock(&td->lock);
  1026. if (!td->enabled) {
  1027. r = -ENODEV;
  1028. goto err1;
  1029. }
  1030. size = min(w * h * 3,
  1031. dssdev->panel.timings.x_res *
  1032. dssdev->panel.timings.y_res * 3);
  1033. dsi_bus_lock(dssdev);
  1034. r = taal_wake_up(dssdev);
  1035. if (r)
  1036. goto err2;
  1037. /* plen 1 or 2 goes into short packet. until checksum error is fixed,
  1038. * use short packets. plen 32 works, but bigger packets seem to cause
  1039. * an error. */
  1040. if (size % 2)
  1041. plen = 1;
  1042. else
  1043. plen = 2;
  1044. taal_set_update_window(td, x, y, w, h);
  1045. r = dsi_vc_set_max_rx_packet_size(dssdev, td->channel, plen);
  1046. if (r)
  1047. goto err2;
  1048. while (buf_used < size) {
  1049. u8 dcs_cmd = first ? 0x2e : 0x3e;
  1050. first = 0;
  1051. r = dsi_vc_dcs_read(dssdev, td->channel, dcs_cmd,
  1052. buf + buf_used, size - buf_used);
  1053. if (r < 0) {
  1054. dev_err(&dssdev->dev, "read error\n");
  1055. goto err3;
  1056. }
  1057. buf_used += r;
  1058. if (r < plen) {
  1059. dev_err(&dssdev->dev, "short read\n");
  1060. break;
  1061. }
  1062. if (signal_pending(current)) {
  1063. dev_err(&dssdev->dev, "signal pending, "
  1064. "aborting memory read\n");
  1065. r = -ERESTARTSYS;
  1066. goto err3;
  1067. }
  1068. }
  1069. r = buf_used;
  1070. err3:
  1071. dsi_vc_set_max_rx_packet_size(dssdev, td->channel, 1);
  1072. err2:
  1073. dsi_bus_unlock(dssdev);
  1074. err1:
  1075. mutex_unlock(&td->lock);
  1076. return r;
  1077. }
  1078. static void taal_ulps_work(struct work_struct *work)
  1079. {
  1080. struct taal_data *td = container_of(work, struct taal_data,
  1081. ulps_work.work);
  1082. struct omap_dss_device *dssdev = td->dssdev;
  1083. mutex_lock(&td->lock);
  1084. if (dssdev->state != OMAP_DSS_DISPLAY_ACTIVE || !td->enabled) {
  1085. mutex_unlock(&td->lock);
  1086. return;
  1087. }
  1088. dsi_bus_lock(dssdev);
  1089. taal_enter_ulps(dssdev);
  1090. dsi_bus_unlock(dssdev);
  1091. mutex_unlock(&td->lock);
  1092. }
  1093. static void taal_esd_work(struct work_struct *work)
  1094. {
  1095. struct taal_data *td = container_of(work, struct taal_data,
  1096. esd_work.work);
  1097. struct omap_dss_device *dssdev = td->dssdev;
  1098. u8 state1, state2;
  1099. int r;
  1100. mutex_lock(&td->lock);
  1101. if (!td->enabled) {
  1102. mutex_unlock(&td->lock);
  1103. return;
  1104. }
  1105. dsi_bus_lock(dssdev);
  1106. r = taal_wake_up(dssdev);
  1107. if (r) {
  1108. dev_err(&dssdev->dev, "failed to exit ULPS\n");
  1109. goto err;
  1110. }
  1111. r = taal_dcs_read_1(td, MIPI_DCS_GET_DIAGNOSTIC_RESULT, &state1);
  1112. if (r) {
  1113. dev_err(&dssdev->dev, "failed to read Taal status\n");
  1114. goto err;
  1115. }
  1116. /* Run self diagnostics */
  1117. r = taal_sleep_out(td);
  1118. if (r) {
  1119. dev_err(&dssdev->dev, "failed to run Taal self-diagnostics\n");
  1120. goto err;
  1121. }
  1122. r = taal_dcs_read_1(td, MIPI_DCS_GET_DIAGNOSTIC_RESULT, &state2);
  1123. if (r) {
  1124. dev_err(&dssdev->dev, "failed to read Taal status\n");
  1125. goto err;
  1126. }
  1127. /* Each sleep out command will trigger a self diagnostic and flip
  1128. * Bit6 if the test passes.
  1129. */
  1130. if (!((state1 ^ state2) & (1 << 6))) {
  1131. dev_err(&dssdev->dev, "LCD self diagnostics failed\n");
  1132. goto err;
  1133. }
  1134. /* Self-diagnostics result is also shown on TE GPIO line. We need
  1135. * to re-enable TE after self diagnostics */
  1136. if (td->te_enabled && gpio_is_valid(td->ext_te_gpio)) {
  1137. r = taal_dcs_write_1(td, MIPI_DCS_SET_TEAR_ON, 0);
  1138. if (r)
  1139. goto err;
  1140. }
  1141. dsi_bus_unlock(dssdev);
  1142. taal_queue_esd_work(dssdev);
  1143. mutex_unlock(&td->lock);
  1144. return;
  1145. err:
  1146. dev_err(&dssdev->dev, "performing LCD reset\n");
  1147. taal_panel_reset(dssdev);
  1148. dsi_bus_unlock(dssdev);
  1149. taal_queue_esd_work(dssdev);
  1150. mutex_unlock(&td->lock);
  1151. }
  1152. static struct omap_dss_driver taal_driver = {
  1153. .probe = taal_probe,
  1154. .remove = __exit_p(taal_remove),
  1155. .enable = taal_enable,
  1156. .disable = taal_disable,
  1157. .update = taal_update,
  1158. .sync = taal_sync,
  1159. .get_resolution = taal_get_resolution,
  1160. .get_recommended_bpp = omapdss_default_get_recommended_bpp,
  1161. .enable_te = taal_enable_te,
  1162. .get_te = taal_get_te,
  1163. .run_test = taal_run_test,
  1164. .memory_read = taal_memory_read,
  1165. .driver = {
  1166. .name = "taal",
  1167. .owner = THIS_MODULE,
  1168. },
  1169. };
  1170. static int __init taal_init(void)
  1171. {
  1172. omap_dss_register_driver(&taal_driver);
  1173. return 0;
  1174. }
  1175. static void __exit taal_exit(void)
  1176. {
  1177. omap_dss_unregister_driver(&taal_driver);
  1178. }
  1179. module_init(taal_init);
  1180. module_exit(taal_exit);
  1181. MODULE_AUTHOR("Tomi Valkeinen <tomi.valkeinen@nokia.com>");
  1182. MODULE_DESCRIPTION("Taal Driver");
  1183. MODULE_LICENSE("GPL");