Skip to contentSkip to conversation

x86: enable common clk and add support for Lynxpoint clocks

PATCH Superseded Mika Westerberg 3 participants 12 messages Jan 14, 2013 – Jan 17, 2013

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover x86: enable common clk and add support for Lynxpoint clocks

Hi all,

The discussion that lead to this patch series starts from the below thread:

	http://thread.gmane.org/gmane.linux.kernel/1417691

In summary, there is no point in adding a special case code to the drivers in order to pass them a fixed clock rate, but instead x86 should just enable common clk subsystem and take advantage of it.

This has been proposed before by Mark Brown but for some reason it has not merged into x86 tree.

This series tries to do the same but in this time we have real users for the clk API.

[1/3] Enables the common clk framework on x86
[2/3] Adds Intel Lynxpoint Low Power Subsystem specific clocks as platform
driver.
[3/3] Creates the platform device for the LPSS clocks driver if we find out
that the Lynxpoint LPSS devices are available.

This series is based on Rafael's linux-pm/linux-next branch because there is a dependency to the ACPI scan rework by Rafael.

Please review.

Mika Westerberg (3):
x86: enable common clk on x86
clk: x86: add support for Lynxpoint LPSS clocks
ACPI: create Lynxpoint clocks if LPSS devices are found during scan

 arch/x86/Kconfig           |    1 +
 drivers/acpi/scan.c        |   36 ++++++++++++----
 drivers/clk/Makefile       |    1 +
 drivers/clk/x86/Makefile   |    2 +
 drivers/clk/x86/clk-lpss.c |   99 ++++++++++++++++++++++++++++++++++++++++++++
 drivers/clk/x86/clk-lpss.h |   36 ++++++++++++++++
 drivers/clk/x86/clk-lpt.c  |   86 ++++++++++++++++++++++++++++++++++++++
 7 files changed, 252 insertions(+), 9 deletions(-)
 create mode 100644 drivers/clk/x86/Makefile
 create mode 100644 drivers/clk/x86/clk-lpss.c
 create mode 100644 drivers/clk/x86/clk-lpss.h
 create mode 100644 drivers/clk/x86/clk-lpt.c
Signature · 1 line
1.7.10.4
#9 lore raw

PATCH 3/3 ACPI: create Lynxpoint clocks if LPSS devices are found during scan

Since we don't want to create the Lynxpoint LPSS clock tree on a machines where no LPSS exists at all we look for the Lynxpoint device ACPI HIDs during ACPI namespace scan and if a known device is seen we assume that it is safe to create the LPSS clocks.

Therefore we allow init function to be passed via acpi_platform_device_ids[] table which is called whenever the corresponding device is found.

---
 drivers/acpi/scan.c |   36 +++++++++++++++++++++++++++---------
 1 file changed, 27 insertions(+), 9 deletions(-)
drivers/acpi/scan.c +27 -9
index 6a12702..8d9965e 100644
@@ -11,6 +11,7 @@
 #include <linux/kthread.h>
 #include <linux/dmi.h>
 #include <linux/nls.h>
+#include <linux/platform_device.h>
 
 #include <acpi/acpi_drivers.h>
 
@@ -29,6 +30,15 @@ extern struct acpi_device *acpi_root;
 
 static const char *dummy_hid = "device";
 
+static void lpt_lpss_init_once(void)
+{
+	static struct platform_device *pdev;
+
+	/* Lynxpoint LPSS clocks */
+	if (!pdev)
+		pdev = platform_device_register_simple("clk-lpt", -1, NULL, 0);
+}
+
 /*
  * The following ACPI IDs are known to be suitable for representing as
  * platform devices.
@@ -38,14 +48,14 @@ static const struct acpi_device_id acpi_platform_device_ids[] = {
 	{ "PNP0D40" },
 
 	/* Haswell LPSS devices */
