mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/chenhuacai/linux-loongson
synced 2025-09-04 18:49:41 +00:00

devm_drm_bridge_alloc() is the new API to be used for allocating (and partially initializing) a private driver struct embedding a struct drm_bridge. For many drivers having a simple code flow in the probe function, this commit does a mass conversion automatically with the following semantic patch. The changes have been reviewed manually for correctness as well as to find any false positives. The patch has been applied with the explicit exclusion of bridge/panel.c, handled by a separate patch. After applying the semantic patch, manually fixed these issues: - 4 drivers need ERR_CAST() instead of PTR_ERR() as the function calling devm_drm_bridge_alloc() returns a pointer - re-added empty lines and comments that the script had removed but that should stay @@ type T; identifier C; identifier BR; expression DEV; expression FUNCS; @@ -T *C; +T *C; ... ( -C = devm_kzalloc(DEV, ...); -if (!C) - return -ENOMEM; +C = devm_drm_bridge_alloc(DEV, T, BR, FUNCS); +if (IS_ERR(C)) + return PTR_ERR(C); | -C = devm_kzalloc(DEV, ...); -if (!C) - return ERR_PTR(-ENOMEM); +C = devm_drm_bridge_alloc(DEV, T, BR, FUNCS); +if (IS_ERR(C)) + return PTR_ERR(C); ) ... -C->BR.funcs = FUNCS; Reviewed-by: Manikandan Muralidharan <manikandan.m@microchip.com> # microchip-lvds.c Reviewed-by: Douglas Anderson <dianders@chromium.org> # parade-ps8640 Tested-by: Douglas Anderson <dianders@chromium.org> # parade-ps8640 Acked-by: Maxime Ripard <mripard@kernel.org> Link: https://lore.kernel.org/r/20250509-drm-bridge-convert-to-alloc-api-v3-2-b8bc1f16d7aa@bootlin.com [Luca: fixed trivial patch conflict in adv7511_drv.c while applying] Signed-off-by: Luca Ceresoli <luca.ceresoli@bootlin.com>
116 lines
3.0 KiB
C
116 lines
3.0 KiB
C
// SPDX-License-Identifier: GPL-2.0-only
|
|
/*
|
|
* Copyright 2024 Freebox SAS
|
|
*/
|
|
|
|
#include <linux/gpio/consumer.h>
|
|
#include <linux/i2c.h>
|
|
|
|
#include <drm/drm_atomic_helper.h>
|
|
#include <drm/drm_bridge.h>
|
|
|
|
struct tdp158 {
|
|
struct drm_bridge bridge;
|
|
struct drm_bridge *next;
|
|
struct gpio_desc *enable; // Operation Enable - pin 36
|
|
struct regulator *vcc; // 3.3V
|
|
struct regulator *vdd; // 1.1V
|
|
struct device *dev;
|
|
};
|
|
|
|
static void tdp158_enable(struct drm_bridge *bridge,
|
|
struct drm_atomic_state *state)
|
|
{
|
|
int err;
|
|
struct tdp158 *tdp158 = bridge->driver_private;
|
|
|
|
err = regulator_enable(tdp158->vcc);
|
|
if (err)
|
|
dev_err(tdp158->dev, "failed to enable vcc: %d", err);
|
|
|
|
err = regulator_enable(tdp158->vdd);
|
|
if (err)
|
|
dev_err(tdp158->dev, "failed to enable vdd: %d", err);
|
|
|
|
gpiod_set_value_cansleep(tdp158->enable, 1);
|
|
}
|
|
|
|
static void tdp158_disable(struct drm_bridge *bridge,
|
|
struct drm_atomic_state *state)
|
|
{
|
|
struct tdp158 *tdp158 = bridge->driver_private;
|
|
|
|
gpiod_set_value_cansleep(tdp158->enable, 0);
|
|
regulator_disable(tdp158->vdd);
|
|
regulator_disable(tdp158->vcc);
|
|
}
|
|
|
|
static int tdp158_attach(struct drm_bridge *bridge,
|
|
struct drm_encoder *encoder,
|
|
enum drm_bridge_attach_flags flags)
|
|
{
|
|
struct tdp158 *tdp158 = bridge->driver_private;
|
|
|
|
return drm_bridge_attach(encoder, tdp158->next, bridge, flags);
|
|
}
|
|
|
|
static const struct drm_bridge_funcs tdp158_bridge_funcs = {
|
|
.attach = tdp158_attach,
|
|
.atomic_enable = tdp158_enable,
|
|
.atomic_disable = tdp158_disable,
|
|
.atomic_duplicate_state = drm_atomic_helper_bridge_duplicate_state,
|
|
.atomic_destroy_state = drm_atomic_helper_bridge_destroy_state,
|
|
.atomic_reset = drm_atomic_helper_bridge_reset,
|
|
};
|
|
|
|
static int tdp158_probe(struct i2c_client *client)
|
|
{
|
|
struct tdp158 *tdp158;
|
|
struct device *dev = &client->dev;
|
|
|
|
tdp158 = devm_drm_bridge_alloc(dev, struct tdp158, bridge,
|
|
&tdp158_bridge_funcs);
|
|
if (IS_ERR(tdp158))
|
|
return PTR_ERR(tdp158);
|
|
|
|
tdp158->next = devm_drm_of_get_bridge(dev, dev->of_node, 1, 0);
|
|
if (IS_ERR(tdp158->next))
|
|
return dev_err_probe(dev, PTR_ERR(tdp158->next), "missing bridge");
|
|
|
|
tdp158->vcc = devm_regulator_get(dev, "vcc");
|
|
if (IS_ERR(tdp158->vcc))
|
|
return dev_err_probe(dev, PTR_ERR(tdp158->vcc), "vcc");
|
|
|
|
tdp158->vdd = devm_regulator_get(dev, "vdd");
|
|
if (IS_ERR(tdp158->vdd))
|
|
return dev_err_probe(dev, PTR_ERR(tdp158->vdd), "vdd");
|
|
|
|
tdp158->enable = devm_gpiod_get_optional(dev, "enable", GPIOD_OUT_LOW);
|
|
if (IS_ERR(tdp158->enable))
|
|
return dev_err_probe(dev, PTR_ERR(tdp158->enable), "enable");
|
|
|
|
tdp158->bridge.of_node = dev->of_node;
|
|
tdp158->bridge.driver_private = tdp158;
|
|
tdp158->dev = dev;
|
|
|
|
return devm_drm_bridge_add(dev, &tdp158->bridge);
|
|
}
|
|
|
|
static const struct of_device_id tdp158_match_table[] = {
|
|
{ .compatible = "ti,tdp158" },
|
|
{ }
|
|
};
|
|
MODULE_DEVICE_TABLE(of, tdp158_match_table);
|
|
|
|
static struct i2c_driver tdp158_driver = {
|
|
.probe = tdp158_probe,
|
|
.driver = {
|
|
.name = "tdp158",
|
|
.of_match_table = tdp158_match_table,
|
|
},
|
|
};
|
|
module_i2c_driver(tdp158_driver);
|
|
|
|
MODULE_DESCRIPTION("TI TDP158 driver");
|
|
MODULE_LICENSE("GPL");
|