From patchwork Wed Apr 16 17:17:23 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Yanovich X-Patchwork-Id: 4003381 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 D75EE9F2CC for ; Wed, 16 Apr 2014 17:27:38 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id CD7AF20375 for ; Wed, 16 Apr 2014 17:27:37 +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 C37B82027D for ; Wed, 16 Apr 2014 17:27:36 +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 1WaTXM-00052J-5R; Wed, 16 Apr 2014 17:22:16 +0000 Received: from casper.infradead.org ([2001:770:15f::2]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1WaTVQ-0000uz-P7 for linux-arm-kernel@bombadil.infradead.org; Wed, 16 Apr 2014 17:20:16 +0000 Received: from mail-la0-x233.google.com ([2a00:1450:4010:c03::233]) by casper.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1WaTVN-0005po-TP for linux-arm-kernel@lists.infradead.org; Wed, 16 Apr 2014 17:20:14 +0000 Received: by mail-la0-f51.google.com with SMTP id pv20so8528614lab.10 for ; Wed, 16 Apr 2014 10:19:47 -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=z9kF+g1XV9DiN5ujdyn3Wg/Ysl+CP+IvSP1gN1cazjM=; b=jsONmLdx2MRLXGI1eyOKOxYjkQed9o+2ZpHw5y2Y3Tg5hipZsvKSKnJjcVkJzmCLAR UGpVEztxZE2mu4YwurlgGIXppEqXTrK1JltcSk9LSkiQCMm1Q6ieBWiyqYEznD+LroES gBFi5Z50QWglCv5x9uSwFMoak0LM4OuqSwnNO/EQRe0+/BHpMLkYe41FEjZwkQqLx13p I+LtxPdThVYGmr3HgkzlivBLwtZKJMVsNzFLPmS8nK+N04qhCBovHggfHPsmHtgr2MG4 VeCPNMkakwbYlMq6yJqrNjPRkEAZSxuB9OLO6Jfxlf8ziz/lLguEAXBytV1xxUmYiJWl PVYA== X-Received: by 10.152.7.8 with SMTP id f8mr2582942laa.39.1397668787248; Wed, 16 Apr 2014 10:19:47 -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.45 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 16 Apr 2014 10:19:46 -0700 (PDT) From: Sergei Ianovich To: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH v4 18/21] misc: support for parallel slots in LP-8x4x Date: Wed, 16 Apr 2014 21:17:23 +0400 Message-Id: <1397668667-27328-12-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_182014_108641_2C4FD59B X-CRM114-Status: GOOD ( 23.47 ) X-Spam-Score: -2.0 (--) Cc: Mark Rutland , "open list:OPEN FIRMWARE AND..." , Arnd Bergmann , Pawel Moll , Ian Campbell , Greg Kroah-Hartman , Randy Dunlap , "open list:DOCUMENTATION" , Sergei Ianovich , Rob Herring , Kumar Gala 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 enumerates parallel modules in expansion slots and exposes model numbers via sysfs. Signed-off-by: Sergei Ianovich --- v3..v4 * move DTS binding to a different patch (8/21) v2..v3 * no changes (except number 13/16 -> 18/21) v0..v2 * use device tree * use devm helpers where possible .../devicetree/bindings/misc/lp8x4x-bus.txt | 9 ++ Documentation/misc-devices/lp8x4x_bus.txt | 8 ++ drivers/misc/lp8x4x_bus.c | 119 +++++++++++++++++++++ 3 files changed, 136 insertions(+) diff --git a/Documentation/devicetree/bindings/misc/lp8x4x-bus.txt b/Documentation/devicetree/bindings/misc/lp8x4x-bus.txt index 24a8c62..75ac3b2 100644 --- a/Documentation/devicetree/bindings/misc/lp8x4x-bus.txt +++ b/Documentation/devicetree/bindings/misc/lp8x4x-bus.txt @@ -7,6 +7,7 @@ Required properties: - reg: physical base addresses and region lengths of * the rotary switch + * 8 plugable industrial IO slots * the 8bit DIP switch * the serial slot select register * the slot count register @@ -18,6 +19,14 @@ Example: backplane { compatible = "icpdas,backplane-lp8x4x"; reg = <0x0 0x2 + 0x1000 0x10 + 0x2000 0x10 + 0x3000 0x10 + 0x4000 0x10 + 0x5000 0x10 + 0x6000 0x10 + 0x7000 0x10 + 0x8000 0x10 0x9002 0x2 0x9004 0x2 0x9046 0x2>; diff --git a/Documentation/misc-devices/lp8x4x_bus.txt b/Documentation/misc-devices/lp8x4x_bus.txt index 7b86797..09380fd 100644 --- a/Documentation/misc-devices/lp8x4x_bus.txt +++ b/Documentation/misc-devices/lp8x4x_bus.txt @@ -28,6 +28,9 @@ 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. +Parallel modules allow much faster communication. There are accessed using +IO memory through the FPGA. Their ports are exposed via sysfs. + SYSFS ----- @@ -50,3 +53,8 @@ rotary slot_count RO - shows total number of expansion slots on the device + +/sys/bus/icpdas/devices/slot%02i: + +model + RO - shows expansion module model number diff --git a/drivers/misc/lp8x4x_bus.c b/drivers/misc/lp8x4x_bus.c index e805640..59dc767 100644 --- a/drivers/misc/lp8x4x_bus.c +++ b/drivers/misc/lp8x4x_bus.c @@ -23,6 +23,13 @@ MODULE_LICENSE("GPL"); MODULE_AUTHOR("Sergei Ianovich "); MODULE_DESCRIPTION("ICP DAS LP-8x4x parallel bus driver"); +struct lp8x4x_slot { + void *data_addr; + unsigned int model; + struct device dev; +}; + +#define LP8X4X_MAX_SLOT_COUNT 8 struct lp8x4x_master { unsigned int slot_count; void *count_addr; @@ -31,9 +38,45 @@ struct lp8x4x_master { struct gpio_desc *eeprom_nWE; unsigned int active_slot; void *switch_addr; + struct lp8x4x_slot slot[LP8X4X_MAX_SLOT_COUNT]; struct device dev; }; +static unsigned char lp8x4x_model[256] = { + 0, 0, 0, 0x11, 0, 0x18, 0x13, 0x11, + 0x0e, 0x11, 0, 0, 0, 0x5a, 0x5b, 0x5c, + 0x3c, 0x44, 0x34, 0x3a, 0x39, 0x36, 0x37, 0x33, + 0x35, 0x40, 0x41, 0x42, 0x38, 0x3f, 0x32, 0x45, + 0xac, 0x70, 0x8e, 0x8e, 0x1e, 0x72, 0x90, 0x29, + 0x4a, 0x22, 0xd3, 0xd2, 0x28, 0x25, 0x2a, 0x29, + 0x48, 0x49, 0x5d, 0x1f, 0x20, 0x23, 0x24, 0x4d, + 0x3d, 0x3e, 0, 0, 0, 0, 0, 0, + 0, 0x78, 0x72, 0x2b, 0x5e, 0x5e, 0x36, 0xae, + 0x30, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0x5c, 0x5e, 0, 0x5e, 0, 0, + 0, 0x3b, 0, 0, 0, 0, 0, 0, + 0, 0x50, 0x2e, 0, 0x58, 0, 0, 0x43, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0x54, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0 +}; + static int lp8x4x_match(struct device *dev, struct device_driver *drv) { return 1; @@ -44,6 +87,26 @@ static struct bus_type lp8x4x_bus_type = { .match = lp8x4x_match, }; +static void lp8x4x_slot_release(struct device *dev) +{ +} + +static ssize_t model_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct lp8x4x_slot *s = container_of(dev, struct lp8x4x_slot, dev); + + return sprintf(buf, "%u\n", s->model + 8000); +} + +static DEVICE_ATTR_RO(model); + +static struct attribute *slot_dev_attrs[] = { + &dev_attr_model.attr, + NULL, +}; +ATTRIBUTE_GROUPS(slot_dev); + static void lp8x4x_master_release(struct device *dev) { struct lp8x4x_master *m = container_of(dev, struct lp8x4x_master, dev); @@ -173,18 +236,50 @@ ATTRIBUTE_GROUPS(master_dev); static void devm_lp8x4x_bus_release(struct device *dev, void *res) { struct lp8x4x_master *m = *(struct lp8x4x_master **)res; + struct lp8x4x_slot *s; + int i; dev_dbg(dev, "releasing devices\n"); + for (i = 0; i < LP8X4X_MAX_SLOT_COUNT; i++) { + s = &m->slot[i]; + if (s->model) + device_unregister(&s->dev); + } device_unregister(&m->dev); bus_unregister(&lp8x4x_bus_type); } +static void __init lp8x4x_bus_probe_slot(struct lp8x4x_master *m, int i, + unsigned char model) +{ + struct lp8x4x_slot *s = &m->slot[i]; + int err; + + dev_info(&m->dev, "found %u in slot %i\n", 8000 + model, i + 1); + + s->dev.bus = &lp8x4x_bus_type; + dev_set_name(&s->dev, "slot%02i", i + 1); + s->dev.parent = &m->dev; + s->dev.release = lp8x4x_slot_release; + s->dev.groups = slot_dev_groups; + s->model = model; + + err = device_register(&s->dev); + if (err < 0) { + dev_err(&s->dev, "failed to register device\n"); + s->model = 0; + return; + } +} + static int __init lp8x4x_bus_probe(struct platform_device *pdev) { struct lp8x4x_master *m, **p; struct resource *res; int r = 0; + int i; int err = 0; + unsigned int model; m = kzalloc(sizeof(*m), GFP_KERNEL); if (!m) @@ -211,6 +306,23 @@ static int __init lp8x4x_bus_probe(struct platform_device *pdev) goto err_free; } + for (i = 0; i < LP8X4X_MAX_SLOT_COUNT; i++) { + res = platform_get_resource(pdev, IORESOURCE_MEM, r++); + if (!res) { + dev_err(&pdev->dev, "Failed to get slot %i address\n", + i); + err = -ENODEV; + goto err_free; + } + + m->slot[i].data_addr = devm_ioremap_resource(&pdev->dev, res); + if (IS_ERR(m->slot[i].data_addr)) { + dev_err(&pdev->dev, "Failed to ioremap slot %i\n", i); + err = PTR_ERR(m->slot[i].data_addr); + goto err_free; + } + } + res = platform_get_resource(pdev, IORESOURCE_MEM, r++); if (!res) { dev_err(&pdev->dev, "Failed to get DIP switch address\n"); @@ -305,6 +417,13 @@ static int __init lp8x4x_bus_probe(struct platform_device *pdev) } devres_add(&pdev->dev, p); + for (i = 0; i < LP8X4X_MAX_SLOT_COUNT; i++) { + model = lp8x4x_model[ioread8(m->slot[i].data_addr)]; + if (!model) + continue; + + lp8x4x_bus_probe_slot(m, i, model); + } return 0; err_bus: