From: Brian Masney <masneyb@onstation.org>
To: jic23@kernel.org, robh+dt@kernel.org, mark.rutland@arm.com,
andy.gross@linaro.org, david.brown@linaro.org,
linux-iio@vger.kernel.org, devicetree@vger.kernel.org,
linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org,
linux-soc@vger.kernel.org
Cc: jonathan@marek.ca, jmaneyrol@invensense.com, knaack.h@gmx.de,
lars@metafoo.de, pmeerw@pmeerw.net, mkelly@xevo.com,
fischerdouglasc@gmail.com, bshah@kde.org, ctatlor97@gmail.com
Subject: [PATCH v3 3/9] iio: tsl2772: add support for reading proximity led settings from device tree
Date: Thu, 2 Aug 2018 20:18:54 -0400 [thread overview]
Message-ID: <20180803001900.25371-4-masneyb@onstation.org> (raw)
In-Reply-To: <20180803001900.25371-1-masneyb@onstation.org>
This patch adds support for optionally reading the proximity led diode
and current settings from device tree. This was tested using a LG
Nexus 5 (hammerhead) which requires a different diode than the driver
default for the IR LED.
Signed-off-by: Brian Masney <masneyb@onstation.org>
---
drivers/iio/light/tsl2772.c | 81 +++++++++++++++++++++++++++++++++++++
1 file changed, 81 insertions(+)
diff --git a/drivers/iio/light/tsl2772.c b/drivers/iio/light/tsl2772.c
index df5b2a0da96c..ae00edf0d87e 100644
--- a/drivers/iio/light/tsl2772.c
+++ b/drivers/iio/light/tsl2772.c
@@ -107,6 +107,8 @@
#define TSL2772_ALS_GAIN_TRIM_MIN 250
#define TSL2772_ALS_GAIN_TRIM_MAX 4000
+#define TSL2772_MAX_PROX_LEDS 2
+
/* Device family members */
enum {
tsl2571,
@@ -141,6 +143,14 @@ struct tsl2772_chip_info {
const struct iio_info *info;
};
+static const int tsl2772_led_currents[][2] = {
+ { 100000, TSL2772_100_mA },
+ { 50000, TSL2772_50_mA },
+ { 25000, TSL2772_25_mA },
+ { 13000, TSL2772_13_mA },
+ { 0, 0 }
+};
+
struct tsl2772_chip {
kernel_ulong_t id;
struct mutex prox_mutex;
@@ -515,6 +525,75 @@ static int tsl2772_get_prox(struct iio_dev *indio_dev)
return ret;
}
+static int tsl2772_read_prox_led_current(struct tsl2772_chip *chip)
+{
+ struct device_node *of_node = chip->client->dev.of_node;
+ int ret, tmp, i;
+
+ ret = of_property_read_u32(of_node, "led-max-microamp", &tmp);
+ if (ret < 0)
+ return ret;
+
+ for (i = 0; tsl2772_led_currents[i][0] != 0; i++) {
+ if (tmp == tsl2772_led_currents[i][0]) {
+ chip->settings.prox_power = tsl2772_led_currents[i][1];
+ return 0;
+ }
+ }
+
+ dev_err(&chip->client->dev, "Invalid value %d for led-max-microamp\n",
+ tmp);
+
+ return -EINVAL;
+
+}
+
+static int tsl2772_read_prox_diodes(struct tsl2772_chip *chip)
+{
+ struct device_node *of_node = chip->client->dev.of_node;
+ int i, ret, num_leds, prox_diode_mask;
+ u32 leds[TSL2772_MAX_PROX_LEDS];
+
+ ret = of_property_count_u32_elems(of_node, "amstaos,proximity-diodes");
+ if (ret < 0)
+ return ret;
+
+ num_leds = ret;
+ if (num_leds > TSL2772_MAX_PROX_LEDS)
+ num_leds = TSL2772_MAX_PROX_LEDS;
+
+ ret = of_property_read_u32_array(of_node, "amstaos,proximity-diodes",
+ leds, num_leds);
+ if (ret < 0) {
+ dev_err(&chip->client->dev,
+ "Invalid value for amstaos,proximity-diodes: %d.\n",
+ ret);
+ return ret;
+ }
+
+ prox_diode_mask = 0;
+ for (i = 0; i < num_leds; i++) {
+ if (leds[i] == 0)
+ prox_diode_mask |= TSL2772_DIODE0;
+ else if (leds[i] == 1)
+ prox_diode_mask |= TSL2772_DIODE1;
+ else {
+ dev_err(&chip->client->dev,
+ "Invalid value %d in amstaos,proximity-diodes.\n",
+ leds[i]);
+ return -EINVAL;
+ }
+ }
+
+ return 0;
+}
+
+static void tsl2772_parse_dt(struct tsl2772_chip *chip)
+{
+ tsl2772_read_prox_led_current(chip);
+ tsl2772_read_prox_diodes(chip);
+}
+
/**
* tsl2772_defaults() - Populates the device nominal operating parameters
* with those provided by a 'platform' data struct or
@@ -541,6 +620,8 @@ static void tsl2772_defaults(struct tsl2772_chip *chip)
memcpy(chip->tsl2772_device_lux,
tsl2772_default_lux_table_group[chip->id],
TSL2772_DEFAULT_TABLE_BYTES);
+
+ tsl2772_parse_dt(chip);
}
/**
--
2.17.1
next prev parent reply other threads:[~2018-08-03 0:19 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-08-03 0:18 [PATCH v3 0/9] treewide: add support for various sensors on the LG Nexus 5 (hammerhead) Brian Masney
2018-08-03 0:18 ` [PATCH v3 1/9] iio: imu: mpu6050: add support for regulator framework Brian Masney
2018-08-03 21:44 ` Jonathan Cameron
2018-08-03 0:18 ` [PATCH v3 2/9] ARM: dts: qcom: msm8974-hammerhead: add device tree bindings for mpu6515 Brian Masney
2018-08-03 21:46 ` Jonathan Cameron
2018-08-03 0:18 ` Brian Masney [this message]
2018-08-18 17:04 ` [PATCH v3 3/9] iio: tsl2772: add support for reading proximity led settings from device tree Jonathan Cameron
2018-08-03 0:18 ` [PATCH v3 4/9] dt-bindings: iio: tsl2772: add new bindings Brian Masney
2018-08-03 21:48 ` Jonathan Cameron
2018-08-07 16:54 ` Rob Herring
2018-08-18 17:01 ` Jonathan Cameron
2018-08-03 0:18 ` [PATCH v3 5/9] iio: tsl2772: add support for regulator framework Brian Masney
2018-08-03 21:50 ` Jonathan Cameron
2018-08-03 0:18 ` [PATCH v3 6/9] dt-bindings: iio: tsl2772: add bindings " Brian Masney
2018-08-03 21:51 ` Jonathan Cameron
2018-08-07 17:20 ` Rob Herring
2018-08-18 17:02 ` Jonathan Cameron
2018-08-03 0:18 ` [PATCH v3 7/9] iio: tsl2772: add support for avago,apds9930 Brian Masney
2018-08-03 21:53 ` Jonathan Cameron
2018-08-18 17:07 ` Jonathan Cameron
2018-08-03 0:18 ` [PATCH v3 8/9] dt-bindings: iio: tsl2772: add binding " Brian Masney
2018-08-03 21:54 ` Jonathan Cameron
2018-08-07 17:21 ` Rob Herring
2018-08-18 17:06 ` Jonathan Cameron
2018-08-03 0:19 ` [PATCH v3 9/9] ARM: dts: qcom: msm8974-hammerhead: add device tree bindings for ALS / proximity Brian Masney
2018-08-18 17:09 ` 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=20180803001900.25371-4-masneyb@onstation.org \
--to=masneyb@onstation.org \
--cc=andy.gross@linaro.org \
--cc=bshah@kde.org \
--cc=ctatlor97@gmail.com \
--cc=david.brown@linaro.org \
--cc=devicetree@vger.kernel.org \
--cc=fischerdouglasc@gmail.com \
--cc=jic23@kernel.org \
--cc=jmaneyrol@invensense.com \
--cc=jonathan@marek.ca \
--cc=knaack.h@gmx.de \
--cc=lars@metafoo.de \
--cc=linux-arm-msm@vger.kernel.org \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-soc@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=mkelly@xevo.com \
--cc=pmeerw@pmeerw.net \
--cc=robh+dt@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
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
all inboxes | Powered by JetHome®