S3C2410上webcam驱动方法(2)--完整版驱动,模块加载

   完整版的spca5xx驱动要比补丁或者 其它包要稳定得多,二者的代码差异很大,现在就参考一网友的文章进行移植处理 ,详细的过程的过程,和可能出现的问题都做了必要的介绍 ,如果你在移植过程中还遇到了其它新的问题,可以联系我,大家一起讨论。

我的开发板是立宇泰ARMSYS2410,内核是2.4.18-rmk7-pxa1。
1、首先下源码包spca5xx-v4l1goodbye.tar.gz spca5xx-v4l1goodbye.tar.gz  (189.43 KB , 下载:6次),然后解压(如果这个地址不能下载 ,就自己在网上搜索 一下,如果没有找到相应文件,可以联系我:[email protected])
#tar -xzvf spca5xx-v4l1goodbye.tar.gz
解压后得到一个spca5xx-v4l1goodbye目录,里边是spca5xx-v4l1goodbye的源代码。

2、修改Makefile
#cd spca5xx-v4l1goodbye
#gedit Makefile&


ifneq ($(shell uname -r | cut -d. -f1,2), 2.4)

ifneq ($(KERNELRELEASE),) # We were called by kbuild
CFLAGS += $(DEFINES)
obj-m += spca5xx.o
spca5xx-objs := drivers/usb/spca5xx.o drivers/usb/spcadecoder.o

else # We were called from command line

KERNEL_VERSION = `uname -r`
KERNELDIR := /lib/modules/$(KERNEL_VERSION)/build
PWD := $(shell pwd)
MODULE_INSTALLDIR = /lib/modules/$(KERNEL_VERSION)/kernel/drivers/usb/media/

# Targets, don't change!
default:
@echo ' Building SPCA5XX driver for 2.5/2.6 kernel.'
@echo ' Remember: you must have read/write access to your kernel source tree.'
$(MAKE) -C $(KERNELDIR) SUBDIRS=$(PWD) CC=$(CC) modules

install:
mkdir -p $(MODULE_INSTALLDIR)
rm -f $(MODULE_INSTALLDIR)spca50x.ko
rm -f $(MODULE_INSTALLDIR)et61x.ko
install -c -m 0644 spca5xx.ko $(MODULE_INSTALLDIR)
/sbin/depmod -ae

uninstall:
rm -f $(MODULE_INSTALLDIR)/spca5xx.ko
/sbin/depmod -aq

endif

else # kernel version test
以及
endif # End kernel version test
删除,应为这些都是针对2.6内核的,我们不需要。

KERNEL_VERSION = `uname -r`
替换为自己的内核版本号,我的是
KERNEL_VERSION = 2.4.18-rmk7-pxa1

KINCLUDE = /lib/modules/$(KERNEL_VERSION)/build/include
替换为自己的内核的代码路径
KINCLUDE = /root/software/kernel/include

CC = gcc
LD = ld
替换为
CC = /usr/local/arm/2.95.3/bin/arm-linux-gcc
LD = /usr/local/arm/2.95.3/bin/arm-linux-ld

3、修改scpca5xx目录下spca5xx.c
找到定义spca5xx_driver的地方,将原来的定义

#if LINUX_VERSION_CODE > KERNEL_VERSION(2,4,22)
static struct usb_driver spca5xx_driver = {
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,16)
.owner = THIS_MODULE,
#endif
.name = "spca5xx",
.id_table = device_table,
.probe = spca5xx_probe,
.disconnect = spca5xx_disconnect
};
#else
static struct usb_driver spca5xx_driver = {
#if LINUX_VERSION_CODE > KERNEL_VERSION(2,4,20)
THIS_MODULE,
#endif
"spca5xx",
spca5xx_probe,
spca5xx_disconnect,
{NULL, NULL}
};
#endif

替换为下边的内容:

