From patchwork Tue Aug 14 13:49:27 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Genoud X-Patchwork-Id: 1319551 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) by patchwork2.kernel.org (Postfix) with ESMTP id 8528CDF215 for ; Tue, 14 Aug 2012 13:59:45 +0000 (UTC) Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1T1HaR-0002z6-LP; Tue, 14 Aug 2012 13:55:12 +0000 Received: from mail-we0-f177.google.com ([74.125.82.177]) by merlin.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1T1HW2-0000YQ-Uh for linux-arm-kernel@lists.infradead.org; Tue, 14 Aug 2012 13:50:45 +0000 Received: by mail-we0-f177.google.com with SMTP id r3so277672wey.36 for ; Tue, 14 Aug 2012 06:50:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; bh=az4Rrb6NhFBBZ6jFJYnXgwcIZMdcfCPyX7D+v7iMXnw=; b=jBP2dXrBOFjDmd15/Zu/bTmAd2BugCne+LWqckWKiZsO7JaDphwbU+5/aIuQ6XTRue FTQaDMMvjuUTlchh/r7o4hAYXQgsWPRuQN7P4r3MpRpfCZUTGugyebHHQ1n//lwPGkEY eOdNXSZwfwH60cIYHLsnb+SBK6OupLobkYNELzC+m6gEwXtroErs7CAojUj7MR56mL4J Pqv6qFu24/FytVQZmWITcr/pv2ufR1i9nC2w8mF0fhG2OIzz8KKsZ78K2E0CBmCqWLG8 OpbqBP8wqMgAA/5BY1TbvU6BQ9jAfzHh4obgiuzqbwxMe31ExR8nzdWlJJ6ixFTo/oGO PVlw== Received: by 10.216.135.148 with SMTP id u20mr8020501wei.137.1344952238584; Tue, 14 Aug 2012 06:50:38 -0700 (PDT) Received: from localhost.localdomain (lyon.paratronic.fr. [213.41.177.106]) by mx.google.com with ESMTPS id eu4sm22509397wib.2.2012.08.14.06.50.37 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 14 Aug 2012 06:50:38 -0700 (PDT) From: Richard Genoud To: Nicolas Ferre Subject: [PATCH 13/23] AT91 DMA OF support Date: Tue, 14 Aug 2012 15:49:27 +0200 Message-Id: <1344952177-18385-14-git-send-email-richard.genoud@gmail.com> X-Mailer: git-send-email 1.7.2.5 In-Reply-To: <1344952177-18385-1-git-send-email-richard.genoud@gmail.com> References: <1344952177-18385-1-git-send-email-richard.genoud@gmail.com> X-Spam-Note: CRM114 invocation failed X-Spam-Score: -2.7 (--) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-2.7 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [74.125.82.177 listed in list.dnswl.org] 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider (richard.genoud[at]gmail.com) -0.0 SPF_PASS SPF: sender matches SPF record -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature Cc: Richard Genoud , Jean-Christophe PLAGNIOL-VILLARD , linux-arm-kernel@lists.infradead.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: linux-arm-kernel-bounces@lists.infradead.org Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org Signed-off-by: Richard Genoud --- arch/arm/mach-at91/include/mach/at_hdmac.h | 1 + drivers/of/Kconfig | 4 + drivers/of/Makefile | 1 + drivers/of/of_atmel.c | 112 ++++++++++++++++++++++++++++ include/linux/of_atmel.h | 29 +++++++ 5 files changed, 147 insertions(+), 0 deletions(-) create mode 100644 drivers/of/of_atmel.c create mode 100644 include/linux/of_atmel.h diff --git a/arch/arm/mach-at91/include/mach/at_hdmac.h b/arch/arm/mach-at91/include/mach/at_hdmac.h index cab0997..35667bd 100644 --- a/arch/arm/mach-at91/include/mach/at_hdmac.h +++ b/arch/arm/mach-at91/include/mach/at_hdmac.h @@ -52,6 +52,7 @@ struct at_dma_slave { #define ATC_LOCK_IF_L_CHUNK (0x0 << 22) #define ATC_LOCK_IF_L_BUFFER (0x1 << 22) #define ATC_AHB_PROT_MASK (0x7 << 24) /* AHB Protection */ +#define ATC_AHB_PROT(h) (((h) << 24) && ATC_AHB_PROT_MASK) #define ATC_FIFOCFG_MASK (0x3 << 28) /* FIFO Request Configuration */ #define ATC_FIFOCFG_LARGESTBURST (0x0 << 28) #define ATC_FIFOCFG_HALFFIFO (0x1 << 28) diff --git a/drivers/of/Kconfig b/drivers/of/Kconfig index dfba3e6..4667960 100644 --- a/drivers/of/Kconfig +++ b/drivers/of/Kconfig @@ -83,4 +83,8 @@ config OF_MTD depends on MTD def_bool y +config OF_ATMEL + depends on AT_HDMAC + def_bool y + endmenu # OF diff --git a/drivers/of/Makefile b/drivers/of/Makefile index e027f44..897de3b 100644 --- a/drivers/of/Makefile +++ b/drivers/of/Makefile @@ -11,3 +11,4 @@ obj-$(CONFIG_OF_MDIO) += of_mdio.o obj-$(CONFIG_OF_PCI) += of_pci.o obj-$(CONFIG_OF_PCI_IRQ) += of_pci_irq.o obj-$(CONFIG_OF_MTD) += of_mtd.o +obj-$(CONFIG_OF_ATMEL) += of_atmel.o diff --git a/drivers/of/of_atmel.c b/drivers/of/of_atmel.c new file mode 100644 index 0000000..bcd3c54a --- /dev/null +++ b/drivers/of/of_atmel.c @@ -0,0 +1,112 @@ +/* + * Copyright (C) 2012 Richard Genoud, Paratronic S.A. + * + * + * Atmel specifics OF helpers + * + * 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 + +static int of_dev_node_match(struct device *dev, void *data) +{ + return dev->of_node == data; +} + +/** + * of_create_at_dma_slave - Alloc and initialize the struct at_dma_slave + * @np: pointer to node to create the struct for + * @bus: pointer to the bus type of the DMA device. + * + * Returns pointer to created DMA slave structure, or NULL in case of error. + */ +struct at_dma_slave *of_create_at_dma_slave(struct device_node *np, + struct bus_type *bus) +{ + struct at_dma_slave *atslave; + struct device_node *n; + struct property *prop; + const __be32 *dma_list; + phandle phandle; + int size; + int err = -1; + u32 val; + + atslave = kzalloc(sizeof(struct at_dma_slave), GFP_KERNEL); + if (unlikely(!atslave)) { + pr_err("cannot allocate memory\n"); + goto error; + } + + atslave->cfg |= of_property_read_bool(np, "atc_src_rep") ? ATC_SRC_REP : 0; + atslave->cfg |= of_property_read_bool(np, "atc_dst_rep") ? ATC_DST_REP : 0; + atslave->cfg |= of_property_read_bool(np, "atc_src_h2sel_hw") ? ATC_SRC_H2SEL_HW : 0; + atslave->cfg |= of_property_read_bool(np, "atc_dst_h2sel_hw") ? ATC_DST_H2SEL_HW : 0; + atslave->cfg |= of_property_read_bool(np, "atc_sod") ? ATC_SOD : 0; + atslave->cfg |= of_property_read_bool(np, "atc_lock_if") ? ATC_LOCK_IF : 0; + atslave->cfg |= of_property_read_bool(np, "atc_lock_b") ? ATC_LOCK_B : 0; + atslave->cfg |= of_property_read_bool(np, "atc_lock_if_l") ? ATC_LOCK_IF_L : 0; + atslave->cfg |= of_property_read_bool(np, "atc_lock_if_l_buffer") ? ATC_LOCK_IF_L_BUFFER : 0; + if (of_property_read_bool(np, "atc_fifocfg_halffifo")) + atslave->cfg = (atslave->cfg & ~ATC_FIFOCFG_MASK) | ATC_FIFOCFG_HALFFIFO; + if (of_property_read_bool(np, "atc_fifocfg_enoughspace")) + atslave->cfg = (atslave->cfg & ~ATC_FIFOCFG_MASK) | ATC_FIFOCFG_ENOUGHSPACE; + if (of_property_read_bool(np, "atc_fifocfg_largestburst")) + atslave->cfg = (atslave->cfg & ~ATC_FIFOCFG_MASK) | ATC_FIFOCFG_LARGESTBURST; + if (!of_property_read_u32(np, "atc_ahb_prot", &val)) + atslave->cfg |= ATC_AHB_PROT(val); + if (!of_property_read_u32(np, "atc_src_per", &val)) + atslave->cfg |= ATC_SRC_PER(val); + if (!of_property_read_u32(np, "atc_dst_per", &val)) + atslave->cfg |= ATC_DST_PER(val); + + /* we need to associate the wanted dma struct device to + * atslave->dma_dev. This is needed when searching for + * a free dma channel + */ + prop = of_find_property(np, "dma", &size); + if (!prop) { + pr_err("can't find the dma child node\n"); + goto error; + } + dma_list = prop->value; + size /= sizeof(*dma_list); + if (size != 1) { + pr_err("only one dma handle is supported\n"); + goto error; + } + + phandle = be32_to_cpup(dma_list); + n = of_find_node_by_phandle(phandle); + if (!n) { + pr_err("unable to find dma device: invalid phandle %s\n", + prop->name); + goto error; + } + + atslave->dma_dev = bus_find_device(bus, NULL, n, of_dev_node_match); + if (!atslave->dma_dev) { + pr_err("can't find struct device for DMA %s\n", prop->name); + goto error; + } + + pr_debug("DMA cfg register=0x%x DMA device path=%s\n", + atslave->cfg, prop->name); + err = 0; +error: + if (err) + kfree(atslave); + return atslave; +} +EXPORT_SYMBOL_GPL(of_create_at_dma_slave); + diff --git a/include/linux/of_atmel.h b/include/linux/of_atmel.h new file mode 100644 index 0000000..256f336 --- /dev/null +++ b/include/linux/of_atmel.h @@ -0,0 +1,29 @@ +#ifndef _LINUX_OF_ATMEL_H +#define _LINUX_OF_ATMEL_H +/* + * Copyright (C) 2012 Richard Genoud, Paratronic S.A. + * + * + * Atmel specifics OF helpers + * + * 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 + +#ifdef CONFIG_OF_ATMEL +extern struct at_dma_slave *of_create_at_dma_slave(struct device_node *np, + struct bus_type *bus); +#else +static struct at_dma_slave *of_create_at_dma_slave(struct device_node *np, + struct bus_type *bus) +{ + return NULL; +} +#endif /* CONFIG_OF_ATMEL */ + +#endif /* _LINUX_OF_ATMEL_H */