Lines Matching refs:st
135 #define AT91_ADC_CHAN(st, ch) \ argument
136 (st->registers->channel_base + (ch * 4))
137 #define at91_adc_readl(st, reg) \ argument
138 (readl_relaxed(st->reg_base + reg))
139 #define at91_adc_writel(st, reg, val) \ argument
140 (writel_relaxed(val, st->reg_base + reg))
267 struct at91_adc_state *st = iio_priv(idev); in at91_adc_trigger_handler() local
275 st->buffer[j] = at91_adc_readl(st, AT91_ADC_CHAN(st, chan->channel)); in at91_adc_trigger_handler()
279 iio_push_to_buffers_with_timestamp(idev, st->buffer, pf->timestamp); in at91_adc_trigger_handler()
284 at91_adc_readl(st, AT91_ADC_LCDR); in at91_adc_trigger_handler()
286 enable_irq(st->irq); in at91_adc_trigger_handler()
294 struct at91_adc_state *st = iio_priv(idev); in handle_adc_eoc_trigger() local
300 st->last_value = at91_adc_readl(st, AT91_ADC_CHAN(st, st->chnb)); in handle_adc_eoc_trigger()
302 at91_adc_readl(st, AT91_ADC_LCDR); in handle_adc_eoc_trigger()
303 st->done = true; in handle_adc_eoc_trigger()
304 wake_up_interruptible(&st->wq_data_avail); in handle_adc_eoc_trigger()
310 struct at91_adc_state *st = iio_priv(idev); in at91_ts_sample() local
316 unsigned int xyz_mask_bits = st->res; in at91_ts_sample()
321 reg = at91_adc_readl(st, AT91_ADC_TSXPOSR); in at91_ts_sample()
332 reg = at91_adc_readl(st, AT91_ADC_TSYPOSR); in at91_ts_sample()
343 reg = at91_adc_readl(st, AT91_ADC_TSPRESSR); in at91_ts_sample()
351 pres = st->ts_pressure_threshold; /* no pen contacted */ in at91_ts_sample()
356 if (pres < st->ts_pressure_threshold) { in at91_ts_sample()
359 input_report_abs(st->ts_input, ABS_X, x); in at91_ts_sample()
360 input_report_abs(st->ts_input, ABS_Y, y); in at91_ts_sample()
361 input_report_abs(st->ts_input, ABS_PRESSURE, pres); in at91_ts_sample()
362 input_report_key(st->ts_input, BTN_TOUCH, 1); in at91_ts_sample()
363 input_sync(st->ts_input); in at91_ts_sample()
374 struct at91_adc_state *st = iio_priv(idev); in at91_adc_rl_interrupt() local
375 u32 status = at91_adc_readl(st, st->registers->status_register); in at91_adc_rl_interrupt()
378 status &= at91_adc_readl(st, AT91_ADC_IMR); in at91_adc_rl_interrupt()
379 if (status & GENMASK(st->num_channels - 1, 0)) in at91_adc_rl_interrupt()
384 reg = at91_adc_readl(st, AT91_ADC_MR); in at91_adc_rl_interrupt()
386 at91_adc_writel(st, AT91_ADC_MR, reg); in at91_adc_rl_interrupt()
388 at91_adc_writel(st, AT91_ADC_IDR, AT91RL_ADC_IER_PEN); in at91_adc_rl_interrupt()
389 at91_adc_writel(st, AT91_ADC_IER, AT91RL_ADC_IER_NOPEN in at91_adc_rl_interrupt()
392 at91_adc_writel(st, st->registers->trigger_register, in at91_adc_rl_interrupt()
394 AT91_ADC_TRGR_TRGPER_(st->ts_sample_period_val)); in at91_adc_rl_interrupt()
396 reg = at91_adc_readl(st, AT91_ADC_MR); in at91_adc_rl_interrupt()
397 reg |= AT91_ADC_PENDBC_(st->ts_pendbc) & AT91_ADC_PENDBC; in at91_adc_rl_interrupt()
398 at91_adc_writel(st, AT91_ADC_MR, reg); in at91_adc_rl_interrupt()
399 at91_adc_writel(st, st->registers->trigger_register, in at91_adc_rl_interrupt()
402 at91_adc_writel(st, AT91_ADC_IDR, AT91RL_ADC_IER_NOPEN in at91_adc_rl_interrupt()
404 at91_adc_writel(st, AT91_ADC_IER, AT91RL_ADC_IER_PEN); in at91_adc_rl_interrupt()
405 st->ts_bufferedmeasure = false; in at91_adc_rl_interrupt()
406 input_report_key(st->ts_input, BTN_TOUCH, 0); in at91_adc_rl_interrupt()
407 input_sync(st->ts_input); in at91_adc_rl_interrupt()
408 } else if (status & AT91_ADC_EOC(3) && st->ts_input) { in at91_adc_rl_interrupt()
410 if (st->ts_bufferedmeasure) { in at91_adc_rl_interrupt()
416 input_report_abs(st->ts_input, ABS_X, st->ts_prev_absx); in at91_adc_rl_interrupt()
417 input_report_abs(st->ts_input, ABS_Y, st->ts_prev_absy); in at91_adc_rl_interrupt()
418 input_report_key(st->ts_input, BTN_TOUCH, 1); in at91_adc_rl_interrupt()
419 input_sync(st->ts_input); in at91_adc_rl_interrupt()
421 st->ts_bufferedmeasure = true; in at91_adc_rl_interrupt()
424 st->ts_prev_absx = at91_adc_readl(st, AT91_ADC_CHAN(st, 3)) in at91_adc_rl_interrupt()
426 st->ts_prev_absx /= at91_adc_readl(st, AT91_ADC_CHAN(st, 2)); in at91_adc_rl_interrupt()
428 st->ts_prev_absy = at91_adc_readl(st, AT91_ADC_CHAN(st, 1)) in at91_adc_rl_interrupt()
430 st->ts_prev_absy /= at91_adc_readl(st, AT91_ADC_CHAN(st, 0)); in at91_adc_rl_interrupt()
439 struct at91_adc_state *st = iio_priv(idev); in at91_adc_9x5_interrupt() local
440 u32 status = at91_adc_readl(st, st->registers->status_register); in at91_adc_9x5_interrupt()
446 if (status & GENMASK(st->num_channels - 1, 0)) in at91_adc_9x5_interrupt()
450 at91_adc_writel(st, AT91_ADC_IDR, AT91_ADC_IER_PEN); in at91_adc_9x5_interrupt()
451 at91_adc_writel(st, AT91_ADC_IER, AT91_ADC_IER_NOPEN | in at91_adc_9x5_interrupt()
454 at91_adc_writel(st, st->registers->trigger_register, in at91_adc_9x5_interrupt()
456 AT91_ADC_TRGR_TRGPER_(st->ts_sample_period_val)); in at91_adc_9x5_interrupt()
458 at91_adc_writel(st, st->registers->trigger_register, 0); in at91_adc_9x5_interrupt()
459 at91_adc_writel(st, AT91_ADC_IDR, AT91_ADC_IER_NOPEN | in at91_adc_9x5_interrupt()
461 at91_adc_writel(st, AT91_ADC_IER, AT91_ADC_IER_PEN); in at91_adc_9x5_interrupt()
463 input_report_key(st->ts_input, BTN_TOUCH, 0); in at91_adc_9x5_interrupt()
464 input_sync(st->ts_input); in at91_adc_9x5_interrupt()
475 at91_adc_readl(st, AT91_ADC_TSXPOSR); in at91_adc_9x5_interrupt()
476 at91_adc_readl(st, AT91_ADC_TSYPOSR); in at91_adc_9x5_interrupt()
477 at91_adc_readl(st, AT91_ADC_TSPRESSR); in at91_adc_9x5_interrupt()
486 struct at91_adc_state *st = iio_priv(idev); in at91_adc_channel_init() local
492 if (st->touchscreen_type == ATMEL_ADC_TOUCHSCREEN_4WIRE) in at91_adc_channel_init()
494 else if (st->touchscreen_type == ATMEL_ADC_TOUCHSCREEN_5WIRE) in at91_adc_channel_init()
498 st->channels_mask &= ~rsvd_mask; in at91_adc_channel_init()
500 idev->num_channels = bitmap_weight(&st->channels_mask, in at91_adc_channel_init()
501 st->num_channels) + 1; in at91_adc_channel_init()
511 for_each_set_bit(bit, &st->channels_mask, st->num_channels) { in at91_adc_channel_init()
519 chan->scan_type.realbits = st->res; in at91_adc_channel_init()
542 struct at91_adc_state *st = iio_priv(idev); in at91_adc_get_trigger_value_by_name() local
545 for (i = 0; i < st->caps->trigger_number; i++) { in at91_adc_get_trigger_value_by_name()
570 struct at91_adc_state *st = iio_priv(idev); in at91_adc_configure_trigger() local
571 const struct at91_adc_reg_desc *reg = st->registers; in at91_adc_configure_trigger()
572 u32 status = at91_adc_readl(st, reg->trigger_register); in at91_adc_configure_trigger()
577 st->caps->triggers, in at91_adc_configure_trigger()
583 st->buffer = kmalloc(idev->scan_bytes, GFP_KERNEL); in at91_adc_configure_trigger()
584 if (st->buffer == NULL) in at91_adc_configure_trigger()
587 at91_adc_writel(st, reg->trigger_register, in at91_adc_configure_trigger()
591 st->num_channels) { in at91_adc_configure_trigger()
593 at91_adc_writel(st, AT91_ADC_CHER, in at91_adc_configure_trigger()
597 at91_adc_writel(st, AT91_ADC_IER, reg->drdy_mask); in at91_adc_configure_trigger()
600 at91_adc_writel(st, AT91_ADC_IDR, reg->drdy_mask); in at91_adc_configure_trigger()
602 at91_adc_writel(st, reg->trigger_register, in at91_adc_configure_trigger()
606 st->num_channels) { in at91_adc_configure_trigger()
608 at91_adc_writel(st, AT91_ADC_CHDR, in at91_adc_configure_trigger()
611 kfree(st->buffer); in at91_adc_configure_trigger()
646 struct at91_adc_state *st = iio_priv(idev); in at91_adc_trigger_init() local
649 st->trig = devm_kcalloc(&idev->dev, in at91_adc_trigger_init()
650 st->caps->trigger_number, sizeof(*st->trig), in at91_adc_trigger_init()
653 if (st->trig == NULL) { in at91_adc_trigger_init()
658 for (i = 0; i < st->caps->trigger_number; i++) { in at91_adc_trigger_init()
659 if (st->caps->triggers[i].is_external && !(st->use_external)) in at91_adc_trigger_init()
662 st->trig[i] = at91_adc_allocate_trigger(idev, in at91_adc_trigger_init()
663 st->caps->triggers + i); in at91_adc_trigger_init()
664 if (st->trig[i] == NULL) { in at91_adc_trigger_init()
676 iio_trigger_unregister(st->trig[i]); in at91_adc_trigger_init()
677 iio_trigger_free(st->trig[i]); in at91_adc_trigger_init()
685 struct at91_adc_state *st = iio_priv(idev); in at91_adc_trigger_remove() local
688 for (i = 0; i < st->caps->trigger_number; i++) { in at91_adc_trigger_remove()
689 iio_trigger_unregister(st->trig[i]); in at91_adc_trigger_remove()
690 iio_trigger_free(st->trig[i]); in at91_adc_trigger_remove()
709 struct at91_adc_state *st = iio_priv(idev); in at91_adc_read_raw() local
714 mutex_lock(&st->lock); in at91_adc_read_raw()
716 st->chnb = chan->channel; in at91_adc_read_raw()
717 at91_adc_writel(st, AT91_ADC_CHER, in at91_adc_read_raw()
719 at91_adc_writel(st, AT91_ADC_IER, BIT(chan->channel)); in at91_adc_read_raw()
720 at91_adc_writel(st, AT91_ADC_CR, AT91_ADC_START); in at91_adc_read_raw()
722 ret = wait_event_interruptible_timeout(st->wq_data_avail, in at91_adc_read_raw()
723 st->done, in at91_adc_read_raw()
729 at91_adc_writel(st, AT91_ADC_CHDR, in at91_adc_read_raw()
731 at91_adc_writel(st, AT91_ADC_IDR, BIT(chan->channel)); in at91_adc_read_raw()
735 *val = st->last_value; in at91_adc_read_raw()
736 st->last_value = 0; in at91_adc_read_raw()
737 st->done = false; in at91_adc_read_raw()
746 mutex_unlock(&st->lock); in at91_adc_read_raw()
750 *val = st->vref_mv; in at91_adc_read_raw()
800 struct at91_adc_state *st, struct device *dev) in at91_adc_probe_dt_ts() argument
814 st->touchscreen_type = prop; in at91_adc_probe_dt_ts()
821 if (!st->caps->has_tsmr) in at91_adc_probe_dt_ts()
825 st->ts_pressure_threshold = prop; in at91_adc_probe_dt_ts()
826 if (st->ts_pressure_threshold) { in at91_adc_probe_dt_ts()
841 struct at91_adc_state *st = input_get_drvdata(dev); in atmel_ts_open() local
843 if (st->caps->has_tsmr) in atmel_ts_open()
844 at91_adc_writel(st, AT91_ADC_IER, AT91_ADC_IER_PEN); in atmel_ts_open()
846 at91_adc_writel(st, AT91_ADC_IER, AT91RL_ADC_IER_PEN); in atmel_ts_open()
852 struct at91_adc_state *st = input_get_drvdata(dev); in atmel_ts_close() local
854 if (st->caps->has_tsmr) in atmel_ts_close()
855 at91_adc_writel(st, AT91_ADC_IDR, AT91_ADC_IER_PEN); in atmel_ts_close()
857 at91_adc_writel(st, AT91_ADC_IDR, AT91RL_ADC_IER_PEN); in atmel_ts_close()
862 struct at91_adc_state *st = iio_priv(idev); in at91_ts_hw_init() local
871 st->ts_pendbc = round_up(TOUCH_PEN_DETECT_DEBOUNCE_US * adc_clk_khz / in at91_ts_hw_init()
874 while (st->ts_pendbc >> ++i) in at91_ts_hw_init()
876 if (abs(st->ts_pendbc - (1 << i)) < abs(st->ts_pendbc - (1 << (i - 1)))) in at91_ts_hw_init()
877 st->ts_pendbc = i; in at91_ts_hw_init()
879 st->ts_pendbc = i - 1; in at91_ts_hw_init()
881 if (!st->caps->has_tsmr) { in at91_ts_hw_init()
882 reg = at91_adc_readl(st, AT91_ADC_MR); in at91_ts_hw_init()
885 reg |= AT91_ADC_PENDBC_(st->ts_pendbc) & AT91_ADC_PENDBC; in at91_ts_hw_init()
886 at91_adc_writel(st, AT91_ADC_MR, reg); in at91_ts_hw_init()
889 at91_adc_writel(st, AT91_ADC_TSR, reg); in at91_ts_hw_init()
891 st->ts_sample_period_val = round_up((TOUCH_SAMPLE_PERIOD_US_RL * in at91_ts_hw_init()
905 if (st->touchscreen_type == ATMEL_ADC_TOUCHSCREEN_4WIRE) in at91_ts_hw_init()
911 reg |= AT91_ADC_TSMR_TSAV_(st->caps->ts_filter_average) in at91_ts_hw_init()
913 reg |= AT91_ADC_TSMR_PENDBC_(st->ts_pendbc) & AT91_ADC_TSMR_PENDBC; in at91_ts_hw_init()
918 at91_adc_writel(st, AT91_ADC_TSMR, reg); in at91_ts_hw_init()
925 at91_adc_writel(st, AT91_ADC_ACR, st->caps->ts_pen_detect_sensitivity in at91_ts_hw_init()
929 st->ts_sample_period_val = round_up((TOUCH_SAMPLE_PERIOD_US * in at91_ts_hw_init()
938 struct at91_adc_state *st = iio_priv(idev); in at91_ts_register() local
957 if (st->caps->has_tsmr) { in at91_ts_register()
964 if (st->touchscreen_type != ATMEL_ADC_TOUCHSCREEN_4WIRE) { in at91_ts_register()
977 st->ts_input = input; in at91_ts_register()
978 input_set_drvdata(input, st); in at91_ts_register()
987 input_free_device(st->ts_input); in at91_ts_register()
991 static void at91_ts_unregister(struct at91_adc_state *st) in at91_ts_unregister() argument
993 input_unregister_device(st->ts_input); in at91_ts_unregister()
1002 struct at91_adc_state *st; in at91_adc_probe() local
1010 st = iio_priv(idev); in at91_adc_probe()
1012 st->caps = of_device_get_match_data(&pdev->dev); in at91_adc_probe()
1014 st->use_external = of_property_read_bool(node, "atmel,adc-use-external-triggers"); in at91_adc_probe()
1020 st->channels_mask = prop; in at91_adc_probe()
1022 st->sleep_mode = of_property_read_bool(node, "atmel,adc-sleep-mode"); in at91_adc_probe()
1028 st->startup_time = prop; in at91_adc_probe()
1032 st->sample_hold_time = prop; in at91_adc_probe()
1038 st->vref_mv = prop; in at91_adc_probe()
1040 st->res = st->caps->high_res_bits; in at91_adc_probe()
1041 if (st->caps->low_res_bits && in at91_adc_probe()
1044 st->res = st->caps->low_res_bits; in at91_adc_probe()
1046 dev_info(&idev->dev, "Resolution used: %u bits\n", st->res); in at91_adc_probe()
1048 st->registers = &st->caps->registers; in at91_adc_probe()
1049 st->num_channels = st->caps->num_channels; in at91_adc_probe()
1052 if (st->caps->has_ts) { in at91_adc_probe()
1053 ret = at91_adc_probe_dt_ts(node, st, &idev->dev); in at91_adc_probe()
1064 st->irq = platform_get_irq(pdev, 0); in at91_adc_probe()
1065 if (st->irq < 0) in at91_adc_probe()
1068 st->reg_base = devm_platform_ioremap_resource(pdev, 0); in at91_adc_probe()
1069 if (IS_ERR(st->reg_base)) in at91_adc_probe()
1070 return PTR_ERR(st->reg_base); in at91_adc_probe()
1076 at91_adc_writel(st, AT91_ADC_CR, AT91_ADC_SWRST); in at91_adc_probe()
1077 at91_adc_writel(st, AT91_ADC_IDR, 0xFFFFFFFF); in at91_adc_probe()
1079 if (st->caps->has_tsmr) in at91_adc_probe()
1080 ret = request_irq(st->irq, at91_adc_9x5_interrupt, 0, in at91_adc_probe()
1083 ret = request_irq(st->irq, at91_adc_rl_interrupt, 0, in at91_adc_probe()
1090 st->clk = devm_clk_get(&pdev->dev, "adc_clk"); in at91_adc_probe()
1091 if (IS_ERR(st->clk)) { in at91_adc_probe()
1093 ret = PTR_ERR(st->clk); in at91_adc_probe()
1097 ret = clk_prepare_enable(st->clk); in at91_adc_probe()
1104 st->adc_clk = devm_clk_get(&pdev->dev, "adc_op_clk"); in at91_adc_probe()
1105 if (IS_ERR(st->adc_clk)) { in at91_adc_probe()
1107 ret = PTR_ERR(st->adc_clk); in at91_adc_probe()
1111 ret = clk_prepare_enable(st->adc_clk); in at91_adc_probe()
1123 mstrclk = clk_get_rate(st->clk); in at91_adc_probe()
1124 adc_clk = clk_get_rate(st->adc_clk); in at91_adc_probe()
1132 if (!st->startup_time) { in at91_adc_probe()
1137 ticks = (*st->caps->calc_startup_ticks)(st->startup_time, adc_clk_khz); in at91_adc_probe()
1144 if (st->sample_hold_time > 0) in at91_adc_probe()
1145 shtim = round_up((st->sample_hold_time * adc_clk_khz / 1000) in at91_adc_probe()
1150 reg = AT91_ADC_PRESCAL_(prsc) & st->registers->mr_prescal_mask; in at91_adc_probe()
1151 reg |= AT91_ADC_STARTUP_(ticks) & st->registers->mr_startup_mask; in at91_adc_probe()
1152 if (st->res == st->caps->low_res_bits) in at91_adc_probe()
1154 if (st->sleep_mode) in at91_adc_probe()
1157 at91_adc_writel(st, AT91_ADC_MR, reg); in at91_adc_probe()
1166 init_waitqueue_head(&st->wq_data_avail); in at91_adc_probe()
1167 mutex_init(&st->lock); in at91_adc_probe()
1174 if (!st->touchscreen_type) { in at91_adc_probe()
1204 if (!st->touchscreen_type) { in at91_adc_probe()
1208 at91_ts_unregister(st); in at91_adc_probe()
1211 clk_disable_unprepare(st->adc_clk); in at91_adc_probe()
1213 clk_disable_unprepare(st->clk); in at91_adc_probe()
1215 free_irq(st->irq, idev); in at91_adc_probe()
1222 struct at91_adc_state *st = iio_priv(idev); in at91_adc_remove() local
1225 if (!st->touchscreen_type) { in at91_adc_remove()
1229 at91_ts_unregister(st); in at91_adc_remove()
1231 clk_disable_unprepare(st->adc_clk); in at91_adc_remove()
1232 clk_disable_unprepare(st->clk); in at91_adc_remove()
1233 free_irq(st->irq, idev); in at91_adc_remove()
1241 struct at91_adc_state *st = iio_priv(idev); in at91_adc_suspend() local
1244 clk_disable_unprepare(st->clk); in at91_adc_suspend()
1252 struct at91_adc_state *st = iio_priv(idev); in at91_adc_resume() local
1254 clk_prepare_enable(st->clk); in at91_adc_resume()