Lines Matching +full:touchscreen +full:- +full:min +full:- +full:pressure

1 // SPDX-License-Identifier: GPL-2.0-only
12 #include <linux/dma-mapping.h>
36 /* Touchscreen Calibration */
98 /* Interrupt Enable Register - TS X measurement ready */
100 /* Interrupt Enable Register - TS Y measurement ready */
102 /* Interrupt Enable Register - TS pressure measurement ready */
104 /* Interrupt Enable Register - Data ready */
106 /* Interrupt Enable Register - general overrun error */
108 /* Interrupt Enable Register - Pen detect */
110 /* Interrupt Enable Register - No pen detect */
118 /* Interrupt Status Register - Pen touching sense status */
128 /* Extended Mode Register - Oversampling rate */
135 /* Extended Mode Register - Averaging on single trigger event */
150 /* Analog Control Register - Pen detect sensitivity mask */
153 /* Touchscreen Mode Register */
155 /* Touchscreen Mode Register - No touch mode */
157 /* Touchscreen Mode Register - 4 wire screen, no pressure measurement */
159 /* Touchscreen Mode Register - 4 wire screen, pressure measurement */
161 /* Touchscreen Mode Register - 5 wire screen */
163 /* Touchscreen Mode Register - Average samples mask */
165 /* Touchscreen Mode Register - Average samples */
167 /* Touchscreen Mode Register - Touch/trigger frequency ratio mask */
169 /* Touchscreen Mode Register - Touch/trigger frequency ratio */
171 /* Touchscreen Mode Register - Pen Debounce Time mask */
173 /* Touchscreen Mode Register - Pen Debounce Time */
175 /* Touchscreen Mode Register - No DMA for touch measurements */
177 /* Touchscreen Mode Register - Disable pen detection */
179 /* Touchscreen Mode Register - Enable pen detection */
182 /* Touchscreen X Position Register */
184 /* Touchscreen Y Position Register */
186 /* Touchscreen Pressure Register */
202 /* Trigger Mode - trigger period mask */
204 /* Trigger Mode - trigger period */
296 .datasheet_name = "CH"#num"-CH"#num2, \
333 #define at91_adc_readl(st, reg) readl_relaxed(st->base + reg)
334 #define at91_adc_writel(st, reg, val) writel_relaxed(val, st->base + reg)
350 * struct at91_adc_dma - at91-sama5d2 dma information struct
372 * struct at91_adc_touch - at91-sama5d2 touchscreen information struct
375 * @x_pos: temporary placeholder for pressure computation
376 * @channels_bitmask: bitmask with the touchscreen channels enabled
463 AT91_SAMA5D2_CHAN_PRESSURE(AT91_SAMA5D2_TOUCH_P_CHAN_IDX, "pressure"),
470 for (i = 0; i < indio_dev->num_channels; i++) { in at91_adc_chan_xlate()
471 if (indio_dev->channels[i].scan_index == chan) in at91_adc_chan_xlate()
474 return -EINVAL; in at91_adc_chan_xlate()
484 return indio_dev->channels + index; in at91_adc_chan_get()
490 return at91_adc_chan_xlate(indio_dev, iiospec->args[0]); in at91_adc_of_xlate()
498 for_each_set_bit(bit, indio_dev->active_scan_mask, in at91_adc_active_scan_mask_to_reg()
499 indio_dev->num_channels) { in at91_adc_active_scan_mask_to_reg()
502 mask |= BIT(chan->channel); in at91_adc_active_scan_mask_to_reg()
520 switch (st->oversampling_ratio) { in at91_adc_config_emr()
540 if (st->oversampling_ratio == AT91_OSR_1SAMPLES) { in at91_adc_adjust_val_osr()
546 } else if (st->oversampling_ratio == AT91_OSR_4SAMPLES) { in at91_adc_adjust_val_osr()
581 u32 clk_khz = st->current_sample_rate / 1000; in at91_adc_configure_touch()
624 st->touch_st.sample_period_val = in at91_adc_configure_touch()
626 clk_khz / 1000) - 1, 1); in at91_adc_configure_touch()
641 * max = 2^AT91_SAMA5D2_MAX_POS_BITS - 1 in at91_adc_touch_pos()
646 dev_dbg(&st->indio_dev->dev, "pos is 0\n"); in at91_adc_touch_pos()
649 result = (pos << AT91_SAMA5D2_MAX_POS_BITS) - pos; in at91_adc_touch_pos()
652 dev_err(&st->indio_dev->dev, "scale is 0\n"); in at91_adc_touch_pos()
662 st->touch_st.x_pos = at91_adc_touch_pos(st, AT91_SAMA5D2_XPOSR); in at91_adc_touch_x_pos()
663 return st->touch_st.x_pos; in at91_adc_touch_x_pos()
679 /* calculate the pressure */ in at91_adc_touch_pressure()
685 pres = rxp * (st->touch_st.x_pos * factor / 1024) * in at91_adc_touch_pressure()
686 (z2 * factor / z1 - factor) / in at91_adc_touch_pressure()
692 * The pressure from device grows down, minimum is 0xFFFF, maximum 0x0. in at91_adc_touch_pressure()
696 return 0xFFFF - pres; in at91_adc_touch_pressure()
702 if (!st->touch_st.touching) in at91_adc_read_position()
703 return -ENODATA; in at91_adc_read_position()
709 return -ENODATA; in at91_adc_read_position()
717 if (!st->touch_st.touching) in at91_adc_read_pressure()
718 return -ENODATA; in at91_adc_read_pressure()
722 return -ENODATA; in at91_adc_read_pressure()
737 status |= st->selected_trig->trgmod_value; in at91_adc_configure_trigger()
751 if (st->dma_st.dma_chan) in at91_adc_reenable_trigger()
754 enable_irq(st->irq); in at91_adc_reenable_trigger()
774 status = dmaengine_tx_status(st->dma_st.dma_chan, in at91_adc_dma_size_done()
775 st->dma_st.dma_chan->cookie, in at91_adc_dma_size_done()
781 i = st->dma_st.rx_buf_sz - state.residue; in at91_adc_dma_size_done()
784 if (i >= st->dma_st.buf_idx) in at91_adc_dma_size_done()
785 size = i - st->dma_st.buf_idx; in at91_adc_dma_size_done()
787 size = st->dma_st.rx_buf_sz + i - st->dma_st.buf_idx; in at91_adc_dma_size_done()
795 iio_trigger_poll_chained(indio_dev->trig); in at91_dma_buffer_done()
806 if (!st->dma_st.dma_chan) in at91_adc_dma_start()
810 st->dma_st.buf_idx = 0; in at91_adc_dma_start()
816 st->dma_st.rx_buf_sz = 0; in at91_adc_dma_start()
818 for_each_set_bit(bit, indio_dev->active_scan_mask, in at91_adc_dma_start()
819 indio_dev->num_channels) { in at91_adc_dma_start()
826 st->dma_st.rx_buf_sz += chan->scan_type.storagebits / 8; in at91_adc_dma_start()
828 st->dma_st.rx_buf_sz *= st->dma_st.watermark; in at91_adc_dma_start()
831 desc = dmaengine_prep_dma_cyclic(st->dma_st.dma_chan, in at91_adc_dma_start()
832 st->dma_st.rx_dma_buf, in at91_adc_dma_start()
833 st->dma_st.rx_buf_sz, in at91_adc_dma_start()
834 st->dma_st.rx_buf_sz / 2, in at91_adc_dma_start()
838 dev_err(&indio_dev->dev, "cannot prepare DMA cyclic\n"); in at91_adc_dma_start()
839 return -EBUSY; in at91_adc_dma_start()
842 desc->callback = at91_dma_buffer_done; in at91_adc_dma_start()
843 desc->callback_param = indio_dev; in at91_adc_dma_start()
848 dev_err(&indio_dev->dev, "cannot submit DMA cyclic\n"); in at91_adc_dma_start()
849 dmaengine_terminate_async(st->dma_st.dma_chan); in at91_adc_dma_start()
856 dma_async_issue_pending(st->dma_st.dma_chan); in at91_adc_dma_start()
859 st->dma_st.dma_ts = iio_get_time_ns(indio_dev); in at91_adc_dma_start()
861 dev_dbg(&indio_dev->dev, "DMA cyclic started\n"); in at91_adc_dma_start()
869 /* if using DMA, we do not use our own IRQ (we use DMA-controller) */ in at91_adc_buffer_check_use_irq()
870 if (st->dma_st.dma_chan) in at91_adc_buffer_check_use_irq()
873 if (iio_trigger_validate_own_device(indio->trig, indio)) in at91_adc_buffer_check_use_irq()
882 return !!bitmap_subset(indio_dev->active_scan_mask, in at91_adc_current_chan_is_touch()
883 &st->touch_st.channels_bitmask, in at91_adc_current_chan_is_touch()
893 /* check if we are enabling triggered buffer or the touchscreen */ in at91_adc_buffer_prepare()
898 if (!(indio_dev->currentmode & INDIO_ALL_TRIGGERED_MODES)) in at91_adc_buffer_prepare()
899 return -EINVAL; in at91_adc_buffer_prepare()
904 dev_err(&indio_dev->dev, "buffer prepare failed\n"); in at91_adc_buffer_prepare()
908 for_each_set_bit(bit, indio_dev->active_scan_mask, in at91_adc_buffer_prepare()
909 indio_dev->num_channels) { in at91_adc_buffer_prepare()
917 if (chan->type == IIO_POSITIONRELATIVE || in at91_adc_buffer_prepare()
918 chan->type == IIO_PRESSURE) in at91_adc_buffer_prepare()
923 if (chan->differential) in at91_adc_buffer_prepare()
924 cor |= (BIT(chan->channel) | BIT(chan->channel2)) << in at91_adc_buffer_prepare()
927 cor &= ~(BIT(chan->channel) << in at91_adc_buffer_prepare()
932 at91_adc_writel(st, AT91_SAMA5D2_CHER, BIT(chan->channel)); in at91_adc_buffer_prepare()
946 /* check if we are disabling triggered buffer or the touchscreen */ in at91_adc_buffer_postdisable()
951 if (!(indio_dev->currentmode & INDIO_ALL_TRIGGERED_MODES)) in at91_adc_buffer_postdisable()
952 return -EINVAL; in at91_adc_buffer_postdisable()
960 for_each_set_bit(bit, indio_dev->active_scan_mask, in at91_adc_buffer_postdisable()
961 indio_dev->num_channels) { in at91_adc_buffer_postdisable()
968 if (chan->type == IIO_POSITIONRELATIVE || in at91_adc_buffer_postdisable()
969 chan->type == IIO_PRESSURE) in at91_adc_buffer_postdisable()
972 at91_adc_writel(st, AT91_SAMA5D2_CHDR, BIT(chan->channel)); in at91_adc_buffer_postdisable()
974 if (st->dma_st.dma_chan) in at91_adc_buffer_postdisable()
975 at91_adc_readl(st, chan->address); in at91_adc_buffer_postdisable()
985 if (st->dma_st.dma_chan) in at91_adc_buffer_postdisable()
986 dmaengine_terminate_sync(st->dma_st.dma_chan); in at91_adc_buffer_postdisable()
1001 trig = devm_iio_trigger_alloc(&indio->dev, "%s-dev%d-%s", indio->name, in at91_adc_allocate_trigger()
1002 indio->id, trigger_name); in at91_adc_allocate_trigger()
1006 trig->dev.parent = indio->dev.parent; in at91_adc_allocate_trigger()
1008 trig->ops = &at91_adc_trigger_ops; in at91_adc_allocate_trigger()
1010 ret = devm_iio_trigger_register(&indio->dev, trig); in at91_adc_allocate_trigger()
1021 st->trig = at91_adc_allocate_trigger(indio, st->selected_trig->name); in at91_adc_trigger_init()
1022 if (IS_ERR(st->trig)) { in at91_adc_trigger_init()
1023 dev_err(&indio->dev, in at91_adc_trigger_init()
1025 return PTR_ERR(st->trig); in at91_adc_trigger_init()
1048 timeout--; in at91_adc_trigger_handler_nodma()
1055 for_each_set_bit(bit, indio_dev->active_scan_mask, in at91_adc_trigger_handler_nodma()
1056 indio_dev->num_channels) { in at91_adc_trigger_handler_nodma()
1072 if (chan->type == IIO_VOLTAGE) { in at91_adc_trigger_handler_nodma()
1073 val = at91_adc_readl(st, chan->address); in at91_adc_trigger_handler_nodma()
1075 st->buffer[i] = val; in at91_adc_trigger_handler_nodma()
1077 st->buffer[i] = 0; in at91_adc_trigger_handler_nodma()
1082 iio_push_to_buffers_with_timestamp(indio_dev, st->buffer, in at91_adc_trigger_handler_nodma()
1083 pf->timestamp); in at91_adc_trigger_handler_nodma()
1098 indio_dev->name); in at91_adc_trigger_handler_dma()
1100 sample_size = div_s64(st->dma_st.rx_buf_sz, st->dma_st.watermark); in at91_adc_trigger_handler_dma()
1108 interval = div_s64((ns - st->dma_st.dma_ts), sample_count); in at91_adc_trigger_handler_dma()
1116 &st->dma_st.rx_buf[st->dma_st.buf_idx], in at91_adc_trigger_handler_dma()
1120 (st->dma_st.rx_buf + st->dma_st.buf_idx), in at91_adc_trigger_handler_dma()
1121 (st->dma_st.dma_ts + interval * sample_index)); in at91_adc_trigger_handler_dma()
1123 transferred_len -= sample_size; in at91_adc_trigger_handler_dma()
1125 st->dma_st.buf_idx += sample_size; in at91_adc_trigger_handler_dma()
1127 if (st->dma_st.buf_idx >= st->dma_st.rx_buf_sz) in at91_adc_trigger_handler_dma()
1128 st->dma_st.buf_idx = 0; in at91_adc_trigger_handler_dma()
1132 st->dma_st.dma_ts = iio_get_time_ns(indio_dev); in at91_adc_trigger_handler_dma()
1138 struct iio_dev *indio_dev = pf->indio_dev; in at91_adc_trigger_handler()
1145 if (iio_trigger_validate_own_device(indio_dev->trig, indio_dev)) in at91_adc_trigger_handler()
1148 if (st->dma_st.dma_chan) in at91_adc_trigger_handler()
1153 iio_trigger_notify_done(indio_dev->trig); in at91_adc_trigger_handler()
1160 return devm_iio_triggered_buffer_setup(&indio->dev, indio, in at91_adc_buffer_init()
1194 f_per = clk_get_rate(st->per_clk); in at91_adc_setup_samp_freq()
1195 prescal = (f_per / (2 * freq)) - 1; in at91_adc_setup_samp_freq()
1197 startup = at91_adc_startup_time(st->soc_info.startup_time, in at91_adc_setup_samp_freq()
1206 dev_dbg(&indio_dev->dev, "freq: %u, startup: %u, prescal: %u\n", in at91_adc_setup_samp_freq()
1208 st->current_sample_rate = freq; in at91_adc_setup_samp_freq()
1213 return st->current_sample_rate; in at91_adc_get_sample_freq()
1223 for_each_set_bit(bit, indio_dev->active_scan_mask, in at91_adc_touch_data_handler()
1228 if (chan->type == IIO_POSITIONRELATIVE) in at91_adc_touch_data_handler()
1229 at91_adc_read_position(st, chan->channel, &val); in at91_adc_touch_data_handler()
1230 else if (chan->type == IIO_PRESSURE) in at91_adc_touch_data_handler()
1231 at91_adc_read_pressure(st, chan->channel, &val); in at91_adc_touch_data_handler()
1234 st->buffer[i] = val; in at91_adc_touch_data_handler()
1245 schedule_work(&st->touch_st.workq); in at91_adc_touch_data_handler()
1256 AT91_SAMA5D2_TRGR_TRGPER(st->touch_st.sample_period_val)); in at91_adc_pen_detect_interrupt()
1257 st->touch_st.touching = true; in at91_adc_pen_detect_interrupt()
1269 st->touch_st.touching = false; in at91_adc_no_pen_detect_interrupt()
1282 struct iio_dev *indio_dev = st->indio_dev; in at91_adc_workq_handler()
1284 iio_push_to_buffers(indio_dev, st->buffer); in at91_adc_workq_handler()
1306 /* periodic trigger IRQ - during pen sense */ in at91_adc_interrupt()
1320 iio_trigger_poll(indio->trig); in at91_adc_interrupt()
1321 } else if (iio_buffer_enabled(indio) && st->dma_st.dma_chan) { in at91_adc_interrupt()
1322 /* triggered buffer with DMA - should not happen */ in at91_adc_interrupt()
1327 st->conversion_value = at91_adc_readl(st, st->chan->address); in at91_adc_interrupt()
1328 st->conversion_done = true; in at91_adc_interrupt()
1329 wake_up_interruptible(&st->wq_data_available); in at91_adc_interrupt()
1343 * Keep in mind that we cannot use software trigger or touchscreen in at91_adc_read_info_raw()
1346 if (chan->type == IIO_POSITIONRELATIVE) { in at91_adc_read_info_raw()
1350 mutex_lock(&st->lock); in at91_adc_read_info_raw()
1352 ret = at91_adc_read_position(st, chan->channel, in at91_adc_read_info_raw()
1355 mutex_unlock(&st->lock); in at91_adc_read_info_raw()
1360 if (chan->type == IIO_PRESSURE) { in at91_adc_read_info_raw()
1364 mutex_lock(&st->lock); in at91_adc_read_info_raw()
1366 ret = at91_adc_read_pressure(st, chan->channel, in at91_adc_read_info_raw()
1369 mutex_unlock(&st->lock); in at91_adc_read_info_raw()
1380 mutex_lock(&st->lock); in at91_adc_read_info_raw()
1382 st->chan = chan; in at91_adc_read_info_raw()
1384 if (chan->differential) in at91_adc_read_info_raw()
1385 cor = (BIT(chan->channel) | BIT(chan->channel2)) << in at91_adc_read_info_raw()
1389 at91_adc_writel(st, AT91_SAMA5D2_CHER, BIT(chan->channel)); in at91_adc_read_info_raw()
1390 at91_adc_writel(st, AT91_SAMA5D2_IER, BIT(chan->channel)); in at91_adc_read_info_raw()
1393 ret = wait_event_interruptible_timeout(st->wq_data_available, in at91_adc_read_info_raw()
1394 st->conversion_done, in at91_adc_read_info_raw()
1397 ret = -ETIMEDOUT; in at91_adc_read_info_raw()
1400 *val = st->conversion_value; in at91_adc_read_info_raw()
1402 if (chan->scan_type.sign == 's') in at91_adc_read_info_raw()
1404 st->conversion_done = false; in at91_adc_read_info_raw()
1407 at91_adc_writel(st, AT91_SAMA5D2_IDR, BIT(chan->channel)); in at91_adc_read_info_raw()
1408 at91_adc_writel(st, AT91_SAMA5D2_CHDR, BIT(chan->channel)); in at91_adc_read_info_raw()
1413 mutex_unlock(&st->lock); in at91_adc_read_info_raw()
1429 *val = st->vref_uv / 1000; in at91_adc_read_raw()
1430 if (chan->differential) in at91_adc_read_raw()
1432 *val2 = chan->scan_type.realbits; in at91_adc_read_raw()
1440 *val = st->oversampling_ratio; in at91_adc_read_raw()
1444 return -EINVAL; in at91_adc_read_raw()
1458 return -EINVAL; in at91_adc_write_raw()
1460 if (val == st->oversampling_ratio) in at91_adc_write_raw()
1462 st->oversampling_ratio = val; in at91_adc_write_raw()
1467 if (val < st->soc_info.min_sample_rate || in at91_adc_write_raw()
1468 val > st->soc_info.max_sample_rate) in at91_adc_write_raw()
1469 return -EINVAL; in at91_adc_write_raw()
1474 return -EINVAL; in at91_adc_write_raw()
1492 if (st->dma_st.dma_chan) in at91_adc_dma_init()
1495 st->dma_st.dma_chan = dma_request_chan(&pdev->dev, "rx"); in at91_adc_dma_init()
1496 if (IS_ERR(st->dma_st.dma_chan)) { in at91_adc_dma_init()
1497 dev_info(&pdev->dev, "can't get DMA channel\n"); in at91_adc_dma_init()
1498 st->dma_st.dma_chan = NULL; in at91_adc_dma_init()
1502 st->dma_st.rx_buf = dma_alloc_coherent(st->dma_st.dma_chan->device->dev, in at91_adc_dma_init()
1504 &st->dma_st.rx_dma_buf, in at91_adc_dma_init()
1506 if (!st->dma_st.rx_buf) { in at91_adc_dma_init()
1507 dev_info(&pdev->dev, "can't allocate coherent DMA area\n"); in at91_adc_dma_init()
1513 config.src_addr = (phys_addr_t)(st->dma_st.phys_addr in at91_adc_dma_init()
1519 if (dmaengine_slave_config(st->dma_st.dma_chan, &config)) { in at91_adc_dma_init()
1520 dev_info(&pdev->dev, "can't configure DMA slave\n"); in at91_adc_dma_init()
1524 dev_info(&pdev->dev, "using %s for rx DMA transfers\n", in at91_adc_dma_init()
1525 dma_chan_name(st->dma_st.dma_chan)); in at91_adc_dma_init()
1530 dma_free_coherent(st->dma_st.dma_chan->device->dev, pages * PAGE_SIZE, in at91_adc_dma_init()
1531 st->dma_st.rx_buf, st->dma_st.rx_dma_buf); in at91_adc_dma_init()
1533 dma_release_channel(st->dma_st.dma_chan); in at91_adc_dma_init()
1534 st->dma_st.dma_chan = NULL; in at91_adc_dma_init()
1536 dev_info(&pdev->dev, "continuing without DMA support\n"); in at91_adc_dma_init()
1548 if (!st->dma_st.dma_chan) in at91_adc_dma_disable()
1552 dmaengine_terminate_sync(st->dma_st.dma_chan); in at91_adc_dma_disable()
1554 dma_free_coherent(st->dma_st.dma_chan->device->dev, pages * PAGE_SIZE, in at91_adc_dma_disable()
1555 st->dma_st.rx_buf, st->dma_st.rx_dma_buf); in at91_adc_dma_disable()
1556 dma_release_channel(st->dma_st.dma_chan); in at91_adc_dma_disable()
1557 st->dma_st.dma_chan = NULL; in at91_adc_dma_disable()
1559 dev_info(&pdev->dev, "continuing without DMA support\n"); in at91_adc_dma_disable()
1568 return -EINVAL; in at91_adc_set_watermark()
1570 if (!st->selected_trig->hw_trig) { in at91_adc_set_watermark()
1571 dev_dbg(&indio_dev->dev, "we need hw trigger for DMA\n"); in at91_adc_set_watermark()
1575 dev_dbg(&indio_dev->dev, "new watermark is %u\n", val); in at91_adc_set_watermark()
1576 st->dma_st.watermark = val; in at91_adc_set_watermark()
1585 at91_adc_dma_disable(to_platform_device(&indio_dev->dev)); in at91_adc_set_watermark()
1587 at91_adc_dma_init(to_platform_device(&indio_dev->dev)); in at91_adc_set_watermark()
1595 at91_adc_dma_disable(to_platform_device(&indio_dev->dev)); in at91_adc_set_watermark()
1605 if (bitmap_subset(scan_mask, &st->touch_st.channels_bitmask, in at91_adc_update_scan_mode()
1609 * if the new bitmap is a combination of touchscreen and regular in at91_adc_update_scan_mode()
1612 if (bitmap_intersects(&st->touch_st.channels_bitmask, scan_mask, in at91_adc_update_scan_mode()
1614 return -EINVAL; in at91_adc_update_scan_mode()
1631 at91_adc_setup_samp_freq(indio_dev, st->soc_info.min_sample_rate); in at91_adc_hw_init()
1643 return scnprintf(buf, PAGE_SIZE, "%d\n", !!st->dma_st.dma_chan); in at91_adc_get_fifo_state()
1652 return scnprintf(buf, PAGE_SIZE, "%d\n", st->dma_st.watermark); in at91_adc_get_watermark()
1702 indio_dev = devm_iio_device_alloc(&pdev->dev, sizeof(*st)); in at91_adc_probe()
1704 return -ENOMEM; in at91_adc_probe()
1706 indio_dev->name = dev_name(&pdev->dev); in at91_adc_probe()
1707 indio_dev->modes = INDIO_DIRECT_MODE | INDIO_BUFFER_SOFTWARE; in at91_adc_probe()
1708 indio_dev->info = &at91_adc_info; in at91_adc_probe()
1709 indio_dev->channels = at91_adc_channels; in at91_adc_probe()
1710 indio_dev->num_channels = ARRAY_SIZE(at91_adc_channels); in at91_adc_probe()
1713 st->indio_dev = indio_dev; in at91_adc_probe()
1715 bitmap_set(&st->touch_st.channels_bitmask, in at91_adc_probe()
1717 bitmap_set(&st->touch_st.channels_bitmask, in at91_adc_probe()
1719 bitmap_set(&st->touch_st.channels_bitmask, in at91_adc_probe()
1722 st->oversampling_ratio = AT91_OSR_1SAMPLES; in at91_adc_probe()
1724 ret = of_property_read_u32(pdev->dev.of_node, in at91_adc_probe()
1725 "atmel,min-sample-rate-hz", in at91_adc_probe()
1726 &st->soc_info.min_sample_rate); in at91_adc_probe()
1728 dev_err(&pdev->dev, in at91_adc_probe()
1729 "invalid or missing value for atmel,min-sample-rate-hz\n"); in at91_adc_probe()
1733 ret = of_property_read_u32(pdev->dev.of_node, in at91_adc_probe()
1734 "atmel,max-sample-rate-hz", in at91_adc_probe()
1735 &st->soc_info.max_sample_rate); in at91_adc_probe()
1737 dev_err(&pdev->dev, in at91_adc_probe()
1738 "invalid or missing value for atmel,max-sample-rate-hz\n"); in at91_adc_probe()
1742 ret = of_property_read_u32(pdev->dev.of_node, "atmel,startup-time-ms", in at91_adc_probe()
1743 &st->soc_info.startup_time); in at91_adc_probe()
1745 dev_err(&pdev->dev, in at91_adc_probe()
1746 "invalid or missing value for atmel,startup-time-ms\n"); in at91_adc_probe()
1750 ret = of_property_read_u32(pdev->dev.of_node, in at91_adc_probe()
1751 "atmel,trigger-edge-type", &edge_type); in at91_adc_probe()
1753 dev_dbg(&pdev->dev, in at91_adc_probe()
1754 "atmel,trigger-edge-type not specified, only software trigger available\n"); in at91_adc_probe()
1757 st->selected_trig = NULL; in at91_adc_probe()
1762 st->selected_trig = &at91_adc_trigger_list[i]; in at91_adc_probe()
1766 if (!st->selected_trig) { in at91_adc_probe()
1767 dev_err(&pdev->dev, "invalid external trigger edge value\n"); in at91_adc_probe()
1768 return -EINVAL; in at91_adc_probe()
1771 init_waitqueue_head(&st->wq_data_available); in at91_adc_probe()
1772 mutex_init(&st->lock); in at91_adc_probe()
1773 INIT_WORK(&st->touch_st.workq, at91_adc_workq_handler); in at91_adc_probe()
1775 st->base = devm_platform_get_and_ioremap_resource(pdev, 0, &res); in at91_adc_probe()
1776 if (IS_ERR(st->base)) in at91_adc_probe()
1777 return PTR_ERR(st->base); in at91_adc_probe()
1780 st->dma_st.phys_addr = res->start; in at91_adc_probe()
1782 st->irq = platform_get_irq(pdev, 0); in at91_adc_probe()
1783 if (st->irq <= 0) { in at91_adc_probe()
1784 if (!st->irq) in at91_adc_probe()
1785 st->irq = -ENXIO; in at91_adc_probe()
1787 return st->irq; in at91_adc_probe()
1790 st->per_clk = devm_clk_get(&pdev->dev, "adc_clk"); in at91_adc_probe()
1791 if (IS_ERR(st->per_clk)) in at91_adc_probe()
1792 return PTR_ERR(st->per_clk); in at91_adc_probe()
1794 st->reg = devm_regulator_get(&pdev->dev, "vddana"); in at91_adc_probe()
1795 if (IS_ERR(st->reg)) in at91_adc_probe()
1796 return PTR_ERR(st->reg); in at91_adc_probe()
1798 st->vref = devm_regulator_get(&pdev->dev, "vref"); in at91_adc_probe()
1799 if (IS_ERR(st->vref)) in at91_adc_probe()
1800 return PTR_ERR(st->vref); in at91_adc_probe()
1802 ret = devm_request_irq(&pdev->dev, st->irq, at91_adc_interrupt, 0, in at91_adc_probe()
1803 pdev->dev.driver->name, indio_dev); in at91_adc_probe()
1807 ret = regulator_enable(st->reg); in at91_adc_probe()
1811 ret = regulator_enable(st->vref); in at91_adc_probe()
1815 st->vref_uv = regulator_get_voltage(st->vref); in at91_adc_probe()
1816 if (st->vref_uv <= 0) { in at91_adc_probe()
1817 ret = -EINVAL; in at91_adc_probe()
1823 ret = clk_prepare_enable(st->per_clk); in at91_adc_probe()
1831 dev_err(&pdev->dev, "couldn't initialize the buffer.\n"); in at91_adc_probe()
1835 if (st->selected_trig->hw_trig) { in at91_adc_probe()
1838 dev_err(&pdev->dev, "couldn't setup the triggers.\n"); in at91_adc_probe()
1845 st->dma_st.watermark = 1; in at91_adc_probe()
1847 iio_buffer_set_attrs(indio_dev->buffer, in at91_adc_probe()
1851 if (dma_coerce_mask_and_coherent(&indio_dev->dev, DMA_BIT_MASK(32))) in at91_adc_probe()
1852 dev_info(&pdev->dev, "cannot set DMA mask to 32-bit\n"); in at91_adc_probe()
1858 if (st->selected_trig->hw_trig) in at91_adc_probe()
1859 dev_info(&pdev->dev, "setting up trigger as %s\n", in at91_adc_probe()
1860 st->selected_trig->name); in at91_adc_probe()
1862 dev_info(&pdev->dev, "version: %x\n", in at91_adc_probe()
1863 readl_relaxed(st->base + AT91_SAMA5D2_VERSION)); in at91_adc_probe()
1870 clk_disable_unprepare(st->per_clk); in at91_adc_probe()
1872 regulator_disable(st->vref); in at91_adc_probe()
1874 regulator_disable(st->reg); in at91_adc_probe()
1887 clk_disable_unprepare(st->per_clk); in at91_adc_remove()
1889 regulator_disable(st->vref); in at91_adc_remove()
1890 regulator_disable(st->reg); in at91_adc_remove()
1908 clk_disable_unprepare(st->per_clk); in at91_adc_suspend()
1909 regulator_disable(st->vref); in at91_adc_suspend()
1910 regulator_disable(st->reg); in at91_adc_suspend()
1925 ret = regulator_enable(st->reg); in at91_adc_resume()
1929 ret = regulator_enable(st->vref); in at91_adc_resume()
1933 ret = clk_prepare_enable(st->per_clk); in at91_adc_resume()
1943 /* check if we are enabling triggered buffer or the touchscreen */ in at91_adc_resume()
1947 return at91_adc_configure_trigger(st->trig, true); in at91_adc_resume()
1953 regulator_disable(st->vref); in at91_adc_resume()
1955 regulator_disable(st->reg); in at91_adc_resume()
1957 dev_err(&indio_dev->dev, "failed to resume\n"); in at91_adc_resume()
1965 .compatible = "atmel,sama5d2-adc",
1976 .name = "at91-sama5d2_adc",