Skip to content

Commit b5c506b

Browse files
William Breathitt Graybroonie
authored andcommitted
gpio: 104-dio-48e: Implement struct dio48e_gpio
A private data structure struct dio48e_gpio is introduced to facilitate passage of the regmap and IRQ mask state for the device to the callback dio48e_handle_mask_sync(). This is in preparation for the removal of the handle_mask_sync() map parameter in a subsequent patch. Signed-off-by: William Breathitt Gray <william.gray@linaro.org Reviewed-by: Linus Walleij <linus.walleij@linaro.org Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com Link: https://lore.kernel.org/r/ca710d14a710fee44f7911f2a84b6a55570561ee.1679323449.git.william.gray@linaro.org Signed-off-by: Mark Brown <broonie@kernel.org
1 parent ac9a786 commit b5c506b

1 file changed

Lines changed: 24 additions & 11 deletions

File tree

drivers/gpio/gpio-104-dio-48e.c

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -100,13 +100,23 @@ static const struct regmap_irq dio48e_regmap_irqs[] = {
100100
DIO48E_REGMAP_IRQ(0), DIO48E_REGMAP_IRQ(1),
101101
};
102102

103+
/**
104+
* struct dio48e_gpio - GPIO device private data structure
105+
* @map: Regmap for the device
106+
* @irq_mask: Current IRQ mask state on the device
107+
*/
108+
struct dio48e_gpio {
109+
struct regmap *map;
110+
unsigned int irq_mask;
111+
};
112+
103113
static int dio48e_handle_mask_sync(struct regmap *const map, const int index,
104114
const unsigned int mask_buf_def,
105115
const unsigned int mask_buf,
106116
void *const irq_drv_data)
107117
{
108-
unsigned int *const irq_mask = irq_drv_data;
109-
const unsigned int prev_mask = *irq_mask;
118+
struct dio48e_gpio *const dio48egpio = irq_drv_data;
119+
const unsigned int prev_mask = dio48egpio->irq_mask;
110120
int err;
111121
unsigned int val;
112122

@@ -115,19 +125,19 @@ static int dio48e_handle_mask_sync(struct regmap *const map, const int index,
115125
return 0;
116126

117127
/* remember the current mask for the next mask sync */
118-
*irq_mask = mask_buf;
128+
dio48egpio->irq_mask = mask_buf;
119129

120130
/* if all previously masked, enable interrupts when unmasking */
121131
if (prev_mask == mask_buf_def) {
122-
err = regmap_write(map, DIO48E_CLEAR_INTERRUPT, 0x00);
132+
err = regmap_write(dio48egpio->map, DIO48E_CLEAR_INTERRUPT, 0x00);
123133
if (err)
124134
return err;
125-
return regmap_write(map, DIO48E_ENABLE_INTERRUPT, 0x00);
135+
return regmap_write(dio48egpio->map, DIO48E_ENABLE_INTERRUPT, 0x00);
126136
}
127137

128138
/* if all are currently masked, disable interrupts */
129139
if (mask_buf == mask_buf_def)
130-
return regmap_read(map, DIO48E_DISABLE_INTERRUPT, &val);
140+
return regmap_read(dio48egpio->map, DIO48E_DISABLE_INTERRUPT, &val);
131141

132142
return 0;
133143
}
@@ -168,7 +178,7 @@ static int dio48e_probe(struct device *dev, unsigned int id)
168178
struct regmap *map;
169179
int err;
170180
struct regmap_irq_chip *chip;
171-
unsigned int irq_mask;
181+
struct dio48e_gpio *dio48egpio;
172182
struct regmap_irq_chip_data *chip_data;
173183

174184
if (!devm_request_region(dev, base[id], DIO48E_EXTENT, name)) {
@@ -186,12 +196,14 @@ static int dio48e_probe(struct device *dev, unsigned int id)
186196
return dev_err_probe(dev, PTR_ERR(map),
187197
"Unable to initialize register map\n");
188198

189-
chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL);
190-
if (!chip)
199+
dio48egpio = devm_kzalloc(dev, sizeof(*dio48egpio), GFP_KERNEL);
200+
if (!dio48egpio)
191201
return -ENOMEM;
192202

193-
chip->irq_drv_data = devm_kzalloc(dev, sizeof(irq_mask), GFP_KERNEL);
194-
if (!chip->irq_drv_data)
203+
dio48egpio->map = map;
204+
205+
chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL);
206+
if (!chip)
195207
return -ENOMEM;
196208

197209
chip->name = name;
@@ -202,6 +214,7 @@ static int dio48e_probe(struct device *dev, unsigned int id)
202214
chip->irqs = dio48e_regmap_irqs;
203215
chip->num_irqs = ARRAY_SIZE(dio48e_regmap_irqs);
204216
chip->handle_mask_sync = dio48e_handle_mask_sync;
217+
chip->irq_drv_data = dio48egpio;
205218

206219
/* Initialize to prevent spurious interrupts before we're ready */
207220
err = dio48e_irq_init_hw(map);

0 commit comments

Comments
 (0)