aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb/media
diff options
context:
space:
mode:
authorLuca Risolia <luca.risolia@studio.unibo.it>2006-01-13 12:19:43 -0500
committerGreg Kroah-Hartman <gregkh@suse.de>2006-01-31 20:23:38 -0500
commitcd6fcc555fe278263880abdb93352ab205099db9 (patch)
treede09c1d3183ed41c1eef653d90a29a03370b2128 /drivers/usb/media
parente988fc8a56bb3f76624dd7b0fb13ae3eaccefa59 (diff)
[PATCH] USB: SN9C10x driver updates
SN9C10x driver updates: - Use kzalloc() instead of kmalloc() - Move some macro definitions from sn9c102.h to sn9c102_core.c - Use vfree() and vmalloc_32() instead of rvfree() and rvmalloc() - Fix mmap() sys call - Documentation updates Signed-off-by: Luca Risolia <luca.risolia@studio.unibo.it> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers/usb/media')
-rw-r--r--drivers/usb/media/sn9c102.h27
-rw-r--r--drivers/usb/media/sn9c102_core.c92
-rw-r--r--drivers/usb/media/sn9c102_sensor.h16
3 files changed, 46 insertions, 89 deletions
diff --git a/drivers/usb/media/sn9c102.h b/drivers/usb/media/sn9c102.h
index 967c6b6bc0fa..17d60c1eea7e 100644
--- a/drivers/usb/media/sn9c102.h
+++ b/drivers/usb/media/sn9c102.h
@@ -23,7 +23,8 @@
23 23
24#include <linux/version.h> 24#include <linux/version.h>
25#include <linux/usb.h> 25#include <linux/usb.h>
26#include <linux/videodev.h> 26#include <linux/videodev2.h>
27#include <media/v4l2-common.h>
27#include <linux/device.h> 28#include <linux/device.h>
28#include <linux/list.h> 29#include <linux/list.h>
29#include <linux/spinlock.h> 30#include <linux/spinlock.h>
@@ -52,13 +53,6 @@
52 53
53/*****************************************************************************/ 54/*****************************************************************************/
54 55
55#define SN9C102_MODULE_NAME "V4L2 driver for SN9C10x PC Camera Controllers"
56#define SN9C102_MODULE_AUTHOR "(C) 2004-2006 Luca Risolia"
57#define SN9C102_AUTHOR_EMAIL "<luca.risolia@studio.unibo.it>"
58#define SN9C102_MODULE_LICENSE "GPL"
59#define SN9C102_MODULE_VERSION "1:1.25"
60#define SN9C102_MODULE_VERSION_CODE KERNEL_VERSION(1, 0, 25)
61
62enum sn9c102_bridge { 56enum sn9c102_bridge {
63 BRIDGE_SN9C101 = 0x01, 57 BRIDGE_SN9C101 = 0x01,
64 BRIDGE_SN9C102 = 0x02, 58 BRIDGE_SN9C102 = 0x02,
@@ -119,8 +113,6 @@ static DECLARE_MUTEX(sn9c102_sysfs_lock);
119static DECLARE_RWSEM(sn9c102_disconnect); 113static DECLARE_RWSEM(sn9c102_disconnect);
120 114
121struct sn9c102_device { 115struct sn9c102_device {
122 struct device dev;
123
124 struct video_device* v4ldev; 116 struct video_device* v4ldev;
125 117
126 enum sn9c102_bridge bridge; 118 enum sn9c102_bridge bridge;
@@ -161,7 +153,6 @@ sn9c102_attach_sensor(struct sn9c102_device* cam,
161 struct sn9c102_sensor* sensor) 153 struct sn9c102_sensor* sensor)
162{ 154{
163 cam->sensor = sensor; 155 cam->sensor = sensor;
164 cam->sensor->dev = &cam->dev;
165 cam->sensor->usbdev = cam->usbdev; 156 cam->sensor->usbdev = cam->usbdev;
166} 157}
167 158
@@ -174,14 +165,19 @@ sn9c102_attach_sensor(struct sn9c102_device* cam,
174do { \ 165do { \
175 if (debug >= (level)) { \ 166 if (debug >= (level)) { \
176 if ((level) == 1) \ 167 if ((level) == 1) \
177 dev_err(&cam->dev, fmt "\n", ## args); \ 168 dev_err(&cam->usbdev->dev, fmt "\n", ## args); \
178 else if ((level) == 2) \ 169 else if ((level) == 2) \
179 dev_info(&cam->dev, fmt "\n", ## args); \ 170 dev_info(&cam->usbdev->dev, fmt "\n", ## args); \
180 else if ((level) >= 3) \ 171 else if ((level) >= 3) \
181 dev_info(&cam->dev, "[%s:%d] " fmt "\n", \ 172 dev_info(&cam->usbdev->dev, "[%s:%d] " fmt "\n", \
182 __FUNCTION__, __LINE__ , ## args); \ 173 __FUNCTION__, __LINE__ , ## args); \
183 } \ 174 } \
184} while (0) 175} while (0)
176# define V4LDBG(level, name, cmd) \
177do { \
178 if (debug >= (level)) \
179 v4l_print_ioctl(name, cmd); \
180} while (0)
185# define KDBG(level, fmt, args...) \ 181# define KDBG(level, fmt, args...) \
186do { \ 182do { \
187 if (debug >= (level)) { \ 183 if (debug >= (level)) { \
@@ -193,8 +189,9 @@ do { \
193 } \ 189 } \
194} while (0) 190} while (0)
195#else 191#else
196# define KDBG(level, fmt, args...) do {;} while(0)
197# define DBG(level, fmt, args...) do {;} while(0) 192# define DBG(level, fmt, args...) do {;} while(0)
193# define V4LDBG(level, name, cmd) do {;} while(0)
194# define KDBG(level, fmt, args...) do {;} while(0)
198#endif 195#endif
199 196
200#undef PDBG 197#undef PDBG
diff --git a/drivers/usb/media/sn9c102_core.c b/drivers/usb/media/sn9c102_core.c
index 6090439663ee..c81397e4714b 100644
--- a/drivers/usb/media/sn9c102_core.c
+++ b/drivers/usb/media/sn9c102_core.c
@@ -45,6 +45,15 @@
45 45
46/*****************************************************************************/ 46/*****************************************************************************/
47 47
48#define SN9C102_MODULE_NAME "V4L2 driver for SN9C10x PC Camera Controllers"
49#define SN9C102_MODULE_AUTHOR "(C) 2004-2006 Luca Risolia"
50#define SN9C102_AUTHOR_EMAIL "<luca.risolia@studio.unibo.it>"
51#define SN9C102_MODULE_LICENSE "GPL"
52#define SN9C102_MODULE_VERSION "1:1.26"
53#define SN9C102_MODULE_VERSION_CODE KERNEL_VERSION(1, 0, 26)
54
55/*****************************************************************************/
56
48MODULE_DEVICE_TABLE(usb, sn9c102_id_table); 57MODULE_DEVICE_TABLE(usb, sn9c102_id_table);
49 58
50MODULE_AUTHOR(SN9C102_MODULE_AUTHOR " " SN9C102_AUTHOR_EMAIL); 59MODULE_AUTHOR(SN9C102_MODULE_AUTHOR " " SN9C102_AUTHOR_EMAIL);
@@ -115,50 +124,6 @@ static sn9c102_eof_header_t sn9c102_eof_header[] = {
115 124
116/*****************************************************************************/ 125/*****************************************************************************/
117 126
118static void* rvmalloc(size_t size)
119{
120 void* mem;
121 unsigned long adr;
122
123 size = PAGE_ALIGN(size);
124
125 mem = vmalloc_32((unsigned long)size);
126 if (!mem)
127 return NULL;
128
129 memset(mem, 0, size);
130
131 adr = (unsigned long)mem;
132 while (size > 0) {
133 SetPageReserved(vmalloc_to_page((void *)adr));
134 adr += PAGE_SIZE;
135 size -= PAGE_SIZE;
136 }
137
138 return mem;
139}
140
141
142static void rvfree(void* mem, size_t size)
143{
144 unsigned long adr;
145
146 if (!mem)
147 return;
148
149 size = PAGE_ALIGN(size);
150
151 adr = (unsigned long)mem;
152 while (size > 0) {
153 ClearPageReserved(vmalloc_to_page((void *)adr));
154 adr += PAGE_SIZE;
155 size -= PAGE_SIZE;
156 }
157
158 vfree(mem);
159}
160
161
162static u32 127static u32
163sn9c102_request_buffers(struct sn9c102_device* cam, u32 count, 128sn9c102_request_buffers(struct sn9c102_device* cam, u32 count,
164 enum sn9c102_io_method io) 129 enum sn9c102_io_method io)
@@ -177,7 +142,7 @@ sn9c102_request_buffers(struct sn9c102_device* cam, u32 count,
177 142
178 cam->nbuffers = count; 143 cam->nbuffers = count;
179 while (cam->nbuffers > 0) { 144 while (cam->nbuffers > 0) {
180 if ((buff = rvmalloc(cam->nbuffers * PAGE_ALIGN(imagesize)))) 145 if ((buff = vmalloc_32(cam->nbuffers * PAGE_ALIGN(imagesize))))
181 break; 146 break;
182 cam->nbuffers--; 147 cam->nbuffers--;
183 } 148 }
@@ -201,8 +166,7 @@ sn9c102_request_buffers(struct sn9c102_device* cam, u32 count,
201static void sn9c102_release_buffers(struct sn9c102_device* cam) 166static void sn9c102_release_buffers(struct sn9c102_device* cam)
202{ 167{
203 if (cam->nbuffers) { 168 if (cam->nbuffers) {
204 rvfree(cam->frame[0].bufmem, 169 vfree(cam->frame[0].bufmem);
205 cam->nbuffers * PAGE_ALIGN(cam->frame[0].buf.length));
206 cam->nbuffers = 0; 170 cam->nbuffers = 0;
207 } 171 }
208 cam->frame_current = NULL; 172 cam->frame_current = NULL;
@@ -745,7 +709,7 @@ static int sn9c102_start_transfer(struct sn9c102_device* cam)
745 int err = 0; 709 int err = 0;
746 710
747 for (i = 0; i < SN9C102_URBS; i++) { 711 for (i = 0; i < SN9C102_URBS; i++) {
748 cam->transfer_buffer[i] = kmalloc(SN9C102_ISO_PACKETS * psz, 712 cam->transfer_buffer[i] = kzalloc(SN9C102_ISO_PACKETS * psz,
749 GFP_KERNEL); 713 GFP_KERNEL);
750 if (!cam->transfer_buffer[i]) { 714 if (!cam->transfer_buffer[i]) {
751 err = -ENOMEM; 715 err = -ENOMEM;
@@ -865,6 +829,7 @@ static int sn9c102_stream_interrupt(struct sn9c102_device* cam)
865 829
866/*****************************************************************************/ 830/*****************************************************************************/
867 831
832#ifdef CONFIG_VIDEO_ADV_DEBUG
868static u8 sn9c102_strtou8(const char* buff, size_t len, ssize_t* count) 833static u8 sn9c102_strtou8(const char* buff, size_t len, ssize_t* count)
869{ 834{
870 char str[5]; 835 char str[5];
@@ -1289,6 +1254,7 @@ static void sn9c102_create_sysfs(struct sn9c102_device* cam)
1289 video_device_create_file(v4ldev, &class_device_attr_i2c_val); 1254 video_device_create_file(v4ldev, &class_device_attr_i2c_val);
1290 } 1255 }
1291} 1256}
1257#endif /* CONFIG_VIDEO_ADV_DEBUG */
1292 1258
1293/*****************************************************************************/ 1259/*****************************************************************************/
1294 1260
@@ -1754,9 +1720,8 @@ static int sn9c102_mmap(struct file* filp, struct vm_area_struct *vma)
1754{ 1720{
1755 struct sn9c102_device* cam = video_get_drvdata(video_devdata(filp)); 1721 struct sn9c102_device* cam = video_get_drvdata(video_devdata(filp));
1756 unsigned long size = vma->vm_end - vma->vm_start, 1722 unsigned long size = vma->vm_end - vma->vm_start,
1757 start = vma->vm_start, 1723 start = vma->vm_start;
1758 pos, 1724 void *pos;
1759 page;
1760 u32 i; 1725 u32 i;
1761 1726
1762 if (down_interruptible(&cam->fileop_sem)) 1727 if (down_interruptible(&cam->fileop_sem))
@@ -1790,15 +1755,12 @@ static int sn9c102_mmap(struct file* filp, struct vm_area_struct *vma)
1790 return -EINVAL; 1755 return -EINVAL;
1791 } 1756 }
1792 1757
1793 /* VM_IO is eventually going to replace PageReserved altogether */
1794 vma->vm_flags |= VM_IO; 1758 vma->vm_flags |= VM_IO;
1795 vma->vm_flags |= VM_RESERVED; /* avoid to swap out this VMA */ 1759 vma->vm_flags |= VM_RESERVED;
1796 1760
1797 pos = (unsigned long)cam->frame[i].bufmem; 1761 pos = cam->frame[i].bufmem;
1798 while (size > 0) { /* size is page-aligned */ 1762 while (size > 0) { /* size is page-aligned */
1799 page = vmalloc_to_pfn((void *)pos); 1763 if (vm_insert_page(vma, start, vmalloc_to_page(pos))) {
1800 if (remap_pfn_range(vma, start, page, PAGE_SIZE,
1801 vma->vm_page_prot)) {
1802 up(&cam->fileop_sem); 1764 up(&cam->fileop_sem);
1803 return -EAGAIN; 1765 return -EAGAIN;
1804 } 1766 }
@@ -1831,7 +1793,8 @@ sn9c102_vidioc_querycap(struct sn9c102_device* cam, void __user * arg)
1831 1793
1832 strlcpy(cap.card, cam->v4ldev->name, sizeof(cap.card)); 1794 strlcpy(cap.card, cam->v4ldev->name, sizeof(cap.card));
1833 if (usb_make_path(cam->usbdev, cap.bus_info, sizeof(cap.bus_info)) < 0) 1795 if (usb_make_path(cam->usbdev, cap.bus_info, sizeof(cap.bus_info)) < 0)
1834 strlcpy(cap.bus_info, cam->dev.bus_id, sizeof(cap.bus_info)); 1796 strlcpy(cap.bus_info, cam->usbdev->dev.bus_id,
1797 sizeof(cap.bus_info));
1835 1798
1836 if (copy_to_user(arg, &cap, sizeof(cap))) 1799 if (copy_to_user(arg, &cap, sizeof(cap)))
1837 return -EFAULT; 1800 return -EFAULT;
@@ -1852,7 +1815,7 @@ sn9c102_vidioc_enuminput(struct sn9c102_device* cam, void __user * arg)
1852 return -EINVAL; 1815 return -EINVAL;
1853 1816
1854 memset(&i, 0, sizeof(i)); 1817 memset(&i, 0, sizeof(i));
1855 strcpy(i.name, "USB"); 1818 strcpy(i.name, "Camera");
1856 1819
1857 if (copy_to_user(arg, &i, sizeof(i))) 1820 if (copy_to_user(arg, &i, sizeof(i)))
1858 return -EFAULT; 1821 return -EFAULT;
@@ -2708,6 +2671,8 @@ static int sn9c102_ioctl(struct inode* inode, struct file* filp,
2708 return -EIO; 2671 return -EIO;
2709 } 2672 }
2710 2673
2674 V4LDBG(3, "sn9c102", cmd);
2675
2711 err = sn9c102_ioctl_v4l2(inode, filp, cmd, (void __user *)arg); 2676 err = sn9c102_ioctl_v4l2(inode, filp, cmd, (void __user *)arg);
2712 2677
2713 up(&cam->fileop_sem); 2678 up(&cam->fileop_sem);
@@ -2740,13 +2705,12 @@ sn9c102_usb_probe(struct usb_interface* intf, const struct usb_device_id* id)
2740 unsigned int i; 2705 unsigned int i;
2741 int err = 0, r; 2706 int err = 0, r;
2742 2707
2743 if (!(cam = kmalloc(sizeof(struct sn9c102_device), GFP_KERNEL))) 2708 if (!(cam = kzalloc(sizeof(struct sn9c102_device), GFP_KERNEL)))
2744 return -ENOMEM; 2709 return -ENOMEM;
2745 2710
2746 cam->usbdev = udev; 2711 cam->usbdev = udev;
2747 memcpy(&cam->dev, &udev->dev, sizeof(struct device));
2748 2712
2749 if (!(cam->control_buffer = kmalloc(8, GFP_KERNEL))) { 2713 if (!(cam->control_buffer = kzalloc(8, GFP_KERNEL))) {
2750 DBG(1, "kmalloc() failed"); 2714 DBG(1, "kmalloc() failed");
2751 err = -ENOMEM; 2715 err = -ENOMEM;
2752 goto fail; 2716 goto fail;
@@ -2806,7 +2770,7 @@ sn9c102_usb_probe(struct usb_interface* intf, const struct usb_device_id* id)
2806 strcpy(cam->v4ldev->name, "SN9C10x PC Camera"); 2770 strcpy(cam->v4ldev->name, "SN9C10x PC Camera");
2807 cam->v4ldev->owner = THIS_MODULE; 2771 cam->v4ldev->owner = THIS_MODULE;
2808 cam->v4ldev->type = VID_TYPE_CAPTURE | VID_TYPE_SCALES; 2772 cam->v4ldev->type = VID_TYPE_CAPTURE | VID_TYPE_SCALES;
2809 cam->v4ldev->hardware = VID_HARDWARE_SN9C102; 2773 cam->v4ldev->hardware = 0;
2810 cam->v4ldev->fops = &sn9c102_fops; 2774 cam->v4ldev->fops = &sn9c102_fops;
2811 cam->v4ldev->minor = video_nr[dev_nr]; 2775 cam->v4ldev->minor = video_nr[dev_nr];
2812 cam->v4ldev->release = video_device_release; 2776 cam->v4ldev->release = video_device_release;
@@ -2832,8 +2796,10 @@ sn9c102_usb_probe(struct usb_interface* intf, const struct usb_device_id* id)
2832 2796
2833 dev_nr = (dev_nr < SN9C102_MAX_DEVICES-1) ? dev_nr+1 : 0; 2797 dev_nr = (dev_nr < SN9C102_MAX_DEVICES-1) ? dev_nr+1 : 0;
2834 2798
2799#ifdef CONFIG_VIDEO_ADV_DEBUG
2835 sn9c102_create_sysfs(cam); 2800 sn9c102_create_sysfs(cam);
2836 DBG(2, "Optional device control through 'sysfs' interface ready"); 2801 DBG(2, "Optional device control through 'sysfs' interface ready");
2802#endif
2837 2803
2838 usb_set_intfdata(intf, cam); 2804 usb_set_intfdata(intf, cam);
2839 2805
diff --git a/drivers/usb/media/sn9c102_sensor.h b/drivers/usb/media/sn9c102_sensor.h
index a0e561b2c852..7d953b24f2f2 100644
--- a/drivers/usb/media/sn9c102_sensor.h
+++ b/drivers/usb/media/sn9c102_sensor.h
@@ -196,10 +196,11 @@ extern int sn9c102_pread_reg(struct sn9c102_device*, u16 index);
196/* 196/*
197 NOTE: there are no exported debugging functions. To uniform the output you 197 NOTE: there are no exported debugging functions. To uniform the output you
198 must use the dev_info()/dev_warn()/dev_err() macros defined in device.h, 198 must use the dev_info()/dev_warn()/dev_err() macros defined in device.h,
199 already included here, the argument being the struct device 'dev' of the 199 already included here, the argument being the struct device '&usbdev->dev'
200 sensor structure. Do NOT use these macros before the sensor is attached or 200 of the sensor structure. Do NOT use these macros before the sensor is
201 the kernel will crash! However, you should not need to notify the user about 201 attached or the kernel will crash! However, you should not need to notify
202 common errors or other messages, since this is done by the master module. 202 the user about common errors or other messages, since this is done by the
203 master module.
203*/ 204*/
204 205
205/*****************************************************************************/ 206/*****************************************************************************/
@@ -358,13 +359,6 @@ struct sn9c102_sensor {
358 error code without rolling back. 359 error code without rolling back.
359 */ 360 */
360 361
361 const struct device* dev;
362 /*
363 This is the argument for dev_err(), dev_info() and dev_warn(). It
364 is used for debugging purposes. You must not access the struct
365 before the sensor is attached.
366 */
367
368 const struct usb_device* usbdev; 362 const struct usb_device* usbdev;
369 /* 363 /*
370 Points to the usb_device struct after the sensor is attached. 364 Points to the usb_device struct after the sensor is attached.