@@ -35,27 +35,28 @@ static int gpio_mmio32_config(struct device *dev, int access_op,
3535 struct gpio_mmio32_context * context = dev -> driver_data ;
3636 const struct gpio_mmio32_config * config = context -> config ;
3737
38- if (flags & GPIO_INT ) {
39- return - ENOTSUP ;
40- }
41-
42- if (access_op != GPIO_ACCESS_BY_PIN ) {
43- return - ENOTSUP ;
44- }
45-
4638 if ((config -> mask & (1 << pin )) == 0 ) {
4739 return - EINVAL ; /* Pin not in our validity mask */
4840 }
4941
50- if (flags & ~(GPIO_DIR_MASK | GPIO_POL_MASK )) {
42+ if (flags & ~(GPIO_INPUT | GPIO_OUTPUT |
43+ GPIO_OUTPUT_INIT_LOW | GPIO_OUTPUT_INIT_HIGH |
44+ GPIO_ACTIVE_LOW )) {
5145 /* We ignore direction and fake polarity, rest is unsupported */
5246 return - ENOTSUP ;
5347 }
5448
55- if ((flags & GPIO_POL_MASK ) == GPIO_POL_INV ) {
56- context -> invert |= (1 << pin );
57- } else {
58- context -> invert &= ~(1 << pin );
49+ if ((flags & GPIO_OUTPUT ) != 0 ) {
50+ unsigned int key ;
51+ volatile u32_t * reg = config -> reg ;
52+
53+ key = irq_lock ();
54+ if ((flags & GPIO_OUTPUT_INIT_HIGH ) != 0 ) {
55+ * reg = (* reg | (1 << pin ));
56+ } else if ((flags & GPIO_OUTPUT_INIT_LOW ) != 0 ) {
57+ * reg = (* reg & (config -> mask & ~(1 << pin )));
58+ }
59+ irq_unlock (key );
5960 }
6061
6162 return 0 ;
@@ -68,7 +69,7 @@ static int gpio_mmio32_write(struct device *dev, int access_op,
6869 const struct gpio_mmio32_config * config = context -> config ;
6970 volatile u32_t * reg = config -> reg ;
7071 u32_t mask = config -> mask ;
71- u32_t invert = context -> invert ;
72+ u32_t invert = context -> common . invert ;
7273 unsigned int key ;
7374
7475 if (access_op == GPIO_ACCESS_BY_PIN ) {
@@ -96,7 +97,7 @@ static int gpio_mmio32_read(struct device *dev, int access_op,
9697 const struct gpio_mmio32_config * config = context -> config ;
9798 u32_t bits ;
9899
99- bits = (* config -> reg ^ context -> invert ) & config -> mask ;
100+ bits = (* config -> reg ^ context -> common . invert ) & config -> mask ;
100101 if (access_op == GPIO_ACCESS_BY_PIN ) {
101102 * value = (bits >> pin ) & 1 ;
102103 if ((config -> mask & (1 << pin )) == 0 ) {
@@ -109,10 +110,107 @@ static int gpio_mmio32_read(struct device *dev, int access_op,
109110 return 0 ;
110111}
111112
113+ static int gpio_mmio32_port_get_raw (struct device * dev , u32_t * value )
114+ {
115+ struct gpio_mmio32_context * context = dev -> driver_data ;
116+ const struct gpio_mmio32_config * config = context -> config ;
117+
118+ * value = * config -> reg & config -> mask ;
119+
120+ return 0 ;
121+ }
122+
123+ static int gpio_mmio32_port_set_masked_raw (struct device * dev , u32_t mask ,
124+ u32_t value )
125+ {
126+ struct gpio_mmio32_context * context = dev -> driver_data ;
127+ const struct gpio_mmio32_config * config = context -> config ;
128+ volatile u32_t * reg = config -> reg ;
129+ unsigned int key ;
130+
131+ mask &= config -> mask ;
132+ value &= mask ;
133+
134+ /* Update pin state atomically */
135+ key = irq_lock ();
136+ * reg = (* reg & ~mask ) | value ;
137+ irq_unlock (key );
138+
139+ return 0 ;
140+ }
141+
142+ static int gpio_mmio32_port_set_bits_raw (struct device * dev , u32_t mask )
143+ {
144+ struct gpio_mmio32_context * context = dev -> driver_data ;
145+ const struct gpio_mmio32_config * config = context -> config ;
146+ volatile u32_t * reg = config -> reg ;
147+ unsigned int key ;
148+
149+ mask &= config -> mask ;
150+
151+ /* Update pin state atomically */
152+ key = irq_lock ();
153+ * reg = (* reg | mask );
154+ irq_unlock (key );
155+
156+ return 0 ;
157+ }
158+
159+ static int gpio_mmio32_port_clear_bits_raw (struct device * dev , u32_t mask )
160+ {
161+ struct gpio_mmio32_context * context = dev -> driver_data ;
162+ const struct gpio_mmio32_config * config = context -> config ;
163+ volatile u32_t * reg = config -> reg ;
164+ unsigned int key ;
165+
166+ mask &= config -> mask ;
167+
168+ /* Update pin state atomically */
169+ key = irq_lock ();
170+ * reg = (* reg & ~mask );
171+ irq_unlock (key );
172+
173+ return 0 ;
174+ }
175+
176+ static int gpio_mmio32_port_toggle_bits (struct device * dev , u32_t mask )
177+ {
178+ struct gpio_mmio32_context * context = dev -> driver_data ;
179+ const struct gpio_mmio32_config * config = context -> config ;
180+ volatile u32_t * reg = config -> reg ;
181+ unsigned int key ;
182+
183+ mask &= config -> mask ;
184+
185+ /* Update pin state atomically */
186+ key = irq_lock ();
187+ * reg = (* reg ^ mask );
188+ irq_unlock (key );
189+
190+ return 0 ;
191+ }
192+
193+ static int gpio_mmio32_pin_interrupt_configure (struct device * dev ,
194+ unsigned int pin , enum gpio_int_mode mode ,
195+ enum gpio_int_trig trig )
196+ {
197+ if (mode != GPIO_INT_MODE_DISABLED ) {
198+ return - ENOTSUP ;
199+ }
200+
201+ return 0 ;
202+ }
203+
112204static const struct gpio_driver_api gpio_mmio32_api = {
113205 .config = gpio_mmio32_config ,
114206 .write = gpio_mmio32_write ,
115207 .read = gpio_mmio32_read ,
208+ .port_get_raw = gpio_mmio32_port_get_raw ,
209+ .port_set_masked_raw = gpio_mmio32_port_set_masked_raw ,
210+ .port_set_bits_raw = gpio_mmio32_port_set_bits_raw ,
211+ .port_clear_bits_raw = gpio_mmio32_port_clear_bits_raw ,
212+ .port_toggle_bits = gpio_mmio32_port_toggle_bits ,
213+ .pin_interrupt_configure = gpio_mmio32_pin_interrupt_configure ,
116214};
117215
118216int gpio_mmio32_init (struct device * dev )
0 commit comments