static int crystalcove_gpadc_show(struct seq_file *s, void *unused) { int num; char *names[GPADC_CH_NUM]; int vals[GPADC_CH_NUM]; int i, j; struct iio_channel *chs; char *ch_names[] = {"VIBAT", "BATID", "PMICTEMP", "BATTEMP", "SYSTEMP", "THERMAL"}; int ret = 0; seq_printf(s, "ADCCNTL:\t0x%02x\n", intel_mid_pmic_readb(ADCCNTL)); seq_printf(s, "ADCVZSE:\t0x%02x\n", intel_mid_pmic_readb(ADCVZSE)); seq_printf(s, "ADCVGE:\t\t0x%02x\n", intel_mid_pmic_readb(ADCVGE)); seq_printf(s, "VRIMONCTL:\t0x%02x\n", intel_mid_pmic_readb(VRIMONCTL)); seq_printf(s, "MANCONV0:\t0x%02x\n", intel_mid_pmic_readb(MANCONV0)); seq_printf(s, "MANCONV1:\t0x%02x\n", intel_mid_pmic_readb(MANCONV1)); seq_printf(s, "ADCIRQ0:\t0x%02x\n", intel_mid_pmic_readb(ADCIRQ0)); seq_printf(s, "ADCIRQ1:\t0x%02x\n", intel_mid_pmic_readb(ADCIRQ1)); seq_printf(s, "MADCIRQ0:\t0x%02x\n", intel_mid_pmic_readb(MADCIRQ0)); seq_printf(s, "MADCIRQ1:\t0x%02x\n", intel_mid_pmic_readb(MADCIRQ1)); memset(names, 0, sizeof(names)); for (i = 0; i < GPADC_CH_NUM; i++) { names[i] = kmalloc(256, GFP_KERNEL); if (names[i] == NULL) { ret = -ENOMEM; goto err; } } for (i = 0; i < sizeof(ch_names)/sizeof(ch_names[0]); i++) { chs = iio_st_channel_get_all(ch_names[i]); if (chs) { num = iio_st_channel_get_num(chs); iio_st_channel_get_name(chs, names); iio_st_read_channel_raw(chs, vals); iio_st_channel_release_all(chs); for (j = 0; j < num; j++) seq_printf(s, "%s:%s\t%d\n", ch_names[i], names[j], vals[j]); } } err: for (i = 0; i < GPADC_CH_NUM; i++) kfree(names[i]); return 0; }
/* * Assumes that IIO and hwmon operate in the same base units. * This is supposed to be true, but needs verification for * new channel types. */ static ssize_t iio_hwmon_read_val(struct device *dev, struct device_attribute *attr, char *buf) { long result; int val, ret, scaleint, scalepart; struct sensor_device_attribute *sattr = to_sensor_dev_attr(attr); struct iio_hwmon_state *state = dev_get_drvdata(dev); /* * No locking between this pair, so theoretically possible * the scale has changed. */ ret = iio_st_read_channel_raw(&state->channels[sattr->index], &val); if (ret < 0) return ret; ret = iio_st_read_channel_scale(&state->channels[sattr->index], &scaleint, &scalepart); if (ret < 0) return ret; switch (ret) { case IIO_VAL_INT: result = val * scaleint; break; case IIO_VAL_INT_PLUS_MICRO: result = (s64)val * (s64)scaleint + div_s64((s64)val * (s64)scalepart, 1000000LL); break; case IIO_VAL_INT_PLUS_NANO: result = (s64)val * (s64)scaleint + div_s64((s64)val * (s64)scalepart, 1000000000LL); break; default: return -EINVAL; } return sprintf(buf, "%ld\n", result); }
static int adc_temp_show(struct seq_file *s, void *p) { struct gadc_thermal_driver_data *drvdata = s->private; int adc, temp; int ret; ret = iio_st_read_channel_raw(drvdata->channel, &adc); if (ret < 0) { dev_err(drvdata->dev, "%s: Failed to read channel, %d\n", __func__, ret); return ret; } if (drvdata->pdata->adc_to_temp) temp = drvdata->pdata->adc_to_temp(drvdata->pdata, adc); else temp = adc; temp += drvdata->pdata->temp_offset; seq_printf(s, "%d %d\n", adc, temp); return 0; }
static int gadc_thermal_get_temp(struct thermal_zone_device *tz, unsigned long *temp) { struct gadc_thermal_driver_data *drvdata = tz->devdata; int val; int ret; ret = iio_st_read_channel_raw(drvdata->channel, &val); if (ret < 0) { dev_err(drvdata->dev, "%s: Failed to read channel, %d\n", __func__, ret); return ret; } if (drvdata->pdata->adc_to_temp) *temp = drvdata->pdata->adc_to_temp(drvdata->pdata, val); else if (drvdata->pdata->adc_temp_lookup) *temp = gadc_thermal_thermistor_adc_to_temp(drvdata, val); else *temp = val; *temp += drvdata->temp_offset; return 0; }