[PATCH V4 02/11] PNPACPI: use whilte list for pnpacpi device enumeration

2014-03-17 Thread Zhang Rui
ACPI can be used to enumerate PNP devices, but the code does not
handle this in a good manner.

Currently, if an ACPI device
1. has _CRS method,
2. has an identifications of
   "three capital charactors followed by four hex numbers",
3. is not in the excluded id list,
it is enumerated to PNP bus.

So actually, PNP bus is used as the default bus for enumerating _HID devices.

But, nowadays, more and more _HID devices are needed to be enumerate to
platform bus instead. And a white list is used for those devices to avoid
overlapping with PNP bus.
The problem is that this list is continuously growing.

So, a solution that uses platform bus as the default bus for _HID enumeration
is preferred.
In order to do this, this patch changes the way of enumerating PNP devices.
As the first step, we use a white list (scan handler) to create PNP devices
instead. This white list contains all the pnp_device_id strings in all the pnp
drivers, thus this change is transparent to PNP core and all the PNP drivers.

Note: I just grep all the id strings in all pnp_device_id instances and
  copy them to the new white list, with a few changes to the comments
  only, to follow the format of:

  /* driver name, or file name if not a PNP driver */
  {"id-string"}, /* optional comments for the id-string */
  ...

Note: the PNPACPI devices are created in two step,
  1. mark the PNPACPI devices by the acpi pnp scan handler.
  2. create the PNPACPI devices in PNPACPI code in a fs_initcall()
  In this case, if PNP/PNPACPI is not set or "pnpacpi=off" kernel option
  is used, the acpi pnp scan handler is still there, to prevent those
  PNPACPI devices from being created to platform bus.

TODO: Reduce this PNPACPI white list by
  1. remove the ids for the devices that are never enumerated via ACPI
  2. remove the ids and convert the drivers to platform bus drivers
 for the devices that are not PNP devices in nature.

Signed-off-by: Zhang Rui 
---
 drivers/acpi/Makefile  |1 +
 drivers/acpi/acpi_pnp.c|  367 
 drivers/acpi/internal.h|1 +
 drivers/acpi/scan.c|1 +
 drivers/pnp/pnpacpi/core.c |   28 +---
 include/linux/acpi.h   |2 +
 6 files changed, 376 insertions(+), 24 deletions(-)
 create mode 100644 drivers/acpi/acpi_pnp.c

diff --git a/drivers/acpi/Makefile b/drivers/acpi/Makefile
index 0331f91..9a43893 100644
--- a/drivers/acpi/Makefile
+++ b/drivers/acpi/Makefile
@@ -41,6 +41,7 @@ acpi-$(CONFIG_ACPI_DOCK)  += dock.o
 acpi-y += pci_root.o pci_link.o pci_irq.o
 acpi-$(CONFIG_X86_INTEL_LPSS)  += acpi_lpss.o
 acpi-y += acpi_platform.o
+acpi-y += acpi_pnp.o
 acpi-y += power.o
 acpi-y += event.o
 acpi-y += sysfs.o
