panel-taal.c 39 KB

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