Thomas Gleixner | d2912cb | 2019-06-04 10:11:33 +0200 | [diff] [blame^] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
Graeme Gregory | 6ce2e18 | 2016-01-20 20:29:27 +0600 | [diff] [blame] | 2 | |
| 3 | /* |
| 4 | * ACPI support for platform bus type. |
| 5 | * |
| 6 | * Copyright (C) 2015, Linaro Ltd |
| 7 | * Author: Graeme Gregory <graeme.gregory@linaro.org> |
Graeme Gregory | 6ce2e18 | 2016-01-20 20:29:27 +0600 | [diff] [blame] | 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 | |
| 20 | #include "internal.h" |
| 21 | |
| 22 | static const struct acpi_device_id amba_id_list[] = { |
| 23 | {"ARMH0061", 0}, /* PL061 GPIO Device */ |
| 24 | {"", 0}, |
| 25 | }; |
| 26 | |
| 27 | static void amba_register_dummy_clk(void) |
| 28 | { |
| 29 | static struct clk *amba_dummy_clk; |
| 30 | |
| 31 | /* If clock already registered */ |
| 32 | if (amba_dummy_clk) |
| 33 | return; |
| 34 | |
Stephen Boyd | 628e35b | 2016-04-19 18:28:38 -0700 | [diff] [blame] | 35 | amba_dummy_clk = clk_register_fixed_rate(NULL, "apb_pclk", NULL, 0, 0); |
Graeme Gregory | 6ce2e18 | 2016-01-20 20:29:27 +0600 | [diff] [blame] | 36 | clk_register_clkdev(amba_dummy_clk, "apb_pclk", NULL); |
| 37 | } |
| 38 | |
| 39 | static int amba_handler_attach(struct acpi_device *adev, |
| 40 | const struct acpi_device_id *id) |
| 41 | { |
| 42 | struct amba_device *dev; |
| 43 | struct resource_entry *rentry; |
| 44 | struct list_head resource_list; |
| 45 | bool address_found = false; |
| 46 | int irq_no = 0; |
| 47 | int ret; |
| 48 | |
| 49 | /* If the ACPI node already has a physical device attached, skip it. */ |
| 50 | if (adev->physical_node_count) |
| 51 | return 0; |
| 52 | |
| 53 | dev = amba_device_alloc(dev_name(&adev->dev), 0, 0); |
| 54 | if (!dev) { |
| 55 | dev_err(&adev->dev, "%s(): amba_device_alloc() failed\n", |
| 56 | __func__); |
| 57 | return -ENOMEM; |
| 58 | } |
| 59 | |
| 60 | INIT_LIST_HEAD(&resource_list); |
| 61 | ret = acpi_dev_get_resources(adev, &resource_list, NULL, NULL); |
| 62 | if (ret < 0) |
| 63 | goto err_free; |
| 64 | |
| 65 | list_for_each_entry(rentry, &resource_list, node) { |
| 66 | switch (resource_type(rentry->res)) { |
| 67 | case IORESOURCE_MEM: |
| 68 | if (!address_found) { |
| 69 | dev->res = *rentry->res; |
| 70 | address_found = true; |
| 71 | } |
| 72 | break; |
| 73 | case IORESOURCE_IRQ: |
| 74 | if (irq_no < AMBA_NR_IRQS) |
| 75 | dev->irq[irq_no++] = rentry->res->start; |
| 76 | break; |
| 77 | default: |
| 78 | dev_warn(&adev->dev, "Invalid resource\n"); |
| 79 | break; |
| 80 | } |
| 81 | } |
| 82 | |
| 83 | acpi_dev_free_resource_list(&resource_list); |
| 84 | |
| 85 | /* |
| 86 | * If the ACPI node has a parent and that parent has a physical device |
| 87 | * attached to it, that physical device should be the parent of |
| 88 | * the amba device we are about to create. |
| 89 | */ |
| 90 | if (adev->parent) |
| 91 | dev->dev.parent = acpi_get_first_physical_node(adev->parent); |
| 92 | |
| 93 | ACPI_COMPANION_SET(&dev->dev, adev); |
| 94 | |
| 95 | ret = amba_device_add(dev, &iomem_resource); |
| 96 | if (ret) { |
| 97 | dev_err(&adev->dev, "%s(): amba_device_add() failed (%d)\n", |
| 98 | __func__, ret); |
| 99 | goto err_free; |
| 100 | } |
| 101 | |
| 102 | return 1; |
| 103 | |
| 104 | err_free: |
| 105 | amba_device_put(dev); |
| 106 | return ret; |
| 107 | } |
| 108 | |
| 109 | static struct acpi_scan_handler amba_handler = { |
| 110 | .ids = amba_id_list, |
| 111 | .attach = amba_handler_attach, |
| 112 | }; |
| 113 | |
| 114 | void __init acpi_amba_init(void) |
| 115 | { |
| 116 | amba_register_dummy_clk(); |
| 117 | acpi_scan_add_handler(&amba_handler); |
| 118 | } |