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-dvi.h>
29 static const struct omap_video_timings tfp410_default_timings = {
44 struct panel_drv_data {
45 struct omap_dss_device *dssdev;
52 static inline struct tfp410_platform_data
53 *get_pdata(const struct omap_dss_device *dssdev)
58 static int tfp410_power_on(struct omap_dss_device *dssdev)
60 struct panel_drv_data *ddata = dev_get_drvdata(&dssdev->dev);
63 if (dssdev->state == OMAP_DSS_DISPLAY_ACTIVE)
66 r = omapdss_dpi_display_enable(dssdev);
70 if (gpio_is_valid(ddata->pd_gpio))
71 gpio_set_value(ddata->pd_gpio, 1);
78 static void tfp410_power_off(struct omap_dss_device *dssdev)
80 struct panel_drv_data *ddata = dev_get_drvdata(&dssdev->dev);
82 if (dssdev->state != OMAP_DSS_DISPLAY_ACTIVE)
85 if (gpio_is_valid(ddata->pd_gpio))
86 gpio_set_value(ddata->pd_gpio, 0);
88 omapdss_dpi_display_disable(dssdev);
91 static int tfp410_probe(struct omap_dss_device *dssdev)
93 struct tfp410_platform_data *pdata = get_pdata(dssdev);
94 struct panel_drv_data *ddata;
97 ddata = kzalloc(sizeof(*ddata), GFP_KERNEL);
101 dssdev->panel.timings = tfp410_default_timings;
102 dssdev->panel.config = OMAP_DSS_LCD_TFT;
104 ddata->dssdev = dssdev;
105 mutex_init(&ddata->lock);
108 ddata->pd_gpio = pdata->power_down_gpio;
112 if (gpio_is_valid(ddata->pd_gpio)) {
113 r = gpio_request_one(ddata->pd_gpio, GPIOF_OUT_INIT_LOW,
116 dev_err(&dssdev->dev, "Failed to request PD GPIO %d\n",
122 dev_set_drvdata(&dssdev->dev, ddata);
127 static void __exit tfp410_remove(struct omap_dss_device *dssdev)
129 struct panel_drv_data *ddata = dev_get_drvdata(&dssdev->dev);
131 mutex_lock(&ddata->lock);
133 if (gpio_is_valid(ddata->pd_gpio))
134 gpio_free(ddata->pd_gpio);
136 dev_set_drvdata(&dssdev->dev, NULL);
138 mutex_unlock(&ddata->lock);
143 static int tfp410_enable(struct omap_dss_device *dssdev)
145 struct panel_drv_data *ddata = dev_get_drvdata(&dssdev->dev);
148 mutex_lock(&ddata->lock);
150 r = tfp410_power_on(dssdev);
152 dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
154 mutex_unlock(&ddata->lock);
159 static void tfp410_disable(struct omap_dss_device *dssdev)
161 struct panel_drv_data *ddata = dev_get_drvdata(&dssdev->dev);
163 mutex_lock(&ddata->lock);
165 tfp410_power_off(dssdev);
167 dssdev->state = OMAP_DSS_DISPLAY_DISABLED;
169 mutex_unlock(&ddata->lock);
172 static int tfp410_suspend(struct omap_dss_device *dssdev)
174 struct panel_drv_data *ddata = dev_get_drvdata(&dssdev->dev);
176 mutex_lock(&ddata->lock);
178 tfp410_power_off(dssdev);
180 dssdev->state = OMAP_DSS_DISPLAY_SUSPENDED;
182 mutex_unlock(&ddata->lock);
187 static int tfp410_resume(struct omap_dss_device *dssdev)
189 struct panel_drv_data *ddata = dev_get_drvdata(&dssdev->dev);
192 mutex_lock(&ddata->lock);
194 r = tfp410_power_on(dssdev);
196 dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
198 mutex_unlock(&ddata->lock);
203 static void tfp410_set_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 dpi_set_timings(dssdev, timings);
210 mutex_unlock(&ddata->lock);
213 static void tfp410_get_timings(struct omap_dss_device *dssdev,
214 struct omap_video_timings *timings)
216 struct panel_drv_data *ddata = dev_get_drvdata(&dssdev->dev);
218 mutex_lock(&ddata->lock);
219 *timings = dssdev->panel.timings;
220 mutex_unlock(&ddata->lock);
223 static int tfp410_check_timings(struct omap_dss_device *dssdev,
224 struct omap_video_timings *timings)
226 struct panel_drv_data *ddata = dev_get_drvdata(&dssdev->dev);
229 mutex_lock(&ddata->lock);
230 r = dpi_check_timings(dssdev, timings);
231 mutex_unlock(&ddata->lock);
237 static int tfp410_ddc_read(struct i2c_adapter *adapter,
238 unsigned char *buf, u16 count, u8 offset)
242 for (retries = 3; retries > 0; retries--) {
243 struct i2c_msg msgs[] = {
257 r = i2c_transfer(adapter, msgs, 2);
265 return r < 0 ? r : -EIO;
268 static int tfp410_read_edid(struct omap_dss_device *dssdev,
271 struct panel_drv_data *ddata = dev_get_drvdata(&dssdev->dev);
272 struct tfp410_platform_data *pdata = get_pdata(dssdev);
273 struct i2c_adapter *adapter;
274 int r, l, bytes_read;
276 mutex_lock(&ddata->lock);
278 if (pdata->i2c_bus_num == 0) {
283 adapter = i2c_get_adapter(pdata->i2c_bus_num);
285 dev_err(&dssdev->dev, "Failed to get I2C adapter, bus %d\n",
291 l = min(EDID_LENGTH, len);
292 r = tfp410_ddc_read(adapter, edid, l, 0);
298 /* if there are extensions, read second block */
299 if (len > EDID_LENGTH && edid[0x7e] > 0) {
300 l = min(EDID_LENGTH, len - EDID_LENGTH);
302 r = tfp410_ddc_read(adapter, edid + EDID_LENGTH,
310 mutex_unlock(&ddata->lock);
315 mutex_unlock(&ddata->lock);
319 static bool tfp410_detect(struct omap_dss_device *dssdev)
321 struct panel_drv_data *ddata = dev_get_drvdata(&dssdev->dev);
322 struct tfp410_platform_data *pdata = get_pdata(dssdev);
323 struct i2c_adapter *adapter;
327 mutex_lock(&ddata->lock);
329 if (pdata->i2c_bus_num == 0)
332 adapter = i2c_get_adapter(pdata->i2c_bus_num);
336 r = tfp410_ddc_read(adapter, &out, 1, 0);
338 mutex_unlock(&ddata->lock);
343 mutex_unlock(&ddata->lock);
347 static struct omap_dss_driver tfp410_driver = {
348 .probe = tfp410_probe,
349 .remove = __exit_p(tfp410_remove),
351 .enable = tfp410_enable,
352 .disable = tfp410_disable,
353 .suspend = tfp410_suspend,
354 .resume = tfp410_resume,
356 .set_timings = tfp410_set_timings,
357 .get_timings = tfp410_get_timings,
358 .check_timings = tfp410_check_timings,
360 .read_edid = tfp410_read_edid,
361 .detect = tfp410_detect,
365 .owner = THIS_MODULE,
369 static int __init tfp410_init(void)
371 return omap_dss_register_driver(&tfp410_driver);
374 static void __exit tfp410_exit(void)
376 omap_dss_unregister_driver(&tfp410_driver);
379 module_init(tfp410_init);
380 module_exit(tfp410_exit);
381 MODULE_LICENSE("GPL");