Merge tag 'armsoc-fixes-nc' of git://git.kernel.org/pub/scm/linux/kernel/git/arm...
[linux-2.6-block.git] / drivers / acpi / acpi_amba.c
CommitLineData
6ce2e188
GG
1
2/*
3 * ACPI support for platform bus type.
4 *
5 * Copyright (C) 2015, Linaro Ltd
6 * Author: Graeme Gregory <graeme.gregory@linaro.org>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
11 */
12
13#include <linux/acpi.h>
14#include <linux/amba/bus.h>
15#include <linux/clkdev.h>
16#include <linux/clk-provider.h>
17#include <linux/device.h>
18#include <linux/err.h>
19#include <linux/ioport.h>
20#include <linux/kernel.h>
21#include <linux/module.h>
22
23#include "internal.h"
24
25static const struct acpi_device_id amba_id_list[] = {
26 {"ARMH0061", 0}, /* PL061 GPIO Device */
27 {"", 0},
28};
29
30static void amba_register_dummy_clk(void)
31{
32 static struct clk *amba_dummy_clk;
33
34 /* If clock already registered */
35 if (amba_dummy_clk)
36 return;
37
38 amba_dummy_clk = clk_register_fixed_rate(NULL, "apb_pclk", NULL,
39 CLK_IS_ROOT, 0);
40 clk_register_clkdev(amba_dummy_clk, "apb_pclk", NULL);
41}
42
43static int amba_handler_attach(struct acpi_device *adev,
44 const struct acpi_device_id *id)
45{
46 struct amba_device *dev;
47 struct resource_entry *rentry;
48 struct list_head resource_list;
49 bool address_found = false;
50 int irq_no = 0;
51 int ret;
52
53 /* If the ACPI node already has a physical device attached, skip it. */
54 if (adev->physical_node_count)
55 return 0;
56
57 dev = amba_device_alloc(dev_name(&adev->dev), 0, 0);
58 if (!dev) {
59 dev_err(&adev->dev, "%s(): amba_device_alloc() failed\n",
60 __func__);
61 return -ENOMEM;
62 }
63
64 INIT_LIST_HEAD(&resource_list);
65 ret = acpi_dev_get_resources(adev, &resource_list, NULL, NULL);
66 if (ret < 0)
67 goto err_free;
68
69 list_for_each_entry(rentry, &resource_list, node) {
70 switch (resource_type(rentry->res)) {
71 case IORESOURCE_MEM:
72 if (!address_found) {
73 dev->res = *rentry->res;
74 address_found = true;
75 }
76 break;
77 case IORESOURCE_IRQ:
78 if (irq_no < AMBA_NR_IRQS)
79 dev->irq[irq_no++] = rentry->res->start;
80 break;
81 default:
82 dev_warn(&adev->dev, "Invalid resource\n");
83 break;
84 }
85 }
86
87 acpi_dev_free_resource_list(&resource_list);
88
89 /*
90 * If the ACPI node has a parent and that parent has a physical device
91 * attached to it, that physical device should be the parent of
92 * the amba device we are about to create.
93 */
94 if (adev->parent)
95 dev->dev.parent = acpi_get_first_physical_node(adev->parent);
96
97 ACPI_COMPANION_SET(&dev->dev, adev);
98
99 ret = amba_device_add(dev, &iomem_resource);
100 if (ret) {
101 dev_err(&adev->dev, "%s(): amba_device_add() failed (%d)\n",
102 __func__, ret);
103 goto err_free;
104 }
105
106 return 1;
107
108err_free:
109 amba_device_put(dev);
110 return ret;
111}
112
113static struct acpi_scan_handler amba_handler = {
114 .ids = amba_id_list,
115 .attach = amba_handler_attach,
116};
117
118void __init acpi_amba_init(void)
119{
120 amba_register_dummy_clk();
121 acpi_scan_add_handler(&amba_handler);
122}