panel-taal.c 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611
  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. props.type = BACKLIGHT_RAW;
  594. bldev = backlight_device_register("taal", &dssdev->dev, dssdev,
  595. &taal_bl_ops, &props);
  596. if (IS_ERR(bldev)) {
  597. r = PTR_ERR(bldev);
  598. goto err_bl;
  599. }
  600. td->bldev = bldev;
  601. bldev->props.fb_blank = FB_BLANK_UNBLANK;
  602. bldev->props.power = FB_BLANK_UNBLANK;
  603. if (td->use_dsi_bl)
  604. bldev->props.brightness = 255;
  605. else
  606. bldev->props.brightness = 127;
  607. taal_bl_update_status(bldev);
  608. if (panel_data->use_ext_te) {
  609. int gpio = panel_data->ext_te_gpio;
  610. r = gpio_request(gpio, "taal irq");
  611. if (r) {
  612. dev_err(&dssdev->dev, "GPIO request failed\n");
  613. goto err_gpio;
  614. }
  615. gpio_direction_input(gpio);
  616. r = request_irq(gpio_to_irq(gpio), taal_te_isr,
  617. IRQF_DISABLED | IRQF_TRIGGER_RISING,
  618. "taal vsync", dssdev);
  619. if (r) {
  620. dev_err(&dssdev->dev, "IRQ request failed\n");
  621. gpio_free(gpio);
  622. goto err_irq;
  623. }
  624. INIT_DELAYED_WORK_DEFERRABLE(&td->te_timeout_work,
  625. taal_te_timeout_work_callback);
  626. dev_dbg(&dssdev->dev, "Using GPIO TE\n");
  627. }
  628. r = omap_dsi_request_vc(dssdev, &td->channel);
  629. if (r) {
  630. dev_err(&dssdev->dev, "failed to get virtual channel\n");
  631. goto err_req_vc;
  632. }
  633. r = omap_dsi_set_vc_id(dssdev, td->channel, TCH);
  634. if (r) {
  635. dev_err(&dssdev->dev, "failed to set VC_ID\n");
  636. goto err_vc_id;
  637. }
  638. r = sysfs_create_group(&dssdev->dev.kobj, &taal_attr_group);
  639. if (r) {
  640. dev_err(&dssdev->dev, "failed to create sysfs files\n");
  641. goto err_vc_id;
  642. }
  643. return 0;
  644. err_vc_id:
  645. omap_dsi_release_vc(dssdev, td->channel);
  646. err_req_vc:
  647. if (panel_data->use_ext_te)
  648. free_irq(gpio_to_irq(panel_data->ext_te_gpio), dssdev);
  649. err_irq:
  650. if (panel_data->use_ext_te)
  651. gpio_free(panel_data->ext_te_gpio);
  652. err_gpio:
  653. backlight_device_unregister(bldev);
  654. err_bl:
  655. destroy_workqueue(td->esd_wq);
  656. err_wq:
  657. free_regulators(panel_config->regulators, panel_config->num_regulators);
  658. err_reg:
  659. kfree(td);
  660. err:
  661. return r;
  662. }
  663. static void taal_remove(struct omap_dss_device *dssdev)
  664. {
  665. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  666. struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev);
  667. struct backlight_device *bldev;
  668. dev_dbg(&dssdev->dev, "remove\n");
  669. sysfs_remove_group(&dssdev->dev.kobj, &taal_attr_group);
  670. omap_dsi_release_vc(dssdev, td->channel);
  671. if (panel_data->use_ext_te) {
  672. int gpio = panel_data->ext_te_gpio;
  673. free_irq(gpio_to_irq(gpio), dssdev);
  674. gpio_free(gpio);
  675. }
  676. bldev = td->bldev;
  677. bldev->props.power = FB_BLANK_POWERDOWN;
  678. taal_bl_update_status(bldev);
  679. backlight_device_unregister(bldev);
  680. cancel_delayed_work(&td->esd_work);
  681. destroy_workqueue(td->esd_wq);
  682. /* reset, to be sure that the panel is in a valid state */
  683. taal_hw_reset(dssdev);
  684. free_regulators(td->panel_config->regulators,
  685. td->panel_config->num_regulators);
  686. kfree(td);
  687. }
  688. static int taal_power_on(struct omap_dss_device *dssdev)
  689. {
  690. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  691. u8 id1, id2, id3;
  692. int r;
  693. r = omapdss_dsi_display_enable(dssdev);
  694. if (r) {
  695. dev_err(&dssdev->dev, "failed to enable DSI\n");
  696. goto err0;
  697. }
  698. taal_hw_reset(dssdev);
  699. omapdss_dsi_vc_enable_hs(td->channel, false);
  700. r = taal_sleep_out(td);
  701. if (r)
  702. goto err;
  703. r = taal_get_id(td, &id1, &id2, &id3);
  704. if (r)
  705. goto err;
  706. /* on early Taal revisions CABC is broken */
  707. if (td->panel_config->type == PANEL_TAAL &&
  708. (id2 == 0x00 || id2 == 0xff || id2 == 0x81))
  709. td->cabc_broken = true;
  710. r = taal_dcs_write_1(td, DCS_BRIGHTNESS, 0xff);
  711. if (r)
  712. goto err;
  713. r = taal_dcs_write_1(td, DCS_CTRL_DISPLAY,
  714. (1<<2) | (1<<5)); /* BL | BCTRL */
  715. if (r)
  716. goto err;
  717. r = taal_dcs_write_1(td, DCS_PIXEL_FORMAT, 0x7); /* 24bit/pixel */
  718. if (r)
  719. goto err;
  720. r = taal_set_addr_mode(td, td->rotate, td->mirror);
  721. if (r)
  722. goto err;
  723. if (!td->cabc_broken) {
  724. r = taal_dcs_write_1(td, DCS_WRITE_CABC, td->cabc_mode);
  725. if (r)
  726. goto err;
  727. }
  728. r = taal_dcs_write_0(td, DCS_DISPLAY_ON);
  729. if (r)
  730. goto err;
  731. r = _taal_enable_te(dssdev, td->te_enabled);
  732. if (r)
  733. goto err;
  734. td->enabled = 1;
  735. if (!td->intro_printed) {
  736. dev_info(&dssdev->dev, "%s panel revision %02x.%02x.%02x\n",
  737. td->panel_config->name, id1, id2, id3);
  738. if (td->cabc_broken)
  739. dev_info(&dssdev->dev,
  740. "old Taal version, CABC disabled\n");
  741. td->intro_printed = true;
  742. }
  743. omapdss_dsi_vc_enable_hs(td->channel, true);
  744. return 0;
  745. err:
  746. dev_err(&dssdev->dev, "error while enabling panel, issuing HW reset\n");
  747. taal_hw_reset(dssdev);
  748. omapdss_dsi_display_disable(dssdev);
  749. err0:
  750. return r;
  751. }
  752. static void taal_power_off(struct omap_dss_device *dssdev)
  753. {
  754. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  755. int r;
  756. r = taal_dcs_write_0(td, DCS_DISPLAY_OFF);
  757. if (!r) {
  758. r = taal_sleep_in(td);
  759. /* HACK: wait a bit so that the message goes through */
  760. msleep(10);
  761. }
  762. if (r) {
  763. dev_err(&dssdev->dev,
  764. "error disabling panel, issuing HW reset\n");
  765. taal_hw_reset(dssdev);
  766. }
  767. omapdss_dsi_display_disable(dssdev);
  768. td->enabled = 0;
  769. }
  770. static int taal_enable(struct omap_dss_device *dssdev)
  771. {
  772. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  773. struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev);
  774. int r;
  775. dev_dbg(&dssdev->dev, "enable\n");
  776. mutex_lock(&td->lock);
  777. if (dssdev->state != OMAP_DSS_DISPLAY_DISABLED) {
  778. r = -EINVAL;
  779. goto err;
  780. }
  781. dsi_bus_lock();
  782. r = taal_power_on(dssdev);
  783. dsi_bus_unlock();
  784. if (r)
  785. goto err;
  786. if (panel_data->use_esd_check)
  787. queue_delayed_work(td->esd_wq, &td->esd_work,
  788. TAAL_ESD_CHECK_PERIOD);
  789. dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
  790. mutex_unlock(&td->lock);
  791. return 0;
  792. err:
  793. dev_dbg(&dssdev->dev, "enable failed\n");
  794. mutex_unlock(&td->lock);
  795. return r;
  796. }
  797. static void taal_disable(struct omap_dss_device *dssdev)
  798. {
  799. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  800. dev_dbg(&dssdev->dev, "disable\n");
  801. mutex_lock(&td->lock);
  802. cancel_delayed_work(&td->esd_work);
  803. dsi_bus_lock();
  804. if (dssdev->state == OMAP_DSS_DISPLAY_ACTIVE)
  805. taal_power_off(dssdev);
  806. dsi_bus_unlock();
  807. dssdev->state = OMAP_DSS_DISPLAY_DISABLED;
  808. mutex_unlock(&td->lock);
  809. }
  810. static int taal_suspend(struct omap_dss_device *dssdev)
  811. {
  812. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  813. int r;
  814. dev_dbg(&dssdev->dev, "suspend\n");
  815. mutex_lock(&td->lock);
  816. if (dssdev->state != OMAP_DSS_DISPLAY_ACTIVE) {
  817. r = -EINVAL;
  818. goto err;
  819. }
  820. cancel_delayed_work(&td->esd_work);
  821. dsi_bus_lock();
  822. taal_power_off(dssdev);
  823. dsi_bus_unlock();
  824. dssdev->state = OMAP_DSS_DISPLAY_SUSPENDED;
  825. mutex_unlock(&td->lock);
  826. return 0;
  827. err:
  828. mutex_unlock(&td->lock);
  829. return r;
  830. }
  831. static int taal_resume(struct omap_dss_device *dssdev)
  832. {
  833. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  834. struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev);
  835. int r;
  836. dev_dbg(&dssdev->dev, "resume\n");
  837. mutex_lock(&td->lock);
  838. if (dssdev->state != OMAP_DSS_DISPLAY_SUSPENDED) {
  839. r = -EINVAL;
  840. goto err;
  841. }
  842. dsi_bus_lock();
  843. r = taal_power_on(dssdev);
  844. dsi_bus_unlock();
  845. if (r) {
  846. dssdev->state = OMAP_DSS_DISPLAY_DISABLED;
  847. } else {
  848. dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
  849. if (panel_data->use_esd_check)
  850. queue_delayed_work(td->esd_wq, &td->esd_work,
  851. TAAL_ESD_CHECK_PERIOD);
  852. }
  853. mutex_unlock(&td->lock);
  854. return r;
  855. err:
  856. mutex_unlock(&td->lock);
  857. return r;
  858. }
  859. static void taal_framedone_cb(int err, void *data)
  860. {
  861. struct omap_dss_device *dssdev = data;
  862. dev_dbg(&dssdev->dev, "framedone, err %d\n", err);
  863. dsi_bus_unlock();
  864. }
  865. static irqreturn_t taal_te_isr(int irq, void *data)
  866. {
  867. struct omap_dss_device *dssdev = data;
  868. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  869. int old;
  870. int r;
  871. old = atomic_cmpxchg(&td->do_update, 1, 0);
  872. if (old) {
  873. cancel_delayed_work(&td->te_timeout_work);
  874. r = omap_dsi_update(dssdev, td->channel,
  875. td->update_region.x,
  876. td->update_region.y,
  877. td->update_region.w,
  878. td->update_region.h,
  879. taal_framedone_cb, dssdev);
  880. if (r)
  881. goto err;
  882. }
  883. return IRQ_HANDLED;
  884. err:
  885. dev_err(&dssdev->dev, "start update failed\n");
  886. dsi_bus_unlock();
  887. return IRQ_HANDLED;
  888. }
  889. static void taal_te_timeout_work_callback(struct work_struct *work)
  890. {
  891. struct taal_data *td = container_of(work, struct taal_data,
  892. te_timeout_work.work);
  893. struct omap_dss_device *dssdev = td->dssdev;
  894. dev_err(&dssdev->dev, "TE not received for 250ms!\n");
  895. atomic_set(&td->do_update, 0);
  896. dsi_bus_unlock();
  897. }
  898. static int taal_update(struct omap_dss_device *dssdev,
  899. u16 x, u16 y, u16 w, u16 h)
  900. {
  901. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  902. struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev);
  903. int r;
  904. dev_dbg(&dssdev->dev, "update %d, %d, %d x %d\n", x, y, w, h);
  905. mutex_lock(&td->lock);
  906. dsi_bus_lock();
  907. if (!td->enabled) {
  908. r = 0;
  909. goto err;
  910. }
  911. r = omap_dsi_prepare_update(dssdev, &x, &y, &w, &h, true);
  912. if (r)
  913. goto err;
  914. r = taal_set_update_window(td, x, y, w, h);
  915. if (r)
  916. goto err;
  917. if (td->te_enabled && panel_data->use_ext_te) {
  918. td->update_region.x = x;
  919. td->update_region.y = y;
  920. td->update_region.w = w;
  921. td->update_region.h = h;
  922. barrier();
  923. schedule_delayed_work(&td->te_timeout_work,
  924. msecs_to_jiffies(250));
  925. atomic_set(&td->do_update, 1);
  926. } else {
  927. r = omap_dsi_update(dssdev, td->channel, x, y, w, h,
  928. taal_framedone_cb, dssdev);
  929. if (r)
  930. goto err;
  931. }
  932. /* note: no bus_unlock here. unlock is in framedone_cb */
  933. mutex_unlock(&td->lock);
  934. return 0;
  935. err:
  936. dsi_bus_unlock();
  937. mutex_unlock(&td->lock);
  938. return r;
  939. }
  940. static int taal_sync(struct omap_dss_device *dssdev)
  941. {
  942. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  943. dev_dbg(&dssdev->dev, "sync\n");
  944. mutex_lock(&td->lock);
  945. dsi_bus_lock();
  946. dsi_bus_unlock();
  947. mutex_unlock(&td->lock);
  948. dev_dbg(&dssdev->dev, "sync done\n");
  949. return 0;
  950. }
  951. static int _taal_enable_te(struct omap_dss_device *dssdev, bool enable)
  952. {
  953. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  954. struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev);
  955. int r;
  956. if (enable)
  957. r = taal_dcs_write_1(td, DCS_TEAR_ON, 0);
  958. else
  959. r = taal_dcs_write_0(td, DCS_TEAR_OFF);
  960. if (!panel_data->use_ext_te)
  961. omapdss_dsi_enable_te(dssdev, enable);
  962. if (td->panel_config->sleep.enable_te)
  963. msleep(td->panel_config->sleep.enable_te);
  964. return r;
  965. }
  966. static int taal_enable_te(struct omap_dss_device *dssdev, bool enable)
  967. {
  968. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  969. int r;
  970. mutex_lock(&td->lock);
  971. if (td->te_enabled == enable)
  972. goto end;
  973. dsi_bus_lock();
  974. if (td->enabled) {
  975. r = _taal_enable_te(dssdev, enable);
  976. if (r)
  977. goto err;
  978. }
  979. td->te_enabled = enable;
  980. dsi_bus_unlock();
  981. end:
  982. mutex_unlock(&td->lock);
  983. return 0;
  984. err:
  985. dsi_bus_unlock();
  986. mutex_unlock(&td->lock);
  987. return r;
  988. }
  989. static int taal_get_te(struct omap_dss_device *dssdev)
  990. {
  991. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  992. int r;
  993. mutex_lock(&td->lock);
  994. r = td->te_enabled;
  995. mutex_unlock(&td->lock);
  996. return r;
  997. }
  998. static int taal_rotate(struct omap_dss_device *dssdev, u8 rotate)
  999. {
  1000. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  1001. int r;
  1002. dev_dbg(&dssdev->dev, "rotate %d\n", rotate);
  1003. mutex_lock(&td->lock);
  1004. if (td->rotate == rotate)
  1005. goto end;
  1006. dsi_bus_lock();
  1007. if (td->enabled) {
  1008. r = taal_set_addr_mode(td, rotate, td->mirror);
  1009. if (r)
  1010. goto err;
  1011. }
  1012. td->rotate = rotate;
  1013. dsi_bus_unlock();
  1014. end:
  1015. mutex_unlock(&td->lock);
  1016. return 0;
  1017. err:
  1018. dsi_bus_unlock();
  1019. mutex_unlock(&td->lock);
  1020. return r;
  1021. }
  1022. static u8 taal_get_rotate(struct omap_dss_device *dssdev)
  1023. {
  1024. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  1025. int r;
  1026. mutex_lock(&td->lock);
  1027. r = td->rotate;
  1028. mutex_unlock(&td->lock);
  1029. return r;
  1030. }
  1031. static int taal_mirror(struct omap_dss_device *dssdev, bool enable)
  1032. {
  1033. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  1034. int r;
  1035. dev_dbg(&dssdev->dev, "mirror %d\n", enable);
  1036. mutex_lock(&td->lock);
  1037. if (td->mirror == enable)
  1038. goto end;
  1039. dsi_bus_lock();
  1040. if (td->enabled) {
  1041. r = taal_set_addr_mode(td, td->rotate, enable);
  1042. if (r)
  1043. goto err;
  1044. }
  1045. td->mirror = enable;
  1046. dsi_bus_unlock();
  1047. end:
  1048. mutex_unlock(&td->lock);
  1049. return 0;
  1050. err:
  1051. dsi_bus_unlock();
  1052. mutex_unlock(&td->lock);
  1053. return r;
  1054. }
  1055. static bool taal_get_mirror(struct omap_dss_device *dssdev)
  1056. {
  1057. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  1058. int r;
  1059. mutex_lock(&td->lock);
  1060. r = td->mirror;
  1061. mutex_unlock(&td->lock);
  1062. return r;
  1063. }
  1064. static int taal_run_test(struct omap_dss_device *dssdev, int test_num)
  1065. {
  1066. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  1067. u8 id1, id2, id3;
  1068. int r;
  1069. mutex_lock(&td->lock);
  1070. if (!td->enabled) {
  1071. r = -ENODEV;
  1072. goto err1;
  1073. }
  1074. dsi_bus_lock();
  1075. r = taal_dcs_read_1(td, DCS_GET_ID1, &id1);
  1076. if (r)
  1077. goto err2;
  1078. r = taal_dcs_read_1(td, DCS_GET_ID2, &id2);
  1079. if (r)
  1080. goto err2;
  1081. r = taal_dcs_read_1(td, DCS_GET_ID3, &id3);
  1082. if (r)
  1083. goto err2;
  1084. dsi_bus_unlock();
  1085. mutex_unlock(&td->lock);
  1086. return 0;
  1087. err2:
  1088. dsi_bus_unlock();
  1089. err1:
  1090. mutex_unlock(&td->lock);
  1091. return r;
  1092. }
  1093. static int taal_memory_read(struct omap_dss_device *dssdev,
  1094. void *buf, size_t size,
  1095. u16 x, u16 y, u16 w, u16 h)
  1096. {
  1097. int r;
  1098. int first = 1;
  1099. int plen;
  1100. unsigned buf_used = 0;
  1101. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  1102. if (size < w * h * 3)
  1103. return -ENOMEM;
  1104. mutex_lock(&td->lock);
  1105. if (!td->enabled) {
  1106. r = -ENODEV;
  1107. goto err1;
  1108. }
  1109. size = min(w * h * 3,
  1110. dssdev->panel.timings.x_res *
  1111. dssdev->panel.timings.y_res * 3);
  1112. dsi_bus_lock();
  1113. /* plen 1 or 2 goes into short packet. until checksum error is fixed,
  1114. * use short packets. plen 32 works, but bigger packets seem to cause
  1115. * an error. */
  1116. if (size % 2)
  1117. plen = 1;
  1118. else
  1119. plen = 2;
  1120. taal_set_update_window(td, x, y, w, h);
  1121. r = dsi_vc_set_max_rx_packet_size(td->channel, plen);
  1122. if (r)
  1123. goto err2;
  1124. while (buf_used < size) {
  1125. u8 dcs_cmd = first ? 0x2e : 0x3e;
  1126. first = 0;
  1127. r = dsi_vc_dcs_read(td->channel, dcs_cmd,
  1128. buf + buf_used, size - buf_used);
  1129. if (r < 0) {
  1130. dev_err(&dssdev->dev, "read error\n");
  1131. goto err3;
  1132. }
  1133. buf_used += r;
  1134. if (r < plen) {
  1135. dev_err(&dssdev->dev, "short read\n");
  1136. break;
  1137. }
  1138. if (signal_pending(current)) {
  1139. dev_err(&dssdev->dev, "signal pending, "
  1140. "aborting memory read\n");
  1141. r = -ERESTARTSYS;
  1142. goto err3;
  1143. }
  1144. }
  1145. r = buf_used;
  1146. err3:
  1147. dsi_vc_set_max_rx_packet_size(td->channel, 1);
  1148. err2:
  1149. dsi_bus_unlock();
  1150. err1:
  1151. mutex_unlock(&td->lock);
  1152. return r;
  1153. }
  1154. static void taal_esd_work(struct work_struct *work)
  1155. {
  1156. struct taal_data *td = container_of(work, struct taal_data,
  1157. esd_work.work);
  1158. struct omap_dss_device *dssdev = td->dssdev;
  1159. struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev);
  1160. u8 state1, state2;
  1161. int r;
  1162. mutex_lock(&td->lock);
  1163. if (!td->enabled) {
  1164. mutex_unlock(&td->lock);
  1165. return;
  1166. }
  1167. dsi_bus_lock();
  1168. r = taal_dcs_read_1(td, DCS_RDDSDR, &state1);
  1169. if (r) {
  1170. dev_err(&dssdev->dev, "failed to read Taal status\n");
  1171. goto err;
  1172. }
  1173. /* Run self diagnostics */
  1174. r = taal_sleep_out(td);
  1175. if (r) {
  1176. dev_err(&dssdev->dev, "failed to run Taal self-diagnostics\n");
  1177. goto err;
  1178. }
  1179. r = taal_dcs_read_1(td, DCS_RDDSDR, &state2);
  1180. if (r) {
  1181. dev_err(&dssdev->dev, "failed to read Taal status\n");
  1182. goto err;
  1183. }
  1184. /* Each sleep out command will trigger a self diagnostic and flip
  1185. * Bit6 if the test passes.
  1186. */
  1187. if (!((state1 ^ state2) & (1 << 6))) {
  1188. dev_err(&dssdev->dev, "LCD self diagnostics failed\n");
  1189. goto err;
  1190. }
  1191. /* Self-diagnostics result is also shown on TE GPIO line. We need
  1192. * to re-enable TE after self diagnostics */
  1193. if (td->te_enabled && panel_data->use_ext_te) {
  1194. r = taal_dcs_write_1(td, DCS_TEAR_ON, 0);
  1195. if (r)
  1196. goto err;
  1197. }
  1198. dsi_bus_unlock();
  1199. queue_delayed_work(td->esd_wq, &td->esd_work, TAAL_ESD_CHECK_PERIOD);
  1200. mutex_unlock(&td->lock);
  1201. return;
  1202. err:
  1203. dev_err(&dssdev->dev, "performing LCD reset\n");
  1204. taal_power_off(dssdev);
  1205. taal_hw_reset(dssdev);
  1206. taal_power_on(dssdev);
  1207. dsi_bus_unlock();
  1208. queue_delayed_work(td->esd_wq, &td->esd_work, TAAL_ESD_CHECK_PERIOD);
  1209. mutex_unlock(&td->lock);
  1210. }
  1211. static int taal_set_update_mode(struct omap_dss_device *dssdev,
  1212. enum omap_dss_update_mode mode)
  1213. {
  1214. if (mode != OMAP_DSS_UPDATE_MANUAL)
  1215. return -EINVAL;
  1216. return 0;
  1217. }
  1218. static enum omap_dss_update_mode taal_get_update_mode(
  1219. struct omap_dss_device *dssdev)
  1220. {
  1221. return OMAP_DSS_UPDATE_MANUAL;
  1222. }
  1223. static struct omap_dss_driver taal_driver = {
  1224. .probe = taal_probe,
  1225. .remove = taal_remove,
  1226. .enable = taal_enable,
  1227. .disable = taal_disable,
  1228. .suspend = taal_suspend,
  1229. .resume = taal_resume,
  1230. .set_update_mode = taal_set_update_mode,
  1231. .get_update_mode = taal_get_update_mode,
  1232. .update = taal_update,
  1233. .sync = taal_sync,
  1234. .get_resolution = taal_get_resolution,
  1235. .get_recommended_bpp = omapdss_default_get_recommended_bpp,
  1236. .enable_te = taal_enable_te,
  1237. .get_te = taal_get_te,
  1238. .set_rotate = taal_rotate,
  1239. .get_rotate = taal_get_rotate,
  1240. .set_mirror = taal_mirror,
  1241. .get_mirror = taal_get_mirror,
  1242. .run_test = taal_run_test,
  1243. .memory_read = taal_memory_read,
  1244. .get_timings = taal_get_timings,
  1245. .driver = {
  1246. .name = "taal",
  1247. .owner = THIS_MODULE,
  1248. },
  1249. };
  1250. static int __init taal_init(void)
  1251. {
  1252. omap_dss_register_driver(&taal_driver);
  1253. return 0;
  1254. }
  1255. static void __exit taal_exit(void)
  1256. {
  1257. omap_dss_unregister_driver(&taal_driver);
  1258. }
  1259. module_init(taal_init);
  1260. module_exit(taal_exit);
  1261. MODULE_AUTHOR("Tomi Valkeinen <tomi.valkeinen@nokia.com>");
  1262. MODULE_DESCRIPTION("Taal Driver");
  1263. MODULE_LICENSE("GPL");