panel-sony-acx565akm.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917
  1. /*
  2. * Sony ACX565AKM LCD Panel driver
  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 <linux/gpio.h>
  32. #include <linux/of.h>
  33. #include <linux/of_gpio.h>
  34. #include <video/omapdss.h>
  35. #include <video/omap-panel-data.h>
  36. #define MIPID_CMD_READ_DISP_ID 0x04
  37. #define MIPID_CMD_READ_RED 0x06
  38. #define MIPID_CMD_READ_GREEN 0x07
  39. #define MIPID_CMD_READ_BLUE 0x08
  40. #define MIPID_CMD_READ_DISP_STATUS 0x09
  41. #define MIPID_CMD_RDDSDR 0x0F
  42. #define MIPID_CMD_SLEEP_IN 0x10
  43. #define MIPID_CMD_SLEEP_OUT 0x11
  44. #define MIPID_CMD_DISP_OFF 0x28
  45. #define MIPID_CMD_DISP_ON 0x29
  46. #define MIPID_CMD_WRITE_DISP_BRIGHTNESS 0x51
  47. #define MIPID_CMD_READ_DISP_BRIGHTNESS 0x52
  48. #define MIPID_CMD_WRITE_CTRL_DISP 0x53
  49. #define CTRL_DISP_BRIGHTNESS_CTRL_ON (1 << 5)
  50. #define CTRL_DISP_AMBIENT_LIGHT_CTRL_ON (1 << 4)
  51. #define CTRL_DISP_BACKLIGHT_ON (1 << 2)
  52. #define CTRL_DISP_AUTO_BRIGHTNESS_ON (1 << 1)
  53. #define MIPID_CMD_READ_CTRL_DISP 0x54
  54. #define MIPID_CMD_WRITE_CABC 0x55
  55. #define MIPID_CMD_READ_CABC 0x56
  56. #define MIPID_VER_LPH8923 3
  57. #define MIPID_VER_LS041Y3 4
  58. #define MIPID_VER_L4F00311 8
  59. #define MIPID_VER_ACX565AKM 9
  60. struct panel_drv_data {
  61. struct omap_dss_device dssdev;
  62. struct omap_dss_device *in;
  63. int reset_gpio;
  64. int datapairs;
  65. struct omap_video_timings videomode;
  66. char *name;
  67. int enabled;
  68. int model;
  69. int revision;
  70. u8 display_id[3];
  71. unsigned has_bc:1;
  72. unsigned has_cabc:1;
  73. unsigned cabc_mode;
  74. unsigned long hw_guard_end; /* next value of jiffies
  75. when we can issue the
  76. next sleep in/out command */
  77. unsigned long hw_guard_wait; /* max guard time in jiffies */
  78. struct spi_device *spi;
  79. struct mutex mutex;
  80. struct backlight_device *bl_dev;
  81. };
  82. static const struct omap_video_timings acx565akm_panel_timings = {
  83. .x_res = 800,
  84. .y_res = 480,
  85. .pixelclock = 24000000,
  86. .hfp = 28,
  87. .hsw = 4,
  88. .hbp = 24,
  89. .vfp = 3,
  90. .vsw = 3,
  91. .vbp = 4,
  92. .vsync_level = OMAPDSS_SIG_ACTIVE_LOW,
  93. .hsync_level = OMAPDSS_SIG_ACTIVE_LOW,
  94. .data_pclk_edge = OMAPDSS_DRIVE_SIG_RISING_EDGE,
  95. .de_level = OMAPDSS_SIG_ACTIVE_HIGH,
  96. .sync_pclk_edge = OMAPDSS_DRIVE_SIG_OPPOSITE_EDGES,
  97. };
  98. #define to_panel_data(p) container_of(p, struct panel_drv_data, dssdev)
  99. static void acx565akm_transfer(struct panel_drv_data *ddata, int cmd,
  100. const u8 *wbuf, int wlen, u8 *rbuf, int rlen)
  101. {
  102. struct spi_message m;
  103. struct spi_transfer *x, xfer[5];
  104. int r;
  105. BUG_ON(ddata->spi == NULL);
  106. spi_message_init(&m);
  107. memset(xfer, 0, sizeof(xfer));
  108. x = &xfer[0];
  109. cmd &= 0xff;
  110. x->tx_buf = &cmd;
  111. x->bits_per_word = 9;
  112. x->len = 2;
  113. if (rlen > 1 && wlen == 0) {
  114. /*
  115. * Between the command and the response data there is a
  116. * dummy clock cycle. Add an extra bit after the command
  117. * word to account for this.
  118. */
  119. x->bits_per_word = 10;
  120. cmd <<= 1;
  121. }
  122. spi_message_add_tail(x, &m);
  123. if (wlen) {
  124. x++;
  125. x->tx_buf = wbuf;
  126. x->len = wlen;
  127. x->bits_per_word = 9;
  128. spi_message_add_tail(x, &m);
  129. }
  130. if (rlen) {
  131. x++;
  132. x->rx_buf = rbuf;
  133. x->len = rlen;
  134. spi_message_add_tail(x, &m);
  135. }
  136. r = spi_sync(ddata->spi, &m);
  137. if (r < 0)
  138. dev_dbg(&ddata->spi->dev, "spi_sync %d\n", r);
  139. }
  140. static inline void acx565akm_cmd(struct panel_drv_data *ddata, int cmd)
  141. {
  142. acx565akm_transfer(ddata, cmd, NULL, 0, NULL, 0);
  143. }
  144. static inline void acx565akm_write(struct panel_drv_data *ddata,
  145. int reg, const u8 *buf, int len)
  146. {
  147. acx565akm_transfer(ddata, reg, buf, len, NULL, 0);
  148. }
  149. static inline void acx565akm_read(struct panel_drv_data *ddata,
  150. int reg, u8 *buf, int len)
  151. {
  152. acx565akm_transfer(ddata, reg, NULL, 0, buf, len);
  153. }
  154. static void hw_guard_start(struct panel_drv_data *ddata, int guard_msec)
  155. {
  156. ddata->hw_guard_wait = msecs_to_jiffies(guard_msec);
  157. ddata->hw_guard_end = jiffies + ddata->hw_guard_wait;
  158. }
  159. static void hw_guard_wait(struct panel_drv_data *ddata)
  160. {
  161. unsigned long wait = ddata->hw_guard_end - jiffies;
  162. if ((long)wait > 0 && wait <= ddata->hw_guard_wait) {
  163. set_current_state(TASK_UNINTERRUPTIBLE);
  164. schedule_timeout(wait);
  165. }
  166. }
  167. static void set_sleep_mode(struct panel_drv_data *ddata, int on)
  168. {
  169. int cmd;
  170. if (on)
  171. cmd = MIPID_CMD_SLEEP_IN;
  172. else
  173. cmd = MIPID_CMD_SLEEP_OUT;
  174. /*
  175. * We have to keep 120msec between sleep in/out commands.
  176. * (8.2.15, 8.2.16).
  177. */
  178. hw_guard_wait(ddata);
  179. acx565akm_cmd(ddata, cmd);
  180. hw_guard_start(ddata, 120);
  181. }
  182. static void set_display_state(struct panel_drv_data *ddata, int enabled)
  183. {
  184. int cmd = enabled ? MIPID_CMD_DISP_ON : MIPID_CMD_DISP_OFF;
  185. acx565akm_cmd(ddata, cmd);
  186. }
  187. static int panel_enabled(struct panel_drv_data *ddata)
  188. {
  189. u32 disp_status;
  190. int enabled;
  191. acx565akm_read(ddata, MIPID_CMD_READ_DISP_STATUS,
  192. (u8 *)&disp_status, 4);
  193. disp_status = __be32_to_cpu(disp_status);
  194. enabled = (disp_status & (1 << 17)) && (disp_status & (1 << 10));
  195. dev_dbg(&ddata->spi->dev,
  196. "LCD panel %senabled by bootloader (status 0x%04x)\n",
  197. enabled ? "" : "not ", disp_status);
  198. return enabled;
  199. }
  200. static int panel_detect(struct panel_drv_data *ddata)
  201. {
  202. acx565akm_read(ddata, MIPID_CMD_READ_DISP_ID, ddata->display_id, 3);
  203. dev_dbg(&ddata->spi->dev, "MIPI display ID: %02x%02x%02x\n",
  204. ddata->display_id[0],
  205. ddata->display_id[1],
  206. ddata->display_id[2]);
  207. switch (ddata->display_id[0]) {
  208. case 0x10:
  209. ddata->model = MIPID_VER_ACX565AKM;
  210. ddata->name = "acx565akm";
  211. ddata->has_bc = 1;
  212. ddata->has_cabc = 1;
  213. break;
  214. case 0x29:
  215. ddata->model = MIPID_VER_L4F00311;
  216. ddata->name = "l4f00311";
  217. break;
  218. case 0x45:
  219. ddata->model = MIPID_VER_LPH8923;
  220. ddata->name = "lph8923";
  221. break;
  222. case 0x83:
  223. ddata->model = MIPID_VER_LS041Y3;
  224. ddata->name = "ls041y3";
  225. break;
  226. default:
  227. ddata->name = "unknown";
  228. dev_err(&ddata->spi->dev, "invalid display ID\n");
  229. return -ENODEV;
  230. }
  231. ddata->revision = ddata->display_id[1];
  232. dev_info(&ddata->spi->dev, "omapfb: %s rev %02x LCD detected\n",
  233. ddata->name, ddata->revision);
  234. return 0;
  235. }
  236. /*----------------------Backlight Control-------------------------*/
  237. static void enable_backlight_ctrl(struct panel_drv_data *ddata, int enable)
  238. {
  239. u16 ctrl;
  240. acx565akm_read(ddata, MIPID_CMD_READ_CTRL_DISP, (u8 *)&ctrl, 1);
  241. if (enable) {
  242. ctrl |= CTRL_DISP_BRIGHTNESS_CTRL_ON |
  243. CTRL_DISP_BACKLIGHT_ON;
  244. } else {
  245. ctrl &= ~(CTRL_DISP_BRIGHTNESS_CTRL_ON |
  246. CTRL_DISP_BACKLIGHT_ON);
  247. }
  248. ctrl |= 1 << 8;
  249. acx565akm_write(ddata, MIPID_CMD_WRITE_CTRL_DISP, (u8 *)&ctrl, 2);
  250. }
  251. static void set_cabc_mode(struct panel_drv_data *ddata, unsigned mode)
  252. {
  253. u16 cabc_ctrl;
  254. ddata->cabc_mode = mode;
  255. if (!ddata->enabled)
  256. return;
  257. cabc_ctrl = 0;
  258. acx565akm_read(ddata, MIPID_CMD_READ_CABC, (u8 *)&cabc_ctrl, 1);
  259. cabc_ctrl &= ~3;
  260. cabc_ctrl |= (1 << 8) | (mode & 3);
  261. acx565akm_write(ddata, MIPID_CMD_WRITE_CABC, (u8 *)&cabc_ctrl, 2);
  262. }
  263. static unsigned get_cabc_mode(struct panel_drv_data *ddata)
  264. {
  265. return ddata->cabc_mode;
  266. }
  267. static unsigned get_hw_cabc_mode(struct panel_drv_data *ddata)
  268. {
  269. u8 cabc_ctrl;
  270. acx565akm_read(ddata, MIPID_CMD_READ_CABC, &cabc_ctrl, 1);
  271. return cabc_ctrl & 3;
  272. }
  273. static void acx565akm_set_brightness(struct panel_drv_data *ddata, int level)
  274. {
  275. int bv;
  276. bv = level | (1 << 8);
  277. acx565akm_write(ddata, MIPID_CMD_WRITE_DISP_BRIGHTNESS, (u8 *)&bv, 2);
  278. if (level)
  279. enable_backlight_ctrl(ddata, 1);
  280. else
  281. enable_backlight_ctrl(ddata, 0);
  282. }
  283. static int acx565akm_get_actual_brightness(struct panel_drv_data *ddata)
  284. {
  285. u8 bv;
  286. acx565akm_read(ddata, MIPID_CMD_READ_DISP_BRIGHTNESS, &bv, 1);
  287. return bv;
  288. }
  289. static int acx565akm_bl_update_status(struct backlight_device *dev)
  290. {
  291. struct panel_drv_data *ddata = dev_get_drvdata(&dev->dev);
  292. int level;
  293. dev_dbg(&ddata->spi->dev, "%s\n", __func__);
  294. if (dev->props.fb_blank == FB_BLANK_UNBLANK &&
  295. dev->props.power == FB_BLANK_UNBLANK)
  296. level = dev->props.brightness;
  297. else
  298. level = 0;
  299. if (ddata->has_bc)
  300. acx565akm_set_brightness(ddata, level);
  301. else
  302. return -ENODEV;
  303. return 0;
  304. }
  305. static int acx565akm_bl_get_intensity(struct backlight_device *dev)
  306. {
  307. struct panel_drv_data *ddata = dev_get_drvdata(&dev->dev);
  308. dev_dbg(&dev->dev, "%s\n", __func__);
  309. if (!ddata->has_bc)
  310. return -ENODEV;
  311. if (dev->props.fb_blank == FB_BLANK_UNBLANK &&
  312. dev->props.power == FB_BLANK_UNBLANK) {
  313. if (ddata->has_bc)
  314. return acx565akm_get_actual_brightness(ddata);
  315. else
  316. return dev->props.brightness;
  317. }
  318. return 0;
  319. }
  320. static int acx565akm_bl_update_status_locked(struct backlight_device *dev)
  321. {
  322. struct panel_drv_data *ddata = dev_get_drvdata(&dev->dev);
  323. int r;
  324. mutex_lock(&ddata->mutex);
  325. r = acx565akm_bl_update_status(dev);
  326. mutex_unlock(&ddata->mutex);
  327. return r;
  328. }
  329. static int acx565akm_bl_get_intensity_locked(struct backlight_device *dev)
  330. {
  331. struct panel_drv_data *ddata = dev_get_drvdata(&dev->dev);
  332. int r;
  333. mutex_lock(&ddata->mutex);
  334. r = acx565akm_bl_get_intensity(dev);
  335. mutex_unlock(&ddata->mutex);
  336. return r;
  337. }
  338. static const struct backlight_ops acx565akm_bl_ops = {
  339. .get_brightness = acx565akm_bl_get_intensity_locked,
  340. .update_status = acx565akm_bl_update_status_locked,
  341. };
  342. /*--------------------Auto Brightness control via Sysfs---------------------*/
  343. static const char * const cabc_modes[] = {
  344. "off", /* always used when CABC is not supported */
  345. "ui",
  346. "still-image",
  347. "moving-image",
  348. };
  349. static ssize_t show_cabc_mode(struct device *dev,
  350. struct device_attribute *attr,
  351. char *buf)
  352. {
  353. struct panel_drv_data *ddata = dev_get_drvdata(dev);
  354. const char *mode_str;
  355. int mode;
  356. int len;
  357. if (!ddata->has_cabc)
  358. mode = 0;
  359. else
  360. mode = get_cabc_mode(ddata);
  361. mode_str = "unknown";
  362. if (mode >= 0 && mode < ARRAY_SIZE(cabc_modes))
  363. mode_str = cabc_modes[mode];
  364. len = snprintf(buf, PAGE_SIZE, "%s\n", mode_str);
  365. return len < PAGE_SIZE - 1 ? len : PAGE_SIZE - 1;
  366. }
  367. static ssize_t store_cabc_mode(struct device *dev,
  368. struct device_attribute *attr,
  369. const char *buf, size_t count)
  370. {
  371. struct panel_drv_data *ddata = dev_get_drvdata(dev);
  372. int i;
  373. for (i = 0; i < ARRAY_SIZE(cabc_modes); i++) {
  374. const char *mode_str = cabc_modes[i];
  375. int cmp_len = strlen(mode_str);
  376. if (count > 0 && buf[count - 1] == '\n')
  377. count--;
  378. if (count != cmp_len)
  379. continue;
  380. if (strncmp(buf, mode_str, cmp_len) == 0)
  381. break;
  382. }
  383. if (i == ARRAY_SIZE(cabc_modes))
  384. return -EINVAL;
  385. if (!ddata->has_cabc && i != 0)
  386. return -EINVAL;
  387. mutex_lock(&ddata->mutex);
  388. set_cabc_mode(ddata, i);
  389. mutex_unlock(&ddata->mutex);
  390. return count;
  391. }
  392. static ssize_t show_cabc_available_modes(struct device *dev,
  393. struct device_attribute *attr,
  394. char *buf)
  395. {
  396. struct panel_drv_data *ddata = dev_get_drvdata(dev);
  397. int len;
  398. int i;
  399. if (!ddata->has_cabc)
  400. return snprintf(buf, PAGE_SIZE, "%s\n", cabc_modes[0]);
  401. for (i = 0, len = 0;
  402. len < PAGE_SIZE && i < ARRAY_SIZE(cabc_modes); i++)
  403. len += snprintf(&buf[len], PAGE_SIZE - len, "%s%s%s",
  404. i ? " " : "", cabc_modes[i],
  405. i == ARRAY_SIZE(cabc_modes) - 1 ? "\n" : "");
  406. return len < PAGE_SIZE ? len : PAGE_SIZE - 1;
  407. }
  408. static DEVICE_ATTR(cabc_mode, S_IRUGO | S_IWUSR,
  409. show_cabc_mode, store_cabc_mode);
  410. static DEVICE_ATTR(cabc_available_modes, S_IRUGO,
  411. show_cabc_available_modes, NULL);
  412. static struct attribute *bldev_attrs[] = {
  413. &dev_attr_cabc_mode.attr,
  414. &dev_attr_cabc_available_modes.attr,
  415. NULL,
  416. };
  417. static struct attribute_group bldev_attr_group = {
  418. .attrs = bldev_attrs,
  419. };
  420. static int acx565akm_connect(struct omap_dss_device *dssdev)
  421. {
  422. struct panel_drv_data *ddata = to_panel_data(dssdev);
  423. struct omap_dss_device *in = ddata->in;
  424. int r;
  425. if (omapdss_device_is_connected(dssdev))
  426. return 0;
  427. r = in->ops.sdi->connect(in, dssdev);
  428. if (r)
  429. return r;
  430. return 0;
  431. }
  432. static void acx565akm_disconnect(struct omap_dss_device *dssdev)
  433. {
  434. struct panel_drv_data *ddata = to_panel_data(dssdev);
  435. struct omap_dss_device *in = ddata->in;
  436. if (!omapdss_device_is_connected(dssdev))
  437. return;
  438. in->ops.sdi->disconnect(in, dssdev);
  439. }
  440. static int acx565akm_panel_power_on(struct omap_dss_device *dssdev)
  441. {
  442. struct panel_drv_data *ddata = to_panel_data(dssdev);
  443. struct omap_dss_device *in = ddata->in;
  444. int r;
  445. dev_dbg(&ddata->spi->dev, "%s\n", __func__);
  446. in->ops.sdi->set_timings(in, &ddata->videomode);
  447. if (ddata->datapairs > 0)
  448. in->ops.sdi->set_datapairs(in, ddata->datapairs);
  449. r = in->ops.sdi->enable(in);
  450. if (r) {
  451. pr_err("%s sdi enable failed\n", __func__);
  452. return r;
  453. }
  454. /*FIXME tweak me */
  455. msleep(50);
  456. if (gpio_is_valid(ddata->reset_gpio))
  457. gpio_set_value(ddata->reset_gpio, 1);
  458. if (ddata->enabled) {
  459. dev_dbg(&ddata->spi->dev, "panel already enabled\n");
  460. return 0;
  461. }
  462. /*
  463. * We have to meet all the following delay requirements:
  464. * 1. tRW: reset pulse width 10usec (7.12.1)
  465. * 2. tRT: reset cancel time 5msec (7.12.1)
  466. * 3. Providing PCLK,HS,VS signals for 2 frames = ~50msec worst
  467. * case (7.6.2)
  468. * 4. 120msec before the sleep out command (7.12.1)
  469. */
  470. msleep(120);
  471. set_sleep_mode(ddata, 0);
  472. ddata->enabled = 1;
  473. /* 5msec between sleep out and the next command. (8.2.16) */
  474. usleep_range(5000, 10000);
  475. set_display_state(ddata, 1);
  476. set_cabc_mode(ddata, ddata->cabc_mode);
  477. return acx565akm_bl_update_status(ddata->bl_dev);
  478. }
  479. static void acx565akm_panel_power_off(struct omap_dss_device *dssdev)
  480. {
  481. struct panel_drv_data *ddata = to_panel_data(dssdev);
  482. struct omap_dss_device *in = ddata->in;
  483. dev_dbg(dssdev->dev, "%s\n", __func__);
  484. if (!ddata->enabled)
  485. return;
  486. set_display_state(ddata, 0);
  487. set_sleep_mode(ddata, 1);
  488. ddata->enabled = 0;
  489. /*
  490. * We have to provide PCLK,HS,VS signals for 2 frames (worst case
  491. * ~50msec) after sending the sleep in command and asserting the
  492. * reset signal. We probably could assert the reset w/o the delay
  493. * but we still delay to avoid possible artifacts. (7.6.1)
  494. */
  495. msleep(50);
  496. if (gpio_is_valid(ddata->reset_gpio))
  497. gpio_set_value(ddata->reset_gpio, 0);
  498. /* FIXME need to tweak this delay */
  499. msleep(100);
  500. in->ops.sdi->disable(in);
  501. }
  502. static int acx565akm_enable(struct omap_dss_device *dssdev)
  503. {
  504. struct panel_drv_data *ddata = to_panel_data(dssdev);
  505. int r;
  506. dev_dbg(dssdev->dev, "%s\n", __func__);
  507. if (!omapdss_device_is_connected(dssdev))
  508. return -ENODEV;
  509. if (omapdss_device_is_enabled(dssdev))
  510. return 0;
  511. mutex_lock(&ddata->mutex);
  512. r = acx565akm_panel_power_on(dssdev);
  513. mutex_unlock(&ddata->mutex);
  514. if (r)
  515. return r;
  516. dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
  517. return 0;
  518. }
  519. static void acx565akm_disable(struct omap_dss_device *dssdev)
  520. {
  521. struct panel_drv_data *ddata = to_panel_data(dssdev);
  522. dev_dbg(dssdev->dev, "%s\n", __func__);
  523. if (!omapdss_device_is_enabled(dssdev))
  524. return;
  525. mutex_lock(&ddata->mutex);
  526. acx565akm_panel_power_off(dssdev);
  527. mutex_unlock(&ddata->mutex);
  528. dssdev->state = OMAP_DSS_DISPLAY_DISABLED;
  529. }
  530. static void acx565akm_set_timings(struct omap_dss_device *dssdev,
  531. struct omap_video_timings *timings)
  532. {
  533. struct panel_drv_data *ddata = to_panel_data(dssdev);
  534. struct omap_dss_device *in = ddata->in;
  535. ddata->videomode = *timings;
  536. dssdev->panel.timings = *timings;
  537. in->ops.sdi->set_timings(in, timings);
  538. }
  539. static void acx565akm_get_timings(struct omap_dss_device *dssdev,
  540. struct omap_video_timings *timings)
  541. {
  542. struct panel_drv_data *ddata = to_panel_data(dssdev);
  543. *timings = ddata->videomode;
  544. }
  545. static int acx565akm_check_timings(struct omap_dss_device *dssdev,
  546. struct omap_video_timings *timings)
  547. {
  548. struct panel_drv_data *ddata = to_panel_data(dssdev);
  549. struct omap_dss_device *in = ddata->in;
  550. return in->ops.sdi->check_timings(in, timings);
  551. }
  552. static struct omap_dss_driver acx565akm_ops = {
  553. .connect = acx565akm_connect,
  554. .disconnect = acx565akm_disconnect,
  555. .enable = acx565akm_enable,
  556. .disable = acx565akm_disable,
  557. .set_timings = acx565akm_set_timings,
  558. .get_timings = acx565akm_get_timings,
  559. .check_timings = acx565akm_check_timings,
  560. .get_resolution = omapdss_default_get_resolution,
  561. };
  562. static int acx565akm_probe_pdata(struct spi_device *spi)
  563. {
  564. const struct panel_acx565akm_platform_data *pdata;
  565. struct panel_drv_data *ddata = dev_get_drvdata(&spi->dev);
  566. struct omap_dss_device *dssdev, *in;
  567. pdata = dev_get_platdata(&spi->dev);
  568. ddata->reset_gpio = pdata->reset_gpio;
  569. in = omap_dss_find_output(pdata->source);
  570. if (in == NULL) {
  571. dev_err(&spi->dev, "failed to find video source '%s'\n",
  572. pdata->source);
  573. return -EPROBE_DEFER;
  574. }
  575. ddata->in = in;
  576. ddata->datapairs = pdata->datapairs;
  577. dssdev = &ddata->dssdev;
  578. dssdev->name = pdata->name;
  579. return 0;
  580. }
  581. static int acx565akm_probe_of(struct spi_device *spi)
  582. {
  583. struct panel_drv_data *ddata = dev_get_drvdata(&spi->dev);
  584. struct device_node *np = spi->dev.of_node;
  585. ddata->reset_gpio = of_get_named_gpio(np, "reset-gpios", 0);
  586. ddata->in = omapdss_of_find_source_for_first_ep(np);
  587. if (IS_ERR(ddata->in)) {
  588. dev_err(&spi->dev, "failed to find video source\n");
  589. return PTR_ERR(ddata->in);
  590. }
  591. return 0;
  592. }
  593. static int acx565akm_probe(struct spi_device *spi)
  594. {
  595. struct panel_drv_data *ddata;
  596. struct omap_dss_device *dssdev;
  597. struct backlight_device *bldev;
  598. int max_brightness, brightness;
  599. struct backlight_properties props;
  600. int r;
  601. dev_dbg(&spi->dev, "%s\n", __func__);
  602. spi->mode = SPI_MODE_3;
  603. ddata = devm_kzalloc(&spi->dev, sizeof(*ddata), GFP_KERNEL);
  604. if (ddata == NULL)
  605. return -ENOMEM;
  606. dev_set_drvdata(&spi->dev, ddata);
  607. ddata->spi = spi;
  608. mutex_init(&ddata->mutex);
  609. if (dev_get_platdata(&spi->dev)) {
  610. r = acx565akm_probe_pdata(spi);
  611. if (r)
  612. return r;
  613. } else if (spi->dev.of_node) {
  614. r = acx565akm_probe_of(spi);
  615. if (r)
  616. return r;
  617. } else {
  618. dev_err(&spi->dev, "platform data missing!\n");
  619. return -ENODEV;
  620. }
  621. if (gpio_is_valid(ddata->reset_gpio)) {
  622. r = devm_gpio_request_one(&spi->dev, ddata->reset_gpio,
  623. GPIOF_OUT_INIT_LOW, "lcd reset");
  624. if (r)
  625. goto err_gpio;
  626. }
  627. if (gpio_is_valid(ddata->reset_gpio))
  628. gpio_set_value(ddata->reset_gpio, 1);
  629. /*
  630. * After reset we have to wait 5 msec before the first
  631. * command can be sent.
  632. */
  633. usleep_range(5000, 10000);
  634. ddata->enabled = panel_enabled(ddata);
  635. r = panel_detect(ddata);
  636. if (!ddata->enabled && gpio_is_valid(ddata->reset_gpio))
  637. gpio_set_value(ddata->reset_gpio, 0);
  638. if (r) {
  639. dev_err(&spi->dev, "%s panel detect error\n", __func__);
  640. goto err_detect;
  641. }
  642. memset(&props, 0, sizeof(props));
  643. props.fb_blank = FB_BLANK_UNBLANK;
  644. props.power = FB_BLANK_UNBLANK;
  645. props.type = BACKLIGHT_RAW;
  646. bldev = backlight_device_register("acx565akm", &ddata->spi->dev,
  647. ddata, &acx565akm_bl_ops, &props);
  648. if (IS_ERR(bldev)) {
  649. r = PTR_ERR(bldev);
  650. goto err_reg_bl;
  651. }
  652. ddata->bl_dev = bldev;
  653. if (ddata->has_cabc) {
  654. r = sysfs_create_group(&bldev->dev.kobj, &bldev_attr_group);
  655. if (r) {
  656. dev_err(&bldev->dev,
  657. "%s failed to create sysfs files\n", __func__);
  658. goto err_sysfs;
  659. }
  660. ddata->cabc_mode = get_hw_cabc_mode(ddata);
  661. }
  662. max_brightness = 255;
  663. if (ddata->has_bc)
  664. brightness = acx565akm_get_actual_brightness(ddata);
  665. else
  666. brightness = 0;
  667. bldev->props.max_brightness = max_brightness;
  668. bldev->props.brightness = brightness;
  669. acx565akm_bl_update_status(bldev);
  670. ddata->videomode = acx565akm_panel_timings;
  671. dssdev = &ddata->dssdev;
  672. dssdev->dev = &spi->dev;
  673. dssdev->driver = &acx565akm_ops;
  674. dssdev->type = OMAP_DISPLAY_TYPE_SDI;
  675. dssdev->owner = THIS_MODULE;
  676. dssdev->panel.timings = ddata->videomode;
  677. r = omapdss_register_display(dssdev);
  678. if (r) {
  679. dev_err(&spi->dev, "Failed to register panel\n");
  680. goto err_reg;
  681. }
  682. return 0;
  683. err_reg:
  684. sysfs_remove_group(&bldev->dev.kobj, &bldev_attr_group);
  685. err_sysfs:
  686. backlight_device_unregister(bldev);
  687. err_reg_bl:
  688. err_detect:
  689. err_gpio:
  690. omap_dss_put_device(ddata->in);
  691. return r;
  692. }
  693. static int acx565akm_remove(struct spi_device *spi)
  694. {
  695. struct panel_drv_data *ddata = dev_get_drvdata(&spi->dev);
  696. struct omap_dss_device *dssdev = &ddata->dssdev;
  697. struct omap_dss_device *in = ddata->in;
  698. dev_dbg(&ddata->spi->dev, "%s\n", __func__);
  699. sysfs_remove_group(&ddata->bl_dev->dev.kobj, &bldev_attr_group);
  700. backlight_device_unregister(ddata->bl_dev);
  701. omapdss_unregister_display(dssdev);
  702. acx565akm_disable(dssdev);
  703. acx565akm_disconnect(dssdev);
  704. omap_dss_put_device(in);
  705. return 0;
  706. }
  707. static const struct of_device_id acx565akm_of_match[] = {
  708. { .compatible = "omapdss,sony,acx565akm", },
  709. {},
  710. };
  711. static struct spi_driver acx565akm_driver = {
  712. .driver = {
  713. .name = "acx565akm",
  714. .owner = THIS_MODULE,
  715. .of_match_table = acx565akm_of_match,
  716. .suppress_bind_attrs = true,
  717. },
  718. .probe = acx565akm_probe,
  719. .remove = acx565akm_remove,
  720. };
  721. module_spi_driver(acx565akm_driver);
  722. MODULE_AUTHOR("Nokia Corporation");
  723. MODULE_DESCRIPTION("acx565akm LCD Driver");
  724. MODULE_LICENSE("GPL");