dt-bindings: iio: light: ROHM BH1745
Subsystems (3)
Mudit Sharma
maintainerPATCH v5 1/2 dt-bindings: iio: light: ROHM BH1745
Add ROHM BH1745 - 4 channel I2C colour sensor's dt-bindings.
---v4->v5:
- Add power supply infov3->v4:
- No changesv2->v3:
- Move 'additionalProperties' after 'required' block
- Remove block style indicator '|' from description v1->v2:
- Fix yaml issue: Make maintainers a list
.../bindings/iio/light/rohm,bh1745.yaml | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 Documentation/devicetree/bindings/iio/light/rohm,bh1745.yaml
Documentation/devicetree/bindings/iio/light/rohm,bh1745.yaml new file +53 -0
@@ -0,0 +1,53 @@ +# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/iio/light/rohm,bh1745.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: ROHM BH1745 colour sensor + +maintainers: + - Mudit Sharma <[email protected]> + +description: + BH1745 is an I2C colour sensor with red, green, blue and clear + channels. It has a programmable active low interrupt pin. + Interrupt occurs when the signal from the selected interrupt + source channel crosses set interrupt threshold high/low level. + +properties: + compatible: + const: rohm,bh1745 + + reg: + maxItems: 1 + + interrupts: + maxItems: 1 + + vdd-supply: true + +required: + - compatible + - reg + - vdd-supply + +additionalProperties: false + +examples: + - | + #include <dt-bindings/interrupt-controller/irq.h> + i2c { + #address-cells = <1>; + #size-cells = <0>; + + colour-sensor@38 { + compatible = "rohm,bh1745"; + reg = <0x38>; + interrupt-parent = <&gpio>; + interrupts = <19 IRQ_TYPE_LEVEL_LOW>; + vdd-supply = <&vdd>; + }; + }; + +...
Signature · 1 line
2.43.0
Mudit Sharma
maintainerPATCH v5 2/2 iio: light: ROHM BH1745 colour sensor
Add support for BH1745, which is an I2C colour sensor with red, green, blue and clear channels. It has a programmable active low interrupt pin. Interrupt occurs when the signal from the selected interrupt source channel crosses set interrupt threshold high or low level.
Interrupt source for the device can be configured by enabling the corresponding event and interrupt latch is always enabled when setting up interrupt.
Add myself as the maintainer for this driver in MAINTAINERS.
---v4->v5:
- Provide scale instead of HW gain
- Use GTS helpers
- Code style fixes
- Add check for part ID during probe
- Always enable latch when enabling interrupt
- Use devm_add_action_or_reset() and drop bh1745_remove() function
- Drop custom DEVICE_ATTR and provide related read_avail and setup interrupt source with event_config
- Make buffer support independent of IRQ
- Add power regulator handing with devm_regulator_get_enable()
- Drop read and write wrappers and use regmap functions directly
- Add MODULE_DEVICE_TABLE for of_device_idv3->v4:
- Fix formatting:
- Remove redundant new line
- Use '0x' rather than '0X'v2->v3:
- Squash commit for addition to MAINTAINERS
- Fix code style for consistency:
- New line before last 'return'
- Use variable name 'value' instead of 'val' in
'bh1745_set_trigger_state()'
- Align function parameters to match parenthesis
- Avoid use of magic number
- Use named enum instead of anonymous enum
- Use 'guard(mutex)(&data->lock)' instead of 'mutex_lock()' 'mutex_unlock()'
- Only initialize 'ret' and 'value' when necessary
- Fix and optimize logic for in_interrupt_latch_store()
- Fix error handling in irq , trigger handlers and dev attribute for latchv1->v2:
- No changes
MAINTAINERS | 6 + drivers/iio/light/Kconfig | 13 + drivers/iio/light/Makefile | 1 + drivers/iio/light/bh1745.c | 936 +++++++++++++++++++++++++++++++++++++ 4 files changed, 956 insertions(+) create mode 100644 drivers/iio/light/bh1745.c
MAINTAINERS +6 -0
@@ -19404,6 +19404,12 @@ S: Supported F: drivers/power/supply/bd99954-charger.c F: drivers/power/supply/bd99954-charger.h +ROHM BH1745 COLOUR SENSOR +M: Mudit Sharma <[email protected]> +L: [email protected] +S: Maintained +F: drivers/iio/light/bh1745.c + ROHM BH1750 AMBIENT LIGHT SENSOR DRIVER M: Tomasz Duszynski <[email protected]> S: Maintained
drivers/iio/light/Kconfig +13 -0
@@ -114,6 +114,19 @@ config AS73211 This driver can also be built as a module. If so, the module will be called as73211. +config BH1745 + tristate "ROHM BH1745 colour sensor" + depends on I2C + select REGMAP_I2C + select IIO_BUFFER + select IIO_TRIGGERED_BUFFER + select IIO_GTS_HELPER + help + Say Y here to build support for the ROHM bh1745 colour sensor. + + To compile this driver as a module, choose M here: the module will + be called bh1745. + config BH1750 tristate "ROHM BH1750 ambient light sensor" depends on I2C
drivers/iio/light/Makefile +1 -0
@@ -13,6 +13,7 @@ obj-$(CONFIG_APDS9300) += apds9300.o obj-$(CONFIG_APDS9306) += apds9306.o obj-$(CONFIG_APDS9960) += apds9960.o obj-$(CONFIG_AS73211) += as73211.o +obj-$(CONFIG_BH1745) += bh1745.o obj-$(CONFIG_BH1750) += bh1750.o obj-$(CONFIG_BH1780) += bh1780.o obj-$(CONFIG_CM32181) += cm32181.o
drivers/iio/light/bh1745.c new file +936 -0
936 lines not on this page · raw message
Signature · 1 line
2.43.0
Re: [PATCH v5 2/2] iio: light: ROHM BH1745 colour sensor
Quoted 9 lines · Mudit Sharma
Add support for BH1745, which is an I2C colour sensor with red, green, blue and clear channels. It has a programmable active low interrupt pin. Interrupt occurs when the signal from the selected interrupt source channel crosses set interrupt threshold high or low level.
Interrupt source for the device can be configured by enabling the corresponding event and interrupt latch is always enabled when setting up interrupt.
Quoted 6 lines
Add myself as the maintainer for this driver in
MAINTAINERS.Signed-off-by Mudit Sharma <[email protected]>Reviewed-by Ivan Orlov <[email protected]>Reviewed-by Javier Carrasco <[email protected]>---
Hi Mudit, some minor comments inline form my side.
...
drivers/iio/light/bh1745.c line 139
Quoted 4 lines
drivers/iio/light/bh1745.c new file +4
-0+ +struct bh1745_data { +/* +* Lock to prevent device setting update or read before related
typo: calculations. I would recommend you to use checkpatch.pl --codespell to cach such typos.
Quoted 10 lines
drivers/iio/light/bh1745.c new file +10
-0+* caluculations or event push are completed +*/ +struct mutex lock; +struct regmap *regmap; +struct i2c_client *client; +struct iio_trigger *trig; +struct iio_gts gts; +u8 int_src; +}; +
...
drivers/iio/light/bh1745.c line 279
Quoted 5 lines
drivers/iio/light/bh1745.c new file +5
-0+static int bh1745_int_time_to_us (int val,int val2) +{ +for (u8 i =0 ; i <ARRAY_SIZE (bh1745_int_time); i++) { +if (val == bh1745_int_time[i][0 ] && val2 == bh1745_int_time[i][1 ]) +return bh1745_int_time_us[i];
Nit: unnecessary blank line before a close brace.
Quoted 5 lines
drivers/iio/light/bh1745.c new file +5
-0+ + } + +return -EINVAL ; +}
...
drivers/iio/light/bh1745.c line 456
Quoted 11 lines
drivers/iio/light/bh1745.c new file +11
-0+static int bh1745_read_raw (struct iio_dev *indio_dev, +struct iio_chan_spec const *chan, +int *val,int *val2,long mask) +{ +struct bh1745_data *data =iio_priv (indio_dev); +int ret; +int value; + +switch (mask) { +case IIO_CHAN_INFO_RAW : { + iio_device_claim_direct_scoped(return -EBUSY, indio_dev) {
Missing scope indentation.
Quoted 10 lines
drivers/iio/light/bh1745.c new file +10
-0+ ret =regmap_bulk_read (data->regmap, chan->address, &value,2 ); +if (ret) +return ret; + *val = value; + +return IIO_VAL_INT ; + } +unreachable (); + } +
...
drivers/iio/light/bh1745.c line 708
Quoted 3 lines
drivers/iio/light/bh1745.c new file +3
-0+static int bh1745_set_trigger_state (struct iio_trigger *trig,bool state) +{ +int ret;
Why is value initialized here? If regmap returns an error, you will not use value anyway. I caught my eye because it is initialized here, and not in the other functions where you use the same pattern.
Quoted 8 lines
drivers/iio/light/bh1745.c new file +8
-0+int value =0 ; +struct iio_dev *indio_dev =iio_trigger_get_drvdata (trig); +struct bh1745_data *data =iio_priv (indio_dev); + +guard (mutex)(&data->lock); +if (state) { + ret =regmap_read (data->regmap,BH1745_INTR , &value); +if (ret)
drivers/iio/light/bh1745.c line 726
Quoted 10 lines
drivers/iio/light/bh1745.c new file +10
-0+return ret; +// Latch is always set when enabling interrupt + value |=BH1745_INT_ENABLE | +FIELD_PREP (BH1745_INT_SIGNAL_LATCHED ,1 ) | +FIELD_PREP (BH1745_INT_SOURCE_MASK , data->int_src); +return regmap_write (data->regmap,BH1745_INTR , value); + } + +return regmap_write (data->regmap,BH1745_INTR , value); +}
Best regards,
Javier Carrasco
Mudit Sharma
maintainerRe: [PATCH v5 2/2] iio: light: ROHM BH1745 colour sensor
Quoted 8 lines · Javier Carrasco
drivers/iio/light/bh1745.c line 708
Quoted 4 lines
drivers/iio/light/bh1745.c new file +3
-0+static int bh1745_set_trigger_state (struct iio_trigger *trig,bool state) +{ +int ret;Why is value initialized here? If regmap returns an error, you will not use value anyway. I caught my eye because it is initialized here, and not in the other functions where you use the same pattern.
Hi Javier,
Thank you for the review on this.
'value' is initialized here for case when we un-set the trigger. In that case, 'state' will be false and 'value' of 0 (default value for BH1745_INTR register) will be written.
Best regards,
Mudit Sharma
Quoted 24 lines
Quoted 9 lines
drivers/iio/light/bh1745.c new file +8
-0+int value =0 ; +struct iio_dev *indio_dev =iio_trigger_get_drvdata (trig); +struct bh1745_data *data =iio_priv (indio_dev); + +guard (mutex)(&data->lock); +if (state) { + ret =regmap_read (data->regmap,BH1745_INTR , &value); +if (ret)drivers/iio/light/bh1745.c line 726
Quoted 10 lines
drivers/iio/light/bh1745.c new file +10
-0+return ret; +// Latch is always set when enabling interrupt + value |=BH1745_INT_ENABLE | +FIELD_PREP (BH1745_INT_SIGNAL_LATCHED ,1 ) | +FIELD_PREP (BH1745_INT_SOURCE_MASK , data->int_src); +return regmap_write (data->regmap,BH1745_INTR , value); + } + +return regmap_write (data->regmap,BH1745_INTR , value); +}Best regards,
Javier Carrasco
Re: [PATCH v5 2/2] iio: light: ROHM BH1745 colour sensor
Quoted 11 lines · Mudit Sharma
Quoted 9 lines · Javier Carrasco
Quoted 5 lines
+static int
bh1745_set_trigger_state(struct iio_trigger *trig, bool state)
+{
+ int ret;Why is value initialized here? If regmap returns an error, you will not use value anyway. I caught my eye because it is initialized here, and not in the other functions where you use the same pattern.
Quoted 8 lines
Hi Javier,
Thank you for the review on this.
'value' is initialized here for case when we un-set the trigger. In that case, 'state' will be false and 'value' of 0 (default value for
BH1745_INTRregister) will be written.
I missed that case. Thanks for clarifying.
By the way, it might be beneficial to wait a bit longer before sending a new version to give more reviewers a chance to look at your series.
24 hours might be a bit too short, and your version count could easily skyrocket if more reviewers get involved.
Best regards,
Javier Carrasco