panel-sony-acx565akm.c 18 KB

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