1515#include <linux/platform_device.h>
1616#include <linux/regmap.h>
1717#include <linux/seq_file.h>
18+ #include <linux/types.h>
1819
1920#define CRYSTALCOVE_GPIO_NUM 16
2021#define CRYSTALCOVE_VGPIO_NUM 95
@@ -110,8 +111,7 @@ static inline int to_reg(int gpio, enum ctrl_register reg_type)
110111 return reg + gpio % 8 ;
111112}
112113
113- static void crystalcove_update_irq_mask (struct crystalcove_gpio * cg ,
114- int gpio )
114+ static void crystalcove_update_irq_mask (struct crystalcove_gpio * cg , int gpio )
115115{
116116 u8 mirqs0 = gpio < 8 ? MGPIO0IRQS0 : MGPIO1IRQS0 ;
117117 int mask = BIT (gpio % 8 );
@@ -140,8 +140,7 @@ static int crystalcove_gpio_dir_in(struct gpio_chip *chip, unsigned int gpio)
140140 return regmap_write (cg -> regmap , reg , CTLO_INPUT_SET );
141141}
142142
143- static int crystalcove_gpio_dir_out (struct gpio_chip * chip , unsigned int gpio ,
144- int value )
143+ static int crystalcove_gpio_dir_out (struct gpio_chip * chip , unsigned int gpio , int value )
145144{
146145 struct crystalcove_gpio * cg = gpiochip_get_data (chip );
147146 int reg = to_reg (gpio , CTRL_OUT );
@@ -168,8 +167,7 @@ static int crystalcove_gpio_get(struct gpio_chip *chip, unsigned int gpio)
168167 return val & 0x1 ;
169168}
170169
171- static void crystalcove_gpio_set (struct gpio_chip * chip ,
172- unsigned int gpio , int value )
170+ static void crystalcove_gpio_set (struct gpio_chip * chip , unsigned int gpio , int value )
173171{
174172 struct crystalcove_gpio * cg = gpiochip_get_data (chip );
175173 int reg = to_reg (gpio , CTRL_OUT );
@@ -185,10 +183,10 @@ static void crystalcove_gpio_set(struct gpio_chip *chip,
185183
186184static int crystalcove_irq_type (struct irq_data * data , unsigned int type )
187185{
188- struct crystalcove_gpio * cg =
189- gpiochip_get_data ( irq_data_get_irq_chip_data ( data ) );
186+ struct crystalcove_gpio * cg = gpiochip_get_data ( irq_data_get_irq_chip_data ( data ));
187+ irq_hw_number_t hwirq = irqd_to_hwirq ( data );
190188
191- if (data -> hwirq >= CRYSTALCOVE_GPIO_NUM )
189+ if (hwirq >= CRYSTALCOVE_GPIO_NUM )
192190 return 0 ;
193191
194192 switch (type ) {
@@ -215,57 +213,64 @@ static int crystalcove_irq_type(struct irq_data *data, unsigned int type)
215213
216214static void crystalcove_bus_lock (struct irq_data * data )
217215{
218- struct crystalcove_gpio * cg =
219- gpiochip_get_data (irq_data_get_irq_chip_data (data ));
216+ struct crystalcove_gpio * cg = gpiochip_get_data (irq_data_get_irq_chip_data (data ));
220217
221218 mutex_lock (& cg -> buslock );
222219}
223220
224221static void crystalcove_bus_sync_unlock (struct irq_data * data )
225222{
226- struct crystalcove_gpio * cg =
227- gpiochip_get_data (irq_data_get_irq_chip_data (data ));
228- int gpio = data -> hwirq ;
223+ struct crystalcove_gpio * cg = gpiochip_get_data (irq_data_get_irq_chip_data (data ));
224+ irq_hw_number_t hwirq = irqd_to_hwirq (data );
229225
230226 if (cg -> update & UPDATE_IRQ_TYPE )
231- crystalcove_update_irq_ctrl (cg , gpio );
227+ crystalcove_update_irq_ctrl (cg , hwirq );
232228 if (cg -> update & UPDATE_IRQ_MASK )
233- crystalcove_update_irq_mask (cg , gpio );
229+ crystalcove_update_irq_mask (cg , hwirq );
234230 cg -> update = 0 ;
235231
236232 mutex_unlock (& cg -> buslock );
237233}
238234
239235static void crystalcove_irq_unmask (struct irq_data * data )
240236{
241- struct crystalcove_gpio * cg =
242- gpiochip_get_data (irq_data_get_irq_chip_data (data ));
237+ struct gpio_chip * gc = irq_data_get_irq_chip_data (data );
238+ struct crystalcove_gpio * cg = gpiochip_get_data (gc );
239+ irq_hw_number_t hwirq = irqd_to_hwirq (data );
243240
244- if (data -> hwirq < CRYSTALCOVE_GPIO_NUM ) {
245- cg -> set_irq_mask = false;
246- cg -> update |= UPDATE_IRQ_MASK ;
247- }
241+ if (hwirq >= CRYSTALCOVE_GPIO_NUM )
242+ return ;
243+
244+ gpiochip_enable_irq (gc , hwirq );
245+
246+ cg -> set_irq_mask = false;
247+ cg -> update |= UPDATE_IRQ_MASK ;
248248}
249249
250250static void crystalcove_irq_mask (struct irq_data * data )
251251{
252- struct crystalcove_gpio * cg =
253- gpiochip_get_data (irq_data_get_irq_chip_data (data ));
252+ struct gpio_chip * gc = irq_data_get_irq_chip_data (data );
253+ struct crystalcove_gpio * cg = gpiochip_get_data (gc );
254+ irq_hw_number_t hwirq = irqd_to_hwirq (data );
254255
255- if (data -> hwirq < CRYSTALCOVE_GPIO_NUM ) {
256- cg -> set_irq_mask = true;
257- cg -> update |= UPDATE_IRQ_MASK ;
258- }
256+ if (hwirq >= CRYSTALCOVE_GPIO_NUM )
257+ return ;
258+
259+ cg -> set_irq_mask = true;
260+ cg -> update |= UPDATE_IRQ_MASK ;
261+
262+ gpiochip_disable_irq (gc , hwirq );
259263}
260264
261- static struct irq_chip crystalcove_irqchip = {
265+ static const struct irq_chip crystalcove_irqchip = {
262266 .name = "Crystal Cove" ,
263267 .irq_mask = crystalcove_irq_mask ,
264268 .irq_unmask = crystalcove_irq_unmask ,
265269 .irq_set_type = crystalcove_irq_type ,
266270 .irq_bus_lock = crystalcove_bus_lock ,
267271 .irq_bus_sync_unlock = crystalcove_bus_sync_unlock ,
268- .flags = IRQCHIP_SKIP_SET_WAKE ,
272+ .flags = IRQCHIP_SKIP_SET_WAKE | IRQCHIP_IMMUTABLE ,
273+ GPIOCHIP_IRQ_RESOURCE_HELPERS ,
269274};
270275
271276static irqreturn_t crystalcove_gpio_irq_handler (int irq , void * data )
@@ -293,8 +298,7 @@ static irqreturn_t crystalcove_gpio_irq_handler(int irq, void *data)
293298 return IRQ_HANDLED ;
294299}
295300
296- static void crystalcove_gpio_dbg_show (struct seq_file * s ,
297- struct gpio_chip * chip )
301+ static void crystalcove_gpio_dbg_show (struct seq_file * s , struct gpio_chip * chip )
298302{
299303 struct crystalcove_gpio * cg = gpiochip_get_data (chip );
300304 int gpio , offset ;
@@ -353,7 +357,7 @@ static int crystalcove_gpio_probe(struct platform_device *pdev)
353357 cg -> regmap = pmic -> regmap ;
354358
355359 girq = & cg -> chip .irq ;
356- girq -> chip = & crystalcove_irqchip ;
360+ gpio_irq_chip_set_chip ( girq , & crystalcove_irqchip ) ;
357361 /* This will let us handle the parent IRQ in the driver */
358362 girq -> parent_handler = NULL ;
359363 girq -> num_parents = 0 ;
0 commit comments