From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4CB14C4338F for ; Tue, 17 Aug 2021 16:58:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2879F60238 for ; Tue, 17 Aug 2021 16:58:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229716AbhHQQ7T (ORCPT ); Tue, 17 Aug 2021 12:59:19 -0400 Received: from mga11.intel.com ([192.55.52.93]:65423 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229699AbhHQQ7T (ORCPT ); Tue, 17 Aug 2021 12:59:19 -0400 X-IronPort-AV: E=McAfee;i="6200,9189,10079"; a="213025298" X-IronPort-AV: E=Sophos;i="5.84,329,1620716400"; d="scan'208";a="213025298" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Aug 2021 09:58:45 -0700 X-IronPort-AV: E=Sophos;i="5.84,329,1620716400"; d="scan'208";a="531149381" Received: from smile.fi.intel.com (HELO smile) ([10.237.68.40]) by fmsmga002-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Aug 2021 09:58:44 -0700 Received: from andy by smile with local (Exim 4.94.2) (envelope-from ) id 1mG2QA-00AoTg-Bv; Tue, 17 Aug 2021 19:58:38 +0300 Date: Tue, 17 Aug 2021 19:58:38 +0300 From: Andy Shevchenko To: Jacopo Mondi Cc: Jonathan Cameron , Lars-Peter Clausen , Matt Ranostay , linux-iio@vger.kernel.org Subject: Re: [PATCH 2/2] iio: chemical: Add Senseair Sunrise 006-0-007 driver Message-ID: References: <20210817154951.50208-1-jacopo@jmondi.org> <20210817154951.50208-3-jacopo@jmondi.org> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20210817154951.50208-3-jacopo@jmondi.org> Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org On Tue, Aug 17, 2021 at 05:49:51PM +0200, Jacopo Mondi wrote: > Add support for the Senseair Sunrise 006-0-0007 driver through the > IIO subsystem. Datasheet tag / link? ... > +config SUNRISE > + tristate "Senseair Sunrise 006-0-0007 CO2 sensor" > + depends on I2C > + help > + Say yes here to build support for Senseair Sunrise 006-0-0007 CO2 > + sensor. > + > + To compile this driver as a module, choose M here: the > + module will be called sunrise. Too generic name for configuration and module, ... > + * iio/co2/sunrise-006-0-0007.c > + * Redundant noise. ... > + * TODO: Add support for controllable EN pin > + * TODO: Add support for single-shot operations by using the nDRY pin. Ditto. If it's not ready, then make it ready. ... > +#include Why? Perhaps mod_devicetable,h is what you had in mind. ... > + i2c_smbus_read_byte(client); Can you use regmap I²C API? ... > +#define sunrise_readb_client(client, addr) \ > +({ \ > + u8 _val; \ > + sunrise_read_byte(client, addr, &_val); \ > + _val; \ > +}) > +#define sunrise_readb(addr) sunrise_readb_client(client, addr) Drop ugly macros and use read_poll_timeout() below. > +#define sunrise_poll_register(reg, val, cond) \ > + readx_poll_timeout(sunrise_readb, reg, val, cond, 100, 0) ... > +static int sunrise_read_raw(struct iio_dev *iio_dev, > + const struct iio_chan_spec *chan, > + int *val, int *val2, long mask) > +{ > + struct sunrise_dev *sunrise = iio_priv(iio_dev); > + struct i2c_client *client = sunrise->client; + u16 value; > + int ret; > + > + switch (mask) { > + case IIO_CHAN_INFO_RAW: > + > + mutex_lock(&sunrise->lock); > + > + switch (chan->type) { > + case IIO_CONCENTRATION: { > + u16 co2; Reuse value. > + ret = sunrise_read_co2_filtered(client, &co2); > + *val = co2; > + mutex_unlock(&sunrise->lock); > + > + return ret ? ret : IIO_VAL_INT; Can be written as return ret ?: IIO_VAL_INT; but up to maintainers. > + } > + > + case IIO_TEMP: { > + u16 temp; Reuse value. > + ret = sunrise_read_word(client, > + SUNRISE_CHIP_TEMPERATURE_REG, > + &temp); > + *val = temp; > + mutex_unlock(&sunrise->lock); > + > + return ret ? ret : IIO_VAL_INT; > + } > + > + default: > + mutex_unlock(&sunrise->lock); > + return -EINVAL; > + } > + > + case IIO_CHAN_INFO_SCALE: > + /* Chip temperature scale = 1/100 */ > + *val = 1; > + *val2 = 100; > + return IIO_VAL_FRACTIONAL; > + > + default: > + return -EINVAL; > + } > + > + return 0; > +} ... > + return sunrise_poll_register(SUNRISE_CALIBRATION_STATUS_REG, status, > + (status & BIT(5))); Too many parentheses. -- With Best Regards, Andy Shevchenko