static struct usb_driver spca5xx_driver = {
.name: "spca5xx",
.id_table: device_table,
.probe: spca5xx_probe,
.disconnect: spca5xx_disconnect
};
找到spca5xx_probe函数定义的地方,将原来的

#if LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0)
static int
spca5xx_probe(struct usb_interface *intf, const struct usb_device_id *id)
#else
static void *spca5xx_probe(struct usb_device *dev, unsigned int ifnum,
const struct usb_device_id *id)
#endif

替换为:

static void *
spca5xx_probe (struct usb_device *dev, unsigned int ifnum,
const struct usb_device_id *id)
如果不修改这两个地方,编译不会有问题,但是驱动不能工作。

#CFLAGS += -mpreferred-stack-boundary=2 这个注释掉,否则编译通不过

4、编译
#make

///////////////////////////////////////
可能出现的问题:
================================================
1.缺少linux/autoconfig.h,或者linux/version.h,
解决方法:用选择正确的内核。
================================================
2.[root@localhost spca5xx-20060402]# make
Compiling drivers/usb/spca5xx.c
In file included from /lib/modules/2.4.20-8/build/include/linux/vmalloc.h:8,
from drivers/usb/spca5xx.c:46:
/lib/modules/2.4.20-8/build/include/linux/highmem.h: In function `bh_kmap':
/lib/modules/2.4.20-8/build/include/linux/highmem.h:20: warning: pointer of
type `void *' used in arithmetic
drivers/usb/spca5xx.c: In function `spca5xx_mmap':
drivers/usb/spca5xx.c:5131: warning: passing arg 1 of
`remap_page_range_R2baf18f2' makes pointer from integer without a cast
drivers/usb/spca5xx.c:5131: incompatible type for argument 4 of
`remap_page_range_R2baf18f2'
drivers/usb/spca5xx.c:5131: too few arguments to function
`remap_page_range_R2baf18f2'
drivers/usb/spca5xx.c: At top level:
..........
make: *** [drivers/usb/spca5xx.o] Error 1

解决办法:
打开源码 spca5xx.c中的spca5xx_mmap,可以发现在这个函数的调用上RH9和RH9以上的版本调用的都不是同一条函数,在 remap_page_range()函数的第一个参数对于RH9就没有做定义,为定义情况下在RH9调用remap_page_range()就缺少了 第一个参数的描述,一个小bug在这里,只要在出错的remap_page_range参数添加第一个参数,设为0,编译就通过了,还有几个 warming可以忽略。
===================================================================
3.#CFLAGS += -mpreferred-stack-boundary=2 这个注释掉,否则编译通不过

在spca5xx-v4l1goodbye目录下生成spca5xx.o文件,这就是我们需要的驱动。将这个文件拷到开发板的文件系统里。
===================================================================
5、将驱动加载到内核
#/sbin/insmod spca5xx.o
Using spca5xx.o
drivers/usb/spca5xx.c: Unable to initialise /proc/video/spca50x//提示无法初始化,先不管
usb.c: registered new driver spca5xx
drivers/usb/spca5xx.c: spca5xx driver 00.60.00.1 registered

插上你的zc301摄像头,就可以看到如下的信息
[root@lyt /]# hub.c: new USB device usb-ohci-1, assigned address 2
Manufacturer: Vimicro Corp.
Product: PC Camera
drivers/usb/spca5xx.c: USB SPCA5XX camera found. Type Vimicro Zc301P 0x303b
drivers/usb/spca5xx.c: [spca5xx_probe:5488] Camera type JPEG
drivers/usb/zc3xx.h: [zc3xx_config:527] Find Sensor PB0330
drivers/usb/spca5xx.c: [spca5xx_getcapability:1767] maxw 640 maxh 480 minw 176 minh 144
同时在/dev下创建了v4l/video0设备文件。
恭喜你的摄像头现在可以使用了。

你可能感兴趣的:(S3C2410上webcam驱动方法(2)--完整版驱动,模块加载)