Skip to content

Commit d4313a6

Browse files
linuswhdeller
authored andcommitted
fbdev/media: Use GPIO descriptors for VIA GPIO
The VIA fbdev exposes a custom GPIO chip for its GPIOs, these are in turn looked up the camera driver using a custom API. Drop the custom API, provide a look-up table and convert to GPIO descriptors. Note proper polarity on the RESET line. Cc: Jonathan Corbet <[email protected]> Signed-off-by: Linus Walleij <[email protected]> Signed-off-by: Helge Deller <[email protected]>
1 parent 568c69a commit d4313a6

File tree

4 files changed

+35
-47
lines changed

4 files changed

+35
-47
lines changed

drivers/media/platform/via/via-camera.c

Lines changed: 20 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#include <linux/device.h>
1212
#include <linux/list.h>
1313
#include <linux/pci.h>
14-
#include <linux/gpio.h>
14+
#include <linux/gpio/consumer.h>
1515
#include <linux/interrupt.h>
1616
#include <linux/platform_device.h>
1717
#include <linux/videodev2.h>
@@ -26,7 +26,6 @@
2626
#include <linux/dma-mapping.h>
2727
#include <linux/pm_qos.h>
2828
#include <linux/via-core.h>
29-
#include <linux/via-gpio.h>
3029
#include <linux/via_i2c.h>
3130

