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 = {
44 struct panel_drv_data {
45 struct omap_dss_device *dssdev;
51 struct i2c_adapter *i2c_adapter;
54 static int tfp410_power_on(struct omap_dss_device *dssdev)
56 struct panel_drv_data *ddata = dev_get_drvdata(&dssdev->dev);
59 if (dssdev->state == OMAP_DSS_DISPLAY_ACTIVE)
62 r = omapdss_dpi_display_enable(dssdev);
66 if (gpio_is_valid(ddata->pd_gpio))
67 gpio_set_value_cansleep(ddata->pd_gpio, 1);
74 static void tfp410_power_off(struct omap_dss_device *dssdev)
76 struct panel_drv_data *ddata = dev_get_drvdata(&dssdev->dev);
78 if (dssdev->state != OMAP_DSS_DISPLAY_ACTIVE)
81 if (gpio_is_valid(ddata->pd_gpio))
82 gpio_set_value_cansleep(ddata->pd_gpio, 0);
84 omapdss_dpi_display_disable(dssdev);
87 static int tfp410_probe(struct omap_dss_device *dssdev)
89 struct panel_drv_data *ddata;
93 ddata = devm_kzalloc(&dssdev->dev, sizeof(*ddata), GFP_KERNEL);
97 dssdev->panel.timings = tfp410_default_timings;
99 ddata->dssdev = dssdev;
100 mutex_init(&ddata->lock);
103 struct tfp410_platform_data *pdata = dssdev->data;
105 ddata->pd_gpio = pdata->power_down_gpio;
106 i2c_bus_num = pdata->i2c_bus_num;
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 if (i2c_bus_num != -1) {
123 struct i2c_adapter *adapter;
125 adapter = i2c_get_adapter(i2c_bus_num);
127 dev_err(&dssdev->dev, "Failed to get I2C adapter, bus %d\n",
133 ddata->i2c_adapter = adapter;
136 dev_set_drvdata(&dssdev->dev, ddata);
140 if (gpio_is_valid(ddata->pd_gpio))
141 gpio_free(ddata->pd_gpio);
145 static void __exit tfp410_remove(struct omap_dss_device *dssdev)
147 struct panel_drv_data *ddata = dev_get_drvdata(&dssdev->dev);
149 mutex_lock(&ddata->lock);
151 if (ddata->i2c_adapter)
152 i2c_put_adapter(ddata->i2c_adapter);
154 if (gpio_is_valid(ddata->pd_gpio))
155 gpio_free(ddata->pd_gpio);
157 dev_set_drvdata(&dssdev->dev, NULL);
159 mutex_unlock(&ddata->lock);
162 static int tfp410_enable(struct omap_dss_device *dssdev)
164 struct panel_drv_data *ddata = dev_get_drvdata(&dssdev->dev);
167 mutex_lock(&ddata->lock);
169 r = tfp410_power_on(dssdev);
171 dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
173 mutex_unlock(&ddata->lock);
178 static void tfp410_disable(struct omap_dss_device *dssdev)
180 struct panel_drv_data *ddata = dev_get_drvdata(&dssdev->dev);
182 mutex_lock(&ddata->lock);
184 tfp410_power_off(dssdev);
186 dssdev->state = OMAP_DSS_DISPLAY_DISABLED;
188 mutex_unlock(&ddata->lock);
191 static int tfp410_suspend(struct omap_dss_device *dssdev)
193 struct panel_drv_data *ddata = dev_get_drvdata(&dssdev->dev);
195 mutex_lock(&ddata->lock);
197 tfp410_power_off(dssdev);
199 dssdev->state = OMAP_DSS_DISPLAY_SUSPENDED;
201 mutex_unlock(&ddata->lock);
206 static int tfp410_resume(struct omap_dss_device *dssdev)
208 struct panel_drv_data *ddata = dev_get_drvdata(&dssdev->dev);
211 mutex_lock(&ddata->lock);
213 r = tfp410_power_on(dssdev);
215 dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
217 mutex_unlock(&ddata->lock);
222 static void tfp410_set_timings(struct omap_dss_device *dssdev,
223 struct omap_video_timings *timings)
225 struct panel_drv_data *ddata = dev_get_drvdata(&dssdev->dev);
227 mutex_lock(&ddata->lock);
228 dpi_set_timings(dssdev, timings);
229 mutex_unlock(&ddata->lock);
232 static void tfp410_get_timings(struct omap_dss_device *dssdev,
233 struct omap_video_timings *timings)
235 struct panel_drv_data *ddata = dev_get_drvdata(&dssdev->dev);
237 mutex_lock(&ddata->lock);
238 *timings = dssdev->panel.timings;
239 mutex_unlock(&ddata->lock);
242 static int tfp410_check_timings(struct omap_dss_device *dssdev,
243 struct omap_video_timings *timings)
245 struct panel_drv_data *ddata = dev_get_drvdata(&dssdev->dev);
248 mutex_lock(&ddata->lock);
249 r = dpi_check_timings(dssdev, timings);
250 mutex_unlock(&ddata->lock);
256 static int tfp410_ddc_read(struct i2c_adapter *adapter,
257 unsigned char *buf, u16 count, u8 offset)
261 for (retries = 3; retries > 0; retries--) {
262 struct i2c_msg msgs[] = {
276 r = i2c_transfer(adapter, msgs, 2);
284 return r < 0 ? r : -EIO;
287 static int tfp410_read_edid(struct omap_dss_device *dssdev,
290 struct panel_drv_data *ddata = dev_get_drvdata(&dssdev->dev);
291 int r, l, bytes_read;
293 mutex_lock(&ddata->lock);
295 if (!ddata->i2c_adapter) {
300 l = min(EDID_LENGTH, len);
301 r = tfp410_ddc_read(ddata->i2c_adapter, edid, l, 0);
307 /* if there are extensions, read second block */
308 if (len > EDID_LENGTH && edid[0x7e] > 0) {
309 l = min(EDID_LENGTH, len - EDID_LENGTH);
311 r = tfp410_ddc_read(ddata->i2c_adapter, edid + EDID_LENGTH,
319 mutex_unlock(&ddata->lock);
324 mutex_unlock(&ddata->lock);
328 static bool tfp410_detect(struct omap_dss_device *dssdev)
330 struct panel_drv_data *ddata = dev_get_drvdata(&dssdev->dev);
334 mutex_lock(&ddata->lock);
336 if (!ddata->i2c_adapter)
339 r = tfp410_ddc_read(ddata->i2c_adapter, &out, 1, 0);
341 mutex_unlock(&ddata->lock);
346 mutex_unlock(&ddata->lock);
350 static struct omap_dss_driver tfp410_driver = {
351 .probe = tfp410_probe,
352 .remove = __exit_p(tfp410_remove),
354 .enable = tfp410_enable,
355 .disable = tfp410_disable,
356 .suspend = tfp410_suspend,
357 .resume = tfp410_resume,
359 .set_timings = tfp410_set_timings,
360 .get_timings = tfp410_get_timings,
361 .check_timings = tfp410_check_timings,
363 .read_edid = tfp410_read_edid,
364 .detect = tfp410_detect,
368 .owner = THIS_MODULE,
372 static int __init tfp410_init(void)
374 return omap_dss_register_driver(&tfp410_driver);
377 static void __exit tfp410_exit(void)
379 omap_dss_unregister_driver(&tfp410_driver);
382 module_init(tfp410_init);
383 module_exit(tfp410_exit);
384 MODULE_LICENSE("GPL");