hc
2024-05-10 61598093bbdd283a7edc367d900f223070ead8d2
kernel/drivers/gpu/drm/imx/imx-tve.c
....@@ -1,32 +1,26 @@
1
+// SPDX-License-Identifier: GPL-2.0+
12 /*
23 * i.MX drm driver - Television Encoder (TVEv2)
34 *
45 * Copyright (C) 2013 Philipp Zabel, Pengutronix
5
- *
6
- * This program is free software; you can redistribute it and/or
7
- * modify it under the terms of the GNU General Public License
8
- * as published by the Free Software Foundation; either version 2
9
- * of the License, or (at your option) any later version.
10
- * This program is distributed in the hope that it will be useful,
11
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
- * GNU General Public License for more details.
146 */
157
16
-#include <linux/clk.h>
178 #include <linux/clk-provider.h>
9
+#include <linux/clk.h>
1810 #include <linux/component.h>
19
-#include <linux/module.h>
2011 #include <linux/i2c.h>
12
+#include <linux/module.h>
13
+#include <linux/platform_device.h>
2114 #include <linux/regmap.h>
2215 #include <linux/regulator/consumer.h>
23
-#include <linux/spinlock.h>
2416 #include <linux/videodev2.h>
25
-#include <drm/drmP.h>
17
+
18
+#include <video/imx-ipu-v3.h>
19
+
2620 #include <drm/drm_atomic_helper.h>
2721 #include <drm/drm_fb_helper.h>
28
-#include <drm/drm_crtc_helper.h>
29
-#include <video/imx-ipu-v3.h>
22
+#include <drm/drm_probe_helper.h>
23
+#include <drm/drm_simple_kms_helper.h>
3024
3125 #include "imx-drm.h"
3226
....@@ -109,8 +103,6 @@
109103 struct drm_connector connector;
110104 struct drm_encoder encoder;
111105 struct device *dev;
112
- spinlock_t lock; /* register lock */
113
- bool enabled;
114106 int mode;
115107 int di_hsync_pin;
116108 int di_vsync_pin;
....@@ -134,30 +126,10 @@
134126 return container_of(e, struct imx_tve, encoder);
135127 }
136128
137
-static void tve_lock(void *__tve)
138
-__acquires(&tve->lock)
139
-{
140
- struct imx_tve *tve = __tve;
141
-
142
- spin_lock(&tve->lock);
143
-}
144
-
145
-static void tve_unlock(void *__tve)
146
-__releases(&tve->lock)
147
-{
148
- struct imx_tve *tve = __tve;
149
-
150
- spin_unlock(&tve->lock);
151
-}
152
-
153129 static void tve_enable(struct imx_tve *tve)
154130 {
155
- if (!tve->enabled) {
156
- tve->enabled = true;
157
- clk_prepare_enable(tve->clk);
158
- regmap_update_bits(tve->regmap, TVE_COM_CONF_REG,
159
- TVE_EN, TVE_EN);
160
- }
131
+ clk_prepare_enable(tve->clk);
132
+ regmap_update_bits(tve->regmap, TVE_COM_CONF_REG, TVE_EN, TVE_EN);
161133
162134 /* clear interrupt status register */
163135 regmap_write(tve->regmap, TVE_STAT_REG, 0xffffffff);
....@@ -174,11 +146,8 @@
174146
175147 static void tve_disable(struct imx_tve *tve)
176148 {
177
- if (tve->enabled) {
178
- tve->enabled = false;
179
- regmap_update_bits(tve->regmap, TVE_COM_CONF_REG, TVE_EN, 0);
180
- clk_disable_unprepare(tve->clk);
181
- }
149
+ regmap_update_bits(tve->regmap, TVE_COM_CONF_REG, TVE_EN, 0);
150
+ clk_disable_unprepare(tve->clk);
182151 }
183152
184153 static int tve_setup_tvout(struct imx_tve *tve)
....@@ -243,8 +212,9 @@
243212 return ret;
244213 }
245214
246
-static int imx_tve_connector_mode_valid(struct drm_connector *connector,
247
- struct drm_display_mode *mode)
215
+static enum drm_mode_status
216
+imx_tve_connector_mode_valid(struct drm_connector *connector,
217
+ struct drm_display_mode *mode)
248218 {
249219 struct imx_tve *tve = con_to_tve(connector);
250220 unsigned long rate;
....@@ -263,14 +233,6 @@
263233 mode->hdisplay, mode->vdisplay);
264234
265235 return MODE_BAD;
266
-}
267
-
268
-static struct drm_encoder *imx_tve_connector_best_encoder(
269
- struct drm_connector *connector)
270
-{
271
- struct imx_tve *tve = con_to_tve(connector);
272
-
273
- return &tve->encoder;
274236 }
275237
276238 static void imx_tve_encoder_mode_set(struct drm_encoder *encoder,
....@@ -350,12 +312,7 @@
350312
351313 static const struct drm_connector_helper_funcs imx_tve_connector_helper_funcs = {
352314 .get_modes = imx_tve_connector_get_modes,
353
- .best_encoder = imx_tve_connector_best_encoder,
354315 .mode_valid = imx_tve_connector_mode_valid,
355
-};
356
-
357
-static const struct drm_encoder_funcs imx_tve_encoder_funcs = {
358
- .destroy = imx_drm_encoder_destroy,
359316 };
360317
361318 static const struct drm_encoder_helper_funcs imx_tve_encoder_helper_funcs = {
....@@ -442,7 +399,7 @@
442399 return 0;
443400 }
444401
445
-static struct clk_ops clk_tve_di_ops = {
402
+static const struct clk_ops clk_tve_di_ops = {
446403 .round_rate = clk_tve_di_round_rate,
447404 .set_rate = clk_tve_di_set_rate,
448405 .recalc_rate = clk_tve_di_recalc_rate,
....@@ -485,13 +442,14 @@
485442 return ret;
486443
487444 drm_encoder_helper_add(&tve->encoder, &imx_tve_encoder_helper_funcs);
488
- drm_encoder_init(drm, &tve->encoder, &imx_tve_encoder_funcs,
489
- encoder_type, NULL);
445
+ drm_simple_encoder_init(drm, &tve->encoder, encoder_type);
490446
491447 drm_connector_helper_add(&tve->connector,
492448 &imx_tve_connector_helper_funcs);
493
- drm_connector_init(drm, &tve->connector, &imx_tve_connector_funcs,
494
- DRM_MODE_CONNECTOR_VGA);
449
+ drm_connector_init_with_ddc(drm, &tve->connector,
450
+ &imx_tve_connector_funcs,
451
+ DRM_MODE_CONNECTOR_VGA,
452
+ tve->ddc);
495453
496454 drm_connector_attach_encoder(&tve->connector, &tve->encoder);
497455
....@@ -517,8 +475,7 @@
517475
518476 .readable_reg = imx_tve_readable_reg,
519477
520
- .lock = tve_lock,
521
- .unlock = tve_unlock,
478
+ .fast_io = true,
522479
523480 .max_register = 0xdc,
524481 };
....@@ -528,7 +485,7 @@
528485 [TVE_MODE_VGA] = "vga",
529486 };
530487
531
-static const int of_get_tve_mode(struct device_node *np)
488
+static int of_get_tve_mode(struct device_node *np)
532489 {
533490 const char *bm;
534491 int ret, i;
....@@ -557,12 +514,10 @@
557514 int irq;
558515 int ret;
559516
560
- tve = devm_kzalloc(dev, sizeof(*tve), GFP_KERNEL);
561
- if (!tve)
562
- return -ENOMEM;
517
+ tve = dev_get_drvdata(dev);
518
+ memset(tve, 0, sizeof(*tve));
563519
564520 tve->dev = dev;
565
- spin_lock_init(&tve->lock);
566521
567522 ddc_node = of_parse_phandle(np, "ddc-i2c-bus", 0);
568523 if (ddc_node) {
....@@ -609,10 +564,8 @@
609564 }
610565
611566 irq = platform_get_irq(pdev, 0);
612
- if (irq < 0) {
613
- dev_err(dev, "failed to get irq\n");
567
+ if (irq < 0)
614568 return irq;
615
- }
616569
617570 ret = devm_request_threaded_irq(dev, irq, NULL,
618571 imx_tve_irq_handler, IRQF_ONESHOT,
....@@ -673,8 +626,6 @@
673626 if (ret)
674627 return ret;
675628
676
- dev_set_drvdata(dev, tve);
677
-
678629 return 0;
679630 }
680631
....@@ -684,6 +635,14 @@
684635
685636 static int imx_tve_probe(struct platform_device *pdev)
686637 {
638
+ struct imx_tve *tve;
639
+
640
+ tve = devm_kzalloc(&pdev->dev, sizeof(*tve), GFP_KERNEL);
641
+ if (!tve)
642
+ return -ENOMEM;
643
+
644
+ platform_set_drvdata(pdev, tve);
645
+
687646 return component_add(&pdev->dev, &imx_tve_ops);
688647 }
689648