huang lin | a97bd5a | 2014-10-14 10:04:16 -0700 | [diff] [blame] | 1 | /* |
| 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 lin | a97bd5a | 2014-10-14 10:04:16 -0700 | [diff] [blame] | 14 | */ |
| 15 | |
Julius Werner | 7a453eb | 2014-10-20 13:14:55 -0700 | [diff] [blame] | 16 | #include <arch/io.h> |
huang lin | a97bd5a | 2014-10-14 10:04:16 -0700 | [diff] [blame] | 17 | #include <assert.h> |
| 18 | #include <console/console.h> |
Julius Werner | 7a453eb | 2014-10-20 13:14:55 -0700 | [diff] [blame] | 19 | #include <delay.h> |
| 20 | #include <soc/clock.h> |
| 21 | #include <soc/grf.h> |
| 22 | #include <soc/pmu.h> |
| 23 | #include <soc/tsadc.h> |
huang lin | a97bd5a | 2014-10-14 10:04:16 -0700 | [diff] [blame] | 24 | #include <stdint.h> |
| 25 | #include <stdlib.h> |
huang lin | a97bd5a | 2014-10-14 10:04:16 -0700 | [diff] [blame] | 26 | |
| 27 | struct 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 | }; |
| 51 | check_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 | |
| 81 | struct rk3288_tsadc_regs *rk3288_tsadc = (void *)TSADC_BASE; |
| 82 | |
| 83 | void tsadc_init(void) |
| 84 | { |
| 85 | rkclk_configure_tsadc(TSADC_CLOCK_HZ); |
| 86 | |
huang lin | 335d9f1 | 2014-11-07 10:56:35 +0800 | [diff] [blame] | 87 | setbits_le32(&rk3288_tsadc->auto_con, LAST_TSHUT); |
huang lin | a97bd5a | 2014-10-14 10:04:16 -0700 | [diff] [blame] | 88 | |
| 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 Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame] | 93 | 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 lin | a97bd5a | 2014-10-14 10:04:16 -0700 | [diff] [blame] | 97 | |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame] | 98 | write32(&rk3288_tsadc->comp1_shut, TSADC_SHUT_VALUE); |
| 99 | write32(&rk3288_tsadc->comp2_shut, TSADC_SHUT_VALUE); |
huang lin | a97bd5a | 2014-10-14 10:04:16 -0700 | [diff] [blame] | 100 | |
| 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 | } |