From patchwork Fri Dec 13 02:27:24 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Yanovich X-Patchwork-Id: 3337081 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 5E6F8C0D4A for ; Fri, 13 Dec 2013 02:39:30 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 7750A201F9 for ; Fri, 13 Dec 2013 02:39:29 +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 7A9C2207D6 for ; Fri, 13 Dec 2013 02:39:28 +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 1VrIdP-0007OU-Db; Fri, 13 Dec 2013 02:37:48 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1VrIcp-0001Eo-PG; Fri, 13 Dec 2013 02:37:11 +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 1VrIWk-0000O0-Tz for linux-arm-kernel@lists.infradead.org; Fri, 13 Dec 2013 02:30:59 +0000 Received: by mail-la0-f48.google.com with SMTP id n7so938273lam.35 for ; Thu, 12 Dec 2013 18:30:37 -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=gMgs13I0BcOm81cVuhiGgLFaLW0B5vShZxzngeILMSg=; b=n7+DkU00v7+0sG/5DWbIGvI/TCfziS/xo28osPh3HJ6DG181kFw4E/RCMJ22DQ63b/ jKRYatRpSbDjvSEF0/x4GHI0AQkpNvGNLUpiUpn80RlzTIwbIjDBnlPhr/aRN7rBDV5l wlqz3TyGo2kF/okXvGj+yoV7UDkLESFesM1ecr9JglmNDYtwpN3anNhj8aL94FA7PdwU YTUGXGTinecSs0bDoOyLYT4L3vPw+6d1hyQrxmZbMySi0dXmndunPV74tC3a2L0kj7NS AEk2vy3rjkWB2rXab043AqDuLuaKXA7I9ivtm6tad+oI/K7Shp2FAa4QqcIrT88Y0FV3 ymPA== X-Received: by 10.152.1.5 with SMTP id 5mr73939lai.20.1386901837257; Thu, 12 Dec 2013 18:30:37 -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.36 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 12 Dec 2013 18:30:36 -0800 (PST) From: Sergei Ianovich To: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH v2 15/16] misc: support for I-8042 in LP-8x4x Date: Fri, 13 Dec 2013 06:27:24 +0400 Message-Id: <1386901645-28895-16-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_213055_237782_332E7830 X-CRM114-Status: GOOD ( 16.52 ) 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-8042 16 digital output channels can be managed via sysfs. Status of I-8042 16 digital input channels can be read via sysfs. http://www.icpdas.com/products/Remote_IO/i-8ke/i-8042w.htm Signed-off-by: Sergei Ianovich --- v0..v2 * no changes Documentation/misc-devices/lp8x4x_bus.txt | 4 ++ drivers/misc/lp8x4x_bus.c | 76 ++++++++++++++++++++++++++++++- 2 files changed, 78 insertions(+), 2 deletions(-) diff --git a/Documentation/misc-devices/lp8x4x_bus.txt b/Documentation/misc-devices/lp8x4x_bus.txt index 74df10b..e3a8bcf 100644 --- a/Documentation/misc-devices/lp8x4x_bus.txt +++ b/Documentation/misc-devices/lp8x4x_bus.txt @@ -50,6 +50,10 @@ active_slot model RO - shows expansion module model number +input_status + RO - get status of digital input channels on the module in + the expansion slot. + 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 1ef1726..684e640 100644 --- a/drivers/misc/lp8x4x_bus.c +++ b/drivers/misc/lp8x4x_bus.c @@ -27,6 +27,8 @@ struct lp8x4x_slot { struct mutex lock; unsigned int DO_len; u32 DO; + unsigned int DI_len; + u32 DI; struct device dev; }; @@ -89,6 +91,21 @@ static void lp8x4x_slot_release(struct device *dev) { } +static void lp8x4x_slot_get_DI(struct lp8x4x_slot *s) +{ + int i; + u32 b; + + mutex_lock(&s->lock); + s->DI = 0; + for (i = 0; i < s->DI_len; i++) { + b = ioread8(s->data_addr + 2 * (i + 1)); + b ^= 0xff; + s->DI += b << (i * 8); + } + mutex_unlock(&s->lock); +} + static void lp8x4x_slot_set_DO(struct lp8x4x_slot *s) { int i; @@ -98,29 +115,70 @@ static void lp8x4x_slot_set_DO(struct lp8x4x_slot *s) mutex_unlock(&s->lock); } +static ssize_t input_status_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct lp8x4x_slot *s = container_of(dev, struct lp8x4x_slot, dev); + + lp8x4x_slot_get_DI(s); + switch (s->DI_len) { + case 4: + return sprintf(buf, "0x%08x\n", s->DI); + case 2: + return sprintf(buf, "0x%04x\n", s->DI); + case 1: + return sprintf(buf, "0x%02x\n", s->DI); + default: + break; + } + return sprintf(buf, "0x%x\n", s->DI); +} + +static DEVICE_ATTR_RO(input_status); + 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); + switch (s->DO_len) { + case 4: + return sprintf(buf, "0x%08x\n", s->DO); + case 2: + return sprintf(buf, "0x%04x\n", s->DO); + case 1: + return sprintf(buf, "0x%02x\n", s->DO); + default: + break; + } + return sprintf(buf, "0x%x\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); + u32 DO; + u8 *b = (void *) &DO; + int i; if (!buf) return count; if (0 == count) return count; - if (kstrtouint(buf, 16, &s->DO) != 0) { + if (kstrtouint(buf, 16, &DO) != 0) { dev_err(dev, "bad input\n"); return count; } + for (i = 4; i > s->DO_len; i--) + if (b[i - 1] != 0) { + dev_err(dev, "bad input\n"); + return count; + } + + s->DO = DO; lp8x4x_slot_set_DO(s); return count; @@ -151,6 +209,14 @@ static struct attribute *do_slot_dev_attrs[] = { }; ATTRIBUTE_GROUPS(do_slot_dev); +static struct attribute *dio_slot_dev_attrs[] = { + &dev_attr_model.attr, + &dev_attr_output_status.attr, + &dev_attr_input_status.attr, + NULL, +}; +ATTRIBUTE_GROUPS(dio_slot_dev); + static void lp8x4x_master_release(struct device *dev) { struct lp8x4x_master *m = container_of(dev, struct lp8x4x_master, dev); @@ -255,6 +321,12 @@ static void __init lp8x4x_bus_probe_slot(struct lp8x4x_master *m, int i, lp8x4x_slot_set_DO(s); s->dev.groups = do_slot_dev_groups; break; + case 42: + s->DI_len = 2; + s->DO_len = 2; + lp8x4x_slot_set_DO(s); + s->dev.groups = dio_slot_dev_groups; + break; default: s->dev.groups = slot_dev_groups; break;