panel-taal.c 38 KB

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