Path: blob/master/drivers/gpu/drm/bridge/ti-tpd12s015.c
26494 views
// SPDX-License-Identifier: GPL-2.01/*2* TPD12S015 HDMI ESD protection & level shifter chip driver3*4* Copyright (C) 2019 Texas Instruments Incorporated5*6* Based on the omapdrm-specific encoder-opa362 driver7*8* Copyright (C) 2013 Texas Instruments Incorporated9* Author: Tomi Valkeinen <[email protected]>10*/1112#include <linux/delay.h>13#include <linux/gpio/consumer.h>14#include <linux/interrupt.h>15#include <linux/module.h>16#include <linux/mutex.h>17#include <linux/of.h>18#include <linux/of_graph.h>19#include <linux/platform_device.h>2021#include <drm/drm_bridge.h>2223struct tpd12s015_device {24struct drm_bridge bridge;2526struct gpio_desc *ct_cp_hpd_gpio;27struct gpio_desc *ls_oe_gpio;28struct gpio_desc *hpd_gpio;29int hpd_irq;3031struct drm_bridge *next_bridge;32};3334static inline struct tpd12s015_device *to_tpd12s015(struct drm_bridge *bridge)35{36return container_of(bridge, struct tpd12s015_device, bridge);37}3839static int tpd12s015_attach(struct drm_bridge *bridge,40struct drm_encoder *encoder,41enum drm_bridge_attach_flags flags)42{43struct tpd12s015_device *tpd = to_tpd12s015(bridge);44int ret;4546if (!(flags & DRM_BRIDGE_ATTACH_NO_CONNECTOR))47return -EINVAL;4849ret = drm_bridge_attach(encoder, tpd->next_bridge,50bridge, flags);51if (ret < 0)52return ret;5354gpiod_set_value_cansleep(tpd->ls_oe_gpio, 1);5556/* DC-DC converter needs at max 300us to get to 90% of 5V. */57usleep_range(300, 1000);5859return 0;60}6162static void tpd12s015_detach(struct drm_bridge *bridge)63{64struct tpd12s015_device *tpd = to_tpd12s015(bridge);6566gpiod_set_value_cansleep(tpd->ls_oe_gpio, 0);67}6869static enum drm_connector_status tpd12s015_detect(struct drm_bridge *bridge)70{71struct tpd12s015_device *tpd = to_tpd12s015(bridge);7273if (gpiod_get_value_cansleep(tpd->hpd_gpio))74return connector_status_connected;75else76return connector_status_disconnected;77}7879static enum drm_connector_status80tpd12s015_bridge_detect(struct drm_bridge *bridge, struct drm_connector *connector)81{82return tpd12s015_detect(bridge);83}8485static void tpd12s015_hpd_enable(struct drm_bridge *bridge)86{87struct tpd12s015_device *tpd = to_tpd12s015(bridge);8889gpiod_set_value_cansleep(tpd->ct_cp_hpd_gpio, 1);90}9192static void tpd12s015_hpd_disable(struct drm_bridge *bridge)93{94struct tpd12s015_device *tpd = to_tpd12s015(bridge);9596gpiod_set_value_cansleep(tpd->ct_cp_hpd_gpio, 0);97}9899static const struct drm_bridge_funcs tpd12s015_bridge_funcs = {100.attach = tpd12s015_attach,101.detach = tpd12s015_detach,102.detect = tpd12s015_bridge_detect,103.hpd_enable = tpd12s015_hpd_enable,104.hpd_disable = tpd12s015_hpd_disable,105};106107static irqreturn_t tpd12s015_hpd_isr(int irq, void *data)108{109struct tpd12s015_device *tpd = data;110struct drm_bridge *bridge = &tpd->bridge;111112drm_bridge_hpd_notify(bridge, tpd12s015_detect(bridge));113114return IRQ_HANDLED;115}116117static int tpd12s015_probe(struct platform_device *pdev)118{119struct tpd12s015_device *tpd;120struct device_node *node;121struct gpio_desc *gpio;122int ret;123124tpd = devm_drm_bridge_alloc(&pdev->dev, struct tpd12s015_device,125bridge, &tpd12s015_bridge_funcs);126if (IS_ERR(tpd))127return PTR_ERR(tpd);128129platform_set_drvdata(pdev, tpd);130131tpd->bridge.of_node = pdev->dev.of_node;132tpd->bridge.type = DRM_MODE_CONNECTOR_HDMIA;133tpd->bridge.ops = DRM_BRIDGE_OP_DETECT;134135/* Get the next bridge, connected to port@1. */136node = of_graph_get_remote_node(pdev->dev.of_node, 1, -1);137if (!node)138return -ENODEV;139140tpd->next_bridge = of_drm_find_bridge(node);141of_node_put(node);142143if (!tpd->next_bridge)144return -EPROBE_DEFER;145146/* Get the control and HPD GPIOs. */147gpio = devm_gpiod_get_index_optional(&pdev->dev, NULL, 0,148GPIOD_OUT_LOW);149if (IS_ERR(gpio))150return PTR_ERR(gpio);151152tpd->ct_cp_hpd_gpio = gpio;153154gpio = devm_gpiod_get_index_optional(&pdev->dev, NULL, 1,155GPIOD_OUT_LOW);156if (IS_ERR(gpio))157return PTR_ERR(gpio);158159tpd->ls_oe_gpio = gpio;160161gpio = devm_gpiod_get_index(&pdev->dev, NULL, 2, GPIOD_IN);162if (IS_ERR(gpio))163return PTR_ERR(gpio);164165tpd->hpd_gpio = gpio;166167/* Register the IRQ if the HPD GPIO is IRQ-capable. */168tpd->hpd_irq = gpiod_to_irq(tpd->hpd_gpio);169if (tpd->hpd_irq >= 0) {170ret = devm_request_threaded_irq(&pdev->dev, tpd->hpd_irq, NULL,171tpd12s015_hpd_isr,172IRQF_TRIGGER_RISING |173IRQF_TRIGGER_FALLING |174IRQF_ONESHOT,175"tpd12s015 hpd", tpd);176if (ret)177return ret;178179tpd->bridge.ops |= DRM_BRIDGE_OP_HPD;180}181182/* Register the DRM bridge. */183drm_bridge_add(&tpd->bridge);184185return 0;186}187188static void tpd12s015_remove(struct platform_device *pdev)189{190struct tpd12s015_device *tpd = platform_get_drvdata(pdev);191192drm_bridge_remove(&tpd->bridge);193}194195static const struct of_device_id tpd12s015_of_match[] = {196{ .compatible = "ti,tpd12s015", },197{},198};199200MODULE_DEVICE_TABLE(of, tpd12s015_of_match);201202static struct platform_driver tpd12s015_driver = {203.probe = tpd12s015_probe,204.remove = tpd12s015_remove,205.driver = {206.name = "tpd12s015",207.of_match_table = tpd12s015_of_match,208},209};210211module_platform_driver(tpd12s015_driver);212213MODULE_AUTHOR("Tomi Valkeinen <[email protected]>");214MODULE_DESCRIPTION("TPD12S015 HDMI level shifter and ESD protection driver");215MODULE_LICENSE("GPL");216217218