panel-taal.c 37 KB

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