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