Path: blob/master/drivers/gpu/drm/bridge/aux-hpd-bridge.c
26494 views
// SPDX-License-Identifier: GPL-2.0+1/*2* Copyright (C) 2023 Linaro Ltd.3*4* Author: Dmitry Baryshkov <[email protected]>5*/6#include <linux/auxiliary_bus.h>7#include <linux/export.h>8#include <linux/module.h>9#include <linux/of.h>1011#include <drm/drm_bridge.h>12#include <drm/bridge/aux-bridge.h>1314static DEFINE_IDA(drm_aux_hpd_bridge_ida);1516struct drm_aux_hpd_bridge_data {17struct drm_bridge bridge;18struct device *dev;19};2021static void drm_aux_hpd_bridge_release(struct device *dev)22{23struct auxiliary_device *adev = to_auxiliary_dev(dev);2425ida_free(&drm_aux_hpd_bridge_ida, adev->id);2627of_node_put(adev->dev.platform_data);28of_node_put(adev->dev.of_node);2930kfree(adev);31}3233static void drm_aux_hpd_bridge_free_adev(void *_adev)34{35auxiliary_device_uninit(_adev);36}3738/**39* devm_drm_dp_hpd_bridge_alloc - allocate a HPD DisplayPort bridge40* @parent: device instance providing this bridge41* @np: device node pointer corresponding to this bridge instance42*43* Creates a simple DRM bridge with the type set to44* DRM_MODE_CONNECTOR_DisplayPort, which terminates the bridge chain and is45* able to send the HPD events.46*47* Return: bridge auxiliary device pointer or an error pointer48*/49struct auxiliary_device *devm_drm_dp_hpd_bridge_alloc(struct device *parent, struct device_node *np)50{51struct auxiliary_device *adev;52int ret;5354adev = kzalloc(sizeof(*adev), GFP_KERNEL);55if (!adev)56return ERR_PTR(-ENOMEM);5758ret = ida_alloc(&drm_aux_hpd_bridge_ida, GFP_KERNEL);59if (ret < 0) {60kfree(adev);61return ERR_PTR(ret);62}6364adev->id = ret;65adev->name = "dp_hpd_bridge";66adev->dev.parent = parent;67adev->dev.release = drm_aux_hpd_bridge_release;68adev->dev.platform_data = of_node_get(np);6970device_set_of_node_from_dev(&adev->dev, parent);7172ret = auxiliary_device_init(adev);73if (ret) {74of_node_put(adev->dev.platform_data);75of_node_put(adev->dev.of_node);76ida_free(&drm_aux_hpd_bridge_ida, adev->id);77kfree(adev);78return ERR_PTR(ret);79}8081ret = devm_add_action_or_reset(parent, drm_aux_hpd_bridge_free_adev, adev);82if (ret)83return ERR_PTR(ret);8485return adev;86}87EXPORT_SYMBOL_GPL(devm_drm_dp_hpd_bridge_alloc);8889static void drm_aux_hpd_bridge_del_adev(void *_adev)90{91auxiliary_device_delete(_adev);92}9394/**95* devm_drm_dp_hpd_bridge_add - register a HDP DisplayPort bridge96* @dev: struct device to tie registration lifetime to97* @adev: bridge auxiliary device to be registered98*99* Returns: zero on success or a negative errno100*/101int devm_drm_dp_hpd_bridge_add(struct device *dev, struct auxiliary_device *adev)102{103int ret;104105ret = auxiliary_device_add(adev);106if (ret)107return ret;108109return devm_add_action_or_reset(dev, drm_aux_hpd_bridge_del_adev, adev);110}111EXPORT_SYMBOL_GPL(devm_drm_dp_hpd_bridge_add);112113/**114* drm_dp_hpd_bridge_register - allocate and register a HDP DisplayPort bridge115* @parent: device instance providing this bridge116* @np: device node pointer corresponding to this bridge instance117*118* Return: device instance that will handle created bridge or an error pointer119*/120struct device *drm_dp_hpd_bridge_register(struct device *parent, struct device_node *np)121{122struct auxiliary_device *adev;123int ret;124125adev = devm_drm_dp_hpd_bridge_alloc(parent, np);126if (IS_ERR(adev))127return ERR_CAST(adev);128129ret = devm_drm_dp_hpd_bridge_add(parent, adev);130if (ret)131return ERR_PTR(ret);132133return &adev->dev;134}135EXPORT_SYMBOL_GPL(drm_dp_hpd_bridge_register);136137/**138* drm_aux_hpd_bridge_notify - notify hot plug detection events139* @dev: device created for the HPD bridge140* @status: output connection status141*142* A wrapper around drm_bridge_hpd_notify() that is used to report hot plug143* detection events for bridges created via drm_dp_hpd_bridge_register().144*145* This function shall be called in a context that can sleep.146*/147void drm_aux_hpd_bridge_notify(struct device *dev, enum drm_connector_status status)148{149struct auxiliary_device *adev = to_auxiliary_dev(dev);150struct drm_aux_hpd_bridge_data *data = auxiliary_get_drvdata(adev);151152if (!data)153return;154155drm_bridge_hpd_notify(&data->bridge, status);156}157EXPORT_SYMBOL_GPL(drm_aux_hpd_bridge_notify);158159static int drm_aux_hpd_bridge_attach(struct drm_bridge *bridge,160struct drm_encoder *encoder,161enum drm_bridge_attach_flags flags)162{163return flags & DRM_BRIDGE_ATTACH_NO_CONNECTOR ? 0 : -EINVAL;164}165166static const struct drm_bridge_funcs drm_aux_hpd_bridge_funcs = {167.attach = drm_aux_hpd_bridge_attach,168};169170static int drm_aux_hpd_bridge_probe(struct auxiliary_device *auxdev,171const struct auxiliary_device_id *id)172{173struct drm_aux_hpd_bridge_data *data;174175data = devm_drm_bridge_alloc(&auxdev->dev,176struct drm_aux_hpd_bridge_data, bridge,177&drm_aux_hpd_bridge_funcs);178if (IS_ERR(data))179return PTR_ERR(data);180181data->dev = &auxdev->dev;182data->bridge.of_node = dev_get_platdata(data->dev);183data->bridge.ops = DRM_BRIDGE_OP_HPD;184data->bridge.type = id->driver_data;185186/* passthrough data, allow everything */187data->bridge.interlace_allowed = true;188data->bridge.ycbcr_420_allowed = true;189190auxiliary_set_drvdata(auxdev, data);191192return devm_drm_bridge_add(data->dev, &data->bridge);193}194195static const struct auxiliary_device_id drm_aux_hpd_bridge_table[] = {196{ .name = KBUILD_MODNAME ".dp_hpd_bridge", .driver_data = DRM_MODE_CONNECTOR_DisplayPort, },197{},198};199MODULE_DEVICE_TABLE(auxiliary, drm_aux_hpd_bridge_table);200201static struct auxiliary_driver drm_aux_hpd_bridge_drv = {202.name = "aux_hpd_bridge",203.id_table = drm_aux_hpd_bridge_table,204.probe = drm_aux_hpd_bridge_probe,205};206module_auxiliary_driver(drm_aux_hpd_bridge_drv);207208MODULE_AUTHOR("Dmitry Baryshkov <[email protected]>");209MODULE_DESCRIPTION("DRM HPD bridge");210MODULE_LICENSE("GPL");211212213