diff options
author | Tomi Valkeinen <tomi.valkeinen@ti.com> | 2012-02-17 05:19:48 -0500 |
---|---|---|
committer | Tomi Valkeinen <tomi.valkeinen@ti.com> | 2012-05-11 07:44:50 -0400 |
commit | 958f2717b84e88bf833d996997fda8f73276f2af (patch) | |
tree | 6a6a6af4d4c323530024aa5e6e4f38e7425da05c /drivers | |
parent | 3a028bb99d1f1e5c444060a176cbd4bf93530df3 (diff) |
OMAPDSS: TFP410: pdata rewrite
To ease device tree adaptation in the future, rewrite TFP410 platform
data handling to be done inside probe(), so that probe() is the only
place where we need to handle the DT/pdata choice.
Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ti.com>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/video/omap2/displays/panel-tfp410.c | 72 |
1 files changed, 38 insertions, 34 deletions
diff --git a/drivers/video/omap2/displays/panel-tfp410.c b/drivers/video/omap2/displays/panel-tfp410.c index 52637fa8fda8..f03964e5b6ab 100644 --- a/drivers/video/omap2/displays/panel-tfp410.c +++ b/drivers/video/omap2/displays/panel-tfp410.c | |||
@@ -47,13 +47,9 @@ struct panel_drv_data { | |||
47 | struct mutex lock; | 47 | struct mutex lock; |
48 | 48 | ||
49 | int pd_gpio; | 49 | int pd_gpio; |
50 | }; | ||
51 | 50 | ||
52 | static inline struct tfp410_platform_data | 51 | struct i2c_adapter *i2c_adapter; |
53 | *get_pdata(const struct omap_dss_device *dssdev) | 52 | }; |
54 | { | ||
55 | return dssdev->data; | ||
56 | } | ||
57 | 53 | ||
58 | static int tfp410_power_on(struct omap_dss_device *dssdev) | 54 | static int tfp410_power_on(struct omap_dss_device *dssdev) |
59 | { | 55 | { |
@@ -90,11 +86,11 @@ static void tfp410_power_off(struct omap_dss_device *dssdev) | |||
90 | 86 | ||
91 | static int tfp410_probe(struct omap_dss_device *dssdev) | 87 | static int tfp410_probe(struct omap_dss_device *dssdev) |
92 | { | 88 | { |
93 | struct tfp410_platform_data *pdata = get_pdata(dssdev); | ||
94 | struct panel_drv_data *ddata; | 89 | struct panel_drv_data *ddata; |
95 | int r; | 90 | int r; |
91 | int i2c_bus_num; | ||
96 | 92 | ||
97 | ddata = kzalloc(sizeof(*ddata), GFP_KERNEL); | 93 | ddata = devm_kzalloc(&dssdev->dev, sizeof(*ddata), GFP_KERNEL); |
98 | if (!ddata) | 94 | if (!ddata) |
99 | return -ENOMEM; | 95 | return -ENOMEM; |
100 | 96 | ||
@@ -104,10 +100,15 @@ static int tfp410_probe(struct omap_dss_device *dssdev) | |||
104 | ddata->dssdev = dssdev; | 100 | ddata->dssdev = dssdev; |
105 | mutex_init(&ddata->lock); | 101 | mutex_init(&ddata->lock); |
106 | 102 | ||
107 | if (pdata) | 103 | if (dssdev->data) { |
104 | struct tfp410_platform_data *pdata = dssdev->data; | ||
105 | |||
108 | ddata->pd_gpio = pdata->power_down_gpio; | 106 | ddata->pd_gpio = pdata->power_down_gpio; |
109 | else | 107 | i2c_bus_num = pdata->i2c_bus_num; |
108 | } else { | ||
110 | ddata->pd_gpio = -1; | 109 | ddata->pd_gpio = -1; |
110 | i2c_bus_num = -1; | ||
111 | } | ||
111 | 112 | ||
112 | if (gpio_is_valid(ddata->pd_gpio)) { | 113 | if (gpio_is_valid(ddata->pd_gpio)) { |
113 | r = gpio_request_one(ddata->pd_gpio, GPIOF_OUT_INIT_LOW, | 114 | r = gpio_request_one(ddata->pd_gpio, GPIOF_OUT_INIT_LOW, |
@@ -115,13 +116,31 @@ static int tfp410_probe(struct omap_dss_device *dssdev) | |||
115 | if (r) { | 116 | if (r) { |
116 | dev_err(&dssdev->dev, "Failed to request PD GPIO %d\n", | 117 | dev_err(&dssdev->dev, "Failed to request PD GPIO %d\n", |
117 | ddata->pd_gpio); | 118 | ddata->pd_gpio); |
118 | ddata->pd_gpio = -1; | 119 | return r; |
119 | } | 120 | } |
120 | } | 121 | } |
121 | 122 | ||
123 | if (i2c_bus_num != -1) { | ||
124 | struct i2c_adapter *adapter; | ||
125 | |||
126 | adapter = i2c_get_adapter(i2c_bus_num); | ||
127 | if (!adapter) { | ||
128 | dev_err(&dssdev->dev, "Failed to get I2C adapter, bus %d\n", | ||
129 | i2c_bus_num); | ||
130 | r = -EINVAL; | ||
131 | goto err_i2c; | ||
132 | } | ||
133 | |||
134 | ddata->i2c_adapter = adapter; | ||
135 | } | ||
136 | |||
122 | dev_set_drvdata(&dssdev->dev, ddata); | 137 | dev_set_drvdata(&dssdev->dev, ddata); |
123 | 138 | ||
124 | return 0; | 139 | return 0; |
140 | err_i2c: | ||
141 | if (gpio_is_valid(ddata->pd_gpio)) | ||
142 | gpio_free(ddata->pd_gpio); | ||
143 | return r; | ||
125 | } | 144 | } |
126 | 145 | ||
127 | static void __exit tfp410_remove(struct omap_dss_device *dssdev) | 146 | static void __exit tfp410_remove(struct omap_dss_device *dssdev) |
@@ -130,14 +149,15 @@ static void __exit tfp410_remove(struct omap_dss_device *dssdev) | |||
130 | 149 | ||
131 | mutex_lock(&ddata->lock); | 150 | mutex_lock(&ddata->lock); |
132 | 151 | ||
152 | if (ddata->i2c_adapter) | ||
153 | i2c_put_adapter(ddata->i2c_adapter); | ||
154 | |||
133 | if (gpio_is_valid(ddata->pd_gpio)) | 155 | if (gpio_is_valid(ddata->pd_gpio)) |
134 | gpio_free(ddata->pd_gpio); | 156 | gpio_free(ddata->pd_gpio); |
135 | 157 | ||
136 | dev_set_drvdata(&dssdev->dev, NULL); | 158 | dev_set_drvdata(&dssdev->dev, NULL); |
137 | 159 | ||
138 | mutex_unlock(&ddata->lock); | 160 | mutex_unlock(&ddata->lock); |
139 | |||
140 | kfree(ddata); | ||
141 | } | 161 | } |
142 | 162 | ||
143 | static int tfp410_enable(struct omap_dss_device *dssdev) | 163 | static int tfp410_enable(struct omap_dss_device *dssdev) |
@@ -269,27 +289,17 @@ static int tfp410_read_edid(struct omap_dss_device *dssdev, | |||
269 | u8 *edid, int len) | 289 | u8 *edid, int len) |
270 | { | 290 | { |
271 | struct panel_drv_data *ddata = dev_get_drvdata(&dssdev->dev); | 291 | 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; | 292 | int r, l, bytes_read; |
275 | 293 | ||
276 | mutex_lock(&ddata->lock); | 294 | mutex_lock(&ddata->lock); |
277 | 295 | ||
278 | if (pdata->i2c_bus_num == 0) { | 296 | if (!ddata->i2c_adapter) { |
279 | r = -ENODEV; | 297 | r = -ENODEV; |
280 | goto err; | 298 | goto err; |
281 | } | 299 | } |
282 | 300 | ||
283 | adapter = i2c_get_adapter(pdata->i2c_bus_num); | ||
284 | if (!adapter) { | ||
285 | dev_err(&dssdev->dev, "Failed to get I2C adapter, bus %d\n", | ||
286 | pdata->i2c_bus_num); | ||
287 | r = -EINVAL; | ||
288 | goto err; | ||
289 | } | ||
290 | |||
291 | l = min(EDID_LENGTH, len); | 301 | l = min(EDID_LENGTH, len); |
292 | r = tfp410_ddc_read(adapter, edid, l, 0); | 302 | r = tfp410_ddc_read(ddata->i2c_adapter, edid, l, 0); |
293 | if (r) | 303 | if (r) |
294 | goto err; | 304 | goto err; |
295 | 305 | ||
@@ -299,7 +309,7 @@ static int tfp410_read_edid(struct omap_dss_device *dssdev, | |||
299 | if (len > EDID_LENGTH && edid[0x7e] > 0) { | 309 | if (len > EDID_LENGTH && edid[0x7e] > 0) { |
300 | l = min(EDID_LENGTH, len - EDID_LENGTH); | 310 | l = min(EDID_LENGTH, len - EDID_LENGTH); |
301 | 311 | ||
302 | r = tfp410_ddc_read(adapter, edid + EDID_LENGTH, | 312 | r = tfp410_ddc_read(ddata->i2c_adapter, edid + EDID_LENGTH, |
303 | l, EDID_LENGTH); | 313 | l, EDID_LENGTH); |
304 | if (r) | 314 | if (r) |
305 | goto err; | 315 | goto err; |
@@ -319,21 +329,15 @@ err: | |||
319 | static bool tfp410_detect(struct omap_dss_device *dssdev) | 329 | static bool tfp410_detect(struct omap_dss_device *dssdev) |
320 | { | 330 | { |
321 | struct panel_drv_data *ddata = dev_get_drvdata(&dssdev->dev); | 331 | struct panel_drv_data *ddata = dev_get_drvdata(&dssdev->dev); |
322 | struct tfp410_platform_data *pdata = get_pdata(dssdev); | ||
323 | struct i2c_adapter *adapter; | ||
324 | unsigned char out; | 332 | unsigned char out; |
325 | int r; | 333 | int r; |
326 | 334 | ||
327 | mutex_lock(&ddata->lock); | 335 | mutex_lock(&ddata->lock); |
328 | 336 | ||
329 | if (pdata->i2c_bus_num == 0) | 337 | if (!ddata->i2c_adapter) |
330 | goto out; | ||
331 | |||
332 | adapter = i2c_get_adapter(pdata->i2c_bus_num); | ||
333 | if (!adapter) | ||
334 | goto out; | 338 | goto out; |
335 | 339 | ||
336 | r = tfp410_ddc_read(adapter, &out, 1, 0); | 340 | r = tfp410_ddc_read(ddata->i2c_adapter, &out, 1, 0); |
337 | 341 | ||
338 | mutex_unlock(&ddata->lock); | 342 | mutex_unlock(&ddata->lock); |
339 | 343 | ||