Lines Matching refs:st
428 #define at91_adc_readl(st, reg) \ argument
429 readl_relaxed((st)->base + (st)->soc_info.platform->layout->reg)
430 #define at91_adc_read_chan(st, reg) \ argument
431 readl_relaxed((st)->base + reg)
432 #define at91_adc_writel(st, reg, val) \ argument
433 writel_relaxed(val, (st)->base + (st)->soc_info.platform->layout->reg)
777 struct at91_adc_state *st = iio_priv(indio_dev); in at91_adc_active_scan_mask_to_reg() local
786 return mask & GENMASK(st->soc_info.platform->nr_channels, 0); in at91_adc_active_scan_mask_to_reg()
789 static void at91_adc_cor(struct at91_adc_state *st, in at91_adc_cor() argument
796 cur_cor = at91_adc_readl(st, COR); in at91_adc_cor()
797 cor <<= st->soc_info.platform->layout->COR_diff_offset; in at91_adc_cor()
799 at91_adc_writel(st, COR, cur_cor | cor); in at91_adc_cor()
801 at91_adc_writel(st, COR, cur_cor & ~cor); in at91_adc_cor()
804 static void at91_adc_irq_status(struct at91_adc_state *st, u32 *status, in at91_adc_irq_status() argument
807 *status = at91_adc_readl(st, ISR); in at91_adc_irq_status()
808 if (st->soc_info.platform->layout->EOC_ISR) in at91_adc_irq_status()
809 *eoc = at91_adc_readl(st, EOC_ISR); in at91_adc_irq_status()
814 static void at91_adc_irq_mask(struct at91_adc_state *st, u32 *status, u32 *eoc) in at91_adc_irq_mask() argument
816 *status = at91_adc_readl(st, IMR); in at91_adc_irq_mask()
817 if (st->soc_info.platform->layout->EOC_IMR) in at91_adc_irq_mask()
818 *eoc = at91_adc_readl(st, EOC_IMR); in at91_adc_irq_mask()
823 static void at91_adc_eoc_dis(struct at91_adc_state *st, unsigned int channel) in at91_adc_eoc_dis() argument
830 if (!st->soc_info.platform->layout->EOC_IDR) in at91_adc_eoc_dis()
831 at91_adc_writel(st, IDR, BIT(channel)); in at91_adc_eoc_dis()
834 static void at91_adc_eoc_ena(struct at91_adc_state *st, unsigned int channel) in at91_adc_eoc_ena() argument
836 if (!st->soc_info.platform->layout->EOC_IDR) in at91_adc_eoc_ena()
837 at91_adc_writel(st, IER, BIT(channel)); in at91_adc_eoc_ena()
839 at91_adc_writel(st, EOC_IER, BIT(channel)); in at91_adc_eoc_ena()
842 static int at91_adc_config_emr(struct at91_adc_state *st, in at91_adc_config_emr() argument
847 unsigned int osr_mask = st->soc_info.platform->osr_mask; in at91_adc_config_emr()
851 for (i = 0; i < st->soc_info.platform->oversampling_avail_no; i++) { in at91_adc_config_emr()
852 if (oversampling_ratio == st->soc_info.platform->oversampling_avail[i]) in at91_adc_config_emr()
855 if (i == st->soc_info.platform->oversampling_avail_no) in at91_adc_config_emr()
882 ret = pm_runtime_resume_and_get(st->dev); in at91_adc_config_emr()
886 emr = at91_adc_readl(st, EMR); in at91_adc_config_emr()
893 at91_adc_writel(st, EMR, emr); in at91_adc_config_emr()
895 pm_runtime_mark_last_busy(st->dev); in at91_adc_config_emr()
896 pm_runtime_put_autosuspend(st->dev); in at91_adc_config_emr()
898 st->oversampling_ratio = oversampling_ratio; in at91_adc_config_emr()
903 static int at91_adc_adjust_val_osr(struct at91_adc_state *st, int *val) in at91_adc_adjust_val_osr() argument
907 if (st->oversampling_ratio == 1) in at91_adc_adjust_val_osr()
909 else if (st->oversampling_ratio == 4) in at91_adc_adjust_val_osr()
911 else if (st->oversampling_ratio == 16) in at91_adc_adjust_val_osr()
913 else if (st->oversampling_ratio == 64) in at91_adc_adjust_val_osr()
915 else if (st->oversampling_ratio == 256) in at91_adc_adjust_val_osr()
925 diff = st->soc_info.platform->chan_realbits - nbits; in at91_adc_adjust_val_osr()
931 static void at91_adc_adjust_val_osr_array(struct at91_adc_state *st, void *buf, in at91_adc_adjust_val_osr_array() argument
947 at91_adc_adjust_val_osr(st, &val); in at91_adc_adjust_val_osr_array()
953 static int at91_adc_configure_touch(struct at91_adc_state *st, bool state) in at91_adc_configure_touch() argument
955 u32 clk_khz = st->current_sample_rate / 1000; in at91_adc_configure_touch()
961 ret = pm_runtime_resume_and_get(st->dev); in at91_adc_configure_touch()
966 at91_adc_writel(st, IDR, in at91_adc_configure_touch()
968 at91_adc_writel(st, TSMR, 0); in at91_adc_configure_touch()
970 pm_runtime_mark_last_busy(st->dev); in at91_adc_configure_touch()
971 pm_runtime_put_autosuspend(st->dev); in at91_adc_configure_touch()
997 at91_adc_writel(st, TSMR, tsmr); in at91_adc_configure_touch()
999 acr = at91_adc_readl(st, ACR); in at91_adc_configure_touch()
1002 at91_adc_writel(st, ACR, acr); in at91_adc_configure_touch()
1005 st->touch_st.sample_period_val = in at91_adc_configure_touch()
1009 at91_adc_writel(st, IER, AT91_SAMA5D2_IER_PEN); in at91_adc_configure_touch()
1014 static u16 at91_adc_touch_pos(struct at91_adc_state *st, int reg) in at91_adc_touch_pos() argument
1025 if (reg == st->soc_info.platform->layout->XPOSR) in at91_adc_touch_pos()
1026 val = at91_adc_readl(st, XPOSR); in at91_adc_touch_pos()
1027 else if (reg == st->soc_info.platform->layout->YPOSR) in at91_adc_touch_pos()
1028 val = at91_adc_readl(st, YPOSR); in at91_adc_touch_pos()
1031 dev_dbg(&st->indio_dev->dev, "pos is 0\n"); in at91_adc_touch_pos()
1037 dev_err(&st->indio_dev->dev, "scale is 0\n"); in at91_adc_touch_pos()
1045 static u16 at91_adc_touch_x_pos(struct at91_adc_state *st) in at91_adc_touch_x_pos() argument
1047 st->touch_st.x_pos = at91_adc_touch_pos(st, st->soc_info.platform->layout->XPOSR); in at91_adc_touch_x_pos()
1048 return st->touch_st.x_pos; in at91_adc_touch_x_pos()
1051 static u16 at91_adc_touch_y_pos(struct at91_adc_state *st) in at91_adc_touch_y_pos() argument
1053 return at91_adc_touch_pos(st, st->soc_info.platform->layout->YPOSR); in at91_adc_touch_y_pos()
1056 static u16 at91_adc_touch_pressure(struct at91_adc_state *st) in at91_adc_touch_pressure() argument
1065 val = at91_adc_readl(st, PRESSR); in at91_adc_touch_pressure()
1070 pres = rxp * (st->touch_st.x_pos * factor / 1024) * in at91_adc_touch_pressure()
1084 static int at91_adc_read_position(struct at91_adc_state *st, int chan, u16 *val) in at91_adc_read_position() argument
1087 if (!st->touch_st.touching) in at91_adc_read_position()
1089 if (chan == st->soc_info.platform->touch_chan_x) in at91_adc_read_position()
1090 *val = at91_adc_touch_x_pos(st); in at91_adc_read_position()
1091 else if (chan == st->soc_info.platform->touch_chan_y) in at91_adc_read_position()
1092 *val = at91_adc_touch_y_pos(st); in at91_adc_read_position()
1099 static int at91_adc_read_pressure(struct at91_adc_state *st, int chan, u16 *val) in at91_adc_read_pressure() argument
1102 if (!st->touch_st.touching) in at91_adc_read_pressure()
1104 if (chan == st->soc_info.platform->touch_chan_p) in at91_adc_read_pressure()
1105 *val = at91_adc_touch_pressure(st); in at91_adc_read_pressure()
1112 static void at91_adc_configure_trigger_registers(struct at91_adc_state *st, in at91_adc_configure_trigger_registers() argument
1115 u32 status = at91_adc_readl(st, TRGR); in at91_adc_configure_trigger_registers()
1121 status |= st->selected_trig->trgmod_value; in at91_adc_configure_trigger_registers()
1124 at91_adc_writel(st, TRGR, status); in at91_adc_configure_trigger_registers()
1130 struct at91_adc_state *st = iio_priv(indio); in at91_adc_configure_trigger() local
1134 ret = pm_runtime_resume_and_get(st->dev); in at91_adc_configure_trigger()
1139 at91_adc_configure_trigger_registers(st, state); in at91_adc_configure_trigger()
1142 pm_runtime_mark_last_busy(st->dev); in at91_adc_configure_trigger()
1143 pm_runtime_put_autosuspend(st->dev); in at91_adc_configure_trigger()
1152 struct at91_adc_state *st = iio_priv(indio); in at91_adc_reenable_trigger() local
1155 if (st->dma_st.dma_chan) in at91_adc_reenable_trigger()
1158 enable_irq(st->irq); in at91_adc_reenable_trigger()
1161 at91_adc_readl(st, LCDR); in at91_adc_reenable_trigger()
1170 static int at91_adc_dma_size_done(struct at91_adc_state *st) in at91_adc_dma_size_done() argument
1176 status = dmaengine_tx_status(st->dma_st.dma_chan, in at91_adc_dma_size_done()
1177 st->dma_st.dma_chan->cookie, in at91_adc_dma_size_done()
1183 i = st->dma_st.rx_buf_sz - state.residue; in at91_adc_dma_size_done()
1186 if (i >= st->dma_st.buf_idx) in at91_adc_dma_size_done()
1187 size = i - st->dma_st.buf_idx; in at91_adc_dma_size_done()
1189 size = st->dma_st.rx_buf_sz + i - st->dma_st.buf_idx; in at91_adc_dma_size_done()
1202 struct at91_adc_state *st = iio_priv(indio_dev); in at91_adc_dma_start() local
1208 if (!st->dma_st.dma_chan) in at91_adc_dma_start()
1212 st->dma_st.buf_idx = 0; in at91_adc_dma_start()
1218 st->dma_st.rx_buf_sz = 0; in at91_adc_dma_start()
1228 st->dma_st.rx_buf_sz += chan->scan_type.storagebits / 8; in at91_adc_dma_start()
1230 st->dma_st.rx_buf_sz *= st->dma_st.watermark; in at91_adc_dma_start()
1233 desc = dmaengine_prep_dma_cyclic(st->dma_st.dma_chan, in at91_adc_dma_start()
1234 st->dma_st.rx_dma_buf, in at91_adc_dma_start()
1235 st->dma_st.rx_buf_sz, in at91_adc_dma_start()
1236 st->dma_st.rx_buf_sz / 2, in at91_adc_dma_start()
1251 dmaengine_terminate_async(st->dma_st.dma_chan); in at91_adc_dma_start()
1256 at91_adc_writel(st, IER, AT91_SAMA5D2_IER_GOVRE); in at91_adc_dma_start()
1258 dma_async_issue_pending(st->dma_st.dma_chan); in at91_adc_dma_start()
1261 st->dma_st.dma_ts = iio_get_time_ns(indio_dev); in at91_adc_dma_start()
1269 struct at91_adc_state *st) in at91_adc_buffer_check_use_irq() argument
1272 if (st->dma_st.dma_chan) in at91_adc_buffer_check_use_irq()
1282 struct at91_adc_state *st = iio_priv(indio_dev); in at91_adc_current_chan_is_touch() local
1285 &st->touch_st.channels_bitmask, in at91_adc_current_chan_is_touch()
1286 st->soc_info.platform->max_index + 1); in at91_adc_current_chan_is_touch()
1293 struct at91_adc_state *st = iio_priv(indio_dev); in at91_adc_buffer_prepare() local
1297 return at91_adc_configure_touch(st, true); in at91_adc_buffer_prepare()
1303 ret = pm_runtime_resume_and_get(st->dev); in at91_adc_buffer_prepare()
1326 at91_adc_cor(st, chan); in at91_adc_buffer_prepare()
1328 at91_adc_writel(st, CHER, BIT(chan->channel)); in at91_adc_buffer_prepare()
1331 if (at91_adc_buffer_check_use_irq(indio_dev, st)) in at91_adc_buffer_prepare()
1332 at91_adc_writel(st, IER, AT91_SAMA5D2_IER_DRDY); in at91_adc_buffer_prepare()
1335 pm_runtime_mark_last_busy(st->dev); in at91_adc_buffer_prepare()
1336 pm_runtime_put_autosuspend(st->dev); in at91_adc_buffer_prepare()
1342 struct at91_adc_state *st = iio_priv(indio_dev); in at91_adc_buffer_postdisable() local
1348 return at91_adc_configure_touch(st, false); in at91_adc_buffer_postdisable()
1354 ret = pm_runtime_resume_and_get(st->dev); in at91_adc_buffer_postdisable()
1377 at91_adc_writel(st, CHDR, BIT(chan->channel)); in at91_adc_buffer_postdisable()
1379 if (st->dma_st.dma_chan) in at91_adc_buffer_postdisable()
1380 at91_adc_read_chan(st, chan->address); in at91_adc_buffer_postdisable()
1383 if (at91_adc_buffer_check_use_irq(indio_dev, st)) in at91_adc_buffer_postdisable()
1384 at91_adc_writel(st, IDR, AT91_SAMA5D2_IER_DRDY); in at91_adc_buffer_postdisable()
1387 at91_adc_readl(st, OVER); in at91_adc_buffer_postdisable()
1390 if (st->dma_st.dma_chan) in at91_adc_buffer_postdisable()
1391 dmaengine_terminate_sync(st->dma_st.dma_chan); in at91_adc_buffer_postdisable()
1393 pm_runtime_mark_last_busy(st->dev); in at91_adc_buffer_postdisable()
1394 pm_runtime_put_autosuspend(st->dev); in at91_adc_buffer_postdisable()
1428 struct at91_adc_state *st = iio_priv(indio_dev); in at91_adc_trigger_handler_nodma() local
1441 at91_adc_irq_status(st, &status, &eoc); in at91_adc_trigger_handler_nodma()
1442 at91_adc_irq_mask(st, &imr, &eoc_imr); in at91_adc_trigger_handler_nodma()
1469 val = at91_adc_read_chan(st, chan->address); in at91_adc_trigger_handler_nodma()
1470 at91_adc_adjust_val_osr(st, &val); in at91_adc_trigger_handler_nodma()
1471 st->buffer[i] = val; in at91_adc_trigger_handler_nodma()
1473 st->buffer[i] = 0; in at91_adc_trigger_handler_nodma()
1478 iio_push_to_buffers_with_timestamp(indio_dev, st->buffer, in at91_adc_trigger_handler_nodma()
1484 struct at91_adc_state *st = iio_priv(indio_dev); in at91_adc_trigger_handler_dma() local
1485 int transferred_len = at91_adc_dma_size_done(st); in at91_adc_trigger_handler_dma()
1490 u32 status = at91_adc_readl(st, ISR); in at91_adc_trigger_handler_dma()
1496 sample_size = div_s64(st->dma_st.rx_buf_sz, st->dma_st.watermark); in at91_adc_trigger_handler_dma()
1504 interval = div_s64((ns - st->dma_st.dma_ts), sample_count); in at91_adc_trigger_handler_dma()
1511 at91_adc_adjust_val_osr_array(st, in at91_adc_trigger_handler_dma()
1512 &st->dma_st.rx_buf[st->dma_st.buf_idx], in at91_adc_trigger_handler_dma()
1516 (st->dma_st.rx_buf + st->dma_st.buf_idx), in at91_adc_trigger_handler_dma()
1517 (st->dma_st.dma_ts + interval * sample_index)); in at91_adc_trigger_handler_dma()
1521 st->dma_st.buf_idx += sample_size; in at91_adc_trigger_handler_dma()
1523 if (st->dma_st.buf_idx >= st->dma_st.rx_buf_sz) in at91_adc_trigger_handler_dma()
1524 st->dma_st.buf_idx = 0; in at91_adc_trigger_handler_dma()
1528 st->dma_st.dma_ts = iio_get_time_ns(indio_dev); in at91_adc_trigger_handler_dma()
1535 struct at91_adc_state *st = iio_priv(indio_dev); in at91_adc_trigger_handler() local
1542 at91_adc_writel(st, CR, AT91_SAMA5D2_CR_START); in at91_adc_trigger_handler()
1544 if (st->dma_st.dma_chan) in at91_adc_trigger_handler()
1582 struct at91_adc_state *st = iio_priv(indio_dev); in at91_adc_setup_samp_freq() local
1586 f_per = clk_get_rate(st->per_clk); in at91_adc_setup_samp_freq()
1591 ret = pm_runtime_resume_and_get(st->dev); in at91_adc_setup_samp_freq()
1595 mr = at91_adc_readl(st, MR); in at91_adc_setup_samp_freq()
1600 at91_adc_writel(st, MR, mr); in at91_adc_setup_samp_freq()
1602 pm_runtime_mark_last_busy(st->dev); in at91_adc_setup_samp_freq()
1603 pm_runtime_put_autosuspend(st->dev); in at91_adc_setup_samp_freq()
1607 st->current_sample_rate = freq; in at91_adc_setup_samp_freq()
1610 static inline unsigned at91_adc_get_sample_freq(struct at91_adc_state *st) in at91_adc_get_sample_freq() argument
1612 return st->current_sample_rate; in at91_adc_get_sample_freq()
1617 struct at91_adc_state *st = iio_priv(indio_dev); in at91_adc_touch_data_handler() local
1623 st->soc_info.platform->max_index + 1) { in at91_adc_touch_data_handler()
1628 at91_adc_read_position(st, chan->channel, &val); in at91_adc_touch_data_handler()
1630 at91_adc_read_pressure(st, chan->channel, &val); in at91_adc_touch_data_handler()
1633 st->buffer[i] = val; in at91_adc_touch_data_handler()
1644 schedule_work(&st->touch_st.workq); in at91_adc_touch_data_handler()
1647 static void at91_adc_pen_detect_interrupt(struct at91_adc_state *st) in at91_adc_pen_detect_interrupt() argument
1649 at91_adc_writel(st, IDR, AT91_SAMA5D2_IER_PEN); in at91_adc_pen_detect_interrupt()
1650 at91_adc_writel(st, IER, AT91_SAMA5D2_IER_NOPEN | in at91_adc_pen_detect_interrupt()
1653 at91_adc_writel(st, TRGR, AT91_SAMA5D2_TRGR_TRGMOD_PERIODIC | in at91_adc_pen_detect_interrupt()
1654 AT91_SAMA5D2_TRGR_TRGPER(st->touch_st.sample_period_val)); in at91_adc_pen_detect_interrupt()
1655 st->touch_st.touching = true; in at91_adc_pen_detect_interrupt()
1660 struct at91_adc_state *st = iio_priv(indio_dev); in at91_adc_no_pen_detect_interrupt() local
1662 at91_adc_writel(st, TRGR, AT91_SAMA5D2_TRGR_TRGMOD_NO_TRIGGER); in at91_adc_no_pen_detect_interrupt()
1663 at91_adc_writel(st, IDR, AT91_SAMA5D2_IER_NOPEN | in at91_adc_no_pen_detect_interrupt()
1666 st->touch_st.touching = false; in at91_adc_no_pen_detect_interrupt()
1670 at91_adc_writel(st, IER, AT91_SAMA5D2_IER_PEN); in at91_adc_no_pen_detect_interrupt()
1677 struct at91_adc_state *st = container_of(touch_st, in at91_adc_workq_handler() local
1679 struct iio_dev *indio_dev = st->indio_dev; in at91_adc_workq_handler()
1681 iio_push_to_buffers(indio_dev, st->buffer); in at91_adc_workq_handler()
1687 struct at91_adc_state *st = iio_priv(indio); in at91_adc_interrupt() local
1692 at91_adc_irq_status(st, &status, &eoc); in at91_adc_interrupt()
1693 at91_adc_irq_mask(st, &imr, &eoc_imr); in at91_adc_interrupt()
1699 at91_adc_pen_detect_interrupt(st); in at91_adc_interrupt()
1712 status = at91_adc_readl(st, XPOSR); in at91_adc_interrupt()
1713 status = at91_adc_readl(st, YPOSR); in at91_adc_interrupt()
1714 status = at91_adc_readl(st, PRESSR); in at91_adc_interrupt()
1720 } else if (iio_buffer_enabled(indio) && st->dma_st.dma_chan) { in at91_adc_interrupt()
1726 st->conversion_value = at91_adc_read_chan(st, st->chan->address); in at91_adc_interrupt()
1727 st->conversion_done = true; in at91_adc_interrupt()
1728 wake_up_interruptible(&st->wq_data_available); in at91_adc_interrupt()
1737 struct at91_adc_state *st = iio_priv(indio_dev); in at91_adc_read_info_raw() local
1741 ret = pm_runtime_resume_and_get(st->dev); in at91_adc_read_info_raw()
1750 ret = at91_adc_read_position(st, chan->channel, in at91_adc_read_info_raw()
1754 ret = at91_adc_adjust_val_osr(st, val); in at91_adc_read_info_raw()
1759 ret = at91_adc_read_pressure(st, chan->channel, in at91_adc_read_info_raw()
1763 ret = at91_adc_adjust_val_osr(st, val); in at91_adc_read_info_raw()
1770 st->chan = chan; in at91_adc_read_info_raw()
1772 at91_adc_cor(st, chan); in at91_adc_read_info_raw()
1773 at91_adc_writel(st, CHER, BIT(chan->channel)); in at91_adc_read_info_raw()
1780 at91_adc_writel(st, TEMPMR, AT91_SAMA5D2_TEMPMR_TEMPON); in at91_adc_read_info_raw()
1781 at91_adc_eoc_ena(st, chan->channel); in at91_adc_read_info_raw()
1782 at91_adc_writel(st, CR, AT91_SAMA5D2_CR_START); in at91_adc_read_info_raw()
1784 ret = wait_event_interruptible_timeout(st->wq_data_available, in at91_adc_read_info_raw()
1785 st->conversion_done, in at91_adc_read_info_raw()
1791 *val = st->conversion_value; in at91_adc_read_info_raw()
1792 ret = at91_adc_adjust_val_osr(st, val); in at91_adc_read_info_raw()
1796 st->conversion_done = false; in at91_adc_read_info_raw()
1799 at91_adc_eoc_dis(st, st->chan->channel); in at91_adc_read_info_raw()
1801 at91_adc_writel(st, TEMPMR, 0U); in at91_adc_read_info_raw()
1802 at91_adc_writel(st, CHDR, BIT(chan->channel)); in at91_adc_read_info_raw()
1805 at91_adc_readl(st, LCDR); in at91_adc_read_info_raw()
1808 pm_runtime_mark_last_busy(st->dev); in at91_adc_read_info_raw()
1809 pm_runtime_put_autosuspend(st->dev); in at91_adc_read_info_raw()
1816 struct at91_adc_state *st = iio_priv(indio_dev); in at91_adc_read_info_locked() local
1823 mutex_lock(&st->lock); in at91_adc_read_info_locked()
1825 mutex_unlock(&st->lock); in at91_adc_read_info_locked()
1832 static void at91_adc_temp_sensor_configure(struct at91_adc_state *st, in at91_adc_temp_sensor_configure() argument
1849 st->temp_st.saved_sample_rate = st->current_sample_rate; in at91_adc_temp_sensor_configure()
1850 st->temp_st.saved_oversampling = st->oversampling_ratio; in at91_adc_temp_sensor_configure()
1853 sample_rate = st->temp_st.saved_sample_rate; in at91_adc_temp_sensor_configure()
1854 oversampling_ratio = st->temp_st.saved_oversampling; in at91_adc_temp_sensor_configure()
1855 startup_time = st->soc_info.startup_time; in at91_adc_temp_sensor_configure()
1860 at91_adc_setup_samp_freq(st->indio_dev, sample_rate, startup_time, in at91_adc_temp_sensor_configure()
1862 at91_adc_config_emr(st, oversampling_ratio, trackx); in at91_adc_temp_sensor_configure()
1868 struct at91_adc_state *st = iio_priv(indio_dev); in at91_adc_read_temp() local
1869 struct at91_adc_temp_sensor_clb *clb = &st->soc_info.temp_sensor_clb; in at91_adc_read_temp()
1877 mutex_lock(&st->lock); in at91_adc_read_temp()
1879 ret = pm_runtime_resume_and_get(st->dev); in at91_adc_read_temp()
1883 at91_adc_temp_sensor_configure(st, true); in at91_adc_read_temp()
1886 tmp = at91_adc_readl(st, ACR); in at91_adc_read_temp()
1888 at91_adc_writel(st, ACR, tmp); in at91_adc_read_temp()
1895 at91_adc_writel(st, ACR, tmp); in at91_adc_read_temp()
1900 at91_adc_temp_sensor_configure(st, false); in at91_adc_read_temp()
1901 pm_runtime_mark_last_busy(st->dev); in at91_adc_read_temp()
1902 pm_runtime_put_autosuspend(st->dev); in at91_adc_read_temp()
1904 mutex_unlock(&st->lock); in at91_adc_read_temp()
1926 struct at91_adc_state *st = iio_priv(indio_dev); in at91_adc_read_raw() local
1933 *val = st->vref_uv / 1000; in at91_adc_read_raw()
1945 *val = at91_adc_get_sample_freq(st); in at91_adc_read_raw()
1949 *val = st->oversampling_ratio; in at91_adc_read_raw()
1961 struct at91_adc_state *st = iio_priv(indio_dev); in at91_adc_write_raw() local
1967 if (val == st->oversampling_ratio) in at91_adc_write_raw()
1973 mutex_lock(&st->lock); in at91_adc_write_raw()
1975 ret = at91_adc_config_emr(st, val, 0); in at91_adc_write_raw()
1976 mutex_unlock(&st->lock); in at91_adc_write_raw()
1980 if (val < st->soc_info.min_sample_rate || in at91_adc_write_raw()
1981 val > st->soc_info.max_sample_rate) in at91_adc_write_raw()
1987 mutex_lock(&st->lock); in at91_adc_write_raw()
1989 st->soc_info.startup_time, 0); in at91_adc_write_raw()
1990 mutex_unlock(&st->lock); in at91_adc_write_raw()
2003 struct at91_adc_state *st = iio_priv(indio_dev); in at91_adc_read_avail() local
2007 *vals = (int *)st->soc_info.platform->oversampling_avail; in at91_adc_read_avail()
2009 *length = st->soc_info.platform->oversampling_avail_no; in at91_adc_read_avail()
2016 static void at91_adc_dma_init(struct at91_adc_state *st) in at91_adc_dma_init() argument
2018 struct device *dev = &st->indio_dev->dev; in at91_adc_dma_init()
2021 unsigned int sample_size = st->soc_info.platform->nr_channels * 2; in at91_adc_dma_init()
2030 if (st->dma_st.dma_chan) in at91_adc_dma_init()
2033 st->dma_st.dma_chan = dma_request_chan(dev, "rx"); in at91_adc_dma_init()
2034 if (IS_ERR(st->dma_st.dma_chan)) { in at91_adc_dma_init()
2036 st->dma_st.dma_chan = NULL; in at91_adc_dma_init()
2040 st->dma_st.rx_buf = dma_alloc_coherent(st->dma_st.dma_chan->device->dev, in at91_adc_dma_init()
2042 &st->dma_st.rx_dma_buf, in at91_adc_dma_init()
2044 if (!st->dma_st.rx_buf) { in at91_adc_dma_init()
2051 config.src_addr = (phys_addr_t)(st->dma_st.phys_addr in at91_adc_dma_init()
2052 + st->soc_info.platform->layout->LCDR); in at91_adc_dma_init()
2057 if (dmaengine_slave_config(st->dma_st.dma_chan, &config)) { in at91_adc_dma_init()
2063 dma_chan_name(st->dma_st.dma_chan)); in at91_adc_dma_init()
2068 dma_free_coherent(st->dma_st.dma_chan->device->dev, pages * PAGE_SIZE, in at91_adc_dma_init()
2069 st->dma_st.rx_buf, st->dma_st.rx_dma_buf); in at91_adc_dma_init()
2071 dma_release_channel(st->dma_st.dma_chan); in at91_adc_dma_init()
2072 st->dma_st.dma_chan = NULL; in at91_adc_dma_init()
2077 static void at91_adc_dma_disable(struct at91_adc_state *st) in at91_adc_dma_disable() argument
2079 struct device *dev = &st->indio_dev->dev; in at91_adc_dma_disable()
2081 unsigned int sample_size = st->soc_info.platform->nr_channels * 2; in at91_adc_dma_disable()
2086 if (!st->dma_st.dma_chan) in at91_adc_dma_disable()
2090 dmaengine_terminate_sync(st->dma_st.dma_chan); in at91_adc_dma_disable()
2092 dma_free_coherent(st->dma_st.dma_chan->device->dev, pages * PAGE_SIZE, in at91_adc_dma_disable()
2093 st->dma_st.rx_buf, st->dma_st.rx_dma_buf); in at91_adc_dma_disable()
2094 dma_release_channel(st->dma_st.dma_chan); in at91_adc_dma_disable()
2095 st->dma_st.dma_chan = NULL; in at91_adc_dma_disable()
2102 struct at91_adc_state *st = iio_priv(indio_dev); in at91_adc_set_watermark() local
2108 if (!st->selected_trig->hw_trig) { in at91_adc_set_watermark()
2114 st->dma_st.watermark = val; in at91_adc_set_watermark()
2123 at91_adc_dma_disable(st); in at91_adc_set_watermark()
2125 at91_adc_dma_init(st); in at91_adc_set_watermark()
2133 at91_adc_dma_disable(st); in at91_adc_set_watermark()
2141 struct at91_adc_state *st = iio_priv(indio_dev); in at91_adc_update_scan_mode() local
2143 if (bitmap_subset(scan_mask, &st->touch_st.channels_bitmask, in at91_adc_update_scan_mode()
2144 st->soc_info.platform->max_index + 1)) in at91_adc_update_scan_mode()
2150 if (bitmap_intersects(&st->touch_st.channels_bitmask, scan_mask, in at91_adc_update_scan_mode()
2151 st->soc_info.platform->max_index + 1)) in at91_adc_update_scan_mode()
2158 struct at91_adc_state *st = iio_priv(indio_dev); in at91_adc_hw_init() local
2160 at91_adc_writel(st, CR, AT91_SAMA5D2_CR_SWRST); in at91_adc_hw_init()
2161 if (st->soc_info.platform->layout->EOC_IDR) in at91_adc_hw_init()
2162 at91_adc_writel(st, EOC_IDR, 0xffffffff); in at91_adc_hw_init()
2163 at91_adc_writel(st, IDR, 0xffffffff); in at91_adc_hw_init()
2168 at91_adc_writel(st, MR, in at91_adc_hw_init()
2171 at91_adc_setup_samp_freq(indio_dev, st->soc_info.min_sample_rate, in at91_adc_hw_init()
2172 st->soc_info.startup_time, 0); in at91_adc_hw_init()
2175 at91_adc_config_emr(st, st->oversampling_ratio, 0); in at91_adc_hw_init()
2182 struct at91_adc_state *st = iio_priv(indio_dev); in at91_adc_get_fifo_state() local
2184 return sysfs_emit(buf, "%d\n", !!st->dma_st.dma_chan); in at91_adc_get_fifo_state()
2191 struct at91_adc_state *st = iio_priv(indio_dev); in at91_adc_get_watermark() local
2193 return sysfs_emit(buf, "%d\n", st->dma_st.watermark); in at91_adc_get_watermark()
2224 struct at91_adc_state *st = iio_priv(indio); in at91_adc_buffer_and_trigger_init() local
2228 if (st->selected_trig->hw_trig) in at91_adc_buffer_and_trigger_init()
2241 if (!st->selected_trig->hw_trig) in at91_adc_buffer_and_trigger_init()
2244 st->trig = at91_adc_allocate_trigger(indio, st->selected_trig->name); in at91_adc_buffer_and_trigger_init()
2245 if (IS_ERR(st->trig)) { in at91_adc_buffer_and_trigger_init()
2247 return PTR_ERR(st->trig); in at91_adc_buffer_and_trigger_init()
2254 st->dma_st.watermark = 1; in at91_adc_buffer_and_trigger_init()
2259 static int at91_adc_temp_sensor_init(struct at91_adc_state *st, in at91_adc_temp_sensor_init() argument
2262 struct at91_adc_temp_sensor_clb *clb = &st->soc_info.temp_sensor_clb; in at91_adc_temp_sensor_init()
2268 if (!st->soc_info.platform->temp_sensor) in at91_adc_temp_sensor_init()
2310 struct at91_adc_state *st; in at91_adc_probe() local
2315 indio_dev = devm_iio_device_alloc(&pdev->dev, sizeof(*st)); in at91_adc_probe()
2319 st = iio_priv(indio_dev); in at91_adc_probe()
2320 st->indio_dev = indio_dev; in at91_adc_probe()
2322 st->soc_info.platform = device_get_match_data(dev); in at91_adc_probe()
2324 ret = at91_adc_temp_sensor_init(st, &pdev->dev); in at91_adc_probe()
2327 num_channels = st->soc_info.platform->max_channels - 1; in at91_adc_probe()
2329 num_channels = st->soc_info.platform->max_channels; in at91_adc_probe()
2334 indio_dev->channels = *st->soc_info.platform->adc_channels; in at91_adc_probe()
2337 bitmap_set(&st->touch_st.channels_bitmask, in at91_adc_probe()
2338 st->soc_info.platform->touch_chan_x, 1); in at91_adc_probe()
2339 bitmap_set(&st->touch_st.channels_bitmask, in at91_adc_probe()
2340 st->soc_info.platform->touch_chan_y, 1); in at91_adc_probe()
2341 bitmap_set(&st->touch_st.channels_bitmask, in at91_adc_probe()
2342 st->soc_info.platform->touch_chan_p, 1); in at91_adc_probe()
2344 st->oversampling_ratio = 1; in at91_adc_probe()
2347 &st->soc_info.min_sample_rate); in at91_adc_probe()
2355 &st->soc_info.max_sample_rate); in at91_adc_probe()
2363 &st->soc_info.startup_time); in at91_adc_probe()
2377 st->selected_trig = NULL; in at91_adc_probe()
2380 for (i = 0; i < st->soc_info.platform->hw_trig_cnt + 1; i++) in at91_adc_probe()
2382 st->selected_trig = &at91_adc_trigger_list[i]; in at91_adc_probe()
2386 if (!st->selected_trig) { in at91_adc_probe()
2391 init_waitqueue_head(&st->wq_data_available); in at91_adc_probe()
2392 mutex_init(&st->lock); in at91_adc_probe()
2393 INIT_WORK(&st->touch_st.workq, at91_adc_workq_handler); in at91_adc_probe()
2395 st->base = devm_platform_get_and_ioremap_resource(pdev, 0, &res); in at91_adc_probe()
2396 if (IS_ERR(st->base)) in at91_adc_probe()
2397 return PTR_ERR(st->base); in at91_adc_probe()
2400 st->dma_st.phys_addr = res->start; in at91_adc_probe()
2402 st->irq = platform_get_irq(pdev, 0); in at91_adc_probe()
2403 if (st->irq < 0) in at91_adc_probe()
2404 return st->irq; in at91_adc_probe()
2406 st->per_clk = devm_clk_get(&pdev->dev, "adc_clk"); in at91_adc_probe()
2407 if (IS_ERR(st->per_clk)) in at91_adc_probe()
2408 return PTR_ERR(st->per_clk); in at91_adc_probe()
2410 st->reg = devm_regulator_get(&pdev->dev, "vddana"); in at91_adc_probe()
2411 if (IS_ERR(st->reg)) in at91_adc_probe()
2412 return PTR_ERR(st->reg); in at91_adc_probe()
2414 st->vref = devm_regulator_get(&pdev->dev, "vref"); in at91_adc_probe()
2415 if (IS_ERR(st->vref)) in at91_adc_probe()
2416 return PTR_ERR(st->vref); in at91_adc_probe()
2418 ret = devm_request_irq(&pdev->dev, st->irq, at91_adc_interrupt, 0, in at91_adc_probe()
2423 ret = regulator_enable(st->reg); in at91_adc_probe()
2427 ret = regulator_enable(st->vref); in at91_adc_probe()
2431 st->vref_uv = regulator_get_voltage(st->vref); in at91_adc_probe()
2432 if (st->vref_uv <= 0) { in at91_adc_probe()
2437 ret = clk_prepare_enable(st->per_clk); in at91_adc_probe()
2442 st->dev = &pdev->dev; in at91_adc_probe()
2443 pm_runtime_set_autosuspend_delay(st->dev, 500); in at91_adc_probe()
2444 pm_runtime_use_autosuspend(st->dev); in at91_adc_probe()
2445 pm_runtime_set_active(st->dev); in at91_adc_probe()
2446 pm_runtime_enable(st->dev); in at91_adc_probe()
2447 pm_runtime_get_noresume(st->dev); in at91_adc_probe()
2462 if (st->selected_trig->hw_trig) in at91_adc_probe()
2464 st->selected_trig->name); in at91_adc_probe()
2467 readl_relaxed(st->base + st->soc_info.platform->layout->VERSION)); in at91_adc_probe()
2469 pm_runtime_mark_last_busy(st->dev); in at91_adc_probe()
2470 pm_runtime_put_autosuspend(st->dev); in at91_adc_probe()
2475 at91_adc_dma_disable(st); in at91_adc_probe()
2477 pm_runtime_put_noidle(st->dev); in at91_adc_probe()
2478 pm_runtime_disable(st->dev); in at91_adc_probe()
2479 pm_runtime_set_suspended(st->dev); in at91_adc_probe()
2480 pm_runtime_dont_use_autosuspend(st->dev); in at91_adc_probe()
2481 clk_disable_unprepare(st->per_clk); in at91_adc_probe()
2483 regulator_disable(st->vref); in at91_adc_probe()
2485 regulator_disable(st->reg); in at91_adc_probe()
2492 struct at91_adc_state *st = iio_priv(indio_dev); in at91_adc_remove() local
2496 at91_adc_dma_disable(st); in at91_adc_remove()
2498 pm_runtime_disable(st->dev); in at91_adc_remove()
2499 pm_runtime_set_suspended(st->dev); in at91_adc_remove()
2500 clk_disable_unprepare(st->per_clk); in at91_adc_remove()
2502 regulator_disable(st->vref); in at91_adc_remove()
2503 regulator_disable(st->reg); in at91_adc_remove()
2511 struct at91_adc_state *st = iio_priv(indio_dev); in at91_adc_suspend() local
2514 ret = pm_runtime_resume_and_get(st->dev); in at91_adc_suspend()
2527 at91_adc_writel(st, CR, AT91_SAMA5D2_CR_SWRST); in at91_adc_suspend()
2529 pm_runtime_mark_last_busy(st->dev); in at91_adc_suspend()
2530 pm_runtime_put_noidle(st->dev); in at91_adc_suspend()
2531 clk_disable_unprepare(st->per_clk); in at91_adc_suspend()
2532 regulator_disable(st->vref); in at91_adc_suspend()
2533 regulator_disable(st->reg); in at91_adc_suspend()
2541 struct at91_adc_state *st = iio_priv(indio_dev); in at91_adc_resume() local
2548 ret = regulator_enable(st->reg); in at91_adc_resume()
2552 ret = regulator_enable(st->vref); in at91_adc_resume()
2556 ret = clk_prepare_enable(st->per_clk); in at91_adc_resume()
2560 pm_runtime_get_noresume(st->dev); in at91_adc_resume()
2570 at91_adc_configure_trigger_registers(st, true); in at91_adc_resume()
2573 pm_runtime_mark_last_busy(st->dev); in at91_adc_resume()
2574 pm_runtime_put_autosuspend(st->dev); in at91_adc_resume()
2579 pm_runtime_mark_last_busy(st->dev); in at91_adc_resume()
2580 pm_runtime_put_noidle(st->dev); in at91_adc_resume()
2581 clk_disable_unprepare(st->per_clk); in at91_adc_resume()
2583 regulator_disable(st->vref); in at91_adc_resume()
2585 regulator_disable(st->reg); in at91_adc_resume()
2594 struct at91_adc_state *st = iio_priv(indio_dev); in at91_adc_runtime_suspend() local
2596 clk_disable(st->per_clk); in at91_adc_runtime_suspend()
2604 struct at91_adc_state *st = iio_priv(indio_dev); in at91_adc_runtime_resume() local
2606 return clk_enable(st->per_clk); in at91_adc_runtime_resume()