panel-taal.c 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590
  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. 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. struct panel_config *panel_config;
  196. };
  197. static inline struct nokia_dsi_panel_data
  198. *get_panel_data(const struct omap_dss_device *dssdev)
  199. {
  200. return (struct nokia_dsi_panel_data *) dssdev->data;
  201. }
  202. static void taal_esd_work(struct work_struct *work);
  203. static void hw_guard_start(struct taal_data *td, int guard_msec)
  204. {
  205. td->hw_guard_wait = msecs_to_jiffies(guard_msec);
  206. td->hw_guard_end = jiffies + td->hw_guard_wait;
  207. }
  208. static void hw_guard_wait(struct taal_data *td)
  209. {
  210. unsigned long wait = td->hw_guard_end - jiffies;
  211. if ((long)wait > 0 && wait <= td->hw_guard_wait) {
  212. set_current_state(TASK_UNINTERRUPTIBLE);
  213. schedule_timeout(wait);
  214. }
  215. }
  216. static int taal_dcs_read_1(u8 dcs_cmd, u8 *data)
  217. {
  218. int r;
  219. u8 buf[1];
  220. r = dsi_vc_dcs_read(TCH, dcs_cmd, buf, 1);
  221. if (r < 0)
  222. return r;
  223. *data = buf[0];
  224. return 0;
  225. }
  226. static int taal_dcs_write_0(u8 dcs_cmd)
  227. {
  228. return dsi_vc_dcs_write(TCH, &dcs_cmd, 1);
  229. }
  230. static int taal_dcs_write_1(u8 dcs_cmd, u8 param)
  231. {
  232. u8 buf[2];
  233. buf[0] = dcs_cmd;
  234. buf[1] = param;
  235. return dsi_vc_dcs_write(TCH, buf, 2);
  236. }
  237. static int taal_sleep_in(struct taal_data *td)
  238. {
  239. u8 cmd;
  240. int r;
  241. hw_guard_wait(td);
  242. cmd = DCS_SLEEP_IN;
  243. r = dsi_vc_dcs_write_nosync(TCH, &cmd, 1);
  244. if (r)
  245. return r;
  246. hw_guard_start(td, 120);
  247. if (td->panel_config->sleep.sleep_in)
  248. msleep(td->panel_config->sleep.sleep_in);
  249. return 0;
  250. }
  251. static int taal_sleep_out(struct taal_data *td)
  252. {
  253. int r;
  254. hw_guard_wait(td);
  255. r = taal_dcs_write_0(DCS_SLEEP_OUT);
  256. if (r)
  257. return r;
  258. hw_guard_start(td, 120);
  259. if (td->panel_config->sleep.sleep_out)
  260. msleep(td->panel_config->sleep.sleep_out);
  261. return 0;
  262. }
  263. static int taal_get_id(u8 *id1, u8 *id2, u8 *id3)
  264. {
  265. int r;
  266. r = taal_dcs_read_1(DCS_GET_ID1, id1);
  267. if (r)
  268. return r;
  269. r = taal_dcs_read_1(DCS_GET_ID2, id2);
  270. if (r)
  271. return r;
  272. r = taal_dcs_read_1(DCS_GET_ID3, id3);
  273. if (r)
  274. return r;
  275. return 0;
  276. }
  277. static int taal_set_addr_mode(u8 rotate, bool mirror)
  278. {
  279. int r;
  280. u8 mode;
  281. int b5, b6, b7;
  282. r = taal_dcs_read_1(DCS_READ_MADCTL, &mode);
  283. if (r)
  284. return r;
  285. switch (rotate) {
  286. default:
  287. case 0:
  288. b7 = 0;
  289. b6 = 0;
  290. b5 = 0;
  291. break;
  292. case 1:
  293. b7 = 0;
  294. b6 = 1;
  295. b5 = 1;
  296. break;
  297. case 2:
  298. b7 = 1;
  299. b6 = 1;
  300. b5 = 0;
  301. break;
  302. case 3:
  303. b7 = 1;
  304. b6 = 0;
  305. b5 = 1;
  306. break;
  307. }
  308. if (mirror)
  309. b6 = !b6;
  310. mode &= ~((1<<7) | (1<<6) | (1<<5));
  311. mode |= (b7 << 7) | (b6 << 6) | (b5 << 5);
  312. return taal_dcs_write_1(DCS_MEM_ACC_CTRL, mode);
  313. }
  314. static int taal_set_update_window(u16 x, u16 y, u16 w, u16 h)
  315. {
  316. int r;
  317. u16 x1 = x;
  318. u16 x2 = x + w - 1;
  319. u16 y1 = y;
  320. u16 y2 = y + h - 1;
  321. u8 buf[5];
  322. buf[0] = DCS_COLUMN_ADDR;
  323. buf[1] = (x1 >> 8) & 0xff;
  324. buf[2] = (x1 >> 0) & 0xff;
  325. buf[3] = (x2 >> 8) & 0xff;
  326. buf[4] = (x2 >> 0) & 0xff;
  327. r = dsi_vc_dcs_write_nosync(TCH, buf, sizeof(buf));
  328. if (r)
  329. return r;
  330. buf[0] = DCS_PAGE_ADDR;
  331. buf[1] = (y1 >> 8) & 0xff;
  332. buf[2] = (y1 >> 0) & 0xff;
  333. buf[3] = (y2 >> 8) & 0xff;
  334. buf[4] = (y2 >> 0) & 0xff;
  335. r = dsi_vc_dcs_write_nosync(TCH, buf, sizeof(buf));
  336. if (r)
  337. return r;
  338. dsi_vc_send_bta_sync(TCH);
  339. return r;
  340. }
  341. static int taal_bl_update_status(struct backlight_device *dev)
  342. {
  343. struct omap_dss_device *dssdev = dev_get_drvdata(&dev->dev);
  344. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  345. struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev);
  346. int r;
  347. int level;
  348. if (dev->props.fb_blank == FB_BLANK_UNBLANK &&
  349. dev->props.power == FB_BLANK_UNBLANK)
  350. level = dev->props.brightness;
  351. else
  352. level = 0;
  353. dev_dbg(&dssdev->dev, "update brightness to %d\n", level);
  354. mutex_lock(&td->lock);
  355. if (td->use_dsi_bl) {
  356. if (td->enabled) {
  357. dsi_bus_lock();
  358. r = taal_dcs_write_1(DCS_BRIGHTNESS, level);
  359. dsi_bus_unlock();
  360. } else {
  361. r = 0;
  362. }
  363. } else {
  364. if (!panel_data->set_backlight)
  365. r = -EINVAL;
  366. else
  367. r = panel_data->set_backlight(dssdev, level);
  368. }
  369. mutex_unlock(&td->lock);
  370. return r;
  371. }
  372. static int taal_bl_get_intensity(struct backlight_device *dev)
  373. {
  374. if (dev->props.fb_blank == FB_BLANK_UNBLANK &&
  375. dev->props.power == FB_BLANK_UNBLANK)
  376. return dev->props.brightness;
  377. return 0;
  378. }
  379. static struct backlight_ops taal_bl_ops = {
  380. .get_brightness = taal_bl_get_intensity,
  381. .update_status = taal_bl_update_status,
  382. };
  383. static void taal_get_timings(struct omap_dss_device *dssdev,
  384. struct omap_video_timings *timings)
  385. {
  386. *timings = dssdev->panel.timings;
  387. }
  388. static void taal_get_resolution(struct omap_dss_device *dssdev,
  389. u16 *xres, u16 *yres)
  390. {
  391. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  392. if (td->rotate == 0 || td->rotate == 2) {
  393. *xres = dssdev->panel.timings.x_res;
  394. *yres = dssdev->panel.timings.y_res;
  395. } else {
  396. *yres = dssdev->panel.timings.x_res;
  397. *xres = dssdev->panel.timings.y_res;
  398. }
  399. }
  400. static ssize_t taal_num_errors_show(struct device *dev,
  401. struct device_attribute *attr, char *buf)
  402. {
  403. struct omap_dss_device *dssdev = to_dss_device(dev);
  404. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  405. u8 errors;
  406. int r;
  407. mutex_lock(&td->lock);
  408. if (td->enabled) {
  409. dsi_bus_lock();
  410. r = taal_dcs_read_1(DCS_READ_NUM_ERRORS, &errors);
  411. dsi_bus_unlock();
  412. } else {
  413. r = -ENODEV;
  414. }
  415. mutex_unlock(&td->lock);
  416. if (r)
  417. return r;
  418. return snprintf(buf, PAGE_SIZE, "%d\n", errors);
  419. }
  420. static ssize_t taal_hw_revision_show(struct device *dev,
  421. struct device_attribute *attr, char *buf)
  422. {
  423. struct omap_dss_device *dssdev = to_dss_device(dev);
  424. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  425. u8 id1, id2, id3;
  426. int r;
  427. mutex_lock(&td->lock);
  428. if (td->enabled) {
  429. dsi_bus_lock();
  430. r = taal_get_id(&id1, &id2, &id3);
  431. dsi_bus_unlock();
  432. } else {
  433. r = -ENODEV;
  434. }
  435. mutex_unlock(&td->lock);
  436. if (r)
  437. return r;
  438. return snprintf(buf, PAGE_SIZE, "%02x.%02x.%02x\n", id1, id2, id3);
  439. }
  440. static const char *cabc_modes[] = {
  441. "off", /* used also always when CABC is not supported */
  442. "ui",
  443. "still-image",
  444. "moving-image",
  445. };
  446. static ssize_t show_cabc_mode(struct device *dev,
  447. struct device_attribute *attr,
  448. char *buf)
  449. {
  450. struct omap_dss_device *dssdev = to_dss_device(dev);
  451. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  452. const char *mode_str;
  453. int mode;
  454. int len;
  455. mode = td->cabc_mode;
  456. mode_str = "unknown";
  457. if (mode >= 0 && mode < ARRAY_SIZE(cabc_modes))
  458. mode_str = cabc_modes[mode];
  459. len = snprintf(buf, PAGE_SIZE, "%s\n", mode_str);
  460. return len < PAGE_SIZE - 1 ? len : PAGE_SIZE - 1;
  461. }
  462. static ssize_t store_cabc_mode(struct device *dev,
  463. struct device_attribute *attr,
  464. const char *buf, size_t count)
  465. {
  466. struct omap_dss_device *dssdev = to_dss_device(dev);
  467. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  468. int i;
  469. for (i = 0; i < ARRAY_SIZE(cabc_modes); i++) {
  470. if (sysfs_streq(cabc_modes[i], buf))
  471. break;
  472. }
  473. if (i == ARRAY_SIZE(cabc_modes))
  474. return -EINVAL;
  475. mutex_lock(&td->lock);
  476. if (td->enabled) {
  477. dsi_bus_lock();
  478. if (!td->cabc_broken)
  479. taal_dcs_write_1(DCS_WRITE_CABC, i);
  480. dsi_bus_unlock();
  481. }
  482. td->cabc_mode = i;
  483. mutex_unlock(&td->lock);
  484. return count;
  485. }
  486. static ssize_t show_cabc_available_modes(struct device *dev,
  487. struct device_attribute *attr,
  488. char *buf)
  489. {
  490. int len;
  491. int i;
  492. for (i = 0, len = 0;
  493. len < PAGE_SIZE && i < ARRAY_SIZE(cabc_modes); i++)
  494. len += snprintf(&buf[len], PAGE_SIZE - len, "%s%s%s",
  495. i ? " " : "", cabc_modes[i],
  496. i == ARRAY_SIZE(cabc_modes) - 1 ? "\n" : "");
  497. return len < PAGE_SIZE ? len : PAGE_SIZE - 1;
  498. }
  499. static DEVICE_ATTR(num_dsi_errors, S_IRUGO, taal_num_errors_show, NULL);
  500. static DEVICE_ATTR(hw_revision, S_IRUGO, taal_hw_revision_show, NULL);
  501. static DEVICE_ATTR(cabc_mode, S_IRUGO | S_IWUSR,
  502. show_cabc_mode, store_cabc_mode);
  503. static DEVICE_ATTR(cabc_available_modes, S_IRUGO,
  504. show_cabc_available_modes, NULL);
  505. static struct attribute *taal_attrs[] = {
  506. &dev_attr_num_dsi_errors.attr,
  507. &dev_attr_hw_revision.attr,
  508. &dev_attr_cabc_mode.attr,
  509. &dev_attr_cabc_available_modes.attr,
  510. NULL,
  511. };
  512. static struct attribute_group taal_attr_group = {
  513. .attrs = taal_attrs,
  514. };
  515. static void taal_hw_reset(struct omap_dss_device *dssdev)
  516. {
  517. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  518. struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev);
  519. if (panel_data->reset_gpio == -1)
  520. return;
  521. gpio_set_value(panel_data->reset_gpio, 1);
  522. if (td->panel_config->reset_sequence.high)
  523. udelay(td->panel_config->reset_sequence.high);
  524. /* reset the panel */
  525. gpio_set_value(panel_data->reset_gpio, 0);
  526. /* assert reset */
  527. if (td->panel_config->reset_sequence.low)
  528. udelay(td->panel_config->reset_sequence.low);
  529. gpio_set_value(panel_data->reset_gpio, 1);
  530. /* wait after releasing reset */
  531. if (td->panel_config->sleep.hw_reset)
  532. msleep(td->panel_config->sleep.hw_reset);
  533. }
  534. static int taal_probe(struct omap_dss_device *dssdev)
  535. {
  536. struct backlight_properties props;
  537. struct taal_data *td;
  538. struct backlight_device *bldev;
  539. struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev);
  540. struct panel_config *panel_config = NULL;
  541. int r, i;
  542. dev_dbg(&dssdev->dev, "probe\n");
  543. if (!panel_data || !panel_data->name) {
  544. r = -EINVAL;
  545. goto err;
  546. }
  547. for (i = 0; i < ARRAY_SIZE(panel_configs); i++) {
  548. if (strcmp(panel_data->name, panel_configs[i].name) == 0) {
  549. panel_config = &panel_configs[i];
  550. break;
  551. }
  552. }
  553. if (!panel_config) {
  554. r = -EINVAL;
  555. goto err;
  556. }
  557. dssdev->panel.config = OMAP_DSS_LCD_TFT;
  558. dssdev->panel.timings = panel_config->timings;
  559. dssdev->ctrl.pixel_size = 24;
  560. td = kzalloc(sizeof(*td), GFP_KERNEL);
  561. if (!td) {
  562. r = -ENOMEM;
  563. goto err;
  564. }
  565. td->dssdev = dssdev;
  566. td->panel_config = panel_config;
  567. mutex_init(&td->lock);
  568. atomic_set(&td->do_update, 0);
  569. r = init_regulators(dssdev, panel_config->regulators,
  570. panel_config->num_regulators);
  571. if (r)
  572. goto err_reg;
  573. td->esd_wq = create_singlethread_workqueue("taal_esd");
  574. if (td->esd_wq == NULL) {
  575. dev_err(&dssdev->dev, "can't create ESD workqueue\n");
  576. r = -ENOMEM;
  577. goto err_wq;
  578. }
  579. INIT_DELAYED_WORK_DEFERRABLE(&td->esd_work, taal_esd_work);
  580. dev_set_drvdata(&dssdev->dev, td);
  581. taal_hw_reset(dssdev);
  582. /* if no platform set_backlight() defined, presume DSI backlight
  583. * control */
  584. memset(&props, 0, sizeof(struct backlight_properties));
  585. if (!panel_data->set_backlight)
  586. td->use_dsi_bl = true;
  587. if (td->use_dsi_bl)
  588. props.max_brightness = 255;
  589. else
  590. props.max_brightness = 127;
  591. bldev = backlight_device_register("taal", &dssdev->dev, dssdev,
  592. &taal_bl_ops, &props);
  593. if (IS_ERR(bldev)) {
  594. r = PTR_ERR(bldev);
  595. goto err_bl;
  596. }
  597. td->bldev = bldev;
  598. bldev->props.fb_blank = FB_BLANK_UNBLANK;
  599. bldev->props.power = FB_BLANK_UNBLANK;
  600. if (td->use_dsi_bl)
  601. bldev->props.brightness = 255;
  602. else
  603. bldev->props.brightness = 127;
  604. taal_bl_update_status(bldev);
  605. if (panel_data->use_ext_te) {
  606. int gpio = panel_data->ext_te_gpio;
  607. r = gpio_request(gpio, "taal irq");
  608. if (r) {
  609. dev_err(&dssdev->dev, "GPIO request failed\n");
  610. goto err_gpio;
  611. }
  612. gpio_direction_input(gpio);
  613. r = request_irq(gpio_to_irq(gpio), taal_te_isr,
  614. IRQF_DISABLED | IRQF_TRIGGER_RISING,
  615. "taal vsync", dssdev);
  616. if (r) {
  617. dev_err(&dssdev->dev, "IRQ request failed\n");
  618. gpio_free(gpio);
  619. goto err_irq;
  620. }
  621. INIT_DELAYED_WORK_DEFERRABLE(&td->te_timeout_work,
  622. taal_te_timeout_work_callback);
  623. dev_dbg(&dssdev->dev, "Using GPIO TE\n");
  624. }
  625. r = sysfs_create_group(&dssdev->dev.kobj, &taal_attr_group);
  626. if (r) {
  627. dev_err(&dssdev->dev, "failed to create sysfs files\n");
  628. goto err_sysfs;
  629. }
  630. return 0;
  631. err_sysfs:
  632. if (panel_data->use_ext_te)
  633. free_irq(gpio_to_irq(panel_data->ext_te_gpio), dssdev);
  634. err_irq:
  635. if (panel_data->use_ext_te)
  636. gpio_free(panel_data->ext_te_gpio);
  637. err_gpio:
  638. backlight_device_unregister(bldev);
  639. err_bl:
  640. destroy_workqueue(td->esd_wq);
  641. err_wq:
  642. free_regulators(panel_config->regulators, panel_config->num_regulators);
  643. err_reg:
  644. kfree(td);
  645. err:
  646. return r;
  647. }
  648. static void taal_remove(struct omap_dss_device *dssdev)
  649. {
  650. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  651. struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev);
  652. struct backlight_device *bldev;
  653. dev_dbg(&dssdev->dev, "remove\n");
  654. sysfs_remove_group(&dssdev->dev.kobj, &taal_attr_group);
  655. if (panel_data->use_ext_te) {
  656. int gpio = panel_data->ext_te_gpio;
  657. free_irq(gpio_to_irq(gpio), dssdev);
  658. gpio_free(gpio);
  659. }
  660. bldev = td->bldev;
  661. bldev->props.power = FB_BLANK_POWERDOWN;
  662. taal_bl_update_status(bldev);
  663. backlight_device_unregister(bldev);
  664. cancel_delayed_work(&td->esd_work);
  665. destroy_workqueue(td->esd_wq);
  666. /* reset, to be sure that the panel is in a valid state */
  667. taal_hw_reset(dssdev);
  668. free_regulators(td->panel_config->regulators,
  669. td->panel_config->num_regulators);
  670. kfree(td);
  671. }
  672. static int taal_power_on(struct omap_dss_device *dssdev)
  673. {
  674. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  675. u8 id1, id2, id3;
  676. int r;
  677. r = omapdss_dsi_display_enable(dssdev);
  678. if (r) {
  679. dev_err(&dssdev->dev, "failed to enable DSI\n");
  680. goto err0;
  681. }
  682. taal_hw_reset(dssdev);
  683. omapdss_dsi_vc_enable_hs(TCH, false);
  684. r = taal_sleep_out(td);
  685. if (r)
  686. goto err;
  687. r = taal_get_id(&id1, &id2, &id3);
  688. if (r)
  689. goto err;
  690. /* on early Taal revisions CABC is broken */
  691. if (td->panel_config->type == PANEL_TAAL &&
  692. (id2 == 0x00 || id2 == 0xff || id2 == 0x81))
  693. td->cabc_broken = true;
  694. r = taal_dcs_write_1(DCS_BRIGHTNESS, 0xff);
  695. if (r)
  696. goto err;
  697. r = taal_dcs_write_1(DCS_CTRL_DISPLAY,
  698. (1<<2) | (1<<5)); /* BL | BCTRL */
  699. if (r)
  700. goto err;
  701. r = taal_dcs_write_1(DCS_PIXEL_FORMAT, 0x7); /* 24bit/pixel */
  702. if (r)
  703. goto err;
  704. r = taal_set_addr_mode(td->rotate, td->mirror);
  705. if (r)
  706. goto err;
  707. if (!td->cabc_broken) {
  708. r = taal_dcs_write_1(DCS_WRITE_CABC, td->cabc_mode);
  709. if (r)
  710. goto err;
  711. }
  712. r = taal_dcs_write_0(DCS_DISPLAY_ON);
  713. if (r)
  714. goto err;
  715. r = _taal_enable_te(dssdev, td->te_enabled);
  716. if (r)
  717. goto err;
  718. td->enabled = 1;
  719. if (!td->intro_printed) {
  720. dev_info(&dssdev->dev, "%s panel revision %02x.%02x.%02x\n",
  721. td->panel_config->name, id1, id2, id3);
  722. if (td->cabc_broken)
  723. dev_info(&dssdev->dev,
  724. "old Taal version, CABC disabled\n");
  725. td->intro_printed = true;
  726. }
  727. omapdss_dsi_vc_enable_hs(TCH, true);
  728. return 0;
  729. err:
  730. dev_err(&dssdev->dev, "error while enabling panel, issuing HW reset\n");
  731. taal_hw_reset(dssdev);
  732. omapdss_dsi_display_disable(dssdev);
  733. err0:
  734. return r;
  735. }
  736. static void taal_power_off(struct omap_dss_device *dssdev)
  737. {
  738. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  739. int r;
  740. r = taal_dcs_write_0(DCS_DISPLAY_OFF);
  741. if (!r) {
  742. r = taal_sleep_in(td);
  743. /* HACK: wait a bit so that the message goes through */
  744. msleep(10);
  745. }
  746. if (r) {
  747. dev_err(&dssdev->dev,
  748. "error disabling panel, issuing HW reset\n");
  749. taal_hw_reset(dssdev);
  750. }
  751. omapdss_dsi_display_disable(dssdev);
  752. td->enabled = 0;
  753. }
  754. static int taal_enable(struct omap_dss_device *dssdev)
  755. {
  756. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  757. struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev);
  758. int r;
  759. dev_dbg(&dssdev->dev, "enable\n");
  760. mutex_lock(&td->lock);
  761. if (dssdev->state != OMAP_DSS_DISPLAY_DISABLED) {
  762. r = -EINVAL;
  763. goto err;
  764. }
  765. dsi_bus_lock();
  766. r = taal_power_on(dssdev);
  767. dsi_bus_unlock();
  768. if (r)
  769. goto err;
  770. if (panel_data->use_esd_check)
  771. queue_delayed_work(td->esd_wq, &td->esd_work,
  772. TAAL_ESD_CHECK_PERIOD);
  773. dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
  774. mutex_unlock(&td->lock);
  775. return 0;
  776. err:
  777. dev_dbg(&dssdev->dev, "enable failed\n");
  778. mutex_unlock(&td->lock);
  779. return r;
  780. }
  781. static void taal_disable(struct omap_dss_device *dssdev)
  782. {
  783. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  784. dev_dbg(&dssdev->dev, "disable\n");
  785. mutex_lock(&td->lock);
  786. cancel_delayed_work(&td->esd_work);
  787. dsi_bus_lock();
  788. if (dssdev->state == OMAP_DSS_DISPLAY_ACTIVE)
  789. taal_power_off(dssdev);
  790. dsi_bus_unlock();
  791. dssdev->state = OMAP_DSS_DISPLAY_DISABLED;
  792. mutex_unlock(&td->lock);
  793. }
  794. static int taal_suspend(struct omap_dss_device *dssdev)
  795. {
  796. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  797. int r;
  798. dev_dbg(&dssdev->dev, "suspend\n");
  799. mutex_lock(&td->lock);
  800. if (dssdev->state != OMAP_DSS_DISPLAY_ACTIVE) {
  801. r = -EINVAL;
  802. goto err;
  803. }
  804. cancel_delayed_work(&td->esd_work);
  805. dsi_bus_lock();
  806. taal_power_off(dssdev);
  807. dsi_bus_unlock();
  808. dssdev->state = OMAP_DSS_DISPLAY_SUSPENDED;
  809. mutex_unlock(&td->lock);
  810. return 0;
  811. err:
  812. mutex_unlock(&td->lock);
  813. return r;
  814. }
  815. static int taal_resume(struct omap_dss_device *dssdev)
  816. {
  817. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  818. struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev);
  819. int r;
  820. dev_dbg(&dssdev->dev, "resume\n");
  821. mutex_lock(&td->lock);
  822. if (dssdev->state != OMAP_DSS_DISPLAY_SUSPENDED) {
  823. r = -EINVAL;
  824. goto err;
  825. }
  826. dsi_bus_lock();
  827. r = taal_power_on(dssdev);
  828. dsi_bus_unlock();
  829. if (r) {
  830. dssdev->state = OMAP_DSS_DISPLAY_DISABLED;
  831. } else {
  832. dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
  833. if (panel_data->use_esd_check)
  834. queue_delayed_work(td->esd_wq, &td->esd_work,
  835. TAAL_ESD_CHECK_PERIOD);
  836. }
  837. mutex_unlock(&td->lock);
  838. return r;
  839. err:
  840. mutex_unlock(&td->lock);
  841. return r;
  842. }
  843. static void taal_framedone_cb(int err, void *data)
  844. {
  845. struct omap_dss_device *dssdev = data;
  846. dev_dbg(&dssdev->dev, "framedone, err %d\n", err);
  847. dsi_bus_unlock();
  848. }
  849. static irqreturn_t taal_te_isr(int irq, void *data)
  850. {
  851. struct omap_dss_device *dssdev = data;
  852. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  853. int old;
  854. int r;
  855. old = atomic_cmpxchg(&td->do_update, 1, 0);
  856. if (old) {
  857. cancel_delayed_work(&td->te_timeout_work);
  858. r = omap_dsi_update(dssdev, TCH,
  859. td->update_region.x,
  860. td->update_region.y,
  861. td->update_region.w,
  862. td->update_region.h,
  863. taal_framedone_cb, dssdev);
  864. if (r)
  865. goto err;
  866. }
  867. return IRQ_HANDLED;
  868. err:
  869. dev_err(&dssdev->dev, "start update failed\n");
  870. dsi_bus_unlock();
  871. return IRQ_HANDLED;
  872. }
  873. static void taal_te_timeout_work_callback(struct work_struct *work)
  874. {
  875. struct taal_data *td = container_of(work, struct taal_data,
  876. te_timeout_work.work);
  877. struct omap_dss_device *dssdev = td->dssdev;
  878. dev_err(&dssdev->dev, "TE not received for 250ms!\n");
  879. atomic_set(&td->do_update, 0);
  880. dsi_bus_unlock();
  881. }
  882. static int taal_update(struct omap_dss_device *dssdev,
  883. u16 x, u16 y, u16 w, u16 h)
  884. {
  885. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  886. struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev);
  887. int r;
  888. dev_dbg(&dssdev->dev, "update %d, %d, %d x %d\n", x, y, w, h);
  889. mutex_lock(&td->lock);
  890. dsi_bus_lock();
  891. if (!td->enabled) {
  892. r = 0;
  893. goto err;
  894. }
  895. r = omap_dsi_prepare_update(dssdev, &x, &y, &w, &h, true);
  896. if (r)
  897. goto err;
  898. r = taal_set_update_window(x, y, w, h);
  899. if (r)
  900. goto err;
  901. if (td->te_enabled && panel_data->use_ext_te) {
  902. td->update_region.x = x;
  903. td->update_region.y = y;
  904. td->update_region.w = w;
  905. td->update_region.h = h;
  906. barrier();
  907. schedule_delayed_work(&td->te_timeout_work,
  908. msecs_to_jiffies(250));
  909. atomic_set(&td->do_update, 1);
  910. } else {
  911. r = omap_dsi_update(dssdev, TCH, x, y, w, h,
  912. taal_framedone_cb, dssdev);
  913. if (r)
  914. goto err;
  915. }
  916. /* note: no bus_unlock here. unlock is in framedone_cb */
  917. mutex_unlock(&td->lock);
  918. return 0;
  919. err:
  920. dsi_bus_unlock();
  921. mutex_unlock(&td->lock);
  922. return r;
  923. }
  924. static int taal_sync(struct omap_dss_device *dssdev)
  925. {
  926. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  927. dev_dbg(&dssdev->dev, "sync\n");
  928. mutex_lock(&td->lock);
  929. dsi_bus_lock();
  930. dsi_bus_unlock();
  931. mutex_unlock(&td->lock);
  932. dev_dbg(&dssdev->dev, "sync done\n");
  933. return 0;
  934. }
  935. static int _taal_enable_te(struct omap_dss_device *dssdev, bool enable)
  936. {
  937. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  938. struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev);
  939. int r;
  940. if (enable)
  941. r = taal_dcs_write_1(DCS_TEAR_ON, 0);
  942. else
  943. r = taal_dcs_write_0(DCS_TEAR_OFF);
  944. if (!panel_data->use_ext_te)
  945. omapdss_dsi_enable_te(dssdev, enable);
  946. if (td->panel_config->sleep.enable_te)
  947. msleep(td->panel_config->sleep.enable_te);
  948. return r;
  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. int r;
  954. mutex_lock(&td->lock);
  955. if (td->te_enabled == enable)
  956. goto end;
  957. dsi_bus_lock();
  958. if (td->enabled) {
  959. r = _taal_enable_te(dssdev, enable);
  960. if (r)
  961. goto err;
  962. }
  963. td->te_enabled = enable;
  964. dsi_bus_unlock();
  965. end:
  966. mutex_unlock(&td->lock);
  967. return 0;
  968. err:
  969. dsi_bus_unlock();
  970. mutex_unlock(&td->lock);
  971. return r;
  972. }
  973. static int taal_get_te(struct omap_dss_device *dssdev)
  974. {
  975. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  976. int r;
  977. mutex_lock(&td->lock);
  978. r = td->te_enabled;
  979. mutex_unlock(&td->lock);
  980. return r;
  981. }
  982. static int taal_rotate(struct omap_dss_device *dssdev, u8 rotate)
  983. {
  984. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  985. int r;
  986. dev_dbg(&dssdev->dev, "rotate %d\n", rotate);
  987. mutex_lock(&td->lock);
  988. if (td->rotate == rotate)
  989. goto end;
  990. dsi_bus_lock();
  991. if (td->enabled) {
  992. r = taal_set_addr_mode(rotate, td->mirror);
  993. if (r)
  994. goto err;
  995. }
  996. td->rotate = rotate;
  997. dsi_bus_unlock();
  998. end:
  999. mutex_unlock(&td->lock);
  1000. return 0;
  1001. err:
  1002. dsi_bus_unlock();
  1003. mutex_unlock(&td->lock);
  1004. return r;
  1005. }
  1006. static u8 taal_get_rotate(struct omap_dss_device *dssdev)
  1007. {
  1008. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  1009. int r;
  1010. mutex_lock(&td->lock);
  1011. r = td->rotate;
  1012. mutex_unlock(&td->lock);
  1013. return r;
  1014. }
  1015. static int taal_mirror(struct omap_dss_device *dssdev, bool enable)
  1016. {
  1017. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  1018. int r;
  1019. dev_dbg(&dssdev->dev, "mirror %d\n", enable);
  1020. mutex_lock(&td->lock);
  1021. if (td->mirror == enable)
  1022. goto end;
  1023. dsi_bus_lock();
  1024. if (td->enabled) {
  1025. r = taal_set_addr_mode(td->rotate, enable);
  1026. if (r)
  1027. goto err;
  1028. }
  1029. td->mirror = enable;
  1030. dsi_bus_unlock();
  1031. end:
  1032. mutex_unlock(&td->lock);
  1033. return 0;
  1034. err:
  1035. dsi_bus_unlock();
  1036. mutex_unlock(&td->lock);
  1037. return r;
  1038. }
  1039. static bool taal_get_mirror(struct omap_dss_device *dssdev)
  1040. {
  1041. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  1042. int r;
  1043. mutex_lock(&td->lock);
  1044. r = td->mirror;
  1045. mutex_unlock(&td->lock);
  1046. return r;
  1047. }
  1048. static int taal_run_test(struct omap_dss_device *dssdev, int test_num)
  1049. {
  1050. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  1051. u8 id1, id2, id3;
  1052. int r;
  1053. mutex_lock(&td->lock);
  1054. if (!td->enabled) {
  1055. r = -ENODEV;
  1056. goto err1;
  1057. }
  1058. dsi_bus_lock();
  1059. r = taal_dcs_read_1(DCS_GET_ID1, &id1);
  1060. if (r)
  1061. goto err2;
  1062. r = taal_dcs_read_1(DCS_GET_ID2, &id2);
  1063. if (r)
  1064. goto err2;
  1065. r = taal_dcs_read_1(DCS_GET_ID3, &id3);
  1066. if (r)
  1067. goto err2;
  1068. dsi_bus_unlock();
  1069. mutex_unlock(&td->lock);
  1070. return 0;
  1071. err2:
  1072. dsi_bus_unlock();
  1073. err1:
  1074. mutex_unlock(&td->lock);
  1075. return r;
  1076. }
  1077. static int taal_memory_read(struct omap_dss_device *dssdev,
  1078. void *buf, size_t size,
  1079. u16 x, u16 y, u16 w, u16 h)
  1080. {
  1081. int r;
  1082. int first = 1;
  1083. int plen;
  1084. unsigned buf_used = 0;
  1085. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  1086. if (size < w * h * 3)
  1087. return -ENOMEM;
  1088. mutex_lock(&td->lock);
  1089. if (!td->enabled) {
  1090. r = -ENODEV;
  1091. goto err1;
  1092. }
  1093. size = min(w * h * 3,
  1094. dssdev->panel.timings.x_res *
  1095. dssdev->panel.timings.y_res * 3);
  1096. dsi_bus_lock();
  1097. /* plen 1 or 2 goes into short packet. until checksum error is fixed,
  1098. * use short packets. plen 32 works, but bigger packets seem to cause
  1099. * an error. */
  1100. if (size % 2)
  1101. plen = 1;
  1102. else
  1103. plen = 2;
  1104. taal_set_update_window(x, y, w, h);
  1105. r = dsi_vc_set_max_rx_packet_size(TCH, plen);
  1106. if (r)
  1107. goto err2;
  1108. while (buf_used < size) {
  1109. u8 dcs_cmd = first ? 0x2e : 0x3e;
  1110. first = 0;
  1111. r = dsi_vc_dcs_read(TCH, dcs_cmd,
  1112. buf + buf_used, size - buf_used);
  1113. if (r < 0) {
  1114. dev_err(&dssdev->dev, "read error\n");
  1115. goto err3;
  1116. }
  1117. buf_used += r;
  1118. if (r < plen) {
  1119. dev_err(&dssdev->dev, "short read\n");
  1120. break;
  1121. }
  1122. if (signal_pending(current)) {
  1123. dev_err(&dssdev->dev, "signal pending, "
  1124. "aborting memory read\n");
  1125. r = -ERESTARTSYS;
  1126. goto err3;
  1127. }
  1128. }
  1129. r = buf_used;
  1130. err3:
  1131. dsi_vc_set_max_rx_packet_size(TCH, 1);
  1132. err2:
  1133. dsi_bus_unlock();
  1134. err1:
  1135. mutex_unlock(&td->lock);
  1136. return r;
  1137. }
  1138. static void taal_esd_work(struct work_struct *work)
  1139. {
  1140. struct taal_data *td = container_of(work, struct taal_data,
  1141. esd_work.work);
  1142. struct omap_dss_device *dssdev = td->dssdev;
  1143. struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev);
  1144. u8 state1, state2;
  1145. int r;
  1146. mutex_lock(&td->lock);
  1147. if (!td->enabled) {
  1148. mutex_unlock(&td->lock);
  1149. return;
  1150. }
  1151. dsi_bus_lock();
  1152. r = taal_dcs_read_1(DCS_RDDSDR, &state1);
  1153. if (r) {
  1154. dev_err(&dssdev->dev, "failed to read Taal status\n");
  1155. goto err;
  1156. }
  1157. /* Run self diagnostics */
  1158. r = taal_sleep_out(td);
  1159. if (r) {
  1160. dev_err(&dssdev->dev, "failed to run Taal self-diagnostics\n");
  1161. goto err;
  1162. }
  1163. r = taal_dcs_read_1(DCS_RDDSDR, &state2);
  1164. if (r) {
  1165. dev_err(&dssdev->dev, "failed to read Taal status\n");
  1166. goto err;
  1167. }
  1168. /* Each sleep out command will trigger a self diagnostic and flip
  1169. * Bit6 if the test passes.
  1170. */
  1171. if (!((state1 ^ state2) & (1 << 6))) {
  1172. dev_err(&dssdev->dev, "LCD self diagnostics failed\n");
  1173. goto err;
  1174. }
  1175. /* Self-diagnostics result is also shown on TE GPIO line. We need
  1176. * to re-enable TE after self diagnostics */
  1177. if (td->te_enabled && panel_data->use_ext_te) {
  1178. r = taal_dcs_write_1(DCS_TEAR_ON, 0);
  1179. if (r)
  1180. goto err;
  1181. }
  1182. dsi_bus_unlock();
  1183. queue_delayed_work(td->esd_wq, &td->esd_work, TAAL_ESD_CHECK_PERIOD);
  1184. mutex_unlock(&td->lock);
  1185. return;
  1186. err:
  1187. dev_err(&dssdev->dev, "performing LCD reset\n");
  1188. taal_power_off(dssdev);
  1189. taal_hw_reset(dssdev);
  1190. taal_power_on(dssdev);
  1191. dsi_bus_unlock();
  1192. queue_delayed_work(td->esd_wq, &td->esd_work, TAAL_ESD_CHECK_PERIOD);
  1193. mutex_unlock(&td->lock);
  1194. }
  1195. static int taal_set_update_mode(struct omap_dss_device *dssdev,
  1196. enum omap_dss_update_mode mode)
  1197. {
  1198. if (mode != OMAP_DSS_UPDATE_MANUAL)
  1199. return -EINVAL;
  1200. return 0;
  1201. }
  1202. static enum omap_dss_update_mode taal_get_update_mode(
  1203. struct omap_dss_device *dssdev)
  1204. {
  1205. return OMAP_DSS_UPDATE_MANUAL;
  1206. }
  1207. static struct omap_dss_driver taal_driver = {
  1208. .probe = taal_probe,
  1209. .remove = taal_remove,
  1210. .enable = taal_enable,
  1211. .disable = taal_disable,
  1212. .suspend = taal_suspend,
  1213. .resume = taal_resume,
  1214. .set_update_mode = taal_set_update_mode,
  1215. .get_update_mode = taal_get_update_mode,
  1216. .update = taal_update,
  1217. .sync = taal_sync,
  1218. .get_resolution = taal_get_resolution,
  1219. .get_recommended_bpp = omapdss_default_get_recommended_bpp,
  1220. .enable_te = taal_enable_te,
  1221. .get_te = taal_get_te,
  1222. .set_rotate = taal_rotate,
  1223. .get_rotate = taal_get_rotate,
  1224. .set_mirror = taal_mirror,
  1225. .get_mirror = taal_get_mirror,
  1226. .run_test = taal_run_test,
  1227. .memory_read = taal_memory_read,
  1228. .get_timings = taal_get_timings,
  1229. .driver = {
  1230. .name = "taal",
  1231. .owner = THIS_MODULE,
  1232. },
  1233. };
  1234. static int __init taal_init(void)
  1235. {
  1236. omap_dss_register_driver(&taal_driver);
  1237. return 0;
  1238. }
  1239. static void __exit taal_exit(void)
  1240. {
  1241. omap_dss_unregister_driver(&taal_driver);
  1242. }
  1243. module_init(taal_init);
  1244. module_exit(taal_exit);
  1245. MODULE_AUTHOR("Tomi Valkeinen <tomi.valkeinen@nokia.com>");
  1246. MODULE_DESCRIPTION("Taal Driver");
  1247. MODULE_LICENSE("GPL");