18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-or-later 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * Freescale MXS LRADC touchscreen driver 48c2ecf20Sopenharmony_ci * 58c2ecf20Sopenharmony_ci * Copyright (c) 2012 DENX Software Engineering, GmbH. 68c2ecf20Sopenharmony_ci * Copyright (c) 2017 Ksenija Stanojevic <ksenija.stanojevic@gmail.com> 78c2ecf20Sopenharmony_ci * 88c2ecf20Sopenharmony_ci * Authors: 98c2ecf20Sopenharmony_ci * Marek Vasut <marex@denx.de> 108c2ecf20Sopenharmony_ci * Ksenija Stanojevic <ksenija.stanojevic@gmail.com> 118c2ecf20Sopenharmony_ci */ 128c2ecf20Sopenharmony_ci 138c2ecf20Sopenharmony_ci#include <linux/device.h> 148c2ecf20Sopenharmony_ci#include <linux/err.h> 158c2ecf20Sopenharmony_ci#include <linux/input.h> 168c2ecf20Sopenharmony_ci#include <linux/interrupt.h> 178c2ecf20Sopenharmony_ci#include <linux/module.h> 188c2ecf20Sopenharmony_ci#include <linux/mfd/core.h> 198c2ecf20Sopenharmony_ci#include <linux/mfd/mxs-lradc.h> 208c2ecf20Sopenharmony_ci#include <linux/of.h> 218c2ecf20Sopenharmony_ci#include <linux/of_irq.h> 228c2ecf20Sopenharmony_ci#include <linux/platform_device.h> 238c2ecf20Sopenharmony_ci 248c2ecf20Sopenharmony_cistatic const char * const mxs_lradc_ts_irq_names[] = { 258c2ecf20Sopenharmony_ci "mxs-lradc-touchscreen", 268c2ecf20Sopenharmony_ci "mxs-lradc-channel6", 278c2ecf20Sopenharmony_ci "mxs-lradc-channel7", 288c2ecf20Sopenharmony_ci}; 298c2ecf20Sopenharmony_ci 308c2ecf20Sopenharmony_ci/* 318c2ecf20Sopenharmony_ci * Touchscreen handling 328c2ecf20Sopenharmony_ci */ 338c2ecf20Sopenharmony_cienum mxs_lradc_ts_plate { 348c2ecf20Sopenharmony_ci LRADC_TOUCH = 0, 358c2ecf20Sopenharmony_ci LRADC_SAMPLE_X, 368c2ecf20Sopenharmony_ci LRADC_SAMPLE_Y, 378c2ecf20Sopenharmony_ci LRADC_SAMPLE_PRESSURE, 388c2ecf20Sopenharmony_ci LRADC_SAMPLE_VALID, 398c2ecf20Sopenharmony_ci}; 408c2ecf20Sopenharmony_ci 418c2ecf20Sopenharmony_cistruct mxs_lradc_ts { 428c2ecf20Sopenharmony_ci struct mxs_lradc *lradc; 438c2ecf20Sopenharmony_ci struct device *dev; 448c2ecf20Sopenharmony_ci 458c2ecf20Sopenharmony_ci void __iomem *base; 468c2ecf20Sopenharmony_ci /* 478c2ecf20Sopenharmony_ci * When the touchscreen is enabled, we give it two private virtual 488c2ecf20Sopenharmony_ci * channels: #6 and #7. This means that only 6 virtual channels (instead 498c2ecf20Sopenharmony_ci * of 8) will be available for buffered capture. 508c2ecf20Sopenharmony_ci */ 518c2ecf20Sopenharmony_ci#define TOUCHSCREEN_VCHANNEL1 7 528c2ecf20Sopenharmony_ci#define TOUCHSCREEN_VCHANNEL2 6 538c2ecf20Sopenharmony_ci 548c2ecf20Sopenharmony_ci struct input_dev *ts_input; 558c2ecf20Sopenharmony_ci 568c2ecf20Sopenharmony_ci enum mxs_lradc_ts_plate cur_plate; /* state machine */ 578c2ecf20Sopenharmony_ci bool ts_valid; 588c2ecf20Sopenharmony_ci unsigned int ts_x_pos; 598c2ecf20Sopenharmony_ci unsigned int ts_y_pos; 608c2ecf20Sopenharmony_ci unsigned int ts_pressure; 618c2ecf20Sopenharmony_ci 628c2ecf20Sopenharmony_ci /* handle touchscreen's physical behaviour */ 638c2ecf20Sopenharmony_ci /* samples per coordinate */ 648c2ecf20Sopenharmony_ci unsigned int over_sample_cnt; 658c2ecf20Sopenharmony_ci /* time clocks between samples */ 668c2ecf20Sopenharmony_ci unsigned int over_sample_delay; 678c2ecf20Sopenharmony_ci /* time in clocks to wait after the plates where switched */ 688c2ecf20Sopenharmony_ci unsigned int settling_delay; 698c2ecf20Sopenharmony_ci spinlock_t lock; 708c2ecf20Sopenharmony_ci}; 718c2ecf20Sopenharmony_ci 728c2ecf20Sopenharmony_cistruct state_info { 738c2ecf20Sopenharmony_ci u32 mask; 748c2ecf20Sopenharmony_ci u32 bit; 758c2ecf20Sopenharmony_ci u32 x_plate; 768c2ecf20Sopenharmony_ci u32 y_plate; 778c2ecf20Sopenharmony_ci u32 pressure; 788c2ecf20Sopenharmony_ci}; 798c2ecf20Sopenharmony_ci 808c2ecf20Sopenharmony_cistatic struct state_info info[] = { 818c2ecf20Sopenharmony_ci {LRADC_CTRL0_MX23_PLATE_MASK, LRADC_CTRL0_MX23_TOUCH_DETECT_ENABLE, 828c2ecf20Sopenharmony_ci LRADC_CTRL0_MX23_XP | LRADC_CTRL0_MX23_XM, 838c2ecf20Sopenharmony_ci LRADC_CTRL0_MX23_YP | LRADC_CTRL0_MX23_YM, 848c2ecf20Sopenharmony_ci LRADC_CTRL0_MX23_YP | LRADC_CTRL0_MX23_XM}, 858c2ecf20Sopenharmony_ci {LRADC_CTRL0_MX28_PLATE_MASK, LRADC_CTRL0_MX28_TOUCH_DETECT_ENABLE, 868c2ecf20Sopenharmony_ci LRADC_CTRL0_MX28_XPPSW | LRADC_CTRL0_MX28_XNNSW, 878c2ecf20Sopenharmony_ci LRADC_CTRL0_MX28_YPPSW | LRADC_CTRL0_MX28_YNNSW, 888c2ecf20Sopenharmony_ci LRADC_CTRL0_MX28_YPPSW | LRADC_CTRL0_MX28_XNNSW} 898c2ecf20Sopenharmony_ci}; 908c2ecf20Sopenharmony_ci 918c2ecf20Sopenharmony_cistatic bool mxs_lradc_check_touch_event(struct mxs_lradc_ts *ts) 928c2ecf20Sopenharmony_ci{ 938c2ecf20Sopenharmony_ci return !!(readl(ts->base + LRADC_STATUS) & 948c2ecf20Sopenharmony_ci LRADC_STATUS_TOUCH_DETECT_RAW); 958c2ecf20Sopenharmony_ci} 968c2ecf20Sopenharmony_ci 978c2ecf20Sopenharmony_cistatic void mxs_lradc_map_ts_channel(struct mxs_lradc_ts *ts, unsigned int vch, 988c2ecf20Sopenharmony_ci unsigned int ch) 998c2ecf20Sopenharmony_ci{ 1008c2ecf20Sopenharmony_ci writel(LRADC_CTRL4_LRADCSELECT_MASK(vch), 1018c2ecf20Sopenharmony_ci ts->base + LRADC_CTRL4 + STMP_OFFSET_REG_CLR); 1028c2ecf20Sopenharmony_ci writel(LRADC_CTRL4_LRADCSELECT(vch, ch), 1038c2ecf20Sopenharmony_ci ts->base + LRADC_CTRL4 + STMP_OFFSET_REG_SET); 1048c2ecf20Sopenharmony_ci} 1058c2ecf20Sopenharmony_ci 1068c2ecf20Sopenharmony_cistatic void mxs_lradc_setup_ts_channel(struct mxs_lradc_ts *ts, unsigned int ch) 1078c2ecf20Sopenharmony_ci{ 1088c2ecf20Sopenharmony_ci /* 1098c2ecf20Sopenharmony_ci * prepare for oversampling conversion 1108c2ecf20Sopenharmony_ci * 1118c2ecf20Sopenharmony_ci * from the datasheet: 1128c2ecf20Sopenharmony_ci * "The ACCUMULATE bit in the appropriate channel register 1138c2ecf20Sopenharmony_ci * HW_LRADC_CHn must be set to 1 if NUM_SAMPLES is greater then 0; 1148c2ecf20Sopenharmony_ci * otherwise, the IRQs will not fire." 1158c2ecf20Sopenharmony_ci */ 1168c2ecf20Sopenharmony_ci writel(LRADC_CH_ACCUMULATE | 1178c2ecf20Sopenharmony_ci LRADC_CH_NUM_SAMPLES(ts->over_sample_cnt - 1), 1188c2ecf20Sopenharmony_ci ts->base + LRADC_CH(ch)); 1198c2ecf20Sopenharmony_ci 1208c2ecf20Sopenharmony_ci /* from the datasheet: 1218c2ecf20Sopenharmony_ci * "Software must clear this register in preparation for a 1228c2ecf20Sopenharmony_ci * multi-cycle accumulation. 1238c2ecf20Sopenharmony_ci */ 1248c2ecf20Sopenharmony_ci writel(LRADC_CH_VALUE_MASK, 1258c2ecf20Sopenharmony_ci ts->base + LRADC_CH(ch) + STMP_OFFSET_REG_CLR); 1268c2ecf20Sopenharmony_ci 1278c2ecf20Sopenharmony_ci /* 1288c2ecf20Sopenharmony_ci * prepare the delay/loop unit according to the oversampling count 1298c2ecf20Sopenharmony_ci * 1308c2ecf20Sopenharmony_ci * from the datasheet: 1318c2ecf20Sopenharmony_ci * "The DELAY fields in HW_LRADC_DELAY0, HW_LRADC_DELAY1, 1328c2ecf20Sopenharmony_ci * HW_LRADC_DELAY2, and HW_LRADC_DELAY3 must be non-zero; otherwise, 1338c2ecf20Sopenharmony_ci * the LRADC will not trigger the delay group." 1348c2ecf20Sopenharmony_ci */ 1358c2ecf20Sopenharmony_ci writel(LRADC_DELAY_TRIGGER(1 << ch) | LRADC_DELAY_TRIGGER_DELAYS(0) | 1368c2ecf20Sopenharmony_ci LRADC_DELAY_LOOP(ts->over_sample_cnt - 1) | 1378c2ecf20Sopenharmony_ci LRADC_DELAY_DELAY(ts->over_sample_delay - 1), 1388c2ecf20Sopenharmony_ci ts->base + LRADC_DELAY(3)); 1398c2ecf20Sopenharmony_ci 1408c2ecf20Sopenharmony_ci writel(LRADC_CTRL1_LRADC_IRQ(ch), 1418c2ecf20Sopenharmony_ci ts->base + LRADC_CTRL1 + STMP_OFFSET_REG_CLR); 1428c2ecf20Sopenharmony_ci 1438c2ecf20Sopenharmony_ci /* 1448c2ecf20Sopenharmony_ci * after changing the touchscreen plates setting 1458c2ecf20Sopenharmony_ci * the signals need some initial time to settle. Start the 1468c2ecf20Sopenharmony_ci * SoC's delay unit and start the conversion later 1478c2ecf20Sopenharmony_ci * and automatically. 1488c2ecf20Sopenharmony_ci */ 1498c2ecf20Sopenharmony_ci writel(LRADC_DELAY_TRIGGER(0) | LRADC_DELAY_TRIGGER_DELAYS(BIT(3)) | 1508c2ecf20Sopenharmony_ci LRADC_DELAY_KICK | LRADC_DELAY_DELAY(ts->settling_delay), 1518c2ecf20Sopenharmony_ci ts->base + LRADC_DELAY(2)); 1528c2ecf20Sopenharmony_ci} 1538c2ecf20Sopenharmony_ci 1548c2ecf20Sopenharmony_ci/* 1558c2ecf20Sopenharmony_ci * Pressure detection is special: 1568c2ecf20Sopenharmony_ci * We want to do both required measurements for the pressure detection in 1578c2ecf20Sopenharmony_ci * one turn. Use the hardware features to chain both conversions and let the 1588c2ecf20Sopenharmony_ci * hardware report one interrupt if both conversions are done 1598c2ecf20Sopenharmony_ci */ 1608c2ecf20Sopenharmony_cistatic void mxs_lradc_setup_ts_pressure(struct mxs_lradc_ts *ts, 1618c2ecf20Sopenharmony_ci unsigned int ch1, unsigned int ch2) 1628c2ecf20Sopenharmony_ci{ 1638c2ecf20Sopenharmony_ci u32 reg; 1648c2ecf20Sopenharmony_ci 1658c2ecf20Sopenharmony_ci /* 1668c2ecf20Sopenharmony_ci * prepare for oversampling conversion 1678c2ecf20Sopenharmony_ci * 1688c2ecf20Sopenharmony_ci * from the datasheet: 1698c2ecf20Sopenharmony_ci * "The ACCUMULATE bit in the appropriate channel register 1708c2ecf20Sopenharmony_ci * HW_LRADC_CHn must be set to 1 if NUM_SAMPLES is greater then 0; 1718c2ecf20Sopenharmony_ci * otherwise, the IRQs will not fire." 1728c2ecf20Sopenharmony_ci */ 1738c2ecf20Sopenharmony_ci reg = LRADC_CH_ACCUMULATE | 1748c2ecf20Sopenharmony_ci LRADC_CH_NUM_SAMPLES(ts->over_sample_cnt - 1); 1758c2ecf20Sopenharmony_ci writel(reg, ts->base + LRADC_CH(ch1)); 1768c2ecf20Sopenharmony_ci writel(reg, ts->base + LRADC_CH(ch2)); 1778c2ecf20Sopenharmony_ci 1788c2ecf20Sopenharmony_ci /* from the datasheet: 1798c2ecf20Sopenharmony_ci * "Software must clear this register in preparation for a 1808c2ecf20Sopenharmony_ci * multi-cycle accumulation. 1818c2ecf20Sopenharmony_ci */ 1828c2ecf20Sopenharmony_ci writel(LRADC_CH_VALUE_MASK, 1838c2ecf20Sopenharmony_ci ts->base + LRADC_CH(ch1) + STMP_OFFSET_REG_CLR); 1848c2ecf20Sopenharmony_ci writel(LRADC_CH_VALUE_MASK, 1858c2ecf20Sopenharmony_ci ts->base + LRADC_CH(ch2) + STMP_OFFSET_REG_CLR); 1868c2ecf20Sopenharmony_ci 1878c2ecf20Sopenharmony_ci /* prepare the delay/loop unit according to the oversampling count */ 1888c2ecf20Sopenharmony_ci writel(LRADC_DELAY_TRIGGER(1 << ch1) | LRADC_DELAY_TRIGGER(1 << ch2) | 1898c2ecf20Sopenharmony_ci LRADC_DELAY_TRIGGER_DELAYS(0) | 1908c2ecf20Sopenharmony_ci LRADC_DELAY_LOOP(ts->over_sample_cnt - 1) | 1918c2ecf20Sopenharmony_ci LRADC_DELAY_DELAY(ts->over_sample_delay - 1), 1928c2ecf20Sopenharmony_ci ts->base + LRADC_DELAY(3)); 1938c2ecf20Sopenharmony_ci 1948c2ecf20Sopenharmony_ci writel(LRADC_CTRL1_LRADC_IRQ(ch2), 1958c2ecf20Sopenharmony_ci ts->base + LRADC_CTRL1 + STMP_OFFSET_REG_CLR); 1968c2ecf20Sopenharmony_ci 1978c2ecf20Sopenharmony_ci /* 1988c2ecf20Sopenharmony_ci * after changing the touchscreen plates setting 1998c2ecf20Sopenharmony_ci * the signals need some initial time to settle. Start the 2008c2ecf20Sopenharmony_ci * SoC's delay unit and start the conversion later 2018c2ecf20Sopenharmony_ci * and automatically. 2028c2ecf20Sopenharmony_ci */ 2038c2ecf20Sopenharmony_ci writel(LRADC_DELAY_TRIGGER(0) | LRADC_DELAY_TRIGGER_DELAYS(BIT(3)) | 2048c2ecf20Sopenharmony_ci LRADC_DELAY_KICK | LRADC_DELAY_DELAY(ts->settling_delay), 2058c2ecf20Sopenharmony_ci ts->base + LRADC_DELAY(2)); 2068c2ecf20Sopenharmony_ci} 2078c2ecf20Sopenharmony_ci 2088c2ecf20Sopenharmony_cistatic unsigned int mxs_lradc_ts_read_raw_channel(struct mxs_lradc_ts *ts, 2098c2ecf20Sopenharmony_ci unsigned int channel) 2108c2ecf20Sopenharmony_ci{ 2118c2ecf20Sopenharmony_ci u32 reg; 2128c2ecf20Sopenharmony_ci unsigned int num_samples, val; 2138c2ecf20Sopenharmony_ci 2148c2ecf20Sopenharmony_ci reg = readl(ts->base + LRADC_CH(channel)); 2158c2ecf20Sopenharmony_ci if (reg & LRADC_CH_ACCUMULATE) 2168c2ecf20Sopenharmony_ci num_samples = ts->over_sample_cnt; 2178c2ecf20Sopenharmony_ci else 2188c2ecf20Sopenharmony_ci num_samples = 1; 2198c2ecf20Sopenharmony_ci 2208c2ecf20Sopenharmony_ci val = (reg & LRADC_CH_VALUE_MASK) >> LRADC_CH_VALUE_OFFSET; 2218c2ecf20Sopenharmony_ci return val / num_samples; 2228c2ecf20Sopenharmony_ci} 2238c2ecf20Sopenharmony_ci 2248c2ecf20Sopenharmony_cistatic unsigned int mxs_lradc_read_ts_pressure(struct mxs_lradc_ts *ts, 2258c2ecf20Sopenharmony_ci unsigned int ch1, unsigned int ch2) 2268c2ecf20Sopenharmony_ci{ 2278c2ecf20Sopenharmony_ci u32 reg, mask; 2288c2ecf20Sopenharmony_ci unsigned int pressure, m1, m2; 2298c2ecf20Sopenharmony_ci 2308c2ecf20Sopenharmony_ci mask = LRADC_CTRL1_LRADC_IRQ(ch1) | LRADC_CTRL1_LRADC_IRQ(ch2); 2318c2ecf20Sopenharmony_ci reg = readl(ts->base + LRADC_CTRL1) & mask; 2328c2ecf20Sopenharmony_ci 2338c2ecf20Sopenharmony_ci while (reg != mask) { 2348c2ecf20Sopenharmony_ci reg = readl(ts->base + LRADC_CTRL1) & mask; 2358c2ecf20Sopenharmony_ci dev_dbg(ts->dev, "One channel is still busy: %X\n", reg); 2368c2ecf20Sopenharmony_ci } 2378c2ecf20Sopenharmony_ci 2388c2ecf20Sopenharmony_ci m1 = mxs_lradc_ts_read_raw_channel(ts, ch1); 2398c2ecf20Sopenharmony_ci m2 = mxs_lradc_ts_read_raw_channel(ts, ch2); 2408c2ecf20Sopenharmony_ci 2418c2ecf20Sopenharmony_ci if (m2 == 0) { 2428c2ecf20Sopenharmony_ci dev_warn(ts->dev, "Cannot calculate pressure\n"); 2438c2ecf20Sopenharmony_ci return 1 << (LRADC_RESOLUTION - 1); 2448c2ecf20Sopenharmony_ci } 2458c2ecf20Sopenharmony_ci 2468c2ecf20Sopenharmony_ci /* simply scale the value from 0 ... max ADC resolution */ 2478c2ecf20Sopenharmony_ci pressure = m1; 2488c2ecf20Sopenharmony_ci pressure *= (1 << LRADC_RESOLUTION); 2498c2ecf20Sopenharmony_ci pressure /= m2; 2508c2ecf20Sopenharmony_ci 2518c2ecf20Sopenharmony_ci dev_dbg(ts->dev, "Pressure = %u\n", pressure); 2528c2ecf20Sopenharmony_ci return pressure; 2538c2ecf20Sopenharmony_ci} 2548c2ecf20Sopenharmony_ci 2558c2ecf20Sopenharmony_ci#define TS_CH_XP 2 2568c2ecf20Sopenharmony_ci#define TS_CH_YP 3 2578c2ecf20Sopenharmony_ci#define TS_CH_XM 4 2588c2ecf20Sopenharmony_ci#define TS_CH_YM 5 2598c2ecf20Sopenharmony_ci 2608c2ecf20Sopenharmony_ci/* 2618c2ecf20Sopenharmony_ci * YP(open)--+-------------+ 2628c2ecf20Sopenharmony_ci * | |--+ 2638c2ecf20Sopenharmony_ci * | | | 2648c2ecf20Sopenharmony_ci * YM(-)--+-------------+ | 2658c2ecf20Sopenharmony_ci * +--------------+ 2668c2ecf20Sopenharmony_ci * | | 2678c2ecf20Sopenharmony_ci * XP(weak+) XM(open) 2688c2ecf20Sopenharmony_ci * 2698c2ecf20Sopenharmony_ci * "weak+" means 200k Ohm VDDIO 2708c2ecf20Sopenharmony_ci * (-) means GND 2718c2ecf20Sopenharmony_ci */ 2728c2ecf20Sopenharmony_cistatic void mxs_lradc_setup_touch_detection(struct mxs_lradc_ts *ts) 2738c2ecf20Sopenharmony_ci{ 2748c2ecf20Sopenharmony_ci struct mxs_lradc *lradc = ts->lradc; 2758c2ecf20Sopenharmony_ci 2768c2ecf20Sopenharmony_ci /* 2778c2ecf20Sopenharmony_ci * In order to detect a touch event the 'touch detect enable' bit 2788c2ecf20Sopenharmony_ci * enables: 2798c2ecf20Sopenharmony_ci * - a weak pullup to the X+ connector 2808c2ecf20Sopenharmony_ci * - a strong ground at the Y- connector 2818c2ecf20Sopenharmony_ci */ 2828c2ecf20Sopenharmony_ci writel(info[lradc->soc].mask, 2838c2ecf20Sopenharmony_ci ts->base + LRADC_CTRL0 + STMP_OFFSET_REG_CLR); 2848c2ecf20Sopenharmony_ci writel(info[lradc->soc].bit, 2858c2ecf20Sopenharmony_ci ts->base + LRADC_CTRL0 + STMP_OFFSET_REG_SET); 2868c2ecf20Sopenharmony_ci} 2878c2ecf20Sopenharmony_ci 2888c2ecf20Sopenharmony_ci/* 2898c2ecf20Sopenharmony_ci * YP(meas)--+-------------+ 2908c2ecf20Sopenharmony_ci * | |--+ 2918c2ecf20Sopenharmony_ci * | | | 2928c2ecf20Sopenharmony_ci * YM(open)--+-------------+ | 2938c2ecf20Sopenharmony_ci * +--------------+ 2948c2ecf20Sopenharmony_ci * | | 2958c2ecf20Sopenharmony_ci * XP(+) XM(-) 2968c2ecf20Sopenharmony_ci * 2978c2ecf20Sopenharmony_ci * (+) means here 1.85 V 2988c2ecf20Sopenharmony_ci * (-) means here GND 2998c2ecf20Sopenharmony_ci */ 3008c2ecf20Sopenharmony_cistatic void mxs_lradc_prepare_x_pos(struct mxs_lradc_ts *ts) 3018c2ecf20Sopenharmony_ci{ 3028c2ecf20Sopenharmony_ci struct mxs_lradc *lradc = ts->lradc; 3038c2ecf20Sopenharmony_ci 3048c2ecf20Sopenharmony_ci writel(info[lradc->soc].mask, 3058c2ecf20Sopenharmony_ci ts->base + LRADC_CTRL0 + STMP_OFFSET_REG_CLR); 3068c2ecf20Sopenharmony_ci writel(info[lradc->soc].x_plate, 3078c2ecf20Sopenharmony_ci ts->base + LRADC_CTRL0 + STMP_OFFSET_REG_SET); 3088c2ecf20Sopenharmony_ci 3098c2ecf20Sopenharmony_ci ts->cur_plate = LRADC_SAMPLE_X; 3108c2ecf20Sopenharmony_ci mxs_lradc_map_ts_channel(ts, TOUCHSCREEN_VCHANNEL1, TS_CH_YP); 3118c2ecf20Sopenharmony_ci mxs_lradc_setup_ts_channel(ts, TOUCHSCREEN_VCHANNEL1); 3128c2ecf20Sopenharmony_ci} 3138c2ecf20Sopenharmony_ci 3148c2ecf20Sopenharmony_ci/* 3158c2ecf20Sopenharmony_ci * YP(+)--+-------------+ 3168c2ecf20Sopenharmony_ci * | |--+ 3178c2ecf20Sopenharmony_ci * | | | 3188c2ecf20Sopenharmony_ci * YM(-)--+-------------+ | 3198c2ecf20Sopenharmony_ci * +--------------+ 3208c2ecf20Sopenharmony_ci * | | 3218c2ecf20Sopenharmony_ci * XP(open) XM(meas) 3228c2ecf20Sopenharmony_ci * 3238c2ecf20Sopenharmony_ci * (+) means here 1.85 V 3248c2ecf20Sopenharmony_ci * (-) means here GND 3258c2ecf20Sopenharmony_ci */ 3268c2ecf20Sopenharmony_cistatic void mxs_lradc_prepare_y_pos(struct mxs_lradc_ts *ts) 3278c2ecf20Sopenharmony_ci{ 3288c2ecf20Sopenharmony_ci struct mxs_lradc *lradc = ts->lradc; 3298c2ecf20Sopenharmony_ci 3308c2ecf20Sopenharmony_ci writel(info[lradc->soc].mask, 3318c2ecf20Sopenharmony_ci ts->base + LRADC_CTRL0 + STMP_OFFSET_REG_CLR); 3328c2ecf20Sopenharmony_ci writel(info[lradc->soc].y_plate, 3338c2ecf20Sopenharmony_ci ts->base + LRADC_CTRL0 + STMP_OFFSET_REG_SET); 3348c2ecf20Sopenharmony_ci 3358c2ecf20Sopenharmony_ci ts->cur_plate = LRADC_SAMPLE_Y; 3368c2ecf20Sopenharmony_ci mxs_lradc_map_ts_channel(ts, TOUCHSCREEN_VCHANNEL1, TS_CH_XM); 3378c2ecf20Sopenharmony_ci mxs_lradc_setup_ts_channel(ts, TOUCHSCREEN_VCHANNEL1); 3388c2ecf20Sopenharmony_ci} 3398c2ecf20Sopenharmony_ci 3408c2ecf20Sopenharmony_ci/* 3418c2ecf20Sopenharmony_ci * YP(+)--+-------------+ 3428c2ecf20Sopenharmony_ci * | |--+ 3438c2ecf20Sopenharmony_ci * | | | 3448c2ecf20Sopenharmony_ci * YM(meas)--+-------------+ | 3458c2ecf20Sopenharmony_ci * +--------------+ 3468c2ecf20Sopenharmony_ci * | | 3478c2ecf20Sopenharmony_ci * XP(meas) XM(-) 3488c2ecf20Sopenharmony_ci * 3498c2ecf20Sopenharmony_ci * (+) means here 1.85 V 3508c2ecf20Sopenharmony_ci * (-) means here GND 3518c2ecf20Sopenharmony_ci */ 3528c2ecf20Sopenharmony_cistatic void mxs_lradc_prepare_pressure(struct mxs_lradc_ts *ts) 3538c2ecf20Sopenharmony_ci{ 3548c2ecf20Sopenharmony_ci struct mxs_lradc *lradc = ts->lradc; 3558c2ecf20Sopenharmony_ci 3568c2ecf20Sopenharmony_ci writel(info[lradc->soc].mask, 3578c2ecf20Sopenharmony_ci ts->base + LRADC_CTRL0 + STMP_OFFSET_REG_CLR); 3588c2ecf20Sopenharmony_ci writel(info[lradc->soc].pressure, 3598c2ecf20Sopenharmony_ci ts->base + LRADC_CTRL0 + STMP_OFFSET_REG_SET); 3608c2ecf20Sopenharmony_ci 3618c2ecf20Sopenharmony_ci ts->cur_plate = LRADC_SAMPLE_PRESSURE; 3628c2ecf20Sopenharmony_ci mxs_lradc_map_ts_channel(ts, TOUCHSCREEN_VCHANNEL1, TS_CH_YM); 3638c2ecf20Sopenharmony_ci mxs_lradc_map_ts_channel(ts, TOUCHSCREEN_VCHANNEL2, TS_CH_XP); 3648c2ecf20Sopenharmony_ci mxs_lradc_setup_ts_pressure(ts, TOUCHSCREEN_VCHANNEL2, 3658c2ecf20Sopenharmony_ci TOUCHSCREEN_VCHANNEL1); 3668c2ecf20Sopenharmony_ci} 3678c2ecf20Sopenharmony_ci 3688c2ecf20Sopenharmony_cistatic void mxs_lradc_enable_touch_detection(struct mxs_lradc_ts *ts) 3698c2ecf20Sopenharmony_ci{ 3708c2ecf20Sopenharmony_ci mxs_lradc_setup_touch_detection(ts); 3718c2ecf20Sopenharmony_ci 3728c2ecf20Sopenharmony_ci ts->cur_plate = LRADC_TOUCH; 3738c2ecf20Sopenharmony_ci writel(LRADC_CTRL1_TOUCH_DETECT_IRQ | LRADC_CTRL1_TOUCH_DETECT_IRQ_EN, 3748c2ecf20Sopenharmony_ci ts->base + LRADC_CTRL1 + STMP_OFFSET_REG_CLR); 3758c2ecf20Sopenharmony_ci writel(LRADC_CTRL1_TOUCH_DETECT_IRQ_EN, 3768c2ecf20Sopenharmony_ci ts->base + LRADC_CTRL1 + STMP_OFFSET_REG_SET); 3778c2ecf20Sopenharmony_ci} 3788c2ecf20Sopenharmony_ci 3798c2ecf20Sopenharmony_cistatic void mxs_lradc_start_touch_event(struct mxs_lradc_ts *ts) 3808c2ecf20Sopenharmony_ci{ 3818c2ecf20Sopenharmony_ci writel(LRADC_CTRL1_TOUCH_DETECT_IRQ_EN, 3828c2ecf20Sopenharmony_ci ts->base + LRADC_CTRL1 + STMP_OFFSET_REG_CLR); 3838c2ecf20Sopenharmony_ci writel(LRADC_CTRL1_LRADC_IRQ_EN(TOUCHSCREEN_VCHANNEL1), 3848c2ecf20Sopenharmony_ci ts->base + LRADC_CTRL1 + STMP_OFFSET_REG_SET); 3858c2ecf20Sopenharmony_ci /* 3868c2ecf20Sopenharmony_ci * start with the Y-pos, because it uses nearly the same plate 3878c2ecf20Sopenharmony_ci * settings like the touch detection 3888c2ecf20Sopenharmony_ci */ 3898c2ecf20Sopenharmony_ci mxs_lradc_prepare_y_pos(ts); 3908c2ecf20Sopenharmony_ci} 3918c2ecf20Sopenharmony_ci 3928c2ecf20Sopenharmony_cistatic void mxs_lradc_report_ts_event(struct mxs_lradc_ts *ts) 3938c2ecf20Sopenharmony_ci{ 3948c2ecf20Sopenharmony_ci input_report_abs(ts->ts_input, ABS_X, ts->ts_x_pos); 3958c2ecf20Sopenharmony_ci input_report_abs(ts->ts_input, ABS_Y, ts->ts_y_pos); 3968c2ecf20Sopenharmony_ci input_report_abs(ts->ts_input, ABS_PRESSURE, ts->ts_pressure); 3978c2ecf20Sopenharmony_ci input_report_key(ts->ts_input, BTN_TOUCH, 1); 3988c2ecf20Sopenharmony_ci input_sync(ts->ts_input); 3998c2ecf20Sopenharmony_ci} 4008c2ecf20Sopenharmony_ci 4018c2ecf20Sopenharmony_cistatic void mxs_lradc_complete_touch_event(struct mxs_lradc_ts *ts) 4028c2ecf20Sopenharmony_ci{ 4038c2ecf20Sopenharmony_ci mxs_lradc_setup_touch_detection(ts); 4048c2ecf20Sopenharmony_ci ts->cur_plate = LRADC_SAMPLE_VALID; 4058c2ecf20Sopenharmony_ci /* 4068c2ecf20Sopenharmony_ci * start a dummy conversion to burn time to settle the signals 4078c2ecf20Sopenharmony_ci * note: we are not interested in the conversion's value 4088c2ecf20Sopenharmony_ci */ 4098c2ecf20Sopenharmony_ci writel(0, ts->base + LRADC_CH(TOUCHSCREEN_VCHANNEL1)); 4108c2ecf20Sopenharmony_ci writel(LRADC_CTRL1_LRADC_IRQ(TOUCHSCREEN_VCHANNEL1) | 4118c2ecf20Sopenharmony_ci LRADC_CTRL1_LRADC_IRQ(TOUCHSCREEN_VCHANNEL2), 4128c2ecf20Sopenharmony_ci ts->base + LRADC_CTRL1 + STMP_OFFSET_REG_CLR); 4138c2ecf20Sopenharmony_ci writel(LRADC_DELAY_TRIGGER(1 << TOUCHSCREEN_VCHANNEL1) | 4148c2ecf20Sopenharmony_ci LRADC_DELAY_KICK | LRADC_DELAY_DELAY(10), 4158c2ecf20Sopenharmony_ci ts->base + LRADC_DELAY(2)); 4168c2ecf20Sopenharmony_ci} 4178c2ecf20Sopenharmony_ci 4188c2ecf20Sopenharmony_ci/* 4198c2ecf20Sopenharmony_ci * in order to avoid false measurements, report only samples where 4208c2ecf20Sopenharmony_ci * the surface is still touched after the position measurement 4218c2ecf20Sopenharmony_ci */ 4228c2ecf20Sopenharmony_cistatic void mxs_lradc_finish_touch_event(struct mxs_lradc_ts *ts, bool valid) 4238c2ecf20Sopenharmony_ci{ 4248c2ecf20Sopenharmony_ci /* if it is still touched, report the sample */ 4258c2ecf20Sopenharmony_ci if (valid && mxs_lradc_check_touch_event(ts)) { 4268c2ecf20Sopenharmony_ci ts->ts_valid = true; 4278c2ecf20Sopenharmony_ci mxs_lradc_report_ts_event(ts); 4288c2ecf20Sopenharmony_ci } 4298c2ecf20Sopenharmony_ci 4308c2ecf20Sopenharmony_ci /* if it is even still touched, continue with the next measurement */ 4318c2ecf20Sopenharmony_ci if (mxs_lradc_check_touch_event(ts)) { 4328c2ecf20Sopenharmony_ci mxs_lradc_prepare_y_pos(ts); 4338c2ecf20Sopenharmony_ci return; 4348c2ecf20Sopenharmony_ci } 4358c2ecf20Sopenharmony_ci 4368c2ecf20Sopenharmony_ci if (ts->ts_valid) { 4378c2ecf20Sopenharmony_ci /* signal the release */ 4388c2ecf20Sopenharmony_ci ts->ts_valid = false; 4398c2ecf20Sopenharmony_ci input_report_key(ts->ts_input, BTN_TOUCH, 0); 4408c2ecf20Sopenharmony_ci input_sync(ts->ts_input); 4418c2ecf20Sopenharmony_ci } 4428c2ecf20Sopenharmony_ci 4438c2ecf20Sopenharmony_ci /* if it is released, wait for the next touch via IRQ */ 4448c2ecf20Sopenharmony_ci ts->cur_plate = LRADC_TOUCH; 4458c2ecf20Sopenharmony_ci writel(0, ts->base + LRADC_DELAY(2)); 4468c2ecf20Sopenharmony_ci writel(0, ts->base + LRADC_DELAY(3)); 4478c2ecf20Sopenharmony_ci writel(LRADC_CTRL1_TOUCH_DETECT_IRQ | 4488c2ecf20Sopenharmony_ci LRADC_CTRL1_LRADC_IRQ_EN(TOUCHSCREEN_VCHANNEL1) | 4498c2ecf20Sopenharmony_ci LRADC_CTRL1_LRADC_IRQ(TOUCHSCREEN_VCHANNEL1), 4508c2ecf20Sopenharmony_ci ts->base + LRADC_CTRL1 + STMP_OFFSET_REG_CLR); 4518c2ecf20Sopenharmony_ci writel(LRADC_CTRL1_TOUCH_DETECT_IRQ_EN, 4528c2ecf20Sopenharmony_ci ts->base + LRADC_CTRL1 + STMP_OFFSET_REG_SET); 4538c2ecf20Sopenharmony_ci} 4548c2ecf20Sopenharmony_ci 4558c2ecf20Sopenharmony_ci/* touchscreen's state machine */ 4568c2ecf20Sopenharmony_cistatic void mxs_lradc_handle_touch(struct mxs_lradc_ts *ts) 4578c2ecf20Sopenharmony_ci{ 4588c2ecf20Sopenharmony_ci switch (ts->cur_plate) { 4598c2ecf20Sopenharmony_ci case LRADC_TOUCH: 4608c2ecf20Sopenharmony_ci if (mxs_lradc_check_touch_event(ts)) 4618c2ecf20Sopenharmony_ci mxs_lradc_start_touch_event(ts); 4628c2ecf20Sopenharmony_ci writel(LRADC_CTRL1_TOUCH_DETECT_IRQ, 4638c2ecf20Sopenharmony_ci ts->base + LRADC_CTRL1 + STMP_OFFSET_REG_CLR); 4648c2ecf20Sopenharmony_ci return; 4658c2ecf20Sopenharmony_ci 4668c2ecf20Sopenharmony_ci case LRADC_SAMPLE_Y: 4678c2ecf20Sopenharmony_ci ts->ts_y_pos = 4688c2ecf20Sopenharmony_ci mxs_lradc_ts_read_raw_channel(ts, TOUCHSCREEN_VCHANNEL1); 4698c2ecf20Sopenharmony_ci mxs_lradc_prepare_x_pos(ts); 4708c2ecf20Sopenharmony_ci return; 4718c2ecf20Sopenharmony_ci 4728c2ecf20Sopenharmony_ci case LRADC_SAMPLE_X: 4738c2ecf20Sopenharmony_ci ts->ts_x_pos = 4748c2ecf20Sopenharmony_ci mxs_lradc_ts_read_raw_channel(ts, TOUCHSCREEN_VCHANNEL1); 4758c2ecf20Sopenharmony_ci mxs_lradc_prepare_pressure(ts); 4768c2ecf20Sopenharmony_ci return; 4778c2ecf20Sopenharmony_ci 4788c2ecf20Sopenharmony_ci case LRADC_SAMPLE_PRESSURE: 4798c2ecf20Sopenharmony_ci ts->ts_pressure = 4808c2ecf20Sopenharmony_ci mxs_lradc_read_ts_pressure(ts, 4818c2ecf20Sopenharmony_ci TOUCHSCREEN_VCHANNEL2, 4828c2ecf20Sopenharmony_ci TOUCHSCREEN_VCHANNEL1); 4838c2ecf20Sopenharmony_ci mxs_lradc_complete_touch_event(ts); 4848c2ecf20Sopenharmony_ci return; 4858c2ecf20Sopenharmony_ci 4868c2ecf20Sopenharmony_ci case LRADC_SAMPLE_VALID: 4878c2ecf20Sopenharmony_ci mxs_lradc_finish_touch_event(ts, 1); 4888c2ecf20Sopenharmony_ci break; 4898c2ecf20Sopenharmony_ci } 4908c2ecf20Sopenharmony_ci} 4918c2ecf20Sopenharmony_ci 4928c2ecf20Sopenharmony_ci/* IRQ Handling */ 4938c2ecf20Sopenharmony_cistatic irqreturn_t mxs_lradc_ts_handle_irq(int irq, void *data) 4948c2ecf20Sopenharmony_ci{ 4958c2ecf20Sopenharmony_ci struct mxs_lradc_ts *ts = data; 4968c2ecf20Sopenharmony_ci struct mxs_lradc *lradc = ts->lradc; 4978c2ecf20Sopenharmony_ci unsigned long reg = readl(ts->base + LRADC_CTRL1); 4988c2ecf20Sopenharmony_ci u32 clr_irq = mxs_lradc_irq_mask(lradc); 4998c2ecf20Sopenharmony_ci const u32 ts_irq_mask = 5008c2ecf20Sopenharmony_ci LRADC_CTRL1_TOUCH_DETECT_IRQ | 5018c2ecf20Sopenharmony_ci LRADC_CTRL1_LRADC_IRQ(TOUCHSCREEN_VCHANNEL1) | 5028c2ecf20Sopenharmony_ci LRADC_CTRL1_LRADC_IRQ(TOUCHSCREEN_VCHANNEL2); 5038c2ecf20Sopenharmony_ci unsigned long flags; 5048c2ecf20Sopenharmony_ci 5058c2ecf20Sopenharmony_ci if (!(reg & mxs_lradc_irq_mask(lradc))) 5068c2ecf20Sopenharmony_ci return IRQ_NONE; 5078c2ecf20Sopenharmony_ci 5088c2ecf20Sopenharmony_ci if (reg & ts_irq_mask) { 5098c2ecf20Sopenharmony_ci spin_lock_irqsave(&ts->lock, flags); 5108c2ecf20Sopenharmony_ci mxs_lradc_handle_touch(ts); 5118c2ecf20Sopenharmony_ci spin_unlock_irqrestore(&ts->lock, flags); 5128c2ecf20Sopenharmony_ci /* Make sure we don't clear the next conversion's interrupt. */ 5138c2ecf20Sopenharmony_ci clr_irq &= ~(LRADC_CTRL1_LRADC_IRQ(TOUCHSCREEN_VCHANNEL1) | 5148c2ecf20Sopenharmony_ci LRADC_CTRL1_LRADC_IRQ(TOUCHSCREEN_VCHANNEL2)); 5158c2ecf20Sopenharmony_ci writel(reg & clr_irq, 5168c2ecf20Sopenharmony_ci ts->base + LRADC_CTRL1 + STMP_OFFSET_REG_CLR); 5178c2ecf20Sopenharmony_ci } 5188c2ecf20Sopenharmony_ci 5198c2ecf20Sopenharmony_ci return IRQ_HANDLED; 5208c2ecf20Sopenharmony_ci} 5218c2ecf20Sopenharmony_ci 5228c2ecf20Sopenharmony_cistatic int mxs_lradc_ts_open(struct input_dev *dev) 5238c2ecf20Sopenharmony_ci{ 5248c2ecf20Sopenharmony_ci struct mxs_lradc_ts *ts = input_get_drvdata(dev); 5258c2ecf20Sopenharmony_ci 5268c2ecf20Sopenharmony_ci /* Enable the touch-detect circuitry. */ 5278c2ecf20Sopenharmony_ci mxs_lradc_enable_touch_detection(ts); 5288c2ecf20Sopenharmony_ci 5298c2ecf20Sopenharmony_ci return 0; 5308c2ecf20Sopenharmony_ci} 5318c2ecf20Sopenharmony_ci 5328c2ecf20Sopenharmony_cistatic void mxs_lradc_ts_stop(struct mxs_lradc_ts *ts) 5338c2ecf20Sopenharmony_ci{ 5348c2ecf20Sopenharmony_ci int i; 5358c2ecf20Sopenharmony_ci struct mxs_lradc *lradc = ts->lradc; 5368c2ecf20Sopenharmony_ci 5378c2ecf20Sopenharmony_ci /* stop all interrupts from firing */ 5388c2ecf20Sopenharmony_ci writel(LRADC_CTRL1_TOUCH_DETECT_IRQ_EN | 5398c2ecf20Sopenharmony_ci LRADC_CTRL1_LRADC_IRQ_EN(TOUCHSCREEN_VCHANNEL1) | 5408c2ecf20Sopenharmony_ci LRADC_CTRL1_LRADC_IRQ_EN(TOUCHSCREEN_VCHANNEL2), 5418c2ecf20Sopenharmony_ci ts->base + LRADC_CTRL1 + STMP_OFFSET_REG_CLR); 5428c2ecf20Sopenharmony_ci 5438c2ecf20Sopenharmony_ci /* Power-down touchscreen touch-detect circuitry. */ 5448c2ecf20Sopenharmony_ci writel(info[lradc->soc].mask, 5458c2ecf20Sopenharmony_ci ts->base + LRADC_CTRL0 + STMP_OFFSET_REG_CLR); 5468c2ecf20Sopenharmony_ci 5478c2ecf20Sopenharmony_ci writel(lradc->buffer_vchans << LRADC_CTRL1_LRADC_IRQ_EN_OFFSET, 5488c2ecf20Sopenharmony_ci ts->base + LRADC_CTRL1 + STMP_OFFSET_REG_CLR); 5498c2ecf20Sopenharmony_ci 5508c2ecf20Sopenharmony_ci for (i = 1; i < LRADC_MAX_DELAY_CHANS; i++) 5518c2ecf20Sopenharmony_ci writel(0, ts->base + LRADC_DELAY(i)); 5528c2ecf20Sopenharmony_ci} 5538c2ecf20Sopenharmony_ci 5548c2ecf20Sopenharmony_cistatic void mxs_lradc_ts_close(struct input_dev *dev) 5558c2ecf20Sopenharmony_ci{ 5568c2ecf20Sopenharmony_ci struct mxs_lradc_ts *ts = input_get_drvdata(dev); 5578c2ecf20Sopenharmony_ci 5588c2ecf20Sopenharmony_ci mxs_lradc_ts_stop(ts); 5598c2ecf20Sopenharmony_ci} 5608c2ecf20Sopenharmony_ci 5618c2ecf20Sopenharmony_cistatic void mxs_lradc_ts_hw_init(struct mxs_lradc_ts *ts) 5628c2ecf20Sopenharmony_ci{ 5638c2ecf20Sopenharmony_ci struct mxs_lradc *lradc = ts->lradc; 5648c2ecf20Sopenharmony_ci 5658c2ecf20Sopenharmony_ci /* Configure the touchscreen type */ 5668c2ecf20Sopenharmony_ci if (lradc->soc == IMX28_LRADC) { 5678c2ecf20Sopenharmony_ci writel(LRADC_CTRL0_MX28_TOUCH_SCREEN_TYPE, 5688c2ecf20Sopenharmony_ci ts->base + LRADC_CTRL0 + STMP_OFFSET_REG_CLR); 5698c2ecf20Sopenharmony_ci 5708c2ecf20Sopenharmony_ci if (lradc->touchscreen_wire == MXS_LRADC_TOUCHSCREEN_5WIRE) 5718c2ecf20Sopenharmony_ci writel(LRADC_CTRL0_MX28_TOUCH_SCREEN_TYPE, 5728c2ecf20Sopenharmony_ci ts->base + LRADC_CTRL0 + STMP_OFFSET_REG_SET); 5738c2ecf20Sopenharmony_ci } 5748c2ecf20Sopenharmony_ci} 5758c2ecf20Sopenharmony_ci 5768c2ecf20Sopenharmony_cistatic int mxs_lradc_ts_register(struct mxs_lradc_ts *ts) 5778c2ecf20Sopenharmony_ci{ 5788c2ecf20Sopenharmony_ci struct input_dev *input; 5798c2ecf20Sopenharmony_ci struct device *dev = ts->dev; 5808c2ecf20Sopenharmony_ci 5818c2ecf20Sopenharmony_ci input = devm_input_allocate_device(dev); 5828c2ecf20Sopenharmony_ci if (!input) 5838c2ecf20Sopenharmony_ci return -ENOMEM; 5848c2ecf20Sopenharmony_ci 5858c2ecf20Sopenharmony_ci input->name = "mxs-lradc-ts"; 5868c2ecf20Sopenharmony_ci input->id.bustype = BUS_HOST; 5878c2ecf20Sopenharmony_ci input->open = mxs_lradc_ts_open; 5888c2ecf20Sopenharmony_ci input->close = mxs_lradc_ts_close; 5898c2ecf20Sopenharmony_ci 5908c2ecf20Sopenharmony_ci __set_bit(INPUT_PROP_DIRECT, input->propbit); 5918c2ecf20Sopenharmony_ci input_set_capability(input, EV_KEY, BTN_TOUCH); 5928c2ecf20Sopenharmony_ci input_set_abs_params(input, ABS_X, 0, LRADC_SINGLE_SAMPLE_MASK, 0, 0); 5938c2ecf20Sopenharmony_ci input_set_abs_params(input, ABS_Y, 0, LRADC_SINGLE_SAMPLE_MASK, 0, 0); 5948c2ecf20Sopenharmony_ci input_set_abs_params(input, ABS_PRESSURE, 0, LRADC_SINGLE_SAMPLE_MASK, 5958c2ecf20Sopenharmony_ci 0, 0); 5968c2ecf20Sopenharmony_ci 5978c2ecf20Sopenharmony_ci ts->ts_input = input; 5988c2ecf20Sopenharmony_ci input_set_drvdata(input, ts); 5998c2ecf20Sopenharmony_ci 6008c2ecf20Sopenharmony_ci return input_register_device(input); 6018c2ecf20Sopenharmony_ci} 6028c2ecf20Sopenharmony_ci 6038c2ecf20Sopenharmony_cistatic int mxs_lradc_ts_probe(struct platform_device *pdev) 6048c2ecf20Sopenharmony_ci{ 6058c2ecf20Sopenharmony_ci struct device *dev = &pdev->dev; 6068c2ecf20Sopenharmony_ci struct device_node *node = dev->parent->of_node; 6078c2ecf20Sopenharmony_ci struct mxs_lradc *lradc = dev_get_drvdata(dev->parent); 6088c2ecf20Sopenharmony_ci struct mxs_lradc_ts *ts; 6098c2ecf20Sopenharmony_ci int ret, irq, virq, i; 6108c2ecf20Sopenharmony_ci u32 ts_wires = 0, adapt; 6118c2ecf20Sopenharmony_ci 6128c2ecf20Sopenharmony_ci ts = devm_kzalloc(dev, sizeof(*ts), GFP_KERNEL); 6138c2ecf20Sopenharmony_ci if (!ts) 6148c2ecf20Sopenharmony_ci return -ENOMEM; 6158c2ecf20Sopenharmony_ci 6168c2ecf20Sopenharmony_ci platform_set_drvdata(pdev, ts); 6178c2ecf20Sopenharmony_ci 6188c2ecf20Sopenharmony_ci ts->lradc = lradc; 6198c2ecf20Sopenharmony_ci ts->dev = dev; 6208c2ecf20Sopenharmony_ci spin_lock_init(&ts->lock); 6218c2ecf20Sopenharmony_ci 6228c2ecf20Sopenharmony_ci ts->base = devm_platform_ioremap_resource(pdev, 0); 6238c2ecf20Sopenharmony_ci if (IS_ERR(ts->base)) 6248c2ecf20Sopenharmony_ci return PTR_ERR(ts->base); 6258c2ecf20Sopenharmony_ci 6268c2ecf20Sopenharmony_ci ret = of_property_read_u32(node, "fsl,lradc-touchscreen-wires", 6278c2ecf20Sopenharmony_ci &ts_wires); 6288c2ecf20Sopenharmony_ci if (ret) 6298c2ecf20Sopenharmony_ci return ret; 6308c2ecf20Sopenharmony_ci 6318c2ecf20Sopenharmony_ci if (of_property_read_u32(node, "fsl,ave-ctrl", &adapt)) { 6328c2ecf20Sopenharmony_ci ts->over_sample_cnt = 4; 6338c2ecf20Sopenharmony_ci } else { 6348c2ecf20Sopenharmony_ci if (adapt >= 1 && adapt <= 32) { 6358c2ecf20Sopenharmony_ci ts->over_sample_cnt = adapt; 6368c2ecf20Sopenharmony_ci } else { 6378c2ecf20Sopenharmony_ci dev_err(ts->dev, "Invalid sample count (%u)\n", 6388c2ecf20Sopenharmony_ci adapt); 6398c2ecf20Sopenharmony_ci return -EINVAL; 6408c2ecf20Sopenharmony_ci } 6418c2ecf20Sopenharmony_ci } 6428c2ecf20Sopenharmony_ci 6438c2ecf20Sopenharmony_ci if (of_property_read_u32(node, "fsl,ave-delay", &adapt)) { 6448c2ecf20Sopenharmony_ci ts->over_sample_delay = 2; 6458c2ecf20Sopenharmony_ci } else { 6468c2ecf20Sopenharmony_ci if (adapt >= 2 && adapt <= LRADC_DELAY_DELAY_MASK + 1) { 6478c2ecf20Sopenharmony_ci ts->over_sample_delay = adapt; 6488c2ecf20Sopenharmony_ci } else { 6498c2ecf20Sopenharmony_ci dev_err(ts->dev, "Invalid sample delay (%u)\n", 6508c2ecf20Sopenharmony_ci adapt); 6518c2ecf20Sopenharmony_ci return -EINVAL; 6528c2ecf20Sopenharmony_ci } 6538c2ecf20Sopenharmony_ci } 6548c2ecf20Sopenharmony_ci 6558c2ecf20Sopenharmony_ci if (of_property_read_u32(node, "fsl,settling", &adapt)) { 6568c2ecf20Sopenharmony_ci ts->settling_delay = 10; 6578c2ecf20Sopenharmony_ci } else { 6588c2ecf20Sopenharmony_ci if (adapt >= 1 && adapt <= LRADC_DELAY_DELAY_MASK) { 6598c2ecf20Sopenharmony_ci ts->settling_delay = adapt; 6608c2ecf20Sopenharmony_ci } else { 6618c2ecf20Sopenharmony_ci dev_err(ts->dev, "Invalid settling delay (%u)\n", 6628c2ecf20Sopenharmony_ci adapt); 6638c2ecf20Sopenharmony_ci return -EINVAL; 6648c2ecf20Sopenharmony_ci } 6658c2ecf20Sopenharmony_ci } 6668c2ecf20Sopenharmony_ci 6678c2ecf20Sopenharmony_ci ret = stmp_reset_block(ts->base); 6688c2ecf20Sopenharmony_ci if (ret) 6698c2ecf20Sopenharmony_ci return ret; 6708c2ecf20Sopenharmony_ci 6718c2ecf20Sopenharmony_ci mxs_lradc_ts_hw_init(ts); 6728c2ecf20Sopenharmony_ci 6738c2ecf20Sopenharmony_ci for (i = 0; i < 3; i++) { 6748c2ecf20Sopenharmony_ci irq = platform_get_irq_byname(pdev, mxs_lradc_ts_irq_names[i]); 6758c2ecf20Sopenharmony_ci if (irq < 0) 6768c2ecf20Sopenharmony_ci return irq; 6778c2ecf20Sopenharmony_ci 6788c2ecf20Sopenharmony_ci virq = irq_of_parse_and_map(node, irq); 6798c2ecf20Sopenharmony_ci 6808c2ecf20Sopenharmony_ci mxs_lradc_ts_stop(ts); 6818c2ecf20Sopenharmony_ci 6828c2ecf20Sopenharmony_ci ret = devm_request_irq(dev, virq, 6838c2ecf20Sopenharmony_ci mxs_lradc_ts_handle_irq, 6848c2ecf20Sopenharmony_ci 0, mxs_lradc_ts_irq_names[i], ts); 6858c2ecf20Sopenharmony_ci if (ret) 6868c2ecf20Sopenharmony_ci return ret; 6878c2ecf20Sopenharmony_ci } 6888c2ecf20Sopenharmony_ci 6898c2ecf20Sopenharmony_ci return mxs_lradc_ts_register(ts); 6908c2ecf20Sopenharmony_ci} 6918c2ecf20Sopenharmony_ci 6928c2ecf20Sopenharmony_cistatic struct platform_driver mxs_lradc_ts_driver = { 6938c2ecf20Sopenharmony_ci .driver = { 6948c2ecf20Sopenharmony_ci .name = "mxs-lradc-ts", 6958c2ecf20Sopenharmony_ci }, 6968c2ecf20Sopenharmony_ci .probe = mxs_lradc_ts_probe, 6978c2ecf20Sopenharmony_ci}; 6988c2ecf20Sopenharmony_cimodule_platform_driver(mxs_lradc_ts_driver); 6998c2ecf20Sopenharmony_ci 7008c2ecf20Sopenharmony_ciMODULE_AUTHOR("Marek Vasut <marex@denx.de>"); 7018c2ecf20Sopenharmony_ciMODULE_DESCRIPTION("Freescale MXS LRADC touchscreen driver"); 7028c2ecf20Sopenharmony_ciMODULE_LICENSE("GPL"); 7038c2ecf20Sopenharmony_ciMODULE_ALIAS("platform:mxs-lradc-ts"); 704