Lines Matching +full:adc +full:- +full:sample +full:- +full:hold +full:- +full:time
1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Driver for the ADC present in the Atmel AT91 evaluation boards.
38 #define AT91_ADC_TSAMOD (3 << 0) /* ADC mode */
39 #define AT91_ADC_TSAMOD_ADC_ONLY_MODE (0 << 0) /* ADC Mode */
53 #define AT91_ADC_STARTUP_9260 (0x1f << 16) /* Startup Up Time */
57 #define AT91_ADC_SHTIM (0xf << 24) /* Sample & Hold Time */
59 #define AT91_ADC_PENDBC (0x0f << 28) /* Pen Debounce time */
63 #define AT91_ADC_TSR_SHTIM (0xf << 24) /* Sample & Hold Time */
103 #define AT91_ADC_ACR_PENDETSENS (0x3 << 0) /* pull-up resistor */
113 #define AT91_ADC_TSMR_SCTIM (0x0f << 16) /* Switch closure time */
115 #define AT91_ADC_TSMR_PENDBC (0x0f << 28) /* Pen Debounce time */
137 (st->registers->channel_base + (ch * 4))
139 (readl_relaxed(st->reg_base + reg))
141 (writel_relaxed(val, st->reg_base + reg))
152 #define TOUCH_SCTIM_US 10 /* 10us for the Touchscreen Switches Closure Time */
161 * struct at91_adc_trigger - description of triggers
163 * @value: value to set in the ADC's trigger setup register
174 * struct at91_adc_reg_desc - Various informations relative to registers
180 * @mr_prescal_mask: Mask of the PRESCAL field in the adc MR register
181 * @mr_startup_mask: Mask of the STARTUP field in the adc MR register
197 * Hardware can average (2 ^ ts_filter_average) sample data.
200 /* Pen Detection input pull-up resistor, can be 0~3 */
203 /* startup time calculate function */
239 * Following ADC channels are shared by touchscreen:
241 * CH0 -- Touch screen XP/UL
242 * CH1 -- Touch screen XM/UR
243 * CH2 -- Touch screen YP/LL
244 * CH3 -- Touch screen YM/Sense
245 * CH4 -- Touch screen LR(5-wire only)
267 struct iio_dev *idev = pf->indio_dev; in at91_adc_trigger_handler()
272 for (i = 0; i < idev->masklength; i++) { in at91_adc_trigger_handler()
273 if (!test_bit(i, idev->active_scan_mask)) in at91_adc_trigger_handler()
275 chan = idev->channels + i; in at91_adc_trigger_handler()
276 st->buffer[j] = at91_adc_readl(st, AT91_ADC_CHAN(st, chan->channel)); in at91_adc_trigger_handler()
280 iio_push_to_buffers_with_timestamp(idev, st->buffer, pf->timestamp); in at91_adc_trigger_handler()
282 iio_trigger_notify_done(idev->trig); in at91_adc_trigger_handler()
287 enable_irq(st->irq); in at91_adc_trigger_handler()
292 /* Handler for classic adc channel eoc trigger */
299 iio_trigger_poll(idev->trig); in handle_adc_eoc_trigger()
301 st->last_value = at91_adc_readl(st, AT91_ADC_CHAN(st, st->chnb)); in handle_adc_eoc_trigger()
304 st->done = true; in handle_adc_eoc_trigger()
305 wake_up_interruptible(&st->wq_data_avail); in handle_adc_eoc_trigger()
317 unsigned int xyz_mask_bits = st->res; in at91_ts_sample()
318 unsigned int xyz_mask = (1 << xyz_mask_bits) - 1; in at91_ts_sample()
321 /* x position = (x / xscale) * max, max = 2^MAX_POS_BITS - 1 */ in at91_ts_sample()
324 x = (xpos << MAX_POS_BITS) - xpos; in at91_ts_sample()
327 dev_err(&idev->dev, "Error: xscale == 0!\n"); in at91_ts_sample()
328 return -1; in at91_ts_sample()
332 /* y position = (y / yscale) * max, max = 2^MAX_POS_BITS - 1 */ in at91_ts_sample()
335 y = (ypos << MAX_POS_BITS) - ypos; in at91_ts_sample()
338 dev_err(&idev->dev, "Error: yscale == 0!\n"); in at91_ts_sample()
339 return -1; in at91_ts_sample()
349 pres = rxp * (x * factor / 1024) * (z2 * factor / z1 - factor) in at91_ts_sample()
352 pres = st->ts_pressure_threshold; /* no pen contacted */ in at91_ts_sample()
354 …dev_dbg(&idev->dev, "xpos = %d, xscale = %d, ypos = %d, yscale = %d, z1 = %d, z2 = %d, press = %d\… in at91_ts_sample()
357 if (pres < st->ts_pressure_threshold) { in at91_ts_sample()
358 dev_dbg(&idev->dev, "x = %d, y = %d, pressure = %d\n", in at91_ts_sample()
360 input_report_abs(st->ts_input, ABS_X, x); in at91_ts_sample()
361 input_report_abs(st->ts_input, ABS_Y, y); in at91_ts_sample()
362 input_report_abs(st->ts_input, ABS_PRESSURE, pres); in at91_ts_sample()
363 input_report_key(st->ts_input, BTN_TOUCH, 1); in at91_ts_sample()
364 input_sync(st->ts_input); in at91_ts_sample()
366 dev_dbg(&idev->dev, "pressure too low: not reporting\n"); in at91_ts_sample()
376 u32 status = at91_adc_readl(st, st->registers->status_register); in at91_adc_rl_interrupt()
380 if (status & GENMASK(st->num_channels - 1, 0)) in at91_adc_rl_interrupt()
393 at91_adc_writel(st, st->registers->trigger_register, in at91_adc_rl_interrupt()
395 AT91_ADC_TRGR_TRGPER_(st->ts_sample_period_val)); in at91_adc_rl_interrupt()
398 reg |= AT91_ADC_PENDBC_(st->ts_pendbc) & AT91_ADC_PENDBC; in at91_adc_rl_interrupt()
400 at91_adc_writel(st, st->registers->trigger_register, in at91_adc_rl_interrupt()
406 st->ts_bufferedmeasure = false; in at91_adc_rl_interrupt()
407 input_report_key(st->ts_input, BTN_TOUCH, 0); in at91_adc_rl_interrupt()
408 input_sync(st->ts_input); in at91_adc_rl_interrupt()
409 } else if (status & AT91_ADC_EOC(3) && st->ts_input) { in at91_adc_rl_interrupt()
411 if (st->ts_bufferedmeasure) { in at91_adc_rl_interrupt()
417 input_report_abs(st->ts_input, ABS_X, st->ts_prev_absx); in at91_adc_rl_interrupt()
418 input_report_abs(st->ts_input, ABS_Y, st->ts_prev_absy); in at91_adc_rl_interrupt()
419 input_report_key(st->ts_input, BTN_TOUCH, 1); in at91_adc_rl_interrupt()
420 input_sync(st->ts_input); in at91_adc_rl_interrupt()
422 st->ts_bufferedmeasure = true; in at91_adc_rl_interrupt()
425 st->ts_prev_absx = at91_adc_readl(st, AT91_ADC_CHAN(st, 3)) in at91_adc_rl_interrupt()
427 st->ts_prev_absx /= at91_adc_readl(st, AT91_ADC_CHAN(st, 2)); in at91_adc_rl_interrupt()
429 st->ts_prev_absy = at91_adc_readl(st, AT91_ADC_CHAN(st, 1)) in at91_adc_rl_interrupt()
431 st->ts_prev_absy /= at91_adc_readl(st, AT91_ADC_CHAN(st, 0)); in at91_adc_rl_interrupt()
441 u32 status = at91_adc_readl(st, st->registers->status_register); in at91_adc_9x5_interrupt()
447 if (status & GENMASK(st->num_channels - 1, 0)) in at91_adc_9x5_interrupt()
455 at91_adc_writel(st, st->registers->trigger_register, in at91_adc_9x5_interrupt()
457 AT91_ADC_TRGR_TRGPER_(st->ts_sample_period_val)); in at91_adc_9x5_interrupt()
459 at91_adc_writel(st, st->registers->trigger_register, 0); in at91_adc_9x5_interrupt()
464 input_report_key(st->ts_input, BTN_TOUCH, 0); in at91_adc_9x5_interrupt()
465 input_sync(st->ts_input); in at91_adc_9x5_interrupt()
492 /* If touchscreen is enable, then reserve the adc channels */ in at91_adc_channel_init()
493 if (st->touchscreen_type == ATMEL_ADC_TOUCHSCREEN_4WIRE) in at91_adc_channel_init()
495 else if (st->touchscreen_type == ATMEL_ADC_TOUCHSCREEN_5WIRE) in at91_adc_channel_init()
499 st->channels_mask &= ~rsvd_mask; in at91_adc_channel_init()
501 idev->num_channels = bitmap_weight(&st->channels_mask, in at91_adc_channel_init()
502 st->num_channels) + 1; in at91_adc_channel_init()
504 chan_array = devm_kzalloc(&idev->dev, in at91_adc_channel_init()
505 ((idev->num_channels + 1) * in at91_adc_channel_init()
510 return -ENOMEM; in at91_adc_channel_init()
512 for_each_set_bit(bit, &st->channels_mask, st->num_channels) { in at91_adc_channel_init()
515 chan->type = IIO_VOLTAGE; in at91_adc_channel_init()
516 chan->indexed = 1; in at91_adc_channel_init()
517 chan->channel = bit; in at91_adc_channel_init()
518 chan->scan_index = idx; in at91_adc_channel_init()
519 chan->scan_type.sign = 'u'; in at91_adc_channel_init()
520 chan->scan_type.realbits = st->res; in at91_adc_channel_init()
521 chan->scan_type.storagebits = 16; in at91_adc_channel_init()
522 chan->info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE); in at91_adc_channel_init()
523 chan->info_mask_separate = BIT(IIO_CHAN_INFO_RAW); in at91_adc_channel_init()
528 timestamp->type = IIO_TIMESTAMP; in at91_adc_channel_init()
529 timestamp->channel = -1; in at91_adc_channel_init()
530 timestamp->scan_index = idx; in at91_adc_channel_init()
531 timestamp->scan_type.sign = 's'; in at91_adc_channel_init()
532 timestamp->scan_type.realbits = 64; in at91_adc_channel_init()
533 timestamp->scan_type.storagebits = 64; in at91_adc_channel_init()
535 idev->channels = chan_array; in at91_adc_channel_init()
536 return idev->num_channels; in at91_adc_channel_init()
546 for (i = 0; i < st->caps->trigger_number; i++) { in at91_adc_get_trigger_value_by_name()
548 "%s-dev%d-%s", in at91_adc_get_trigger_value_by_name()
549 idev->name, in at91_adc_get_trigger_value_by_name()
553 return -ENOMEM; in at91_adc_get_trigger_value_by_name()
558 return -EINVAL; in at91_adc_get_trigger_value_by_name()
565 return -EINVAL; in at91_adc_get_trigger_value_by_name()
572 const struct at91_adc_reg_desc *reg = st->registers; in at91_adc_configure_trigger()
573 u32 status = at91_adc_readl(st, reg->trigger_register); in at91_adc_configure_trigger()
578 st->caps->triggers, in at91_adc_configure_trigger()
579 idev->trig->name); in at91_adc_configure_trigger()
584 st->buffer = kmalloc(idev->scan_bytes, GFP_KERNEL); in at91_adc_configure_trigger()
585 if (st->buffer == NULL) in at91_adc_configure_trigger()
586 return -ENOMEM; in at91_adc_configure_trigger()
588 at91_adc_writel(st, reg->trigger_register, in at91_adc_configure_trigger()
591 for_each_set_bit(bit, idev->active_scan_mask, in at91_adc_configure_trigger()
592 st->num_channels) { in at91_adc_configure_trigger()
593 struct iio_chan_spec const *chan = idev->channels + bit; in at91_adc_configure_trigger()
595 AT91_ADC_CH(chan->channel)); in at91_adc_configure_trigger()
598 at91_adc_writel(st, AT91_ADC_IER, reg->drdy_mask); in at91_adc_configure_trigger()
601 at91_adc_writel(st, AT91_ADC_IDR, reg->drdy_mask); in at91_adc_configure_trigger()
603 at91_adc_writel(st, reg->trigger_register, in at91_adc_configure_trigger()
606 for_each_set_bit(bit, idev->active_scan_mask, in at91_adc_configure_trigger()
607 st->num_channels) { in at91_adc_configure_trigger()
608 struct iio_chan_spec const *chan = idev->channels + bit; in at91_adc_configure_trigger()
610 AT91_ADC_CH(chan->channel)); in at91_adc_configure_trigger()
612 kfree(st->buffer); in at91_adc_configure_trigger()
628 trig = iio_trigger_alloc(idev->dev.parent, "%s-dev%d-%s", idev->name, in at91_adc_allocate_trigger()
629 iio_device_id(idev), trigger->name); in at91_adc_allocate_trigger()
634 trig->ops = &at91_adc_trigger_ops; in at91_adc_allocate_trigger()
650 st->trig = devm_kcalloc(&idev->dev, in at91_adc_trigger_init()
651 st->caps->trigger_number, sizeof(*st->trig), in at91_adc_trigger_init()
654 if (st->trig == NULL) { in at91_adc_trigger_init()
655 ret = -ENOMEM; in at91_adc_trigger_init()
659 for (i = 0; i < st->caps->trigger_number; i++) { in at91_adc_trigger_init()
660 if (st->caps->triggers[i].is_external && !(st->use_external)) in at91_adc_trigger_init()
663 st->trig[i] = at91_adc_allocate_trigger(idev, in at91_adc_trigger_init()
664 st->caps->triggers + i); in at91_adc_trigger_init()
665 if (st->trig[i] == NULL) { in at91_adc_trigger_init()
666 dev_err(&idev->dev, in at91_adc_trigger_init()
668 ret = -ENOMEM; in at91_adc_trigger_init()
676 for (i--; i >= 0; i--) { in at91_adc_trigger_init()
677 iio_trigger_unregister(st->trig[i]); in at91_adc_trigger_init()
678 iio_trigger_free(st->trig[i]); in at91_adc_trigger_init()
689 for (i = 0; i < st->caps->trigger_number; i++) { in at91_adc_trigger_remove()
690 iio_trigger_unregister(st->trig[i]); in at91_adc_trigger_remove()
691 iio_trigger_free(st->trig[i]); in at91_adc_trigger_remove()
715 mutex_lock(&st->lock); in at91_adc_read_raw()
717 st->chnb = chan->channel; in at91_adc_read_raw()
719 AT91_ADC_CH(chan->channel)); in at91_adc_read_raw()
720 at91_adc_writel(st, AT91_ADC_IER, BIT(chan->channel)); in at91_adc_read_raw()
723 ret = wait_event_interruptible_timeout(st->wq_data_avail, in at91_adc_read_raw()
724 st->done, in at91_adc_read_raw()
727 /* Disable interrupts, regardless if adc conversion was in at91_adc_read_raw()
731 AT91_ADC_CH(chan->channel)); in at91_adc_read_raw()
732 at91_adc_writel(st, AT91_ADC_IDR, BIT(chan->channel)); in at91_adc_read_raw()
736 *val = st->last_value; in at91_adc_read_raw()
737 st->last_value = 0; in at91_adc_read_raw()
738 st->done = false; in at91_adc_read_raw()
742 dev_err(&idev->dev, "ADC Channel %d timeout.\n", in at91_adc_read_raw()
743 chan->channel); in at91_adc_read_raw()
744 ret = -ETIMEDOUT; in at91_adc_read_raw()
747 mutex_unlock(&st->lock); in at91_adc_read_raw()
751 *val = st->vref_mv; in at91_adc_read_raw()
752 *val2 = chan->scan_type.realbits; in at91_adc_read_raw()
757 return -EINVAL; in at91_adc_read_raw()
764 * Number of ticks needed to cover the startup time of the ADC in calc_startup_ticks_9260()
767 * Startup Time = (ticks + 1) * 8 / ADC Clock in calc_startup_ticks_9260()
769 return round_up((startup_time * adc_clk_khz / 1000) - 1, 8) / 8; in calc_startup_ticks_9260()
776 * Startup Time = <lookup_table_value> / ADC Clock in calc_startup_ticks_9x5()
795 ticks = size - 1; in calc_startup_ticks_9x5()
806 ret = of_property_read_u32(node, "atmel,adc-ts-wires", &prop); in at91_adc_probe_dt_ts()
808 dev_info(dev, "ADC Touch screen is disabled.\n"); in at91_adc_probe_dt_ts()
815 st->touchscreen_type = prop; in at91_adc_probe_dt_ts()
819 return -EINVAL; in at91_adc_probe_dt_ts()
822 if (!st->caps->has_tsmr) in at91_adc_probe_dt_ts()
825 of_property_read_u32(node, "atmel,adc-ts-pressure-threshold", &prop); in at91_adc_probe_dt_ts()
826 st->ts_pressure_threshold = prop; in at91_adc_probe_dt_ts()
827 if (st->ts_pressure_threshold) { in at91_adc_probe_dt_ts()
831 return -EINVAL; in at91_adc_probe_dt_ts()
844 if (st->caps->has_tsmr) in atmel_ts_open()
855 if (st->caps->has_tsmr) in atmel_ts_close()
868 /* a Pen Detect Debounce Time is necessary for the ADC Touch to avoid in at91_ts_hw_init()
870 * The formula is : Pen Detect Debounce Time = (2 ^ pendbc) / ADCClock in at91_ts_hw_init()
872 st->ts_pendbc = round_up(TOUCH_PEN_DETECT_DEBOUNCE_US * adc_clk_khz / in at91_ts_hw_init()
875 while (st->ts_pendbc >> ++i) in at91_ts_hw_init()
877 if (abs(st->ts_pendbc - (1 << i)) < abs(st->ts_pendbc - (1 << (i - 1)))) in at91_ts_hw_init()
878 st->ts_pendbc = i; in at91_ts_hw_init()
880 st->ts_pendbc = i - 1; in at91_ts_hw_init()
882 if (!st->caps->has_tsmr) { in at91_ts_hw_init()
886 reg |= AT91_ADC_PENDBC_(st->ts_pendbc) & AT91_ADC_PENDBC; in at91_ts_hw_init()
892 st->ts_sample_period_val = round_up((TOUCH_SAMPLE_PERIOD_US_RL * in at91_ts_hw_init()
893 adc_clk_khz / 1000) - 1, 1); in at91_ts_hw_init()
898 /* Touchscreen Switches Closure time needed for allowing the value to in at91_ts_hw_init()
900 * Switch Closure Time = (TSSCTIM * 4) ADCClock periods in at91_ts_hw_init()
903 dev_dbg(&idev->dev, "adc_clk at: %d KHz, tssctim at: %d\n", in at91_ts_hw_init()
906 if (st->touchscreen_type == ATMEL_ADC_TOUCHSCREEN_4WIRE) in at91_ts_hw_init()
912 reg |= AT91_ADC_TSMR_TSAV_(st->caps->ts_filter_average) in at91_ts_hw_init()
914 reg |= AT91_ADC_TSMR_PENDBC_(st->ts_pendbc) & AT91_ADC_TSMR_PENDBC; in at91_ts_hw_init()
921 /* Change adc internal resistor value for better pen detection, in at91_ts_hw_init()
926 at91_adc_writel(st, AT91_ADC_ACR, st->caps->ts_pen_detect_sensitivity in at91_ts_hw_init()
929 /* Sample Period Time = (TRGPER + 1) / ADCClock */ in at91_ts_hw_init()
930 st->ts_sample_period_val = round_up((TOUCH_SAMPLE_PERIOD_US * in at91_ts_hw_init()
931 adc_clk_khz / 1000) - 1, 1); in at91_ts_hw_init()
945 dev_err(&idev->dev, "Failed to allocate TS device!\n"); in at91_ts_register()
946 return -ENOMEM; in at91_ts_register()
949 input->name = DRIVER_NAME; in at91_ts_register()
950 input->id.bustype = BUS_HOST; in at91_ts_register()
951 input->dev.parent = &pdev->dev; in at91_ts_register()
952 input->open = atmel_ts_open; in at91_ts_register()
953 input->close = atmel_ts_close; in at91_ts_register()
955 __set_bit(EV_ABS, input->evbit); in at91_ts_register()
956 __set_bit(EV_KEY, input->evbit); in at91_ts_register()
957 __set_bit(BTN_TOUCH, input->keybit); in at91_ts_register()
958 if (st->caps->has_tsmr) { in at91_ts_register()
959 input_set_abs_params(input, ABS_X, 0, (1 << MAX_POS_BITS) - 1, in at91_ts_register()
961 input_set_abs_params(input, ABS_Y, 0, (1 << MAX_POS_BITS) - 1, in at91_ts_register()
965 if (st->touchscreen_type != ATMEL_ADC_TOUCHSCREEN_4WIRE) { in at91_ts_register()
966 dev_err(&pdev->dev, in at91_ts_register()
968 ret = -EINVAL; in at91_ts_register()
972 input_set_abs_params(input, ABS_X, 0, (1 << MAX_RLPOS_BITS) - 1, in at91_ts_register()
974 input_set_abs_params(input, ABS_Y, 0, (1 << MAX_RLPOS_BITS) - 1, in at91_ts_register()
978 st->ts_input = input; in at91_ts_register()
988 input_free_device(st->ts_input); in at91_ts_register()
994 input_unregister_device(st->ts_input); in at91_ts_unregister()
1000 struct device_node *node = pdev->dev.of_node; in at91_adc_probe()
1007 idev = devm_iio_device_alloc(&pdev->dev, sizeof(struct at91_adc_state)); in at91_adc_probe()
1009 return -ENOMEM; in at91_adc_probe()
1013 st->caps = of_device_get_match_data(&pdev->dev); in at91_adc_probe()
1015 st->use_external = of_property_read_bool(node, "atmel,adc-use-external-triggers"); in at91_adc_probe()
1017 if (of_property_read_u32(node, "atmel,adc-channels-used", &prop)) { in at91_adc_probe()
1018 dev_err(&idev->dev, "Missing adc-channels-used property in the DT.\n"); in at91_adc_probe()
1019 return -EINVAL; in at91_adc_probe()
1021 st->channels_mask = prop; in at91_adc_probe()
1023 st->sleep_mode = of_property_read_bool(node, "atmel,adc-sleep-mode"); in at91_adc_probe()
1025 if (of_property_read_u32(node, "atmel,adc-startup-time", &prop)) { in at91_adc_probe()
1026 dev_err(&idev->dev, "Missing adc-startup-time property in the DT.\n"); in at91_adc_probe()
1027 return -EINVAL; in at91_adc_probe()
1029 st->startup_time = prop; in at91_adc_probe()
1032 of_property_read_u32(node, "atmel,adc-sample-hold-time", &prop); in at91_adc_probe()
1033 st->sample_hold_time = prop; in at91_adc_probe()
1035 if (of_property_read_u32(node, "atmel,adc-vref", &prop)) { in at91_adc_probe()
1036 dev_err(&idev->dev, "Missing adc-vref property in the DT.\n"); in at91_adc_probe()
1037 return -EINVAL; in at91_adc_probe()
1039 st->vref_mv = prop; in at91_adc_probe()
1041 st->res = st->caps->high_res_bits; in at91_adc_probe()
1042 if (st->caps->low_res_bits && in at91_adc_probe()
1043 !of_property_read_string(node, "atmel,adc-use-res", (const char **)&s) in at91_adc_probe()
1045 st->res = st->caps->low_res_bits; in at91_adc_probe()
1047 dev_info(&idev->dev, "Resolution used: %u bits\n", st->res); in at91_adc_probe()
1049 st->registers = &st->caps->registers; in at91_adc_probe()
1050 st->num_channels = st->caps->num_channels; in at91_adc_probe()
1053 if (st->caps->has_ts) { in at91_adc_probe()
1054 ret = at91_adc_probe_dt_ts(node, st, &idev->dev); in at91_adc_probe()
1061 idev->name = dev_name(&pdev->dev); in at91_adc_probe()
1062 idev->modes = INDIO_DIRECT_MODE; in at91_adc_probe()
1063 idev->info = &at91_adc_info; in at91_adc_probe()
1065 st->irq = platform_get_irq(pdev, 0); in at91_adc_probe()
1066 if (st->irq < 0) in at91_adc_probe()
1067 return -ENODEV; in at91_adc_probe()
1069 st->reg_base = devm_platform_ioremap_resource(pdev, 0); in at91_adc_probe()
1070 if (IS_ERR(st->reg_base)) in at91_adc_probe()
1071 return PTR_ERR(st->reg_base); in at91_adc_probe()
1080 if (st->caps->has_tsmr) in at91_adc_probe()
1081 ret = request_irq(st->irq, at91_adc_9x5_interrupt, 0, in at91_adc_probe()
1082 pdev->dev.driver->name, idev); in at91_adc_probe()
1084 ret = request_irq(st->irq, at91_adc_rl_interrupt, 0, in at91_adc_probe()
1085 pdev->dev.driver->name, idev); in at91_adc_probe()
1087 dev_err(&pdev->dev, "Failed to allocate IRQ.\n"); in at91_adc_probe()
1091 st->clk = devm_clk_get(&pdev->dev, "adc_clk"); in at91_adc_probe()
1092 if (IS_ERR(st->clk)) { in at91_adc_probe()
1093 dev_err(&pdev->dev, "Failed to get the clock.\n"); in at91_adc_probe()
1094 ret = PTR_ERR(st->clk); in at91_adc_probe()
1098 ret = clk_prepare_enable(st->clk); in at91_adc_probe()
1100 dev_err(&pdev->dev, in at91_adc_probe()
1105 st->adc_clk = devm_clk_get(&pdev->dev, "adc_op_clk"); in at91_adc_probe()
1106 if (IS_ERR(st->adc_clk)) { in at91_adc_probe()
1107 dev_err(&pdev->dev, "Failed to get the ADC clock.\n"); in at91_adc_probe()
1108 ret = PTR_ERR(st->adc_clk); in at91_adc_probe()
1112 ret = clk_prepare_enable(st->adc_clk); in at91_adc_probe()
1114 dev_err(&pdev->dev, in at91_adc_probe()
1115 "Could not prepare or enable the ADC clock.\n"); in at91_adc_probe()
1121 * datasheet : ADC Clock = MCK / ((Prescaler + 1) * 2), ADC Clock being in at91_adc_probe()
1124 mstrclk = clk_get_rate(st->clk); in at91_adc_probe()
1125 adc_clk = clk_get_rate(st->adc_clk); in at91_adc_probe()
1128 dev_dbg(&pdev->dev, "Master clock is set as: %d Hz, adc_clk should set as: %d Hz\n", in at91_adc_probe()
1131 prsc = (mstrclk / (2 * adc_clk)) - 1; in at91_adc_probe()
1133 if (!st->startup_time) { in at91_adc_probe()
1134 dev_err(&pdev->dev, "No startup time available.\n"); in at91_adc_probe()
1135 ret = -EINVAL; in at91_adc_probe()
1138 ticks = (*st->caps->calc_startup_ticks)(st->startup_time, adc_clk_khz); in at91_adc_probe()
1141 * a minimal Sample and Hold Time is necessary for the ADC to guarantee in at91_adc_probe()
1143 * The formula thus is : Sample and Hold Time = (shtim + 1) / ADCClock in at91_adc_probe()
1145 if (st->sample_hold_time > 0) in at91_adc_probe()
1146 shtim = round_up((st->sample_hold_time * adc_clk_khz / 1000) in at91_adc_probe()
1147 - 1, 1); in at91_adc_probe()
1151 reg = AT91_ADC_PRESCAL_(prsc) & st->registers->mr_prescal_mask; in at91_adc_probe()
1152 reg |= AT91_ADC_STARTUP_(ticks) & st->registers->mr_startup_mask; in at91_adc_probe()
1153 if (st->res == st->caps->low_res_bits) in at91_adc_probe()
1155 if (st->sleep_mode) in at91_adc_probe()
1160 /* Setup the ADC channels available on the board */ in at91_adc_probe()
1163 dev_err(&pdev->dev, "Couldn't initialize the channels.\n"); in at91_adc_probe()
1167 init_waitqueue_head(&st->wq_data_avail); in at91_adc_probe()
1168 mutex_init(&st->lock); in at91_adc_probe()
1173 * trigger for classic adc. in at91_adc_probe()
1175 if (!st->touchscreen_type) { in at91_adc_probe()
1178 dev_err(&pdev->dev, "Couldn't initialize the buffer.\n"); in at91_adc_probe()
1184 dev_err(&pdev->dev, "Couldn't setup the triggers.\n"); in at91_adc_probe()
1198 dev_err(&pdev->dev, "Couldn't register the device.\n"); in at91_adc_probe()
1205 if (!st->touchscreen_type) { in at91_adc_probe()
1212 clk_disable_unprepare(st->adc_clk); in at91_adc_probe()
1214 clk_disable_unprepare(st->clk); in at91_adc_probe()
1216 free_irq(st->irq, idev); in at91_adc_probe()
1226 if (!st->touchscreen_type) { in at91_adc_remove()
1232 clk_disable_unprepare(st->adc_clk); in at91_adc_remove()
1233 clk_disable_unprepare(st->clk); in at91_adc_remove()
1234 free_irq(st->irq, idev); in at91_adc_remove()
1245 clk_disable_unprepare(st->clk); in at91_adc_suspend()
1255 clk_prepare_enable(st->clk); in at91_adc_resume()
1265 { .name = "timer-counter-0", .value = 0x1 },
1266 { .name = "timer-counter-1", .value = 0x3 },
1267 { .name = "timer-counter-2", .value = 0x5 },
1289 { .name = "external-rising", .value = 0x1, .is_external = true },
1290 { .name = "external-falling", .value = 0x2, .is_external = true },
1291 { .name = "external-any", .value = 0x3, .is_external = true },
1375 { .compatible = "atmel,at91sam9260-adc", .data = &at91sam9260_caps },
1376 { .compatible = "atmel,at91sam9rl-adc", .data = &at91sam9rl_caps },
1377 { .compatible = "atmel,at91sam9g45-adc", .data = &at91sam9g45_caps },
1378 { .compatible = "atmel,at91sam9x5-adc", .data = &at91sam9x5_caps },
1379 { .compatible = "atmel,sama5d3-adc", .data = &sama5d3_caps },
1397 MODULE_DESCRIPTION("Atmel AT91 ADC Driver");
1398 MODULE_AUTHOR("Maxime Ripard <maxime.ripard@free-electrons.com>");