panel-taal.c 38 KB

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