panel-taal.c 26 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351
  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 err;
  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 err_wq;
  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 err_bl;
  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 err_gpio;
  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 err_irq;
  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 err_sysfs;
  490. }
  491. return 0;
  492. err_sysfs:
  493. if (td->use_ext_te)
  494. free_irq(gpio_to_irq(dssdev->phy.dsi.ext_te_gpio), dssdev);
  495. err_irq:
  496. if (td->use_ext_te)
  497. gpio_free(dssdev->phy.dsi.ext_te_gpio);
  498. err_gpio:
  499. backlight_device_unregister(bldev);
  500. err_bl:
  501. destroy_workqueue(td->esd_wq);
  502. err_wq:
  503. kfree(td);
  504. err:
  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(&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. r = omapdss_dsi_display_enable(dssdev);
  536. if (r) {
  537. dev_err(&dssdev->dev, "failed to enable DSI\n");
  538. goto err0;
  539. }
  540. taal_hw_reset(dssdev);
  541. omapdss_dsi_vc_enable_hs(TCH, false);
  542. r = taal_sleep_out(td);
  543. if (r)
  544. goto err;
  545. r = taal_get_id(&id1, &id2, &id3);
  546. if (r)
  547. goto err;
  548. /* on early revisions CABC is broken */
  549. if (id2 == 0x00 || id2 == 0xff || id2 == 0x81)
  550. td->cabc_broken = true;
  551. r = taal_dcs_write_1(DCS_BRIGHTNESS, 0xff);
  552. if (r)
  553. goto err;
  554. r = taal_dcs_write_1(DCS_CTRL_DISPLAY,
  555. (1<<2) | (1<<5)); /* BL | BCTRL */
  556. if (r)
  557. goto err;
  558. r = taal_dcs_write_1(DCS_PIXEL_FORMAT, 0x7); /* 24bit/pixel */
  559. if (r)
  560. goto err;
  561. r = taal_set_addr_mode(td->rotate, td->mirror);
  562. if (r)
  563. goto err;
  564. if (!td->cabc_broken) {
  565. r = taal_dcs_write_1(DCS_WRITE_CABC, td->cabc_mode);
  566. if (r)
  567. goto err;
  568. }
  569. r = taal_dcs_write_0(DCS_DISPLAY_ON);
  570. if (r)
  571. goto err;
  572. r = _taal_enable_te(dssdev, td->te_enabled);
  573. if (r)
  574. goto err;
  575. td->enabled = 1;
  576. if (!td->intro_printed) {
  577. dev_info(&dssdev->dev, "revision %02x.%02x.%02x\n",
  578. id1, id2, id3);
  579. if (td->cabc_broken)
  580. dev_info(&dssdev->dev,
  581. "old Taal version, CABC disabled\n");
  582. td->intro_printed = true;
  583. }
  584. omapdss_dsi_vc_enable_hs(TCH, true);
  585. return 0;
  586. err:
  587. dev_err(&dssdev->dev, "error while enabling panel, issuing HW reset\n");
  588. taal_hw_reset(dssdev);
  589. omapdss_dsi_display_disable(dssdev);
  590. err0:
  591. return r;
  592. }
  593. static void taal_power_off(struct omap_dss_device *dssdev)
  594. {
  595. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  596. int r;
  597. r = taal_dcs_write_0(DCS_DISPLAY_OFF);
  598. if (!r) {
  599. r = taal_sleep_in(td);
  600. /* wait a bit so that the message goes through */
  601. msleep(10);
  602. }
  603. if (r) {
  604. dev_err(&dssdev->dev,
  605. "error disabling panel, issuing HW reset\n");
  606. taal_hw_reset(dssdev);
  607. }
  608. omapdss_dsi_display_disable(dssdev);
  609. td->enabled = 0;
  610. }
  611. static int taal_enable(struct omap_dss_device *dssdev)
  612. {
  613. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  614. int r;
  615. dev_dbg(&dssdev->dev, "enable\n");
  616. mutex_lock(&td->lock);
  617. if (dssdev->state != OMAP_DSS_DISPLAY_DISABLED) {
  618. r = -EINVAL;
  619. goto err;
  620. }
  621. dsi_bus_lock();
  622. r = taal_power_on(dssdev);
  623. dsi_bus_unlock();
  624. if (r)
  625. goto err;
  626. #ifdef TAAL_USE_ESD_CHECK
  627. queue_delayed_work(td->esd_wq, &td->esd_work, TAAL_ESD_CHECK_PERIOD);
  628. #endif
  629. dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
  630. mutex_unlock(&td->lock);
  631. return 0;
  632. err:
  633. dev_dbg(&dssdev->dev, "enable failed\n");
  634. mutex_unlock(&td->lock);
  635. return r;
  636. }
  637. static void taal_disable(struct omap_dss_device *dssdev)
  638. {
  639. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  640. dev_dbg(&dssdev->dev, "disable\n");
  641. mutex_lock(&td->lock);
  642. cancel_delayed_work(&td->esd_work);
  643. dsi_bus_lock();
  644. if (dssdev->state == OMAP_DSS_DISPLAY_ACTIVE)
  645. taal_power_off(dssdev);
  646. dsi_bus_unlock();
  647. dssdev->state = OMAP_DSS_DISPLAY_DISABLED;
  648. mutex_unlock(&td->lock);
  649. }
  650. static int taal_suspend(struct omap_dss_device *dssdev)
  651. {
  652. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  653. int r;
  654. dev_dbg(&dssdev->dev, "suspend\n");
  655. mutex_lock(&td->lock);
  656. if (dssdev->state != OMAP_DSS_DISPLAY_ACTIVE) {
  657. r = -EINVAL;
  658. goto err;
  659. }
  660. cancel_delayed_work(&td->esd_work);
  661. dsi_bus_lock();
  662. taal_power_off(dssdev);
  663. dsi_bus_unlock();
  664. dssdev->state = OMAP_DSS_DISPLAY_SUSPENDED;
  665. mutex_unlock(&td->lock);
  666. return 0;
  667. err:
  668. mutex_unlock(&td->lock);
  669. return r;
  670. }
  671. static int taal_resume(struct omap_dss_device *dssdev)
  672. {
  673. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  674. int r;
  675. dev_dbg(&dssdev->dev, "resume\n");
  676. mutex_lock(&td->lock);
  677. if (dssdev->state != OMAP_DSS_DISPLAY_SUSPENDED) {
  678. r = -EINVAL;
  679. goto err;
  680. }
  681. dsi_bus_lock();
  682. r = taal_power_on(dssdev);
  683. dsi_bus_unlock();
  684. if (r) {
  685. dssdev->state = OMAP_DSS_DISPLAY_DISABLED;
  686. } else {
  687. dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
  688. #ifdef TAAL_USE_ESD_CHECK
  689. queue_delayed_work(td->esd_wq, &td->esd_work,
  690. TAAL_ESD_CHECK_PERIOD);
  691. #endif
  692. }
  693. mutex_unlock(&td->lock);
  694. return r;
  695. err:
  696. mutex_unlock(&td->lock);
  697. return r;
  698. }
  699. static void taal_framedone_cb(int err, void *data)
  700. {
  701. struct omap_dss_device *dssdev = data;
  702. dev_dbg(&dssdev->dev, "framedone, err %d\n", err);
  703. dsi_bus_unlock();
  704. }
  705. static int taal_update(struct omap_dss_device *dssdev,
  706. u16 x, u16 y, u16 w, u16 h)
  707. {
  708. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  709. int r;
  710. dev_dbg(&dssdev->dev, "update %d, %d, %d x %d\n", x, y, w, h);
  711. mutex_lock(&td->lock);
  712. dsi_bus_lock();
  713. if (!td->enabled) {
  714. r = 0;
  715. goto err;
  716. }
  717. r = omap_dsi_prepare_update(dssdev, &x, &y, &w, &h);
  718. if (r)
  719. goto err;
  720. r = taal_set_update_window(x, y, w, h);
  721. if (r)
  722. goto err;
  723. r = omap_dsi_update(dssdev, TCH, x, y, w, h,
  724. taal_framedone_cb, dssdev);
  725. if (r)
  726. goto err;
  727. /* note: no bus_unlock here. unlock is in framedone_cb */
  728. mutex_unlock(&td->lock);
  729. return 0;
  730. err:
  731. dsi_bus_unlock();
  732. mutex_unlock(&td->lock);
  733. return r;
  734. }
  735. static int taal_sync(struct omap_dss_device *dssdev)
  736. {
  737. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  738. dev_dbg(&dssdev->dev, "sync\n");
  739. mutex_lock(&td->lock);
  740. dsi_bus_lock();
  741. dsi_bus_unlock();
  742. mutex_unlock(&td->lock);
  743. dev_dbg(&dssdev->dev, "sync done\n");
  744. return 0;
  745. }
  746. static int _taal_enable_te(struct omap_dss_device *dssdev, bool enable)
  747. {
  748. int r;
  749. if (enable)
  750. r = taal_dcs_write_1(DCS_TEAR_ON, 0);
  751. else
  752. r = taal_dcs_write_0(DCS_TEAR_OFF);
  753. omapdss_dsi_enable_te(dssdev, enable);
  754. /* XXX for some reason, DSI TE breaks if we don't wait here.
  755. * Panel bug? Needs more studying */
  756. msleep(100);
  757. return r;
  758. }
  759. static int taal_enable_te(struct omap_dss_device *dssdev, bool enable)
  760. {
  761. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  762. int r;
  763. mutex_lock(&td->lock);
  764. dsi_bus_lock();
  765. if (td->enabled) {
  766. r = _taal_enable_te(dssdev, enable);
  767. if (r)
  768. goto err;
  769. }
  770. td->te_enabled = enable;
  771. dsi_bus_unlock();
  772. mutex_unlock(&td->lock);
  773. return 0;
  774. err:
  775. dsi_bus_unlock();
  776. mutex_unlock(&td->lock);
  777. return r;
  778. }
  779. static int taal_get_te(struct omap_dss_device *dssdev)
  780. {
  781. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  782. int r;
  783. mutex_lock(&td->lock);
  784. r = td->te_enabled;
  785. mutex_unlock(&td->lock);
  786. return r;
  787. }
  788. static int taal_rotate(struct omap_dss_device *dssdev, u8 rotate)
  789. {
  790. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  791. int r;
  792. dev_dbg(&dssdev->dev, "rotate %d\n", rotate);
  793. mutex_lock(&td->lock);
  794. dsi_bus_lock();
  795. if (td->enabled) {
  796. r = taal_set_addr_mode(rotate, td->mirror);
  797. if (r)
  798. goto err;
  799. }
  800. td->rotate = rotate;
  801. dsi_bus_unlock();
  802. mutex_unlock(&td->lock);
  803. return 0;
  804. err:
  805. dsi_bus_unlock();
  806. mutex_unlock(&td->lock);
  807. return r;
  808. }
  809. static u8 taal_get_rotate(struct omap_dss_device *dssdev)
  810. {
  811. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  812. int r;
  813. mutex_lock(&td->lock);
  814. r = td->rotate;
  815. mutex_unlock(&td->lock);
  816. return r;
  817. }
  818. static int taal_mirror(struct omap_dss_device *dssdev, bool enable)
  819. {
  820. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  821. int r;
  822. dev_dbg(&dssdev->dev, "mirror %d\n", enable);
  823. mutex_lock(&td->lock);
  824. dsi_bus_lock();
  825. if (td->enabled) {
  826. r = taal_set_addr_mode(td->rotate, enable);
  827. if (r)
  828. goto err;
  829. }
  830. td->mirror = enable;
  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 bool taal_get_mirror(struct omap_dss_device *dssdev)
  840. {
  841. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  842. int r;
  843. mutex_lock(&td->lock);
  844. r = td->mirror;
  845. mutex_unlock(&td->lock);
  846. return r;
  847. }
  848. static int taal_run_test(struct omap_dss_device *dssdev, int test_num)
  849. {
  850. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  851. u8 id1, id2, id3;
  852. int r;
  853. mutex_lock(&td->lock);
  854. if (!td->enabled) {
  855. r = -ENODEV;
  856. goto err1;
  857. }
  858. dsi_bus_lock();
  859. r = taal_dcs_read_1(DCS_GET_ID1, &id1);
  860. if (r)
  861. goto err2;
  862. r = taal_dcs_read_1(DCS_GET_ID2, &id2);
  863. if (r)
  864. goto err2;
  865. r = taal_dcs_read_1(DCS_GET_ID3, &id3);
  866. if (r)
  867. goto err2;
  868. dsi_bus_unlock();
  869. mutex_unlock(&td->lock);
  870. return 0;
  871. err2:
  872. dsi_bus_unlock();
  873. err1:
  874. mutex_unlock(&td->lock);
  875. return r;
  876. }
  877. static int taal_memory_read(struct omap_dss_device *dssdev,
  878. void *buf, size_t size,
  879. u16 x, u16 y, u16 w, u16 h)
  880. {
  881. int r;
  882. int first = 1;
  883. int plen;
  884. unsigned buf_used = 0;
  885. struct taal_data *td = dev_get_drvdata(&dssdev->dev);
  886. if (size < w * h * 3)
  887. return -ENOMEM;
  888. mutex_lock(&td->lock);
  889. if (!td->enabled) {
  890. r = -ENODEV;
  891. goto err1;
  892. }
  893. size = min(w * h * 3,
  894. dssdev->panel.timings.x_res *
  895. dssdev->panel.timings.y_res * 3);
  896. dsi_bus_lock();
  897. /* plen 1 or 2 goes into short packet. until checksum error is fixed,
  898. * use short packets. plen 32 works, but bigger packets seem to cause
  899. * an error. */
  900. if (size % 2)
  901. plen = 1;
  902. else
  903. plen = 2;
  904. taal_set_update_window(x, y, w, h);
  905. r = dsi_vc_set_max_rx_packet_size(TCH, plen);
  906. if (r)
  907. goto err2;
  908. while (buf_used < size) {
  909. u8 dcs_cmd = first ? 0x2e : 0x3e;
  910. first = 0;
  911. r = dsi_vc_dcs_read(TCH, dcs_cmd,
  912. buf + buf_used, size - buf_used);
  913. if (r < 0) {
  914. dev_err(&dssdev->dev, "read error\n");
  915. goto err3;
  916. }
  917. buf_used += r;
  918. if (r < plen) {
  919. dev_err(&dssdev->dev, "short read\n");
  920. break;
  921. }
  922. if (signal_pending(current)) {
  923. dev_err(&dssdev->dev, "signal pending, "
  924. "aborting memory read\n");
  925. r = -ERESTARTSYS;
  926. goto err3;
  927. }
  928. }
  929. r = buf_used;
  930. err3:
  931. dsi_vc_set_max_rx_packet_size(TCH, 1);
  932. err2:
  933. dsi_bus_unlock();
  934. err1:
  935. mutex_unlock(&td->lock);
  936. return r;
  937. }
  938. static void taal_esd_work(struct work_struct *work)
  939. {
  940. struct taal_data *td = container_of(work, struct taal_data,
  941. esd_work.work);
  942. struct omap_dss_device *dssdev = td->dssdev;
  943. u8 state1, state2;
  944. int r;
  945. mutex_lock(&td->lock);
  946. if (!td->enabled) {
  947. mutex_unlock(&td->lock);
  948. return;
  949. }
  950. dsi_bus_lock();
  951. r = taal_dcs_read_1(DCS_RDDSDR, &state1);
  952. if (r) {
  953. dev_err(&dssdev->dev, "failed to read Taal status\n");
  954. goto err;
  955. }
  956. /* Run self diagnostics */
  957. r = taal_sleep_out(td);
  958. if (r) {
  959. dev_err(&dssdev->dev, "failed to run Taal self-diagnostics\n");
  960. goto err;
  961. }
  962. r = taal_dcs_read_1(DCS_RDDSDR, &state2);
  963. if (r) {
  964. dev_err(&dssdev->dev, "failed to read Taal status\n");
  965. goto err;
  966. }
  967. /* Each sleep out command will trigger a self diagnostic and flip
  968. * Bit6 if the test passes.
  969. */
  970. if (!((state1 ^ state2) & (1 << 6))) {
  971. dev_err(&dssdev->dev, "LCD self diagnostics failed\n");
  972. goto err;
  973. }
  974. /* Self-diagnostics result is also shown on TE GPIO line. We need
  975. * to re-enable TE after self diagnostics */
  976. if (td->use_ext_te && td->te_enabled) {
  977. r = taal_dcs_write_1(DCS_TEAR_ON, 0);
  978. if (r)
  979. goto err;
  980. }
  981. dsi_bus_unlock();
  982. queue_delayed_work(td->esd_wq, &td->esd_work, TAAL_ESD_CHECK_PERIOD);
  983. mutex_unlock(&td->lock);
  984. return;
  985. err:
  986. dev_err(&dssdev->dev, "performing LCD reset\n");
  987. taal_power_off(dssdev);
  988. taal_hw_reset(dssdev);
  989. taal_power_on(dssdev);
  990. dsi_bus_unlock();
  991. queue_delayed_work(td->esd_wq, &td->esd_work, TAAL_ESD_CHECK_PERIOD);
  992. mutex_unlock(&td->lock);
  993. }
  994. static int taal_set_update_mode(struct omap_dss_device *dssdev,
  995. enum omap_dss_update_mode mode)
  996. {
  997. if (mode != OMAP_DSS_UPDATE_MANUAL)
  998. return -EINVAL;
  999. return 0;
  1000. }
  1001. static enum omap_dss_update_mode taal_get_update_mode(
  1002. struct omap_dss_device *dssdev)
  1003. {
  1004. return OMAP_DSS_UPDATE_MANUAL;
  1005. }
  1006. static struct omap_dss_driver taal_driver = {
  1007. .probe = taal_probe,
  1008. .remove = taal_remove,
  1009. .enable = taal_enable,
  1010. .disable = taal_disable,
  1011. .suspend = taal_suspend,
  1012. .resume = taal_resume,
  1013. .set_update_mode = taal_set_update_mode,
  1014. .get_update_mode = taal_get_update_mode,
  1015. .update = taal_update,
  1016. .sync = taal_sync,
  1017. .get_resolution = taal_get_resolution,
  1018. .get_recommended_bpp = omapdss_default_get_recommended_bpp,
  1019. .enable_te = taal_enable_te,
  1020. .get_te = taal_get_te,
  1021. .set_rotate = taal_rotate,
  1022. .get_rotate = taal_get_rotate,
  1023. .set_mirror = taal_mirror,
  1024. .get_mirror = taal_get_mirror,
  1025. .run_test = taal_run_test,
  1026. .memory_read = taal_memory_read,
  1027. .get_timings = taal_get_timings,
  1028. .driver = {
  1029. .name = "taal",
  1030. .owner = THIS_MODULE,
  1031. },
  1032. };
  1033. static int __init taal_init(void)
  1034. {
  1035. omap_dss_register_driver(&taal_driver);
  1036. return 0;
  1037. }
  1038. static void __exit taal_exit(void)
  1039. {
  1040. omap_dss_unregister_driver(&taal_driver);
  1041. }
  1042. module_init(taal_init);
  1043. module_exit(taal_exit);
  1044. MODULE_AUTHOR("Tomi Valkeinen <tomi.valkeinen@nokia.com>");
  1045. MODULE_DESCRIPTION("Taal Driver");
  1046. MODULE_LICENSE("GPL");