Re: [PATCH v3 1/3] ACPI: amba bus probing support

2015-12-22 Thread Andy Shevchenko
On Tue, Dec 22, 2015 at 1:54 AM, Vladimir Zapolskiy  wrote:
> On 21.12.2015 18:41, Aleksey Makarov wrote:

>> +static int amba_handler_attach(struct acpi_device *adev,
>> + const struct acpi_device_id *id)
>> +{
>> + struct amba_device *dev = NULL;
>> + struct acpi_device *acpi_parent;
>> + struct resource_entry *rentry;
>> + struct list_head resource_list;
>> + struct resource *resources = NULL;
>> + bool address_found = false;
>> + int ret, count, irq_no = 0;
>> +
>> + /* If the ACPI node already has a physical device attached, skip it. */
>> + if (adev->physical_node_count)
>> + return 0;
>> +
>> + amba_register_dummy_clk();
>
> Since it is a single time dummy clock registration, may be it is better
> to move it to acpi_amba_init() or somewhere else? I understand that
> "apb_pclk" is wanted, but I'm not sure that this driver should serve as
> a clock provider.

Depends on actual hardware topology. Intel HW has few drivers that are
clock providers because they are really ones.

-- 
With Best Regards,
Andy Shevchenko
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH v3 1/3] ACPI: amba bus probing support

2015-12-22 Thread Andy Shevchenko
On Tue, Dec 22, 2015 at 1:54 AM, Vladimir Zapolskiy  wrote:
> On 21.12.2015 18:41, Aleksey Makarov wrote:

>> +static int amba_handler_attach(struct acpi_device *adev,
>> + const struct acpi_device_id *id)
>> +{
>> + struct amba_device *dev = NULL;
>> + struct acpi_device *acpi_parent;
>> + struct resource_entry *rentry;
>> + struct list_head resource_list;
>> + struct resource *resources = NULL;
>> + bool address_found = false;
>> + int ret, count, irq_no = 0;
>> +
>> + /* If the ACPI node already has a physical device attached, skip it. */
>> + if (adev->physical_node_count)
>> + return 0;
>> +
>> + amba_register_dummy_clk();
>
> Since it is a single time dummy clock registration, may be it is better
> to move it to acpi_amba_init() or somewhere else? I understand that
> "apb_pclk" is wanted, but I'm not sure that this driver should serve as
> a clock provider.

Depends on actual hardware topology. Intel HW has few drivers that are
clock providers because they are really ones.

-- 
With Best Regards,
Andy Shevchenko
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH v3 1/3] ACPI: amba bus probing support

2015-12-21 Thread Vladimir Zapolskiy
Hi,

