@@ -85,46 +85,62 @@ static int tqmx86_gpio_get(struct gpio_chip *chip, unsigned int offset)
85
85
return !!(tqmx86_gpio_read (gpio , TQMX86_GPIOD ) & BIT (offset ));
86
86
}
87
87
88
+ static void _tqmx86_gpio_set (struct tqmx86_gpio_data * gpio , unsigned int offset ,
89
+ int value )
90
+ __must_hold (& gpio - > spinlock )
91
+ {
92
+ __assign_bit (offset , gpio -> output , value );
93
+ tqmx86_gpio_write (gpio , bitmap_get_value8 (gpio -> output , 0 ), TQMX86_GPIOD );
94
+ }
95
+
88
96
static void tqmx86_gpio_set (struct gpio_chip * chip , unsigned int offset ,
89
97
int value )
90
98
{
91
99
struct tqmx86_gpio_data * gpio = gpiochip_get_data (chip );
92
100
93
101
guard (raw_spinlock_irqsave )(& gpio -> spinlock );
94
102
95
- __assign_bit (offset , gpio -> output , value );
96
- tqmx86_gpio_write (gpio , bitmap_get_value8 (gpio -> output , 0 ), TQMX86_GPIOD );
103
+ _tqmx86_gpio_set (gpio , offset , value );
97
104
}
98
105
99
106
static int tqmx86_gpio_direction_input (struct gpio_chip * chip ,
100
107
unsigned int offset )
101
108
{
102
- /* Direction cannot be changed. Validate is an input. */
103
- if (BIT (offset ) & TQMX86_DIR_INPUT_MASK )
104
- return 0 ;
105
- else
106
- return - EINVAL ;
109
+ struct tqmx86_gpio_data * gpio = gpiochip_get_data (chip );
110
+
111
+ guard (raw_spinlock_irqsave )(& gpio -> spinlock );
112
+
113
+ tqmx86_gpio_clrsetbits (gpio , BIT (offset ), 0 , TQMX86_GPIODD );
114
+
115
+ return 0 ;
107
116
}
108
117
109
118
static int tqmx86_gpio_direction_output (struct gpio_chip * chip ,
110
119
unsigned int offset ,
111
120
int value )
112
121
{
113
- /* Direction cannot be changed, validate is an output */
114
- if (BIT (offset ) & TQMX86_DIR_INPUT_MASK )
115
- return - EINVAL ;
122
+ struct tqmx86_gpio_data * gpio = gpiochip_get_data (chip );
123
+
124
+ guard (raw_spinlock_irqsave )(& gpio -> spinlock );
125
+
126
+ _tqmx86_gpio_set (gpio , offset , value );
127
+ tqmx86_gpio_clrsetbits (gpio , 0 , BIT (offset ), TQMX86_GPIODD );
116
128
117
- tqmx86_gpio_set (chip , offset , value );
118
129
return 0 ;
119
130
}
120
131
121
132
static int tqmx86_gpio_get_direction (struct gpio_chip * chip ,
122
133
unsigned int offset )
123
134
{
124
- if (TQMX86_DIR_INPUT_MASK & BIT (offset ))
125
- return GPIO_LINE_DIRECTION_IN ;
135
+ struct tqmx86_gpio_data * gpio = gpiochip_get_data (chip );
136
+ u8 val ;
137
+
138
+ val = tqmx86_gpio_read (gpio , TQMX86_GPIODD );
139
+
140
+ if (val & BIT (offset ))
141
+ return GPIO_LINE_DIRECTION_OUT ;
126
142
127
- return GPIO_LINE_DIRECTION_OUT ;
143
+ return GPIO_LINE_DIRECTION_IN ;
128
144
}
129
145
130
146
static void tqmx86_gpio_irq_config (struct tqmx86_gpio_data * gpio , int hwirq )
0 commit comments