panel-taal.c 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848
  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. r = -EINVAL;
  678. goto err;
  679. }
  680. for (i = 0; i < ARRAY_SIZE(panel_configs); i++) {
  681. if (strcmp(panel_data->name, panel_configs[i].name) == 0) {
  682. panel_config = &panel_configs[i];
  683. break;
  684. }
  685. }
  686. if (!panel_config) {
  687. r = -EINVAL;
  688. goto err;
  689. }
  690. dssdev->panel.timings = panel_config->timings;
  691. dssdev->panel.dsi_pix_fmt = OMAP_DSS_DSI_FMT_RGB888;
  692. td = kzalloc(sizeof(*td), GFP_KERNEL);
  693. if (!td) {
  694. r = -ENOMEM;
  695. goto err;
  696. }
  697. td->dssdev = dssdev;
  698. td->panel_config = panel_config;
  699. td->esd_interval = panel_data->esd_interval;
  700. td->ulps_enabled = false;
  701. td->ulps_timeout = panel_data->ulps_timeout;
  702. mutex_init(&td->lock);
  703. atomic_set(&td->do_update, 0);
  704. td->workqueue = create_singlethread_workqueue("taal_esd");
  705. if (td->workqueue == NULL) {
  706. dev_err(&dssdev->dev, "can't create ESD workqueue\n");
  707. r = -ENOMEM;
  708. goto err_wq;
  709. }
  710. INIT_DELAYED_WORK_DEFERRABLE(&td->esd_work, taal_esd_work);
  711. INIT_DELAYED_WORK(&td->ulps_work, taal_ulps_work);
  712. dev_set_drvdata(&dssdev->dev, td);
  713. if (gpio_is_valid(panel_data->reset_gpio)) {
  714. r = gpio_request_one(panel_data->reset_gpio, GPIOF_OUT_INIT_LOW,
  715. "taal rst");
  716. if (r) {
  717. dev_err(&dssdev->dev, "failed to request reset gpio\n");
  718. goto err_rst_gpio;
  719. }
  720. }
  721. taal_hw_reset(dssdev);
  722. if (panel_data->use_dsi_backlight) {
  723. memset(&props, 0, sizeof(struct backlight_properties));
  724. props.max_brightness = 255;
  725. props.type = BACKLIGHT_RAW;
  726. bldev = backlight_device_register(dev_name(&dssdev->dev),
  727. &dssdev->dev, dssdev, &taal_bl_ops, &props);
  728. if (IS_ERR(bldev)) {
  729. r = PTR_ERR(bldev);
  730. goto err_bl;
  731. }
  732. td->bldev = bldev;
  733. bldev->props.fb_blank = FB_BLANK_UNBLANK;
  734. bldev->props.power = FB_BLANK_UNBLANK;
  735. bldev->props.brightness = 255;
  736. taal_bl_update_status(bldev);
  737. }
  738. if (panel_data->use_ext_te) {
  739. int gpio = panel_data->ext_te_gpio;
  740. r = gpio_request_one(gpio, GPIOF_IN, "taal irq");
  741. if (r) {
  742. dev_err(&dssdev->dev, "GPIO request failed\n");
  743. goto err_gpio;
  744. }
  745. r = request_irq(gpio_to_irq(gpio), taal_te_isr,
  746. IRQF_TRIGGER_RISING,
  747. "taal vsync", dssdev);
  748. if (r) {
  749. dev_err(&dssdev->dev, "IRQ request failed\n");
  750. gpio_free(gpio);
  751. goto err_irq;
  752. }
  753. INIT_DELAYED_WORK_DEFERRABLE(&td->te_timeout_work,
  754. taal_te_timeout_work_callback);
  755. dev_dbg(&dssdev->dev, "Using GPIO TE\n");
  756. }
  757. r = omap_dsi_request_vc(dssdev, &td->channel);
  758. if (r) {
  759. dev_err(&dssdev->dev, "failed to get virtual channel\n");
  760. goto err_req_vc;
  761. }
  762. r = omap_dsi_set_vc_id(dssdev, td->channel, TCH);
  763. if (r) {
  764. dev_err(&dssdev->dev, "failed to set VC_ID\n");
  765. goto err_vc_id;
  766. }
  767. r = sysfs_create_group(&dssdev->dev.kobj, &taal_attr_group);
  768. if (r) {
  769. dev_err(&dssdev->dev, "failed to create sysfs files\n");
  770. goto err_vc_id;
  771. }
  772. return 0;
  773. err_vc_id:
  774. omap_dsi_release_vc(dssdev, td->channel);
  775. err_req_vc:
  776. if (panel_data->use_ext_te)
  777. free_irq(gpio_to_irq(panel_data->ext_te_gpio), dssdev);
  778. err_irq:
  779. if (panel_data->use_ext_te)
  780. gpio_free(panel_data->ext_te_gpio);
  781. err_gpio:
  782. if (bldev != NULL)
  783. backlight_device_unregister(bldev);
  784. err_bl:
  785. if (gpio_is_valid(panel_data->reset_gpio))
  786. gpio_free(panel_data->reset_gpio);
  787. err_rst_gpio:
  788. destroy_workqueue(td->workqueue);
  789. err_wq:
  790. kfree(td);
  791. err:
  792. return r;
  793. }
  794. static void __exit taal_remove(struct omap_dss_device *dssdev)
  795. {
  796. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  797. struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev);
  798. struct backlight_device *bldev;
  799. dev_dbg(&dssdev->dev, "remove\n");
  800. sysfs_remove_group(&dssdev->dev.kobj, &taal_attr_group);
  801. omap_dsi_release_vc(dssdev, td->channel);
  802. if (panel_data->use_ext_te) {
  803. int gpio = panel_data->ext_te_gpio;
  804. free_irq(gpio_to_irq(gpio), dssdev);
  805. gpio_free(gpio);
  806. }
  807. bldev = td->bldev;
  808. if (bldev != NULL) {
  809. bldev->props.power = FB_BLANK_POWERDOWN;
  810. taal_bl_update_status(bldev);
  811. backlight_device_unregister(bldev);
  812. }
  813. taal_cancel_ulps_work(dssdev);
  814. taal_cancel_esd_work(dssdev);
  815. destroy_workqueue(td->workqueue);
  816. /* reset, to be sure that the panel is in a valid state */
  817. taal_hw_reset(dssdev);
  818. if (gpio_is_valid(panel_data->reset_gpio))
  819. gpio_free(panel_data->reset_gpio);
  820. kfree(td);
  821. }
  822. static int taal_power_on(struct omap_dss_device *dssdev)
  823. {
  824. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  825. struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev);
  826. u8 id1, id2, id3;
  827. int r;
  828. r = omapdss_dsi_configure_pins(dssdev, &panel_data->pin_config);
  829. if (r) {
  830. dev_err(&dssdev->dev, "failed to configure DSI pins\n");
  831. goto err0;
  832. };
  833. r = omapdss_dsi_display_enable(dssdev);
  834. if (r) {
  835. dev_err(&dssdev->dev, "failed to enable DSI\n");
  836. goto err0;
  837. }
  838. taal_hw_reset(dssdev);
  839. omapdss_dsi_vc_enable_hs(dssdev, td->channel, false);
  840. r = taal_sleep_out(td);
  841. if (r)
  842. goto err;
  843. r = taal_get_id(td, &id1, &id2, &id3);
  844. if (r)
  845. goto err;
  846. /* on early Taal revisions CABC is broken */
  847. if (td->panel_config->type == PANEL_TAAL &&
  848. (id2 == 0x00 || id2 == 0xff || id2 == 0x81))
  849. td->cabc_broken = true;
  850. r = taal_dcs_write_1(td, DCS_BRIGHTNESS, 0xff);
  851. if (r)
  852. goto err;
  853. r = taal_dcs_write_1(td, DCS_CTRL_DISPLAY,
  854. (1<<2) | (1<<5)); /* BL | BCTRL */
  855. if (r)
  856. goto err;
  857. r = taal_dcs_write_1(td, MIPI_DCS_SET_PIXEL_FORMAT,
  858. MIPI_DCS_PIXEL_FMT_24BIT);
  859. if (r)
  860. goto err;
  861. r = taal_set_addr_mode(td, td->rotate, td->mirror);
  862. if (r)
  863. goto err;
  864. if (!td->cabc_broken) {
  865. r = taal_dcs_write_1(td, DCS_WRITE_CABC, td->cabc_mode);
  866. if (r)
  867. goto err;
  868. }
  869. r = taal_dcs_write_0(td, MIPI_DCS_SET_DISPLAY_ON);
  870. if (r)
  871. goto err;
  872. r = _taal_enable_te(dssdev, td->te_enabled);
  873. if (r)
  874. goto err;
  875. r = dsi_enable_video_output(dssdev, td->channel);
  876. if (r)
  877. goto err;
  878. td->enabled = 1;
  879. if (!td->intro_printed) {
  880. dev_info(&dssdev->dev, "%s panel revision %02x.%02x.%02x\n",
  881. td->panel_config->name, id1, id2, id3);
  882. if (td->cabc_broken)
  883. dev_info(&dssdev->dev,
  884. "old Taal version, CABC disabled\n");
  885. td->intro_printed = true;
  886. }
  887. omapdss_dsi_vc_enable_hs(dssdev, td->channel, true);
  888. return 0;
  889. err:
  890. dev_err(&dssdev->dev, "error while enabling panel, issuing HW reset\n");
  891. taal_hw_reset(dssdev);
  892. omapdss_dsi_display_disable(dssdev, true, false);
  893. err0:
  894. return r;
  895. }
  896. static void taal_power_off(struct omap_dss_device *dssdev)
  897. {
  898. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  899. int r;
  900. dsi_disable_video_output(dssdev, td->channel);
  901. r = taal_dcs_write_0(td, MIPI_DCS_SET_DISPLAY_OFF);
  902. if (!r)
  903. r = taal_sleep_in(td);
  904. if (r) {
  905. dev_err(&dssdev->dev,
  906. "error disabling panel, issuing HW reset\n");
  907. taal_hw_reset(dssdev);
  908. }
  909. omapdss_dsi_display_disable(dssdev, true, false);
  910. td->enabled = 0;
  911. }
  912. static int taal_panel_reset(struct omap_dss_device *dssdev)
  913. {
  914. dev_err(&dssdev->dev, "performing LCD reset\n");
  915. taal_power_off(dssdev);
  916. taal_hw_reset(dssdev);
  917. return taal_power_on(dssdev);
  918. }
  919. static int taal_enable(struct omap_dss_device *dssdev)
  920. {
  921. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  922. int r;
  923. dev_dbg(&dssdev->dev, "enable\n");
  924. mutex_lock(&td->lock);
  925. if (dssdev->state != OMAP_DSS_DISPLAY_DISABLED) {
  926. r = -EINVAL;
  927. goto err;
  928. }
  929. dsi_bus_lock(dssdev);
  930. r = taal_power_on(dssdev);
  931. dsi_bus_unlock(dssdev);
  932. if (r)
  933. goto err;
  934. taal_queue_esd_work(dssdev);
  935. dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
  936. mutex_unlock(&td->lock);
  937. return 0;
  938. err:
  939. dev_dbg(&dssdev->dev, "enable failed\n");
  940. mutex_unlock(&td->lock);
  941. return r;
  942. }
  943. static void taal_disable(struct omap_dss_device *dssdev)
  944. {
  945. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  946. dev_dbg(&dssdev->dev, "disable\n");
  947. mutex_lock(&td->lock);
  948. taal_cancel_ulps_work(dssdev);
  949. taal_cancel_esd_work(dssdev);
  950. dsi_bus_lock(dssdev);
  951. if (dssdev->state == OMAP_DSS_DISPLAY_ACTIVE) {
  952. int r;
  953. r = taal_wake_up(dssdev);
  954. if (!r)
  955. taal_power_off(dssdev);
  956. }
  957. dsi_bus_unlock(dssdev);
  958. dssdev->state = OMAP_DSS_DISPLAY_DISABLED;
  959. mutex_unlock(&td->lock);
  960. }
  961. static int taal_suspend(struct omap_dss_device *dssdev)
  962. {
  963. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  964. int r;
  965. dev_dbg(&dssdev->dev, "suspend\n");
  966. mutex_lock(&td->lock);
  967. if (dssdev->state != OMAP_DSS_DISPLAY_ACTIVE) {
  968. r = -EINVAL;
  969. goto err;
  970. }
  971. taal_cancel_ulps_work(dssdev);
  972. taal_cancel_esd_work(dssdev);
  973. dsi_bus_lock(dssdev);
  974. r = taal_wake_up(dssdev);
  975. if (!r)
  976. taal_power_off(dssdev);
  977. dsi_bus_unlock(dssdev);
  978. dssdev->state = OMAP_DSS_DISPLAY_SUSPENDED;
  979. mutex_unlock(&td->lock);
  980. return 0;
  981. err:
  982. mutex_unlock(&td->lock);
  983. return r;
  984. }
  985. static int taal_resume(struct omap_dss_device *dssdev)
  986. {
  987. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  988. int r;
  989. dev_dbg(&dssdev->dev, "resume\n");
  990. mutex_lock(&td->lock);
  991. if (dssdev->state != OMAP_DSS_DISPLAY_SUSPENDED) {
  992. r = -EINVAL;
  993. goto err;
  994. }
  995. dsi_bus_lock(dssdev);
  996. r = taal_power_on(dssdev);
  997. dsi_bus_unlock(dssdev);
  998. if (r) {
  999. dssdev->state = OMAP_DSS_DISPLAY_DISABLED;
  1000. } else {
  1001. dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
  1002. taal_queue_esd_work(dssdev);
  1003. }
  1004. mutex_unlock(&td->lock);
  1005. return r;
  1006. err:
  1007. mutex_unlock(&td->lock);
  1008. return r;
  1009. }
  1010. static void taal_framedone_cb(int err, void *data)
  1011. {
  1012. struct omap_dss_device *dssdev = data;
  1013. dev_dbg(&dssdev->dev, "framedone, err %d\n", err);
  1014. dsi_bus_unlock(dssdev);
  1015. }
  1016. static irqreturn_t taal_te_isr(int irq, void *data)
  1017. {
  1018. struct omap_dss_device *dssdev = data;
  1019. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  1020. int old;
  1021. int r;
  1022. old = atomic_cmpxchg(&td->do_update, 1, 0);
  1023. if (old) {
  1024. cancel_delayed_work(&td->te_timeout_work);
  1025. r = omap_dsi_update(dssdev, td->channel, taal_framedone_cb,
  1026. dssdev);
  1027. if (r)
  1028. goto err;
  1029. }
  1030. return IRQ_HANDLED;
  1031. err:
  1032. dev_err(&dssdev->dev, "start update failed\n");
  1033. dsi_bus_unlock(dssdev);
  1034. return IRQ_HANDLED;
  1035. }
  1036. static void taal_te_timeout_work_callback(struct work_struct *work)
  1037. {
  1038. struct taal_data *td = container_of(work, struct taal_data,
  1039. te_timeout_work.work);
  1040. struct omap_dss_device *dssdev = td->dssdev;
  1041. dev_err(&dssdev->dev, "TE not received for 250ms!\n");
  1042. atomic_set(&td->do_update, 0);
  1043. dsi_bus_unlock(dssdev);
  1044. }
  1045. static int taal_update(struct omap_dss_device *dssdev,
  1046. u16 x, u16 y, u16 w, u16 h)
  1047. {
  1048. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  1049. struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev);
  1050. int r;
  1051. dev_dbg(&dssdev->dev, "update %d, %d, %d x %d\n", x, y, w, h);
  1052. mutex_lock(&td->lock);
  1053. dsi_bus_lock(dssdev);
  1054. r = taal_wake_up(dssdev);
  1055. if (r)
  1056. goto err;
  1057. if (!td->enabled) {
  1058. r = 0;
  1059. goto err;
  1060. }
  1061. /* XXX no need to send this every frame, but dsi break if not done */
  1062. r = taal_set_update_window(td, 0, 0,
  1063. td->panel_config->timings.x_res,
  1064. td->panel_config->timings.y_res);
  1065. if (r)
  1066. goto err;
  1067. if (td->te_enabled && panel_data->use_ext_te) {
  1068. schedule_delayed_work(&td->te_timeout_work,
  1069. msecs_to_jiffies(250));
  1070. atomic_set(&td->do_update, 1);
  1071. } else {
  1072. r = omap_dsi_update(dssdev, td->channel, taal_framedone_cb,
  1073. dssdev);
  1074. if (r)
  1075. goto err;
  1076. }
  1077. /* note: no bus_unlock here. unlock is in framedone_cb */
  1078. mutex_unlock(&td->lock);
  1079. return 0;
  1080. err:
  1081. dsi_bus_unlock(dssdev);
  1082. mutex_unlock(&td->lock);
  1083. return r;
  1084. }
  1085. static int taal_sync(struct omap_dss_device *dssdev)
  1086. {
  1087. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  1088. dev_dbg(&dssdev->dev, "sync\n");
  1089. mutex_lock(&td->lock);
  1090. dsi_bus_lock(dssdev);
  1091. dsi_bus_unlock(dssdev);
  1092. mutex_unlock(&td->lock);
  1093. dev_dbg(&dssdev->dev, "sync done\n");
  1094. return 0;
  1095. }
  1096. static int _taal_enable_te(struct omap_dss_device *dssdev, bool enable)
  1097. {
  1098. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  1099. struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev);
  1100. int r;
  1101. if (enable)
  1102. r = taal_dcs_write_1(td, MIPI_DCS_SET_TEAR_ON, 0);
  1103. else
  1104. r = taal_dcs_write_0(td, MIPI_DCS_SET_TEAR_OFF);
  1105. if (!panel_data->use_ext_te)
  1106. omapdss_dsi_enable_te(dssdev, enable);
  1107. if (td->panel_config->sleep.enable_te)
  1108. msleep(td->panel_config->sleep.enable_te);
  1109. return r;
  1110. }
  1111. static int taal_enable_te(struct omap_dss_device *dssdev, bool enable)
  1112. {
  1113. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  1114. int r;
  1115. mutex_lock(&td->lock);
  1116. if (td->te_enabled == enable)
  1117. goto end;
  1118. dsi_bus_lock(dssdev);
  1119. if (td->enabled) {
  1120. r = taal_wake_up(dssdev);
  1121. if (r)
  1122. goto err;
  1123. r = _taal_enable_te(dssdev, enable);
  1124. if (r)
  1125. goto err;
  1126. }
  1127. td->te_enabled = enable;
  1128. dsi_bus_unlock(dssdev);
  1129. end:
  1130. mutex_unlock(&td->lock);
  1131. return 0;
  1132. err:
  1133. dsi_bus_unlock(dssdev);
  1134. mutex_unlock(&td->lock);
  1135. return r;
  1136. }
  1137. static int taal_get_te(struct omap_dss_device *dssdev)
  1138. {
  1139. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  1140. int r;
  1141. mutex_lock(&td->lock);
  1142. r = td->te_enabled;
  1143. mutex_unlock(&td->lock);
  1144. return r;
  1145. }
  1146. static int taal_rotate(struct omap_dss_device *dssdev, u8 rotate)
  1147. {
  1148. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  1149. int r;
  1150. dev_dbg(&dssdev->dev, "rotate %d\n", rotate);
  1151. mutex_lock(&td->lock);
  1152. if (td->rotate == rotate)
  1153. goto end;
  1154. dsi_bus_lock(dssdev);
  1155. if (td->enabled) {
  1156. r = taal_wake_up(dssdev);
  1157. if (r)
  1158. goto err;
  1159. r = taal_set_addr_mode(td, rotate, td->mirror);
  1160. if (r)
  1161. goto err;
  1162. }
  1163. td->rotate = rotate;
  1164. dsi_bus_unlock(dssdev);
  1165. end:
  1166. mutex_unlock(&td->lock);
  1167. return 0;
  1168. err:
  1169. dsi_bus_unlock(dssdev);
  1170. mutex_unlock(&td->lock);
  1171. return r;
  1172. }
  1173. static u8 taal_get_rotate(struct omap_dss_device *dssdev)
  1174. {
  1175. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  1176. int r;
  1177. mutex_lock(&td->lock);
  1178. r = td->rotate;
  1179. mutex_unlock(&td->lock);
  1180. return r;
  1181. }
  1182. static int taal_mirror(struct omap_dss_device *dssdev, bool enable)
  1183. {
  1184. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  1185. int r;
  1186. dev_dbg(&dssdev->dev, "mirror %d\n", enable);
  1187. mutex_lock(&td->lock);
  1188. if (td->mirror == enable)
  1189. goto end;
  1190. dsi_bus_lock(dssdev);
  1191. if (td->enabled) {
  1192. r = taal_wake_up(dssdev);
  1193. if (r)
  1194. goto err;
  1195. r = taal_set_addr_mode(td, td->rotate, enable);
  1196. if (r)
  1197. goto err;
  1198. }
  1199. td->mirror = enable;
  1200. dsi_bus_unlock(dssdev);
  1201. end:
  1202. mutex_unlock(&td->lock);
  1203. return 0;
  1204. err:
  1205. dsi_bus_unlock(dssdev);
  1206. mutex_unlock(&td->lock);
  1207. return r;
  1208. }
  1209. static bool taal_get_mirror(struct omap_dss_device *dssdev)
  1210. {
  1211. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  1212. int r;
  1213. mutex_lock(&td->lock);
  1214. r = td->mirror;
  1215. mutex_unlock(&td->lock);
  1216. return r;
  1217. }
  1218. static int taal_run_test(struct omap_dss_device *dssdev, int test_num)
  1219. {
  1220. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  1221. u8 id1, id2, id3;
  1222. int r;
  1223. mutex_lock(&td->lock);
  1224. if (!td->enabled) {
  1225. r = -ENODEV;
  1226. goto err1;
  1227. }
  1228. dsi_bus_lock(dssdev);
  1229. r = taal_wake_up(dssdev);
  1230. if (r)
  1231. goto err2;
  1232. r = taal_dcs_read_1(td, DCS_GET_ID1, &id1);
  1233. if (r)
  1234. goto err2;
  1235. r = taal_dcs_read_1(td, DCS_GET_ID2, &id2);
  1236. if (r)
  1237. goto err2;
  1238. r = taal_dcs_read_1(td, DCS_GET_ID3, &id3);
  1239. if (r)
  1240. goto err2;
  1241. dsi_bus_unlock(dssdev);
  1242. mutex_unlock(&td->lock);
  1243. return 0;
  1244. err2:
  1245. dsi_bus_unlock(dssdev);
  1246. err1:
  1247. mutex_unlock(&td->lock);
  1248. return r;
  1249. }
  1250. static int taal_memory_read(struct omap_dss_device *dssdev,
  1251. void *buf, size_t size,
  1252. u16 x, u16 y, u16 w, u16 h)
  1253. {
  1254. int r;
  1255. int first = 1;
  1256. int plen;
  1257. unsigned buf_used = 0;
  1258. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  1259. if (size < w * h * 3)
  1260. return -ENOMEM;
  1261. mutex_lock(&td->lock);
  1262. if (!td->enabled) {
  1263. r = -ENODEV;
  1264. goto err1;
  1265. }
  1266. size = min(w * h * 3,
  1267. dssdev->panel.timings.x_res *
  1268. dssdev->panel.timings.y_res * 3);
  1269. dsi_bus_lock(dssdev);
  1270. r = taal_wake_up(dssdev);
  1271. if (r)
  1272. goto err2;
  1273. /* plen 1 or 2 goes into short packet. until checksum error is fixed,
  1274. * use short packets. plen 32 works, but bigger packets seem to cause
  1275. * an error. */
  1276. if (size % 2)
  1277. plen = 1;
  1278. else
  1279. plen = 2;
  1280. taal_set_update_window(td, x, y, w, h);
  1281. r = dsi_vc_set_max_rx_packet_size(dssdev, td->channel, plen);
  1282. if (r)
  1283. goto err2;
  1284. while (buf_used < size) {
  1285. u8 dcs_cmd = first ? 0x2e : 0x3e;
  1286. first = 0;
  1287. r = dsi_vc_dcs_read(dssdev, td->channel, dcs_cmd,
  1288. buf + buf_used, size - buf_used);
  1289. if (r < 0) {
  1290. dev_err(&dssdev->dev, "read error\n");
  1291. goto err3;
  1292. }
  1293. buf_used += r;
  1294. if (r < plen) {
  1295. dev_err(&dssdev->dev, "short read\n");
  1296. break;
  1297. }
  1298. if (signal_pending(current)) {
  1299. dev_err(&dssdev->dev, "signal pending, "
  1300. "aborting memory read\n");
  1301. r = -ERESTARTSYS;
  1302. goto err3;
  1303. }
  1304. }
  1305. r = buf_used;
  1306. err3:
  1307. dsi_vc_set_max_rx_packet_size(dssdev, td->channel, 1);
  1308. err2:
  1309. dsi_bus_unlock(dssdev);
  1310. err1:
  1311. mutex_unlock(&td->lock);
  1312. return r;
  1313. }
  1314. static void taal_ulps_work(struct work_struct *work)
  1315. {
  1316. struct taal_data *td = container_of(work, struct taal_data,
  1317. ulps_work.work);
  1318. struct omap_dss_device *dssdev = td->dssdev;
  1319. mutex_lock(&td->lock);
  1320. if (dssdev->state != OMAP_DSS_DISPLAY_ACTIVE || !td->enabled) {
  1321. mutex_unlock(&td->lock);
  1322. return;
  1323. }
  1324. dsi_bus_lock(dssdev);
  1325. taal_enter_ulps(dssdev);
  1326. dsi_bus_unlock(dssdev);
  1327. mutex_unlock(&td->lock);
  1328. }
  1329. static void taal_esd_work(struct work_struct *work)
  1330. {
  1331. struct taal_data *td = container_of(work, struct taal_data,
  1332. esd_work.work);
  1333. struct omap_dss_device *dssdev = td->dssdev;
  1334. struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev);
  1335. u8 state1, state2;
  1336. int r;
  1337. mutex_lock(&td->lock);
  1338. if (!td->enabled) {
  1339. mutex_unlock(&td->lock);
  1340. return;
  1341. }
  1342. dsi_bus_lock(dssdev);
  1343. r = taal_wake_up(dssdev);
  1344. if (r) {
  1345. dev_err(&dssdev->dev, "failed to exit ULPS\n");
  1346. goto err;
  1347. }
  1348. r = taal_dcs_read_1(td, MIPI_DCS_GET_DIAGNOSTIC_RESULT, &state1);
  1349. if (r) {
  1350. dev_err(&dssdev->dev, "failed to read Taal status\n");
  1351. goto err;
  1352. }
  1353. /* Run self diagnostics */
  1354. r = taal_sleep_out(td);
  1355. if (r) {
  1356. dev_err(&dssdev->dev, "failed to run Taal self-diagnostics\n");
  1357. goto err;
  1358. }
  1359. r = taal_dcs_read_1(td, MIPI_DCS_GET_DIAGNOSTIC_RESULT, &state2);
  1360. if (r) {
  1361. dev_err(&dssdev->dev, "failed to read Taal status\n");
  1362. goto err;
  1363. }
  1364. /* Each sleep out command will trigger a self diagnostic and flip
  1365. * Bit6 if the test passes.
  1366. */
  1367. if (!((state1 ^ state2) & (1 << 6))) {
  1368. dev_err(&dssdev->dev, "LCD self diagnostics failed\n");
  1369. goto err;
  1370. }
  1371. /* Self-diagnostics result is also shown on TE GPIO line. We need
  1372. * to re-enable TE after self diagnostics */
  1373. if (td->te_enabled && panel_data->use_ext_te) {
  1374. r = taal_dcs_write_1(td, MIPI_DCS_SET_TEAR_ON, 0);
  1375. if (r)
  1376. goto err;
  1377. }
  1378. dsi_bus_unlock(dssdev);
  1379. taal_queue_esd_work(dssdev);
  1380. mutex_unlock(&td->lock);
  1381. return;
  1382. err:
  1383. dev_err(&dssdev->dev, "performing LCD reset\n");
  1384. taal_panel_reset(dssdev);
  1385. dsi_bus_unlock(dssdev);
  1386. taal_queue_esd_work(dssdev);
  1387. mutex_unlock(&td->lock);
  1388. }
  1389. static struct omap_dss_driver taal_driver = {
  1390. .probe = taal_probe,
  1391. .remove = __exit_p(taal_remove),
  1392. .enable = taal_enable,
  1393. .disable = taal_disable,
  1394. .suspend = taal_suspend,
  1395. .resume = taal_resume,
  1396. .update = taal_update,
  1397. .sync = taal_sync,
  1398. .get_resolution = taal_get_resolution,
  1399. .get_recommended_bpp = omapdss_default_get_recommended_bpp,
  1400. .enable_te = taal_enable_te,
  1401. .get_te = taal_get_te,
  1402. .set_rotate = taal_rotate,
  1403. .get_rotate = taal_get_rotate,
  1404. .set_mirror = taal_mirror,
  1405. .get_mirror = taal_get_mirror,
  1406. .run_test = taal_run_test,
  1407. .memory_read = taal_memory_read,
  1408. .driver = {
  1409. .name = "taal",
  1410. .owner = THIS_MODULE,
  1411. },
  1412. };
  1413. static int __init taal_init(void)
  1414. {
  1415. omap_dss_register_driver(&taal_driver);
  1416. return 0;
  1417. }
  1418. static void __exit taal_exit(void)
  1419. {
  1420. omap_dss_unregister_driver(&taal_driver);
  1421. }
  1422. module_init(taal_init);
  1423. module_exit(taal_exit);
  1424. MODULE_AUTHOR("Tomi Valkeinen <tomi.valkeinen@nokia.com>");
  1425. MODULE_DESCRIPTION("Taal Driver");
  1426. MODULE_LICENSE("GPL");