panel-taal.c 38 KB

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