Linux-IIO Archive on lore.kernel.org
 help / color / Atom feed
From: Tomasz Duszynski <tduszyns@gmail.com>
To: Johan Hovold <johan@kernel.org>
Cc: Tomasz Duszynski <tduszyns@gmail.com>,
	linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org,
	devicetree@vger.kernel.org
Subject: Re: [PATCH 1/3] iio: chemical: add support for Plantower PMS7003 sensor
Date: Tue, 8 Jan 2019 20:07:57 +0100
Message-ID: <20190108190756.GA25862@arch> (raw)
In-Reply-To: <20190107153542.GD14782@localhost>

On Mon, Jan 07, 2019 at 04:35:42PM +0100, Johan Hovold wrote:
> On Sun, Jan 06, 2019 at 06:16:12PM +0100, Tomasz Duszynski wrote:
> > Add support for Plantower PMS7003 particulate matter sensor.
> >
> > Signed-off-by: Tomasz Duszynski <tduszyns@gmail.com>
>
> > +static int pms7003_do_cmd(struct pms7003_state *state, u8 cmd)
> > +{
> > +	/*
> > +	 * commands have following format:
> > +	 *
> > +	 * +------+------+-----+------+-----+-----------+-----------+
> > +	 * | 0x42 | 0x4d | cmd | 0x00 | arg | cksum msb | cksum lsb |
> > +	 * +------+------+-----+------+-----+-----------+-----------+
> > +	 */
> > +	u8 tmp[PMS7003_CMD_LENGTH] = { PMS7003_MAGIC_MSB, PMS7003_MAGIC_LSB };
> > +	int ret, n = 2;
> > +	u16 checksum;
> > +
> > +	switch (cmd) {
> > +	case CMD_WAKEUP:
> > +		tmp[n++] = 0xe4;
> > +		tmp[n++] = 0x00;
> > +		tmp[n++] = 0x01;
> > +		break;
> > +	case CMD_ENTER_PASSIVE_MODE:
> > +		tmp[n++] = 0xe1;
> > +		tmp[n++] = 0x00;
> > +		tmp[n++] = 0x00;
> > +		break;
> > +	case CMD_READ_PASSIVE:
> > +		tmp[n++] = 0xe2;
> > +		tmp[n++] = 0x00;
> > +		tmp[n++] = 0x00;
> > +		break;
> > +	case CMD_SLEEP:
> > +		tmp[n++] = 0xe4;
> > +		tmp[n++] = 0x00;
> > +		tmp[n++] = 0x00;
> > +		break;
> > +	}
> > +
> > +	checksum = pms7003_calc_checksum(tmp, n);
> > +	put_unaligned_be16(checksum, tmp + n);
> > +	n += PMS7003_CHECKSUM_LENGTH;
> > +
> > +	ret = serdev_device_write(state->serdev, tmp, n, PMS7003_TIMEOUT);
> > +	if (ret)
> > +		return ret;
>
> Beginning with 5.0, serdev_device_write() returns the number of bytes
> written before timeout (or being interrupted) so you need to check
> against < n here.
>

Right, on the second though that can be simplified by just ignoring
return value I guess. Anyway, thanks for pointing this out.

> Johan

  reply index

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-01-06 17:16 [PATCH 0/3] add support for PMS7003 PM sensor Tomasz Duszynski
2019-01-06 17:16 ` [PATCH 1/3] iio: chemical: add support for Plantower PMS7003 sensor Tomasz Duszynski
2019-01-07 15:35   ` Johan Hovold
2019-01-08 19:07     ` Tomasz Duszynski [this message]
2019-01-12 17:48   ` Jonathan Cameron
2019-01-23 21:08     ` Tomasz Duszynski
2019-01-06 17:16 ` [PATCH 2/3] dt-bindings: add Plantower to the vendor prefixes Tomasz Duszynski
2019-01-11 22:12   ` Rob Herring
2019-01-06 17:16 ` [PATCH 3/3] dt-bindings: iio: chemical: pms7003: add device tree support Tomasz Duszynski
2019-01-11 22:15   ` Rob Herring
2019-01-27 13:45     ` Tomasz Duszynski

Reply instructions:

You may reply publically to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190108190756.GA25862@arch \
    --to=tduszyns@gmail.com \
    --cc=devicetree@vger.kernel.org \
    --cc=johan@kernel.org \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Linux-IIO Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-iio/0 linux-iio/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-iio linux-iio/ https://lore.kernel.org/linux-iio \
		linux-iio@vger.kernel.org linux-iio@archiver.kernel.org
	public-inbox-index linux-iio


Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-iio


AGPL code for this site: git clone https://public-inbox.org/ public-inbox