From: Alan Cox <alan-qBU/x9rampVanCEyBjwyrvXRex20P6io@public.gmane.org>
To: Samu Onkalo <samu.p.onkalo-xNZwKgViW5gAvxtiuMwx3w@public.gmane.org>
Cc: linux-i2c-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Subject: Re: [PATCH 1/5] misc: Driver for bh1770glc / sfh7770 ALS and proximity sensor
Date: Tue, 5 Oct 2010 12:21:57 +0100 [thread overview]
Message-ID: <20101005122157.149f14d0@lxorguk.ukuu.org.uk> (raw)
In-Reply-To: <1286271779-19819-2-git-send-email-samu.p.onkalo-xNZwKgViW5gAvxtiuMwx3w@public.gmane.org>
On Tue, 5 Oct 2010 12:42:55 +0300
Samu Onkalo <samu.p.onkalo-xNZwKgViW5gAvxtiuMwx3w@public.gmane.org> wrote:
> This is a driver for ROHM BH1770GLC and OSRAM SFH7770 combined
> ALS and proximity sensor.
Same comment about regulators.
> +/* Supported stand alone rates in ms from chip data sheet */
> +static s16 prox_rates[] = {10, 20, 30, 40, 70, 100, 200, 500, 1000, 2000};
> +
> +/* Supported IR-led currents in mA */
> +static const u8 prox_curr_ma[] = {5, 10, 20, 50, 100, 150, 200};
> +
> +/* Supported stand alone rates in ms from chip data sheet */
> +static s16 lux_rates[] = {100, 200, 500, 1000, 2000};
Any reason only one of the three is const ?
> +static int bhsfh_prox_rates(struct bhsfh_chip *chip, int rate,
> + int rate_threshold)
> +{
> + int i;
> +
> + for (i = 0; i < ARRAY_SIZE(prox_rates); i++)
> + if (prox_rates[i] == rate) {
> + chip->prox_rate = i;
> + break;
> + }
> +
> + if (i == ARRAY_SIZE(prox_rates))
> + return -EINVAL;
> +
> + for (i = 0; i < ARRAY_SIZE(prox_rates); i++)
> + if (prox_rates[i] == rate_threshold) {
> + chip->prox_rate_threshold = i;
> + return 0;
> + }
> +
> + return -EINVAL;
This makes it hard for generic code. Wouldn't picking the best (first at
least as good as required) be a bit more polite to user space ?
> +static ssize_t bhsfh_lux_result_show(struct device *dev,
> + struct device_attribute *attr, char *buf)
> +{
> + struct bhsfh_chip *chip = dev_get_drvdata(dev);
> + ssize_t ret;
> +
> + mutex_lock(&chip->mutex);
> + if (pm_runtime_suspended(dev))
> + ret = -EIO; /* Chip is not enabled at all */
> + else if (chip->lux_wait_result)
> + ret = -EAGAIN; /* Waiting for result */
This makes no sense because you can't poll() a sysfs file
> +static ssize_t bhsfh_lux_calib_show(struct device *dev,
> + struct device_attribute *attr, char *buf)
> +{
> + struct bhsfh_chip *chip = dev_get_drvdata(dev);
> + return snprintf(buf, PAGE_SIZE, "%u\n", chip->lux_calib);
> +}
This is short chip->mutex locks as you sometimes temporarily change the
value (error path below)
> +
> +static ssize_t bhsfh_lux_calib_store(struct device *dev,
> + struct device_attribute *attr,
> + const char *buf, size_t len)
> +{
> + struct bhsfh_chip *chip = dev_get_drvdata(dev);
> + unsigned long value;
> + u32 old_calib;
> + u32 new_corr;
> +
> + if (strict_strtoul(buf, 0, &value))
> + return -EINVAL;
> +
> + mutex_lock(&chip->mutex);
> + old_calib = chip->lux_calib;
> + chip->lux_calib = value;
> + new_corr = bhsfh_get_corr_value(chip);
> + if (new_corr == 0) {
> + chip->lux_calib = old_calib;
> + mutex_unlock(&chip->mutex);
> + return -EINVAL;
> + }
> + chip->lux_corr = new_corr;
> + mutex_unlock(&chip->mutex);
> +
> + return len;
next prev parent reply other threads:[~2010-10-05 11:21 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-10-05 9:42 [PATCH 0/5] BH1770GLC, SFH7770 and APDS990x als / proximity sensor drivers Samu Onkalo
2010-10-05 9:42 ` [PATCH 1/5] misc: Driver for bh1770glc / sfh7770 ALS and proximity sensor Samu Onkalo
[not found] ` <1286271779-19819-2-git-send-email-samu.p.onkalo-xNZwKgViW5gAvxtiuMwx3w@public.gmane.org>
2010-10-05 11:21 ` Alan Cox [this message]
[not found] ` <20101005122157.149f14d0-qBU/x9rampVanCEyBjwyrvXRex20P6io@public.gmane.org>
2010-10-05 11:29 ` Onkalo Samu
2010-10-05 12:01 ` Alan Cox
[not found] ` <20101005130102.7690c484-qBU/x9rampVanCEyBjwyrvXRex20P6io@public.gmane.org>
2010-10-05 12:37 ` Onkalo Samu
2010-10-05 9:42 ` [PATCH 3/5] misc: Driver for APDS990X ALS and proximity sensors Samu Onkalo
[not found] ` <1286271779-19819-4-git-send-email-samu.p.onkalo-xNZwKgViW5gAvxtiuMwx3w@public.gmane.org>
2010-10-05 11:23 ` Alan Cox
2010-10-05 11:48 ` Onkalo Samu
2010-10-05 13:00 ` Alan Cox
[not found] ` <20101005140049.1f25bb24-qBU/x9rampVanCEyBjwyrvXRex20P6io@public.gmane.org>
2010-10-05 12:39 ` Onkalo Samu
[not found] ` <20101005122323.2d2870ee-qBU/x9rampVanCEyBjwyrvXRex20P6io@public.gmane.org>
2010-10-05 21:42 ` Mark Brown
[not found] ` <1286271779-19819-1-git-send-email-samu.p.onkalo-xNZwKgViW5gAvxtiuMwx3w@public.gmane.org>
2010-10-05 9:42 ` [PATCH 2/5] misc: update bhsfh driver to Kconfig and Makefile Samu Onkalo
2010-10-05 9:42 ` [PATCH 4/5] misc: update apds990x " Samu Onkalo
2010-10-05 9:42 ` [PATCH 5/5] Documentation: Short descriptions for bhsfh and apds990x drivers Samu Onkalo
[not found] ` <1286271779-19819-6-git-send-email-samu.p.onkalo-xNZwKgViW5gAvxtiuMwx3w@public.gmane.org>
2010-10-05 11:53 ` Jonathan Cameron
[not found] ` <4CAB11C7.8040408-KWPb1pKIrIJaa/9Udqfwiw@public.gmane.org>
2010-10-05 12:22 ` Onkalo Samu
2010-10-05 14:13 ` Jonathan Cameron
Reply instructions:
You may reply publicly 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=20101005122157.149f14d0@lxorguk.ukuu.org.uk \
--to=alan-qbu/x9rampvanceybjwyrvxrex20p6io@public.gmane.org \
--cc=linux-i2c-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=samu.p.onkalo-xNZwKgViW5gAvxtiuMwx3w@public.gmane.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
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox