Re: [PATCH v3 11/19] hwmon: (mr75203) add VM pre-scaler support

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

 



On Tue, Aug 30, 2022 at 07:22:04PM +0000, Eliav Farber wrote:
> Add mr76006 pre-scaler support to normalize the voltage output result for
> channels that use pre-scaler units to get the measurement to be within
> the range that the sensor supports.
> 
> For channels that are listed in the device-tree to have a pre-scaler, the
> voltage result is multiplied by a factor of 2, to represent to the user
> the actual voltage source which is measured.

...

> +static int pvt_get_pre_scaler(struct device *dev, struct pvt_device *pvt)
> +{
> +	const struct device_node *np = dev->of_node;
> +	u32 total_channels = pvt->vm_channels.total;
> +	u32 channel;
> +	u8 *pre_scaler_ch_list;
> +	int i, ret, num_ch;
> +
> +	/* Set default pre-scaler value to be 1. */
> +	for (i = 0; i < total_channels; i++)
> +		pvt->vd[i].pre_scaler = PRE_SCALER_X1;
> +
> +	/* Get number of channels configured in "moortec,vm-pre-scaler". */
> +	num_ch = of_property_count_u8_elems(np, "moortec,vm-pre-scaler");

of_ ?!

> +	if (num_ch <= 0)
> +		return 0;
> +
> +	pre_scaler_ch_list = kcalloc(total_channels,
> +				     sizeof(*pre_scaler_ch_list), GFP_KERNEL);
> +	if (!pre_scaler_ch_list)
> +		return -ENOMEM;
> +
> +	/* Get list of all channels that have pre-scaler of 2. */
> +	ret = device_property_read_u8_array(dev, "moortec,vm-pre-scaler",
> +					    pre_scaler_ch_list, num_ch);
> +	if (ret)
> +		goto out;
> +
> +	for (i = 0; i < num_ch; i++) {
> +		channel = pre_scaler_ch_list[i];

> +

Unnecessary blank line.

> +		if (channel >= total_channels) {
> +			dev_err(dev,
> +				"invalid channel (%u) in pre-scaler list\n",
> +				channel);
> +			ret = -EINVAL;

> +			goto out;

Wouldn't

			break;

suffice? (I understand the point, up to you)

> +		}
> +
> +		pvt->vd[channel].pre_scaler = PRE_SCALER_X2;
> +	}
> +
> +out:

out_free:

> +	kfree(pre_scaler_ch_list);
> +
> +	return ret;
> +}


-- 
With Best Regards,
Andy Shevchenko





[Index of Archives]     [LM Sensors]     [Linux Sound]     [ALSA Users]     [ALSA Devel]     [Linux Audio Users]     [Linux Media]     [Kernel]     [Gimp]     [Yosemite News]     [Linux Media]

  Powered by Linux