Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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 <corbet@lwn.net>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Helge Deller <deller@gmx.de>

authored by

Linus Walleij and committed by
Helge Deller
d4313a68 568c69ae

+35 -47
+20 -31
drivers/media/platform/via/via-camera.c
··· 11 11 #include <linux/device.h> 12 12 #include <linux/list.h> 13 13 #include <linux/pci.h> 14 - #include <linux/gpio.h> 14 + #include <linux/gpio/consumer.h> 15 15 #include <linux/interrupt.h> 16 16 #include <linux/platform_device.h> 17 17 #include <linux/videodev2.h> ··· 26 26 #include <linux/dma-mapping.h> 27 27 #include <linux/pm_qos.h> 28 28 #include <linux/via-core.h> 29 - #include <linux/via-gpio.h> 30 29 #include <linux/via_i2c.h> 31 30 32 31 #ifdef CONFIG_X86 ··· 70 71 /* 71 72 * GPIO info for power/reset management 72 73 */ 73 - int power_gpio; 74 - int reset_gpio; 74 + struct gpio_desc *power_gpio; 75 + struct gpio_desc *reset_gpio; 75 76 /* 76 77 * I/O memory stuff. 77 78 */ ··· 179 180 */ 180 181 static int via_sensor_power_setup(struct via_camera *cam) 181 182 { 182 - int ret; 183 + struct device *dev = &cam->platdev->dev; 183 184 184 - cam->power_gpio = viafb_gpio_lookup("VGPIO3"); 185 - cam->reset_gpio = viafb_gpio_lookup("VGPIO2"); 186 - if (!gpio_is_valid(cam->power_gpio) || !gpio_is_valid(cam->reset_gpio)) { 187 - dev_err(&cam->platdev->dev, "Unable to find GPIO lines\n"); 188 - return -EINVAL; 189 - } 190 - ret = gpio_request(cam->power_gpio, "viafb-camera"); 191 - if (ret) { 192 - dev_err(&cam->platdev->dev, "Unable to request power GPIO\n"); 193 - return ret; 194 - } 195 - ret = gpio_request(cam->reset_gpio, "viafb-camera"); 196 - if (ret) { 197 - dev_err(&cam->platdev->dev, "Unable to request reset GPIO\n"); 198 - gpio_free(cam->power_gpio); 199 - return ret; 200 - } 201 - gpio_direction_output(cam->power_gpio, 0); 202 - gpio_direction_output(cam->reset_gpio, 0); 185 + cam->power_gpio = devm_gpiod_get(dev, "VGPIO3", GPIOD_OUT_LOW); 186 + if (IS_ERR(cam->power_gpio)) 187 + return dev_err_probe(dev, PTR_ERR(cam->power_gpio), 188 + "failed to get power GPIO"); 189 + 190 + /* Request the reset line asserted */ 191 + cam->reset_gpio = devm_gpiod_get(dev, "VGPIO2", GPIOD_OUT_HIGH); 192 + if (IS_ERR(cam->reset_gpio)) 193 + return dev_err_probe(dev, PTR_ERR(cam->reset_gpio), 194 + "failed to get reset GPIO"); 195 + 203 196 return 0; 204 197 } 205 198 ··· 200 209 */ 201 210 static void via_sensor_power_up(struct via_camera *cam) 202 211 { 203 - gpio_set_value(cam->power_gpio, 1); 204 - gpio_set_value(cam->reset_gpio, 0); 212 + gpiod_set_value(cam->power_gpio, 1); 213 + gpiod_set_value(cam->reset_gpio, 1); 205 214 msleep(20); /* Probably excessive */ 206 - gpio_set_value(cam->reset_gpio, 1); 215 + gpiod_set_value(cam->reset_gpio, 0); 207 216 msleep(20); 208 217 } 209 218 210 219 static void via_sensor_power_down(struct via_camera *cam) 211 220 { 212 - gpio_set_value(cam->power_gpio, 0); 213 - gpio_set_value(cam->reset_gpio, 0); 221 + gpiod_set_value(cam->power_gpio, 0); 222 + gpiod_set_value(cam->reset_gpio, 1); 214 223 } 215 224 216 225 217 226 static void via_sensor_power_release(struct via_camera *cam) 218 227 { 219 228 via_sensor_power_down(cam); 220 - gpio_free(cam->power_gpio); 221 - gpio_free(cam->reset_gpio); 222 229 } 223 230 224 231 /* --------------------------------------------------------------------------*/
+1 -1
drivers/video/fbdev/via/via-core.c
··· 11 11 #include <linux/aperture.h> 12 12 #include <linux/via-core.h> 13 13 #include <linux/via_i2c.h> 14 - #include <linux/via-gpio.h> 14 + #include "via-gpio.h" 15 15 #include "global.h" 16 16 17 17 #include <linux/module.h>
+14 -14
drivers/video/fbdev/via/via-gpio.c
··· 7 7 8 8 #include <linux/spinlock.h> 9 9 #include <linux/gpio/driver.h> 10 + #include <linux/gpio/machine.h> 10 11 #include <linux/platform_device.h> 11 12 #include <linux/via-core.h> 12 - #include <linux/via-gpio.h> 13 13 #include <linux/export.h> 14 + #include "via-gpio.h" 14 15 15 16 /* 16 17 * The ports we know about. Note that the port-25 gpios are not ··· 190 189 }; 191 190 #endif /* CONFIG_PM */ 192 191 193 - /* 194 - * Look up a specific gpio and return the number it was assigned. 195 - */ 196 - int viafb_gpio_lookup(const char *name) 197 - { 198 - int i; 199 - 200 - for (i = 0; i < viafb_gpio_config.gpio_chip.ngpio; i++) 201 - if (!strcmp(name, viafb_gpio_config.active_gpios[i]->vg_name)) 202 - return viafb_gpio_config.gpio_chip.base + i; 203 - return -1; 204 - } 205 - EXPORT_SYMBOL_GPL(viafb_gpio_lookup); 192 + static struct gpiod_lookup_table viafb_gpio_table = { 193 + .dev_id = "viafb-camera", 194 + .table = { 195 + GPIO_LOOKUP("via-gpio", 2, "VGPIO2", GPIO_ACTIVE_LOW), 196 + GPIO_LOOKUP("via-gpio", 3, "VGPIO3", GPIO_ACTIVE_HIGH), 197 + { } 198 + }, 199 + }; 206 200 207 201 /* 208 202 * Platform device stuff. ··· 245 249 * Get registered. 246 250 */ 247 251 viafb_gpio_config.gpio_chip.base = -1; /* Dynamic */ 252 + viafb_gpio_config.gpio_chip.label = "via-gpio"; 248 253 ret = gpiochip_add_data(&viafb_gpio_config.gpio_chip, 249 254 &viafb_gpio_config); 250 255 if (ret) { 251 256 printk(KERN_ERR "viafb: failed to add gpios (%d)\n", ret); 252 257 viafb_gpio_config.gpio_chip.ngpio = 0; 253 258 } 259 + 260 + gpiod_add_lookup_table(&viafb_gpio_table); 261 + 254 262 #ifdef CONFIG_PM 255 263 viafb_pm_register(&viafb_gpio_pm_hooks); 256 264 #endif
-1
include/linux/via-gpio.h drivers/video/fbdev/via/via-gpio.h
··· 8 8 #ifndef __VIA_GPIO_H__ 9 9 #define __VIA_GPIO_H__ 10 10 11 - extern int viafb_gpio_lookup(const char *name); 12 11 extern int viafb_gpio_init(void); 13 12 extern void viafb_gpio_exit(void); 14 13 #endif