panel-taal.c 21 KB

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