2013-05-24 18:20:14 +07:00
|
|
|
/*
|
|
|
|
* TPD12S015 HDMI ESD protection & level shifter chip driver
|
|
|
|
*
|
2017-12-06 03:29:31 +07:00
|
|
|
* Copyright (C) 2013 Texas Instruments Incorporated - http://www.ti.com/
|
2013-05-24 18:20:14 +07:00
|
|
|
* Author: Tomi Valkeinen <tomi.valkeinen@ti.com>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License version 2 as published by
|
|
|
|
* the Free Software Foundation.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/completion.h>
|
|
|
|
#include <linux/delay.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/slab.h>
|
|
|
|
#include <linux/platform_device.h>
|
2015-11-04 04:22:49 +07:00
|
|
|
#include <linux/gpio/consumer.h>
|
2017-06-02 19:26:37 +07:00
|
|
|
#include <linux/mutex.h>
|
2013-05-24 18:20:14 +07:00
|
|
|
|
2016-05-27 18:40:49 +07:00
|
|
|
#include "../dss/omapdss.h"
|
2013-05-24 18:20:14 +07:00
|
|
|
|
|
|
|
struct panel_drv_data {
|
|
|
|
struct omap_dss_device dssdev;
|
2017-06-02 19:26:37 +07:00
|
|
|
void (*hpd_cb)(void *cb_data, enum drm_connector_status status);
|
|
|
|
void *hpd_cb_data;
|
|
|
|
bool hpd_enabled;
|
|
|
|
struct mutex hpd_lock;
|
2013-05-24 18:20:14 +07:00
|
|
|
|
2015-11-04 04:22:49 +07:00
|
|
|
struct gpio_desc *ct_cp_hpd_gpio;
|
|
|
|
struct gpio_desc *ls_oe_gpio;
|
|
|
|
struct gpio_desc *hpd_gpio;
|
2013-05-24 18:20:14 +07:00
|
|
|
|
2016-09-22 18:07:04 +07:00
|
|
|
struct videomode vm;
|
2013-05-24 18:20:14 +07:00
|
|
|
};
|
|
|
|
|
|
|
|
#define to_panel_data(x) container_of(x, struct panel_drv_data, dssdev)
|
|
|
|
|
2018-03-05 04:42:36 +07:00
|
|
|
static int tpd_connect(struct omap_dss_device *src,
|
|
|
|
struct omap_dss_device *dst)
|
2013-05-24 18:20:14 +07:00
|
|
|
{
|
2018-03-05 04:42:36 +07:00
|
|
|
struct panel_drv_data *ddata = to_panel_data(dst);
|
2013-05-24 18:20:14 +07:00
|
|
|
int r;
|
|
|
|
|
2018-03-05 04:42:36 +07:00
|
|
|
r = omapdss_device_connect(dst->dss, dst, dst->next);
|
|
|
|
if (r)
|
2013-05-24 18:20:14 +07:00
|
|
|
return r;
|
|
|
|
|
2015-11-04 04:22:49 +07:00
|
|
|
gpiod_set_value_cansleep(ddata->ct_cp_hpd_gpio, 1);
|
2017-08-02 15:54:00 +07:00
|
|
|
gpiod_set_value_cansleep(ddata->ls_oe_gpio, 1);
|
|
|
|
|
2013-05-24 18:20:14 +07:00
|
|
|
/* DC-DC converter needs at max 300us to get to 90% of 5V */
|
|
|
|
udelay(300);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-03-05 04:42:36 +07:00
|
|
|
static void tpd_disconnect(struct omap_dss_device *src,
|
|
|
|
struct omap_dss_device *dst)
|
2013-05-24 18:20:14 +07:00
|
|
|
{
|
2018-03-05 04:42:36 +07:00
|
|
|
struct panel_drv_data *ddata = to_panel_data(dst);
|
2013-05-24 18:20:14 +07:00
|
|
|
|
2015-11-04 04:22:49 +07:00
|
|
|
gpiod_set_value_cansleep(ddata->ct_cp_hpd_gpio, 0);
|
2017-08-02 15:54:00 +07:00
|
|
|
gpiod_set_value_cansleep(ddata->ls_oe_gpio, 0);
|
2013-05-24 18:20:14 +07:00
|
|
|
|
2018-03-05 04:42:36 +07:00
|
|
|
omapdss_device_disconnect(dst, dst->next);
|
2013-05-24 18:20:14 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
static int tpd_enable(struct omap_dss_device *dssdev)
|
|
|
|
{
|
|
|
|
struct panel_drv_data *ddata = to_panel_data(dssdev);
|
2018-02-28 22:30:30 +07:00
|
|
|
struct omap_dss_device *src = dssdev->src;
|
2013-05-24 18:20:14 +07:00
|
|
|
int r;
|
|
|
|
|
|
|
|
if (dssdev->state == OMAP_DSS_DISPLAY_ACTIVE)
|
|
|
|
return 0;
|
|
|
|
|
2018-02-28 22:30:30 +07:00
|
|
|
src->ops->set_timings(src, &ddata->vm);
|
2013-05-24 18:20:14 +07:00
|
|
|
|
2018-02-28 22:30:30 +07:00
|
|
|
r = src->ops->enable(src);
|
2013-05-24 18:20:14 +07:00
|
|
|
if (r)
|
|
|
|
return r;
|
|
|
|
|
|
|
|
dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
|
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void tpd_disable(struct omap_dss_device *dssdev)
|
|
|
|
{
|
2018-02-28 22:30:30 +07:00
|
|
|
struct omap_dss_device *src = dssdev->src;
|
2013-05-24 18:20:14 +07:00
|
|
|
|
|
|
|
if (dssdev->state != OMAP_DSS_DISPLAY_ACTIVE)
|
|
|
|
return;
|
|
|
|
|
2018-02-28 22:30:30 +07:00
|
|
|
src->ops->disable(src);
|
2013-05-24 18:20:14 +07:00
|
|
|
|
|
|
|
dssdev->state = OMAP_DSS_DISPLAY_DISABLED;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void tpd_set_timings(struct omap_dss_device *dssdev,
|
2016-09-22 18:07:04 +07:00
|
|
|
struct videomode *vm)
|
2013-05-24 18:20:14 +07:00
|
|
|
{
|
|
|
|
struct panel_drv_data *ddata = to_panel_data(dssdev);
|
2018-02-28 22:30:30 +07:00
|
|
|
struct omap_dss_device *src = dssdev->src;
|
2013-05-24 18:20:14 +07:00
|
|
|
|
2016-09-22 18:07:04 +07:00
|
|
|
ddata->vm = *vm;
|
2013-05-24 18:20:14 +07:00
|
|
|
|
2018-02-28 22:30:30 +07:00
|
|
|
src->ops->set_timings(src, vm);
|
2013-05-24 18:20:14 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
static int tpd_check_timings(struct omap_dss_device *dssdev,
|
2016-09-22 18:07:04 +07:00
|
|
|
struct videomode *vm)
|
2013-05-24 18:20:14 +07:00
|
|
|
{
|
2018-02-28 22:30:30 +07:00
|
|
|
struct omap_dss_device *src = dssdev->src;
|
2013-05-24 18:20:14 +07:00
|
|
|
|
2018-02-28 22:30:30 +07:00
|
|
|
return src->ops->check_timings(src, vm);
|
2013-05-24 18:20:14 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
static int tpd_read_edid(struct omap_dss_device *dssdev,
|
|
|
|
u8 *edid, int len)
|
|
|
|
{
|
|
|
|
struct panel_drv_data *ddata = to_panel_data(dssdev);
|
2018-02-28 22:30:30 +07:00
|
|
|
struct omap_dss_device *src = dssdev->src;
|
2013-05-24 18:20:14 +07:00
|
|
|
|
2015-11-04 04:22:49 +07:00
|
|
|
if (!gpiod_get_value_cansleep(ddata->hpd_gpio))
|
2013-05-24 18:20:14 +07:00
|
|
|
return -ENODEV;
|
|
|
|
|
2018-06-01 23:45:01 +07:00
|
|
|
return src->ops->read_edid(src, edid, len);
|
2013-05-24 18:20:14 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
static bool tpd_detect(struct omap_dss_device *dssdev)
|
|
|
|
{
|
|
|
|
struct panel_drv_data *ddata = to_panel_data(dssdev);
|
2018-02-28 22:30:30 +07:00
|
|
|
struct omap_dss_device *src = dssdev->src;
|
2018-05-28 20:49:36 +07:00
|
|
|
bool connected;
|
2013-05-24 18:20:14 +07:00
|
|
|
|
2018-05-28 20:49:36 +07:00
|
|
|
connected = gpiod_get_value_cansleep(ddata->hpd_gpio);
|
2018-02-28 22:30:30 +07:00
|
|
|
if (!connected && src->ops->hdmi.lost_hotplug)
|
|
|
|
src->ops->hdmi.lost_hotplug(src);
|
2017-08-17 20:19:57 +07:00
|
|
|
return connected;
|
2013-05-24 18:20:14 +07:00
|
|
|
}
|
|
|
|
|
2018-05-30 22:51:59 +07:00
|
|
|
static void tpd_register_hpd_cb(struct omap_dss_device *dssdev,
|
|
|
|
void (*cb)(void *cb_data,
|
2017-06-02 19:26:37 +07:00
|
|
|
enum drm_connector_status status),
|
2018-05-30 22:51:59 +07:00
|
|
|
void *cb_data)
|
2017-06-02 19:26:37 +07:00
|
|
|
{
|
|
|
|
struct panel_drv_data *ddata = to_panel_data(dssdev);
|
|
|
|
|
|
|
|
mutex_lock(&ddata->hpd_lock);
|
|
|
|
ddata->hpd_cb = cb;
|
|
|
|
ddata->hpd_cb_data = cb_data;
|
|
|
|
mutex_unlock(&ddata->hpd_lock);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void tpd_unregister_hpd_cb(struct omap_dss_device *dssdev)
|
|
|
|
{
|
|
|
|
struct panel_drv_data *ddata = to_panel_data(dssdev);
|
|
|
|
|
|
|
|
mutex_lock(&ddata->hpd_lock);
|
|
|
|
ddata->hpd_cb = NULL;
|
|
|
|
ddata->hpd_cb_data = NULL;
|
|
|
|
mutex_unlock(&ddata->hpd_lock);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void tpd_enable_hpd(struct omap_dss_device *dssdev)
|
|
|
|
{
|
|
|
|
struct panel_drv_data *ddata = to_panel_data(dssdev);
|
|
|
|
|
|
|
|
mutex_lock(&ddata->hpd_lock);
|
|
|
|
ddata->hpd_enabled = true;
|
|
|
|
mutex_unlock(&ddata->hpd_lock);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void tpd_disable_hpd(struct omap_dss_device *dssdev)
|
|
|
|
{
|
|
|
|
struct panel_drv_data *ddata = to_panel_data(dssdev);
|
|
|
|
|
|
|
|
mutex_lock(&ddata->hpd_lock);
|
|
|
|
ddata->hpd_enabled = false;
|
|
|
|
mutex_unlock(&ddata->hpd_lock);
|
|
|
|
}
|
|
|
|
|
2014-06-18 16:58:02 +07:00
|
|
|
static int tpd_set_infoframe(struct omap_dss_device *dssdev,
|
|
|
|
const struct hdmi_avi_infoframe *avi)
|
|
|
|
{
|
2018-02-28 22:30:30 +07:00
|
|
|
struct omap_dss_device *src = dssdev->src;
|
2014-06-18 16:58:02 +07:00
|
|
|
|
2018-02-28 22:30:30 +07:00
|
|
|
return src->ops->hdmi.set_infoframe(src, avi);
|
2014-06-18 16:58:02 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
static int tpd_set_hdmi_mode(struct omap_dss_device *dssdev,
|
|
|
|
bool hdmi_mode)
|
|
|
|
{
|
2018-02-28 22:30:30 +07:00
|
|
|
struct omap_dss_device *src = dssdev->src;
|
2014-06-18 16:58:02 +07:00
|
|
|
|
2018-02-28 22:30:30 +07:00
|
|
|
return src->ops->hdmi.set_hdmi_mode(src, hdmi_mode);
|
2014-06-18 16:58:02 +07:00
|
|
|
}
|
|
|
|
|
2018-02-28 20:58:13 +07:00
|
|
|
static const struct omap_dss_device_ops tpd_ops = {
|
2013-05-24 18:20:14 +07:00
|
|
|
.connect = tpd_connect,
|
|
|
|
.disconnect = tpd_disconnect,
|
|
|
|
.enable = tpd_enable,
|
|
|
|
.disable = tpd_disable,
|
|
|
|
.check_timings = tpd_check_timings,
|
|
|
|
.set_timings = tpd_set_timings,
|
2018-06-01 23:45:01 +07:00
|
|
|
.read_edid = tpd_read_edid,
|
|
|
|
.detect = tpd_detect,
|
|
|
|
.register_hpd_cb = tpd_register_hpd_cb,
|
|
|
|
.unregister_hpd_cb = tpd_unregister_hpd_cb,
|
|
|
|
.enable_hpd = tpd_enable_hpd,
|
|
|
|
.disable_hpd = tpd_disable_hpd,
|
2013-05-24 18:20:14 +07:00
|
|
|
|
2018-02-28 20:58:13 +07:00
|
|
|
.hdmi = {
|
|
|
|
.set_infoframe = tpd_set_infoframe,
|
|
|
|
.set_hdmi_mode = tpd_set_hdmi_mode,
|
|
|
|
},
|
2013-05-24 18:20:14 +07:00
|
|
|
};
|
|
|
|
|
2017-06-02 19:26:37 +07:00
|
|
|
static irqreturn_t tpd_hpd_isr(int irq, void *data)
|
|
|
|
{
|
|
|
|
struct panel_drv_data *ddata = data;
|
|
|
|
|
|
|
|
mutex_lock(&ddata->hpd_lock);
|
|
|
|
if (ddata->hpd_enabled && ddata->hpd_cb) {
|
|
|
|
enum drm_connector_status status;
|
|
|
|
|
|
|
|
if (tpd_detect(&ddata->dssdev))
|
|
|
|
status = connector_status_connected;
|
|
|
|
else
|
|
|
|
status = connector_status_disconnected;
|
|
|
|
|
|
|
|
ddata->hpd_cb(ddata->hpd_cb_data, status);
|
|
|
|
}
|
|
|
|
mutex_unlock(&ddata->hpd_lock);
|
|
|
|
|
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
|
2013-05-24 18:20:14 +07:00
|
|
|
static int tpd_probe(struct platform_device *pdev)
|
|
|
|
{
|
2018-02-28 22:30:30 +07:00
|
|
|
struct omap_dss_device *dssdev;
|
2013-05-24 18:20:14 +07:00
|
|
|
struct panel_drv_data *ddata;
|
|
|
|
int r;
|
2015-11-04 04:22:49 +07:00
|
|
|
struct gpio_desc *gpio;
|
2013-05-24 18:20:14 +07:00
|
|
|
|
|
|
|
ddata = devm_kzalloc(&pdev->dev, sizeof(*ddata), GFP_KERNEL);
|
|
|
|
if (!ddata)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
platform_set_drvdata(pdev, ddata);
|
|
|
|
|
2015-11-04 04:22:50 +07:00
|
|
|
gpio = devm_gpiod_get_index_optional(&pdev->dev, NULL, 0,
|
2015-11-04 04:22:49 +07:00
|
|
|
GPIOD_OUT_LOW);
|
2018-02-11 20:07:41 +07:00
|
|
|
if (IS_ERR(gpio))
|
|
|
|
return PTR_ERR(gpio);
|
2013-05-24 18:20:14 +07:00
|
|
|
|
2015-11-04 04:22:49 +07:00
|
|
|
ddata->ct_cp_hpd_gpio = gpio;
|
2013-05-24 18:20:14 +07:00
|
|
|
|
2015-11-04 04:22:49 +07:00
|
|
|
gpio = devm_gpiod_get_index_optional(&pdev->dev, NULL, 1,
|
|
|
|
GPIOD_OUT_LOW);
|
2018-02-11 20:07:41 +07:00
|
|
|
if (IS_ERR(gpio))
|
|
|
|
return PTR_ERR(gpio);
|
2013-05-24 18:20:14 +07:00
|
|
|
|
2015-11-04 04:22:49 +07:00
|
|
|
ddata->ls_oe_gpio = gpio;
|
|
|
|
|
|
|
|
gpio = devm_gpiod_get_index(&pdev->dev, NULL, 2,
|
|
|
|
GPIOD_IN);
|
2018-02-11 20:07:41 +07:00
|
|
|
if (IS_ERR(gpio))
|
|
|
|
return PTR_ERR(gpio);
|
2015-11-04 04:22:49 +07:00
|
|
|
|
|
|
|
ddata->hpd_gpio = gpio;
|
|
|
|
|
2017-06-02 19:26:37 +07:00
|
|
|
mutex_init(&ddata->hpd_lock);
|
|
|
|
|
|
|
|
r = devm_request_threaded_irq(&pdev->dev, gpiod_to_irq(ddata->hpd_gpio),
|
|
|
|
NULL, tpd_hpd_isr,
|
|
|
|
IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING | IRQF_ONESHOT,
|
|
|
|
"tpd12s015 hpd", ddata);
|
|
|
|
if (r)
|
2018-02-11 20:07:41 +07:00
|
|
|
return r;
|
2017-06-02 19:26:37 +07:00
|
|
|
|
2013-05-24 18:20:14 +07:00
|
|
|
dssdev = &ddata->dssdev;
|
2018-02-28 20:58:13 +07:00
|
|
|
dssdev->ops = &tpd_ops;
|
2013-05-24 18:20:14 +07:00
|
|
|
dssdev->dev = &pdev->dev;
|
|
|
|
dssdev->type = OMAP_DISPLAY_TYPE_HDMI;
|
|
|
|
dssdev->output_type = OMAP_DISPLAY_TYPE_HDMI;
|
|
|
|
dssdev->owner = THIS_MODULE;
|
2018-03-05 02:49:28 +07:00
|
|
|
dssdev->of_ports = BIT(1) | BIT(0);
|
2018-05-30 22:49:48 +07:00
|
|
|
dssdev->ops_flags = OMAP_DSS_DEVICE_OP_DETECT
|
|
|
|
| OMAP_DSS_DEVICE_OP_HPD;
|
2013-05-24 18:20:14 +07:00
|
|
|
|
2018-03-03 03:13:06 +07:00
|
|
|
dssdev->next = omapdss_of_find_connected_device(pdev->dev.of_node, 1);
|
|
|
|
if (IS_ERR(dssdev->next)) {
|
|
|
|
if (PTR_ERR(dssdev->next) != -EPROBE_DEFER)
|
|
|
|
dev_err(&pdev->dev, "failed to find video sink\n");
|
|
|
|
return PTR_ERR(dssdev->next);
|
|
|
|
}
|
|
|
|
|
2018-03-02 06:25:32 +07:00
|
|
|
omapdss_device_register(dssdev);
|
2013-05-24 18:20:14 +07:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int __exit tpd_remove(struct platform_device *pdev)
|
|
|
|
{
|
|
|
|
struct panel_drv_data *ddata = platform_get_drvdata(pdev);
|
|
|
|
struct omap_dss_device *dssdev = &ddata->dssdev;
|
|
|
|
|
2018-03-03 03:13:06 +07:00
|
|
|
if (dssdev->next)
|
|
|
|
omapdss_device_put(dssdev->next);
|
2018-03-02 06:25:32 +07:00
|
|
|
omapdss_device_unregister(&ddata->dssdev);
|
2013-05-24 18:20:14 +07:00
|
|
|
|
|
|
|
WARN_ON(omapdss_device_is_enabled(dssdev));
|
|
|
|
if (omapdss_device_is_enabled(dssdev))
|
|
|
|
tpd_disable(dssdev);
|
|
|
|
|
|
|
|
WARN_ON(omapdss_device_is_connected(dssdev));
|
|
|
|
if (omapdss_device_is_connected(dssdev))
|
2018-03-05 04:42:36 +07:00
|
|
|
omapdss_device_disconnect(NULL, dssdev);
|
2013-05-24 18:20:14 +07:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-07-30 14:37:17 +07:00
|
|
|
static const struct of_device_id tpd_of_match[] = {
|
|
|
|
{ .compatible = "omapdss,ti,tpd12s015", },
|
|
|
|
{},
|
|
|
|
};
|
|
|
|
|
|
|
|
MODULE_DEVICE_TABLE(of, tpd_of_match);
|
|
|
|
|
2013-05-24 18:20:14 +07:00
|
|
|
static struct platform_driver tpd_driver = {
|
|
|
|
.probe = tpd_probe,
|
|
|
|
.remove = __exit_p(tpd_remove),
|
|
|
|
.driver = {
|
|
|
|
.name = "tpd12s015",
|
2013-07-30 14:37:17 +07:00
|
|
|
.of_match_table = tpd_of_match,
|
2014-10-16 13:54:25 +07:00
|
|
|
.suppress_bind_attrs = true,
|
2013-05-24 18:20:14 +07:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
module_platform_driver(tpd_driver);
|
|
|
|
|
|
|
|
MODULE_AUTHOR("Tomi Valkeinen <tomi.valkeinen@ti.com>");
|
|
|
|
MODULE_DESCRIPTION("TPD12S015 driver");
|
|
|
|
MODULE_LICENSE("GPL");
|