panel-taal.c 25 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301
  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. mutex_lock(&td->lock);
  233. if (td->use_dsi_bl) {
  234. if (td->enabled) {
  235. dsi_bus_lock();
  236. r = taal_dcs_write_1(DCS_BRIGHTNESS, level);
  237. dsi_bus_unlock();
  238. } else {
  239. r = 0;
  240. }
  241. } else {
  242. if (!dssdev->set_backlight)
  243. r = -EINVAL;
  244. else
  245. r = dssdev->set_backlight(dssdev, level);
  246. }
  247. mutex_unlock(&td->lock);
  248. return r;
  249. }
  250. static int taal_bl_get_intensity(struct backlight_device *dev)
  251. {
  252. if (dev->props.fb_blank == FB_BLANK_UNBLANK &&
  253. dev->props.power == FB_BLANK_UNBLANK)
  254. return dev->props.brightness;
  255. return 0;
  256. }
  257. static struct backlight_ops taal_bl_ops = {
  258. .get_brightness = taal_bl_get_intensity,
  259. .update_status = taal_bl_update_status,
  260. };
  261. static void taal_get_timings(struct omap_dss_device *dssdev,
  262. struct omap_video_timings *timings)
  263. {
  264. *timings = dssdev->panel.timings;
  265. }
  266. static void taal_get_resolution(struct omap_dss_device *dssdev,
  267. u16 *xres, u16 *yres)
  268. {
  269. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  270. if (td->rotate == 0 || td->rotate == 2) {
  271. *xres = dssdev->panel.timings.x_res;
  272. *yres = dssdev->panel.timings.y_res;
  273. } else {
  274. *yres = dssdev->panel.timings.x_res;
  275. *xres = dssdev->panel.timings.y_res;
  276. }
  277. }
  278. static irqreturn_t taal_te_isr(int irq, void *data)
  279. {
  280. struct omap_dss_device *dssdev = data;
  281. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  282. complete_all(&td->te_completion);
  283. return IRQ_HANDLED;
  284. }
  285. static ssize_t taal_num_errors_show(struct device *dev,
  286. struct device_attribute *attr, char *buf)
  287. {
  288. struct omap_dss_device *dssdev = to_dss_device(dev);
  289. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  290. u8 errors;
  291. int r;
  292. mutex_lock(&td->lock);
  293. if (td->enabled) {
  294. dsi_bus_lock();
  295. r = taal_dcs_read_1(DCS_READ_NUM_ERRORS, &errors);
  296. dsi_bus_unlock();
  297. } else {
  298. r = -ENODEV;
  299. }
  300. mutex_unlock(&td->lock);
  301. if (r)
  302. return r;
  303. return snprintf(buf, PAGE_SIZE, "%d\n", errors);
  304. }
  305. static ssize_t taal_hw_revision_show(struct device *dev,
  306. struct device_attribute *attr, char *buf)
  307. {
  308. struct omap_dss_device *dssdev = to_dss_device(dev);
  309. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  310. u8 id1, id2, id3;
  311. int r;
  312. mutex_lock(&td->lock);
  313. if (td->enabled) {
  314. dsi_bus_lock();
  315. r = taal_get_id(&id1, &id2, &id3);
  316. dsi_bus_unlock();
  317. } else {
  318. r = -ENODEV;
  319. }
  320. mutex_unlock(&td->lock);
  321. if (r)
  322. return r;
  323. return snprintf(buf, PAGE_SIZE, "%02x.%02x.%02x\n", id1, id2, id3);
  324. }
  325. static const char *cabc_modes[] = {
  326. "off", /* used also always when CABC is not supported */
  327. "ui",
  328. "still-image",
  329. "moving-image",
  330. };
  331. static ssize_t show_cabc_mode(struct device *dev,
  332. struct device_attribute *attr,
  333. char *buf)
  334. {
  335. struct omap_dss_device *dssdev = to_dss_device(dev);
  336. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  337. const char *mode_str;
  338. int mode;
  339. int len;
  340. mode = td->cabc_mode;
  341. mode_str = "unknown";
  342. if (mode >= 0 && mode < ARRAY_SIZE(cabc_modes))
  343. mode_str = cabc_modes[mode];
  344. len = snprintf(buf, PAGE_SIZE, "%s\n", mode_str);
  345. return len < PAGE_SIZE - 1 ? len : PAGE_SIZE - 1;
  346. }
  347. static ssize_t store_cabc_mode(struct device *dev,
  348. struct device_attribute *attr,
  349. const char *buf, size_t count)
  350. {
  351. struct omap_dss_device *dssdev = to_dss_device(dev);
  352. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  353. int i;
  354. for (i = 0; i < ARRAY_SIZE(cabc_modes); i++) {
  355. if (sysfs_streq(cabc_modes[i], buf))
  356. break;
  357. }
  358. if (i == ARRAY_SIZE(cabc_modes))
  359. return -EINVAL;
  360. mutex_lock(&td->lock);
  361. if (td->enabled) {
  362. dsi_bus_lock();
  363. if (!td->cabc_broken)
  364. taal_dcs_write_1(DCS_WRITE_CABC, i);
  365. dsi_bus_unlock();
  366. }
  367. td->cabc_mode = i;
  368. mutex_unlock(&td->lock);
  369. return count;
  370. }
  371. static ssize_t show_cabc_available_modes(struct device *dev,
  372. struct device_attribute *attr,
  373. char *buf)
  374. {
  375. int len;
  376. int i;
  377. for (i = 0, len = 0;
  378. len < PAGE_SIZE && i < ARRAY_SIZE(cabc_modes); i++)
  379. len += snprintf(&buf[len], PAGE_SIZE - len, "%s%s%s",
  380. i ? " " : "", cabc_modes[i],
  381. i == ARRAY_SIZE(cabc_modes) - 1 ? "\n" : "");
  382. return len < PAGE_SIZE ? len : PAGE_SIZE - 1;
  383. }
  384. static DEVICE_ATTR(num_dsi_errors, S_IRUGO, taal_num_errors_show, NULL);
  385. static DEVICE_ATTR(hw_revision, S_IRUGO, taal_hw_revision_show, NULL);
  386. static DEVICE_ATTR(cabc_mode, S_IRUGO | S_IWUSR,
  387. show_cabc_mode, store_cabc_mode);
  388. static DEVICE_ATTR(cabc_available_modes, S_IRUGO,
  389. show_cabc_available_modes, NULL);
  390. static struct attribute *taal_attrs[] = {
  391. &dev_attr_num_dsi_errors.attr,
  392. &dev_attr_hw_revision.attr,
  393. &dev_attr_cabc_mode.attr,
  394. &dev_attr_cabc_available_modes.attr,
  395. NULL,
  396. };
  397. static struct attribute_group taal_attr_group = {
  398. .attrs = taal_attrs,
  399. };
  400. static void taal_hw_reset(struct omap_dss_device *dssdev)
  401. {
  402. if (dssdev->reset_gpio == -1)
  403. return;
  404. gpio_set_value(dssdev->reset_gpio, 1);
  405. udelay(10);
  406. /* reset the panel */
  407. gpio_set_value(dssdev->reset_gpio, 0);
  408. /* assert reset for at least 10us */
  409. udelay(10);
  410. gpio_set_value(dssdev->reset_gpio, 1);
  411. /* wait 5ms after releasing reset */
  412. msleep(5);
  413. }
  414. static int taal_probe(struct omap_dss_device *dssdev)
  415. {
  416. struct backlight_properties props;
  417. struct taal_data *td;
  418. struct backlight_device *bldev;
  419. int r;
  420. const struct omap_video_timings taal_panel_timings = {
  421. .x_res = 864,
  422. .y_res = 480,
  423. };
  424. dev_dbg(&dssdev->dev, "probe\n");
  425. dssdev->panel.config = OMAP_DSS_LCD_TFT;
  426. dssdev->panel.timings = taal_panel_timings;
  427. dssdev->ctrl.pixel_size = 24;
  428. td = kzalloc(sizeof(*td), GFP_KERNEL);
  429. if (!td) {
  430. r = -ENOMEM;
  431. goto err0;
  432. }
  433. td->dssdev = dssdev;
  434. mutex_init(&td->lock);
  435. td->esd_wq = create_singlethread_workqueue("taal_esd");
  436. if (td->esd_wq == NULL) {
  437. dev_err(&dssdev->dev, "can't create ESD workqueue\n");
  438. r = -ENOMEM;
  439. goto err1;
  440. }
  441. INIT_DELAYED_WORK_DEFERRABLE(&td->esd_work, taal_esd_work);
  442. dev_set_drvdata(&dssdev->dev, td);
  443. taal_hw_reset(dssdev);
  444. /* if no platform set_backlight() defined, presume DSI backlight
  445. * control */
  446. memset(&props, 0, sizeof(struct backlight_properties));
  447. if (!dssdev->set_backlight)
  448. td->use_dsi_bl = true;
  449. if (td->use_dsi_bl)
  450. props.max_brightness = 255;
  451. else
  452. props.max_brightness = 127;
  453. bldev = backlight_device_register("taal", &dssdev->dev, dssdev,
  454. &taal_bl_ops, &props);
  455. if (IS_ERR(bldev)) {
  456. r = PTR_ERR(bldev);
  457. goto err2;
  458. }
  459. td->bldev = bldev;
  460. bldev->props.fb_blank = FB_BLANK_UNBLANK;
  461. bldev->props.power = FB_BLANK_UNBLANK;
  462. if (td->use_dsi_bl)
  463. bldev->props.brightness = 255;
  464. else
  465. bldev->props.brightness = 127;
  466. taal_bl_update_status(bldev);
  467. if (dssdev->phy.dsi.ext_te) {
  468. int gpio = dssdev->phy.dsi.ext_te_gpio;
  469. r = gpio_request(gpio, "taal irq");
  470. if (r) {
  471. dev_err(&dssdev->dev, "GPIO request failed\n");
  472. goto err3;
  473. }
  474. gpio_direction_input(gpio);
  475. r = request_irq(gpio_to_irq(gpio), taal_te_isr,
  476. IRQF_DISABLED | IRQF_TRIGGER_RISING,
  477. "taal vsync", dssdev);
  478. if (r) {
  479. dev_err(&dssdev->dev, "IRQ request failed\n");
  480. gpio_free(gpio);
  481. goto err4;
  482. }
  483. init_completion(&td->te_completion);
  484. td->use_ext_te = true;
  485. }
  486. r = sysfs_create_group(&dssdev->dev.kobj, &taal_attr_group);
  487. if (r) {
  488. dev_err(&dssdev->dev, "failed to create sysfs files\n");
  489. goto err5;
  490. }
  491. return 0;
  492. err5:
  493. if (td->use_ext_te)
  494. free_irq(gpio_to_irq(dssdev->phy.dsi.ext_te_gpio), dssdev);
  495. err4:
  496. if (td->use_ext_te)
  497. gpio_free(dssdev->phy.dsi.ext_te_gpio);
  498. err3:
  499. backlight_device_unregister(bldev);
  500. err2:
  501. destroy_workqueue(td->esd_wq);
  502. err1:
  503. kfree(td);
  504. err0:
  505. return r;
  506. }
  507. static void taal_remove(struct omap_dss_device *dssdev)
  508. {
  509. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  510. struct backlight_device *bldev;
  511. dev_dbg(&dssdev->dev, "remove\n");
  512. sysfs_remove_group(&dssdev->dev.kobj, &taal_attr_group);
  513. if (td->use_ext_te) {
  514. int gpio = dssdev->phy.dsi.ext_te_gpio;
  515. free_irq(gpio_to_irq(gpio), dssdev);
  516. gpio_free(gpio);
  517. }
  518. bldev = td->bldev;
  519. bldev->props.power = FB_BLANK_POWERDOWN;
  520. taal_bl_update_status(bldev);
  521. backlight_device_unregister(bldev);
  522. cancel_delayed_work_sync(&td->esd_work);
  523. destroy_workqueue(td->esd_wq);
  524. /* reset, to be sure that the panel is in a valid state */
  525. taal_hw_reset(dssdev);
  526. kfree(td);
  527. }
  528. static int taal_power_on(struct omap_dss_device *dssdev)
  529. {
  530. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  531. u8 id1, id2, id3;
  532. int r;
  533. /* it seems we have to wait a bit until taal is ready */
  534. msleep(5);
  535. dsi_bus_lock();
  536. r = omapdss_dsi_display_enable(dssdev);
  537. if (r) {
  538. dev_err(&dssdev->dev, "failed to enable DSI\n");
  539. goto err0;
  540. }
  541. taal_hw_reset(dssdev);
  542. omapdss_dsi_vc_enable_hs(TCH, false);
  543. r = taal_sleep_out(td);
  544. if (r)
  545. goto err;
  546. r = taal_get_id(&id1, &id2, &id3);
  547. if (r)
  548. goto err;
  549. /* on early revisions CABC is broken */
  550. if (id2 == 0x00 || id2 == 0xff || id2 == 0x81)
  551. td->cabc_broken = true;
  552. taal_dcs_write_1(DCS_BRIGHTNESS, 0xff);
  553. taal_dcs_write_1(DCS_CTRL_DISPLAY, (1<<2) | (1<<5)); /* BL | BCTRL */
  554. taal_dcs_write_1(DCS_PIXEL_FORMAT, 0x7); /* 24bit/pixel */
  555. taal_set_addr_mode(td->rotate, td->mirror);
  556. if (!td->cabc_broken)
  557. taal_dcs_write_1(DCS_WRITE_CABC, td->cabc_mode);
  558. taal_dcs_write_0(DCS_DISPLAY_ON);
  559. r = _taal_enable_te(dssdev, td->te_enabled);
  560. if (r)
  561. goto err;
  562. #ifdef TAAL_USE_ESD_CHECK
  563. queue_delayed_work(td->esd_wq, &td->esd_work, TAAL_ESD_CHECK_PERIOD);
  564. #endif
  565. td->enabled = 1;
  566. if (!td->intro_printed) {
  567. dev_info(&dssdev->dev, "revision %02x.%02x.%02x\n",
  568. id1, id2, id3);
  569. if (td->cabc_broken)
  570. dev_info(&dssdev->dev,
  571. "old Taal version, CABC disabled\n");
  572. td->intro_printed = true;
  573. }
  574. omapdss_dsi_vc_enable_hs(TCH, true);
  575. dsi_bus_unlock();
  576. return 0;
  577. err:
  578. dev_err(&dssdev->dev, "error while enabling panel, issuing HW reset\n");
  579. taal_hw_reset(dssdev);
  580. omapdss_dsi_display_disable(dssdev);
  581. err0:
  582. dsi_bus_unlock();
  583. return r;
  584. }
  585. static void taal_power_off(struct omap_dss_device *dssdev)
  586. {
  587. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  588. int r;
  589. dsi_bus_lock();
  590. cancel_delayed_work(&td->esd_work);
  591. r = taal_dcs_write_0(DCS_DISPLAY_OFF);
  592. if (!r) {
  593. r = taal_sleep_in(td);
  594. /* wait a bit so that the message goes through */
  595. msleep(10);
  596. }
  597. if (r) {
  598. dev_err(&dssdev->dev,
  599. "error disabling panel, issuing HW reset\n");
  600. taal_hw_reset(dssdev);
  601. }
  602. omapdss_dsi_display_disable(dssdev);
  603. td->enabled = 0;
  604. dsi_bus_unlock();
  605. }
  606. static int taal_enable(struct omap_dss_device *dssdev)
  607. {
  608. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  609. int r;
  610. dev_dbg(&dssdev->dev, "enable\n");
  611. mutex_lock(&td->lock);
  612. if (dssdev->state != OMAP_DSS_DISPLAY_DISABLED) {
  613. r = -EINVAL;
  614. goto err;
  615. }
  616. r = taal_power_on(dssdev);
  617. if (r)
  618. goto err;
  619. dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
  620. mutex_unlock(&td->lock);
  621. return 0;
  622. err:
  623. dev_dbg(&dssdev->dev, "enable failed\n");
  624. mutex_unlock(&td->lock);
  625. return r;
  626. }
  627. static void taal_disable(struct omap_dss_device *dssdev)
  628. {
  629. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  630. dev_dbg(&dssdev->dev, "disable\n");
  631. mutex_lock(&td->lock);
  632. if (dssdev->state == OMAP_DSS_DISPLAY_ACTIVE)
  633. taal_power_off(dssdev);
  634. dssdev->state = OMAP_DSS_DISPLAY_DISABLED;
  635. mutex_unlock(&td->lock);
  636. }
  637. static int taal_suspend(struct omap_dss_device *dssdev)
  638. {
  639. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  640. int r;
  641. dev_dbg(&dssdev->dev, "suspend\n");
  642. mutex_lock(&td->lock);
  643. if (dssdev->state != OMAP_DSS_DISPLAY_ACTIVE) {
  644. r = -EINVAL;
  645. goto err;
  646. }
  647. taal_power_off(dssdev);
  648. dssdev->state = OMAP_DSS_DISPLAY_SUSPENDED;
  649. mutex_unlock(&td->lock);
  650. return 0;
  651. err:
  652. mutex_unlock(&td->lock);
  653. return r;
  654. }
  655. static int taal_resume(struct omap_dss_device *dssdev)
  656. {
  657. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  658. int r;
  659. dev_dbg(&dssdev->dev, "resume\n");
  660. mutex_lock(&td->lock);
  661. if (dssdev->state != OMAP_DSS_DISPLAY_SUSPENDED) {
  662. r = -EINVAL;
  663. goto err;
  664. }
  665. r = taal_power_on(dssdev);
  666. dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
  667. mutex_unlock(&td->lock);
  668. return r;
  669. err:
  670. mutex_unlock(&td->lock);
  671. return r;
  672. }
  673. static void taal_framedone_cb(int err, void *data)
  674. {
  675. struct omap_dss_device *dssdev = data;
  676. dev_dbg(&dssdev->dev, "framedone, err %d\n", err);
  677. dsi_bus_unlock();
  678. }
  679. static int taal_update(struct omap_dss_device *dssdev,
  680. u16 x, u16 y, u16 w, u16 h)
  681. {
  682. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  683. int r;
  684. dev_dbg(&dssdev->dev, "update %d, %d, %d x %d\n", x, y, w, h);
  685. mutex_lock(&td->lock);
  686. dsi_bus_lock();
  687. if (!td->enabled) {
  688. r = 0;
  689. goto err;
  690. }
  691. r = omap_dsi_prepare_update(dssdev, &x, &y, &w, &h);
  692. if (r)
  693. goto err;
  694. r = taal_set_update_window(x, y, w, h);
  695. if (r)
  696. goto err;
  697. r = omap_dsi_update(dssdev, TCH, x, y, w, h,
  698. taal_framedone_cb, dssdev);
  699. if (r)
  700. goto err;
  701. /* note: no bus_unlock here. unlock is in framedone_cb */
  702. mutex_unlock(&td->lock);
  703. return 0;
  704. err:
  705. dsi_bus_unlock();
  706. mutex_unlock(&td->lock);
  707. return r;
  708. }
  709. static int taal_sync(struct omap_dss_device *dssdev)
  710. {
  711. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  712. dev_dbg(&dssdev->dev, "sync\n");
  713. mutex_lock(&td->lock);
  714. dsi_bus_lock();
  715. dsi_bus_unlock();
  716. mutex_unlock(&td->lock);
  717. dev_dbg(&dssdev->dev, "sync done\n");
  718. return 0;
  719. }
  720. static int _taal_enable_te(struct omap_dss_device *dssdev, bool enable)
  721. {
  722. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  723. int r;
  724. td->te_enabled = enable;
  725. if (enable)
  726. r = taal_dcs_write_1(DCS_TEAR_ON, 0);
  727. else
  728. r = taal_dcs_write_0(DCS_TEAR_OFF);
  729. omapdss_dsi_enable_te(dssdev, enable);
  730. /* XXX for some reason, DSI TE breaks if we don't wait here.
  731. * Panel bug? Needs more studying */
  732. msleep(100);
  733. return r;
  734. }
  735. static int taal_enable_te(struct omap_dss_device *dssdev, bool enable)
  736. {
  737. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  738. int r;
  739. mutex_lock(&td->lock);
  740. dsi_bus_lock();
  741. r = _taal_enable_te(dssdev, enable);
  742. dsi_bus_unlock();
  743. mutex_unlock(&td->lock);
  744. return r;
  745. }
  746. static int taal_get_te(struct omap_dss_device *dssdev)
  747. {
  748. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  749. int r;
  750. mutex_lock(&td->lock);
  751. r = td->te_enabled;
  752. mutex_unlock(&td->lock);
  753. return r;
  754. }
  755. static int taal_rotate(struct omap_dss_device *dssdev, u8 rotate)
  756. {
  757. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  758. int r;
  759. dev_dbg(&dssdev->dev, "rotate %d\n", rotate);
  760. mutex_lock(&td->lock);
  761. dsi_bus_lock();
  762. if (td->enabled) {
  763. r = taal_set_addr_mode(rotate, td->mirror);
  764. if (r)
  765. goto err;
  766. }
  767. td->rotate = rotate;
  768. dsi_bus_unlock();
  769. mutex_unlock(&td->lock);
  770. return 0;
  771. err:
  772. dsi_bus_unlock();
  773. mutex_unlock(&td->lock);
  774. return r;
  775. }
  776. static u8 taal_get_rotate(struct omap_dss_device *dssdev)
  777. {
  778. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  779. int r;
  780. mutex_lock(&td->lock);
  781. r = td->rotate;
  782. mutex_unlock(&td->lock);
  783. return r;
  784. }
  785. static int taal_mirror(struct omap_dss_device *dssdev, bool enable)
  786. {
  787. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  788. int r;
  789. dev_dbg(&dssdev->dev, "mirror %d\n", enable);
  790. mutex_lock(&td->lock);
  791. dsi_bus_lock();
  792. if (td->enabled) {
  793. r = taal_set_addr_mode(td->rotate, enable);
  794. if (r)
  795. goto err;
  796. }
  797. td->mirror = enable;
  798. dsi_bus_unlock();
  799. mutex_unlock(&td->lock);
  800. return 0;
  801. err:
  802. dsi_bus_unlock();
  803. mutex_unlock(&td->lock);
  804. return r;
  805. }
  806. static bool taal_get_mirror(struct omap_dss_device *dssdev)
  807. {
  808. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  809. int r;
  810. mutex_lock(&td->lock);
  811. r = td->mirror;
  812. mutex_unlock(&td->lock);
  813. return r;
  814. }
  815. static int taal_run_test(struct omap_dss_device *dssdev, int test_num)
  816. {
  817. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  818. u8 id1, id2, id3;
  819. int r;
  820. mutex_lock(&td->lock);
  821. dsi_bus_lock();
  822. r = taal_dcs_read_1(DCS_GET_ID1, &id1);
  823. if (r)
  824. goto err;
  825. r = taal_dcs_read_1(DCS_GET_ID2, &id2);
  826. if (r)
  827. goto err;
  828. r = taal_dcs_read_1(DCS_GET_ID3, &id3);
  829. if (r)
  830. goto err;
  831. dsi_bus_unlock();
  832. mutex_unlock(&td->lock);
  833. return 0;
  834. err:
  835. dsi_bus_unlock();
  836. mutex_unlock(&td->lock);
  837. return r;
  838. }
  839. static int taal_memory_read(struct omap_dss_device *dssdev,
  840. void *buf, size_t size,
  841. u16 x, u16 y, u16 w, u16 h)
  842. {
  843. int r;
  844. int first = 1;
  845. int plen;
  846. unsigned buf_used = 0;
  847. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  848. if (size < w * h * 3)
  849. return -ENOMEM;
  850. mutex_lock(&td->lock);
  851. if (!td->enabled) {
  852. r = -ENODEV;
  853. goto err1;
  854. }
  855. size = min(w * h * 3,
  856. dssdev->panel.timings.x_res *
  857. dssdev->panel.timings.y_res * 3);
  858. dsi_bus_lock();
  859. /* plen 1 or 2 goes into short packet. until checksum error is fixed,
  860. * use short packets. plen 32 works, but bigger packets seem to cause
  861. * an error. */
  862. if (size % 2)
  863. plen = 1;
  864. else
  865. plen = 2;
  866. taal_set_update_window(x, y, w, h);
  867. r = dsi_vc_set_max_rx_packet_size(TCH, plen);
  868. if (r)
  869. goto err2;
  870. while (buf_used < size) {
  871. u8 dcs_cmd = first ? 0x2e : 0x3e;
  872. first = 0;
  873. r = dsi_vc_dcs_read(TCH, dcs_cmd,
  874. buf + buf_used, size - buf_used);
  875. if (r < 0) {
  876. dev_err(&dssdev->dev, "read error\n");
  877. goto err3;
  878. }
  879. buf_used += r;
  880. if (r < plen) {
  881. dev_err(&dssdev->dev, "short read\n");
  882. break;
  883. }
  884. if (signal_pending(current)) {
  885. dev_err(&dssdev->dev, "signal pending, "
  886. "aborting memory read\n");
  887. r = -ERESTARTSYS;
  888. goto err3;
  889. }
  890. }
  891. r = buf_used;
  892. err3:
  893. dsi_vc_set_max_rx_packet_size(TCH, 1);
  894. err2:
  895. dsi_bus_unlock();
  896. err1:
  897. mutex_unlock(&td->lock);
  898. return r;
  899. }
  900. static void taal_esd_work(struct work_struct *work)
  901. {
  902. struct taal_data *td = container_of(work, struct taal_data,
  903. esd_work.work);
  904. struct omap_dss_device *dssdev = td->dssdev;
  905. u8 state1, state2;
  906. int r;
  907. mutex_lock(&td->lock);
  908. if (!td->enabled) {
  909. mutex_unlock(&td->lock);
  910. return;
  911. }
  912. dsi_bus_lock();
  913. r = taal_dcs_read_1(DCS_RDDSDR, &state1);
  914. if (r) {
  915. dev_err(&dssdev->dev, "failed to read Taal status\n");
  916. goto err;
  917. }
  918. /* Run self diagnostics */
  919. r = taal_sleep_out(td);
  920. if (r) {
  921. dev_err(&dssdev->dev, "failed to run Taal self-diagnostics\n");
  922. goto err;
  923. }
  924. r = taal_dcs_read_1(DCS_RDDSDR, &state2);
  925. if (r) {
  926. dev_err(&dssdev->dev, "failed to read Taal status\n");
  927. goto err;
  928. }
  929. /* Each sleep out command will trigger a self diagnostic and flip
  930. * Bit6 if the test passes.
  931. */
  932. if (!((state1 ^ state2) & (1 << 6))) {
  933. dev_err(&dssdev->dev, "LCD self diagnostics failed\n");
  934. goto err;
  935. }
  936. /* Self-diagnostics result is also shown on TE GPIO line. We need
  937. * to re-enable TE after self diagnostics */
  938. if (td->use_ext_te && td->te_enabled) {
  939. r = taal_dcs_write_1(DCS_TEAR_ON, 0);
  940. if (r)
  941. goto err;
  942. }
  943. dsi_bus_unlock();
  944. queue_delayed_work(td->esd_wq, &td->esd_work, TAAL_ESD_CHECK_PERIOD);
  945. mutex_unlock(&td->lock);
  946. return;
  947. err:
  948. dev_err(&dssdev->dev, "performing LCD reset\n");
  949. taal_power_off(dssdev);
  950. taal_hw_reset(dssdev);
  951. taal_power_on(dssdev);
  952. dsi_bus_unlock();
  953. queue_delayed_work(td->esd_wq, &td->esd_work, TAAL_ESD_CHECK_PERIOD);
  954. mutex_unlock(&td->lock);
  955. }
  956. static int taal_set_update_mode(struct omap_dss_device *dssdev,
  957. enum omap_dss_update_mode mode)
  958. {
  959. if (mode != OMAP_DSS_UPDATE_MANUAL)
  960. return -EINVAL;
  961. return 0;
  962. }
  963. static enum omap_dss_update_mode taal_get_update_mode(
  964. struct omap_dss_device *dssdev)
  965. {
  966. return OMAP_DSS_UPDATE_MANUAL;
  967. }
  968. static struct omap_dss_driver taal_driver = {
  969. .probe = taal_probe,
  970. .remove = taal_remove,
  971. .enable = taal_enable,
  972. .disable = taal_disable,
  973. .suspend = taal_suspend,
  974. .resume = taal_resume,
  975. .set_update_mode = taal_set_update_mode,
  976. .get_update_mode = taal_get_update_mode,
  977. .update = taal_update,
  978. .sync = taal_sync,
  979. .get_resolution = taal_get_resolution,
  980. .get_recommended_bpp = omapdss_default_get_recommended_bpp,
  981. .enable_te = taal_enable_te,
  982. .get_te = taal_get_te,
  983. .set_rotate = taal_rotate,
  984. .get_rotate = taal_get_rotate,
  985. .set_mirror = taal_mirror,
  986. .get_mirror = taal_get_mirror,
  987. .run_test = taal_run_test,
  988. .memory_read = taal_memory_read,
  989. .get_timings = taal_get_timings,
  990. .driver = {
  991. .name = "taal",
  992. .owner = THIS_MODULE,
  993. },
  994. };
  995. static int __init taal_init(void)
  996. {
  997. omap_dss_register_driver(&taal_driver);
  998. return 0;
  999. }
  1000. static void __exit taal_exit(void)
  1001. {
  1002. omap_dss_unregister_driver(&taal_driver);
  1003. }
  1004. module_init(taal_init);
  1005. module_exit(taal_exit);
  1006. MODULE_AUTHOR("Tomi Valkeinen <tomi.valkeinen@nokia.com>");
  1007. MODULE_DESCRIPTION("Taal Driver");
  1008. MODULE_LICENSE("GPL");