From patchwork Wed Apr 16 17:17:26 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Yanovich X-Patchwork-Id: 4003391 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 20FE29F2CC for ; Wed, 16 Apr 2014 17:29:29 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 3E49B20375 for ; Wed, 16 Apr 2014 17:29:28 +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 60B6D201DE for ; Wed, 16 Apr 2014 17:29:27 +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 1WaTXv-0006V2-77; Wed, 16 Apr 2014 17:22: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 1WaTVT-0007z2-0A for linux-arm-kernel@lists.infradead.org; Wed, 16 Apr 2014 17:20:19 +0000 Received: by mail-la0-f47.google.com with SMTP id pn19so8280747lab.20 for ; Wed, 16 Apr 2014 10:19:56 -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=jdjAuSfRS10iu5CkVtXEA6WKp9f7aBpNBiFos2DosfQ=; b=Td1Da2FIUPkbxozulbX8aUY+ccWa4aEeap+3h63IiRspOiksaAp8xP4i8E1RSocF7U N59LiuX5Ee78+/Z56NbITRFlcHIWwbCXTBkOsvTuPvcID52wfiIUdRP/embmfSrooYgU H2lR4AOWgzgzAA2Ym+qkjOjmgjqhCCKJgBtjknGyi8ZB0iSotL2tIZhUBQ7EhDR58meo vmS5TvHytKtCnCno1XEsTCMtumh3TmbIXF3M5XbNDhRABgQGDj9inlagqILXlhBSeE4P 2gEQahEH5BOUZNyLXwphvLkREF7MUjquaSTBpHln2FL109W6xiX+1+UrY2AUkPtKfbnA 5TkQ== X-Received: by 10.112.55.5 with SMTP id n5mr105749lbp.71.1397668796641; Wed, 16 Apr 2014 10:19:56 -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.55 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 16 Apr 2014 10:19:56 -0700 (PDT) From: Sergei Ianovich To: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH v4 21/21] misc: support for I-8024 in LP-8x4x Date: Wed, 16 Apr 2014 21:17:26 +0400 Message-Id: <1397668667-27328-15-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_102019_256401_38803C42 X-CRM114-Status: GOOD ( 18.18 ) X-Spam-Score: -0.1 (/) Cc: Sergei Ianovich , Greg Kroah-Hartman , Randy Dunlap , Arnd Bergmann , "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=-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 Status of I-8042 4 analog output channels can be managed via sysfs. http://www.icpdas.com/root/product/solutions/remote_io/rs-485/i-8k_i-87k/i-8024w.html Signed-off-by: Sergei Ianovich --- v3..v4 * no changes v2..v3 * use usleep_range instead of custom nsleep * number change (16/16 -> 21/21) v0..v2 * no changes Documentation/misc-devices/lp8x4x_bus.txt | 15 ++++++ drivers/misc/lp8x4x_bus.c | 78 +++++++++++++++++++++++++++++++ 2 files changed, 93 insertions(+) diff --git a/Documentation/misc-devices/lp8x4x_bus.txt b/Documentation/misc-devices/lp8x4x_bus.txt index 3ea257d..6076e01 100644 --- a/Documentation/misc-devices/lp8x4x_bus.txt +++ b/Documentation/misc-devices/lp8x4x_bus.txt @@ -66,3 +66,18 @@ input_status output_status RW - set status of digital output channels on the module in the expansion slot. Value can be read back. + +analog_output + RW - set status of analog output channels on the module in + the expansion slot. Tested with voltage output. Bits 0-13: + 0x00c0 is -10.0V + 0x2000 is 0.0V + 0x3f40 is +10.0V + + So 1 unit of output is 1.25 mV. + + Bits 15 and 14 determine which channel to apply the value: + 0x0000 is channel 1 + 0x4000 is channel 2 + 0x8000 is channel 3 + 0xc000 is channel 4 diff --git a/drivers/misc/lp8x4x_bus.c b/drivers/misc/lp8x4x_bus.c index 3fb227d..72cd0b2 100644 --- a/drivers/misc/lp8x4x_bus.c +++ b/drivers/misc/lp8x4x_bus.c @@ -8,6 +8,7 @@ * 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 @@ -23,6 +24,7 @@ MODULE_LICENSE("GPL"); MODULE_AUTHOR("Sergei Ianovich "); MODULE_DESCRIPTION("ICP DAS LP-8x4x parallel bus driver"); +#define LP8X4X_MAX_AO_CHANNELS 4 struct lp8x4x_slot { void *data_addr; unsigned int model; @@ -31,6 +33,8 @@ struct lp8x4x_slot { u32 DO; unsigned int DI_len; u32 DI; + unsigned int AO_len; + u32 AO[LP8X4X_MAX_AO_CHANNELS]; struct device dev; }; @@ -120,6 +124,26 @@ static void lp8x4x_slot_set_DO(struct lp8x4x_slot *s) mutex_unlock(&s->lock); } +static void lp8x4x_slot_reset_AO(struct lp8x4x_slot *s) +{ + int i; + mutex_lock(&s->lock); + for (i = 0; i < s->AO_len; i++) + s->AO[i] = 0x2000; + iowrite8(0x00, s->data_addr); + usleep_range(1, 2); + iowrite8(0xff, s->data_addr); + mutex_unlock(&s->lock); +} + +static void lp8x4x_slot_set_AO(struct lp8x4x_slot *s, u32 val) +{ + mutex_lock(&s->lock); + iowrite8(val & 0xff, s->data_addr + 2); + iowrite8((val >> 8) & 0xff, s->data_addr + 4); + mutex_unlock(&s->lock); +} + static ssize_t input_status_show(struct device *dev, struct device_attribute *attr, char *buf) { @@ -191,6 +215,48 @@ static ssize_t output_status_store(struct device *dev, static DEVICE_ATTR_RW(output_status); +static ssize_t analog_output_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct lp8x4x_slot *s = container_of(dev, struct lp8x4x_slot, dev); + int i, c = 0; + + for (i = 0; i < s->AO_len; i++) + c += sprintf(&buf[c], "0x%04x\n", s->AO[i]); + return c; +} + +static ssize_t analog_output_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 AO; + int i; + + if (!buf) + return count; + if (0 == count) + return count; + + if (kstrtouint(buf, 16, &AO) != 0) { + dev_err(dev, "bad input\n"); + return count; + } + + if (AO & 0xffff0000) { + dev_err(dev, "bad input\n"); + return count; + } + + i = AO >> 14; + s->AO[i] = AO & 0x3fff; + lp8x4x_slot_set_AO(s, AO); + + return count; +} + +static DEVICE_ATTR_RW(analog_output); + static ssize_t model_show(struct device *dev, struct device_attribute *attr, char *buf) { @@ -222,6 +288,13 @@ static struct attribute *dio_slot_dev_attrs[] = { }; ATTRIBUTE_GROUPS(dio_slot_dev); +static struct attribute *ao_slot_dev_attrs[] = { + &dev_attr_model.attr, + &dev_attr_analog_output.attr, + NULL, +}; +ATTRIBUTE_GROUPS(ao_slot_dev); + static void lp8x4x_master_release(struct device *dev) { struct lp8x4x_master *m = container_of(dev, struct lp8x4x_master, dev); @@ -382,6 +455,11 @@ static void __init lp8x4x_bus_probe_slot(struct lp8x4x_master *m, int i, mutex_init(&s->lock); switch (model) { + case 24: + s->AO_len = 4; + lp8x4x_slot_reset_AO(s); + s->dev.groups = ao_slot_dev_groups; + break; case 41: s->DO_len = 4; lp8x4x_slot_set_DO(s);