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;
98 dssdev->panel.config = OMAP_DSS_LCD_TFT;
100 ddata->dssdev = dssdev;
101 mutex_init(&ddata->lock);
104 struct tfp410_platform_data *pdata = dssdev->data;
106 ddata->pd_gpio = pdata->power_down_gpio;
107 i2c_bus_num = pdata->i2c_bus_num;
113 if (gpio_is_valid(ddata->pd_gpio)) {
114 r = gpio_request_one(ddata->pd_gpio, GPIOF_OUT_INIT_LOW,
117 dev_err(&dssdev->dev, "Failed to request PD GPIO %d\n",
123 if (i2c_bus_num != -1) {
124 struct i2c_adapter *adapter;
126 adapter = i2c_get_adapter(i2c_bus_num);
128 dev_err(&dssdev->dev, "Failed to get I2C adapter, bus %d\n",
134 ddata->i2c_adapter = adapter;
137 dev_set_drvdata(&dssdev->dev, ddata);
141 if (gpio_is_valid(ddata->pd_gpio))
142 gpio_free(ddata->pd_gpio);
146 static void __exit tfp410_remove(struct omap_dss_device *dssdev)
148 struct panel_drv_data *ddata = dev_get_drvdata(&dssdev->dev);
150 mutex_lock(&ddata->lock);
152 if (ddata->i2c_adapter)
153 i2c_put_adapter(ddata->i2c_adapter);
155 if (gpio_is_valid(ddata->pd_gpio))
156 gpio_free(ddata->pd_gpio);
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 int tfp410_suspend(struct omap_dss_device *dssdev)
194 struct panel_drv_data *ddata = dev_get_drvdata(&dssdev->dev);
196 mutex_lock(&ddata->lock);
198 tfp410_power_off(dssdev);
200 dssdev->state = OMAP_DSS_DISPLAY_SUSPENDED;
202 mutex_unlock(&ddata->lock);
207 static int tfp410_resume(struct omap_dss_device *dssdev)
209 struct panel_drv_data *ddata = dev_get_drvdata(&dssdev->dev);
212 mutex_lock(&ddata->lock);
214 r = tfp410_power_on(dssdev);
216 dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
218 mutex_unlock(&ddata->lock);
223 static void tfp410_set_timings(struct omap_dss_device *dssdev,
224 struct omap_video_timings *timings)
226 struct panel_drv_data *ddata = dev_get_drvdata(&dssdev->dev);
228 mutex_lock(&ddata->lock);
229 dpi_set_timings(dssdev, timings);
230 mutex_unlock(&ddata->lock);
233 static void tfp410_get_timings(struct omap_dss_device *dssdev,
234 struct omap_video_timings *timings)
236 struct panel_drv_data *ddata = dev_get_drvdata(&dssdev->dev);
238 mutex_lock(&ddata->lock);
239 *timings = dssdev->panel.timings;
240 mutex_unlock(&ddata->lock);
243 static int tfp410_check_timings(struct omap_dss_device *dssdev,
244 struct omap_video_timings *timings)
246 struct panel_drv_data *ddata = dev_get_drvdata(&dssdev->dev);
249 mutex_lock(&ddata->lock);
250 r = dpi_check_timings(dssdev, timings);
251 mutex_unlock(&ddata->lock);
257 static int tfp410_ddc_read(struct i2c_adapter *adapter,
258 unsigned char *buf, u16 count, u8 offset)
262 for (retries = 3; retries > 0; retries--) {
263 struct i2c_msg msgs[] = {
277 r = i2c_transfer(adapter, msgs, 2);
285 return r < 0 ? r : -EIO;
288 static int tfp410_read_edid(struct omap_dss_device *dssdev,
291 struct panel_drv_data *ddata = dev_get_drvdata(&dssdev->dev);
292 int r, l, bytes_read;
294 mutex_lock(&ddata->lock);
296 if (!ddata->i2c_adapter) {
301 l = min(EDID_LENGTH, len);
302 r = tfp410_ddc_read(ddata->i2c_adapter, edid, l, 0);
308 /* if there are extensions, read second block */
309 if (len > EDID_LENGTH && edid[0x7e] > 0) {
310 l = min(EDID_LENGTH, len - EDID_LENGTH);
312 r = tfp410_ddc_read(ddata->i2c_adapter, edid + EDID_LENGTH,
320 mutex_unlock(&ddata->lock);
325 mutex_unlock(&ddata->lock);
329 static bool tfp410_detect(struct omap_dss_device *dssdev)
331 struct panel_drv_data *ddata = dev_get_drvdata(&dssdev->dev);
335 mutex_lock(&ddata->lock);
337 if (!ddata->i2c_adapter)
340 r = tfp410_ddc_read(ddata->i2c_adapter, &out, 1, 0);
342 mutex_unlock(&ddata->lock);
347 mutex_unlock(&ddata->lock);
351 static struct omap_dss_driver tfp410_driver = {
352 .probe = tfp410_probe,
353 .remove = __exit_p(tfp410_remove),
355 .enable = tfp410_enable,
356 .disable = tfp410_disable,
357 .suspend = tfp410_suspend,
358 .resume = tfp410_resume,
360 .set_timings = tfp410_set_timings,
361 .get_timings = tfp410_get_timings,
362 .check_timings = tfp410_check_timings,
364 .read_edid = tfp410_read_edid,
365 .detect = tfp410_detect,
369 .owner = THIS_MODULE,
373 static int __init tfp410_init(void)
375 return omap_dss_register_driver(&tfp410_driver);
378 static void __exit tfp410_exit(void)
380 omap_dss_unregister_driver(&tfp410_driver);
383 module_init(tfp410_init);
384 module_exit(tfp410_exit);
385 MODULE_LICENSE("GPL");