blob: 1542ccf7e86f16326f872be8b0b0b1bb957c11bd [file] [log] [blame]
huang lina97bd5a2014-10-14 10:04:16 -07001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright 2014 Rockchip Inc.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
huang lina97bd5a2014-10-14 10:04:16 -070014 */
15
Julius Werner7a453eb2014-10-20 13:14:55 -070016#include <arch/io.h>
huang lina97bd5a2014-10-14 10:04:16 -070017#include <assert.h>
18#include <console/console.h>
Julius Werner7a453eb2014-10-20 13:14:55 -070019#include <delay.h>
20#include <soc/clock.h>
21#include <soc/grf.h>
22#include <soc/pmu.h>
23#include <soc/tsadc.h>
huang lina97bd5a2014-10-14 10:04:16 -070024#include <stdint.h>
25#include <stdlib.h>
huang lina97bd5a2014-10-14 10:04:16 -070026
27struct rk3288_tsadc_regs {
28 u32 user_con;
29 u32 auto_con;
30 u32 int_en;
31 u32 int_pd;
32 u32 reserved0[(0x20 - 0x10) / 4];
33 u32 data0;
34 u32 data1;
35 u32 data2;
36 u32 data3;
37 u32 comp0_int;
38 u32 comp1_int;
39 u32 comp2_int;
40 u32 comp3_int;
41 u32 comp0_shut;
42 u32 comp1_shut;
43 u32 comp2_shut;
44 u32 comp3_shut;
45 u32 reserved1[(0x60 - 0x50) / 4];
46 u32 hight_int_debounce;
47 u32 hight_tshut_debounce;
48 u32 auto_period;
49 u32 auto_period_ht;
50};
51check_member(rk3288_tsadc_regs, auto_period_ht, 0x6c);
52
53/* auto_con */
54#define LAST_TSHUT (1 << 24)
55#define TSHUT_POL_HIGH (1 << 8)
56#define SRC3_EN (1 << 7)
57#define SRC2_EN (1 << 6)
58#define SRC1_EN (1 << 5)
59#define SRC0_EN (1 << 4)
60#define AUTO_EN (1 << 0)
61
62/* int_en */
63#define TSHUT_CRU_EN_SRC3 (1 << 11)
64#define TSHUT_CRU_EN_SRC2 (1 << 10)
65#define TSHUT_CRU_EN_SRC1 (1 << 9)
66#define TSHUT_CRU_EN_SRC0 (1 << 8)
67#define TSHUT_GPIO_EN_SRC3 (1 << 7)
68#define TSHUT_GPIO_EN_SRC2 (1 << 6)
69#define TSHUT_GPIO_EN_SRC1 (1 << 5)
70#define TSHUT_GPIO_EN_SRC0 (1 << 4)
71
72#define AUTO_PERIOD 10
73#define AUTO_DEBOUNCE 4
74#define AUTO_PERIOD_HT 10
75#define AUTO_DEBOUNCE_HT 4
76#define TSADC_CLOCK_HZ (8 * KHz)
77
78/* AD value, correspond to 120 degrees Celsius */
79#define TSADC_SHUT_VALUE 3437
80
81struct rk3288_tsadc_regs *rk3288_tsadc = (void *)TSADC_BASE;
82
83void tsadc_init(void)
84{
85 rkclk_configure_tsadc(TSADC_CLOCK_HZ);
86
huang lin335d9f12014-11-07 10:56:35 +080087 setbits_le32(&rk3288_tsadc->auto_con, LAST_TSHUT);
huang lina97bd5a2014-10-14 10:04:16 -070088
89 setbits_le32(&rk3288_tsadc->int_en,
90 TSHUT_CRU_EN_SRC2 | TSHUT_CRU_EN_SRC1 |
91 TSHUT_GPIO_EN_SRC2 | TSHUT_GPIO_EN_SRC1);
92
Julius Werner2f37bd62015-02-19 14:51:15 -080093 write32(&rk3288_tsadc->auto_period, AUTO_PERIOD);
94 write32(&rk3288_tsadc->hight_int_debounce, AUTO_DEBOUNCE);
95 write32(&rk3288_tsadc->auto_period_ht, AUTO_PERIOD_HT);
96 write32(&rk3288_tsadc->hight_tshut_debounce, AUTO_DEBOUNCE_HT);
huang lina97bd5a2014-10-14 10:04:16 -070097
Julius Werner2f37bd62015-02-19 14:51:15 -080098 write32(&rk3288_tsadc->comp1_shut, TSADC_SHUT_VALUE);
99 write32(&rk3288_tsadc->comp2_shut, TSADC_SHUT_VALUE);
huang lina97bd5a2014-10-14 10:04:16 -0700100
101 /* polarity set to high,channel1 for cpu,channel2 for gpu */
102 setbits_le32(&rk3288_tsadc->auto_con, TSHUT_POL_HIGH | SRC2_EN |
103 SRC1_EN | AUTO_EN);
104
105 /*
106 tsadc iomux must be set after the tshut polarity setting,
107 since the tshut polarity defalut low active,
108 so if you enable tsadc iomux,it will output high
109 */
110 setbits_le32(&rk3288_pmu->iomux_tsadc_int, IOMUX_TSADC_INT);
111}