static ssize_t tiadc_set_mode(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { struct iio_dev *indio_dev = dev_get_drvdata(dev); struct adc_device *adc_dev = iio_priv(indio_dev); unsigned int config; config = adc_readl(adc_dev, TSCADC_REG_CTRL); config &= ~(TSCADC_CNTRLREG_TSCSSENB); adc_writel(adc_dev, TSCADC_REG_CTRL, config); if (!strncmp(buf, "oneshot", 7)) adc_dev->is_continuous_mode = false; else if (!strncmp(buf, "continuous", 10)) adc_dev->is_continuous_mode = true; else { dev_err(dev, "Operational mode unknown\n"); return -EINVAL; } adc_step_config(adc_dev, adc_dev->is_continuous_mode); config = adc_readl(adc_dev, TSCADC_REG_CTRL); adc_writel(adc_dev, TSCADC_REG_CTRL, (config | TSCADC_CNTRLREG_TSCSSENB)); return count; }
static void rk30_adc_dump(struct adc_host *adc) { struct rk30_adc_device *dev = adc_priv(adc); dev_info(adc->dev, "[0x00-0x0c]: 0x%08x 0x%08x 0x%08x 0x%08x\n", adc_readl(dev->regs + 0x00), adc_readl(dev->regs + 0x04), adc_readl(dev->regs + 0x08), adc_readl(dev->regs + 0x0c)); }
static ssize_t tiadc_show_mode(struct device *dev, struct device_attribute *attr, char *buf) { struct iio_dev *indio_dev = dev_get_drvdata(dev); struct adc_device *adc_dev = iio_priv(indio_dev); unsigned int tmp; tmp = adc_readl(adc_dev, TSCADC_REG_STEPCONFIG(TOTAL_STEPS)); tmp &= TSCADC_STEPCONFIG_MODE(1); if (tmp == 0x00) return sprintf(buf, "oneshot\n"); else if (tmp == 0x01) return sprintf(buf, "continuous\n"); else return sprintf(buf, "Operation mode unknown\n"); }
static int rk30_adc_read(struct adc_host *adc) { struct rk30_adc_device *dev = adc_priv(adc); return adc_readl(dev->regs + ADC_DATA) & ADC_DATA_MASK; }
static struct attribute *tiadc_attributes[] = { &iio_dev_attr_mode.dev_attr.attr, NULL, }; static const struct attribute_group tiadc_attribute_group = { .attrs = tiadc_attributes, }; static irqreturn_t tiadc_irq(int irq, void *private) { struct iio_dev *idev = private; struct adc_device *adc_dev = iio_priv(idev); unsigned int status, config; status = adc_readl(adc_dev, TSCADC_REG_IRQSTATUS); if (status & TSCADC_IRQENB_FIFO1OVRRUN) { config = adc_readl(adc_dev, TSCADC_REG_CTRL); config &= ~(TSCADC_CNTRLREG_TSCSSENB); adc_writel(adc_dev, TSCADC_REG_CTRL, config); adc_writel(adc_dev, TSCADC_REG_IRQSTATUS, TSCADC_IRQENB_FIFO1OVRRUN | TSCADC_IRQENB_FIFO1UNDRFLW | TSCADC_IRQENB_FIFO1THRES); adc_writel(adc_dev, TSCADC_REG_CTRL, (config | TSCADC_CNTRLREG_TSCSSENB)); return IRQ_HANDLED; } else if (status & TSCADC_IRQENB_FIFO1THRES) { adc_writel(adc_dev, TSCADC_REG_IRQCLR,