panel-acx565akm.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787
  1. /*
  2. * Support for ACX565AKM LCD Panel used on Nokia N900
  3. *
  4. * Copyright (C) 2010 Nokia Corporation
  5. *
  6. * Original Driver Author: Imre Deak <imre.deak@nokia.com>
  7. * Based on panel-generic.c by Tomi Valkeinen <tomi.valkeinen@nokia.com>
  8. * Adapted to new DSS2 framework: Roger Quadros <roger.quadros@nokia.com>
  9. *
  10. * This program is free software; you can redistribute it and/or modify it
  11. * under the terms of the GNU General Public License version 2 as published by
  12. * the Free Software Foundation.
  13. *
  14. * This program is distributed in the hope that it will be useful, but WITHOUT
  15. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  16. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  17. * more details.
  18. *
  19. * You should have received a copy of the GNU General Public License along with
  20. * this program. If not, see <http://www.gnu.org/licenses/>.
  21. */
  22. #include <linux/kernel.h>
  23. #include <linux/module.h>
  24. #include <linux/platform_device.h>
  25. #include <linux/delay.h>
  26. #include <linux/spi/spi.h>
  27. #include <linux/jiffies.h>
  28. #include <linux/sched.h>
  29. #include <linux/backlight.h>
  30. #include <linux/fb.h>
  31. #include <video/omapdss.h>
  32. #define MIPID_CMD_READ_DISP_ID 0x04
  33. #define MIPID_CMD_READ_RED 0x06
  34. #define MIPID_CMD_READ_GREEN 0x07
  35. #define MIPID_CMD_READ_BLUE 0x08
  36. #define MIPID_CMD_READ_DISP_STATUS 0x09
  37. #define MIPID_CMD_RDDSDR 0x0F
  38. #define MIPID_CMD_SLEEP_IN 0x10
  39. #define MIPID_CMD_SLEEP_OUT 0x11
  40. #define MIPID_CMD_DISP_OFF 0x28
  41. #define MIPID_CMD_DISP_ON 0x29
  42. #define MIPID_CMD_WRITE_DISP_BRIGHTNESS 0x51
  43. #define MIPID_CMD_READ_DISP_BRIGHTNESS 0x52
  44. #define MIPID_CMD_WRITE_CTRL_DISP 0x53
  45. #define CTRL_DISP_BRIGHTNESS_CTRL_ON (1 << 5)
  46. #define CTRL_DISP_AMBIENT_LIGHT_CTRL_ON (1 << 4)
  47. #define CTRL_DISP_BACKLIGHT_ON (1 << 2)
  48. #define CTRL_DISP_AUTO_BRIGHTNESS_ON (1 << 1)
  49. #define MIPID_CMD_READ_CTRL_DISP 0x54
  50. #define MIPID_CMD_WRITE_CABC 0x55
  51. #define MIPID_CMD_READ_CABC 0x56
  52. #define MIPID_VER_LPH8923 3
  53. #define MIPID_VER_LS041Y3 4
  54. #define MIPID_VER_L4F00311 8
  55. #define MIPID_VER_ACX565AKM 9
  56. struct acx565akm_device {
  57. char *name;
  58. int enabled;
  59. int model;
  60. int revision;
  61. u8 display_id[3];
  62. unsigned has_bc:1;
  63. unsigned has_cabc:1;
  64. unsigned cabc_mode;
  65. unsigned long hw_guard_end; /* next value of jiffies
  66. when we can issue the
  67. next sleep in/out command */
  68. unsigned long hw_guard_wait; /* max guard time in jiffies */
  69. struct spi_device *spi;
  70. struct mutex mutex;
  71. struct omap_dss_device *dssdev;
  72. struct backlight_device *bl_dev;
  73. };
  74. static struct acx565akm_device acx_dev;
  75. static int acx565akm_bl_update_status(struct backlight_device *dev);
  76. /*--------------------MIPID interface-----------------------------*/
  77. static void acx565akm_transfer(struct acx565akm_device *md, int cmd,
  78. const u8 *wbuf, int wlen, u8 *rbuf, int rlen)
  79. {
  80. struct spi_message m;
  81. struct spi_transfer *x, xfer[5];
  82. int r;
  83. BUG_ON(md->spi == NULL);
  84. spi_message_init(&m);
  85. memset(xfer, 0, sizeof(xfer));
  86. x = &xfer[0];
  87. cmd &= 0xff;
  88. x->tx_buf = &cmd;
  89. x->bits_per_word = 9;
  90. x->len = 2;
  91. if (rlen > 1 && wlen == 0) {
  92. /*
  93. * Between the command and the response data there is a
  94. * dummy clock cycle. Add an extra bit after the command
  95. * word to account for this.
  96. */
  97. x->bits_per_word = 10;
  98. cmd <<= 1;
  99. }
  100. spi_message_add_tail(x, &m);
  101. if (wlen) {
  102. x++;
  103. x->tx_buf = wbuf;
  104. x->len = wlen;
  105. x->bits_per_word = 9;
  106. spi_message_add_tail(x, &m);
  107. }
  108. if (rlen) {
  109. x++;
  110. x->rx_buf = rbuf;
  111. x->len = rlen;
  112. spi_message_add_tail(x, &m);
  113. }
  114. r = spi_sync(md->spi, &m);
  115. if (r < 0)
  116. dev_dbg(&md->spi->dev, "spi_sync %d\n", r);
  117. }
  118. static inline void acx565akm_cmd(struct acx565akm_device *md, int cmd)
  119. {
  120. acx565akm_transfer(md, cmd, NULL, 0, NULL, 0);
  121. }
  122. static inline void acx565akm_write(struct acx565akm_device *md,
  123. int reg, const u8 *buf, int len)
  124. {
  125. acx565akm_transfer(md, reg, buf, len, NULL, 0);
  126. }
  127. static inline void acx565akm_read(struct acx565akm_device *md,
  128. int reg, u8 *buf, int len)
  129. {
  130. acx565akm_transfer(md, reg, NULL, 0, buf, len);
  131. }
  132. static void hw_guard_start(struct acx565akm_device *md, int guard_msec)
  133. {
  134. md->hw_guard_wait = msecs_to_jiffies(guard_msec);
  135. md->hw_guard_end = jiffies + md->hw_guard_wait;
  136. }
  137. static void hw_guard_wait(struct acx565akm_device *md)
  138. {
  139. unsigned long wait = md->hw_guard_end - jiffies;
  140. if ((long)wait > 0 && wait <= md->hw_guard_wait) {
  141. set_current_state(TASK_UNINTERRUPTIBLE);
  142. schedule_timeout(wait);
  143. }
  144. }
  145. /*----------------------MIPID wrappers----------------------------*/
  146. static void set_sleep_mode(struct acx565akm_device *md, int on)
  147. {
  148. int cmd;
  149. if (on)
  150. cmd = MIPID_CMD_SLEEP_IN;
  151. else
  152. cmd = MIPID_CMD_SLEEP_OUT;
  153. /*
  154. * We have to keep 120msec between sleep in/out commands.
  155. * (8.2.15, 8.2.16).
  156. */
  157. hw_guard_wait(md);
  158. acx565akm_cmd(md, cmd);
  159. hw_guard_start(md, 120);
  160. }
  161. static void set_display_state(struct acx565akm_device *md, int enabled)
  162. {
  163. int cmd = enabled ? MIPID_CMD_DISP_ON : MIPID_CMD_DISP_OFF;
  164. acx565akm_cmd(md, cmd);
  165. }
  166. static int panel_enabled(struct acx565akm_device *md)
  167. {
  168. u32 disp_status;
  169. int enabled;
  170. acx565akm_read(md, MIPID_CMD_READ_DISP_STATUS, (u8 *)&disp_status, 4);
  171. disp_status = __be32_to_cpu(disp_status);
  172. enabled = (disp_status & (1 << 17)) && (disp_status & (1 << 10));
  173. dev_dbg(&md->spi->dev,
  174. "LCD panel %senabled by bootloader (status 0x%04x)\n",
  175. enabled ? "" : "not ", disp_status);
  176. return enabled;
  177. }
  178. static int panel_detect(struct acx565akm_device *md)
  179. {
  180. acx565akm_read(md, MIPID_CMD_READ_DISP_ID, md->display_id, 3);
  181. dev_dbg(&md->spi->dev, "MIPI display ID: %02x%02x%02x\n",
  182. md->display_id[0], md->display_id[1], md->display_id[2]);
  183. switch (md->display_id[0]) {
  184. case 0x10:
  185. md->model = MIPID_VER_ACX565AKM;
  186. md->name = "acx565akm";
  187. md->has_bc = 1;
  188. md->has_cabc = 1;
  189. break;
  190. case 0x29:
  191. md->model = MIPID_VER_L4F00311;
  192. md->name = "l4f00311";
  193. break;
  194. case 0x45:
  195. md->model = MIPID_VER_LPH8923;
  196. md->name = "lph8923";
  197. break;
  198. case 0x83:
  199. md->model = MIPID_VER_LS041Y3;
  200. md->name = "ls041y3";
  201. break;
  202. default:
  203. md->name = "unknown";
  204. dev_err(&md->spi->dev, "invalid display ID\n");
  205. return -ENODEV;
  206. }
  207. md->revision = md->display_id[1];
  208. dev_info(&md->spi->dev, "omapfb: %s rev %02x LCD detected\n",
  209. md->name, md->revision);
  210. return 0;
  211. }
  212. /*----------------------Backlight Control-------------------------*/
  213. static void enable_backlight_ctrl(struct acx565akm_device *md, int enable)
  214. {
  215. u16 ctrl;
  216. acx565akm_read(md, MIPID_CMD_READ_CTRL_DISP, (u8 *)&ctrl, 1);
  217. if (enable) {
  218. ctrl |= CTRL_DISP_BRIGHTNESS_CTRL_ON |
  219. CTRL_DISP_BACKLIGHT_ON;
  220. } else {
  221. ctrl &= ~(CTRL_DISP_BRIGHTNESS_CTRL_ON |
  222. CTRL_DISP_BACKLIGHT_ON);
  223. }
  224. ctrl |= 1 << 8;
  225. acx565akm_write(md, MIPID_CMD_WRITE_CTRL_DISP, (u8 *)&ctrl, 2);
  226. }
  227. static void set_cabc_mode(struct acx565akm_device *md, unsigned mode)
  228. {
  229. u16 cabc_ctrl;
  230. md->cabc_mode = mode;
  231. if (!md->enabled)
  232. return;
  233. cabc_ctrl = 0;
  234. acx565akm_read(md, MIPID_CMD_READ_CABC, (u8 *)&cabc_ctrl, 1);
  235. cabc_ctrl &= ~3;
  236. cabc_ctrl |= (1 << 8) | (mode & 3);
  237. acx565akm_write(md, MIPID_CMD_WRITE_CABC, (u8 *)&cabc_ctrl, 2);
  238. }
  239. static unsigned get_cabc_mode(struct acx565akm_device *md)
  240. {
  241. return md->cabc_mode;
  242. }
  243. static unsigned get_hw_cabc_mode(struct acx565akm_device *md)
  244. {
  245. u8 cabc_ctrl;
  246. acx565akm_read(md, MIPID_CMD_READ_CABC, &cabc_ctrl, 1);
  247. return cabc_ctrl & 3;
  248. }
  249. static void acx565akm_set_brightness(struct acx565akm_device *md, int level)
  250. {
  251. int bv;
  252. bv = level | (1 << 8);
  253. acx565akm_write(md, MIPID_CMD_WRITE_DISP_BRIGHTNESS, (u8 *)&bv, 2);
  254. if (level)
  255. enable_backlight_ctrl(md, 1);
  256. else
  257. enable_backlight_ctrl(md, 0);
  258. }
  259. static int acx565akm_get_actual_brightness(struct acx565akm_device *md)
  260. {
  261. u8 bv;
  262. acx565akm_read(md, MIPID_CMD_READ_DISP_BRIGHTNESS, &bv, 1);
  263. return bv;
  264. }
  265. static int acx565akm_bl_update_status(struct backlight_device *dev)
  266. {
  267. struct acx565akm_device *md = dev_get_drvdata(&dev->dev);
  268. int r;
  269. int level;
  270. dev_dbg(&md->spi->dev, "%s\n", __func__);
  271. mutex_lock(&md->mutex);
  272. if (dev->props.fb_blank == FB_BLANK_UNBLANK &&
  273. dev->props.power == FB_BLANK_UNBLANK)
  274. level = dev->props.brightness;
  275. else
  276. level = 0;
  277. r = 0;
  278. if (md->has_bc)
  279. acx565akm_set_brightness(md, level);
  280. else if (md->dssdev->set_backlight)
  281. r = md->dssdev->set_backlight(md->dssdev, level);
  282. else
  283. r = -ENODEV;
  284. mutex_unlock(&md->mutex);
  285. return r;
  286. }
  287. static int acx565akm_bl_get_intensity(struct backlight_device *dev)
  288. {
  289. struct acx565akm_device *md = dev_get_drvdata(&dev->dev);
  290. dev_dbg(&dev->dev, "%s\n", __func__);
  291. if (!md->has_bc && md->dssdev->set_backlight == NULL)
  292. return -ENODEV;
  293. if (dev->props.fb_blank == FB_BLANK_UNBLANK &&
  294. dev->props.power == FB_BLANK_UNBLANK) {
  295. if (md->has_bc)
  296. return acx565akm_get_actual_brightness(md);
  297. else
  298. return dev->props.brightness;
  299. }
  300. return 0;
  301. }
  302. static const struct backlight_ops acx565akm_bl_ops = {
  303. .get_brightness = acx565akm_bl_get_intensity,
  304. .update_status = acx565akm_bl_update_status,
  305. };
  306. /*--------------------Auto Brightness control via Sysfs---------------------*/
  307. static const char *cabc_modes[] = {
  308. "off", /* always used when CABC is not supported */
  309. "ui",
  310. "still-image",
  311. "moving-image",
  312. };
  313. static ssize_t show_cabc_mode(struct device *dev,
  314. struct device_attribute *attr,
  315. char *buf)
  316. {
  317. struct acx565akm_device *md = dev_get_drvdata(dev);
  318. const char *mode_str;
  319. int mode;
  320. int len;
  321. if (!md->has_cabc)
  322. mode = 0;
  323. else
  324. mode = get_cabc_mode(md);
  325. mode_str = "unknown";
  326. if (mode >= 0 && mode < ARRAY_SIZE(cabc_modes))
  327. mode_str = cabc_modes[mode];
  328. len = snprintf(buf, PAGE_SIZE, "%s\n", mode_str);
  329. return len < PAGE_SIZE - 1 ? len : PAGE_SIZE - 1;
  330. }
  331. static ssize_t store_cabc_mode(struct device *dev,
  332. struct device_attribute *attr,
  333. const char *buf, size_t count)
  334. {
  335. struct acx565akm_device *md = dev_get_drvdata(dev);
  336. int i;
  337. for (i = 0; i < ARRAY_SIZE(cabc_modes); i++) {
  338. const char *mode_str = cabc_modes[i];
  339. int cmp_len = strlen(mode_str);
  340. if (count > 0 && buf[count - 1] == '\n')
  341. count--;
  342. if (count != cmp_len)
  343. continue;
  344. if (strncmp(buf, mode_str, cmp_len) == 0)
  345. break;
  346. }
  347. if (i == ARRAY_SIZE(cabc_modes))
  348. return -EINVAL;
  349. if (!md->has_cabc && i != 0)
  350. return -EINVAL;
  351. mutex_lock(&md->mutex);
  352. set_cabc_mode(md, i);
  353. mutex_unlock(&md->mutex);
  354. return count;
  355. }
  356. static ssize_t show_cabc_available_modes(struct device *dev,
  357. struct device_attribute *attr,
  358. char *buf)
  359. {
  360. struct acx565akm_device *md = dev_get_drvdata(dev);
  361. int len;
  362. int i;
  363. if (!md->has_cabc)
  364. return snprintf(buf, PAGE_SIZE, "%s\n", cabc_modes[0]);
  365. for (i = 0, len = 0;
  366. len < PAGE_SIZE && i < ARRAY_SIZE(cabc_modes); i++)
  367. len += snprintf(&buf[len], PAGE_SIZE - len, "%s%s%s",
  368. i ? " " : "", cabc_modes[i],
  369. i == ARRAY_SIZE(cabc_modes) - 1 ? "\n" : "");
  370. return len < PAGE_SIZE ? len : PAGE_SIZE - 1;
  371. }
  372. static DEVICE_ATTR(cabc_mode, S_IRUGO | S_IWUSR,
  373. show_cabc_mode, store_cabc_mode);
  374. static DEVICE_ATTR(cabc_available_modes, S_IRUGO,
  375. show_cabc_available_modes, NULL);
  376. static struct attribute *bldev_attrs[] = {
  377. &dev_attr_cabc_mode.attr,
  378. &dev_attr_cabc_available_modes.attr,
  379. NULL,
  380. };
  381. static struct attribute_group bldev_attr_group = {
  382. .attrs = bldev_attrs,
  383. };
  384. /*---------------------------ACX Panel----------------------------*/
  385. static int acx_get_recommended_bpp(struct omap_dss_device *dssdev)
  386. {
  387. return 16;
  388. }
  389. static struct omap_video_timings acx_panel_timings = {
  390. .x_res = 800,
  391. .y_res = 480,
  392. .pixel_clock = 24000,
  393. .hfp = 28,
  394. .hsw = 4,
  395. .hbp = 24,
  396. .vfp = 3,
  397. .vsw = 3,
  398. .vbp = 4,
  399. .vsync_level = OMAPDSS_SIG_ACTIVE_LOW,
  400. .hsync_level = OMAPDSS_SIG_ACTIVE_LOW,
  401. .data_pclk_edge = OMAPDSS_DRIVE_SIG_RISING_EDGE,
  402. .de_level = OMAPDSS_SIG_ACTIVE_HIGH,
  403. .sync_pclk_edge = OMAPDSS_DRIVE_SIG_OPPOSITE_EDGES,
  404. };
  405. static int acx_panel_probe(struct omap_dss_device *dssdev)
  406. {
  407. int r;
  408. struct acx565akm_device *md = &acx_dev;
  409. struct backlight_device *bldev;
  410. int max_brightness, brightness;
  411. struct backlight_properties props;
  412. dev_dbg(&dssdev->dev, "%s\n", __func__);
  413. /* FIXME AC bias ? */
  414. dssdev->panel.timings = acx_panel_timings;
  415. if (dssdev->platform_enable)
  416. dssdev->platform_enable(dssdev);
  417. /*
  418. * After reset we have to wait 5 msec before the first
  419. * command can be sent.
  420. */
  421. msleep(5);
  422. md->enabled = panel_enabled(md);
  423. r = panel_detect(md);
  424. if (r) {
  425. dev_err(&dssdev->dev, "%s panel detect error\n", __func__);
  426. if (!md->enabled && dssdev->platform_disable)
  427. dssdev->platform_disable(dssdev);
  428. return r;
  429. }
  430. mutex_lock(&acx_dev.mutex);
  431. acx_dev.dssdev = dssdev;
  432. mutex_unlock(&acx_dev.mutex);
  433. if (!md->enabled) {
  434. if (dssdev->platform_disable)
  435. dssdev->platform_disable(dssdev);
  436. }
  437. /*------- Backlight control --------*/
  438. memset(&props, 0, sizeof(props));
  439. props.fb_blank = FB_BLANK_UNBLANK;
  440. props.power = FB_BLANK_UNBLANK;
  441. props.type = BACKLIGHT_RAW;
  442. bldev = backlight_device_register("acx565akm", &md->spi->dev,
  443. md, &acx565akm_bl_ops, &props);
  444. md->bl_dev = bldev;
  445. if (md->has_cabc) {
  446. r = sysfs_create_group(&bldev->dev.kobj, &bldev_attr_group);
  447. if (r) {
  448. dev_err(&bldev->dev,
  449. "%s failed to create sysfs files\n", __func__);
  450. backlight_device_unregister(bldev);
  451. return r;
  452. }
  453. md->cabc_mode = get_hw_cabc_mode(md);
  454. }
  455. if (md->has_bc)
  456. max_brightness = 255;
  457. else
  458. max_brightness = dssdev->max_backlight_level;
  459. if (md->has_bc)
  460. brightness = acx565akm_get_actual_brightness(md);
  461. else if (dssdev->get_backlight)
  462. brightness = dssdev->get_backlight(dssdev);
  463. else
  464. brightness = 0;
  465. bldev->props.max_brightness = max_brightness;
  466. bldev->props.brightness = brightness;
  467. acx565akm_bl_update_status(bldev);
  468. return 0;
  469. }
  470. static void acx_panel_remove(struct omap_dss_device *dssdev)
  471. {
  472. struct acx565akm_device *md = &acx_dev;
  473. dev_dbg(&dssdev->dev, "%s\n", __func__);
  474. sysfs_remove_group(&md->bl_dev->dev.kobj, &bldev_attr_group);
  475. backlight_device_unregister(md->bl_dev);
  476. mutex_lock(&acx_dev.mutex);
  477. acx_dev.dssdev = NULL;
  478. mutex_unlock(&acx_dev.mutex);
  479. }
  480. static int acx_panel_power_on(struct omap_dss_device *dssdev)
  481. {
  482. struct acx565akm_device *md = &acx_dev;
  483. int r;
  484. dev_dbg(&dssdev->dev, "%s\n", __func__);
  485. if (dssdev->state == OMAP_DSS_DISPLAY_ACTIVE)
  486. return 0;
  487. mutex_lock(&md->mutex);
  488. omapdss_sdi_set_timings(dssdev, &dssdev->panel.timings);
  489. omapdss_sdi_set_datapairs(dssdev, dssdev->phy.sdi.datapairs);
  490. r = omapdss_sdi_display_enable(dssdev);
  491. if (r) {
  492. pr_err("%s sdi enable failed\n", __func__);
  493. goto fail_unlock;
  494. }
  495. /*FIXME tweak me */
  496. msleep(50);
  497. if (dssdev->platform_enable) {
  498. r = dssdev->platform_enable(dssdev);
  499. if (r)
  500. goto fail;
  501. }
  502. if (md->enabled) {
  503. dev_dbg(&md->spi->dev, "panel already enabled\n");
  504. mutex_unlock(&md->mutex);
  505. return 0;
  506. }
  507. /*
  508. * We have to meet all the following delay requirements:
  509. * 1. tRW: reset pulse width 10usec (7.12.1)
  510. * 2. tRT: reset cancel time 5msec (7.12.1)
  511. * 3. Providing PCLK,HS,VS signals for 2 frames = ~50msec worst
  512. * case (7.6.2)
  513. * 4. 120msec before the sleep out command (7.12.1)
  514. */
  515. msleep(120);
  516. set_sleep_mode(md, 0);
  517. md->enabled = 1;
  518. /* 5msec between sleep out and the next command. (8.2.16) */
  519. msleep(5);
  520. set_display_state(md, 1);
  521. set_cabc_mode(md, md->cabc_mode);
  522. mutex_unlock(&md->mutex);
  523. return acx565akm_bl_update_status(md->bl_dev);
  524. fail:
  525. omapdss_sdi_display_disable(dssdev);
  526. fail_unlock:
  527. mutex_unlock(&md->mutex);
  528. return r;
  529. }
  530. static void acx_panel_power_off(struct omap_dss_device *dssdev)
  531. {
  532. struct acx565akm_device *md = &acx_dev;
  533. dev_dbg(&dssdev->dev, "%s\n", __func__);
  534. if (dssdev->state != OMAP_DSS_DISPLAY_ACTIVE)
  535. return;
  536. mutex_lock(&md->mutex);
  537. if (!md->enabled) {
  538. mutex_unlock(&md->mutex);
  539. return;
  540. }
  541. set_display_state(md, 0);
  542. set_sleep_mode(md, 1);
  543. md->enabled = 0;
  544. /*
  545. * We have to provide PCLK,HS,VS signals for 2 frames (worst case
  546. * ~50msec) after sending the sleep in command and asserting the
  547. * reset signal. We probably could assert the reset w/o the delay
  548. * but we still delay to avoid possible artifacts. (7.6.1)
  549. */
  550. msleep(50);
  551. if (dssdev->platform_disable)
  552. dssdev->platform_disable(dssdev);
  553. /* FIXME need to tweak this delay */
  554. msleep(100);
  555. omapdss_sdi_display_disable(dssdev);
  556. mutex_unlock(&md->mutex);
  557. }
  558. static int acx_panel_enable(struct omap_dss_device *dssdev)
  559. {
  560. int r;
  561. dev_dbg(&dssdev->dev, "%s\n", __func__);
  562. r = acx_panel_power_on(dssdev);
  563. if (r)
  564. return r;
  565. dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
  566. return 0;
  567. }
  568. static void acx_panel_disable(struct omap_dss_device *dssdev)
  569. {
  570. dev_dbg(&dssdev->dev, "%s\n", __func__);
  571. acx_panel_power_off(dssdev);
  572. dssdev->state = OMAP_DSS_DISPLAY_DISABLED;
  573. }
  574. static void acx_panel_set_timings(struct omap_dss_device *dssdev,
  575. struct omap_video_timings *timings)
  576. {
  577. omapdss_sdi_set_timings(dssdev, timings);
  578. dssdev->panel.timings = *timings;
  579. }
  580. static int acx_panel_check_timings(struct omap_dss_device *dssdev,
  581. struct omap_video_timings *timings)
  582. {
  583. return 0;
  584. }
  585. static struct omap_dss_driver acx_panel_driver = {
  586. .probe = acx_panel_probe,
  587. .remove = acx_panel_remove,
  588. .enable = acx_panel_enable,
  589. .disable = acx_panel_disable,
  590. .set_timings = acx_panel_set_timings,
  591. .check_timings = acx_panel_check_timings,
  592. .get_recommended_bpp = acx_get_recommended_bpp,
  593. .driver = {
  594. .name = "panel-acx565akm",
  595. .owner = THIS_MODULE,
  596. },
  597. };
  598. /*--------------------SPI probe-------------------------*/
  599. static int acx565akm_spi_probe(struct spi_device *spi)
  600. {
  601. struct acx565akm_device *md = &acx_dev;
  602. dev_dbg(&spi->dev, "%s\n", __func__);
  603. spi->mode = SPI_MODE_3;
  604. md->spi = spi;
  605. mutex_init(&md->mutex);
  606. dev_set_drvdata(&spi->dev, md);
  607. omap_dss_register_driver(&acx_panel_driver);
  608. return 0;
  609. }
  610. static int acx565akm_spi_remove(struct spi_device *spi)
  611. {
  612. struct acx565akm_device *md = dev_get_drvdata(&spi->dev);
  613. dev_dbg(&md->spi->dev, "%s\n", __func__);
  614. omap_dss_unregister_driver(&acx_panel_driver);
  615. return 0;
  616. }
  617. static struct spi_driver acx565akm_spi_driver = {
  618. .driver = {
  619. .name = "acx565akm",
  620. .owner = THIS_MODULE,
  621. },
  622. .probe = acx565akm_spi_probe,
  623. .remove = acx565akm_spi_remove,
  624. };
  625. module_spi_driver(acx565akm_spi_driver);
  626. MODULE_AUTHOR("Nokia Corporation");
  627. MODULE_DESCRIPTION("acx565akm LCD Driver");
  628. MODULE_LICENSE("GPL");