| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * Copyright (C) 2017 Free Electrons |
|---|
| 3 | | - * |
|---|
| 4 | | - * This program is free software; you can redistribute it and/or |
|---|
| 5 | | - * modify it under the terms of the GNU General Public License version |
|---|
| 6 | | - * 2 as published by the Free Software Foundation. |
|---|
| 7 | 4 | */ |
|---|
| 8 | 5 | |
|---|
| 6 | +#include <linux/delay.h> |
|---|
| 9 | 7 | #include <linux/gpio/consumer.h> |
|---|
| 8 | +#include <linux/module.h> |
|---|
| 10 | 9 | #include <linux/regulator/consumer.h> |
|---|
| 11 | 10 | #include <linux/spi/spi.h> |
|---|
| 12 | 11 | |
|---|
| 13 | | -#include <drm/drmP.h> |
|---|
| 14 | | -#include <drm/drm_panel.h> |
|---|
| 15 | | - |
|---|
| 16 | 12 | #include <video/mipi_display.h> |
|---|
| 13 | + |
|---|
| 14 | +#include <drm/drm_device.h> |
|---|
| 15 | +#include <drm/drm_modes.h> |
|---|
| 16 | +#include <drm/drm_panel.h> |
|---|
| 17 | 17 | |
|---|
| 18 | 18 | #define ST7789V_COLMOD_RGB_FMT_18BITS (6 << 4) |
|---|
| 19 | 19 | #define ST7789V_COLMOD_CTRL_FMT_18BITS (6 << 0) |
|---|
| .. | .. |
|---|
| 115 | 115 | struct drm_panel panel; |
|---|
| 116 | 116 | struct spi_device *spi; |
|---|
| 117 | 117 | struct gpio_desc *reset; |
|---|
| 118 | | - struct backlight_device *backlight; |
|---|
| 119 | 118 | struct regulator *power; |
|---|
| 120 | 119 | }; |
|---|
| 121 | 120 | |
|---|
| .. | .. |
|---|
| 166 | 165 | .vsync_start = 320 + 8, |
|---|
| 167 | 166 | .vsync_end = 320 + 8 + 4, |
|---|
| 168 | 167 | .vtotal = 320 + 8 + 4 + 4, |
|---|
| 169 | | - .vrefresh = 60, |
|---|
| 170 | 168 | }; |
|---|
| 171 | 169 | |
|---|
| 172 | | -static int st7789v_get_modes(struct drm_panel *panel) |
|---|
| 170 | +static int st7789v_get_modes(struct drm_panel *panel, |
|---|
| 171 | + struct drm_connector *connector) |
|---|
| 173 | 172 | { |
|---|
| 174 | | - struct drm_connector *connector = panel->connector; |
|---|
| 175 | 173 | struct drm_display_mode *mode; |
|---|
| 176 | 174 | |
|---|
| 177 | | - mode = drm_mode_duplicate(panel->drm, &default_mode); |
|---|
| 175 | + mode = drm_mode_duplicate(connector->dev, &default_mode); |
|---|
| 178 | 176 | if (!mode) { |
|---|
| 179 | | - dev_err(panel->drm->dev, "failed to add mode %ux%ux@%u\n", |
|---|
| 177 | + dev_err(panel->dev, "failed to add mode %ux%ux@%u\n", |
|---|
| 180 | 178 | default_mode.hdisplay, default_mode.vdisplay, |
|---|
| 181 | | - default_mode.vrefresh); |
|---|
| 179 | + drm_mode_vrefresh(&default_mode)); |
|---|
| 182 | 180 | return -ENOMEM; |
|---|
| 183 | 181 | } |
|---|
| 184 | 182 | |
|---|
| .. | .. |
|---|
| 187 | 185 | mode->type = DRM_MODE_TYPE_DRIVER | DRM_MODE_TYPE_PREFERRED; |
|---|
| 188 | 186 | drm_mode_probed_add(connector, mode); |
|---|
| 189 | 187 | |
|---|
| 190 | | - panel->connector->display_info.width_mm = 61; |
|---|
| 191 | | - panel->connector->display_info.height_mm = 103; |
|---|
| 188 | + connector->display_info.width_mm = 61; |
|---|
| 189 | + connector->display_info.height_mm = 103; |
|---|
| 192 | 190 | |
|---|
| 193 | 191 | return 1; |
|---|
| 194 | 192 | } |
|---|
| .. | .. |
|---|
| 322 | 320 | { |
|---|
| 323 | 321 | struct st7789v *ctx = panel_to_st7789v(panel); |
|---|
| 324 | 322 | |
|---|
| 325 | | - if (ctx->backlight) { |
|---|
| 326 | | - ctx->backlight->props.state &= ~BL_CORE_FBBLANK; |
|---|
| 327 | | - ctx->backlight->props.power = FB_BLANK_UNBLANK; |
|---|
| 328 | | - backlight_update_status(ctx->backlight); |
|---|
| 329 | | - } |
|---|
| 330 | | - |
|---|
| 331 | 323 | return st7789v_write_command(ctx, MIPI_DCS_SET_DISPLAY_ON); |
|---|
| 332 | 324 | } |
|---|
| 333 | 325 | |
|---|
| .. | .. |
|---|
| 337 | 329 | int ret; |
|---|
| 338 | 330 | |
|---|
| 339 | 331 | ST7789V_TEST(ret, st7789v_write_command(ctx, MIPI_DCS_SET_DISPLAY_OFF)); |
|---|
| 340 | | - |
|---|
| 341 | | - if (ctx->backlight) { |
|---|
| 342 | | - ctx->backlight->props.power = FB_BLANK_POWERDOWN; |
|---|
| 343 | | - ctx->backlight->props.state |= BL_CORE_FBBLANK; |
|---|
| 344 | | - backlight_update_status(ctx->backlight); |
|---|
| 345 | | - } |
|---|
| 346 | 332 | |
|---|
| 347 | 333 | return 0; |
|---|
| 348 | 334 | } |
|---|
| .. | .. |
|---|
| 369 | 355 | |
|---|
| 370 | 356 | static int st7789v_probe(struct spi_device *spi) |
|---|
| 371 | 357 | { |
|---|
| 372 | | - struct device_node *backlight; |
|---|
| 373 | 358 | struct st7789v *ctx; |
|---|
| 374 | 359 | int ret; |
|---|
| 375 | 360 | |
|---|
| .. | .. |
|---|
| 380 | 365 | spi_set_drvdata(spi, ctx); |
|---|
| 381 | 366 | ctx->spi = spi; |
|---|
| 382 | 367 | |
|---|
| 383 | | - drm_panel_init(&ctx->panel); |
|---|
| 384 | | - ctx->panel.dev = &spi->dev; |
|---|
| 385 | | - ctx->panel.funcs = &st7789v_drm_funcs; |
|---|
| 368 | + drm_panel_init(&ctx->panel, &spi->dev, &st7789v_drm_funcs, |
|---|
| 369 | + DRM_MODE_CONNECTOR_DPI); |
|---|
| 386 | 370 | |
|---|
| 387 | 371 | ctx->power = devm_regulator_get(&spi->dev, "power"); |
|---|
| 388 | 372 | if (IS_ERR(ctx->power)) |
|---|
| .. | .. |
|---|
| 394 | 378 | return PTR_ERR(ctx->reset); |
|---|
| 395 | 379 | } |
|---|
| 396 | 380 | |
|---|
| 397 | | - backlight = of_parse_phandle(spi->dev.of_node, "backlight", 0); |
|---|
| 398 | | - if (backlight) { |
|---|
| 399 | | - ctx->backlight = of_find_backlight_by_node(backlight); |
|---|
| 400 | | - of_node_put(backlight); |
|---|
| 381 | + ret = drm_panel_of_backlight(&ctx->panel); |
|---|
| 382 | + if (ret) |
|---|
| 383 | + return ret; |
|---|
| 401 | 384 | |
|---|
| 402 | | - if (!ctx->backlight) |
|---|
| 403 | | - return -EPROBE_DEFER; |
|---|
| 404 | | - } |
|---|
| 405 | | - |
|---|
| 406 | | - ret = drm_panel_add(&ctx->panel); |
|---|
| 407 | | - if (ret < 0) |
|---|
| 408 | | - goto err_free_backlight; |
|---|
| 385 | + drm_panel_add(&ctx->panel); |
|---|
| 409 | 386 | |
|---|
| 410 | 387 | return 0; |
|---|
| 411 | | - |
|---|
| 412 | | -err_free_backlight: |
|---|
| 413 | | - if (ctx->backlight) |
|---|
| 414 | | - put_device(&ctx->backlight->dev); |
|---|
| 415 | | - |
|---|
| 416 | | - return ret; |
|---|
| 417 | 388 | } |
|---|
| 418 | 389 | |
|---|
| 419 | 390 | static int st7789v_remove(struct spi_device *spi) |
|---|
| .. | .. |
|---|
| 421 | 392 | struct st7789v *ctx = spi_get_drvdata(spi); |
|---|
| 422 | 393 | |
|---|
| 423 | 394 | drm_panel_remove(&ctx->panel); |
|---|
| 424 | | - |
|---|
| 425 | | - if (ctx->backlight) |
|---|
| 426 | | - put_device(&ctx->backlight->dev); |
|---|
| 427 | 395 | |
|---|
| 428 | 396 | return 0; |
|---|
| 429 | 397 | } |
|---|