From: Jonathan Cameron <jic23@kernel.org>
To: Brian Masney <masneyb@onstation.org>
Cc: linux-iio@vger.kernel.org, gregkh@linuxfoundation.org,
devel@driverdev.osuosl.org, knaack.h@gmx.de, lars@metafoo.de,
pmeerw@pmeerw.net, linux-kernel@vger.kernel.org,
Jon.Brenner@ams.com
Subject: Re: [PATCH 12/12] staging: iio: tsl2x7x: make proximity sensor function correctly
Date: Sat, 10 Mar 2018 14:56:30 +0000 [thread overview]
Message-ID: <20180310145630.73007f89@archlinux> (raw)
In-Reply-To: <20180304014942.18727-13-masneyb@onstation.org>
On Sat, 3 Mar 2018 20:49:42 -0500
Brian Masney <masneyb@onstation.org> wrote:
> The bits for setting up the proximity diode were not setup correctly and
> this was causing the proximity sensor to not function correctly. This
> patch sets up the correct bit mask in tsl2x7x_chip_on() based on what
> the data sheet expects. From page 35 of the TSL2771 data sheet:
> https://ams.com/eng/content/download/250264/976045/file/TSL2771_DS000105_3-00.pdf
>
> - Bits 0-1 is the ALS gain control
> - Bits 2-3 is reserved (The proximity gain control on other tsl2x7x chips)
> - Bits 4-5 is the proximity diode select
> - Bits 6-7 is the LED drive strength
>
> tsl2x7x_chip_on() had the power and diode hardcoded, so these are
> extracted out into the settings so that these fields can be configured
> in the platform data.
>
> The default prox_gain is changed from 1 (2X gain) to 0 (1X gain) since
> the proximity gain control on the TSL2771, TMD2771, and other chips have
> these fields listed as reserved, and to write 0 into those bits.
>
> Verified that the proximity sensor now works correctly on a TSL2771
> hooked up to a Raspberry Pi 2.
>
> Signed-off-by: Brian Masney <masneyb@onstation.org>
Applied to the togreg branch of iio.git and pushed out as testing for
the autobuilders to play with it.
So just patch 10 that needs a v2.
Thanks for the set - nearly there ;)
Jonathan
> ---
> drivers/staging/iio/light/tsl2x7x.c | 25 ++++++++++++++-----------
> drivers/staging/iio/light/tsl2x7x.h | 2 ++
> 2 files changed, 16 insertions(+), 11 deletions(-)
>
> diff --git a/drivers/staging/iio/light/tsl2x7x.c b/drivers/staging/iio/light/tsl2x7x.c
> index 8c29a52153c1..ab518cdec43e 100644
> --- a/drivers/staging/iio/light/tsl2x7x.c
> +++ b/drivers/staging/iio/light/tsl2x7x.c
> @@ -109,15 +109,15 @@
> #define TSL2X7X_CNTL_INTPROXPON_ENBL 0x2F
>
> /*Prox diode to use */
> -#define TSL2X7X_DIODE0 0x10
> -#define TSL2X7X_DIODE1 0x20
> -#define TSL2X7X_DIODE_BOTH 0x30
> +#define TSL2X7X_DIODE0 0x01
> +#define TSL2X7X_DIODE1 0x02
> +#define TSL2X7X_DIODE_BOTH 0x03
>
> /* LED Power */
> #define TSL2X7X_100_mA 0x00
> -#define TSL2X7X_50_mA 0x40
> -#define TSL2X7X_25_mA 0x80
> -#define TSL2X7X_13_mA 0xD0
> +#define TSL2X7X_50_mA 0x01
> +#define TSL2X7X_25_mA 0x02
> +#define TSL2X7X_13_mA 0x03
> #define TSL2X7X_MAX_TIMER_CNT 0xFF
>
> #define TSL2X7X_MIN_ITIME 3
> @@ -228,7 +228,7 @@ static const struct tsl2x7x_settings tsl2x7x_default_settings = {
> .als_time = 219, /* 101 ms */
> .als_gain = 0,
> .prx_time = 254, /* 5.4 ms */
> - .prox_gain = 1,
> + .prox_gain = 0,
> .wait_time = 245,
> .prox_config = 0,
> .als_gain_trim = 1000,
> @@ -240,7 +240,9 @@ static const struct tsl2x7x_settings tsl2x7x_default_settings = {
> .prox_thres_low = 0,
> .prox_thres_high = 512,
> .prox_max_samples_cal = 30,
> - .prox_pulse_count = 8
> + .prox_pulse_count = 8,
> + .prox_diode = TSL2X7X_DIODE1,
> + .prox_power = TSL2X7X_100_mA
> };
>
> static const s16 tsl2x7x_als_gain[] = {
> @@ -664,9 +666,10 @@ static int tsl2x7x_chip_on(struct iio_dev *indio_dev)
>
> /* Set the gain based on tsl2x7x_settings struct */
> chip->tsl2x7x_config[TSL2X7X_GAIN] =
> - chip->settings.als_gain |
> - (TSL2X7X_100_mA | TSL2X7X_DIODE1) |
> - (chip->settings.prox_gain << 2);
> + (chip->settings.als_gain & 0xFF) |
> + ((chip->settings.prox_gain & 0xFF) << 2) |
> + (chip->settings.prox_diode << 4) |
> + (chip->settings.prox_power << 6);
>
> /* set chip struct re scaling and saturation */
> chip->als_saturation = als_count * 922; /* 90% of full scale */
> diff --git a/drivers/staging/iio/light/tsl2x7x.h b/drivers/staging/iio/light/tsl2x7x.h
> index 6624cbca7a83..28b0e7fdc9b8 100644
> --- a/drivers/staging/iio/light/tsl2x7x.h
> +++ b/drivers/staging/iio/light/tsl2x7x.h
> @@ -78,6 +78,8 @@ struct tsl2x7x_settings {
> int prox_thres_high;
> int prox_pulse_count;
> int prox_max_samples_cal;
> + int prox_diode;
> + int prox_power;
> };
>
> /**
prev parent reply other threads:[~2018-03-10 14:56 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-03-04 1:49 [PATCH 00/12] staging cleanups Brian Masney
2018-03-04 1:49 ` [PATCH 01/12] staging: iio: tsl2x7x: remove power functions from tsl2X7X_platform_data Brian Masney
2018-03-10 14:20 ` Jonathan Cameron
2018-03-04 1:49 ` [PATCH 02/12] staging: iio: tsl2x7x: add common function for clearing interrupts Brian Masney
2018-03-10 14:27 ` Jonathan Cameron
2018-03-04 1:49 ` [PATCH 03/12] staging: iio: tsl2x7x: add common function for reading chip status Brian Masney
2018-03-10 14:34 ` Jonathan Cameron
2018-03-04 1:49 ` [PATCH 04/12] staging: iio: tsl2x7x: add common function for writing to the control register Brian Masney
2018-03-10 14:36 ` Jonathan Cameron
2018-03-04 1:49 ` [PATCH 05/12] staging: iio: tsl2x7x: convert mutex_trylock() to mutex_lock() Brian Masney
2018-03-10 14:39 ` Jonathan Cameron
2018-03-04 1:49 ` [PATCH 06/12] staging: iio: tsl2x7x: correctly return errors in tsl2x7x_get_prox() Brian Masney
2018-03-10 14:42 ` Jonathan Cameron
2018-03-04 1:49 ` [PATCH 07/12] staging: iio: tsl2x7x: correct 'Avoid CamelCase' warning from checkpatch Brian Masney
2018-03-10 14:43 ` Jonathan Cameron
2018-03-04 1:49 ` [PATCH 08/12] staging: iio: tsl2x7x: add error handling to tsl2x7x_prox_cal() Brian Masney
2018-03-10 14:44 ` Jonathan Cameron
2018-03-04 1:49 ` [PATCH 09/12] staging: iio: tsl2x7x: add missing error checks Brian Masney
2018-03-10 14:45 ` Jonathan Cameron
2018-03-04 1:49 ` [PATCH 10/12] staging: iio: tsl2x7x: make logging consistent and correct newlines Brian Masney
2018-03-10 14:52 ` Jonathan Cameron
2018-03-11 13:45 ` Jonathan Cameron
2018-03-04 1:49 ` [PATCH 11/12] staging: iio: tsl2x7x: remove unnecessary sysfs attribute Brian Masney
2018-03-10 14:54 ` Jonathan Cameron
2018-03-04 1:49 ` [PATCH 12/12] staging: iio: tsl2x7x: make proximity sensor function correctly Brian Masney
2018-03-10 14:56 ` Jonathan Cameron [this message]
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=20180310145630.73007f89@archlinux \
--to=jic23@kernel.org \
--cc=Jon.Brenner@ams.com \
--cc=devel@driverdev.osuosl.org \
--cc=gregkh@linuxfoundation.org \
--cc=knaack.h@gmx.de \
--cc=lars@metafoo.de \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=masneyb@onstation.org \
--cc=pmeerw@pmeerw.net \
/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