1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281
|
// SPDX-License-Identifier: GPL-2.0
#include <linux/array_size.h>
#include <linux/delay.h>
#include <linux/err.h>
#include <linux/gpio/consumer.h>
#include <linux/mod_devicetable.h>
#include <linux/module.h>
#include <linux/property.h>
#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>
#define R69328_MACP 0xb0 /* Manufacturer Access CMD Protect */
#define R69328_MACP_ON 0x03
#define R69328_MACP_OFF 0x04
#define R69328_GAMMA_SET_A 0xc8 /* Gamma Setting A */
#define R69328_GAMMA_SET_B 0xc9 /* Gamma Setting B */
#define R69328_GAMMA_SET_C 0xca /* Gamma Setting C */
#define R69328_POWER_SET 0xd1
struct renesas_r69328 {
struct drm_panel panel;
struct mipi_dsi_device *dsi;
struct regulator *vdd_supply;
struct regulator *vddio_supply;
struct gpio_desc *reset_gpio;
bool prepared;
};
static inline struct renesas_r69328 *to_renesas_r69328(struct drm_panel *panel)
{
return container_of(panel, struct renesas_r69328, panel);
}
static void renesas_r69328_reset(struct renesas_r69328 *priv)
{
gpiod_set_value_cansleep(priv->reset_gpio, 1);
usleep_range(10000, 11000);
gpiod_set_value_cansleep(priv->reset_gpio, 0);
usleep_range(2000, 3000);
}
static int renesas_r69328_prepare(struct drm_panel *panel)
{
struct renesas_r69328 *priv = to_renesas_r69328(panel);
struct device *dev = &priv->dsi->dev;
int ret;
if (priv->prepared)
return 0;
ret = regulator_enable(priv->vdd_supply);
if (ret) {
dev_err(dev, "failed to enable vdd power supply\n");
return ret;
}
usleep_range(10000, 11000);
ret = regulator_enable(priv->vddio_supply);
if (ret < 0) {
dev_err(dev, "failed to enable vddio power supply\n");
return ret;
}
usleep_range(10000, 11000);
renesas_r69328_reset(priv);
priv->prepared = true;
return 0;
}
static int renesas_r69328_enable(struct drm_panel *panel)
{
struct renesas_r69328 *priv = to_renesas_r69328(panel);
struct mipi_dsi_multi_context ctx = { .dsi = priv->dsi };
/* Set address mode */
mipi_dsi_dcs_write_seq_multi(&ctx, MIPI_DCS_SET_ADDRESS_MODE, 0x00);
mipi_dsi_dcs_set_pixel_format_multi(&ctx, MIPI_DCS_PIXEL_FMT_24BIT << 4);
mipi_dsi_dcs_exit_sleep_mode_multi(&ctx);
mipi_dsi_msleep(&ctx, 100);
/* MACP Off */
mipi_dsi_generic_write_seq_multi(&ctx, R69328_MACP, R69328_MACP_OFF);
mipi_dsi_generic_write_seq_multi(&ctx, R69328_POWER_SET, 0x14, 0x1d,
0x21, 0x67, 0x11, 0x9a);
mipi_dsi_generic_write_seq_multi(&ctx, R69328_GAMMA_SET_A, 0x00, 0x1a,
0x20, 0x28, 0x25, 0x24, 0x26, 0x15, 0x13,
0x11, 0x18, 0x1e, 0x1c, 0x00, 0x00, 0x1a,
0x20, 0x28, 0x25, 0x24, 0x26, 0x15, 0x13,
0x11, 0x18, 0x1e, 0x1c, 0x00);
mipi_dsi_generic_write_seq_multi(&ctx, R69328_GAMMA_SET_B, 0x00, 0x1a,
0x20, 0x28, 0x25, 0x24, 0x26, 0x15, 0x13,
0x11, 0x18, 0x1e, 0x1c, 0x00, 0x00, 0x1a,
0x20, 0x28, 0x25, 0x24, 0x26, 0x15, 0x13,
0x11, 0x18, 0x1e, 0x1c, 0x00);
mipi_dsi_generic_write_seq_multi(&ctx, R69328_GAMMA_SET_C, 0x00, 0x1a,
0x20, 0x28, 0x25, 0x24, 0x26, 0x15, 0x13,
0x11, 0x18, 0x1e, 0x1c, 0x00, 0x00, 0x1a,
0x20, 0x28, 0x25, 0x24, 0x26, 0x15, 0x13,
0x11, 0x18, 0x1e, 0x1c, 0x00);
/* MACP On */
mipi_dsi_generic_write_seq_multi(&ctx, R69328_MACP, R69328_MACP_ON);
mipi_dsi_dcs_set_display_on_multi(&ctx);
mipi_dsi_msleep(&ctx, 50);
return 0;
}
static int renesas_r69328_disable(struct drm_panel *panel)
{
struct renesas_r69328 *priv = to_renesas_r69328(panel);
struct mipi_dsi_multi_context ctx = { .dsi = priv->dsi };
mipi_dsi_dcs_set_display_off_multi(&ctx);
mipi_dsi_msleep(&ctx, 60);
mipi_dsi_dcs_enter_sleep_mode_multi(&ctx);
return 0;
}
static int renesas_r69328_unprepare(struct drm_panel *panel)
{
struct renesas_r69328 *priv = to_renesas_r69328(panel);
if (!priv->prepared)
return 0;
gpiod_set_value_cansleep(priv->reset_gpio, 1);
usleep_range(5000, 6000);
regulator_disable(priv->vddio_supply);
regulator_disable(priv->vdd_supply);
priv->prepared = false;
return 0;
}
static const struct drm_display_mode renesas_r69328_mode = {
.clock = (720 + 92 + 62 + 4) * (1280 + 6 + 3 + 1) * 60 / 1000,
.hdisplay = 720,
.hsync_start = 720 + 92,
.hsync_end = 720 + 92 + 62,
.htotal = 720 + 92 + 62 + 4,
.vdisplay = 1280,
.vsync_start = 1280 + 6,
.vsync_end = 1280 + 6 + 3,
.vtotal = 1280 + 6 + 3 + 1,
.width_mm = 59,
.height_mm = 105,
};
static int renesas_r69328_get_modes(struct drm_panel *panel,
struct drm_connector *connector)
{
struct drm_display_mode *mode;
mode = drm_mode_duplicate(connector->dev, &renesas_r69328_mode);
if (!mode)
return -ENOMEM;
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;
}
static const struct drm_panel_funcs renesas_r69328_panel_funcs = {
.prepare = renesas_r69328_prepare,
.enable = renesas_r69328_enable,
.disable = renesas_r69328_disable,
.unprepare = renesas_r69328_unprepare,
.get_modes = renesas_r69328_get_modes,
};
static int renesas_r69328_probe(struct mipi_dsi_device *dsi)
{
struct device *dev = &dsi->dev;
struct renesas_r69328 *priv;
int ret;
priv = devm_drm_panel_alloc(dev, struct renesas_r69328, panel,
&renesas_r69328_panel_funcs,
DRM_MODE_CONNECTOR_DSI);
if (IS_ERR(priv))
return PTR_ERR(priv);
priv->vdd_supply = devm_regulator_get(dev, "vdd");
if (IS_ERR(priv->vdd_supply))
return dev_err_probe(dev, PTR_ERR(priv->vdd_supply),
"Failed to get vdd-supply\n");
priv->vddio_supply = devm_regulator_get(dev, "vddio");
if (IS_ERR(priv->vddio_supply))
return dev_err_probe(dev, PTR_ERR(priv->vddio_supply),
"Failed to get vddio-supply\n");
priv->reset_gpio = devm_gpiod_get_optional(dev, "reset",
GPIOD_OUT_LOW);
if (IS_ERR(priv->reset_gpio))
return dev_err_probe(dev, PTR_ERR(priv->reset_gpio),
"Failed to get reset-gpios\n");
priv->dsi = dsi;
mipi_dsi_set_drvdata(dsi, priv);
dsi->lanes = 4;
dsi->format = MIPI_DSI_FMT_RGB888;
dsi->mode_flags = MIPI_DSI_MODE_VIDEO | MIPI_DSI_MODE_VIDEO_SYNC_PULSE |
MIPI_DSI_CLOCK_NON_CONTINUOUS | MIPI_DSI_MODE_LPM;
ret = drm_panel_of_backlight(&priv->panel);
if (ret)
return dev_err_probe(dev, ret, "Failed to get backlight\n");
drm_panel_add(&priv->panel);
ret = mipi_dsi_attach(dsi);
if (ret) {
drm_panel_remove(&priv->panel);
return dev_err_probe(dev, ret, "Failed to attach to DSI host\n");
}
return 0;
}
static void renesas_r69328_remove(struct mipi_dsi_device *dsi)
{
struct renesas_r69328 *priv = mipi_dsi_get_drvdata(dsi);
int ret;
ret = mipi_dsi_detach(dsi);
if (ret)
dev_err(&dsi->dev, "Failed to detach from DSI host: %d\n", ret);
drm_panel_remove(&priv->panel);
}
static const struct of_device_id renesas_r69328_of_match[] = {
{ .compatible = "jdi,dx12d100vm0eaa" },
{ /* sentinel */ }
};
MODULE_DEVICE_TABLE(of, renesas_r69328_of_match);
static struct mipi_dsi_driver renesas_r69328_driver = {
.probe = renesas_r69328_probe,
.remove = renesas_r69328_remove,
.driver = {
.name = "panel-renesas-r69328",
.of_match_table = renesas_r69328_of_match,
},
};
module_mipi_dsi_driver(renesas_r69328_driver);
MODULE_AUTHOR("Maxim Schwalm <maxim.schwalm@gmail.com>");
MODULE_AUTHOR("Svyatoslav Ryhel <clamor95@gmail.com>");
MODULE_DESCRIPTION("Renesas R69328-based panel driver");
MODULE_LICENSE("GPL");
|