/******************************************************************************* ** ** FUNCTION: flashDrv_open ** ___________________________________________________________________________ ** ** DESCRIPTION: open Flash driver file descriptor ** ** INPUTS: inode - inode structure ** file - file structure ** ** OUTPUTS: NONE ** ** RETURNS: function result ** *******************************************************************************/ static int flashDrv_open(struct inode *inode, struct file *file) { DRV_LOCK(); /* return OK */ return 0; }
int i2c_add_driver(struct i2c_driver *driver) { int i; DRV_LOCK(); for (i = 0; i < I2C_DRIVER_MAX; i++) if (NULL == drivers[i]) break; if (I2C_DRIVER_MAX == i) { printk(KERN_WARNING " i2c-core.o: register_driver(%s) " "- enlarge I2C_DRIVER_MAX.\n", driver->name); DRV_UNLOCK(); return -ENOMEM; } drivers[i] = driver; driver_count++; DRV_UNLOCK(); /* driver was successfully added */ DEB(printk(KERN_DEBUG "i2c-core.o: driver %s registered.\n",driver->name)); ADAP_LOCK(); /* now look for instances of driver on our adapters */ if (driver->flags& (I2C_DF_NOTIFY|I2C_DF_DUMMY)) { for (i=0;i<I2C_ADAP_MAX;i++) if (adapters[i]!=NULL) /* Ignore errors */ driver->attach_adapter(adapters[i]); } ADAP_UNLOCK(); return 0; }
int i2c_del_driver(struct i2c_driver *driver) { int i,j,k,res; DRV_LOCK(); for (i = 0; i < I2C_DRIVER_MAX; i++) if (driver == drivers[i]) break; if (I2C_DRIVER_MAX == i) { printk(KERN_WARNING " i2c-core.o: unregister_driver: " "[%s] not found\n", driver->name); DRV_UNLOCK(); return -ENODEV; } /* Have a look at each adapter, if clients of this driver are still * attached. If so, detach them to be able to kill the driver * afterwards. */ DEB2(printk(KERN_DEBUG "i2c-core.o: unregister_driver - looking for clients.\n")); /* removing clients does not depend on the notify flag, else * invalid operation might (will!) result, when using stale client * pointers. */ ADAP_LOCK(); /* should be moved inside the if statement... */ for (k=0;k<I2C_ADAP_MAX;k++) { struct i2c_adapter *adap = adapters[k]; if (adap == NULL) /* skip empty entries. */ continue; DEB2(printk(KERN_DEBUG "i2c-core.o: examining adapter %s:\n", adap->name)); if (driver->flags & I2C_DF_DUMMY) { /* DUMMY drivers do not register their clients, so we have to * use a trick here: we call driver->attach_adapter to * *detach* it! Of course, each dummy driver should know about * this or hell will break loose... */ if ((res = driver->attach_adapter(adap))) { printk(KERN_WARNING "i2c-core.o: while unregistering " "dummy driver %s, adapter %s could " "not be detached properly; driver " "not unloaded!\n", driver->name, adap->name); ADAP_UNLOCK(); return res; } } else { for (j=0;j<I2C_CLIENT_MAX;j++) { struct i2c_client *client = adap->clients[j]; if (client != NULL && client->driver == driver) { DEB2(printk(KERN_DEBUG "i2c-core.o: " "detaching client %s:\n", client->name)); if ((res = driver-> detach_client(client))) { printk(KERN_ERR "i2c-core.o: while " "unregistering driver " "`%s', the client at " "address %02x of " "adapter `%s' could not " "be detached; driver " "not unloaded!\n", driver->name, client->addr, adap->name); ADAP_UNLOCK(); return res; } } } } } ADAP_UNLOCK(); drivers[i] = NULL; driver_count--; DRV_UNLOCK(); DEB(printk(KERN_DEBUG "i2c-core.o: driver unregistered: %s\n",driver->name)); return 0; }
int i2c_del_adapter(struct i2c_adapter *adap) { int i,j,res; ADAP_LOCK(); for (i = 0; i < I2C_ADAP_MAX; i++) if (adap == adapters[i]) break; if (I2C_ADAP_MAX == i) { printk(KERN_WARNING "i2c-core.o: unregister_adapter adap [%s] not found.\n", adap->name); res = -ENODEV; goto ERROR0; } /* DUMMY drivers do not register their clients, so we have to * use a trick here: we call driver->attach_adapter to * *detach* it! Of course, each dummy driver should know about * this or hell will break loose... */ DRV_LOCK(); for (j = 0; j < I2C_DRIVER_MAX; j++) if (drivers[j] && (drivers[j]->flags & I2C_DF_DUMMY)) if ((res = drivers[j]->attach_adapter(adap))) { printk(KERN_WARNING "i2c-core.o: can't detach adapter %s " "while detaching driver %s: driver not " "detached!\n", adap->name, drivers[j]->name); goto ERROR1; } DRV_UNLOCK(); /* detach any active clients. This must be done first, because * it can fail; in which case we give up. */ for (j=0;j<I2C_CLIENT_MAX;j++) { struct i2c_client *client = adap->clients[j]; if (client!=NULL) /* detaching devices is unconditional of the set notify * flag, as _all_ clients that reside on the adapter * must be deleted, as this would cause invalid states. */ if ((res=client->driver->detach_client(client))) { printk(KERN_ERR "i2c-core.o: adapter %s not " "unregistered, because client at " "address %02x can't be detached\n", adap->name, client->addr); goto ERROR0; } } #ifdef CONFIG_PROC_FS if (i2cproc_initialized) { char name[8]; sprintf(name,"i2c-%d", i); remove_proc_entry(name,proc_bus); } #endif /* def CONFIG_PROC_FS */ adapters[i] = NULL; adap_count--; ADAP_UNLOCK(); DEB(printk(KERN_DEBUG "i2c-core.o: adapter unregistered: %s\n",adap->name)); return 0; ERROR0: ADAP_UNLOCK(); return res; ERROR1: DRV_UNLOCK(); return res; }
/* ----- * i2c_add_adapter is called from within the algorithm layer, * when a new hw adapter registers. A new device is register to be * available for clients. */ int i2c_add_adapter(struct i2c_adapter *adap) { int i,j,res; ADAP_LOCK(); for (i = 0; i < I2C_ADAP_MAX; i++) if (NULL == adapters[i]) break; if (I2C_ADAP_MAX == i) { printk(KERN_WARNING " i2c-core.o: register_adapter(%s) - enlarge I2C_ADAP_MAX.\n", adap->name); res = -ENOMEM; goto ERROR0; } adapters[i] = adap; adap_count++; ADAP_UNLOCK(); /* init data types */ init_MUTEX(&adap->lock); #ifdef CONFIG_PROC_FS if (i2cproc_initialized) { char name[8]; struct proc_dir_entry *proc_entry; sprintf(name,"i2c-%d", i); proc_entry = create_proc_entry(name,0,proc_bus); if (! proc_entry) { printk("i2c-core.o: Could not create /proc/bus/%s\n", name); res = -ENOENT; goto ERROR1; } proc_entry->proc_fops = &i2cproc_operations; proc_entry->owner = THIS_MODULE; adap->inode = proc_entry->low_ino; } #endif /* def CONFIG_PROC_FS */ /* inform drivers of new adapters */ DRV_LOCK(); for (j=0;j<I2C_DRIVER_MAX;j++) if (drivers[j]!=NULL && (drivers[j]->flags&(I2C_DF_NOTIFY|I2C_DF_DUMMY))) /* We ignore the return code; if it fails, too bad */ drivers[j]->attach_adapter(adap); DRV_UNLOCK(); DEB(printk(KERN_DEBUG "i2c-core.o: adapter %s registered as adapter %d.\n", adap->name,i)); return 0; ERROR1: ADAP_LOCK(); adapters[i] = NULL; adap_count--; ERROR0: ADAP_UNLOCK(); return res; }