Message ID | 20241030185854.4015348-1-quic_jprakash@quicinc.com |
---|---|
Headers | show |
Series | Add support for QCOM SPMI PMIC5 Gen3 ADC | expand |
Hi Krzysztof, On 10/31/2024 4:33 PM, Krzysztof Kozlowski wrote: > On 30/10/2024 19:58, Jishnu Prakash wrote: >> + >> +static int adc5_gen3_read(struct adc5_device_data *adc, unsigned int sdam_index, >> + u16 offset, u8 *data, int len) >> +{ >> + return regmap_bulk_read(adc->regmap, adc->base[sdam_index].base_addr + offset, data, len); >> +} >> + >> +static int adc5_gen3_write(struct adc5_device_data *adc, unsigned int sdam_index, >> + u16 offset, u8 *data, int len) >> +{ >> + return regmap_bulk_write(adc->regmap, adc->base[sdam_index].base_addr + offset, data, len); >> +} >> + >> +/* >> + * Worst case delay from PBS in readying handshake bit >> + * can be up to 15ms, when PBS is busy running other >> + * simultaneous transactions, while in the best case, it is >> + * already ready at this point. Assigning polling delay and >> + * retry count accordingly. >> + */ >> + >> +#define ADC5_GEN3_HS_DELAY_MIN_US 100 >> +#define ADC5_GEN3_HS_DELAY_MAX_US 110 >> +#define ADC5_GEN3_HS_RETRY_COUNT 150 >> + >> +static int adc5_gen3_poll_wait_hs(struct adc5_device_data *adc, >> + unsigned int sdam_index) >> +{ >> + u8 conv_req = ADC5_GEN3_CONV_REQ_REQ; >> + int ret, count; >> + u8 status = 0; >> + >> + for (count = 0; count < ADC5_GEN3_HS_RETRY_COUNT; count++) { >> + ret = adc5_gen3_read(adc, sdam_index, ADC5_GEN3_HS, &status, 1); >> + if (ret) >> + return ret; >> + >> + if (status == ADC5_GEN3_HS_READY) { >> + ret = adc5_gen3_read(adc, sdam_index, ADC5_GEN3_CONV_REQ, >> + &conv_req, 1); >> + if (ret) >> + return ret; >> + >> + if (!conv_req) >> + return 0; >> + } >> + >> + usleep_range(ADC5_GEN3_HS_DELAY_MIN_US, ADC5_GEN3_HS_DELAY_MAX_US); >> + } >> + >> + pr_err("Setting HS ready bit timed out, sdam_index:%d, status:%#x\n", sdam_index, status); >> + return -ETIMEDOUT; >> +} >> + >> +static void adc5_gen3_update_dig_param(struct adc5_channel_common_prop *prop, u8 *data) >> +{ >> + /* Update calibration select and decimation ratio select */ >> + *data &= ~(ADC5_GEN3_DIG_PARAM_CAL_SEL_MASK | ADC5_GEN3_DIG_PARAM_DEC_RATIO_SEL_MASK); >> + *data |= FIELD_PREP(ADC5_GEN3_DIG_PARAM_CAL_SEL_MASK, prop->cal_method); >> + *data |= FIELD_PREP(ADC5_GEN3_DIG_PARAM_DEC_RATIO_SEL_MASK, prop->decimation); >> +} >> + >> +static int adc5_gen3_status_clear(struct adc5_device_data *adc, >> + int sdam_index, u16 offset, u8 *val, int len) >> +{ > > Wait, what? Why are you defining functions in header causing multiple > copies of them? And even if: why this is not inline? But regardless: > this is a strong NAK from me. This was meant to hold macros and some helper functions used in both main and auxiliary driver files. I see what you mean - I'll move the function definitions into a new .c file and mark them inline. Thanks, Jishnu > > Best regards, > Krzysztof >
Hi Krzysztof, On 10/31/2024 1:06 PM, Krzysztof Kozlowski wrote: > On Thu, Oct 31, 2024 at 12:28:50AM +0530, Jishnu Prakash wrote: >> PMIC5 Gen3 has a similar ADC architecture to that on PMIC5 Gen2, >> with all SW communication to ADC going through PMK8550 which >> communicates with other PMICs through PBS. The major difference is >> that the register interface used here is that of an SDAM present on >> PMK8550, rather than a dedicated ADC peripheral. There may be more than one >> SDAM used for ADC5 Gen3. Each ADC SDAM has eight channels, each of which may >> be used for either immediate reads (same functionality as previous PMIC5 and >> PMIC5 Gen2 ADC peripherals) or recurring measurements (same as PMIC5 and PMIC5 >> Gen2 ADC_TM functionality). In this case, we have VADC and ADC_TM functionality >> combined into the same driver. >> >> Patch 1 is a cleanup, to move the QCOM ADC dt-bindings files from >> dt-bindings/iio to dt-bindings/iio/adc folder, as they are >> specifically for ADC devices. It also fixes all compilation errors >> with this change in driver and devicetree files and similar errors >> in documentation for dtbinding check. >> >> Patch 2 adds bindings for ADC5 Gen3 peripheral. >> >> Patch 3 adds the main driver for ADC5 Gen3. >> >> Patch 4 adds the auxiliary thermal driver which supports the ADC_TM >> functionality of ADC5 Gen3. >> >> Changes since v3: >> - Updated files affected by adc file path change in /arch/arm folder, >> which were missed earlier. > > I don't think this was tested afterwards... If you are referring to the error found by the bot in my V4 patches 1 and 2, I think the error is invalid. In both cases, this is the error: fatal error: dt-bindings/iio/adc/qcom,spmi-vadc.h: No such file or directory But this file is added in patch 1, through a renaming: rename include/dt-bindings/iio/{ => adc}/qcom,spmi-vadc.h (100%) I have replied to Rob on the patch 1 mail pointing this out, but I did not get any reply yet. I have also tried updating dtschema and running 'make dt_binding_check' again myself and I did not get this error. If this was some rare error on the bot's side, which may not always happen, I'm thinking of pushing the same patch again in the next patch series, as I think there is nothing to fix from my side. Please let me know if you have any other suggestions. Thanks, Jishnu > > Best regards, > Krzysztof >
On 13/11/2024 15:06, Jishnu Prakash wrote: > Hi Krzysztof, > > On 10/31/2024 4:33 PM, Krzysztof Kozlowski wrote: >> On 30/10/2024 19:58, Jishnu Prakash wrote: >>> + >>> +static int adc5_gen3_read(struct adc5_device_data *adc, unsigned int sdam_index, >>> + u16 offset, u8 *data, int len) >>> +{ >>> + return regmap_bulk_read(adc->regmap, adc->base[sdam_index].base_addr + offset, data, len); >>> +} >>> + >>> +static int adc5_gen3_write(struct adc5_device_data *adc, unsigned int sdam_index, >>> + u16 offset, u8 *data, int len) >>> +{ >>> + return regmap_bulk_write(adc->regmap, adc->base[sdam_index].base_addr + offset, data, len); >>> +} >>> + >>> +/* >>> + * Worst case delay from PBS in readying handshake bit >>> + * can be up to 15ms, when PBS is busy running other >>> + * simultaneous transactions, while in the best case, it is >>> + * already ready at this point. Assigning polling delay and >>> + * retry count accordingly. >>> + */ >>> + >>> +#define ADC5_GEN3_HS_DELAY_MIN_US 100 >>> +#define ADC5_GEN3_HS_DELAY_MAX_US 110 >>> +#define ADC5_GEN3_HS_RETRY_COUNT 150 >>> + >>> +static int adc5_gen3_poll_wait_hs(struct adc5_device_data *adc, >>> + unsigned int sdam_index) >>> +{ >>> + u8 conv_req = ADC5_GEN3_CONV_REQ_REQ; >>> + int ret, count; >>> + u8 status = 0; >>> + >>> + for (count = 0; count < ADC5_GEN3_HS_RETRY_COUNT; count++) { >>> + ret = adc5_gen3_read(adc, sdam_index, ADC5_GEN3_HS, &status, 1); >>> + if (ret) >>> + return ret; >>> + >>> + if (status == ADC5_GEN3_HS_READY) { >>> + ret = adc5_gen3_read(adc, sdam_index, ADC5_GEN3_CONV_REQ, >>> + &conv_req, 1); >>> + if (ret) >>> + return ret; >>> + >>> + if (!conv_req) >>> + return 0; >>> + } >>> + >>> + usleep_range(ADC5_GEN3_HS_DELAY_MIN_US, ADC5_GEN3_HS_DELAY_MAX_US); >>> + } >>> + >>> + pr_err("Setting HS ready bit timed out, sdam_index:%d, status:%#x\n", sdam_index, status); >>> + return -ETIMEDOUT; >>> +} >>> + >>> +static void adc5_gen3_update_dig_param(struct adc5_channel_common_prop *prop, u8 *data) >>> +{ >>> + /* Update calibration select and decimation ratio select */ >>> + *data &= ~(ADC5_GEN3_DIG_PARAM_CAL_SEL_MASK | ADC5_GEN3_DIG_PARAM_DEC_RATIO_SEL_MASK); >>> + *data |= FIELD_PREP(ADC5_GEN3_DIG_PARAM_CAL_SEL_MASK, prop->cal_method); >>> + *data |= FIELD_PREP(ADC5_GEN3_DIG_PARAM_DEC_RATIO_SEL_MASK, prop->decimation); >>> +} >>> + >>> +static int adc5_gen3_status_clear(struct adc5_device_data *adc, >>> + int sdam_index, u16 offset, u8 *val, int len) >>> +{ >> >> Wait, what? Why are you defining functions in header causing multiple >> copies of them? And even if: why this is not inline? But regardless: >> this is a strong NAK from me. > > This was meant to hold macros and some helper functions used in both main and auxiliary driver files. > I see what you mean - I'll move the function definitions into a new .c file and mark them inline. This is a very odd coding style. Look around other header files: do you see such patterns? No, because it leads to potential issues I mentioned above.. Best regards, Krzysztof