iio: light: Added CM36672 Proximity Sensor Driver.
Quoted 4 lines · Kevin Tsai
Added Vishay Capella CM36672 Proximity Sensor IIO driver. Support both ACPI and Device Tree.
Signed-off-by Kevin Tsai <[email protected]>
Aha OK...
Review
Quoted 8 lines
(quoted diff) +8
-0+Required properties: +- compatible: must be "capella,cm36672" +- reg: the I2C address of the device +- interrupts: interrupt-specifier for the sole interrupt generated by the device + +Optionoal properties: +- capella,reg_prx_conf: PS_CONF1 and PS_CONF2 registers +- capella,reg_prx_conf3: PS_CONF3 and PS_MS registers
This doesn't work at all, you are just taking magic values and poking into registers.
Make real configurations for each and every option in the registers that you want to support.
We already have standardized config options in DT for a lot of stuff. If one bit means "open drain IRQ line" or so, it should be its own config option.
See:Documentation/devicetree/bindings/iio/light/us5182d.txt For a good example.
Quoted 3 lines
+- capella,reg_prx_canc: PS cancellation level setting +- capella,reg_prx_thdl: PS low interrupt threshold setting +- capella,reg_prx_thdh: PS high interrupt threshold setting
This looks similar to magic, what unit(s) are these levels set in? Are they really 32 bit?
Quoted 2 lines
+- capella,name_prx_int_rising: enable/disable rising interrupt +- capella,name_prx_int_falling: enable/disable falling interrupt
NACK this should be handled by flags from the irqchip. If this client has falling edge assigned in the device tree it looks something like so:
interrupt-parent = <&gpio2>;
interrupts = <18 IRQ_TYPE_EDGE_FALLING>,
Then your driver should just react to that and set up rising/falling edge accordingly, see e.g. drivers/iio/common/st_sensors/st_sensors_trigger.c:
unsigned long irq_trig;
irq_trig = irqd_get_trigger_type(irq_get_irq_data(irq));
if (irq_trig == IRQF_TRIGGER_FALLING) {
...Quoted 3 lines
+- capella,name_prx_duty: PS duty ratio setting +- capella,name_prx_pers: persistence setting +- capella,name_prx_it: integration time setting
Unit? kiloohms? megajoule?
Also: are they really 32bit?
Quoted 1 line
+- capella,name_prx_led_current: LED current selection
Isn't this rather something that should be modelled by a regulator in the device tree?
Look at the other examples for light sensor bindings, e.g. Documentation/devicetree/bindings/iio/light/gp2ap020a00f.txt
Quoted 2 lines
+- capella,name_prx_threshold_falling: interrupt falling threshold +- capella,name_prx_threshold_rising: interrupt rising threshold
Units?
+ cm36672@60 {
Review
Quoted 4 lines
(quoted diff) +4
-0+ compatible = "capella,cm36672"; + reg = <0x60>; + interrupt-parent = <&gpio0>; + interrupts = <30 0>;
I understand until here.
Quoted 6 lines
(quoted diff) +6
-0+ /* Initialized by register */ + capella,reg_prx_conf = <0x0322>; + capella,reg_prx_conf3 = <0x0000>; + capella,reg_prx_canc = <0x0000>; + capella,reg_prx_thdl = <0x0007>; + capella,reg_prx_thdh = <0x000A>;
Review
Quoted 10 lines
(quoted diff) +10
-0+ + /* Or, initialized by name */ + capella,name_prx_int_rising = <1>; + capella,name_prx_int_falling = <1>; + capella,name_prx_duty = <0>; + capella,name_prx_pers = <2>; + capella,name_prx_it = <1>; + capella,name_prx_led_current = <0>; + capella,name_prx_threshold_falling = <7>; + capella,name_prx_threshold_rising = <10>;
I don't understand any of this. The purpose of the bindings is to make a detailed explanantion of all options.
Review
Quoted 8 lines
(quoted diff) +8
-0+/* RESERVED00 */ +#define CM36672_RESERVED00_DEFAULT 0x0001 + +/* RESERVED01 */ +#define CM36672_RESERVED01_DEFAULT 0x0000 + +/* RESERVED02 */ +#define CM36672_RESERVED02_DEFAULT 0x0000
I don't understand these. Why are they even here?
Review
Quoted 6 lines
(quoted diff) +6
-0+/* PRX_CONF */ +#define CM36672_PRX_DISABLE 0x0001 +#define CM36672_PRX_INT_RISING BIT(8) +#define CM36672_PRX_INT_FALLING BIT(9) +#define CM36672_PRX_INT_MASK (CM36672_PRX_INT_RISING | \ + CM36672_PRX_INT_FALLING)
So you do know what the different bits are doing.
Quoted 4 lines
(quoted diff) +4
-0+/* PRX_CONF: duty ratio */ +#define CM36672_PRX_DR_MASK (BIT(6) | BIT(7)) +#define CM36672_PRX_DR_SHIFT 6 +#define CM36672_PRX_DR1 0x0000 /* Duty ratio 1/40 */
Review
Quoted 10 lines
(quoted diff) +10
-0+#define CM36672_PRX_DR2 0x0040 /* Duty ratio 1/80 */ +#define CM36672_PRX_DR3 0x0080 /* Duty ratio 1/160 */ +#define CM36672_PRX_DR4 0x00C0 /* Duty ratio 1/320 */ + +/* PRX_CONF: persistence */ +#define CM36672_PRX_PERS_MASK (BIT(4) | BIT(5)) +#define CM36672_PRX_PERS_SHIFT 4 +#define CM36672_PRX_PERS2 0x0010 +#define CM36672_PRX_PERS3 0x0020 +#define CM36672_PRX_PERS4 0x0030
And these things are then doubly-defined in the device tree as it seems.
There is more stuff but fixing these will change the driver a bit so I prefer to review the rest later.
Yours,
Linus Walleij