From patchwork Thu Jul 23 06:29:43 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matt Ranostay X-Patchwork-Id: 11680119 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 38807138C for ; Thu, 23 Jul 2020 06:29:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2050D20888 for ; Thu, 23 Jul 2020 06:29:51 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=konsulko.com header.i=@konsulko.com header.b="DfXWRTBj" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726390AbgGWG3u (ORCPT ); Thu, 23 Jul 2020 02:29:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59684 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725984AbgGWG3u (ORCPT ); Thu, 23 Jul 2020 02:29:50 -0400 Received: from mail-ed1-x544.google.com (mail-ed1-x544.google.com [IPv6:2a00:1450:4864:20::544]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3A520C0619DC for ; Wed, 22 Jul 2020 23:29:50 -0700 (PDT) Received: by mail-ed1-x544.google.com with SMTP id q4so420703edv.13 for ; Wed, 22 Jul 2020 23:29:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=konsulko.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=fDs0zCZM+B5tbC0Z03ibEwdhGnrGYty6w4AaVIm8tns=; b=DfXWRTBjFVpC0EJpXnnSNKHvRNdwks2jt3ae2IPedNYS4KeI4LkIVZKG0DXxJDKrkz ss3lbwi2xaW5dGT4dWy7gQXUPuScnqzPLFaqGyWWnfaI9sVd2sgwn9znuH49bk2EKeLx wOpdwDFtN3L6LxyNsiq7n2PKLQO0DYmaHBj4A= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=fDs0zCZM+B5tbC0Z03ibEwdhGnrGYty6w4AaVIm8tns=; b=Kh7UwQQzOu4X8lcVGQlOQXjXd/9KGQxsY2WKleSbQm9eiNesg4tEVEI4PQ80GhOXSn CYGvgCHI2LODcKPJc/8RSADGlOtwRnjN4CNPF6+Rys7/CHGm8sjvAwyFdlHGnd5syMKz 9wwPdHDD2ZHwP+B5jLZrYSrhktccuAkcAH/8gUQg4SUYGDqJgpvUs2R6h0rQRngCXKYQ gCg2VR3TltcL/lr4FYXUPVdtYQwaPb3x0/sw9hyn4JdQr76QcI2b/LeUCJdgWh+d3YgJ gvCwXcGwokkPMlP5AjRwDQi86udnWQqL8Rdf42G6IqcnxNPcBhGkMeC9PRLhe1r4jV9o X9nw== X-Gm-Message-State: AOAM533ZMHJUB/iyMEykqHq2ukeELhTPrENPXm4eUW5mlAkDFu3NZz6+ CkpGZToiEF/YnqbnBNb0KPubfA== X-Google-Smtp-Source: ABdhPJwELjZRU2v4tb9WoPzVIe8WABwKKQauXcDkWJFjUks5T+Zt0dHKDOU3mZvx0jBiciE6YWa7+Q== X-Received: by 2002:a05:6402:b6c:: with SMTP id cb12mr2841791edb.116.1595485788898; Wed, 22 Jul 2020 23:29:48 -0700 (PDT) Received: from taos.konsulko.bg (lan.nucleusys.com. [92.247.61.126]) by smtp.gmail.com with ESMTPSA id bq8sm1358866ejb.103.2020.07.22.23.29.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Jul 2020 23:29:48 -0700 (PDT) From: Matt Ranostay To: jic23@kernel.org Cc: linux-iio@vger.kernel.org, Matt Ranostay Subject: [PATCH v3 1/2] iio: add IIO_MOD_O2 modifier Date: Thu, 23 Jul 2020 09:29:43 +0300 Message-Id: <20200723062944.11438-2-matt.ranostay@konsulko.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200723062944.11438-1-matt.ranostay@konsulko.com> References: <20200723062944.11438-1-matt.ranostay@konsulko.com> MIME-Version: 1.0 Sender: linux-iio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org Add modifier IIO_MOD_O2 for O2 concentration reporting Signed-off-by: Matt Ranostay --- Documentation/ABI/testing/sysfs-bus-iio | 2 ++ drivers/iio/industrialio-core.c | 1 + include/uapi/linux/iio/types.h | 1 + tools/iio/iio_event_monitor.c | 2 ++ 4 files changed, 6 insertions(+) diff --git a/Documentation/ABI/testing/sysfs-bus-iio b/Documentation/ABI/testing/sysfs-bus-iio index 5c62bfb0f3f5..405181fde40a 100644 --- a/Documentation/ABI/testing/sysfs-bus-iio +++ b/Documentation/ABI/testing/sysfs-bus-iio @@ -1564,6 +1564,8 @@ What: /sys/bus/iio/devices/iio:deviceX/in_concentration_ethanol_raw What: /sys/bus/iio/devices/iio:deviceX/in_concentrationX_ethanol_raw What: /sys/bus/iio/devices/iio:deviceX/in_concentration_h2_raw What: /sys/bus/iio/devices/iio:deviceX/in_concentrationX_h2_raw +What: /sys/bus/iio/devices/iio:deviceX/in_concentration_o2_raw +What: /sys/bus/iio/devices/iio:deviceX/in_concentrationX_o2_raw What: /sys/bus/iio/devices/iio:deviceX/in_concentration_voc_raw What: /sys/bus/iio/devices/iio:deviceX/in_concentrationX_voc_raw KernelVersion: 4.3 diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c index 606d5e61c575..59003dc44e60 100644 --- a/drivers/iio/industrialio-core.c +++ b/drivers/iio/industrialio-core.c @@ -133,6 +133,7 @@ static const char * const iio_modifier_names[] = { [IIO_MOD_PM10] = "pm10", [IIO_MOD_ETHANOL] = "ethanol", [IIO_MOD_H2] = "h2", + [IIO_MOD_O2] = "o2", }; /* relies on pairs of these shared then separate */ diff --git a/include/uapi/linux/iio/types.h b/include/uapi/linux/iio/types.h index fdd81affca4b..48c13147c0a8 100644 --- a/include/uapi/linux/iio/types.h +++ b/include/uapi/linux/iio/types.h @@ -94,6 +94,7 @@ enum iio_modifier { IIO_MOD_PM10, IIO_MOD_ETHANOL, IIO_MOD_H2, + IIO_MOD_O2, }; enum iio_event_type { diff --git a/tools/iio/iio_event_monitor.c b/tools/iio/iio_event_monitor.c index f115d166c985..bb03859db89d 100644 --- a/tools/iio/iio_event_monitor.c +++ b/tools/iio/iio_event_monitor.c @@ -119,6 +119,7 @@ static const char * const iio_modifier_names[] = { [IIO_MOD_PM2P5] = "pm2p5", [IIO_MOD_PM4] = "pm4", [IIO_MOD_PM10] = "pm10", + [IIO_MOD_O2] = "o2", }; static bool event_is_known(struct iio_event_data *event) @@ -211,6 +212,7 @@ static bool event_is_known(struct iio_event_data *event) case IIO_MOD_PM2P5: case IIO_MOD_PM4: case IIO_MOD_PM10: + case IIO_MOD_O2: break; default: return false; From patchwork Thu Jul 23 06:29:44 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matt Ranostay X-Patchwork-Id: 11680121 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6682D138C for ; Thu, 23 Jul 2020 06:29:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4EB77208E4 for ; Thu, 23 Jul 2020 06:29:52 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=konsulko.com header.i=@konsulko.com header.b="G8Aep+D3" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726780AbgGWG3w (ORCPT ); Thu, 23 Jul 2020 02:29:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59688 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725984AbgGWG3v (ORCPT ); Thu, 23 Jul 2020 02:29:51 -0400 Received: from mail-ed1-x542.google.com (mail-ed1-x542.google.com [IPv6:2a00:1450:4864:20::542]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 63D45C0619DC for ; Wed, 22 Jul 2020 23:29:51 -0700 (PDT) Received: by mail-ed1-x542.google.com with SMTP id h28so3669482edz.0 for ; Wed, 22 Jul 2020 23:29:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=konsulko.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=EAM1jyzJK3KL5nC2vaBWvf/2Lg8CovKQH+OxucJDd1E=; b=G8Aep+D366vJS9bC3UfYjWoHK4cM9v8OnLt2VETXqQCQoHB473aQD5gvj1PJTEmqls mpndymshI5fkX2qE7cvQyDuhJgUKrRI8sVjQ/x3gf7kSGu7qoywlrIVolJrIqwvTRwGP 0/1YC3nzlt+Z5xGeazbwq7125tCCRtGMnBrR4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=EAM1jyzJK3KL5nC2vaBWvf/2Lg8CovKQH+OxucJDd1E=; b=poosftYym5vVBNA7Jhx/IrvL3Ch7WT9NBsb2ioQMKWFsDhO9ok9pCkmn8SQVsydk+J CdiLl/cOhQY7TtooqVBPz0pPpylCk1DE0L0qQ/WgpjJdEupdPrvG6P11R3IYE8rNW79z 92uMY3EzMPqd70eNGTWC77loNJqnEhbfj+o3h+6cDBc2Tr6m2T2E/aJssx3X8zdjjDAa AWgkaqRJE2xGp63Qn0xecE+FCAaIxubojAwUEuKLJ3NahEPXrJHj8srsOmYr5Tmw3aIA R5v1DxOVnaYvQG2ZkG8MWcuGsjO/a2H8PAj89U73EiRUo8sPvU8IBgfT+4wws7X5nxAC wvUw== X-Gm-Message-State: AOAM532Owvl013K2VNtSEHSz3CaQnsrArgeHkNAqYkD1G4sv8suIYYcO 0Yfa+OSII+7Xqajwq7da/rFHLA== X-Google-Smtp-Source: ABdhPJwchTSfFsaShOZokdO+zLr1406BKGMWR3xnM6eJFmeITtZDGxpgeMTRnyqiV9ElhJu3IifjQw== X-Received: by 2002:a50:ab52:: with SMTP id t18mr2793893edc.195.1595485790069; Wed, 22 Jul 2020 23:29:50 -0700 (PDT) Received: from taos.konsulko.bg (lan.nucleusys.com. [92.247.61.126]) by smtp.gmail.com with ESMTPSA id bq8sm1358866ejb.103.2020.07.22.23.29.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Jul 2020 23:29:49 -0700 (PDT) From: Matt Ranostay To: jic23@kernel.org Cc: linux-iio@vger.kernel.org, Matt Ranostay , Jonathan Cameron Subject: [PATCH v3 2/2] iio: chemical: atlas-ezo-sensor: add support for O2 sensor Date: Thu, 23 Jul 2020 09:29:44 +0300 Message-Id: <20200723062944.11438-3-matt.ranostay@konsulko.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200723062944.11438-1-matt.ranostay@konsulko.com> References: <20200723062944.11438-1-matt.ranostay@konsulko.com> MIME-Version: 1.0 Sender: linux-iio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org Add support for the Atlas EZO O2 chemical sensor which required some refactoring of the driver and parsing of i2c transfer. Sensor data is converted by the scaling value from percent to IIO_CONCENTRATION. Signed-off-by: Matt Ranostay Signed-off-by: Jonathan Cameron --- drivers/iio/chemical/atlas-ezo-sensor.c | 73 ++++++++++++++++++------- 1 file changed, 54 insertions(+), 19 deletions(-) diff --git a/drivers/iio/chemical/atlas-ezo-sensor.c b/drivers/iio/chemical/atlas-ezo-sensor.c index 8b72bb012363..60a0c752fbc5 100644 --- a/drivers/iio/chemical/atlas-ezo-sensor.c +++ b/drivers/iio/chemical/atlas-ezo-sensor.c @@ -16,10 +16,11 @@ #include #define ATLAS_EZO_DRV_NAME "atlas-ezo-sensor" -#define ATLAS_CO2_INT_TIME_IN_MS 950 +#define ATLAS_INT_TIME_IN_MS 950 enum { ATLAS_CO2_EZO, + ATLAS_O2_EZO, }; struct atlas_ezo_device { @@ -38,31 +39,53 @@ struct atlas_ezo_data { u8 buffer[8]; }; +#define ATLAS_CONCENTRATION_CHANNEL(_modifier) \ + { \ + .type = IIO_CONCENTRATION, \ + .modified = 1,\ + .channel2 = _modifier, \ + .info_mask_separate = \ + BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE), \ + .scan_index = 0, \ + .scan_type = { \ + .sign = 'u', \ + .realbits = 32, \ + .storagebits = 32, \ + .endianness = IIO_CPU, \ + }, \ + } + static const struct iio_chan_spec atlas_co2_ezo_channels[] = { - { - .type = IIO_CONCENTRATION, - .modified = 1, - .channel2 = IIO_MOD_CO2, - .info_mask_separate = - BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE), - .scan_index = 0, - .scan_type = { - .sign = 'u', - .realbits = 32, - .storagebits = 32, - .endianness = IIO_CPU, - }, - }, + ATLAS_CONCENTRATION_CHANNEL(IIO_MOD_CO2), +}; + +static const struct iio_chan_spec atlas_o2_ezo_channels[] = { + ATLAS_CONCENTRATION_CHANNEL(IIO_MOD_O2), }; static struct atlas_ezo_device atlas_ezo_devices[] = { [ATLAS_CO2_EZO] = { .channels = atlas_co2_ezo_channels, .num_channels = 1, - .delay = ATLAS_CO2_INT_TIME_IN_MS, + .delay = ATLAS_INT_TIME_IN_MS, }, + [ATLAS_O2_EZO] = { + .channels = atlas_o2_ezo_channels, + .num_channels = 1, + .delay = ATLAS_INT_TIME_IN_MS, + } }; +static void atlas_ezo_sanitize(char *buf) +{ + char *ptr = strchr(buf, '.'); + + if (!ptr) + return; + + memmove(ptr, ptr + 1, strlen(ptr)); +} + static int atlas_ezo_read_raw(struct iio_dev *indio_dev, struct iio_chan_spec const *chan, int *val, int *val2, long mask) @@ -96,6 +119,9 @@ static int atlas_ezo_read_raw(struct iio_dev *indio_dev, return -EBUSY; } + /* removing floating point for fixed number representation */ + atlas_ezo_sanitize(data->buffer + 2); + ret = kstrtol(data->buffer + 1, 10, &tmp); *val = tmp; @@ -105,9 +131,16 @@ static int atlas_ezo_read_raw(struct iio_dev *indio_dev, return ret ? ret : IIO_VAL_INT; } case IIO_CHAN_INFO_SCALE: - *val = 0; - *val2 = 100; /* 0.0001 */ - return IIO_VAL_INT_PLUS_MICRO; + switch (chan->channel2) { + case IIO_MOD_CO2: + *val = 0; + *val2 = 100; /* 0.0001 */ + return IIO_VAL_INT_PLUS_MICRO; + case IIO_MOD_O2: + *val = 100; + return IIO_VAL_INT; + } + return -EINVAL; } return 0; @@ -119,12 +152,14 @@ static const struct iio_info atlas_info = { static const struct i2c_device_id atlas_ezo_id[] = { { "atlas-co2-ezo", ATLAS_CO2_EZO }, + { "atlas-o2-ezo", ATLAS_O2_EZO }, {} }; MODULE_DEVICE_TABLE(i2c, atlas_ezo_id); static const struct of_device_id atlas_ezo_dt_ids[] = { { .compatible = "atlas,co2-ezo", .data = (void *)ATLAS_CO2_EZO, }, + { .compatible = "atlas,o2-ezo", .data = (void *)ATLAS_O2_EZO, }, {} }; MODULE_DEVICE_TABLE(of, atlas_ezo_dt_ids);