From patchwork Sun Dec 1 06:26:22 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Yanovich X-Patchwork-Id: 3261691 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 D59529F39D for ; Sun, 1 Dec 2013 07:06:51 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id E0A0D2041B for ; Sun, 1 Dec 2013 07:06:50 +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 7B3C0203F3 for ; Sun, 1 Dec 2013 07:06:49 +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 1Vn0Xt-0007EN-Em; Sun, 01 Dec 2013 06:30:24 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1Vn0X8-0002Wm-H3; Sun, 01 Dec 2013 06:29:34 +0000 Received: from mail-lb0-x231.google.com ([2a00:1450:4010:c04::231]) by merlin.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1Vn0Ws-0002RI-Ao for linux-arm-kernel@lists.infradead.org; Sun, 01 Dec 2013 06:29:20 +0000 Received: by mail-lb0-f177.google.com with SMTP id w7so7646547lbi.8 for ; Sat, 30 Nov 2013 22:28:56 -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=gLoidMMglecy4aPRbYc9NreXYko+cJUX3OczC3dCg60=; b=SONo2FNPcmc0J8Q4CSueSrUg6poykZVu2/c3RAdr3II4KjY3ah9sS9qyiSFSmmOprz B9K6ICTdV5yBPaLNVnXrIvdy+VdVhUdYQZI6G6t1LJNizX0rITe4X30tJnCbVhWnEhC5 JppSghL2gPQo8NJYqiwZzvBy9Hxv33RuVbjOTTbLz48WzcLHUuz8ZefhYivIcow6wqlF B97ItHkVqHz5vqxSy3lVJY2z+8A8UxkiJ+8TvaJc7cTjC8RxNX7ocXL0RgIgpr13oHWj IEI0kHm7gTSIs8q/ydLKABVPmr15MjVjuTfgmZzmGG7YsuLgsoxKqd9Syab0IG+QR0JF iREw== X-Received: by 10.152.143.101 with SMTP id sd5mr66820lab.26.1385879336755; Sat, 30 Nov 2013 22:28:56 -0800 (PST) Received: from host5.omatika.ru (0893675324.static.corbina.ru. [95.31.1.192]) by mx.google.com with ESMTPSA id e10sm82577921laa.6.2013.11.30.22.28.55 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 30 Nov 2013 22:28:56 -0800 (PST) From: Sergei Ianovich To: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH 09/11] misc: support for I-8041 in LP-8x4x Date: Sun, 1 Dec 2013 10:26:22 +0400 Message-Id: <1385879185-22455-10-git-send-email-ynvich@gmail.com> X-Mailer: git-send-email 1.8.4.3 In-Reply-To: <1385879185-22455-1-git-send-email-ynvich@gmail.com> References: <1385879185-22455-1-git-send-email-ynvich@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20131201_012918_591371_D8D9C7D7 X-CRM114-Status: GOOD ( 17.09 ) X-Spam-Score: -1.9 (-) Cc: Sergei Ianovich , Greg Kroah-Hartman , Arnd Bergmann , Rob Landley , "open list:DOCUMENTATION" 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 Status of I-8041 32 digital output channels can be managed via sysfs now. http://www.icpdas.com/products/Remote_IO/i-8ke/i-8041w.htm Signed-off-by: Sergei Ianovich --- Documentation/misc-devices/lp8x4x_bus.txt | 4 ++ drivers/misc/lp8x4x_bus.c | 67 ++++++++++++++++++++++++++++++- 2 files changed, 69 insertions(+), 2 deletions(-) diff --git a/Documentation/misc-devices/lp8x4x_bus.txt b/Documentation/misc-devices/lp8x4x_bus.txt index 9285fdc..74df10b 100644 --- a/Documentation/misc-devices/lp8x4x_bus.txt +++ b/Documentation/misc-devices/lp8x4x_bus.txt @@ -49,3 +49,7 @@ active_slot model RO - shows expansion module model number + +output_status + RW - set status of digital output channels on the module in + the expansion slot. Value can be read back. diff --git a/drivers/misc/lp8x4x_bus.c b/drivers/misc/lp8x4x_bus.c index b2d4a04..d177735 100644 --- a/drivers/misc/lp8x4x_bus.c +++ b/drivers/misc/lp8x4x_bus.c @@ -27,6 +27,9 @@ MODULE_DESCRIPTION("ICP DAS LP-8x4x parallel bus driver"); struct lp8x4x_slot { void *data_addr; unsigned int model; + struct mutex lock; + unsigned int DO_len; + u32 DO; struct device dev; }; @@ -89,6 +92,45 @@ static void lp8x4x_slot_release(struct device *dev) { } +static void lp8x4x_slot_set_DO(struct lp8x4x_slot *s) +{ + int i; + mutex_lock(&s->lock); + for (i = 0; i < s->DO_len; i++) + iowrite8((s->DO >> (i * 8)) & 0xff, s->data_addr + 2 * i); + mutex_unlock(&s->lock); +} + +static ssize_t output_status_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct lp8x4x_slot *s = container_of(dev, struct lp8x4x_slot, dev); + + return sprintf(buf, "0x%08x\n", s->DO); +} + +static ssize_t output_status_store(struct device *dev, + struct device_attribute *attr, const char *buf, size_t count) +{ + struct lp8x4x_slot *s = container_of(dev, struct lp8x4x_slot, dev); + + if (!buf) + return count; + if (0 == count) + return count; + + if (kstrtouint(buf, 16, &s->DO) != 0) { + dev_err(dev, "bad input\n"); + return count; + } + + lp8x4x_slot_set_DO(s); + + return count; +} + +static DEVICE_ATTR_RW(output_status); + static ssize_t model_show(struct device *dev, struct device_attribute *attr, char *buf) { @@ -105,6 +147,13 @@ static struct attribute *slot_dev_attrs[] = { }; ATTRIBUTE_GROUPS(slot_dev); +static struct attribute *do_slot_dev_attrs[] = { + &dev_attr_model.attr, + &dev_attr_output_status.attr, + NULL, +}; +ATTRIBUTE_GROUPS(do_slot_dev); + static void lp8x4x_master_release(struct device *dev) { struct lp8x4x_master *m = container_of(dev, struct lp8x4x_master, dev); @@ -178,8 +227,10 @@ static void devm_lp8x4x_bus_release(struct device *dev, void *res) dev_info(dev, "releasing devices\n"); for (i = 0; i < LP8X4X_MAX_SLOT_COUNT; i++) { s = &m->slot[i]; - if (s->model) + if (s->model) { device_unregister(&s->dev); + mutex_destroy(&s->lock); + } iounmap(s->data_addr); } device_unregister(&m->dev); @@ -203,13 +254,25 @@ static void __init lp8x4x_bus_probe_slot(struct lp8x4x_master *m, int i, 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; + mutex_init(&s->lock); + + switch (model) { + case 41: + s->DO_len = 4; + lp8x4x_slot_set_DO(s); + s->dev.groups = do_slot_dev_groups; + break; + default: + s->dev.groups = slot_dev_groups; + break; + }; err = device_register(&s->dev); if (err < 0) { dev_err(&s->dev, "failed to register device\n"); s->model = 0; + mutex_destroy(&s->lock); return; } }