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