panel-taal.c 31 KB

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