panel-taal.c 38 KB

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