1 // SPDX-License-Identifier: GPL-2.0-only
2 /* Copyright (c) 2021 Linaro Ltd.
3 * Generated with linux-mdss-dsi-panel-driver-generator from vendor device tree:
4 * Copyright (c) 2013-2014, The Linux Foundation. All rights reserved.
7 #include <linux/delay.h>
8 #include <linux/gpio/consumer.h>
9 #include <linux/module.h>
11 #include <linux/regulator/consumer.h>
13 #include <video/mipi_display.h>
15 #include <drm/drm_mipi_dsi.h>
16 #include <drm/drm_modes.h>
17 #include <drm/drm_panel.h>
20 struct drm_panel panel;
21 struct mipi_dsi_device *dsi;
22 struct regulator *vddi_supply;
23 struct regulator *vddh_supply;
24 struct regulator *avdd_supply;
25 struct regulator *avee_supply;
26 struct gpio_desc *reset_gpio;
30 static inline struct sharp_ls060 *to_sharp_ls060(struct drm_panel *panel)
32 return container_of(panel, struct sharp_ls060, panel);
35 #define dsi_dcs_write_seq(dsi, seq...) ({ \
36 static const u8 d[] = { seq }; \
38 mipi_dsi_dcs_write_buffer(dsi, d, ARRAY_SIZE(d)); \
41 static void sharp_ls060_reset(struct sharp_ls060 *ctx)
43 gpiod_set_value_cansleep(ctx->reset_gpio, 0);
44 usleep_range(10000, 11000);
45 gpiod_set_value_cansleep(ctx->reset_gpio, 1);
46 usleep_range(10000, 11000);
47 gpiod_set_value_cansleep(ctx->reset_gpio, 0);
48 usleep_range(10000, 11000);
51 static int sharp_ls060_on(struct sharp_ls060 *ctx)
53 struct mipi_dsi_device *dsi = ctx->dsi;
54 struct device *dev = &dsi->dev;
57 dsi->mode_flags |= MIPI_DSI_MODE_LPM;
59 ret = dsi_dcs_write_seq(dsi, 0xbb, 0x13);
61 dev_err(dev, "Failed to send command: %d\n", ret);
65 ret = dsi_dcs_write_seq(dsi, MIPI_DCS_WRITE_MEMORY_START);
67 dev_err(dev, "Failed to send command: %d\n", ret);
71 ret = mipi_dsi_dcs_exit_sleep_mode(dsi);
73 dev_err(dev, "Failed to exit sleep mode: %d\n", ret);
78 ret = mipi_dsi_dcs_set_display_on(dsi);
80 dev_err(dev, "Failed to set display on: %d\n", ret);
88 static int sharp_ls060_off(struct sharp_ls060 *ctx)
90 struct mipi_dsi_device *dsi = ctx->dsi;
91 struct device *dev = &dsi->dev;
94 dsi->mode_flags &= ~MIPI_DSI_MODE_LPM;
96 ret = mipi_dsi_dcs_set_display_off(dsi);
98 dev_err(dev, "Failed to set display off: %d\n", ret);
101 usleep_range(2000, 3000);
103 ret = mipi_dsi_dcs_enter_sleep_mode(dsi);
105 dev_err(dev, "Failed to enter sleep mode: %d\n", ret);
113 static int sharp_ls060_prepare(struct drm_panel *panel)
115 struct sharp_ls060 *ctx = to_sharp_ls060(panel);
116 struct device *dev = &ctx->dsi->dev;
122 ret = regulator_enable(ctx->vddi_supply);
126 ret = regulator_enable(ctx->avdd_supply);
130 usleep_range(1000, 2000);
132 ret = regulator_enable(ctx->avee_supply);
136 usleep_range(10000, 11000);
138 ret = regulator_enable(ctx->vddh_supply);
142 usleep_range(10000, 11000);
144 sharp_ls060_reset(ctx);
146 ret = sharp_ls060_on(ctx);
148 dev_err(dev, "Failed to initialize panel: %d\n", ret);
152 ctx->prepared = true;
157 regulator_disable(ctx->vddh_supply);
159 usleep_range(10000, 11000);
162 regulator_disable(ctx->avee_supply);
165 regulator_disable(ctx->avdd_supply);
167 gpiod_set_value_cansleep(ctx->reset_gpio, 1);
170 regulator_disable(ctx->vddi_supply);
175 static int sharp_ls060_unprepare(struct drm_panel *panel)
177 struct sharp_ls060 *ctx = to_sharp_ls060(panel);
178 struct device *dev = &ctx->dsi->dev;
184 ret = sharp_ls060_off(ctx);
186 dev_err(dev, "Failed to un-initialize panel: %d\n", ret);
188 regulator_disable(ctx->vddh_supply);
190 usleep_range(10000, 11000);
192 regulator_disable(ctx->avee_supply);
193 regulator_disable(ctx->avdd_supply);
195 gpiod_set_value_cansleep(ctx->reset_gpio, 1);
197 regulator_disable(ctx->vddi_supply);
199 ctx->prepared = false;
203 static const struct drm_display_mode sharp_ls060_mode = {
204 .clock = (1080 + 96 + 16 + 64) * (1920 + 4 + 1 + 16) * 60 / 1000,
206 .hsync_start = 1080 + 96,
207 .hsync_end = 1080 + 96 + 16,
208 .htotal = 1080 + 96 + 16 + 64,
210 .vsync_start = 1920 + 4,
211 .vsync_end = 1920 + 4 + 1,
212 .vtotal = 1920 + 4 + 1 + 16,
217 static int sharp_ls060_get_modes(struct drm_panel *panel,
218 struct drm_connector *connector)
220 struct drm_display_mode *mode;
222 mode = drm_mode_duplicate(connector->dev, &sharp_ls060_mode);
226 drm_mode_set_name(mode);
228 mode->type = DRM_MODE_TYPE_DRIVER | DRM_MODE_TYPE_PREFERRED;
229 connector->display_info.width_mm = mode->width_mm;
230 connector->display_info.height_mm = mode->height_mm;
231 drm_mode_probed_add(connector, mode);
236 static const struct drm_panel_funcs sharp_ls060_panel_funcs = {
237 .prepare = sharp_ls060_prepare,
238 .unprepare = sharp_ls060_unprepare,
239 .get_modes = sharp_ls060_get_modes,
242 static int sharp_ls060_probe(struct mipi_dsi_device *dsi)
244 struct device *dev = &dsi->dev;
245 struct sharp_ls060 *ctx;
248 ctx = devm_kzalloc(dev, sizeof(*ctx), GFP_KERNEL);
252 ctx->vddi_supply = devm_regulator_get(dev, "vddi");
253 if (IS_ERR(ctx->vddi_supply))
254 return PTR_ERR(ctx->vddi_supply);
256 ctx->vddh_supply = devm_regulator_get(dev, "vddh");
257 if (IS_ERR(ctx->vddh_supply))
258 return PTR_ERR(ctx->vddh_supply);
260 ctx->avdd_supply = devm_regulator_get(dev, "avdd");
261 if (IS_ERR(ctx->avdd_supply))
262 return PTR_ERR(ctx->avdd_supply);
264 ctx->avee_supply = devm_regulator_get(dev, "avee");
265 if (IS_ERR(ctx->avee_supply))
266 return PTR_ERR(ctx->avee_supply);
268 ctx->reset_gpio = devm_gpiod_get(dev, "reset", GPIOD_OUT_HIGH);
269 if (IS_ERR(ctx->reset_gpio))
270 return dev_err_probe(dev, PTR_ERR(ctx->reset_gpio),
271 "Failed to get reset-gpios\n");
274 mipi_dsi_set_drvdata(dsi, ctx);
277 dsi->format = MIPI_DSI_FMT_RGB888;
278 dsi->mode_flags = MIPI_DSI_MODE_VIDEO | MIPI_DSI_MODE_VIDEO_BURST |
279 MIPI_DSI_MODE_NO_EOT_PACKET |
280 MIPI_DSI_CLOCK_NON_CONTINUOUS;
282 drm_panel_init(&ctx->panel, dev, &sharp_ls060_panel_funcs,
283 DRM_MODE_CONNECTOR_DSI);
285 ret = drm_panel_of_backlight(&ctx->panel);
287 return dev_err_probe(dev, ret, "Failed to get backlight\n");
289 drm_panel_add(&ctx->panel);
291 ret = mipi_dsi_attach(dsi);
293 dev_err(dev, "Failed to attach to DSI host: %d\n", ret);
294 drm_panel_remove(&ctx->panel);
301 static int sharp_ls060_remove(struct mipi_dsi_device *dsi)
303 struct sharp_ls060 *ctx = mipi_dsi_get_drvdata(dsi);
306 ret = mipi_dsi_detach(dsi);
308 dev_err(&dsi->dev, "Failed to detach from DSI host: %d\n", ret);
310 drm_panel_remove(&ctx->panel);
315 static const struct of_device_id sharp_ls060t1sx01_of_match[] = {
316 { .compatible = "sharp,ls060t1sx01" },
319 MODULE_DEVICE_TABLE(of, sharp_ls060t1sx01_of_match);
321 static struct mipi_dsi_driver sharp_ls060_driver = {
322 .probe = sharp_ls060_probe,
323 .remove = sharp_ls060_remove,
325 .name = "panel-sharp-ls060t1sx01",
326 .of_match_table = sharp_ls060t1sx01_of_match,
329 module_mipi_dsi_driver(sharp_ls060_driver);
331 MODULE_AUTHOR("Dmitry Baryshkov <dmitry.baryshkov@linaro.org>");
332 MODULE_DESCRIPTION("DRM driver for Sharp LS060T1SX01 1080p video mode dsi panel");
333 MODULE_LICENSE("GPL v2");