-	{ "INT33C0", 0 },
-	{ "INT33C1", 0 },
-	{ "INT33C2", 0 },
-	{ "INT33C3", 0 },
-	{ "INT33C4", 0 },
-	{ "INT33C5", 0 },
-	{ "INT33C6", 0 },
-	{ "INT33C7", 0 },
+	{ "INT33C0", (kernel_ulong_t)lpt_lpss_init_once },
+	{ "INT33C1", (kernel_ulong_t)lpt_lpss_init_once },
+	{ "INT33C2", (kernel_ulong_t)lpt_lpss_init_once },
+	{ "INT33C3", (kernel_ulong_t)lpt_lpss_init_once },
+	{ "INT33C4", (kernel_ulong_t)lpt_lpss_init_once },
+	{ "INT33C5", (kernel_ulong_t)lpt_lpss_init_once },
+	{ "INT33C6", (kernel_ulong_t)lpt_lpss_init_once },
+	{ "INT33C7", (kernel_ulong_t)lpt_lpss_init_once },
 
 	{ }
 };
@@ -1580,6 +1590,7 @@ static acpi_status acpi_bus_check_add(acpi_handle handle, u32 lvl_not_used,
 static acpi_status acpi_bus_device_attach(acpi_handle handle, u32 lvl_not_used,
 					  void *not_used, void **ret_not_used)
 {
+	const struct acpi_device_id *id;
 	acpi_status status = AE_OK;
 	struct acpi_device *device;
 	unsigned long long sta_not_used;
@@ -1595,7 +1606,14 @@ static acpi_status acpi_bus_device_attach(acpi_handle handle, u32 lvl_not_used,
 	if (acpi_bus_get_device(handle, &device))
 		return AE_CTRL_DEPTH;
 
-	if (!acpi_match_device_ids(device, acpi_platform_device_ids)) {
+	id = __acpi_match_device(device, acpi_platform_device_ids);
+	if (id) {
+		void (*init)(void) = (void (*)(void))id->driver_data;
+
+		/* Run any initialization if required */
+		if (init)
+			init();
+
 		/* This is a known good platform device. */
 		acpi_create_platform_device(device);
 	} else if (device_attach(&device->dev) < 0) {
Signature · 1 line
1.7.10.4
#1 lore raw

PATCH 1/3 x86: enable common clk on x86

In reply to Mika Westerberg

We are starting to see traditional SoC peripherals also in the x86 world, things like UART, I2C and SPI controllers that might already have a working device driver. These drivers typically take advantage of the Linux clk framework to control and retrieve information about the peripheral clock.

There hasn't been a standard way on x86 to pass the clock rate from whatever configuration system is used to the driver, but instead different variations have emerged, like adding this information to the platform data.

In order to use the standard Linux way we enable the common clk subsystem also on x86. This allows us to re-use the drivers with little or no modification wrt. clock API usage.

This patch was originally proposed by Mark Brown.

---
 arch/x86/Kconfig |    1 +
 1 file changed, 1 insertion(+)
arch/x86/Kconfig +1 -0
index 79795af..decda04 100644
@@ -114,6 +114,7 @@ config X86
 	select MODULES_USE_ELF_RELA if X86_64
 	select CLONE_BACKWARDS if X86_32
 	select GENERIC_SIGALTSTACK
+	select COMMON_CLK
 
 config INSTRUCTION_DECODER
 	def_bool y
Signature · 1 line
1.7.10.4
#7 lore raw

PATCH 2/3 clk: x86: add support for Lynxpoint LPSS clocks

In reply to Mika Westerberg

Intel Lynxpoint Low Power Subsystem hosts peripherals like UART, I2C and SPI controllers. For most of these there is a configuration register that allows software to enable and disable the functional clock. Disabling the clock while the peripheral is not used saves power.

In order to take advantage of this we add a new clock gate of type 'lpss_gate' that just re-uses the ordinary clk_gate but in addition is able to enumerate the base address register of the device using ACPI.

We then create a clock tree that models the Lynxpoint LPSS clocks using these gates and fixed clocks so that we can pass clock rate to the drivers as well.

---
 drivers/clk/Makefile       |    1 +
 drivers/clk/x86/Makefile   |    2 +
 drivers/clk/x86/clk-lpss.c |   99 ++++++++++++++++++++++++++++++++++++++++++++
 drivers/clk/x86/clk-lpss.h |   36 ++++++++++++++++
 drivers/clk/x86/clk-lpt.c  |   86 ++++++++++++++++++++++++++++++++++++++
 5 files changed, 224 insertions(+)
 create mode 100644 drivers/clk/x86/Makefile
 create mode 100644 drivers/clk/x86/clk-lpss.c
 create mode 100644 drivers/clk/x86/clk-lpss.h
 create mode 100644 drivers/clk/x86/clk-lpt.c
drivers/clk/Makefile +1 -0
index ee90e87..ee11460 100644
@@ -22,6 +22,7 @@ obj-$(CONFIG_ARCH_U8500)	+= ux500/
 obj-$(CONFIG_ARCH_VT8500)	+= clk-vt8500.o
 obj-$(CONFIG_ARCH_SUNXI)	+= clk-sunxi.o
 obj-$(CONFIG_ARCH_ZYNQ)		+= clk-zynq.o
+obj-$(CONFIG_X86)		+= x86/
 
 # Chip specific
 obj-$(CONFIG_COMMON_CLK_WM831X) += clk-wm831x.o
drivers/clk/x86/Makefile new file +2 -0
new file mode 100644
index 0000000..9ca9c83
@@ -0,0 +1,2 @@
+obj-$(CONFIG_ACPI)		+= clk-lpss.o
+obj-y				+= clk-lpt.o
drivers/clk/x86/clk-lpss.c new file +99 -0

99 lines not on this page · raw message

drivers/clk/x86/clk-lpss.h new file +36 -0
new file mode 100644
index 0000000..e9460f4
@@ -0,0 +1,36 @@
+/*
+ * Intel Low Power Subsystem clock.
+ *
+ * Copyright (C) 2013, Intel Corporation
+ * Authors: Mika Westerberg <[email protected]>
+ *	    Heikki Krogerus <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#ifndef __CLK_LPSS_H
+#define __CLK_LPSS_H
+
+#include <linux/err.h>
+#include <linux/errno.h>
+#include <linux/clk.h>
+
+#ifdef CONFIG_ACPI
+extern struct clk *clk_register_lpss_gate(const char *name,
+					  const char *parent_name,
+					  const char *hid, const char *uid,
+					  unsigned offset);
+#else
+static inline struct clk *clk_register_lpss_gate(const char *name,
+						 const char *parent_name,
+						 const char *hid,
+						 const char *uid,
+						 unsigned offset)
+{
+	return ERR_PTR(-ENODEV);
+}
+#endif
+
+#endif /* __CLK_LPSS_H */
drivers/clk/x86/clk-lpt.c new file +86 -0

86 lines not on this page · raw message

Signature · 1 line
1.7.10.4
Reviewed-by on v1 2/3
#8 lore raw

Re: [PATCH 2/3] clk: x86: add support for Lynxpoint LPSS clocks

Quoted 5 lines · Mika Westerberg

Intel Lynxpoint Low Power Subsystem hosts peripherals like UART, I2C and SPI controllers. For most of these there is a configuration register that allows software to enable and disable the functional clock. Disabling the clock while the peripheral is not used saves power.

Quoted 7 lines

In order to take advantage of this we add a new clock gate of type 'lpss_gate' that just re-uses the ordinary clk_gate but in addition is able to enumerate the base address register of the device using ACPI.

We then create a clock tree that models the Lynxpoint LPSS clocks using these gates and fixed clocks so that we can pass clock rate to the drivers as well.

#11 lore raw
In reply to Mika Westerberg
Quoted 16 lines · Mika Westerberg

Hi all,

The discussion that lead to this patch series starts from the below thread:

	http://thread.gmane.org/gmane.linux.kernel/1417691

In summary, there is no point in adding a special case code to the drivers in order to pass them a fixed clock rate, but instead x86 should just enable common clk subsystem and take advantage of it.

This has been proposed before by Mark Brown but for some reason it has not merged into x86 tree.

This series tries to do the same but in this time we have real users for the clk API.

Quoted 8 lines

[1/3] Enables the common clk framework on x86
[2/3] Adds Intel Lynxpoint Low Power Subsystem specific clocks as platform
driver.
[3/3] Creates the platform device for the LPSS clocks driver if we find out
that the Lynxpoint LPSS devices are available.

This series is based on Rafael's linux-pm/linux-next branch because there is a dependency to the ACPI scan rework by Rafael.

I meant that they apply on top of 3.8-rcX but in order to patch [2/3] to work it needs to have the ACPI scan rework patches. Otherwise it is not able to find the base addresses of the devices.

#2 lore raw

Re: [PATCH 1/3] x86: enable common clk on x86

In reply to Mika Westerberg
Quoted 9 lines · Mika Westerberg

We are starting to see traditional SoC peripherals also in the x86 world, things like UART, I2C and SPI controllers that might already have a working device driver. These drivers typically take advantage of the Linux clk framework to control and retrieve information about the peripheral clock.

There hasn't been a standard way on x86 to pass the clock rate from whatever configuration system is used to the driver, but instead different variations have emerged, like adding this information to the platform data.

Quoted 5 lines

In order to use the standard Linux way we enable the common clk subsystem also on x86. This allows us to re-use the drivers with little or no modification wrt. clock API usage.

This patch was originally proposed by Mark Brown.

Are there any side effects of selecting COMMON_CLK by an arch and if so then what are they?

Rafael

Quoted 18 lines
---
 arch/x86/Kconfig |    1 +
 1 file changed, 1 insertion(+)
arch/x86/Kconfig +1 -0
index 79795af..decda04 100644
@@ -114,6 +114,7 @@ config X86
 	select MODULES_USE_ELF_RELA if X86_64
 	select CLONE_BACKWARDS if X86_32
 	select GENERIC_SIGALTSTACK
+	select COMMON_CLK
 
 config INSTRUCTION_DECODER
 	def_bool y
Signature · 2 lines
I speak only for myself.
Rafael J. Wysocki, Intel Open Source Technology Center.
#3 lore raw

Re: [PATCH 1/3] x86: enable common clk on x86

Quoted 10 lines · Rafael J. Wysocki
Quoted 9 lines · Mika Westerberg

We are starting to see traditional SoC peripherals also in the x86 world, things like UART, I2C and SPI controllers that might already have a working device driver. These drivers typically take advantage of the Linux clk framework to control and retrieve information about the peripheral clock.

There hasn't been a standard way on x86 to pass the clock rate from whatever configuration system is used to the driver, but instead different variations have emerged, like adding this information to the platform data.

Quoted 8 lines
Quoted 5 lines

In order to use the standard Linux way we enable the common clk subsystem also on x86. This allows us to re-use the drivers with little or no modification wrt. clock API usage.

This patch was originally proposed by Mark Brown.

Are there any side effects of selecting COMMON_CLK by an arch and if so then what are they?

Selecting COMMON_CLK also selects HAVE_CLK, so drivers that are dependent on that option become available when you run make config.

It also makes clk_get() and friends to return errors if the clock is not found (instead of returning NULL as in case with !HAVE_CLK). This means that if there is a driver that counted on the stubbed out clocks on x86 it will fail to get the clock after this patch. However, the patch that adds the stub functions was merged only lately:

commit 93abe8e4b13ae9a0428ce940a8a03ac72a7626f1
Author: Viresh Kumar <[email protected]>
Date: Mon Jul 30 14:39:27 2012 -0700

clk: add non CONFIG_HAVE_CLK routines

Many drivers are shared between architectures that may or may not have HAVE_CLK selected for them. To remove compilation errors for them we enclose clk_*() calls in these drivers within #ifdef CONFIG_HAVE_CLK, #endif.

This patch removes the need of these CONFIG_HAVE_CLK statements, by introducing dummy routines when HAVE_CLK is not selected by platforms. So, definition of these routines will always be available. These calls will return error for platforms that don't select HAVE_CLK.

#4 lore raw

Re: [PATCH 1/3] x86: enable common clk on x86

Quoted 15 lines · Mika Westerberg
Quoted 14 lines · Rafael J. Wysocki
Quoted 13 lines · Mika Westerberg

We are starting to see traditional SoC peripherals also in the x86 world, things like UART, I2C and SPI controllers that might already have a working device driver. These drivers typically take advantage of the Linux clk framework to control and retrieve information about the peripheral clock.

There hasn't been a standard way on x86 to pass the clock rate from whatever configuration system is used to the driver, but instead different variations have emerged, like adding this information to the platform data.

In order to use the standard Linux way we enable the common clk subsystem also on x86. This allows us to re-use the drivers with little or no modification wrt. clock API usage.

Quoted 7 lines
Quoted 4 lines
Quoted 1 line

This patch was originally proposed by Mark Brown.

Are there any side effects of selecting COMMON_CLK by an arch and if so then what are they?

Selecting COMMON_CLK also selects HAVE_CLK, so drivers that are dependent on that option become available when you run make config.

Well, that's not very nice. Do you know how many of them there are?

Distros often build all drivers available regardless of whether or not they are going to be used and it would be kind of wasteful for them to build drivers that aren't even going to work.

Quoted 17 lines

It also makes clk_get() and friends to return errors if the clock is not found (instead of returning NULL as in case with !HAVE_CLK). This means that if there is a driver that counted on the stubbed out clocks on x86 it will fail to get the clock after this patch. However, the patch that adds the stub functions was merged only lately:

commit 93abe8e4b13ae9a0428ce940a8a03ac72a7626f1
Author: Viresh Kumar <[email protected]>
Date: Mon Jul 30 14:39:27 2012 -0700

clk: add non CONFIG_HAVE_CLK routines

Many drivers are shared between architectures that may or may not have HAVE_CLK selected for them. To remove compilation errors for them we enclose clk_*() calls in these drivers within #ifdef CONFIG_HAVE_CLK, #endif.

Quoted 5 lines

This patch removes the need of these CONFIG_HAVE_CLK statements, by introducing dummy routines when HAVE_CLK is not selected by platforms. So, definition of these routines will always be available. These calls will return error for platforms that don't select HAVE_CLK.
--

That should be fine, then.

Peter, what do you think?

Rafael

Signature · 2 lines
I speak only for myself.
Rafael J. Wysocki, Intel Open Source Technology Center.
#5 lore raw

Re: [PATCH 1/3] x86: enable common clk on x86

Quoted 18 lines · Rafael J. Wysocki
Quoted 17 lines · Mika Westerberg
Quoted 16 lines · Rafael J. Wysocki
Quoted 14 lines · Mika Westerberg

We are starting to see traditional SoC peripherals also in the x86 world, things like UART, I2C and SPI controllers that might already have a working device driver. These drivers typically take advantage of the Linux clk framework to control and retrieve information about the peripheral clock.

There hasn't been a standard way on x86 to pass the clock rate from whatever configuration system is used to the driver, but instead different variations have emerged, like adding this information to the platform data.

In order to use the standard Linux way we enable the common clk subsystem also on x86. This allows us to re-use the drivers with little or no modification wrt. clock API usage.

This patch was originally proposed by Mark Brown.

Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

Are there any side effects of selecting COMMON_CLK by an arch and if so then what are they?

Selecting COMMON_CLK also selects HAVE_CLK, so drivers that are dependent on that option become available when you run make config.

Well, that's not very nice. Do you know how many of them there are?

There are few. I tried how many I get on my config and there were 9 new questions with 'make oldconfig'.

Grepping (if I did it correctly) reveals:

% git grep 'depends .*HAVE_CLK' -- '*/Kconfig' | wc -l 27

Quoted 3 lines

Distros often build all drivers available regardless of whether or not they are going to be used and it would be kind of wasteful for them to build drivers that aren't even going to work.

If a driver depends only on HAVE_CLK and doesn't work everywhere, there is a problem in that particular driver and its Kconfig options (some dependencies are missing). These drivers should be fixed.

#6 lore raw

Re: [PATCH 1/3] x86: enable common clk on x86

Quoted 35 lines · Mika Westerberg
Quoted 18 lines · Rafael J. Wysocki
Quoted 17 lines · Mika Westerberg
Quoted 16 lines · Rafael J. Wysocki
Quoted 14 lines · Mika Westerberg

We are starting to see traditional SoC peripherals also in the x86 world, things like UART, I2C and SPI controllers that might already have a working device driver. These drivers typically take advantage of the Linux clk framework to control and retrieve information about the peripheral clock.

There hasn't been a standard way on x86 to pass the clock rate from whatever configuration system is used to the driver, but instead different variations have emerged, like adding this information to the platform data.

In order to use the standard Linux way we enable the common clk subsystem also on x86. This allows us to re-use the drivers with little or no modification wrt. clock API usage.

This patch was originally proposed by Mark Brown.

Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

Are there any side effects of selecting COMMON_CLK by an arch and if so then what are they?

Selecting COMMON_CLK also selects HAVE_CLK, so drivers that are dependent on that option become available when you run make config.

Well, that's not very nice. Do you know how many of them there are?

There are few. I tried how many I get on my config and there were 9 new questions with 'make oldconfig'.

Grepping (if I did it correctly) reveals:

% git grep 'depends .*HAVE_CLK' -- '*/Kconfig' | wc -l 27

Quoted 7 lines
Quoted 3 lines

Distros often build all drivers available regardless of whether or not they are going to be used and it would be kind of wasteful for them to build drivers that aren't even going to work.

If a driver depends only on HAVE_CLK and doesn't work everywhere, there is a problem in that particular driver and its Kconfig options (some dependencies are missing). These drivers should be fixed.

Well, on a second thought it might be better to add a new Kconfig option for x86, say CONFIG_INTEL_LPSS ("Intel LPSS Support") that will select COMMON_CLK and depend on ACPI. This way we'll only compile the clocks stuff when explicitly requested (although distros will probably set that to 'y' anyway).

Thanks,
Rafael

Signature · 2 lines
I speak only for myself.
Rafael J. Wysocki, Intel Open Source Technology Center.
#10 lore raw

Re: [PATCH 3/3] ACPI: create Lynxpoint clocks if LPSS devices are found during scan

In reply to Mika Westerberg
Quoted 75 lines · Mika Westerberg

Since we don't want to create the Lynxpoint LPSS clock tree on a machines where no LPSS exists at all we look for the Lynxpoint device ACPI HIDs during ACPI namespace scan and if a known device is seen we assume that it is safe to create the LPSS clocks.

Therefore we allow init function to be passed via acpi_platform_device_ids[] table which is called whenever the corresponding device is found.

---
 drivers/acpi/scan.c |   36 +++++++++++++++++++++++++++---------
 1 file changed, 27 insertions(+), 9 deletions(-)
drivers/acpi/scan.c +19 -8
index 6a12702..8d9965e 100644
@@ -11,6 +11,7 @@
 #include <linux/kthread.h>
 #include <linux/dmi.h>
 #include <linux/nls.h>
+#include <linux/platform_device.h>
 
 #include <acpi/acpi_drivers.h>
 
@@ -29,6 +30,15 @@ extern struct acpi_device *acpi_root;
 
 static const char *dummy_hid = "device";
 
+static void lpt_lpss_init_once(void)
+{
+	static struct platform_device *pdev;
+
+	/* Lynxpoint LPSS clocks */
+	if (!pdev)
+		pdev = platform_device_register_simple("clk-lpt", -1, NULL, 0);
+}
+
 /*
  * The following ACPI IDs are known to be suitable for representing as
  * platform devices.
@@ -38,14 +48,14 @@ static const struct acpi_device_id acpi_platform_device_ids[] = {
 	{ "PNP0D40" },
 
 	/* Haswell LPSS devices */
-	{ "INT33C0", 0 },
-	{ "INT33C1", 0 },
-	{ "INT33C2", 0 },
-	{ "INT33C3", 0 },
-	{ "INT33C4", 0 },
-	{ "INT33C5", 0 },
-	{ "INT33C6", 0 },
-	{ "INT33C7", 0 },
+	{ "INT33C0", (kernel_ulong_t)lpt_lpss_init_once },
+	{ "INT33C1", (kernel_ulong_t)lpt_lpss_init_once },
+	{ "INT33C2", (kernel_ulong_t)lpt_lpss_init_once },
+	{ "INT33C3", (kernel_ulong_t)lpt_lpss_init_once },
+	{ "INT33C4", (kernel_ulong_t)lpt_lpss_init_once },
+	{ "INT33C5", (kernel_ulong_t)lpt_lpss_init_once },
+	{ "INT33C6", (kernel_ulong_t)lpt_lpss_init_once },
+	{ "INT33C7", (kernel_ulong_t)lpt_lpss_init_once },
 
 	{ }
 };
@@ -1580,6 +1590,7 @@ static acpi_status acpi_bus_check_add(acpi_handle handle, u32 lvl_not_used,
 static acpi_status acpi_bus_device_attach(acpi_handle handle, u32 lvl_not_used,
 					  void *not_used, void **ret_not_used)
 {
+	const struct acpi_device_id *id;
 	acpi_status status = AE_OK;
 	struct acpi_device *device;
 	unsigned long long sta_not_used;
@@ -1595,7 +1606,14 @@ static acpi_status acpi_bus_device_attach(acpi_handle handle, u32 lvl_not_used,
 	if (acpi_bus_get_device(handle, &device))
 		return AE_CTRL_DEPTH;

drivers/acpi/scan.c static acpi_status acpi_bus_device_attach(acpi_handle handle, u32 lvl_not_used, · line 1616

Quoted 10 lines
drivers/acpi/scan.c +8 -1
 
-	if (!acpi_match_device_ids(device, acpi_platform_device_ids)) {
+	id = __acpi_match_device(device, acpi_platform_device_ids);
+	if (id) {
+		void (*init)(void) = (void (*)(void))id->driver_data;
+
+		/* Run any initialization if required */
+		if (init)
+			init();
+

I'd prefer this to be done by acpi_create_platform_device() and you can add an extra arg to it for this purpose.

Moreover the driver_data need not be a function pointer. I actually think it should consist of a number of flags that may be set or unset and the 0 bit could be ACPI_PLATFORM_CLK or something like this. Then, if that is set in its (new) second arg, acpi_create_platform_device() will do the platform_device_register_simple("clk-lpt", ...), if not done already.

And yes, we may need those flags for other stuff.

drivers/acpi/scan.c static acpi_status acpi_bus_device_attach(acpi_handle handle, u32 lvl_not_used, · line 1619

Quoted 4 lines
drivers/acpi/scan.c +0 -0
 		/* This is a known good platform device. */
 		acpi_create_platform_device(device);
 	} else if (device_attach(&device->dev) < 0) {

Thanks,
Rafael

Signature · 2 lines
I speak only for myself.
Rafael J. Wysocki, Intel Open Source Technology Center.