]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/IA32_flat_GCC_Galileo_Gen_2/Support_Files/GPIO_I2C.h
commit 9f316c246baafa15c542a5aea81a94f26e3d6507
[freertos] / FreeRTOS / Demo / IA32_flat_GCC_Galileo_Gen_2 / Support_Files / GPIO_I2C.h
1 /*--------------------------------------------------------------------\r
2  Copyright(c) 2015 Intel Corporation. All rights reserved.\r
3 \r
4  Redistribution and use in source and binary forms, with or without\r
5  modification, are permitted provided that the following conditions\r
6  are met:\r
7 \r
8  * Redistributions of source code must retain the above copyright\r
9  notice, this list of conditions and the following disclaimer.\r
10  * Redistributions in binary form must reproduce the above copyright\r
11  notice, this list of conditions and the following disclaimer in\r
12  the documentation and/or other materials provided with the\r
13  distribution.\r
14  * Neither the name of Intel Corporation nor the names of its\r
15  contributors may be used to endorse or promote products derived\r
16  from this software without specific prior written permission.\r
17 \r
18  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\r
19  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\r
20  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\r
21  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\r
22  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\r
23  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\r
24  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\r
25  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\r
26  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\r
27  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\r
28  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
29  --------------------------------------------------------------------*/\r
30 \r
31 #ifndef __GPIO_I2C_H__\r
32 #define __GPIO_I2C_H__\r
33 \r
34 #ifdef __cplusplus\r
35         extern "C" {\r
36 #endif\r
37 \r
38 //---------------------------------------------------------------------\r
39 // Any required includes\r
40 //---------------------------------------------------------------------\r
41 #include "galileo_gen_defs.h"\r
42 \r
43 //---------------------------------------------------------------------\r
44 // PCI Configuration Map Register Offsets\r
45 //---------------------------------------------------------------------\r
46 #define PCI_REG_VID             0x00    // Vendor ID Register\r
47 #define PCI_REG_DID             0x02    // Device ID Register\r
48 #define PCI_REG_PCICMD          0x04    // PCI Command Register\r
49 #define PCI_REG_PCISTS          0x06    // PCI Status Register\r
50 #define PCI_REG_RID             0x08    // PCI Revision ID Register\r
51 #define PCI_REG_PI              0x09    // Programming Interface\r
52 #define PCI_REG_SCC             0x0a    // Sub Class Code Register\r
53 #define PCI_REG_BCC             0x0b    // Base Class Code Register\r
54 #define PCI_REG_PMLT            0x0d    // Primary Master Latency Timer\r
55 #define PCI_REG_HDR             0x0e    // Header Type Register\r
56 #define PCI_REG_PBUS            0x18    // Primary Bus Number Register\r
57 #define PCI_REG_SBUS            0x19    // Secondary Bus Number Register\r
58 #define PCI_REG_SUBUS           0x1a    // Subordinate Bus Number Register\r
59 #define PCI_REG_SMLT            0x1b    // Secondary Master Latency Timer\r
60 #define PCI_REG_IOBASE          0x1c    // I/O base Register\r
61 #define PCI_REG_IOLIMIT         0x1d    // I/O Limit Register\r
62 #define PCI_REG_SECSTATUS       0x1e    // Secondary Status Register\r
63 #define PCI_REG_MEMBASE         0x20    // Memory Base Register\r
64 #define PCI_REG_MEMLIMIT        0x22    // Memory Limit Register\r
65 #define PCI_REG_PRE_MEMBASE     0x24    // Prefetchable memory Base register\r
66 #define PCI_REG_PRE_MEMLIMIT    0x26    // Prefetchable memory Limit register\r
67 #define PCI_REG_SVID0           0x2c    // Subsystem Vendor ID low byte\r
68 #define PCI_REG_SVID1           0x2d    // Subsystem Vendor ID high byte\r
69 #define PCI_REG_SID0            0x2e    // Subsystem ID low byte\r
70 #define PCI_REG_SID1            0x2f    // Subsystem ID high byte\r
71 #define PCI_REG_IOBASE_U        0x30    // I/O base Upper Register\r
72 #define PCI_REG_IOLIMIT_U       0x32    // I/O Limit Upper Register\r
73 #define PCI_REG_INTLINE         0x3c    // Interrupt Line Register\r
74 #define PCI_REG_BRIDGE_CNTL     0x3e    // Bridge Control Register\r
75 \r
76 #define IO_PCI_ADDRESS(bus, dev, fn, reg) \\r
77 (0x80000000 | (bus << 16) | (dev << 11) | (fn << 8) | (reg & ~3))\r
78 \r
79 //---------------------------------------------------------------------\r
80 // PCI Read/Write IO Data\r
81 //---------------------------------------------------------------------\r
82 #define IO_PCI_ADDRESS_PORT     0xcf8\r
83 #define IO_PCI_DATA_PORT    0xcfc\r
84 \r
85 //---------------------------------------------------------------------\r
86 // GPIO structures\r
87 //---------------------------------------------------------------------\r
88 \r
89 struct __attribute__ ((__packed__)) BOARD_GPIO_CONTROLLER_CONFIG\r
90 {\r
91 uint32_t  PortADR;                      ///< Value for IOH REG GPIO_SWPORTA_DR.\r
92 uint32_t  PortADir;                     ///< Value for IOH REG GPIO_SWPORTA_DDR.\r
93 uint32_t  IntEn;                        ///< Value for IOH REG GPIO_INTEN.\r
94 uint32_t  IntMask;                      ///< Value for IOH REG GPIO_INTMASK.\r
95 uint32_t  IntType;                      ///< Value for IOH REG GPIO_INTTYPE_LEVEL.\r
96 uint32_t  IntPolarity;                  ///< Value for IOH REG GPIO_INT_POLARITY.\r
97 uint32_t  Debounce;                     ///< Value for IOH REG GPIO_DEBOUNCE.\r
98 uint32_t  LsSync;                       ///< Value for IOH REG GPIO_LS_SYNC.\r
99 };\r
100 \r
101 struct  __attribute__ ((__packed__)) BOARD_LEGACY_GPIO_CONFIG\r
102 {\r
103 uint32_t  CoreWellEnable;               ///< Value for QNC NC Reg R_QNC_GPIO_CGEN_CORE_WELL.\r
104 uint32_t  CoreWellIoSelect;             ///< Value for QNC NC Reg R_QNC_GPIO_CGIO_CORE_WELL.\r
105 uint32_t  CoreWellLvlForInputOrOutput;  ///< Value for QNC NC Reg R_QNC_GPIO_CGLVL_CORE_WELL.\r
106 uint32_t  CoreWellTriggerPositiveEdge;  ///< Value for QNC NC Reg R_QNC_GPIO_CGTPE_CORE_WELL.\r
107 uint32_t  CoreWellTriggerNegativeEdge;  ///< Value for QNC NC Reg R_QNC_GPIO_CGTNE_CORE_WELL.\r
108 uint32_t  CoreWellGPEEnable;            ///< Value for QNC NC Reg R_QNC_GPIO_CGGPE_CORE_WELL.\r
109 uint32_t  CoreWellSMIEnable;            ///< Value for QNC NC Reg R_QNC_GPIO_CGSMI_CORE_WELL.\r
110 uint32_t  CoreWellTriggerStatus;        ///< Value for QNC NC Reg R_QNC_GPIO_CGTS_CORE_WELL.\r
111 uint32_t  CoreWellNMIEnable;            ///< Value for QNC NC Reg R_QNC_GPIO_CGNMIEN_CORE_WELL.\r
112 uint32_t  ResumeWellEnable;             ///< Value for QNC NC Reg R_QNC_GPIO_RGEN_RESUME_WELL.\r
113 uint32_t  ResumeWellIoSelect;           ///< Value for QNC NC Reg R_QNC_GPIO_RGIO_RESUME_WELL.\r
114 uint32_t  ResumeWellLvlForInputOrOutput;///< Value for QNC NC Reg R_QNC_GPIO_RGLVL_RESUME_WELL.\r
115 uint32_t  ResumeWellTriggerPositiveEdge;///< Value for QNC NC Reg R_QNC_GPIO_RGTPE_RESUME_WELL.\r
116 uint32_t  ResumeWellTriggerNegativeEdge;///< Value for QNC NC Reg R_QNC_GPIO_RGTNE_RESUME_WELL.\r
117 uint32_t  ResumeWellGPEEnable;          ///< Value for QNC NC Reg R_QNC_GPIO_RGGPE_RESUME_WELL.\r
118 uint32_t  ResumeWellSMIEnable;          ///< Value for QNC NC Reg R_QNC_GPIO_RGSMI_RESUME_WELL.\r
119 uint32_t  ResumeWellTriggerStatus;      ///< Value for QNC NC Reg R_QNC_GPIO_RGTS_RESUME_WELL.\r
120 uint32_t  ResumeWellNMIEnable;          ///< Value for QNC NC Reg R_QNC_GPIO_RGNMIEN_RESUME_WELL.\r
121 } ;\r
122 \r
123 //---------------------------------------------------------------------\r
124 // GPIO definitions\r
125 //---------------------------------------------------------------------\r
126 #define GALILEO_GEN2_GPIO_CONTROLLER_INITIALIZER  {0x05, 0x05, 0, 0, 0, 0, 0, 0}\r
127 #define GALILEO_GEN2_LEGACY_GPIO_INITIALIZER      {0x03, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, \\r
128                                                        0x03, 0x00, 0x3f, 0x1c, 0x02, 0x00, 0x00, \\r
129                                                        0x00, 0x00, 0x3f, 0x00}\r
130 \r
131 #define PLATFORM_GPIO_CONTROLLER_CONFIG_DEFINITION \\r
132 /* EFI_PLATFORM_TYPE - Galileo Gen 2 */   \\r
133 GALILEO_GEN2_GPIO_CONTROLLER_INITIALIZER ,\\r
134 \r
135 #define PLATFORM_LEGACY_GPIO_CONFIG_DEFINITION \\r
136 /* EFI_PLATFORM_TYPE - Galileo Gen 2 */   \\r
137 GALILEO_GEN2_LEGACY_GPIO_INITIALIZER ,    \\r
138 \r
139 #define IOH_I2C_GPIO_BUS_NUMBER           0x00\r
140 #define IOH_I2C_GPIO_DEVICE_NUMBER        0x15\r
141 #define IOH_I2C_GPIO_FUNCTION_NUMBER      0x02\r
142 \r
143 #define INTEL_VENDOR_ID                                   0x8086\r
144 #define V_IOH_I2C_GPIO_VENDOR_ID          INTEL_VENDOR_ID\r
145 #define V_IOH_I2C_GPIO_DEVICE_ID          0x0934\r
146 \r
147 #define R_IOH_I2C_MEMBAR                  0x10\r
148 #define R_IOH_GPIO_MEMBAR                 0x14\r
149 \r
150 #define GPIO_SWPORTA_DR                   0x00\r
151 #define GPIO_SWPORTA_DDR                  0x04\r
152 #define GPIO_SWPORTB_DR                   0x0C\r
153 #define GPIO_SWPORTB_DDR                  0x10\r
154 #define GPIO_SWPORTC_DR                   0x18\r
155 #define GPIO_SWPORTC_DDR                  0x1C\r
156 #define GPIO_SWPORTD_DR                   0x24\r
157 #define GPIO_SWPORTD_DDR                  0x28\r
158 #define GPIO_INTEN                        0x30\r
159 #define GPIO_INTMASK                      0x34\r
160 #define GPIO_INTTYPE_LEVEL                0x38\r
161 #define GPIO_INT_POLARITY                 0x3C\r
162 #define GPIO_INTSTATUS                    0x40\r
163 #define GPIO_RAW_INTSTATUS                0x44\r
164 #define GPIO_DEBOUNCE                     0x48\r
165 #define GPIO_PORTA_EOI                    0x4C\r
166 #define GPIO_EXT_PORTA                    0x50\r
167 #define GPIO_EXT_PORTB                    0x54\r
168 #define GPIO_EXT_PORTC                    0x58\r
169 #define GPIO_EXT_PORTD                    0x5C\r
170 #define GPIO_LS_SYNC                      0x60\r
171 #define GPIO_CONFIG_REG2                  0x70\r
172 #define GPIO_CONFIG_REG1                  0x74\r
173 \r
174 //---------------------------------------------------------------------\r
175 // GPIO defines for cypress chip\r
176 //---------------------------------------------------------------------\r
177 #define PCAL9555_REG_OUT_PORT0            0x02\r
178 #define PCAL9555_REG_OUT_PORT1            0x03\r
179 #define PCAL9555_REG_CFG_PORT0            0x06\r
180 #define PCAL9555_REG_CFG_PORT1            0x07\r
181 #define PCAL9555_REG_PULL_EN_PORT0        0x46\r
182 #define PCAL9555_REG_PULL_EN_PORT1        0x47\r
183 \r
184 //---------------------------------------------------------------------\r
185 // Three IO Expanders at fixed addresses on Galileo Gen2.\r
186 //---------------------------------------------------------------------\r
187 #define GALILEO_GEN2_IOEXP0_7BIT_SLAVE_ADDR 0x25\r
188 #define GALILEO_GEN2_IOEXP1_7BIT_SLAVE_ADDR 0x26\r
189 #define GALILEO_GEN2_IOEXP2_7BIT_SLAVE_ADDR 0x27\r
190 \r
191 //---------------------------------------------------------------------\r
192 // Legacy GPIO defines\r
193 //---------------------------------------------------------------------\r
194 #define LEGACY_GPIO_BUS_NUMBER                  0\r
195 #define LEGACY_GPIO_DEVICE_NUMBER               31\r
196 #define LEGACY_GPIO_FUNCTION_NUMBER     0\r
197 \r
198 #define R_QNC_LPC_GBA_BASE              0x44\r
199 #define B_QNC_LPC_GPA_BASE_MASK         0x0000FFC0\r
200 \r
201 //---------------------------------------------------------------------\r
202 // I2C structures and enums\r
203 //---------------------------------------------------------------------\r
204  typedef struct\r
205  {\r
206          /// The I2C hardware address to which the I2C device is preassigned or allocated.\r
207          uintn_t I2CDeviceAddress : 10;\r
208  } I2C_DEVICE_ADDRESS;\r
209 \r
210  typedef enum _I2C_ADDR_MODE\r
211  {\r
212          EfiI2CSevenBitAddrMode,\r
213          EfiI2CTenBitAddrMode,\r
214  } I2C_ADDR_MODE;\r
215 \r
216 //---------------------------------------------------------------------\r
217 // I2C definitions\r
218 //---------------------------------------------------------------------\r
219 #define GALILEO_GEN2_FLASH_UPDATE_LED_RESUMEWELL_GPIO   5\r
220 #define R_QNC_GPIO_CGEN_CORE_WELL       0x00\r
221 #define R_QNC_GPIO_CGIO_CORE_WELL       0x04\r
222 #define R_QNC_GPIO_CGLVL_CORE_WELL      0x08\r
223 #define R_QNC_GPIO_CGTPE_CORE_WELL      0x0C   // Core well GPIO Trigger Positive Edge Enable\r
224 #define R_QNC_GPIO_CGTNE_CORE_WELL      0x10   // Core well GPIO Trigger Negative Edge Enable\r
225 #define R_QNC_GPIO_CGGPE_CORE_WELL      0x14   // Core well GPIO GPE Enable\r
226 #define R_QNC_GPIO_CGSMI_CORE_WELL      0x18   // Core well GPIO SMI Enable\r
227 #define R_QNC_GPIO_CGTS_CORE_WELL       0x1C   // Core well GPIO Trigger Status\r
228 #define R_QNC_GPIO_RGEN_RESUME_WELL     0x20\r
229 #define R_QNC_GPIO_RGIO_RESUME_WELL     0x24\r
230 #define R_QNC_GPIO_RGLVL_RESUME_WELL    0x28\r
231 #define R_QNC_GPIO_RGTPE_RESUME_WELL    0x2C   // Resume well GPIO Trigger Positive Edge Enable\r
232 #define R_QNC_GPIO_RGTNE_RESUME_WELL    0x30   // Resume well GPIO Trigger Negative Edge Enable\r
233 #define R_QNC_GPIO_RGGPE_RESUME_WELL    0x34   // Resume well GPIO GPE Enable\r
234 #define R_QNC_GPIO_RGSMI_RESUME_WELL    0x38   // Resume well GPIO SMI Enable\r
235 #define R_QNC_GPIO_RGTS_RESUME_WELL     0x3C   // Resume well GPIO Trigger Status\r
236 #define R_QNC_GPIO_CNMIEN_CORE_WELL     0x40   // Core well GPIO NMI Enable\r
237 #define R_QNC_GPIO_RNMIEN_RESUME_WELL   0x44   // Resume well GPIO NMI Enable\r
238 \r
239 #define B_IOH_I2C_GPIO_MEMBAR_ADDR_MASK    0xFFFFF000    // [31:12].\r
240 #define I2C_REG_CLR_START_DET              0x64          // Clear START DET Interrupt Register\r
241 #define I2C_REG_CLR_STOP_DET               0x60          // Clear STOP DET Interrupt Register\r
242 #define B_I2C_REG_CLR_START_DET            (BIT0)        // Clear START DET Interrupt Register\r
243 #define B_I2C_REG_CLR_STOP_DET             (BIT0)        // Clear STOP DET Interrupt Register\r
244 #define B_I2C_REG_CON_10BITADD_MASTER      (BIT4)        // 7-bit addressing (0) or 10-bit addressing (1)\r
245 #define B_I2C_REG_CON_SPEED                (BIT2+BIT1)   // standard mode (01) or fast mode (10)\r
246 #define I2C_REG_CON                         0x00         // Control Register\r
247 #define I2C_REG_ENABLE                      0x6C         // Enable Register\r
248 #define B_I2C_REG_ENABLE                   (BIT0)        // Enable (1) or disable (0) I2C Controller\r
249 #define I2C_REG_ENABLE_STATUS               0x9C         // Enable Status Register\r
250 #define I2C_REG_CLR_INT                     0x40         // Clear Combined and Individual Interrupt Register\r
251 #define MAX_T_POLL_COUNT                                100\r
252 #define TI2C_POLL                                       25               // microseconds\r
253 #define I2C_REG_CLR_RX_OVER                 0x48         // Clear RX Over Interrupt Register\r
254 #define I2C_REG_CLR_TX_OVER                 0x4C         // Clear TX Over Interrupt Register\r
255 #define I2C_REG_CLR_TX_ABRT                 0x54         // Clear TX ABRT Interrupt Register\r
256 #define I2C_FIFO_SIZE                      16\r
257 #define I2C_REG_TAR                        0x04          // Master Target Address Register\r
258 #define B_I2C_REG_TAR                      (BIT9+BIT8+BIT7+BIT6+BIT5+BIT4+BIT3+BIT2+BIT1+BIT0) // Master Target Address bits\r
259 #define I2C_REG_DATA_CMD                   0x10          // Data Buffer and Command Register\r
260 #define B_I2C_REG_DATA_CMD_RW              (BIT8)        // Data Buffer and Command Register Read/Write bit\r
261 #define I2C_REG_RXFLR                      0x78          // Receive FIFO Level Register\r
262 #define B_I2C_REG_DATA_CMD_STOP            (BIT9)        // Data Buffer and Command Register STOP bit\r
263 #define I2C_REG_RAW_INTR_STAT              0x34          // Raw Interrupt Status Register\r
264 #define I2C_REG_RAW_INTR_STAT_RX_OVER      (BIT1)        // Raw Interrupt Status Register RX Overflow signal status.\r
265 #define I2C_REG_RAW_INTR_STAT_RX_UNDER     (BIT0)        // Raw Interrupt Status Register RX Underflow signal status.\r
266 #define I2C_REG_CLR_RX_UNDER               0x44          // Clear RX Under Interrupt Register\r
267 #define MAX_STOP_DET_POLL_COUNT                    ((1000 * 1000) / TI2C_POLL)  // Extreme for expected Stop detect.\r
268 #define I2C_REG_RAW_INTR_STAT_TX_ABRT      (BIT6)        // Raw Interrupt Status Register TX Abort status.\r
269 #define I2C_REG_RAW_INTR_STAT_TX_OVER      (BIT3)        // Raw Interrupt Status Register TX Overflow signal status.\r
270 #define I2C_REG_RAW_INTR_STAT_STOP_DET     (BIT9)        // Raw Interrupt Status Register STOP_DET signal status.\r
271 \r
272 //---------------------------------------------------------------------\r
273 // GPIO Prototypes\r
274 //---------------------------------------------------------------------\r
275 #define GPIO_OUTPUT     (0)\r
276 #define GPIO_INPUT      (1)\r
277 #define LOW                     (0)\r
278 #define HIGH            (1)\r
279 #define GPIO_NUMBER (7UL)\r
280 \r
281 void vMicroSecondDelay(uint32_t DelayTime);\r
282 void vMilliSecondDelay(uint32_t DelayTime);\r
283 void vGalileoInitializeLegacyGPIO(void);\r
284 void vGalileoInitializeGpioController(void);\r
285 void vGalileoLegacyGPIOInitializationForLED(void);\r
286 void vGalileoSetGPIOBitDirection(uint32_t GPIONumber, uint32_t Direction);\r
287 void vGalileoSetGPIOBitLevel(uint32_t GPIONumber, uint32_t Level);\r
288 void vGalileoBlinkLEDUsingLegacyGPIO(uint32_t Level);\r
289 \r
290 #ifdef __cplusplus\r
291         } /* extern C */\r
292 #endif\r
293 \r
294 #endif /* __GPIO_I2C_H__ */\r
295 \r