panel-sony-acx565akm.c 21 KB

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