From patchwork Wed Apr 16 17:17:19 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Yanovich X-Patchwork-Id: 4003321 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 650FABFF02 for ; Wed, 16 Apr 2014 17:24:34 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 7A10B2027D for ; Wed, 16 Apr 2014 17:24:33 +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 8E74E200D7 for ; Wed, 16 Apr 2014 17:24:32 +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 1WaTWA-0002Oi-Qd; Wed, 16 Apr 2014 17:21:02 +0000 Received: from mail-lb0-x22b.google.com ([2a00:1450:4010:c04::22b]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1WaTV0-00075Z-9o for linux-arm-kernel@lists.infradead.org; Wed, 16 Apr 2014 17:19:52 +0000 Received: by mail-lb0-f171.google.com with SMTP id w7so8507826lbi.30 for ; Wed, 16 Apr 2014 10:19:27 -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=bje0rnK/7iL+GA3N33NMVDSZRvTFJdqywl8qDI6qBIU=; b=Rsn5fBUaAaY1TUAO3lIAiVy1jfMg3Ru57mu5+cbjQxRkFWeR9ix+Unaj02rsbRPpfR +7FDyMi4YTbDuAVtGEFKYOqAceEEJLLbzRtsSUYwEUPZaUI67UHhCrhI/x9N3Of4dgd5 9HJVGXcoGXWhkgNowTiVyGNDB5OQUVZeJbyD8iQA2A6if3vYSIkMUJ46lhz7yr+qiumH 0SaKtQq9Rmq6MgerSRZGT0zm3vMy8QnHpnLIfeKZ7NZ+9o3rj+wxYN+WOteInL98P23R zg9iW3Aqg/YojyqfQ3H3P/WEjGjn02RvH+VgjqS+9BC67oovdJowFwBCMgNZQnIqcIz6 s0zQ== X-Received: by 10.152.243.35 with SMTP id wv3mr2349570lac.47.1397668767434; Wed, 16 Apr 2014 10:19:27 -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.25 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 16 Apr 2014 10:19:26 -0700 (PDT) From: Sergei Ianovich To: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH v4 14/21] misc: support for LP-8x4x rotary switch Date: Wed, 16 Apr 2014 21:17:19 +0400 Message-Id: <1397668667-27328-8-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_101950_752217_F179CA06 X-CRM114-Status: GOOD ( 16.40 ) X-Spam-Score: -0.1 (/) 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 Signed-off-by: Sergei Ianovich --- v3..v4 * move DTS binding to a different patch (8/21) v2..v3 * new patch .../devicetree/bindings/misc/lp8x4x-bus.txt | 8 ++-- Documentation/misc-devices/lp8x4x_bus.txt | 3 ++ drivers/misc/lp8x4x_bus.c | 43 ++++++++++++++++++---- 3 files changed, 43 insertions(+), 11 deletions(-) diff --git a/Documentation/devicetree/bindings/misc/lp8x4x-bus.txt b/Documentation/devicetree/bindings/misc/lp8x4x-bus.txt index 1c87a29..8a55020 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 rotary switch + * the slot count register Example: backplane { compatible = "icpdas,backplane-lp8x4x"; - reg = <0x17009046 0x2>; + reg = <0x0 0x2 + 0x9046 0x2>; }; diff --git a/Documentation/misc-devices/lp8x4x_bus.txt b/Documentation/misc-devices/lp8x4x_bus.txt index f5392b3..bea435b 100644 --- a/Documentation/misc-devices/lp8x4x_bus.txt +++ b/Documentation/misc-devices/lp8x4x_bus.txt @@ -26,5 +26,8 @@ SYSFS /sys/bus/icpdas/devices/backplane: +rotary + RO - shows position of LP-8x4x rotary switch (0-9) + slot_count RO - shows total number of expansion slots on the device diff --git a/drivers/misc/lp8x4x_bus.c b/drivers/misc/lp8x4x_bus.c index 7aa55cf..18ca8f8 100644 --- a/drivers/misc/lp8x4x_bus.c +++ b/drivers/misc/lp8x4x_bus.c @@ -25,6 +25,7 @@ MODULE_DESCRIPTION("ICP DAS LP-8x4x parallel bus driver"); struct lp8x4x_master { unsigned int slot_count; void *count_addr; + void *rotary_addr; struct device dev; }; @@ -56,8 +57,19 @@ static ssize_t slot_count_show(struct device *dev, static DEVICE_ATTR_RO(slot_count); +static ssize_t rotary_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", (ioread8(m->rotary_addr) ^ 0xf) & 0xf); +} + +static DEVICE_ATTR_RO(rotary); + static struct attribute *master_dev_attrs[] = { &dev_attr_slot_count.attr, + &dev_attr_rotary.attr, NULL, }; ATTRIBUTE_GROUPS(master_dev); @@ -76,6 +88,7 @@ static int __init lp8x4x_bus_probe(struct platform_device *pdev) { struct lp8x4x_master *m, **p; struct resource *res; + int r = 0; int err = 0; m = kzalloc(sizeof(*m), GFP_KERNEL); @@ -89,18 +102,32 @@ static int __init lp8x4x_bus_probe(struct platform_device *pdev) } *p = m; - res = platform_get_resource(pdev, IORESOURCE_MEM, 0); + res = platform_get_resource(pdev, IORESOURCE_MEM, r++); + if (!res) { + dev_err(&pdev->dev, "Failed to get rotary address\n"); + err = -ENODEV; + goto err_free; + } + + m->rotary_addr = devm_ioremap_resource(&pdev->dev, res); + if (IS_ERR(m->rotary_addr)) { + dev_err(&pdev->dev, "Failed to ioremap rotary address\n"); + err = PTR_ERR(m->rotary_addr); + goto err_free; + } + + res = platform_get_resource(pdev, IORESOURCE_MEM, r++); if (!res) { dev_err(&pdev->dev, "could not get slot count address\n"); err = -ENODEV; - goto err2; + goto err_free; } 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; + goto err_free; } m->slot_count = ioread8(m->count_addr); @@ -115,7 +142,7 @@ static int __init lp8x4x_bus_probe(struct platform_device *pdev) dev_err(&pdev->dev, "unexpected slot number(%u)", m->slot_count); err = -ENODEV; - goto err2; + goto err_free; }; dev_info(&pdev->dev, "found bus with up to %u slots\n", m->slot_count); @@ -123,7 +150,7 @@ static int __init lp8x4x_bus_probe(struct platform_device *pdev) err = bus_register(&lp8x4x_bus_type); if (err < 0) { dev_err(&pdev->dev, "failed to register bus type\n"); - goto err2; + goto err_free; } m->dev.bus = &lp8x4x_bus_type; @@ -135,15 +162,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);