| .. | .. |
|---|
| 6 | 6 | * Yannick Fertre <yannick.fertre@st.com> |
|---|
| 7 | 7 | */ |
|---|
| 8 | 8 | |
|---|
| 9 | | -#include <linux/backlight.h> |
|---|
| 9 | +#include <linux/delay.h> |
|---|
| 10 | 10 | #include <linux/gpio/consumer.h> |
|---|
| 11 | +#include <linux/mod_devicetable.h> |
|---|
| 12 | +#include <linux/module.h> |
|---|
| 11 | 13 | #include <linux/regulator/consumer.h> |
|---|
| 12 | 14 | |
|---|
| 13 | 15 | #include <video/mipi_display.h> |
|---|
| 14 | 16 | |
|---|
| 15 | | -#include <drm/drmP.h> |
|---|
| 16 | 17 | #include <drm/drm_mipi_dsi.h> |
|---|
| 18 | +#include <drm/drm_modes.h> |
|---|
| 17 | 19 | #include <drm/drm_panel.h> |
|---|
| 18 | 20 | |
|---|
| 19 | 21 | /*** Manufacturer Command Set ***/ |
|---|
| .. | .. |
|---|
| 75 | 77 | struct drm_panel panel; |
|---|
| 76 | 78 | struct gpio_desc *reset_gpio; |
|---|
| 77 | 79 | struct regulator *supply; |
|---|
| 78 | | - struct backlight_device *backlight; |
|---|
| 79 | 80 | bool prepared; |
|---|
| 80 | 81 | bool enabled; |
|---|
| 81 | 82 | }; |
|---|
| .. | .. |
|---|
| 90 | 91 | .vsync_start = 1280 + 12, |
|---|
| 91 | 92 | .vsync_end = 1280 + 12 + 4, |
|---|
| 92 | 93 | .vtotal = 1280 + 12 + 4 + 12, |
|---|
| 93 | | - .vrefresh = 50, |
|---|
| 94 | 94 | .flags = 0, |
|---|
| 95 | 95 | .width_mm = 68, |
|---|
| 96 | 96 | .height_mm = 122, |
|---|
| .. | .. |
|---|
| 109 | 109 | |
|---|
| 110 | 110 | err = mipi_dsi_dcs_write_buffer(dsi, data, len); |
|---|
| 111 | 111 | if (err < 0) |
|---|
| 112 | | - DRM_ERROR_RATELIMITED("MIPI DSI DCS write buffer failed: %d\n", |
|---|
| 113 | | - err); |
|---|
| 112 | + dev_err_ratelimited(ctx->dev, "MIPI DSI DCS write buffer failed: %d\n", err); |
|---|
| 114 | 113 | } |
|---|
| 115 | 114 | |
|---|
| 116 | 115 | static void rm68200_dcs_write_cmd(struct rm68200 *ctx, u8 cmd, u8 value) |
|---|
| .. | .. |
|---|
| 120 | 119 | |
|---|
| 121 | 120 | err = mipi_dsi_dcs_write(dsi, cmd, &value, 1); |
|---|
| 122 | 121 | if (err < 0) |
|---|
| 123 | | - DRM_ERROR_RATELIMITED("MIPI DSI DCS write failed: %d\n", err); |
|---|
| 122 | + dev_err_ratelimited(ctx->dev, "MIPI DSI DCS write failed: %d\n", err); |
|---|
| 124 | 123 | } |
|---|
| 125 | 124 | |
|---|
| 126 | 125 | #define dcs_write_seq(ctx, seq...) \ |
|---|
| .. | .. |
|---|
| 239 | 238 | if (!ctx->enabled) |
|---|
| 240 | 239 | return 0; |
|---|
| 241 | 240 | |
|---|
| 242 | | - backlight_disable(ctx->backlight); |
|---|
| 243 | | - |
|---|
| 244 | 241 | ctx->enabled = false; |
|---|
| 245 | 242 | |
|---|
| 246 | 243 | return 0; |
|---|
| .. | .. |
|---|
| 257 | 254 | |
|---|
| 258 | 255 | ret = mipi_dsi_dcs_set_display_off(dsi); |
|---|
| 259 | 256 | if (ret) |
|---|
| 260 | | - DRM_WARN("failed to set display off: %d\n", ret); |
|---|
| 257 | + dev_warn(panel->dev, "failed to set display off: %d\n", ret); |
|---|
| 261 | 258 | |
|---|
| 262 | 259 | ret = mipi_dsi_dcs_enter_sleep_mode(dsi); |
|---|
| 263 | 260 | if (ret) |
|---|
| 264 | | - DRM_WARN("failed to enter sleep mode: %d\n", ret); |
|---|
| 261 | + dev_warn(panel->dev, "failed to enter sleep mode: %d\n", ret); |
|---|
| 265 | 262 | |
|---|
| 266 | 263 | msleep(120); |
|---|
| 267 | 264 | |
|---|
| .. | .. |
|---|
| 288 | 285 | |
|---|
| 289 | 286 | ret = regulator_enable(ctx->supply); |
|---|
| 290 | 287 | if (ret < 0) { |
|---|
| 291 | | - DRM_ERROR("failed to enable supply: %d\n", ret); |
|---|
| 288 | + dev_err(ctx->dev, "failed to enable supply: %d\n", ret); |
|---|
| 292 | 289 | return ret; |
|---|
| 293 | 290 | } |
|---|
| 294 | 291 | |
|---|
| .. | .. |
|---|
| 325 | 322 | if (ctx->enabled) |
|---|
| 326 | 323 | return 0; |
|---|
| 327 | 324 | |
|---|
| 328 | | - backlight_enable(ctx->backlight); |
|---|
| 329 | | - |
|---|
| 330 | 325 | ctx->enabled = true; |
|---|
| 331 | 326 | |
|---|
| 332 | 327 | return 0; |
|---|
| 333 | 328 | } |
|---|
| 334 | 329 | |
|---|
| 335 | | -static int rm68200_get_modes(struct drm_panel *panel) |
|---|
| 330 | +static int rm68200_get_modes(struct drm_panel *panel, |
|---|
| 331 | + struct drm_connector *connector) |
|---|
| 336 | 332 | { |
|---|
| 337 | 333 | struct drm_display_mode *mode; |
|---|
| 338 | 334 | |
|---|
| 339 | | - mode = drm_mode_duplicate(panel->drm, &default_mode); |
|---|
| 335 | + mode = drm_mode_duplicate(connector->dev, &default_mode); |
|---|
| 340 | 336 | if (!mode) { |
|---|
| 341 | | - DRM_ERROR("failed to add mode %ux%ux@%u\n", |
|---|
| 342 | | - default_mode.hdisplay, default_mode.vdisplay, |
|---|
| 343 | | - default_mode.vrefresh); |
|---|
| 337 | + dev_err(panel->dev, "failed to add mode %ux%u@%u\n", |
|---|
| 338 | + default_mode.hdisplay, default_mode.vdisplay, |
|---|
| 339 | + drm_mode_vrefresh(&default_mode)); |
|---|
| 344 | 340 | return -ENOMEM; |
|---|
| 345 | 341 | } |
|---|
| 346 | 342 | |
|---|
| 347 | 343 | drm_mode_set_name(mode); |
|---|
| 348 | 344 | |
|---|
| 349 | 345 | mode->type = DRM_MODE_TYPE_DRIVER | DRM_MODE_TYPE_PREFERRED; |
|---|
| 350 | | - drm_mode_probed_add(panel->connector, mode); |
|---|
| 346 | + drm_mode_probed_add(connector, mode); |
|---|
| 351 | 347 | |
|---|
| 352 | | - panel->connector->display_info.width_mm = mode->width_mm; |
|---|
| 353 | | - panel->connector->display_info.height_mm = mode->height_mm; |
|---|
| 348 | + connector->display_info.width_mm = mode->width_mm; |
|---|
| 349 | + connector->display_info.height_mm = mode->height_mm; |
|---|
| 354 | 350 | |
|---|
| 355 | 351 | return 1; |
|---|
| 356 | 352 | } |
|---|
| .. | .. |
|---|
| 383 | 379 | ctx->supply = devm_regulator_get(dev, "power"); |
|---|
| 384 | 380 | if (IS_ERR(ctx->supply)) { |
|---|
| 385 | 381 | ret = PTR_ERR(ctx->supply); |
|---|
| 386 | | - dev_err(dev, "cannot get regulator: %d\n", ret); |
|---|
| 382 | + if (ret != -EPROBE_DEFER) |
|---|
| 383 | + dev_err(dev, "cannot get regulator: %d\n", ret); |
|---|
| 387 | 384 | return ret; |
|---|
| 388 | 385 | } |
|---|
| 389 | | - |
|---|
| 390 | | - ctx->backlight = devm_of_find_backlight(dev); |
|---|
| 391 | | - if (IS_ERR(ctx->backlight)) |
|---|
| 392 | | - return PTR_ERR(ctx->backlight); |
|---|
| 393 | 386 | |
|---|
| 394 | 387 | mipi_dsi_set_drvdata(dsi, ctx); |
|---|
| 395 | 388 | |
|---|
| .. | .. |
|---|
| 400 | 393 | dsi->mode_flags = MIPI_DSI_MODE_VIDEO | MIPI_DSI_MODE_VIDEO_BURST | |
|---|
| 401 | 394 | MIPI_DSI_MODE_LPM; |
|---|
| 402 | 395 | |
|---|
| 403 | | - drm_panel_init(&ctx->panel); |
|---|
| 404 | | - ctx->panel.dev = dev; |
|---|
| 405 | | - ctx->panel.funcs = &rm68200_drm_funcs; |
|---|
| 396 | + drm_panel_init(&ctx->panel, dev, &rm68200_drm_funcs, |
|---|
| 397 | + DRM_MODE_CONNECTOR_DSI); |
|---|
| 398 | + |
|---|
| 399 | + ret = drm_panel_of_backlight(&ctx->panel); |
|---|
| 400 | + if (ret) |
|---|
| 401 | + return ret; |
|---|
| 406 | 402 | |
|---|
| 407 | 403 | drm_panel_add(&ctx->panel); |
|---|
| 408 | 404 | |
|---|