panel-taal.c 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956
  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. dev_err(&dssdev->dev, "failed to enable DSI\n");
  404. goto err1;
  405. }
  406. omapdss_dsi_vc_enable_hs(dssdev, td->channel, true);
  407. r = _taal_enable_te(dssdev, true);
  408. if (r) {
  409. dev_err(&dssdev->dev, "failed to re-enable TE");
  410. goto err2;
  411. }
  412. enable_irq(gpio_to_irq(panel_data->ext_te_gpio));
  413. taal_queue_ulps_work(dssdev);
  414. td->ulps_enabled = false;
  415. return 0;
  416. err2:
  417. dev_err(&dssdev->dev, "failed to exit ULPS");
  418. r = taal_panel_reset(dssdev);
  419. if (!r) {
  420. enable_irq(gpio_to_irq(panel_data->ext_te_gpio));
  421. td->ulps_enabled = false;
  422. }
  423. err1:
  424. taal_queue_ulps_work(dssdev);
  425. return r;
  426. }
  427. static int taal_wake_up(struct omap_dss_device *dssdev)
  428. {
  429. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  430. if (td->ulps_enabled)
  431. return taal_exit_ulps(dssdev);
  432. taal_cancel_ulps_work(dssdev);
  433. taal_queue_ulps_work(dssdev);
  434. return 0;
  435. }
  436. static int taal_bl_update_status(struct backlight_device *dev)
  437. {
  438. struct omap_dss_device *dssdev = dev_get_drvdata(&dev->dev);
  439. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  440. struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev);
  441. int r;
  442. int level;
  443. if (dev->props.fb_blank == FB_BLANK_UNBLANK &&
  444. dev->props.power == FB_BLANK_UNBLANK)
  445. level = dev->props.brightness;
  446. else
  447. level = 0;
  448. dev_dbg(&dssdev->dev, "update brightness to %d\n", level);
  449. mutex_lock(&td->lock);
  450. if (td->use_dsi_bl) {
  451. if (td->enabled) {
  452. dsi_bus_lock(dssdev);
  453. r = taal_wake_up(dssdev);
  454. if (!r)
  455. r = taal_dcs_write_1(td, DCS_BRIGHTNESS, level);
  456. dsi_bus_unlock(dssdev);
  457. } else {
  458. r = 0;
  459. }
  460. } else {
  461. if (!panel_data->set_backlight)
  462. r = -EINVAL;
  463. else
  464. r = panel_data->set_backlight(dssdev, level);
  465. }
  466. mutex_unlock(&td->lock);
  467. return r;
  468. }
  469. static int taal_bl_get_intensity(struct backlight_device *dev)
  470. {
  471. if (dev->props.fb_blank == FB_BLANK_UNBLANK &&
  472. dev->props.power == FB_BLANK_UNBLANK)
  473. return dev->props.brightness;
  474. return 0;
  475. }
  476. static const struct backlight_ops taal_bl_ops = {
  477. .get_brightness = taal_bl_get_intensity,
  478. .update_status = taal_bl_update_status,
  479. };
  480. static void taal_get_timings(struct omap_dss_device *dssdev,
  481. struct omap_video_timings *timings)
  482. {
  483. *timings = dssdev->panel.timings;
  484. }
  485. static void taal_get_resolution(struct omap_dss_device *dssdev,
  486. u16 *xres, u16 *yres)
  487. {
  488. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  489. if (td->rotate == 0 || td->rotate == 2) {
  490. *xres = dssdev->panel.timings.x_res;
  491. *yres = dssdev->panel.timings.y_res;
  492. } else {
  493. *yres = dssdev->panel.timings.x_res;
  494. *xres = dssdev->panel.timings.y_res;
  495. }
  496. }
  497. static ssize_t taal_num_errors_show(struct device *dev,
  498. struct device_attribute *attr, char *buf)
  499. {
  500. struct omap_dss_device *dssdev = to_dss_device(dev);
  501. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  502. u8 errors;
  503. int r;
  504. mutex_lock(&td->lock);
  505. if (td->enabled) {
  506. dsi_bus_lock(dssdev);
  507. r = taal_wake_up(dssdev);
  508. if (!r)
  509. r = taal_dcs_read_1(td, DCS_READ_NUM_ERRORS, &errors);
  510. dsi_bus_unlock(dssdev);
  511. } else {
  512. r = -ENODEV;
  513. }
  514. mutex_unlock(&td->lock);
  515. if (r)
  516. return r;
  517. return snprintf(buf, PAGE_SIZE, "%d\n", errors);
  518. }
  519. static ssize_t taal_hw_revision_show(struct device *dev,
  520. struct device_attribute *attr, char *buf)
  521. {
  522. struct omap_dss_device *dssdev = to_dss_device(dev);
  523. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  524. u8 id1, id2, id3;
  525. int r;
  526. mutex_lock(&td->lock);
  527. if (td->enabled) {
  528. dsi_bus_lock(dssdev);
  529. r = taal_wake_up(dssdev);
  530. if (!r)
  531. r = taal_get_id(td, &id1, &id2, &id3);
  532. dsi_bus_unlock(dssdev);
  533. } else {
  534. r = -ENODEV;
  535. }
  536. mutex_unlock(&td->lock);
  537. if (r)
  538. return r;
  539. return snprintf(buf, PAGE_SIZE, "%02x.%02x.%02x\n", id1, id2, id3);
  540. }
  541. static const char *cabc_modes[] = {
  542. "off", /* used also always when CABC is not supported */
  543. "ui",
  544. "still-image",
  545. "moving-image",
  546. };
  547. static ssize_t show_cabc_mode(struct device *dev,
  548. struct device_attribute *attr,
  549. char *buf)
  550. {
  551. struct omap_dss_device *dssdev = to_dss_device(dev);
  552. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  553. const char *mode_str;
  554. int mode;
  555. int len;
  556. mode = td->cabc_mode;
  557. mode_str = "unknown";
  558. if (mode >= 0 && mode < ARRAY_SIZE(cabc_modes))
  559. mode_str = cabc_modes[mode];
  560. len = snprintf(buf, PAGE_SIZE, "%s\n", mode_str);
  561. return len < PAGE_SIZE - 1 ? len : PAGE_SIZE - 1;
  562. }
  563. static ssize_t store_cabc_mode(struct device *dev,
  564. struct device_attribute *attr,
  565. const char *buf, size_t count)
  566. {
  567. struct omap_dss_device *dssdev = to_dss_device(dev);
  568. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  569. int i;
  570. int r;
  571. for (i = 0; i < ARRAY_SIZE(cabc_modes); i++) {
  572. if (sysfs_streq(cabc_modes[i], buf))
  573. break;
  574. }
  575. if (i == ARRAY_SIZE(cabc_modes))
  576. return -EINVAL;
  577. mutex_lock(&td->lock);
  578. if (td->enabled) {
  579. dsi_bus_lock(dssdev);
  580. if (!td->cabc_broken) {
  581. r = taal_wake_up(dssdev);
  582. if (r)
  583. goto err;
  584. r = taal_dcs_write_1(td, DCS_WRITE_CABC, i);
  585. if (r)
  586. goto err;
  587. }
  588. dsi_bus_unlock(dssdev);
  589. }
  590. td->cabc_mode = i;
  591. mutex_unlock(&td->lock);
  592. return count;
  593. err:
  594. dsi_bus_unlock(dssdev);
  595. mutex_unlock(&td->lock);
  596. return r;
  597. }
  598. static ssize_t show_cabc_available_modes(struct device *dev,
  599. struct device_attribute *attr,
  600. char *buf)
  601. {
  602. int len;
  603. int i;
  604. for (i = 0, len = 0;
  605. len < PAGE_SIZE && i < ARRAY_SIZE(cabc_modes); i++)
  606. len += snprintf(&buf[len], PAGE_SIZE - len, "%s%s%s",
  607. i ? " " : "", cabc_modes[i],
  608. i == ARRAY_SIZE(cabc_modes) - 1 ? "\n" : "");
  609. return len < PAGE_SIZE ? len : PAGE_SIZE - 1;
  610. }
  611. static ssize_t taal_store_esd_interval(struct device *dev,
  612. struct device_attribute *attr,
  613. const char *buf, size_t count)
  614. {
  615. struct omap_dss_device *dssdev = to_dss_device(dev);
  616. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  617. unsigned long t;
  618. int r;
  619. r = strict_strtoul(buf, 10, &t);
  620. if (r)
  621. return r;
  622. mutex_lock(&td->lock);
  623. taal_cancel_esd_work(dssdev);
  624. td->esd_interval = t;
  625. if (td->enabled)
  626. taal_queue_esd_work(dssdev);
  627. mutex_unlock(&td->lock);
  628. return count;
  629. }
  630. static ssize_t taal_show_esd_interval(struct device *dev,
  631. struct device_attribute *attr,
  632. char *buf)
  633. {
  634. struct omap_dss_device *dssdev = to_dss_device(dev);
  635. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  636. unsigned t;
  637. mutex_lock(&td->lock);
  638. t = td->esd_interval;
  639. mutex_unlock(&td->lock);
  640. return snprintf(buf, PAGE_SIZE, "%u\n", t);
  641. }
  642. static ssize_t taal_store_ulps(struct device *dev,
  643. struct device_attribute *attr,
  644. const char *buf, size_t count)
  645. {
  646. struct omap_dss_device *dssdev = to_dss_device(dev);
  647. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  648. unsigned long t;
  649. int r;
  650. r = strict_strtoul(buf, 10, &t);
  651. if (r)
  652. return r;
  653. mutex_lock(&td->lock);
  654. if (td->enabled) {
  655. dsi_bus_lock(dssdev);
  656. if (t)
  657. r = taal_enter_ulps(dssdev);
  658. else
  659. r = taal_wake_up(dssdev);
  660. dsi_bus_unlock(dssdev);
  661. }
  662. mutex_unlock(&td->lock);
  663. if (r)
  664. return r;
  665. return count;
  666. }
  667. static ssize_t taal_show_ulps(struct device *dev,
  668. struct device_attribute *attr,
  669. char *buf)
  670. {
  671. struct omap_dss_device *dssdev = to_dss_device(dev);
  672. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  673. unsigned t;
  674. mutex_lock(&td->lock);
  675. t = td->ulps_enabled;
  676. mutex_unlock(&td->lock);
  677. return snprintf(buf, PAGE_SIZE, "%u\n", t);
  678. }
  679. static ssize_t taal_store_ulps_timeout(struct device *dev,
  680. struct device_attribute *attr,
  681. const char *buf, size_t count)
  682. {
  683. struct omap_dss_device *dssdev = to_dss_device(dev);
  684. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  685. unsigned long t;
  686. int r;
  687. r = strict_strtoul(buf, 10, &t);
  688. if (r)
  689. return r;
  690. mutex_lock(&td->lock);
  691. td->ulps_timeout = t;
  692. if (td->enabled) {
  693. /* taal_wake_up will restart the timer */
  694. dsi_bus_lock(dssdev);
  695. r = taal_wake_up(dssdev);
  696. dsi_bus_unlock(dssdev);
  697. }
  698. mutex_unlock(&td->lock);
  699. if (r)
  700. return r;
  701. return count;
  702. }
  703. static ssize_t taal_show_ulps_timeout(struct device *dev,
  704. struct device_attribute *attr,
  705. char *buf)
  706. {
  707. struct omap_dss_device *dssdev = to_dss_device(dev);
  708. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  709. unsigned t;
  710. mutex_lock(&td->lock);
  711. t = td->ulps_timeout;
  712. mutex_unlock(&td->lock);
  713. return snprintf(buf, PAGE_SIZE, "%u\n", t);
  714. }
  715. static DEVICE_ATTR(num_dsi_errors, S_IRUGO, taal_num_errors_show, NULL);
  716. static DEVICE_ATTR(hw_revision, S_IRUGO, taal_hw_revision_show, NULL);
  717. static DEVICE_ATTR(cabc_mode, S_IRUGO | S_IWUSR,
  718. show_cabc_mode, store_cabc_mode);
  719. static DEVICE_ATTR(cabc_available_modes, S_IRUGO,
  720. show_cabc_available_modes, NULL);
  721. static DEVICE_ATTR(esd_interval, S_IRUGO | S_IWUSR,
  722. taal_show_esd_interval, taal_store_esd_interval);
  723. static DEVICE_ATTR(ulps, S_IRUGO | S_IWUSR,
  724. taal_show_ulps, taal_store_ulps);
  725. static DEVICE_ATTR(ulps_timeout, S_IRUGO | S_IWUSR,
  726. taal_show_ulps_timeout, taal_store_ulps_timeout);
  727. static struct attribute *taal_attrs[] = {
  728. &dev_attr_num_dsi_errors.attr,
  729. &dev_attr_hw_revision.attr,
  730. &dev_attr_cabc_mode.attr,
  731. &dev_attr_cabc_available_modes.attr,
  732. &dev_attr_esd_interval.attr,
  733. &dev_attr_ulps.attr,
  734. &dev_attr_ulps_timeout.attr,
  735. NULL,
  736. };
  737. static struct attribute_group taal_attr_group = {
  738. .attrs = taal_attrs,
  739. };
  740. static void taal_hw_reset(struct omap_dss_device *dssdev)
  741. {
  742. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  743. struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev);
  744. if (panel_data->reset_gpio == -1)
  745. return;
  746. gpio_set_value(panel_data->reset_gpio, 1);
  747. if (td->panel_config->reset_sequence.high)
  748. udelay(td->panel_config->reset_sequence.high);
  749. /* reset the panel */
  750. gpio_set_value(panel_data->reset_gpio, 0);
  751. /* assert reset */
  752. if (td->panel_config->reset_sequence.low)
  753. udelay(td->panel_config->reset_sequence.low);
  754. gpio_set_value(panel_data->reset_gpio, 1);
  755. /* wait after releasing reset */
  756. if (td->panel_config->sleep.hw_reset)
  757. msleep(td->panel_config->sleep.hw_reset);
  758. }
  759. static int taal_probe(struct omap_dss_device *dssdev)
  760. {
  761. struct backlight_properties props;
  762. struct taal_data *td;
  763. struct backlight_device *bldev;
  764. struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev);
  765. struct panel_config *panel_config = NULL;
  766. int r, i;
  767. dev_dbg(&dssdev->dev, "probe\n");
  768. if (!panel_data || !panel_data->name) {
  769. r = -EINVAL;
  770. goto err;
  771. }
  772. for (i = 0; i < ARRAY_SIZE(panel_configs); i++) {
  773. if (strcmp(panel_data->name, panel_configs[i].name) == 0) {
  774. panel_config = &panel_configs[i];
  775. break;
  776. }
  777. }
  778. if (!panel_config) {
  779. r = -EINVAL;
  780. goto err;
  781. }
  782. dssdev->panel.config = OMAP_DSS_LCD_TFT;
  783. dssdev->panel.timings = panel_config->timings;
  784. dssdev->ctrl.pixel_size = 24;
  785. td = kzalloc(sizeof(*td), GFP_KERNEL);
  786. if (!td) {
  787. r = -ENOMEM;
  788. goto err;
  789. }
  790. td->dssdev = dssdev;
  791. td->panel_config = panel_config;
  792. td->esd_interval = panel_data->esd_interval;
  793. td->ulps_enabled = false;
  794. td->ulps_timeout = panel_data->ulps_timeout;
  795. mutex_init(&td->lock);
  796. atomic_set(&td->do_update, 0);
  797. r = init_regulators(dssdev, panel_config->regulators,
  798. panel_config->num_regulators);
  799. if (r)
  800. goto err_reg;
  801. td->workqueue = create_singlethread_workqueue("taal_esd");
  802. if (td->workqueue == NULL) {
  803. dev_err(&dssdev->dev, "can't create ESD workqueue\n");
  804. r = -ENOMEM;
  805. goto err_wq;
  806. }
  807. INIT_DELAYED_WORK_DEFERRABLE(&td->esd_work, taal_esd_work);
  808. INIT_DELAYED_WORK(&td->ulps_work, taal_ulps_work);
  809. dev_set_drvdata(&dssdev->dev, td);
  810. taal_hw_reset(dssdev);
  811. /* if no platform set_backlight() defined, presume DSI backlight
  812. * control */
  813. memset(&props, 0, sizeof(struct backlight_properties));
  814. if (!panel_data->set_backlight)
  815. td->use_dsi_bl = true;
  816. if (td->use_dsi_bl)
  817. props.max_brightness = 255;
  818. else
  819. props.max_brightness = 127;
  820. props.type = BACKLIGHT_RAW;
  821. bldev = backlight_device_register(dev_name(&dssdev->dev), &dssdev->dev,
  822. dssdev, &taal_bl_ops, &props);
  823. if (IS_ERR(bldev)) {
  824. r = PTR_ERR(bldev);
  825. goto err_bl;
  826. }
  827. td->bldev = bldev;
  828. bldev->props.fb_blank = FB_BLANK_UNBLANK;
  829. bldev->props.power = FB_BLANK_UNBLANK;
  830. if (td->use_dsi_bl)
  831. bldev->props.brightness = 255;
  832. else
  833. bldev->props.brightness = 127;
  834. taal_bl_update_status(bldev);
  835. if (panel_data->use_ext_te) {
  836. int gpio = panel_data->ext_te_gpio;
  837. r = gpio_request(gpio, "taal irq");
  838. if (r) {
  839. dev_err(&dssdev->dev, "GPIO request failed\n");
  840. goto err_gpio;
  841. }
  842. gpio_direction_input(gpio);
  843. r = request_irq(gpio_to_irq(gpio), taal_te_isr,
  844. IRQF_DISABLED | IRQF_TRIGGER_RISING,
  845. "taal vsync", dssdev);
  846. if (r) {
  847. dev_err(&dssdev->dev, "IRQ request failed\n");
  848. gpio_free(gpio);
  849. goto err_irq;
  850. }
  851. INIT_DELAYED_WORK_DEFERRABLE(&td->te_timeout_work,
  852. taal_te_timeout_work_callback);
  853. dev_dbg(&dssdev->dev, "Using GPIO TE\n");
  854. }
  855. r = omap_dsi_request_vc(dssdev, &td->channel);
  856. if (r) {
  857. dev_err(&dssdev->dev, "failed to get virtual channel\n");
  858. goto err_req_vc;
  859. }
  860. r = omap_dsi_set_vc_id(dssdev, td->channel, TCH);
  861. if (r) {
  862. dev_err(&dssdev->dev, "failed to set VC_ID\n");
  863. goto err_vc_id;
  864. }
  865. r = sysfs_create_group(&dssdev->dev.kobj, &taal_attr_group);
  866. if (r) {
  867. dev_err(&dssdev->dev, "failed to create sysfs files\n");
  868. goto err_vc_id;
  869. }
  870. return 0;
  871. err_vc_id:
  872. omap_dsi_release_vc(dssdev, td->channel);
  873. err_req_vc:
  874. if (panel_data->use_ext_te)
  875. free_irq(gpio_to_irq(panel_data->ext_te_gpio), dssdev);
  876. err_irq:
  877. if (panel_data->use_ext_te)
  878. gpio_free(panel_data->ext_te_gpio);
  879. err_gpio:
  880. backlight_device_unregister(bldev);
  881. err_bl:
  882. destroy_workqueue(td->workqueue);
  883. err_wq:
  884. free_regulators(panel_config->regulators, panel_config->num_regulators);
  885. err_reg:
  886. kfree(td);
  887. err:
  888. return r;
  889. }
  890. static void __exit taal_remove(struct omap_dss_device *dssdev)
  891. {
  892. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  893. struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev);
  894. struct backlight_device *bldev;
  895. dev_dbg(&dssdev->dev, "remove\n");
  896. sysfs_remove_group(&dssdev->dev.kobj, &taal_attr_group);
  897. omap_dsi_release_vc(dssdev, td->channel);
  898. if (panel_data->use_ext_te) {
  899. int gpio = panel_data->ext_te_gpio;
  900. free_irq(gpio_to_irq(gpio), dssdev);
  901. gpio_free(gpio);
  902. }
  903. bldev = td->bldev;
  904. bldev->props.power = FB_BLANK_POWERDOWN;
  905. taal_bl_update_status(bldev);
  906. backlight_device_unregister(bldev);
  907. taal_cancel_ulps_work(dssdev);
  908. taal_cancel_esd_work(dssdev);
  909. destroy_workqueue(td->workqueue);
  910. /* reset, to be sure that the panel is in a valid state */
  911. taal_hw_reset(dssdev);
  912. free_regulators(td->panel_config->regulators,
  913. td->panel_config->num_regulators);
  914. kfree(td);
  915. }
  916. static int taal_power_on(struct omap_dss_device *dssdev)
  917. {
  918. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  919. u8 id1, id2, id3;
  920. int r;
  921. r = omapdss_dsi_display_enable(dssdev);
  922. if (r) {
  923. dev_err(&dssdev->dev, "failed to enable DSI\n");
  924. goto err0;
  925. }
  926. taal_hw_reset(dssdev);
  927. omapdss_dsi_vc_enable_hs(dssdev, td->channel, false);
  928. r = taal_sleep_out(td);
  929. if (r)
  930. goto err;
  931. r = taal_get_id(td, &id1, &id2, &id3);
  932. if (r)
  933. goto err;
  934. /* on early Taal revisions CABC is broken */
  935. if (td->panel_config->type == PANEL_TAAL &&
  936. (id2 == 0x00 || id2 == 0xff || id2 == 0x81))
  937. td->cabc_broken = true;
  938. r = taal_dcs_write_1(td, DCS_BRIGHTNESS, 0xff);
  939. if (r)
  940. goto err;
  941. r = taal_dcs_write_1(td, DCS_CTRL_DISPLAY,
  942. (1<<2) | (1<<5)); /* BL | BCTRL */
  943. if (r)
  944. goto err;
  945. r = taal_dcs_write_1(td, DCS_PIXEL_FORMAT, 0x7); /* 24bit/pixel */
  946. if (r)
  947. goto err;
  948. r = taal_set_addr_mode(td, td->rotate, td->mirror);
  949. if (r)
  950. goto err;
  951. if (!td->cabc_broken) {
  952. r = taal_dcs_write_1(td, DCS_WRITE_CABC, td->cabc_mode);
  953. if (r)
  954. goto err;
  955. }
  956. r = taal_dcs_write_0(td, DCS_DISPLAY_ON);
  957. if (r)
  958. goto err;
  959. r = _taal_enable_te(dssdev, td->te_enabled);
  960. if (r)
  961. goto err;
  962. td->enabled = 1;
  963. if (!td->intro_printed) {
  964. dev_info(&dssdev->dev, "%s panel revision %02x.%02x.%02x\n",
  965. td->panel_config->name, id1, id2, id3);
  966. if (td->cabc_broken)
  967. dev_info(&dssdev->dev,
  968. "old Taal version, CABC disabled\n");
  969. td->intro_printed = true;
  970. }
  971. omapdss_dsi_vc_enable_hs(dssdev, td->channel, true);
  972. return 0;
  973. err:
  974. dev_err(&dssdev->dev, "error while enabling panel, issuing HW reset\n");
  975. taal_hw_reset(dssdev);
  976. omapdss_dsi_display_disable(dssdev, true, false);
  977. err0:
  978. return r;
  979. }
  980. static void taal_power_off(struct omap_dss_device *dssdev)
  981. {
  982. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  983. int r;
  984. r = taal_dcs_write_0(td, DCS_DISPLAY_OFF);
  985. if (!r)
  986. r = taal_sleep_in(td);
  987. if (r) {
  988. dev_err(&dssdev->dev,
  989. "error disabling panel, issuing HW reset\n");
  990. taal_hw_reset(dssdev);
  991. }
  992. omapdss_dsi_display_disable(dssdev, true, false);
  993. td->enabled = 0;
  994. }
  995. static int taal_panel_reset(struct omap_dss_device *dssdev)
  996. {
  997. dev_err(&dssdev->dev, "performing LCD reset\n");
  998. taal_power_off(dssdev);
  999. taal_hw_reset(dssdev);
  1000. return taal_power_on(dssdev);
  1001. }
  1002. static int taal_enable(struct omap_dss_device *dssdev)
  1003. {
  1004. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  1005. int r;
  1006. dev_dbg(&dssdev->dev, "enable\n");
  1007. mutex_lock(&td->lock);
  1008. if (dssdev->state != OMAP_DSS_DISPLAY_DISABLED) {
  1009. r = -EINVAL;
  1010. goto err;
  1011. }
  1012. dsi_bus_lock(dssdev);
  1013. r = taal_power_on(dssdev);
  1014. dsi_bus_unlock(dssdev);
  1015. if (r)
  1016. goto err;
  1017. taal_queue_esd_work(dssdev);
  1018. dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
  1019. mutex_unlock(&td->lock);
  1020. return 0;
  1021. err:
  1022. dev_dbg(&dssdev->dev, "enable failed\n");
  1023. mutex_unlock(&td->lock);
  1024. return r;
  1025. }
  1026. static void taal_disable(struct omap_dss_device *dssdev)
  1027. {
  1028. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  1029. dev_dbg(&dssdev->dev, "disable\n");
  1030. mutex_lock(&td->lock);
  1031. taal_cancel_ulps_work(dssdev);
  1032. taal_cancel_esd_work(dssdev);
  1033. dsi_bus_lock(dssdev);
  1034. if (dssdev->state == OMAP_DSS_DISPLAY_ACTIVE) {
  1035. int r;
  1036. r = taal_wake_up(dssdev);
  1037. if (!r)
  1038. taal_power_off(dssdev);
  1039. }
  1040. dsi_bus_unlock(dssdev);
  1041. dssdev->state = OMAP_DSS_DISPLAY_DISABLED;
  1042. mutex_unlock(&td->lock);
  1043. }
  1044. static int taal_suspend(struct omap_dss_device *dssdev)
  1045. {
  1046. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  1047. int r;
  1048. dev_dbg(&dssdev->dev, "suspend\n");
  1049. mutex_lock(&td->lock);
  1050. if (dssdev->state != OMAP_DSS_DISPLAY_ACTIVE) {
  1051. r = -EINVAL;
  1052. goto err;
  1053. }
  1054. taal_cancel_ulps_work(dssdev);
  1055. taal_cancel_esd_work(dssdev);
  1056. dsi_bus_lock(dssdev);
  1057. r = taal_wake_up(dssdev);
  1058. if (!r)
  1059. taal_power_off(dssdev);
  1060. dsi_bus_unlock(dssdev);
  1061. dssdev->state = OMAP_DSS_DISPLAY_SUSPENDED;
  1062. mutex_unlock(&td->lock);
  1063. return 0;
  1064. err:
  1065. mutex_unlock(&td->lock);
  1066. return r;
  1067. }
  1068. static int taal_resume(struct omap_dss_device *dssdev)
  1069. {
  1070. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  1071. int r;
  1072. dev_dbg(&dssdev->dev, "resume\n");
  1073. mutex_lock(&td->lock);
  1074. if (dssdev->state != OMAP_DSS_DISPLAY_SUSPENDED) {
  1075. r = -EINVAL;
  1076. goto err;
  1077. }
  1078. dsi_bus_lock(dssdev);
  1079. r = taal_power_on(dssdev);
  1080. dsi_bus_unlock(dssdev);
  1081. if (r) {
  1082. dssdev->state = OMAP_DSS_DISPLAY_DISABLED;
  1083. } else {
  1084. dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
  1085. taal_queue_esd_work(dssdev);
  1086. }
  1087. mutex_unlock(&td->lock);
  1088. return r;
  1089. err:
  1090. mutex_unlock(&td->lock);
  1091. return r;
  1092. }
  1093. static void taal_framedone_cb(int err, void *data)
  1094. {
  1095. struct omap_dss_device *dssdev = data;
  1096. dev_dbg(&dssdev->dev, "framedone, err %d\n", err);
  1097. dsi_bus_unlock(dssdev);
  1098. }
  1099. static irqreturn_t taal_te_isr(int irq, void *data)
  1100. {
  1101. struct omap_dss_device *dssdev = data;
  1102. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  1103. int old;
  1104. int r;
  1105. old = atomic_cmpxchg(&td->do_update, 1, 0);
  1106. if (old) {
  1107. cancel_delayed_work(&td->te_timeout_work);
  1108. r = omap_dsi_update(dssdev, td->channel,
  1109. td->update_region.x,
  1110. td->update_region.y,
  1111. td->update_region.w,
  1112. td->update_region.h,
  1113. taal_framedone_cb, dssdev);
  1114. if (r)
  1115. goto err;
  1116. }
  1117. return IRQ_HANDLED;
  1118. err:
  1119. dev_err(&dssdev->dev, "start update failed\n");
  1120. dsi_bus_unlock(dssdev);
  1121. return IRQ_HANDLED;
  1122. }
  1123. static void taal_te_timeout_work_callback(struct work_struct *work)
  1124. {
  1125. struct taal_data *td = container_of(work, struct taal_data,
  1126. te_timeout_work.work);
  1127. struct omap_dss_device *dssdev = td->dssdev;
  1128. dev_err(&dssdev->dev, "TE not received for 250ms!\n");
  1129. atomic_set(&td->do_update, 0);
  1130. dsi_bus_unlock(dssdev);
  1131. }
  1132. static int taal_update(struct omap_dss_device *dssdev,
  1133. u16 x, u16 y, u16 w, u16 h)
  1134. {
  1135. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  1136. struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev);
  1137. int r;
  1138. dev_dbg(&dssdev->dev, "update %d, %d, %d x %d\n", x, y, w, h);
  1139. mutex_lock(&td->lock);
  1140. dsi_bus_lock(dssdev);
  1141. r = taal_wake_up(dssdev);
  1142. if (r)
  1143. goto err;
  1144. if (!td->enabled) {
  1145. r = 0;
  1146. goto err;
  1147. }
  1148. r = omap_dsi_prepare_update(dssdev, &x, &y, &w, &h, true);
  1149. if (r)
  1150. goto err;
  1151. r = taal_set_update_window(td, x, y, w, h);
  1152. if (r)
  1153. goto err;
  1154. if (td->te_enabled && panel_data->use_ext_te) {
  1155. td->update_region.x = x;
  1156. td->update_region.y = y;
  1157. td->update_region.w = w;
  1158. td->update_region.h = h;
  1159. barrier();
  1160. schedule_delayed_work(&td->te_timeout_work,
  1161. msecs_to_jiffies(250));
  1162. atomic_set(&td->do_update, 1);
  1163. } else {
  1164. r = omap_dsi_update(dssdev, td->channel, x, y, w, h,
  1165. taal_framedone_cb, dssdev);
  1166. if (r)
  1167. goto err;
  1168. }
  1169. /* note: no bus_unlock here. unlock is in framedone_cb */
  1170. mutex_unlock(&td->lock);
  1171. return 0;
  1172. err:
  1173. dsi_bus_unlock(dssdev);
  1174. mutex_unlock(&td->lock);
  1175. return r;
  1176. }
  1177. static int taal_sync(struct omap_dss_device *dssdev)
  1178. {
  1179. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  1180. dev_dbg(&dssdev->dev, "sync\n");
  1181. mutex_lock(&td->lock);
  1182. dsi_bus_lock(dssdev);
  1183. dsi_bus_unlock(dssdev);
  1184. mutex_unlock(&td->lock);
  1185. dev_dbg(&dssdev->dev, "sync done\n");
  1186. return 0;
  1187. }
  1188. static int _taal_enable_te(struct omap_dss_device *dssdev, bool enable)
  1189. {
  1190. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  1191. struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev);
  1192. int r;
  1193. if (enable)
  1194. r = taal_dcs_write_1(td, DCS_TEAR_ON, 0);
  1195. else
  1196. r = taal_dcs_write_0(td, DCS_TEAR_OFF);
  1197. if (!panel_data->use_ext_te)
  1198. omapdss_dsi_enable_te(dssdev, enable);
  1199. if (td->panel_config->sleep.enable_te)
  1200. msleep(td->panel_config->sleep.enable_te);
  1201. return r;
  1202. }
  1203. static int taal_enable_te(struct omap_dss_device *dssdev, bool enable)
  1204. {
  1205. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  1206. int r;
  1207. mutex_lock(&td->lock);
  1208. if (td->te_enabled == enable)
  1209. goto end;
  1210. dsi_bus_lock(dssdev);
  1211. if (td->enabled) {
  1212. r = taal_wake_up(dssdev);
  1213. if (r)
  1214. goto err;
  1215. r = _taal_enable_te(dssdev, enable);
  1216. if (r)
  1217. goto err;
  1218. }
  1219. td->te_enabled = enable;
  1220. dsi_bus_unlock(dssdev);
  1221. end:
  1222. mutex_unlock(&td->lock);
  1223. return 0;
  1224. err:
  1225. dsi_bus_unlock(dssdev);
  1226. mutex_unlock(&td->lock);
  1227. return r;
  1228. }
  1229. static int taal_get_te(struct omap_dss_device *dssdev)
  1230. {
  1231. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  1232. int r;
  1233. mutex_lock(&td->lock);
  1234. r = td->te_enabled;
  1235. mutex_unlock(&td->lock);
  1236. return r;
  1237. }
  1238. static int taal_rotate(struct omap_dss_device *dssdev, u8 rotate)
  1239. {
  1240. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  1241. int r;
  1242. dev_dbg(&dssdev->dev, "rotate %d\n", rotate);
  1243. mutex_lock(&td->lock);
  1244. if (td->rotate == rotate)
  1245. goto end;
  1246. dsi_bus_lock(dssdev);
  1247. if (td->enabled) {
  1248. r = taal_wake_up(dssdev);
  1249. if (r)
  1250. goto err;
  1251. r = taal_set_addr_mode(td, rotate, td->mirror);
  1252. if (r)
  1253. goto err;
  1254. }
  1255. td->rotate = rotate;
  1256. dsi_bus_unlock(dssdev);
  1257. end:
  1258. mutex_unlock(&td->lock);
  1259. return 0;
  1260. err:
  1261. dsi_bus_unlock(dssdev);
  1262. mutex_unlock(&td->lock);
  1263. return r;
  1264. }
  1265. static u8 taal_get_rotate(struct omap_dss_device *dssdev)
  1266. {
  1267. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  1268. int r;
  1269. mutex_lock(&td->lock);
  1270. r = td->rotate;
  1271. mutex_unlock(&td->lock);
  1272. return r;
  1273. }
  1274. static int taal_mirror(struct omap_dss_device *dssdev, bool enable)
  1275. {
  1276. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  1277. int r;
  1278. dev_dbg(&dssdev->dev, "mirror %d\n", enable);
  1279. mutex_lock(&td->lock);
  1280. if (td->mirror == enable)
  1281. goto end;
  1282. dsi_bus_lock(dssdev);
  1283. if (td->enabled) {
  1284. r = taal_wake_up(dssdev);
  1285. if (r)
  1286. goto err;
  1287. r = taal_set_addr_mode(td, td->rotate, enable);
  1288. if (r)
  1289. goto err;
  1290. }
  1291. td->mirror = enable;
  1292. dsi_bus_unlock(dssdev);
  1293. end:
  1294. mutex_unlock(&td->lock);
  1295. return 0;
  1296. err:
  1297. dsi_bus_unlock(dssdev);
  1298. mutex_unlock(&td->lock);
  1299. return r;
  1300. }
  1301. static bool taal_get_mirror(struct omap_dss_device *dssdev)
  1302. {
  1303. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  1304. int r;
  1305. mutex_lock(&td->lock);
  1306. r = td->mirror;
  1307. mutex_unlock(&td->lock);
  1308. return r;
  1309. }
  1310. static int taal_run_test(struct omap_dss_device *dssdev, int test_num)
  1311. {
  1312. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  1313. u8 id1, id2, id3;
  1314. int r;
  1315. mutex_lock(&td->lock);
  1316. if (!td->enabled) {
  1317. r = -ENODEV;
  1318. goto err1;
  1319. }
  1320. dsi_bus_lock(dssdev);
  1321. r = taal_wake_up(dssdev);
  1322. if (r)
  1323. goto err2;
  1324. r = taal_dcs_read_1(td, DCS_GET_ID1, &id1);
  1325. if (r)
  1326. goto err2;
  1327. r = taal_dcs_read_1(td, DCS_GET_ID2, &id2);
  1328. if (r)
  1329. goto err2;
  1330. r = taal_dcs_read_1(td, DCS_GET_ID3, &id3);
  1331. if (r)
  1332. goto err2;
  1333. dsi_bus_unlock(dssdev);
  1334. mutex_unlock(&td->lock);
  1335. return 0;
  1336. err2:
  1337. dsi_bus_unlock(dssdev);
  1338. err1:
  1339. mutex_unlock(&td->lock);
  1340. return r;
  1341. }
  1342. static int taal_memory_read(struct omap_dss_device *dssdev,
  1343. void *buf, size_t size,
  1344. u16 x, u16 y, u16 w, u16 h)
  1345. {
  1346. int r;
  1347. int first = 1;
  1348. int plen;
  1349. unsigned buf_used = 0;
  1350. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  1351. if (size < w * h * 3)
  1352. return -ENOMEM;
  1353. mutex_lock(&td->lock);
  1354. if (!td->enabled) {
  1355. r = -ENODEV;
  1356. goto err1;
  1357. }
  1358. size = min(w * h * 3,
  1359. dssdev->panel.timings.x_res *
  1360. dssdev->panel.timings.y_res * 3);
  1361. dsi_bus_lock(dssdev);
  1362. r = taal_wake_up(dssdev);
  1363. if (r)
  1364. goto err2;
  1365. /* plen 1 or 2 goes into short packet. until checksum error is fixed,
  1366. * use short packets. plen 32 works, but bigger packets seem to cause
  1367. * an error. */
  1368. if (size % 2)
  1369. plen = 1;
  1370. else
  1371. plen = 2;
  1372. taal_set_update_window(td, x, y, w, h);
  1373. r = dsi_vc_set_max_rx_packet_size(dssdev, td->channel, plen);
  1374. if (r)
  1375. goto err2;
  1376. while (buf_used < size) {
  1377. u8 dcs_cmd = first ? 0x2e : 0x3e;
  1378. first = 0;
  1379. r = dsi_vc_dcs_read(dssdev, td->channel, dcs_cmd,
  1380. buf + buf_used, size - buf_used);
  1381. if (r < 0) {
  1382. dev_err(&dssdev->dev, "read error\n");
  1383. goto err3;
  1384. }
  1385. buf_used += r;
  1386. if (r < plen) {
  1387. dev_err(&dssdev->dev, "short read\n");
  1388. break;
  1389. }
  1390. if (signal_pending(current)) {
  1391. dev_err(&dssdev->dev, "signal pending, "
  1392. "aborting memory read\n");
  1393. r = -ERESTARTSYS;
  1394. goto err3;
  1395. }
  1396. }
  1397. r = buf_used;
  1398. err3:
  1399. dsi_vc_set_max_rx_packet_size(dssdev, td->channel, 1);
  1400. err2:
  1401. dsi_bus_unlock(dssdev);
  1402. err1:
  1403. mutex_unlock(&td->lock);
  1404. return r;
  1405. }
  1406. static void taal_ulps_work(struct work_struct *work)
  1407. {
  1408. struct taal_data *td = container_of(work, struct taal_data,
  1409. ulps_work.work);
  1410. struct omap_dss_device *dssdev = td->dssdev;
  1411. mutex_lock(&td->lock);
  1412. if (dssdev->state != OMAP_DSS_DISPLAY_ACTIVE || !td->enabled) {
  1413. mutex_unlock(&td->lock);
  1414. return;
  1415. }
  1416. dsi_bus_lock(dssdev);
  1417. taal_enter_ulps(dssdev);
  1418. dsi_bus_unlock(dssdev);
  1419. mutex_unlock(&td->lock);
  1420. }
  1421. static void taal_esd_work(struct work_struct *work)
  1422. {
  1423. struct taal_data *td = container_of(work, struct taal_data,
  1424. esd_work.work);
  1425. struct omap_dss_device *dssdev = td->dssdev;
  1426. struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev);
  1427. u8 state1, state2;
  1428. int r;
  1429. mutex_lock(&td->lock);
  1430. if (!td->enabled) {
  1431. mutex_unlock(&td->lock);
  1432. return;
  1433. }
  1434. dsi_bus_lock(dssdev);
  1435. r = taal_wake_up(dssdev);
  1436. if (r) {
  1437. dev_err(&dssdev->dev, "failed to exit ULPS\n");
  1438. goto err;
  1439. }
  1440. r = taal_dcs_read_1(td, DCS_RDDSDR, &state1);
  1441. if (r) {
  1442. dev_err(&dssdev->dev, "failed to read Taal status\n");
  1443. goto err;
  1444. }
  1445. /* Run self diagnostics */
  1446. r = taal_sleep_out(td);
  1447. if (r) {
  1448. dev_err(&dssdev->dev, "failed to run Taal self-diagnostics\n");
  1449. goto err;
  1450. }
  1451. r = taal_dcs_read_1(td, DCS_RDDSDR, &state2);
  1452. if (r) {
  1453. dev_err(&dssdev->dev, "failed to read Taal status\n");
  1454. goto err;
  1455. }
  1456. /* Each sleep out command will trigger a self diagnostic and flip
  1457. * Bit6 if the test passes.
  1458. */
  1459. if (!((state1 ^ state2) & (1 << 6))) {
  1460. dev_err(&dssdev->dev, "LCD self diagnostics failed\n");
  1461. goto err;
  1462. }
  1463. /* Self-diagnostics result is also shown on TE GPIO line. We need
  1464. * to re-enable TE after self diagnostics */
  1465. if (td->te_enabled && panel_data->use_ext_te) {
  1466. r = taal_dcs_write_1(td, DCS_TEAR_ON, 0);
  1467. if (r)
  1468. goto err;
  1469. }
  1470. dsi_bus_unlock(dssdev);
  1471. taal_queue_esd_work(dssdev);
  1472. mutex_unlock(&td->lock);
  1473. return;
  1474. err:
  1475. dev_err(&dssdev->dev, "performing LCD reset\n");
  1476. taal_panel_reset(dssdev);
  1477. dsi_bus_unlock(dssdev);
  1478. taal_queue_esd_work(dssdev);
  1479. mutex_unlock(&td->lock);
  1480. }
  1481. static struct omap_dss_driver taal_driver = {
  1482. .probe = taal_probe,
  1483. .remove = __exit_p(taal_remove),
  1484. .enable = taal_enable,
  1485. .disable = taal_disable,
  1486. .suspend = taal_suspend,
  1487. .resume = taal_resume,
  1488. .update = taal_update,
  1489. .sync = taal_sync,
  1490. .get_resolution = taal_get_resolution,
  1491. .get_recommended_bpp = omapdss_default_get_recommended_bpp,
  1492. .enable_te = taal_enable_te,
  1493. .get_te = taal_get_te,
  1494. .set_rotate = taal_rotate,
  1495. .get_rotate = taal_get_rotate,
  1496. .set_mirror = taal_mirror,
  1497. .get_mirror = taal_get_mirror,
  1498. .run_test = taal_run_test,
  1499. .memory_read = taal_memory_read,
  1500. .get_timings = taal_get_timings,
  1501. .driver = {
  1502. .name = "taal",
  1503. .owner = THIS_MODULE,
  1504. },
  1505. };
  1506. static int __init taal_init(void)
  1507. {
  1508. omap_dss_register_driver(&taal_driver);
  1509. return 0;
  1510. }
  1511. static void __exit taal_exit(void)
  1512. {
  1513. omap_dss_unregister_driver(&taal_driver);
  1514. }
  1515. module_init(taal_init);
  1516. module_exit(taal_exit);
  1517. MODULE_AUTHOR("Tomi Valkeinen <tomi.valkeinen@nokia.com>");
  1518. MODULE_DESCRIPTION("Taal Driver");
  1519. MODULE_LICENSE("GPL");