2020-01-09 15:28:15 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
|
|
|
/*
|
2022-01-03 19:38:20 +08:00
|
|
|
* MIPI-DSI Novatek NT35560-based panel controller.
|
2020-01-09 15:28:15 +08:00
|
|
|
*
|
2022-01-03 19:38:20 +08:00
|
|
|
* Supported panels include:
|
|
|
|
* Sony ACX424AKM - a 480x854 AMOLED DSI panel
|
|
|
|
* Sony ACX424AKP - a 480x864 AMOLED DSI panel
|
|
|
|
*
|
|
|
|
* Copyright (C) Linaro Ltd. 2019-2021
|
2020-01-09 15:28:15 +08:00
|
|
|
* Author: Linus Walleij
|
|
|
|
* Based on code and know-how from Marcus Lorentzon
|
|
|
|
* Copyright (C) ST-Ericsson SA 2010
|
2022-01-03 19:38:22 +08:00
|
|
|
* Based on code and know-how from Johan Olson and Joakim Wesslen
|
|
|
|
* Copyright (C) Sony Ericsson Mobile Communications 2010
|
2020-01-09 15:28:15 +08:00
|
|
|
*/
|
|
|
|
#include <linux/backlight.h>
|
|
|
|
#include <linux/delay.h>
|
|
|
|
#include <linux/gpio/consumer.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/of.h>
|
2022-01-03 19:38:22 +08:00
|
|
|
#include <linux/of_device.h>
|
2020-01-09 15:28:15 +08:00
|
|
|
#include <linux/regulator/consumer.h>
|
|
|
|
|
|
|
|
#include <video/mipi_display.h>
|
|
|
|
|
|
|
|
#include <drm/drm_mipi_dsi.h>
|
|
|
|
#include <drm/drm_modes.h>
|
|
|
|
#include <drm/drm_panel.h>
|
|
|
|
|
2022-01-03 19:38:20 +08:00
|
|
|
#define NT35560_DCS_READ_ID1 0xDA
|
|
|
|
#define NT35560_DCS_READ_ID2 0xDB
|
|
|
|
#define NT35560_DCS_READ_ID3 0xDC
|
|
|
|
#define NT35560_DCS_SET_MDDI 0xAE
|
2020-01-09 15:28:15 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Sony seems to use vendor ID 0x81
|
|
|
|
*/
|
2022-01-03 19:38:21 +08:00
|
|
|
#define DISPLAY_SONY_ACX424AKP_ID1 0x8103
|
2020-01-09 15:28:15 +08:00
|
|
|
#define DISPLAY_SONY_ACX424AKP_ID2 0x811a
|
2022-01-03 19:38:21 +08:00
|
|
|
#define DISPLAY_SONY_ACX424AKP_ID3 0x811b
|
2020-01-09 15:28:15 +08:00
|
|
|
/*
|
2022-01-03 19:38:21 +08:00
|
|
|
* The fourth ID looks like a bug, vendor IDs begin at 0x80
|
2020-01-09 15:28:15 +08:00
|
|
|
* and panel 00 ... seems like default values.
|
|
|
|
*/
|
2022-01-03 19:38:21 +08:00
|
|
|
#define DISPLAY_SONY_ACX424AKP_ID4 0x8000
|
2020-01-09 15:28:15 +08:00
|
|
|
|
2022-01-03 19:38:22 +08:00
|
|
|
struct nt35560_config {
|
|
|
|
const struct drm_display_mode *vid_mode;
|
|
|
|
const struct drm_display_mode *cmd_mode;
|
|
|
|
};
|
|
|
|
|
2022-01-03 19:38:20 +08:00
|
|
|
struct nt35560 {
|
2022-01-03 19:38:22 +08:00
|
|
|
const struct nt35560_config *conf;
|
2020-01-09 15:28:15 +08:00
|
|
|
struct drm_panel panel;
|
|
|
|
struct device *dev;
|
|
|
|
struct regulator *supply;
|
|
|
|
struct gpio_desc *reset_gpio;
|
|
|
|
bool video_mode;
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct drm_display_mode sony_acx424akp_vid_mode = {
|
2020-03-03 04:34:27 +08:00
|
|
|
.clock = 27234,
|
2020-01-09 15:28:15 +08:00
|
|
|
.hdisplay = 480,
|
|
|
|
.hsync_start = 480 + 15,
|
|
|
|
.hsync_end = 480 + 15 + 0,
|
|
|
|
.htotal = 480 + 15 + 0 + 15,
|
|
|
|
.vdisplay = 864,
|
|
|
|
.vsync_start = 864 + 14,
|
|
|
|
.vsync_end = 864 + 14 + 1,
|
|
|
|
.vtotal = 864 + 14 + 1 + 11,
|
|
|
|
.width_mm = 48,
|
|
|
|
.height_mm = 84,
|
|
|
|
.flags = DRM_MODE_FLAG_PVSYNC,
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The timings are not very helpful as the display is used in
|
|
|
|
* command mode using the maximum HS frequency.
|
|
|
|
*/
|
|
|
|
static const struct drm_display_mode sony_acx424akp_cmd_mode = {
|
2020-03-03 04:34:27 +08:00
|
|
|
.clock = 35478,
|
2020-01-09 15:28:15 +08:00
|
|
|
.hdisplay = 480,
|
|
|
|
.hsync_start = 480 + 154,
|
|
|
|
.hsync_end = 480 + 154 + 16,
|
|
|
|
.htotal = 480 + 154 + 16 + 32,
|
|
|
|
.vdisplay = 864,
|
|
|
|
.vsync_start = 864 + 1,
|
|
|
|
.vsync_end = 864 + 1 + 1,
|
|
|
|
.vtotal = 864 + 1 + 1 + 1,
|
|
|
|
/*
|
|
|
|
* Some desired refresh rate, experiments at the maximum "pixel"
|
|
|
|
* clock speed (HS clock 420 MHz) yields around 117Hz.
|
|
|
|
*/
|
|
|
|
.width_mm = 48,
|
|
|
|
.height_mm = 84,
|
|
|
|
};
|
|
|
|
|
2022-01-03 19:38:22 +08:00
|
|
|
static const struct nt35560_config sony_acx424akp_data = {
|
|
|
|
.vid_mode = &sony_acx424akp_vid_mode,
|
|
|
|
.cmd_mode = &sony_acx424akp_cmd_mode,
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct drm_display_mode sony_acx424akm_vid_mode = {
|
|
|
|
.clock = 27234,
|
|
|
|
.hdisplay = 480,
|
|
|
|
.hsync_start = 480 + 15,
|
|
|
|
.hsync_end = 480 + 15 + 0,
|
|
|
|
.htotal = 480 + 15 + 0 + 15,
|
|
|
|
.vdisplay = 854,
|
|
|
|
.vsync_start = 854 + 14,
|
|
|
|
.vsync_end = 854 + 14 + 1,
|
|
|
|
.vtotal = 854 + 14 + 1 + 11,
|
|
|
|
.width_mm = 46,
|
|
|
|
.height_mm = 82,
|
|
|
|
.flags = DRM_MODE_FLAG_PVSYNC,
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The timings are not very helpful as the display is used in
|
|
|
|
* command mode using the maximum HS frequency.
|
|
|
|
*/
|
|
|
|
static const struct drm_display_mode sony_acx424akm_cmd_mode = {
|
|
|
|
.clock = 35478,
|
|
|
|
.hdisplay = 480,
|
|
|
|
.hsync_start = 480 + 154,
|
|
|
|
.hsync_end = 480 + 154 + 16,
|
|
|
|
.htotal = 480 + 154 + 16 + 32,
|
|
|
|
.vdisplay = 854,
|
|
|
|
.vsync_start = 854 + 1,
|
|
|
|
.vsync_end = 854 + 1 + 1,
|
|
|
|
.vtotal = 854 + 1 + 1 + 1,
|
|
|
|
.width_mm = 46,
|
|
|
|
.height_mm = 82,
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct nt35560_config sony_acx424akm_data = {
|
|
|
|
.vid_mode = &sony_acx424akm_vid_mode,
|
|
|
|
.cmd_mode = &sony_acx424akm_cmd_mode,
|
|
|
|
};
|
|
|
|
|
2022-01-03 19:38:20 +08:00
|
|
|
static inline struct nt35560 *panel_to_nt35560(struct drm_panel *panel)
|
2020-01-09 15:28:15 +08:00
|
|
|
{
|
2022-01-03 19:38:20 +08:00
|
|
|
return container_of(panel, struct nt35560, panel);
|
2020-01-09 15:28:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#define FOSC 20 /* 20Mhz */
|
|
|
|
#define SCALE_FACTOR_NS_DIV_MHZ 1000
|
|
|
|
|
2022-01-03 19:38:20 +08:00
|
|
|
static int nt35560_set_brightness(struct backlight_device *bl)
|
2020-01-09 15:28:15 +08:00
|
|
|
{
|
2022-01-03 19:38:20 +08:00
|
|
|
struct nt35560 *nt = bl_get_data(bl);
|
|
|
|
struct mipi_dsi_device *dsi = to_mipi_dsi_device(nt->dev);
|
2020-01-09 15:28:15 +08:00
|
|
|
int period_ns = 1023;
|
|
|
|
int duty_ns = bl->props.brightness;
|
|
|
|
u8 pwm_ratio;
|
|
|
|
u8 pwm_div;
|
|
|
|
u8 par;
|
|
|
|
int ret;
|
|
|
|
|
2021-07-15 17:28:08 +08:00
|
|
|
if (backlight_is_blank(bl)) {
|
|
|
|
/* Disable backlight */
|
|
|
|
par = 0x00;
|
|
|
|
ret = mipi_dsi_dcs_write(dsi, MIPI_DCS_WRITE_CONTROL_DISPLAY,
|
|
|
|
&par, 1);
|
|
|
|
if (ret) {
|
2022-01-03 19:38:20 +08:00
|
|
|
dev_err(nt->dev, "failed to disable display backlight (%d)\n", ret);
|
2021-07-15 17:28:08 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-01-09 15:28:15 +08:00
|
|
|
/* Calculate the PWM duty cycle in n/256's */
|
|
|
|
pwm_ratio = max(((duty_ns * 256) / period_ns) - 1, 1);
|
|
|
|
pwm_div = max(1,
|
|
|
|
((FOSC * period_ns) / 256) /
|
|
|
|
SCALE_FACTOR_NS_DIV_MHZ);
|
|
|
|
|
|
|
|
/* Set up PWM dutycycle ONE byte (differs from the standard) */
|
2022-01-03 19:38:20 +08:00
|
|
|
dev_dbg(nt->dev, "calculated duty cycle %02x\n", pwm_ratio);
|
2020-01-09 15:28:15 +08:00
|
|
|
ret = mipi_dsi_dcs_write(dsi, MIPI_DCS_SET_DISPLAY_BRIGHTNESS,
|
|
|
|
&pwm_ratio, 1);
|
|
|
|
if (ret < 0) {
|
2022-01-03 19:38:20 +08:00
|
|
|
dev_err(nt->dev, "failed to set display PWM ratio (%d)\n", ret);
|
2020-01-09 15:28:15 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Sequence to write PWMDIV:
|
|
|
|
* address data
|
|
|
|
* 0xF3 0xAA CMD2 Unlock
|
|
|
|
* 0x00 0x01 Enter CMD2 page 0
|
|
|
|
* 0X7D 0x01 No reload MTP of CMD2 P1
|
|
|
|
* 0x22 PWMDIV
|
|
|
|
* 0x7F 0xAA CMD2 page 1 lock
|
|
|
|
*/
|
|
|
|
par = 0xaa;
|
|
|
|
ret = mipi_dsi_dcs_write(dsi, 0xf3, &par, 1);
|
|
|
|
if (ret < 0) {
|
2022-01-03 19:38:20 +08:00
|
|
|
dev_err(nt->dev, "failed to unlock CMD 2 (%d)\n", ret);
|
2020-01-09 15:28:15 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
par = 0x01;
|
|
|
|
ret = mipi_dsi_dcs_write(dsi, 0x00, &par, 1);
|
|
|
|
if (ret < 0) {
|
2022-01-03 19:38:20 +08:00
|
|
|
dev_err(nt->dev, "failed to enter page 1 (%d)\n", ret);
|
2020-01-09 15:28:15 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
par = 0x01;
|
|
|
|
ret = mipi_dsi_dcs_write(dsi, 0x7d, &par, 1);
|
|
|
|
if (ret < 0) {
|
2022-01-03 19:38:20 +08:00
|
|
|
dev_err(nt->dev, "failed to disable MTP reload (%d)\n", ret);
|
2020-01-09 15:28:15 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
ret = mipi_dsi_dcs_write(dsi, 0x22, &pwm_div, 1);
|
|
|
|
if (ret < 0) {
|
2022-01-03 19:38:20 +08:00
|
|
|
dev_err(nt->dev, "failed to set PWM divisor (%d)\n", ret);
|
2020-01-09 15:28:15 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
par = 0xaa;
|
|
|
|
ret = mipi_dsi_dcs_write(dsi, 0x7f, &par, 1);
|
|
|
|
if (ret < 0) {
|
2022-01-03 19:38:20 +08:00
|
|
|
dev_err(nt->dev, "failed to lock CMD 2 (%d)\n", ret);
|
2020-01-09 15:28:15 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Enable backlight */
|
|
|
|
par = 0x24;
|
|
|
|
ret = mipi_dsi_dcs_write(dsi, MIPI_DCS_WRITE_CONTROL_DISPLAY,
|
|
|
|
&par, 1);
|
|
|
|
if (ret < 0) {
|
2022-01-03 19:38:20 +08:00
|
|
|
dev_err(nt->dev, "failed to enable display backlight (%d)\n", ret);
|
2020-01-09 15:28:15 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2022-01-03 19:38:20 +08:00
|
|
|
static const struct backlight_ops nt35560_bl_ops = {
|
|
|
|
.update_status = nt35560_set_brightness,
|
2020-01-09 15:28:15 +08:00
|
|
|
};
|
|
|
|
|
2022-01-03 19:38:20 +08:00
|
|
|
static const struct backlight_properties nt35560_bl_props = {
|
2021-07-15 17:28:08 +08:00
|
|
|
.type = BACKLIGHT_RAW,
|
|
|
|
.brightness = 512,
|
|
|
|
.max_brightness = 1023,
|
|
|
|
};
|
|
|
|
|
2022-01-03 19:38:20 +08:00
|
|
|
static int nt35560_read_id(struct nt35560 *nt)
|
2020-01-09 15:28:15 +08:00
|
|
|
{
|
2022-01-03 19:38:20 +08:00
|
|
|
struct mipi_dsi_device *dsi = to_mipi_dsi_device(nt->dev);
|
2020-01-09 15:28:15 +08:00
|
|
|
u8 vendor, version, panel;
|
|
|
|
u16 val;
|
|
|
|
int ret;
|
|
|
|
|
2022-01-03 19:38:20 +08:00
|
|
|
ret = mipi_dsi_dcs_read(dsi, NT35560_DCS_READ_ID1, &vendor, 1);
|
2020-01-09 15:28:15 +08:00
|
|
|
if (ret < 0) {
|
2022-01-03 19:38:20 +08:00
|
|
|
dev_err(nt->dev, "could not vendor ID byte\n");
|
2020-01-09 15:28:15 +08:00
|
|
|
return ret;
|
|
|
|
}
|
2022-01-03 19:38:20 +08:00
|
|
|
ret = mipi_dsi_dcs_read(dsi, NT35560_DCS_READ_ID2, &version, 1);
|
2020-01-09 15:28:15 +08:00
|
|
|
if (ret < 0) {
|
2022-01-03 19:38:20 +08:00
|
|
|
dev_err(nt->dev, "could not read device version byte\n");
|
2020-01-09 15:28:15 +08:00
|
|
|
return ret;
|
|
|
|
}
|
2022-01-03 19:38:20 +08:00
|
|
|
ret = mipi_dsi_dcs_read(dsi, NT35560_DCS_READ_ID3, &panel, 1);
|
2020-01-09 15:28:15 +08:00
|
|
|
if (ret < 0) {
|
2022-01-03 19:38:20 +08:00
|
|
|
dev_err(nt->dev, "could not read panel ID byte\n");
|
2020-01-09 15:28:15 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (vendor == 0x00) {
|
2022-01-03 19:38:20 +08:00
|
|
|
dev_err(nt->dev, "device vendor ID is zero\n");
|
2020-01-09 15:28:15 +08:00
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
|
|
|
val = (vendor << 8) | panel;
|
|
|
|
switch (val) {
|
|
|
|
case DISPLAY_SONY_ACX424AKP_ID1:
|
|
|
|
case DISPLAY_SONY_ACX424AKP_ID2:
|
|
|
|
case DISPLAY_SONY_ACX424AKP_ID3:
|
2022-01-03 19:38:21 +08:00
|
|
|
case DISPLAY_SONY_ACX424AKP_ID4:
|
2022-01-03 19:38:20 +08:00
|
|
|
dev_info(nt->dev, "MTP vendor: %02x, version: %02x, panel: %02x\n",
|
2020-08-15 20:54:06 +08:00
|
|
|
vendor, version, panel);
|
2020-01-09 15:28:15 +08:00
|
|
|
break;
|
|
|
|
default:
|
2022-01-03 19:38:20 +08:00
|
|
|
dev_info(nt->dev, "unknown vendor: %02x, version: %02x, panel: %02x\n",
|
2020-08-15 20:54:06 +08:00
|
|
|
vendor, version, panel);
|
2020-01-09 15:28:15 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2022-01-03 19:38:20 +08:00
|
|
|
static int nt35560_power_on(struct nt35560 *nt)
|
2020-01-09 15:28:15 +08:00
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
2022-01-03 19:38:20 +08:00
|
|
|
ret = regulator_enable(nt->supply);
|
2020-01-09 15:28:15 +08:00
|
|
|
if (ret) {
|
2022-01-03 19:38:20 +08:00
|
|
|
dev_err(nt->dev, "failed to enable supply (%d)\n", ret);
|
2020-01-09 15:28:15 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Assert RESET */
|
2022-01-03 19:38:20 +08:00
|
|
|
gpiod_set_value_cansleep(nt->reset_gpio, 1);
|
2020-01-09 15:28:15 +08:00
|
|
|
udelay(20);
|
|
|
|
/* De-assert RESET */
|
2022-01-03 19:38:20 +08:00
|
|
|
gpiod_set_value_cansleep(nt->reset_gpio, 0);
|
2020-01-09 15:28:15 +08:00
|
|
|
usleep_range(11000, 20000);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2022-01-03 19:38:20 +08:00
|
|
|
static void nt35560_power_off(struct nt35560 *nt)
|
2020-01-09 15:28:15 +08:00
|
|
|
{
|
|
|
|
/* Assert RESET */
|
2022-01-03 19:38:20 +08:00
|
|
|
gpiod_set_value_cansleep(nt->reset_gpio, 1);
|
2020-01-09 15:28:15 +08:00
|
|
|
usleep_range(11000, 20000);
|
|
|
|
|
2022-01-03 19:38:20 +08:00
|
|
|
regulator_disable(nt->supply);
|
2020-01-09 15:28:15 +08:00
|
|
|
}
|
|
|
|
|
2022-01-03 19:38:20 +08:00
|
|
|
static int nt35560_prepare(struct drm_panel *panel)
|
2020-01-09 15:28:15 +08:00
|
|
|
{
|
2022-01-03 19:38:20 +08:00
|
|
|
struct nt35560 *nt = panel_to_nt35560(panel);
|
|
|
|
struct mipi_dsi_device *dsi = to_mipi_dsi_device(nt->dev);
|
2020-01-09 15:28:15 +08:00
|
|
|
const u8 mddi = 3;
|
|
|
|
int ret;
|
|
|
|
|
2022-01-03 19:38:20 +08:00
|
|
|
ret = nt35560_power_on(nt);
|
2020-01-09 15:28:15 +08:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
2022-01-03 19:38:20 +08:00
|
|
|
ret = nt35560_read_id(nt);
|
2020-01-09 15:28:15 +08:00
|
|
|
if (ret) {
|
2022-01-03 19:38:20 +08:00
|
|
|
dev_err(nt->dev, "failed to read panel ID (%d)\n", ret);
|
2020-01-09 15:28:15 +08:00
|
|
|
goto err_power_off;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Enabe tearing mode: send TE (tearing effect) at VBLANK */
|
|
|
|
ret = mipi_dsi_dcs_set_tear_on(dsi,
|
|
|
|
MIPI_DSI_DCS_TEAR_MODE_VBLANK);
|
|
|
|
if (ret) {
|
2022-01-03 19:38:20 +08:00
|
|
|
dev_err(nt->dev, "failed to enable vblank TE (%d)\n", ret);
|
2020-01-09 15:28:15 +08:00
|
|
|
goto err_power_off;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set MDDI
|
|
|
|
*
|
|
|
|
* This presumably deactivates the Qualcomm MDDI interface and
|
|
|
|
* selects DSI, similar code is found in other drivers such as the
|
|
|
|
* Sharp LS043T1LE01 which makes us suspect that this panel may be
|
|
|
|
* using a Novatek NT35565 or similar display driver chip that shares
|
|
|
|
* this command. Due to the lack of documentation we cannot know for
|
|
|
|
* sure.
|
|
|
|
*/
|
2022-01-03 19:38:20 +08:00
|
|
|
ret = mipi_dsi_dcs_write(dsi, NT35560_DCS_SET_MDDI,
|
2020-01-09 15:28:15 +08:00
|
|
|
&mddi, sizeof(mddi));
|
|
|
|
if (ret < 0) {
|
2022-01-03 19:38:20 +08:00
|
|
|
dev_err(nt->dev, "failed to set MDDI (%d)\n", ret);
|
2020-01-09 15:28:15 +08:00
|
|
|
goto err_power_off;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Exit sleep mode */
|
|
|
|
ret = mipi_dsi_dcs_exit_sleep_mode(dsi);
|
|
|
|
if (ret) {
|
2022-01-03 19:38:20 +08:00
|
|
|
dev_err(nt->dev, "failed to exit sleep mode (%d)\n", ret);
|
2020-01-09 15:28:15 +08:00
|
|
|
goto err_power_off;
|
|
|
|
}
|
|
|
|
msleep(140);
|
|
|
|
|
|
|
|
ret = mipi_dsi_dcs_set_display_on(dsi);
|
|
|
|
if (ret) {
|
2022-01-03 19:38:20 +08:00
|
|
|
dev_err(nt->dev, "failed to turn display on (%d)\n", ret);
|
2020-01-09 15:28:15 +08:00
|
|
|
goto err_power_off;
|
|
|
|
}
|
2022-01-03 19:38:20 +08:00
|
|
|
if (nt->video_mode) {
|
2020-01-09 15:28:15 +08:00
|
|
|
/* In video mode turn peripheral on */
|
|
|
|
ret = mipi_dsi_turn_on_peripheral(dsi);
|
|
|
|
if (ret) {
|
2022-01-03 19:38:20 +08:00
|
|
|
dev_err(nt->dev, "failed to turn on peripheral\n");
|
2020-01-09 15:28:15 +08:00
|
|
|
goto err_power_off;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
err_power_off:
|
2022-01-03 19:38:20 +08:00
|
|
|
nt35560_power_off(nt);
|
2020-01-09 15:28:15 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2022-01-03 19:38:20 +08:00
|
|
|
static int nt35560_unprepare(struct drm_panel *panel)
|
2020-01-09 15:28:15 +08:00
|
|
|
{
|
2022-01-03 19:38:20 +08:00
|
|
|
struct nt35560 *nt = panel_to_nt35560(panel);
|
|
|
|
struct mipi_dsi_device *dsi = to_mipi_dsi_device(nt->dev);
|
2020-01-09 15:28:15 +08:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = mipi_dsi_dcs_set_display_off(dsi);
|
|
|
|
if (ret) {
|
2022-01-03 19:38:20 +08:00
|
|
|
dev_err(nt->dev, "failed to turn display off (%d)\n", ret);
|
2020-01-09 15:28:15 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Enter sleep mode */
|
|
|
|
ret = mipi_dsi_dcs_enter_sleep_mode(dsi);
|
|
|
|
if (ret) {
|
2022-01-03 19:38:20 +08:00
|
|
|
dev_err(nt->dev, "failed to enter sleep mode (%d)\n", ret);
|
2020-01-09 15:28:15 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
msleep(85);
|
|
|
|
|
2022-01-03 19:38:20 +08:00
|
|
|
nt35560_power_off(nt);
|
2020-01-09 15:28:15 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-01-03 19:38:20 +08:00
|
|
|
static int nt35560_get_modes(struct drm_panel *panel,
|
|
|
|
struct drm_connector *connector)
|
2020-01-09 15:28:15 +08:00
|
|
|
{
|
2022-01-03 19:38:20 +08:00
|
|
|
struct nt35560 *nt = panel_to_nt35560(panel);
|
2022-01-03 19:38:22 +08:00
|
|
|
const struct nt35560_config *conf = nt->conf;
|
2020-01-09 15:28:15 +08:00
|
|
|
struct drm_display_mode *mode;
|
|
|
|
|
2022-01-03 19:38:20 +08:00
|
|
|
if (nt->video_mode)
|
2020-01-09 15:28:15 +08:00
|
|
|
mode = drm_mode_duplicate(connector->dev,
|
2022-01-03 19:38:22 +08:00
|
|
|
conf->vid_mode);
|
2020-01-09 15:28:15 +08:00
|
|
|
else
|
|
|
|
mode = drm_mode_duplicate(connector->dev,
|
2022-01-03 19:38:22 +08:00
|
|
|
conf->cmd_mode);
|
2020-01-09 15:28:15 +08:00
|
|
|
if (!mode) {
|
2020-08-15 20:54:06 +08:00
|
|
|
dev_err(panel->dev, "bad mode or failed to add mode\n");
|
2020-01-09 15:28:15 +08:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
drm_mode_set_name(mode);
|
|
|
|
mode->type = DRM_MODE_TYPE_DRIVER | DRM_MODE_TYPE_PREFERRED;
|
|
|
|
|
|
|
|
connector->display_info.width_mm = mode->width_mm;
|
|
|
|
connector->display_info.height_mm = mode->height_mm;
|
|
|
|
|
|
|
|
drm_mode_probed_add(connector, mode);
|
|
|
|
|
|
|
|
return 1; /* Number of modes */
|
|
|
|
}
|
|
|
|
|
2022-01-03 19:38:20 +08:00
|
|
|
static const struct drm_panel_funcs nt35560_drm_funcs = {
|
|
|
|
.unprepare = nt35560_unprepare,
|
|
|
|
.prepare = nt35560_prepare,
|
|
|
|
.get_modes = nt35560_get_modes,
|
2020-01-09 15:28:15 +08:00
|
|
|
};
|
|
|
|
|
2022-01-03 19:38:20 +08:00
|
|
|
static int nt35560_probe(struct mipi_dsi_device *dsi)
|
2020-01-09 15:28:15 +08:00
|
|
|
{
|
|
|
|
struct device *dev = &dsi->dev;
|
2022-01-03 19:38:20 +08:00
|
|
|
struct nt35560 *nt;
|
2020-01-09 15:28:15 +08:00
|
|
|
int ret;
|
|
|
|
|
2022-01-03 19:38:20 +08:00
|
|
|
nt = devm_kzalloc(dev, sizeof(struct nt35560), GFP_KERNEL);
|
|
|
|
if (!nt)
|
2020-01-09 15:28:15 +08:00
|
|
|
return -ENOMEM;
|
2022-01-03 19:38:20 +08:00
|
|
|
nt->video_mode = of_property_read_bool(dev->of_node,
|
2020-01-09 15:28:15 +08:00
|
|
|
"enforce-video-mode");
|
|
|
|
|
2022-01-03 19:38:20 +08:00
|
|
|
mipi_dsi_set_drvdata(dsi, nt);
|
|
|
|
nt->dev = dev;
|
2020-01-09 15:28:15 +08:00
|
|
|
|
2022-01-03 19:38:22 +08:00
|
|
|
nt->conf = of_device_get_match_data(dev);
|
|
|
|
if (!nt->conf) {
|
|
|
|
dev_err(dev, "missing device configuration\n");
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
2020-01-09 15:28:15 +08:00
|
|
|
dsi->lanes = 2;
|
|
|
|
dsi->format = MIPI_DSI_FMT_RGB888;
|
|
|
|
/*
|
|
|
|
* FIXME: these come from the ST-Ericsson vendor driver for the
|
|
|
|
* HREF520 and seems to reflect limitations in the PLLs on that
|
|
|
|
* platform, if you have the datasheet, please cross-check the
|
|
|
|
* actual max rates.
|
|
|
|
*/
|
|
|
|
dsi->lp_rate = 19200000;
|
|
|
|
dsi->hs_rate = 420160000;
|
|
|
|
|
2022-01-03 19:38:20 +08:00
|
|
|
if (nt->video_mode)
|
2020-01-09 15:28:15 +08:00
|
|
|
/* Burst mode using event for sync */
|
|
|
|
dsi->mode_flags =
|
|
|
|
MIPI_DSI_MODE_VIDEO |
|
|
|
|
MIPI_DSI_MODE_VIDEO_BURST;
|
|
|
|
else
|
|
|
|
dsi->mode_flags =
|
2021-03-04 08:41:38 +08:00
|
|
|
MIPI_DSI_CLOCK_NON_CONTINUOUS;
|
2020-01-09 15:28:15 +08:00
|
|
|
|
2022-01-03 19:38:20 +08:00
|
|
|
nt->supply = devm_regulator_get(dev, "vddi");
|
|
|
|
if (IS_ERR(nt->supply))
|
|
|
|
return PTR_ERR(nt->supply);
|
2020-01-09 15:28:15 +08:00
|
|
|
|
|
|
|
/* This asserts RESET by default */
|
2022-01-03 19:38:20 +08:00
|
|
|
nt->reset_gpio = devm_gpiod_get_optional(dev, "reset",
|
|
|
|
GPIOD_OUT_HIGH);
|
|
|
|
if (IS_ERR(nt->reset_gpio))
|
|
|
|
return dev_err_probe(dev, PTR_ERR(nt->reset_gpio),
|
2021-07-15 17:28:08 +08:00
|
|
|
"failed to request GPIO\n");
|
2020-01-09 15:28:15 +08:00
|
|
|
|
2022-01-03 19:38:20 +08:00
|
|
|
drm_panel_init(&nt->panel, dev, &nt35560_drm_funcs,
|
2020-01-09 15:28:15 +08:00
|
|
|
DRM_MODE_CONNECTOR_DSI);
|
|
|
|
|
2022-01-03 19:38:20 +08:00
|
|
|
nt->panel.backlight = devm_backlight_device_register(dev, "nt35560", dev, nt,
|
|
|
|
&nt35560_bl_ops, &nt35560_bl_props);
|
|
|
|
if (IS_ERR(nt->panel.backlight))
|
|
|
|
return dev_err_probe(dev, PTR_ERR(nt->panel.backlight),
|
2021-07-15 17:28:08 +08:00
|
|
|
"failed to register backlight device\n");
|
2020-01-09 15:28:15 +08:00
|
|
|
|
2022-01-03 19:38:20 +08:00
|
|
|
drm_panel_add(&nt->panel);
|
2020-01-09 15:28:15 +08:00
|
|
|
|
|
|
|
ret = mipi_dsi_attach(dsi);
|
|
|
|
if (ret < 0) {
|
2022-01-03 19:38:20 +08:00
|
|
|
drm_panel_remove(&nt->panel);
|
2020-01-09 15:28:15 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2022-07-08 17:49:22 +08:00
|
|
|
static void nt35560_remove(struct mipi_dsi_device *dsi)
|
2020-01-09 15:28:15 +08:00
|
|
|
{
|
2022-01-03 19:38:20 +08:00
|
|
|
struct nt35560 *nt = mipi_dsi_get_drvdata(dsi);
|
2020-01-09 15:28:15 +08:00
|
|
|
|
|
|
|
mipi_dsi_detach(dsi);
|
2022-01-03 19:38:20 +08:00
|
|
|
drm_panel_remove(&nt->panel);
|
2020-01-09 15:28:15 +08:00
|
|
|
}
|
|
|
|
|
2022-01-03 19:38:20 +08:00
|
|
|
static const struct of_device_id nt35560_of_match[] = {
|
2022-01-03 19:38:22 +08:00
|
|
|
{
|
|
|
|
.compatible = "sony,acx424akp",
|
|
|
|
.data = &sony_acx424akp_data,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.compatible = "sony,acx424akm",
|
|
|
|
.data = &sony_acx424akm_data,
|
|
|
|
},
|
2020-01-09 15:28:15 +08:00
|
|
|
{ /* sentinel */ }
|
|
|
|
};
|
2022-01-03 19:38:20 +08:00
|
|
|
MODULE_DEVICE_TABLE(of, nt35560_of_match);
|
2020-01-09 15:28:15 +08:00
|
|
|
|
2022-01-03 19:38:20 +08:00
|
|
|
static struct mipi_dsi_driver nt35560_driver = {
|
|
|
|
.probe = nt35560_probe,
|
|
|
|
.remove = nt35560_remove,
|
2020-01-09 15:28:15 +08:00
|
|
|
.driver = {
|
2022-01-03 19:38:20 +08:00
|
|
|
.name = "panel-novatek-nt35560",
|
|
|
|
.of_match_table = nt35560_of_match,
|
2020-01-09 15:28:15 +08:00
|
|
|
},
|
|
|
|
};
|
2022-01-03 19:38:20 +08:00
|
|
|
module_mipi_dsi_driver(nt35560_driver);
|
2020-01-09 15:28:15 +08:00
|
|
|
|
|
|
|
MODULE_AUTHOR("Linus Wallei <linus.walleij@linaro.org>");
|
2022-01-03 19:38:20 +08:00
|
|
|
MODULE_DESCRIPTION("MIPI-DSI Novatek NT35560 Panel Driver");
|
2020-01-09 15:28:15 +08:00
|
|
|
MODULE_LICENSE("GPL v2");
|