From patchwork Wed Apr 16 17:17:18 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Yanovich X-Patchwork-Id: 4003311 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 955F8BFF02 for ; Wed, 16 Apr 2014 17:24:10 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 913E92027D for ; Wed, 16 Apr 2014 17:24:09 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (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 7DC14200D7 for ; Wed, 16 Apr 2014 17:24:08 +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 1WaTVz-0001yc-J8; Wed, 16 Apr 2014 17:20:51 +0000 Received: from mail-la0-x22f.google.com ([2a00:1450:4010:c03::22f]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1WaTUv-0006vA-1z for linux-arm-kernel@lists.infradead.org; Wed, 16 Apr 2014 17:19:47 +0000 Received: by mail-la0-f47.google.com with SMTP id pn19so8418613lab.34 for ; Wed, 16 Apr 2014 10:19:22 -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:in-reply-to:references; bh=Tv9L6C7IBY2bWa+PjWPi8LZG/k1pUjoRIvecAmRAIHg=; b=OhIDW0B4fQjs+Ntnwo/b1/ynxo/uzEVUOTRJKJmosXVgnYY9PNs0J0U5AXv/3oSq80 hZi0JgsIxUQc5T6s9dY7nDFPKyVTTzrKhEsY8EAP78Cr/HQooDnFKB2du4bDwUm6e4HL S4QjqLu7VblCoHKdUJME958Vz86HRy4zM0bF8UAiM3X0YgxYmCEJdnm80z6PD22JuH9G Z+OBWpiVumQmvacG0PAxuLXbM24hYj+FJcoGKwnniqjivHiEGk66l9iwHFg7dRhEfT3w o9B7I5YMHqhDzqV71mt9E2eX5Oc8ruLCVskzsQtJJ6AFT9IiwskkACjS3CDpC/Ah9ScW EDBg== X-Received: by 10.152.42.164 with SMTP id p4mr6157784lal.5.1397668762262; Wed, 16 Apr 2014 10:19:22 -0700 (PDT) Received: from host5.omatika.ru (0893675324.static.corbina.ru. [95.31.1.192]) by mx.google.com with ESMTPSA id q4sm21186297lbh.20.2014.04.16.10.19.20 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 16 Apr 2014 10:19:21 -0700 (PDT) From: Sergei Ianovich To: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH v4 13/21] misc: support for LP-8x4x custom parallel bus Date: Wed, 16 Apr 2014 21:17:18 +0400 Message-Id: <1397668667-27328-7-git-send-email-ynvich@gmail.com> X-Mailer: git-send-email 1.9.2 In-Reply-To: <1397668667-27328-1-git-send-email-ynvich@gmail.com> References: <1397668411-27162-7-git-send-email-ynvich@gmail.com> <1397668667-27328-1-git-send-email-ynvich@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20140416_101945_569237_C80A2F05 X-CRM114-Status: GOOD ( 20.86 ) X-Spam-Score: -0.1 (/) Cc: Mark Rutland , "open list:OPEN FIRMWARE AND..." , Heikki Krogerus , Russell King , Arnd Bergmann , Pawel Moll , Ian Campbell , Greg Kroah-Hartman , Randy Dunlap , "open list:DOCUMENTATION" , Sergei Ianovich , Rob Herring , Kumar Gala , Grant Likely 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=-2.4 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, 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 This patch implements probing for the bus and reporting the number of available expansion slots. Signed-off-by: Sergei Ianovich --- v3..v4 * move DTS binding to a different patch (8/21) v2..v3 * fixed goto after bus_register * number change (11/16 -> 13/21) v0..v2 * use device tree * use devm helpers where possible .../devicetree/bindings/misc/lp8x4x-bus.txt | 16 ++ Documentation/misc-devices/lp8x4x_bus.txt | 30 ++++ arch/arm/configs/lp8x4x_defconfig | 1 + drivers/misc/Kconfig | 13 ++ drivers/misc/Makefile | 1 + drivers/misc/lp8x4x_bus.c | 167 +++++++++++++++++++++ 6 files changed, 228 insertions(+) create mode 100644 Documentation/devicetree/bindings/misc/lp8x4x-bus.txt create mode 100644 Documentation/misc-devices/lp8x4x_bus.txt create mode 100644 drivers/misc/lp8x4x_bus.c diff --git a/Documentation/devicetree/bindings/misc/lp8x4x-bus.txt b/Documentation/devicetree/bindings/misc/lp8x4x-bus.txt new file mode 100644 index 0000000..1c87a29 --- /dev/null +++ b/Documentation/devicetree/bindings/misc/lp8x4x-bus.txt @@ -0,0 +1,16 @@ +Custom parallel bus on ICP DAS LP-8x4x industrial computers + +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. + +Example: + + backplane { + compatible = "icpdas,backplane-lp8x4x"; + reg = <0x17009046 0x2>; + }; diff --git a/Documentation/misc-devices/lp8x4x_bus.txt b/Documentation/misc-devices/lp8x4x_bus.txt new file mode 100644 index 0000000..f5392b3 --- /dev/null +++ b/Documentation/misc-devices/lp8x4x_bus.txt @@ -0,0 +1,30 @@ +Kernel driver lpx8x4x_bus +====================== + +Supported hardare: +Custom parallel bus on ICP DAS LP-8x4x industrial computers + +Data sheet: +Not freely available + +Author: +Sergei Ianovich + +Description +----------- + +http://www.icpdas.com/root/product/solutions/pac/linpac/lp-8x4x_hardware.html + +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. + +SYSFS +----- + +/sys/bus/icpdas/devices/backplane: + +slot_count + RO - shows total number of expansion slots on the device diff --git a/arch/arm/configs/lp8x4x_defconfig b/arch/arm/configs/lp8x4x_defconfig index 9116ce1..c34eb2a 100644 --- a/arch/arm/configs/lp8x4x_defconfig +++ b/arch/arm/configs/lp8x4x_defconfig @@ -62,6 +62,7 @@ CONFIG_PROC_DEVICETREE=y CONFIG_BLK_DEV_LOOP=y CONFIG_BLK_DEV_LOOP_MIN_COUNT=2 CONFIG_EEPROM_AT24=m +CONFIG_LP8X4X_BUS=m CONFIG_SCSI=y # CONFIG_SCSI_PROC_FS is not set CONFIG_BLK_DEV_SD=y diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig index 1cb7408..08ffe63 100644 --- a/drivers/misc/Kconfig +++ b/drivers/misc/Kconfig @@ -515,6 +515,19 @@ config SRAM the genalloc API. It is supposed to be used for small on-chip SRAM areas found on many SoCs. +config LP8X4X_BUS + tristate "ICP DAS LP-8x4x industrial IO bus" + depends on OF && ARCH_PXA + select SYSFS + ---help--- + This is a driver for ICP DAS LP-8x4x programmable automation + controller. It exposes a custom parallel bus. The bus services + data acquisition and control modules. + + Say N, unless you plan to run this kernel on a LP-8x4x system. + + If you say M here, the module will be called lp8x4x_bus. + source "drivers/misc/c2port/Kconfig" source "drivers/misc/eeprom/Kconfig" source "drivers/misc/cb710/Kconfig" diff --git a/drivers/misc/Makefile b/drivers/misc/Makefile index 7eb4b69..2bfe25d 100644 --- a/drivers/misc/Makefile +++ b/drivers/misc/Makefile @@ -55,3 +55,4 @@ obj-$(CONFIG_SRAM) += sram.o obj-y += mic/ obj-$(CONFIG_GENWQE) += genwqe/ obj-$(CONFIG_ECHO) += echo/ +obj-$(CONFIG_LP8X4X_BUS) += lp8x4x_bus.o diff --git a/drivers/misc/lp8x4x_bus.c b/drivers/misc/lp8x4x_bus.c new file mode 100644 index 0000000..7aa55cf --- /dev/null +++ b/drivers/misc/lp8x4x_bus.c @@ -0,0 +1,167 @@ +/* + * linux/misc/lp8x4x_bus.c + * + * Support for ICP DAS LP-8x4x programmable automation controller bus + * Copyright (C) 2013 Sergei Ianovich + * + * 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 or any later version. + */ +#include +#include +#include +#include +#include +#include +#include +#include + +#define MODULE_NAME "lp8x4x-bus" +MODULE_LICENSE("GPL"); +MODULE_AUTHOR("Sergei Ianovich "); +MODULE_DESCRIPTION("ICP DAS LP-8x4x parallel bus driver"); + +struct lp8x4x_master { + unsigned int slot_count; + void *count_addr; + struct device dev; +}; + +static int lp8x4x_match(struct device *dev, struct device_driver *drv) +{ + return 1; +} + +static struct bus_type lp8x4x_bus_type = { + .name = "icpdas", + .match = lp8x4x_match, +}; + +static void lp8x4x_master_release(struct device *dev) +{ + struct lp8x4x_master *m = container_of(dev, struct lp8x4x_master, dev); + WARN_ON(!dev); + + kfree(m); +} + +static ssize_t slot_count_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->slot_count); +} + +static DEVICE_ATTR_RO(slot_count); + +static struct attribute *master_dev_attrs[] = { + &dev_attr_slot_count.attr, + NULL, +}; +ATTRIBUTE_GROUPS(master_dev); + + +static void devm_lp8x4x_bus_release(struct device *dev, void *res) +{ + struct lp8x4x_master *m = *(struct lp8x4x_master **)res; + + dev_dbg(dev, "releasing devices\n"); + device_unregister(&m->dev); + bus_unregister(&lp8x4x_bus_type); +} + +static int __init lp8x4x_bus_probe(struct platform_device *pdev) +{ + struct lp8x4x_master *m, **p; + struct resource *res; + int err = 0; + + m = kzalloc(sizeof(*m), GFP_KERNEL); + if (!m) + return -ENOMEM; + + p = devres_alloc(devm_lp8x4x_bus_release, sizeof(*p), GFP_KERNEL); + if (!p) { + err = -ENOMEM; + goto err1; + } + *p = m; + + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); + if (!res) { + dev_err(&pdev->dev, "could not get slot count address\n"); + err = -ENODEV; + goto err2; + } + + m->count_addr = devm_ioremap_resource(&pdev->dev, res); + if (IS_ERR(m->count_addr)) { + dev_err(&pdev->dev, "Failed to ioremap slot count address\n"); + err = PTR_ERR(m->count_addr); + goto err2; + } + + m->slot_count = ioread8(m->count_addr); + switch (m->slot_count) { + case 1: + case 4: + break; + case 7: + m->slot_count = 8; + break; + default: + dev_err(&pdev->dev, "unexpected slot number(%u)", + m->slot_count); + err = -ENODEV; + goto err2; + }; + + dev_info(&pdev->dev, "found bus with up to %u slots\n", m->slot_count); + + err = bus_register(&lp8x4x_bus_type); + if (err < 0) { + dev_err(&pdev->dev, "failed to register bus type\n"); + goto err2; + } + + m->dev.bus = &lp8x4x_bus_type; + dev_set_name(&m->dev, "backplane"); + m->dev.parent = &pdev->dev; + m->dev.release = lp8x4x_master_release; + m->dev.groups = master_dev_groups; + + err = device_register(&m->dev); + if (err < 0) { + dev_err(&pdev->dev, "failed to register backplane device\n"); + goto err3; + } + + devres_add(&pdev->dev, p); + return 0; + +err3: + bus_unregister(&lp8x4x_bus_type); +err2: + devres_free(p); +err1: + kfree(m); + return err; +} + +static const struct of_device_id lp8x4x_bus_dt_ids[] = { + { .compatible = "icpdas,backplane-lp8x4x" }, + { } +}; +MODULE_DEVICE_TABLE(of, lp8x4x_bus_dt_ids); + +static struct platform_driver lp8x4x_bus_driver = { + .driver = { + .name = MODULE_NAME, + .owner = THIS_MODULE, + .of_match_table = lp8x4x_bus_dt_ids, + }, +}; + +module_platform_driver_probe(lp8x4x_bus_driver, lp8x4x_bus_probe);