Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp1015881iob; Fri, 13 May 2022 19:44:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwFlfgqXMohu0XBqeQvQg7c0U7BVHRLX6H1goYJSsG59QHMvK+/6O6mNYH8mik7Zew8r/uk X-Received: by 2002:a05:6000:c2:b0:20c:ff3b:e5b5 with SMTP id q2-20020a05600000c200b0020cff3be5b5mr128494wrx.26.1652496240647; Fri, 13 May 2022 19:44:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652496240; cv=none; d=google.com; s=arc-20160816; b=hhuk5MzVPyjz9HI5wOLlaiBf0pWjRuc9fFKC3PehUTPmDDT/8Y1YI4L1TgcZWMOzPu q+0cC6VzqxXr0MLiSznV9VWqL28QzRbmscAr9efT1+7VZWblSIS2JHv+dLDOxhyJgF3H ZBZh1B0kbX7Nf9KoUfJgFVUDQymlOFBqFpAk0N0pzCgJqOJ7HtiYbvNxv2FE1Khd8YFa H/WpDi5FmzsSpys0iPMThsG+btjxABkp/qDz5eLOye8x76WSsqXSQ+zVJdeIfcYd0/Pi b/76dCOZsT8KUyU4frvAb1+YWxG+IES4eTFJ4O7Puo6FE9WeJuHWM59NfrbqFeZAFGdv Je8w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=LDeSEeG6sYN/4I8BLWwVYheQ8YlAvLVklfd9fc7g84c=; b=VxhIRpKyKx/Wj8nmIx5X6sjYQqpBNmKjsshDrH/DoFY+jOVI0huATSO8bLVPpL70Sz ecDoUCxAT1ws5BJQzxcw+OFiFbA7elLY83I8dQy+2VoRAQb6MQPaDCXP2xvaTdAbHJmh qTa0nzLxY2cQKdpE9AF4Ox13xfA0Uh281SWHvN1zUehjax3r9jMK1jx4G8bN3cYUq3i1 p+0rnh/SAvfStSi/ttt7ZFnTOdve2/Z2+Dh/vKjVmg0yolUaPYUh+vy9/GKwaw+7aGMZ y6EJaJS4tQT2mdugtRAWR2n+09GTWrlTXANjo5zvwazAQ4wNt71MfH/TQgyilCB+5TZj rXDA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=l3OJo2qh; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id t5-20020a1c4605000000b00393e7e73449si3859029wma.128.2022.05.13.19.43.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 May 2022 19:44:00 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=l3OJo2qh; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 728D030B2D8; Fri, 13 May 2022 16:31:52 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1359567AbiELXks (ORCPT + 99 others); Thu, 12 May 2022 19:40:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60532 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1359559AbiELXkq (ORCPT ); Thu, 12 May 2022 19:40:46 -0400 Received: from mail-lf1-x134.google.com (mail-lf1-x134.google.com [IPv6:2a00:1450:4864:20::134]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B1C541116B; Thu, 12 May 2022 16:40:44 -0700 (PDT) Received: by mail-lf1-x134.google.com with SMTP id bu29so11815301lfb.0; Thu, 12 May 2022 16:40:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:date:mime-version:user-agent:subject:content-language:to :cc:references:from:in-reply-to:content-transfer-encoding; bh=LDeSEeG6sYN/4I8BLWwVYheQ8YlAvLVklfd9fc7g84c=; b=l3OJo2qhUsCbaOlrSzfbmQJJYanAByxF2plXQtkDybX8/5nwgM0xdtjBY2suhls6as Ap1Yo00IreihXYoc6JR4QjfeyyeJGnWaoazVyCLYZ5Lbo+9JSv4oRMbVhgGShG2kqzEy tycAx7k9t1c5KCOUk3tpquMF9Kwk11Bx/H2bwLnRHaxqf0uCihqZcn0tgqE+SrL1I6Qh CAeOLylleLsOjDHXBOTunDICcemQkXNbYFqSgVd9OMVIh+x7bKwTlGzcHCxygszwsCs2 lm89hyiAXWNiYHSoGHz2Zt+HDWZe0pvW67nLskHwCqgjdw8oMjow2CeA2lGjSCSKCtI5 No4Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:cc:references:from:in-reply-to :content-transfer-encoding; bh=LDeSEeG6sYN/4I8BLWwVYheQ8YlAvLVklfd9fc7g84c=; b=0FtkXK3nz4i2QCC0VSPpn02NFULUaVfuESKOk8klPaODhAZs3R2FCK7pxHIkAIS8VZ WgFwQ7UOpFsysgmkpobfTdIhrWCmSg04YwU0geiQ6OIYmT5oP80BE8nx1fZH9hMPb83D crwsqng2+L7gZqc9csY9n9P8Gs75AsesE8do7YOggUD+b8S3O52NzlIP8hHTJa9tq4od SaMUFETQIeZzG9s5QtDnZqR4pEYcYlTL7JrnyhGlNuRZ+fnAnBiVowB5iGGvA5McTK+d QZmQxkhIHy3rbyTSJ6LrqKg3refjaG8zEn1NpXdzPkq0g9R6tolUIDEcgZPHGPaaoIbm MUIw== X-Gm-Message-State: AOAM5327PIglWdXc5A/Ggx+PJz+H7yNHtUXMP/HmBgHCEIRyD+C7he4I 9WoUqUZo/xP2s8x3Z2erBTgLz7XVQ2o= X-Received: by 2002:a05:6512:acb:b0:473:c2ad:efe5 with SMTP id n11-20020a0565120acb00b00473c2adefe5mr1453355lfu.290.1652398842909; Thu, 12 May 2022 16:40:42 -0700 (PDT) Received: from [192.168.2.145] (109-252-137-244.dynamic.spd-mgts.ru. [109.252.137.244]) by smtp.googlemail.com with ESMTPSA id h16-20020a05651211d000b0047255d2116dsm132208lfr.156.2022.05.12.16.40.41 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 12 May 2022 16:40:42 -0700 (PDT) Message-ID: <57bfc915-c761-3ba4-93d0-776f9b5f93b3@gmail.com> Date: Fri, 13 May 2022 02:40:41 +0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.5.0 Subject: Re: [PATCH v4 3/3] iio: light: Add support for ltrf216a sensor Content-Language: en-US To: Shreeya Patel , jic23@kernel.org, lars@metafoo.de, robh+dt@kernel.org, Zhigang.Shi@liteon.com, krisman@collabora.com Cc: linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, kernel@collabora.com, alvaro.soliverez@collabora.com References: <20220511094024.175994-1-shreeya.patel@collabora.com> <20220511094024.175994-4-shreeya.patel@collabora.com> From: Dmitry Osipenko In-Reply-To: <20220511094024.175994-4-shreeya.patel@collabora.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-4.6 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,NICE_REPLY_A, RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hello Shreeya, ... > +#include > +#include You may safely remove these includes because module.h always provides them. > +#include > +#include > +#include > +#include > +#include > + > +#define LTRF216A_DRV_NAME "ltrf216a" This define doesn't bring much benefits, you may use "ltrf216a" directly in the code. > +#define LTRF216A_MAIN_CTRL 0x00 > + > +#define LTRF216A_ALS_DATA_STATUS BIT(3) > +#define LTRF216A_ALS_ENABLE_MASK BIT(1) > + > +#define LTRF216A_ALS_MEAS_RES 0x04 > +#define LTRF216A_MAIN_STATUS 0x07 > +#define LTRF216A_CLEAR_DATA_0 0x0A > + Is any reason for separating these regs with a newline? If no, then you may remove this newline. > +#define LTRF216A_ALS_DATA_0 0x0D > + ... > +struct ltrf216a_data { > + struct i2c_client *client; > + u32 int_time; > + u16 int_time_fac; > + u8 als_gain_fac; > + /* > + * Ensure cached value of integration time is consistent > + * with hardware setting and remains constant during a > + * measurement of Lux. > + */ > + struct mutex mutex; I'd rename the "mutex" -> "lock". > +}; > + > +/* open air. need to update based on TP transmission rate. */ > +#define WIN_FAC 1 Usually all defines are placed before the code. You may move this define before struct ltrf216a_data. ... > +static int ltrf216a_init(struct iio_dev *indio_dev) > +{ > + int ret; > + struct ltrf216a_data *data = iio_priv(indio_dev); Reverse Xmas tree is a common coding style in kernel for the function variables. ****** **** ** Will be great if you could use the same coding style everywhere in this source file, i.e. like this: struct ltrf216a_data *data = iio_priv(indio_dev); int ret; > + ret = i2c_smbus_read_byte_data(data->client, LTRF216A_MAIN_CTRL); > + if (ret < 0) { > + dev_err(&data->client->dev, "Error reading LTRF216A_MAIN_CTRL\n"); > + return ret; > + } > + > + /* enable sensor */ > + ret |= FIELD_PREP(LTRF216A_ALS_ENABLE_MASK, 1); > + ret = i2c_smbus_write_byte_data(data->client, LTRF216A_MAIN_CTRL, ret); > + if (ret < 0) { > + dev_err(&data->client->dev, "Error writing LTRF216A_MAIN_CTRL\n"); This message doesn't tell us the error code, which usually is very handy to know. I'd also change all the error messages in this driver to tell which action failed, like this: dev_err(dev, "Failed to enable sensor: %d\n", ret); > + return ret; > + } > + > + return 0; > +} > + > +static int ltrf216a_disable(struct iio_dev *indio_dev) > +{ > + int ret; > + struct ltrf216a_data *data = iio_priv(indio_dev); > + > + ret = i2c_smbus_write_byte_data(data->client, LTRF216A_MAIN_CTRL, 0); > + if (ret < 0) > + dev_err(&data->client->dev, "Error writing LTRF216A_MAIN_CTRL\n"); Please add error code to the message here too and reword it. This is exactly the same error message as in ltrf216a_init(), so you can't distinguish whether it's enabling or disabling that failed. > + return ret; > +} > + > +static void als_ltrf216a_disable(void *data) > +{ > + struct iio_dev *indio_dev = data; > + > + ltrf216a_disable(indio_dev); > +} > + > +static int ltrf216a_set_int_time(struct ltrf216a_data *data, int itime) > +{ > + int i, ret, index = -1; > + u8 reg_val; > + > + for (i = 0; i < ARRAY_SIZE(ltrf216a_int_time_available); i++) { > + if (ltrf216a_int_time_available[i][1] == itime) { > + index = i; > + break; > + } > + } > + > + if (index < 0) > + return -EINVAL; > + > + reg_val = ltrf216a_int_time_reg[index][1]; > + data->int_time_fac = ltrf216a_int_time_reg[index][0]; > + > + ret = i2c_smbus_write_byte_data(data->client, LTRF216A_ALS_MEAS_RES, reg_val); > + if (ret < 0) > + return ret; Won't hurt to add error message here for consistency. > + data->int_time = itime; > + > + return 0; > +} > + > +static int ltrf216a_get_int_time(struct ltrf216a_data *data, int *val, int *val2) > +{ > + *val = 0; > + *val2 = data->int_time; > + return IIO_VAL_INT_PLUS_MICRO; > +} > + > +static int ltrf216a_read_data(struct ltrf216a_data *data, u8 addr) > +{ > + int ret = -1, tries = 25; No need to initialize the ret variable. > + u8 buf[3]; > + > + while (tries--) { > + ret = i2c_smbus_read_byte_data(data->client, LTRF216A_MAIN_STATUS); > + if (ret < 0) > + return ret; Need error message > + if (ret & LTRF216A_ALS_DATA_STATUS) > + break; > + msleep(20); > + } > + > + ret = i2c_smbus_read_i2c_block_data(data->client, addr, sizeof(buf), buf); > + if (ret < 0) > + return ret; Same here .. > +MODULE_AUTHOR("Shi Zhigang "); Driver could have multiple MODULE_AUTHOR(), you may add yourself here: MODULE_AUTHOR("Shreeya Patel ")