panel-taal.c 33 KB

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