mirror of
https://github.com/torvalds/linux.git
synced 2024-11-05 11:32:04 +00:00
0b8e74c6f4
Pull media updates from Mauro Carvalho Chehab: "The first part of the media updates for Kernel 3.7. This series contain: - A major tree renaming patch series: now, drivers are organized internally by their used bus, instead of by V4L2 and/or DVB API, providing a cleaner driver location for hybrid drivers that implement both APIs, and allowing to cleanup the Kconfig items and make them more intuitive for the end user; - Media Kernel developers are typically very lazy with their duties of keeping the MAINTAINERS entries for their drivers updated. As now the tree is more organized, we're doing an effort to add/update those entries for the drivers that aren't currently orphan; - Several DVB USB drivers got moved to a new DVB USB v2 core; the new core fixes several bugs (as the existing one that got bitroted). Now, suspend/resume finally started to work fine (at least with some devices - we should expect more work with regards to it); - added multistream support for DVB-T2, and unified the API for DVB-S2 and ISDB-S. Backward binary support is preserved; - as usual, a few new drivers, some V4L2 core improvements and lots of drivers improvements and fixes. There are some points to notice on this series: 1) you should expect a trivial merge conflict on your tree, with the removal of Documentation/feature-removal-schedule.txt: this series would be adding two additional entries there. I opted to not rebase it due to this recent change; 2) With regards to the PCTV 520e udev-related breakage, I opted to fix it in a way that the patches can be backported to 3.5 even without your firmware fix patch. This way, Greg doesn't need to rush backporting your patch (as there are still the firmware cache and firmware path customization issues to be addressed there). I'll send later a patch (likely after the end of the merge window) reverting the rest of the DRX-K async firmware request, fully restoring its original behaviour to allow media drivers to initialize everything serialized as before for 3.7 and upper. 3) I'm planning to work on this weekend to test the DMABUF patches for V4L2. The patches are on my queue for several Kernel cycles, but, up to now, there is/was no way to test the series locally. I have some concerns about this particular changeset with regards to security issues, and with regards to the replacement of the old VIDIOC_OVERLAY ioctl's that is broken on modern systems, due to GPU drivers change. The Overlay API allows direct PCI2PCI transfers from a media capture card into the GPU framebuffer, but its API is crappy. Also, the only existing X11 driver that implements it requires a XV extension that is not available anymore on modern drivers. The DMABUF can do the same thing, but with it is promising to be a properly-designed API. If I can successfully test this series and be happy with it, I should be asking you to pull them next week." * 'v4l_for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mchehab/linux-media: (717 commits) em28xx: regression fix: use DRX-K sync firmware requests on em28xx drxk: allow loading firmware synchrousnously em28xx: Make all em28xx extensions to be initialized asynchronously [media] tda18271: properly report read errors in tda18271_get_id [media] tda18271: delay IR & RF calibration until init() if delay_cal is set [media] MAINTAINERS: add Michael Krufky as tda827x maintainer [media] MAINTAINERS: add Michael Krufky as tda8290 maintainer [media] MAINTAINERS: add Michael Krufky as cxusb maintainer [media] MAINTAINERS: add Michael Krufky as lg2160 maintainer [media] MAINTAINERS: add Michael Krufky as lgdt3305 maintainer [media] MAINTAINERS: add Michael Krufky as mxl111sf maintainer [media] MAINTAINERS: add Michael Krufky as mxl5007t maintainer [media] MAINTAINERS: add Michael Krufky as tda18271 maintainer [media] s5p-tv: Report only multi-plane capabilities in vidioc_querycap [media] s5p-mfc: Fix misplaced return statement in s5p_mfc_suspend() [media] exynos-gsc: Add missing static storage class specifiers [media] exynos-gsc: Remove <linux/version.h> header file inclusion [media] s5p-fimc: Fix incorrect condition in fimc_lite_reqbufs() [media] s5p-tv: Fix potential NULL pointer dereference error [media] s5k6aa: Fix possible NULL pointer dereference ...
336 lines
8.0 KiB
C
336 lines
8.0 KiB
C
/*
|
|
|
|
bt8xx GPIO abuser
|
|
|
|
Copyright (C) 2008 Michael Buesch <m@bues.ch>
|
|
|
|
Please do _only_ contact the people listed _above_ 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 <linux/gpio.h>
|
|
#include <linux/slab.h>
|
|
|
|
/* Steal the hardware definitions from the bttv driver. */
|
|
#include "../media/pci/bt8xx/bt848.h"
|
|
|
|
|
|
#define BT8XXGPIO_NR_GPIOS 24 /* We have 24 GPIO pins */
|
|
|
|
|
|
struct bt8xxgpio {
|
|
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 modparam_gpiobase = -1/* dynamic */;
|
|
module_param_named(gpiobase, modparam_gpiobase, int, 0444);
|
|
MODULE_PARM_DESC(gpiobase, "The GPIO number base. -1 means dynamic, which is the default.");
|
|
|
|
|
|
static int bt8xxgpio_gpio_direction_input(struct gpio_chip *gpio, unsigned nr)
|
|
{
|
|
struct bt8xxgpio *bg = container_of(gpio, struct bt8xxgpio, 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 bt8xxgpio_gpio_get(struct gpio_chip *gpio, unsigned nr)
|
|
{
|
|
struct bt8xxgpio *bg = container_of(gpio, struct bt8xxgpio, 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 bt8xxgpio_gpio_direction_output(struct gpio_chip *gpio,
|
|
unsigned nr, int val)
|
|
{
|
|
struct bt8xxgpio *bg = container_of(gpio, struct bt8xxgpio, gpio);
|
|
unsigned long flags;
|
|
u32 outen, data;
|
|
|
|
spin_lock_irqsave(&bg->lock, flags);
|
|
|
|
outen = bgread(BT848_GPIO_OUT_EN);
|
|
outen |= (1 << nr);
|
|
bgwrite(outen, BT848_GPIO_OUT_EN);
|
|
|
|
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);
|
|
|
|
return 0;
|
|
}
|
|
|
|
static void bt8xxgpio_gpio_set(struct gpio_chip *gpio,
|
|
unsigned nr, int val)
|
|
{
|
|
struct bt8xxgpio *bg = container_of(gpio, struct bt8xxgpio, 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 bt8xxgpio_gpio_setup(struct bt8xxgpio *bg)
|
|
{
|
|
struct gpio_chip *c = &bg->gpio;
|
|
|
|
c->label = dev_name(&bg->pdev->dev);
|
|
c->owner = THIS_MODULE;
|
|
c->direction_input = bt8xxgpio_gpio_direction_input;
|
|
c->get = bt8xxgpio_gpio_get;
|
|
c->direction_output = bt8xxgpio_gpio_direction_output;
|
|
c->set = bt8xxgpio_gpio_set;
|
|
c->dbg_show = NULL;
|
|
c->base = modparam_gpiobase;
|
|
c->ngpio = BT8XXGPIO_NR_GPIOS;
|
|
c->can_sleep = 0;
|
|
}
|
|
|
|
static int bt8xxgpio_probe(struct pci_dev *dev,
|
|
const struct pci_device_id *pci_id)
|
|
{
|
|
struct bt8xxgpio *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 "bt8xxgpio: Can't enable device.\n");
|
|
goto err_freebg;
|
|
}
|
|
if (!request_mem_region(pci_resource_start(dev, 0),
|
|
pci_resource_len(dev, 0),
|
|
"bt8xxgpio")) {
|
|
printk(KERN_WARNING "bt8xxgpio: 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 "bt8xxgpio: ioremap() failed\n");
|
|
err = -EIO;
|
|
goto err_release_mem;
|
|
}
|
|
|
|
/* Disable interrupts */
|
|
bgwrite(0, BT848_INT_MASK);
|
|
|
|
/* gpio init */
|
|
bgwrite(0, BT848_GPIO_DMA_CTL);
|
|
bgwrite(0, BT848_GPIO_REG_INP);
|
|
bgwrite(0, BT848_GPIO_OUT_EN);
|
|
|
|
bt8xxgpio_gpio_setup(bg);
|
|
err = gpiochip_add(&bg->gpio);
|
|
if (err) {
|
|
printk(KERN_ERR "bt8xxgpio: Failed to register GPIOs\n");
|
|
goto err_release_mem;
|
|
}
|
|
|
|
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 bt8xxgpio_remove(struct pci_dev *pdev)
|
|
{
|
|
struct bt8xxgpio *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 bt8xxgpio_suspend(struct pci_dev *pdev, pm_message_t state)
|
|
{
|
|
struct bt8xxgpio *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 bt8xxgpio_resume(struct pci_dev *pdev)
|
|
{
|
|
struct bt8xxgpio *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_DMA_CTL);
|
|
bgwrite(0, BT848_GPIO_REG_INP);
|
|
bgwrite(bg->saved_outen, BT848_GPIO_OUT_EN);
|
|
bgwrite(bg->saved_data & bg->saved_outen,
|
|
BT848_GPIO_DATA);
|
|
|
|
spin_unlock_irqrestore(&bg->lock, flags);
|
|
|
|
return 0;
|
|
}
|
|
#else
|
|
#define bt8xxgpio_suspend NULL
|
|
#define bt8xxgpio_resume NULL
|
|
#endif /* CONFIG_PM */
|
|
|
|
static DEFINE_PCI_DEVICE_TABLE(bt8xxgpio_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, bt8xxgpio_pci_tbl);
|
|
|
|
static struct pci_driver bt8xxgpio_pci_driver = {
|
|
.name = "bt8xxgpio",
|
|
.id_table = bt8xxgpio_pci_tbl,
|
|
.probe = bt8xxgpio_probe,
|
|
.remove = bt8xxgpio_remove,
|
|
.suspend = bt8xxgpio_suspend,
|
|
.resume = bt8xxgpio_resume,
|
|
};
|
|
|
|
module_pci_driver(bt8xxgpio_pci_driver);
|
|
|
|
MODULE_LICENSE("GPL");
|
|
MODULE_AUTHOR("Michael Buesch");
|
|
MODULE_DESCRIPTION("Abuse a BT8xx framegrabber card as generic GPIO card");
|