hc
2023-12-06 08f87f769b595151be1afeff53e144f543faa614
kernel/drivers/gpu/drm/bridge/parade-ps8622.c
....@@ -1,22 +1,13 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * Parade PS8622 eDP/LVDS bridge driver
34 *
45 * Copyright (C) 2014 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/backlight.h>
179 #include <linux/delay.h>
1810 #include <linux/err.h>
19
-#include <linux/gpio.h>
2011 #include <linux/gpio/consumer.h>
2112 #include <linux/i2c.h>
2213 #include <linux/module.h>
....@@ -24,12 +15,14 @@
2415 #include <linux/of_device.h>
2516 #include <linux/pm.h>
2617 #include <linux/regulator/consumer.h>
18
+
2719 #include <drm/drm_atomic_helper.h>
20
+#include <drm/drm_bridge.h>
2821 #include <drm/drm_crtc.h>
29
-#include <drm/drm_crtc_helper.h>
3022 #include <drm/drm_of.h>
3123 #include <drm/drm_panel.h>
32
-#include <drm/drmP.h>
24
+#include <drm/drm_print.h>
25
+#include <drm/drm_probe_helper.h>
3326
3427 /* Brightness scale on the Parade chip */
3528 #define PS8622_MAX_BRIGHTNESS 0xff
....@@ -49,10 +42,9 @@
4942 #endif
5043
5144 struct ps8622_bridge {
52
- struct drm_connector connector;
5345 struct i2c_client *client;
5446 struct drm_bridge bridge;
55
- struct drm_panel *panel;
47
+ struct drm_bridge *panel_bridge;
5648 struct regulator *v12;
5749 struct backlight_device *bl;
5850
....@@ -69,12 +61,6 @@
6961 bridge_to_ps8622(struct drm_bridge *bridge)
7062 {
7163 return container_of(bridge, struct ps8622_bridge, bridge);
72
-}
73
-
74
-static inline struct ps8622_bridge *
75
- connector_to_ps8622(struct drm_connector *connector)
76
-{
77
- return container_of(connector, struct ps8622_bridge, connector);
7864 }
7965
8066 static int ps8622_set(struct i2c_client *client, u8 page, u8 reg, u8 val)
....@@ -372,11 +358,6 @@
372358 DRM_ERROR("fails to enable ps8622->v12");
373359 }
374360
375
- if (drm_panel_prepare(ps8622->panel)) {
376
- DRM_ERROR("failed to prepare panel\n");
377
- return;
378
- }
379
-
380361 gpiod_set_value(ps8622->gpio_slp, 1);
381362
382363 /*
....@@ -406,24 +387,9 @@
406387 ps8622->enabled = true;
407388 }
408389
409
-static void ps8622_enable(struct drm_bridge *bridge)
410
-{
411
- struct ps8622_bridge *ps8622 = bridge_to_ps8622(bridge);
412
-
413
- if (drm_panel_enable(ps8622->panel)) {
414
- DRM_ERROR("failed to enable panel\n");
415
- return;
416
- }
417
-}
418
-
419390 static void ps8622_disable(struct drm_bridge *bridge)
420391 {
421
- struct ps8622_bridge *ps8622 = bridge_to_ps8622(bridge);
422
-
423
- if (drm_panel_disable(ps8622->panel)) {
424
- DRM_ERROR("failed to disable panel\n");
425
- return;
426
- }
392
+ /* Delay after panel is disabled */
427393 msleep(PS8622_PWMO_END_T12_MS);
428394 }
429395
....@@ -443,11 +409,6 @@
443409 */
444410 gpiod_set_value(ps8622->gpio_slp, 0);
445411
446
- if (drm_panel_unprepare(ps8622->panel)) {
447
- DRM_ERROR("failed to unprepare panel\n");
448
- return;
449
- }
450
-
451412 if (ps8622->v12)
452413 regulator_disable(ps8622->v12);
453414
....@@ -462,61 +423,17 @@
462423 msleep(PS8622_POWER_OFF_T17_MS);
463424 }
464425
465
-static int ps8622_get_modes(struct drm_connector *connector)
466
-{
467
- struct ps8622_bridge *ps8622;
468
-
469
- ps8622 = connector_to_ps8622(connector);
470
-
471
- return drm_panel_get_modes(ps8622->panel);
472
-}
473
-
474
-static const struct drm_connector_helper_funcs ps8622_connector_helper_funcs = {
475
- .get_modes = ps8622_get_modes,
476
-};
477
-
478
-static const struct drm_connector_funcs ps8622_connector_funcs = {
479
- .fill_modes = drm_helper_probe_single_connector_modes,
480
- .destroy = drm_connector_cleanup,
481
- .reset = drm_atomic_helper_connector_reset,
482
- .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state,
483
- .atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
484
-};
485
-
486
-static int ps8622_attach(struct drm_bridge *bridge)
426
+static int ps8622_attach(struct drm_bridge *bridge,
427
+ enum drm_bridge_attach_flags flags)
487428 {
488429 struct ps8622_bridge *ps8622 = bridge_to_ps8622(bridge);
489
- int ret;
490430
491
- if (!bridge->encoder) {
492
- DRM_ERROR("Parent encoder object not found");
493
- return -ENODEV;
494
- }
495
-
496
- ps8622->connector.polled = DRM_CONNECTOR_POLL_HPD;
497
- ret = drm_connector_init(bridge->dev, &ps8622->connector,
498
- &ps8622_connector_funcs, DRM_MODE_CONNECTOR_LVDS);
499
- if (ret) {
500
- DRM_ERROR("Failed to initialize connector with drm\n");
501
- return ret;
502
- }
503
- drm_connector_helper_add(&ps8622->connector,
504
- &ps8622_connector_helper_funcs);
505
- drm_connector_register(&ps8622->connector);
506
- drm_connector_attach_encoder(&ps8622->connector,
507
- bridge->encoder);
508
-
509
- if (ps8622->panel)
510
- drm_panel_attach(ps8622->panel, &ps8622->connector);
511
-
512
- drm_helper_hpd_irq_event(ps8622->connector.dev);
513
-
514
- return ret;
431
+ return drm_bridge_attach(ps8622->bridge.encoder, ps8622->panel_bridge,
432
+ &ps8622->bridge, flags);
515433 }
516434
517435 static const struct drm_bridge_funcs ps8622_bridge_funcs = {
518436 .pre_enable = ps8622_pre_enable,
519
- .enable = ps8622_enable,
520437 .disable = ps8622_disable,
521438 .post_disable = ps8622_post_disable,
522439 .attach = ps8622_attach,
....@@ -534,16 +451,23 @@
534451 {
535452 struct device *dev = &client->dev;
536453 struct ps8622_bridge *ps8622;
454
+ struct drm_bridge *panel_bridge;
455
+ struct drm_panel *panel;
537456 int ret;
538457
539458 ps8622 = devm_kzalloc(dev, sizeof(*ps8622), GFP_KERNEL);
540459 if (!ps8622)
541460 return -ENOMEM;
542461
543
- ret = drm_of_find_panel_or_bridge(dev->of_node, 0, 0, &ps8622->panel, NULL);
462
+ ret = drm_of_find_panel_or_bridge(dev->of_node, 0, 0, &panel, NULL);
544463 if (ret)
545464 return ret;
546465
466
+ panel_bridge = devm_drm_panel_bridge_add(dev, panel);
467
+ if (IS_ERR(panel_bridge))
468
+ return PTR_ERR(panel_bridge);
469
+
470
+ ps8622->panel_bridge = panel_bridge;
547471 ps8622->client = client;
548472
549473 ps8622->v12 = devm_regulator_get(dev, "vdd12");
....@@ -596,6 +520,7 @@
596520 }
597521
598522 ps8622->bridge.funcs = &ps8622_bridge_funcs;
523
+ ps8622->bridge.type = DRM_MODE_CONNECTOR_LVDS;
599524 ps8622->bridge.of_node = dev->of_node;
600525 drm_bridge_add(&ps8622->bridge);
601526