Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

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