forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-01-04 1543e317f1da31b75942316931e8f491a8920811
kernel/drivers/gpu/drm/panel/panel-sitronix-st7789v.c
....@@ -1,19 +1,19 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * 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.
74 */
85
6
+#include <linux/delay.h>
97 #include <linux/gpio/consumer.h>
8
+#include <linux/module.h>
109 #include <linux/regulator/consumer.h>
1110 #include <linux/spi/spi.h>
1211
13
-#include <drm/drmP.h>
14
-#include <drm/drm_panel.h>
15
-
1612 #include <video/mipi_display.h>
13
+
14
+#include <drm/drm_device.h>
15
+#include <drm/drm_modes.h>
16
+#include <drm/drm_panel.h>
1717
1818 #define ST7789V_COLMOD_RGB_FMT_18BITS (6 << 4)
1919 #define ST7789V_COLMOD_CTRL_FMT_18BITS (6 << 0)
....@@ -115,7 +115,6 @@
115115 struct drm_panel panel;
116116 struct spi_device *spi;
117117 struct gpio_desc *reset;
118
- struct backlight_device *backlight;
119118 struct regulator *power;
120119 };
121120
....@@ -166,19 +165,18 @@
166165 .vsync_start = 320 + 8,
167166 .vsync_end = 320 + 8 + 4,
168167 .vtotal = 320 + 8 + 4 + 4,
169
- .vrefresh = 60,
170168 };
171169
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)
173172 {
174
- struct drm_connector *connector = panel->connector;
175173 struct drm_display_mode *mode;
176174
177
- mode = drm_mode_duplicate(panel->drm, &default_mode);
175
+ mode = drm_mode_duplicate(connector->dev, &default_mode);
178176 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",
180178 default_mode.hdisplay, default_mode.vdisplay,
181
- default_mode.vrefresh);
179
+ drm_mode_vrefresh(&default_mode));
182180 return -ENOMEM;
183181 }
184182
....@@ -187,8 +185,8 @@
187185 mode->type = DRM_MODE_TYPE_DRIVER | DRM_MODE_TYPE_PREFERRED;
188186 drm_mode_probed_add(connector, mode);
189187
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;
192190
193191 return 1;
194192 }
....@@ -322,12 +320,6 @@
322320 {
323321 struct st7789v *ctx = panel_to_st7789v(panel);
324322
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
-
331323 return st7789v_write_command(ctx, MIPI_DCS_SET_DISPLAY_ON);
332324 }
333325
....@@ -337,12 +329,6 @@
337329 int ret;
338330
339331 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
- }
346332
347333 return 0;
348334 }
....@@ -369,7 +355,6 @@
369355
370356 static int st7789v_probe(struct spi_device *spi)
371357 {
372
- struct device_node *backlight;
373358 struct st7789v *ctx;
374359 int ret;
375360
....@@ -380,9 +365,8 @@
380365 spi_set_drvdata(spi, ctx);
381366 ctx->spi = spi;
382367
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);
386370
387371 ctx->power = devm_regulator_get(&spi->dev, "power");
388372 if (IS_ERR(ctx->power))
....@@ -394,26 +378,13 @@
394378 return PTR_ERR(ctx->reset);
395379 }
396380
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;
401384
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);
409386
410387 return 0;
411
-
412
-err_free_backlight:
413
- if (ctx->backlight)
414
- put_device(&ctx->backlight->dev);
415
-
416
- return ret;
417388 }
418389
419390 static int st7789v_remove(struct spi_device *spi)
....@@ -421,9 +392,6 @@
421392 struct st7789v *ctx = spi_get_drvdata(spi);
422393
423394 drm_panel_remove(&ctx->panel);
424
-
425
- if (ctx->backlight)
426
- put_device(&ctx->backlight->dev);
427395
428396 return 0;
429397 }