Re: [PATCH v5 3/7] iio: light: vcnl4000: Add als_it for vcnl4040/4200

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Tue, May 30, 2023 at 04:24:01PM +0200, Astrid Rost kirjoitti:
> Add illuminance integration time for vcnl4040 and vcnl4200.
> Add read/write attribute for illuminance integration time and read
> attribute for available integration times.
> Set scale and sampling rate according to the integration time.

...

> +static int vcnl4040_read_als_it(struct vcnl4000_data *data, int *val, int *val2)
> +{
> +	int ret;
> +
> +	ret = i2c_smbus_read_word_data(data->client, VCNL4200_AL_CONF);
> +	if (ret < 0)
> +		return ret;
> +
> +	ret = FIELD_GET(VCNL4040_ALS_CONF_IT, ret);

> +

Redundant blank line.

> +	if (ret >= data->chip_spec->num_als_it_times)
> +		return -EINVAL;
> +
> +	*val = (*data->chip_spec->als_it_times)[ret][0];
> +	*val2 = (*data->chip_spec->als_it_times)[ret][1];
> +
> +	return 0;
> +}

...

> +static ssize_t vcnl4040_write_als_it(struct vcnl4000_data *data, int val)
> +{
> +	unsigned int i;
> +	int ret, reg_val = -1;
> +	u16 regval;

Besides confusing naming schema (two variables with only a _ difference)

	unsigned int i;
	u16 regval;
	int ret;

> +	for (i = 0; i < data->chip_spec->num_als_it_times; i++) {
> +		if (val == (*data->chip_spec->als_it_times)[i][1]) {

> +			reg_val = i;

Remove.

> +			break;
> +		}
> +	}

> +	if (reg_val < 0)

	if (i == data->chip_spec->num_als_it_times)

> +		return -EINVAL;

(1)

> +	data->vcnl4200_al.sampling_rate = ktime_set(0, val * 1200);
> +	data->al_scale = div_u64(mul_u32_u32(data->chip_spec->ulux_step,
> +			 (*data->chip_spec->als_it_times)[0][1]),
> +			 val);
> +
> +	mutex_lock(&data->vcnl4000_lock);
> +
> +	ret = i2c_smbus_read_word_data(data->client, VCNL4200_AL_CONF);
> +	if (ret < 0)
> +		goto out_unlock;
> +
> +	regval = (ret & ~VCNL4040_ALS_CONF_IT) |
> +		 FIELD_PREP(VCNL4040_ALS_CONF_IT, reg_val);

Use temporary variable for this field,

	u16 als_conf;
	...See (1)...
	als_conf = FIELD_PREP(..., i);

> +	ret = i2c_smbus_write_word_data(data->client,
> +					VCNL4200_AL_CONF,
> +					regval);
> +
> +out_unlock:
> +	mutex_unlock(&data->vcnl4000_lock);
> +	return ret;
> +}

-- 
With Best Regards,
Andy Shevchenko





[Index of Archives]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Input]     [Linux Kernel]     [Linux SCSI]     [X.org]

  Powered by Linux