Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755278AbbLDDkN (ORCPT ); Thu, 3 Dec 2015 22:40:13 -0500 Received: from mail-bn1bon0059.outbound.protection.outlook.com ([157.56.111.59]:39969 "EHLO na01-bn1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1755235AbbLDDkI (ORCPT ); Thu, 3 Dec 2015 22:40:08 -0500 X-Greylist: delayed 837 seconds by postgrey-1.27 at vger.kernel.org; Thu, 03 Dec 2015 22:40:07 EST Authentication-Results: spf=none (sender IP is 165.204.84.221) smtp.mailfrom=amd.com; 8bytes.org; dkim=none (message not signed) header.d=none;8bytes.org; dmarc=permerror action=none header.from=amd.com; X-WSS-ID: 0NYTDIW-07-25P-02 X-M-MSG: From: Wang Hongcheng To: Vinod Koul , Mika Westerberg , Joerg Roedel , "Greg Kroah-Hartman" , "Rafael J. Wysocki" CC: , , , , , Borislav Petkov , Huang Rui , Wan Zongshun , Ken Xue , Tony Li , Wang Hongcheng Subject: [PATCH 1/9] ACPI: Add support for AMBA bus type Date: Fri, 4 Dec 2015 11:24:18 +0800 Message-ID: <1449199466-6081-2-git-send-email-annie.wang@amd.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1449199466-6081-1-git-send-email-annie.wang@amd.com> References: <1449199466-6081-1-git-send-email-annie.wang@amd.com> MIME-Version: 1.0 Content-Type: text/plain X-EOPAttributedMessage: 0 X-Forefront-Antispam-Report: CIP:165.204.84.221;CTRY:US;IPV:NLI;EFV:NLI;SFV:NSPM;SFS:(10009020)(6009001)(2980300002)(428002)(189002)(199003)(48376002)(77096005)(2950100001)(50986999)(87936001)(86362001)(5003940100001)(5003600100002)(586003)(1096002)(1220700001)(11100500001)(101416001)(50466002)(53416004)(76176999)(5890100001)(189998001)(47776003)(97736004)(50226001)(5008740100001)(33646002)(92566002)(5001770100001)(36756003)(229853001)(19580405001)(19580395003)(106466001)(105586002)(2004002);DIR:OUT;SFP:1101;SCL:1;SRVR:DM3PR12MB0858;H:atltwp01.amd.com;FPR:;SPF:None;PTR:InfoDomainNonexistent;MX:1;A:3;LANG:en; X-Microsoft-Exchange-Diagnostics: 1;DM3PR12MB0858;2:dvfREYd1jv2hIBd2pGTRJNAbF0rXIMxbgc9tccLZMm7AkI7m+vRRiOsnMFqaID2NLeX9iS/0gZiwIV2p2sVzvnLx60hydo+CnfoTBXx0ggGSEqwnRGxC5IL3Z+Q4FWqtmjEtl+Kd2LrJdvukqXwvjA==;3:xAtLJimOfgwJ4ZQ9aA/0Ad0LJdfIGoN/sKLDufjRm3wzDrsjNa/KFeUAjsdL0hCGDJR32DVPyC/Ou/f25xB5h2qFAzTVKOHmWOj02L/josXxdZjkmC3dfpcQzlr4oie2VUEvsoaDuBsckcNRyaWTUWiMD3/pla1vzV36MidPXbwcYnl8SoHfHC35JBR6lfuLHFLpiO/cTRhd3y9IOSdUMd0XDIVPEbCEgGk6djqoDFM=;25:WV+iMjMDEMz3GFVoIDKnLHCBhyrjLiU3gd9so7DampNfN145M79TuDCM6dKRElsWgGk/wBRwltz1IvTMRFyTTdwJqCCq8FC+NkMCzQPCNHQhYijKNm5liFHj1Is/mKzK2Eh0LERgJTNQebHcizik1paIcZoqx/sdRddpH7CLvlpSAbswz7vnuYYZ7zPryh4dZo0LmWK0IT8nmDd7iHhfBDh8Uj0WLGYZFn9ugd5k78XNs4au78gHvyH+PCtVBUgyExQPA2OmQoC697WcUPM/MA== X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:DM3PR12MB0858; X-Microsoft-Exchange-Diagnostics: 1;DM3PR12MB0858;20:3IQEuG9Pqo/KxZQNB1cSs1hnzcbEHEnU+/7NxCKQyFoXBVvRIb7SPUqi/TqJv8oYCCjwl+CSaXNT/KbRQfhMfZCFWt1mfUjh1B5/nMm0aiPc59hNTGk9aaoaLG1zw1nSf/zlhYvk3DrUKWxI6XQ8iNGevbRkGA9ddyCFAFNDcqpw5L6Hv4Xw3TJRHJAuCwA3RzL0RMaQshydruNMGF77Er3O2H+AR9/D4AQswMQiCTUJXzXVZ2I0ox/7AKuJ3TN2Lm4jCzqQQyv/nqlUkr4+wOdylVeFeO4voru43UEsmqlF9TqstOqhVKmSKXf5FyncQz3KtoYHgEHpJasXAJKrTLuBaTRatp13VTSjE8UlJDwMgXh05b1pYWy3yrCji4s5QAuEesksi0paFh1ASMC8xpRdWcID79Jc47EstK7dlJGeX9vvN58cZmzR602qICxZ4Z5TcOddKwMvhDdJ5kCTF7KeLjN/aWiTwREdz8AfP+B5dDq5k0o3F8FG7yBhV7S+;4:BGMToP/AHgJKU76c4Zzt8RkcdEc30ud+ELhxq5Jqz9zVsHxwAv+C6pk1Cyg8mW9atXL+tk7tSA/5X2KwP8vIU2KOSAPRAsrVq2y/6rY9Fb4ACNWbMvLxcYXzkIE+BPof8rBbykPC6eKn4Jl06mbHAMQhtXDdCIXsdujWPY84KO22/dz0UuANCwmZCN8iNL6rztQdmzSVRONypKkLSSMHOc1k4R9QISjDv0zkShFrxm8AJ2FuoBmIFk2ool0Kjq1HYpUnQ95VZ2jO6XTrZ+AHs1bwU1+S5rnP2gajvLAMngEAVPhEIZC8IT8sgGeLnzvwGRfvZfws2GuiqtLfNsEqHF1gcaUhhIL+q+f3KU7fYvQlqGsf82Qo0kwD8eONgF41cUxdTUlJQMR7Af2bZ4+fME3mw8LufnZ2NVHZg9Eb0Ks= X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(767451399110); X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(601004)(2401047)(8121501046)(520078)(5005006)(3002001)(10201501046);SRVR:DM3PR12MB0858;BCL:0;PCL:0;RULEID:;SRVR:DM3PR12MB0858; X-Forefront-PRVS: 07807C55DC X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1;DM3PR12MB0858;23:4De30q+jKqEd2uL04MM2YKflglX0Oq6tcEcDb8sSk?= =?us-ascii?Q?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aQIBzwcVZ2zTM?= =?us-ascii?Q?ilp5+Uz6odlOd8KMR7/Bo+Gn8wTVTimryePVNdGAfe80DPzZMeTO4jPyp/vm?= =?us-ascii?Q?BezE9QJeDvjixfQFlgJYjjq?= X-Microsoft-Exchange-Diagnostics: 1;DM3PR12MB0858;5:zL2I6PGk9B/8T9Qvd49u55GxwDKhMROgKZ1puQL/UtEf/1WKTqrNBr6g+YTnym/xbIreSSWdyvqCsNFQnJ4n4Wzp15xHmeU7zyHwc/ftqdrzQYHzZZqcXVVXI1FbGLwt0DpXxbOaB7qt5nmHY1h0Lg==;24:LAVXoed5Q0yJHKrnME698FO5hSHTvWrQxxDXwYiNySD+sSGm7oiHFK2uMaeSL1uNovTC+glxrrM2/jqEpN/+QEwT5SCvXCMluGTT/Ol0kd8=;20:gGDl1cQBu1DdlufInzkDB2KfOkAwTrwI2iVjsVUUn64xBWdYAdpsA6EU377NCdUxEGQlNPcMR79MI3FA2VE+l7MSbkWXhOnRFMEt/gr1aYhAlERYrGDqA0UwuaA7XGPddJxZ2cYqPsV2ToYIXqkbxKwyiFvHFh8VX61j1u51fU2fd5LfPKJ/Hyv2WCSOKBBQN/pB8AQuGf+rCaNZaFJ8asnNwzCnKkgE/wiOHKlp32JYXb+lPclEk5SjQqqkhK7g SpamDiagnosticOutput: 1:23 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Dec 2015 03:25:46.7112 (UTC) X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.221];Helo=[atltwp01.amd.com] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM3PR12MB0858 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 6912 Lines: 241 From: Huang Rui Inspired by acpi platform bus type, to make driver "porting" more straightforward, this patch introduces ACPI support to the AMBA bus type. Instead of writing ACPI "glue" drivers for the exiting AMBA drivers. In the subsequent patches, we will use this function to support pl330 AMBA driver. Signed-off-by: Huang Rui Signed-off-by: Wang Hongcheng --- drivers/acpi/Makefile | 1 + drivers/acpi/acpi_amba.c | 157 +++++++++++++++++++++++++++++++++++++++++++++++ include/linux/acpi.h | 21 +++++++ 3 files changed, 179 insertions(+) create mode 100644 drivers/acpi/acpi_amba.c diff --git a/drivers/acpi/Makefile b/drivers/acpi/Makefile index 675eaf3..7d84446 100644 --- a/drivers/acpi/Makefile +++ b/drivers/acpi/Makefile @@ -42,6 +42,7 @@ acpi-$(CONFIG_ACPI_DOCK) += dock.o acpi-y += pci_root.o pci_link.o pci_irq.o acpi-y += acpi_lpss.o acpi_apd.o acpi-y += acpi_platform.o +acpi-$(CONFIG_ARM_AMBA) += acpi_amba.o acpi-y += acpi_pnp.o acpi-y += int340x_thermal.o acpi-y += power.o diff --git a/drivers/acpi/acpi_amba.c b/drivers/acpi/acpi_amba.c new file mode 100644 index 0000000..4f0366a --- /dev/null +++ b/drivers/acpi/acpi_amba.c @@ -0,0 +1,157 @@ +/* + * ACPI support for AMBA bus type. + * + * Copyright (C) 2015, Advanced Micro Devices, Inc. + * Authors: Huang Rui + * Wang Hongcheng + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "internal.h" + +ACPI_MODULE_NAME("amba"); + +/** + * acpi_create_amba_device - Create AMBA device for ACPI device node. + * @adev: ACPI device node to create an AMBA device. + * @periphid: AMBA device periphid. + * @fixed_rate: Clock frequency. + * @pdata: Platform data specific to the device. + * + * Check if the given @adev can be represented as an AMBA device and, if + * that's the case, create and register an AMBA device, populate its + * common resources and returns a pointer to it. Otherwise, return + * %NULL or ERR_PTR() on error. + * + * Name of the AMBA device will be the same as @adev's. + */ +struct amba_device *acpi_create_amba_device(struct acpi_device *adev, + unsigned int periphid, + unsigned long fixed_rate, + void *pdata) +{ + struct amba_device *amba_dev = NULL; + struct device *parent; + struct acpi_device *acpi_parent; + struct resource_entry *rentry; + struct list_head resource_list; + struct resource *resource = NULL; + int count, ret = 0; + unsigned int i; + unsigned int irq[AMBA_NR_IRQS]; + struct clk *clk = ERR_PTR(-ENODEV); + + /* + * If the ACPI node already has a physical device attached, + * skip it. + */ + if (adev->physical_node_count) + return NULL; + + INIT_LIST_HEAD(&resource_list); + count = acpi_dev_get_resources(adev, &resource_list, NULL, NULL); + if (count <= 0) + return NULL; + + resource = kzalloc(sizeof(*resource), GFP_KERNEL); + if (!resource) + goto resource_alloc_err; + + count = 0; + list_for_each_entry(rentry, &resource_list, node) { + if (resource_type(rentry->res) == IORESOURCE_IRQ) { + irq[count] = rentry->res->start; + count++; + } + /* + * there is only one io memory resource entry + * at current AMBA device design + */ + if (resource_type(rentry->res) | IORESOURCE_MEM) + memcpy(resource, rentry->res, sizeof(struct resource)); + } + + amba_dev = amba_device_alloc(dev_name(&adev->dev), + resource->start, + resource_size(resource)); + + if (!amba_dev) + goto amba_alloc_err; + + amba_dev->dev.coherent_dma_mask = acpi_dma_supported(adev) ? DMA_BIT_MASK(64) : 0; + amba_dev->dev.platform_data = pdata; + amba_dev->dev.fwnode = acpi_fwnode_handle(adev); + + /* + * If the ACPI node has a parent and that parent has a + * physical device attached to it, that physical device should + * be the parent of the AMBA device we are about to create. + */ + parent = NULL; + acpi_parent = adev->parent; + if (acpi_parent) { + struct acpi_device_physical_node *entry; + struct list_head *list; + + mutex_lock(&acpi_parent->physical_node_lock); + list = &acpi_parent->physical_node_list; + if (!list_empty(list)) { + entry = list_first_entry(list, struct acpi_device_physical_node, node); + parent = entry->dev; + } + mutex_unlock(&acpi_parent->physical_node_lock); + } + + amba_dev->dev.parent = parent; + amba_dev->periphid = periphid; + + WARN_ON_ONCE(count > AMBA_NR_IRQS); + + for (i = 0; i < count; i++) + amba_dev->irq[i] = irq[i]; + + clk = clk_register_fixed_rate(&amba_dev->dev, + dev_name(&amba_dev->dev), + NULL, CLK_IS_ROOT, + fixed_rate); + if (IS_ERR_OR_NULL(clk)) + goto amba_register_err; + + ret = clk_register_clkdev(clk, "apb_pclk", + dev_name(&amba_dev->dev)); + if (ret) + goto amba_register_err; + + ret = amba_device_add(amba_dev, resource); + if (ret) + goto amba_register_err; + + acpi_dev_free_resource_list(&resource_list); + kfree(resource); + return amba_dev; + +amba_register_err: + amba_device_put(amba_dev); + +amba_alloc_err: + kfree(resource); + +resource_alloc_err: + acpi_dev_free_resource_list(&resource_list); + + return ERR_PTR(ret); +} diff --git a/include/linux/acpi.h b/include/linux/acpi.h index 0548339..04827d8 100644 --- a/include/linux/acpi.h +++ b/include/linux/acpi.h @@ -37,6 +37,7 @@ #include #include #include +#include #include #include @@ -466,6 +467,26 @@ int acpi_device_modalias(struct device *, char *, int); void acpi_walk_dep_device_list(acpi_handle handle); struct platform_device *acpi_create_platform_device(struct acpi_device *); + +#ifdef CONFIG_ARM_AMBA + +struct amba_device *acpi_create_amba_device(struct acpi_device *adev, + unsigned int periphid, + unsigned long fixed_rate, + void *pdata); + +#else /* !CONFIG_ARM_AMBA */ + +static inline struct amba_device *acpi_create_amba_device(struct acpi_device *adev, + unsigned int periphid, + unsigned long fixed_rate, + void *pdata) +{ + return NULL; +} + +#endif + #define ACPI_PTR(_ptr) (_ptr) #else /* !CONFIG_ACPI */ -- 1.9.1 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/