diff options
Diffstat (limited to 'firmware/target/arm/imx233/lradc-imx233.h')
-rw-r--r-- | firmware/target/arm/imx233/lradc-imx233.h | 128 |
1 files changed, 128 insertions, 0 deletions
diff --git a/firmware/target/arm/imx233/lradc-imx233.h b/firmware/target/arm/imx233/lradc-imx233.h new file mode 100644 index 0000000000..a72916054a --- /dev/null +++ b/firmware/target/arm/imx233/lradc-imx233.h | |||
@@ -0,0 +1,128 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2011 by Amaury Pouly | ||
11 | * | ||
12 | * This program is free software; you can redistribute it and/or | ||
13 | * modify it under the terms of the GNU General Public License | ||
14 | * as published by the Free Software Foundation; either version 2 | ||
15 | * of the License, or (at your option) any later version. | ||
16 | * | ||
17 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
18 | * KIND, either express or implied. | ||
19 | * | ||
20 | ****************************************************************************/ | ||
21 | #ifndef __lradc_imx233__ | ||
22 | #define __lradc_imx233__ | ||
23 | |||
24 | #include "config.h" | ||
25 | #include "cpu.h" | ||
26 | |||
27 | #include "cpu.h" | ||
28 | #include "system.h" | ||
29 | #include "system-target.h" | ||
30 | |||
31 | #define HW_LRADC_BASE 0x80050000 | ||
32 | |||
33 | #define HW_LRADC_CTRL0 (*(volatile uint32_t *)(HW_LRADC_BASE + 0x0)) | ||
34 | #define HW_LRADC_CTRL0__ONCHIP_GROUNDREF (1 << 21) | ||
35 | #define HW_LRADC_CTRL0__SCHEDULE(x) (1 << (x)) | ||
36 | |||
37 | #define HW_LRADC_CTRL1 (*(volatile uint32_t *)(HW_LRADC_BASE + 0x10)) | ||
38 | #define HW_LRADC_CTRL1__LRADCx_IRQ(x) (1 << (x)) | ||
39 | #define HW_LRADC_CTRL1__LRADCx_IRQ_EN(x) (1 << ((x) + 16)) | ||
40 | |||
41 | #define HW_LRADC_CTRL2 (*(volatile uint32_t *)(HW_LRADC_BASE + 0x20)) | ||
42 | #define HW_LRADC_CTRL2__TEMP_ISRC1_BP 4 | ||
43 | #define HW_LRADC_CTRL2__TEMP_ISRC1_BM 0xf0 | ||
44 | #define HW_LRADC_CTRL2__TEMP_ISRC0_BP 0 | ||
45 | #define HW_LRADC_CTRL2__TEMP_ISRC0_BM 0xf | ||
46 | #define HW_LRADC_CTRL2__TEMP_SENSOR_IENABLE0 (1 << 8) | ||
47 | #define HW_LRADC_CTRL2__TEMP_SENSOR_IENABLE1 (1 << 9) | ||
48 | #define HW_LRADC_CTRL2__TEMPSENSE_PWD (1 << 15) | ||
49 | #define HW_LRADC_CTRL2__DIVIDE_BY_TWO(x) (1 << ((x) + 24)) | ||
50 | |||
51 | #define HW_LRADC_CTRL3 (*(volatile uint32_t *)(HW_LRADC_BASE + 0x30)) | ||
52 | #define HW_LRADC_CTRL3__CYCLE_TIME_BM 0x300 | ||
53 | #define HW_LRADC_CTRL3__CYCLE_TIME_BP 8 | ||
54 | #define HW_LRADC_CTRL3__CYCLE_TIME__6MHz (0 << 8) | ||
55 | #define HW_LRADC_CTRL3__CYCLE_TIME__4MHz (1 << 8) | ||
56 | #define HW_LRADC_CTRL3__CYCLE_TIME__3MHz (2 << 8) | ||
57 | #define HW_LRADC_CTRL3__CYCLE_TIME__2MHz (3 << 8) | ||
58 | |||
59 | #define HW_LRADC_STATUS (*(volatile uint32_t *)(HW_LRADC_BASE + 0x40)) | ||
60 | |||
61 | #define HW_LRADC_CHx(x) (*(volatile uint32_t *)(HW_LRADC_BASE + 0x50 + (x) * 0x10)) | ||
62 | #define HW_LRADC_CHx__NUM_SAMPLES_BM (0xf << 24) | ||
63 | #define HW_LRADC_CHx__NUM_SAMPLES_BP 24 | ||
64 | #define HW_LRADC_CHx__ACCUMULATE 29 | ||
65 | #define HW_LRADC_CHx__VALUE_BM 0x3ffff | ||
66 | #define HW_LRADC_CHx__VALUE_BP 0 | ||
67 | |||
68 | #define HW_LRADC_DELAYx(x) (*(volatile uint32_t *)(HW_LRADC_BASE + 0xD0 + (x) * 0x10)) | ||
69 | #define HW_LRADC_DELAYx__DELAY_BP 0 | ||
70 | #define HW_LRADC_DELAYx__DELAY_BM 0x7ff | ||
71 | #define HW_LRADC_DELAYx__LOOP_COUNT_BP 11 | ||
72 | #define HW_LRADC_DELAYx__LOOP_COUNT_BM (0x1f << 11) | ||
73 | #define HW_LRADC_DELAYx__TRIGGER_DELAYS_BP 16 | ||
74 | #define HW_LRADC_DELAYx__TRIGGER_DELAYS_BM (0xf << 16) | ||
75 | #define HW_LRADC_DELAYx__KICK (1 << 20) | ||
76 | #define HW_LRADC_DELAYx__TRIGGER_LRADCS_BP 24 | ||
77 | #define HW_LRADC_DELAYx__TRIGGER_LRADCS_BM (0xff << 24) | ||
78 | |||
79 | #define HW_LRADC_CONVERSION (*(volatile uint32_t *)(HW_LRADC_BASE + 0x130)) | ||
80 | #define HW_LRADC_CONVERSION__SCALED_BATT_VOLTAGE_BP 0 | ||
81 | #define HW_LRADC_CONVERSION__SCALED_BATT_VOLTAGE_BM 0x3ff | ||
82 | #define HW_LRADC_CONVERSION__SCALE_FACTOR_BM (3 << 16) | ||
83 | #define HW_LRADC_CONVERSION__SCALE_FACTOR_BP 16 | ||
84 | #define HW_LRADC_CONVERSION__SCALE_FACTOR__LI_ION (2 << 16) | ||
85 | #define HW_LRADC_CONVERSION__AUTOMATIC (1 << 20) | ||
86 | |||
87 | #define HW_LRADC_CTRL4 (*(volatile uint32_t *)(HW_LRADC_BASE + 0x140)) | ||
88 | #define HW_LRADC_CTRL4__LRADCxSELECT_BM(x) (0xf << ((x) * 4)) | ||
89 | #define HW_LRADC_CTRL4__LRADCxSELECT_BP(x) ((x) * 4) | ||
90 | |||
91 | #define HW_LRADC_VERSION (*(volatile uint32_t *)(HW_LRADC_BASE + 0x150)) | ||
92 | |||
93 | #define HW_LRADC_NUM_CHANNELS 8 | ||
94 | #define HW_LRADC_NUM_DELAYS 4 | ||
95 | |||
96 | #define HW_LRADC_CHANNEL(x) (x) | ||
97 | #define HW_LRADC_CHANNEL_VDDIO HW_LRADC_CHANNEL(6) | ||
98 | #define HW_LRADC_CHANNEL_BATTERY HW_LRADC_CHANNEL(7) | ||
99 | #define HW_LRADC_CHANNEL_PMOS_THIN HW_LRADC_CHANNEL(8) | ||
100 | #define HW_LRADC_CHANNEL_NMOS_THIN HW_LRADC_CHANNEL(9) | ||
101 | #define HW_LRADC_CHANNEL_NMOS_THICK HW_LRADC_CHANNEL(10) | ||
102 | #define HW_LRADC_CHANNEL_PMOS_THICK HW_LRADC_CHANNEL(11) | ||
103 | #define HW_LRADC_CHANNEL_PMOS_THICK HW_LRADC_CHANNEL(11) | ||
104 | #define HW_LRADC_CHANNEL_USB_DP HW_LRADC_CHANNEL(12) | ||
105 | #define HW_LRADC_CHANNEL_USB_DN HW_LRADC_CHANNEL(13) | ||
106 | #define HW_LRADC_CHANNEL_VBG HW_LRADC_CHANNEL(14) | ||
107 | #define HW_LRADC_CHANNEL_5V HW_LRADC_CHANNEL(15) | ||
108 | |||
109 | void imx233_lradc_init(void); | ||
110 | void imx233_lradc_setup_channel(int channel, bool div2, bool acc, int nr_samples, int src); | ||
111 | void imx233_lradc_setup_delay(int dchan, int trigger_lradc, int trigger_delays, | ||
112 | int loop_count, int delay); | ||
113 | void imx233_lradc_kick_channel(int channel); | ||
114 | void imx233_lradc_kick_delay(int dchan); | ||
115 | void imx233_lradc_wait_channel(int channel); | ||
116 | int imx233_lradc_read_channel(int channel); | ||
117 | void imx233_lradc_clear_channel(int channel); | ||
118 | // acquire a virtual channel, returns -1 on timeout, channel otherwise */ | ||
119 | int imx233_lradc_acquire_channel(int timeout); | ||
120 | void imx233_lradc_release_channel(int chan); | ||
121 | // doesn't check that channel is in use! | ||
122 | void imx233_lradc_reserve_channel(int channel); | ||
123 | |||
124 | /* enable sensing and return temperature in kelvin, | ||
125 | * channels must already be configured as nmos and pmos */ | ||
126 | int imx233_lradc_sense_die_temperature(int nmos_chan, int pmos_chan); | ||
127 | |||
128 | #endif /* __lradc_imx233__ */ | ||