diff options
author | Guennadi Liakhovetski <g.liakhovetski@pengutronix.de> | 2008-04-04 12:41:25 -0400 |
---|---|---|
committer | Mauro Carvalho Chehab <mchehab@infradead.org> | 2008-04-24 13:07:57 -0400 |
commit | b8d9904c3525c0a149976ffaad48fcb03e8703f7 (patch) | |
tree | ac116e518f70a694046752a05c16a5285bc4713f | |
parent | ce54093cefd64c1a2cb6b8c5ed1d68d2bd7a34ab (diff) |
V4L/DVB (7500): soc-camera: extract function pointers from host object into operations
Function pointers and the driver owner are not expected to change
throughout soc-camera host's life. Extract them into an operations struct.
Signed-off-by: Guennadi Liakhovetski <g.liakhovetski@pengutronix.de>
Signed-off-by: Mauro Carvalho Chehab <mchehab@infradead.org>
-rw-r--r-- | drivers/media/video/pxa_camera.c | 27 | ||||
-rw-r--r-- | drivers/media/video/soc_camera.c | 37 | ||||
-rw-r--r-- | include/media/soc_camera.h | 9 |
3 files changed, 40 insertions, 33 deletions
diff --git a/drivers/media/video/pxa_camera.c b/drivers/media/video/pxa_camera.c index 4756699d16aa..9758f7eb5932 100644 --- a/drivers/media/video/pxa_camera.c +++ b/drivers/media/video/pxa_camera.c | |||
@@ -803,20 +803,25 @@ static int pxa_camera_querycap(struct soc_camera_host *ici, | |||
803 | return 0; | 803 | return 0; |
804 | } | 804 | } |
805 | 805 | ||
806 | /* Should beallocated dynamically too, but we have only one. */ | 806 | static struct soc_camera_host_ops pxa_soc_camera_host_ops = { |
807 | .owner = THIS_MODULE, | ||
808 | .add = pxa_camera_add_device, | ||
809 | .remove = pxa_camera_remove_device, | ||
810 | .set_fmt_cap = pxa_camera_set_fmt_cap, | ||
811 | .try_fmt_cap = pxa_camera_try_fmt_cap, | ||
812 | .reqbufs = pxa_camera_reqbufs, | ||
813 | .poll = pxa_camera_poll, | ||
814 | .querycap = pxa_camera_querycap, | ||
815 | .try_bus_param = pxa_camera_try_bus_param, | ||
816 | .set_bus_param = pxa_camera_set_bus_param, | ||
817 | }; | ||
818 | |||
819 | /* Should be allocated dynamically too, but we have only one. */ | ||
807 | static struct soc_camera_host pxa_soc_camera_host = { | 820 | static struct soc_camera_host pxa_soc_camera_host = { |
808 | .drv_name = PXA_CAM_DRV_NAME, | 821 | .drv_name = PXA_CAM_DRV_NAME, |
809 | .vbq_ops = &pxa_videobuf_ops, | 822 | .vbq_ops = &pxa_videobuf_ops, |
810 | .add = pxa_camera_add_device, | ||
811 | .remove = pxa_camera_remove_device, | ||
812 | .msize = sizeof(struct pxa_buffer), | 823 | .msize = sizeof(struct pxa_buffer), |
813 | .set_fmt_cap = pxa_camera_set_fmt_cap, | 824 | .ops = &pxa_soc_camera_host_ops, |
814 | .try_fmt_cap = pxa_camera_try_fmt_cap, | ||
815 | .reqbufs = pxa_camera_reqbufs, | ||
816 | .poll = pxa_camera_poll, | ||
817 | .querycap = pxa_camera_querycap, | ||
818 | .try_bus_param = pxa_camera_try_bus_param, | ||
819 | .set_bus_param = pxa_camera_set_bus_param, | ||
820 | }; | 825 | }; |
821 | 826 | ||
822 | static int pxa_camera_probe(struct platform_device *pdev) | 827 | static int pxa_camera_probe(struct platform_device *pdev) |
@@ -912,7 +917,7 @@ static int pxa_camera_probe(struct platform_device *pdev) | |||
912 | pxa_soc_camera_host.priv = pcdev; | 917 | pxa_soc_camera_host.priv = pcdev; |
913 | pxa_soc_camera_host.dev.parent = &pdev->dev; | 918 | pxa_soc_camera_host.dev.parent = &pdev->dev; |
914 | pxa_soc_camera_host.nr = pdev->id; | 919 | pxa_soc_camera_host.nr = pdev->id; |
915 | err = soc_camera_host_register(&pxa_soc_camera_host, THIS_MODULE); | 920 | err = soc_camera_host_register(&pxa_soc_camera_host); |
916 | if (err) | 921 | if (err) |
917 | goto exit_free_irq; | 922 | goto exit_free_irq; |
918 | 923 | ||
diff --git a/drivers/media/video/soc_camera.c b/drivers/media/video/soc_camera.c index 4af38d444e0c..43c8110599e8 100644 --- a/drivers/media/video/soc_camera.c +++ b/drivers/media/video/soc_camera.c | |||
@@ -76,12 +76,12 @@ static int soc_camera_try_fmt_cap(struct file *file, void *priv, | |||
76 | } | 76 | } |
77 | 77 | ||
78 | /* test physical bus parameters */ | 78 | /* test physical bus parameters */ |
79 | ret = ici->try_bus_param(icd, f->fmt.pix.pixelformat); | 79 | ret = ici->ops->try_bus_param(icd, f->fmt.pix.pixelformat); |
80 | if (ret) | 80 | if (ret) |
81 | return ret; | 81 | return ret; |
82 | 82 | ||
83 | /* limit format to hardware capabilities */ | 83 | /* limit format to hardware capabilities */ |
84 | ret = ici->try_fmt_cap(icd, f); | 84 | ret = ici->ops->try_fmt_cap(icd, f); |
85 | 85 | ||
86 | /* calculate missing fields */ | 86 | /* calculate missing fields */ |
87 | f->fmt.pix.field = field; | 87 | f->fmt.pix.field = field; |
@@ -143,7 +143,7 @@ static int soc_camera_reqbufs(struct file *file, void *priv, | |||
143 | if (ret < 0) | 143 | if (ret < 0) |
144 | return ret; | 144 | return ret; |
145 | 145 | ||
146 | return ici->reqbufs(icf, p); | 146 | return ici->ops->reqbufs(icf, p); |
147 | 147 | ||
148 | return ret; | 148 | return ret; |
149 | } | 149 | } |
@@ -203,7 +203,7 @@ static int soc_camera_open(struct inode *inode, struct file *file) | |||
203 | goto emgd; | 203 | goto emgd; |
204 | } | 204 | } |
205 | 205 | ||
206 | if (!try_module_get(ici->owner)) { | 206 | if (!try_module_get(ici->ops->owner)) { |
207 | dev_err(&icd->dev, "Couldn't lock capture bus driver.\n"); | 207 | dev_err(&icd->dev, "Couldn't lock capture bus driver.\n"); |
208 | ret = -EINVAL; | 208 | ret = -EINVAL; |
209 | goto emgi; | 209 | goto emgi; |
@@ -215,7 +215,7 @@ static int soc_camera_open(struct inode *inode, struct file *file) | |||
215 | 215 | ||
216 | /* Now we really have to activate the camera */ | 216 | /* Now we really have to activate the camera */ |
217 | if (icd->use_count == 1) { | 217 | if (icd->use_count == 1) { |
218 | ret = ici->add(icd); | 218 | ret = ici->ops->add(icd); |
219 | if (ret < 0) { | 219 | if (ret < 0) { |
220 | dev_err(&icd->dev, "Couldn't activate the camera: %d\n", ret); | 220 | dev_err(&icd->dev, "Couldn't activate the camera: %d\n", ret); |
221 | icd->use_count--; | 221 | icd->use_count--; |
@@ -238,7 +238,7 @@ static int soc_camera_open(struct inode *inode, struct file *file) | |||
238 | 238 | ||
239 | /* All errors are entered with the video_lock held */ | 239 | /* All errors are entered with the video_lock held */ |
240 | eiciadd: | 240 | eiciadd: |
241 | module_put(ici->owner); | 241 | module_put(ici->ops->owner); |
242 | emgi: | 242 | emgi: |
243 | module_put(icd->ops->owner); | 243 | module_put(icd->ops->owner); |
244 | emgd: | 244 | emgd: |
@@ -257,9 +257,9 @@ static int soc_camera_close(struct inode *inode, struct file *file) | |||
257 | mutex_lock(&video_lock); | 257 | mutex_lock(&video_lock); |
258 | icd->use_count--; | 258 | icd->use_count--; |
259 | if (!icd->use_count) | 259 | if (!icd->use_count) |
260 | ici->remove(icd); | 260 | ici->ops->remove(icd); |
261 | module_put(icd->ops->owner); | 261 | module_put(icd->ops->owner); |
262 | module_put(ici->owner); | 262 | module_put(ici->ops->owner); |
263 | mutex_unlock(&video_lock); | 263 | mutex_unlock(&video_lock); |
264 | 264 | ||
265 | vfree(file->private_data); | 265 | vfree(file->private_data); |
@@ -312,7 +312,7 @@ static unsigned int soc_camera_poll(struct file *file, poll_table *pt) | |||
312 | return POLLERR; | 312 | return POLLERR; |
313 | } | 313 | } |
314 | 314 | ||
315 | return ici->poll(file, pt); | 315 | return ici->ops->poll(file, pt); |
316 | } | 316 | } |
317 | 317 | ||
318 | 318 | ||
@@ -356,7 +356,7 @@ static int soc_camera_s_fmt_cap(struct file *file, void *priv, | |||
356 | rect.top = icd->y_current; | 356 | rect.top = icd->y_current; |
357 | rect.width = f->fmt.pix.width; | 357 | rect.width = f->fmt.pix.width; |
358 | rect.height = f->fmt.pix.height; | 358 | rect.height = f->fmt.pix.height; |
359 | ret = ici->set_fmt_cap(icd, f->fmt.pix.pixelformat, &rect); | 359 | ret = ici->ops->set_fmt_cap(icd, f->fmt.pix.pixelformat, &rect); |
360 | if (ret < 0) | 360 | if (ret < 0) |
361 | return ret; | 361 | return ret; |
362 | 362 | ||
@@ -372,7 +372,7 @@ static int soc_camera_s_fmt_cap(struct file *file, void *priv, | |||
372 | icd->width, icd->height); | 372 | icd->width, icd->height); |
373 | 373 | ||
374 | /* set physical bus parameters */ | 374 | /* set physical bus parameters */ |
375 | return ici->set_bus_param(icd, f->fmt.pix.pixelformat); | 375 | return ici->ops->set_bus_param(icd, f->fmt.pix.pixelformat); |
376 | } | 376 | } |
377 | 377 | ||
378 | static int soc_camera_enum_fmt_cap(struct file *file, void *priv, | 378 | static int soc_camera_enum_fmt_cap(struct file *file, void *priv, |
@@ -426,7 +426,7 @@ static int soc_camera_querycap(struct file *file, void *priv, | |||
426 | WARN_ON(priv != file->private_data); | 426 | WARN_ON(priv != file->private_data); |
427 | 427 | ||
428 | strlcpy(cap->driver, ici->drv_name, sizeof(cap->driver)); | 428 | strlcpy(cap->driver, ici->drv_name, sizeof(cap->driver)); |
429 | return ici->querycap(ici, cap); | 429 | return ici->ops->querycap(ici, cap); |
430 | } | 430 | } |
431 | 431 | ||
432 | static int soc_camera_streamon(struct file *file, void *priv, | 432 | static int soc_camera_streamon(struct file *file, void *priv, |
@@ -579,7 +579,7 @@ static int soc_camera_s_crop(struct file *file, void *fh, | |||
579 | if (a->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) | 579 | if (a->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) |
580 | return -EINVAL; | 580 | return -EINVAL; |
581 | 581 | ||
582 | ret = ici->set_fmt_cap(icd, 0, &a->c); | 582 | ret = ici->ops->set_fmt_cap(icd, 0, &a->c); |
583 | if (!ret) { | 583 | if (!ret) { |
584 | icd->width = a->c.width; | 584 | icd->width = a->c.width; |
585 | icd->height = a->c.height; | 585 | icd->height = a->c.height; |
@@ -706,7 +706,7 @@ static int soc_camera_probe(struct device *dev) | |||
706 | 706 | ||
707 | /* We only call ->add() here to activate and probe the camera. | 707 | /* We only call ->add() here to activate and probe the camera. |
708 | * We shall ->remove() and deactivate it immediately afterwards. */ | 708 | * We shall ->remove() and deactivate it immediately afterwards. */ |
709 | ret = ici->add(icd); | 709 | ret = ici->ops->add(icd); |
710 | if (ret < 0) | 710 | if (ret < 0) |
711 | return ret; | 711 | return ret; |
712 | 712 | ||
@@ -720,7 +720,7 @@ static int soc_camera_probe(struct device *dev) | |||
720 | icd->exposure = qctrl ? qctrl->default_value : | 720 | icd->exposure = qctrl ? qctrl->default_value : |
721 | (unsigned short)~0; | 721 | (unsigned short)~0; |
722 | } | 722 | } |
723 | ici->remove(icd); | 723 | ici->ops->remove(icd); |
724 | 724 | ||
725 | return ret; | 725 | return ret; |
726 | } | 726 | } |
@@ -762,12 +762,12 @@ static void dummy_release(struct device *dev) | |||
762 | { | 762 | { |
763 | } | 763 | } |
764 | 764 | ||
765 | int soc_camera_host_register(struct soc_camera_host *ici, struct module *owner) | 765 | int soc_camera_host_register(struct soc_camera_host *ici) |
766 | { | 766 | { |
767 | int ret; | 767 | int ret; |
768 | struct soc_camera_host *ix; | 768 | struct soc_camera_host *ix; |
769 | 769 | ||
770 | if (!ici->vbq_ops || !ici->add || !ici->remove || !owner) | 770 | if (!ici->vbq_ops || !ici->ops->add || !ici->ops->remove) |
771 | return -EINVAL; | 771 | return -EINVAL; |
772 | 772 | ||
773 | /* Number might be equal to the platform device ID */ | 773 | /* Number might be equal to the platform device ID */ |
@@ -785,7 +785,6 @@ int soc_camera_host_register(struct soc_camera_host *ici, struct module *owner) | |||
785 | list_add_tail(&ici->list, &hosts); | 785 | list_add_tail(&ici->list, &hosts); |
786 | mutex_unlock(&list_lock); | 786 | mutex_unlock(&list_lock); |
787 | 787 | ||
788 | ici->owner = owner; | ||
789 | ici->dev.release = dummy_release; | 788 | ici->dev.release = dummy_release; |
790 | 789 | ||
791 | ret = device_register(&ici->dev); | 790 | ret = device_register(&ici->dev); |
@@ -819,7 +818,7 @@ void soc_camera_host_unregister(struct soc_camera_host *ici) | |||
819 | if (icd->dev.parent == &ici->dev) { | 818 | if (icd->dev.parent == &ici->dev) { |
820 | device_unregister(&icd->dev); | 819 | device_unregister(&icd->dev); |
821 | /* Not before device_unregister(), .remove | 820 | /* Not before device_unregister(), .remove |
822 | * needs parent to call ici->remove() */ | 821 | * needs parent to call ici->ops->remove() */ |
823 | icd->dev.parent = NULL; | 822 | icd->dev.parent = NULL; |
824 | memset(&icd->dev.kobj, 0, sizeof(icd->dev.kobj)); | 823 | memset(&icd->dev.kobj, 0, sizeof(icd->dev.kobj)); |
825 | } | 824 | } |
diff --git a/include/media/soc_camera.h b/include/media/soc_camera.h index 7a2fa3ed849e..80e1193c07d5 100644 --- a/include/media/soc_camera.h +++ b/include/media/soc_camera.h | |||
@@ -56,9 +56,13 @@ struct soc_camera_host { | |||
56 | unsigned char nr; /* Host number */ | 56 | unsigned char nr; /* Host number */ |
57 | size_t msize; | 57 | size_t msize; |
58 | struct videobuf_queue_ops *vbq_ops; | 58 | struct videobuf_queue_ops *vbq_ops; |
59 | struct module *owner; | ||
60 | void *priv; | 59 | void *priv; |
61 | char *drv_name; | 60 | char *drv_name; |
61 | struct soc_camera_host_ops *ops; | ||
62 | }; | ||
63 | |||
64 | struct soc_camera_host_ops { | ||
65 | struct module *owner; | ||
62 | int (*add)(struct soc_camera_device *); | 66 | int (*add)(struct soc_camera_device *); |
63 | void (*remove)(struct soc_camera_device *); | 67 | void (*remove)(struct soc_camera_device *); |
64 | int (*set_fmt_cap)(struct soc_camera_device *, __u32, | 68 | int (*set_fmt_cap)(struct soc_camera_device *, __u32, |
@@ -88,8 +92,7 @@ static inline struct soc_camera_host *to_soc_camera_host(struct device *dev) | |||
88 | return container_of(dev, struct soc_camera_host, dev); | 92 | return container_of(dev, struct soc_camera_host, dev); |
89 | } | 93 | } |
90 | 94 | ||
91 | extern int soc_camera_host_register(struct soc_camera_host *ici, | 95 | extern int soc_camera_host_register(struct soc_camera_host *ici); |
92 | struct module *owner); | ||
93 | extern void soc_camera_host_unregister(struct soc_camera_host *ici); | 96 | extern void soc_camera_host_unregister(struct soc_camera_host *ici); |
94 | extern int soc_camera_device_register(struct soc_camera_device *icd); | 97 | extern int soc_camera_device_register(struct soc_camera_device *icd); |
95 | extern void soc_camera_device_unregister(struct soc_camera_device *icd); | 98 | extern void soc_camera_device_unregister(struct soc_camera_device *icd); |