hc
2024-05-10 cde9070d9970eef1f7ec2360586c802a16230ad8
kernel/drivers/gpu/drm/bridge/nxp-ptn3460.c
....@@ -1,32 +1,23 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * NXP PTN3460 DP/LVDS bridge driver
34 *
45 * Copyright (C) 2013 Google, Inc.
5
- *
6
- * This software is licensed under the terms of the GNU General Public
7
- * License version 2, as published by the Free Software Foundation, and
8
- * may be copied, distributed, and modified under those terms.
9
- *
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
168 #include <linux/delay.h>
17
-#include <linux/gpio.h>
189 #include <linux/gpio/consumer.h>
1910 #include <linux/i2c.h>
2011 #include <linux/module.h>
2112 #include <linux/of.h>
22
-#include <linux/of_gpio.h>
2313 #include <drm/drm_atomic_helper.h>
14
+#include <drm/drm_bridge.h>
2415 #include <drm/drm_crtc.h>
25
-#include <drm/drm_crtc_helper.h>
2616 #include <drm/drm_edid.h>
2717 #include <drm/drm_of.h>
2818 #include <drm/drm_panel.h>
29
-#include <drm/drmP.h>
19
+#include <drm/drm_print.h>
20
+#include <drm/drm_probe_helper.h>
3021
3122 #define PTN3460_EDID_ADDR 0x0
3223 #define PTN3460_EDID_EMULATION_ADDR 0x84
....@@ -38,8 +29,7 @@
3829 struct drm_connector connector;
3930 struct i2c_client *client;
4031 struct drm_bridge bridge;
41
- struct edid *edid;
42
- struct drm_panel *panel;
32
+ struct drm_bridge *panel_bridge;
4333 struct gpio_desc *gpio_pd_n;
4434 struct gpio_desc *gpio_rst_n;
4535 u32 edid_emulation;
....@@ -136,11 +126,6 @@
136126 usleep_range(10, 20);
137127 gpiod_set_value(ptn_bridge->gpio_rst_n, 1);
138128
139
- if (drm_panel_prepare(ptn_bridge->panel)) {
140
- DRM_ERROR("failed to prepare panel\n");
141
- return;
142
- }
143
-
144129 /*
145130 * There's a bug in the PTN chip where it falsely asserts hotplug before
146131 * it is fully functional. We're forced to wait for the maximum start up
....@@ -155,16 +140,6 @@
155140 ptn_bridge->enabled = true;
156141 }
157142
158
-static void ptn3460_enable(struct drm_bridge *bridge)
159
-{
160
- struct ptn3460_bridge *ptn_bridge = bridge_to_ptn3460(bridge);
161
-
162
- if (drm_panel_enable(ptn_bridge->panel)) {
163
- DRM_ERROR("failed to enable panel\n");
164
- return;
165
- }
166
-}
167
-
168143 static void ptn3460_disable(struct drm_bridge *bridge)
169144 {
170145 struct ptn3460_bridge *ptn_bridge = bridge_to_ptn3460(bridge);
....@@ -174,36 +149,18 @@
174149
175150 ptn_bridge->enabled = false;
176151
177
- if (drm_panel_disable(ptn_bridge->panel)) {
178
- DRM_ERROR("failed to disable panel\n");
179
- return;
180
- }
181
-
182152 gpiod_set_value(ptn_bridge->gpio_rst_n, 1);
183153 gpiod_set_value(ptn_bridge->gpio_pd_n, 0);
184154 }
185155
186
-static void ptn3460_post_disable(struct drm_bridge *bridge)
156
+
157
+static struct edid *ptn3460_get_edid(struct drm_bridge *bridge,
158
+ struct drm_connector *connector)
187159 {
188160 struct ptn3460_bridge *ptn_bridge = bridge_to_ptn3460(bridge);
189
-
190
- if (drm_panel_unprepare(ptn_bridge->panel)) {
191
- DRM_ERROR("failed to unprepare panel\n");
192
- return;
193
- }
194
-}
195
-
196
-static int ptn3460_get_modes(struct drm_connector *connector)
197
-{
198
- struct ptn3460_bridge *ptn_bridge;
199
- u8 *edid;
200
- int ret, num_modes = 0;
201161 bool power_off;
202
-
203
- ptn_bridge = connector_to_ptn3460(connector);
204
-
205
- if (ptn_bridge->edid)
206
- return drm_add_edid_modes(connector, ptn_bridge->edid);
162
+ u8 *edid;
163
+ int ret;
207164
208165 power_off = !ptn_bridge->enabled;
209166 ptn3460_pre_enable(&ptn_bridge->bridge);
....@@ -211,30 +168,40 @@
211168 edid = kmalloc(EDID_LENGTH, GFP_KERNEL);
212169 if (!edid) {
213170 DRM_ERROR("Failed to allocate EDID\n");
214
- return 0;
215
- }
216
-
217
- ret = ptn3460_read_bytes(ptn_bridge, PTN3460_EDID_ADDR, edid,
218
- EDID_LENGTH);
219
- if (ret) {
220
- kfree(edid);
221171 goto out;
222172 }
223173
224
- ptn_bridge->edid = (struct edid *)edid;
225
- drm_connector_update_edid_property(connector, ptn_bridge->edid);
226
-
227
- num_modes = drm_add_edid_modes(connector, ptn_bridge->edid);
174
+ ret = ptn3460_read_bytes(ptn_bridge, PTN3460_EDID_ADDR, edid,
175
+ EDID_LENGTH);
176
+ if (ret) {
177
+ kfree(edid);
178
+ edid = NULL;
179
+ goto out;
180
+ }
228181
229182 out:
230183 if (power_off)
231184 ptn3460_disable(&ptn_bridge->bridge);
232185
186
+ return (struct edid *)edid;
187
+}
188
+
189
+static int ptn3460_connector_get_modes(struct drm_connector *connector)
190
+{
191
+ struct ptn3460_bridge *ptn_bridge = connector_to_ptn3460(connector);
192
+ struct edid *edid;
193
+ int num_modes;
194
+
195
+ edid = ptn3460_get_edid(&ptn_bridge->bridge, connector);
196
+ drm_connector_update_edid_property(connector, edid);
197
+ num_modes = drm_add_edid_modes(connector, edid);
198
+ kfree(edid);
199
+
233200 return num_modes;
234201 }
235202
236203 static const struct drm_connector_helper_funcs ptn3460_connector_helper_funcs = {
237
- .get_modes = ptn3460_get_modes,
204
+ .get_modes = ptn3460_connector_get_modes,
238205 };
239206
240207 static const struct drm_connector_funcs ptn3460_connector_funcs = {
....@@ -245,10 +212,20 @@
245212 .atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
246213 };
247214
248
-static int ptn3460_bridge_attach(struct drm_bridge *bridge)
215
+static int ptn3460_bridge_attach(struct drm_bridge *bridge,
216
+ enum drm_bridge_attach_flags flags)
249217 {
250218 struct ptn3460_bridge *ptn_bridge = bridge_to_ptn3460(bridge);
251219 int ret;
220
+
221
+ /* Let this driver create connector if requested */
222
+ ret = drm_bridge_attach(bridge->encoder, ptn_bridge->panel_bridge,
223
+ bridge, flags | DRM_BRIDGE_ATTACH_NO_CONNECTOR);
224
+ if (ret < 0)
225
+ return ret;
226
+
227
+ if (flags & DRM_BRIDGE_ATTACH_NO_CONNECTOR)
228
+ return 0;
252229
253230 if (!bridge->encoder) {
254231 DRM_ERROR("Parent encoder object not found");
....@@ -268,9 +245,6 @@
268245 drm_connector_attach_encoder(&ptn_bridge->connector,
269246 bridge->encoder);
270247
271
- if (ptn_bridge->panel)
272
- drm_panel_attach(ptn_bridge->panel, &ptn_bridge->connector);
273
-
274248 drm_helper_hpd_irq_event(ptn_bridge->connector.dev);
275249
276250 return ret;
....@@ -278,10 +252,9 @@
278252
279253 static const struct drm_bridge_funcs ptn3460_bridge_funcs = {
280254 .pre_enable = ptn3460_pre_enable,
281
- .enable = ptn3460_enable,
282255 .disable = ptn3460_disable,
283
- .post_disable = ptn3460_post_disable,
284256 .attach = ptn3460_bridge_attach,
257
+ .get_edid = ptn3460_get_edid,
285258 };
286259
287260 static int ptn3460_probe(struct i2c_client *client,
....@@ -289,6 +262,8 @@
289262 {
290263 struct device *dev = &client->dev;
291264 struct ptn3460_bridge *ptn_bridge;
265
+ struct drm_bridge *panel_bridge;
266
+ struct drm_panel *panel;
292267 int ret;
293268
294269 ptn_bridge = devm_kzalloc(dev, sizeof(*ptn_bridge), GFP_KERNEL);
....@@ -296,10 +271,15 @@
296271 return -ENOMEM;
297272 }
298273
299
- ret = drm_of_find_panel_or_bridge(dev->of_node, 0, 0, &ptn_bridge->panel, NULL);
274
+ ret = drm_of_find_panel_or_bridge(dev->of_node, 0, 0, &panel, NULL);
300275 if (ret)
301276 return ret;
302277
278
+ panel_bridge = devm_drm_panel_bridge_add(dev, panel);
279
+ if (IS_ERR(panel_bridge))
280
+ return PTR_ERR(panel_bridge);
281
+
282
+ ptn_bridge->panel_bridge = panel_bridge;
303283 ptn_bridge->client = client;
304284
305285 ptn_bridge->gpio_pd_n = devm_gpiod_get(&client->dev, "powerdown",
....@@ -330,6 +310,8 @@
330310 }
331311
332312 ptn_bridge->bridge.funcs = &ptn3460_bridge_funcs;
313
+ ptn_bridge->bridge.ops = DRM_BRIDGE_OP_EDID;
314
+ ptn_bridge->bridge.type = DRM_MODE_CONNECTOR_LVDS;
333315 ptn_bridge->bridge.of_node = dev->of_node;
334316 drm_bridge_add(&ptn_bridge->bridge);
335317