@@ -89,12 +89,12 @@ static inline int i2c_reg_write_word_be(struct device *dev, u16_t dev_addr,
8989}
9090
9191/**
92- * @brief Configure pin or port
92+ * @brief Configure pin ( port not supported)
9393 *
9494 * @param dev Device struct of the SX1509B
95- * @param access_op Access operation (pin or port)
95+ * @param access_op Access operation (pin only, port not supported )
9696 * @param pin The pin number
97- * @param flags Flags of pin or port
97+ * @param flags Flags of pin
9898 *
9999 * @return 0 if successful, failed otherwise
100100 */
@@ -104,84 +104,48 @@ static int gpio_sx1509b_config(struct device *dev, int access_op, u32_t pin,
104104 const struct gpio_sx1509b_config * cfg = dev -> config -> config_info ;
105105 struct gpio_sx1509b_drv_data * drv_data = dev -> driver_data ;
106106 struct gpio_sx1509b_pin_state * pins = & drv_data -> pin_state ;
107- int ret = 0 ;
107+ int ret = - ENOTSUP ;
108108
109109 if (flags & GPIO_INT ) {
110- return - ENOTSUP ;
110+ goto out ;
111+ }
112+
113+ if (access_op != GPIO_ACCESS_BY_PIN ) {
114+ goto out ;
111115 }
112116
113117 k_sem_take (& drv_data -> lock , K_FOREVER );
114118
115- switch (access_op ) {
116- case GPIO_ACCESS_BY_PIN :
117- if ((flags & GPIO_DIR_MASK ) == GPIO_DIR_IN ) {
118- pins -> dir |= BIT (pin );
119- pins -> input_disable &= ~BIT (pin );
120- } else {
121- pins -> dir &= ~BIT (pin );
122- pins -> input_disable |= BIT (pin );
123- }
124- if ((flags & GPIO_PUD_MASK ) == GPIO_PUD_PULL_UP ) {
125- pins -> pull_up |= BIT (pin );
126- } else {
127- pins -> pull_up &= ~BIT (pin );
128- }
129- if ((flags & GPIO_PUD_MASK ) == GPIO_PUD_PULL_DOWN ) {
130- pins -> pull_down |= BIT (pin );
131- } else {
132- pins -> pull_down &= ~BIT (pin );
133- }
134- if ((flags & GPIO_PUD_MASK ) == GPIO_PUD_NORMAL ) {
135- pins -> pull_up &= ~BIT (pin );
136- pins -> pull_down &= ~BIT (pin );
137- }
138- if (flags & GPIO_DS_DISCONNECT_HIGH ) {
139- pins -> open_drain |= BIT (pin );
140- } else {
141- pins -> open_drain &= ~BIT (pin );
142- }
143- if (flags & GPIO_POL_INV ) {
144- pins -> polarity |= BIT (pin );
145- } else {
146- pins -> polarity &= ~BIT (pin );
147- }
148- break ;
149- case GPIO_ACCESS_BY_PORT :
150- if ((flags & GPIO_DIR_MASK ) == GPIO_DIR_IN ) {
151- pins -> dir = 0xffff ;
152- pins -> input_disable = 0x0000 ;
153- } else {
154- pins -> dir = 0x0000 ;
155- pins -> input_disable = 0xffff ;
156- }
157- if ((flags & GPIO_PUD_MASK ) == GPIO_PUD_PULL_UP ) {
158- pins -> pull_up = 0xffff ;
159- } else {
160- pins -> pull_up = 0x0000 ;
161- }
162- if ((flags & GPIO_PUD_MASK ) == GPIO_PUD_PULL_DOWN ) {
163- pins -> pull_down = 0xffff ;
164- } else {
165- pins -> pull_down = 0x0000 ;
166- }
167- if ((flags & GPIO_PUD_MASK ) == GPIO_PUD_NORMAL ) {
168- pins -> pull_up = 0x0000 ;
169- pins -> pull_down = 0x0000 ;
170- }
171- if (flags & GPIO_DS_DISCONNECT_HIGH ) {
172- pins -> open_drain = 0xffff ;
173- } else {
174- pins -> open_drain = 0x0000 ;
175- }
176- if (flags & GPIO_POL_INV ) {
177- pins -> polarity = 0xffff ;
178- } else {
179- pins -> polarity = 0x0000 ;
180- }
181- break ;
182- default :
183- ret = - ENOTSUP ;
184- goto out ;
119+ if ((flags & GPIO_DIR_MASK ) == GPIO_DIR_IN ) {
120+ pins -> dir |= BIT (pin );
121+ pins -> input_disable &= ~BIT (pin );
122+ } else {
123+ pins -> dir &= ~BIT (pin );
124+ pins -> input_disable |= BIT (pin );
125+ }
126+ if ((flags & GPIO_PUD_MASK ) == GPIO_PUD_PULL_UP ) {
127+ pins -> pull_up |= BIT (pin );
128+ } else {
129+ pins -> pull_up &= ~BIT (pin );
130+ }
131+ if ((flags & GPIO_PUD_MASK ) == GPIO_PUD_PULL_DOWN ) {
132+ pins -> pull_down |= BIT (pin );
133+ } else {
134+ pins -> pull_down &= ~BIT (pin );
135+ }
136+ if ((flags & GPIO_PUD_MASK ) == GPIO_PUD_NORMAL ) {
137+ pins -> pull_up &= ~BIT (pin );
138+ pins -> pull_down &= ~BIT (pin );
139+ }
140+ if (flags & GPIO_DS_DISCONNECT_HIGH ) {
141+ pins -> open_drain |= BIT (pin );
142+ } else {
143+ pins -> open_drain &= ~BIT (pin );
144+ }
145+ if (flags & GPIO_POL_INV ) {
146+ pins -> polarity |= BIT (pin );
147+ } else {
148+ pins -> polarity &= ~BIT (pin );
185149 }
186150
187151 ret = i2c_reg_write_word_be (drv_data -> i2c_master , cfg -> i2c_slave_addr ,
0 commit comments