On Mon, 18 Oct 2021 at 10:18, Jishnu Prakash <quic_jprakash@xxxxxxxxxxx> wrote:
Add support for PMIC5 Gen2 ADC_TM, used on PMIC7 chips. It is aIt looks to me like the Gen2 suffix is a bit misleading. I haven't
checked the docs, but following the ADC example, I think we should
name it ADC_TM7.
Or maybe my original naming was wrong and we should use ADC5_TM and ADC7_TM.
I'll split them in the next post.
close counterpart of PMIC7 ADC and has the same functionality asPlease split iio changes to the separate patch.
PMIC5 ADC_TM, for threshold monitoring and interrupt generation.
It is present on PMK8350 alone, like PMIC7 ADC and can be used
to monitor up to 8 ADC channels, from any of the PMIC7 PMICs
having ADC on a target, through PBS(Programmable Boot Sequence).
Signed-off-by: Jishnu Prakash <quic_jprakash@xxxxxxxxxxx>
---
drivers/iio/adc/qcom-vadc-common.c | 187 ++++++++++++++
drivers/thermal/qcom/qcom-spmi-adc-tm5.c | 431 ++++++++++++++++++++++++++++++-
include/linux/iio/adc/qcom-vadc-common.h | 2 +
3 files changed, 611 insertions(+), 9 deletions(-)There is the adcmap7_100k table, which looks identical. Do you need
diff --git a/drivers/iio/adc/qcom-vadc-common.c b/drivers/iio/adc/qcom-vadc-common.c
index 1472389..e192736 100644
--- a/drivers/iio/adc/qcom-vadc-common.c
+++ b/drivers/iio/adc/qcom-vadc-common.c
@@ -100,6 +100,182 @@ static const struct vadc_map_pt adcmap_100k_104ef_104fb_1875_vref[] = {
{ 46, 125000 },
};
+/*
+ * Resistance to temperature table for NTCG104EF104 thermistor with
+ * 100k pull-up.
+ */
+static const struct vadc_map_pt adcmap_100k_adc7[] = {
this extra table?
+ { 4250657, -40960 },
+ { 3962085, -39936 },
+ { 3694875, -38912 },
+ { 3447322, -37888 },
+ { 3217867, -36864 },
+ { 3005082, -35840 },
Will remove this.+ { 2633, 126976 },Extra newline
+ { 2560, 128000 },
+ { 2489, 129024 },
+ { 2420, 130048 }
+};
+
+
static const struct vadc_map_pt adcmap7_die_temp[] = {This is definitely not an qcom_adc_tm5-kind of function. What about
{ 857300, 160000 },
{ 820100, 140000 },
@@ -677,6 +853,17 @@ u16 qcom_adc_tm5_temp_volt_scale(unsigned int prescale_ratio,
}
EXPORT_SYMBOL(qcom_adc_tm5_temp_volt_scale);
+u16 qcom_adc_tm5_temp_res_scale(int temp)
qcom_adc_tm7_temp_res_scale() ?
Will fix it in the next post.+{Internal brackets are not needed.
+ int64_t resistance;
+
+ resistance = qcom_vadc_map_temp_voltage(adcmap_100k_adc7,
+ ARRAY_SIZE(adcmap_100k_adc7), temp);
+
+ return div64_s64((resistance * RATIO_MAX_ADC7), (resistance + R_PU_100K));
That is one major difference between PMIC5 and PMIC5 Gen2 ADC_TM. In PMIC5, there was a separate set of
struct adc_tm5_data {Is there any reason for using the data here rather than reading it
+ const struct adc_tm_ops *ops;
const u32 full_scale_code_volt;
unsigned int *decimation;
unsigned int *hw_settle;
@@ -100,6 +155,12 @@ struct adc_tm5_chip;
* @prescale: channel scaling performed on the input signal.
* @hw_settle_time: the time between AMUX being configured and the
* start of conversion.
+ * @decimation: sampling rate supported for the channel.
+ * @avg_samples: ability to provide single result from the ADC
+ * that is an average of multiple measurements.
+ * @high_thr_en: channel upper voltage threshold enable state.
+ * @low_thr_en: channel lower voltage threshold enable state.
+ * @meas_en: recurring measurement enable state
* @iio: IIO channel instance used by this channel.
* @chip: ADC TM chip instance.
* @tzd: thermal zone device used by this channel.
@@ -110,6 +171,11 @@ struct adc_tm5_channel {
enum adc_tm5_cal_method cal_method;
unsigned int prescale;
unsigned int hw_settle_time;
+ unsigned int decimation; /* For Gen2 ADC_TM */
+ unsigned int avg_samples; /* For Gen2 ADC_TM */
+ bool high_thr_en;
+ bool low_thr_en;
+ bool meas_en;
back from the register?
And if there is one, adc_tm5 code should be converted to use them too.
struct iio_channel *iio;
struct adc_tm5_chip *chip;
struct thermal_zone_device *tzd;
@@ -123,9 +189,12 @@ struct adc_tm5_channel {
* @channels: array of ADC TM channel data.
* @nchannels: amount of channels defined/allocated
* @decimation: sampling rate supported for the channel.
Yes, I'll use the existing adc_tm5_data directly for these in the next post.There is no need for this extra array, please use ops directly. And if
+enum adc_tm_index {
+ ADC_TM5,
+ ADC_TM5_GEN2,
+ ADC_TM5_MAX
+};
+
+static const struct adc_tm_ops ops_adc_tm5[ADC_TM5_MAX];
you introduce flags into the data, you won't have to forward declare
the ops here.
+static irqreturn_t adc_tm5_gen2_isr(int irq, void *data)Any reason for having the meas_en here rather than reading the MEAS_EN
+{
+ struct adc_tm5_chip *chip = data;
+ u8 status_low, status_high;
+ int ret, i;
+
+ ret = adc_tm5_read(chip, ADC_TM_GEN2_STATUS_LOW_CLR, &status_low, sizeof(status_low));
+ if (ret) {
+ dev_err(chip->dev, "read status_low failed: %d\n", ret);
+ return IRQ_HANDLED;
+ }
+
+ ret = adc_tm5_read(chip, ADC_TM_GEN2_STATUS_HIGH_CLR, &status_high, sizeof(status_high));
+ if (ret) {
+ dev_err(chip->dev, "read status_high failed: %d\n", ret);
+ return IRQ_HANDLED;
+ }
+
+ ret = adc_tm5_write(chip, ADC_TM_GEN2_STATUS_LOW_CLR, &status_low, sizeof(status_low));
+ if (ret < 0) {
+ dev_err(chip->dev, "clear status low failed with %d\n", ret);
+ return IRQ_HANDLED;
+ }
+
+ ret = adc_tm5_write(chip, ADC_TM_GEN2_STATUS_HIGH_CLR, &status_high, sizeof(status_high));
+ if (ret < 0) {
+ dev_err(chip->dev, "clear status high failed with %d\n", ret);
+ return IRQ_HANDLED;
+ }
+
+ for (i = 0; i < chip->nchannels; i++) {
+ bool upper_set = false, lower_set = false;
+ unsigned int ch = chip->channels[i].channel;
+
+ /* No TZD, we warned at the boot time */
+ if (!chip->channels[i].tzd)
+ continue;
+
+ if (!chip->channels[i].meas_en)
+ continue;
bit like the ADC_TM5 code does?
Same as above comment.
+And the high_thr_en/low_thr_en too.
+ lower_set = (status_low & BIT(ch)) &&
+ (chip->channels[i].low_thr_en);
+
+ upper_set = (status_high & BIT(ch)) &&
+ (chip->channels[i].high_thr_en);
+Should this section be protected by the mutex then, so that any other
+ if (upper_set || lower_set)
+ thermal_zone_device_update(chip->channels[i].tzd,
+ THERMAL_EVENT_UNSPECIFIED);
+ }
+
+ return IRQ_HANDLED;
+}
+
static int adc_tm5_get_temp(void *data, int *temp)
{
struct adc_tm5_channel *channel = data;
@@ -240,6 +398,104 @@ static int adc_tm5_disable_channel(struct adc_tm5_channel *channel)
0);
}
+#define ADC_TM_GEN2_POLL_DELAY_MIN_US 100
+#define ADC_TM_GEN2_POLL_DELAY_MAX_US 110
+#define ADC_TM_GEN2_POLL_RETRY_COUNT 3
+
+static int32_t adc_tm5_gen2_conv_req(struct adc_tm5_chip *chip)
+{
+ int ret = 0;
+ u8 data = 0;
+ unsigned int count;
+
+ data = ADC_TM_GEN2_EN;
+ ret = adc_tm5_write(chip, ADC_TM_GEN2_EN_CTL1, &data, 1);
+ if (ret < 0) {
+ pr_err("adc-tm enable failed with %d\n", ret);
+ return ret;
+ }
+
+ data = ADC_TM_GEN2_CFG_HS_FLAG;
+ ret = adc_tm5_write(chip, ADC_TM_GEN2_CFG_HS_SET, &data, 1);
+ if (ret < 0) {
+ pr_err("adc-tm handshake failed with %d\n", ret);
+ return ret;
+ }
+
+ data = ADC_TM_GEN2_CONV_REQ_EN;
+ ret = adc_tm5_write(chip, ADC_TM_GEN2_CONV_REQ, &data, 1);
+ if (ret < 0) {
+ pr_err("adc-tm request conversion failed with %d\n", ret);
+ return ret;
+ }
+
+ /*
+ * SW sets a handshake bit and waits for PBS to clear it
+ * before the next conversion request can be queued.
+ */
possible user won't queue the conversion?
+
+ for (count = 0; count < ADC_TM_GEN2_POLL_RETRY_COUNT; count++) {
+ ret = adc_tm5_read(chip, ADC_TM_GEN2_CFG_HS_SET, &data, sizeof(data));
+ if (ret < 0) {
+ pr_err("adc-tm read failed with %d\n", ret);
+ return ret;
+ }
+
+ if (!(data & ADC_TM_GEN2_CFG_HS_FLAG))
+ return ret;
+ usleep_range(ADC_TM_GEN2_POLL_DELAY_MIN_US,
+ ADC_TM_GEN2_POLL_DELAY_MAX_US);
+ }
+
+ pr_err("adc-tm conversion request handshake timed out\n");
+
+ return -ETIMEDOUT;
+}
+
I believe the mutex lock is not really needed for PMIC5 ADC_TM configuration because there we have one separate set of registers per TM channel, so onlystatic int adc_tm5_enable(struct adc_tm5_chip *chip)Either introduce mutex into the adc_tm5 code too, or drop it here.
{
int ret;
@@ -320,6 +576,86 @@ static int adc_tm5_configure(struct adc_tm5_channel *channel, int low, int high)
return adc_tm5_enable(chip);
}
+static int adc_tm5_gen2_configure(struct adc_tm5_channel *channel, int low, int high)
+{
+ struct adc_tm5_chip *chip = channel->chip;
+ int ret;
+ u8 buf[14];
+ u16 adc_code;
+
+ mutex_lock(&chip->adc_mutex_lock);
Will fix it in the next post.
+measurement
+ channel->meas_en = true;
+
+ ret = adc_tm5_read(chip, ADC_TM_GEN2_SID, buf, sizeof(buf));
+ if (ret < 0) {
+ pr_err("adc-tm block read failed with %d\n", ret);
+ goto config_fail;
+ }
+
+ /* Set SID from virtual channel number */
+ buf[0] = channel->adc_channel >> 8;
+
+ /* Set TM channel number used and measurment interval */
+static int adc_tm5_gen2_init(struct adc_tm5_chip *chip)Will do it in the next post.
+{
+ u8 channels_available;
+ int ret;
+ unsigned int i;
+
+ ret = adc_tm5_read(chip, ADC_TM5_NUM_BTM,
+ &channels_available, sizeof(channels_available));
+ if (ret) {
+ dev_err(chip->dev, "read failed for BTM channels\n");
+ return ret;
+ }
+
+ mutex_init(&chip->adc_mutex_lock);
+
+ for (i = 0; i < chip->nchannels; i++) {
+ if (chip->channels[i].channel >= channels_available) {
+ dev_err(chip->dev, "Invalid channel %d\n", chip->channels[i].channel);
+ return -EINVAL;
+ }
+ }
+
+ return ret;
This is the adc_tm5_init(), but with the ADC_DIG_PARAM bits left off.
So it might be better to split the adc_tm5_init() rather than
introducing the duplicate.
I'm not sure what you mean here, can you please explain some more? Which part exactly needs to change?
+}This does not apply either against current linux master or against
+
static int adc_tm5_get_dt_channel_data(struct adc_tm5_chip *adc_tm,
struct adc_tm5_channel *channel,
struct device_node *node)
{
const char *name = node->name;
- u32 chan, value, varr[2];
+ u32 chan, value, adc_channel, varr[2];
int ret;
struct device *dev = adc_tm->dev;
struct of_phandle_args args;
@@ -445,7 +806,11 @@ static int adc_tm5_get_dt_channel_data(struct adc_tm5_chip *adc_tm,
}
of_node_put(args.np);
- if (args.args_count != 1 || args.args[0] >= ADC5_MAX_CHANNEL) {
linux-next master.
Will do it in the next post.
+ adc_channel = args.args[0];Please replace ops comparison with flags.
+ if (adc_tm->data->ops == &ops_adc_tm5[ADC_TM5_GEN2])
Will do it in the next post.
+ adc_channel &= 0xff;And here too, please replace it with flags.
+
+ if (args.args_count != 1 || adc_channel >= ADC5_MAX_CHANNEL) {
dev_err(dev, "%s: invalid ADC channel number %d\n", name, chan);
return -EINVAL;
}
@@ -491,6 +856,32 @@ static int adc_tm5_get_dt_channel_data(struct adc_tm5_chip *adc_tm,
else
channel->cal_method = ADC_TM5_ABSOLUTE_CAL;
+ if (adc_tm->data->ops == &ops_adc_tm5[ADC_TM5_GEN2]) {
Will do it in the next post.@@ -591,7 +982,7 @@ static int adc_tm5_probe(struct platform_device *pdev)Push ISR into TM data.
return ret;
}
- ret = adc_tm5_init(adc_tm);
+ ret = adc_tm->data->ops->init(adc_tm);
if (ret) {
dev_err(dev, "adc-tm init failed\n");
return ret;
@@ -603,15 +994,37 @@ static int adc_tm5_probe(struct platform_device *pdev)
return ret;
}
+ if (adc_tm->data->ops == &ops_adc_tm5[ADC_TM5_GEN2])
+ return devm_request_threaded_irq(dev, irq, NULL, adc_tm5_gen2_isr,
+ IRQF_ONESHOT, "pm-adc-tm5-gen2", adc_tm);
+
return devm_request_threaded_irq(dev, irq, NULL, adc_tm5_isr,
- IRQF_ONESHOT, "pm-adc-tm5", adc_tm);
+ IRQF_ONESHOT, "pm-adc-tm5", adc_tm);
Thanks,
}