Lines Matching +full:adc +full:- +full:clk

1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Driver for the ADC present in the Atmel AT91 evaluation boards.
11 #include <linux/clk.h>
38 #define AT91_ADC_TSAMOD (3 << 0) /* ADC mode */
39 #define AT91_ADC_TSAMOD_ADC_ONLY_MODE (0 << 0) /* ADC Mode */
103 #define AT91_ADC_ACR_PENDETSENS (0x3 << 0) /* pull-up resistor */
137 (st->registers->channel_base + (ch * 4))
139 (readl_relaxed(st->reg_base + reg))
141 (writel_relaxed(val, st->reg_base + reg))
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
200 /* Pen Detection input pull-up resistor, can be 0~3 */
216 struct clk *adc_clk;
219 struct clk *clk; member
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()
273 chan = idev->channels + i; in at91_adc_trigger_handler()
274 st->buffer[j] = at91_adc_readl(st, AT91_ADC_CHAN(st, chan->channel)); in at91_adc_trigger_handler()
278 iio_push_to_buffers_with_timestamp(idev, st->buffer, pf->timestamp); in at91_adc_trigger_handler()
280 iio_trigger_notify_done(idev->trig); in at91_adc_trigger_handler()
285 enable_irq(st->irq); in at91_adc_trigger_handler()
290 /* Handler for classic adc channel eoc trigger */
297 iio_trigger_poll(idev->trig); in handle_adc_eoc_trigger()
299 st->last_value = at91_adc_readl(st, AT91_ADC_CHAN(st, st->chnb)); in handle_adc_eoc_trigger()
302 st->done = true; in handle_adc_eoc_trigger()
303 wake_up_interruptible(&st->wq_data_avail); in handle_adc_eoc_trigger()
315 unsigned int xyz_mask_bits = st->res; in at91_ts_sample()
316 unsigned int xyz_mask = (1 << xyz_mask_bits) - 1; in at91_ts_sample()
319 /* x position = (x / xscale) * max, max = 2^MAX_POS_BITS - 1 */ in at91_ts_sample()
322 x = (xpos << MAX_POS_BITS) - xpos; in at91_ts_sample()
325 dev_err(&idev->dev, "Error: xscale == 0!\n"); in at91_ts_sample()
326 return -1; in at91_ts_sample()
330 /* y position = (y / yscale) * max, max = 2^MAX_POS_BITS - 1 */ in at91_ts_sample()
333 y = (ypos << MAX_POS_BITS) - ypos; in at91_ts_sample()
336 dev_err(&idev->dev, "Error: yscale == 0!\n"); in at91_ts_sample()
337 return -1; in at91_ts_sample()
347 pres = rxp * (x * factor / 1024) * (z2 * factor / z1 - factor) in at91_ts_sample()
350 pres = st->ts_pressure_threshold; /* no pen contacted */ in at91_ts_sample()
352 …dev_dbg(&idev->dev, "xpos = %d, xscale = %d, ypos = %d, yscale = %d, z1 = %d, z2 = %d, press = %d\… in at91_ts_sample()
355 if (pres < st->ts_pressure_threshold) { in at91_ts_sample()
356 dev_dbg(&idev->dev, "x = %d, y = %d, pressure = %d\n", in at91_ts_sample()
358 input_report_abs(st->ts_input, ABS_X, x); in at91_ts_sample()
359 input_report_abs(st->ts_input, ABS_Y, y); in at91_ts_sample()
360 input_report_abs(st->ts_input, ABS_PRESSURE, pres); in at91_ts_sample()
361 input_report_key(st->ts_input, BTN_TOUCH, 1); in at91_ts_sample()
362 input_sync(st->ts_input); in at91_ts_sample()
364 dev_dbg(&idev->dev, "pressure too low: not reporting\n"); in at91_ts_sample()
374 u32 status = at91_adc_readl(st, st->registers->status_register); in at91_adc_rl_interrupt()
378 if (status & GENMASK(st->num_channels - 1, 0)) in at91_adc_rl_interrupt()
391 at91_adc_writel(st, st->registers->trigger_register, in at91_adc_rl_interrupt()
393 AT91_ADC_TRGR_TRGPER_(st->ts_sample_period_val)); in at91_adc_rl_interrupt()
396 reg |= AT91_ADC_PENDBC_(st->ts_pendbc) & AT91_ADC_PENDBC; in at91_adc_rl_interrupt()
398 at91_adc_writel(st, st->registers->trigger_register, in at91_adc_rl_interrupt()
404 st->ts_bufferedmeasure = false; in at91_adc_rl_interrupt()
405 input_report_key(st->ts_input, BTN_TOUCH, 0); in at91_adc_rl_interrupt()
406 input_sync(st->ts_input); in at91_adc_rl_interrupt()
407 } else if (status & AT91_ADC_EOC(3) && st->ts_input) { in at91_adc_rl_interrupt()
409 if (st->ts_bufferedmeasure) { in at91_adc_rl_interrupt()
415 input_report_abs(st->ts_input, ABS_X, st->ts_prev_absx); in at91_adc_rl_interrupt()
416 input_report_abs(st->ts_input, ABS_Y, st->ts_prev_absy); in at91_adc_rl_interrupt()
417 input_report_key(st->ts_input, BTN_TOUCH, 1); in at91_adc_rl_interrupt()
418 input_sync(st->ts_input); in at91_adc_rl_interrupt()
420 st->ts_bufferedmeasure = true; in at91_adc_rl_interrupt()
423 st->ts_prev_absx = at91_adc_readl(st, AT91_ADC_CHAN(st, 3)) in at91_adc_rl_interrupt()
425 st->ts_prev_absx /= at91_adc_readl(st, AT91_ADC_CHAN(st, 2)); in at91_adc_rl_interrupt()
427 st->ts_prev_absy = at91_adc_readl(st, AT91_ADC_CHAN(st, 1)) in at91_adc_rl_interrupt()
429 st->ts_prev_absy /= at91_adc_readl(st, AT91_ADC_CHAN(st, 0)); in at91_adc_rl_interrupt()
439 u32 status = at91_adc_readl(st, st->registers->status_register); in at91_adc_9x5_interrupt()
445 if (status & GENMASK(st->num_channels - 1, 0)) in at91_adc_9x5_interrupt()
453 at91_adc_writel(st, st->registers->trigger_register, in at91_adc_9x5_interrupt()
455 AT91_ADC_TRGR_TRGPER_(st->ts_sample_period_val)); in at91_adc_9x5_interrupt()
457 at91_adc_writel(st, st->registers->trigger_register, 0); in at91_adc_9x5_interrupt()
462 input_report_key(st->ts_input, BTN_TOUCH, 0); in at91_adc_9x5_interrupt()
463 input_sync(st->ts_input); in at91_adc_9x5_interrupt()
490 /* If touchscreen is enable, then reserve the adc channels */ in at91_adc_channel_init()
491 if (st->touchscreen_type == ATMEL_ADC_TOUCHSCREEN_4WIRE) in at91_adc_channel_init()
493 else if (st->touchscreen_type == ATMEL_ADC_TOUCHSCREEN_5WIRE) in at91_adc_channel_init()
497 st->channels_mask &= ~rsvd_mask; in at91_adc_channel_init()
499 idev->num_channels = bitmap_weight(&st->channels_mask, in at91_adc_channel_init()
500 st->num_channels) + 1; in at91_adc_channel_init()
502 chan_array = devm_kzalloc(&idev->dev, in at91_adc_channel_init()
503 ((idev->num_channels + 1) * in at91_adc_channel_init()
508 return -ENOMEM; in at91_adc_channel_init()
510 for_each_set_bit(bit, &st->channels_mask, st->num_channels) { in at91_adc_channel_init()
513 chan->type = IIO_VOLTAGE; in at91_adc_channel_init()
514 chan->indexed = 1; in at91_adc_channel_init()
515 chan->channel = bit; in at91_adc_channel_init()
516 chan->scan_index = idx; in at91_adc_channel_init()
517 chan->scan_type.sign = 'u'; in at91_adc_channel_init()
518 chan->scan_type.realbits = st->res; in at91_adc_channel_init()
519 chan->scan_type.storagebits = 16; in at91_adc_channel_init()
520 chan->info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE); in at91_adc_channel_init()
521 chan->info_mask_separate = BIT(IIO_CHAN_INFO_RAW); in at91_adc_channel_init()
526 timestamp->type = IIO_TIMESTAMP; in at91_adc_channel_init()
527 timestamp->channel = -1; in at91_adc_channel_init()
528 timestamp->scan_index = idx; in at91_adc_channel_init()
529 timestamp->scan_type.sign = 's'; in at91_adc_channel_init()
530 timestamp->scan_type.realbits = 64; in at91_adc_channel_init()
531 timestamp->scan_type.storagebits = 64; in at91_adc_channel_init()
533 idev->channels = chan_array; in at91_adc_channel_init()
534 return idev->num_channels; in at91_adc_channel_init()
544 for (i = 0; i < st->caps->trigger_number; i++) { in at91_adc_get_trigger_value_by_name()
545 char *name __free(kfree) = kasprintf(GFP_KERNEL, "%s-dev%d-%s", in at91_adc_get_trigger_value_by_name()
546 idev->name, in at91_adc_get_trigger_value_by_name()
550 return -ENOMEM; in at91_adc_get_trigger_value_by_name()
554 return -EINVAL; in at91_adc_get_trigger_value_by_name()
559 return -EINVAL; in at91_adc_get_trigger_value_by_name()
566 const struct at91_adc_reg_desc *reg = st->registers; in at91_adc_configure_trigger()
567 u32 status = at91_adc_readl(st, reg->trigger_register); in at91_adc_configure_trigger()
572 st->caps->triggers, in at91_adc_configure_trigger()
573 idev->trig->name); in at91_adc_configure_trigger()
578 st->buffer = kmalloc(idev->scan_bytes, GFP_KERNEL); in at91_adc_configure_trigger()
579 if (st->buffer == NULL) in at91_adc_configure_trigger()
580 return -ENOMEM; in at91_adc_configure_trigger()
582 at91_adc_writel(st, reg->trigger_register, in at91_adc_configure_trigger()
585 for_each_set_bit(bit, idev->active_scan_mask, in at91_adc_configure_trigger()
586 st->num_channels) { in at91_adc_configure_trigger()
587 struct iio_chan_spec const *chan = idev->channels + bit; in at91_adc_configure_trigger()
589 AT91_ADC_CH(chan->channel)); in at91_adc_configure_trigger()
592 at91_adc_writel(st, AT91_ADC_IER, reg->drdy_mask); in at91_adc_configure_trigger()
595 at91_adc_writel(st, AT91_ADC_IDR, reg->drdy_mask); in at91_adc_configure_trigger()
597 at91_adc_writel(st, reg->trigger_register, in at91_adc_configure_trigger()
600 for_each_set_bit(bit, idev->active_scan_mask, in at91_adc_configure_trigger()
601 st->num_channels) { in at91_adc_configure_trigger()
602 struct iio_chan_spec const *chan = idev->channels + bit; in at91_adc_configure_trigger()
604 AT91_ADC_CH(chan->channel)); in at91_adc_configure_trigger()
606 kfree(st->buffer); in at91_adc_configure_trigger()
622 trig = iio_trigger_alloc(idev->dev.parent, "%s-dev%d-%s", idev->name, in at91_adc_allocate_trigger()
623 iio_device_id(idev), trigger->name); in at91_adc_allocate_trigger()
628 trig->ops = &at91_adc_trigger_ops; in at91_adc_allocate_trigger()
644 st->trig = devm_kcalloc(&idev->dev, in at91_adc_trigger_init()
645 st->caps->trigger_number, sizeof(*st->trig), in at91_adc_trigger_init()
648 if (st->trig == NULL) { in at91_adc_trigger_init()
649 ret = -ENOMEM; in at91_adc_trigger_init()
653 for (i = 0; i < st->caps->trigger_number; i++) { in at91_adc_trigger_init()
654 if (st->caps->triggers[i].is_external && !(st->use_external)) in at91_adc_trigger_init()
657 st->trig[i] = at91_adc_allocate_trigger(idev, in at91_adc_trigger_init()
658 st->caps->triggers + i); in at91_adc_trigger_init()
659 if (st->trig[i] == NULL) { in at91_adc_trigger_init()
660 dev_err(&idev->dev, in at91_adc_trigger_init()
662 ret = -ENOMEM; in at91_adc_trigger_init()
670 for (i--; i >= 0; i--) { in at91_adc_trigger_init()
671 iio_trigger_unregister(st->trig[i]); in at91_adc_trigger_init()
672 iio_trigger_free(st->trig[i]); in at91_adc_trigger_init()
683 for (i = 0; i < st->caps->trigger_number; i++) { in at91_adc_trigger_remove()
684 iio_trigger_unregister(st->trig[i]); in at91_adc_trigger_remove()
685 iio_trigger_free(st->trig[i]); in at91_adc_trigger_remove()
709 mutex_lock(&st->lock); in at91_adc_read_raw()
711 st->chnb = chan->channel; in at91_adc_read_raw()
713 AT91_ADC_CH(chan->channel)); in at91_adc_read_raw()
714 at91_adc_writel(st, AT91_ADC_IER, BIT(chan->channel)); in at91_adc_read_raw()
717 ret = wait_event_interruptible_timeout(st->wq_data_avail, in at91_adc_read_raw()
718 st->done, in at91_adc_read_raw()
721 /* Disable interrupts, regardless if adc conversion was in at91_adc_read_raw()
725 AT91_ADC_CH(chan->channel)); in at91_adc_read_raw()
726 at91_adc_writel(st, AT91_ADC_IDR, BIT(chan->channel)); in at91_adc_read_raw()
730 *val = st->last_value; in at91_adc_read_raw()
731 st->last_value = 0; in at91_adc_read_raw()
732 st->done = false; in at91_adc_read_raw()
736 dev_err(&idev->dev, "ADC Channel %d timeout.\n", in at91_adc_read_raw()
737 chan->channel); in at91_adc_read_raw()
738 ret = -ETIMEDOUT; in at91_adc_read_raw()
741 mutex_unlock(&st->lock); in at91_adc_read_raw()
745 *val = st->vref_mv; in at91_adc_read_raw()
746 *val2 = chan->scan_type.realbits; in at91_adc_read_raw()
751 return -EINVAL; in at91_adc_read_raw()
758 * Number of ticks needed to cover the startup time of the ADC in calc_startup_ticks_9260()
761 * Startup Time = (ticks + 1) * 8 / ADC Clock in calc_startup_ticks_9260()
763 return round_up((startup_time * adc_clk_khz / 1000) - 1, 8) / 8; in calc_startup_ticks_9260()
770 * Startup Time = <lookup_table_value> / ADC Clock in calc_startup_ticks_9x5()
789 ticks = size - 1; in calc_startup_ticks_9x5()
800 ret = of_property_read_u32(node, "atmel,adc-ts-wires", &prop); in at91_adc_probe_dt_ts()
802 dev_info(dev, "ADC Touch screen is disabled.\n"); in at91_adc_probe_dt_ts()
809 st->touchscreen_type = prop; in at91_adc_probe_dt_ts()
813 return -EINVAL; in at91_adc_probe_dt_ts()
816 if (!st->caps->has_tsmr) in at91_adc_probe_dt_ts()
819 of_property_read_u32(node, "atmel,adc-ts-pressure-threshold", &prop); in at91_adc_probe_dt_ts()
820 st->ts_pressure_threshold = prop; in at91_adc_probe_dt_ts()
821 if (st->ts_pressure_threshold) { in at91_adc_probe_dt_ts()
825 return -EINVAL; in at91_adc_probe_dt_ts()
838 if (st->caps->has_tsmr) in atmel_ts_open()
849 if (st->caps->has_tsmr) in atmel_ts_close()
862 /* a Pen Detect Debounce Time is necessary for the ADC Touch to avoid in at91_ts_hw_init()
866 st->ts_pendbc = round_up(TOUCH_PEN_DETECT_DEBOUNCE_US * adc_clk_khz / in at91_ts_hw_init()
869 while (st->ts_pendbc >> ++i) in at91_ts_hw_init()
871 if (abs(st->ts_pendbc - (1 << i)) < abs(st->ts_pendbc - (1 << (i - 1)))) in at91_ts_hw_init()
872 st->ts_pendbc = i; in at91_ts_hw_init()
874 st->ts_pendbc = i - 1; in at91_ts_hw_init()
876 if (!st->caps->has_tsmr) { in at91_ts_hw_init()
880 reg |= AT91_ADC_PENDBC_(st->ts_pendbc) & AT91_ADC_PENDBC; in at91_ts_hw_init()
886 st->ts_sample_period_val = round_up((TOUCH_SAMPLE_PERIOD_US_RL * in at91_ts_hw_init()
887 adc_clk_khz / 1000) - 1, 1); in at91_ts_hw_init()
897 dev_dbg(&idev->dev, "adc_clk at: %d KHz, tssctim at: %d\n", in at91_ts_hw_init()
900 if (st->touchscreen_type == ATMEL_ADC_TOUCHSCREEN_4WIRE) in at91_ts_hw_init()
906 reg |= AT91_ADC_TSMR_TSAV_(st->caps->ts_filter_average) in at91_ts_hw_init()
908 reg |= AT91_ADC_TSMR_PENDBC_(st->ts_pendbc) & AT91_ADC_TSMR_PENDBC; in at91_ts_hw_init()
915 /* Change adc internal resistor value for better pen detection, in at91_ts_hw_init()
920 at91_adc_writel(st, AT91_ADC_ACR, st->caps->ts_pen_detect_sensitivity in at91_ts_hw_init()
924 st->ts_sample_period_val = round_up((TOUCH_SAMPLE_PERIOD_US * in at91_ts_hw_init()
925 adc_clk_khz / 1000) - 1, 1); in at91_ts_hw_init()
939 dev_err(&idev->dev, "Failed to allocate TS device!\n"); in at91_ts_register()
940 return -ENOMEM; in at91_ts_register()
943 input->name = DRIVER_NAME; in at91_ts_register()
944 input->id.bustype = BUS_HOST; in at91_ts_register()
945 input->dev.parent = &pdev->dev; in at91_ts_register()
946 input->open = atmel_ts_open; in at91_ts_register()
947 input->close = atmel_ts_close; in at91_ts_register()
949 __set_bit(EV_ABS, input->evbit); in at91_ts_register()
950 __set_bit(EV_KEY, input->evbit); in at91_ts_register()
951 __set_bit(BTN_TOUCH, input->keybit); in at91_ts_register()
952 if (st->caps->has_tsmr) { in at91_ts_register()
953 input_set_abs_params(input, ABS_X, 0, (1 << MAX_POS_BITS) - 1, in at91_ts_register()
955 input_set_abs_params(input, ABS_Y, 0, (1 << MAX_POS_BITS) - 1, in at91_ts_register()
959 if (st->touchscreen_type != ATMEL_ADC_TOUCHSCREEN_4WIRE) { in at91_ts_register()
960 dev_err(&pdev->dev, in at91_ts_register()
962 ret = -EINVAL; in at91_ts_register()
966 input_set_abs_params(input, ABS_X, 0, (1 << MAX_RLPOS_BITS) - 1, in at91_ts_register()
968 input_set_abs_params(input, ABS_Y, 0, (1 << MAX_RLPOS_BITS) - 1, in at91_ts_register()
972 st->ts_input = input; in at91_ts_register()
982 input_free_device(st->ts_input); in at91_ts_register()
988 input_unregister_device(st->ts_input); in at91_ts_unregister()
994 struct device_node *node = pdev->dev.of_node; in at91_adc_probe()
1001 idev = devm_iio_device_alloc(&pdev->dev, sizeof(struct at91_adc_state)); in at91_adc_probe()
1003 return -ENOMEM; in at91_adc_probe()
1007 st->caps = of_device_get_match_data(&pdev->dev); in at91_adc_probe()
1009 st->use_external = of_property_read_bool(node, "atmel,adc-use-external-triggers"); in at91_adc_probe()
1011 if (of_property_read_u32(node, "atmel,adc-channels-used", &prop)) in at91_adc_probe()
1012 return dev_err_probe(&idev->dev, -EINVAL, in at91_adc_probe()
1013 "Missing adc-channels-used property in the DT.\n"); in at91_adc_probe()
1014 st->channels_mask = prop; in at91_adc_probe()
1016 st->sleep_mode = of_property_read_bool(node, "atmel,adc-sleep-mode"); in at91_adc_probe()
1018 if (of_property_read_u32(node, "atmel,adc-startup-time", &prop)) in at91_adc_probe()
1019 return dev_err_probe(&idev->dev, -EINVAL, in at91_adc_probe()
1020 "Missing adc-startup-time property in the DT.\n"); in at91_adc_probe()
1021 st->startup_time = prop; in at91_adc_probe()
1024 of_property_read_u32(node, "atmel,adc-sample-hold-time", &prop); in at91_adc_probe()
1025 st->sample_hold_time = prop; in at91_adc_probe()
1027 if (of_property_read_u32(node, "atmel,adc-vref", &prop)) in at91_adc_probe()
1028 return dev_err_probe(&idev->dev, -EINVAL, in at91_adc_probe()
1029 "Missing adc-vref property in the DT.\n"); in at91_adc_probe()
1030 st->vref_mv = prop; in at91_adc_probe()
1032 st->res = st->caps->high_res_bits; in at91_adc_probe()
1033 if (st->caps->low_res_bits && in at91_adc_probe()
1034 !of_property_read_string(node, "atmel,adc-use-res", (const char **)&s) in at91_adc_probe()
1036 st->res = st->caps->low_res_bits; in at91_adc_probe()
1038 dev_info(&idev->dev, "Resolution used: %u bits\n", st->res); in at91_adc_probe()
1040 st->registers = &st->caps->registers; in at91_adc_probe()
1041 st->num_channels = st->caps->num_channels; in at91_adc_probe()
1044 if (st->caps->has_ts) { in at91_adc_probe()
1045 ret = at91_adc_probe_dt_ts(node, st, &idev->dev); in at91_adc_probe()
1052 idev->name = dev_name(&pdev->dev); in at91_adc_probe()
1053 idev->modes = INDIO_DIRECT_MODE; in at91_adc_probe()
1054 idev->info = &at91_adc_info; in at91_adc_probe()
1056 st->irq = platform_get_irq(pdev, 0); in at91_adc_probe()
1057 if (st->irq < 0) in at91_adc_probe()
1058 return -ENODEV; in at91_adc_probe()
1060 st->reg_base = devm_platform_ioremap_resource(pdev, 0); in at91_adc_probe()
1061 if (IS_ERR(st->reg_base)) in at91_adc_probe()
1062 return PTR_ERR(st->reg_base); in at91_adc_probe()
1070 if (st->caps->has_tsmr) in at91_adc_probe()
1071 ret = devm_request_irq(&pdev->dev, st->irq, in at91_adc_probe()
1073 pdev->dev.driver->name, idev); in at91_adc_probe()
1075 ret = devm_request_irq(&pdev->dev, st->irq, in at91_adc_probe()
1077 pdev->dev.driver->name, idev); in at91_adc_probe()
1079 return dev_err_probe(&pdev->dev, ret, in at91_adc_probe()
1082 st->clk = devm_clk_get_enabled(&pdev->dev, "adc_clk"); in at91_adc_probe()
1083 if (IS_ERR(st->clk)) in at91_adc_probe()
1084 return dev_err_probe(&pdev->dev, PTR_ERR(st->clk), in at91_adc_probe()
1087 st->adc_clk = devm_clk_get_enabled(&pdev->dev, "adc_op_clk"); in at91_adc_probe()
1088 if (IS_ERR(st->adc_clk)) in at91_adc_probe()
1089 return dev_err_probe(&pdev->dev, PTR_ERR(st->adc_clk), in at91_adc_probe()
1090 "Could not prepare or enable the ADC clock.\n"); in at91_adc_probe()
1094 * datasheet : ADC Clock = MCK / ((Prescaler + 1) * 2), ADC Clock being in at91_adc_probe()
1097 mstrclk = clk_get_rate(st->clk); in at91_adc_probe()
1098 adc_clk = clk_get_rate(st->adc_clk); in at91_adc_probe()
1101 dev_dbg(&pdev->dev, "Master clock is set as: %d Hz, adc_clk should set as: %d Hz\n", in at91_adc_probe()
1104 prsc = (mstrclk / (2 * adc_clk)) - 1; in at91_adc_probe()
1106 if (!st->startup_time) in at91_adc_probe()
1107 return dev_err_probe(&pdev->dev, -EINVAL, in at91_adc_probe()
1109 ticks = (*st->caps->calc_startup_ticks)(st->startup_time, adc_clk_khz); in at91_adc_probe()
1112 * a minimal Sample and Hold Time is necessary for the ADC to guarantee in at91_adc_probe()
1116 if (st->sample_hold_time > 0) in at91_adc_probe()
1117 shtim = round_up((st->sample_hold_time * adc_clk_khz / 1000) in at91_adc_probe()
1118 - 1, 1); in at91_adc_probe()
1122 reg = AT91_ADC_PRESCAL_(prsc) & st->registers->mr_prescal_mask; in at91_adc_probe()
1123 reg |= AT91_ADC_STARTUP_(ticks) & st->registers->mr_startup_mask; in at91_adc_probe()
1124 if (st->res == st->caps->low_res_bits) in at91_adc_probe()
1126 if (st->sleep_mode) in at91_adc_probe()
1131 /* Setup the ADC channels available on the board */ in at91_adc_probe()
1134 return dev_err_probe(&pdev->dev, ret, in at91_adc_probe()
1137 init_waitqueue_head(&st->wq_data_avail); in at91_adc_probe()
1138 mutex_init(&st->lock); in at91_adc_probe()
1143 * trigger for classic adc. in at91_adc_probe()
1145 if (!st->touchscreen_type) { in at91_adc_probe()
1148 return dev_err_probe(&pdev->dev, ret, in at91_adc_probe()
1153 dev_err(&pdev->dev, "Couldn't setup the triggers.\n"); in at91_adc_probe()
1167 dev_err(&pdev->dev, "Couldn't register the device.\n"); in at91_adc_probe()
1174 if (!st->touchscreen_type) { in at91_adc_probe()
1189 if (!st->touchscreen_type) { in at91_adc_remove()
1203 clk_disable_unprepare(st->clk); in at91_adc_suspend()
1213 clk_prepare_enable(st->clk); in at91_adc_resume()
1223 { .name = "timer-counter-0", .value = 0x1 },
1224 { .name = "timer-counter-1", .value = 0x3 },
1225 { .name = "timer-counter-2", .value = 0x5 },
1247 { .name = "external-rising", .value = 0x1, .is_external = true },
1248 { .name = "external-falling", .value = 0x2, .is_external = true },
1249 { .name = "external-any", .value = 0x3, .is_external = true },
1333 { .compatible = "atmel,at91sam9260-adc", .data = &at91sam9260_caps },
1334 { .compatible = "atmel,at91sam9rl-adc", .data = &at91sam9rl_caps },
1335 { .compatible = "atmel,at91sam9g45-adc", .data = &at91sam9g45_caps },
1336 { .compatible = "atmel,at91sam9x5-adc", .data = &at91sam9x5_caps },
1337 { .compatible = "atmel,sama5d3-adc", .data = &sama5d3_caps },
1355 MODULE_DESCRIPTION("Atmel AT91 ADC Driver");
1356 MODULE_AUTHOR("Maxime Ripard <maxime.ripard@free-electrons.com>");