From: <hap...@us...> - 2007-06-22 21:00:28
|
Revision: 1046 http://svn.sourceforge.net/hackndev/?rev=1046&view=rev Author: happy-slapin Date: 2007-06-22 14:00:23 -0700 (Fri, 22 Jun 2007) Log Message: ----------- OV9640: Fixed i2c driver Modified Paths: -------------- linux4palm/linux/trunk/drivers/i2c/chips/Kconfig linux4palm/linux/trunk/drivers/i2c/chips/Makefile linux4palm/linux/trunk/drivers/i2c/chips/i2c-ov9640.c linux4palm/linux/trunk/drivers/i2c/chips/i2c-ov9640.h Modified: linux4palm/linux/trunk/drivers/i2c/chips/Kconfig =================================================================== --- linux4palm/linux/trunk/drivers/i2c/chips/Kconfig 2007-06-22 20:03:14 UTC (rev 1045) +++ linux4palm/linux/trunk/drivers/i2c/chips/Kconfig 2007-06-22 21:00:23 UTC (rev 1046) @@ -150,4 +150,10 @@ This driver can also be built as a module. If so, the module will be called max6875. +config I2C_OV9640 + tristate "Support for OmniVision 9640 camera sensor" + depends on I2C + help + Say yes here to enable OV9640 sensor which is found in some + handhelds and phones endmenu Modified: linux4palm/linux/trunk/drivers/i2c/chips/Makefile =================================================================== --- linux4palm/linux/trunk/drivers/i2c/chips/Makefile 2007-06-22 20:03:14 UTC (rev 1045) +++ linux4palm/linux/trunk/drivers/i2c/chips/Makefile 2007-06-22 21:00:23 UTC (rev 1046) @@ -15,8 +15,10 @@ obj-$(CONFIG_ISP1301_OMAP) += isp1301_omap.o obj-$(CONFIG_TPS65010) += tps65010.o -obj-$(CONFIG_I2C_ADCM2650) +=adcm2650-i2c.o +obj-$(CONFIG_I2C_ADCM2650) += adcm2650-i2c.o +obj-$(CONFIG_I2C_OV9640) += i2c-ov9640.o + ifeq ($(CONFIG_I2C_DEBUG_CHIP),y) EXTRA_CFLAGS += -DDEBUG endif Modified: linux4palm/linux/trunk/drivers/i2c/chips/i2c-ov9640.c =================================================================== --- linux4palm/linux/trunk/drivers/i2c/chips/i2c-ov9640.c 2007-06-22 20:03:14 UTC (rev 1045) +++ linux4palm/linux/trunk/drivers/i2c/chips/i2c-ov9640.c 2007-06-22 21:00:23 UTC (rev 1046) @@ -13,63 +13,48 @@ #define DPRINTK(fmt,args...) do { if (DEBUG) printk("in function %s "fmt,__FUNCTION__,##args);} while(0) extern int i2c_adapter_id(struct i2c_adapter *adap); -int i2c_ov9640_cleanup(void); -void i2c_ov9640_inc_use (struct i2c_client *client); -void i2c_ov9640_dec_use (struct i2c_client *client); -int i2c_ov9640_attach_adapter(struct i2c_adapter *adapter); -int i2c_ov9640_detect_client(struct i2c_adapter *, int, unsigned short, int); -int i2c_ov9640_detach_client(struct i2c_client *client); +void i2c_ov9640_cleanup(void); +static int i2c_ov9640_attach_adapter(struct i2c_adapter *adapter); +static int i2c_ov9640_detect_client(struct i2c_adapter *, int, int); +static int i2c_ov9640_detach_client(struct i2c_client *client); struct i2c_driver ov9640_driver = { - name: "ov9640 driver", /* name */ - id: I2C_DRIVERID_OV9640, /* id */ - flags: I2C_DF_NOTIFY, /* flags */ - attach_adapter: &i2c_ov9640_attach_adapter, /* attach_adapter */ - detach_client: &i2c_ov9640_detach_client, /* detach_client */ - command: NULL, - inc_use: &i2c_ov9640_inc_use, - dec_use: &i2c_ov9640_dec_use + .driver = { + .name = "i2c-ov9640", /* name */ + }, + .attach_adapter = &i2c_ov9640_attach_adapter, /* attach_adapter */ + .detach_client = &i2c_ov9640_detach_client, /* detach_client */ }; extern struct i2c_adapter *i2cdev_adaps[]; -/* Unique ID allocation */ -static int ov9640_id = 0; struct i2c_client *g_client = NULL; static unsigned short normal_i2c[] = {OV9640_SLAVE_ADDR ,I2C_CLIENT_END }; -static unsigned short normal_i2c_range[] = { I2C_CLIENT_END }; +/* static unsigned short normal_i2c_range[] = { I2C_CLIENT_END }; */ I2C_CLIENT_INSMOD; -/* - * This call returns a unique low identifier for each registered adapter, - * or -1 if the adapter was not registered. - */ -void i2c_ov9640_inc_use (struct i2c_client *client) -{ - MOD_INC_USE_COUNT; -#ifdef MODULE -#endif -} - -void i2c_ov9640_dec_use (struct i2c_client *client) -{ - MOD_DEC_USE_COUNT; -#ifdef MODULE -#endif -} - char ov9640_read(u8 addr, u8 *pvalue) { - int res=0; - char buf=0; - struct i2c_msg msgs[2] = { - { 0, I2C_M_WR, 1, &addr }, - { 0, I2C_M_RD, 1, &buf }}; + int res = 0; + char buf = 0; + struct i2c_msg msgs[2]; + struct ov9640_data * p; if( g_client == NULL ) return -1; - i2c_ov9640_inc_use(g_client); - msgs[0].addr=msgs[1].addr=g_client->addr; + p = i2c_get_clientdata(g_client); + + msgs[0].addr = g_client->addr; + msgs[0].flags = 0; + msgs[0].len = 1; + msgs[0].buf = &addr; + + msgs[1].addr = g_client->addr; + msgs[1].flags = I2C_M_RD; + msgs[1].len = 1; + msgs[1].buf = &buf; + + down(&p->update_lock); res=i2c_transfer(g_client->adapter,&msgs[0],1); if (res<=0) goto out; @@ -77,7 +62,7 @@ if (res<=0) goto out; *pvalue = buf; - i2c_ov9640_dec_use(g_client); + up(&p->update_lock); out: DPRINTK(KERN_INFO "In funtion %s addr:%x,value=%x\n", __FUNCTION__, addr,*pvalue); if (res<=0) DPRINTK("res = %d \n",res); @@ -86,27 +71,16 @@ int ov9640_write(u8 addr, u8 value) { - int res=0; + int res = 0; + char buf[2] = {addr, value}; + + struct ov9640_data * p; if( g_client == NULL ) return -1; - /* - char buf=0; - struct i2c_msg msgs[2] = { - { 0, I2C_M_WR, 1, &addr }, - { 0, I2C_M_WR, 1, &value }}; - msgs[0].addr=msgs[1].addr=g_client->addr; - res=i2c_transfer(g_client->adapter,&msgs[0],1); - if (res<=0) return res; - res=i2c_transfer(g_client->adapter,&msgs[1],1); - if (res<=0) return res; - - - res=i2c_smbus_write_byte_data(g_client, addr, value ); - */ - char buf[2]={addr,value}; - i2c_ov9640_inc_use(g_client); + p = i2c_get_clientdata(g_client); + down(&p->update_lock); res = i2c_master_send(g_client, buf, 2); - i2c_ov9640_dec_use(g_client); + up(&p->update_lock); if (res >0) res =0; else res =-1; DPRINTK(KERN_INFO "In funtion %s addr:%x value:%xreturn %d \n", __FUNCTION__, addr,value,res); @@ -120,10 +94,6 @@ DPRINTK("in function %s\n",__FUNCTION__); i2c_master_recv(client,&msgbuf,1); return msgbuf; - /* - */ -// return i2c_smbus_read_word_data(client,reg); -// return i2c_smbus_read_byte_data(client,reg); } int i2c_ov9640_write(struct i2c_client *client, u8 reg, u16 value) @@ -139,7 +109,7 @@ } -int i2c_ov9640_detect_client(struct i2c_adapter *adapter, int address, unsigned short flags, int kind) +static int i2c_ov9640_detect_client(struct i2c_adapter *adapter, int address, int kind) { struct i2c_client *new_client; int err = 0; @@ -168,7 +138,7 @@ need it, remove it. We do it here to help to lessen memory fragmentation. */ - new_client=kmalloc(sizeof(struct i2c_client)+sizeof(struct ov9640_data), + new_client=kzalloc(sizeof(struct i2c_client)+sizeof(struct ov9640_data), GFP_KERNEL ); if ( !new_client ) { @@ -177,9 +147,8 @@ } data = (struct ov9640_data *) (new_client + 1); - new_client->addr = address; - new_client->data = data; + i2c_set_clientdata(new_client, data); new_client->adapter = adapter; new_client->driver = &ov9640_driver; new_client->flags = 0; @@ -210,8 +179,6 @@ } strcpy(new_client->name, "ov9640"); - /* Automatically unique */ - new_client->id = ov9640_id++; /* Only if you use this field */ data->valid = 0; @@ -232,7 +199,6 @@ very code-efficient in this case. */ ERROR3: -ERROR1: kfree(new_client); g_client = NULL; ERROR0: @@ -279,25 +245,22 @@ return 0; } -int i2c_ov9640_cleanup(void) +void i2c_ov9640_cleanup(void) { - int res; - if (ov9640_initialized == 1) { - if ((res = i2c_del_driver(&ov9640_driver))) { + if (i2c_del_driver(&ov9640_driver)) { DPRINTK("ov9640: Driver registration failed, module not removed.\n"); - return res; + return; } ov9640_initialized --; } - return 0; } -EXPORT_SYMBOL(i2c_ov9640_init); +//EXPORT_SYMBOL(i2c_ov9640_init); EXPORT_SYMBOL(ov9640_write); EXPORT_SYMBOL(ov9640_read); -EXPORT_SYMBOL(i2c_ov9640_cleanup); -//module_init(i2c_ov9640_init); -//module_exit(i2c_ov9640_cleanup); +//EXPORT_SYMBOL(i2c_ov9640_cleanup); +module_init(i2c_ov9640_init); +module_exit(i2c_ov9640_cleanup); MODULE_LICENSE("GPL"); Modified: linux4palm/linux/trunk/drivers/i2c/chips/i2c-ov9640.h =================================================================== --- linux4palm/linux/trunk/drivers/i2c/chips/i2c-ov9640.h 2007-06-22 20:03:14 UTC (rev 1045) +++ linux4palm/linux/trunk/drivers/i2c/chips/i2c-ov9640.h 2007-06-22 21:00:23 UTC (rev 1046) @@ -1,7 +1,9 @@ #ifndef __I2C_OV9640_H__ #define __I2C_OV9640_H__ +#ifndef DEBUG #define DEBUG +#endif /* Calculating the Module Block Number */ #define BLOCK(a) (u8)((a) >> 7) /* register's module block address. */ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |