Path: blob/master/drivers/gpu/drm/bridge/ti-tpd12s015.c
51610 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;30};3132static inline struct tpd12s015_device *to_tpd12s015(struct drm_bridge *bridge)33{34return container_of(bridge, struct tpd12s015_device, bridge);35}3637static int tpd12s015_attach(struct drm_bridge *bridge,38struct drm_encoder *encoder,39enum drm_bridge_attach_flags flags)40{41struct tpd12s015_device *tpd = to_tpd12s015(bridge);42int ret;4344if (!(flags & DRM_BRIDGE_ATTACH_NO_CONNECTOR))45return -EINVAL;4647ret = drm_bridge_attach(encoder, tpd->bridge.next_bridge,48bridge, flags);49if (ret < 0)50return ret;5152gpiod_set_value_cansleep(tpd->ls_oe_gpio, 1);5354/* DC-DC converter needs at max 300us to get to 90% of 5V. */55usleep_range(300, 1000);5657return 0;58}5960static void tpd12s015_detach(struct drm_bridge *bridge)61{62struct tpd12s015_device *tpd = to_tpd12s015(bridge);6364gpiod_set_value_cansleep(tpd->ls_oe_gpio, 0);65}6667static enum drm_connector_status tpd12s015_detect(struct drm_bridge *bridge)68{69struct tpd12s015_device *tpd = to_tpd12s015(bridge);7071if (gpiod_get_value_cansleep(tpd->hpd_gpio))72return connector_status_connected;73else74return connector_status_disconnected;75}7677static enum drm_connector_status78tpd12s015_bridge_detect(struct drm_bridge *bridge, struct drm_connector *connector)79{80return tpd12s015_detect(bridge);81}8283static void tpd12s015_hpd_enable(struct drm_bridge *bridge)84{85struct tpd12s015_device *tpd = to_tpd12s015(bridge);8687gpiod_set_value_cansleep(tpd->ct_cp_hpd_gpio, 1);88}8990static void tpd12s015_hpd_disable(struct drm_bridge *bridge)91{92struct tpd12s015_device *tpd = to_tpd12s015(bridge);9394gpiod_set_value_cansleep(tpd->ct_cp_hpd_gpio, 0);95}9697static const struct drm_bridge_funcs tpd12s015_bridge_funcs = {98.attach = tpd12s015_attach,99.detach = tpd12s015_detach,100.detect = tpd12s015_bridge_detect,101.hpd_enable = tpd12s015_hpd_enable,102.hpd_disable = tpd12s015_hpd_disable,103};104105static irqreturn_t tpd12s015_hpd_isr(int irq, void *data)106{107struct tpd12s015_device *tpd = data;108struct drm_bridge *bridge = &tpd->bridge;109110drm_bridge_hpd_notify(bridge, tpd12s015_detect(bridge));111112return IRQ_HANDLED;113}114115static int tpd12s015_probe(struct platform_device *pdev)116{117struct tpd12s015_device *tpd;118struct device_node *node;119struct gpio_desc *gpio;120int ret;121122tpd = devm_drm_bridge_alloc(&pdev->dev, struct tpd12s015_device,123bridge, &tpd12s015_bridge_funcs);124if (IS_ERR(tpd))125return PTR_ERR(tpd);126127platform_set_drvdata(pdev, tpd);128129tpd->bridge.of_node = pdev->dev.of_node;130tpd->bridge.type = DRM_MODE_CONNECTOR_HDMIA;131tpd->bridge.ops = DRM_BRIDGE_OP_DETECT;132133/* Get the next bridge, connected to port@1. */134node = of_graph_get_remote_node(pdev->dev.of_node, 1, -1);135if (!node)136return -ENODEV;137138tpd->bridge.next_bridge = of_drm_find_and_get_bridge(node);139of_node_put(node);140141if (!tpd->bridge.next_bridge)142return -EPROBE_DEFER;143144/* Get the control and HPD GPIOs. */145gpio = devm_gpiod_get_index_optional(&pdev->dev, NULL, 0,146GPIOD_OUT_LOW);147if (IS_ERR(gpio))148return PTR_ERR(gpio);149150tpd->ct_cp_hpd_gpio = gpio;151152gpio = devm_gpiod_get_index_optional(&pdev->dev, NULL, 1,153GPIOD_OUT_LOW);154if (IS_ERR(gpio))155return PTR_ERR(gpio);156157tpd->ls_oe_gpio = gpio;158159gpio = devm_gpiod_get_index(&pdev->dev, NULL, 2, GPIOD_IN);160if (IS_ERR(gpio))161return PTR_ERR(gpio);162163tpd->hpd_gpio = gpio;164165/* Register the IRQ if the HPD GPIO is IRQ-capable. */166tpd->hpd_irq = gpiod_to_irq(tpd->hpd_gpio);167if (tpd->hpd_irq >= 0) {168ret = devm_request_threaded_irq(&pdev->dev, tpd->hpd_irq, NULL,169tpd12s015_hpd_isr,170IRQF_TRIGGER_RISING |171IRQF_TRIGGER_FALLING |172IRQF_ONESHOT,173"tpd12s015 hpd", tpd);174if (ret)175return ret;176177tpd->bridge.ops |= DRM_BRIDGE_OP_HPD;178}179180/* Register the DRM bridge. */181drm_bridge_add(&tpd->bridge);182183return 0;184}185186static void tpd12s015_remove(struct platform_device *pdev)187{188struct tpd12s015_device *tpd = platform_get_drvdata(pdev);189190drm_bridge_remove(&tpd->bridge);191}192193static const struct of_device_id tpd12s015_of_match[] = {194{ .compatible = "ti,tpd12s015", },195{},196};197198MODULE_DEVICE_TABLE(of, tpd12s015_of_match);199200static struct platform_driver tpd12s015_driver = {201.probe = tpd12s015_probe,202.remove = tpd12s015_remove,203.driver = {204.name = "tpd12s015",205.of_match_table = tpd12s015_of_match,206},207};208209module_platform_driver(tpd12s015_driver);210211MODULE_AUTHOR("Tomi Valkeinen <[email protected]>");212MODULE_DESCRIPTION("TPD12S015 HDMI level shifter and ESD protection driver");213MODULE_LICENSE("GPL");214215216