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