fbdev/media: Use GPIO descriptors for VIA GPIO
Commit Message
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>
---
I don't know about the merge path for this one, let's merge
it in the provider (fbdev) if possible.
This looks like OLPC stuff.
---
drivers/media/platform/via/via-camera.c | 51 ++++++++-----------
drivers/video/fbdev/via/via-core.c | 2 +-
drivers/video/fbdev/via/via-gpio.c | 26 +++++-----
.../video/fbdev/via}/via-gpio.h | 1 -
4 files changed, 34 insertions(+), 46 deletions(-)
rename {include/linux => drivers/video/fbdev/via}/via-gpio.h (84%)
Comments
Hi Linus,
kernel test robot noticed the following build errors:
[auto build test ERROR on media-tree/master]
[also build test ERROR on linus/master v6.4-rc6 next-20230609]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Linus-Walleij/fbdev-media-Use-GPIO-descriptors-for-VIA-GPIO/20230612-214746
base: git://linuxtv.org/media_tree.git master
patch link: https://lore.kernel.org/r/20230612134500.249178-1-linus.walleij%40linaro.org
patch subject: [PATCH] fbdev/media: Use GPIO descriptors for VIA GPIO
config: i386-randconfig-r034-20230612 (https://download.01.org/0day-ci/archive/20230613/202306130650.BS2fQAUp-lkp@intel.com/config)
compiler: clang version 15.0.7 (https://github.com/llvm/llvm-project.git 8dfdcc7b7bf66834a761bd8de445840ef68e4d1a)
reproduce (this is a W=1 build):
mkdir -p ~/bin
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
git remote add media-tree git://linuxtv.org/media_tree.git
git fetch media-tree master
git checkout media-tree/master
b4 shazam https://lore.kernel.org/r/20230612134500.249178-1-linus.walleij@linaro.org
# save the config file
mkdir build_dir && cp config build_dir/.config
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang ~/bin/make.cross W=1 O=build_dir ARCH=i386 olddefconfig
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang ~/bin/make.cross W=1 O=build_dir ARCH=i386 SHELL=/bin/bash
If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202306130650.BS2fQAUp-lkp@intel.com/
All errors (new ones prefixed by >>):
>> drivers/video/fbdev/via/via-gpio.c:13:10: fatal error: 'linux/via-gpio.h' file not found
#include <linux/via-gpio.h>
^~~~~~~~~~~~~~~~~~
1 error generated.
vim +13 drivers/video/fbdev/via/via-gpio.c
ec66841e495b9a drivers/video/via/via-gpio.c Jonathan Corbet 2010-05-05 @13 #include <linux/via-gpio.h>
a8a359318530a7 drivers/video/via/via-gpio.c Paul Gortmaker 2011-07-10 14 #include <linux/export.h>
7e0de022680f78 drivers/video/via/via-gpio.c Jonathan Corbet 2009-12-01 15
Hi Linus,
kernel test robot noticed the following build errors:
[auto build test ERROR on media-tree/master]
[also build test ERROR on linus/master v6.4-rc6 next-20230609]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Linus-Walleij/fbdev-media-Use-GPIO-descriptors-for-VIA-GPIO/20230612-214746
base: git://linuxtv.org/media_tree.git master
patch link: https://lore.kernel.org/r/20230612134500.249178-1-linus.walleij%40linaro.org
patch subject: [PATCH] fbdev/media: Use GPIO descriptors for VIA GPIO
config: i386-allyesconfig (https://download.01.org/0day-ci/archive/20230613/202306130745.DRBLkZcT-lkp@intel.com/config)
compiler: gcc-12 (Debian 12.2.0-14) 12.2.0
reproduce (this is a W=1 build):
git remote add media-tree git://linuxtv.org/media_tree.git
git fetch media-tree master
git checkout media-tree/master
b4 shazam https://lore.kernel.org/r/20230612134500.249178-1-linus.walleij@linaro.org
# save the config file
mkdir build_dir && cp config build_dir/.config
make W=1 O=build_dir ARCH=i386 olddefconfig
make W=1 O=build_dir ARCH=i386 SHELL=/bin/bash
If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202306130745.DRBLkZcT-lkp@intel.com/
All errors (new ones prefixed by >>):
>> drivers/video/fbdev/via/via-gpio.c:13:10: fatal error: linux/via-gpio.h: No such file or directory
13 | #include <linux/via-gpio.h>
| ^~~~~~~~~~~~~~~~~~
compilation terminated.
vim +13 drivers/video/fbdev/via/via-gpio.c
ec66841e495b9a drivers/video/via/via-gpio.c Jonathan Corbet 2010-05-05 @13 #include <linux/via-gpio.h>
a8a359318530a7 drivers/video/via/via-gpio.c Paul Gortmaker 2011-07-10 14 #include <linux/export.h>
7e0de022680f78 drivers/video/via/via-gpio.c Jonathan Corbet 2009-12-01 15
@@ -11,7 +11,7 @@
#include <linux/device.h>
#include <linux/list.h>
#include <linux/pci.h>
-#include <linux/gpio.h>
+#include <linux/gpio/consumer.h>
#include <linux/interrupt.h>
#include <linux/platform_device.h>
#include <linux/videodev2.h>
@@ -26,7 +26,6 @@
#include <linux/dma-mapping.h>
#include <linux/pm_qos.h>
#include <linux/via-core.h>
-#include <linux/via-gpio.h>
#include <linux/via_i2c.h>
#ifdef CONFIG_X86
@@ -71,8 +70,8 @@ struct via_camera {
/*
* GPIO info for power/reset management
*/
- int power_gpio;
- int reset_gpio;
+ struct gpio_desc *power_gpio;
+ struct gpio_desc *reset_gpio;
/*
* I/O memory stuff.
*/
@@ -180,27 +179,19 @@ static struct via_format *via_find_format(u32 pixelformat)
*/
static int via_sensor_power_setup(struct via_camera *cam)
{
- int ret;
+ struct device *dev = &cam->platdev->dev;
+
+ cam->power_gpio = devm_gpiod_get(dev, "VGPIO3", GPIOD_OUT_LOW);
+ if (IS_ERR(cam->power_gpio))
+ return dev_err_probe(dev, PTR_ERR(cam->power_gpio),
+ "failed to get power GPIO");
+
+ /* Request the reset line asserted */
+ cam->reset_gpio = devm_gpiod_get(dev, "VGPIO2", GPIOD_OUT_HIGH);
+ if (IS_ERR(cam->reset_gpio))
+ return dev_err_probe(dev, PTR_ERR(cam->reset_gpio),
+ "failed to get reset GPIO");
- cam->power_gpio = viafb_gpio_lookup("VGPIO3");
- cam->reset_gpio = viafb_gpio_lookup("VGPIO2");
- if (!gpio_is_valid(cam->power_gpio) || !gpio_is_valid(cam->reset_gpio)) {
- dev_err(&cam->platdev->dev, "Unable to find GPIO lines\n");
- return -EINVAL;
- }
- ret = gpio_request(cam->power_gpio, "viafb-camera");
- if (ret) {
- dev_err(&cam->platdev->dev, "Unable to request power GPIO\n");
- return ret;
- }
- ret = gpio_request(cam->reset_gpio, "viafb-camera");
- if (ret) {
- dev_err(&cam->platdev->dev, "Unable to request reset GPIO\n");
- gpio_free(cam->power_gpio);
- return ret;
- }
- gpio_direction_output(cam->power_gpio, 0);
- gpio_direction_output(cam->reset_gpio, 0);
return 0;
}
@@ -209,25 +200,23 @@ static int via_sensor_power_setup(struct via_camera *cam)
*/
static void via_sensor_power_up(struct via_camera *cam)
{
- gpio_set_value(cam->power_gpio, 1);
- gpio_set_value(cam->reset_gpio, 0);
+ gpiod_set_value(cam->power_gpio, 1);
+ gpiod_set_value(cam->reset_gpio, 1);
msleep(20); /* Probably excessive */
- gpio_set_value(cam->reset_gpio, 1);
+ gpiod_set_value(cam->reset_gpio, 0);
msleep(20);
}
static void via_sensor_power_down(struct via_camera *cam)
{
- gpio_set_value(cam->power_gpio, 0);
- gpio_set_value(cam->reset_gpio, 0);
+ gpiod_set_value(cam->power_gpio, 0);
+ gpiod_set_value(cam->reset_gpio, 1);
}
static void via_sensor_power_release(struct via_camera *cam)
{
via_sensor_power_down(cam);
- gpio_free(cam->power_gpio);
- gpio_free(cam->reset_gpio);
}
/* --------------------------------------------------------------------------*/
@@ -11,7 +11,7 @@
#include <linux/aperture.h>
#include <linux/via-core.h>
#include <linux/via_i2c.h>
-#include <linux/via-gpio.h>
+#include "via-gpio.h"
#include "global.h"
#include <linux/module.h>
@@ -7,6 +7,7 @@
#include <linux/spinlock.h>
#include <linux/gpio/driver.h>
+#include <linux/gpio/machine.h>
#include <linux/platform_device.h>
#include <linux/via-core.h>
#include <linux/via-gpio.h>
@@ -189,19 +190,14 @@ static struct viafb_pm_hooks viafb_gpio_pm_hooks = {
};
#endif /* CONFIG_PM */
-/*
- * Look up a specific gpio and return the number it was assigned.
- */
-int viafb_gpio_lookup(const char *name)
-{
- int i;
-
- for (i = 0; i < viafb_gpio_config.gpio_chip.ngpio; i++)
- if (!strcmp(name, viafb_gpio_config.active_gpios[i]->vg_name))
- return viafb_gpio_config.gpio_chip.base + i;
- return -1;
-}
-EXPORT_SYMBOL_GPL(viafb_gpio_lookup);
+static struct gpiod_lookup_table viafb_gpio_table = {
+ .dev_id = "viafb-camera",
+ .table = {
+ GPIO_LOOKUP("via-gpio", 2, "VGPIO2", GPIO_ACTIVE_LOW),
+ GPIO_LOOKUP("via-gpio", 3, "VGPIO3", GPIO_ACTIVE_HIGH),
+ { }
+ },
+};
/*
* Platform device stuff.
@@ -249,12 +245,16 @@ static int viafb_gpio_probe(struct platform_device *platdev)
* Get registered.
*/
viafb_gpio_config.gpio_chip.base = -1; /* Dynamic */
+ viafb_gpio_config.gpio_chip.label = "via-gpio";
ret = gpiochip_add_data(&viafb_gpio_config.gpio_chip,
&viafb_gpio_config);
if (ret) {
printk(KERN_ERR "viafb: failed to add gpios (%d)\n", ret);
viafb_gpio_config.gpio_chip.ngpio = 0;
}
+
+ gpiod_add_lookup_table(&viafb_gpio_table);
+
#ifdef CONFIG_PM
viafb_pm_register(&viafb_gpio_pm_hooks);
#endif
similarity index 84%
rename from include/linux/via-gpio.h
rename to drivers/video/fbdev/via/via-gpio.h
@@ -8,7 +8,6 @@
#ifndef __VIA_GPIO_H__
#define __VIA_GPIO_H__
-extern int viafb_gpio_lookup(const char *name);
extern int viafb_gpio_init(void);
extern void viafb_gpio_exit(void);
#endif