linux-i2c.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Lan Tianyu <tianyu.lan-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
To: wsa-z923LK4zBo2bacvFa/9K2g@public.gmane.org,
	rjw-LthD3rsA81gm4RdzfppkhA@public.gmane.org,
	mika.westerberg-VuQAYsv1563Yd54FQh9/CA@public.gmane.org,
	awilliam-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org,
	lenb-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org
Cc: linux-i2c-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	linux-acpi-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	tianyu.lan-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org
Subject: [Patch V2 8/9] I2C/ACPI: Move ACPI related code to i2c-acpi.c
Date: Mon, 28 Apr 2014 22:27:47 +0800	[thread overview]
Message-ID: <1398695268-28645-9-git-send-email-tianyu.lan@intel.com> (raw)
In-Reply-To: <1398695268-28645-1-git-send-email-tianyu.lan-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>

Clean up ACPI related code in the i2c core.

Reviewed-by: Mika Westerberg <mika.westerberg-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
Signed-off-by: Lan Tianyu <tianyu.lan-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
---
 drivers/i2c/i2c-acpi.c | 89 ++++++++++++++++++++++++++++++++++++++++++++++
 drivers/i2c/i2c-core.c | 95 --------------------------------------------------
 include/linux/i2c.h    |  2 ++
 3 files changed, 91 insertions(+), 95 deletions(-)

diff --git a/drivers/i2c/i2c-acpi.c b/drivers/i2c/i2c-acpi.c
index ab0272e..e2ad72d 100644
--- a/drivers/i2c/i2c-acpi.c
+++ b/drivers/i2c/i2c-acpi.c
@@ -37,6 +37,95 @@ struct gsb_buffer {
 	};
 } __packed;
 
