Lines Matching +full:lcd +full:- +full:backlight
1 // SPDX-License-Identifier: GPL-2.0
3 * Sony ACX565AKM LCD Panel driver
7 * Based on the omapdrm-specific panel-sony-acx565akm driver
16 * - Update backlight support to use backlight_update_status() etc.
17 * - Use prepare/unprepare for the basic power on/off of the backligt
20 #include <linux/backlight.h>
52 struct backlight_device *backlight; member
75 static void acx565akm_transfer(struct acx565akm_panel *lcd, int cmd, in acx565akm_transfer() argument
88 x->tx_buf = &cmd; in acx565akm_transfer()
89 x->bits_per_word = 9; in acx565akm_transfer()
90 x->len = 2; in acx565akm_transfer()
98 x->bits_per_word = 10; in acx565akm_transfer()
105 x->tx_buf = wbuf; in acx565akm_transfer()
106 x->len = wlen; in acx565akm_transfer()
107 x->bits_per_word = 9; in acx565akm_transfer()
113 x->rx_buf = rbuf; in acx565akm_transfer()
114 x->len = rlen; in acx565akm_transfer()
118 ret = spi_sync(lcd->spi, &m); in acx565akm_transfer()
120 dev_dbg(&lcd->spi->dev, "spi_sync %d\n", ret); in acx565akm_transfer()
123 static inline void acx565akm_cmd(struct acx565akm_panel *lcd, int cmd) in acx565akm_cmd() argument
125 acx565akm_transfer(lcd, cmd, NULL, 0, NULL, 0); in acx565akm_cmd()
128 static inline void acx565akm_write(struct acx565akm_panel *lcd, in acx565akm_write() argument
131 acx565akm_transfer(lcd, reg, buf, len, NULL, 0); in acx565akm_write()
134 static inline void acx565akm_read(struct acx565akm_panel *lcd, in acx565akm_read() argument
137 acx565akm_transfer(lcd, reg, NULL, 0, buf, len); in acx565akm_read()
140 /* -----------------------------------------------------------------------------
144 static unsigned int acx565akm_get_cabc_mode(struct acx565akm_panel *lcd) in acx565akm_get_cabc_mode() argument
146 return lcd->cabc_mode; in acx565akm_get_cabc_mode()
149 static void acx565akm_set_cabc_mode(struct acx565akm_panel *lcd, in acx565akm_set_cabc_mode() argument
154 lcd->cabc_mode = mode; in acx565akm_set_cabc_mode()
155 if (!lcd->enabled) in acx565akm_set_cabc_mode()
158 acx565akm_read(lcd, MIPID_CMD_READ_CABC, (u8 *)&cabc_ctrl, 1); in acx565akm_set_cabc_mode()
161 acx565akm_write(lcd, MIPID_CMD_WRITE_CABC, (u8 *)&cabc_ctrl, 2); in acx565akm_set_cabc_mode()
164 static unsigned int acx565akm_get_hw_cabc_mode(struct acx565akm_panel *lcd) in acx565akm_get_hw_cabc_mode() argument
168 acx565akm_read(lcd, MIPID_CMD_READ_CABC, &cabc_ctrl, 1); in acx565akm_get_hw_cabc_mode()
175 "still-image",
176 "moving-image",
183 struct acx565akm_panel *lcd = dev_get_drvdata(dev); in cabc_mode_show() local
187 if (!lcd->has_cabc) in cabc_mode_show()
190 mode = acx565akm_get_cabc_mode(lcd); in cabc_mode_show()
203 struct acx565akm_panel *lcd = dev_get_drvdata(dev); in cabc_mode_store() local
210 if (count > 0 && buf[count - 1] == '\n') in cabc_mode_store()
211 count--; in cabc_mode_store()
220 return -EINVAL; in cabc_mode_store()
222 if (!lcd->has_cabc && i != 0) in cabc_mode_store()
223 return -EINVAL; in cabc_mode_store()
225 mutex_lock(&lcd->mutex); in cabc_mode_store()
226 acx565akm_set_cabc_mode(lcd, i); in cabc_mode_store()
227 mutex_unlock(&lcd->mutex); in cabc_mode_store()
236 struct acx565akm_panel *lcd = dev_get_drvdata(dev); in cabc_available_modes_show() local
240 if (!lcd->has_cabc) in cabc_available_modes_show()
265 /* -----------------------------------------------------------------------------
266 * Backlight Device
269 static int acx565akm_get_actual_brightness(struct acx565akm_panel *lcd) in acx565akm_get_actual_brightness() argument
273 acx565akm_read(lcd, MIPI_DCS_GET_DISPLAY_BRIGHTNESS, &bv, 1); in acx565akm_get_actual_brightness()
278 static void acx565akm_set_brightness(struct acx565akm_panel *lcd, int level) in acx565akm_set_brightness() argument
284 acx565akm_write(lcd, MIPI_DCS_SET_DISPLAY_BRIGHTNESS, (u8 *)&bv, 2); in acx565akm_set_brightness()
286 acx565akm_read(lcd, MIPI_DCS_GET_CONTROL_DISPLAY, (u8 *)&ctrl, 1); in acx565akm_set_brightness()
295 acx565akm_write(lcd, MIPI_DCS_WRITE_CONTROL_DISPLAY, (u8 *)&ctrl, 2); in acx565akm_set_brightness()
300 struct acx565akm_panel *lcd = dev_get_drvdata(&dev->dev); in acx565akm_bl_update_status_locked() local
303 acx565akm_set_brightness(lcd, level); in acx565akm_bl_update_status_locked()
310 struct acx565akm_panel *lcd = dev_get_drvdata(&dev->dev); in acx565akm_bl_update_status() local
313 mutex_lock(&lcd->mutex); in acx565akm_bl_update_status()
315 mutex_unlock(&lcd->mutex); in acx565akm_bl_update_status()
322 struct acx565akm_panel *lcd = dev_get_drvdata(&dev->dev); in acx565akm_bl_get_intensity() local
325 mutex_lock(&lcd->mutex); in acx565akm_bl_get_intensity()
328 intensity = acx565akm_get_actual_brightness(lcd); in acx565akm_bl_get_intensity()
332 mutex_unlock(&lcd->mutex); in acx565akm_bl_get_intensity()
342 static int acx565akm_backlight_init(struct acx565akm_panel *lcd) in acx565akm_backlight_init() argument
350 lcd->backlight = backlight_device_register(lcd->name, &lcd->spi->dev, in acx565akm_backlight_init()
351 lcd, &acx565akm_bl_ops, in acx565akm_backlight_init()
353 if (IS_ERR(lcd->backlight)) { in acx565akm_backlight_init()
354 ret = PTR_ERR(lcd->backlight); in acx565akm_backlight_init()
355 lcd->backlight = NULL; in acx565akm_backlight_init()
359 if (lcd->has_cabc) { in acx565akm_backlight_init()
360 ret = sysfs_create_group(&lcd->backlight->dev.kobj, in acx565akm_backlight_init()
363 dev_err(&lcd->spi->dev, in acx565akm_backlight_init()
365 backlight_device_unregister(lcd->backlight); in acx565akm_backlight_init()
369 lcd->cabc_mode = acx565akm_get_hw_cabc_mode(lcd); in acx565akm_backlight_init()
372 lcd->backlight->props.max_brightness = 255; in acx565akm_backlight_init()
373 lcd->backlight->props.brightness = acx565akm_get_actual_brightness(lcd); in acx565akm_backlight_init()
375 acx565akm_bl_update_status_locked(lcd->backlight); in acx565akm_backlight_init()
380 static void acx565akm_backlight_cleanup(struct acx565akm_panel *lcd) in acx565akm_backlight_cleanup() argument
382 if (lcd->has_cabc) in acx565akm_backlight_cleanup()
383 sysfs_remove_group(&lcd->backlight->dev.kobj, in acx565akm_backlight_cleanup()
386 backlight_device_unregister(lcd->backlight); in acx565akm_backlight_cleanup()
389 /* -----------------------------------------------------------------------------
393 static void acx565akm_set_sleep_mode(struct acx565akm_panel *lcd, int on) in acx565akm_set_sleep_mode() argument
402 wait = lcd->hw_guard_end - jiffies; in acx565akm_set_sleep_mode()
403 if ((long)wait > 0 && wait <= lcd->hw_guard_wait) { in acx565akm_set_sleep_mode()
408 acx565akm_cmd(lcd, cmd); in acx565akm_set_sleep_mode()
410 lcd->hw_guard_wait = msecs_to_jiffies(120); in acx565akm_set_sleep_mode()
411 lcd->hw_guard_end = jiffies + lcd->hw_guard_wait; in acx565akm_set_sleep_mode()
414 static void acx565akm_set_display_state(struct acx565akm_panel *lcd, in acx565akm_set_display_state() argument
419 acx565akm_cmd(lcd, cmd); in acx565akm_set_display_state()
422 static int acx565akm_power_on(struct acx565akm_panel *lcd) in acx565akm_power_on() argument
427 gpiod_set_value(lcd->reset_gpio, 1); in acx565akm_power_on()
429 if (lcd->enabled) { in acx565akm_power_on()
430 dev_dbg(&lcd->spi->dev, "panel already enabled\n"); in acx565akm_power_on()
444 acx565akm_set_sleep_mode(lcd, 0); in acx565akm_power_on()
445 lcd->enabled = true; in acx565akm_power_on()
449 acx565akm_set_display_state(lcd, 1); in acx565akm_power_on()
450 acx565akm_set_cabc_mode(lcd, lcd->cabc_mode); in acx565akm_power_on()
452 return acx565akm_bl_update_status_locked(lcd->backlight); in acx565akm_power_on()
455 static void acx565akm_power_off(struct acx565akm_panel *lcd) in acx565akm_power_off() argument
457 acx565akm_set_display_state(lcd, 0); in acx565akm_power_off()
458 acx565akm_set_sleep_mode(lcd, 1); in acx565akm_power_off()
459 lcd->enabled = false; in acx565akm_power_off()
468 gpiod_set_value(lcd->reset_gpio, 0); in acx565akm_power_off()
476 struct acx565akm_panel *lcd = to_acx565akm_device(panel); in acx565akm_disable() local
478 mutex_lock(&lcd->mutex); in acx565akm_disable()
479 acx565akm_power_off(lcd); in acx565akm_disable()
480 mutex_unlock(&lcd->mutex); in acx565akm_disable()
487 struct acx565akm_panel *lcd = to_acx565akm_device(panel); in acx565akm_enable() local
489 mutex_lock(&lcd->mutex); in acx565akm_enable()
490 acx565akm_power_on(lcd); in acx565akm_enable()
491 mutex_unlock(&lcd->mutex); in acx565akm_enable()
517 mode = drm_mode_duplicate(connector->dev, &acx565akm_mode); in acx565akm_get_modes()
519 return -ENOMEM; in acx565akm_get_modes()
524 connector->display_info.width_mm = acx565akm_mode.width_mm; in acx565akm_get_modes()
525 connector->display_info.height_mm = acx565akm_mode.height_mm; in acx565akm_get_modes()
526 connector->display_info.bus_flags = DRM_BUS_FLAG_DE_HIGH in acx565akm_get_modes()
539 /* -----------------------------------------------------------------------------
543 static int acx565akm_detect(struct acx565akm_panel *lcd) in acx565akm_detect() argument
553 gpiod_set_value(lcd->reset_gpio, 1); in acx565akm_detect()
556 acx565akm_read(lcd, MIPI_DCS_GET_DISPLAY_STATUS, (u8 *)&value, 4); in acx565akm_detect()
558 lcd->enabled = (status & (1 << 17)) && (status & (1 << 10)); in acx565akm_detect()
560 dev_dbg(&lcd->spi->dev, in acx565akm_detect()
561 "LCD panel %s by bootloader (status 0x%04x)\n", in acx565akm_detect()
562 lcd->enabled ? "enabled" : "disabled ", status); in acx565akm_detect()
564 acx565akm_read(lcd, MIPI_DCS_GET_DISPLAY_ID, lcd->display_id, 3); in acx565akm_detect()
565 dev_dbg(&lcd->spi->dev, "MIPI display ID: %3phN\n", lcd->display_id); in acx565akm_detect()
567 switch (lcd->display_id[0]) { in acx565akm_detect()
569 lcd->model = MIPID_VER_ACX565AKM; in acx565akm_detect()
570 lcd->name = "acx565akm"; in acx565akm_detect()
571 lcd->has_bc = 1; in acx565akm_detect()
572 lcd->has_cabc = 1; in acx565akm_detect()
575 lcd->model = MIPID_VER_L4F00311; in acx565akm_detect()
576 lcd->name = "l4f00311"; in acx565akm_detect()
579 lcd->model = MIPID_VER_LPH8923; in acx565akm_detect()
580 lcd->name = "lph8923"; in acx565akm_detect()
583 lcd->model = MIPID_VER_LS041Y3; in acx565akm_detect()
584 lcd->name = "ls041y3"; in acx565akm_detect()
587 lcd->name = "unknown"; in acx565akm_detect()
588 dev_err(&lcd->spi->dev, "unknown display ID\n"); in acx565akm_detect()
589 ret = -ENODEV; in acx565akm_detect()
593 lcd->revision = lcd->display_id[1]; in acx565akm_detect()
595 dev_info(&lcd->spi->dev, "%s rev %02x panel detected\n", in acx565akm_detect()
596 lcd->name, lcd->revision); in acx565akm_detect()
599 if (!lcd->enabled) in acx565akm_detect()
600 gpiod_set_value(lcd->reset_gpio, 0); in acx565akm_detect()
607 struct acx565akm_panel *lcd; in acx565akm_probe() local
610 lcd = devm_kzalloc(&spi->dev, sizeof(*lcd), GFP_KERNEL); in acx565akm_probe()
611 if (!lcd) in acx565akm_probe()
612 return -ENOMEM; in acx565akm_probe()
614 spi_set_drvdata(spi, lcd); in acx565akm_probe()
615 spi->mode = SPI_MODE_3; in acx565akm_probe()
617 lcd->spi = spi; in acx565akm_probe()
618 mutex_init(&lcd->mutex); in acx565akm_probe()
620 lcd->reset_gpio = devm_gpiod_get(&spi->dev, "reset", GPIOD_OUT_HIGH); in acx565akm_probe()
621 if (IS_ERR(lcd->reset_gpio)) { in acx565akm_probe()
622 dev_err(&spi->dev, "failed to get reset GPIO\n"); in acx565akm_probe()
623 return PTR_ERR(lcd->reset_gpio); in acx565akm_probe()
626 ret = acx565akm_detect(lcd); in acx565akm_probe()
628 dev_err(&spi->dev, "panel detection failed\n"); in acx565akm_probe()
632 if (lcd->has_bc) { in acx565akm_probe()
633 ret = acx565akm_backlight_init(lcd); in acx565akm_probe()
638 drm_panel_init(&lcd->panel, &lcd->spi->dev, &acx565akm_funcs, in acx565akm_probe()
641 drm_panel_add(&lcd->panel); in acx565akm_probe()
648 struct acx565akm_panel *lcd = spi_get_drvdata(spi); in acx565akm_remove() local
650 drm_panel_remove(&lcd->panel); in acx565akm_remove()
652 if (lcd->has_bc) in acx565akm_remove()
653 acx565akm_backlight_cleanup(lcd); in acx565akm_remove()
675 .name = "panel-sony-acx565akm",
683 MODULE_DESCRIPTION("Sony ACX565AKM LCD Panel Driver");