|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
| 2 | +// Copyright (c) 2025 FIXME |
| 3 | +// Generated with linux-mdss-dsi-panel-driver-generator from vendor device tree: |
| 4 | +// Copyright (c) 2013, The Linux Foundation. All rights reserved. (FIXME) |
| 5 | + |
| 6 | +#include <linux/backlight.h> |
| 7 | +#include <linux/delay.h> |
| 8 | +#include <linux/gpio/consumer.h> |
| 9 | +#include <linux/mod_devicetable.h> |
| 10 | +#include <linux/module.h> |
| 11 | +#include <linux/regulator/consumer.h> |
| 12 | + |
| 13 | +#include <drm/drm_mipi_dsi.h> |
| 14 | +#include <drm/drm_modes.h> |
| 15 | +#include <drm/drm_panel.h> |
| 16 | +#include <drm/drm_probe_helper.h> |
| 17 | + |
| 18 | +struct tm5p5_nt35596 { |
| 19 | + struct drm_panel panel; |
| 20 | + struct mipi_dsi_device *dsi; |
| 21 | + struct regulator *supply; |
| 22 | + struct gpio_desc *reset_gpio; |
| 23 | + struct gpio_desc *backlight_gpio; |
| 24 | +}; |
| 25 | + |
| 26 | +static inline struct tm5p5_nt35596 *to_tm5p5_nt35596(struct drm_panel *panel) |
| 27 | +{ |
| 28 | + return container_of(panel, struct tm5p5_nt35596, panel); |
| 29 | +} |
| 30 | + |
| 31 | +static void tm5p5_nt35596_reset(struct tm5p5_nt35596 *ctx) |
| 32 | +{ |
| 33 | + gpiod_set_value_cansleep(ctx->reset_gpio, 0); |
| 34 | + usleep_range(1000, 2000); |
| 35 | + gpiod_set_value_cansleep(ctx->reset_gpio, 1); |
| 36 | + usleep_range(1000, 2000); |
| 37 | + gpiod_set_value_cansleep(ctx->reset_gpio, 0); |
| 38 | + usleep_range(15000, 16000); |
| 39 | +} |
| 40 | + |
| 41 | +static int tm5p5_nt35596_on(struct tm5p5_nt35596 *ctx) |
| 42 | +{ |
| 43 | + struct mipi_dsi_multi_context dsi_ctx = { .dsi = ctx->dsi }; |
| 44 | + |
| 45 | + mipi_dsi_generic_write_seq_multi(&dsi_ctx, 0xff, 0x05); |
| 46 | + mipi_dsi_generic_write_seq_multi(&dsi_ctx, 0xfb, 0x01); |
| 47 | + mipi_dsi_generic_write_seq_multi(&dsi_ctx, 0xc5, 0x31); |
| 48 | + mipi_dsi_generic_write_seq_multi(&dsi_ctx, 0xff, 0x04); |
| 49 | + mipi_dsi_generic_write_seq_multi(&dsi_ctx, 0x01, 0x84); |
| 50 | + mipi_dsi_generic_write_seq_multi(&dsi_ctx, 0x05, 0x25); |
| 51 | + mipi_dsi_generic_write_seq_multi(&dsi_ctx, 0x06, 0x01); |
| 52 | + mipi_dsi_generic_write_seq_multi(&dsi_ctx, 0x07, 0x20); |
| 53 | + mipi_dsi_generic_write_seq_multi(&dsi_ctx, 0x08, 0x06); |
| 54 | + mipi_dsi_generic_write_seq_multi(&dsi_ctx, 0x09, 0x08); |
| 55 | + mipi_dsi_generic_write_seq_multi(&dsi_ctx, 0x0a, 0x10); |
| 56 | + mipi_dsi_generic_write_seq_multi(&dsi_ctx, 0x0b, 0x10); |
| 57 | + mipi_dsi_generic_write_seq_multi(&dsi_ctx, 0x0c, 0x10); |
| 58 | + mipi_dsi_generic_write_seq_multi(&dsi_ctx, 0x0d, 0x14); |
| 59 | + mipi_dsi_generic_write_seq_multi(&dsi_ctx, 0x0e, 0x14); |
| 60 | + mipi_dsi_generic_write_seq_multi(&dsi_ctx, 0x0f, 0x14); |
| 61 | + mipi_dsi_generic_write_seq_multi(&dsi_ctx, 0x10, 0x14); |
| 62 | + mipi_dsi_generic_write_seq_multi(&dsi_ctx, 0x11, 0x14); |
| 63 | + mipi_dsi_generic_write_seq_multi(&dsi_ctx, 0x12, 0x14); |
| 64 | + mipi_dsi_generic_write_seq_multi(&dsi_ctx, 0x17, 0xf3); |
| 65 | + mipi_dsi_generic_write_seq_multi(&dsi_ctx, 0x18, 0xc0); |
| 66 | + mipi_dsi_generic_write_seq_multi(&dsi_ctx, 0x19, 0xc0); |
| 67 | + mipi_dsi_generic_write_seq_multi(&dsi_ctx, 0x1a, 0xc0); |
| 68 | + mipi_dsi_generic_write_seq_multi(&dsi_ctx, 0x1b, 0xb3); |
| 69 | + mipi_dsi_generic_write_seq_multi(&dsi_ctx, 0x1c, 0xb3); |
| 70 | + mipi_dsi_generic_write_seq_multi(&dsi_ctx, 0x1d, 0xb3); |
| 71 | + mipi_dsi_generic_write_seq_multi(&dsi_ctx, 0x1e, 0xb3); |
| 72 | + mipi_dsi_generic_write_seq_multi(&dsi_ctx, 0x1f, 0xb3); |
| 73 | + mipi_dsi_generic_write_seq_multi(&dsi_ctx, 0x20, 0xb3); |
| 74 | + mipi_dsi_generic_write_seq_multi(&dsi_ctx, 0xfb, 0x01); |
| 75 | + mipi_dsi_generic_write_seq_multi(&dsi_ctx, 0xff, 0x00); |
| 76 | + mipi_dsi_generic_write_seq_multi(&dsi_ctx, 0xfb, 0x01); |
| 77 | + mipi_dsi_generic_write_seq_multi(&dsi_ctx, 0x35, 0x01); |
| 78 | + mipi_dsi_generic_write_seq_multi(&dsi_ctx, 0xd3, 0x06); |
| 79 | + mipi_dsi_generic_write_seq_multi(&dsi_ctx, 0xd4, 0x04); |
| 80 | + mipi_dsi_generic_write_seq_multi(&dsi_ctx, 0x51, 0x0d); |
| 81 | + mipi_dsi_generic_write_seq_multi(&dsi_ctx, 0x53, 0x24); |
| 82 | + mipi_dsi_generic_write_seq_multi(&dsi_ctx, 0x5e, 0x0d); |
| 83 | + mipi_dsi_generic_write_seq_multi(&dsi_ctx, 0x11, 0x00); |
| 84 | + mipi_dsi_msleep(&dsi_ctx, 100); |
| 85 | + mipi_dsi_generic_write_seq_multi(&dsi_ctx, 0x29, 0x00); |
| 86 | + |
| 87 | + return dsi_ctx.accum_err; |
| 88 | +} |
| 89 | + |
| 90 | +static int tm5p5_nt35596_off(struct tm5p5_nt35596 *ctx) |
| 91 | +{ |
| 92 | + struct mipi_dsi_multi_context dsi_ctx = { .dsi = ctx->dsi }; |
| 93 | + |
| 94 | + mipi_dsi_dcs_set_display_off_multi(&dsi_ctx); |
| 95 | + mipi_dsi_msleep(&dsi_ctx, 60); |
| 96 | + mipi_dsi_dcs_enter_sleep_mode_multi(&dsi_ctx); |
| 97 | + // WARNING: Ignoring weird NULL_PACKET |
| 98 | + mipi_dsi_msleep(&dsi_ctx, 72); |
| 99 | + mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0x4f, 0x01); |
| 100 | + |
| 101 | + return dsi_ctx.accum_err; |
| 102 | +} |
| 103 | + |
| 104 | +static int tm5p5_nt35596_prepare(struct drm_panel *panel) |
| 105 | +{ |
| 106 | + struct tm5p5_nt35596 *ctx = to_tm5p5_nt35596(panel); |
| 107 | + struct device *dev = &ctx->dsi->dev; |
| 108 | + int ret; |
| 109 | + |
| 110 | + ret = regulator_enable(ctx->supply); |
| 111 | + if (ret < 0) { |
| 112 | + dev_err(dev, "Failed to enable regulator: %d\n", ret); |
| 113 | + return ret; |
| 114 | + } |
| 115 | + |
| 116 | + tm5p5_nt35596_reset(ctx); |
| 117 | + |
| 118 | + ret = tm5p5_nt35596_on(ctx); |
| 119 | + if (ret < 0) { |
| 120 | + dev_err(dev, "Failed to initialize panel: %d\n", ret); |
| 121 | + gpiod_set_value_cansleep(ctx->reset_gpio, 1); |
| 122 | + regulator_disable(ctx->supply); |
| 123 | + return ret; |
| 124 | + } |
| 125 | + |
| 126 | + return 0; |
| 127 | +} |
| 128 | + |
| 129 | +static int tm5p5_nt35596_unprepare(struct drm_panel *panel) |
| 130 | +{ |
| 131 | + struct tm5p5_nt35596 *ctx = to_tm5p5_nt35596(panel); |
| 132 | + struct device *dev = &ctx->dsi->dev; |
| 133 | + int ret; |
| 134 | + |
| 135 | + ret = tm5p5_nt35596_off(ctx); |
| 136 | + if (ret < 0) |
| 137 | + dev_err(dev, "Failed to un-initialize panel: %d\n", ret); |
| 138 | + |
| 139 | + gpiod_set_value_cansleep(ctx->reset_gpio, 1); |
| 140 | + regulator_disable(ctx->supply); |
| 141 | + |
| 142 | + return 0; |
| 143 | +} |
| 144 | + |
| 145 | +static const struct drm_display_mode tm5p5_nt35596_mode = { |
| 146 | + .clock = (1080 + 100 + 8 + 16) * (1920 + 4 + 2 + 4) * 60 / 1000, |
| 147 | + .hdisplay = 1080, |
| 148 | + .hsync_start = 1080 + 100, |
| 149 | + .hsync_end = 1080 + 100 + 8, |
| 150 | + .htotal = 1080 + 100 + 8 + 16, |
| 151 | + .vdisplay = 1920, |
| 152 | + .vsync_start = 1920 + 4, |
| 153 | + .vsync_end = 1920 + 4 + 2, |
| 154 | + .vtotal = 1920 + 4 + 2 + 4, |
| 155 | + .width_mm = 68, |
| 156 | + .height_mm = 121, |
| 157 | + .type = DRM_MODE_TYPE_DRIVER, |
| 158 | +}; |
| 159 | + |
| 160 | +static int tm5p5_nt35596_get_modes(struct drm_panel *panel, |
| 161 | + struct drm_connector *connector) |
| 162 | +{ |
| 163 | + return drm_connector_helper_get_modes_fixed(connector, &tm5p5_nt35596_mode); |
| 164 | +} |
| 165 | + |
| 166 | +static const struct drm_panel_funcs tm5p5_nt35596_panel_funcs = { |
| 167 | + .prepare = tm5p5_nt35596_prepare, |
| 168 | + .unprepare = tm5p5_nt35596_unprepare, |
| 169 | + .get_modes = tm5p5_nt35596_get_modes, |
| 170 | +}; |
| 171 | + |
| 172 | +static int tm5p5_nt35596_bl_update_status(struct backlight_device *bl) |
| 173 | +{ |
| 174 | + struct mipi_dsi_device *dsi = bl_get_data(bl); |
| 175 | + struct tm5p5_nt35596 *ctx = mipi_dsi_get_drvdata(dsi); |
| 176 | + u16 brightness = backlight_get_brightness(bl); |
| 177 | + int ret; |
| 178 | + |
| 179 | + gpiod_set_value_cansleep(ctx->backlight_gpio, !!brightness); |
| 180 | + |
| 181 | + dsi->mode_flags &= ~MIPI_DSI_MODE_LPM; |
| 182 | + |
| 183 | + ret = mipi_dsi_dcs_set_display_brightness(dsi, brightness); |
| 184 | + if (ret < 0) |
| 185 | + return ret; |
| 186 | + |
| 187 | + dsi->mode_flags |= MIPI_DSI_MODE_LPM; |
| 188 | + |
| 189 | + return 0; |
| 190 | +} |
| 191 | + |
| 192 | +static const struct backlight_ops tm5p5_nt35596_bl_ops = { |
| 193 | + .update_status = tm5p5_nt35596_bl_update_status, |
| 194 | +}; |
| 195 | + |
| 196 | +static struct backlight_device * |
| 197 | +tm5p5_nt35596_create_backlight(struct mipi_dsi_device *dsi) |
| 198 | +{ |
| 199 | + struct device *dev = &dsi->dev; |
| 200 | + const struct backlight_properties props = { |
| 201 | + .type = BACKLIGHT_RAW, |
| 202 | + .brightness = 255, |
| 203 | + .max_brightness = 255, |
| 204 | + }; |
| 205 | + |
| 206 | + return devm_backlight_device_register(dev, dev_name(dev), dev, dsi, |
| 207 | + &tm5p5_nt35596_bl_ops, &props); |
| 208 | +} |
| 209 | + |
| 210 | +static int tm5p5_nt35596_probe(struct mipi_dsi_device *dsi) |
| 211 | +{ |
| 212 | + struct device *dev = &dsi->dev; |
| 213 | + struct tm5p5_nt35596 *ctx; |
| 214 | + int ret; |
| 215 | + |
| 216 | + ctx = devm_kzalloc(dev, sizeof(*ctx), GFP_KERNEL); |
| 217 | + if (!ctx) |
| 218 | + return -ENOMEM; |
| 219 | + |
| 220 | + ctx->supply = devm_regulator_get(dev, "power"); |
| 221 | + if (IS_ERR(ctx->supply)) |
| 222 | + return dev_err_probe(dev, PTR_ERR(ctx->supply), |
| 223 | + "Failed to get power regulator\n"); |
| 224 | + |
| 225 | + ctx->reset_gpio = devm_gpiod_get(dev, "reset", GPIOD_OUT_HIGH); |
| 226 | + if (IS_ERR(ctx->reset_gpio)) |
| 227 | + return dev_err_probe(dev, PTR_ERR(ctx->reset_gpio), |
| 228 | + "Failed to get reset-gpios\n"); |
| 229 | + |
| 230 | + ctx->backlight_gpio = devm_gpiod_get(dev, "backlight", GPIOD_OUT_LOW); |
| 231 | + if (IS_ERR(ctx->backlight_gpio)) |
| 232 | + return dev_err_probe(dev, PTR_ERR(ctx->backlight_gpio), |
| 233 | + "Failed to get backlight-gpios\n"); |
| 234 | + |
| 235 | + ctx->dsi = dsi; |
| 236 | + mipi_dsi_set_drvdata(dsi, ctx); |
| 237 | + |
| 238 | + dsi->lanes = 4; |
| 239 | + dsi->format = MIPI_DSI_FMT_RGB888; |
| 240 | + dsi->mode_flags = MIPI_DSI_MODE_VIDEO | MIPI_DSI_MODE_VIDEO_BURST | |
| 241 | + MIPI_DSI_MODE_VIDEO_HSE | MIPI_DSI_MODE_NO_EOT_PACKET | |
| 242 | + MIPI_DSI_CLOCK_NON_CONTINUOUS | MIPI_DSI_MODE_LPM; |
| 243 | + |
| 244 | + drm_panel_init(&ctx->panel, dev, &tm5p5_nt35596_panel_funcs, |
| 245 | + DRM_MODE_CONNECTOR_DSI); |
| 246 | + ctx->panel.prepare_prev_first = true; |
| 247 | + |
| 248 | + ctx->panel.backlight = tm5p5_nt35596_create_backlight(dsi); |
| 249 | + if (IS_ERR(ctx->panel.backlight)) |
| 250 | + return dev_err_probe(dev, PTR_ERR(ctx->panel.backlight), |
| 251 | + "Failed to create backlight\n"); |
| 252 | + |
| 253 | + drm_panel_add(&ctx->panel); |
| 254 | + |
| 255 | + ret = mipi_dsi_attach(dsi); |
| 256 | + if (ret < 0) { |
| 257 | + drm_panel_remove(&ctx->panel); |
| 258 | + return dev_err_probe(dev, ret, "Failed to attach to DSI host\n"); |
| 259 | + } |
| 260 | + |
| 261 | + return 0; |
| 262 | +} |
| 263 | + |
| 264 | +static void tm5p5_nt35596_remove(struct mipi_dsi_device *dsi) |
| 265 | +{ |
| 266 | + struct tm5p5_nt35596 *ctx = mipi_dsi_get_drvdata(dsi); |
| 267 | + int ret; |
| 268 | + |
| 269 | + ret = mipi_dsi_detach(dsi); |
| 270 | + if (ret < 0) |
| 271 | + dev_err(&dsi->dev, "Failed to detach from DSI host: %d\n", ret); |
| 272 | + |
| 273 | + drm_panel_remove(&ctx->panel); |
| 274 | +} |
| 275 | + |
| 276 | +static const struct of_device_id tm5p5_nt35596_of_match[] = { |
| 277 | + { .compatible = "asus,z00t-tm5p5-nt35596" }, // FIXME |
| 278 | + { /* sentinel */ } |
| 279 | +}; |
| 280 | +MODULE_DEVICE_TABLE(of, tm5p5_nt35596_of_match); |
| 281 | + |
| 282 | +static struct mipi_dsi_driver tm5p5_nt35596_driver = { |
| 283 | + .probe = tm5p5_nt35596_probe, |
| 284 | + .remove = tm5p5_nt35596_remove, |
| 285 | + .driver = { |
| 286 | + .name = "panel-asus-z00t-tm5p5-nt35596", |
| 287 | + .of_match_table = tm5p5_nt35596_of_match, |
| 288 | + }, |
| 289 | +}; |
| 290 | +module_mipi_dsi_driver(tm5p5_nt35596_driver); |
| 291 | + |
| 292 | +MODULE_AUTHOR("linux-mdss-dsi-panel-driver-generator <fix@me>"); // FIXME |
| 293 | +MODULE_DESCRIPTION("DRM driver for tm5p5 nt35596 1080p video mode dsi panel"); |
| 294 | +MODULE_LICENSE("GPL"); |
0 commit comments