panel-taal.c 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263
  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/completion.h>
  30. #include <linux/workqueue.h>
  31. #include <linux/slab.h>
  32. #include <linux/mutex.h>
  33. #include <plat/display.h>
  34. /* DSI Virtual channel. Hardcoded for now. */
  35. #define TCH 0
  36. #define DCS_READ_NUM_ERRORS 0x05
  37. #define DCS_READ_POWER_MODE 0x0a
  38. #define DCS_READ_MADCTL 0x0b
  39. #define DCS_READ_PIXEL_FORMAT 0x0c
  40. #define DCS_RDDSDR 0x0f
  41. #define DCS_SLEEP_IN 0x10
  42. #define DCS_SLEEP_OUT 0x11
  43. #define DCS_DISPLAY_OFF 0x28
  44. #define DCS_DISPLAY_ON 0x29
  45. #define DCS_COLUMN_ADDR 0x2a
  46. #define DCS_PAGE_ADDR 0x2b
  47. #define DCS_MEMORY_WRITE 0x2c
  48. #define DCS_TEAR_OFF 0x34
  49. #define DCS_TEAR_ON 0x35
  50. #define DCS_MEM_ACC_CTRL 0x36
  51. #define DCS_PIXEL_FORMAT 0x3a
  52. #define DCS_BRIGHTNESS 0x51
  53. #define DCS_CTRL_DISPLAY 0x53
  54. #define DCS_WRITE_CABC 0x55
  55. #define DCS_READ_CABC 0x56
  56. #define DCS_GET_ID1 0xda
  57. #define DCS_GET_ID2 0xdb
  58. #define DCS_GET_ID3 0xdc
  59. /* #define TAAL_USE_ESD_CHECK */
  60. #define TAAL_ESD_CHECK_PERIOD msecs_to_jiffies(5000)
  61. static int _taal_enable_te(struct omap_dss_device *dssdev, bool enable);
  62. struct taal_data {
  63. struct mutex lock;
  64. struct backlight_device *bldev;
  65. unsigned long hw_guard_end; /* next value of jiffies when we can
  66. * issue the next sleep in/out command
  67. */
  68. unsigned long hw_guard_wait; /* max guard time in jiffies */
  69. struct omap_dss_device *dssdev;
  70. bool enabled;
  71. u8 rotate;
  72. bool mirror;
  73. bool te_enabled;
  74. bool use_ext_te;
  75. struct completion te_completion;
  76. bool use_dsi_bl;
  77. bool cabc_broken;
  78. unsigned cabc_mode;
  79. bool intro_printed;
  80. struct workqueue_struct *esd_wq;
  81. struct delayed_work esd_work;
  82. };
  83. static void taal_esd_work(struct work_struct *work);
  84. static void hw_guard_start(struct taal_data *td, int guard_msec)
  85. {
  86. td->hw_guard_wait = msecs_to_jiffies(guard_msec);
  87. td->hw_guard_end = jiffies + td->hw_guard_wait;
  88. }
  89. static void hw_guard_wait(struct taal_data *td)
  90. {
  91. unsigned long wait = td->hw_guard_end - jiffies;
  92. if ((long)wait > 0 && wait <= td->hw_guard_wait) {
  93. set_current_state(TASK_UNINTERRUPTIBLE);
  94. schedule_timeout(wait);
  95. }
  96. }
  97. static int taal_dcs_read_1(u8 dcs_cmd, u8 *data)
  98. {
  99. int r;
  100. u8 buf[1];
  101. r = dsi_vc_dcs_read(TCH, dcs_cmd, buf, 1);
  102. if (r < 0)
  103. return r;
  104. *data = buf[0];
  105. return 0;
  106. }
  107. static int taal_dcs_write_0(u8 dcs_cmd)
  108. {
  109. return dsi_vc_dcs_write(TCH, &dcs_cmd, 1);
  110. }
  111. static int taal_dcs_write_1(u8 dcs_cmd, u8 param)
  112. {
  113. u8 buf[2];
  114. buf[0] = dcs_cmd;
  115. buf[1] = param;
  116. return dsi_vc_dcs_write(TCH, buf, 2);
  117. }
  118. static int taal_sleep_in(struct taal_data *td)
  119. {
  120. u8 cmd;
  121. int r;
  122. hw_guard_wait(td);
  123. cmd = DCS_SLEEP_IN;
  124. r = dsi_vc_dcs_write_nosync(TCH, &cmd, 1);
  125. if (r)
  126. return r;
  127. hw_guard_start(td, 120);
  128. msleep(5);
  129. return 0;
  130. }
  131. static int taal_sleep_out(struct taal_data *td)
  132. {
  133. int r;
  134. hw_guard_wait(td);
  135. r = taal_dcs_write_0(DCS_SLEEP_OUT);
  136. if (r)
  137. return r;
  138. hw_guard_start(td, 120);
  139. msleep(5);
  140. return 0;
  141. }
  142. static int taal_get_id(u8 *id1, u8 *id2, u8 *id3)
  143. {
  144. int r;
  145. r = taal_dcs_read_1(DCS_GET_ID1, id1);
  146. if (r)
  147. return r;
  148. r = taal_dcs_read_1(DCS_GET_ID2, id2);
  149. if (r)
  150. return r;
  151. r = taal_dcs_read_1(DCS_GET_ID3, id3);
  152. if (r)
  153. return r;
  154. return 0;
  155. }
  156. static int taal_set_addr_mode(u8 rotate, bool mirror)
  157. {
  158. int r;
  159. u8 mode;
  160. int b5, b6, b7;
  161. r = taal_dcs_read_1(DCS_READ_MADCTL, &mode);
  162. if (r)
  163. return r;
  164. switch (rotate) {
  165. default:
  166. case 0:
  167. b7 = 0;
  168. b6 = 0;
  169. b5 = 0;
  170. break;
  171. case 1:
  172. b7 = 0;
  173. b6 = 1;
  174. b5 = 1;
  175. break;
  176. case 2:
  177. b7 = 1;
  178. b6 = 1;
  179. b5 = 0;
  180. break;
  181. case 3:
  182. b7 = 1;
  183. b6 = 0;
  184. b5 = 1;
  185. break;
  186. }
  187. if (mirror)
  188. b6 = !b6;
  189. mode &= ~((1<<7) | (1<<6) | (1<<5));
  190. mode |= (b7 << 7) | (b6 << 6) | (b5 << 5);
  191. return taal_dcs_write_1(DCS_MEM_ACC_CTRL, mode);
  192. }
  193. static int taal_set_update_window(u16 x, u16 y, u16 w, u16 h)
  194. {
  195. int r;
  196. u16 x1 = x;
  197. u16 x2 = x + w - 1;
  198. u16 y1 = y;
  199. u16 y2 = y + h - 1;
  200. u8 buf[5];
  201. buf[0] = DCS_COLUMN_ADDR;
  202. buf[1] = (x1 >> 8) & 0xff;
  203. buf[2] = (x1 >> 0) & 0xff;
  204. buf[3] = (x2 >> 8) & 0xff;
  205. buf[4] = (x2 >> 0) & 0xff;
  206. r = dsi_vc_dcs_write_nosync(TCH, buf, sizeof(buf));
  207. if (r)
  208. return r;
  209. buf[0] = DCS_PAGE_ADDR;
  210. buf[1] = (y1 >> 8) & 0xff;
  211. buf[2] = (y1 >> 0) & 0xff;
  212. buf[3] = (y2 >> 8) & 0xff;
  213. buf[4] = (y2 >> 0) & 0xff;
  214. r = dsi_vc_dcs_write_nosync(TCH, buf, sizeof(buf));
  215. if (r)
  216. return r;
  217. dsi_vc_send_bta_sync(TCH);
  218. return r;
  219. }
  220. static int taal_bl_update_status(struct backlight_device *dev)
  221. {
  222. struct omap_dss_device *dssdev = dev_get_drvdata(&dev->dev);
  223. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  224. int r;
  225. int level;
  226. if (dev->props.fb_blank == FB_BLANK_UNBLANK &&
  227. dev->props.power == FB_BLANK_UNBLANK)
  228. level = dev->props.brightness;
  229. else
  230. level = 0;
  231. dev_dbg(&dssdev->dev, "update brightness to %d\n", level);
  232. if (td->use_dsi_bl) {
  233. if (td->enabled) {
  234. dsi_bus_lock();
  235. r = taal_dcs_write_1(DCS_BRIGHTNESS, level);
  236. dsi_bus_unlock();
  237. if (r)
  238. return r;
  239. }
  240. } else {
  241. if (!dssdev->set_backlight)
  242. return -EINVAL;
  243. r = dssdev->set_backlight(dssdev, level);
  244. if (r)
  245. return r;
  246. }
  247. return 0;
  248. }
  249. static int taal_bl_get_intensity(struct backlight_device *dev)
  250. {
  251. if (dev->props.fb_blank == FB_BLANK_UNBLANK &&
  252. dev->props.power == FB_BLANK_UNBLANK)
  253. return dev->props.brightness;
  254. return 0;
  255. }
  256. static struct backlight_ops taal_bl_ops = {
  257. .get_brightness = taal_bl_get_intensity,
  258. .update_status = taal_bl_update_status,
  259. };
  260. static void taal_get_timings(struct omap_dss_device *dssdev,
  261. struct omap_video_timings *timings)
  262. {
  263. *timings = dssdev->panel.timings;
  264. }
  265. static void taal_get_resolution(struct omap_dss_device *dssdev,
  266. u16 *xres, u16 *yres)
  267. {
  268. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  269. if (td->rotate == 0 || td->rotate == 2) {
  270. *xres = dssdev->panel.timings.x_res;
  271. *yres = dssdev->panel.timings.y_res;
  272. } else {
  273. *yres = dssdev->panel.timings.x_res;
  274. *xres = dssdev->panel.timings.y_res;
  275. }
  276. }
  277. static irqreturn_t taal_te_isr(int irq, void *data)
  278. {
  279. struct omap_dss_device *dssdev = data;
  280. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  281. complete_all(&td->te_completion);
  282. return IRQ_HANDLED;
  283. }
  284. static ssize_t taal_num_errors_show(struct device *dev,
  285. struct device_attribute *attr, char *buf)
  286. {
  287. struct omap_dss_device *dssdev = to_dss_device(dev);
  288. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  289. u8 errors;
  290. int r;
  291. if (td->enabled) {
  292. dsi_bus_lock();
  293. r = taal_dcs_read_1(DCS_READ_NUM_ERRORS, &errors);
  294. dsi_bus_unlock();
  295. } else {
  296. r = -ENODEV;
  297. }
  298. if (r)
  299. return r;
  300. return snprintf(buf, PAGE_SIZE, "%d\n", errors);
  301. }
  302. static ssize_t taal_hw_revision_show(struct device *dev,
  303. struct device_attribute *attr, char *buf)
  304. {
  305. struct omap_dss_device *dssdev = to_dss_device(dev);
  306. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  307. u8 id1, id2, id3;
  308. int r;
  309. if (td->enabled) {
  310. dsi_bus_lock();
  311. r = taal_get_id(&id1, &id2, &id3);
  312. dsi_bus_unlock();
  313. } else {
  314. r = -ENODEV;
  315. }
  316. if (r)
  317. return r;
  318. return snprintf(buf, PAGE_SIZE, "%02x.%02x.%02x\n", id1, id2, id3);
  319. }
  320. static const char *cabc_modes[] = {
  321. "off", /* used also always when CABC is not supported */
  322. "ui",
  323. "still-image",
  324. "moving-image",
  325. };
  326. static ssize_t show_cabc_mode(struct device *dev,
  327. struct device_attribute *attr,
  328. char *buf)
  329. {
  330. struct omap_dss_device *dssdev = to_dss_device(dev);
  331. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  332. const char *mode_str;
  333. int mode;
  334. int len;
  335. mode = td->cabc_mode;
  336. mode_str = "unknown";
  337. if (mode >= 0 && mode < ARRAY_SIZE(cabc_modes))
  338. mode_str = cabc_modes[mode];
  339. len = snprintf(buf, PAGE_SIZE, "%s\n", mode_str);
  340. return len < PAGE_SIZE - 1 ? len : PAGE_SIZE - 1;
  341. }
  342. static ssize_t store_cabc_mode(struct device *dev,
  343. struct device_attribute *attr,
  344. const char *buf, size_t count)
  345. {
  346. struct omap_dss_device *dssdev = to_dss_device(dev);
  347. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  348. int i;
  349. for (i = 0; i < ARRAY_SIZE(cabc_modes); i++) {
  350. if (sysfs_streq(cabc_modes[i], buf))
  351. break;
  352. }
  353. if (i == ARRAY_SIZE(cabc_modes))
  354. return -EINVAL;
  355. if (td->enabled) {
  356. dsi_bus_lock();
  357. if (!td->cabc_broken)
  358. taal_dcs_write_1(DCS_WRITE_CABC, i);
  359. dsi_bus_unlock();
  360. }
  361. td->cabc_mode = i;
  362. return count;
  363. }
  364. static ssize_t show_cabc_available_modes(struct device *dev,
  365. struct device_attribute *attr,
  366. char *buf)
  367. {
  368. int len;
  369. int i;
  370. for (i = 0, len = 0;
  371. len < PAGE_SIZE && i < ARRAY_SIZE(cabc_modes); i++)
  372. len += snprintf(&buf[len], PAGE_SIZE - len, "%s%s%s",
  373. i ? " " : "", cabc_modes[i],
  374. i == ARRAY_SIZE(cabc_modes) - 1 ? "\n" : "");
  375. return len < PAGE_SIZE ? len : PAGE_SIZE - 1;
  376. }
  377. static DEVICE_ATTR(num_dsi_errors, S_IRUGO, taal_num_errors_show, NULL);
  378. static DEVICE_ATTR(hw_revision, S_IRUGO, taal_hw_revision_show, NULL);
  379. static DEVICE_ATTR(cabc_mode, S_IRUGO | S_IWUSR,
  380. show_cabc_mode, store_cabc_mode);
  381. static DEVICE_ATTR(cabc_available_modes, S_IRUGO,
  382. show_cabc_available_modes, NULL);
  383. static struct attribute *taal_attrs[] = {
  384. &dev_attr_num_dsi_errors.attr,
  385. &dev_attr_hw_revision.attr,
  386. &dev_attr_cabc_mode.attr,
  387. &dev_attr_cabc_available_modes.attr,
  388. NULL,
  389. };
  390. static struct attribute_group taal_attr_group = {
  391. .attrs = taal_attrs,
  392. };
  393. static int taal_probe(struct omap_dss_device *dssdev)
  394. {
  395. struct backlight_properties props;
  396. struct taal_data *td;
  397. struct backlight_device *bldev;
  398. int r;
  399. const struct omap_video_timings taal_panel_timings = {
  400. .x_res = 864,
  401. .y_res = 480,
  402. };
  403. dev_dbg(&dssdev->dev, "probe\n");
  404. dssdev->panel.config = OMAP_DSS_LCD_TFT;
  405. dssdev->panel.timings = taal_panel_timings;
  406. dssdev->ctrl.pixel_size = 24;
  407. td = kzalloc(sizeof(*td), GFP_KERNEL);
  408. if (!td) {
  409. r = -ENOMEM;
  410. goto err0;
  411. }
  412. td->dssdev = dssdev;
  413. mutex_init(&td->lock);
  414. td->esd_wq = create_singlethread_workqueue("taal_esd");
  415. if (td->esd_wq == NULL) {
  416. dev_err(&dssdev->dev, "can't create ESD workqueue\n");
  417. r = -ENOMEM;
  418. goto err1;
  419. }
  420. INIT_DELAYED_WORK_DEFERRABLE(&td->esd_work, taal_esd_work);
  421. dev_set_drvdata(&dssdev->dev, td);
  422. /* if no platform set_backlight() defined, presume DSI backlight
  423. * control */
  424. memset(&props, 0, sizeof(struct backlight_properties));
  425. if (!dssdev->set_backlight)
  426. td->use_dsi_bl = true;
  427. if (td->use_dsi_bl)
  428. props.max_brightness = 255;
  429. else
  430. props.max_brightness = 127;
  431. bldev = backlight_device_register("taal", &dssdev->dev, dssdev,
  432. &taal_bl_ops, &props);
  433. if (IS_ERR(bldev)) {
  434. r = PTR_ERR(bldev);
  435. goto err2;
  436. }
  437. td->bldev = bldev;
  438. bldev->props.fb_blank = FB_BLANK_UNBLANK;
  439. bldev->props.power = FB_BLANK_UNBLANK;
  440. if (td->use_dsi_bl)
  441. bldev->props.brightness = 255;
  442. else
  443. bldev->props.brightness = 127;
  444. taal_bl_update_status(bldev);
  445. if (dssdev->phy.dsi.ext_te) {
  446. int gpio = dssdev->phy.dsi.ext_te_gpio;
  447. r = gpio_request(gpio, "taal irq");
  448. if (r) {
  449. dev_err(&dssdev->dev, "GPIO request failed\n");
  450. goto err3;
  451. }
  452. gpio_direction_input(gpio);
  453. r = request_irq(gpio_to_irq(gpio), taal_te_isr,
  454. IRQF_DISABLED | IRQF_TRIGGER_RISING,
  455. "taal vsync", dssdev);
  456. if (r) {
  457. dev_err(&dssdev->dev, "IRQ request failed\n");
  458. gpio_free(gpio);
  459. goto err3;
  460. }
  461. init_completion(&td->te_completion);
  462. td->use_ext_te = true;
  463. }
  464. r = sysfs_create_group(&dssdev->dev.kobj, &taal_attr_group);
  465. if (r) {
  466. dev_err(&dssdev->dev, "failed to create sysfs files\n");
  467. goto err4;
  468. }
  469. return 0;
  470. err4:
  471. if (td->use_ext_te) {
  472. int gpio = dssdev->phy.dsi.ext_te_gpio;
  473. free_irq(gpio_to_irq(gpio), dssdev);
  474. gpio_free(gpio);
  475. }
  476. err3:
  477. backlight_device_unregister(bldev);
  478. err2:
  479. cancel_delayed_work_sync(&td->esd_work);
  480. destroy_workqueue(td->esd_wq);
  481. err1:
  482. kfree(td);
  483. err0:
  484. return r;
  485. }
  486. static void taal_remove(struct omap_dss_device *dssdev)
  487. {
  488. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  489. struct backlight_device *bldev;
  490. dev_dbg(&dssdev->dev, "remove\n");
  491. sysfs_remove_group(&dssdev->dev.kobj, &taal_attr_group);
  492. if (td->use_ext_te) {
  493. int gpio = dssdev->phy.dsi.ext_te_gpio;
  494. free_irq(gpio_to_irq(gpio), dssdev);
  495. gpio_free(gpio);
  496. }
  497. bldev = td->bldev;
  498. bldev->props.power = FB_BLANK_POWERDOWN;
  499. taal_bl_update_status(bldev);
  500. backlight_device_unregister(bldev);
  501. cancel_delayed_work_sync(&td->esd_work);
  502. destroy_workqueue(td->esd_wq);
  503. kfree(td);
  504. }
  505. static int taal_power_on(struct omap_dss_device *dssdev)
  506. {
  507. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  508. u8 id1, id2, id3;
  509. int r;
  510. if (dssdev->platform_enable) {
  511. r = dssdev->platform_enable(dssdev);
  512. if (r)
  513. return r;
  514. }
  515. /* it seems we have to wait a bit until taal is ready */
  516. msleep(5);
  517. dsi_bus_lock();
  518. r = omapdss_dsi_display_enable(dssdev);
  519. if (r) {
  520. dev_err(&dssdev->dev, "failed to enable DSI\n");
  521. goto err0;
  522. }
  523. omapdss_dsi_vc_enable_hs(TCH, false);
  524. r = taal_sleep_out(td);
  525. if (r)
  526. goto err;
  527. r = taal_get_id(&id1, &id2, &id3);
  528. if (r)
  529. goto err;
  530. /* on early revisions CABC is broken */
  531. if (id2 == 0x00 || id2 == 0xff || id2 == 0x81)
  532. td->cabc_broken = true;
  533. taal_dcs_write_1(DCS_BRIGHTNESS, 0xff);
  534. taal_dcs_write_1(DCS_CTRL_DISPLAY, (1<<2) | (1<<5)); /* BL | BCTRL */
  535. taal_dcs_write_1(DCS_PIXEL_FORMAT, 0x7); /* 24bit/pixel */
  536. taal_set_addr_mode(td->rotate, td->mirror);
  537. if (!td->cabc_broken)
  538. taal_dcs_write_1(DCS_WRITE_CABC, td->cabc_mode);
  539. taal_dcs_write_0(DCS_DISPLAY_ON);
  540. r = _taal_enable_te(dssdev, td->te_enabled);
  541. if (r)
  542. goto err;
  543. #ifdef TAAL_USE_ESD_CHECK
  544. queue_delayed_work(td->esd_wq, &td->esd_work, TAAL_ESD_CHECK_PERIOD);
  545. #endif
  546. td->enabled = 1;
  547. if (!td->intro_printed) {
  548. dev_info(&dssdev->dev, "revision %02x.%02x.%02x\n",
  549. id1, id2, id3);
  550. if (td->cabc_broken)
  551. dev_info(&dssdev->dev,
  552. "old Taal version, CABC disabled\n");
  553. td->intro_printed = true;
  554. }
  555. omapdss_dsi_vc_enable_hs(TCH, true);
  556. dsi_bus_unlock();
  557. return 0;
  558. err:
  559. omapdss_dsi_display_disable(dssdev);
  560. err0:
  561. dsi_bus_unlock();
  562. if (dssdev->platform_disable)
  563. dssdev->platform_disable(dssdev);
  564. return r;
  565. }
  566. static void taal_power_off(struct omap_dss_device *dssdev)
  567. {
  568. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  569. dsi_bus_lock();
  570. cancel_delayed_work(&td->esd_work);
  571. taal_dcs_write_0(DCS_DISPLAY_OFF);
  572. taal_sleep_in(td);
  573. /* wait a bit so that the message goes through */
  574. msleep(10);
  575. omapdss_dsi_display_disable(dssdev);
  576. if (dssdev->platform_disable)
  577. dssdev->platform_disable(dssdev);
  578. td->enabled = 0;
  579. dsi_bus_unlock();
  580. }
  581. static int taal_enable(struct omap_dss_device *dssdev)
  582. {
  583. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  584. int r;
  585. dev_dbg(&dssdev->dev, "enable\n");
  586. mutex_lock(&td->lock);
  587. if (dssdev->state != OMAP_DSS_DISPLAY_DISABLED) {
  588. r = -EINVAL;
  589. goto err;
  590. }
  591. r = taal_power_on(dssdev);
  592. if (r)
  593. goto err;
  594. dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
  595. mutex_unlock(&td->lock);
  596. return 0;
  597. err:
  598. dev_dbg(&dssdev->dev, "enable failed\n");
  599. mutex_unlock(&td->lock);
  600. return r;
  601. }
  602. static void taal_disable(struct omap_dss_device *dssdev)
  603. {
  604. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  605. dev_dbg(&dssdev->dev, "disable\n");
  606. mutex_lock(&td->lock);
  607. if (dssdev->state == OMAP_DSS_DISPLAY_ACTIVE)
  608. taal_power_off(dssdev);
  609. dssdev->state = OMAP_DSS_DISPLAY_DISABLED;
  610. mutex_unlock(&td->lock);
  611. }
  612. static int taal_suspend(struct omap_dss_device *dssdev)
  613. {
  614. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  615. int r;
  616. dev_dbg(&dssdev->dev, "suspend\n");
  617. mutex_lock(&td->lock);
  618. if (dssdev->state != OMAP_DSS_DISPLAY_ACTIVE) {
  619. r = -EINVAL;
  620. goto err;
  621. }
  622. taal_power_off(dssdev);
  623. dssdev->state = OMAP_DSS_DISPLAY_SUSPENDED;
  624. mutex_unlock(&td->lock);
  625. return 0;
  626. err:
  627. mutex_unlock(&td->lock);
  628. return r;
  629. }
  630. static int taal_resume(struct omap_dss_device *dssdev)
  631. {
  632. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  633. int r;
  634. dev_dbg(&dssdev->dev, "resume\n");
  635. mutex_lock(&td->lock);
  636. if (dssdev->state != OMAP_DSS_DISPLAY_SUSPENDED) {
  637. r = -EINVAL;
  638. goto err;
  639. }
  640. r = taal_power_on(dssdev);
  641. dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
  642. mutex_unlock(&td->lock);
  643. return r;
  644. err:
  645. mutex_unlock(&td->lock);
  646. return r;
  647. }
  648. static void taal_framedone_cb(int err, void *data)
  649. {
  650. struct omap_dss_device *dssdev = data;
  651. dev_dbg(&dssdev->dev, "framedone, err %d\n", err);
  652. dsi_bus_unlock();
  653. }
  654. static int taal_update(struct omap_dss_device *dssdev,
  655. u16 x, u16 y, u16 w, u16 h)
  656. {
  657. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  658. int r;
  659. dev_dbg(&dssdev->dev, "update %d, %d, %d x %d\n", x, y, w, h);
  660. mutex_lock(&td->lock);
  661. dsi_bus_lock();
  662. if (!td->enabled) {
  663. r = 0;
  664. goto err;
  665. }
  666. r = omap_dsi_prepare_update(dssdev, &x, &y, &w, &h);
  667. if (r)
  668. goto err;
  669. r = taal_set_update_window(x, y, w, h);
  670. if (r)
  671. goto err;
  672. r = omap_dsi_update(dssdev, TCH, x, y, w, h,
  673. taal_framedone_cb, dssdev);
  674. if (r)
  675. goto err;
  676. /* note: no bus_unlock here. unlock is in framedone_cb */
  677. mutex_unlock(&td->lock);
  678. return 0;
  679. err:
  680. dsi_bus_unlock();
  681. mutex_unlock(&td->lock);
  682. return r;
  683. }
  684. static int taal_sync(struct omap_dss_device *dssdev)
  685. {
  686. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  687. dev_dbg(&dssdev->dev, "sync\n");
  688. mutex_lock(&td->lock);
  689. dsi_bus_lock();
  690. dsi_bus_unlock();
  691. mutex_unlock(&td->lock);
  692. dev_dbg(&dssdev->dev, "sync done\n");
  693. return 0;
  694. }
  695. static int _taal_enable_te(struct omap_dss_device *dssdev, bool enable)
  696. {
  697. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  698. int r;
  699. td->te_enabled = enable;
  700. if (enable)
  701. r = taal_dcs_write_1(DCS_TEAR_ON, 0);
  702. else
  703. r = taal_dcs_write_0(DCS_TEAR_OFF);
  704. omapdss_dsi_enable_te(dssdev, enable);
  705. /* XXX for some reason, DSI TE breaks if we don't wait here.
  706. * Panel bug? Needs more studying */
  707. msleep(100);
  708. return r;
  709. }
  710. static int taal_enable_te(struct omap_dss_device *dssdev, bool enable)
  711. {
  712. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  713. int r;
  714. mutex_lock(&td->lock);
  715. dsi_bus_lock();
  716. r = _taal_enable_te(dssdev, enable);
  717. dsi_bus_unlock();
  718. mutex_unlock(&td->lock);
  719. return r;
  720. }
  721. static int taal_get_te(struct omap_dss_device *dssdev)
  722. {
  723. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  724. int r;
  725. mutex_lock(&td->lock);
  726. r = td->te_enabled;
  727. mutex_unlock(&td->lock);
  728. return r;
  729. }
  730. static int taal_rotate(struct omap_dss_device *dssdev, u8 rotate)
  731. {
  732. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  733. int r;
  734. dev_dbg(&dssdev->dev, "rotate %d\n", rotate);
  735. mutex_lock(&td->lock);
  736. dsi_bus_lock();
  737. if (td->enabled) {
  738. r = taal_set_addr_mode(rotate, td->mirror);
  739. if (r)
  740. goto err;
  741. }
  742. td->rotate = rotate;
  743. dsi_bus_unlock();
  744. mutex_unlock(&td->lock);
  745. return 0;
  746. err:
  747. dsi_bus_unlock();
  748. mutex_unlock(&td->lock);
  749. return r;
  750. }
  751. static u8 taal_get_rotate(struct omap_dss_device *dssdev)
  752. {
  753. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  754. int r;
  755. mutex_lock(&td->lock);
  756. r = td->rotate;
  757. mutex_unlock(&td->lock);
  758. return r;
  759. }
  760. static int taal_mirror(struct omap_dss_device *dssdev, bool enable)
  761. {
  762. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  763. int r;
  764. dev_dbg(&dssdev->dev, "mirror %d\n", enable);
  765. mutex_lock(&td->lock);
  766. dsi_bus_lock();
  767. if (td->enabled) {
  768. r = taal_set_addr_mode(td->rotate, enable);
  769. if (r)
  770. goto err;
  771. }
  772. td->mirror = enable;
  773. dsi_bus_unlock();
  774. mutex_unlock(&td->lock);
  775. return 0;
  776. err:
  777. dsi_bus_unlock();
  778. mutex_unlock(&td->lock);
  779. return r;
  780. }
  781. static bool taal_get_mirror(struct omap_dss_device *dssdev)
  782. {
  783. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  784. int r;
  785. mutex_lock(&td->lock);
  786. r = td->mirror;
  787. mutex_unlock(&td->lock);
  788. return r;
  789. }
  790. static int taal_run_test(struct omap_dss_device *dssdev, int test_num)
  791. {
  792. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  793. u8 id1, id2, id3;
  794. int r;
  795. mutex_lock(&td->lock);
  796. dsi_bus_lock();
  797. r = taal_dcs_read_1(DCS_GET_ID1, &id1);
  798. if (r)
  799. goto err;
  800. r = taal_dcs_read_1(DCS_GET_ID2, &id2);
  801. if (r)
  802. goto err;
  803. r = taal_dcs_read_1(DCS_GET_ID3, &id3);
  804. if (r)
  805. goto err;
  806. dsi_bus_unlock();
  807. mutex_unlock(&td->lock);
  808. return 0;
  809. err:
  810. dsi_bus_unlock();
  811. mutex_unlock(&td->lock);
  812. return r;
  813. }
  814. static int taal_memory_read(struct omap_dss_device *dssdev,
  815. void *buf, size_t size,
  816. u16 x, u16 y, u16 w, u16 h)
  817. {
  818. int r;
  819. int first = 1;
  820. int plen;
  821. unsigned buf_used = 0;
  822. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  823. if (size < w * h * 3)
  824. return -ENOMEM;
  825. mutex_lock(&td->lock);
  826. if (!td->enabled) {
  827. r = -ENODEV;
  828. goto err1;
  829. }
  830. size = min(w * h * 3,
  831. dssdev->panel.timings.x_res *
  832. dssdev->panel.timings.y_res * 3);
  833. dsi_bus_lock();
  834. /* plen 1 or 2 goes into short packet. until checksum error is fixed,
  835. * use short packets. plen 32 works, but bigger packets seem to cause
  836. * an error. */
  837. if (size % 2)
  838. plen = 1;
  839. else
  840. plen = 2;
  841. taal_set_update_window(x, y, w, h);
  842. r = dsi_vc_set_max_rx_packet_size(TCH, plen);
  843. if (r)
  844. goto err2;
  845. while (buf_used < size) {
  846. u8 dcs_cmd = first ? 0x2e : 0x3e;
  847. first = 0;
  848. r = dsi_vc_dcs_read(TCH, dcs_cmd,
  849. buf + buf_used, size - buf_used);
  850. if (r < 0) {
  851. dev_err(&dssdev->dev, "read error\n");
  852. goto err3;
  853. }
  854. buf_used += r;
  855. if (r < plen) {
  856. dev_err(&dssdev->dev, "short read\n");
  857. break;
  858. }
  859. if (signal_pending(current)) {
  860. dev_err(&dssdev->dev, "signal pending, "
  861. "aborting memory read\n");
  862. r = -ERESTARTSYS;
  863. goto err3;
  864. }
  865. }
  866. r = buf_used;
  867. err3:
  868. dsi_vc_set_max_rx_packet_size(TCH, 1);
  869. err2:
  870. dsi_bus_unlock();
  871. err1:
  872. mutex_unlock(&td->lock);
  873. return r;
  874. }
  875. static void taal_esd_work(struct work_struct *work)
  876. {
  877. struct taal_data *td = container_of(work, struct taal_data,
  878. esd_work.work);
  879. struct omap_dss_device *dssdev = td->dssdev;
  880. u8 state1, state2;
  881. int r;
  882. mutex_lock(&td->lock);
  883. if (!td->enabled) {
  884. mutex_unlock(&td->lock);
  885. return;
  886. }
  887. dsi_bus_lock();
  888. r = taal_dcs_read_1(DCS_RDDSDR, &state1);
  889. if (r) {
  890. dev_err(&dssdev->dev, "failed to read Taal status\n");
  891. goto err;
  892. }
  893. /* Run self diagnostics */
  894. r = taal_sleep_out(td);
  895. if (r) {
  896. dev_err(&dssdev->dev, "failed to run Taal self-diagnostics\n");
  897. goto err;
  898. }
  899. r = taal_dcs_read_1(DCS_RDDSDR, &state2);
  900. if (r) {
  901. dev_err(&dssdev->dev, "failed to read Taal status\n");
  902. goto err;
  903. }
  904. /* Each sleep out command will trigger a self diagnostic and flip
  905. * Bit6 if the test passes.
  906. */
  907. if (!((state1 ^ state2) & (1 << 6))) {
  908. dev_err(&dssdev->dev, "LCD self diagnostics failed\n");
  909. goto err;
  910. }
  911. /* Self-diagnostics result is also shown on TE GPIO line. We need
  912. * to re-enable TE after self diagnostics */
  913. if (td->use_ext_te && td->te_enabled) {
  914. r = taal_dcs_write_1(DCS_TEAR_ON, 0);
  915. if (r)
  916. goto err;
  917. }
  918. dsi_bus_unlock();
  919. queue_delayed_work(td->esd_wq, &td->esd_work, TAAL_ESD_CHECK_PERIOD);
  920. mutex_unlock(&td->lock);
  921. return;
  922. err:
  923. dev_err(&dssdev->dev, "performing LCD reset\n");
  924. taal_power_off(dssdev);
  925. taal_power_on(dssdev);
  926. dsi_bus_unlock();
  927. queue_delayed_work(td->esd_wq, &td->esd_work, TAAL_ESD_CHECK_PERIOD);
  928. mutex_unlock(&td->lock);
  929. }
  930. static int taal_set_update_mode(struct omap_dss_device *dssdev,
  931. enum omap_dss_update_mode mode)
  932. {
  933. if (mode != OMAP_DSS_UPDATE_MANUAL)
  934. return -EINVAL;
  935. return 0;
  936. }
  937. static enum omap_dss_update_mode taal_get_update_mode(
  938. struct omap_dss_device *dssdev)
  939. {
  940. return OMAP_DSS_UPDATE_MANUAL;
  941. }
  942. static struct omap_dss_driver taal_driver = {
  943. .probe = taal_probe,
  944. .remove = taal_remove,
  945. .enable = taal_enable,
  946. .disable = taal_disable,
  947. .suspend = taal_suspend,
  948. .resume = taal_resume,
  949. .set_update_mode = taal_set_update_mode,
  950. .get_update_mode = taal_get_update_mode,
  951. .update = taal_update,
  952. .sync = taal_sync,
  953. .get_resolution = taal_get_resolution,
  954. .get_recommended_bpp = omapdss_default_get_recommended_bpp,
  955. .enable_te = taal_enable_te,
  956. .get_te = taal_get_te,
  957. .set_rotate = taal_rotate,
  958. .get_rotate = taal_get_rotate,
  959. .set_mirror = taal_mirror,
  960. .get_mirror = taal_get_mirror,
  961. .run_test = taal_run_test,
  962. .memory_read = taal_memory_read,
  963. .get_timings = taal_get_timings,
  964. .driver = {
  965. .name = "taal",
  966. .owner = THIS_MODULE,
  967. },
  968. };
  969. static int __init taal_init(void)
  970. {
  971. omap_dss_register_driver(&taal_driver);
  972. return 0;
  973. }
  974. static void __exit taal_exit(void)
  975. {
  976. omap_dss_unregister_driver(&taal_driver);
  977. }
  978. module_init(taal_init);
  979. module_exit(taal_exit);
  980. MODULE_AUTHOR("Tomi Valkeinen <tomi.valkeinen@nokia.com>");
  981. MODULE_DESCRIPTION("Taal Driver");
  982. MODULE_LICENSE("GPL");