ACPI: Introduce ACPI I2C controller enumeration driver
RFC PATCH 5/6 ACPI: Introduce ACPI I2C controller enumeration driver
Quoted 1 line
From
6077a62f2865201ab6727ca7d628ee5e43aa57e1Mon Sep 17 00:00:00 2001
From: Zhang Rui <[email protected]>
Date: Fri, 24 Aug 2012 15:18:25 +0800
Subject: [RFC PATCH 5/6] ACPI: Introduce ACPI I2C controller enumeration
driver
This driver is able to
1) enumerate I2C controller via ACPI namespace and register it as a platform device.
2) enumerate I2C slave devices via ACPI namespace.
--- drivers/acpi/Makefile | 1 + drivers/acpi/i2c_root.c | 229 +++++++++++++++++++++++++++++++++++++++++++ drivers/acpi/sysfs.c | 1 + include/acpi/acpi_drivers.h | 1 + 4 files changed, 232 insertions(+), 0 deletions(-) create mode 100644 drivers/acpi/i2c_root.c
drivers/acpi/Makefile +1 -0
@@ -35,6 +35,7 @@ acpi-y += scan.o acpi-y += processor_core.o acpi-y += ec.o acpi-y += gpio.o +acpi-y += i2c_root.o acpi-$(CONFIG_ACPI_DOCK) += dock.o acpi-y += pci_root.o pci_link.o pci_irq.o pci_bind.o acpi-y += power.o
drivers/acpi/i2c_root.c new file +229 -0
229 lines not on this page · raw message
drivers/acpi/sysfs.c +1 -0
@@ -63,6 +63,7 @@ static const struct acpi_dlayer acpi_debug_layers[] = {ACPI_DEBUG_INIT (ACPI_MEMORY_DEVICE_COMPONENT ),ACPI_DEBUG_INIT (ACPI_VIDEO_COMPONENT ),ACPI_DEBUG_INIT (ACPI_PROCESSOR_COMPONENT ), + ACPI_DEBUG_INIT(ACPI_SPB_COMPONENT), };static const struct acpi_dlevel acpi_debug_levels[] = {
include/acpi/acpi_drivers.h +1 -0
@@ -49,6 +49,7 @@#define ACPI_MEMORY_DEVICE_COMPONENT 0x08000000#define ACPI_VIDEO_COMPONENT 0x10000000#define ACPI_PROCESSOR_COMPONENT 0x20000000 +#define ACPI_SPB_COMPONENT 0x40000000/* * _HID definitions
Signature · 1 line
1.7.7.6
Quoted 10 lines · On Fri, 28 Sep 2012 15:40:32 +0800 Zhang Rui <[email protected]> wrote:
Quoted 1 line
From
6077a62f2865201ab6727ca7d628ee5e43aa57e1Mon Sep 17 00:00:00 2001From: Zhang Rui <[email protected]>
Date: Fri, 24 Aug 2012 15:18:25 +0800
Subject: [RFC PATCH 5/6] ACPI: Introduce ACPI I2C controller enumeration
driverThis driver is able to
1) enumerate I2C controller via ACPI namespace and register it as a platform device.
2) enumerate I2C slave devices via ACPI namespace.
Will this also trigger and work with the ACPI4 based devices that seem to have I²C tables that Linux currently doesn't understand (eq some GMA600/Oaktrail platforms) ?
Quoted 22 lines
-----Original Message-----
From: Alan Cox [mailto:[email protected]]
Sent: Friday, September 28, 2012 8:54 PM
To: Zhang, Rui
Cc: LKML; linux-pm; linux-i2c; [email protected]; Len, Brown; Rafael J. Wysocki; Grant Likely; Dirk Brandewie
Subject: Re: [RFC PATCH 5/6] ACPI: Introduce ACPI I2C controller enumeration driver
Importance: HighQuoted 7 lines · On Fri, 28 Sep 2012 15:40:32 +0800 Zhang Rui <[email protected]> wrote:
Quoted 2 lines
From
6077a62f2865201ab6727ca7d628ee5e43aa57e1Mon Sep 17 00:00:00 2001From: Zhang Rui <[email protected]>
Date: Fri, 24 Aug 2012 15:18:25 +0800
Subject: [RFC PATCH 5/6] ACPI: Introduce ACPI I2C controller enumeration driver
Quoted 8 lines
Quoted 4 lines
This driver is able to
1) enumerate I2C controller via ACPI namespace and register it as a platform device.
2) enumerate I2C slave devices via ACPI namespace.Will this also trigger and work with the ACPI4 based devices that seem to have I²C tables that Linux currently doesn't understand (eq some GMA600/Oaktrail platforms) ?
I'm not aware of this. I think the answer is probably "No" because these PNPids are pretty new.
But we can check FADT.revision to make the driver work on ACPI5 platforms only.
Thanks,
rui
Quoted 25 lines · Zhang Rui
drivers/acpi/i2c_root.c new file +25
-0+acpi_status __init i2c_enumerate_slave (acpi_handle handle,u32 level, +void *data,void **return_value) +{ +int result; +acpi_status status; +struct acpi_buffer buffer; +struct acpi_resource *resource; +struct acpi_resource_gpio *gpio; +struct acpi_resource_i2c_serialbus *i2c; +int i; +struct acpi_i2c_root *root = data; +struct i2c_board_info info; +struct acpi_device *device; + +if (acpi_bus_get_device (handle, &device)) +return AE_OK ; + + status =acpi_get_current_resources (handle, &buffer); +if (ACPI_FAILURE (status)) { +dev_err (&device->dev,"Failed to get ACPI resources\n" ); +return AE_OK ; + } + +for (i =0 ; i < buffer.length; i +=sizeof (struct acpi_resource )) { + resource = (struct acpi_resource *)(buffer.pointer + i);
drivers/acpi/i2c_root.c line 138
Quoted 10 lines
drivers/acpi/i2c_root.c new file +10
-0+ +switch (resource->type) { +case ACPI_RESOURCE_TYPE_GPIO : + gpio = &resource->data.gpio; + +if (gpio->connection_type ==ACPI_RESOURCE_GPIO_TYPE_INT ) { + result = +acpi_device_get_gpio_irq + (gpio->resource_source.string_ptr, + gpio->pin_table[0 ], &info.irq);
acpi_device_get_gpio_irq() is not defined in this patch series?
Also you need to do the gpio_request()/gpio_to_irq() things somewhere. Are they handled in acpi_device_get_gpio_irq()?
How about GpioIo resources?
Quoted 21 lines
drivers/acpi/i2c_root.c new file +21
-0+if (result) +dev_err (&device->dev, +"Failed to get IRQ\n" ); + } +break ; +case ACPI_RESOURCE_TYPE_SERIAL_BUS : + i2c = &resource->data.i2c_serial_bus; + + info.addr = i2c->slave_address; +break ; +default : +break ; + } + } + +add_slave (root, &info); + +kfree (buffer.pointer); +return AE_OK ; +} +
drivers/acpi/i2c_root.c line 169
Quoted 10 lines
drivers/acpi/i2c_root.c new file +10
-0+static int __devinit acpi_i2c_root_add (struct acpi_device *device) +{ +acpi_status status; +struct acpi_i2c_root *root; +struct resource *resources; +int result; + +if (!device->pnp.unique_id) { +dev_err (&device->dev, +"Unsupported ACPI I2C controller. No UID\n" );
Where does this restriction come from? As far as I understand UID is optional.
Quoted 45 lines
drivers/acpi/i2c_root.c new file +45
-0+return -ENODEV ; + } + + root =kzalloc (sizeof (struct acpi_i2c_root ),GFP_KERNEL ); +if (!root) +return -ENOMEM ; + + root->device = device; + +kstrtoint (device->pnp.unique_id,10 , &root->busnum); + +/* enumerate I2C controller */ + root->pdev = +platform_device_alloc (acpi_device_hid (device), root->busnum); +if (!root->pdev) { +dev_err (&device->dev,"Failed to alloc platform device\n" ); + goto err; + } + + result =acpi_get_generic_resources (device, &resources); +if (result <0 ) { +dev_err (&device->dev,"Failed to get resources\n" ); + goto err; + } + +platform_device_add_resources (root->pdev, resources, result); +platform_device_add (root->pdev); + +/* enumerate I2C slave devices */ + status =acpi_walk_namespace (ACPI_TYPE_DEVICE , root->device->handle,1 , + i2c_enumerate_slave,NULL , root,NULL ); + +if (ACPI_FAILURE (status)) { +dev_err (&root->device->dev,"i2c ACPI namespace walk error!\n" ); +kfree (root); +return -ENODEV ; + } + +register_slaves (root); + +return 0 ; +err: +kfree (root); +return -ENODEV ; +}
Quoted 46 lines
-----Original Message-----
From: [email protected] [mailto:linux-i2c- [email protected]] On Behalf Of Mika Westerberg
Sent: Monday, October 01, 2012 2:55 PM
To: Zhang, Rui
Cc: LKML; linux-pm; linux-i2c; [email protected]; Len, Brown; Rafael J. Wysocki; Grant Likely; Dirk Brandewie
Subject: Re: [RFC PATCH 5/6] ACPI: Introduce ACPI I2C controller enumeration driver
Importance: HighQuoted 13 lines · Zhang Rui
drivers/acpi/i2c_root.c new file +13
-0+acpi_status __init i2c_enumerate_slave (acpi_handle handle,u32 level, +void *data,void **return_value) { +int result; +acpi_status status; +struct acpi_buffer buffer; +struct acpi_resource *resource; +struct acpi_resource_gpio *gpio; +struct acpi_resource_i2c_serialbus *i2c; +int i; +struct acpi_i2c_root *root = data; +struct i2c_board_info info; +struct acpi_device *device; +drivers/acpi/i2c_root.c
Quoted 10 lines
drivers/acpi/i2c_root.c new file +10
-0+if (acpi_bus_get_device (handle, &device)) +return AE_OK ; + + status =acpi_get_current_resources (handle, &buffer); +if (ACPI_FAILURE (status)) { +dev_err (&device->dev,"Failed to get ACPI resources\n" ); +return AE_OK ; + } + +for (i =0 ; i < buffer.length; i +=sizeof (struct acpi_resource )){
drivers/acpi/i2c_root.c
Quoted 7 lines
drivers/acpi/i2c_root.c new file +7
-0+ resource = (struct acpi_resource *)(buffer.pointer + i); + +switch (resource->type) { +case ACPI_RESOURCE_TYPE_GPIO : + gpio = &resource->data.gpio; + + if (gpio->connection_type ==
ACPI_RESOURCE_GPIO_TYPE_INT) {
Quoted 7 lines
drivers/acpi/i2c_root.c line 138
Quoted 4 lines
drivers/acpi/i2c_root.c new file +4
-0+ result = +acpi_device_get_gpio_irq + (gpio->resource_source.string_ptr, + gpio->pin_table[0 ], &info.irq);
acpi_device_get_gpio_irq()is not defined in this patch series?
ACPI GPIO controller patch has already been sent out, but in ACPI mailing list only.
Quoted 3 lines
Also you need to do the gpio_request()/gpio_to_irq() things somewhere. Are they handled in
acpi_device_get_gpio_irq()?
Yep.
Quoted 2 lines
How about GpioIo resources?
This is not covered in this patch set, but will be in the next patch set.
Quoted 25 lines
Quoted 25 lines
drivers/acpi/i2c_root.c new file +25
-0+if (result) +dev_err (&device->dev, +"Failed to get IRQ\n" ); + } +break ; +case ACPI_RESOURCE_TYPE_SERIAL_BUS : + i2c = &resource->data.i2c_serial_bus; + + info.addr = i2c->slave_address; +break ; +default : +break ; + } + } + +add_slave (root, &info); + +kfree (buffer.pointer); +return AE_OK ; +} + +static int __devinit acpi_i2c_root_add (struct acpi_device *device) { +acpi_status status; +struct acpi_i2c_root *root; +struct resource *resources;
Quoted 9 lines
drivers/acpi/i2c_root.c line 169
Quoted 5 lines
drivers/acpi/i2c_root.c new file +5
-0+int result; + +if (!device->pnp.unique_id) { +dev_err (&device->dev, +"Unsupported ACPI I2C controller. No UID\n" );Where does this restriction come from? As far as I understand UID is optional.
_UID is optional.
But it seems to be required for SPB buses that need ACPI device enumeration. At least this is true for the ACPI 5 compatible ACPI tables I have.
Thanks,
rui
Quoted 46 lines · Rui
Quoted 46 lines
-----Original Message-----
From: [email protected] [mailto:linux-i2c- [email protected]] On Behalf Of Mika Westerberg
Sent: Monday, October 01, 2012 2:55 PM
To: Zhang, Rui
Cc: LKML; linux-pm; linux-i2c; [email protected]; Len, Brown; Rafael J. Wysocki; Grant Likely; Dirk Brandewie
Subject: Re: [RFC PATCH 5/6] ACPI: Introduce ACPI I2C controller enumeration driver
Importance: HighQuoted 13 lines · Zhang Rui
drivers/acpi/i2c_root.c new file +13
-0+acpi_status __init i2c_enumerate_slave (acpi_handle handle,u32 level, +void *data,void **return_value) { +int result; +acpi_status status; +struct acpi_buffer buffer; +struct acpi_resource *resource; +struct acpi_resource_gpio *gpio; +struct acpi_resource_i2c_serialbus *i2c; +int i; +struct acpi_i2c_root *root = data; +struct i2c_board_info info; +struct acpi_device *device; +drivers/acpi/i2c_root.c
Quoted 10 lines
drivers/acpi/i2c_root.c new file +10
-0+if (acpi_bus_get_device (handle, &device)) +return AE_OK ; + + status =acpi_get_current_resources (handle, &buffer); +if (ACPI_FAILURE (status)) { +dev_err (&device->dev,"Failed to get ACPI resources\n" ); +return AE_OK ; + } + +for (i =0 ; i < buffer.length; i +=sizeof (struct acpi_resource )){
drivers/acpi/i2c_root.c
Quoted 7 lines
drivers/acpi/i2c_root.c new file +7
-0+ resource = (struct acpi_resource *)(buffer.pointer + i); + +switch (resource->type) { +case ACPI_RESOURCE_TYPE_GPIO : + gpio = &resource->data.gpio; + + if (gpio->connection_type ==
ACPI_RESOURCE_GPIO_TYPE_INT) {
Quoted 8 lines
Quoted 7 lines
drivers/acpi/i2c_root.c line 138
Quoted 4 lines
drivers/acpi/i2c_root.c new file +4
-0+ result = +acpi_device_get_gpio_irq + (gpio->resource_source.string_ptr, + gpio->pin_table[0 ], &info.irq);
acpi_device_get_gpio_irq()is not defined in this patch series?ACPI GPIO controller patch has already been sent out, but in ACPI mailing list only.
It would have been good idea to mention this in the cover letter at least.
Quoted 45 lines
Quoted 4 lines
Also you need to do the gpio_request()/gpio_to_irq() things somewhere. Are they handled in
acpi_device_get_gpio_irq()?Yep.
Quoted 2 lines
How about GpioIo resources?
This is not covered in this patch set, but will be in the next patch set.
Quoted 25 lines
Quoted 25 lines
drivers/acpi/i2c_root.c new file +25
-0+if (result) +dev_err (&device->dev, +"Failed to get IRQ\n" ); + } +break ; +case ACPI_RESOURCE_TYPE_SERIAL_BUS : + i2c = &resource->data.i2c_serial_bus; + + info.addr = i2c->slave_address; +break ; +default : +break ; + } + } + +add_slave (root, &info); + +kfree (buffer.pointer); +return AE_OK ; +} + +static int __devinit acpi_i2c_root_add (struct acpi_device *device) { +acpi_status status; +struct acpi_i2c_root *root; +struct resource *resources;Quoted 9 lines
drivers/acpi/i2c_root.c line 169
Quoted 5 lines
drivers/acpi/i2c_root.c new file +5
-0+int result; + +if (!device->pnp.unique_id) { +dev_err (&device->dev, +"Unsupported ACPI I2C controller. No UID\n" );Where does this restriction come from? As far as I understand UID is optional.
Quoted 3 lines
_UIDis optional.
But it seems to be required for SPB buses that need ACPI device enumeration. At least this is true for the ACPI 5 compatible ACPI tables I have.
Yes but if some vendor is not setting it (as it is optional) you still want your code to work, right?