panel-taal.c 23 KB

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