* Drivers for selfmade hardware
@ 2008-06-29 19:47 Michael Buesch
2008-06-29 20:01 ` Christoph Hellwig
` (4 more replies)
0 siblings, 5 replies; 9+ messages in thread
From: Michael Buesch @ 2008-06-29 19:47 UTC (permalink / raw)
To: linux-kernel
I'm wondering what the policy is for selfmade hardware
or other hardware where only a few pieces exist. Is it desired
to get drivers for this kind of hardware merged upstream into the
mainline kernel?
I have a tiny driver that can be used to drive a modified
Brooktree 8xx based card in 24-port GPIO mode.
So the card can be used as a cheap digital PCI GPIO card.
This hardware can be built with some soldering skills, a tiny
soldering tip and a few hours of free time.
So what's the policy? Push to mainline or keep as seperate
patch?
(The following patch is not complete, but just what I have for now
to show you...)
Index: linux-2.6/drivers/gpio/Kconfig
===================================================================
--- linux-2.6.orig/drivers/gpio/Kconfig 2008-05-01 13:19:48.000000000 +0200
+++ linux-2.6/drivers/gpio/Kconfig 2008-06-29 21:19:26.000000000 +0200
@@ -61,6 +61,24 @@ config GPIO_PCF857X
This driver provides an in-kernel interface to those GPIOs using
platform-neutral GPIO calls.
+comment "PCI GPIO expanders:"
+
+config GPIO_BT8XX
+ tristate "BT8XX GPIO abuser"
+ depends on PCI && !VIDEO_BT848
+ help
+ The BT8xx frame grabber chip has 24 GPIO pins than can be abused
+ as a cheap PCI GPIO card.
+
+ This chip can be found on Miro, Hauppauge and STB TV-cards.
+
+ The card needs to be physically altered for using it as a
+ GPIO card. For more information on how to build a GPIO card
+ from a BT8xx TV card, see the following link:
+ http://bu3sch.de/btgpio.php
+
+ If unsure, say N.
+
comment "SPI GPIO expanders:"
config GPIO_MCP23S08
Index: linux-2.6/drivers/gpio/Makefile
===================================================================
--- linux-2.6.orig/drivers/gpio/Makefile 2008-05-01 13:19:48.000000000 +0200
+++ linux-2.6/drivers/gpio/Makefile 2008-06-29 17:58:05.000000000 +0200
@@ -7,3 +7,4 @@ obj-$(CONFIG_HAVE_GPIO_LIB) += gpiolib.o
obj-$(CONFIG_GPIO_MCP23S08) += mcp23s08.o
obj-$(CONFIG_GPIO_PCA953X) += pca953x.o
obj-$(CONFIG_GPIO_PCF857X) += pcf857x.o
+obj-$(CONFIG_GPIO_BT8XX) += btgpio.o
Index: linux-2.6/drivers/gpio/btgpio.c
===================================================================
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
+++ linux-2.6/drivers/gpio/btgpio.c 2008-06-29 19:21:23.000000000 +0200
@@ -0,0 +1,334 @@
+/*
+
+ bt8xx GPIO abuser
+
+ Copyright (C) 2008 Michael Buesch <mb@bu3sch.de>
+
+ Please do _only_ contact Michael Buesch with issues related to this driver.
+ All the other people listed below are not related to this driver. Their names
+ are only here, because this driver is derived from the bt848 driver.
+
+
+ Derived from the bt848 driver:
+
+ Copyright (C) 1996,97,98 Ralph Metzler
+ & Marcus Metzler
+ (c) 1999-2002 Gerd Knorr
+
+ some v4l2 code lines are taken from Justin's bttv2 driver which is
+ (c) 2000 Justin Schoeman
+
+ V4L1 removal from:
+ (c) 2005-2006 Nickolay V. Shmyrev
+
+ Fixes to be fully V4L2 compliant by
+ (c) 2006 Mauro Carvalho Chehab
+
+ Cropping and overscan support
+ Copyright (C) 2005, 2006 Michael H. Schimek
+ Sponsored by OPQ Systems AB
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+*/
+
+#include <linux/module.h>
+#include <linux/pci.h>
+#include <linux/spinlock.h>
+#include <asm/gpio.h>
+
+/* Steal the hardware definitions from the bttv driver. */
+#include "../media/video/bt8xx/bt848.h"
+
+
+struct btgpio {
+ spinlock_t lock;
+
+ void __iomem *mmio;
+ struct pci_dev *pdev;
+ struct gpio_chip gpio;
+
+#ifdef CONFIG_PM
+ u32 saved_outen;
+ u32 saved_data;
+#endif
+};
+
+#define bgwrite(dat,adr) writel((dat), bg->mmio+(adr))
+#define bgread(adr) readl(bg->mmio+(adr))
+
+
+static int btgpio_gpio_direction_input(struct gpio_chip *gpio, unsigned nr)
+{
+ struct btgpio *bg = container_of(gpio, struct btgpio, gpio);
+ unsigned long flags;
+ u32 outen, data;
+
+ spin_lock_irqsave(&bg->lock, flags);
+
+ data = bgread(BT848_GPIO_DATA);
+ data &= ~(1 << nr);
+ bgwrite(data, BT848_GPIO_DATA);
+
+ outen = bgread(BT848_GPIO_OUT_EN);
+ outen &= ~(1 << nr);
+ bgwrite(outen, BT848_GPIO_OUT_EN);
+
+ spin_unlock_irqrestore(&bg->lock, flags);
+
+ return 0;
+}
+
+static int btgpio_gpio_get(struct gpio_chip *gpio, unsigned nr)
+{
+ struct btgpio *bg = container_of(gpio, struct btgpio, gpio);
+ unsigned long flags;
+ u32 val;
+
+ spin_lock_irqsave(&bg->lock, flags);
+ val = bgread(BT848_GPIO_DATA);
+ spin_unlock_irqrestore(&bg->lock, flags);
+
+ return !!(val & (1 << nr));
+}
+
+static int btgpio_gpio_direction_output(struct gpio_chip *gpio,
+ unsigned nr, int val)
+{
+ struct btgpio *bg = container_of(gpio, struct btgpio, gpio);
+ unsigned long flags;
+ u32 outen, data;
+
+ spin_lock_irqsave(&bg->lock, flags);
+
+ data = bgread(BT848_GPIO_DATA);
+ if (val)
+ data |= (1 << nr);
+ else
+ data &= ~(1 << nr);
+ bgwrite(data, BT848_GPIO_DATA);
+
+ outen = bgread(BT848_GPIO_OUT_EN);
+ outen |= (1 << nr);
+ bgwrite(outen, BT848_GPIO_OUT_EN);
+
+ spin_unlock_irqrestore(&bg->lock, flags);
+
+ return 0;
+}
+
+static void btgpio_gpio_set(struct gpio_chip *gpio,
+ unsigned nr, int val)
+{
+ struct btgpio *bg = container_of(gpio, struct btgpio, gpio);
+ unsigned long flags;
+ u32 data;
+
+ spin_lock_irqsave(&bg->lock, flags);
+
+ data = bgread(BT848_GPIO_DATA);
+ if (val)
+ data |= (1 << nr);
+ else
+ data &= ~(1 << nr);
+ bgwrite(data, BT848_GPIO_DATA);
+
+ spin_unlock_irqrestore(&bg->lock, flags);
+}
+
+static void btgpio_gpio_setup(struct btgpio *bg)
+{
+ struct gpio_chip *c = &bg->gpio;
+
+ c->label = bg->pdev->dev.bus_id;
+ c->owner = THIS_MODULE;
+ c->direction_input = btgpio_gpio_direction_input;
+ c->get = btgpio_gpio_get;
+ c->direction_output = btgpio_gpio_direction_output;
+ c->set = btgpio_gpio_set;
+ c->dbg_show = NULL;
+ c->base = -1;
+ c->ngpio = 24;
+ c->can_sleep = 0;
+}
+
+static int btgpio_probe(struct pci_dev *dev,
+ const struct pci_device_id *pci_id)
+{
+ struct btgpio *bg;
+ int err;
+
+ bg = kzalloc(sizeof(*bg), GFP_KERNEL);
+ if (!bg)
+ return -ENOMEM;
+
+ bg->pdev = dev;
+ spin_lock_init(&bg->lock);
+
+ err = pci_enable_device(dev);
+ if (err) {
+ printk(KERN_ERR "btgpio: Can't enable device.\n");
+ goto err_freebg;
+ }
+ if (!request_mem_region(pci_resource_start(dev, 0),
+ pci_resource_len(dev, 0),
+ "btgpio")) {
+ printk(KERN_WARNING "btgpio: can't request iomem (0x%llx).\n",
+ (unsigned long long)pci_resource_start(dev, 0));
+ err = -EBUSY;
+ goto err_disable;
+ }
+ pci_set_master(dev);
+ pci_set_drvdata(dev, bg);
+
+ bg->mmio = ioremap(pci_resource_start(dev, 0), 0x1000);
+ if (!bg->mmio) {
+ printk(KERN_ERR "btgpio: ioremap() failed\n");
+ err = -EIO;
+ goto err_release_mem;
+ }
+
+ /* Disable interrupts */
+ bgwrite(0, BT848_INT_MASK);
+
+ /* gpio init */
+ bgwrite(0, BT848_GPIO_REG_INP);
+ bgwrite(0, BT848_GPIO_OUT_EN);
+
+ btgpio_gpio_setup(bg);
+ err = gpiochip_add(&bg->gpio);
+ if (err) {
+ printk(KERN_ERR "btgpio: Failed to register GPIOs\n");
+ goto err_release_mem;
+ }
+
+ printk(KERN_INFO "btgpio: Abusing BT8xx card for GPIO\n");
+
+ return 0;
+
+err_release_mem:
+ release_mem_region(pci_resource_start(dev, 0),
+ pci_resource_len(dev, 0));
+ pci_set_drvdata(dev, NULL);
+err_disable:
+ pci_disable_device(dev);
+err_freebg:
+ kfree(bg);
+
+ return err;
+}
+
+static void btgpio_remove(struct pci_dev *pdev)
+{
+ struct btgpio *bg = pci_get_drvdata(pdev);
+
+ gpiochip_remove(&bg->gpio);
+
+ bgwrite(0, BT848_INT_MASK);
+ bgwrite(~0x0, BT848_INT_STAT);
+ bgwrite(0x0, BT848_GPIO_OUT_EN);
+
+ iounmap(bg->mmio);
+ release_mem_region(pci_resource_start(pdev,0),
+ pci_resource_len(pdev,0));
+ pci_disable_device(pdev);
+
+ pci_set_drvdata(pdev, NULL);
+ kfree(bg);
+}
+
+#ifdef CONFIG_PM
+static int btgpio_suspend(struct pci_dev *pdev, pm_message_t state)
+{
+ struct btgpio *bg = pci_get_drvdata(pdev);
+ unsigned long flags;
+
+ spin_lock_irqsave(&bg->lock, flags);
+
+ bg->saved_outen = bgread(BT848_GPIO_OUT_EN);
+ bg->saved_data = bgread(BT848_GPIO_DATA);
+
+ bgwrite(0, BT848_INT_MASK);
+ bgwrite(~0x0, BT848_INT_STAT);
+ bgwrite(0x0, BT848_GPIO_OUT_EN);
+
+ spin_unlock_irqrestore(&bg->lock, flags);
+
+ pci_save_state(pdev);
+ pci_disable_device(pdev);
+ pci_set_power_state(pdev, pci_choose_state(pdev, state));
+
+ return 0;
+}
+
+static int btgpio_resume(struct pci_dev *pdev)
+{
+ struct btgpio *bg = pci_get_drvdata(pdev);
+ unsigned long flags;
+ int err;
+
+ pci_set_power_state(pdev, 0);
+ err = pci_enable_device(pdev);
+ if (err)
+ return err;
+ pci_restore_state(pdev);
+
+ spin_lock_irqsave(&bg->lock, flags);
+
+ bgwrite(0, BT848_INT_MASK);
+ bgwrite(0, BT848_GPIO_REG_INP);
+ bgwrite(bg->saved_outen, BT848_GPIO_OUT_EN);
+ bgwrite(bg->saved_data, BT848_GPIO_DATA);
+
+ spin_unlock_irqrestore(&bg->lock, flags);
+
+ return 0;
+}
+#endif /* CONFIG_PM */
+
+static struct pci_device_id btgpio_pci_tbl[] = {
+ { PCI_DEVICE(PCI_VENDOR_ID_BROOKTREE, PCI_DEVICE_ID_BT848) },
+ { PCI_DEVICE(PCI_VENDOR_ID_BROOKTREE, PCI_DEVICE_ID_BT849) },
+ { PCI_DEVICE(PCI_VENDOR_ID_BROOKTREE, PCI_DEVICE_ID_BT878) },
+ { PCI_DEVICE(PCI_VENDOR_ID_BROOKTREE, PCI_DEVICE_ID_BT879) },
+ { 0, },
+};
+MODULE_DEVICE_TABLE(pci, btgpio_pci_tbl);
+
+static struct pci_driver btgpio_pci_driver = {
+ .name = "btgpio",
+ .id_table = btgpio_pci_tbl,
+ .probe = btgpio_probe,
+ .remove = btgpio_remove,
+#ifdef CONFIG_PM
+ .suspend = btgpio_suspend,
+ .resume = btgpio_resume,
+#endif
+};
+
+static int btgpio_init(void)
+{
+ return pci_register_driver(&btgpio_pci_driver);
+}
+module_init(btgpio_init)
+
+static void btgpio_exit(void)
+{
+ pci_unregister_driver(&btgpio_pci_driver);
+}
+module_exit(btgpio_exit)
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Michael Buesch");
+MODULE_DESCRIPTION("Abuse a BT8xx framegrabber card as generic GPIO card");
--
Greetings Michael.
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Drivers for selfmade hardware
2008-06-29 19:47 Drivers for selfmade hardware Michael Buesch
@ 2008-06-29 20:01 ` Christoph Hellwig
2008-06-29 21:26 ` Alan Cox
` (3 subsequent siblings)
4 siblings, 0 replies; 9+ messages in thread
From: Christoph Hellwig @ 2008-06-29 20:01 UTC (permalink / raw)
To: Michael Buesch; +Cc: linux-kernel
On Sun, Jun 29, 2008 at 09:47:52PM +0200, Michael Buesch wrote:
> I'm wondering what the policy is for selfmade hardware
> or other hardware where only a few pieces exist. Is it desired
> to get drivers for this kind of hardware merged upstream into the
> mainline kernel?
>
> I have a tiny driver that can be used to drive a modified
> Brooktree 8xx based card in 24-port GPIO mode.
> So the card can be used as a cheap digital PCI GPIO card.
> This hardware can be built with some soldering skills, a tiny
> soldering tip and a few hours of free time.
>
> So what's the policy? Push to mainline or keep as seperate
Push to mainline as long as you have a nice enough guide on the web
somewhere describing how to build it :)
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Drivers for selfmade hardware
2008-06-29 19:47 Drivers for selfmade hardware Michael Buesch
2008-06-29 20:01 ` Christoph Hellwig
@ 2008-06-29 21:26 ` Alan Cox
2008-06-30 9:50 ` Hans J. Koch
` (2 subsequent siblings)
4 siblings, 0 replies; 9+ messages in thread
From: Alan Cox @ 2008-06-29 21:26 UTC (permalink / raw)
To: Michael Buesch; +Cc: linux-kernel
On Sun, 29 Jun 2008 21:47:52 +0200
Michael Buesch <mb@bu3sch.de> wrote:
> I'm wondering what the policy is for selfmade hardware
> or other hardware where only a few pieces exist. Is it desired
> to get drivers for this kind of hardware merged upstream into the
> mainline kernel?
>
> I have a tiny driver that can be used to drive a modified
> Brooktree 8xx based card in 24-port GPIO mode.
> So the card can be used as a cheap digital PCI GPIO card.
> This hardware can be built with some soldering skills, a tiny
> soldering tip and a few hours of free time.
>
> So what's the policy? Push to mainline or keep as seperate
> patch?
>
> (The following patch is not complete, but just what I have for now
> to show you...)
>
> Index: linux-2.6/drivers/gpio/Kconfig
> ===================================================================
> --- linux-2.6.orig/drivers/gpio/Kconfig 2008-05-01 13:19:48.000000000 +0200
> +++ linux-2.6/drivers/gpio/Kconfig 2008-06-29 21:19:26.000000000 +0200
> @@ -61,6 +61,24 @@ config GPIO_PCF857X
> This driver provides an in-kernel interface to those GPIOs using
> platform-neutral GPIO calls.
>
> +comment "PCI GPIO expanders:"
> +
> +config GPIO_BT8XX
> + tristate "BT8XX GPIO abuser"
> + depends on PCI && !VIDEO_BT848
> + help
> + The BT8xx frame grabber chip has 24 GPIO pins than can be abused
> + as a cheap PCI GPIO card.
> +
> + This chip can be found on Miro, Hauppauge and STB TV-cards.
> +
> + The card needs to be physically altered for using it as a
> + GPIO card. For more information on how to build a GPIO card
> + from a BT8xx TV card, see the following link:
> + http://bu3sch.de/btgpio.php
> +
> + If unsure, say N.
> +
> comment "SPI GPIO expanders:"
>
> config GPIO_MCP23S08
> Index: linux-2.6/drivers/gpio/Makefile
> ===================================================================
> --- linux-2.6.orig/drivers/gpio/Makefile 2008-05-01 13:19:48.000000000 +0200
> +++ linux-2.6/drivers/gpio/Makefile 2008-06-29 17:58:05.000000000 +0200
> @@ -7,3 +7,4 @@ obj-$(CONFIG_HAVE_GPIO_LIB) += gpiolib.o
> obj-$(CONFIG_GPIO_MCP23S08) += mcp23s08.o
> obj-$(CONFIG_GPIO_PCA953X) += pca953x.o
> obj-$(CONFIG_GPIO_PCF857X) += pcf857x.o
> +obj-$(CONFIG_GPIO_BT8XX) += btgpio.o
> Index: linux-2.6/drivers/gpio/btgpio.c
> ===================================================================
> --- /dev/null 1970-01-01 00:00:00.000000000 +0000
> +++ linux-2.6/drivers/gpio/btgpio.c 2008-06-29 19:21:23.000000000 +0200
> @@ -0,0 +1,334 @@
> +/*
> +
> + bt8xx GPIO abuser
> +
> + Copyright (C) 2008 Michael Buesch <mb@bu3sch.de>
> +
> + Please do _only_ contact Michael Buesch with issues related to this driver.
> + All the other people listed below are not related to this driver. Their names
> + are only here, because this driver is derived from the bt848 driver.
> +
> +
> + Derived from the bt848 driver:
> +
> + Copyright (C) 1996,97,98 Ralph Metzler
> + & Marcus Metzler
> + (c) 1999-2002 Gerd Knorr
> +
> + some v4l2 code lines are taken from Justin's bttv2 driver which is
> + (c) 2000 Justin Schoeman
> +
> + V4L1 removal from:
> + (c) 2005-2006 Nickolay V. Shmyrev
> +
> + Fixes to be fully V4L2 compliant by
> + (c) 2006 Mauro Carvalho Chehab
> +
> + Cropping and overscan support
> + Copyright (C) 2005, 2006 Michael H. Schimek
> + Sponsored by OPQ Systems AB
> +
> + This program is free software; you can redistribute it and/or modify
> + it under the terms of the GNU General Public License as published by
> + the Free Software Foundation; either version 2 of the License, or
> + (at your option) any later version.
> +
> + This program is distributed in the hope that it will be useful,
> + but WITHOUT ANY WARRANTY; without even the implied warranty of
> + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> + GNU General Public License for more details.
> +
> + You should have received a copy of the GNU General Public License
> + along with this program; if not, write to the Free Software
> + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
> +*/
> +
> +#include <linux/module.h>
> +#include <linux/pci.h>
> +#include <linux/spinlock.h>
> +#include <asm/gpio.h>
> +
> +/* Steal the hardware definitions from the bttv driver. */
> +#include "../media/video/bt8xx/bt848.h"
> +
> +
> +struct btgpio {
> + spinlock_t lock;
> +
> + void __iomem *mmio;
> + struct pci_dev *pdev;
> + struct gpio_chip gpio;
> +
> +#ifdef CONFIG_PM
> + u32 saved_outen;
> + u32 saved_data;
> +#endif
> +};
> +
> +#define bgwrite(dat,adr) writel((dat), bg->mmio+(adr))
> +#define bgread(adr) readl(bg->mmio+(adr))
> +
> +
> +static int btgpio_gpio_direction_input(struct gpio_chip *gpio, unsigned nr)
> +{
> + struct btgpio *bg = container_of(gpio, struct btgpio, gpio);
> + unsigned long flags;
> + u32 outen, data;
> +
> + spin_lock_irqsave(&bg->lock, flags);
> +
> + data = bgread(BT848_GPIO_DATA);
> + data &= ~(1 << nr);
> + bgwrite(data, BT848_GPIO_DATA);
> +
> + outen = bgread(BT848_GPIO_OUT_EN);
> + outen &= ~(1 << nr);
> + bgwrite(outen, BT848_GPIO_OUT_EN);
> +
> + spin_unlock_irqrestore(&bg->lock, flags);
> +
> + return 0;
> +}
> +
> +static int btgpio_gpio_get(struct gpio_chip *gpio, unsigned nr)
> +{
> + struct btgpio *bg = container_of(gpio, struct btgpio, gpio);
> + unsigned long flags;
> + u32 val;
> +
> + spin_lock_irqsave(&bg->lock, flags);
> + val = bgread(BT848_GPIO_DATA);
> + spin_unlock_irqrestore(&bg->lock, flags);
> +
> + return !!(val & (1 << nr));
> +}
> +
> +static int btgpio_gpio_direction_output(struct gpio_chip *gpio,
> + unsigned nr, int val)
> +{
> + struct btgpio *bg = container_of(gpio, struct btgpio, gpio);
> + unsigned long flags;
> + u32 outen, data;
> +
> + spin_lock_irqsave(&bg->lock, flags);
> +
> + data = bgread(BT848_GPIO_DATA);
> + if (val)
> + data |= (1 << nr);
> + else
> + data &= ~(1 << nr);
> + bgwrite(data, BT848_GPIO_DATA);
> +
> + outen = bgread(BT848_GPIO_OUT_EN);
> + outen |= (1 << nr);
> + bgwrite(outen, BT848_GPIO_OUT_EN);
> +
> + spin_unlock_irqrestore(&bg->lock, flags);
> +
> + return 0;
> +}
> +
> +static void btgpio_gpio_set(struct gpio_chip *gpio,
> + unsigned nr, int val)
> +{
> + struct btgpio *bg = container_of(gpio, struct btgpio, gpio);
> + unsigned long flags;
> + u32 data;
> +
> + spin_lock_irqsave(&bg->lock, flags);
> +
> + data = bgread(BT848_GPIO_DATA);
> + if (val)
> + data |= (1 << nr);
> + else
> + data &= ~(1 << nr);
> + bgwrite(data, BT848_GPIO_DATA);
> +
> + spin_unlock_irqrestore(&bg->lock, flags);
> +}
> +
> +static void btgpio_gpio_setup(struct btgpio *bg)
> +{
> + struct gpio_chip *c = &bg->gpio;
> +
> + c->label = bg->pdev->dev.bus_id;
> + c->owner = THIS_MODULE;
> + c->direction_input = btgpio_gpio_direction_input;
> + c->get = btgpio_gpio_get;
> + c->direction_output = btgpio_gpio_direction_output;
> + c->set = btgpio_gpio_set;
> + c->dbg_show = NULL;
> + c->base = -1;
> + c->ngpio = 24;
> + c->can_sleep = 0;
> +}
> +
> +static int btgpio_probe(struct pci_dev *dev,
> + const struct pci_device_id *pci_id)
> +{
> + struct btgpio *bg;
> + int err;
> +
> + bg = kzalloc(sizeof(*bg), GFP_KERNEL);
> + if (!bg)
> + return -ENOMEM;
> +
> + bg->pdev = dev;
> + spin_lock_init(&bg->lock);
> +
> + err = pci_enable_device(dev);
> + if (err) {
> + printk(KERN_ERR "btgpio: Can't enable device.\n");
> + goto err_freebg;
> + }
> + if (!request_mem_region(pci_resource_start(dev, 0),
> + pci_resource_len(dev, 0),
> + "btgpio")) {
> + printk(KERN_WARNING "btgpio: can't request iomem (0x%llx).\n",
> + (unsigned long long)pci_resource_start(dev, 0));
> + err = -EBUSY;
> + goto err_disable;
> + }
> + pci_set_master(dev);
> + pci_set_drvdata(dev, bg);
> +
> + bg->mmio = ioremap(pci_resource_start(dev, 0), 0x1000);
> + if (!bg->mmio) {
> + printk(KERN_ERR "btgpio: ioremap() failed\n");
> + err = -EIO;
> + goto err_release_mem;
> + }
> +
> + /* Disable interrupts */
> + bgwrite(0, BT848_INT_MASK);
> +
> + /* gpio init */
> + bgwrite(0, BT848_GPIO_REG_INP);
> + bgwrite(0, BT848_GPIO_OUT_EN);
> +
> + btgpio_gpio_setup(bg);
> + err = gpiochip_add(&bg->gpio);
> + if (err) {
> + printk(KERN_ERR "btgpio: Failed to register GPIOs\n");
> + goto err_release_mem;
> + }
> +
> + printk(KERN_INFO "btgpio: Abusing BT8xx card for GPIO\n");
> +
> + return 0;
> +
> +err_release_mem:
> + release_mem_region(pci_resource_start(dev, 0),
> + pci_resource_len(dev, 0));
> + pci_set_drvdata(dev, NULL);
> +err_disable:
> + pci_disable_device(dev);
> +err_freebg:
> + kfree(bg);
> +
> + return err;
> +}
> +
> +static void btgpio_remove(struct pci_dev *pdev)
> +{
> + struct btgpio *bg = pci_get_drvdata(pdev);
> +
> + gpiochip_remove(&bg->gpio);
> +
> + bgwrite(0, BT848_INT_MASK);
> + bgwrite(~0x0, BT848_INT_STAT);
> + bgwrite(0x0, BT848_GPIO_OUT_EN);
> +
> + iounmap(bg->mmio);
> + release_mem_region(pci_resource_start(pdev,0),
> + pci_resource_len(pdev,0));
> + pci_disable_device(pdev);
> +
> + pci_set_drvdata(pdev, NULL);
> + kfree(bg);
> +}
> +
> +#ifdef CONFIG_PM
> +static int btgpio_suspend(struct pci_dev *pdev, pm_message_t state)
> +{
> + struct btgpio *bg = pci_get_drvdata(pdev);
> + unsigned long flags;
> +
> + spin_lock_irqsave(&bg->lock, flags);
> +
> + bg->saved_outen = bgread(BT848_GPIO_OUT_EN);
> + bg->saved_data = bgread(BT848_GPIO_DATA);
> +
> + bgwrite(0, BT848_INT_MASK);
> + bgwrite(~0x0, BT848_INT_STAT);
> + bgwrite(0x0, BT848_GPIO_OUT_EN);
> +
> + spin_unlock_irqrestore(&bg->lock, flags);
> +
> + pci_save_state(pdev);
> + pci_disable_device(pdev);
> + pci_set_power_state(pdev, pci_choose_state(pdev, state));
> +
> + return 0;
> +}
> +
> +static int btgpio_resume(struct pci_dev *pdev)
> +{
> + struct btgpio *bg = pci_get_drvdata(pdev);
> + unsigned long flags;
> + int err;
> +
> + pci_set_power_state(pdev, 0);
> + err = pci_enable_device(pdev);
> + if (err)
> + return err;
> + pci_restore_state(pdev);
> +
> + spin_lock_irqsave(&bg->lock, flags);
> +
> + bgwrite(0, BT848_INT_MASK);
> + bgwrite(0, BT848_GPIO_REG_INP);
> + bgwrite(bg->saved_outen, BT848_GPIO_OUT_EN);
> + bgwrite(bg->saved_data, BT848_GPIO_DATA);
> +
> + spin_unlock_irqrestore(&bg->lock, flags);
> +
> + return 0;
> +}
> +#endif /* CONFIG_PM */
> +
> +static struct pci_device_id btgpio_pci_tbl[] = {
> + { PCI_DEVICE(PCI_VENDOR_ID_BROOKTREE, PCI_DEVICE_ID_BT848) },
> + { PCI_DEVICE(PCI_VENDOR_ID_BROOKTREE, PCI_DEVICE_ID_BT849) },
> + { PCI_DEVICE(PCI_VENDOR_ID_BROOKTREE, PCI_DEVICE_ID_BT878) },
> + { PCI_DEVICE(PCI_VENDOR_ID_BROOKTREE, PCI_DEVICE_ID_BT879) },
> + { 0, },
> +};
> +MODULE_DEVICE_TABLE(pci, btgpio_pci_tbl);
> +
> +static struct pci_driver btgpio_pci_driver = {
> + .name = "btgpio",
> + .id_table = btgpio_pci_tbl,
> + .probe = btgpio_probe,
> + .remove = btgpio_remove,
> +#ifdef CONFIG_PM
> + .suspend = btgpio_suspend,
> + .resume = btgpio_resume,
> +#endif
> +};
> +
> +static int btgpio_init(void)
> +{
> + return pci_register_driver(&btgpio_pci_driver);
> +}
> +module_init(btgpio_init)
> +
> +static void btgpio_exit(void)
> +{
> + pci_unregister_driver(&btgpio_pci_driver);
> +}
> +module_exit(btgpio_exit)
> +
> +MODULE_LICENSE("GPL");
> +MODULE_AUTHOR("Michael Buesch");
> +MODULE_DESCRIPTION("Abuse a BT8xx framegrabber card as generic GPIO card");
>
--
--
"Alan, I'm getting a bit worried about you."
-- Linus Torvalds
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Drivers for selfmade hardware
2008-06-29 19:47 Drivers for selfmade hardware Michael Buesch
2008-06-29 20:01 ` Christoph Hellwig
2008-06-29 21:26 ` Alan Cox
@ 2008-06-30 9:50 ` Hans J. Koch
2008-06-30 10:00 ` Michael Buesch
2008-06-30 15:37 ` Miguel Ojeda
2008-07-10 5:45 ` Andrew Morton
4 siblings, 1 reply; 9+ messages in thread
From: Hans J. Koch @ 2008-06-30 9:50 UTC (permalink / raw)
To: Michael Buesch; +Cc: linux-kernel
On Sun, Jun 29, 2008 at 09:47:52PM +0200, Michael Buesch wrote:
> I'm wondering what the policy is for selfmade hardware
> or other hardware where only a few pieces exist. Is it desired
> to get drivers for this kind of hardware merged upstream into the
> mainline kernel?
>
> I have a tiny driver that can be used to drive a modified
> Brooktree 8xx based card in 24-port GPIO mode.
> So the card can be used as a cheap digital PCI GPIO card.
> This hardware can be built with some soldering skills, a tiny
> soldering tip and a few hours of free time.
This driver is not only useful for PCI TV cards. With little
modification, it could be used for bttv chips integrated in embedded
systems as platform devices. You might have more users than you think
;-)
>
> So what's the policy? Push to mainline or keep as seperate
> patch?
Definetly mainline. But don't forget to cc: other relevant
maintainers/lists (v4l, gpio, maybe linux-embedded).
hjk
>
> (The following patch is not complete, but just what I have for now
> to show you...)
>
> Index: linux-2.6/drivers/gpio/Kconfig
> ===================================================================
> --- linux-2.6.orig/drivers/gpio/Kconfig 2008-05-01 13:19:48.000000000 +0200
> +++ linux-2.6/drivers/gpio/Kconfig 2008-06-29 21:19:26.000000000 +0200
> @@ -61,6 +61,24 @@ config GPIO_PCF857X
> This driver provides an in-kernel interface to those GPIOs using
> platform-neutral GPIO calls.
>
> +comment "PCI GPIO expanders:"
> +
> +config GPIO_BT8XX
> + tristate "BT8XX GPIO abuser"
> + depends on PCI && !VIDEO_BT848
> + help
> + The BT8xx frame grabber chip has 24 GPIO pins than can be abused
> + as a cheap PCI GPIO card.
> +
> + This chip can be found on Miro, Hauppauge and STB TV-cards.
> +
> + The card needs to be physically altered for using it as a
> + GPIO card. For more information on how to build a GPIO card
> + from a BT8xx TV card, see the following link:
> + http://bu3sch.de/btgpio.php
> +
> + If unsure, say N.
> +
> comment "SPI GPIO expanders:"
>
> config GPIO_MCP23S08
> Index: linux-2.6/drivers/gpio/Makefile
> ===================================================================
> --- linux-2.6.orig/drivers/gpio/Makefile 2008-05-01 13:19:48.000000000 +0200
> +++ linux-2.6/drivers/gpio/Makefile 2008-06-29 17:58:05.000000000 +0200
> @@ -7,3 +7,4 @@ obj-$(CONFIG_HAVE_GPIO_LIB) += gpiolib.o
> obj-$(CONFIG_GPIO_MCP23S08) += mcp23s08.o
> obj-$(CONFIG_GPIO_PCA953X) += pca953x.o
> obj-$(CONFIG_GPIO_PCF857X) += pcf857x.o
> +obj-$(CONFIG_GPIO_BT8XX) += btgpio.o
> Index: linux-2.6/drivers/gpio/btgpio.c
> ===================================================================
> --- /dev/null 1970-01-01 00:00:00.000000000 +0000
> +++ linux-2.6/drivers/gpio/btgpio.c 2008-06-29 19:21:23.000000000 +0200
> @@ -0,0 +1,334 @@
> +/*
> +
> + bt8xx GPIO abuser
> +
> + Copyright (C) 2008 Michael Buesch <mb@bu3sch.de>
> +
> + Please do _only_ contact Michael Buesch with issues related to this driver.
> + All the other people listed below are not related to this driver. Their names
> + are only here, because this driver is derived from the bt848 driver.
> +
> +
> + Derived from the bt848 driver:
> +
> + Copyright (C) 1996,97,98 Ralph Metzler
> + & Marcus Metzler
> + (c) 1999-2002 Gerd Knorr
> +
> + some v4l2 code lines are taken from Justin's bttv2 driver which is
> + (c) 2000 Justin Schoeman
> +
> + V4L1 removal from:
> + (c) 2005-2006 Nickolay V. Shmyrev
> +
> + Fixes to be fully V4L2 compliant by
> + (c) 2006 Mauro Carvalho Chehab
> +
> + Cropping and overscan support
> + Copyright (C) 2005, 2006 Michael H. Schimek
> + Sponsored by OPQ Systems AB
> +
> + This program is free software; you can redistribute it and/or modify
> + it under the terms of the GNU General Public License as published by
> + the Free Software Foundation; either version 2 of the License, or
> + (at your option) any later version.
> +
> + This program is distributed in the hope that it will be useful,
> + but WITHOUT ANY WARRANTY; without even the implied warranty of
> + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> + GNU General Public License for more details.
> +
> + You should have received a copy of the GNU General Public License
> + along with this program; if not, write to the Free Software
> + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
> +*/
> +
> +#include <linux/module.h>
> +#include <linux/pci.h>
> +#include <linux/spinlock.h>
> +#include <asm/gpio.h>
> +
> +/* Steal the hardware definitions from the bttv driver. */
> +#include "../media/video/bt8xx/bt848.h"
> +
> +
> +struct btgpio {
> + spinlock_t lock;
> +
> + void __iomem *mmio;
> + struct pci_dev *pdev;
> + struct gpio_chip gpio;
> +
> +#ifdef CONFIG_PM
> + u32 saved_outen;
> + u32 saved_data;
> +#endif
> +};
> +
> +#define bgwrite(dat,adr) writel((dat), bg->mmio+(adr))
> +#define bgread(adr) readl(bg->mmio+(adr))
> +
> +
> +static int btgpio_gpio_direction_input(struct gpio_chip *gpio, unsigned nr)
> +{
> + struct btgpio *bg = container_of(gpio, struct btgpio, gpio);
> + unsigned long flags;
> + u32 outen, data;
> +
> + spin_lock_irqsave(&bg->lock, flags);
> +
> + data = bgread(BT848_GPIO_DATA);
> + data &= ~(1 << nr);
> + bgwrite(data, BT848_GPIO_DATA);
> +
> + outen = bgread(BT848_GPIO_OUT_EN);
> + outen &= ~(1 << nr);
> + bgwrite(outen, BT848_GPIO_OUT_EN);
> +
> + spin_unlock_irqrestore(&bg->lock, flags);
> +
> + return 0;
> +}
> +
> +static int btgpio_gpio_get(struct gpio_chip *gpio, unsigned nr)
> +{
> + struct btgpio *bg = container_of(gpio, struct btgpio, gpio);
> + unsigned long flags;
> + u32 val;
> +
> + spin_lock_irqsave(&bg->lock, flags);
> + val = bgread(BT848_GPIO_DATA);
> + spin_unlock_irqrestore(&bg->lock, flags);
> +
> + return !!(val & (1 << nr));
> +}
> +
> +static int btgpio_gpio_direction_output(struct gpio_chip *gpio,
> + unsigned nr, int val)
> +{
> + struct btgpio *bg = container_of(gpio, struct btgpio, gpio);
> + unsigned long flags;
> + u32 outen, data;
> +
> + spin_lock_irqsave(&bg->lock, flags);
> +
> + data = bgread(BT848_GPIO_DATA);
> + if (val)
> + data |= (1 << nr);
> + else
> + data &= ~(1 << nr);
> + bgwrite(data, BT848_GPIO_DATA);
> +
> + outen = bgread(BT848_GPIO_OUT_EN);
> + outen |= (1 << nr);
> + bgwrite(outen, BT848_GPIO_OUT_EN);
> +
> + spin_unlock_irqrestore(&bg->lock, flags);
> +
> + return 0;
> +}
> +
> +static void btgpio_gpio_set(struct gpio_chip *gpio,
> + unsigned nr, int val)
> +{
> + struct btgpio *bg = container_of(gpio, struct btgpio, gpio);
> + unsigned long flags;
> + u32 data;
> +
> + spin_lock_irqsave(&bg->lock, flags);
> +
> + data = bgread(BT848_GPIO_DATA);
> + if (val)
> + data |= (1 << nr);
> + else
> + data &= ~(1 << nr);
> + bgwrite(data, BT848_GPIO_DATA);
> +
> + spin_unlock_irqrestore(&bg->lock, flags);
> +}
> +
> +static void btgpio_gpio_setup(struct btgpio *bg)
> +{
> + struct gpio_chip *c = &bg->gpio;
> +
> + c->label = bg->pdev->dev.bus_id;
> + c->owner = THIS_MODULE;
> + c->direction_input = btgpio_gpio_direction_input;
> + c->get = btgpio_gpio_get;
> + c->direction_output = btgpio_gpio_direction_output;
> + c->set = btgpio_gpio_set;
> + c->dbg_show = NULL;
> + c->base = -1;
> + c->ngpio = 24;
> + c->can_sleep = 0;
> +}
> +
> +static int btgpio_probe(struct pci_dev *dev,
> + const struct pci_device_id *pci_id)
> +{
> + struct btgpio *bg;
> + int err;
> +
> + bg = kzalloc(sizeof(*bg), GFP_KERNEL);
> + if (!bg)
> + return -ENOMEM;
> +
> + bg->pdev = dev;
> + spin_lock_init(&bg->lock);
> +
> + err = pci_enable_device(dev);
> + if (err) {
> + printk(KERN_ERR "btgpio: Can't enable device.\n");
> + goto err_freebg;
> + }
> + if (!request_mem_region(pci_resource_start(dev, 0),
> + pci_resource_len(dev, 0),
> + "btgpio")) {
> + printk(KERN_WARNING "btgpio: can't request iomem (0x%llx).\n",
> + (unsigned long long)pci_resource_start(dev, 0));
> + err = -EBUSY;
> + goto err_disable;
> + }
> + pci_set_master(dev);
> + pci_set_drvdata(dev, bg);
> +
> + bg->mmio = ioremap(pci_resource_start(dev, 0), 0x1000);
> + if (!bg->mmio) {
> + printk(KERN_ERR "btgpio: ioremap() failed\n");
> + err = -EIO;
> + goto err_release_mem;
> + }
> +
> + /* Disable interrupts */
> + bgwrite(0, BT848_INT_MASK);
> +
> + /* gpio init */
> + bgwrite(0, BT848_GPIO_REG_INP);
> + bgwrite(0, BT848_GPIO_OUT_EN);
> +
> + btgpio_gpio_setup(bg);
> + err = gpiochip_add(&bg->gpio);
> + if (err) {
> + printk(KERN_ERR "btgpio: Failed to register GPIOs\n");
> + goto err_release_mem;
> + }
> +
> + printk(KERN_INFO "btgpio: Abusing BT8xx card for GPIO\n");
> +
> + return 0;
> +
> +err_release_mem:
> + release_mem_region(pci_resource_start(dev, 0),
> + pci_resource_len(dev, 0));
> + pci_set_drvdata(dev, NULL);
> +err_disable:
> + pci_disable_device(dev);
> +err_freebg:
> + kfree(bg);
> +
> + return err;
> +}
> +
> +static void btgpio_remove(struct pci_dev *pdev)
> +{
> + struct btgpio *bg = pci_get_drvdata(pdev);
> +
> + gpiochip_remove(&bg->gpio);
> +
> + bgwrite(0, BT848_INT_MASK);
> + bgwrite(~0x0, BT848_INT_STAT);
> + bgwrite(0x0, BT848_GPIO_OUT_EN);
> +
> + iounmap(bg->mmio);
> + release_mem_region(pci_resource_start(pdev,0),
> + pci_resource_len(pdev,0));
> + pci_disable_device(pdev);
> +
> + pci_set_drvdata(pdev, NULL);
> + kfree(bg);
> +}
> +
> +#ifdef CONFIG_PM
> +static int btgpio_suspend(struct pci_dev *pdev, pm_message_t state)
> +{
> + struct btgpio *bg = pci_get_drvdata(pdev);
> + unsigned long flags;
> +
> + spin_lock_irqsave(&bg->lock, flags);
> +
> + bg->saved_outen = bgread(BT848_GPIO_OUT_EN);
> + bg->saved_data = bgread(BT848_GPIO_DATA);
> +
> + bgwrite(0, BT848_INT_MASK);
> + bgwrite(~0x0, BT848_INT_STAT);
> + bgwrite(0x0, BT848_GPIO_OUT_EN);
> +
> + spin_unlock_irqrestore(&bg->lock, flags);
> +
> + pci_save_state(pdev);
> + pci_disable_device(pdev);
> + pci_set_power_state(pdev, pci_choose_state(pdev, state));
> +
> + return 0;
> +}
> +
> +static int btgpio_resume(struct pci_dev *pdev)
> +{
> + struct btgpio *bg = pci_get_drvdata(pdev);
> + unsigned long flags;
> + int err;
> +
> + pci_set_power_state(pdev, 0);
> + err = pci_enable_device(pdev);
> + if (err)
> + return err;
> + pci_restore_state(pdev);
> +
> + spin_lock_irqsave(&bg->lock, flags);
> +
> + bgwrite(0, BT848_INT_MASK);
> + bgwrite(0, BT848_GPIO_REG_INP);
> + bgwrite(bg->saved_outen, BT848_GPIO_OUT_EN);
> + bgwrite(bg->saved_data, BT848_GPIO_DATA);
> +
> + spin_unlock_irqrestore(&bg->lock, flags);
> +
> + return 0;
> +}
> +#endif /* CONFIG_PM */
> +
> +static struct pci_device_id btgpio_pci_tbl[] = {
> + { PCI_DEVICE(PCI_VENDOR_ID_BROOKTREE, PCI_DEVICE_ID_BT848) },
> + { PCI_DEVICE(PCI_VENDOR_ID_BROOKTREE, PCI_DEVICE_ID_BT849) },
> + { PCI_DEVICE(PCI_VENDOR_ID_BROOKTREE, PCI_DEVICE_ID_BT878) },
> + { PCI_DEVICE(PCI_VENDOR_ID_BROOKTREE, PCI_DEVICE_ID_BT879) },
> + { 0, },
> +};
> +MODULE_DEVICE_TABLE(pci, btgpio_pci_tbl);
> +
> +static struct pci_driver btgpio_pci_driver = {
> + .name = "btgpio",
> + .id_table = btgpio_pci_tbl,
> + .probe = btgpio_probe,
> + .remove = btgpio_remove,
> +#ifdef CONFIG_PM
> + .suspend = btgpio_suspend,
> + .resume = btgpio_resume,
> +#endif
> +};
> +
> +static int btgpio_init(void)
> +{
> + return pci_register_driver(&btgpio_pci_driver);
> +}
> +module_init(btgpio_init)
> +
> +static void btgpio_exit(void)
> +{
> + pci_unregister_driver(&btgpio_pci_driver);
> +}
> +module_exit(btgpio_exit)
> +
> +MODULE_LICENSE("GPL");
> +MODULE_AUTHOR("Michael Buesch");
> +MODULE_DESCRIPTION("Abuse a BT8xx framegrabber card as generic GPIO card");
>
> --
> Greetings Michael.
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at http://www.tux.org/lkml/
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Drivers for selfmade hardware
2008-06-30 9:50 ` Hans J. Koch
@ 2008-06-30 10:00 ` Michael Buesch
0 siblings, 0 replies; 9+ messages in thread
From: Michael Buesch @ 2008-06-30 10:00 UTC (permalink / raw)
To: Hans J. Koch; +Cc: linux-kernel
On Monday 30 June 2008 11:50:15 Hans J. Koch wrote:
> This driver is not only useful for PCI TV cards. With little
> modification, it could be used for bttv chips integrated in embedded
> systems as platform devices. You might have more users than you think
> ;-)
Oh nice. I didn't know that such devices exist. However, these embedded
devices might want to use the original bttv driver and modify that for
generic GPIO support.
This btgpio driver clashes with the bttv driver and the two drivers can't be
used at the same time. That's fine for me, however, as I removed the TV tuner
and more stuff from the card. So I decided to write a stripped-down driver
instead of extending the bttv driver.
But of course, if you still use the card as TV card, we cannot use
all GPIOs for generic GPIOs, as the card uses some of them to communicate
with other chips (That's why I unsoldered the pins). So extending bttv for
generic GPIO support might become hairy with all the different boards with
possibly different GPIO assignments. I didn't want to get into that for now.
But it's nice to know that such devices do exist.
> >
> > So what's the policy? Push to mainline or keep as seperate
> > patch?
>
> Definetly mainline. But don't forget to cc: other relevant
> maintainers/lists (v4l, gpio, maybe linux-embedded).
Ok, nice.
--
Greetings Michael.
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Drivers for selfmade hardware
2008-06-29 19:47 Drivers for selfmade hardware Michael Buesch
` (2 preceding siblings ...)
2008-06-30 9:50 ` Hans J. Koch
@ 2008-06-30 15:37 ` Miguel Ojeda
2008-07-10 5:45 ` Andrew Morton
4 siblings, 0 replies; 9+ messages in thread
From: Miguel Ojeda @ 2008-06-30 15:37 UTC (permalink / raw)
To: Michael Buesch; +Cc: linux-kernel
On Sun, Jun 29, 2008 at 9:47 PM, Michael Buesch <mb@bu3sch.de> wrote:
>
> So what's the policy? Push to mainline or keep as seperate
> patch?
>
If it is simple enough, maybe you could describe the hardware (as
detailed as possible: models, schematics, ...) in a text file
somewhere at Documentation/ so there is no need to
maintain/update/change a link which could die in the future.
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Drivers for selfmade hardware
2008-06-29 19:47 Drivers for selfmade hardware Michael Buesch
` (3 preceding siblings ...)
2008-06-30 15:37 ` Miguel Ojeda
@ 2008-07-10 5:45 ` Andrew Morton
2008-07-10 12:57 ` Michael Buesch
4 siblings, 1 reply; 9+ messages in thread
From: Andrew Morton @ 2008-07-10 5:45 UTC (permalink / raw)
To: Michael Buesch; +Cc: linux-kernel
On Sun, 29 Jun 2008 21:47:52 +0200 Michael Buesch <mb@bu3sch.de> wrote:
> I'm wondering what the policy is for selfmade hardware
> or other hardware where only a few pieces exist. Is it desired
> to get drivers for this kind of hardware merged upstream into the
> mainline kernel?
>
> I have a tiny driver that can be used to drive a modified
> Brooktree 8xx based card in 24-port GPIO mode.
> So the card can be used as a cheap digital PCI GPIO card.
> This hardware can be built with some soldering skills, a tiny
> soldering tip and a few hours of free time.
>
> So what's the policy? Push to mainline or keep as seperate
> patch?
>
> (The following patch is not complete, but just what I have for now
> to show you...)
>
> ...
>
> +#ifdef CONFIG_PM
> +static int btgpio_suspend(struct pci_dev *pdev, pm_message_t state)
> +{
> + struct btgpio *bg = pci_get_drvdata(pdev);
> + unsigned long flags;
> +
> + spin_lock_irqsave(&bg->lock, flags);
> +
> + bg->saved_outen = bgread(BT848_GPIO_OUT_EN);
> + bg->saved_data = bgread(BT848_GPIO_DATA);
> +
> + bgwrite(0, BT848_INT_MASK);
> + bgwrite(~0x0, BT848_INT_STAT);
> + bgwrite(0x0, BT848_GPIO_OUT_EN);
> +
> + spin_unlock_irqrestore(&bg->lock, flags);
> +
> + pci_save_state(pdev);
> + pci_disable_device(pdev);
> + pci_set_power_state(pdev, pci_choose_state(pdev, state));
> +
> + return 0;
> +}
> +
> +static int btgpio_resume(struct pci_dev *pdev)
> +{
> + struct btgpio *bg = pci_get_drvdata(pdev);
> + unsigned long flags;
> + int err;
> +
> + pci_set_power_state(pdev, 0);
> + err = pci_enable_device(pdev);
> + if (err)
> + return err;
> + pci_restore_state(pdev);
> +
> + spin_lock_irqsave(&bg->lock, flags);
> +
> + bgwrite(0, BT848_INT_MASK);
> + bgwrite(0, BT848_GPIO_REG_INP);
> + bgwrite(bg->saved_outen, BT848_GPIO_OUT_EN);
> + bgwrite(bg->saved_data, BT848_GPIO_DATA);
> +
> + spin_unlock_irqrestore(&bg->lock, flags);
> +
> + return 0;
> +}
#else
#define btgpio_suspend NULL
#define btgpio_resume NULL
> +#endif /* CONFIG_PM */
> +
> +static struct pci_device_id btgpio_pci_tbl[] = {
> + { PCI_DEVICE(PCI_VENDOR_ID_BROOKTREE, PCI_DEVICE_ID_BT848) },
> + { PCI_DEVICE(PCI_VENDOR_ID_BROOKTREE, PCI_DEVICE_ID_BT849) },
> + { PCI_DEVICE(PCI_VENDOR_ID_BROOKTREE, PCI_DEVICE_ID_BT878) },
> + { PCI_DEVICE(PCI_VENDOR_ID_BROOKTREE, PCI_DEVICE_ID_BT879) },
> + { 0, },
> +};
> +MODULE_DEVICE_TABLE(pci, btgpio_pci_tbl);
> +
> +static struct pci_driver btgpio_pci_driver = {
> + .name = "btgpio",
> + .id_table = btgpio_pci_tbl,
> + .probe = btgpio_probe,
> + .remove = btgpio_remove,
> +#ifdef CONFIG_PM
dd
> + .suspend = btgpio_suspend,
> + .resume = btgpio_resume,
> +#endif
dd
> +};
> +
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Drivers for selfmade hardware
2008-07-10 5:45 ` Andrew Morton
@ 2008-07-10 12:57 ` Michael Buesch
2008-07-10 13:13 ` Andrew Morton
0 siblings, 1 reply; 9+ messages in thread
From: Michael Buesch @ 2008-07-10 12:57 UTC (permalink / raw)
To: Andrew Morton; +Cc: linux-kernel
On Thursday 10 July 2008 07:45:57 Andrew Morton wrote:
> #else
> #define btgpio_suspend NULL
> #define btgpio_resume NULL
Yeah I thought you had a patch in -mm which does this. Don't you?
--
Greetings Michael.
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Drivers for selfmade hardware
2008-07-10 12:57 ` Michael Buesch
@ 2008-07-10 13:13 ` Andrew Morton
0 siblings, 0 replies; 9+ messages in thread
From: Andrew Morton @ 2008-07-10 13:13 UTC (permalink / raw)
To: Michael Buesch; +Cc: linux-kernel
On Thu, 10 Jul 2008 14:57:47 +0200 Michael Buesch <mb@bu3sch.de> wrote:
> On Thursday 10 July 2008 07:45:57 Andrew Morton wrote:
> > #else
> > #define btgpio_suspend NULL
> > #define btgpio_resume NULL
>
> Yeah I thought you had a patch in -mm which does this. Don't you?
>
Nope. A grep for btgpio_suspend comes up empty.
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2008-07-10 13:19 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-06-29 19:47 Drivers for selfmade hardware Michael Buesch
2008-06-29 20:01 ` Christoph Hellwig
2008-06-29 21:26 ` Alan Cox
2008-06-30 9:50 ` Hans J. Koch
2008-06-30 10:00 ` Michael Buesch
2008-06-30 15:37 ` Miguel Ojeda
2008-07-10 5:45 ` Andrew Morton
2008-07-10 12:57 ` Michael Buesch
2008-07-10 13:13 ` Andrew Morton
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox