1 /*
2  * Copyright (C) 2016 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef __PLAT_I2C_H
18 #define __PLAT_I2C_H
19 
20 #include <gpio.h>
21 #include <platform.h>
22 #include <plat/inc/cmsis.h>
23 #include <plat/inc/gpio.h>
24 #include <plat/inc/plat.h>
25 
26 struct StmI2cDmaCfg {
27     uint8_t channel;
28     uint8_t stream;
29 };
30 
31 struct StmI2cGpioCfg {
32     uint8_t gpioNum;
33     enum StmGpioAltFunc func;
34 };
35 
36 struct StmI2cBoardCfg {
37     struct StmI2cGpioCfg gpioScl;
38     struct StmI2cGpioCfg gpioSda;
39 
40     enum StmGpioSpeed gpioSpeed;
41     enum GpioPullMode gpioPull;
42 
43     struct StmI2cDmaCfg dmaRx;
44     struct StmI2cDmaCfg dmaTx;
45 
46     enum PlatSleepDevID sleepDev;
47 };
48 
49 #define I2C_DMA_BUS         0
50 
51 #define I2C1_GPIO_SCL_PB6   { .gpioNum = GPIO_PB(6), .func = GPIO_AF_I2C1 }
52 #define I2C1_GPIO_SCL_PB8   { .gpioNum = GPIO_PB(8), .func = GPIO_AF_I2C1 }
53 #define I2C1_GPIO_SDA_PB7   { .gpioNum = GPIO_PB(7), .func = GPIO_AF_I2C1 }
54 #define I2C1_GPIO_SDA_PB9   { .gpioNum = GPIO_PB(9), .func = GPIO_AF_I2C1 }
55 #define I2C1_DMA_RX_CFG_A   { .channel = 1, .stream = 0 }
56 #define I2C1_DMA_RX_CFG_B   { .channel = 1, .stream = 5 }
57 #define I2C1_DMA_TX_CFG_A   { .channel = 0, .stream = 1 }
58 #define I2C1_DMA_TX_CFG_B   { .channel = 1, .stream = 6 }
59 #define I2C1_DMA_TX_CFG_C   { .channel = 1, .stream = 7 }
60 
61 #define I2C2_GPIO_SCL_PB10  { .gpioNum = GPIO_PB(10), .func = GPIO_AF_I2C2_A }
62 #define I2C2_GPIO_SDA_PB3   { .gpioNum = GPIO_PB(3), .func = GPIO_AF_I2C2_B }
63 #define I2C2_GPIO_SDA_PB9   { .gpioNum = GPIO_PB(9), .func = GPIO_AF_I2C2_B }
64 #define I2C2_GPIO_SDA_PB11  { .gpioNum = GPIO_PB(11), .func = GPIO_AF_I2C2_A }
65 #define I2C2_DMA_RX_CFG_A   { .channel = 7, .stream = 2 }
66 #define I2C2_DMA_RX_CFG_B   { .channel = 7, .stream = 3 }
67 #define I2C2_DMA_TX_CFG     { .channel = 7, .stream = 7 }
68 
69 #define I2C3_GPIO_SCL_PA8   { .gpioNum = GPIO_PA(8), .func = GPIO_AF_I2C3_A }
70 #define I2C3_GPIO_SDA_PB4   { .gpioNum = GPIO_PB(4), .func = GPIO_AF_I2C3_B }
71 #define I2C3_GPIO_SDA_PC9   { .gpioNum = GPIO_PC(9), .func = GPIO_AF_I2C3_A }
72 #define I2C3_DMA_RX_CFG_A   { .channel = 1, .stream = 1 }
73 #define I2C3_DMA_RX_CFG_B   { .channel = 3, .stream = 2 }
74 #define I2C3_DMA_TX_CFG_A   { .channel = 3, .stream = 4 }
75 #define I2C3_DMA_TX_CFG_B   { .channel = 6, .stream = 5 }
76 
77 extern const struct StmI2cBoardCfg *boardStmI2cCfg(uint8_t busId);
78 
79 #endif /* __PLAT_I2C_H */
80