Linux Audio

Check our new training course

Loading...
v5.9
  1// SPDX-License-Identifier: GPL-2.0-only
  2
  3/*
  4 * ACPI support for platform bus type.
  5 *
  6 * Copyright (C) 2015, Linaro Ltd
  7 * Author: Graeme Gregory <graeme.gregory@linaro.org>
  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
 22static const struct acpi_device_id amba_id_list[] = {
 23	{"ARMH0061", 0}, /* PL061 GPIO Device */
 
 24	{"ARMHC500", 0}, /* ARM CoreSight ETM4x */
 25	{"ARMHC501", 0}, /* ARM CoreSight ETR */
 26	{"ARMHC502", 0}, /* ARM CoreSight STM */
 27	{"ARMHC503", 0}, /* ARM CoreSight Debug */
 28	{"ARMHC979", 0}, /* ARM CoreSight TPIU */
 29	{"ARMHC97C", 0}, /* ARM CoreSight SoC-400 TMC, SoC-600 ETF/ETB */
 30	{"ARMHC98D", 0}, /* ARM CoreSight Dynamic Replicator */
 31	{"ARMHC9CA", 0}, /* ARM CoreSight CATU */
 32	{"ARMHC9FF", 0}, /* ARM CoreSight Dynamic Funnel */
 33	{"", 0},
 34};
 35
 36static void amba_register_dummy_clk(void)
 37{
 38	static struct clk *amba_dummy_clk;
 39
 40	/* If clock already registered */
 41	if (amba_dummy_clk)
 42		return;
 43
 44	amba_dummy_clk = clk_register_fixed_rate(NULL, "apb_pclk", NULL, 0, 0);
 45	clk_register_clkdev(amba_dummy_clk, "apb_pclk", NULL);
 46}
 47
 48static int amba_handler_attach(struct acpi_device *adev,
 49				const struct acpi_device_id *id)
 50{
 
 51	struct amba_device *dev;
 52	struct resource_entry *rentry;
 53	struct list_head resource_list;
 54	bool address_found = false;
 55	int irq_no = 0;
 56	int ret;
 57
 58	/* If the ACPI node already has a physical device attached, skip it. */
 59	if (adev->physical_node_count)
 60		return 0;
 61
 62	dev = amba_device_alloc(dev_name(&adev->dev), 0, 0);
 63	if (!dev) {
 64		dev_err(&adev->dev, "%s(): amba_device_alloc() failed\n",
 65			__func__);
 66		return -ENOMEM;
 67	}
 68
 69	INIT_LIST_HEAD(&resource_list);
 70	ret = acpi_dev_get_resources(adev, &resource_list, NULL, NULL);
 71	if (ret < 0)
 72		goto err_free;
 73
 74	list_for_each_entry(rentry, &resource_list, node) {
 75		switch (resource_type(rentry->res)) {
 76		case IORESOURCE_MEM:
 77			if (!address_found) {
 78				dev->res = *rentry->res;
 
 79				address_found = true;
 80			}
 81			break;
 82		case IORESOURCE_IRQ:
 83			if (irq_no < AMBA_NR_IRQS)
 84				dev->irq[irq_no++] = rentry->res->start;
 85			break;
 86		default:
 87			dev_warn(&adev->dev, "Invalid resource\n");
 88			break;
 89		}
 90	}
 91
 92	acpi_dev_free_resource_list(&resource_list);
 93
 94	/*
 95	 * If the ACPI node has a parent and that parent has a physical device
 96	 * attached to it, that physical device should be the parent of
 97	 * the amba device we are about to create.
 98	 */
 99	if (adev->parent)
100		dev->dev.parent = acpi_get_first_physical_node(adev->parent);
101
102	ACPI_COMPANION_SET(&dev->dev, adev);
103
104	ret = amba_device_add(dev, &iomem_resource);
105	if (ret) {
106		dev_err(&adev->dev, "%s(): amba_device_add() failed (%d)\n",
107		       __func__, ret);
108		goto err_free;
109	}
110
111	return 1;
112
113err_free:
114	amba_device_put(dev);
115	return ret;
116}
117
118static struct acpi_scan_handler amba_handler = {
119	.ids = amba_id_list,
120	.attach = amba_handler_attach,
121};
122
123void __init acpi_amba_init(void)
124{
125	amba_register_dummy_clk();
126	acpi_scan_add_handler(&amba_handler);
127}
v6.2
  1// SPDX-License-Identifier: GPL-2.0-only
  2
  3/*
  4 * ACPI support for platform bus type.
  5 *
  6 * Copyright (C) 2015, Linaro Ltd
  7 * Author: Graeme Gregory <graeme.gregory@linaro.org>
  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
 22static const struct acpi_device_id amba_id_list[] = {
 23	{"ARMH0061", 0}, /* PL061 GPIO Device */
 24	{"ARMH0330", 0}, /* ARM DMA Controller DMA-330 */
 25	{"ARMHC500", 0}, /* ARM CoreSight ETM4x */
 26	{"ARMHC501", 0}, /* ARM CoreSight ETR */
 27	{"ARMHC502", 0}, /* ARM CoreSight STM */
 28	{"ARMHC503", 0}, /* ARM CoreSight Debug */
 29	{"ARMHC979", 0}, /* ARM CoreSight TPIU */
 30	{"ARMHC97C", 0}, /* ARM CoreSight SoC-400 TMC, SoC-600 ETF/ETB */
 31	{"ARMHC98D", 0}, /* ARM CoreSight Dynamic Replicator */
 32	{"ARMHC9CA", 0}, /* ARM CoreSight CATU */
 33	{"ARMHC9FF", 0}, /* ARM CoreSight Dynamic Funnel */
 34	{"", 0},
 35};
 36
 37static void amba_register_dummy_clk(void)
 38{
 39	static struct clk *amba_dummy_clk;
 40
 41	/* If clock already registered */
 42	if (amba_dummy_clk)
 43		return;
 44
 45	amba_dummy_clk = clk_register_fixed_rate(NULL, "apb_pclk", NULL, 0, 0);
 46	clk_register_clkdev(amba_dummy_clk, "apb_pclk", NULL);
 47}
 48
 49static int amba_handler_attach(struct acpi_device *adev,
 50				const struct acpi_device_id *id)
 51{
 52	struct acpi_device *parent = acpi_dev_parent(adev);
 53	struct amba_device *dev;
 54	struct resource_entry *rentry;
 55	struct list_head resource_list;
 56	bool address_found = false;
 57	int irq_no = 0;
 58	int ret;
 59
 60	/* If the ACPI node already has a physical device attached, skip it. */
 61	if (adev->physical_node_count)
 62		return 0;
 63
 64	dev = amba_device_alloc(dev_name(&adev->dev), 0, 0);
 65	if (!dev) {
 66		dev_err(&adev->dev, "%s(): amba_device_alloc() failed\n",
 67			__func__);
 68		return -ENOMEM;
 69	}
 70
 71	INIT_LIST_HEAD(&resource_list);
 72	ret = acpi_dev_get_resources(adev, &resource_list, NULL, NULL);
 73	if (ret < 0)
 74		goto err_free;
 75
 76	list_for_each_entry(rentry, &resource_list, node) {
 77		switch (resource_type(rentry->res)) {
 78		case IORESOURCE_MEM:
 79			if (!address_found) {
 80				dev->res = *rentry->res;
 81				dev->res.name = dev_name(&dev->dev);
 82				address_found = true;
 83			}
 84			break;
 85		case IORESOURCE_IRQ:
 86			if (irq_no < AMBA_NR_IRQS)
 87				dev->irq[irq_no++] = rentry->res->start;
 88			break;
 89		default:
 90			dev_warn(&adev->dev, "Invalid resource\n");
 91			break;
 92		}
 93	}
 94
 95	acpi_dev_free_resource_list(&resource_list);
 96
 97	/*
 98	 * If the ACPI node has a parent and that parent has a physical device
 99	 * attached to it, that physical device should be the parent of
100	 * the amba device we are about to create.
101	 */
102	if (parent)
103		dev->dev.parent = acpi_get_first_physical_node(parent);
104
105	ACPI_COMPANION_SET(&dev->dev, adev);
106
107	ret = amba_device_add(dev, &iomem_resource);
108	if (ret) {
109		dev_err(&adev->dev, "%s(): amba_device_add() failed (%d)\n",
110		       __func__, ret);
111		goto err_free;
112	}
113
114	return 1;
115
116err_free:
117	amba_device_put(dev);
118	return ret;
119}
120
121static struct acpi_scan_handler amba_handler = {
122	.ids = amba_id_list,
123	.attach = amba_handler_attach,
124};
125
126void __init acpi_amba_init(void)
127{
128	amba_register_dummy_clk();
129	acpi_scan_add_handler(&amba_handler);
130}