panel-taal.c 32 KB

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