panel-acx565akm.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828
  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 <plat/display.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. };
  400. static int acx_panel_probe(struct omap_dss_device *dssdev)
  401. {
  402. int r;
  403. struct acx565akm_device *md = &acx_dev;
  404. struct backlight_device *bldev;
  405. int max_brightness, brightness;
  406. struct backlight_properties props;
  407. dev_dbg(&dssdev->dev, "%s\n", __func__);
  408. dssdev->panel.config = OMAP_DSS_LCD_TFT | OMAP_DSS_LCD_IVS |
  409. OMAP_DSS_LCD_IHS;
  410. /* FIXME AC bias ? */
  411. dssdev->panel.timings = acx_panel_timings;
  412. if (dssdev->platform_enable)
  413. dssdev->platform_enable(dssdev);
  414. /*
  415. * After reset we have to wait 5 msec before the first
  416. * command can be sent.
  417. */
  418. msleep(5);
  419. md->enabled = panel_enabled(md);
  420. r = panel_detect(md);
  421. if (r) {
  422. dev_err(&dssdev->dev, "%s panel detect error\n", __func__);
  423. if (!md->enabled && dssdev->platform_disable)
  424. dssdev->platform_disable(dssdev);
  425. return r;
  426. }
  427. mutex_lock(&acx_dev.mutex);
  428. acx_dev.dssdev = dssdev;
  429. mutex_unlock(&acx_dev.mutex);
  430. if (!md->enabled) {
  431. if (dssdev->platform_disable)
  432. dssdev->platform_disable(dssdev);
  433. }
  434. /*------- Backlight control --------*/
  435. props.fb_blank = FB_BLANK_UNBLANK;
  436. props.power = FB_BLANK_UNBLANK;
  437. props.type = BACKLIGHT_RAW;
  438. bldev = backlight_device_register("acx565akm", &md->spi->dev,
  439. md, &acx565akm_bl_ops, &props);
  440. md->bl_dev = bldev;
  441. if (md->has_cabc) {
  442. r = sysfs_create_group(&bldev->dev.kobj, &bldev_attr_group);
  443. if (r) {
  444. dev_err(&bldev->dev,
  445. "%s failed to create sysfs files\n", __func__);
  446. backlight_device_unregister(bldev);
  447. return r;
  448. }
  449. md->cabc_mode = get_hw_cabc_mode(md);
  450. }
  451. if (md->has_bc)
  452. max_brightness = 255;
  453. else
  454. max_brightness = dssdev->max_backlight_level;
  455. if (md->has_bc)
  456. brightness = acx565akm_get_actual_brightness(md);
  457. else if (dssdev->get_backlight)
  458. brightness = dssdev->get_backlight(dssdev);
  459. else
  460. brightness = 0;
  461. bldev->props.max_brightness = max_brightness;
  462. bldev->props.brightness = brightness;
  463. acx565akm_bl_update_status(bldev);
  464. return 0;
  465. }
  466. static void acx_panel_remove(struct omap_dss_device *dssdev)
  467. {
  468. struct acx565akm_device *md = &acx_dev;
  469. dev_dbg(&dssdev->dev, "%s\n", __func__);
  470. sysfs_remove_group(&md->bl_dev->dev.kobj, &bldev_attr_group);
  471. backlight_device_unregister(md->bl_dev);
  472. mutex_lock(&acx_dev.mutex);
  473. acx_dev.dssdev = NULL;
  474. mutex_unlock(&acx_dev.mutex);
  475. }
  476. static int acx_panel_power_on(struct omap_dss_device *dssdev)
  477. {
  478. struct acx565akm_device *md = &acx_dev;
  479. int r;
  480. dev_dbg(&dssdev->dev, "%s\n", __func__);
  481. if (dssdev->state == OMAP_DSS_DISPLAY_ACTIVE)
  482. return 0;
  483. mutex_lock(&md->mutex);
  484. r = omapdss_sdi_display_enable(dssdev);
  485. if (r) {
  486. pr_err("%s sdi enable failed\n", __func__);
  487. goto fail_unlock;
  488. }
  489. /*FIXME tweak me */
  490. msleep(50);
  491. if (dssdev->platform_enable) {
  492. r = dssdev->platform_enable(dssdev);
  493. if (r)
  494. goto fail;
  495. }
  496. if (md->enabled) {
  497. dev_dbg(&md->spi->dev, "panel already enabled\n");
  498. mutex_unlock(&md->mutex);
  499. return 0;
  500. }
  501. /*
  502. * We have to meet all the following delay requirements:
  503. * 1. tRW: reset pulse width 10usec (7.12.1)
  504. * 2. tRT: reset cancel time 5msec (7.12.1)
  505. * 3. Providing PCLK,HS,VS signals for 2 frames = ~50msec worst
  506. * case (7.6.2)
  507. * 4. 120msec before the sleep out command (7.12.1)
  508. */
  509. msleep(120);
  510. set_sleep_mode(md, 0);
  511. md->enabled = 1;
  512. /* 5msec between sleep out and the next command. (8.2.16) */
  513. msleep(5);
  514. set_display_state(md, 1);
  515. set_cabc_mode(md, md->cabc_mode);
  516. mutex_unlock(&md->mutex);
  517. return acx565akm_bl_update_status(md->bl_dev);
  518. fail:
  519. omapdss_sdi_display_disable(dssdev);
  520. fail_unlock:
  521. mutex_unlock(&md->mutex);
  522. return r;
  523. }
  524. static void acx_panel_power_off(struct omap_dss_device *dssdev)
  525. {
  526. struct acx565akm_device *md = &acx_dev;
  527. dev_dbg(&dssdev->dev, "%s\n", __func__);
  528. if (dssdev->state != OMAP_DSS_DISPLAY_ACTIVE)
  529. return;
  530. mutex_lock(&md->mutex);
  531. if (!md->enabled) {
  532. mutex_unlock(&md->mutex);
  533. return;
  534. }
  535. set_display_state(md, 0);
  536. set_sleep_mode(md, 1);
  537. md->enabled = 0;
  538. /*
  539. * We have to provide PCLK,HS,VS signals for 2 frames (worst case
  540. * ~50msec) after sending the sleep in command and asserting the
  541. * reset signal. We probably could assert the reset w/o the delay
  542. * but we still delay to avoid possible artifacts. (7.6.1)
  543. */
  544. msleep(50);
  545. if (dssdev->platform_disable)
  546. dssdev->platform_disable(dssdev);
  547. /* FIXME need to tweak this delay */
  548. msleep(100);
  549. omapdss_sdi_display_disable(dssdev);
  550. mutex_unlock(&md->mutex);
  551. }
  552. static int acx_panel_enable(struct omap_dss_device *dssdev)
  553. {
  554. int r;
  555. dev_dbg(&dssdev->dev, "%s\n", __func__);
  556. r = acx_panel_power_on(dssdev);
  557. if (r)
  558. return r;
  559. dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
  560. return 0;
  561. }
  562. static void acx_panel_disable(struct omap_dss_device *dssdev)
  563. {
  564. dev_dbg(&dssdev->dev, "%s\n", __func__);
  565. acx_panel_power_off(dssdev);
  566. dssdev->state = OMAP_DSS_DISPLAY_DISABLED;
  567. }
  568. static int acx_panel_suspend(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_SUSPENDED;
  573. return 0;
  574. }
  575. static int acx_panel_resume(struct omap_dss_device *dssdev)
  576. {
  577. int r;
  578. dev_dbg(&dssdev->dev, "%s\n", __func__);
  579. r = acx_panel_power_on(dssdev);
  580. if (r)
  581. return r;
  582. dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
  583. return 0;
  584. }
  585. static void acx_panel_set_timings(struct omap_dss_device *dssdev,
  586. struct omap_video_timings *timings)
  587. {
  588. int r;
  589. if (dssdev->state == OMAP_DSS_DISPLAY_ACTIVE)
  590. omapdss_sdi_display_disable(dssdev);
  591. dssdev->panel.timings = *timings;
  592. if (dssdev->state == OMAP_DSS_DISPLAY_ACTIVE) {
  593. r = omapdss_sdi_display_enable(dssdev);
  594. if (r)
  595. dev_err(&dssdev->dev, "%s enable failed\n", __func__);
  596. }
  597. }
  598. static void acx_panel_get_timings(struct omap_dss_device *dssdev,
  599. struct omap_video_timings *timings)
  600. {
  601. *timings = dssdev->panel.timings;
  602. }
  603. static int acx_panel_check_timings(struct omap_dss_device *dssdev,
  604. struct omap_video_timings *timings)
  605. {
  606. return 0;
  607. }
  608. static struct omap_dss_driver acx_panel_driver = {
  609. .probe = acx_panel_probe,
  610. .remove = acx_panel_remove,
  611. .enable = acx_panel_enable,
  612. .disable = acx_panel_disable,
  613. .suspend = acx_panel_suspend,
  614. .resume = acx_panel_resume,
  615. .set_timings = acx_panel_set_timings,
  616. .get_timings = acx_panel_get_timings,
  617. .check_timings = acx_panel_check_timings,
  618. .get_recommended_bpp = acx_get_recommended_bpp,
  619. .driver = {
  620. .name = "panel-acx565akm",
  621. .owner = THIS_MODULE,
  622. },
  623. };
  624. /*--------------------SPI probe-------------------------*/
  625. static int acx565akm_spi_probe(struct spi_device *spi)
  626. {
  627. struct acx565akm_device *md = &acx_dev;
  628. dev_dbg(&spi->dev, "%s\n", __func__);
  629. spi->mode = SPI_MODE_3;
  630. md->spi = spi;
  631. mutex_init(&md->mutex);
  632. dev_set_drvdata(&spi->dev, md);
  633. omap_dss_register_driver(&acx_panel_driver);
  634. return 0;
  635. }
  636. static int acx565akm_spi_remove(struct spi_device *spi)
  637. {
  638. struct acx565akm_device *md = dev_get_drvdata(&spi->dev);
  639. dev_dbg(&md->spi->dev, "%s\n", __func__);
  640. omap_dss_unregister_driver(&acx_panel_driver);
  641. return 0;
  642. }
  643. static struct spi_driver acx565akm_spi_driver = {
  644. .driver = {
  645. .name = "acx565akm",
  646. .bus = &spi_bus_type,
  647. .owner = THIS_MODULE,
  648. },
  649. .probe = acx565akm_spi_probe,
  650. .remove = __devexit_p(acx565akm_spi_remove),
  651. };
  652. static int __init acx565akm_init(void)
  653. {
  654. return spi_register_driver(&acx565akm_spi_driver);
  655. }
  656. static void __exit acx565akm_exit(void)
  657. {
  658. spi_unregister_driver(&acx565akm_spi_driver);
  659. }
  660. module_init(acx565akm_init);
  661. module_exit(acx565akm_exit);
  662. MODULE_AUTHOR("Nokia Corporation");
  663. MODULE_DESCRIPTION("acx565akm LCD Driver");
  664. MODULE_LICENSE("GPL");