Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 77351
b: refs/heads/master
c: e9f1373
h: refs/heads/master
i:
  77349: 3e336ba
  77347: 9996412
  77343: 9f012a6
v: v3
  • Loading branch information
David Brownell authored and Jean Delvare committed Jan 27, 2008
1 parent cb043b4 commit b8a410b
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 2 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 0b987dcd3ae5626ac006fbbe366e9a8415b303df
refs/heads/master: e9f1373b643887f63878d1169b310c9acc534cd5
59 changes: 58 additions & 1 deletion trunk/drivers/i2c/i2c-core.c
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,50 @@ void i2c_unregister_device(struct i2c_client *client)
EXPORT_SYMBOL_GPL(i2c_unregister_device);


static int dummy_nop(struct i2c_client *client)
{
return 0;
}

static struct i2c_driver dummy_driver = {
.driver.name = "dummy",
.probe = dummy_nop,
.remove = dummy_nop,
};

/**
* i2c_new_dummy - return a new i2c device bound to a dummy driver
* @adapter: the adapter managing the device
* @address: seven bit address to be used
* @type: optional label used for i2c_client.name
* Context: can sleep
*
* This returns an I2C client bound to the "dummy" driver, intended for use
* with devices that consume multiple addresses. Examples of such chips
* include various EEPROMS (like 24c04 and 24c08 models).
*
* These dummy devices have two main uses. First, most I2C and SMBus calls
* except i2c_transfer() need a client handle; the dummy will be that handle.
* And second, this prevents the specified address from being bound to a
* different driver.
*
* This returns the new i2c client, which should be saved for later use with
* i2c_unregister_device(); or NULL to indicate an error.
*/
struct i2c_client *
i2c_new_dummy(struct i2c_adapter *adapter, u16 address, const char *type)
{
struct i2c_board_info info = {
.driver_name = "dummy",
.addr = address,
};

if (type)
strlcpy(info.type, type, sizeof info.type);
return i2c_new_device(adapter, &info);
}
EXPORT_SYMBOL_GPL(i2c_new_dummy);

/* ------------------------------------------------------------------------- */

/* I2C bus adapters -- one roots each I2C or SMBUS segment */
Expand Down Expand Up @@ -841,11 +885,24 @@ static int __init i2c_init(void)
retval = bus_register(&i2c_bus_type);
if (retval)
return retval;
return class_register(&i2c_adapter_class);
retval = class_register(&i2c_adapter_class);
if (retval)
goto bus_err;
retval = i2c_add_driver(&dummy_driver);
if (retval)
goto class_err;
return 0;

class_err:
class_unregister(&i2c_adapter_class);
bus_err:
bus_unregister(&i2c_bus_type);
return retval;
}

static void __exit i2c_exit(void)
{
i2c_del_driver(&dummy_driver);
class_unregister(&i2c_adapter_class);
bus_unregister(&i2c_bus_type);
}
Expand Down
6 changes: 6 additions & 0 deletions trunk/include/linux/i2c.h
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,12 @@ i2c_new_probed_device(struct i2c_adapter *adap,
struct i2c_board_info *info,
unsigned short const *addr_list);

/* For devices that use several addresses, use i2c_new_dummy() to make
* client handles for the extra addresses.
*/
extern struct i2c_client *
i2c_new_dummy(struct i2c_adapter *adap, u16 address, const char *type);

extern void i2c_unregister_device(struct i2c_client *);

/* Mainboard arch_initcall() code should register all its I2C devices.
Expand Down

0 comments on commit b8a410b

Please sign in to comment.