Commit a8f35ce3 authored by Hans Verkuil's avatar Hans Verkuil Committed by Mauro Carvalho Chehab

[media] cx25821: remove unnecessary global devlist

This device list is not necessary. The kernel already has all that information,
so just use that instead.
Also remove a bogus refcount and some dead 'private_free' code in the alsa driver.
Signed-off-by: default avatarHans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@redhat.com>
parent bfef0d35
...@@ -59,7 +59,6 @@ do { \ ...@@ -59,7 +59,6 @@ do { \
Data type declarations - Can be moded to a header file later Data type declarations - Can be moded to a header file later
****************************************************************************/ ****************************************************************************/
static struct snd_card *snd_cx25821_cards[SNDRV_CARDS];
static int devno; static int devno;
struct cx25821_audio_buffer { struct cx25821_audio_buffer {
...@@ -626,34 +625,6 @@ static DEFINE_PCI_DEVICE_TABLE(cx25821_audio_pci_tbl) = { ...@@ -626,34 +625,6 @@ static DEFINE_PCI_DEVICE_TABLE(cx25821_audio_pci_tbl) = {
MODULE_DEVICE_TABLE(pci, cx25821_audio_pci_tbl); MODULE_DEVICE_TABLE(pci, cx25821_audio_pci_tbl);
/*
* Not used in the function snd_cx25821_dev_free so removing
* from the file.
*/
/*
static int snd_cx25821_free(struct cx25821_audio_dev *chip)
{
if (chip->irq >= 0)
free_irq(chip->irq, chip);
cx25821_dev_unregister(chip->dev);
pci_disable_device(chip->pci);
return 0;
}
*/
/*
* Component Destructor
*/
static void snd_cx25821_dev_free(struct snd_card *card)
{
struct cx25821_audio_dev *chip = card->private_data;
/* snd_cx25821_free(chip); */
snd_card_free(chip->card);
}
/* /*
* Alsa Constructor - Component probe * Alsa Constructor - Component probe
*/ */
...@@ -685,7 +656,6 @@ static int cx25821_audio_initdev(struct cx25821_dev *dev) ...@@ -685,7 +656,6 @@ static int cx25821_audio_initdev(struct cx25821_dev *dev)
strcpy(card->driver, "cx25821"); strcpy(card->driver, "cx25821");
/* Card "creation" */ /* Card "creation" */
card->private_free = snd_cx25821_dev_free;
chip = card->private_data; chip = card->private_data;
spin_lock_init(&chip->reg_lock); spin_lock_init(&chip->reg_lock);
...@@ -729,8 +699,7 @@ static int cx25821_audio_initdev(struct cx25821_dev *dev) ...@@ -729,8 +699,7 @@ static int cx25821_audio_initdev(struct cx25821_dev *dev)
goto error; goto error;
} }
snd_cx25821_cards[devno] = card; dev->card = card;
devno++; devno++;
return 0; return 0;
...@@ -742,9 +711,31 @@ static int cx25821_audio_initdev(struct cx25821_dev *dev) ...@@ -742,9 +711,31 @@ static int cx25821_audio_initdev(struct cx25821_dev *dev)
/**************************************************************************** /****************************************************************************
LINUX MODULE INIT LINUX MODULE INIT
****************************************************************************/ ****************************************************************************/
static int cx25821_alsa_exit_callback(struct device *dev, void *data)
{
struct v4l2_device *v4l2_dev = dev_get_drvdata(dev);
struct cx25821_dev *cxdev = get_cx25821(v4l2_dev);
snd_card_free(cxdev->card);
return 0;
}
static void cx25821_audio_fini(void) static void cx25821_audio_fini(void)
{ {
snd_card_free(snd_cx25821_cards[0]); struct device_driver *drv = driver_find("cx25821", &pci_bus_type);
int ret;
ret = driver_for_each_device(drv, NULL, NULL, cx25821_alsa_exit_callback);
}
static int cx25821_alsa_init_callback(struct device *dev, void *data)
{
struct v4l2_device *v4l2_dev = dev_get_drvdata(dev);
struct cx25821_dev *cxdev = get_cx25821(v4l2_dev);
cx25821_audio_initdev(cxdev);
return 0;
} }
/* /*
...@@ -756,29 +747,11 @@ static void cx25821_audio_fini(void) ...@@ -756,29 +747,11 @@ static void cx25821_audio_fini(void)
*/ */
static int cx25821_alsa_init(void) static int cx25821_alsa_init(void)
{ {
struct cx25821_dev *dev = NULL; struct device_driver *drv = driver_find("cx25821", &pci_bus_type);
struct list_head *list;
mutex_lock(&cx25821_devlist_mutex); return driver_for_each_device(drv, NULL, NULL, cx25821_alsa_init_callback);
list_for_each(list, &cx25821_devlist) {
dev = list_entry(list, struct cx25821_dev, devlist);
cx25821_audio_initdev(dev);
}
mutex_unlock(&cx25821_devlist_mutex);
if (dev == NULL)
pr_info("ERROR ALSA: no cx25821 cards found\n");
return 0;
} }
late_initcall(cx25821_alsa_init); late_initcall(cx25821_alsa_init);
module_exit(cx25821_audio_fini); module_exit(cx25821_audio_fini);
/* ----------------------------------------------------------- */
/*
* Local variables:
* c-basic-offset: 8
* End:
*/
...@@ -41,13 +41,6 @@ static unsigned int card[] = {[0 ... (CX25821_MAXBOARDS - 1)] = UNSET }; ...@@ -41,13 +41,6 @@ static unsigned int card[] = {[0 ... (CX25821_MAXBOARDS - 1)] = UNSET };
module_param_array(card, int, NULL, 0444); module_param_array(card, int, NULL, 0444);
MODULE_PARM_DESC(card, "card type"); MODULE_PARM_DESC(card, "card type");
static unsigned int cx25821_devcount;
DEFINE_MUTEX(cx25821_devlist_mutex);
EXPORT_SYMBOL(cx25821_devlist_mutex);
LIST_HEAD(cx25821_devlist);
EXPORT_SYMBOL(cx25821_devlist);
const struct sram_channel cx25821_sram_channels[] = { const struct sram_channel cx25821_sram_channels[] = {
[SRAM_CH00] = { [SRAM_CH00] = {
.i = SRAM_CH00, .i = SRAM_CH00,
...@@ -871,6 +864,7 @@ static void cx25821_iounmap(struct cx25821_dev *dev) ...@@ -871,6 +864,7 @@ static void cx25821_iounmap(struct cx25821_dev *dev)
static int cx25821_dev_setup(struct cx25821_dev *dev) static int cx25821_dev_setup(struct cx25821_dev *dev)
{ {
static unsigned int cx25821_devcount;
int i; int i;
pr_info("\n***********************************\n"); pr_info("\n***********************************\n");
...@@ -879,15 +873,9 @@ static int cx25821_dev_setup(struct cx25821_dev *dev) ...@@ -879,15 +873,9 @@ static int cx25821_dev_setup(struct cx25821_dev *dev)
mutex_init(&dev->lock); mutex_init(&dev->lock);
atomic_inc(&dev->refcount);
dev->nr = ++cx25821_devcount; dev->nr = ++cx25821_devcount;
sprintf(dev->name, "cx25821[%d]", dev->nr); sprintf(dev->name, "cx25821[%d]", dev->nr);
mutex_lock(&cx25821_devlist_mutex);
list_add_tail(&dev->devlist, &cx25821_devlist);
mutex_unlock(&cx25821_devlist_mutex);
if (dev->pci->device != 0x8210) { if (dev->pci->device != 0x8210) {
pr_info("%s(): Exiting. Incorrect Hardware device = 0x%02x\n", pr_info("%s(): Exiting. Incorrect Hardware device = 0x%02x\n",
__func__, dev->pci->device); __func__, dev->pci->device);
...@@ -1021,9 +1009,6 @@ void cx25821_dev_unregister(struct cx25821_dev *dev) ...@@ -1021,9 +1009,6 @@ void cx25821_dev_unregister(struct cx25821_dev *dev)
release_mem_region(dev->base_io_addr, pci_resource_len(dev->pci, 0)); release_mem_region(dev->base_io_addr, pci_resource_len(dev->pci, 0));
if (!atomic_dec_and_test(&dev->refcount))
return;
for (i = 0; i < MAX_VID_CHANNEL_NUM - 1; i++) { for (i = 0; i < MAX_VID_CHANNEL_NUM - 1; i++) {
if (i == SRAM_CH08) /* audio channel */ if (i == SRAM_CH08) /* audio channel */
continue; continue;
...@@ -1414,10 +1399,6 @@ static void cx25821_finidev(struct pci_dev *pci_dev) ...@@ -1414,10 +1399,6 @@ static void cx25821_finidev(struct pci_dev *pci_dev)
if (pci_dev->irq) if (pci_dev->irq)
free_irq(pci_dev->irq, dev); free_irq(pci_dev->irq, dev);
mutex_lock(&cx25821_devlist_mutex);
list_del(&dev->devlist);
mutex_unlock(&cx25821_devlist_mutex);
cx25821_dev_unregister(dev); cx25821_dev_unregister(dev);
v4l2_device_unregister(v4l2_dev); v4l2_device_unregister(v4l2_dev);
kfree(dev); kfree(dev);
......
...@@ -654,45 +654,28 @@ static struct videobuf_queue_ops cx25821_video_qops = { ...@@ -654,45 +654,28 @@ static struct videobuf_queue_ops cx25821_video_qops = {
static int video_open(struct file *file) static int video_open(struct file *file)
{ {
struct video_device *vdev = video_devdata(file); struct video_device *vdev = video_devdata(file);
struct cx25821_dev *h, *dev = video_drvdata(file); struct cx25821_dev *dev = video_drvdata(file);
struct cx25821_fh *fh; struct cx25821_fh *fh;
struct list_head *list;
int minor = video_devdata(file)->minor;
enum v4l2_buf_type type = V4L2_BUF_TYPE_VIDEO_CAPTURE; enum v4l2_buf_type type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
u32 pix_format; u32 pix_format;
int ch_id = 0; int ch_id;
int i;
dprintk(1, "open dev=%s type=%s\n", video_device_node_name(vdev), dprintk(1, "open dev=%s type=%s\n", video_device_node_name(vdev),
v4l2_type_names[type]); v4l2_type_names[type]);
for (ch_id = 0; ch_id < MAX_VID_CHANNEL_NUM - 1; ch_id++)
if (dev->channels[ch_id].video_dev == vdev)
break;
/* Can't happen */
if (ch_id >= MAX_VID_CHANNEL_NUM - 1)
return -ENODEV;
/* allocate + initialize per filehandle data */ /* allocate + initialize per filehandle data */
fh = kzalloc(sizeof(*fh), GFP_KERNEL); fh = kzalloc(sizeof(*fh), GFP_KERNEL);
if (NULL == fh) if (NULL == fh)
return -ENOMEM; return -ENOMEM;
mutex_lock(&cx25821_devlist_mutex);
list_for_each(list, &cx25821_devlist)
{
h = list_entry(list, struct cx25821_dev, devlist);
for (i = 0; i < MAX_VID_CHANNEL_NUM - 1; i++) {
if (h->channels[i].video_dev &&
h->channels[i].video_dev->minor == minor) {
dev = h;
ch_id = i;
type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
}
}
}
if (NULL == dev) {
mutex_unlock(&cx25821_devlist_mutex);
kfree(fh);
return -ENODEV;
}
file->private_data = fh; file->private_data = fh;
fh->dev = dev; fh->dev = dev;
fh->type = type; fh->type = type;
...@@ -719,7 +702,6 @@ static int video_open(struct file *file) ...@@ -719,7 +702,6 @@ static int video_open(struct file *file)
fh, NULL); fh, NULL);
dprintk(1, "post videobuf_queue_init()\n"); dprintk(1, "post videobuf_queue_init()\n");
mutex_unlock(&cx25821_devlist_mutex);
return 0; return 0;
} }
......
...@@ -238,9 +238,9 @@ struct cx25821_channel { ...@@ -238,9 +238,9 @@ struct cx25821_channel {
int cif_width; int cif_width;
}; };
struct snd_card;
struct cx25821_dev { struct cx25821_dev {
struct list_head devlist;
atomic_t refcount;
struct v4l2_device v4l2_dev; struct v4l2_device v4l2_dev;
/* pci stuff */ /* pci stuff */
...@@ -252,6 +252,8 @@ struct cx25821_dev { ...@@ -252,6 +252,8 @@ struct cx25821_dev {
u8 __iomem *bmmio; u8 __iomem *bmmio;
int pci_irqmask; int pci_irqmask;
int hwrevision; int hwrevision;
/* used by cx25821-alsa */
struct snd_card *card;
u32 clk_freq; u32 clk_freq;
...@@ -403,9 +405,6 @@ static inline struct cx25821_dev *get_cx25821(struct v4l2_device *v4l2_dev) ...@@ -403,9 +405,6 @@ static inline struct cx25821_dev *get_cx25821(struct v4l2_device *v4l2_dev)
#define cx25821_call_all(dev, o, f, args...) \ #define cx25821_call_all(dev, o, f, args...) \
v4l2_device_call_all(&dev->v4l2_dev, 0, o, f, ##args) v4l2_device_call_all(&dev->v4l2_dev, 0, o, f, ##args)
extern struct list_head cx25821_devlist;
extern struct mutex cx25821_devlist_mutex;
extern struct cx25821_board cx25821_boards[]; extern struct cx25821_board cx25821_boards[];
extern struct cx25821_subid cx25821_subids[]; extern struct cx25821_subid cx25821_subids[];
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment