panel-taal.c 37 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849
  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;
  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.config = OMAP_DSS_LCD_TFT;
  691. dssdev->panel.timings = panel_config->timings;
  692. dssdev->panel.dsi_pix_fmt = OMAP_DSS_DSI_FMT_RGB888;
  693. td = kzalloc(sizeof(*td), GFP_KERNEL);
  694. if (!td) {
  695. r = -ENOMEM;
  696. goto err;
  697. }
  698. td->dssdev = dssdev;
  699. td->panel_config = panel_config;
  700. td->esd_interval = panel_data->esd_interval;
  701. td->ulps_enabled = false;
  702. td->ulps_timeout = panel_data->ulps_timeout;
  703. mutex_init(&td->lock);
  704. atomic_set(&td->do_update, 0);
  705. td->workqueue = create_singlethread_workqueue("taal_esd");
  706. if (td->workqueue == NULL) {
  707. dev_err(&dssdev->dev, "can't create ESD workqueue\n");
  708. r = -ENOMEM;
  709. goto err_wq;
  710. }
  711. INIT_DELAYED_WORK_DEFERRABLE(&td->esd_work, taal_esd_work);
  712. INIT_DELAYED_WORK(&td->ulps_work, taal_ulps_work);
  713. dev_set_drvdata(&dssdev->dev, td);
  714. if (gpio_is_valid(panel_data->reset_gpio)) {
  715. r = gpio_request_one(panel_data->reset_gpio, GPIOF_OUT_INIT_LOW,
  716. "taal rst");
  717. if (r) {
  718. dev_err(&dssdev->dev, "failed to request reset gpio\n");
  719. goto err_rst_gpio;
  720. }
  721. }
  722. taal_hw_reset(dssdev);
  723. if (panel_data->use_dsi_backlight) {
  724. memset(&props, 0, sizeof(struct backlight_properties));
  725. props.max_brightness = 255;
  726. props.type = BACKLIGHT_RAW;
  727. bldev = backlight_device_register(dev_name(&dssdev->dev),
  728. &dssdev->dev, dssdev, &taal_bl_ops, &props);
  729. if (IS_ERR(bldev)) {
  730. r = PTR_ERR(bldev);
  731. goto err_bl;
  732. }
  733. td->bldev = bldev;
  734. bldev->props.fb_blank = FB_BLANK_UNBLANK;
  735. bldev->props.power = FB_BLANK_UNBLANK;
  736. bldev->props.brightness = 255;
  737. taal_bl_update_status(bldev);
  738. }
  739. if (panel_data->use_ext_te) {
  740. int gpio = panel_data->ext_te_gpio;
  741. r = gpio_request_one(gpio, GPIOF_IN, "taal irq");
  742. if (r) {
  743. dev_err(&dssdev->dev, "GPIO request failed\n");
  744. goto err_gpio;
  745. }
  746. r = request_irq(gpio_to_irq(gpio), taal_te_isr,
  747. IRQF_TRIGGER_RISING,
  748. "taal vsync", dssdev);
  749. if (r) {
  750. dev_err(&dssdev->dev, "IRQ request failed\n");
  751. gpio_free(gpio);
  752. goto err_irq;
  753. }
  754. INIT_DELAYED_WORK_DEFERRABLE(&td->te_timeout_work,
  755. taal_te_timeout_work_callback);
  756. dev_dbg(&dssdev->dev, "Using GPIO TE\n");
  757. }
  758. r = omap_dsi_request_vc(dssdev, &td->channel);
  759. if (r) {
  760. dev_err(&dssdev->dev, "failed to get virtual channel\n");
  761. goto err_req_vc;
  762. }
  763. r = omap_dsi_set_vc_id(dssdev, td->channel, TCH);
  764. if (r) {
  765. dev_err(&dssdev->dev, "failed to set VC_ID\n");
  766. goto err_vc_id;
  767. }
  768. r = sysfs_create_group(&dssdev->dev.kobj, &taal_attr_group);
  769. if (r) {
  770. dev_err(&dssdev->dev, "failed to create sysfs files\n");
  771. goto err_vc_id;
  772. }
  773. return 0;
  774. err_vc_id:
  775. omap_dsi_release_vc(dssdev, td->channel);
  776. err_req_vc:
  777. if (panel_data->use_ext_te)
  778. free_irq(gpio_to_irq(panel_data->ext_te_gpio), dssdev);
  779. err_irq:
  780. if (panel_data->use_ext_te)
  781. gpio_free(panel_data->ext_te_gpio);
  782. err_gpio:
  783. if (bldev != NULL)
  784. backlight_device_unregister(bldev);
  785. err_bl:
  786. if (gpio_is_valid(panel_data->reset_gpio))
  787. gpio_free(panel_data->reset_gpio);
  788. err_rst_gpio:
  789. destroy_workqueue(td->workqueue);
  790. err_wq:
  791. kfree(td);
  792. err:
  793. return r;
  794. }
  795. static void __exit taal_remove(struct omap_dss_device *dssdev)
  796. {
  797. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  798. struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev);
  799. struct backlight_device *bldev;
  800. dev_dbg(&dssdev->dev, "remove\n");
  801. sysfs_remove_group(&dssdev->dev.kobj, &taal_attr_group);
  802. omap_dsi_release_vc(dssdev, td->channel);
  803. if (panel_data->use_ext_te) {
  804. int gpio = panel_data->ext_te_gpio;
  805. free_irq(gpio_to_irq(gpio), dssdev);
  806. gpio_free(gpio);
  807. }
  808. bldev = td->bldev;
  809. if (bldev != NULL) {
  810. bldev->props.power = FB_BLANK_POWERDOWN;
  811. taal_bl_update_status(bldev);
  812. backlight_device_unregister(bldev);
  813. }
  814. taal_cancel_ulps_work(dssdev);
  815. taal_cancel_esd_work(dssdev);
  816. destroy_workqueue(td->workqueue);
  817. /* reset, to be sure that the panel is in a valid state */
  818. taal_hw_reset(dssdev);
  819. if (gpio_is_valid(panel_data->reset_gpio))
  820. gpio_free(panel_data->reset_gpio);
  821. kfree(td);
  822. }
  823. static int taal_power_on(struct omap_dss_device *dssdev)
  824. {
  825. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  826. struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev);
  827. u8 id1, id2, id3;
  828. int r;
  829. r = omapdss_dsi_configure_pins(dssdev, &panel_data->pin_config);
  830. if (r) {
  831. dev_err(&dssdev->dev, "failed to configure DSI pins\n");
  832. goto err0;
  833. };
  834. r = omapdss_dsi_display_enable(dssdev);
  835. if (r) {
  836. dev_err(&dssdev->dev, "failed to enable DSI\n");
  837. goto err0;
  838. }
  839. taal_hw_reset(dssdev);
  840. omapdss_dsi_vc_enable_hs(dssdev, td->channel, false);
  841. r = taal_sleep_out(td);
  842. if (r)
  843. goto err;
  844. r = taal_get_id(td, &id1, &id2, &id3);
  845. if (r)
  846. goto err;
  847. /* on early Taal revisions CABC is broken */
  848. if (td->panel_config->type == PANEL_TAAL &&
  849. (id2 == 0x00 || id2 == 0xff || id2 == 0x81))
  850. td->cabc_broken = true;
  851. r = taal_dcs_write_1(td, DCS_BRIGHTNESS, 0xff);
  852. if (r)
  853. goto err;
  854. r = taal_dcs_write_1(td, DCS_CTRL_DISPLAY,
  855. (1<<2) | (1<<5)); /* BL | BCTRL */
  856. if (r)
  857. goto err;
  858. r = taal_dcs_write_1(td, MIPI_DCS_SET_PIXEL_FORMAT,
  859. MIPI_DCS_PIXEL_FMT_24BIT);
  860. if (r)
  861. goto err;
  862. r = taal_set_addr_mode(td, td->rotate, td->mirror);
  863. if (r)
  864. goto err;
  865. if (!td->cabc_broken) {
  866. r = taal_dcs_write_1(td, DCS_WRITE_CABC, td->cabc_mode);
  867. if (r)
  868. goto err;
  869. }
  870. r = taal_dcs_write_0(td, MIPI_DCS_SET_DISPLAY_ON);
  871. if (r)
  872. goto err;
  873. r = _taal_enable_te(dssdev, td->te_enabled);
  874. if (r)
  875. goto err;
  876. r = dsi_enable_video_output(dssdev, td->channel);
  877. if (r)
  878. goto err;
  879. td->enabled = 1;
  880. if (!td->intro_printed) {
  881. dev_info(&dssdev->dev, "%s panel revision %02x.%02x.%02x\n",
  882. td->panel_config->name, id1, id2, id3);
  883. if (td->cabc_broken)
  884. dev_info(&dssdev->dev,
  885. "old Taal version, CABC disabled\n");
  886. td->intro_printed = true;
  887. }
  888. omapdss_dsi_vc_enable_hs(dssdev, td->channel, true);
  889. return 0;
  890. err:
  891. dev_err(&dssdev->dev, "error while enabling panel, issuing HW reset\n");
  892. taal_hw_reset(dssdev);
  893. omapdss_dsi_display_disable(dssdev, true, false);
  894. err0:
  895. return r;
  896. }
  897. static void taal_power_off(struct omap_dss_device *dssdev)
  898. {
  899. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  900. int r;
  901. dsi_disable_video_output(dssdev, td->channel);
  902. r = taal_dcs_write_0(td, MIPI_DCS_SET_DISPLAY_OFF);
  903. if (!r)
  904. r = taal_sleep_in(td);
  905. if (r) {
  906. dev_err(&dssdev->dev,
  907. "error disabling panel, issuing HW reset\n");
  908. taal_hw_reset(dssdev);
  909. }
  910. omapdss_dsi_display_disable(dssdev, true, false);
  911. td->enabled = 0;
  912. }
  913. static int taal_panel_reset(struct omap_dss_device *dssdev)
  914. {
  915. dev_err(&dssdev->dev, "performing LCD reset\n");
  916. taal_power_off(dssdev);
  917. taal_hw_reset(dssdev);
  918. return taal_power_on(dssdev);
  919. }
  920. static int taal_enable(struct omap_dss_device *dssdev)
  921. {
  922. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  923. int r;
  924. dev_dbg(&dssdev->dev, "enable\n");
  925. mutex_lock(&td->lock);
  926. if (dssdev->state != OMAP_DSS_DISPLAY_DISABLED) {
  927. r = -EINVAL;
  928. goto err;
  929. }
  930. dsi_bus_lock(dssdev);
  931. r = taal_power_on(dssdev);
  932. dsi_bus_unlock(dssdev);
  933. if (r)
  934. goto err;
  935. taal_queue_esd_work(dssdev);
  936. dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
  937. mutex_unlock(&td->lock);
  938. return 0;
  939. err:
  940. dev_dbg(&dssdev->dev, "enable failed\n");
  941. mutex_unlock(&td->lock);
  942. return r;
  943. }
  944. static void taal_disable(struct omap_dss_device *dssdev)
  945. {
  946. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  947. dev_dbg(&dssdev->dev, "disable\n");
  948. mutex_lock(&td->lock);
  949. taal_cancel_ulps_work(dssdev);
  950. taal_cancel_esd_work(dssdev);
  951. dsi_bus_lock(dssdev);
  952. if (dssdev->state == OMAP_DSS_DISPLAY_ACTIVE) {
  953. int r;
  954. r = taal_wake_up(dssdev);
  955. if (!r)
  956. taal_power_off(dssdev);
  957. }
  958. dsi_bus_unlock(dssdev);
  959. dssdev->state = OMAP_DSS_DISPLAY_DISABLED;
  960. mutex_unlock(&td->lock);
  961. }
  962. static int taal_suspend(struct omap_dss_device *dssdev)
  963. {
  964. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  965. int r;
  966. dev_dbg(&dssdev->dev, "suspend\n");
  967. mutex_lock(&td->lock);
  968. if (dssdev->state != OMAP_DSS_DISPLAY_ACTIVE) {
  969. r = -EINVAL;
  970. goto err;
  971. }
  972. taal_cancel_ulps_work(dssdev);
  973. taal_cancel_esd_work(dssdev);
  974. dsi_bus_lock(dssdev);
  975. r = taal_wake_up(dssdev);
  976. if (!r)
  977. taal_power_off(dssdev);
  978. dsi_bus_unlock(dssdev);
  979. dssdev->state = OMAP_DSS_DISPLAY_SUSPENDED;
  980. mutex_unlock(&td->lock);
  981. return 0;
  982. err:
  983. mutex_unlock(&td->lock);
  984. return r;
  985. }
  986. static int taal_resume(struct omap_dss_device *dssdev)
  987. {
  988. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  989. int r;
  990. dev_dbg(&dssdev->dev, "resume\n");
  991. mutex_lock(&td->lock);
  992. if (dssdev->state != OMAP_DSS_DISPLAY_SUSPENDED) {
  993. r = -EINVAL;
  994. goto err;
  995. }
  996. dsi_bus_lock(dssdev);
  997. r = taal_power_on(dssdev);
  998. dsi_bus_unlock(dssdev);
  999. if (r) {
  1000. dssdev->state = OMAP_DSS_DISPLAY_DISABLED;
  1001. } else {
  1002. dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
  1003. taal_queue_esd_work(dssdev);
  1004. }
  1005. mutex_unlock(&td->lock);
  1006. return r;
  1007. err:
  1008. mutex_unlock(&td->lock);
  1009. return r;
  1010. }
  1011. static void taal_framedone_cb(int err, void *data)
  1012. {
  1013. struct omap_dss_device *dssdev = data;
  1014. dev_dbg(&dssdev->dev, "framedone, err %d\n", err);
  1015. dsi_bus_unlock(dssdev);
  1016. }
  1017. static irqreturn_t taal_te_isr(int irq, void *data)
  1018. {
  1019. struct omap_dss_device *dssdev = data;
  1020. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  1021. int old;
  1022. int r;
  1023. old = atomic_cmpxchg(&td->do_update, 1, 0);
  1024. if (old) {
  1025. cancel_delayed_work(&td->te_timeout_work);
  1026. r = omap_dsi_update(dssdev, td->channel, taal_framedone_cb,
  1027. dssdev);
  1028. if (r)
  1029. goto err;
  1030. }
  1031. return IRQ_HANDLED;
  1032. err:
  1033. dev_err(&dssdev->dev, "start update failed\n");
  1034. dsi_bus_unlock(dssdev);
  1035. return IRQ_HANDLED;
  1036. }
  1037. static void taal_te_timeout_work_callback(struct work_struct *work)
  1038. {
  1039. struct taal_data *td = container_of(work, struct taal_data,
  1040. te_timeout_work.work);
  1041. struct omap_dss_device *dssdev = td->dssdev;
  1042. dev_err(&dssdev->dev, "TE not received for 250ms!\n");
  1043. atomic_set(&td->do_update, 0);
  1044. dsi_bus_unlock(dssdev);
  1045. }
  1046. static int taal_update(struct omap_dss_device *dssdev,
  1047. u16 x, u16 y, u16 w, u16 h)
  1048. {
  1049. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  1050. struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev);
  1051. int r;
  1052. dev_dbg(&dssdev->dev, "update %d, %d, %d x %d\n", x, y, w, h);
  1053. mutex_lock(&td->lock);
  1054. dsi_bus_lock(dssdev);
  1055. r = taal_wake_up(dssdev);
  1056. if (r)
  1057. goto err;
  1058. if (!td->enabled) {
  1059. r = 0;
  1060. goto err;
  1061. }
  1062. /* XXX no need to send this every frame, but dsi break if not done */
  1063. r = taal_set_update_window(td, 0, 0,
  1064. td->panel_config->timings.x_res,
  1065. td->panel_config->timings.y_res);
  1066. if (r)
  1067. goto err;
  1068. if (td->te_enabled && panel_data->use_ext_te) {
  1069. schedule_delayed_work(&td->te_timeout_work,
  1070. msecs_to_jiffies(250));
  1071. atomic_set(&td->do_update, 1);
  1072. } else {
  1073. r = omap_dsi_update(dssdev, td->channel, taal_framedone_cb,
  1074. dssdev);
  1075. if (r)
  1076. goto err;
  1077. }
  1078. /* note: no bus_unlock here. unlock is in framedone_cb */
  1079. mutex_unlock(&td->lock);
  1080. return 0;
  1081. err:
  1082. dsi_bus_unlock(dssdev);
  1083. mutex_unlock(&td->lock);
  1084. return r;
  1085. }
  1086. static int taal_sync(struct omap_dss_device *dssdev)
  1087. {
  1088. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  1089. dev_dbg(&dssdev->dev, "sync\n");
  1090. mutex_lock(&td->lock);
  1091. dsi_bus_lock(dssdev);
  1092. dsi_bus_unlock(dssdev);
  1093. mutex_unlock(&td->lock);
  1094. dev_dbg(&dssdev->dev, "sync done\n");
  1095. return 0;
  1096. }
  1097. static int _taal_enable_te(struct omap_dss_device *dssdev, bool enable)
  1098. {
  1099. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  1100. struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev);
  1101. int r;
  1102. if (enable)
  1103. r = taal_dcs_write_1(td, MIPI_DCS_SET_TEAR_ON, 0);
  1104. else
  1105. r = taal_dcs_write_0(td, MIPI_DCS_SET_TEAR_OFF);
  1106. if (!panel_data->use_ext_te)
  1107. omapdss_dsi_enable_te(dssdev, enable);
  1108. if (td->panel_config->sleep.enable_te)
  1109. msleep(td->panel_config->sleep.enable_te);
  1110. return r;
  1111. }
  1112. static int taal_enable_te(struct omap_dss_device *dssdev, bool enable)
  1113. {
  1114. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  1115. int r;
  1116. mutex_lock(&td->lock);
  1117. if (td->te_enabled == enable)
  1118. goto end;
  1119. dsi_bus_lock(dssdev);
  1120. if (td->enabled) {
  1121. r = taal_wake_up(dssdev);
  1122. if (r)
  1123. goto err;
  1124. r = _taal_enable_te(dssdev, enable);
  1125. if (r)
  1126. goto err;
  1127. }
  1128. td->te_enabled = enable;
  1129. dsi_bus_unlock(dssdev);
  1130. end:
  1131. mutex_unlock(&td->lock);
  1132. return 0;
  1133. err:
  1134. dsi_bus_unlock(dssdev);
  1135. mutex_unlock(&td->lock);
  1136. return r;
  1137. }
  1138. static int taal_get_te(struct omap_dss_device *dssdev)
  1139. {
  1140. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  1141. int r;
  1142. mutex_lock(&td->lock);
  1143. r = td->te_enabled;
  1144. mutex_unlock(&td->lock);
  1145. return r;
  1146. }
  1147. static int taal_rotate(struct omap_dss_device *dssdev, u8 rotate)
  1148. {
  1149. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  1150. int r;
  1151. dev_dbg(&dssdev->dev, "rotate %d\n", rotate);
  1152. mutex_lock(&td->lock);
  1153. if (td->rotate == rotate)
  1154. goto end;
  1155. dsi_bus_lock(dssdev);
  1156. if (td->enabled) {
  1157. r = taal_wake_up(dssdev);
  1158. if (r)
  1159. goto err;
  1160. r = taal_set_addr_mode(td, rotate, td->mirror);
  1161. if (r)
  1162. goto err;
  1163. }
  1164. td->rotate = rotate;
  1165. dsi_bus_unlock(dssdev);
  1166. end:
  1167. mutex_unlock(&td->lock);
  1168. return 0;
  1169. err:
  1170. dsi_bus_unlock(dssdev);
  1171. mutex_unlock(&td->lock);
  1172. return r;
  1173. }
  1174. static u8 taal_get_rotate(struct omap_dss_device *dssdev)
  1175. {
  1176. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  1177. int r;
  1178. mutex_lock(&td->lock);
  1179. r = td->rotate;
  1180. mutex_unlock(&td->lock);
  1181. return r;
  1182. }
  1183. static int taal_mirror(struct omap_dss_device *dssdev, bool enable)
  1184. {
  1185. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  1186. int r;
  1187. dev_dbg(&dssdev->dev, "mirror %d\n", enable);
  1188. mutex_lock(&td->lock);
  1189. if (td->mirror == enable)
  1190. goto end;
  1191. dsi_bus_lock(dssdev);
  1192. if (td->enabled) {
  1193. r = taal_wake_up(dssdev);
  1194. if (r)
  1195. goto err;
  1196. r = taal_set_addr_mode(td, td->rotate, enable);
  1197. if (r)
  1198. goto err;
  1199. }
  1200. td->mirror = enable;
  1201. dsi_bus_unlock(dssdev);
  1202. end:
  1203. mutex_unlock(&td->lock);
  1204. return 0;
  1205. err:
  1206. dsi_bus_unlock(dssdev);
  1207. mutex_unlock(&td->lock);
  1208. return r;
  1209. }
  1210. static bool taal_get_mirror(struct omap_dss_device *dssdev)
  1211. {
  1212. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  1213. int r;
  1214. mutex_lock(&td->lock);
  1215. r = td->mirror;
  1216. mutex_unlock(&td->lock);
  1217. return r;
  1218. }
  1219. static int taal_run_test(struct omap_dss_device *dssdev, int test_num)
  1220. {
  1221. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  1222. u8 id1, id2, id3;
  1223. int r;
  1224. mutex_lock(&td->lock);
  1225. if (!td->enabled) {
  1226. r = -ENODEV;
  1227. goto err1;
  1228. }
  1229. dsi_bus_lock(dssdev);
  1230. r = taal_wake_up(dssdev);
  1231. if (r)
  1232. goto err2;
  1233. r = taal_dcs_read_1(td, DCS_GET_ID1, &id1);
  1234. if (r)
  1235. goto err2;
  1236. r = taal_dcs_read_1(td, DCS_GET_ID2, &id2);
  1237. if (r)
  1238. goto err2;
  1239. r = taal_dcs_read_1(td, DCS_GET_ID3, &id3);
  1240. if (r)
  1241. goto err2;
  1242. dsi_bus_unlock(dssdev);
  1243. mutex_unlock(&td->lock);
  1244. return 0;
  1245. err2:
  1246. dsi_bus_unlock(dssdev);
  1247. err1:
  1248. mutex_unlock(&td->lock);
  1249. return r;
  1250. }
  1251. static int taal_memory_read(struct omap_dss_device *dssdev,
  1252. void *buf, size_t size,
  1253. u16 x, u16 y, u16 w, u16 h)
  1254. {
  1255. int r;
  1256. int first = 1;
  1257. int plen;
  1258. unsigned buf_used = 0;
  1259. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  1260. if (size < w * h * 3)
  1261. return -ENOMEM;
  1262. mutex_lock(&td->lock);
  1263. if (!td->enabled) {
  1264. r = -ENODEV;
  1265. goto err1;
  1266. }
  1267. size = min(w * h * 3,
  1268. dssdev->panel.timings.x_res *
  1269. dssdev->panel.timings.y_res * 3);
  1270. dsi_bus_lock(dssdev);
  1271. r = taal_wake_up(dssdev);
  1272. if (r)
  1273. goto err2;
  1274. /* plen 1 or 2 goes into short packet. until checksum error is fixed,
  1275. * use short packets. plen 32 works, but bigger packets seem to cause
  1276. * an error. */
  1277. if (size % 2)
  1278. plen = 1;
  1279. else
  1280. plen = 2;
  1281. taal_set_update_window(td, x, y, w, h);
  1282. r = dsi_vc_set_max_rx_packet_size(dssdev, td->channel, plen);
  1283. if (r)
  1284. goto err2;
  1285. while (buf_used < size) {
  1286. u8 dcs_cmd = first ? 0x2e : 0x3e;
  1287. first = 0;
  1288. r = dsi_vc_dcs_read(dssdev, td->channel, dcs_cmd,
  1289. buf + buf_used, size - buf_used);
  1290. if (r < 0) {
  1291. dev_err(&dssdev->dev, "read error\n");
  1292. goto err3;
  1293. }
  1294. buf_used += r;
  1295. if (r < plen) {
  1296. dev_err(&dssdev->dev, "short read\n");
  1297. break;
  1298. }
  1299. if (signal_pending(current)) {
  1300. dev_err(&dssdev->dev, "signal pending, "
  1301. "aborting memory read\n");
  1302. r = -ERESTARTSYS;
  1303. goto err3;
  1304. }
  1305. }
  1306. r = buf_used;
  1307. err3:
  1308. dsi_vc_set_max_rx_packet_size(dssdev, td->channel, 1);
  1309. err2:
  1310. dsi_bus_unlock(dssdev);
  1311. err1:
  1312. mutex_unlock(&td->lock);
  1313. return r;
  1314. }
  1315. static void taal_ulps_work(struct work_struct *work)
  1316. {
  1317. struct taal_data *td = container_of(work, struct taal_data,
  1318. ulps_work.work);
  1319. struct omap_dss_device *dssdev = td->dssdev;
  1320. mutex_lock(&td->lock);
  1321. if (dssdev->state != OMAP_DSS_DISPLAY_ACTIVE || !td->enabled) {
  1322. mutex_unlock(&td->lock);
  1323. return;
  1324. }
  1325. dsi_bus_lock(dssdev);
  1326. taal_enter_ulps(dssdev);
  1327. dsi_bus_unlock(dssdev);
  1328. mutex_unlock(&td->lock);
  1329. }
  1330. static void taal_esd_work(struct work_struct *work)
  1331. {
  1332. struct taal_data *td = container_of(work, struct taal_data,
  1333. esd_work.work);
  1334. struct omap_dss_device *dssdev = td->dssdev;
  1335. struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev);
  1336. u8 state1, state2;
  1337. int r;
  1338. mutex_lock(&td->lock);
  1339. if (!td->enabled) {
  1340. mutex_unlock(&td->lock);
  1341. return;
  1342. }
  1343. dsi_bus_lock(dssdev);
  1344. r = taal_wake_up(dssdev);
  1345. if (r) {
  1346. dev_err(&dssdev->dev, "failed to exit ULPS\n");
  1347. goto err;
  1348. }
  1349. r = taal_dcs_read_1(td, MIPI_DCS_GET_DIAGNOSTIC_RESULT, &state1);
  1350. if (r) {
  1351. dev_err(&dssdev->dev, "failed to read Taal status\n");
  1352. goto err;
  1353. }
  1354. /* Run self diagnostics */
  1355. r = taal_sleep_out(td);
  1356. if (r) {
  1357. dev_err(&dssdev->dev, "failed to run Taal self-diagnostics\n");
  1358. goto err;
  1359. }
  1360. r = taal_dcs_read_1(td, MIPI_DCS_GET_DIAGNOSTIC_RESULT, &state2);
  1361. if (r) {
  1362. dev_err(&dssdev->dev, "failed to read Taal status\n");
  1363. goto err;
  1364. }
  1365. /* Each sleep out command will trigger a self diagnostic and flip
  1366. * Bit6 if the test passes.
  1367. */
  1368. if (!((state1 ^ state2) & (1 << 6))) {
  1369. dev_err(&dssdev->dev, "LCD self diagnostics failed\n");
  1370. goto err;
  1371. }
  1372. /* Self-diagnostics result is also shown on TE GPIO line. We need
  1373. * to re-enable TE after self diagnostics */
  1374. if (td->te_enabled && panel_data->use_ext_te) {
  1375. r = taal_dcs_write_1(td, MIPI_DCS_SET_TEAR_ON, 0);
  1376. if (r)
  1377. goto err;
  1378. }
  1379. dsi_bus_unlock(dssdev);
  1380. taal_queue_esd_work(dssdev);
  1381. mutex_unlock(&td->lock);
  1382. return;
  1383. err:
  1384. dev_err(&dssdev->dev, "performing LCD reset\n");
  1385. taal_panel_reset(dssdev);
  1386. dsi_bus_unlock(dssdev);
  1387. taal_queue_esd_work(dssdev);
  1388. mutex_unlock(&td->lock);
  1389. }
  1390. static struct omap_dss_driver taal_driver = {
  1391. .probe = taal_probe,
  1392. .remove = __exit_p(taal_remove),
  1393. .enable = taal_enable,
  1394. .disable = taal_disable,
  1395. .suspend = taal_suspend,
  1396. .resume = taal_resume,
  1397. .update = taal_update,
  1398. .sync = taal_sync,
  1399. .get_resolution = taal_get_resolution,
  1400. .get_recommended_bpp = omapdss_default_get_recommended_bpp,
  1401. .enable_te = taal_enable_te,
  1402. .get_te = taal_get_te,
  1403. .set_rotate = taal_rotate,
  1404. .get_rotate = taal_get_rotate,
  1405. .set_mirror = taal_mirror,
  1406. .get_mirror = taal_get_mirror,
  1407. .run_test = taal_run_test,
  1408. .memory_read = taal_memory_read,
  1409. .driver = {
  1410. .name = "taal",
  1411. .owner = THIS_MODULE,
  1412. },
  1413. };
  1414. static int __init taal_init(void)
  1415. {
  1416. omap_dss_register_driver(&taal_driver);
  1417. return 0;
  1418. }
  1419. static void __exit taal_exit(void)
  1420. {
  1421. omap_dss_unregister_driver(&taal_driver);
  1422. }
  1423. module_init(taal_init);
  1424. module_exit(taal_exit);
  1425. MODULE_AUTHOR("Tomi Valkeinen <tomi.valkeinen@nokia.com>");
  1426. MODULE_DESCRIPTION("Taal Driver");
  1427. MODULE_LICENSE("GPL");