12
12
#include <linux/init.h>
13
13
#include <linux/mod_devicetable.h>
14
14
#include <linux/platform_device.h>
15
+ #include <linux/property.h>
15
16
#include <linux/regmap.h>
16
17
#include <linux/spinlock.h>
17
18
30
31
#define MPFS_GPIO_TYPE_INT_LEVEL_HIGH 0x00
31
32
#define MPFS_GPIO_TYPE_INT_MASK GENMASK(7, 5)
32
33
#define MPFS_IRQ_REG 0x80
34
+
33
35
#define MPFS_INP_REG 0x84
36
+ #define COREGPIO_INP_REG 0x90
34
37
#define MPFS_OUTP_REG 0x88
38
+ #define COREGPIO_OUTP_REG 0xA0
39
+
40
+ struct mpfs_gpio_reg_offsets {
41
+ u8 inp ;
42
+ u8 outp ;
43
+ };
35
44
36
45
struct mpfs_gpio_chip {
37
46
struct regmap * regs ;
47
+ const struct mpfs_gpio_reg_offsets * offsets ;
38
48
struct gpio_chip gc ;
39
49
};
40
50
@@ -60,7 +70,7 @@ static int mpfs_gpio_direction_output(struct gpio_chip *gc, unsigned int gpio_in
60
70
61
71
regmap_update_bits (mpfs_gpio -> regs , MPFS_GPIO_CTRL (gpio_index ),
62
72
MPFS_GPIO_DIR_MASK , MPFS_GPIO_EN_IN );
63
- regmap_update_bits (mpfs_gpio -> regs , MPFS_OUTP_REG , BIT (gpio_index ),
73
+ regmap_update_bits (mpfs_gpio -> regs , mpfs_gpio -> offsets -> outp , BIT (gpio_index ),
64
74
value << gpio_index );
65
75
66
76
return 0 ;
@@ -84,9 +94,9 @@ static int mpfs_gpio_get(struct gpio_chip *gc, unsigned int gpio_index)
84
94
struct mpfs_gpio_chip * mpfs_gpio = gpiochip_get_data (gc );
85
95
86
96
if (mpfs_gpio_get_direction (gc , gpio_index ) == GPIO_LINE_DIRECTION_OUT )
87
- return regmap_test_bits (mpfs_gpio -> regs , MPFS_OUTP_REG , BIT (gpio_index ));
97
+ return regmap_test_bits (mpfs_gpio -> regs , mpfs_gpio -> offsets -> outp , BIT (gpio_index ));
88
98
else
89
- return regmap_test_bits (mpfs_gpio -> regs , MPFS_INP_REG , BIT (gpio_index ));
99
+ return regmap_test_bits (mpfs_gpio -> regs , mpfs_gpio -> offsets -> inp , BIT (gpio_index ));
90
100
}
91
101
92
102
static void mpfs_gpio_set (struct gpio_chip * gc , unsigned int gpio_index , int value )
@@ -95,7 +105,7 @@ static void mpfs_gpio_set(struct gpio_chip *gc, unsigned int gpio_index, int val
95
105
96
106
mpfs_gpio_get (gc , gpio_index );
97
107
98
- regmap_update_bits (mpfs_gpio -> regs , MPFS_OUTP_REG , BIT (gpio_index ),
108
+ regmap_update_bits (mpfs_gpio -> regs , mpfs_gpio -> offsets -> outp , BIT (gpio_index ),
99
109
value << gpio_index );
100
110
101
111
mpfs_gpio_get (gc , gpio_index );
@@ -113,6 +123,8 @@ static int mpfs_gpio_probe(struct platform_device *pdev)
113
123
if (!mpfs_gpio )
114
124
return - ENOMEM ;
115
125
126
+ mpfs_gpio -> offsets = device_get_match_data (& pdev -> dev );
127
+
116
128
base = devm_platform_ioremap_resource (pdev , 0 );
117
129
if (IS_ERR (base ))
118
130
return dev_err_probe (dev , PTR_ERR (base ), "failed to ioremap memory resource\n" );
@@ -145,8 +157,24 @@ static int mpfs_gpio_probe(struct platform_device *pdev)
145
157
return devm_gpiochip_add_data (dev , & mpfs_gpio -> gc , mpfs_gpio );
146
158
}
147
159
160
+ static const struct mpfs_gpio_reg_offsets mpfs_reg_offsets = {
161
+ .inp = MPFS_INP_REG ,
162
+ .outp = MPFS_OUTP_REG ,
163
+ };
164
+
165
+ static const struct mpfs_gpio_reg_offsets coregpio_reg_offsets = {
166
+ .inp = COREGPIO_INP_REG ,
167
+ .outp = COREGPIO_OUTP_REG ,
168
+ };
169
+
148
170
static const struct of_device_id mpfs_gpio_of_ids [] = {
149
- { .compatible = "microchip,mpfs-gpio" , },
171
+ {
172
+ .compatible = "microchip,mpfs-gpio" ,
173
+ .data = & mpfs_reg_offsets ,
174
+ }, {
175
+ .compatible = "microchip,coregpio-rtl-v3" ,
176
+ .data = & coregpio_reg_offsets ,
177
+ },
150
178
{ /* end of list */ }
151
179
};
152
180
0 commit comments