From patchwork Mon Apr 2 01:21:25 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 7565 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id B7DC623E23 for ; Mon, 2 Apr 2012 01:21:31 +0000 (UTC) Received: from mail-iy0-f180.google.com (mail-iy0-f180.google.com [209.85.210.180]) by fiordland.canonical.com (Postfix) with ESMTP id 7A0F7A1812D for ; Mon, 2 Apr 2012 01:21:31 +0000 (UTC) Received: by mail-iy0-f180.google.com with SMTP id e36so4975195iag.11 for ; Sun, 01 Apr 2012 18:21:31 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-forwarded-to:x-forwarded-for:delivered-to:received-spf:from:to:cc :subject:date:message-id:x-mailer:x-gm-message-state; bh=YaXVAwxbi9j8c5iLD+O7tcrhaLWFS/cdlzf0O39UGd0=; b=T8KOci19xK2I9tmP5BjkPF+ZMj3FfH83AMslceO/YJ+c8a/dd7r4Pe9nLcfsJ48pKH FRk0RSguebaz/dbx5v9Kz7C1kBU4zY+OTwGV+uV3hSTE9WHSlceRAI3UjEyoxHk4Hwan v+X5D4g+9Ut6uq4toXS9DSJmJUqIsS539NGbFbIQlFzb5rx1BRvBVQu8+ZytdbivbPXZ eITrrBHCaaNHAlalhzB9oaiVxsnQajJIFNbZzr0C7qF91YiC+Fi10aX2NAJaYf/rbjnX FhSrYX4VNTp01bxcTGrCkXLC0hbVPEYrjTTW9Ioid9EjWLEnG4R5mdXwat6qeJxrejg5 toEw== Received: by 10.50.149.131 with SMTP id ua3mr4193624igb.41.1333329691231; Sun, 01 Apr 2012 18:21:31 -0700 (PDT) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.231.5.205 with SMTP id 13csp87683ibw; Sun, 1 Apr 2012 18:21:30 -0700 (PDT) Received: by 10.204.133.196 with SMTP id g4mr2819487bkt.0.1333329689904; Sun, 01 Apr 2012 18:21:29 -0700 (PDT) Received: from mail.df.lth.se (mail.df.lth.se. [194.47.250.12]) by mx.google.com with ESMTPS id hs1si8978916bkc.29.2012.04.01.18.21.29 (version=TLSv1/SSLv3 cipher=OTHER); Sun, 01 Apr 2012 18:21:29 -0700 (PDT) Received-SPF: neutral (google.com: 194.47.250.12 is neither permitted nor denied by best guess record for domain of linus.walleij@linaro.org) client-ip=194.47.250.12; Authentication-Results: mx.google.com; spf=neutral (google.com: 194.47.250.12 is neither permitted nor denied by best guess record for domain of linus.walleij@linaro.org) smtp.mail=linus.walleij@linaro.org Received: from fecusia (c83-249-217-152.bredband.comhem.se [83.249.217.152]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.df.lth.se (Postfix) with ESMTPSA id CA49C65D6F; Mon, 2 Apr 2012 03:21:27 +0200 (CEST) Received: by fecusia (sSMTP sendmail emulation); Mon, 2 Apr 2012 03:21:27 +0200 From: "Linus Walleij" To: linux-arm-kernel@lists.infradead.org Cc: Shawn Guo , Linus Walleij , Russell King Subject: [PATCH 1/4] amba: add functions to add devices dynamically Date: Mon, 2 Apr 2012 03:21:25 +0200 Message-Id: <1333329685-31631-1-git-send-email-linus.walleij@linaro.org> X-Mailer: git-send-email 1.7.7.6 X-Gm-Message-State: ALoCoQnbrIE2wRZ/9mRKvEfv3dWe+FQW/xFiJJ851PcpuOiUryXWjHpyUGf0OSJbP4DRLdZBOLzk Add two functions to add APB and AHB devices to the amba (PrimeCell) bus dynamically. This is modeled after the static definition macros recently introduced into and can help us in factoring out a bunch of code across the kernel. Since a lot of call sites seem to be using a returned struct amba device* pointer, let's use that. Cc: Russell King Signed-off-by: Linus Walleij --- drivers/amba/bus.c | 49 ++++++++++++++++++++++++++++++++++++++++++++++ include/linux/amba/bus.h | 8 +++++++ 2 files changed, 57 insertions(+), 0 deletions(-) diff --git a/drivers/amba/bus.c b/drivers/amba/bus.c index 01c2cf4..5382624 100644 --- a/drivers/amba/bus.c +++ b/drivers/amba/bus.c @@ -583,6 +583,55 @@ int amba_device_add(struct amba_device *dev, struct resource *parent) } EXPORT_SYMBOL_GPL(amba_device_add); +static struct amba_device * +amba_aphb_device_add(struct device *parent, const char *name, + resource_size_t base, size_t size, int irq1, int irq2, + void *pdata, unsigned int periphid, u64 dma_mask) +{ + struct amba_device *dev; + int ret; + + dev = amba_device_alloc(name, base, size); + if (!dev) + return ERR_PTR(-ENOMEM); + + dev->dma_mask = dma_mask; + dev->dev.coherent_dma_mask = dma_mask; + dev->irq[0] = irq1; + dev->irq[1] = irq2; + dev->periphid = periphid; + dev->dev.platform_data = pdata; + dev->dev.parent = parent; + + ret = amba_device_add(dev, &iomem_resource); + if (ret) { + amba_device_put(dev); + return ERR_PTR(ret); + } + + return dev; +} + +struct amba_device * +amba_apb_device_add(struct device *parent, const char *name, + resource_size_t base, size_t size, int irq1, int irq2, + void *pdata, unsigned int periphid) +{ + return amba_aphb_device_add(parent, name, base, size, irq1, irq2, pdata, + periphid, 0); +} +EXPORT_SYMBOL_GPL(amba_apb_device_add); + +struct amba_device * +amba_ahb_device_add(struct device *parent, const char *name, + resource_size_t base, size_t size, int irq1, int irq2, + void *pdata, unsigned int periphid) +{ + return amba_aphb_device_add(parent, name, base, size, irq1, irq2, pdata, + periphid, ~0ULL); +} +EXPORT_SYMBOL_GPL(amba_ahb_device_add); + static void amba_device_initialize(struct amba_device *dev, const char *name) { device_initialize(&dev->dev); diff --git a/include/linux/amba/bus.h b/include/linux/amba/bus.h index 7847e19..db64b0c 100644 --- a/include/linux/amba/bus.h +++ b/include/linux/amba/bus.h @@ -64,6 +64,14 @@ struct amba_device *amba_device_alloc(const char *, resource_size_t, size_t); void amba_device_put(struct amba_device *); int amba_device_add(struct amba_device *, struct resource *); int amba_device_register(struct amba_device *, struct resource *); +struct amba_device *amba_apb_device_add(struct device *parent, const char *name, + resource_size_t base, size_t size, + int irq1, int irq2, void *pdata, + unsigned int periphid); +struct amba_device *amba_ahb_device_add(struct device *parent, const char *name, + resource_size_t base, size_t size, + int irq1, int irq2, void *pdata, + unsigned int periphid); void amba_device_unregister(struct amba_device *); struct amba_device *amba_find_device(const char *, struct device *, unsigned int, unsigned int); int amba_request_regions(struct amba_device *, const char *);