Re: [PATCHv2] iio: adc: cpcap: Add minimal support for CPCAP PMIC ADC

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

 



* Tony Lindgren <tony@xxxxxxxxxxx> [170322 16:39]:
> +/**
> + * enum cpcap_adc_type - cpcap adc types
> + *
> + * Two banks of channels with eight channels in each. The first two channels
> + * in bank0 can be muxed for other functionality with CPCAP_ADC_TYPE_BATT_PI.
> + */
> +enum cpcap_adc_type {
> +	CPCAP_ADC_TYPE_BANK_0,
> +	CPCAP_ADC_TYPE_BANK_1,
> +	CPCAP_ADC_TYPE_BATT_PI,
> +};

Hmm looks like I only got half done yesterday.. I can now get
rid of the above in favor of using just channels.

> +static void cpcap_adc_phase(struct cpcap_adc_request *req, int index)
> +{
> +	const struct cpcap_adc_conversion_tbl *conv_tbl;
> +	const struct cpcap_adc_phasing_tbl *phase_tbl;
> +	int tbl_index;
> +
> +	switch (req->type) {
> +	case CPCAP_ADC_TYPE_BANK_0:
> +		conv_tbl = bank0_conversion;
> +		phase_tbl = bank0_phasing;
> +		tbl_index = index;
> +		break;
> +	case CPCAP_ADC_TYPE_BANK_1:
> +		conv_tbl = bank1_conversion;
> +		phase_tbl = bank1_phasing;
> +		tbl_index = index;
> +		break;
> +	case CPCAP_ADC_TYPE_BATT_PI:
> +		conv_tbl = bank0_conversion;
> +		phase_tbl = bank0_phasing;
> +		tbl_index = (index % 2) ? CPCAP_ADC_BATTI :
> +			CPCAP_ADC_BATTP;
> +		break;
> +	default:
> +		return;
> +	}

And then the above switch will go away.

> +static void cpcap_adc_convert(struct cpcap_adc_request *req, int index)
> +{
> +	const struct cpcap_adc_conversion_tbl *conv_tbl;
> +	int tbl_index;
> +
> +	switch (req->type) {
> +	case CPCAP_ADC_TYPE_BANK_0:
> +		conv_tbl = bank0_conversion;
> +		tbl_index = index;
> +		break;
> +	case CPCAP_ADC_TYPE_BANK_1:
> +		conv_tbl = bank1_conversion;
> +		tbl_index = index;
> +		break;
> +	case CPCAP_ADC_TYPE_BATT_PI:
> +		conv_tbl = bank0_conversion;
> +		tbl_index = (index % 2) ?
> +			CPCAP_ADC_BATTI : CPCAP_ADC_BATTP;
> +		break;
> +	default:
> +		return;
> +	}

And here too.

> +static int cpcap_adc_init_request(struct cpcap_adc_request *req,
> +				  int channel)
> +{
> +	switch (channel) {
> +	case 0 ... 7:
> +		req->bank_index = channel;
> +		req->type = CPCAP_ADC_TYPE_BANK_0;
> +		break;
> +	case 8 ... 15:
> +		req->bank_index = channel - 8;
> +		req->type = CPCAP_ADC_TYPE_BANK_1;
> +		break;
> +	case 16 ... 17:
> +		req->bank_index = channel - 16;
> +		req->type = CPCAP_ADC_TYPE_BATT_PI;
> +		break;
> +	default:
> +		return -EINVAL;
> +	}
> +
> +	return 0;
> +}

And this can be done by indexing everything with just the
channels. So I'll be posting v3 of this patch at some point
hopefully later on today.

Regards,

Tony
--
To unsubscribe from this list: send the line "unsubscribe linux-omap" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Linux Arm (vger)]     [ARM Kernel]     [ARM MSM]     [Linux Tegra]     [Linux WPAN Networking]     [Linux Wireless Networking]     [Maemo Users]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite Trails]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux