Lines Matching refs:adc_dev
66 static inline void cc10001_adc_write_reg(struct cc10001_adc_device *adc_dev, in cc10001_adc_write_reg() argument
69 writel(val, adc_dev->reg_base + reg); in cc10001_adc_write_reg()
72 static inline u32 cc10001_adc_read_reg(struct cc10001_adc_device *adc_dev, in cc10001_adc_read_reg() argument
75 return readl(adc_dev->reg_base + reg); in cc10001_adc_read_reg()
78 static void cc10001_adc_power_up(struct cc10001_adc_device *adc_dev) in cc10001_adc_power_up() argument
80 cc10001_adc_write_reg(adc_dev, CC10001_ADC_POWER_DOWN, 0); in cc10001_adc_power_up()
81 ndelay(adc_dev->start_delay_ns); in cc10001_adc_power_up()
84 static void cc10001_adc_power_down(struct cc10001_adc_device *adc_dev) in cc10001_adc_power_down() argument
86 cc10001_adc_write_reg(adc_dev, CC10001_ADC_POWER_DOWN, in cc10001_adc_power_down()
90 static void cc10001_adc_start(struct cc10001_adc_device *adc_dev, in cc10001_adc_start() argument
97 cc10001_adc_write_reg(adc_dev, CC10001_ADC_CONFIG, val); in cc10001_adc_start()
100 val = cc10001_adc_read_reg(adc_dev, CC10001_ADC_CONFIG); in cc10001_adc_start()
102 cc10001_adc_write_reg(adc_dev, CC10001_ADC_CONFIG, val); in cc10001_adc_start()
109 struct cc10001_adc_device *adc_dev = iio_priv(indio_dev); in cc10001_adc_poll_done() local
112 while (!(cc10001_adc_read_reg(adc_dev, CC10001_ADC_EOC) & in cc10001_adc_poll_done()
121 while ((cc10001_adc_read_reg(adc_dev, CC10001_ADC_CHSEL_SAMPLED) & in cc10001_adc_poll_done()
130 return cc10001_adc_read_reg(adc_dev, CC10001_ADC_DDATA_OUT) & in cc10001_adc_poll_done()
136 struct cc10001_adc_device *adc_dev; in cc10001_adc_trigger_h() local
147 adc_dev = iio_priv(indio_dev); in cc10001_adc_trigger_h()
148 data = adc_dev->buf; in cc10001_adc_trigger_h()
150 mutex_lock(&adc_dev->lock); in cc10001_adc_trigger_h()
152 if (!adc_dev->shared) in cc10001_adc_trigger_h()
153 cc10001_adc_power_up(adc_dev); in cc10001_adc_trigger_h()
156 delay_ns = adc_dev->eoc_delay_ns / CC10001_MAX_POLL_COUNT; in cc10001_adc_trigger_h()
164 cc10001_adc_start(adc_dev, channel); in cc10001_adc_trigger_h()
177 if (!adc_dev->shared) in cc10001_adc_trigger_h()
178 cc10001_adc_power_down(adc_dev); in cc10001_adc_trigger_h()
180 mutex_unlock(&adc_dev->lock); in cc10001_adc_trigger_h()
193 struct cc10001_adc_device *adc_dev = iio_priv(indio_dev); in cc10001_adc_read_raw_voltage() local
197 if (!adc_dev->shared) in cc10001_adc_read_raw_voltage()
198 cc10001_adc_power_up(adc_dev); in cc10001_adc_read_raw_voltage()
201 delay_ns = adc_dev->eoc_delay_ns / CC10001_MAX_POLL_COUNT; in cc10001_adc_read_raw_voltage()
203 cc10001_adc_start(adc_dev, chan->channel); in cc10001_adc_read_raw_voltage()
207 if (!adc_dev->shared) in cc10001_adc_read_raw_voltage()
208 cc10001_adc_power_down(adc_dev); in cc10001_adc_read_raw_voltage()
217 struct cc10001_adc_device *adc_dev = iio_priv(indio_dev); in cc10001_adc_read_raw() local
224 mutex_lock(&adc_dev->lock); in cc10001_adc_read_raw()
226 mutex_unlock(&adc_dev->lock); in cc10001_adc_read_raw()
233 ret = regulator_get_voltage(adc_dev->reg); in cc10001_adc_read_raw()
249 struct cc10001_adc_device *adc_dev = iio_priv(indio_dev); in cc10001_update_scan_mode() local
251 kfree(adc_dev->buf); in cc10001_update_scan_mode()
252 adc_dev->buf = kmalloc(indio_dev->scan_bytes, GFP_KERNEL); in cc10001_update_scan_mode()
253 if (!adc_dev->buf) in cc10001_update_scan_mode()
321 struct cc10001_adc_device *adc_dev; in cc10001_adc_probe() local
327 indio_dev = devm_iio_device_alloc(dev, sizeof(*adc_dev)); in cc10001_adc_probe()
331 adc_dev = iio_priv(indio_dev); in cc10001_adc_probe()
335 adc_dev->shared = true; in cc10001_adc_probe()
339 adc_dev->reg = devm_regulator_get(dev, "vref"); in cc10001_adc_probe()
340 if (IS_ERR(adc_dev->reg)) in cc10001_adc_probe()
341 return PTR_ERR(adc_dev->reg); in cc10001_adc_probe()
343 ret = regulator_enable(adc_dev->reg); in cc10001_adc_probe()
347 ret = devm_add_action_or_reset(dev, cc10001_reg_disable, adc_dev->reg); in cc10001_adc_probe()
355 adc_dev->reg_base = devm_platform_ioremap_resource(pdev, 0); in cc10001_adc_probe()
356 if (IS_ERR(adc_dev->reg_base)) in cc10001_adc_probe()
357 return PTR_ERR(adc_dev->reg_base); in cc10001_adc_probe()
359 adc_dev->adc_clk = devm_clk_get_enabled(dev, "adc"); in cc10001_adc_probe()
360 if (IS_ERR(adc_dev->adc_clk)) { in cc10001_adc_probe()
362 return PTR_ERR(adc_dev->adc_clk); in cc10001_adc_probe()
365 adc_clk_rate = clk_get_rate(adc_dev->adc_clk); in cc10001_adc_probe()
371 adc_dev->eoc_delay_ns = NSEC_PER_SEC / adc_clk_rate; in cc10001_adc_probe()
372 adc_dev->start_delay_ns = adc_dev->eoc_delay_ns * CC10001_WAIT_CYCLES; in cc10001_adc_probe()
379 if (adc_dev->shared) in cc10001_adc_probe()
380 cc10001_adc_power_up(adc_dev); in cc10001_adc_probe()
382 ret = devm_add_action_or_reset(dev, cc10001_pd_cb, adc_dev); in cc10001_adc_probe()
390 mutex_init(&adc_dev->lock); in cc10001_adc_probe()