panel-taal.c 27 KB

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