diff options
Diffstat (limited to 'firmware/target/arm/s5l8702/gpio-s5l8702.h')
-rw-r--r-- | firmware/target/arm/s5l8702/gpio-s5l8702.h | 145 |
1 files changed, 145 insertions, 0 deletions
diff --git a/firmware/target/arm/s5l8702/gpio-s5l8702.h b/firmware/target/arm/s5l8702/gpio-s5l8702.h new file mode 100644 index 0000000000..00f5ba18f3 --- /dev/null +++ b/firmware/target/arm/s5l8702/gpio-s5l8702.h | |||
@@ -0,0 +1,145 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2014 Cástor Muñoz | ||
11 | * Code based on openiBoot project | ||
12 | * | ||
13 | * This program is free software; you can redistribute it and/or | ||
14 | * modify it under the terms of the GNU General Public License | ||
15 | * as published by the Free Software Foundation; either version 2 | ||
16 | * of the License, or (at your option) any later version. | ||
17 | * | ||
18 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
19 | * KIND, either express or implied. | ||
20 | * | ||
21 | ****************************************************************************/ | ||
22 | #ifndef __GPIO_S5L8702_H__ | ||
23 | #define __GPIO_S5L8702_H__ | ||
24 | #include <stdint.h> | ||
25 | |||
26 | /* This is very preliminary work in progress, ATM this region is called | ||
27 | * system 'alive' because it seems there are similiarities when mixing | ||
28 | * concepts from: | ||
29 | * - s3c2440 datasheet (figure 7-12, Sleep mode) and | ||
30 | * - ARM-DDI-0287B (2.1.8 System Mode Control, Sleep an Doze modes) | ||
31 | * | ||
32 | * Known components: | ||
33 | * - independent clocking | ||
34 | * - 32-bit timer | ||
35 | * - level/edge configurable interrupt controller | ||
36 | * | ||
37 | * | ||
38 | * OSCSEL | ||
39 | * |\ CKSEL | ||
40 | * OSC0 -->| | |\ | ||
41 | * | |--->| | _________ ___________ | ||
42 | * OSC1 -->| | | | | | SClk | | | ||
43 | * |/ | |--->| 1/CKDIV |---------->| 1/ALVTDIV |--> Timer | ||
44 | * | | |_________| | |___________| counter | ||
45 | * PClk --------->| | | ___________ | ||
46 | * |/ | | | | ||
47 | * +-->| 1/UNKDIV |--> Unknown | ||
48 | * |___________| | ||
49 | */ | ||
50 | |||
51 | #define REG32_PTR_T volatile uint32_t * | ||
52 | |||
53 | #define SYSALV_BASE 0x39a00000 | ||
54 | |||
55 | #define ALVCON (*((REG32_PTR_T)(SYSALV_BASE + 0x0))) | ||
56 | #define ALVUNK4 (*((REG32_PTR_T)(SYSALV_BASE + 0x4))) | ||
57 | #define ALVUNK100 (*((REG32_PTR_T)(SYSALV_BASE + 0x100))) | ||
58 | #define ALVUNK104 (*((REG32_PTR_T)(SYSALV_BASE + 0x104))) | ||
59 | |||
60 | |||
61 | /* | ||
62 | * System Alive control register | ||
63 | */ | ||
64 | #define ALVCON_CKSEL_BIT (1 << 25) /* 0 -> S5L8702_OSCx, 1 -> PClk */ | ||
65 | #define ALVCON_CKDIVEN_BIT (1 << 24) /* 0 -> CK divider Off, 1 -> On */ | ||
66 | #define ALVCON_CKDIV_POS 20 /* real_val = reg_val+1 */ | ||
67 | #define ALVCON_CKDIV_MSK 0xf | ||
68 | |||
69 | /* UNKDIV: real_val = reg_val+1 (TBC), valid reg_val=0,1,2 */ | ||
70 | /* experimental: for registers in this region, read/write speed is | ||
71 | * scaled by this divider, so probably it is related with internal | ||
72 | * 'working' frequency. | ||
73 | */ | ||
74 | #define ALVCON_UNKDIV_POS 16 | ||
75 | #define ALVCON_UNKDIV_MSK 0x3 | ||
76 | |||
77 | /* bits[14:1] are UNKNOWN */ | ||
78 | |||
79 | #define ALVCON_OSCSEL_BIT (1 << 0) /* 0 -> OSC0, 1 -> OSC1 */ | ||
80 | |||
81 | |||
82 | /* | ||
83 | * System Alive timer | ||
84 | */ | ||
85 | /* ALVCOM_RUN_BIT starts/stops count on ALVTCNT, counter frequency | ||
86 | * is SClk / ALVTDIV. When count reachs ALVTEND then ALVTSTAT[0] | ||
87 | * and ALVUNK4[0] are set, optionally an interrupt is generated (see | ||
88 | * GPIO_IC below). Writing 1 to ALVTCOM_RST_BIT clears ALVSTAT[0] | ||
89 | * and ALVUNK4[0] and initializes ALVTCNT to zero. | ||
90 | */ | ||
91 | #define ALVTCOM (*((REG32_PTR_T)(SYSALV_BASE + 0x6c))) | ||
92 | #define ALVTCOM_RUN_BIT (1 << 0) /* 0 -> Stop, 1 -> Start */ | ||
93 | #define ALVTCOM_RST_BIT (1 << 1) /* 1 -> Reset */ | ||
94 | |||
95 | #define ALVTEND (*((REG32_PTR_T)(SYSALV_BASE + 0x70))) | ||
96 | #define ALVTDIV (*((REG32_PTR_T)(SYSALV_BASE + 0x74))) | ||
97 | |||
98 | #define ALVTCNT (*((REG32_PTR_T)(SYSALV_BASE + 0x78))) | ||
99 | #define ALVTSTAT (*((REG32_PTR_T)(SYSALV_BASE + 0x7c))) | ||
100 | |||
101 | |||
102 | /* | ||
103 | * s5l8702 GPIO Interrupt Controller | ||
104 | */ | ||
105 | #define GPIOIC_BASE 0x39a00000 /* probably a part of the system controller */ | ||
106 | |||
107 | #define GPIOIC_INTLEVEL(g) (*((REG32_PTR_T)(GPIOIC_BASE + 0x80 + 4*(g)))) | ||
108 | #define GPIOIC_INTSTAT(g) (*((REG32_PTR_T)(GPIOIC_BASE + 0xA0 + 4*(g)))) | ||
109 | #define GPIOIC_INTEN(g) (*((REG32_PTR_T)(GPIOIC_BASE + 0xC0 + 4*(g)))) | ||
110 | #define GPIOIC_INTTYPE(g) (*((REG32_PTR_T)(GPIOIC_BASE + 0xE0 + 4*(g)))) | ||
111 | |||
112 | #define GPIOIC_INTLEVEL_LOW 0 | ||
113 | #define GPIOIC_INTLEVEL_HIGH 1 | ||
114 | |||
115 | #define GPIOIC_INTTYPE_EDGE 0 | ||
116 | #define GPIOIC_INTTYPE_LEVEL 1 | ||
117 | |||
118 | /* 7 groups of 32 interrupts, GPIO pins are seen as 'wired' | ||
119 | * to groups 6..3 in reverse order. | ||
120 | * On group 3, last four bits are dissbled (GPIO 124..127). | ||
121 | * All bits in groups 1 and 2 are disabled (not used). | ||
122 | * On group 0, all bits are masked except bits 0 and 2: | ||
123 | * bit 0: if unmasked, EINT6 is generated when ALVTCNT | ||
124 | * reachs ALVTEND. | ||
125 | * bit 2: if unmasked, EINT6 is generated when USB cable | ||
126 | * is plugged and/or(TBC) unplugged. | ||
127 | * | ||
128 | * IC_GROUP0..6 are connected to EINT6..0 of the VIC. | ||
129 | */ | ||
130 | |||
131 | /* get GPIOIC group and bit for a given GPIO port */ | ||
132 | #define IC_GROUP(n) (6 - (n >> 5)) | ||
133 | #define IC_IDX(n) ((0x18 - (n & 0x18)) | (n & 0x7)) | ||
134 | |||
135 | void gpio_init(void); | ||
136 | void gpio_int_register(int gpio_n, void *isr, | ||
137 | int type, int level, int autoflip); | ||
138 | void gpio_int_enable(int gpio_n); | ||
139 | void gpio_int_disable(int gpio_n); | ||
140 | |||
141 | /* get/set configuration for GPIO groups (0..15) */ | ||
142 | uint32_t gpio_group_get(int group); | ||
143 | void gpio_group_set(int group, uint32_t mask, uint32_t cfg); | ||
144 | |||
145 | #endif /* __GPIO_S5L8702_H__ */ | ||