panel-taal.c 25 KB

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