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

1 // SPDX-License-Identifier: GPL-2.0-or-later
105 #define AT91_ADC_ACR_PENDETSENS (0x3 << 0) /* pull-up resistor */
119 #define AT91_ADC_TSMR_NOTSDMA (1 << 22) /* No Touchscreen DMA */
139 (st->registers->channel_base + (ch * 4))
141 (readl_relaxed(st->reg_base + reg))
143 (writel_relaxed(val, st->reg_base + reg))
154 #define TOUCH_SCTIM_US 10 /* 10us for the Touchscreen Switches Closure Time */
157 * struct at91_adc_reg_desc - Various informations relative to registers
183 /* Pen Detection input pull-up resistor, can be 0~3 */
220 * Following ADC channels are shared by touchscreen:
222 * CH0 -- Touch screen XP/UL
223 * CH1 -- Touch screen XM/UR
224 * CH2 -- Touch screen YP/LL
225 * CH3 -- Touch screen YM/Sense
226 * CH4 -- Touch screen LR(5-wire only)
229 * touchscreen mode.
248 struct iio_dev *idev = pf->indio_dev; in at91_adc_trigger_handler()
253 for (i = 0; i < idev->masklength; i++) { in at91_adc_trigger_handler()
254 if (!test_bit(i, idev->active_scan_mask)) in at91_adc_trigger_handler()
256 chan = idev->channels + i; in at91_adc_trigger_handler()
257 st->buffer[j] = at91_adc_readl(st, AT91_ADC_CHAN(st, chan->channel)); in at91_adc_trigger_handler()
261 iio_push_to_buffers_with_timestamp(idev, st->buffer, pf->timestamp); in at91_adc_trigger_handler()
263 iio_trigger_notify_done(idev->trig); in at91_adc_trigger_handler()
268 enable_irq(st->irq); in at91_adc_trigger_handler()
280 iio_trigger_poll(idev->trig); in handle_adc_eoc_trigger()
282 st->last_value = at91_adc_readl(st, AT91_ADC_CHAN(st, st->chnb)); in handle_adc_eoc_trigger()
285 st->done = true; in handle_adc_eoc_trigger()
286 wake_up_interruptible(&st->wq_data_avail); in handle_adc_eoc_trigger()
298 unsigned int xyz_mask_bits = st->res; in at91_ts_sample()
299 unsigned int xyz_mask = (1 << xyz_mask_bits) - 1; in at91_ts_sample()
302 /* x position = (x / xscale) * max, max = 2^MAX_POS_BITS - 1 */ in at91_ts_sample()
305 x = (xpos << MAX_POS_BITS) - xpos; in at91_ts_sample()
308 dev_err(&idev->dev, "Error: xscale == 0!\n"); in at91_ts_sample()
309 return -1; in at91_ts_sample()
313 /* y position = (y / yscale) * max, max = 2^MAX_POS_BITS - 1 */ in at91_ts_sample()
316 y = (ypos << MAX_POS_BITS) - ypos; in at91_ts_sample()
319 dev_err(&idev->dev, "Error: yscale == 0!\n"); in at91_ts_sample()
320 return -1; in at91_ts_sample()
324 /* calculate the pressure */ in at91_ts_sample()
330 pres = rxp * (x * factor / 1024) * (z2 * factor / z1 - factor) in at91_ts_sample()
333 pres = st->ts_pressure_threshold; /* no pen contacted */ in at91_ts_sample()
335 …dev_dbg(&idev->dev, "xpos = %d, xscale = %d, ypos = %d, yscale = %d, z1 = %d, z2 = %d, press = %d\… in at91_ts_sample()
338 if (pres < st->ts_pressure_threshold) { in at91_ts_sample()
339 dev_dbg(&idev->dev, "x = %d, y = %d, pressure = %d\n", in at91_ts_sample()
341 input_report_abs(st->ts_input, ABS_X, x); in at91_ts_sample()
342 input_report_abs(st->ts_input, ABS_Y, y); in at91_ts_sample()
343 input_report_abs(st->ts_input, ABS_PRESSURE, pres); in at91_ts_sample()
344 input_report_key(st->ts_input, BTN_TOUCH, 1); in at91_ts_sample()
345 input_sync(st->ts_input); in at91_ts_sample()
347 dev_dbg(&idev->dev, "pressure too low: not reporting\n"); in at91_ts_sample()
357 u32 status = at91_adc_readl(st, st->registers->status_register); in at91_adc_rl_interrupt()
361 if (status & GENMASK(st->num_channels - 1, 0)) in at91_adc_rl_interrupt()
374 at91_adc_writel(st, st->registers->trigger_register, in at91_adc_rl_interrupt()
376 AT91_ADC_TRGR_TRGPER_(st->ts_sample_period_val)); in at91_adc_rl_interrupt()
379 reg |= AT91_ADC_PENDBC_(st->ts_pendbc) & AT91_ADC_PENDBC; in at91_adc_rl_interrupt()
381 at91_adc_writel(st, st->registers->trigger_register, in at91_adc_rl_interrupt()
387 st->ts_bufferedmeasure = false; in at91_adc_rl_interrupt()
388 input_report_key(st->ts_input, BTN_TOUCH, 0); in at91_adc_rl_interrupt()
389 input_sync(st->ts_input); in at91_adc_rl_interrupt()
390 } else if (status & AT91_ADC_EOC(3) && st->ts_input) { in at91_adc_rl_interrupt()
391 /* Conversion finished and we've a touchscreen */ in at91_adc_rl_interrupt()
392 if (st->ts_bufferedmeasure) { in at91_adc_rl_interrupt()
398 input_report_abs(st->ts_input, ABS_X, st->ts_prev_absx); in at91_adc_rl_interrupt()
399 input_report_abs(st->ts_input, ABS_Y, st->ts_prev_absy); in at91_adc_rl_interrupt()
400 input_report_key(st->ts_input, BTN_TOUCH, 1); in at91_adc_rl_interrupt()
401 input_sync(st->ts_input); in at91_adc_rl_interrupt()
403 st->ts_bufferedmeasure = true; in at91_adc_rl_interrupt()
406 st->ts_prev_absx = at91_adc_readl(st, AT91_ADC_CHAN(st, 3)) in at91_adc_rl_interrupt()
408 st->ts_prev_absx /= at91_adc_readl(st, AT91_ADC_CHAN(st, 2)); in at91_adc_rl_interrupt()
410 st->ts_prev_absy = at91_adc_readl(st, AT91_ADC_CHAN(st, 1)) in at91_adc_rl_interrupt()
412 st->ts_prev_absy /= at91_adc_readl(st, AT91_ADC_CHAN(st, 0)); in at91_adc_rl_interrupt()
422 u32 status = at91_adc_readl(st, st->registers->status_register); in at91_adc_9x5_interrupt()
428 if (status & GENMASK(st->num_channels - 1, 0)) in at91_adc_9x5_interrupt()
436 at91_adc_writel(st, st->registers->trigger_register, in at91_adc_9x5_interrupt()
438 AT91_ADC_TRGR_TRGPER_(st->ts_sample_period_val)); in at91_adc_9x5_interrupt()
440 at91_adc_writel(st, st->registers->trigger_register, 0); in at91_adc_9x5_interrupt()
445 input_report_key(st->ts_input, BTN_TOUCH, 0); in at91_adc_9x5_interrupt()
446 input_sync(st->ts_input); in at91_adc_9x5_interrupt()
448 /* Now all touchscreen data is ready */ in at91_adc_9x5_interrupt()
473 /* If touchscreen is enable, then reserve the adc channels */ in at91_adc_channel_init()
474 if (st->touchscreen_type == ATMEL_ADC_TOUCHSCREEN_4WIRE) in at91_adc_channel_init()
476 else if (st->touchscreen_type == ATMEL_ADC_TOUCHSCREEN_5WIRE) in at91_adc_channel_init()
479 /* set up the channel mask to reserve touchscreen channels */ in at91_adc_channel_init()
480 st->channels_mask &= ~rsvd_mask; in at91_adc_channel_init()
482 idev->num_channels = bitmap_weight(&st->channels_mask, in at91_adc_channel_init()
483 st->num_channels) + 1; in at91_adc_channel_init()
485 chan_array = devm_kzalloc(&idev->dev, in at91_adc_channel_init()
486 ((idev->num_channels + 1) * in at91_adc_channel_init()
491 return -ENOMEM; in at91_adc_channel_init()
493 for_each_set_bit(bit, &st->channels_mask, st->num_channels) { in at91_adc_channel_init()
496 chan->type = IIO_VOLTAGE; in at91_adc_channel_init()
497 chan->indexed = 1; in at91_adc_channel_init()
498 chan->channel = bit; in at91_adc_channel_init()
499 chan->scan_index = idx; in at91_adc_channel_init()
500 chan->scan_type.sign = 'u'; in at91_adc_channel_init()
501 chan->scan_type.realbits = st->res; in at91_adc_channel_init()
502 chan->scan_type.storagebits = 16; in at91_adc_channel_init()
503 chan->info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE); in at91_adc_channel_init()
504 chan->info_mask_separate = BIT(IIO_CHAN_INFO_RAW); in at91_adc_channel_init()
509 timestamp->type = IIO_TIMESTAMP; in at91_adc_channel_init()
510 timestamp->channel = -1; in at91_adc_channel_init()
511 timestamp->scan_index = idx; in at91_adc_channel_init()
512 timestamp->scan_type.sign = 's'; in at91_adc_channel_init()
513 timestamp->scan_type.realbits = 64; in at91_adc_channel_init()
514 timestamp->scan_type.storagebits = 64; in at91_adc_channel_init()
516 idev->channels = chan_array; in at91_adc_channel_init()
517 return idev->num_channels; in at91_adc_channel_init()
527 for (i = 0; i < st->trigger_number; i++) { in at91_adc_get_trigger_value_by_name()
529 "%s-dev%d-%s", in at91_adc_get_trigger_value_by_name()
530 idev->name, in at91_adc_get_trigger_value_by_name()
531 idev->id, in at91_adc_get_trigger_value_by_name()
534 return -ENOMEM; in at91_adc_get_trigger_value_by_name()
539 return -EINVAL; in at91_adc_get_trigger_value_by_name()
546 return -EINVAL; in at91_adc_get_trigger_value_by_name()
553 struct at91_adc_reg_desc *reg = st->registers; in at91_adc_configure_trigger()
554 u32 status = at91_adc_readl(st, reg->trigger_register); in at91_adc_configure_trigger()
559 st->trigger_list, in at91_adc_configure_trigger()
560 idev->trig->name); in at91_adc_configure_trigger()
565 st->buffer = kmalloc(idev->scan_bytes, GFP_KERNEL); in at91_adc_configure_trigger()
566 if (st->buffer == NULL) in at91_adc_configure_trigger()
567 return -ENOMEM; in at91_adc_configure_trigger()
569 at91_adc_writel(st, reg->trigger_register, in at91_adc_configure_trigger()
572 for_each_set_bit(bit, idev->active_scan_mask, in at91_adc_configure_trigger()
573 st->num_channels) { in at91_adc_configure_trigger()
574 struct iio_chan_spec const *chan = idev->channels + bit; in at91_adc_configure_trigger()
576 AT91_ADC_CH(chan->channel)); in at91_adc_configure_trigger()
579 at91_adc_writel(st, AT91_ADC_IER, reg->drdy_mask); in at91_adc_configure_trigger()
582 at91_adc_writel(st, AT91_ADC_IDR, reg->drdy_mask); in at91_adc_configure_trigger()
584 at91_adc_writel(st, reg->trigger_register, in at91_adc_configure_trigger()
587 for_each_set_bit(bit, idev->active_scan_mask, in at91_adc_configure_trigger()
588 st->num_channels) { in at91_adc_configure_trigger()
589 struct iio_chan_spec const *chan = idev->channels + bit; in at91_adc_configure_trigger()
591 AT91_ADC_CH(chan->channel)); in at91_adc_configure_trigger()
593 kfree(st->buffer); in at91_adc_configure_trigger()
609 trig = iio_trigger_alloc("%s-dev%d-%s", idev->name, in at91_adc_allocate_trigger()
610 idev->id, trigger->name); in at91_adc_allocate_trigger()
614 trig->dev.parent = idev->dev.parent; in at91_adc_allocate_trigger()
616 trig->ops = &at91_adc_trigger_ops; in at91_adc_allocate_trigger()
630 st->trig = devm_kcalloc(&idev->dev, in at91_adc_trigger_init()
631 st->trigger_number, sizeof(*st->trig), in at91_adc_trigger_init()
634 if (st->trig == NULL) { in at91_adc_trigger_init()
635 ret = -ENOMEM; in at91_adc_trigger_init()
639 for (i = 0; i < st->trigger_number; i++) { in at91_adc_trigger_init()
640 if (st->trigger_list[i].is_external && !(st->use_external)) in at91_adc_trigger_init()
643 st->trig[i] = at91_adc_allocate_trigger(idev, in at91_adc_trigger_init()
644 st->trigger_list + i); in at91_adc_trigger_init()
645 if (st->trig[i] == NULL) { in at91_adc_trigger_init()
646 dev_err(&idev->dev, in at91_adc_trigger_init()
648 ret = -ENOMEM; in at91_adc_trigger_init()
656 for (i--; i >= 0; i--) { in at91_adc_trigger_init()
657 iio_trigger_unregister(st->trig[i]); in at91_adc_trigger_init()
658 iio_trigger_free(st->trig[i]); in at91_adc_trigger_init()
669 for (i = 0; i < st->trigger_number; i++) { in at91_adc_trigger_remove()
670 iio_trigger_unregister(st->trig[i]); in at91_adc_trigger_remove()
671 iio_trigger_free(st->trig[i]); in at91_adc_trigger_remove()
695 mutex_lock(&st->lock); in at91_adc_read_raw()
697 st->chnb = chan->channel; in at91_adc_read_raw()
699 AT91_ADC_CH(chan->channel)); in at91_adc_read_raw()
700 at91_adc_writel(st, AT91_ADC_IER, BIT(chan->channel)); in at91_adc_read_raw()
703 ret = wait_event_interruptible_timeout(st->wq_data_avail, in at91_adc_read_raw()
704 st->done, in at91_adc_read_raw()
711 AT91_ADC_CH(chan->channel)); in at91_adc_read_raw()
712 at91_adc_writel(st, AT91_ADC_IDR, BIT(chan->channel)); in at91_adc_read_raw()
716 *val = st->last_value; in at91_adc_read_raw()
717 st->last_value = 0; in at91_adc_read_raw()
718 st->done = false; in at91_adc_read_raw()
722 dev_err(&idev->dev, "ADC Channel %d timeout.\n", in at91_adc_read_raw()
723 chan->channel); in at91_adc_read_raw()
724 ret = -ETIMEDOUT; in at91_adc_read_raw()
727 mutex_unlock(&st->lock); in at91_adc_read_raw()
731 *val = st->vref_mv; in at91_adc_read_raw()
732 *val2 = chan->scan_type.realbits; in at91_adc_read_raw()
737 return -EINVAL; in at91_adc_read_raw()
744 struct device_node *np = pdev->dev.of_node; in at91_adc_of_get_resolution()
749 count = of_property_count_strings(np, "atmel,adc-res-names"); in at91_adc_of_get_resolution()
751 dev_err(&idev->dev, "You must specified at least two resolution names for " in at91_adc_of_get_resolution()
752 "adc-res-names property in the DT\n"); in at91_adc_of_get_resolution()
758 return -ENOMEM; in at91_adc_of_get_resolution()
760 if (of_property_read_u32_array(np, "atmel,adc-res", resolutions, count)) { in at91_adc_of_get_resolution()
761 dev_err(&idev->dev, "Missing adc-res property in the DT.\n"); in at91_adc_of_get_resolution()
762 ret = -ENODEV; in at91_adc_of_get_resolution()
766 if (of_property_read_string(np, "atmel,adc-use-res", (const char **)&res_name)) in at91_adc_of_get_resolution()
770 if (of_property_read_string_index(np, "atmel,adc-res-names", i, (const char **)&s)) in at91_adc_of_get_resolution()
776 st->res = resolutions[i]; in at91_adc_of_get_resolution()
778 st->low_res = true; in at91_adc_of_get_resolution()
780 st->low_res = false; in at91_adc_of_get_resolution()
782 dev_info(&idev->dev, "Resolution used: %u bits\n", st->res); in at91_adc_of_get_resolution()
786 dev_err(&idev->dev, "There is no resolution for %s\n", res_name); in at91_adc_of_get_resolution()
801 return round_up((startup_time * adc_clk_khz / 1000) - 1, 8) / 8; in calc_startup_ticks_9260()
827 ticks = size - 1; in calc_startup_ticks_9x5()
840 ret = of_property_read_u32(node, "atmel,adc-ts-wires", &prop); in at91_adc_probe_dt_ts()
849 st->touchscreen_type = prop; in at91_adc_probe_dt_ts()
852 dev_err(dev, "Unsupported number of touchscreen wires (%d). Should be 4 or 5.\n", prop); in at91_adc_probe_dt_ts()
853 return -EINVAL; in at91_adc_probe_dt_ts()
856 if (!st->caps->has_tsmr) in at91_adc_probe_dt_ts()
859 of_property_read_u32(node, "atmel,adc-ts-pressure-threshold", &prop); in at91_adc_probe_dt_ts()
860 st->ts_pressure_threshold = prop; in at91_adc_probe_dt_ts()
861 if (st->ts_pressure_threshold) { in at91_adc_probe_dt_ts()
864 dev_err(dev, "Invalid pressure threshold for the touchscreen\n"); in at91_adc_probe_dt_ts()
865 return -EINVAL; in at91_adc_probe_dt_ts()
873 struct device_node *node = pdev->dev.of_node; in at91_adc_probe_dt()
879 return -EINVAL; in at91_adc_probe_dt()
881 st->caps = (struct at91_adc_caps *) in at91_adc_probe_dt()
882 of_match_device(at91_adc_dt_ids, &pdev->dev)->data; in at91_adc_probe_dt()
884 st->use_external = of_property_read_bool(node, "atmel,adc-use-external-triggers"); in at91_adc_probe_dt()
886 if (of_property_read_u32(node, "atmel,adc-channels-used", &prop)) { in at91_adc_probe_dt()
887 dev_err(&idev->dev, "Missing adc-channels-used property in the DT.\n"); in at91_adc_probe_dt()
888 ret = -EINVAL; in at91_adc_probe_dt()
891 st->channels_mask = prop; in at91_adc_probe_dt()
893 st->sleep_mode = of_property_read_bool(node, "atmel,adc-sleep-mode"); in at91_adc_probe_dt()
895 if (of_property_read_u32(node, "atmel,adc-startup-time", &prop)) { in at91_adc_probe_dt()
896 dev_err(&idev->dev, "Missing adc-startup-time property in the DT.\n"); in at91_adc_probe_dt()
897 ret = -EINVAL; in at91_adc_probe_dt()
900 st->startup_time = prop; in at91_adc_probe_dt()
903 of_property_read_u32(node, "atmel,adc-sample-hold-time", &prop); in at91_adc_probe_dt()
904 st->sample_hold_time = prop; in at91_adc_probe_dt()
906 if (of_property_read_u32(node, "atmel,adc-vref", &prop)) { in at91_adc_probe_dt()
907 dev_err(&idev->dev, "Missing adc-vref property in the DT.\n"); in at91_adc_probe_dt()
908 ret = -EINVAL; in at91_adc_probe_dt()
911 st->vref_mv = prop; in at91_adc_probe_dt()
917 st->registers = &st->caps->registers; in at91_adc_probe_dt()
918 st->num_channels = st->caps->num_channels; in at91_adc_probe_dt()
919 st->trigger_number = of_get_child_count(node); in at91_adc_probe_dt()
920 st->trigger_list = devm_kcalloc(&idev->dev, in at91_adc_probe_dt()
921 st->trigger_number, in at91_adc_probe_dt()
924 if (!st->trigger_list) { in at91_adc_probe_dt()
925 dev_err(&idev->dev, "Could not allocate trigger list memory.\n"); in at91_adc_probe_dt()
926 ret = -ENOMEM; in at91_adc_probe_dt()
931 struct at91_adc_trigger *trig = st->trigger_list + i; in at91_adc_probe_dt()
934 if (of_property_read_string(trig_node, "trigger-name", &name)) { in at91_adc_probe_dt()
935 dev_err(&idev->dev, "Missing trigger-name property in the DT.\n"); in at91_adc_probe_dt()
936 ret = -EINVAL; in at91_adc_probe_dt()
939 trig->name = name; in at91_adc_probe_dt()
941 if (of_property_read_u32(trig_node, "trigger-value", &prop)) { in at91_adc_probe_dt()
942 dev_err(&idev->dev, "Missing trigger-value property in the DT.\n"); in at91_adc_probe_dt()
943 ret = -EINVAL; in at91_adc_probe_dt()
946 trig->value = prop; in at91_adc_probe_dt()
947 trig->is_external = of_property_read_bool(trig_node, "trigger-external"); in at91_adc_probe_dt()
951 /* Check if touchscreen is supported. */ in at91_adc_probe_dt()
952 if (st->caps->has_ts) in at91_adc_probe_dt()
953 return at91_adc_probe_dt_ts(node, st, &idev->dev); in at91_adc_probe_dt()
955 dev_info(&idev->dev, "not support touchscreen in the adc compatible string.\n"); in at91_adc_probe_dt()
966 struct at91_adc_data *pdata = pdev->dev.platform_data; in at91_adc_probe_pdata()
969 return -EINVAL; in at91_adc_probe_pdata()
971 st->caps = (struct at91_adc_caps *) in at91_adc_probe_pdata()
972 platform_get_device_id(pdev)->driver_data; in at91_adc_probe_pdata()
974 st->use_external = pdata->use_external_triggers; in at91_adc_probe_pdata()
975 st->vref_mv = pdata->vref; in at91_adc_probe_pdata()
976 st->channels_mask = pdata->channels_used; in at91_adc_probe_pdata()
977 st->num_channels = st->caps->num_channels; in at91_adc_probe_pdata()
978 st->startup_time = pdata->startup_time; in at91_adc_probe_pdata()
979 st->trigger_number = pdata->trigger_number; in at91_adc_probe_pdata()
980 st->trigger_list = pdata->trigger_list; in at91_adc_probe_pdata()
981 st->registers = &st->caps->registers; in at91_adc_probe_pdata()
982 st->touchscreen_type = pdata->touchscreen_type; in at91_adc_probe_pdata()
991 /* Touchscreen related functions */
996 if (st->caps->has_tsmr) in atmel_ts_open()
1007 if (st->caps->has_tsmr) in atmel_ts_close()
1024 st->ts_pendbc = round_up(TOUCH_PEN_DETECT_DEBOUNCE_US * adc_clk_khz / in at91_ts_hw_init()
1027 while (st->ts_pendbc >> ++i) in at91_ts_hw_init()
1029 if (abs(st->ts_pendbc - (1 << i)) < abs(st->ts_pendbc - (1 << (i - 1)))) in at91_ts_hw_init()
1030 st->ts_pendbc = i; in at91_ts_hw_init()
1032 st->ts_pendbc = i - 1; in at91_ts_hw_init()
1034 if (!st->caps->has_tsmr) { in at91_ts_hw_init()
1038 reg |= AT91_ADC_PENDBC_(st->ts_pendbc) & AT91_ADC_PENDBC; in at91_ts_hw_init()
1044 st->ts_sample_period_val = round_up((TOUCH_SAMPLE_PERIOD_US_RL * in at91_ts_hw_init()
1045 adc_clk_khz / 1000) - 1, 1); in at91_ts_hw_init()
1050 /* Touchscreen Switches Closure time needed for allowing the value to in at91_ts_hw_init()
1055 dev_dbg(&idev->dev, "adc_clk at: %d KHz, tssctim at: %d\n", in at91_ts_hw_init()
1058 if (st->touchscreen_type == ATMEL_ADC_TOUCHSCREEN_4WIRE) in at91_ts_hw_init()
1064 reg |= AT91_ADC_TSMR_TSAV_(st->caps->ts_filter_average) in at91_ts_hw_init()
1066 reg |= AT91_ADC_TSMR_PENDBC_(st->ts_pendbc) & AT91_ADC_TSMR_PENDBC; in at91_ts_hw_init()
1078 at91_adc_writel(st, AT91_ADC_ACR, st->caps->ts_pen_detect_sensitivity in at91_ts_hw_init()
1082 st->ts_sample_period_val = round_up((TOUCH_SAMPLE_PERIOD_US * in at91_ts_hw_init()
1083 adc_clk_khz / 1000) - 1, 1); in at91_ts_hw_init()
1097 dev_err(&idev->dev, "Failed to allocate TS device!\n"); in at91_ts_register()
1098 return -ENOMEM; in at91_ts_register()
1101 input->name = DRIVER_NAME; in at91_ts_register()
1102 input->id.bustype = BUS_HOST; in at91_ts_register()
1103 input->dev.parent = &pdev->dev; in at91_ts_register()
1104 input->open = atmel_ts_open; in at91_ts_register()
1105 input->close = atmel_ts_close; in at91_ts_register()
1107 __set_bit(EV_ABS, input->evbit); in at91_ts_register()
1108 __set_bit(EV_KEY, input->evbit); in at91_ts_register()
1109 __set_bit(BTN_TOUCH, input->keybit); in at91_ts_register()
1110 if (st->caps->has_tsmr) { in at91_ts_register()
1111 input_set_abs_params(input, ABS_X, 0, (1 << MAX_POS_BITS) - 1, in at91_ts_register()
1113 input_set_abs_params(input, ABS_Y, 0, (1 << MAX_POS_BITS) - 1, in at91_ts_register()
1117 if (st->touchscreen_type != ATMEL_ADC_TOUCHSCREEN_4WIRE) { in at91_ts_register()
1118 dev_err(&pdev->dev, in at91_ts_register()
1119 "This touchscreen controller only support 4 wires\n"); in at91_ts_register()
1120 ret = -EINVAL; in at91_ts_register()
1124 input_set_abs_params(input, ABS_X, 0, (1 << MAX_RLPOS_BITS) - 1, in at91_ts_register()
1126 input_set_abs_params(input, ABS_Y, 0, (1 << MAX_RLPOS_BITS) - 1, in at91_ts_register()
1130 st->ts_input = input; in at91_ts_register()
1140 input_free_device(st->ts_input); in at91_ts_register()
1146 input_unregister_device(st->ts_input); in at91_ts_unregister()
1157 idev = devm_iio_device_alloc(&pdev->dev, sizeof(struct at91_adc_state)); in at91_adc_probe()
1159 return -ENOMEM; in at91_adc_probe()
1163 if (pdev->dev.of_node) in at91_adc_probe()
1169 dev_err(&pdev->dev, "No platform data available.\n"); in at91_adc_probe()
1170 return -EINVAL; in at91_adc_probe()
1175 idev->name = dev_name(&pdev->dev); in at91_adc_probe()
1176 idev->modes = INDIO_DIRECT_MODE; in at91_adc_probe()
1177 idev->info = &at91_adc_info; in at91_adc_probe()
1179 st->irq = platform_get_irq(pdev, 0); in at91_adc_probe()
1180 if (st->irq < 0) in at91_adc_probe()
1181 return -ENODEV; in at91_adc_probe()
1183 st->reg_base = devm_platform_ioremap_resource(pdev, 0); in at91_adc_probe()
1184 if (IS_ERR(st->reg_base)) in at91_adc_probe()
1185 return PTR_ERR(st->reg_base); in at91_adc_probe()
1194 if (st->caps->has_tsmr) in at91_adc_probe()
1195 ret = request_irq(st->irq, at91_adc_9x5_interrupt, 0, in at91_adc_probe()
1196 pdev->dev.driver->name, idev); in at91_adc_probe()
1198 ret = request_irq(st->irq, at91_adc_rl_interrupt, 0, in at91_adc_probe()
1199 pdev->dev.driver->name, idev); in at91_adc_probe()
1201 dev_err(&pdev->dev, "Failed to allocate IRQ.\n"); in at91_adc_probe()
1205 st->clk = devm_clk_get(&pdev->dev, "adc_clk"); in at91_adc_probe()
1206 if (IS_ERR(st->clk)) { in at91_adc_probe()
1207 dev_err(&pdev->dev, "Failed to get the clock.\n"); in at91_adc_probe()
1208 ret = PTR_ERR(st->clk); in at91_adc_probe()
1212 ret = clk_prepare_enable(st->clk); in at91_adc_probe()
1214 dev_err(&pdev->dev, in at91_adc_probe()
1219 st->adc_clk = devm_clk_get(&pdev->dev, "adc_op_clk"); in at91_adc_probe()
1220 if (IS_ERR(st->adc_clk)) { in at91_adc_probe()
1221 dev_err(&pdev->dev, "Failed to get the ADC clock.\n"); in at91_adc_probe()
1222 ret = PTR_ERR(st->adc_clk); in at91_adc_probe()
1226 ret = clk_prepare_enable(st->adc_clk); in at91_adc_probe()
1228 dev_err(&pdev->dev, in at91_adc_probe()
1238 mstrclk = clk_get_rate(st->clk); in at91_adc_probe()
1239 adc_clk = clk_get_rate(st->adc_clk); in at91_adc_probe()
1242 dev_dbg(&pdev->dev, "Master clock is set as: %d Hz, adc_clk should set as: %d Hz\n", in at91_adc_probe()
1245 prsc = (mstrclk / (2 * adc_clk)) - 1; in at91_adc_probe()
1247 if (!st->startup_time) { in at91_adc_probe()
1248 dev_err(&pdev->dev, "No startup time available.\n"); in at91_adc_probe()
1249 ret = -EINVAL; in at91_adc_probe()
1252 ticks = (*st->caps->calc_startup_ticks)(st->startup_time, adc_clk_khz); in at91_adc_probe()
1259 if (st->sample_hold_time > 0) in at91_adc_probe()
1260 shtim = round_up((st->sample_hold_time * adc_clk_khz / 1000) in at91_adc_probe()
1261 - 1, 1); in at91_adc_probe()
1265 reg = AT91_ADC_PRESCAL_(prsc) & st->registers->mr_prescal_mask; in at91_adc_probe()
1266 reg |= AT91_ADC_STARTUP_(ticks) & st->registers->mr_startup_mask; in at91_adc_probe()
1267 if (st->low_res) in at91_adc_probe()
1269 if (st->sleep_mode) in at91_adc_probe()
1277 dev_err(&pdev->dev, "Couldn't initialize the channels.\n"); in at91_adc_probe()
1281 init_waitqueue_head(&st->wq_data_avail); in at91_adc_probe()
1282 mutex_init(&st->lock); in at91_adc_probe()
1289 if (!st->touchscreen_type) { in at91_adc_probe()
1292 dev_err(&pdev->dev, "Couldn't initialize the buffer.\n"); in at91_adc_probe()
1298 dev_err(&pdev->dev, "Couldn't setup the triggers.\n"); in at91_adc_probe()
1312 dev_err(&pdev->dev, "Couldn't register the device.\n"); in at91_adc_probe()
1319 if (!st->touchscreen_type) { in at91_adc_probe()
1326 clk_disable_unprepare(st->adc_clk); in at91_adc_probe()
1328 clk_disable_unprepare(st->clk); in at91_adc_probe()
1330 free_irq(st->irq, idev); in at91_adc_probe()
1340 if (!st->touchscreen_type) { in at91_adc_remove()
1346 clk_disable_unprepare(st->adc_clk); in at91_adc_remove()
1347 clk_disable_unprepare(st->clk); in at91_adc_remove()
1348 free_irq(st->irq, idev); in at91_adc_remove()
1360 clk_disable_unprepare(st->clk); in at91_adc_suspend()
1370 clk_prepare_enable(st->clk); in at91_adc_resume()
1439 { .compatible = "atmel,at91sam9260-adc", .data = &at91sam9260_caps },
1440 { .compatible = "atmel,at91sam9rl-adc", .data = &at91sam9rl_caps },
1441 { .compatible = "atmel,at91sam9g45-adc", .data = &at91sam9g45_caps },
1442 { .compatible = "atmel,at91sam9x5-adc", .data = &at91sam9x5_caps },
1449 .name = "at91sam9260-adc",
1452 .name = "at91sam9rl-adc",
1455 .name = "at91sam9g45-adc",
1458 .name = "at91sam9x5-adc",
1481 MODULE_AUTHOR("Maxime Ripard <maxime.ripard@free-electrons.com>");