Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp1451248ybg; Tue, 2 Jun 2020 10:16:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzn471cTldTziBIJk8k71oOM7YdNPwwRYeclvCxnv5s9ciRUAS2X/wgGenGMv5OqUvchHlI X-Received: by 2002:a17:906:1841:: with SMTP id w1mr17937624eje.21.1591118204322; Tue, 02 Jun 2020 10:16:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591118204; cv=none; d=google.com; s=arc-20160816; b=vZoG8jGkJtEpM0AImFpwslcAiNVjWR5tpCT4kazGZnMbPoWrsc4qk1ZQiDFN3LxwH/ If2ZvhmPjzavP5xPAH3noS6/EnhoSWyKQd/A5ch7KX1syDwRy8Iz7s0nd51qTnfS3SZG ogvcE6iYfPj/98CejseEE8oWsKQILvaApNhnkClnT21he7E5n5tovFr2KjjlZMnp688d lNc4doadi3jjDgMgiPcQ3xKAHM1+v5G+QQMxJLnfGyLRq42Pyxyfb3+uE95zCiRUl1Nj Jba4BnZ6TqOVPekgBFZEw/KUSHkdwrPl8KqVm43kD6KiD3NfQHEraA/4QMT6kK+4A4H1 y9dg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=yDKEOQW3zzKg27PHbCCQiuGUgsLSAgNyAkY4CZ592P8=; b=Z0TSelGglJafMRMq66A1SI0S/ewx3HDl5OW+FD/8uh9OHHXbXJaZQXpuwAFsJzWSBk aS8LO2hBStbV6HvXtpS9OwerT4Scc09pflw6KkcM8XUqH6TlFhd2fau953fsMdn+oqQR hKXeBCv54r2ku6q+ct/ZQH09v5T6VbP/KrHayVR4HcecG9vbS9nox0xJUtQ1XTuTn2eV diOW5hlYid9wLE0hdyUarN8sF8v2fqkYTWoSHQZRQTZbUiNN0bxQvQHV4urxOBeWNlUh EQ+SAS+IiG2i3QO0xg1pISRKq4puHW0Yz+ew3npf+Pv5iUmvZ/Pze8sJutXbdy+yX7ml Tiqw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=QX2NqYaK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id n10si1771985ejj.375.2020.06.02.10.16.20; Tue, 02 Jun 2020 10:16:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=QX2NqYaK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726373AbgFBRO0 (ORCPT + 99 others); Tue, 2 Jun 2020 13:14:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56524 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725969AbgFBRO0 (ORCPT ); Tue, 2 Jun 2020 13:14:26 -0400 Received: from mail-pf1-x441.google.com (mail-pf1-x441.google.com [IPv6:2607:f8b0:4864:20::441]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2E540C05BD1E; Tue, 2 Jun 2020 10:14:26 -0700 (PDT) Received: by mail-pf1-x441.google.com with SMTP id f3so5322103pfd.11; Tue, 02 Jun 2020 10:14:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=yDKEOQW3zzKg27PHbCCQiuGUgsLSAgNyAkY4CZ592P8=; b=QX2NqYaKI02lh99tfRoYpKssbJuXJc/viEZOCaPdRM99I9ujjBp6i7QH/PeX/tZycn WHBIWtyV1hP5huS546uhTOS+LThr94j5tz6Ytm7yuUDzP2Ntot5OEccGlPDIQcSd3Vza T6nqJAtB+XUcaulomzKKodYKIKUqrmvs/z6fwSZt3tlF4ppjuV1+UdpNxDp7fedu6Trm nyH6xrjmVUrdc5dfTAoe3+DXAoH2LaOxhP4E1+pcwa5lEKXB75YVOskFvj2+TKK2Kj+z sV28XsrrAossb/smm1uc9+CHSs2wJUHOM2G4mtFcNetg+Mum+uyipAAlRzjYDaGn8UsF DtYw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=yDKEOQW3zzKg27PHbCCQiuGUgsLSAgNyAkY4CZ592P8=; b=KG/9NOJb0egoZDv9CI1zHoKprhCqSsr8vX6oLpbgsay8Oivvot2MA2+GepVtQdYs67 UHEhA9piFGTGTXx29TK0BKSsTyfhUlCEIw7ZczbIgUedGPzlkJaICseSax7gOlWn7zXA rFdO5w3k6doUpmnClQ6pcLQ/f2M2xJecyD1aMlMsTCTotkcY5BP+tPA9hB+hdKNn2rKF QzGCdti+qtD7rDZ7n/NHnjTim+JBzYyd2G/AR4aGx0kx4Hds30WzY/TE16UUyTgRplVJ wiVXFtLXDBkIWpU3j7l//bpTWwNo7TvTRP34VW5OxIDRWJO1tCvXq64sCDWCE1SL1y4/ ZOPQ== X-Gm-Message-State: AOAM533sByq5Phfliyv/omYYQ0bbvTdVgrUkAitBzpKVtMm7ygbnnexf H8wW14Ti7pSzeeBQ6iP05LNoU7qEDu3BF2HiGPU= X-Received: by 2002:a63:305:: with SMTP id 5mr24196734pgd.74.1591118065723; Tue, 02 Jun 2020 10:14:25 -0700 (PDT) MIME-Version: 1.0 References: <20200602164723.28858-1-tomasz.duszynski@octakon.com> <20200602164723.28858-3-tomasz.duszynski@octakon.com> In-Reply-To: <20200602164723.28858-3-tomasz.duszynski@octakon.com> From: Andy Shevchenko Date: Tue, 2 Jun 2020 20:14:13 +0300 Message-ID: Subject: Re: [PATCH v3 2/4] iio: chemical: scd30: add I2C interface driver To: Tomasz Duszynski Cc: linux-iio , Linux Kernel Mailing List , devicetree , Rob Herring , Jonathan Cameron , Peter Meerwald Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jun 2, 2020 at 7:49 PM Tomasz Duszynski wrote: > > Add I2C interface driver for the SCD30 sensor. ... > +static u16 scd30_i2c_cmd_lookup_tbl[] = { > + [CMD_START_MEAS] = 0x0010, > + [CMD_STOP_MEAS] = 0x0104, > + [CMD_MEAS_INTERVAL] = 0x4600, > + [CMD_MEAS_READY] = 0x0202, > + [CMD_READ_MEAS] = 0x0300, > + [CMD_ASC] = 0x5306, > + [CMD_FRC] = 0x5204, > + [CMD_TEMP_OFFSET] = 0x5403, > + [CMD_FW_VERSION] = 0xd100, > + [CMD_RESET] = 0xd304, Keep sorted by value? > +}; ... > + ret = i2c_master_send(client, txbuf, txsize); > + if (ret != txsize) > + return ret < 0 ? ret : -EIO; Wouldn't be better if (ret < 0) return ret; if (ret != txsize) return -EIO; ? > + if (!rxbuf) > + return 0; > + > + ret = i2c_master_recv(client, rxbuf, rxsize); > + if (ret != rxsize) > + return ret < 0 ? ret : -EIO; Ditto. ... > +static int scd30_i2c_command(struct scd30_state *state, enum scd30_cmd cmd, > + u16 arg, void *response, int size) > +{ > + char crc, buf[SCD30_I2C_MAX_BUF_SIZE], *rsp = response; > + int i, ret; i -> offset ? > + put_unaligned_be16(scd30_i2c_cmd_lookup_tbl[cmd], buf); > + i = 2; > + > + if (rsp) { > + /* each two bytes are followed by a crc8 */ > + size += size / 2; > + } else { > + put_unaligned_be16(arg, buf + i); > + crc = crc8(scd30_i2c_crc8_tbl, buf + i, 2, CRC8_INIT_VALUE); > + i += 2; > + buf[i] = crc; > + i += 1; buf[offset++] = crc; ? > + /* commands below don't take an argument */ > + if ((cmd == CMD_STOP_MEAS) || (cmd == CMD_RESET)) > + i -= 3; > + } > + > + ret = scd30_i2c_xfer(state, buf, i, buf, size); > + if (ret) > + return ret; > + > + /* validate received data and strip off crc bytes */ > + for (i = 0; i < size; i += 3) { > + crc = crc8(scd30_i2c_crc8_tbl, buf + i, 2, CRC8_INIT_VALUE); > + if (crc != buf[i + 2]) { > + dev_err(state->dev, "data integrity check failed\n"); > + return -EIO; > + } > + > + *rsp++ = buf[i]; + 0 (for the sake of consistency? > + *rsp++ = buf[i + 1]; > + } > + > + return 0; > +} ... > +static struct i2c_driver scd30_i2c_driver = { > + .driver = { > + .name = KBUILD_MODNAME, Better to hard code. > + .of_match_table = scd30_i2c_of_match, > + .pm = &scd30_pm_ops, > + }, > + .probe_new = scd30_i2c_probe, > +}; -- With Best Regards, Andy Shevchenko