2 * TFP410 DPI-to-DVI chip
4 * Copyright (C) 2011 Texas Instruments Inc
5 * Author: Tomi Valkeinen <tomi.valkeinen@ti.com>
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License version 2 as published by
9 * the Free Software Foundation.
11 * This program is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
16 * You should have received a copy of the GNU General Public License along with
17 * this program. If not, see <http://www.gnu.org/licenses/>.
20 #include <linux/module.h>
21 #include <linux/slab.h>
22 #include <video/omapdss.h>
23 #include <linux/i2c.h>
24 #include <linux/gpio.h>
25 #include <drm/drm_edid.h>
27 #include <video/omap-panel-data.h>
29 static const struct omap_video_timings tfp410_default_timings = {
43 .vsync_level = OMAPDSS_SIG_ACTIVE_HIGH,
44 .hsync_level = OMAPDSS_SIG_ACTIVE_HIGH,
45 .data_pclk_edge = OMAPDSS_DRIVE_SIG_RISING_EDGE,
46 .de_level = OMAPDSS_SIG_ACTIVE_HIGH,
47 .sync_pclk_edge = OMAPDSS_DRIVE_SIG_OPPOSITE_EDGES,
50 struct panel_drv_data {
51 struct omap_dss_device *dssdev;
57 struct i2c_adapter *i2c_adapter;
60 static int tfp410_power_on(struct omap_dss_device *dssdev)
62 struct panel_drv_data *ddata = dev_get_drvdata(dssdev->dev);
65 if (dssdev->state == OMAP_DSS_DISPLAY_ACTIVE)
68 omapdss_dpi_set_timings(dssdev, &dssdev->panel.timings);
69 omapdss_dpi_set_data_lines(dssdev, dssdev->phy.dpi.data_lines);
71 r = omapdss_dpi_display_enable(dssdev);
75 if (gpio_is_valid(ddata->pd_gpio))
76 gpio_set_value_cansleep(ddata->pd_gpio, 1);
83 static void tfp410_power_off(struct omap_dss_device *dssdev)
85 struct panel_drv_data *ddata = dev_get_drvdata(dssdev->dev);
87 if (dssdev->state != OMAP_DSS_DISPLAY_ACTIVE)
90 if (gpio_is_valid(ddata->pd_gpio))
91 gpio_set_value_cansleep(ddata->pd_gpio, 0);
93 omapdss_dpi_display_disable(dssdev);
96 static int tfp410_probe(struct omap_dss_device *dssdev)
98 struct panel_drv_data *ddata;
102 ddata = devm_kzalloc(dssdev->dev, sizeof(*ddata), GFP_KERNEL);
106 dssdev->panel.timings = tfp410_default_timings;
108 ddata->dssdev = dssdev;
109 mutex_init(&ddata->lock);
112 struct tfp410_platform_data *pdata = dssdev->data;
114 ddata->pd_gpio = pdata->power_down_gpio;
115 i2c_bus_num = pdata->i2c_bus_num;
121 if (gpio_is_valid(ddata->pd_gpio)) {
122 r = devm_gpio_request_one(dssdev->dev, ddata->pd_gpio,
123 GPIOF_OUT_INIT_LOW, "tfp410 pd");
125 dev_err(dssdev->dev, "Failed to request PD GPIO %d\n",
131 if (i2c_bus_num != -1) {
132 struct i2c_adapter *adapter;
134 adapter = i2c_get_adapter(i2c_bus_num);
136 dev_err(dssdev->dev, "Failed to get I2C adapter, bus %d\n",
138 return -EPROBE_DEFER;
141 ddata->i2c_adapter = adapter;
144 dev_set_drvdata(dssdev->dev, ddata);
149 static void __exit tfp410_remove(struct omap_dss_device *dssdev)
151 struct panel_drv_data *ddata = dev_get_drvdata(dssdev->dev);
153 mutex_lock(&ddata->lock);
155 if (ddata->i2c_adapter)
156 i2c_put_adapter(ddata->i2c_adapter);
158 dev_set_drvdata(dssdev->dev, NULL);
160 mutex_unlock(&ddata->lock);
163 static int tfp410_enable(struct omap_dss_device *dssdev)
165 struct panel_drv_data *ddata = dev_get_drvdata(dssdev->dev);
168 mutex_lock(&ddata->lock);
170 r = tfp410_power_on(dssdev);
172 dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
174 mutex_unlock(&ddata->lock);
179 static void tfp410_disable(struct omap_dss_device *dssdev)
181 struct panel_drv_data *ddata = dev_get_drvdata(dssdev->dev);
183 mutex_lock(&ddata->lock);
185 tfp410_power_off(dssdev);
187 dssdev->state = OMAP_DSS_DISPLAY_DISABLED;
189 mutex_unlock(&ddata->lock);
192 static void tfp410_set_timings(struct omap_dss_device *dssdev,
193 struct omap_video_timings *timings)
195 struct panel_drv_data *ddata = dev_get_drvdata(dssdev->dev);
197 mutex_lock(&ddata->lock);
198 omapdss_dpi_set_timings(dssdev, timings);
199 dssdev->panel.timings = *timings;
200 mutex_unlock(&ddata->lock);
203 static void tfp410_get_timings(struct omap_dss_device *dssdev,
204 struct omap_video_timings *timings)
206 struct panel_drv_data *ddata = dev_get_drvdata(dssdev->dev);
208 mutex_lock(&ddata->lock);
209 *timings = dssdev->panel.timings;
210 mutex_unlock(&ddata->lock);
213 static int tfp410_check_timings(struct omap_dss_device *dssdev,
214 struct omap_video_timings *timings)
216 struct panel_drv_data *ddata = dev_get_drvdata(dssdev->dev);
219 mutex_lock(&ddata->lock);
220 r = dpi_check_timings(dssdev, timings);
221 mutex_unlock(&ddata->lock);
227 static int tfp410_ddc_read(struct i2c_adapter *adapter,
228 unsigned char *buf, u16 count, u8 offset)
232 for (retries = 3; retries > 0; retries--) {
233 struct i2c_msg msgs[] = {
247 r = i2c_transfer(adapter, msgs, 2);
255 return r < 0 ? r : -EIO;
258 static int tfp410_read_edid(struct omap_dss_device *dssdev,
261 struct panel_drv_data *ddata = dev_get_drvdata(dssdev->dev);
262 int r, l, bytes_read;
264 mutex_lock(&ddata->lock);
266 if (!ddata->i2c_adapter) {
271 l = min(EDID_LENGTH, len);
272 r = tfp410_ddc_read(ddata->i2c_adapter, edid, l, 0);
278 /* if there are extensions, read second block */
279 if (len > EDID_LENGTH && edid[0x7e] > 0) {
280 l = min(EDID_LENGTH, len - EDID_LENGTH);
282 r = tfp410_ddc_read(ddata->i2c_adapter, edid + EDID_LENGTH,
290 mutex_unlock(&ddata->lock);
295 mutex_unlock(&ddata->lock);
299 static bool tfp410_detect(struct omap_dss_device *dssdev)
301 struct panel_drv_data *ddata = dev_get_drvdata(dssdev->dev);
305 mutex_lock(&ddata->lock);
307 if (!ddata->i2c_adapter)
310 r = tfp410_ddc_read(ddata->i2c_adapter, &out, 1, 0);
312 mutex_unlock(&ddata->lock);
317 mutex_unlock(&ddata->lock);
321 static struct omap_dss_driver tfp410_driver = {
322 .probe = tfp410_probe,
323 .remove = __exit_p(tfp410_remove),
325 .enable = tfp410_enable,
326 .disable = tfp410_disable,
328 .set_timings = tfp410_set_timings,
329 .get_timings = tfp410_get_timings,
330 .check_timings = tfp410_check_timings,
332 .read_edid = tfp410_read_edid,
333 .detect = tfp410_detect,
337 .owner = THIS_MODULE,
341 static int __init tfp410_init(void)
343 return omap_dss_register_driver(&tfp410_driver);
346 static void __exit tfp410_exit(void)
348 omap_dss_unregister_driver(&tfp410_driver);
351 module_init(tfp410_init);
352 module_exit(tfp410_exit);
353 MODULE_LICENSE("GPL");