aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/video/bt8xx
diff options
context:
space:
mode:
authorTrent Piepho <xyzzy@speakeasy.org>2009-01-28 19:32:59 -0500
committerMauro Carvalho Chehab <mchehab@redhat.com>2009-03-30 11:42:47 -0400
commit4b10d3b626922ffa2387905a230b12450281a12d (patch)
treed65429e98adf29ba08b6ddbf09e6ac78fcaaeac3 /drivers/media/video/bt8xx
parent6f98700a5bb8d218162b04db1b8a3921a0dcc7ce (diff)
V4L/DVB (10568): bttv: dynamically allocate device data
The bttv driver had static array of structures for up to 16 possible bttv devices, even though few users have more than one or two. The structures were quite large and this resulted in a huge BSS segment. Change the driver to allocate the bttv device data dynamically, which changes "struct bttv bttvs[BTTV_MAX]" to "struct bttv *bttvs[BTTV_MAX]". It would be nice to get ride of "bttvs" entirely but there are some complications with gpio access from the audio & mpeg drivers. To help bttvs removal along anyway, I changed the open() methods use the video device's drvdata to get the driver data instead of looking it up in the bttvs array. This is also more efficient. Some WARN_ON()s are added in cases the device node exists by the bttv device doesn't, which I don't think should be possible. The gpio access functions need to check if bttvs[card] is NULL now. Though calling them on a non-existent card in the first place is wrong, but hard to solve given the fundamental problems in how the gpio access code works. This patch reduces the bss size by 66560 bytes on ia32. Overall change is a reduction of 66398 bytes, as the WARN_ON()s add some 198 bytes. Signed-off-by: Trent Piepho <xyzzy@speakeasy.org> Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
Diffstat (limited to 'drivers/media/video/bt8xx')
-rw-r--r--drivers/media/video/bt8xx/bttv-driver.c45
-rw-r--r--drivers/media/video/bt8xx/bttv-if.c18
-rw-r--r--drivers/media/video/bt8xx/bttvp.h2
3 files changed, 31 insertions, 34 deletions
diff --git a/drivers/media/video/bt8xx/bttv-driver.c b/drivers/media/video/bt8xx/bttv-driver.c
index ccf6aa6a975b..826ca60b42e6 100644
--- a/drivers/media/video/bt8xx/bttv-driver.c
+++ b/drivers/media/video/bt8xx/bttv-driver.c
@@ -58,7 +58,7 @@
58 58
59 59
60unsigned int bttv_num; /* number of Bt848s in use */ 60unsigned int bttv_num; /* number of Bt848s in use */
61struct bttv bttvs[BTTV_MAX]; 61struct bttv *bttvs[BTTV_MAX];
62 62
63unsigned int bttv_debug; 63unsigned int bttv_debug;
64unsigned int bttv_verbose = 1; 64unsigned int bttv_verbose = 1;
@@ -3217,29 +3217,19 @@ err:
3217static int bttv_open(struct file *file) 3217static int bttv_open(struct file *file)
3218{ 3218{
3219 int minor = video_devdata(file)->minor; 3219 int minor = video_devdata(file)->minor;
3220 struct bttv *btv = NULL; 3220 struct bttv *btv = video_drvdata(file);
3221 struct bttv_fh *fh; 3221 struct bttv_fh *fh;
3222 enum v4l2_buf_type type = 0; 3222 enum v4l2_buf_type type = 0;
3223 unsigned int i;
3224 3223
3225 dprintk(KERN_DEBUG "bttv: open minor=%d\n",minor); 3224 dprintk(KERN_DEBUG "bttv: open minor=%d\n",minor);
3226 3225
3227 lock_kernel(); 3226 lock_kernel();
3228 for (i = 0; i < bttv_num; i++) { 3227 if (btv->video_dev->minor == minor) {
3229 if (bttvs[i].video_dev && 3228 type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
3230 bttvs[i].video_dev->minor == minor) { 3229 } else if (btv->vbi_dev->minor == minor) {
3231 btv = &bttvs[i]; 3230 type = V4L2_BUF_TYPE_VBI_CAPTURE;
3232 type = V4L2_BUF_TYPE_VIDEO_CAPTURE; 3231 } else {
3233 break; 3232 WARN_ON(1);
3234 }
3235 if (bttvs[i].vbi_dev &&
3236 bttvs[i].vbi_dev->minor == minor) {
3237 btv = &bttvs[i];
3238 type = V4L2_BUF_TYPE_VBI_CAPTURE;
3239 break;
3240 }
3241 }
3242 if (NULL == btv) {
3243 unlock_kernel(); 3233 unlock_kernel();
3244 return -ENODEV; 3234 return -ENODEV;
3245 } 3235 }
@@ -3429,20 +3419,14 @@ static struct video_device bttv_video_template = {
3429static int radio_open(struct file *file) 3419static int radio_open(struct file *file)
3430{ 3420{
3431 int minor = video_devdata(file)->minor; 3421 int minor = video_devdata(file)->minor;
3432 struct bttv *btv = NULL; 3422 struct bttv *btv = video_drvdata(file);
3433 struct bttv_fh *fh; 3423 struct bttv_fh *fh;
3434 unsigned int i;
3435 3424
3436 dprintk("bttv: open minor=%d\n",minor); 3425 dprintk("bttv: open minor=%d\n",minor);
3437 3426
3438 lock_kernel(); 3427 lock_kernel();
3439 for (i = 0; i < bttv_num; i++) { 3428 WARN_ON(btv->radio_dev && btv->radio_dev->minor != minor);
3440 if (bttvs[i].radio_dev && bttvs[i].radio_dev->minor == minor) { 3429 if (!btv->radio_dev || btv->radio_dev->minor != minor) {
3441 btv = &bttvs[i];
3442 break;
3443 }
3444 }
3445 if (NULL == btv) {
3446 unlock_kernel(); 3430 unlock_kernel();
3447 return -ENODEV; 3431 return -ENODEV;
3448 } 3432 }
@@ -4203,6 +4187,7 @@ static struct video_device *vdev_init(struct bttv *btv,
4203 vfd->parent = &btv->c.pci->dev; 4187 vfd->parent = &btv->c.pci->dev;
4204 vfd->release = video_device_release; 4188 vfd->release = video_device_release;
4205 vfd->debug = bttv_debug; 4189 vfd->debug = bttv_debug;
4190 video_set_drvdata(vfd, btv);
4206 snprintf(vfd->name, sizeof(vfd->name), "BT%d%s %s (%s)", 4191 snprintf(vfd->name, sizeof(vfd->name), "BT%d%s %s (%s)",
4207 btv->id, (btv->id==848 && btv->revision==0x12) ? "A" : "", 4192 btv->id, (btv->id==848 && btv->revision==0x12) ? "A" : "",
4208 type_name, bttv_tvcards[btv->c.type].name); 4193 type_name, bttv_tvcards[btv->c.type].name);
@@ -4312,8 +4297,7 @@ static int __devinit bttv_probe(struct pci_dev *dev,
4312 if (bttv_num == BTTV_MAX) 4297 if (bttv_num == BTTV_MAX)
4313 return -ENOMEM; 4298 return -ENOMEM;
4314 printk(KERN_INFO "bttv: Bt8xx card found (%d).\n", bttv_num); 4299 printk(KERN_INFO "bttv: Bt8xx card found (%d).\n", bttv_num);
4315 btv=&bttvs[bttv_num]; 4300 bttvs[bttv_num] = btv = kzalloc(sizeof(*btv), GFP_KERNEL);
4316 memset(btv,0,sizeof(*btv));
4317 btv->c.nr = bttv_num; 4301 btv->c.nr = bttv_num;
4318 sprintf(btv->c.name,"bttv%d",btv->c.nr); 4302 sprintf(btv->c.name,"bttv%d",btv->c.nr);
4319 4303
@@ -4517,6 +4501,9 @@ static void __devexit bttv_remove(struct pci_dev *pci_dev)
4517 pci_resource_len(btv->c.pci,0)); 4501 pci_resource_len(btv->c.pci,0));
4518 4502
4519 pci_set_drvdata(pci_dev, NULL); 4503 pci_set_drvdata(pci_dev, NULL);
4504 bttvs[btv->c.nr] = NULL;
4505 kfree(btv);
4506
4520 return; 4507 return;
4521} 4508}
4522 4509
diff --git a/drivers/media/video/bt8xx/bttv-if.c b/drivers/media/video/bt8xx/bttv-if.c
index ecf07988cd33..a6a540dc9e4b 100644
--- a/drivers/media/video/bt8xx/bttv-if.c
+++ b/drivers/media/video/bt8xx/bttv-if.c
@@ -47,7 +47,10 @@ struct pci_dev* bttv_get_pcidev(unsigned int card)
47{ 47{
48 if (card >= bttv_num) 48 if (card >= bttv_num)
49 return NULL; 49 return NULL;
50 return bttvs[card].c.pci; 50 if (!bttvs[card])
51 return NULL;
52
53 return bttvs[card]->c.pci;
51} 54}
52 55
53 56
@@ -59,7 +62,10 @@ int bttv_gpio_enable(unsigned int card, unsigned long mask, unsigned long data)
59 return -EINVAL; 62 return -EINVAL;
60 } 63 }
61 64
62 btv = &bttvs[card]; 65 btv = bttvs[card];
66 if (!btv)
67 return -ENODEV;
68
63 gpio_inout(mask,data); 69 gpio_inout(mask,data);
64 if (bttv_gpio) 70 if (bttv_gpio)
65 bttv_gpio_tracking(btv,"extern enable"); 71 bttv_gpio_tracking(btv,"extern enable");
@@ -74,7 +80,9 @@ int bttv_read_gpio(unsigned int card, unsigned long *data)
74 return -EINVAL; 80 return -EINVAL;
75 } 81 }
76 82
77 btv = &bttvs[card]; 83 btv = bttvs[card];
84 if (!btv)
85 return -ENODEV;
78 86
79 if(btv->shutdown) { 87 if(btv->shutdown) {
80 return -ENODEV; 88 return -ENODEV;
@@ -94,7 +102,9 @@ int bttv_write_gpio(unsigned int card, unsigned long mask, unsigned long data)
94 return -EINVAL; 102 return -EINVAL;
95 } 103 }
96 104
97 btv = &bttvs[card]; 105 btv = bttvs[card];
106 if (!btv)
107 return -ENODEV;
98 108
99/* prior setting BT848_GPIO_REG_INP is (probably) not needed 109/* prior setting BT848_GPIO_REG_INP is (probably) not needed
100 because direct input is set on init */ 110 because direct input is set on init */
diff --git a/drivers/media/video/bt8xx/bttvp.h b/drivers/media/video/bt8xx/bttvp.h
index 497c8dcb4ae8..b8274d233fd0 100644
--- a/drivers/media/video/bt8xx/bttvp.h
+++ b/drivers/media/video/bt8xx/bttvp.h
@@ -462,7 +462,7 @@ struct bttv {
462/* our devices */ 462/* our devices */
463#define BTTV_MAX 32 463#define BTTV_MAX 32
464extern unsigned int bttv_num; 464extern unsigned int bttv_num;
465extern struct bttv bttvs[BTTV_MAX]; 465extern struct bttv *bttvs[BTTV_MAX];
466 466
467static inline unsigned int bttv_muxsel(const struct bttv *btv, 467static inline unsigned int bttv_muxsel(const struct bttv *btv,
468 unsigned int input) 468 unsigned int input)