panel-taal.c 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917
  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. r = dsi_enable_video_output(dssdev, td->channel);
  930. if (r)
  931. goto err;
  932. td->enabled = 1;
  933. if (!td->intro_printed) {
  934. dev_info(&dssdev->dev, "%s panel revision %02x.%02x.%02x\n",
  935. td->panel_config->name, id1, id2, id3);
  936. if (td->cabc_broken)
  937. dev_info(&dssdev->dev,
  938. "old Taal version, CABC disabled\n");
  939. td->intro_printed = true;
  940. }
  941. omapdss_dsi_vc_enable_hs(dssdev, td->channel, true);
  942. return 0;
  943. err:
  944. dev_err(&dssdev->dev, "error while enabling panel, issuing HW reset\n");
  945. taal_hw_reset(dssdev);
  946. omapdss_dsi_display_disable(dssdev, true, false);
  947. err0:
  948. return r;
  949. }
  950. static void taal_power_off(struct omap_dss_device *dssdev)
  951. {
  952. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  953. int r;
  954. dsi_disable_video_output(dssdev, td->channel);
  955. r = taal_dcs_write_0(td, MIPI_DCS_SET_DISPLAY_OFF);
  956. if (!r)
  957. r = taal_sleep_in(td);
  958. if (r) {
  959. dev_err(&dssdev->dev,
  960. "error disabling panel, issuing HW reset\n");
  961. taal_hw_reset(dssdev);
  962. }
  963. omapdss_dsi_display_disable(dssdev, true, false);
  964. td->enabled = 0;
  965. }
  966. static int taal_panel_reset(struct omap_dss_device *dssdev)
  967. {
  968. dev_err(&dssdev->dev, "performing LCD reset\n");
  969. taal_power_off(dssdev);
  970. taal_hw_reset(dssdev);
  971. return taal_power_on(dssdev);
  972. }
  973. static int taal_enable(struct omap_dss_device *dssdev)
  974. {
  975. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  976. int r;
  977. dev_dbg(&dssdev->dev, "enable\n");
  978. mutex_lock(&td->lock);
  979. if (dssdev->state != OMAP_DSS_DISPLAY_DISABLED) {
  980. r = -EINVAL;
  981. goto err;
  982. }
  983. dsi_bus_lock(dssdev);
  984. r = taal_power_on(dssdev);
  985. dsi_bus_unlock(dssdev);
  986. if (r)
  987. goto err;
  988. taal_queue_esd_work(dssdev);
  989. dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
  990. mutex_unlock(&td->lock);
  991. return 0;
  992. err:
  993. dev_dbg(&dssdev->dev, "enable failed\n");
  994. mutex_unlock(&td->lock);
  995. return r;
  996. }
  997. static void taal_disable(struct omap_dss_device *dssdev)
  998. {
  999. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  1000. dev_dbg(&dssdev->dev, "disable\n");
  1001. mutex_lock(&td->lock);
  1002. taal_cancel_ulps_work(dssdev);
  1003. taal_cancel_esd_work(dssdev);
  1004. dsi_bus_lock(dssdev);
  1005. if (dssdev->state == OMAP_DSS_DISPLAY_ACTIVE) {
  1006. int r;
  1007. r = taal_wake_up(dssdev);
  1008. if (!r)
  1009. taal_power_off(dssdev);
  1010. }
  1011. dsi_bus_unlock(dssdev);
  1012. dssdev->state = OMAP_DSS_DISPLAY_DISABLED;
  1013. mutex_unlock(&td->lock);
  1014. }
  1015. static int taal_suspend(struct omap_dss_device *dssdev)
  1016. {
  1017. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  1018. int r;
  1019. dev_dbg(&dssdev->dev, "suspend\n");
  1020. mutex_lock(&td->lock);
  1021. if (dssdev->state != OMAP_DSS_DISPLAY_ACTIVE) {
  1022. r = -EINVAL;
  1023. goto err;
  1024. }
  1025. taal_cancel_ulps_work(dssdev);
  1026. taal_cancel_esd_work(dssdev);
  1027. dsi_bus_lock(dssdev);
  1028. r = taal_wake_up(dssdev);
  1029. if (!r)
  1030. taal_power_off(dssdev);
  1031. dsi_bus_unlock(dssdev);
  1032. dssdev->state = OMAP_DSS_DISPLAY_SUSPENDED;
  1033. mutex_unlock(&td->lock);
  1034. return 0;
  1035. err:
  1036. mutex_unlock(&td->lock);
  1037. return r;
  1038. }
  1039. static int taal_resume(struct omap_dss_device *dssdev)
  1040. {
  1041. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  1042. int r;
  1043. dev_dbg(&dssdev->dev, "resume\n");
  1044. mutex_lock(&td->lock);
  1045. if (dssdev->state != OMAP_DSS_DISPLAY_SUSPENDED) {
  1046. r = -EINVAL;
  1047. goto err;
  1048. }
  1049. dsi_bus_lock(dssdev);
  1050. r = taal_power_on(dssdev);
  1051. dsi_bus_unlock(dssdev);
  1052. if (r) {
  1053. dssdev->state = OMAP_DSS_DISPLAY_DISABLED;
  1054. } else {
  1055. dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
  1056. taal_queue_esd_work(dssdev);
  1057. }
  1058. mutex_unlock(&td->lock);
  1059. return r;
  1060. err:
  1061. mutex_unlock(&td->lock);
  1062. return r;
  1063. }
  1064. static void taal_framedone_cb(int err, void *data)
  1065. {
  1066. struct omap_dss_device *dssdev = data;
  1067. dev_dbg(&dssdev->dev, "framedone, err %d\n", err);
  1068. dsi_bus_unlock(dssdev);
  1069. }
  1070. static irqreturn_t taal_te_isr(int irq, void *data)
  1071. {
  1072. struct omap_dss_device *dssdev = data;
  1073. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  1074. int old;
  1075. int r;
  1076. old = atomic_cmpxchg(&td->do_update, 1, 0);
  1077. if (old) {
  1078. cancel_delayed_work(&td->te_timeout_work);
  1079. r = omap_dsi_update(dssdev, td->channel, taal_framedone_cb,
  1080. dssdev);
  1081. if (r)
  1082. goto err;
  1083. }
  1084. return IRQ_HANDLED;
  1085. err:
  1086. dev_err(&dssdev->dev, "start update failed\n");
  1087. dsi_bus_unlock(dssdev);
  1088. return IRQ_HANDLED;
  1089. }
  1090. static void taal_te_timeout_work_callback(struct work_struct *work)
  1091. {
  1092. struct taal_data *td = container_of(work, struct taal_data,
  1093. te_timeout_work.work);
  1094. struct omap_dss_device *dssdev = td->dssdev;
  1095. dev_err(&dssdev->dev, "TE not received for 250ms!\n");
  1096. atomic_set(&td->do_update, 0);
  1097. dsi_bus_unlock(dssdev);
  1098. }
  1099. static int taal_update(struct omap_dss_device *dssdev,
  1100. u16 x, u16 y, u16 w, u16 h)
  1101. {
  1102. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  1103. struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev);
  1104. int r;
  1105. dev_dbg(&dssdev->dev, "update %d, %d, %d x %d\n", x, y, w, h);
  1106. mutex_lock(&td->lock);
  1107. dsi_bus_lock(dssdev);
  1108. r = taal_wake_up(dssdev);
  1109. if (r)
  1110. goto err;
  1111. if (!td->enabled) {
  1112. r = 0;
  1113. goto err;
  1114. }
  1115. /* XXX no need to send this every frame, but dsi break if not done */
  1116. r = taal_set_update_window(td, 0, 0,
  1117. td->panel_config->timings.x_res,
  1118. td->panel_config->timings.y_res);
  1119. if (r)
  1120. goto err;
  1121. if (td->te_enabled && panel_data->use_ext_te) {
  1122. schedule_delayed_work(&td->te_timeout_work,
  1123. msecs_to_jiffies(250));
  1124. atomic_set(&td->do_update, 1);
  1125. } else {
  1126. r = omap_dsi_update(dssdev, td->channel, taal_framedone_cb,
  1127. dssdev);
  1128. if (r)
  1129. goto err;
  1130. }
  1131. /* note: no bus_unlock here. unlock is in framedone_cb */
  1132. mutex_unlock(&td->lock);
  1133. return 0;
  1134. err:
  1135. dsi_bus_unlock(dssdev);
  1136. mutex_unlock(&td->lock);
  1137. return r;
  1138. }
  1139. static int taal_sync(struct omap_dss_device *dssdev)
  1140. {
  1141. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  1142. dev_dbg(&dssdev->dev, "sync\n");
  1143. mutex_lock(&td->lock);
  1144. dsi_bus_lock(dssdev);
  1145. dsi_bus_unlock(dssdev);
  1146. mutex_unlock(&td->lock);
  1147. dev_dbg(&dssdev->dev, "sync done\n");
  1148. return 0;
  1149. }
  1150. static int _taal_enable_te(struct omap_dss_device *dssdev, bool enable)
  1151. {
  1152. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  1153. struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev);
  1154. int r;
  1155. if (enable)
  1156. r = taal_dcs_write_1(td, MIPI_DCS_SET_TEAR_ON, 0);
  1157. else
  1158. r = taal_dcs_write_0(td, MIPI_DCS_SET_TEAR_OFF);
  1159. if (!panel_data->use_ext_te)
  1160. omapdss_dsi_enable_te(dssdev, enable);
  1161. if (td->panel_config->sleep.enable_te)
  1162. msleep(td->panel_config->sleep.enable_te);
  1163. return r;
  1164. }
  1165. static int taal_enable_te(struct omap_dss_device *dssdev, bool enable)
  1166. {
  1167. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  1168. int r;
  1169. mutex_lock(&td->lock);
  1170. if (td->te_enabled == enable)
  1171. goto end;
  1172. dsi_bus_lock(dssdev);
  1173. if (td->enabled) {
  1174. r = taal_wake_up(dssdev);
  1175. if (r)
  1176. goto err;
  1177. r = _taal_enable_te(dssdev, enable);
  1178. if (r)
  1179. goto err;
  1180. }
  1181. td->te_enabled = enable;
  1182. dsi_bus_unlock(dssdev);
  1183. end:
  1184. mutex_unlock(&td->lock);
  1185. return 0;
  1186. err:
  1187. dsi_bus_unlock(dssdev);
  1188. mutex_unlock(&td->lock);
  1189. return r;
  1190. }
  1191. static int taal_get_te(struct omap_dss_device *dssdev)
  1192. {
  1193. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  1194. int r;
  1195. mutex_lock(&td->lock);
  1196. r = td->te_enabled;
  1197. mutex_unlock(&td->lock);
  1198. return r;
  1199. }
  1200. static int taal_rotate(struct omap_dss_device *dssdev, u8 rotate)
  1201. {
  1202. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  1203. int r;
  1204. dev_dbg(&dssdev->dev, "rotate %d\n", rotate);
  1205. mutex_lock(&td->lock);
  1206. if (td->rotate == rotate)
  1207. goto end;
  1208. dsi_bus_lock(dssdev);
  1209. if (td->enabled) {
  1210. r = taal_wake_up(dssdev);
  1211. if (r)
  1212. goto err;
  1213. r = taal_set_addr_mode(td, rotate, td->mirror);
  1214. if (r)
  1215. goto err;
  1216. }
  1217. td->rotate = rotate;
  1218. dsi_bus_unlock(dssdev);
  1219. end:
  1220. mutex_unlock(&td->lock);
  1221. return 0;
  1222. err:
  1223. dsi_bus_unlock(dssdev);
  1224. mutex_unlock(&td->lock);
  1225. return r;
  1226. }
  1227. static u8 taal_get_rotate(struct omap_dss_device *dssdev)
  1228. {
  1229. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  1230. int r;
  1231. mutex_lock(&td->lock);
  1232. r = td->rotate;
  1233. mutex_unlock(&td->lock);
  1234. return r;
  1235. }
  1236. static int taal_mirror(struct omap_dss_device *dssdev, bool enable)
  1237. {
  1238. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  1239. int r;
  1240. dev_dbg(&dssdev->dev, "mirror %d\n", enable);
  1241. mutex_lock(&td->lock);
  1242. if (td->mirror == enable)
  1243. goto end;
  1244. dsi_bus_lock(dssdev);
  1245. if (td->enabled) {
  1246. r = taal_wake_up(dssdev);
  1247. if (r)
  1248. goto err;
  1249. r = taal_set_addr_mode(td, td->rotate, enable);
  1250. if (r)
  1251. goto err;
  1252. }
  1253. td->mirror = enable;
  1254. dsi_bus_unlock(dssdev);
  1255. end:
  1256. mutex_unlock(&td->lock);
  1257. return 0;
  1258. err:
  1259. dsi_bus_unlock(dssdev);
  1260. mutex_unlock(&td->lock);
  1261. return r;
  1262. }
  1263. static bool taal_get_mirror(struct omap_dss_device *dssdev)
  1264. {
  1265. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  1266. int r;
  1267. mutex_lock(&td->lock);
  1268. r = td->mirror;
  1269. mutex_unlock(&td->lock);
  1270. return r;
  1271. }
  1272. static int taal_run_test(struct omap_dss_device *dssdev, int test_num)
  1273. {
  1274. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  1275. u8 id1, id2, id3;
  1276. int r;
  1277. mutex_lock(&td->lock);
  1278. if (!td->enabled) {
  1279. r = -ENODEV;
  1280. goto err1;
  1281. }
  1282. dsi_bus_lock(dssdev);
  1283. r = taal_wake_up(dssdev);
  1284. if (r)
  1285. goto err2;
  1286. r = taal_dcs_read_1(td, DCS_GET_ID1, &id1);
  1287. if (r)
  1288. goto err2;
  1289. r = taal_dcs_read_1(td, DCS_GET_ID2, &id2);
  1290. if (r)
  1291. goto err2;
  1292. r = taal_dcs_read_1(td, DCS_GET_ID3, &id3);
  1293. if (r)
  1294. goto err2;
  1295. dsi_bus_unlock(dssdev);
  1296. mutex_unlock(&td->lock);
  1297. return 0;
  1298. err2:
  1299. dsi_bus_unlock(dssdev);
  1300. err1:
  1301. mutex_unlock(&td->lock);
  1302. return r;
  1303. }
  1304. static int taal_memory_read(struct omap_dss_device *dssdev,
  1305. void *buf, size_t size,
  1306. u16 x, u16 y, u16 w, u16 h)
  1307. {
  1308. int r;
  1309. int first = 1;
  1310. int plen;
  1311. unsigned buf_used = 0;
  1312. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  1313. if (size < w * h * 3)
  1314. return -ENOMEM;
  1315. mutex_lock(&td->lock);
  1316. if (!td->enabled) {
  1317. r = -ENODEV;
  1318. goto err1;
  1319. }
  1320. size = min(w * h * 3,
  1321. dssdev->panel.timings.x_res *
  1322. dssdev->panel.timings.y_res * 3);
  1323. dsi_bus_lock(dssdev);
  1324. r = taal_wake_up(dssdev);
  1325. if (r)
  1326. goto err2;
  1327. /* plen 1 or 2 goes into short packet. until checksum error is fixed,
  1328. * use short packets. plen 32 works, but bigger packets seem to cause
  1329. * an error. */
  1330. if (size % 2)
  1331. plen = 1;
  1332. else
  1333. plen = 2;
  1334. taal_set_update_window(td, x, y, w, h);
  1335. r = dsi_vc_set_max_rx_packet_size(dssdev, td->channel, plen);
  1336. if (r)
  1337. goto err2;
  1338. while (buf_used < size) {
  1339. u8 dcs_cmd = first ? 0x2e : 0x3e;
  1340. first = 0;
  1341. r = dsi_vc_dcs_read(dssdev, td->channel, dcs_cmd,
  1342. buf + buf_used, size - buf_used);
  1343. if (r < 0) {
  1344. dev_err(&dssdev->dev, "read error\n");
  1345. goto err3;
  1346. }
  1347. buf_used += r;
  1348. if (r < plen) {
  1349. dev_err(&dssdev->dev, "short read\n");
  1350. break;
  1351. }
  1352. if (signal_pending(current)) {
  1353. dev_err(&dssdev->dev, "signal pending, "
  1354. "aborting memory read\n");
  1355. r = -ERESTARTSYS;
  1356. goto err3;
  1357. }
  1358. }
  1359. r = buf_used;
  1360. err3:
  1361. dsi_vc_set_max_rx_packet_size(dssdev, td->channel, 1);
  1362. err2:
  1363. dsi_bus_unlock(dssdev);
  1364. err1:
  1365. mutex_unlock(&td->lock);
  1366. return r;
  1367. }
  1368. static void taal_ulps_work(struct work_struct *work)
  1369. {
  1370. struct taal_data *td = container_of(work, struct taal_data,
  1371. ulps_work.work);
  1372. struct omap_dss_device *dssdev = td->dssdev;
  1373. mutex_lock(&td->lock);
  1374. if (dssdev->state != OMAP_DSS_DISPLAY_ACTIVE || !td->enabled) {
  1375. mutex_unlock(&td->lock);
  1376. return;
  1377. }
  1378. dsi_bus_lock(dssdev);
  1379. taal_enter_ulps(dssdev);
  1380. dsi_bus_unlock(dssdev);
  1381. mutex_unlock(&td->lock);
  1382. }
  1383. static void taal_esd_work(struct work_struct *work)
  1384. {
  1385. struct taal_data *td = container_of(work, struct taal_data,
  1386. esd_work.work);
  1387. struct omap_dss_device *dssdev = td->dssdev;
  1388. struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev);
  1389. u8 state1, state2;
  1390. int r;
  1391. mutex_lock(&td->lock);
  1392. if (!td->enabled) {
  1393. mutex_unlock(&td->lock);
  1394. return;
  1395. }
  1396. dsi_bus_lock(dssdev);
  1397. r = taal_wake_up(dssdev);
  1398. if (r) {
  1399. dev_err(&dssdev->dev, "failed to exit ULPS\n");
  1400. goto err;
  1401. }
  1402. r = taal_dcs_read_1(td, MIPI_DCS_GET_DIAGNOSTIC_RESULT, &state1);
  1403. if (r) {
  1404. dev_err(&dssdev->dev, "failed to read Taal status\n");
  1405. goto err;
  1406. }
  1407. /* Run self diagnostics */
  1408. r = taal_sleep_out(td);
  1409. if (r) {
  1410. dev_err(&dssdev->dev, "failed to run Taal self-diagnostics\n");
  1411. goto err;
  1412. }
  1413. r = taal_dcs_read_1(td, MIPI_DCS_GET_DIAGNOSTIC_RESULT, &state2);
  1414. if (r) {
  1415. dev_err(&dssdev->dev, "failed to read Taal status\n");
  1416. goto err;
  1417. }
  1418. /* Each sleep out command will trigger a self diagnostic and flip
  1419. * Bit6 if the test passes.
  1420. */
  1421. if (!((state1 ^ state2) & (1 << 6))) {
  1422. dev_err(&dssdev->dev, "LCD self diagnostics failed\n");
  1423. goto err;
  1424. }
  1425. /* Self-diagnostics result is also shown on TE GPIO line. We need
  1426. * to re-enable TE after self diagnostics */
  1427. if (td->te_enabled && panel_data->use_ext_te) {
  1428. r = taal_dcs_write_1(td, MIPI_DCS_SET_TEAR_ON, 0);
  1429. if (r)
  1430. goto err;
  1431. }
  1432. dsi_bus_unlock(dssdev);
  1433. taal_queue_esd_work(dssdev);
  1434. mutex_unlock(&td->lock);
  1435. return;
  1436. err:
  1437. dev_err(&dssdev->dev, "performing LCD reset\n");
  1438. taal_panel_reset(dssdev);
  1439. dsi_bus_unlock(dssdev);
  1440. taal_queue_esd_work(dssdev);
  1441. mutex_unlock(&td->lock);
  1442. }
  1443. static struct omap_dss_driver taal_driver = {
  1444. .probe = taal_probe,
  1445. .remove = __exit_p(taal_remove),
  1446. .enable = taal_enable,
  1447. .disable = taal_disable,
  1448. .suspend = taal_suspend,
  1449. .resume = taal_resume,
  1450. .update = taal_update,
  1451. .sync = taal_sync,
  1452. .get_resolution = taal_get_resolution,
  1453. .get_recommended_bpp = omapdss_default_get_recommended_bpp,
  1454. .enable_te = taal_enable_te,
  1455. .get_te = taal_get_te,
  1456. .set_rotate = taal_rotate,
  1457. .get_rotate = taal_get_rotate,
  1458. .set_mirror = taal_mirror,
  1459. .get_mirror = taal_get_mirror,
  1460. .run_test = taal_run_test,
  1461. .memory_read = taal_memory_read,
  1462. .get_timings = taal_get_timings,
  1463. .driver = {
  1464. .name = "taal",
  1465. .owner = THIS_MODULE,
  1466. },
  1467. };
  1468. static int __init taal_init(void)
  1469. {
  1470. omap_dss_register_driver(&taal_driver);
  1471. return 0;
  1472. }
  1473. static void __exit taal_exit(void)
  1474. {
  1475. omap_dss_unregister_driver(&taal_driver);
  1476. }
  1477. module_init(taal_init);
  1478. module_exit(taal_exit);
  1479. MODULE_AUTHOR("Tomi Valkeinen <tomi.valkeinen@nokia.com>");
  1480. MODULE_DESCRIPTION("Taal Driver");
  1481. MODULE_LICENSE("GPL");