From patchwork Wed Sep 30 10:38:48 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Graeme Gregory X-Patchwork-Id: 54296 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f197.google.com (mail-wi0-f197.google.com [209.85.212.197]) by patches.linaro.org (Postfix) with ESMTPS id E74C822E23 for ; Wed, 30 Sep 2015 10:39:07 +0000 (UTC) Received: by wicuu12 with SMTP id uu12sf20132591wic.2 for ; Wed, 30 Sep 2015 03:39:07 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:sender:precedence:list-id :x-original-sender:x-original-authentication-results:mailing-list :list-post:list-help:list-archive:list-unsubscribe; bh=jSznghp6ob1zzo96iSWPmT6UpvWpLgopWv51jAAuB/o=; b=kXPQgBDDilqXKdWhCQuhvvJjp8E2fKbvhoShOsOusM574cE6mUmJqKe/It/x/cx9jd 2nJ4SDTmqqOFo4Oia8z93aMrOColj9WN/iOJE0SBXi4ZjeWWDz4AjA47ms055L40bj4a F7HzJlJb0B5qeXpkZ6AGOC8MvrhCf2e+olWBQYXnvcX+xd83cyrGedKZ2HX7Z932qCGW YZGqX+Gq+xekMHID3ESuaI3aiTiYQa29jxi2bE9JVi63r3H1HdhUZvhsbzNLPahNStkM zdj0ClIFqO4wWE8pKtbzNoNjLwQ2ddE98ahaohBW1jV+QsnxiP7UWeyAlzHS6W5k2l9j SW3A== X-Gm-Message-State: ALoCoQmmVs1kxQ/IksfqkE8guwFpxRT/vVOGPF0aJEFcusCSympztkntprEovNFlKYCmE3IhOSNq X-Received: by 10.152.170.169 with SMTP id an9mr423259lac.2.1443609547146; Wed, 30 Sep 2015 03:39:07 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.21.166 with SMTP id w6ls32682lae.10.gmail; Wed, 30 Sep 2015 03:39:07 -0700 (PDT) X-Received: by 10.112.164.35 with SMTP id yn3mr895965lbb.18.1443609547008; Wed, 30 Sep 2015 03:39:07 -0700 (PDT) Received: from mail-la0-f51.google.com (mail-la0-f51.google.com. [209.85.215.51]) by mx.google.com with ESMTPS id 38si213025lft.44.2015.09.30.03.39.06 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 30 Sep 2015 03:39:06 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.51 as permitted sender) client-ip=209.85.215.51; Received: by labzv5 with SMTP id zv5so40872247lab.1 for ; Wed, 30 Sep 2015 03:39:06 -0700 (PDT) X-Received: by 10.112.156.167 with SMTP id wf7mr873567lbb.88.1443609546841; Wed, 30 Sep 2015 03:39:06 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.59.35 with SMTP id w3csp2663576lbq; Wed, 30 Sep 2015 03:39:05 -0700 (PDT) X-Received: by 10.50.143.102 with SMTP id sd6mr7990660igb.5.1443609545521; Wed, 30 Sep 2015 03:39:05 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 9si597073iod.108.2015.09.30.03.39.05; Wed, 30 Sep 2015 03:39:05 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-serial-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754870AbbI3KjC (ORCPT + 1 other); Wed, 30 Sep 2015 06:39:02 -0400 Received: from mail-wi0-f181.google.com ([209.85.212.181]:34263 "EHLO mail-wi0-f181.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754962AbbI3Ki5 (ORCPT ); Wed, 30 Sep 2015 06:38:57 -0400 Received: by wicfx3 with SMTP id fx3so190479967wic.1 for ; Wed, 30 Sep 2015 03:38:56 -0700 (PDT) X-Received: by 10.180.23.231 with SMTP id p7mr31186811wif.30.1443609536497; Wed, 30 Sep 2015 03:38:56 -0700 (PDT) Received: from xora-haswell.xora.org.uk.xora.org.uk (host-92-22-69-126.as13285.net. [92.22.69.126]) by smtp.gmail.com with ESMTPSA id gh9sm544528wjb.27.2015.09.30.03.38.54 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 30 Sep 2015 03:38:55 -0700 (PDT) From: Graeme Gregory To: linux-acpi@vger.kernel.org Cc: linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org, shannon.zhao@linaro.org, Graeme Gregory , "Rafael J. Wysocki" , Len Brown , Russell King Subject: [PATCH 1/3] ACPI: amba bus probing support Date: Wed, 30 Sep 2015 11:38:48 +0100 Message-Id: <1443609530-21524-2-git-send-email-graeme.gregory@linaro.org> X-Mailer: git-send-email 2.4.3 In-Reply-To: <1443609530-21524-1-git-send-email-graeme.gregory@linaro.org> References: <1443609530-21524-1-git-send-email-graeme.gregory@linaro.org> Sender: linux-serial-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-serial@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: graeme.gregory@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.51 as permitted sender) smtp.mailfrom=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , 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. Cc: Rafael J. Wysocki Cc: Len Brown Cc: Russell King Signed-off-by: Graeme Gregory --- drivers/acpi/Makefile | 1 + drivers/acpi/acpi_amba.c | 157 +++++++++++++++++++++++++++++++++++++++++++++++ include/linux/acpi.h | 1 + 3 files changed, 159 insertions(+) create mode 100644 drivers/acpi/acpi_amba.c diff --git a/drivers/acpi/Makefile b/drivers/acpi/Makefile index b5e7cd8..b94aa9f 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-y += 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..2f45b71 --- /dev/null +++ b/drivers/acpi/acpi_amba.c @@ -0,0 +1,157 @@ + +/* + * 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 + +#ifdef CONFIG_ARM_AMBA +static const struct acpi_device_id amba_id_list[] = { + {"ARMH0011", 0}, /* PL011 SBSA Uart */ + {"ARMH0061", 0}, /* PL061 GPIO Device */ + {"", 0}, +}; + +struct clk *amba_dummy_clk; + +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; +} + +/** + * acpi_create_amba_device - Create platform device for ACPI device node + * @adev: ACPI device node to create a AMBA device for. + * + * Create and register an AMBA device, populate its common + * resources and return a pointer to it. Otherwise, return %NULL. + * + * Name of the AMBA device will be the same as @adev's. + */ +struct amba_device *acpi_create_amba_device(struct acpi_device *adev) +{ + 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 NULL; + + /* AMBA devices use amba_device not platform device */ + if (acpi_match_device_ids(adev, amba_id_list)) + return NULL; + + 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 NULL; + } + + INIT_LIST_HEAD(&resource_list); + count = acpi_dev_get_resources(adev, &resource_list, NULL, NULL); + if (count < 0) { + return NULL; + } else if (count > 0) { + resources = kmalloc_array(count, sizeof(struct resource), + GFP_KERNEL); + if (!resources) { + acpi_dev_free_resource_list(&resource_list); + return ERR_PTR(-ENOMEM); + } + 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 dev; + +err_free: + amba_device_put(dev); + return NULL; +} +#else +struct amba_device *acpi_create_amba_device(struct acpi_device *adev) +{ + return NULL; +} +#endif /* CONFIG_ARM_AMBA */ +EXPORT_SYMBOL_GPL(acpi_create_amba_device); diff --git a/include/linux/acpi.h b/include/linux/acpi.h index 84e7055..dc42ec0 100644 --- a/include/linux/acpi.h +++ b/include/linux/acpi.h @@ -457,6 +457,7 @@ 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 *); +struct amba_device *acpi_create_amba_device(struct acpi_device *); #define ACPI_PTR(_ptr) (_ptr) #else /* !CONFIG_ACPI */