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-tfp410.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 r = omapdss_dpi_display_enable(dssdev);
72 if (gpio_is_valid(ddata->pd_gpio))
73 gpio_set_value_cansleep(ddata->pd_gpio, 1);
80 static void tfp410_power_off(struct omap_dss_device *dssdev)
82 struct panel_drv_data *ddata = dev_get_drvdata(&dssdev->dev);
84 if (dssdev->state != OMAP_DSS_DISPLAY_ACTIVE)
87 if (gpio_is_valid(ddata->pd_gpio))
88 gpio_set_value_cansleep(ddata->pd_gpio, 0);
90 omapdss_dpi_display_disable(dssdev);
93 static int tfp410_probe(struct omap_dss_device *dssdev)
95 struct panel_drv_data *ddata;
99 ddata = devm_kzalloc(&dssdev->dev, sizeof(*ddata), GFP_KERNEL);
103 dssdev->panel.timings = tfp410_default_timings;
105 ddata->dssdev = dssdev;
106 mutex_init(&ddata->lock);
109 struct tfp410_platform_data *pdata = dssdev->data;
111 ddata->pd_gpio = pdata->power_down_gpio;
112 i2c_bus_num = pdata->i2c_bus_num;
118 if (gpio_is_valid(ddata->pd_gpio)) {
119 r = gpio_request_one(ddata->pd_gpio, GPIOF_OUT_INIT_LOW,
122 dev_err(&dssdev->dev, "Failed to request PD GPIO %d\n",
128 if (i2c_bus_num != -1) {
129 struct i2c_adapter *adapter;
131 adapter = i2c_get_adapter(i2c_bus_num);
133 dev_err(&dssdev->dev, "Failed to get I2C adapter, bus %d\n",
139 ddata->i2c_adapter = adapter;
142 dev_set_drvdata(&dssdev->dev, ddata);
146 if (gpio_is_valid(ddata->pd_gpio))
147 gpio_free(ddata->pd_gpio);
151 static void __exit tfp410_remove(struct omap_dss_device *dssdev)
153 struct panel_drv_data *ddata = dev_get_drvdata(&dssdev->dev);
155 mutex_lock(&ddata->lock);
157 if (ddata->i2c_adapter)
158 i2c_put_adapter(ddata->i2c_adapter);
160 if (gpio_is_valid(ddata->pd_gpio))
161 gpio_free(ddata->pd_gpio);
163 dev_set_drvdata(&dssdev->dev, NULL);
165 mutex_unlock(&ddata->lock);
168 static int tfp410_enable(struct omap_dss_device *dssdev)
170 struct panel_drv_data *ddata = dev_get_drvdata(&dssdev->dev);
173 mutex_lock(&ddata->lock);
175 r = tfp410_power_on(dssdev);
177 dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
179 mutex_unlock(&ddata->lock);
184 static void tfp410_disable(struct omap_dss_device *dssdev)
186 struct panel_drv_data *ddata = dev_get_drvdata(&dssdev->dev);
188 mutex_lock(&ddata->lock);
190 tfp410_power_off(dssdev);
192 dssdev->state = OMAP_DSS_DISPLAY_DISABLED;
194 mutex_unlock(&ddata->lock);
197 static int tfp410_suspend(struct omap_dss_device *dssdev)
199 struct panel_drv_data *ddata = dev_get_drvdata(&dssdev->dev);
201 mutex_lock(&ddata->lock);
203 tfp410_power_off(dssdev);
205 dssdev->state = OMAP_DSS_DISPLAY_SUSPENDED;
207 mutex_unlock(&ddata->lock);
212 static int tfp410_resume(struct omap_dss_device *dssdev)
214 struct panel_drv_data *ddata = dev_get_drvdata(&dssdev->dev);
217 mutex_lock(&ddata->lock);
219 r = tfp410_power_on(dssdev);
221 dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
223 mutex_unlock(&ddata->lock);
228 static void tfp410_set_timings(struct omap_dss_device *dssdev,
229 struct omap_video_timings *timings)
231 struct panel_drv_data *ddata = dev_get_drvdata(&dssdev->dev);
233 mutex_lock(&ddata->lock);
234 dpi_set_timings(dssdev, timings);
235 mutex_unlock(&ddata->lock);
238 static void tfp410_get_timings(struct omap_dss_device *dssdev,
239 struct omap_video_timings *timings)
241 struct panel_drv_data *ddata = dev_get_drvdata(&dssdev->dev);
243 mutex_lock(&ddata->lock);
244 *timings = dssdev->panel.timings;
245 mutex_unlock(&ddata->lock);
248 static int tfp410_check_timings(struct omap_dss_device *dssdev,
249 struct omap_video_timings *timings)
251 struct panel_drv_data *ddata = dev_get_drvdata(&dssdev->dev);
254 mutex_lock(&ddata->lock);
255 r = dpi_check_timings(dssdev, timings);
256 mutex_unlock(&ddata->lock);
262 static int tfp410_ddc_read(struct i2c_adapter *adapter,
263 unsigned char *buf, u16 count, u8 offset)
267 for (retries = 3; retries > 0; retries--) {
268 struct i2c_msg msgs[] = {
282 r = i2c_transfer(adapter, msgs, 2);
290 return r < 0 ? r : -EIO;
293 static int tfp410_read_edid(struct omap_dss_device *dssdev,
296 struct panel_drv_data *ddata = dev_get_drvdata(&dssdev->dev);
297 int r, l, bytes_read;
299 mutex_lock(&ddata->lock);
301 if (!ddata->i2c_adapter) {
306 l = min(EDID_LENGTH, len);
307 r = tfp410_ddc_read(ddata->i2c_adapter, edid, l, 0);
313 /* if there are extensions, read second block */
314 if (len > EDID_LENGTH && edid[0x7e] > 0) {
315 l = min(EDID_LENGTH, len - EDID_LENGTH);
317 r = tfp410_ddc_read(ddata->i2c_adapter, edid + EDID_LENGTH,
325 mutex_unlock(&ddata->lock);
330 mutex_unlock(&ddata->lock);
334 static bool tfp410_detect(struct omap_dss_device *dssdev)
336 struct panel_drv_data *ddata = dev_get_drvdata(&dssdev->dev);
340 mutex_lock(&ddata->lock);
342 if (!ddata->i2c_adapter)
345 r = tfp410_ddc_read(ddata->i2c_adapter, &out, 1, 0);
347 mutex_unlock(&ddata->lock);
352 mutex_unlock(&ddata->lock);
356 static struct omap_dss_driver tfp410_driver = {
357 .probe = tfp410_probe,
358 .remove = __exit_p(tfp410_remove),
360 .enable = tfp410_enable,
361 .disable = tfp410_disable,
362 .suspend = tfp410_suspend,
363 .resume = tfp410_resume,
365 .set_timings = tfp410_set_timings,
366 .get_timings = tfp410_get_timings,
367 .check_timings = tfp410_check_timings,
369 .read_edid = tfp410_read_edid,
370 .detect = tfp410_detect,
374 .owner = THIS_MODULE,
378 static int __init tfp410_init(void)
380 return omap_dss_register_driver(&tfp410_driver);
383 static void __exit tfp410_exit(void)
385 omap_dss_unregister_driver(&tfp410_driver);
388 module_init(tfp410_init);
389 module_exit(tfp410_exit);
390 MODULE_LICENSE("GPL");