Skip to content

Commit f52d6d8

Browse files
greentimebrgl
authored andcommitted
gpio: sifive: To get gpio irq offset from device tree data
We can get hwirq number of the gpio by its irq_data->hwirq so that we don't need to add more macros for different platforms. This patch is tested in SiFive Unleashed board and SiFive Unmatched board. Signed-off-by: Greentime Hu <greentime.hu@sifive.com> Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
1 parent 3c6e73e commit f52d6d8

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

drivers/gpio/gpio-sifive.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,14 @@
2929
#define SIFIVE_GPIO_OUTPUT_XOR 0x40
3030

3131
#define SIFIVE_GPIO_MAX 32
32-
#define SIFIVE_GPIO_IRQ_OFFSET 7
3332

3433
struct sifive_gpio {
3534
void __iomem *base;
3635
struct gpio_chip gc;
3736
struct regmap *regs;
3837
unsigned long irq_state;
3938
unsigned int trigger[SIFIVE_GPIO_MAX];
40-
unsigned int irq_parent[SIFIVE_GPIO_MAX];
39+
unsigned int irq_number[SIFIVE_GPIO_MAX];
4140
};
4241

4342
static void sifive_gpio_set_ie(struct sifive_gpio *chip, unsigned int offset)
@@ -144,8 +143,12 @@ static int sifive_gpio_child_to_parent_hwirq(struct gpio_chip *gc,
144143
unsigned int *parent,
145144
unsigned int *parent_type)
146145
{
146+
struct sifive_gpio *chip = gpiochip_get_data(gc);
147+
struct irq_data *d = irq_get_irq_data(chip->irq_number[child]);
148+
147149
*parent_type = IRQ_TYPE_NONE;
148-
*parent = child + SIFIVE_GPIO_IRQ_OFFSET;
150+
*parent = irqd_to_hwirq(d);
151+
149152
return 0;
150153
}
151154

@@ -165,7 +168,7 @@ static int sifive_gpio_probe(struct platform_device *pdev)
165168
struct irq_domain *parent;
166169
struct gpio_irq_chip *girq;
167170
struct sifive_gpio *chip;
168-
int ret, ngpio;
171+
int ret, ngpio, i;
169172

170173
chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL);
171174
if (!chip)
@@ -200,6 +203,9 @@ static int sifive_gpio_probe(struct platform_device *pdev)
200203
return -ENODEV;
201204
}
202205

206+
for (i = 0; i < ngpio; i++)
207+
chip->irq_number[i] = platform_get_irq(pdev, i);
208+
203209
ret = bgpio_init(&chip->gc, dev, 4,
204210
chip->base + SIFIVE_GPIO_INPUT_VAL,
205211
chip->base + SIFIVE_GPIO_OUTPUT_VAL,

0 commit comments

Comments
 (0)