From patchwork Mon Dec 21 14:49:55 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aleksey Makarov X-Patchwork-Id: 7896371 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 0EBA89F1AF for ; Mon, 21 Dec 2015 14:54:07 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id F037C2055C for ; Mon, 21 Dec 2015 14:54:05 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 0520A20502 for ; Mon, 21 Dec 2015 14:54:05 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1aB1pF-0003yY-EX; Mon, 21 Dec 2015 14:52:37 +0000 Received: from mail-lf0-x22a.google.com ([2a00:1450:4010:c07::22a]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1aB1ox-0003m8-00 for linux-arm-kernel@lists.infradead.org; Mon, 21 Dec 2015 14:52:21 +0000 Received: by mail-lf0-x22a.google.com with SMTP id y184so112316089lfc.1 for ; Mon, 21 Dec 2015 06:51:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=L0Rc16R5r/Ak3st0deIX8Qwbt9EC5qtOJIa1EFBzw+o=; b=hiw3z8r1zAEgfBUNFW4Y/Xh780bY0Ljv0a8g6JMCq2bFpk7R7dTlMp33aSqxqXOFoH qpVTZlOKwsOV67jT+fkbbeO5D9pC7hUK0YH9HliYnK4ObG50dEWd1N2T55xxuDDVC3qp APBIlTldUlOzVGH3CGEr/VdDXd4laUQ9LCA74= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=L0Rc16R5r/Ak3st0deIX8Qwbt9EC5qtOJIa1EFBzw+o=; b=hD/LLQqjHuP6FOUVFtAgKA4D84V08sv7n3Qa5Tt8vmnZEPF54ZgsW4EdclU+Ii9uiG HRVWW69TKciFL4o/RDPatHqXSszWaYuVOHOnMCuMKU7uvl1OOzQTTJ35inw/XXveRUDd dLrBxfB+F+c4GuRuCxOKelgm2n8xEsA/mW+2JZcjik5bBlWtEVu5SRbUbhedWM9k8ZMO BHYD6SjPAaqileoQesi5btUNA1qjneP7ahACTlAV5DKxUcZzBn7M5feDg98UoQh5Lxdq dsV6XiODuyoQo/Q4xxU91vD0X4lHV0cNXYd7p2atqi5x8rnwAXi6BhbQRogMr1uCTkQX 6f2A== X-Gm-Message-State: ALoCoQmoTjWVisTUT6QOzGSPaJ+Js++sENMB4DTbo/ADvYbx/4yEJi/X1gdTPjxqqqqYm834x2j9fw/+QgxiXMdkw1TVYBBUeg== X-Received: by 10.25.134.2 with SMTP id i2mr6744206lfd.68.1450709516848; Mon, 21 Dec 2015 06:51:56 -0800 (PST) Received: from turnip.localdomain (nivc-213.auriga.ru. [80.240.102.213]) by smtp.gmail.com with ESMTPSA id y15sm5061874lfd.3.2015.12.21.06.51.55 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 21 Dec 2015 06:51:55 -0800 (PST) From: Aleksey Makarov To: linux-acpi@vger.kernel.org Subject: [PATCH v2 1/3] ACPI: amba bus probing support Date: Mon, 21 Dec 2015 17:49:55 +0300 Message-Id: <1450709399-7246-2-git-send-email-aleksey.makarov@linaro.org> X-Mailer: git-send-email 2.6.4 In-Reply-To: <1450709399-7246-1-git-send-email-aleksey.makarov@linaro.org> References: <1450709399-7246-1-git-send-email-aleksey.makarov@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20151221_065219_564458_1E307460 X-CRM114-Status: GOOD ( 22.99 ) X-Spam-Score: -2.7 (--) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Russell King , Graeme Gregory , Greg Kroah-Hartman , "Rafael J . Wysocki" , linux-kernel@vger.kernel.org, Aleksey Makarov , Shannon Zhao , linux-serial@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Len Brown MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,RP_MATCHES_RCVD,T_DKIM_INVALID,UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Graeme Gregory On ARM64 some devices use the AMBA device and not the platform bus for probing so add support for this. Uses a dummy clock for apb_pclk as ACPI does not have a suitable clock representation and to keep the core AMBA bus code unchanged between probing methods. Signed-off-by: Graeme Gregory Signed-off-by: Aleksey Makarov --- drivers/acpi/Makefile | 1 + drivers/acpi/acpi_amba.c | 149 +++++++++++++++++++++++++++++++++++++++++++++++ drivers/acpi/internal.h | 5 ++ 3 files changed, 155 insertions(+) create mode 100644 drivers/acpi/acpi_amba.c diff --git a/drivers/acpi/Makefile b/drivers/acpi/Makefile index 675eaf3..3cf732f 100644 --- a/drivers/acpi/Makefile +++ b/drivers/acpi/Makefile @@ -43,6 +43,7 @@ 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-y += acpi_pnp.o +acpi-$(CONFIG_ARM_AMBA) += acpi_amba.o acpi-y += int340x_thermal.o acpi-y += power.o acpi-y += event.o diff --git a/drivers/acpi/acpi_amba.c b/drivers/acpi/acpi_amba.c new file mode 100644 index 0000000..ebc8913 --- /dev/null +++ b/drivers/acpi/acpi_amba.c @@ -0,0 +1,149 @@ + +/* + * ACPI support for platform bus type. + * + * Copyright (C) 2015, Linaro Ltd + * Authors: Graeme Gregory + * + * 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 "internal.h" + +static const struct acpi_device_id amba_id_list[] = { + {"ARMH0011", 0}, /* PL011 SBSA Uart */ + {"ARMH0061", 0}, /* PL061 GPIO Device */ + {"", 0}, +}; + +static struct clk *amba_dummy_clk; + +static void amba_register_dummy_clk(void) +{ + struct clk *clk; + + /* If clock already registered */ + if (amba_dummy_clk) + return; + + clk = clk_register_fixed_rate(NULL, "apb_pclk", NULL, CLK_IS_ROOT, 0); + clk_register_clkdev(clk, "apb_pclk", NULL); + + amba_dummy_clk = clk; +} + +static int amba_handler_attach(struct acpi_device *adev, + const struct acpi_device_id *id) +{ + struct amba_device *dev = NULL; + struct acpi_device *acpi_parent; + struct resource_entry *rentry; + struct list_head resource_list; + struct resource *resources = NULL; + bool address_found = false; + int ret, count, irq_no = 0; + + /* If the ACPI node already has a physical device attached, skip it. */ + if (adev->physical_node_count) + return 0; + + amba_register_dummy_clk(); + + dev = amba_device_alloc(NULL, 0, 0); + if (!dev) { + pr_err("%s(): amba_device_alloc() failed for %s\n", + __func__, dev_name(&adev->dev)); + return 0; + } + + INIT_LIST_HEAD(&resource_list); + count = acpi_dev_get_resources(adev, &resource_list, NULL, NULL); + if (count < 0) { + return 0; + } else if (count > 0) { + resources = kmalloc_array(count, sizeof(struct resource), + GFP_KERNEL); + if (!resources) { + acpi_dev_free_resource_list(&resource_list); + return 0; + } + count = 0; + list_for_each_entry(rentry, &resource_list, node) { + switch (resource_type(rentry->res)) { + case IORESOURCE_MEM: + if (!address_found) { + dev->res = *rentry->res; + address_found = true; + } + break; + case IORESOURCE_IRQ: + if (irq_no < AMBA_NR_IRQS) + dev->irq[irq_no++] = rentry->res->start; + break; + default: + dev_warn(&adev->dev, "Invalid resource\n"); + } + } + acpi_dev_free_resource_list(&resource_list); + } + + /* + * 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 + * platform device we are about to create. + */ + dev->dev.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); + dev->dev.parent = entry->dev; + } + mutex_unlock(&acpi_parent->physical_node_lock); + } + + dev_set_name(&dev->dev, "%s", dev_name(&adev->dev)); + ACPI_COMPANION_SET(&dev->dev, adev); + + ret = amba_device_add(dev, &iomem_resource); + if (ret) { + pr_err("%s(): amba_device_add() failed (%d) for %s\n", + __func__, ret, dev_name(&adev->dev)); + goto err_free; + } + + return 1; + +err_free: + amba_device_put(dev); + return 0; +} + +static struct acpi_scan_handler amba_handler = { + .ids = amba_id_list, + .attach = amba_handler_attach, +}; + +void __init acpi_amba_init(void) +{ + acpi_scan_add_handler(&amba_handler); +} diff --git a/drivers/acpi/internal.h b/drivers/acpi/internal.h index 11d87bf..8f6e7ff 100644 --- a/drivers/acpi/internal.h +++ b/drivers/acpi/internal.h @@ -29,6 +29,11 @@ void acpi_processor_init(void); void acpi_platform_init(void); void acpi_pnp_init(void); void acpi_int340x_thermal_init(void); +#ifdef CONFIG_ARM_AMBA +void acpi_amba_init(void); +#else +void acpi_amba_init(void) {} +#endif int acpi_sysfs_init(void); void acpi_container_init(void); void acpi_memory_hotplug_init(void);