i2c/acpi: Support for multiple serial bus addresses
Subsystems (2)
v2 cover i2c/acpi: Support for multiple serial bus addresses
The ACPI spec allows multiple i2c addresses for a single device. This series addresses the implementation of this support in core i2c for ACPI enumeration.
v2
Restructured based on 3.17.rc3 as acpi i2c part has been moved out of i2c-core.
v1
Create an i2c device for the first valid i2c address which is not a SMBus reserved address and let the first enumerated driver use the other defined addresses by providing helper function to retrieve them.
v0
Sent on Mar 6, 2014
This patchset create an i2c device at every specified i2c serial bus address.
[PATCH 1/2] i2c/ACPI: Support for multiple serial bus addresses
Mika Westerberg (1):
i2c / ACPI: Add support for extracting multiple I2C addresses
Srinivas Pandruvada (1):
i2c / ACPI: Create device on a valid first address
drivers/i2c/i2c-acpi.c | 143 +++++++++++++++++++++++++++++++++++++++++++++++++ drivers/i2c/i2c-core.c | 61 +++++++++++++++++++++ include/linux/i2c.h | 8 +++ 3 files changed, 212 insertions(+)
Signature · 1 line
1.9.3
A message that is not in the archive (sent off-list or not yet received): 1409930466-31746-1-git-send-email-srinivas.pandruvada-VuQAYsv1563Yd54FQh9/[email protected]
PATCH v2 1/2 i2c / ACPI: Create device on a valid first address
The ACPI spec allows multiple I2cSerialBus addresses for a single device. The current logic creates a i2c device for the last I2cSerialBus address. In many configuration the first address is valid not the last one.
But in some configuration it is possible that the chosen address is not valid, so skip to next address and create a device on it.
Examples:
1.
Method (_CRS, 0, NotSerialized) // _CRS: Current Resource Settings
{
Name (RBUF, ResourceTemplate ()
{
I2cSerialBus (0x0068, ControllerInitiated, 0x00061A80,
AddressingMode7Bit, "\\_SB.I2C5",
0x00, ResourceConsumer, ,
)
I2cSerialBus (0x000C, ControllerInitiated, 0x00061A80,
AddressingMode7Bit, "\\_SB.I2C5",
0x00, ResourceConsumer, ,
)
Interrupt (ResourceConsumer, Level, ActiveHigh, Shared, ,, )
{
0x00000044,
}
})
Return (RBUF)
}This device is a combo device, where the first address is a valid address of the main controller device. So this change will create i2c device for 0x068, the first address.
2.
Method (_CRS, 0, NotSerialized) // _CRS: Current Resource Settings
{
Name (SBUF, ResourceTemplate ()
{
I2cSerialBus (0x000C, ControllerInitiated, 0x00061A80,
AddressingMode7Bit, "\\_SB.I2C3",
0x00, ResourceConsumer, ,
)
I2cSerialBus (0x0048, ControllerInitiated, 0x00061A80,
AddressingMode7Bit, "\\_SB.I2C3",
0x00, ResourceConsumer, ,
)
Interrupt (ResourceConsumer, Level, ActiveHigh, Exclusive, ,, )
{
0x00000033,
}
})
Return (SBUF)
}This device is a SMBUS compliant, where 0x0C is address of alert response address (ARA). This patch will skip 0x0C, as this is reserved address, and will create an i2c device at 0x48.
--- drivers/i2c/i2c-acpi.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+)
drivers/i2c/i2c-acpi.c +36 -0
@@ -37,6 +37,28 @@ struct gsb_buffer { }; } __packed; +static int acpi_i2c_smbus_match_reserved_addr (unsigned short addr) +{ +/* +* Reserved addresses per SMBUS specification +* in addition to i2c reserved addresses: +* 0x08 SMBUS Host +* 0x0C ARA +* 0x61 Device default address +* 0x28 Access bus host +* 0x37 Access bus default addr +*/ +int i; +u8 resvd_addrs[] = {0x08 ,0x0C ,0x061 ,0x28 ,0x37 }; + +for (i =0 ; i <ARRAY_SIZE (resvd_addrs); ++i) { +if (resvd_addrs[i] == addr) +return 0 ; + } + +return -EINVAL ; +} +static int acpi_i2c_add_resource (struct acpi_resource *ares,void *data) {struct i2c_board_info *info = data;
@@ -46,6 +68,20 @@ static int acpi_i2c_add_resource(struct acpi_resource *ares, void *data) sb = &ares->data.i2c_serial_bus;if (sb->type ==ACPI_RESOURCE_SERIAL_TYPE_I2C ) { +if (info->addr) { +/* +* We have multiple I2cSerialBus present. Check +* the validity of last parsed address. +* i2c device create rejects reserved address +* for i2C. But if the last address was an +* invalid SMBUS reserved address, skip to next +* valid address in the list and call +* i2c_new_device for this address instead. +*/ +if (acpi_i2c_smbus_match_reserved_addr ( + info->addr)) +return 1 ;/* last addr was valid */ + } info->addr = sb->slave_address;if (sb->access_mode ==ACPI_I2C_10BIT_MODE ) info->flags |=I2C_CLIENT_TEN ;
Signature · 1 line
1.9.3
PATCH v2 2/2 i2c / ACPI: Add support for extracting multiple I2C addresses
In reply to a message not in the archiveFrom: Mika Westerberg <mika.westerberg-VuQAYsv1563Yd54FQh9/[email protected]>
Some I2C devices can have multiple addresses and this is allowed by the ACPI specification as well. However, it doesn't specify how these addresses should be interpreted but leaves it up to the OS/drivers to deal with.
Since we can't tell in a generic code whether it is a single device with multiple addresses (like I2C attached EEPROM) or a multifunction device, we let the corresponding first level device's driver to decide how to best handle the addresses assigned to it.
To make driver writers life a bit easier, we add two new helper functions:i2c_address_by_index() and i2c_num_addressess() which can be used to extract all addresses for a given device.
--- drivers/i2c/i2c-acpi.c | 107 +++++++++++++++++++++++++++++++++++++++++++++++++ drivers/i2c/i2c-core.c | 61 ++++++++++++++++++++++++++++ include/linux/i2c.h | 8 ++++ 3 files changed, 176 insertions(+)
drivers/i2c/i2c-acpi.c +107 -0
@@ -37,6 +37,113 @@ struct gsb_buffer { }; } __packed; +struct acpi_i2c_lookup { +struct i2c_board_info *info; +struct i2c_adapter *adapter; +bool found; +int index; +int n; +}; + +static int acpi_i2c_match_adapter (struct device *dev,void *data) +{ +return !!i2c_verify_adapter (dev); +} + +static int acpi_i2c_find (struct acpi_resource *ares,void *data) +{ +struct acpi_i2c_lookup *lookup = data; +struct acpi_resource_i2c_serialbus *sb; +struct acpi_device_physical_node *phys; +struct acpi_device *adev; +acpi_status status; +acpi_handle handle; +char *path; + +if (ares->type !=ACPI_RESOURCE_TYPE_SERIAL_BUS ) +return 1 ; + + sb = &ares->data.i2c_serial_bus; +if (sb->type !=ACPI_RESOURCE_SERIAL_TYPE_I2C ) +return 1 ; + +if (lookup->n++ != lookup->index) +return 1 ; + +/* +* Need to look up the adapter from ACPI namespace and translate it +* to a physical device. That device should be existing I2C +* adapter. +*/ + path = sb->resource_source.string_ptr; + status =acpi_get_handle (ACPI_ROOT_OBJECT , path, &handle); +if (ACPI_FAILURE (status) ||acpi_bus_get_device (handle, &adev)) +return 1 ; + +mutex_lock (&adev->physical_node_lock); +list_for_each_entry (phys, &adev->physical_node_list, node) { +struct device *dev; + + dev =device_find_child (phys->dev,NULL , + acpi_i2c_match_adapter); +if (dev) { + lookup->adapter =to_i2c_adapter (dev); +break ; + } + } +mutex_unlock (&adev->physical_node_lock); + +if (!lookup->adapter) +return 1 ; + +if (lookup->info) { + lookup->info->addr = sb->slave_address; +if (sb->access_mode ==ACPI_I2C_10BIT_MODE ) + lookup->info->flags |=I2C_CLIENT_TEN ; + } + + lookup->found = true; +return 1 ; +} + +int acpi_i2c_address_by_index (struct i2c_client *client,int index, +struct i2c_board_info *info, +struct i2c_adapter **adapter) +{ +struct acpi_i2c_lookup lookup; +struct acpi_device *adev; +LIST_HEAD (resources); +int ret; + + adev =ACPI_COMPANION (&client->dev); +if (!adev) +return -ENODEV ; + +memset (&lookup,0 ,sizeof (lookup)); + lookup.index = index; + lookup.info = info; + + ret =acpi_dev_get_resources (adev, &resources, acpi_i2c_find, &lookup); +acpi_dev_free_resource_list (&resources); +if (ret <0 ) +return ret; + +if (lookup.found) { +if (!adapter) { +/* +* Caller is not interested in the adapter so we +* will release it now. Otherwise it is up to the +* caller to call put_device() for it. +*/ +put_device (&lookup.adapter->dev); + }else { + *adapter = lookup.adapter; + } + } + +return lookup.found ?0 : -EADDRNOTAVAIL ; +} +static int acpi_i2c_smbus_match_reserved_addr (unsigned short addr) {/*
drivers/i2c/i2c-core.c +61 -0
67 lines not on this page · raw message
include/linux/i2c.h +8 -0
@@ -322,6 +322,11 @@ extern int i2c_probe_func_quick_read(struct i2c_adapter *, unsigned short addr);extern struct i2c_client *i2c_new_dummy (struct i2c_adapter *adap,u16 address); +extern int i2c_address_by_index (struct i2c_client *client,int index, +struct i2c_board_info *info, +struct i2c_adapter **adapter); +extern size_t i2c_num_addresses (struct i2c_client *client); +extern void i2c_unregister_device (struct i2c_client *);#endif /* I2C */
@@ -579,6 +584,9 @@ static inline struct i2c_adapter *of_find_i2c_adapter_by_node(struct device_node#ifdef CONFIG_ACPI void acpi_i2c_register_devices (struct i2c_adapter *adap); +int acpi_i2c_address_by_index (struct i2c_client *client,int index, +struct i2c_board_info *info, +struct i2c_adapter **adapter);#else static inline void acpi_i2c_register_devices (struct i2c_adapter *adap) { }#endif /* CONFIG_ACPI */
Signature · 1 line
1.9.3