Lines Matching full:saradc
3 * Sophgo CV1800B SARADC Driver
72 static void cv1800b_adc_start_measurement(struct cv1800b_adc *saradc, in cv1800b_adc_start_measurement() argument
75 writel(0, saradc->regs + CV1800B_ADC_CTRL_REG); in cv1800b_adc_start_measurement()
77 saradc->regs + CV1800B_ADC_CTRL_REG); in cv1800b_adc_start_measurement()
80 static int cv1800b_adc_wait(struct cv1800b_adc *saradc) in cv1800b_adc_wait() argument
82 if (saradc->irq < 0) { in cv1800b_adc_wait()
85 return readl_poll_timeout(saradc->regs + CV1800B_ADC_STATUS_REG, in cv1800b_adc_wait()
90 return wait_for_completion_timeout(&saradc->completion, in cv1800b_adc_wait()
99 struct cv1800b_adc *saradc = iio_priv(indio_dev); in cv1800b_adc_read_raw() local
105 scoped_guard(mutex, &saradc->lock) { in cv1800b_adc_read_raw()
108 cv1800b_adc_start_measurement(saradc, chan->scan_index); in cv1800b_adc_read_raw()
109 ret = cv1800b_adc_wait(saradc); in cv1800b_adc_read_raw()
113 sample = readl(saradc->regs + CV1800B_ADC_CH_RESULT_REG(chan->scan_index)); in cv1800b_adc_read_raw()
126 u32 status_reg = readl(saradc->regs + CV1800B_ADC_CYC_SET_REG); in cv1800b_adc_read_raw()
128 unsigned int freq = clk_get_rate(saradc->clk) / clk_div; in cv1800b_adc_read_raw()
143 struct cv1800b_adc *saradc = private; in cv1800b_adc_interrupt_handler() local
144 u32 reg = readl(saradc->regs + CV1800B_ADC_INTR_STA_REG); in cv1800b_adc_interrupt_handler()
149 writel(CV1800B_ADC_INTR_CLR_BIT, saradc->regs + CV1800B_ADC_INTR_CLR_REG); in cv1800b_adc_interrupt_handler()
150 complete(&saradc->completion); in cv1800b_adc_interrupt_handler()
162 struct cv1800b_adc *saradc; in cv1800b_adc_probe() local
166 indio_dev = devm_iio_device_alloc(dev, sizeof(*saradc)); in cv1800b_adc_probe()
170 saradc = iio_priv(indio_dev); in cv1800b_adc_probe()
177 saradc->clk = devm_clk_get_enabled(dev, NULL); in cv1800b_adc_probe()
178 if (IS_ERR(saradc->clk)) in cv1800b_adc_probe()
179 return PTR_ERR(saradc->clk); in cv1800b_adc_probe()
181 saradc->regs = devm_platform_ioremap_resource(pdev, 0); in cv1800b_adc_probe()
182 if (IS_ERR(saradc->regs)) in cv1800b_adc_probe()
183 return PTR_ERR(saradc->regs); in cv1800b_adc_probe()
185 saradc->irq = platform_get_irq_optional(pdev, 0); in cv1800b_adc_probe()
186 if (saradc->irq > 0) { in cv1800b_adc_probe()
187 init_completion(&saradc->completion); in cv1800b_adc_probe()
188 ret = devm_request_irq(dev, saradc->irq, in cv1800b_adc_probe()
190 dev_name(dev), saradc); in cv1800b_adc_probe()
194 writel(1, saradc->regs + CV1800B_ADC_INTR_EN_REG); in cv1800b_adc_probe()
197 ret = devm_mutex_init(dev, &saradc->lock); in cv1800b_adc_probe()
205 saradc->regs + CV1800B_ADC_CYC_SET_REG); in cv1800b_adc_probe()
211 { .compatible = "sophgo,cv1800b-saradc", },
218 .name = "sophgo-cv1800b-saradc",
226 MODULE_DESCRIPTION("Sophgo CV1800B SARADC driver");