Lines Matching refs:adc
100 int (*init_clk_div)(struct device *dev, struct ingenic_adc *adc);
114 struct ingenic_adc *adc = iio_priv(iio_dev); in ingenic_adc_set_adcmd() local
116 mutex_lock(&adc->lock); in ingenic_adc_set_adcmd()
119 readl(adc->base + JZ_ADC_REG_ADCMD); in ingenic_adc_set_adcmd()
126 adc->base + JZ_ADC_REG_ADCMD); in ingenic_adc_set_adcmd()
132 adc->base + JZ_ADC_REG_ADCMD); in ingenic_adc_set_adcmd()
140 adc->base + JZ_ADC_REG_ADCMD); in ingenic_adc_set_adcmd()
146 adc->base + JZ_ADC_REG_ADCMD); in ingenic_adc_set_adcmd()
153 adc->base + JZ_ADC_REG_ADCMD); in ingenic_adc_set_adcmd()
158 adc->base + JZ_ADC_REG_ADCMD); in ingenic_adc_set_adcmd()
162 writel(0, adc->base + JZ_ADC_REG_ADCMD); in ingenic_adc_set_adcmd()
164 mutex_unlock(&adc->lock); in ingenic_adc_set_adcmd()
167 static void ingenic_adc_set_config(struct ingenic_adc *adc, in ingenic_adc_set_config() argument
173 mutex_lock(&adc->lock); in ingenic_adc_set_config()
175 cfg = readl(adc->base + JZ_ADC_REG_CFG) & ~mask; in ingenic_adc_set_config()
177 writel(cfg, adc->base + JZ_ADC_REG_CFG); in ingenic_adc_set_config()
179 mutex_unlock(&adc->lock); in ingenic_adc_set_config()
182 static void ingenic_adc_enable_unlocked(struct ingenic_adc *adc, in ingenic_adc_enable_unlocked() argument
188 val = readb(adc->base + JZ_ADC_REG_ENABLE); in ingenic_adc_enable_unlocked()
195 writeb(val, adc->base + JZ_ADC_REG_ENABLE); in ingenic_adc_enable_unlocked()
198 static void ingenic_adc_enable(struct ingenic_adc *adc, in ingenic_adc_enable() argument
202 mutex_lock(&adc->lock); in ingenic_adc_enable()
203 ingenic_adc_enable_unlocked(adc, engine, enabled); in ingenic_adc_enable()
204 mutex_unlock(&adc->lock); in ingenic_adc_enable()
207 static int ingenic_adc_capture(struct ingenic_adc *adc, in ingenic_adc_capture() argument
219 mutex_lock(&adc->lock); in ingenic_adc_capture()
220 cfg = readl(adc->base + JZ_ADC_REG_CFG); in ingenic_adc_capture()
221 writel(cfg & ~JZ_ADC_REG_CFG_CMD_SEL, adc->base + JZ_ADC_REG_CFG); in ingenic_adc_capture()
223 ingenic_adc_enable_unlocked(adc, engine, true); in ingenic_adc_capture()
224 ret = readb_poll_timeout(adc->base + JZ_ADC_REG_ENABLE, val, in ingenic_adc_capture()
227 ingenic_adc_enable_unlocked(adc, engine, false); in ingenic_adc_capture()
229 writel(cfg, adc->base + JZ_ADC_REG_CFG); in ingenic_adc_capture()
230 mutex_unlock(&adc->lock); in ingenic_adc_capture()
241 struct ingenic_adc *adc = iio_priv(iio_dev); in ingenic_adc_write_raw() local
249 if (!adc->soc_data->battery_vref_mode) in ingenic_adc_write_raw()
252 ret = clk_enable(adc->clk); in ingenic_adc_write_raw()
260 ingenic_adc_set_config(adc, in ingenic_adc_write_raw()
263 adc->low_vref_mode = false; in ingenic_adc_write_raw()
265 ingenic_adc_set_config(adc, in ingenic_adc_write_raw()
268 adc->low_vref_mode = true; in ingenic_adc_write_raw()
271 clk_disable(adc->clk); in ingenic_adc_write_raw()
312 static int jz4725b_adc_init_clk_div(struct device *dev, struct ingenic_adc *adc) in jz4725b_adc_init_clk_div() argument
318 parent_clk = clk_get_parent(adc->clk); in jz4725b_adc_init_clk_div()
343 adc->base + JZ_ADC_REG_ADCLK); in jz4725b_adc_init_clk_div()
348 static int jz4770_adc_init_clk_div(struct device *dev, struct ingenic_adc *adc) in jz4770_adc_init_clk_div() argument
354 parent_clk = clk_get_parent(adc->clk); in jz4770_adc_init_clk_div()
381 adc->base + JZ_ADC_REG_ADCLK); in jz4770_adc_init_clk_div()
611 struct ingenic_adc *adc = iio_priv(iio_dev); in ingenic_adc_read_avail() local
616 *length = adc->soc_data->battery_raw_avail_size; in ingenic_adc_read_avail()
617 *vals = adc->soc_data->battery_raw_avail; in ingenic_adc_read_avail()
621 *length = adc->soc_data->battery_scale_avail_size; in ingenic_adc_read_avail()
622 *vals = adc->soc_data->battery_scale_avail; in ingenic_adc_read_avail()
634 struct ingenic_adc *adc = iio_priv(iio_dev); in ingenic_adc_read_chan_info_raw() local
636 ret = clk_enable(adc->clk); in ingenic_adc_read_chan_info_raw()
644 mutex_lock(&adc->aux_lock); in ingenic_adc_read_chan_info_raw()
645 if (adc->soc_data->has_aux_md && engine == 0) { in ingenic_adc_read_chan_info_raw()
658 ingenic_adc_set_config(adc, JZ_ADC_REG_CFG_AUX_MD, cmd); in ingenic_adc_read_chan_info_raw()
661 ret = ingenic_adc_capture(adc, engine); in ingenic_adc_read_chan_info_raw()
669 *val = readw(adc->base + JZ_ADC_REG_ADSDAT); in ingenic_adc_read_chan_info_raw()
672 *val = readw(adc->base + JZ_ADC_REG_ADBDAT); in ingenic_adc_read_chan_info_raw()
678 mutex_unlock(&adc->aux_lock); in ingenic_adc_read_chan_info_raw()
679 clk_disable(adc->clk); in ingenic_adc_read_chan_info_raw()
690 struct ingenic_adc *adc = iio_priv(iio_dev); in ingenic_adc_read_raw() local
704 if (adc->low_vref_mode) { in ingenic_adc_read_raw()
708 *val = adc->soc_data->battery_high_vref; in ingenic_adc_read_raw()
709 *val2 = adc->soc_data->battery_high_vref_bits; in ingenic_adc_read_raw()
749 struct ingenic_adc *adc = iio_priv(iio_dev); in ingenic_adc_buffer_enable() local
752 ret = clk_enable(adc->clk); in ingenic_adc_buffer_enable()
761 ingenic_adc_set_config(adc, JZ_ADC_REG_CFG_TOUCH_OPS_MASK, in ingenic_adc_buffer_enable()
765 writew(80, adc->base + JZ_ADC_REG_ADWAIT); in ingenic_adc_buffer_enable()
766 writew(2, adc->base + JZ_ADC_REG_ADSAME); in ingenic_adc_buffer_enable()
767 writeb((u8)~JZ_ADC_IRQ_TOUCH, adc->base + JZ_ADC_REG_CTRL); in ingenic_adc_buffer_enable()
768 writel(0, adc->base + JZ_ADC_REG_ADTCH); in ingenic_adc_buffer_enable()
770 ingenic_adc_set_config(adc, JZ_ADC_REG_CFG_CMD_SEL, in ingenic_adc_buffer_enable()
774 ingenic_adc_enable(adc, 2, true); in ingenic_adc_buffer_enable()
781 struct ingenic_adc *adc = iio_priv(iio_dev); in ingenic_adc_buffer_disable() local
783 ingenic_adc_enable(adc, 2, false); in ingenic_adc_buffer_disable()
785 ingenic_adc_set_config(adc, JZ_ADC_REG_CFG_CMD_SEL, 0); in ingenic_adc_buffer_disable()
787 writeb(0xff, adc->base + JZ_ADC_REG_CTRL); in ingenic_adc_buffer_disable()
788 writeb(0xff, adc->base + JZ_ADC_REG_STATUS); in ingenic_adc_buffer_disable()
789 ingenic_adc_set_config(adc, JZ_ADC_REG_CFG_TOUCH_OPS_MASK, 0); in ingenic_adc_buffer_disable()
790 writew(0, adc->base + JZ_ADC_REG_ADSAME); in ingenic_adc_buffer_disable()
791 writew(0, adc->base + JZ_ADC_REG_ADWAIT); in ingenic_adc_buffer_disable()
792 clk_disable(adc->clk); in ingenic_adc_buffer_disable()
805 struct ingenic_adc *adc = iio_priv(iio_dev); in ingenic_adc_irq() local
812 tdat[i] = readl(adc->base + JZ_ADC_REG_ADTCH); in ingenic_adc_irq()
818 writeb(JZ_ADC_IRQ_TOUCH, adc->base + JZ_ADC_REG_STATUS); in ingenic_adc_irq()
827 struct ingenic_adc *adc; in ingenic_adc_probe() local
835 iio_dev = devm_iio_device_alloc(dev, sizeof(*adc)); in ingenic_adc_probe()
839 adc = iio_priv(iio_dev); in ingenic_adc_probe()
840 mutex_init(&adc->lock); in ingenic_adc_probe()
841 mutex_init(&adc->aux_lock); in ingenic_adc_probe()
842 adc->soc_data = soc_data; in ingenic_adc_probe()
855 adc->base = devm_platform_ioremap_resource(pdev, 0); in ingenic_adc_probe()
856 if (IS_ERR(adc->base)) in ingenic_adc_probe()
857 return PTR_ERR(adc->base); in ingenic_adc_probe()
859 adc->clk = devm_clk_get(dev, "adc"); in ingenic_adc_probe()
860 if (IS_ERR(adc->clk)) { in ingenic_adc_probe()
862 return PTR_ERR(adc->clk); in ingenic_adc_probe()
865 ret = clk_prepare_enable(adc->clk); in ingenic_adc_probe()
873 ret = soc_data->init_clk_div(dev, adc); in ingenic_adc_probe()
875 clk_disable_unprepare(adc->clk); in ingenic_adc_probe()
881 writeb(0x00, adc->base + JZ_ADC_REG_ENABLE); in ingenic_adc_probe()
882 writeb(0xff, adc->base + JZ_ADC_REG_CTRL); in ingenic_adc_probe()
886 ingenic_adc_set_config(adc, JZ_ADC_REG_CFG_VBAT_SEL, in ingenic_adc_probe()
889 ingenic_adc_set_config(adc, JZ_ADC_REG_CFG_VBAT_SEL, 0); in ingenic_adc_probe()
892 clk_disable(adc->clk); in ingenic_adc_probe()
894 ret = devm_add_action_or_reset(dev, ingenic_adc_clk_cleanup, adc->clk); in ingenic_adc_probe()