From patchwork Fri Dec 13 02:27:21 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Yanovich X-Patchwork-Id: 3337781 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.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id D62D39F44E for ; Fri, 13 Dec 2013 04:55:39 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id C9925207EF for ; Fri, 13 Dec 2013 04:55:38 +0000 (UTC) Received: from casper.infradead.org (casper.infradead.org [85.118.1.10]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id A4172207E4 for ; Fri, 13 Dec 2013 04:55:37 +0000 (UTC) Received: from merlin.infradead.org ([2001:4978:20e::2]) by casper.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1VrIZL-0004aB-OB; Fri, 13 Dec 2013 02:33:37 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1VrIYr-0000fI-C7; Fri, 13 Dec 2013 02:33:05 +0000 Received: from mail-la0-x230.google.com ([2a00:1450:4010:c03::230]) by merlin.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1VrIWX-0000L4-0e for linux-arm-kernel@lists.infradead.org; Fri, 13 Dec 2013 02:30:42 +0000 Received: by mail-la0-f48.google.com with SMTP id n7so926832lam.21 for ; Thu, 12 Dec 2013 18:30:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=l3z5259gXTutVCM855aq/aJ9a6kFMFy7IRs8/zpzXLE=; b=N2Z2iZTj0WjmzSWXW1gPKE6gImgEfY4D5sP0vkQ9nyCJMgj3cZVrdFxhU/sFZLPB7A hy/ZAJ9MhMQK8GrNb2izxf3EiH8IkzSLglOO7bFiMhYajuUoL30MbzZPt4axnre4ZJK3 jB1mB+EDzYoM6T2maEZum/6GBIelO0bErSFyMRZSYdR3+aIWcKaM1NARLQbv6MdoCJML sKt8S5c3xIiQpPTclJSgj7JBf2rMnbGnzQDiZyHeHwaipmcmWlpQmmf64KXMasuYuz4u z2I6Kh8WR8NNlsSsGVIl+Nq6kxRgauRQxNokKCUpG6Bwrwfh6vlOYImhcg4WejVWb3iv Bmow== X-Received: by 10.152.203.168 with SMTP id kr8mr61690lac.44.1386901817860; Thu, 12 Dec 2013 18:30:17 -0800 (PST) Received: from host5.omatika.ru (0893675324.static.corbina.ru. [95.31.1.192]) by mx.google.com with ESMTPSA id e10sm809634laa.6.2013.12.12.18.30.16 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 12 Dec 2013 18:30:17 -0800 (PST) From: Sergei Ianovich To: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH v2 12/16] misc: support for serial slots in LP-8x4x Date: Fri, 13 Dec 2013 06:27:21 +0400 Message-Id: <1386901645-28895-13-git-send-email-ynvich@gmail.com> X-Mailer: git-send-email 1.8.4.3 In-Reply-To: <1386901645-28895-1-git-send-email-ynvich@gmail.com> References: <1386543229-1542-1-git-send-email-ynvich@gmail.com> <1386901645-28895-1-git-send-email-ynvich@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20131212_213041_393695_0D0761B9 X-CRM114-Status: GOOD ( 19.75 ) X-Spam-Score: -1.9 (-) Cc: Mark Rutland , "open list:OPEN FIRMWARE AND..." , Arnd Bergmann , Pawel Moll , Ian Campbell , Greg Kroah-Hartman , Stephen Warren , "open list:DOCUMENTATION" , Rob Herring , Sergei Ianovich , Rob Landley X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , 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=-3.9 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_MED, RCVD_IN_SBL, RP_MATCHES_RCVD, T_DKIM_INVALID,UNPARSEABLE_RELAY autolearn=no 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 Serial modules (I-870xxW series) implement DCON protocol which allows one-master-many-slaves configuration over RS-485. When these modules are installed into the device, they could be accessed using the 2nd PXA built-in UART port (/dev/ttySA1). However, it seems that addresses are not processed by the modules. So the parallel bus needs to select which slot is connected. Signed-off-by: Sergei Ianovich --- v0..v2 * use device tree * use devm helpers where possible .../devicetree/bindings/misc/lp8x4x-bus.txt | 8 ++- Documentation/misc-devices/lp8x4x_bus.txt | 15 ++++- drivers/misc/lp8x4x_bus.c | 75 ++++++++++++++++++++-- 3 files changed, 87 insertions(+), 11 deletions(-) diff --git a/Documentation/devicetree/bindings/misc/lp8x4x-bus.txt b/Documentation/devicetree/bindings/misc/lp8x4x-bus.txt index 1c87a29..61ac96e 100644 --- a/Documentation/devicetree/bindings/misc/lp8x4x-bus.txt +++ b/Documentation/devicetree/bindings/misc/lp8x4x-bus.txt @@ -5,12 +5,14 @@ See Documentation/misc-devices/lp8x4x_bus.txt for details. Required properties: - compatible : should be "icpdas,backplane-lp8x4x" -- reg: physical base address of the slot count register and the length - of the memory mapped region. +- reg: physical base addresses and region lengths of + * the slot count register + * the serial slot select register Example: backplane { compatible = "icpdas,backplane-lp8x4x"; - reg = <0x17009046 0x2>; + reg = <0x17009046 0x2 + 0x17009004 0x2>; }; diff --git a/Documentation/misc-devices/lp8x4x_bus.txt b/Documentation/misc-devices/lp8x4x_bus.txt index f5392b3..d9a069d 100644 --- a/Documentation/misc-devices/lp8x4x_bus.txt +++ b/Documentation/misc-devices/lp8x4x_bus.txt @@ -19,7 +19,14 @@ LP-8x4x is an ARM-based industrial computer with a custom parallel bus to connect expansion modules with digital input/output, analog input/output, serial, CAN and other types of ports. -The bus is implemented by a FPGA. +The bus is implemented by a FPGA. There are two major groups of expansion +modules: serial and parallel. + +Serial modules (I-870xxW series) implement DCON protocol which allows one- +master-many-slaves configuration over RS-485. When these modules are installed +into the device, they could be accessed using the 2nd PXA built-in UART port +(/dev/ttyS1). However, it seems that addresses are not processed by +the modules. So the parallel bus needs to select which slot is connected. SYSFS ----- @@ -28,3 +35,9 @@ SYSFS slot_count RO - shows total number of expansion slots on the device + +active_slot + RW - connects the select slot for serial communications. If there + is a parallel module in the selected slot, it simply ignores + incoming packets. So it is safe to activate any available + slot. diff --git a/drivers/misc/lp8x4x_bus.c b/drivers/misc/lp8x4x_bus.c index 7119738..cffe121 100644 --- a/drivers/misc/lp8x4x_bus.c +++ b/drivers/misc/lp8x4x_bus.c @@ -24,6 +24,8 @@ MODULE_DESCRIPTION("ICP DAS LP-8x4x parallel bus driver"); struct lp8x4x_master { unsigned int slot_count; void *count_addr; + unsigned int active_slot; + void *switch_addr; struct device dev; }; @@ -55,8 +57,45 @@ static ssize_t slot_count_show(struct device *dev, static DEVICE_ATTR_RO(slot_count); +static ssize_t active_slot_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct lp8x4x_master *m = container_of(dev, struct lp8x4x_master, dev); + + return sprintf(buf, "%u\n", m->active_slot); +} + +static ssize_t active_slot_store(struct device *dev, + struct device_attribute *attr, const char *buf, size_t count) +{ + struct lp8x4x_master *m = container_of(dev, struct lp8x4x_master, dev); + unsigned int active_slot = 0; + int err; + + if (!buf) + return count; + if (0 == count) + return count; + + err = kstrtouint(buf, 10, &active_slot); + if (err != 0 || !active_slot || active_slot > m->slot_count) { + dev_err(dev, "slot number is out of range 1..%u\n", + m->slot_count); + return count; + } + + m->active_slot = active_slot; + + iowrite8((1 << (m->active_slot - 1)) ^ 0xff, m->switch_addr); + + return count; +} + +static DEVICE_ATTR_RW(active_slot); + static struct attribute *master_dev_attrs[] = { &dev_attr_slot_count.attr, + &dev_attr_active_slot.attr, NULL, }; ATTRIBUTE_GROUPS(master_dev); @@ -69,6 +108,9 @@ static void devm_lp8x4x_bus_release(struct device *dev, void *res) dev_dbg(dev, "releasing devices\n"); device_unregister(&m->dev); bus_unregister(&lp8x4x_bus_type); + + /* Disable serial communications */ + iowrite8(0xff, m->switch_addr); } static int __init lp8x4x_bus_probe(struct platform_device *pdev) @@ -90,8 +132,9 @@ static int __init lp8x4x_bus_probe(struct platform_device *pdev) res = platform_get_resource(pdev, IORESOURCE_MEM, 0); if (!res) { + dev_err(&pdev->dev, "Failed to get slot number address\n"); err = -ENODEV; - goto err2; + goto err_free; } m->count_addr = devm_ioremap_resource(&pdev->dev, res); @@ -99,7 +142,22 @@ static int __init lp8x4x_bus_probe(struct platform_device *pdev) dev_err(&pdev->dev, "Failed to ioremap %p\n", m->count_addr); err = -EFAULT; - goto err2; + goto err_free; + } + + res = platform_get_resource(pdev, IORESOURCE_MEM, 1); + if (!res) { + dev_err(&pdev->dev, "Failed to get slot switch address\n"); + err = -ENODEV; + goto err_free; + } + + m->switch_addr = devm_ioremap_resource(&pdev->dev, res); + if (!m->switch_addr) { + dev_err(&pdev->dev, "Failed to ioremap %p\n", + m->switch_addr); + err = -EFAULT; + goto err_free; } m->slot_count = ioread8(m->count_addr); @@ -113,15 +171,18 @@ static int __init lp8x4x_bus_probe(struct platform_device *pdev) default: dev_err(&pdev->dev, "unexpected slot number(%u)", m->slot_count); - goto err2; + goto err_free; }; dev_info(&pdev->dev, "found bus with up to %u slots\n", m->slot_count); + /* Disable serial communications until explicitly enabled */ + iowrite8(0xff, m->switch_addr); + err = bus_register(&lp8x4x_bus_type); if (err < 0) { dev_err(&pdev->dev, "failed to register bus type\n"); - goto err3; + goto err_free; } m->dev.bus = &lp8x4x_bus_type; @@ -133,15 +194,15 @@ static int __init lp8x4x_bus_probe(struct platform_device *pdev) err = device_register(&m->dev); if (err < 0) { dev_err(&pdev->dev, "failed to register backplane device\n"); - goto err3; + goto err_bus; } devres_add(&pdev->dev, p); return 0; -err3: +err_bus: bus_unregister(&lp8x4x_bus_type); -err2: +err_free: devres_free(p); err1: kfree(m);