connector-hdmi.c 4.7 KB
Newer Older
1 2 3
/*
 * HDMI Connector driver
 *
4
 * Copyright (C) 2013 Texas Instruments Incorporated - http://www.ti.com/
5 6 7 8 9 10 11
 * 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.
 */

12
#include <linux/gpio/consumer.h>
13
#include <linux/module.h>
14
#include <linux/mutex.h>
15 16
#include <linux/platform_device.h>
#include <linux/slab.h>
17

18 19
#include "../dss/omapdss.h"

20 21
struct panel_drv_data {
	struct omap_dss_device dssdev;
22 23 24
	void (*hpd_cb)(void *cb_data, enum drm_connector_status status);
	void *hpd_cb_data;
	struct mutex hpd_lock;
25 26 27

	struct device *dev;

28
	struct gpio_desc *hpd_gpio;
29 30 31 32
};

#define to_panel_data(x) container_of(x, struct panel_drv_data, dssdev)

33 34
static int hdmic_connect(struct omap_dss_device *src,
			 struct omap_dss_device *dst)
35 36 37 38
{
	return 0;
}

39 40
static void hdmic_disconnect(struct omap_dss_device *src,
			     struct omap_dss_device *dst)
41 42 43 44 45
{
}

static int hdmic_enable(struct omap_dss_device *dssdev)
{
46
	struct omap_dss_device *src = dssdev->src;
47

48
	return src->ops->enable(src);
49 50 51 52
}

static void hdmic_disable(struct omap_dss_device *dssdev)
{
53
	struct omap_dss_device *src = dssdev->src;
54

55
	src->ops->disable(src);
56 57 58 59 60 61
}

static bool hdmic_detect(struct omap_dss_device *dssdev)
{
	struct panel_drv_data *ddata = to_panel_data(dssdev);

62
	return gpiod_get_value_cansleep(ddata->hpd_gpio);
63 64
}

65 66
static void hdmic_register_hpd_cb(struct omap_dss_device *dssdev,
				  void (*cb)(void *cb_data,
67
					    enum drm_connector_status status),
68
				  void *cb_data)
69 70 71
{
	struct panel_drv_data *ddata = to_panel_data(dssdev);

72 73 74 75
	mutex_lock(&ddata->hpd_lock);
	ddata->hpd_cb = cb;
	ddata->hpd_cb_data = cb_data;
	mutex_unlock(&ddata->hpd_lock);
76 77 78 79 80 81
}

static void hdmic_unregister_hpd_cb(struct omap_dss_device *dssdev)
{
	struct panel_drv_data *ddata = to_panel_data(dssdev);

82 83 84 85
	mutex_lock(&ddata->hpd_lock);
	ddata->hpd_cb = NULL;
	ddata->hpd_cb_data = NULL;
	mutex_unlock(&ddata->hpd_lock);
86 87
}

88
static const struct omap_dss_device_ops hdmic_ops = {
89 90 91 92 93 94 95
	.connect		= hdmic_connect,
	.disconnect		= hdmic_disconnect,

	.enable			= hdmic_enable,
	.disable		= hdmic_disable,

	.detect			= hdmic_detect,
96 97
	.register_hpd_cb	= hdmic_register_hpd_cb,
	.unregister_hpd_cb	= hdmic_unregister_hpd_cb,
98 99
};

100 101 102 103 104
static irqreturn_t hdmic_hpd_isr(int irq, void *data)
{
	struct panel_drv_data *ddata = data;

	mutex_lock(&ddata->hpd_lock);
105
	if (ddata->hpd_cb) {
106 107 108 109 110 111 112 113 114 115 116 117 118 119
		enum drm_connector_status status;

		if (hdmic_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;
}

120 121 122 123
static int hdmic_probe(struct platform_device *pdev)
{
	struct panel_drv_data *ddata;
	struct omap_dss_device *dssdev;
124
	struct gpio_desc *gpio;
125 126 127 128 129 130 131 132 133
	int r;

	ddata = devm_kzalloc(&pdev->dev, sizeof(*ddata), GFP_KERNEL);
	if (!ddata)
		return -ENOMEM;

	platform_set_drvdata(pdev, ddata);
	ddata->dev = &pdev->dev;

134 135
	mutex_init(&ddata->hpd_lock);

136 137 138 139 140 141 142 143
	/* HPD GPIO */
	gpio = devm_gpiod_get_optional(&pdev->dev, "hpd", GPIOD_IN);
	if (IS_ERR(gpio)) {
		dev_err(&pdev->dev, "failed to parse HPD gpio\n");
		return PTR_ERR(gpio);
	}

	ddata->hpd_gpio = gpio;
144

145
	if (ddata->hpd_gpio) {
146
		r = devm_request_threaded_irq(&pdev->dev,
147
				gpiod_to_irq(ddata->hpd_gpio),
148 149 150 151 152
				NULL, hdmic_hpd_isr,
				IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING |
				IRQF_ONESHOT,
				"hdmic hpd", ddata);
		if (r)
153
			return r;
154 155
	}

156
	dssdev = &ddata->dssdev;
157
	dssdev->ops = &hdmic_ops;
158 159 160
	dssdev->dev = &pdev->dev;
	dssdev->type = OMAP_DISPLAY_TYPE_HDMI;
	dssdev->owner = THIS_MODULE;
161
	dssdev->of_ports = BIT(0);
162 163 164
	dssdev->ops_flags = ddata->hpd_gpio
			  ? OMAP_DSS_DEVICE_OP_DETECT | OMAP_DSS_DEVICE_OP_HPD
			  : 0;
165

166
	omapdss_display_init(dssdev);
167
	omapdss_device_register(dssdev);
168 169 170 171 172 173 174 175 176

	return 0;
}

static int __exit hdmic_remove(struct platform_device *pdev)
{
	struct panel_drv_data *ddata = platform_get_drvdata(pdev);
	struct omap_dss_device *dssdev = &ddata->dssdev;

177
	omapdss_device_unregister(&ddata->dssdev);
178

179 180
	if (omapdss_device_is_enabled(dssdev))
		hdmic_disable(dssdev);
181 182 183 184

	return 0;
}

185 186 187 188 189 190 191
static const struct of_device_id hdmic_of_match[] = {
	{ .compatible = "omapdss,hdmi-connector", },
	{},
};

MODULE_DEVICE_TABLE(of, hdmic_of_match);

192 193 194 195 196
static struct platform_driver hdmi_connector_driver = {
	.probe	= hdmic_probe,
	.remove	= __exit_p(hdmic_remove),
	.driver	= {
		.name	= "connector-hdmi",
197
		.of_match_table = hdmic_of_match,
T
Tomi Valkeinen 已提交
198
		.suppress_bind_attrs = true,
199 200 201 202 203 204 205 206
	},
};

module_platform_driver(hdmi_connector_driver);

MODULE_AUTHOR("Tomi Valkeinen <tomi.valkeinen@ti.com>");
MODULE_DESCRIPTION("HDMI Connector driver");
MODULE_LICENSE("GPL");