To my eyes this driver looks nice. Just spotted two minor things.
+ gain_new_closest = iio_find_closest_gain_low(&data->gts, gain_new, &ok);
+ if (gain_new_closest < 0) {
+ gain_new_closest = iio_gts_get_min_gain(&data->gts);
+ if (gain_new_closest < 0)
+ return gain_new_closest < 0;
Returning the truth value on purpose? :)
+static int get_device_id_lux_per_count(struct apds9306_data *data)
+{
+ int ret, part_id;
+
+ ret = regmap_read(data->regmap, APDS9306_PART_ID, &part_id);
+ if (ret)
+ return ret;
+
+ if (part_id == apds9306_part_id_nlux_per_count[0].part_id)
+ data->nlux_per_count =
+ apds9306_part_id_nlux_per_count[0].nlux_per_count;
+ else if (part_id == apds9306_part_id_nlux_per_count[1].part_id)
+ data->nlux_per_count =
+ apds9306_part_id_nlux_per_count[1].nlux_per_count;
+ else
+ return -ENXIO;
I think we should be able to differentiate between the IC variants by DT compatible. (Commented that on bindings patch). Not sure if we need to support cases where the sensor is instantiated without device-tree. I am not super happy when code requires the part-id to be known if we have separate compatibles for variants. Can we in dt-case just print a warning if the part-ID is not what we expect - and proceed assuming the nlux_per_count based on the DT information? (Sometimes we see new variants with same part-IDs - or many part-IDs with no SW changes needed. Hence maintaining the part-ID lists may be tedious). This is just some pondering though, no strong requirements from my side