From patchwork Sun Dec 1 06:26: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: 3261651 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 942749F373 for ; Sun, 1 Dec 2013 06:45:42 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 9356220498 for ; Sun, 1 Dec 2013 06:45:41 +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 6DEE420494 for ; Sun, 1 Dec 2013 06:45:40 +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 1Vn0YB-0007PE-VB; Sun, 01 Dec 2013 06:30:42 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1Vn0XM-0002YP-3N; Sun, 01 Dec 2013 06:29:48 +0000 Received: from mail-lb0-x22d.google.com ([2a00:1450:4010:c04::22d]) by merlin.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1Vn0X6-0002TO-6p for linux-arm-kernel@lists.infradead.org; Sun, 01 Dec 2013 06:29:35 +0000 Received: by mail-lb0-f173.google.com with SMTP id u14so7977187lbd.32 for ; Sat, 30 Nov 2013 22:29:09 -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=uBwAa1JMbsC8pApcOQAhrUylO1CppAmcIHcq9YB+cxI=; b=W3y+tRl2FtsslmvAOVtDYbdROgBUvduX5WXTWiPtuQvMRWnXuPQrUv8yN82NdCkSQb tOBiYa4zZQ8uukk/UzVmLeL6TcB9fPmNZVTpoz3QsAk/nq/rFVhmJigXac9mnGcmiO48 vR//GTWrXUYXLldoPbHXSFYt92NjLkgmkgyLz6SIB70Pld/JDiMUhDk4m48JNDT7uMyG uDGPKVbng5l6zoId52xVOu+xacN2U5q1cWE1o9NWjG0MtZ3xFrTETBLDpOx9s+0yJ8Fg /53oQlLUUdqT2m6CBe7LW0DYLo9pPR8WupVoVXRt16OkDM4b8Ad3INSeYYyaM8rV33wM W6gw== X-Received: by 10.112.155.70 with SMTP id vu6mr47427lbb.41.1385879349595; Sat, 30 Nov 2013 22:29:09 -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.29.08 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 30 Nov 2013 22:29:08 -0800 (PST) From: Sergei Ianovich To: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH 11/11] misc: support for I-8024 in LP-8x4x Date: Sun, 1 Dec 2013 10:26:24 +0400 Message-Id: <1385879185-22455-12-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_012932_617184_67C4293A X-CRM114-Status: GOOD ( 16.31 ) 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 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 --- Documentation/misc-devices/lp8x4x_bus.txt | 15 ++++++ drivers/misc/lp8x4x_bus.c | 89 +++++++++++++++++++++++++++++++ 2 files changed, 104 insertions(+) diff --git a/Documentation/misc-devices/lp8x4x_bus.txt b/Documentation/misc-devices/lp8x4x_bus.txt index e3a8bcf..08419d1 100644 --- a/Documentation/misc-devices/lp8x4x_bus.txt +++ b/Documentation/misc-devices/lp8x4x_bus.txt @@ -57,3 +57,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 fce11c4..0fa13a3 100644 --- a/drivers/misc/lp8x4x_bus.c +++ b/drivers/misc/lp8x4x_bus.c @@ -14,6 +14,8 @@ #include #include #include +#include +#include #include #include @@ -24,6 +26,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; @@ -32,6 +35,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; }; @@ -118,6 +123,36 @@ static void lp8x4x_slot_set_DO(struct lp8x4x_slot *s) mutex_unlock(&s->lock); } +void nsleep(unsigned long nanosec) +{ + ktime_t t = ns_to_ktime(nanosec); + long state = current->state; + + __set_current_state(TASK_UNINTERRUPTIBLE); + schedule_hrtimeout(&t, HRTIMER_MODE_REL); + __set_current_state(state); +} + +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); + nsleep(450); + 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) { @@ -189,6 +224,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) { @@ -220,6 +297,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); @@ -324,6 +408,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);