+static int acpi_i2c_add_resource(struct acpi_resource *ares, void *data)
+{
+	struct i2c_board_info *info = data;
+
+	if (ares->type == ACPI_RESOURCE_TYPE_SERIAL_BUS) {
+		struct acpi_resource_i2c_serialbus *sb;
+
+		sb = &ares->data.i2c_serial_bus;
+		if (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;
+		}
+	} else if (info->irq < 0) {
+		struct resource r;
+
+		if (acpi_dev_resource_interrupt(ares, 0, &r))
+			info->irq = r.start;
+	}
+
+	/* Tell the ACPI core to skip this resource */
+	return 1;
+}
+
+static acpi_status acpi_i2c_add_device(acpi_handle handle, u32 level,
+				       void *data, void **return_value)
+{
+	struct i2c_adapter *adapter = data;
+	struct list_head resource_list;
+	struct i2c_board_info info;
+	struct acpi_device *adev;
+	int ret;
+
+	if (acpi_bus_get_device(handle, &adev))
+		return AE_OK;
+	if (acpi_bus_get_status(adev) || !adev->status.present)
+		return AE_OK;
+
+	memset(&info, 0, sizeof(info));
+	info.acpi_node.companion = adev;
+	info.irq = -1;
+
+	INIT_LIST_HEAD(&resource_list);
+	ret = acpi_dev_get_resources(adev, &resource_list,
+				     acpi_i2c_add_resource, &info);
+	acpi_dev_free_resource_list(&resource_list);
+
+	if (ret < 0 || !info.addr)
+		return AE_OK;
+
+	adev->power.flags.ignore_parent = true;
+	strlcpy(info.type, dev_name(&adev->dev), sizeof(info.type));
+	if (!i2c_new_device(adapter, &info)) {
+		adev->power.flags.ignore_parent = false;
+		dev_err(&adapter->dev,
+			"failed to add I2C device %s from ACPI\n",
+			dev_name(&adev->dev));
+	}
+
+	return AE_OK;
+}
+
+/**
+ * acpi_i2c_register_devices - enumerate I2C slave devices behind adapter
+ * @adap: pointer to adapter
+ *
+ * Enumerate all I2C slave devices behind this adapter by walking the ACPI
+ * namespace. When a device is found it will be added to the Linux device
+ * model and bound to the corresponding ACPI handle.
+ */
+void acpi_i2c_register_devices(struct i2c_adapter *adap)
+{
+	acpi_handle handle;
+	acpi_status status;
+
+	if (!adap->dev.parent)
+		return;
+
+	handle = ACPI_HANDLE(adap->dev.parent);
+	if (!handle)
+		return;
+
+	status = acpi_walk_namespace(ACPI_TYPE_DEVICE, handle, 1,
+				     acpi_i2c_add_device, NULL,
+				     adap, NULL);
+	if (ACPI_FAILURE(status))
+		dev_warn(&adap->dev, "failed to enumerate I2C slaves\n");
+}
+
 static int acpi_gsb_i2c_read_bytes(struct i2c_client *client,
 		u8 cmd, u8 *data, u8 data_len)
 {
diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c
index bb9dc56..9ca50c8 100644
--- a/drivers/i2c/i2c-core.c
+++ b/drivers/i2c/i2c-core.c
@@ -1092,101 +1092,6 @@ EXPORT_SYMBOL(of_find_i2c_adapter_by_node);
 static void of_i2c_register_devices(struct i2c_adapter *adap) { }
 #endif /* CONFIG_OF */
 
-/* ACPI support code */
-
-#if IS_ENABLED(CONFIG_ACPI)
-static int acpi_i2c_add_resource(struct acpi_resource *ares, void *data)
-{
-	struct i2c_board_info *info = data;
-
-	if (ares->type == ACPI_RESOURCE_TYPE_SERIAL_BUS) {
-		struct acpi_resource_i2c_serialbus *sb;
-
-		sb = &ares->data.i2c_serial_bus;
-		if (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;
-		}
-	} else if (info->irq < 0) {
-		struct resource r;
-
-		if (acpi_dev_resource_interrupt(ares, 0, &r))
-			info->irq = r.start;
-	}
-
-	/* Tell the ACPI core to skip this resource */
-	return 1;
-}
-
-static acpi_status acpi_i2c_add_device(acpi_handle handle, u32 level,
-				       void *data, void **return_value)
-{
-	struct i2c_adapter *adapter = data;
-	struct list_head resource_list;
-	struct i2c_board_info info;
-	struct acpi_device *adev;
-	int ret;
-
-	if (acpi_bus_get_device(handle, &adev))
-		return AE_OK;
-	if (acpi_bus_get_status(adev) || !adev->status.present)
-		return AE_OK;
-
-	memset(&info, 0, sizeof(info));
-	info.acpi_node.companion = adev;
-	info.irq = -1;
-
-	INIT_LIST_HEAD(&resource_list);
-	ret = acpi_dev_get_resources(adev, &resource_list,
-				     acpi_i2c_add_resource, &info);
-	acpi_dev_free_resource_list(&resource_list);
-
-	if (ret < 0 || !info.addr)
-		return AE_OK;
-
-	adev->power.flags.ignore_parent = true;
-	strlcpy(info.type, dev_name(&adev->dev), sizeof(info.type));
-	if (!i2c_new_device(adapter, &info)) {
-		adev->power.flags.ignore_parent = false;
-		dev_err(&adapter->dev,
-			"failed to add I2C device %s from ACPI\n",
-			dev_name(&adev->dev));
-	}
-
-	return AE_OK;
-}
-
-/**
- * acpi_i2c_register_devices - enumerate I2C slave devices behind adapter
- * @adap: pointer to adapter
- *
- * Enumerate all I2C slave devices behind this adapter by walking the ACPI
- * namespace. When a device is found it will be added to the Linux device
- * model and bound to the corresponding ACPI handle.
- */
-static void acpi_i2c_register_devices(struct i2c_adapter *adap)
-{
-	acpi_handle handle;
-	acpi_status status;
-
-	if (!adap->dev.parent)
-		return;
-
-	handle = ACPI_HANDLE(adap->dev.parent);
-	if (!handle)
-		return;
-
-	status = acpi_walk_namespace(ACPI_TYPE_DEVICE, handle, 1,
-				     acpi_i2c_add_device, NULL,
-				     adap, NULL);
-	if (ACPI_FAILURE(status))
-		dev_warn(&adap->dev, "failed to enumerate I2C slaves\n");
-}
-#else
-static inline void acpi_i2c_register_devices(struct i2c_adapter *adap) {}
-#endif /* CONFIG_ACPI */
-
 static int i2c_do_add_adapter(struct i2c_driver *driver,
 			      struct i2c_adapter *adap)
 {
diff --git a/include/linux/i2c.h b/include/linux/i2c.h
index 681e689..4b6fcdb 100644
--- a/include/linux/i2c.h
+++ b/include/linux/i2c.h
@@ -586,7 +586,9 @@ static inline struct i2c_adapter *of_find_i2c_adapter_by_node(struct device_node
 #ifdef CONFIG_ACPI
 int acpi_i2c_install_space_handler(struct i2c_adapter *adapter);
 void acpi_i2c_remove_space_handler(struct i2c_adapter *adapter);
+void acpi_i2c_register_devices(struct i2c_adapter *adap);
 #else
+static inline void acpi_i2c_register_devices(struct i2c_adapter *adap) { }
 static inline void acpi_i2c_remove_space_handler(struct i2c_adapter *adapter)
 { }
 static inline int acpi_i2c_install_space_handler(struct i2c_adapter *adapter)
-- 
1.8.3.1

  parent reply	other threads:[~2014-04-28 14:27 UTC|newest]

Thread overview: 79+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-04-16 13:24 [PATCH 0/9] I2C ACPI operation region handler support Lan Tianyu
     [not found] ` <1397654682-7094-1-git-send-email-tianyu.lan-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
2014-04-16 13:24   ` [PATCH 1/9] ACPICA: Executer: Fix buffer allocation issue for generic_serial_bus region field accesses Lan Tianyu
2014-04-21 21:38     ` Rafael J. Wysocki
2014-04-22  1:14       ` Lan Tianyu
2014-04-16 13:24 ` [PATCH 2/9] ACPICA: Export acpi_buffer_to_resource symbol Lan Tianyu
2014-04-16 13:24 ` [PATCH 3/9] ACPI: Add acpi_bus_attach_private_data() to facilitate to attach data to ACPI handle Lan Tianyu
2014-04-16 13:24 ` [PATCH 4/9] ACPI/Thermal: Use acpi_bus_attach_private_data() to attach private data Lan Tianyu
2014-04-16 13:24 ` [PATCH 5/9] I2C: Add smbus quick read/write helper function Lan Tianyu
2014-04-16 13:24 ` [PATCH 6/9] I2C: Add smbus word/block process call " Lan Tianyu
2014-04-16 13:24 ` [PATCH 7/9] I2C/ACPI: Add i2c ACPI operation region support Lan Tianyu
2014-04-16 13:24 ` [PATCH 8/9] I2C/ACPI: Move ACPI related code to i2c-acpi.c Lan Tianyu
2014-04-16 13:24 ` [PATCH 9/9] I2C/ACPI: Add CONFIG_I2C_ACPI config Lan Tianyu
2014-04-16 13:33 ` [PATCH 0/9] I2C ACPI operation region handler support Lan Tianyu
2014-04-16 16:35 ` Adam Williamson
2014-04-22  6:24 ` [Resend Patch " Lan Tianyu
2014-04-22  6:24   ` [Resend Patch 1/9] ACPICA: Executer: Fix buffer allocation issue for generic_serial_bus region field accesses Lan Tianyu
     [not found]     ` <1398147855-9868-2-git-send-email-tianyu.lan-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
2014-04-22 11:21       ` Mika Westerberg
2014-04-22  6:24   ` [Resend Patch 2/9] ACPICA: Export acpi_buffer_to_resource symbol Lan Tianyu
     [not found]     ` <1398147855-9868-3-git-send-email-tianyu.lan-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
2014-04-22 11:21       ` Mika Westerberg
2014-04-22  6:24   ` [Resend Patch 3/9] ACPI: Add acpi_bus_attach_private_data() to facilitate to attach data to ACPI handle Lan Tianyu
     [not found]     ` <1398147855-9868-4-git-send-email-tianyu.lan-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
2014-04-22 11:23       ` Mika Westerberg
2014-04-22  6:24   ` [Resend Patch 4/9] ACPI/Thermal: Use acpi_bus_attach_private_data() to attach private data Lan Tianyu
     [not found]     ` <1398147855-9868-5-git-send-email-tianyu.lan-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
2014-04-22 11:24       ` Mika Westerberg
2014-04-22  6:24   ` [Resend Patch 5/9] I2C: Add smbus quick read/write helper function Lan Tianyu
     [not found]     ` <1398147855-9868-6-git-send-email-tianyu.lan-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
2014-04-22 11:24       ` Mika Westerberg
2014-04-22  6:24   ` [Resend Patch 6/9] I2C: Add smbus word/block process call " Lan Tianyu
2014-04-22 11:26     ` Mika Westerberg
     [not found]   ` <1398147855-9868-1-git-send-email-tianyu.lan-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
2014-04-22  6:24     ` [Resend Patch 7/9] I2C/ACPI: Add i2c ACPI operation region support Lan Tianyu
2014-04-22 11:36       ` Mika Westerberg
2014-04-23  1:53         ` Lan Tianyu
2014-04-23  7:28           ` Mika Westerberg
2014-04-23  7:17             ` Lan Tianyu
2014-04-22  6:24   ` [Resend Patch 8/9] I2C/ACPI: Move ACPI related code to i2c-acpi.c Lan Tianyu
     [not found]     ` <1398147855-9868-9-git-send-email-tianyu.lan-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
2014-04-22 11:38       ` Mika Westerberg
2014-04-22  6:24   ` [Resend Patch 9/9] I2C/ACPI: Add CONFIG_I2C_ACPI config Lan Tianyu
2014-04-22 11:45     ` Mika Westerberg
     [not found]       ` <20140422114510.GM30677-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
2014-04-23  5:39         ` Lan Tianyu
     [not found]           ` <53575227.7080407-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
2014-04-23  6:47             ` Zheng, Lv
2014-04-23  7:40               ` Mika Westerberg
2014-04-23 23:03   ` [Resend Patch 0/9] I2C ACPI operation region handler support Adam Williamson
2014-04-28 14:27   ` [Patch V2 " Lan Tianyu
2014-04-28 14:27     ` [Patch V2 1/9] ACPICA: Executer: Fix buffer allocation issue for generic_serial_bus region field accesses Lan Tianyu
2014-04-28 17:52       ` Adam Williamson
2014-04-28 18:08         ` Adam Williamson
2014-04-28 22:50           ` Rafael J. Wysocki
2014-04-29 11:31             ` Wolfram Sang
2014-04-29 21:37               ` Rafael J. Wysocki
2014-04-28 14:27     ` [Patch V2 2/9] ACPICA: Export acpi_buffer_to_resource symbol Lan Tianyu
2014-04-28 14:27     ` [Patch V2 3/9] ACPI: Add acpi_bus_attach_private_data() to facilitate to attach data to ACPI handle Lan Tianyu
2014-04-28 14:27     ` [Patch V2 4/9] ACPI/Thermal: Use acpi_bus_attach_private_data() to attach private data Lan Tianyu
2014-04-28 14:27     ` [Patch V2 5/9] I2C: Add smbus quick read/write helper function Lan Tianyu
     [not found]       ` <1398695268-28645-6-git-send-email-tianyu.lan-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
2014-05-17  9:41         ` Wolfram Sang
2014-05-17 13:13           ` Lan Tianyu
2014-05-17 17:15             ` Wolfram Sang
2014-04-28 14:27     ` [Patch V2 6/9] I2C: Add smbus word/block process call " Lan Tianyu
2014-05-17 10:21       ` Wolfram Sang
2014-05-17 13:59         ` Lan Tianyu
     [not found]           ` <53776B32.8010400-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
2014-05-17 17:17             ` Wolfram Sang
2014-05-19  9:23               ` Lan Tianyu
2014-04-28 14:27     ` [Patch V2 7/9] I2C/ACPI: Add i2c ACPI operation region support Lan Tianyu
2014-04-29  8:02       ` Mika Westerberg
2014-04-28 14:27     ` [Patch V2 9/9] I2C/ACPI: Add CONFIG_I2C_ACPI config Lan Tianyu
2014-04-29  8:16       ` Mika Westerberg
2014-05-17 17:48         ` Wolfram Sang
2014-05-19  8:49           ` Mika Westerberg
     [not found]             ` <20140519084944.GH2067-3PARRvDOhMZrdx17CPfAsdBPR1lH4CV8@public.gmane.org>
2014-05-19  9:44               ` Lan Tianyu
     [not found]                 ` <5379D28F.1020200-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
2014-05-19 20:23                   ` Rafael J. Wysocki
     [not found]     ` <1398695268-28645-1-git-send-email-tianyu.lan-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
2014-04-28 14:27       ` Lan Tianyu [this message]
2014-04-28 22:51       ` [Patch V2 0/9] I2C ACPI operation region handler support Rafael J. Wysocki
     [not found]         ` <43726986.W0L99n76oE-sKB8Sp2ER+y1GS7QM15AGw@public.gmane.org>
2014-04-29  1:54           ` Lan Tianyu
2014-04-29 15:47             ` Rafael J. Wysocki
2014-05-13 13:09       ` Rolf Eike Beer
2014-05-13 14:06         ` Lan Tianyu
     [not found]           ` <53722700.6010001-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
2014-05-15  7:50             ` Rolf Eike Beer
2014-05-15 14:49               ` Lan Tianyu
     [not found]                 ` <5374D401.2010608-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
2014-05-16  8:43                   ` Rolf Eike Beer
2014-05-20 14:17               ` Rolf Eike Beer
2014-05-22 15:14                 ` Lan Tianyu
     [not found]                   ` <537E143F.7060701-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
2014-05-23  6:55                     ` Rolf Eike Beer

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=1398695268-28645-9-git-send-email-tianyu.lan@intel.com \
    --to=tianyu.lan-ral2jqcrhueavxtiumwx3w@public.gmane.org \
    --cc=awilliam-H+wXaHxf7aLQT0dZR+AlfA@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=mika.westerberg-VuQAYsv1563Yd54FQh9/CA@public.gmane.org \
    --cc=rjw-LthD3rsA81gm4RdzfppkhA@public.gmane.org \
    --cc=wsa-z923LK4zBo2bacvFa/9K2g@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).