diff mbox

i2c / ACPI: Pick the first address if device has multiple

Message ID 1419860928-195404-1-git-send-email-mika.westerberg@linux.intel.com
State Accepted
Headers show

Commit Message

Mika Westerberg Dec. 29, 2014, 1:48 p.m. UTC
ACPI specification allows I2C devices with multiple addresses. The current
implementation goes over all addresses and assigns the last one to the
device. This is typically not the primary address of the device.

Instead of doing that we assign the first address to the device and then
let the driver handle rest of the addresses as it wishes.

Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com>
Cc: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
---
 drivers/i2c/i2c-core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Wolfram Sang Jan. 13, 2015, 3:50 p.m. UTC | #1
On Mon, Dec 29, 2014 at 03:48:48PM +0200, Mika Westerberg wrote:
> ACPI specification allows I2C devices with multiple addresses. The current
> implementation goes over all addresses and assigns the last one to the
> device. This is typically not the primary address of the device.
> 
> Instead of doing that we assign the first address to the device and then
> let the driver handle rest of the addresses as it wishes.
> 
> Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com>
> Cc: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>

Yes, seems better than what we do know. But maybe taking the lowest
address is a bit better heuristic than taking the first address?
Not sure, though...

> ---
>  drivers/i2c/i2c-core.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c
> index 39d25a8cb1ad..a06be43b7842 100644
> --- a/drivers/i2c/i2c-core.c
> +++ b/drivers/i2c/i2c-core.c
> @@ -102,7 +102,7 @@ static int acpi_i2c_add_resource(struct acpi_resource *ares, void *data)
>  		struct acpi_resource_i2c_serialbus *sb;
>  
>  		sb = &ares->data.i2c_serial_bus;
> -		if (sb->type == ACPI_RESOURCE_SERIAL_TYPE_I2C) {
> +		if (!info->addr && sb->type == ACPI_RESOURCE_SERIAL_TYPE_I2C) {
>  			info->addr = sb->slave_address;
>  			if (sb->access_mode == ACPI_I2C_10BIT_MODE)
>  				info->flags |= I2C_CLIENT_TEN;
> -- 
> 2.1.4
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-i2c" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
srinivas pandruvada Jan. 13, 2015, 4:44 p.m. UTC | #2
On Tue, 2015-01-13 at 16:50 +0100, Wolfram Sang wrote: 
> On Mon, Dec 29, 2014 at 03:48:48PM +0200, Mika Westerberg wrote:
> > ACPI specification allows I2C devices with multiple addresses. The current
> > implementation goes over all addresses and assigns the last one to the
> > device. This is typically not the primary address of the device.
> > 
> > Instead of doing that we assign the first address to the device and then
> > let the driver handle rest of the addresses as it wishes.
> > 
> > Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com>
> > Cc: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
> 
> Yes, seems better than what we do know. But maybe taking the lowest
> address is a bit better heuristic than taking the first address?
> Not sure, though...
The problem in taking lowest is that in many cases in current devices,
the lowest address may end being 0x0C, which is reserved address for
SMBUS (ARA). This will require different handling. Unfortunately ACPI
doesn't have a way to distinguish whether SMBUS support is desired or
not. 
The other option is to skip all reserved addresses for SMBUS also and
then create on the lowest.

Thanks,
Srinivas 
> 
> > ---
> >  drivers/i2c/i2c-core.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c
> > index 39d25a8cb1ad..a06be43b7842 100644
> > --- a/drivers/i2c/i2c-core.c
> > +++ b/drivers/i2c/i2c-core.c
> > @@ -102,7 +102,7 @@ static int acpi_i2c_add_resource(struct acpi_resource *ares, void *data)
> >  		struct acpi_resource_i2c_serialbus *sb;
> >  
> >  		sb = &ares->data.i2c_serial_bus;
> > -		if (sb->type == ACPI_RESOURCE_SERIAL_TYPE_I2C) {
> > +		if (!info->addr && sb->type == ACPI_RESOURCE_SERIAL_TYPE_I2C) {
> >  			info->addr = sb->slave_address;
> >  			if (sb->access_mode == ACPI_I2C_10BIT_MODE)
> >  				info->flags |= I2C_CLIENT_TEN;
> > -- 
> > 2.1.4
> > 
> > --
> > To unsubscribe from this list: send the line "unsubscribe linux-i2c" in
> > the body of a message to majordomo@vger.kernel.org
> > More majordomo info at  http://vger.kernel.org/majordomo-info.html


--
To unsubscribe from this list: send the line "unsubscribe linux-i2c" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Wolfram Sang Jan. 13, 2015, 4:48 p.m. UTC | #3
On Tue, Jan 13, 2015 at 08:44:37AM -0800, Srinivas Pandruvada wrote:
> On Tue, 2015-01-13 at 16:50 +0100, Wolfram Sang wrote: 
> > On Mon, Dec 29, 2014 at 03:48:48PM +0200, Mika Westerberg wrote:
> > > ACPI specification allows I2C devices with multiple addresses. The current
> > > implementation goes over all addresses and assigns the last one to the
> > > device. This is typically not the primary address of the device.
> > > 
> > > Instead of doing that we assign the first address to the device and then
> > > let the driver handle rest of the addresses as it wishes.
> > > 
> > > Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com>
> > > Cc: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
> > 
> > Yes, seems better than what we do know. But maybe taking the lowest
> > address is a bit better heuristic than taking the first address?
> > Not sure, though...
> The problem in taking lowest is that in many cases in current devices,
> the lowest address may end being 0x0C, which is reserved address for
> SMBUS (ARA). This will require different handling. Unfortunately ACPI
> doesn't have a way to distinguish whether SMBUS support is desired or
> not. 
> The other option is to skip all reserved addresses for SMBUS also and
> then create on the lowest.

Well, this makes me think that Mika's approach is probably the sanest
one...
Mika Westerberg Jan. 13, 2015, 5 p.m. UTC | #4
On Tue, Jan 13, 2015 at 05:48:29PM +0100, Wolfram Sang wrote:
> On Tue, Jan 13, 2015 at 08:44:37AM -0800, Srinivas Pandruvada wrote:
> > On Tue, 2015-01-13 at 16:50 +0100, Wolfram Sang wrote: 
> > > On Mon, Dec 29, 2014 at 03:48:48PM +0200, Mika Westerberg wrote:
> > > > ACPI specification allows I2C devices with multiple addresses. The current
> > > > implementation goes over all addresses and assigns the last one to the
> > > > device. This is typically not the primary address of the device.
> > > > 
> > > > Instead of doing that we assign the first address to the device and then
> > > > let the driver handle rest of the addresses as it wishes.
> > > > 
> > > > Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com>
> > > > Cc: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
> > > 
> > > Yes, seems better than what we do know. But maybe taking the lowest
> > > address is a bit better heuristic than taking the first address?
> > > Not sure, though...
> > The problem in taking lowest is that in many cases in current devices,
> > the lowest address may end being 0x0C, which is reserved address for
> > SMBUS (ARA). This will require different handling. Unfortunately ACPI
> > doesn't have a way to distinguish whether SMBUS support is desired or
> > not. 
> > The other option is to skip all reserved addresses for SMBUS also and
> > then create on the lowest.
> 
> Well, this makes me think that Mika's approach is probably the sanest
> one...

Also I think it is more consistent that way.
--
To unsubscribe from this list: send the line "unsubscribe linux-i2c" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Wolfram Sang Jan. 14, 2015, 10:55 a.m. UTC | #5
On Mon, Dec 29, 2014 at 03:48:48PM +0200, Mika Westerberg wrote:
> ACPI specification allows I2C devices with multiple addresses. The current
> implementation goes over all addresses and assigns the last one to the
> device. This is typically not the primary address of the device.
> 
> Instead of doing that we assign the first address to the device and then
> let the driver handle rest of the addresses as it wishes.
> 
> Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com>
> Cc: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>

Applied to for-next, thanks!
diff mbox

Patch

diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c
index 39d25a8cb1ad..a06be43b7842 100644
--- a/drivers/i2c/i2c-core.c
+++ b/drivers/i2c/i2c-core.c
@@ -102,7 +102,7 @@  static int acpi_i2c_add_resource(struct acpi_resource *ares, void *data)
 		struct acpi_resource_i2c_serialbus *sb;
 
 		sb = &ares->data.i2c_serial_bus;
-		if (sb->type == ACPI_RESOURCE_SERIAL_TYPE_I2C) {
+		if (!info->addr && sb->type == ACPI_RESOURCE_SERIAL_TYPE_I2C) {
 			info->addr = sb->slave_address;
 			if (sb->access_mode == ACPI_I2C_10BIT_MODE)
 				info->flags |= I2C_CLIENT_TEN;