1 /* SPDX-License-Identifier: GPL-2.0-only */
3 #include <device/mmio.h>
10 struct rk3288_tsadc_regs
{
15 u32 reserved0
[(0x20 - 0x10) / 4];
28 u32 reserved1
[(0x60 - 0x50) / 4];
29 u32 hight_int_debounce
;
30 u32 hight_tshut_debounce
;
34 check_member(rk3288_tsadc_regs
, auto_period_ht
, 0x6c);
37 #define LAST_TSHUT (1 << 24)
38 #define TSHUT_POL_HIGH (1 << 8)
39 #define SRC3_EN (1 << 7)
40 #define SRC2_EN (1 << 6)
41 #define SRC1_EN (1 << 5)
42 #define SRC0_EN (1 << 4)
43 #define AUTO_EN (1 << 0)
46 #define TSHUT_CRU_EN_SRC3 (1 << 11)
47 #define TSHUT_CRU_EN_SRC2 (1 << 10)
48 #define TSHUT_CRU_EN_SRC1 (1 << 9)
49 #define TSHUT_CRU_EN_SRC0 (1 << 8)
50 #define TSHUT_GPIO_EN_SRC3 (1 << 7)
51 #define TSHUT_GPIO_EN_SRC2 (1 << 6)
52 #define TSHUT_GPIO_EN_SRC1 (1 << 5)
53 #define TSHUT_GPIO_EN_SRC0 (1 << 4)
55 #define AUTO_PERIOD 10
56 #define AUTO_DEBOUNCE 4
57 #define AUTO_PERIOD_HT 10
58 #define AUTO_DEBOUNCE_HT 4
59 #define TSADC_CLOCK_HZ (8 * KHz)
61 /* AD value, correspond to 120 degrees Celsius */
62 #define TSADC_SHUT_VALUE 3437
64 struct rk3288_tsadc_regs
*rk3288_tsadc
= (void *)TSADC_BASE
;
68 rkclk_configure_tsadc(TSADC_CLOCK_HZ
);
70 setbits32(&rk3288_tsadc
->auto_con
, LAST_TSHUT
);
72 setbits32(&rk3288_tsadc
->int_en
,
73 TSHUT_CRU_EN_SRC2
| TSHUT_CRU_EN_SRC1
|
74 TSHUT_GPIO_EN_SRC2
| TSHUT_GPIO_EN_SRC1
);
76 write32(&rk3288_tsadc
->auto_period
, AUTO_PERIOD
);
77 write32(&rk3288_tsadc
->hight_int_debounce
, AUTO_DEBOUNCE
);
78 write32(&rk3288_tsadc
->auto_period_ht
, AUTO_PERIOD_HT
);
79 write32(&rk3288_tsadc
->hight_tshut_debounce
, AUTO_DEBOUNCE_HT
);
81 write32(&rk3288_tsadc
->comp1_shut
, TSADC_SHUT_VALUE
);
82 write32(&rk3288_tsadc
->comp2_shut
, TSADC_SHUT_VALUE
);
84 /* polarity set to high,channel1 for cpu,channel2 for gpu */
85 setbits32(&rk3288_tsadc
->auto_con
, TSHUT_POL_HIGH
| SRC2_EN
|
89 tsadc iomux must be set after the tshut polarity setting,
90 since the tshut polarity default low active,
91 so if you enable tsadc iomux,it will output high
93 setbits32(&rk3288_pmu
->iomux_tsadc_int
, IOMUX_TSADC_INT
);