diff --git a/drivers/acpi/acpi_pnp.c b/drivers/acpi/acpi_pnp.c
new file mode 100644
index 000..5971934
--- /dev/null
+++ b/drivers/acpi/acpi_pnp.c
@@ -0,0 +1,367 @@
+/*
+ * ACPI support for PNP bus type
+ *
+ * Copyright (C) 2014, Intel Corporation
+ * Authors: Zhang Rui 
+ *
+ * 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.
+ */
+
+#include 
+#include 
+
+static const struct acpi_device_id acpi_pnp_device_ids[] = {
+   /* pata_isapnp */
+   {"PNP0600"},/* Generic ESDI/IDE/ATA compatible hard disk 
controller */
+   /* floppy */
+   {"PNP0700"},
+   /* ipmi_si */
+   {"IPI0001"},
+   /* tpm_inf_pnp */
+   {"IFX0101"},/* Infineon TPMs */
+   {"IFX0102"},/* Infineon TPMs */
+   /*tpm_tis */
+   {"PNP0C31"},/* TPM */
+   {"ATM1200"},/* Atmel */
+   {"IFX0102"},/* Infineon */
+   {"BCM0101"},/* Broadcom */
+   {"BCM0102"},/* Broadcom */
+   {"NSC1200"},/* National */
+   {"ICO0102"},/* Intel */
+   /* ide   */
+   {"PNP0600"},/* Generic ESDI/IDE/ATA compatible hard disk 
controller */
+   /* ns558 */
+   {"@P@0001"},/* ALS 100 */
+   {"@P@0020"},/* ALS 200 */
+   {"@P@1001"},/* ALS 100+ */
+   {"@P@2001"},/* ALS 120 */
+   {"ASB16fd"},/* AdLib NSC16 */
+   {"AZT3001"},/* AZT1008 */
+   {"CDC0001"},/* Opl3-SAx */
+   {"CSC0001"},/* CS4232 */
+   {"CSC000f"},/* CS4236 */
+   {"CSC0101"},/* CS4327 */
+   {"CTL7001"},/* SB16 */
+   {"CTL7002"},/* AWE64 */
+   {"CTL7005"},/* Vibra16 */
+   {"ENS2020"},/* SoundscapeVIVO */
+   {"ESS0001"},/* ES1869 */
+   {"ESS0005"}, 

[PATCH V4 02/11] PNPACPI: use whilte list for pnpacpi device enumeration

2014-03-17 Thread Zhang Rui
ACPI can be used to enumerate PNP devices, but the code does not
handle this in a good manner.

Currently, if an ACPI device
1. has _CRS method,
2. has an identifications of
   three capital charactors followed by four hex numbers,
3. is not in the excluded id list,
it is enumerated to PNP bus.

So actually, PNP bus is used as the default bus for enumerating _HID devices.

But, nowadays, more and more _HID devices are needed to be enumerate to
platform bus instead. And a white list is used for those devices to avoid
overlapping with PNP bus.
The problem is that this list is continuously growing.

So, a solution that uses platform bus as the default bus for _HID enumeration
is preferred.
In order to do this, this patch changes the way of enumerating PNP devices.
As the first step, we use a white list (scan handler) to create PNP devices
instead. This white list contains all the pnp_device_id strings in all the pnp
drivers, thus this change is transparent to PNP core and all the PNP drivers.

Note: I just grep all the id strings in all pnp_device_id instances and
  copy them to the new white list, with a few changes to the comments
  only, to follow the format of:

  /* driver name, or file name if not a PNP driver */
  {id-string}, /* optional comments for the id-string */
  ...

Note: the PNPACPI devices are created in two step,
  1. mark the PNPACPI devices by the acpi pnp scan handler.
  2. create the PNPACPI devices in PNPACPI code in a fs_initcall()
  In this case, if PNP/PNPACPI is not set or pnpacpi=off kernel option
  is used, the acpi pnp scan handler is still there, to prevent those
  PNPACPI devices from being created to platform bus.

TODO: Reduce this PNPACPI white list by
  1. remove the ids for the devices that are never enumerated via ACPI
  2. remove the ids and convert the drivers to platform bus drivers
 for the devices that are not PNP devices in nature.

Signed-off-by: Zhang Rui rui.zh...@intel.com
---
 drivers/acpi/Makefile  |1 +
 drivers/acpi/acpi_pnp.c|  367 
 drivers/acpi/internal.h|1 +
 drivers/acpi/scan.c|1 +
 drivers/pnp/pnpacpi/core.c |   28 +---
 include/linux/acpi.h   |2 +
 6 files changed, 376 insertions(+), 24 deletions(-)
 create mode 100644 drivers/acpi/acpi_pnp.c

diff --git a/drivers/acpi/Makefile b/drivers/acpi/Makefile
index 0331f91..9a43893 100644
--- a/drivers/acpi/Makefile
+++ b/drivers/acpi/Makefile
@@ -41,6 +41,7 @@ acpi-$(CONFIG_ACPI_DOCK)  += dock.o
 acpi-y += pci_root.o pci_link.o pci_irq.o
 acpi-$(CONFIG_X86_INTEL_LPSS)  += acpi_lpss.o
 acpi-y += acpi_platform.o
+acpi-y += acpi_pnp.o
 acpi-y += power.o
 acpi-y += event.o
 acpi-y += sysfs.o
diff --git a/drivers/acpi/acpi_pnp.c b/drivers/acpi/acpi_pnp.c
new file mode 100644
index 000..5971934
--- /dev/null
+++ b/drivers/acpi/acpi_pnp.c
@@ -0,0 +1,367 @@
+/*
+ * ACPI support for PNP bus type
+ *
+ * Copyright (C) 2014, Intel Corporation
+ * Authors: Zhang Rui rui.zh...@intel.com
+ *
+ * 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.
+ */
+
+#include linux/acpi.h
+#include linux/module.h
+
+static const struct acpi_device_id acpi_pnp_device_ids[] = {
+   /* pata_isapnp */
+   {PNP0600},/* Generic ESDI/IDE/ATA compatible hard disk 
controller */
+   /* floppy */
+   {PNP0700},
+   /* ipmi_si */
+   {IPI0001},
+   /* tpm_inf_pnp */
+   {IFX0101},/* Infineon TPMs */
+   {IFX0102},/* Infineon TPMs */
+   /*tpm_tis */
+   {PNP0C31},/* TPM */
+   {ATM1200},/* Atmel */
+   {IFX0102},/* Infineon */
+   {BCM0101},/* Broadcom */
+   {BCM0102},/* Broadcom */
+   {NSC1200},/* National */
+   {ICO0102},/* Intel */
+   /* ide   */
+   {PNP0600},/* Generic ESDI/IDE/ATA compatible hard disk 
controller */
+   /* ns558 */
+   {@P@0001},/* ALS 100 */
+   {@P@0020},/* ALS 200 */
+   {@P@1001},/* ALS 100+ */
+   {@P@2001},/* ALS 120 */
+   {ASB16fd},/* AdLib NSC16 */
+   {AZT3001},/* AZT1008 */
+   {CDC0001},/* Opl3-SAx */
+   {CSC0001},/* CS4232 */
+   {CSC000f},/* CS4236 */
+   {CSC0101},/* CS4327 */
+   {CTL7001},/* SB16 */
+   {CTL7002},/* AWE64 */
+   {CTL7005},/* Vibra16 */
+   {ENS2020},/* SoundscapeVIVO */
+   {ESS0001},/* ES1869 */
+   {ESS0005},