3231
#ifdef CONFIG_X86
@@ -71,8 +70,8 @@ struct via_camera {
7170
/*
7271
* GPIO info for power/reset management
7372
*/
74-
int power_gpio;
75-
int reset_gpio;
73+
struct gpio_desc *power_gpio;
74+
struct gpio_desc *reset_gpio;
7675
/*
7776
* I/O memory stuff.
7877
*/
@@ -180,27 +179,19 @@ static struct via_format *via_find_format(u32 pixelformat)
180179
*/
181180
static int via_sensor_power_setup(struct via_camera *cam)
182181
{
183-
int ret;
182+
struct device *dev = &cam->platdev->dev;
183+
184+
cam->power_gpio = devm_gpiod_get(dev, "VGPIO3", GPIOD_OUT_LOW);
185+
if (IS_ERR(cam->power_gpio))
186+
return dev_err_probe(dev, PTR_ERR(cam->power_gpio),
187+
"failed to get power GPIO");
188+
189+
/* Request the reset line asserted */
190+
cam->reset_gpio = devm_gpiod_get(dev, "VGPIO2", GPIOD_OUT_HIGH);
191+
if (IS_ERR(cam->reset_gpio))
192+
return dev_err_probe(dev, PTR_ERR(cam->reset_gpio),
193+
"failed to get reset GPIO");
184194

185-
cam->power_gpio = viafb_gpio_lookup("VGPIO3");
186-
cam->reset_gpio = viafb_gpio_lookup("VGPIO2");
187-
if (!gpio_is_valid(cam->power_gpio) || !gpio_is_valid(cam->reset_gpio)) {
188-
dev_err(&cam->platdev->dev, "Unable to find GPIO lines\n");
189-
return -EINVAL;
190-
}
191-
ret = gpio_request(cam->power_gpio, "viafb-camera");
192-
if (ret) {
193-
dev_err(&cam->platdev->dev, "Unable to request power GPIO\n");
194-
return ret;
195-
}
196-
ret = gpio_request(cam->reset_gpio, "viafb-camera");
197-
if (ret) {
198-
dev_err(&cam->platdev->dev, "Unable to request reset GPIO\n");
199-
gpio_free(cam->power_gpio);
200-
return ret;
201-
}
202-
gpio_direction_output(cam->power_gpio, 0);
203-
gpio_direction_output(cam->reset_gpio, 0);
204195
return 0;
205196
}
206197

@@ -209,25 +200,23 @@ static int via_sensor_power_setup(struct via_camera *cam)
209200
*/
210201
static void via_sensor_power_up(struct via_camera *cam)
211202
{
212-
gpio_set_value(cam->power_gpio, 1);
213-
gpio_set_value(cam->reset_gpio, 0);
203+
gpiod_set_value(cam->power_gpio, 1);
204+
gpiod_set_value(cam->reset_gpio, 1);
214205
msleep(20); /* Probably excessive */
215-
gpio_set_value(cam->reset_gpio, 1);
206+
gpiod_set_value(cam->reset_gpio, 0);
216207
msleep(20);
217208
}
218209

219210
static void via_sensor_power_down(struct via_camera *cam)
220211
{
221-
gpio_set_value(cam->power_gpio, 0);
222-
gpio_set_value(cam->reset_gpio, 0);
212+
gpiod_set_value(cam->power_gpio, 0);
213+
gpiod_set_value(cam->reset_gpio, 1);
223214
}
224215

225216

226217
static void via_sensor_power_release(struct via_camera *cam)
227218
{
228219
via_sensor_power_down(cam);
229-
gpio_free(cam->power_gpio);
230-
gpio_free(cam->reset_gpio);
231220
}
232221

233222
/* --------------------------------------------------------------------------*/

drivers/video/fbdev/via/via-core.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#include <linux/aperture.h>
1212
#include <linux/via-core.h>
1313
#include <linux/via_i2c.h>
14-
#include <linux/via-gpio.h>
14+
#include "via-gpio.h"
1515
#include "global.h"
1616

1717
#include <linux/module.h>

drivers/video/fbdev/via/via-gpio.c

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@
77

88
#include <linux/spinlock.h>
99
#include <linux/gpio/driver.h>
10+
#include <linux/gpio/machine.h>
1011
#include <linux/platform_device.h>
1112
#include <linux/via-core.h>
12-
#include <linux/via-gpio.h>
1313
#include <linux/export.h>
14+
#include "via-gpio.h"
1415

1516
/*
1617
* The ports we know about. Note that the port-25 gpios are not
@@ -189,19 +190,14 @@ static struct viafb_pm_hooks viafb_gpio_pm_hooks = {
189190
};
190191
#endif /* CONFIG_PM */
191192

192-
/*
193-
* Look up a specific gpio and return the number it was assigned.
194-
*/
195-
int viafb_gpio_lookup(const char *name)
196-
{
197-
int i;
198-
199-
for (i = 0; i < viafb_gpio_config.gpio_chip.ngpio; i++)
200-
if (!strcmp(name, viafb_gpio_config.active_gpios[i]->vg_name))
201-
return viafb_gpio_config.gpio_chip.base + i;
202-
return -1;
203-
}
204-
EXPORT_SYMBOL_GPL(viafb_gpio_lookup);
193+
static struct gpiod_lookup_table viafb_gpio_table = {
194+
.dev_id = "viafb-camera",
195+
.table = {
196+
GPIO_LOOKUP("via-gpio", 2, "VGPIO2", GPIO_ACTIVE_LOW),
197+
GPIO_LOOKUP("via-gpio", 3, "VGPIO3", GPIO_ACTIVE_HIGH),
198+
{ }
199+
},
200+
};
205201

206202
/*
207203
* Platform device stuff.
@@ -249,12 +245,16 @@ static int viafb_gpio_probe(struct platform_device *platdev)
249245
* Get registered.
250246
*/
251247
viafb_gpio_config.gpio_chip.base = -1; /* Dynamic */
248+
viafb_gpio_config.gpio_chip.label = "via-gpio";
252249
ret = gpiochip_add_data(&viafb_gpio_config.gpio_chip,
253250
&viafb_gpio_config);
254251
if (ret) {
255252
printk(KERN_ERR "viafb: failed to add gpios (%d)\n", ret);
256253
viafb_gpio_config.gpio_chip.ngpio = 0;
257254
}
255+
256+
gpiod_add_lookup_table(&viafb_gpio_table);
257+
258258
#ifdef CONFIG_PM
259259
viafb_pm_register(&viafb_gpio_pm_hooks);
260260
#endif

include/linux/via-gpio.h renamed to drivers/video/fbdev/via/via-gpio.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
#ifndef __VIA_GPIO_H__
99
#define __VIA_GPIO_H__
1010

11-
extern int viafb_gpio_lookup(const char *name);
1211
extern int viafb_gpio_init(void);
1312
extern void viafb_gpio_exit(void);
1413
#endif

0 commit comments

Comments
 (0)