linux-pm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Mika Westerberg <mika.westerberg-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
To: Zhang Rui <rui.zhang-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
Cc: LKML <linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>,
	linux-pm
	<linux-pm-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org>,
	linux-i2c <linux-i2c-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>,
	"linux-acpi-u79uwXL29TY76Z2rM5mHXA@public.gmane.org"
	<linux-acpi-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>,
	"Len, Brown" <lenb-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>,
	"Rafael J. Wysocki" <rjw-KKrjLPT3xs0@public.gmane.org>,
	Grant Likely
	<grant.likely-s3s/WqlpOiPyB63q8FvJNQ@public.gmane.org>,
	Dirk Brandewie
	<dirk.brandewie-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
Subject: Re: [RFC PATCH 5/6] ACPI: Introduce ACPI I2C controller enumeration driver
Date: Mon, 1 Oct 2012 09:55:26 +0300	[thread overview]
Message-ID: <20121001065526.GH15548@intel.com> (raw)
In-Reply-To: <1348818032.10877.325.camel-fuY85erJQUO75v1z/vFq2g@public.gmane.org>

On Fri, Sep 28, 2012 at 03:40:32PM +0800, Zhang Rui wrote:
> +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);
> +
> +		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?

> +				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;
> +	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.

> +		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;
> +}

  parent reply	other threads:[~2012-10-01  6:55 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-09-28  7:40 [RFC PATCH 5/6] ACPI: Introduce ACPI I2C controller enumeration driver Zhang Rui
2012-09-28 12:54 ` Alan Cox
2012-09-29 13:37   ` Zhang, Rui
     [not found] ` <1348818032.10877.325.camel-fuY85erJQUO75v1z/vFq2g@public.gmane.org>
2012-10-01  6:55   ` Mika Westerberg [this message]
2012-10-01 14:19     ` Zhang, Rui
2012-10-02  6:12       ` Mika Westerberg

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20121001065526.GH15548@intel.com \
    --to=mika.westerberg-vuqaysv1563yd54fqh9/ca@public.gmane.org \
    --cc=dirk.brandewie-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
    --cc=grant.likely-s3s/WqlpOiPyB63q8FvJNQ@public.gmane.org \
    --cc=lenb-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org \
    --cc=linux-acpi-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=linux-i2c-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=linux-pm-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org \
    --cc=rjw-KKrjLPT3xs0@public.gmane.org \
    --cc=rui.zhang-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).