On 21.12.2015 18:41, Aleksey Makarov wrote:
> From: Graeme Gregory 
> 
> On ARM64 some devices use the AMBA device and not the platform bus for
> probing so add support for this. Uses a dummy clock for apb_pclk as ACPI
> does not have a suitable clock representation and to keep the core
> AMBA bus code unchanged between probing methods.
> 
> Signed-off-by: Graeme Gregory 
> Signed-off-by: Aleksey Makarov 
> ---
>  drivers/acpi/Makefile|   1 +
>  drivers/acpi/acpi_amba.c | 149 
> +++
>  drivers/acpi/internal.h  |   5 ++
>  3 files changed, 155 insertions(+)
>  create mode 100644 drivers/acpi/acpi_amba.c
> 
> diff --git a/drivers/acpi/Makefile b/drivers/acpi/Makefile
> index 675eaf3..3cf732f 100644
> --- a/drivers/acpi/Makefile
> +++ b/drivers/acpi/Makefile
> @@ -43,6 +43,7 @@ acpi-y  += pci_root.o 
> pci_link.o pci_irq.o
>  acpi-y   += acpi_lpss.o acpi_apd.o
>  acpi-y   += acpi_platform.o
>  acpi-y   += acpi_pnp.o
> +acpi-$(CONFIG_ARM_AMBA)  += acpi_amba.o
>  acpi-y   += int340x_thermal.o
>  acpi-y   += power.o
>  acpi-y   += event.o
> diff --git a/drivers/acpi/acpi_amba.c b/drivers/acpi/acpi_amba.c
> new file mode 100644
> index 000..ebc8913
> --- /dev/null
> +++ b/drivers/acpi/acpi_amba.c
> @@ -0,0 +1,149 @@
> +
> +/*
> + * ACPI support for platform bus type.
> + *
> + * Copyright (C) 2015, Linaro Ltd
> + * Authors: Graeme Gregory 
> + *
> + * 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 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +#include "internal.h"
> +
> +static const struct acpi_device_id amba_id_list[] = {
> + {"ARMH0011", 0}, /* PL011 SBSA Uart */
> + {"ARMH0061", 0}, /* PL061 GPIO Device */
> + {"", 0},
> +};
> +
> +static struct clk *amba_dummy_clk;
> +
> +static void amba_register_dummy_clk(void)
> +{
> + struct clk *clk;
> +
> + /* If clock already registered */
> + if (amba_dummy_clk)
> + return;
> +
> + clk = clk_register_fixed_rate(NULL, "apb_pclk", NULL, CLK_IS_ROOT, 0);
> + clk_register_clkdev(clk, "apb_pclk", NULL);
> +
> + amba_dummy_clk = clk;
> +}
> +
> +static int amba_handler_attach(struct acpi_device *adev,
> + const struct acpi_device_id *id)
> +{
> + struct amba_device *dev = NULL;
> + struct acpi_device *acpi_parent;
> + struct resource_entry *rentry;
> + struct list_head resource_list;
> + struct resource *resources = NULL;
> + bool address_found = false;
> + int ret, count, irq_no = 0;
> +
> + /* If the ACPI node already has a physical device attached, skip it. */
> + if (adev->physical_node_count)
> + return 0;
> +
> + amba_register_dummy_clk();

Since it is a single time dummy clock registration, may be it is better
to move it to acpi_amba_init() or somewhere else? I understand that
"apb_pclk" is wanted, but I'm not sure that this driver should serve as
a clock provider.

> + dev = amba_device_alloc(NULL, 0, 0);
> + if (!dev) {
> + pr_err("%s(): amba_device_alloc() failed for %s\n",
> +__func__, dev_name(>dev));
> + return 0;
> + }
> +
> + INIT_LIST_HEAD(_list);
> + count = acpi_dev_get_resources(adev, _list, NULL, NULL);
> + if (count < 0) {
> + return 0;
> + } else if (count > 0) {

if you return from one of two if-branches, please don't use if-else nesting
for another one.

> + resources = kmalloc_array(count, sizeof(struct resource),
> + GFP_KERNEL);

resources is never used and it is never freed, why do you allocate it?

> + if (!resources) {
> + acpi_dev_free_resource_list(_list);
> + return 0;

return -ENOMEM; seems to be more appropriate here.

> + }
> + count = 0;
> + list_for_each_entry(rentry, _list, node) {
> + switch (resource_type(rentry->res)) {
> + case IORESOURCE_MEM:
> + if (!address_found) {
> + dev->res = *rentry->res;
> + address_found = true;
> + }
> + break;
> + case IORESOURCE_IRQ:
> + if (irq_no < AMBA_NR_IRQS)
> + dev->irq[irq_no++] = rentry->res->start;
> + break;
> + default:
> +   

Re: [PATCH v3 1/3] ACPI: amba bus probing support

2015-12-21 Thread G Gregory
On 21 December 2015 at 18:19, Andy Shevchenko  wrote:
> On Mon, Dec 21, 2015 at 6:41 PM, Aleksey Makarov
>  wrote:
>> From: Graeme Gregory 
>>
>> On ARM64 some devices use the AMBA device and not the platform bus for
>> probing so add support for this. Uses a dummy clock for apb_pclk as ACPI
>> does not have a suitable clock representation and to keep the core
>> AMBA bus code unchanged between probing methods.
>>
>> Signed-off-by: Graeme Gregory 
>> Signed-off-by: Aleksey Makarov 
>> ---
>>  drivers/acpi/Makefile|   1 +
>>  drivers/acpi/acpi_amba.c | 149 
>> +++
>>  drivers/acpi/internal.h  |   5 ++
>>  3 files changed, 155 insertions(+)
>>  create mode 100644 drivers/acpi/acpi_amba.c
>>
>> diff --git a/drivers/acpi/Makefile b/drivers/acpi/Makefile
>> index 675eaf3..3cf732f 100644
>> --- a/drivers/acpi/Makefile
>> +++ b/drivers/acpi/Makefile
>> @@ -43,6 +43,7 @@ acpi-y+= pci_root.o 
>> pci_link.o pci_irq.o
>>  acpi-y += acpi_lpss.o acpi_apd.o
>>  acpi-y += acpi_platform.o
>>  acpi-y += acpi_pnp.o
>> +acpi-$(CONFIG_ARM_AMBA)+= acpi_amba.o
>>  acpi-y += int340x_thermal.o
>>  acpi-y += power.o
>>  acpi-y += event.o
>> diff --git a/drivers/acpi/acpi_amba.c b/drivers/acpi/acpi_amba.c
>> new file mode 100644
>> index 000..ebc8913
>> --- /dev/null
>> +++ b/drivers/acpi/acpi_amba.c
>> @@ -0,0 +1,149 @@
>> +
>> +/*
>> + * ACPI support for platform bus type.
>> + *
>> + * Copyright (C) 2015, Linaro Ltd
>> + * Authors: Graeme Gregory 
>> + *
>> + * 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 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +
>> +#include "internal.h"
>> +
>> +static const struct acpi_device_id amba_id_list[] = {
>> +   {"ARMH0011", 0}, /* PL011 SBSA Uart */
>> +   {"ARMH0061", 0}, /* PL061 GPIO Device */
>> +   {"", 0},
>> +};
>> +
>> +static struct clk *amba_dummy_clk;
>> +
>> +static void amba_register_dummy_clk(void)
>> +{
>> +   struct clk *clk;
>> +
>> +   /* If clock already registered */
>> +   if (amba_dummy_clk)
>> +   return;
>> +
>> +   clk = clk_register_fixed_rate(NULL, "apb_pclk", NULL, CLK_IS_ROOT, 
>> 0);
>> +   clk_register_clkdev(clk, "apb_pclk", NULL);
>> +
>> +   amba_dummy_clk = clk;
>> +}
>> +
>> +static int amba_handler_attach(struct acpi_device *adev,
>> +   const struct acpi_device_id *id)
>> +{
>> +   struct amba_device *dev = NULL;
>> +   struct acpi_device *acpi_parent;
>> +   struct resource_entry *rentry;
>> +   struct list_head resource_list;
>> +   struct resource *resources = NULL;
>> +   bool address_found = false;
>> +   int ret, count, irq_no = 0;
>> +
>> +   /* If the ACPI node already has a physical device attached, skip it. 
>> */
>> +   if (adev->physical_node_count)
>> +   return 0;
>> +
>> +   amba_register_dummy_clk();
>> +
>> +   dev = amba_device_alloc(NULL, 0, 0);
>> +   if (!dev) {
>> +   pr_err("%s(): amba_device_alloc() failed for %s\n",
>
> Can it be dev_err(>dev, …); ?
> Same for below cases.
>
Yes it probably can, I took the code directly from DT version and
didn't think of using adev->dev directly.

Graeme

>> +  __func__, dev_name(>dev));
>> +   return 0;
>> +   }
>> +
>> +   INIT_LIST_HEAD(_list);
>
>> +   count = acpi_dev_get_resources(adev, _list, NULL, NULL);
>> +   if (count < 0) {
>> +   return 0;
>> +   } else if (count > 0) {
>> +   resources = kmalloc_array(count, sizeof(struct resource),
>> +   GFP_KERNEL);
>> +   if (!resources) {
>> +   acpi_dev_free_resource_list(_list);
>> +   return 0;
>> +   }
>> +   count = 0;
>> +   list_for_each_entry(rentry, _list, node) {
>> +   switch (resource_type(rentry->res)) {
>> +   case IORESOURCE_MEM:
>> +   if (!address_found) {
>> +   dev->res = *rentry->res;
>> +   address_found = true;
>> +   }
>> +   break;
>> +   case IORESOURCE_IRQ:
>> +   if (irq_no < AMBA_NR_IRQS)
>> +   dev->irq[irq_no++] = 
>> rentry->res->start;
>> +   break;
>> +   default:
>> +

Re: [PATCH v3 1/3] ACPI: amba bus probing support

2015-12-21 Thread Andy Shevchenko
On Mon, Dec 21, 2015 at 6:41 PM, Aleksey Makarov
 wrote:
> From: Graeme Gregory 
>
> On ARM64 some devices use the AMBA device and not the platform bus for
> probing so add support for this. Uses a dummy clock for apb_pclk as ACPI
> does not have a suitable clock representation and to keep the core
> AMBA bus code unchanged between probing methods.
>
> Signed-off-by: Graeme Gregory 
> Signed-off-by: Aleksey Makarov 
> ---
>  drivers/acpi/Makefile|   1 +
>  drivers/acpi/acpi_amba.c | 149 
> +++
>  drivers/acpi/internal.h  |   5 ++
>  3 files changed, 155 insertions(+)
>  create mode 100644 drivers/acpi/acpi_amba.c
>
> diff --git a/drivers/acpi/Makefile b/drivers/acpi/Makefile
> index 675eaf3..3cf732f 100644
> --- a/drivers/acpi/Makefile
> +++ b/drivers/acpi/Makefile
> @@ -43,6 +43,7 @@ acpi-y+= pci_root.o 
> pci_link.o pci_irq.o
>  acpi-y += acpi_lpss.o acpi_apd.o
>  acpi-y += acpi_platform.o
>  acpi-y += acpi_pnp.o
> +acpi-$(CONFIG_ARM_AMBA)+= acpi_amba.o
>  acpi-y += int340x_thermal.o
>  acpi-y += power.o
>  acpi-y += event.o
> diff --git a/drivers/acpi/acpi_amba.c b/drivers/acpi/acpi_amba.c
> new file mode 100644
> index 000..ebc8913
> --- /dev/null
> +++ b/drivers/acpi/acpi_amba.c
> @@ -0,0 +1,149 @@
> +
> +/*
> + * ACPI support for platform bus type.
> + *
> + * Copyright (C) 2015, Linaro Ltd
> + * Authors: Graeme Gregory 
> + *
> + * 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 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +#include "internal.h"
> +
> +static const struct acpi_device_id amba_id_list[] = {
> +   {"ARMH0011", 0}, /* PL011 SBSA Uart */
> +   {"ARMH0061", 0}, /* PL061 GPIO Device */
> +   {"", 0},
> +};
> +
> +static struct clk *amba_dummy_clk;
> +
> +static void amba_register_dummy_clk(void)
> +{
> +   struct clk *clk;
> +
> +   /* If clock already registered */
> +   if (amba_dummy_clk)
> +   return;
> +
> +   clk = clk_register_fixed_rate(NULL, "apb_pclk", NULL, CLK_IS_ROOT, 0);
> +   clk_register_clkdev(clk, "apb_pclk", NULL);
> +
> +   amba_dummy_clk = clk;
> +}
> +
> +static int amba_handler_attach(struct acpi_device *adev,
> +   const struct acpi_device_id *id)
> +{
> +   struct amba_device *dev = NULL;
> +   struct acpi_device *acpi_parent;
> +   struct resource_entry *rentry;
> +   struct list_head resource_list;
> +   struct resource *resources = NULL;
> +   bool address_found = false;
> +   int ret, count, irq_no = 0;
> +
> +   /* If the ACPI node already has a physical device attached, skip it. 
> */
> +   if (adev->physical_node_count)
> +   return 0;
> +
> +   amba_register_dummy_clk();
> +
> +   dev = amba_device_alloc(NULL, 0, 0);
> +   if (!dev) {
> +   pr_err("%s(): amba_device_alloc() failed for %s\n",

Can it be dev_err(>dev, …); ?
Same for below cases.

> +  __func__, dev_name(>dev));
> +   return 0;
> +   }
> +
> +   INIT_LIST_HEAD(_list);

> +   count = acpi_dev_get_resources(adev, _list, NULL, NULL);
> +   if (count < 0) {
> +   return 0;
> +   } else if (count > 0) {
> +   resources = kmalloc_array(count, sizeof(struct resource),
> +   GFP_KERNEL);
> +   if (!resources) {
> +   acpi_dev_free_resource_list(_list);
> +   return 0;
> +   }
> +   count = 0;
> +   list_for_each_entry(rentry, _list, node) {
> +   switch (resource_type(rentry->res)) {
> +   case IORESOURCE_MEM:
> +   if (!address_found) {
> +   dev->res = *rentry->res;
> +   address_found = true;
> +   }
> +   break;
> +   case IORESOURCE_IRQ:
> +   if (irq_no < AMBA_NR_IRQS)
> +   dev->irq[irq_no++] = 
> rentry->res->start;
> +   break;
> +   default:
> +   dev_warn(>dev, "Invalid resource\n");
> +   }
> +   }
> +   acpi_dev_free_resource_list(_list);
> +   }
> +
> +   /*
> +* If the ACPI node has a parent and that parent has a physical device
> +* attached to it, that physical device 

[PATCH v3 1/3] ACPI: amba bus probing support

2015-12-21 Thread Aleksey Makarov
From: Graeme Gregory 

On ARM64 some devices use the AMBA device and not the platform bus for
probing so add support for this. Uses a dummy clock for apb_pclk as ACPI
does not have a suitable clock representation and to keep the core
AMBA bus code unchanged between probing methods.

Signed-off-by: Graeme Gregory 
Signed-off-by: Aleksey Makarov 
---
 drivers/acpi/Makefile|   1 +
 drivers/acpi/acpi_amba.c | 149 +++
 drivers/acpi/internal.h  |   5 ++
 3 files changed, 155 insertions(+)
 create mode 100644 drivers/acpi/acpi_amba.c

diff --git a/drivers/acpi/Makefile b/drivers/acpi/Makefile
index 675eaf3..3cf732f 100644
--- a/drivers/acpi/Makefile
+++ b/drivers/acpi/Makefile
@@ -43,6 +43,7 @@ acpi-y+= pci_root.o 
pci_link.o pci_irq.o
 acpi-y += acpi_lpss.o acpi_apd.o
 acpi-y += acpi_platform.o
 acpi-y += acpi_pnp.o
+acpi-$(CONFIG_ARM_AMBA)+= acpi_amba.o
 acpi-y += int340x_thermal.o
 acpi-y += power.o
 acpi-y += event.o
diff --git a/drivers/acpi/acpi_amba.c b/drivers/acpi/acpi_amba.c
new file mode 100644
index 000..ebc8913
--- /dev/null
+++ b/drivers/acpi/acpi_amba.c
@@ -0,0 +1,149 @@
+
+/*
+ * ACPI support for platform bus type.
+ *
+ * Copyright (C) 2015, Linaro Ltd
+ * Authors: Graeme Gregory 
+ *
+ * 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 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "internal.h"
+
+static const struct acpi_device_id amba_id_list[] = {
+   {"ARMH0011", 0}, /* PL011 SBSA Uart */
+   {"ARMH0061", 0}, /* PL061 GPIO Device */
+   {"", 0},
+};
+
+static struct clk *amba_dummy_clk;
+
+static void amba_register_dummy_clk(void)
+{
+   struct clk *clk;
+
+   /* If clock already registered */
+   if (amba_dummy_clk)
+   return;
+
+   clk = clk_register_fixed_rate(NULL, "apb_pclk", NULL, CLK_IS_ROOT, 0);
+   clk_register_clkdev(clk, "apb_pclk", NULL);
+
+   amba_dummy_clk = clk;
+}
+
+static int amba_handler_attach(struct acpi_device *adev,
+   const struct acpi_device_id *id)
+{
+   struct amba_device *dev = NULL;
+   struct acpi_device *acpi_parent;
+   struct resource_entry *rentry;
+   struct list_head resource_list;
+   struct resource *resources = NULL;
+   bool address_found = false;
+   int ret, count, irq_no = 0;
+
+   /* If the ACPI node already has a physical device attached, skip it. */
+   if (adev->physical_node_count)
+   return 0;
+
+   amba_register_dummy_clk();
+
+   dev = amba_device_alloc(NULL, 0, 0);
+   if (!dev) {
+   pr_err("%s(): amba_device_alloc() failed for %s\n",
+  __func__, dev_name(>dev));
+   return 0;
+   }
+
+   INIT_LIST_HEAD(_list);
+   count = acpi_dev_get_resources(adev, _list, NULL, NULL);
+   if (count < 0) {
+   return 0;
+   } else if (count > 0) {
+   resources = kmalloc_array(count, sizeof(struct resource),
+   GFP_KERNEL);
+   if (!resources) {
+   acpi_dev_free_resource_list(_list);
+   return 0;
+   }
+   count = 0;
+   list_for_each_entry(rentry, _list, node) {
+   switch (resource_type(rentry->res)) {
+   case IORESOURCE_MEM:
+   if (!address_found) {
+   dev->res = *rentry->res;
+   address_found = true;
+   }
+   break;
+   case IORESOURCE_IRQ:
+   if (irq_no < AMBA_NR_IRQS)
+   dev->irq[irq_no++] = rentry->res->start;
+   break;
+   default:
+   dev_warn(>dev, "Invalid resource\n");
+   }
+   }
+   acpi_dev_free_resource_list(_list);
+   }
+
+   /*
+* If the ACPI node has a parent and that parent has a physical device
+* attached to it, that physical device should be the parent of the
+* platform device we are about to create.
+*/
+   dev->dev.parent = NULL;
+   acpi_parent = adev->parent;
+   if (acpi_parent) {
+   struct acpi_device_physical_node *entry;
+   struct list_head *list;
+
+   mutex_lock(_parent->physical_node_lock);
+   list = _parent->physical_node_list;
+  

Re: [PATCH v3 1/3] ACPI: amba bus probing support

2015-12-21 Thread Andy Shevchenko
On Mon, Dec 21, 2015 at 6:41 PM, Aleksey Makarov
 wrote:
> From: Graeme Gregory 
>
> On ARM64 some devices use the AMBA device and not the platform bus for
> probing so add support for this. Uses a dummy clock for apb_pclk as ACPI
> does not have a suitable clock representation and to keep the core
> AMBA bus code unchanged between probing methods.
>
> Signed-off-by: Graeme Gregory 
> Signed-off-by: Aleksey Makarov 
> ---
>  drivers/acpi/Makefile|   1 +
>  drivers/acpi/acpi_amba.c | 149 
> +++
>  drivers/acpi/internal.h  |   5 ++
>  3 files changed, 155 insertions(+)
>  create mode 100644 drivers/acpi/acpi_amba.c
>
> diff --git a/drivers/acpi/Makefile b/drivers/acpi/Makefile
> index 675eaf3..3cf732f 100644
> --- a/drivers/acpi/Makefile
> +++ b/drivers/acpi/Makefile
> @@ -43,6 +43,7 @@ acpi-y+= pci_root.o 
> pci_link.o pci_irq.o
>  acpi-y += acpi_lpss.o acpi_apd.o
>  acpi-y += acpi_platform.o
>  acpi-y += acpi_pnp.o
> +acpi-$(CONFIG_ARM_AMBA)+= acpi_amba.o
>  acpi-y += int340x_thermal.o
>  acpi-y += power.o
>  acpi-y += event.o
> diff --git a/drivers/acpi/acpi_amba.c b/drivers/acpi/acpi_amba.c
> new file mode 100644
> index 000..ebc8913
> --- /dev/null
> +++ b/drivers/acpi/acpi_amba.c
> @@ -0,0 +1,149 @@
> +
> +/*
> + * ACPI support for platform bus type.
> + *
> + * Copyright (C) 2015, Linaro Ltd
> + * Authors: Graeme Gregory 
> + *
> + * 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 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +#include "internal.h"
> +
> +static const struct acpi_device_id amba_id_list[] = {
> +   {"ARMH0011", 0}, /* PL011 SBSA Uart */
> +   {"ARMH0061", 0}, /* PL061 GPIO Device */
> +   {"", 0},
> +};
> +
> +static struct clk *amba_dummy_clk;
> +
> +static void amba_register_dummy_clk(void)
> +{
> +   struct clk *clk;
> +
> +   /* If clock already registered */
> +   if (amba_dummy_clk)
> +   return;
> +
> +   clk = clk_register_fixed_rate(NULL, "apb_pclk", NULL, CLK_IS_ROOT, 0);
> +   clk_register_clkdev(clk, "apb_pclk", NULL);
> +
> +   amba_dummy_clk = clk;
> +}
> +
> +static int amba_handler_attach(struct acpi_device *adev,
> +   const struct acpi_device_id *id)
> +{
> +   struct amba_device *dev = NULL;
> +   struct acpi_device *acpi_parent;
> +   struct resource_entry *rentry;
> +   struct list_head resource_list;
> +   struct resource *resources = NULL;
> +   bool address_found = false;
> +   int ret, count, irq_no = 0;
> +
> +   /* If the ACPI node already has a physical device attached, skip it. 
> */
> +   if (adev->physical_node_count)
> +   return 0;
> +
> +   amba_register_dummy_clk();
> +
> +   dev = amba_device_alloc(NULL, 0, 0);
> +   if (!dev) {
> +   pr_err("%s(): amba_device_alloc() failed for %s\n",

Can it be dev_err(>dev, …); ?
Same for below cases.

> +  __func__, dev_name(>dev));
> +   return 0;
> +   }
> +
> +   INIT_LIST_HEAD(_list);

> +   count = acpi_dev_get_resources(adev, _list, NULL, NULL);
> +   if (count < 0) {
> +   return 0;
> +   } else if (count > 0) {
> +   resources = kmalloc_array(count, sizeof(struct resource),
> +   GFP_KERNEL);
> +   if (!resources) {
> +   acpi_dev_free_resource_list(_list);
> +   return 0;
> +   }
> +   count = 0;
> +   list_for_each_entry(rentry, _list, node) {
> +   switch (resource_type(rentry->res)) {
> +   case IORESOURCE_MEM:
> +   if (!address_found) {
> +   dev->res = *rentry->res;
> +   address_found = true;
> +   }
> +   break;
> +   case IORESOURCE_IRQ:
> +   if (irq_no < AMBA_NR_IRQS)
> +   dev->irq[irq_no++] = 
> rentry->res->start;
> +   break;
> +   default:
> +   dev_warn(>dev, "Invalid resource\n");
> +   }
> +   }
> +   acpi_dev_free_resource_list(_list);
> +   }
> +
> +   

Re: [PATCH v3 1/3] ACPI: amba bus probing support

2015-12-21 Thread G Gregory
On 21 December 2015 at 18:19, Andy Shevchenko  wrote:
> On Mon, Dec 21, 2015 at 6:41 PM, Aleksey Makarov
>  wrote:
>> From: Graeme Gregory 
>>
>> On ARM64 some devices use the AMBA device and not the platform bus for
>> probing so add support for this. Uses a dummy clock for apb_pclk as ACPI
>> does not have a suitable clock representation and to keep the core
>> AMBA bus code unchanged between probing methods.
>>
>> Signed-off-by: Graeme Gregory 
>> Signed-off-by: Aleksey Makarov 
>> ---
>>  drivers/acpi/Makefile|   1 +
>>  drivers/acpi/acpi_amba.c | 149 
>> +++
>>  drivers/acpi/internal.h  |   5 ++
>>  3 files changed, 155 insertions(+)
>>  create mode 100644 drivers/acpi/acpi_amba.c
>>
>> diff --git a/drivers/acpi/Makefile b/drivers/acpi/Makefile
>> index 675eaf3..3cf732f 100644
>> --- a/drivers/acpi/Makefile
>> +++ b/drivers/acpi/Makefile
>> @@ -43,6 +43,7 @@ acpi-y+= pci_root.o 
>> pci_link.o pci_irq.o
>>  acpi-y += acpi_lpss.o acpi_apd.o
>>  acpi-y += acpi_platform.o
>>  acpi-y += acpi_pnp.o
>> +acpi-$(CONFIG_ARM_AMBA)+= acpi_amba.o
>>  acpi-y += int340x_thermal.o
>>  acpi-y += power.o
>>  acpi-y += event.o
>> diff --git a/drivers/acpi/acpi_amba.c b/drivers/acpi/acpi_amba.c
>> new file mode 100644
>> index 000..ebc8913
>> --- /dev/null
>> +++ b/drivers/acpi/acpi_amba.c
>> @@ -0,0 +1,149 @@
>> +
>> +/*
>> + * ACPI support for platform bus type.
>> + *
>> + * Copyright (C) 2015, Linaro Ltd
>> + * Authors: Graeme Gregory 
>> + *
>> + * 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 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +
>> +#include "internal.h"
>> +
>> +static const struct acpi_device_id amba_id_list[] = {
>> +   {"ARMH0011", 0}, /* PL011 SBSA Uart */
>> +   {"ARMH0061", 0}, /* PL061 GPIO Device */
>> +   {"", 0},
>> +};
>> +
>> +static struct clk *amba_dummy_clk;
>> +
>> +static void amba_register_dummy_clk(void)
>> +{
>> +   struct clk *clk;
>> +
>> +   /* If clock already registered */
>> +   if (amba_dummy_clk)
>> +   return;
>> +
>> +   clk = clk_register_fixed_rate(NULL, "apb_pclk", NULL, CLK_IS_ROOT, 
>> 0);
>> +   clk_register_clkdev(clk, "apb_pclk", NULL);
>> +
>> +   amba_dummy_clk = clk;
>> +}
>> +
>> +static int amba_handler_attach(struct acpi_device *adev,
>> +   const struct acpi_device_id *id)
>> +{
>> +   struct amba_device *dev = NULL;
>> +   struct acpi_device *acpi_parent;
>> +   struct resource_entry *rentry;
>> +   struct list_head resource_list;
>> +   struct resource *resources = NULL;
>> +   bool address_found = false;
>> +   int ret, count, irq_no = 0;
>> +
>> +   /* If the ACPI node already has a physical device attached, skip it. 
>> */
>> +   if (adev->physical_node_count)
>> +   return 0;
>> +
>> +   amba_register_dummy_clk();
>> +
>> +   dev = amba_device_alloc(NULL, 0, 0);
>> +   if (!dev) {
>> +   pr_err("%s(): amba_device_alloc() failed for %s\n",
>
> Can it be dev_err(>dev, …); ?
> Same for below cases.
>
Yes it probably can, I took the code directly from DT version and
didn't think of using adev->dev directly.

Graeme

>> +  __func__, dev_name(>dev));
>> +   return 0;
>> +   }
>> +
>> +   INIT_LIST_HEAD(_list);
>
>> +   count = acpi_dev_get_resources(adev, _list, NULL, NULL);
>> +   if (count < 0) {
>> +   return 0;
>> +   } else if (count > 0) {
>> +   resources = kmalloc_array(count, sizeof(struct resource),
>> +   GFP_KERNEL);
>> +   if (!resources) {
>> +   acpi_dev_free_resource_list(_list);
>> +   return 0;
>> +   }
>> +   count = 0;
>> +   list_for_each_entry(rentry, _list, node) {
>> +   switch (resource_type(rentry->res)) {
>> +   case IORESOURCE_MEM:
>> +   if (!address_found) {
>> +   dev->res = *rentry->res;
>> +   address_found = true;
>> +   }
>> +   break;
>> +   case IORESOURCE_IRQ:
>> +   if (irq_no < AMBA_NR_IRQS)
>> +  

Re: [PATCH v3 1/3] ACPI: amba bus probing support

2015-12-21 Thread Vladimir Zapolskiy
Hi,

On 21.12.2015 18:41, Aleksey Makarov wrote:
> From: Graeme Gregory 
> 
> On ARM64 some devices use the AMBA device and not the platform bus for
> probing so add support for this. Uses a dummy clock for apb_pclk as ACPI
> does not have a suitable clock representation and to keep the core
> AMBA bus code unchanged between probing methods.
> 
> Signed-off-by: Graeme Gregory 
> Signed-off-by: Aleksey Makarov 
> ---
>  drivers/acpi/Makefile|   1 +
>  drivers/acpi/acpi_amba.c | 149 
> +++
>  drivers/acpi/internal.h  |   5 ++
>  3 files changed, 155 insertions(+)
>  create mode 100644 drivers/acpi/acpi_amba.c
> 
> diff --git a/drivers/acpi/Makefile b/drivers/acpi/Makefile
> index 675eaf3..3cf732f 100644
> --- a/drivers/acpi/Makefile
> +++ b/drivers/acpi/Makefile
> @@ -43,6 +43,7 @@ acpi-y  += pci_root.o 
> pci_link.o pci_irq.o
>  acpi-y   += acpi_lpss.o acpi_apd.o
>  acpi-y   += acpi_platform.o
>  acpi-y   += acpi_pnp.o
> +acpi-$(CONFIG_ARM_AMBA)  += acpi_amba.o
>  acpi-y   += int340x_thermal.o
>  acpi-y   += power.o
>  acpi-y   += event.o
> diff --git a/drivers/acpi/acpi_amba.c b/drivers/acpi/acpi_amba.c
> new file mode 100644
> index 000..ebc8913
> --- /dev/null
> +++ b/drivers/acpi/acpi_amba.c
> @@ -0,0 +1,149 @@
> +
> +/*
> + * ACPI support for platform bus type.
> + *
> + * Copyright (C) 2015, Linaro Ltd
> + * Authors: Graeme Gregory 
> + *
> + * 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 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +#include "internal.h"
> +
> +static const struct acpi_device_id amba_id_list[] = {
> + {"ARMH0011", 0}, /* PL011 SBSA Uart */
> + {"ARMH0061", 0}, /* PL061 GPIO Device */
> + {"", 0},
> +};
> +
> +static struct clk *amba_dummy_clk;
> +
> +static void amba_register_dummy_clk(void)
> +{
> + struct clk *clk;
> +
> + /* If clock already registered */
> + if (amba_dummy_clk)
> + return;
> +
> + clk = clk_register_fixed_rate(NULL, "apb_pclk", NULL, CLK_IS_ROOT, 0);
> + clk_register_clkdev(clk, "apb_pclk", NULL);
> +
> + amba_dummy_clk = clk;
> +}
> +
> +static int amba_handler_attach(struct acpi_device *adev,
> + const struct acpi_device_id *id)
> +{
> + struct amba_device *dev = NULL;
> + struct acpi_device *acpi_parent;
> + struct resource_entry *rentry;
> + struct list_head resource_list;
> + struct resource *resources = NULL;
> + bool address_found = false;
> + int ret, count, irq_no = 0;
> +
> + /* If the ACPI node already has a physical device attached, skip it. */
> + if (adev->physical_node_count)
> + return 0;
> +
> + amba_register_dummy_clk();

Since it is a single time dummy clock registration, may be it is better
to move it to acpi_amba_init() or somewhere else? I understand that
"apb_pclk" is wanted, but I'm not sure that this driver should serve as
a clock provider.

> + dev = amba_device_alloc(NULL, 0, 0);
> + if (!dev) {
> + pr_err("%s(): amba_device_alloc() failed for %s\n",
> +__func__, dev_name(>dev));
> + return 0;
> + }
> +
> + INIT_LIST_HEAD(_list);
> + count = acpi_dev_get_resources(adev, _list, NULL, NULL);
> + if (count < 0) {
> + return 0;
> + } else if (count > 0) {

if you return from one of two if-branches, please don't use if-else nesting
for another one.

> + resources = kmalloc_array(count, sizeof(struct resource),
> + GFP_KERNEL);

resources is never used and it is never freed, why do you allocate it?

> + if (!resources) {
> + acpi_dev_free_resource_list(_list);
> + return 0;

return -ENOMEM; seems to be more appropriate here.

> + }
> + count = 0;
> + list_for_each_entry(rentry, _list, node) {
> + switch (resource_type(rentry->res)) {
> + case IORESOURCE_MEM:
> + if (!address_found) {
> + dev->res = *rentry->res;
> + address_found = true;
> + }
> + break;
> + case IORESOURCE_IRQ:
> + if (irq_no < AMBA_NR_IRQS)
> + dev->irq[irq_no++] = 

[PATCH v3 1/3] ACPI: amba bus probing support

2015-12-21 Thread Aleksey Makarov
From: Graeme Gregory 

On ARM64 some devices use the AMBA device and not the platform bus for
probing so add support for this. Uses a dummy clock for apb_pclk as ACPI
does not have a suitable clock representation and to keep the core
AMBA bus code unchanged between probing methods.

Signed-off-by: Graeme Gregory 
Signed-off-by: Aleksey Makarov 
---
 drivers/acpi/Makefile|   1 +
 drivers/acpi/acpi_amba.c | 149 +++
 drivers/acpi/internal.h  |   5 ++
 3 files changed, 155 insertions(+)
 create mode 100644 drivers/acpi/acpi_amba.c

diff --git a/drivers/acpi/Makefile b/drivers/acpi/Makefile
index 675eaf3..3cf732f 100644
--- a/drivers/acpi/Makefile
+++ b/drivers/acpi/Makefile
@@ -43,6 +43,7 @@ acpi-y+= pci_root.o 
pci_link.o pci_irq.o
 acpi-y += acpi_lpss.o acpi_apd.o
 acpi-y += acpi_platform.o
 acpi-y += acpi_pnp.o
+acpi-$(CONFIG_ARM_AMBA)+= acpi_amba.o
 acpi-y += int340x_thermal.o
 acpi-y += power.o
 acpi-y += event.o
diff --git a/drivers/acpi/acpi_amba.c b/drivers/acpi/acpi_amba.c
new file mode 100644
index 000..ebc8913
--- /dev/null
+++ b/drivers/acpi/acpi_amba.c
@@ -0,0 +1,149 @@
+
+/*
+ * ACPI support for platform bus type.
+ *
+ * Copyright (C) 2015, Linaro Ltd
+ * Authors: Graeme Gregory 
+ *
+ * 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 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "internal.h"
+
+static const struct acpi_device_id amba_id_list[] = {
+   {"ARMH0011", 0}, /* PL011 SBSA Uart */
+   {"ARMH0061", 0}, /* PL061 GPIO Device */
+   {"", 0},
+};
+
+static struct clk *amba_dummy_clk;
+
+static void amba_register_dummy_clk(void)
+{
+   struct clk *clk;
+
+   /* If clock already registered */
+   if (amba_dummy_clk)
+   return;
+
+   clk = clk_register_fixed_rate(NULL, "apb_pclk", NULL, CLK_IS_ROOT, 0);
+   clk_register_clkdev(clk, "apb_pclk", NULL);
+
+   amba_dummy_clk = clk;
+}
+
+static int amba_handler_attach(struct acpi_device *adev,
+   const struct acpi_device_id *id)
+{
+   struct amba_device *dev = NULL;
+   struct acpi_device *acpi_parent;
+   struct resource_entry *rentry;
+   struct list_head resource_list;
+   struct resource *resources = NULL;
+   bool address_found = false;
+   int ret, count, irq_no = 0;
+
+   /* If the ACPI node already has a physical device attached, skip it. */
+   if (adev->physical_node_count)
+   return 0;
+
+   amba_register_dummy_clk();
+
+   dev = amba_device_alloc(NULL, 0, 0);
+   if (!dev) {
+   pr_err("%s(): amba_device_alloc() failed for %s\n",
+  __func__, dev_name(>dev));
+   return 0;
+   }
+
+   INIT_LIST_HEAD(_list);
+   count = acpi_dev_get_resources(adev, _list, NULL, NULL);
+   if (count < 0) {
+   return 0;
+   } else if (count > 0) {
+   resources = kmalloc_array(count, sizeof(struct resource),
+   GFP_KERNEL);
+   if (!resources) {
+   acpi_dev_free_resource_list(_list);
+   return 0;
+   }
+   count = 0;
+   list_for_each_entry(rentry, _list, node) {
+   switch (resource_type(rentry->res)) {
+   case IORESOURCE_MEM:
+   if (!address_found) {
+   dev->res = *rentry->res;
+   address_found = true;
+   }
+   break;
+   case IORESOURCE_IRQ:
+   if (irq_no < AMBA_NR_IRQS)
+   dev->irq[irq_no++] = rentry->res->start;
+   break;
+   default:
+   dev_warn(>dev, "Invalid resource\n");
+   }
+   }
+   acpi_dev_free_resource_list(_list);
+   }
+
+   /*
+* If the ACPI node has a parent and that parent has a physical device
+* attached to it, that physical device should be the parent of the
+* platform device we are about to create.
+*/
+   dev->dev.parent = NULL;
+   acpi_parent = adev->parent;
+   if (acpi_parent) {
+   struct acpi_device_physical_node *entry;
+   struct list_head *list;
+
+