* [PATCH 0/5] Add Aspeed G7 sgpio support
@ 2026-01-17 11:17 Billy Tsai
2026-01-17 11:17 ` [PATCH 1/5] gpio: aspeed-sgpio: Change the macro to support deferred probe Billy Tsai
` (5 more replies)
0 siblings, 6 replies; 12+ messages in thread
From: Billy Tsai @ 2026-01-17 11:17 UTC (permalink / raw)
To: Linus Walleij, Bartosz Golaszewski, Joel Stanley, Andrew Jeffery,
Rob Herring, Krzysztof Kozlowski, Conor Dooley
Cc: linux-gpio, linux-arm-kernel, linux-aspeed, linux-kernel,
Andrew Jeffery, devicetree, bmc-sw, Billy Tsai
The Aspeed 7th generation SoC features two SGPIO master controllers: both
with 256 serial inputs and outputs. The main difference from the previous
generation is that the control logic has been updated to support
per-pin control, allowing each pin to have its own 32-bit register for
configuring value, interrupt type, and more.
This patch serial also add low-level operations (llops) to abstract the
register access for SGPIO registers making it easier to extend the driver
to support different hardware register layouts.
Signed-off-by: Billy Tsai <billy_tsai@aspeedtech.com>
---
Billy Tsai (5):
gpio: aspeed-sgpio: Change the macro to support deferred probe
gpio: aspeed-sgpio: Remove unused bank name field
gpio: aspeed-sgpio: Create llops to handle hardware access
dt-bindings: gpio: aspeed,sgpio: Support ast2700
gpio: aspeed-sgpio: Support G7 Aspeed sgpiom controller
.../devicetree/bindings/gpio/aspeed,sgpio.yaml | 4 +-
drivers/gpio/gpio-aspeed-sgpio.c | 364 +++++++++++++--------
2 files changed, 228 insertions(+), 140 deletions(-)
---
base-commit: dd9b004b7ff3289fb7bae35130c0a5c0537266af
change-id: 20251223-upstream_sgpio-70d815c64a19
Best regards,
--
Billy Tsai <billy_tsai@aspeedtech.com>
^ permalink raw reply [flat|nested] 12+ messages in thread* [PATCH 1/5] gpio: aspeed-sgpio: Change the macro to support deferred probe 2026-01-17 11:17 [PATCH 0/5] Add Aspeed G7 sgpio support Billy Tsai @ 2026-01-17 11:17 ` Billy Tsai 2026-01-17 11:17 ` [PATCH 2/5] gpio: aspeed-sgpio: Remove unused bank name field Billy Tsai ` (4 subsequent siblings) 5 siblings, 0 replies; 12+ messages in thread From: Billy Tsai @ 2026-01-17 11:17 UTC (permalink / raw) To: Linus Walleij, Bartosz Golaszewski, Joel Stanley, Andrew Jeffery, Rob Herring, Krzysztof Kozlowski, Conor Dooley Cc: linux-gpio, linux-arm-kernel, linux-aspeed, linux-kernel, Andrew Jeffery, devicetree, bmc-sw, Billy Tsai Use module_platform_driver() to replace module_platform_driver_probe(). The former utilizes platform_driver_register(), which allows the driver to defer probing when it doesn't acquire the necessary resources due to probe order. In contrast, the latter uses __platform_driver_probe(), which includes the comment "Note that this is incompatible with deferred probing." Since our SGPIO driver requires access to the clock resource, the former is more suitable. Signed-off-by: Billy Tsai <billy_tsai@aspeedtech.com> --- drivers/gpio/gpio-aspeed-sgpio.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/gpio/gpio-aspeed-sgpio.c b/drivers/gpio/gpio-aspeed-sgpio.c index 7622f9e9f54a..318cd0e39741 100644 --- a/drivers/gpio/gpio-aspeed-sgpio.c +++ b/drivers/gpio/gpio-aspeed-sgpio.c @@ -516,7 +516,7 @@ static const struct of_device_id aspeed_sgpio_of_table[] = { MODULE_DEVICE_TABLE(of, aspeed_sgpio_of_table); -static int __init aspeed_sgpio_probe(struct platform_device *pdev) +static int aspeed_sgpio_probe(struct platform_device *pdev) { u32 nr_gpios, sgpio_freq, sgpio_clk_div, gpio_cnt_regval, pin_mask; const struct aspeed_sgpio_pdata *pdata; @@ -611,11 +611,12 @@ static int __init aspeed_sgpio_probe(struct platform_device *pdev) } static struct platform_driver aspeed_sgpio_driver = { + .probe = aspeed_sgpio_probe, .driver = { .name = KBUILD_MODNAME, .of_match_table = aspeed_sgpio_of_table, }, }; -module_platform_driver_probe(aspeed_sgpio_driver, aspeed_sgpio_probe); +module_platform_driver(aspeed_sgpio_driver); MODULE_DESCRIPTION("Aspeed Serial GPIO Driver"); -- 2.34.1 ^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH 2/5] gpio: aspeed-sgpio: Remove unused bank name field 2026-01-17 11:17 [PATCH 0/5] Add Aspeed G7 sgpio support Billy Tsai 2026-01-17 11:17 ` [PATCH 1/5] gpio: aspeed-sgpio: Change the macro to support deferred probe Billy Tsai @ 2026-01-17 11:17 ` Billy Tsai 2026-01-17 11:17 ` [PATCH 3/5] gpio: aspeed-sgpio: Create llops to handle hardware access Billy Tsai ` (3 subsequent siblings) 5 siblings, 0 replies; 12+ messages in thread From: Billy Tsai @ 2026-01-17 11:17 UTC (permalink / raw) To: Linus Walleij, Bartosz Golaszewski, Joel Stanley, Andrew Jeffery, Rob Herring, Krzysztof Kozlowski, Conor Dooley Cc: linux-gpio, linux-arm-kernel, linux-aspeed, linux-kernel, Andrew Jeffery, devicetree, bmc-sw, Billy Tsai Drops the names array from the bank struct and its initializers, as it is unused in the driver. Signed-off-by: Billy Tsai <billy_tsai@aspeedtech.com> --- drivers/gpio/gpio-aspeed-sgpio.c | 5 ----- 1 file changed, 5 deletions(-) diff --git a/drivers/gpio/gpio-aspeed-sgpio.c b/drivers/gpio/gpio-aspeed-sgpio.c index 318cd0e39741..a96ed6d8a55d 100644 --- a/drivers/gpio/gpio-aspeed-sgpio.c +++ b/drivers/gpio/gpio-aspeed-sgpio.c @@ -43,7 +43,6 @@ struct aspeed_sgpio_bank { u16 rdata_reg; u16 irq_regs; u16 tolerance_regs; - const char names[4][3]; }; /* @@ -59,28 +58,24 @@ static const struct aspeed_sgpio_bank aspeed_sgpio_banks[] = { .rdata_reg = 0x0070, .irq_regs = 0x0004, .tolerance_regs = 0x0018, - .names = { "A", "B", "C", "D" }, }, { .val_regs = 0x001C, .rdata_reg = 0x0074, .irq_regs = 0x0020, .tolerance_regs = 0x0034, - .names = { "E", "F", "G", "H" }, }, { .val_regs = 0x0038, .rdata_reg = 0x0078, .irq_regs = 0x003C, .tolerance_regs = 0x0050, - .names = { "I", "J", "K", "L" }, }, { .val_regs = 0x0090, .rdata_reg = 0x007C, .irq_regs = 0x0094, .tolerance_regs = 0x00A8, - .names = { "M", "N", "O", "P" }, }, }; -- 2.34.1 ^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH 3/5] gpio: aspeed-sgpio: Create llops to handle hardware access 2026-01-17 11:17 [PATCH 0/5] Add Aspeed G7 sgpio support Billy Tsai 2026-01-17 11:17 ` [PATCH 1/5] gpio: aspeed-sgpio: Change the macro to support deferred probe Billy Tsai 2026-01-17 11:17 ` [PATCH 2/5] gpio: aspeed-sgpio: Remove unused bank name field Billy Tsai @ 2026-01-17 11:17 ` Billy Tsai 2026-01-17 15:46 ` Andrew Lunn 2026-01-17 11:17 ` [PATCH 4/5] dt-bindings: gpio: aspeed,sgpio: Support ast2700 Billy Tsai ` (2 subsequent siblings) 5 siblings, 1 reply; 12+ messages in thread From: Billy Tsai @ 2026-01-17 11:17 UTC (permalink / raw) To: Linus Walleij, Bartosz Golaszewski, Joel Stanley, Andrew Jeffery, Rob Herring, Krzysztof Kozlowski, Conor Dooley Cc: linux-gpio, linux-arm-kernel, linux-aspeed, linux-kernel, Andrew Jeffery, devicetree, bmc-sw, Billy Tsai Add low-level operations (llops) to abstract the register access for SGPIO registers. With this abstraction layer, the driver can separate the hardware and software logic, making it easier to extend the driver to support different hardware register layouts. Signed-off-by: Billy Tsai <billy_tsai@aspeedtech.com> --- drivers/gpio/gpio-aspeed-sgpio.c | 239 ++++++++++++++++++--------------------- 1 file changed, 111 insertions(+), 128 deletions(-) diff --git a/drivers/gpio/gpio-aspeed-sgpio.c b/drivers/gpio/gpio-aspeed-sgpio.c index a96ed6d8a55d..a2401f4e8e37 100644 --- a/drivers/gpio/gpio-aspeed-sgpio.c +++ b/drivers/gpio/gpio-aspeed-sgpio.c @@ -27,6 +27,7 @@ struct aspeed_sgpio_pdata { const u32 pin_mask; + const struct aspeed_sgpio_llops *llops; }; struct aspeed_sgpio { @@ -36,6 +37,7 @@ struct aspeed_sgpio { raw_spinlock_t lock; void __iomem *base; int irq; + const struct aspeed_sgpio_pdata *pdata; }; struct aspeed_sgpio_bank { @@ -90,6 +92,15 @@ enum aspeed_sgpio_reg { reg_tolerance, }; +struct aspeed_sgpio_llops { + void (*reg_bit_set)(struct aspeed_sgpio *gpio, unsigned int offset, + const enum aspeed_sgpio_reg reg, bool val); + bool (*reg_bit_get)(struct aspeed_sgpio *gpio, unsigned int offset, + const enum aspeed_sgpio_reg reg); + int (*reg_bank_get)(struct aspeed_sgpio *gpio, unsigned int offset, + const enum aspeed_sgpio_reg reg); +}; + #define GPIO_VAL_VALUE 0x00 #define GPIO_IRQ_ENABLE 0x00 #define GPIO_IRQ_TYPE0 0x04 @@ -97,9 +108,9 @@ enum aspeed_sgpio_reg { #define GPIO_IRQ_TYPE2 0x0C #define GPIO_IRQ_STATUS 0x10 -static void __iomem *bank_reg(struct aspeed_sgpio *gpio, - const struct aspeed_sgpio_bank *bank, - const enum aspeed_sgpio_reg reg) +static void __iomem *aspeed_sgpio_g4_bank_reg(struct aspeed_sgpio *gpio, + const struct aspeed_sgpio_bank *bank, + const enum aspeed_sgpio_reg reg) { switch (reg) { case reg_val: @@ -165,14 +176,13 @@ static bool aspeed_sgpio_is_input(unsigned int offset) static int aspeed_sgpio_get(struct gpio_chip *gc, unsigned int offset) { struct aspeed_sgpio *gpio = gpiochip_get_data(gc); - const struct aspeed_sgpio_bank *bank = to_bank(offset); enum aspeed_sgpio_reg reg; int rc = 0; guard(raw_spinlock_irqsave)(&gpio->lock); reg = aspeed_sgpio_is_input(offset) ? reg_val : reg_rdata; - rc = !!(ioread32(bank_reg(gpio, bank, reg)) & GPIO_BIT(offset)); + rc = gpio->pdata->llops->reg_bit_get(gpio, offset, reg); return rc; } @@ -180,26 +190,11 @@ static int aspeed_sgpio_get(struct gpio_chip *gc, unsigned int offset) static int sgpio_set_value(struct gpio_chip *gc, unsigned int offset, int val) { struct aspeed_sgpio *gpio = gpiochip_get_data(gc); - const struct aspeed_sgpio_bank *bank = to_bank(offset); - void __iomem *addr_r, *addr_w; - u32 reg = 0; if (aspeed_sgpio_is_input(offset)) return -EINVAL; - /* Since this is an output, read the cached value from rdata, then - * update val. */ - addr_r = bank_reg(gpio, bank, reg_rdata); - addr_w = bank_reg(gpio, bank, reg_val); - - reg = ioread32(addr_r); - - if (val) - reg |= GPIO_BIT(offset); - else - reg &= ~GPIO_BIT(offset); - - iowrite32(reg, addr_w); + gpio->pdata->llops->reg_bit_set(gpio, offset, reg_val, val); return 0; } @@ -238,69 +233,34 @@ static int aspeed_sgpio_get_direction(struct gpio_chip *gc, unsigned int offset) return !!aspeed_sgpio_is_input(offset); } -static void irqd_to_aspeed_sgpio_data(struct irq_data *d, - struct aspeed_sgpio **gpio, - const struct aspeed_sgpio_bank **bank, - u32 *bit, int *offset) -{ - struct aspeed_sgpio *internal; - - *offset = irqd_to_hwirq(d); - internal = irq_data_get_irq_chip_data(d); - WARN_ON(!internal); - - *gpio = internal; - *bank = to_bank(*offset); - *bit = GPIO_BIT(*offset); -} static void aspeed_sgpio_irq_ack(struct irq_data *d) { - const struct aspeed_sgpio_bank *bank; - struct aspeed_sgpio *gpio; - void __iomem *status_addr; - int offset; - u32 bit; - - irqd_to_aspeed_sgpio_data(d, &gpio, &bank, &bit, &offset); - - status_addr = bank_reg(gpio, bank, reg_irq_status); + struct aspeed_sgpio *gpio = irq_data_get_irq_chip_data(d); + int offset = irqd_to_hwirq(d); guard(raw_spinlock_irqsave)(&gpio->lock); - iowrite32(bit, status_addr); + gpio->pdata->llops->reg_bit_set(gpio, offset, reg_irq_status, 1); } static void aspeed_sgpio_irq_set_mask(struct irq_data *d, bool set) { - const struct aspeed_sgpio_bank *bank; - struct aspeed_sgpio *gpio; - u32 reg, bit; - void __iomem *addr; - int offset; - - irqd_to_aspeed_sgpio_data(d, &gpio, &bank, &bit, &offset); - addr = bank_reg(gpio, bank, reg_irq_enable); + struct aspeed_sgpio *gpio = irq_data_get_irq_chip_data(d); + int offset = irqd_to_hwirq(d); /* Unmasking the IRQ */ if (set) - gpiochip_enable_irq(&gpio->chip, irqd_to_hwirq(d)); - - scoped_guard(raw_spinlock_irqsave, &gpio->lock) { - reg = ioread32(addr); - if (set) - reg |= bit; - else - reg &= ~bit; - - iowrite32(reg, addr); + gpiochip_enable_irq(&gpio->chip, offset); + scoped_guard(raw_spinlock_irqsave, &gpio->lock) + { + gpio->pdata->llops->reg_bit_set(gpio, offset, reg_irq_enable, + set); } /* Masking the IRQ */ if (!set) - gpiochip_disable_irq(&gpio->chip, irqd_to_hwirq(d)); - - + gpiochip_disable_irq(&gpio->chip, offset); } static void aspeed_sgpio_irq_mask(struct irq_data *d) @@ -318,30 +278,25 @@ static int aspeed_sgpio_set_type(struct irq_data *d, unsigned int type) u32 type0 = 0; u32 type1 = 0; u32 type2 = 0; - u32 bit, reg; - const struct aspeed_sgpio_bank *bank; irq_flow_handler_t handler; - struct aspeed_sgpio *gpio; - void __iomem *addr; - int offset; - - irqd_to_aspeed_sgpio_data(d, &gpio, &bank, &bit, &offset); + struct aspeed_sgpio *gpio = irq_data_get_irq_chip_data(d); + int offset = irqd_to_hwirq(d); switch (type & IRQ_TYPE_SENSE_MASK) { case IRQ_TYPE_EDGE_BOTH: - type2 |= bit; + type2 = 1; fallthrough; case IRQ_TYPE_EDGE_RISING: - type0 |= bit; + type0 = 1; fallthrough; case IRQ_TYPE_EDGE_FALLING: handler = handle_edge_irq; break; case IRQ_TYPE_LEVEL_HIGH: - type0 |= bit; + type0 = 1; fallthrough; case IRQ_TYPE_LEVEL_LOW: - type1 |= bit; + type1 = 1; handler = handle_level_irq; break; default: @@ -349,20 +304,9 @@ static int aspeed_sgpio_set_type(struct irq_data *d, unsigned int type) } scoped_guard(raw_spinlock_irqsave, &gpio->lock) { - addr = bank_reg(gpio, bank, reg_irq_type0); - reg = ioread32(addr); - reg = (reg & ~bit) | type0; - iowrite32(reg, addr); - - addr = bank_reg(gpio, bank, reg_irq_type1); - reg = ioread32(addr); - reg = (reg & ~bit) | type1; - iowrite32(reg, addr); - - addr = bank_reg(gpio, bank, reg_irq_type2); - reg = ioread32(addr); - reg = (reg & ~bit) | type2; - iowrite32(reg, addr); + gpio->pdata->llops->reg_bit_set(gpio, offset, reg_irq_type0, type0); + gpio->pdata->llops->reg_bit_set(gpio, offset, reg_irq_type1, type1); + gpio->pdata->llops->reg_bit_set(gpio, offset, reg_irq_type2, type2); } irq_set_handler_locked(d, handler); @@ -374,16 +318,14 @@ static void aspeed_sgpio_irq_handler(struct irq_desc *desc) { struct gpio_chip *gc = irq_desc_get_handler_data(desc); struct irq_chip *ic = irq_desc_get_chip(desc); - struct aspeed_sgpio *data = gpiochip_get_data(gc); + struct aspeed_sgpio *gpio = gpiochip_get_data(gc); unsigned int i, p; unsigned long reg; chained_irq_enter(ic, desc); for (i = 0; i < ARRAY_SIZE(aspeed_sgpio_banks); i++) { - const struct aspeed_sgpio_bank *bank = &aspeed_sgpio_banks[i]; - - reg = ioread32(bank_reg(data, bank, reg_irq_status)); + reg = gpio->pdata->llops->reg_bank_get(gpio, i << 6, reg_irq_status); for_each_set_bit(p, ®, 32) generic_handle_domain_irq(gc->irq.domain, (i * 32 + p) * 2); @@ -394,12 +336,8 @@ static void aspeed_sgpio_irq_handler(struct irq_desc *desc) static void aspeed_sgpio_irq_print_chip(struct irq_data *d, struct seq_file *p) { - const struct aspeed_sgpio_bank *bank; - struct aspeed_sgpio *gpio; - u32 bit; - int offset; + struct aspeed_sgpio *gpio = irq_data_get_irq_chip_data(d); - irqd_to_aspeed_sgpio_data(d, &gpio, &bank, &bit, &offset); seq_puts(p, dev_name(gpio->dev)); } @@ -417,7 +355,6 @@ static int aspeed_sgpio_setup_irqs(struct aspeed_sgpio *gpio, struct platform_device *pdev) { int rc, i; - const struct aspeed_sgpio_bank *bank; struct gpio_irq_chip *irq; rc = platform_get_irq(pdev, 0); @@ -427,12 +364,11 @@ static int aspeed_sgpio_setup_irqs(struct aspeed_sgpio *gpio, gpio->irq = rc; /* Disable IRQ and clear Interrupt status registers for all SGPIO Pins. */ - for (i = 0; i < ARRAY_SIZE(aspeed_sgpio_banks); i++) { - bank = &aspeed_sgpio_banks[i]; + for (i = 0; i < gpio->chip.ngpio; i += 2) { /* disable irq enable bits */ - iowrite32(0x00000000, bank_reg(gpio, bank, reg_irq_enable)); + gpio->pdata->llops->reg_bit_set(gpio, i, reg_irq_enable, 0); /* clear status bits */ - iowrite32(0xffffffff, bank_reg(gpio, bank, reg_irq_status)); + gpio->pdata->llops->reg_bit_set(gpio, i, reg_irq_status, 1); } irq = &gpio->chip.irq; @@ -446,42 +382,90 @@ static int aspeed_sgpio_setup_irqs(struct aspeed_sgpio *gpio, irq->num_parents = 1; /* Apply default IRQ settings */ - for (i = 0; i < ARRAY_SIZE(aspeed_sgpio_banks); i++) { - bank = &aspeed_sgpio_banks[i]; + for (i = 0; i < gpio->chip.ngpio; i += 2) { /* set falling or level-low irq */ - iowrite32(0x00000000, bank_reg(gpio, bank, reg_irq_type0)); + gpio->pdata->llops->reg_bit_set(gpio, i, reg_irq_type0, 0); /* trigger type is edge */ - iowrite32(0x00000000, bank_reg(gpio, bank, reg_irq_type1)); + gpio->pdata->llops->reg_bit_set(gpio, i, reg_irq_type1, 0); /* single edge trigger */ - iowrite32(0x00000000, bank_reg(gpio, bank, reg_irq_type2)); + gpio->pdata->llops->reg_bit_set(gpio, i, reg_irq_type2, 0); } return 0; } +static void aspeed_sgpio_g4_reg_bit_set(struct aspeed_sgpio *gpio, unsigned int offset, + const enum aspeed_sgpio_reg reg, bool val) +{ + const struct aspeed_sgpio_bank *bank = to_bank(offset); + void __iomem *addr = aspeed_sgpio_g4_bank_reg(gpio, bank, reg); + u32 temp; + + if (reg == reg_val) { + /* Since this is an output, read the cached value from rdata, then update val. */ + addr = aspeed_sgpio_g4_bank_reg(gpio, bank, reg_rdata); + temp = ioread32(addr); + if (val) + temp |= GPIO_BIT(offset); + else + temp &= ~GPIO_BIT(offset); + + addr = aspeed_sgpio_g4_bank_reg(gpio, bank, reg_val); + iowrite32(temp, addr); + } else if (reg == reg_irq_status) { + if (val) + iowrite32(GPIO_BIT(offset), addr); + } else { + /* When setting other registers, we read from the register itself */ + temp = ioread32(addr); + if (val) + temp |= GPIO_BIT(offset); + else + temp &= ~GPIO_BIT(offset); + iowrite32(temp, addr); + } +} + +static bool aspeed_sgpio_g4_reg_bit_get(struct aspeed_sgpio *gpio, unsigned int offset, + const enum aspeed_sgpio_reg reg) +{ + const struct aspeed_sgpio_bank *bank = to_bank(offset); + void __iomem *addr = aspeed_sgpio_g4_bank_reg(gpio, bank, reg); + + return !!(ioread32(addr) & GPIO_BIT(offset)); +} + +static int aspeed_sgpio_g4_reg_bank_get(struct aspeed_sgpio *gpio, unsigned int offset, + const enum aspeed_sgpio_reg reg) +{ + const struct aspeed_sgpio_bank *bank = to_bank(offset); + void __iomem *addr = aspeed_sgpio_g4_bank_reg(gpio, bank, reg); + + if (reg == reg_irq_status) + return ioread32(addr); + else + return -EOPNOTSUPP; +} + +static const struct aspeed_sgpio_llops aspeed_sgpio_g4_llops = { + .reg_bit_set = aspeed_sgpio_g4_reg_bit_set, + .reg_bit_get = aspeed_sgpio_g4_reg_bit_get, + .reg_bank_get = aspeed_sgpio_g4_reg_bank_get, +}; + static const struct aspeed_sgpio_pdata ast2400_sgpio_pdata = { .pin_mask = GENMASK(9, 6), + .llops = &aspeed_sgpio_g4_llops, }; static int aspeed_sgpio_reset_tolerance(struct gpio_chip *chip, unsigned int offset, bool enable) { struct aspeed_sgpio *gpio = gpiochip_get_data(chip); - void __iomem *reg; - u32 val; - - reg = bank_reg(gpio, to_bank(offset), reg_tolerance); guard(raw_spinlock_irqsave)(&gpio->lock); - val = readl(reg); - - if (enable) - val |= GPIO_BIT(offset); - else - val &= ~GPIO_BIT(offset); - - writel(val, reg); + gpio->pdata->llops->reg_bit_set(gpio, offset, reg_tolerance, enable); return 0; } @@ -500,6 +484,7 @@ static int aspeed_sgpio_set_config(struct gpio_chip *chip, unsigned int offset, static const struct aspeed_sgpio_pdata ast2600_sgpiom_pdata = { .pin_mask = GENMASK(10, 6), + .llops = &aspeed_sgpio_g4_llops, }; static const struct of_device_id aspeed_sgpio_of_table[] = { @@ -514,7 +499,6 @@ MODULE_DEVICE_TABLE(of, aspeed_sgpio_of_table); static int aspeed_sgpio_probe(struct platform_device *pdev) { u32 nr_gpios, sgpio_freq, sgpio_clk_div, gpio_cnt_regval, pin_mask; - const struct aspeed_sgpio_pdata *pdata; struct aspeed_sgpio *gpio; unsigned long apb_freq; int rc; @@ -529,12 +513,11 @@ static int aspeed_sgpio_probe(struct platform_device *pdev) gpio->dev = &pdev->dev; - pdata = device_get_match_data(&pdev->dev); - if (!pdata) + gpio->pdata = device_get_match_data(&pdev->dev); + if (!gpio->pdata) return -EINVAL; - pin_mask = pdata->pin_mask; - + pin_mask = gpio->pdata->pin_mask; rc = device_property_read_u32(&pdev->dev, "ngpios", &nr_gpios); if (rc < 0) { dev_err(&pdev->dev, "Could not read ngpios property\n"); -- 2.34.1 ^ permalink raw reply related [flat|nested] 12+ messages in thread
* Re: [PATCH 3/5] gpio: aspeed-sgpio: Create llops to handle hardware access 2026-01-17 11:17 ` [PATCH 3/5] gpio: aspeed-sgpio: Create llops to handle hardware access Billy Tsai @ 2026-01-17 15:46 ` Andrew Lunn 2026-01-19 2:39 ` Billy Tsai [not found] ` <OSQPR06MB725219B6ED261DBB4E8BC33D8B88A@OSQPR06MB7252.apcprd06.prod.outlook.com> 0 siblings, 2 replies; 12+ messages in thread From: Andrew Lunn @ 2026-01-17 15:46 UTC (permalink / raw) To: Billy Tsai Cc: Linus Walleij, Bartosz Golaszewski, Joel Stanley, Andrew Jeffery, Rob Herring, Krzysztof Kozlowski, Conor Dooley, linux-gpio, linux-arm-kernel, linux-aspeed, linux-kernel, Andrew Jeffery, devicetree, bmc-sw On Sat, Jan 17, 2026 at 07:17:10PM +0800, Billy Tsai wrote: > Add low-level operations (llops) to abstract the register access for SGPIO > registers. With this abstraction layer, the driver can separate the > hardware and software logic, making it easier to extend the driver to > support different hardware register layouts. With a quick look at the code, it appears the register numbers stay the same? Is that true? I think you have reinvented regmap. > @@ -318,30 +278,25 @@ static int aspeed_sgpio_set_type(struct irq_data *d, unsigned int type) > u32 type0 = 0; > u32 type1 = 0; > u32 type2 = 0; > - u32 bit, reg; > - const struct aspeed_sgpio_bank *bank; > irq_flow_handler_t handler; > - struct aspeed_sgpio *gpio; > - void __iomem *addr; > - int offset; > - > - irqd_to_aspeed_sgpio_data(d, &gpio, &bank, &bit, &offset); > + struct aspeed_sgpio *gpio = irq_data_get_irq_chip_data(d); > + int offset = irqd_to_hwirq(d); > > switch (type & IRQ_TYPE_SENSE_MASK) { > case IRQ_TYPE_EDGE_BOTH: > - type2 |= bit; > + type2 = 1; > fallthrough; > case IRQ_TYPE_EDGE_RISING: > - type0 |= bit; > + type0 = 1; > fallthrough; > case IRQ_TYPE_EDGE_FALLING: > handler = handle_edge_irq; > break; > case IRQ_TYPE_LEVEL_HIGH: > - type0 |= bit; > + type0 = 1; > fallthrough; > case IRQ_TYPE_LEVEL_LOW: > - type1 |= bit; > + type1 = 1; > handler = handle_level_irq; > break; This change is not obviously correct to me. It is not about abstracting register accesses, what you actually write to the registers appears to of changed. Maybe you could add a refactoring patch first which does this change, with a commit message explaining it, and then insert the register abstraction? > @@ -374,16 +318,14 @@ static void aspeed_sgpio_irq_handler(struct irq_desc *desc) > { > struct gpio_chip *gc = irq_desc_get_handler_data(desc); > struct irq_chip *ic = irq_desc_get_chip(desc); > - struct aspeed_sgpio *data = gpiochip_get_data(gc); > + struct aspeed_sgpio *gpio = gpiochip_get_data(gc); This rename does not belong in this patch. You want lots of small patches, each doing one logical thing, with a good commit message, and obviously correct. Changes like this make it a lot less obviously correct. > /* Disable IRQ and clear Interrupt status registers for all SGPIO Pins. */ > - for (i = 0; i < ARRAY_SIZE(aspeed_sgpio_banks); i++) { > - bank = &aspeed_sgpio_banks[i]; > + for (i = 0; i < gpio->chip.ngpio; i += 2) { Why are ARRAY_SIZE() gone? There probably is a good reason, so doing this in a patch of its own, with a commit message explaining "Why?" would make this easier to review. Andrew ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH 3/5] gpio: aspeed-sgpio: Create llops to handle hardware access 2026-01-17 15:46 ` Andrew Lunn @ 2026-01-19 2:39 ` Billy Tsai 2026-01-19 3:37 ` Billy Tsai [not found] ` <OSQPR06MB725219B6ED261DBB4E8BC33D8B88A@OSQPR06MB7252.apcprd06.prod.outlook.com> 1 sibling, 1 reply; 12+ messages in thread From: Billy Tsai @ 2026-01-19 2:39 UTC (permalink / raw) To: Andrew Lunn Cc: Linus Walleij, Bartosz Golaszewski, Joel Stanley, Andrew Jeffery, Rob Herring, Krzysztof Kozlowski, Conor Dooley, linux-gpio@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-aspeed@lists.ozlabs.org, linux-kernel@vger.kernel.org, Andrew Jeffery, devicetree@vger.kernel.org, BMC-SW Thanks for the detailed review — your comments are very helpful. > > Add low-level operations (llops) to abstract the register access for SGPIO > > registers. With this abstraction layer, the driver can separate the > > hardware and software logic, making it easier to extend the driver to > > support different hardware register layouts. > With a quick look at the code, it appears the register numbers stay > the same? Is that true? > I think you have reinvented regmap. Yes, the register numbers remain unchanged for ASPEED G4 in this patch. The intent of introducing the llops abstraction is to decouple the driver logic from the underlying register layout so that we can support SoCs with different SGPIO register organizations in the future. The actual AST2700-specific support will be added in a subsequent patch. We did consider regmap. However, llops is intended to abstract not only register access but also layout-specific bit mapping, which is difficult to express cleanly with a flat regmap interface. > > @@ -318,30 +278,25 @@ static int aspeed_sgpio_set_type(struct irq_data *d, unsigned int type) > > u32 type0 = 0; > > u32 type1 = 0; > > u32 type2 = 0; > > - u32 bit, reg; > > - const struct aspeed_sgpio_bank *bank; > > irq_flow_handler_t handler; > > - struct aspeed_sgpio *gpio; > > - void __iomem *addr; > > - int offset; > > - > > - irqd_to_aspeed_sgpio_data(d, &gpio, &bank, &bit, &offset); > > + struct aspeed_sgpio *gpio = irq_data_get_irq_chip_data(d); > > + int offset = irqd_to_hwirq(d); > > > > switch (type & IRQ_TYPE_SENSE_MASK) { > > case IRQ_TYPE_EDGE_BOTH: > > - type2 |= bit; > > + type2 = 1; > > fallthrough; > > case IRQ_TYPE_EDGE_RISING: > > - type0 |= bit; > > + type0 = 1; > > fallthrough; > > case IRQ_TYPE_EDGE_FALLING: > > handler = handle_edge_irq; > > break; > > case IRQ_TYPE_LEVEL_HIGH: > > - type0 |= bit; > > + type0 = 1; > > fallthrough; > > case IRQ_TYPE_LEVEL_LOW: > > - type1 |= bit; > > + type1 = 1; > > handler = handle_level_irq; > > break; > This change is not obviously correct to me. It is not about > abstracting register accesses, what you actually write to the > registers appears to of changed. Maybe you could add a refactoring > patch first which does this change, with a commit message explaining > it, and then insert the register abstraction? You’re right — viewed together, this change is not obviously correct and makes the refactoring harder to review. While the llops interface is designed to handle bit positioning internally (changing the semantics from passing a bitmask to passing a value), combining this semantic change with the abstraction refactoring increases review complexity. To address this, I will respin the series and split it into: 1. a preparatory refactoring patch that introduces the llops helpers without changing behavior, and 2. a follow-up patch that switches callers to the new value-based interface, with a commit message explicitly explaining the semantic change. > > @@ -374,16 +318,14 @@ static void aspeed_sgpio_irq_handler(struct irq_desc *desc) > > { > > struct gpio_chip *gc = irq_desc_get_handler_data(desc); > > struct irq_chip *ic = irq_desc_get_chip(desc); > > - struct aspeed_sgpio *data = gpiochip_get_data(gc); > > + struct aspeed_sgpio *gpio = gpiochip_get_data(gc); > This rename does not belong in this patch. You want lots of small > patches, each doing one logical thing, with a good commit message, and > obviously correct. Changes like this make it a lot less obviously > correct. Agreed. I will revert the rename from this patch and handle it separately if needed. > > /* Disable IRQ and clear Interrupt status registers for all SGPIO Pins. */ > > - for (i = 0; i < ARRAY_SIZE(aspeed_sgpio_banks); i++) { > > - bank = &aspeed_sgpio_banks[i]; > > + for (i = 0; i < gpio->chip.ngpio; i += 2) { > Why are ARRAY_SIZE() gone? There probably is a good reason, so doing > this in a patch of its own, with a commit message explaining "Why?" > would make this easier to review. The change from ARRAY_SIZE(aspeed_sgpio_banks) to gpio->chip.ngpio is required because AST2700 does not use a fixed bank-based register layout. Using ngpio removes the dependency on a static bank array and allows the IRQ handling code to work with SoCs that have different SGPIO organizations. I agree this change deserves a dedicated patch with a commit message explaining the rationale, and I will split it out accordingly. Thanks again for the review. I’ll send a revised version with the changes above. Billy Tsai ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH 3/5] gpio: aspeed-sgpio: Create llops to handle hardware access 2026-01-19 2:39 ` Billy Tsai @ 2026-01-19 3:37 ` Billy Tsai 0 siblings, 0 replies; 12+ messages in thread From: Billy Tsai @ 2026-01-19 3:37 UTC (permalink / raw) To: Andrew Lunn Cc: Linus Walleij, Bartosz Golaszewski, Joel Stanley, Andrew Jeffery, Rob Herring, Krzysztof Kozlowski, Conor Dooley, linux-gpio@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-aspeed@lists.ozlabs.org, linux-kernel@vger.kernel.org, Andrew Jeffery, devicetree@vger.kernel.org, BMC-SW > > > @@ -318,30 +278,25 @@ static int aspeed_sgpio_set_type(struct irq_data *d, unsigned int type) > > > u32 type0 = 0; > > > u32 type1 = 0; > > > u32 type2 = 0; > > > - u32 bit, reg; > > > - const struct aspeed_sgpio_bank *bank; > > > irq_flow_handler_t handler; > > > - struct aspeed_sgpio *gpio; > > > - void __iomem *addr; > > > - int offset; > > > - > > > - irqd_to_aspeed_sgpio_data(d, &gpio, &bank, &bit, &offset); > > > + struct aspeed_sgpio *gpio = irq_data_get_irq_chip_data(d); > > > + int offset = irqd_to_hwirq(d); > > > > > > switch (type & IRQ_TYPE_SENSE_MASK) { > > > case IRQ_TYPE_EDGE_BOTH: > > > - type2 |= bit; > > > + type2 = 1; > > > fallthrough; > > > case IRQ_TYPE_EDGE_RISING: > > > - type0 |= bit; > > > + type0 = 1; > > > fallthrough; > > > case IRQ_TYPE_EDGE_FALLING: > > > handler = handle_edge_irq; > > > break; > > > case IRQ_TYPE_LEVEL_HIGH: > > > - type0 |= bit; > > > + type0 = 1; > > > fallthrough; > > > case IRQ_TYPE_LEVEL_LOW: > > > - type1 |= bit; > > > + type1 = 1; > > > handler = handle_level_irq; > > > break; > > This change is not obviously correct to me. It is not about > > abstracting register accesses, what you actually write to the > > registers appears to of changed. Maybe you could add a refactoring > > patch first which does this change, with a commit message explaining > > it, and then insert the register abstraction? > You’re right — viewed together, this change is not obviously correct and makes > the refactoring harder to review. > > While the llops interface is designed to handle bit positioning internally > (changing the semantics from passing a bitmask to passing a value), combining > this semantic change with the abstraction refactoring increases review > complexity. > > To address this, I will respin the series and split it into: > 1. a preparatory refactoring patch that introduces the llops helpers without > changing behavior, and > 2. a follow-up patch that switches callers to the new value-based interface, > with a commit message explicitly explaining the semantic change. Follow-up clarification I’d like to clarify this part after double-checking the logic. You’re right that, when viewed in isolation, this change is not obviously correct. In the llops-based design, the semantics intentionally change from passing a bitmask to passing an offset plus a value. The llops helpers are responsible for deriving the correct bit position internally. The same model is used on the other side as well, so functionally this does not change the behavior. Thanks again for pointing this out. Billy Tsai ^ permalink raw reply [flat|nested] 12+ messages in thread
[parent not found: <OSQPR06MB725219B6ED261DBB4E8BC33D8B88A@OSQPR06MB7252.apcprd06.prod.outlook.com>]
* Re: [PATCH 3/5] gpio: aspeed-sgpio: Create llops to handle hardware access [not found] ` <OSQPR06MB725219B6ED261DBB4E8BC33D8B88A@OSQPR06MB7252.apcprd06.prod.outlook.com> @ 2026-01-19 14:20 ` Andrew Lunn 0 siblings, 0 replies; 12+ messages in thread From: Andrew Lunn @ 2026-01-19 14:20 UTC (permalink / raw) To: Billy Tsai Cc: Linus Walleij, Bartosz Golaszewski, Joel Stanley, Andrew Jeffery, Rob Herring, Krzysztof Kozlowski, Conor Dooley, linux-gpio@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-aspeed@lists.ozlabs.org, linux-kernel@vger.kernel.org, Andrew Jeffery, devicetree@vger.kernel.org, BMC-SW > We did consider regmap. However, llops is intended to abstract not only > register > > access but also layout-specific bit mapping, which is difficult to express > > cleanly with a flat regmap interface. O.K. I was just thinking, if you can swap to regmap, you could maybe then go one step further and use gpio_regmap_register(). But if you have extra logic in here, that will not work. Andrew ^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH 4/5] dt-bindings: gpio: aspeed,sgpio: Support ast2700 2026-01-17 11:17 [PATCH 0/5] Add Aspeed G7 sgpio support Billy Tsai ` (2 preceding siblings ...) 2026-01-17 11:17 ` [PATCH 3/5] gpio: aspeed-sgpio: Create llops to handle hardware access Billy Tsai @ 2026-01-17 11:17 ` Billy Tsai 2026-01-18 10:21 ` Krzysztof Kozlowski 2026-01-17 11:17 ` [PATCH 5/5] gpio: aspeed-sgpio: Support G7 Aspeed sgpiom controller Billy Tsai 2026-01-21 12:42 ` [PATCH 0/5] Add Aspeed G7 sgpio support Linus Walleij 5 siblings, 1 reply; 12+ messages in thread From: Billy Tsai @ 2026-01-17 11:17 UTC (permalink / raw) To: Linus Walleij, Bartosz Golaszewski, Joel Stanley, Andrew Jeffery, Rob Herring, Krzysztof Kozlowski, Conor Dooley Cc: linux-gpio, linux-arm-kernel, linux-aspeed, linux-kernel, Andrew Jeffery, devicetree, bmc-sw, Billy Tsai The AST2700 is the 7th generation SoC from Aspeed, featuring two SGPIO master controllers: both with 256 serial inputs and outputs. Signed-off-by: Billy Tsai <billy_tsai@aspeedtech.com> --- Documentation/devicetree/bindings/gpio/aspeed,sgpio.yaml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Documentation/devicetree/bindings/gpio/aspeed,sgpio.yaml b/Documentation/devicetree/bindings/gpio/aspeed,sgpio.yaml index 1046f0331c09..974185e3478f 100644 --- a/Documentation/devicetree/bindings/gpio/aspeed,sgpio.yaml +++ b/Documentation/devicetree/bindings/gpio/aspeed,sgpio.yaml @@ -10,7 +10,8 @@ maintainers: - Andrew Jeffery <andrew@aj.id.au> description: - This SGPIO controller is for ASPEED AST2400, AST2500 and AST2600 SoC, + This SGPIO controller is for ASPEED AST2400, AST2500, AST2600 and AST2700 SoC, + AST2700 have two sgpio master both with 256 pins, AST2600 have two sgpio master one with 128 pins another one with 80 pins, AST2500/AST2400 have one sgpio master with 80 pins. Each of the Serial GPIO pins can be programmed to support the following options @@ -27,6 +28,7 @@ properties: - aspeed,ast2400-sgpio - aspeed,ast2500-sgpio - aspeed,ast2600-sgpiom + - aspeed,ast2700-sgpiom reg: maxItems: 1 -- 2.34.1 ^ permalink raw reply related [flat|nested] 12+ messages in thread
* Re: [PATCH 4/5] dt-bindings: gpio: aspeed,sgpio: Support ast2700 2026-01-17 11:17 ` [PATCH 4/5] dt-bindings: gpio: aspeed,sgpio: Support ast2700 Billy Tsai @ 2026-01-18 10:21 ` Krzysztof Kozlowski 0 siblings, 0 replies; 12+ messages in thread From: Krzysztof Kozlowski @ 2026-01-18 10:21 UTC (permalink / raw) To: Billy Tsai Cc: Linus Walleij, Bartosz Golaszewski, Joel Stanley, Andrew Jeffery, Rob Herring, Krzysztof Kozlowski, Conor Dooley, linux-gpio, linux-arm-kernel, linux-aspeed, linux-kernel, Andrew Jeffery, devicetree, bmc-sw On Sat, Jan 17, 2026 at 07:17:11PM +0800, Billy Tsai wrote: > The AST2700 is the 7th generation SoC from Aspeed, featuring two SGPIO > master controllers: both with 256 serial inputs and outputs. > > Signed-off-by: Billy Tsai <billy_tsai@aspeedtech.com> > --- > Documentation/devicetree/bindings/gpio/aspeed,sgpio.yaml | 4 +++- > 1 file changed, 3 insertions(+), 1 deletion(-) Acked-by: Krzysztof Kozlowski <krzysztof.kozlowski@oss.qualcomm.com> Best regards, Krzysztof ^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH 5/5] gpio: aspeed-sgpio: Support G7 Aspeed sgpiom controller 2026-01-17 11:17 [PATCH 0/5] Add Aspeed G7 sgpio support Billy Tsai ` (3 preceding siblings ...) 2026-01-17 11:17 ` [PATCH 4/5] dt-bindings: gpio: aspeed,sgpio: Support ast2700 Billy Tsai @ 2026-01-17 11:17 ` Billy Tsai 2026-01-21 12:42 ` [PATCH 0/5] Add Aspeed G7 sgpio support Linus Walleij 5 siblings, 0 replies; 12+ messages in thread From: Billy Tsai @ 2026-01-17 11:17 UTC (permalink / raw) To: Linus Walleij, Bartosz Golaszewski, Joel Stanley, Andrew Jeffery, Rob Herring, Krzysztof Kozlowski, Conor Dooley Cc: linux-gpio, linux-arm-kernel, linux-aspeed, linux-kernel, Andrew Jeffery, devicetree, bmc-sw, Billy Tsai In the 7th generation of the SoC from Aspeed, the control logic of the SGPIO controller has been updated to support per-pin control. Each pin now has its own 32-bit register, allowing for individual control of the pin's value, interrupt type, and other settings. Signed-off-by: Billy Tsai <billy_tsai@aspeedtech.com> --- drivers/gpio/gpio-aspeed-sgpio.c | 115 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 111 insertions(+), 4 deletions(-) diff --git a/drivers/gpio/gpio-aspeed-sgpio.c b/drivers/gpio/gpio-aspeed-sgpio.c index a2401f4e8e37..840a2486e3de 100644 --- a/drivers/gpio/gpio-aspeed-sgpio.c +++ b/drivers/gpio/gpio-aspeed-sgpio.c @@ -19,7 +19,31 @@ #include <linux/spinlock.h> #include <linux/string.h> -#define ASPEED_SGPIO_CTRL 0x54 +#define SGPIO_G7_IRQ_STS_BASE 0x40 +#define SGPIO_G7_IRQ_STS_OFFSET(x) (SGPIO_G7_IRQ_STS_BASE + (x) * 0x4) +#define SGPIO_G7_CTRL_REG_BASE 0x80 +#define SGPIO_G7_CTRL_REG_OFFSET(x) (SGPIO_G7_CTRL_REG_BASE + (x) * 0x4) +#define SGPIO_G7_OUT_DATA BIT(0) +#define SGPIO_G7_PARALLEL_OUT_DATA BIT(1) +#define SGPIO_G7_IRQ_EN BIT(2) +#define SGPIO_G7_IRQ_TYPE0 BIT(3) +#define SGPIO_G7_IRQ_TYPE1 BIT(4) +#define SGPIO_G7_IRQ_TYPE2 BIT(5) +#define SGPIO_G7_RST_TOLERANCE BIT(6) +#define SGPIO_G7_INPUT_MASK BIT(9) +#define SGPIO_G7_HW_BYPASS_EN BIT(10) +#define SGPIO_G7_HW_IN_SEL BIT(11) +#define SGPIO_G7_IRQ_STS BIT(12) +#define SGPIO_G7_IN_DATA BIT(13) +#define SGPIO_G7_PARALLEL_IN_DATA BIT(14) +#define SGPIO_G7_SERIAL_OUT_SEL GENMASK(17, 16) +#define SGPIO_G7_PARALLEL_OUT_SEL GENMASK(19, 18) +#define SELECT_FROM_CSR 0 +#define SELECT_FROM_PARALLEL_IN 1 +#define SELECT_FROM_SERIAL_IN 2 + +#define ASPEED_SGPIO_G4_CFG_OFFSET 0x54 +#define ASPEED_SGPIO_G7_CFG_OFFSET 0x0 #define ASPEED_SGPIO_CLK_DIV_MASK GENMASK(31, 16) #define ASPEED_SGPIO_ENABLE BIT(0) @@ -28,6 +52,7 @@ struct aspeed_sgpio_pdata { const u32 pin_mask; const struct aspeed_sgpio_llops *llops; + const u32 cfg_offset; }; struct aspeed_sgpio { @@ -135,6 +160,30 @@ static void __iomem *aspeed_sgpio_g4_bank_reg(struct aspeed_sgpio *gpio, } } +static u32 aspeed_sgpio_g7_reg_mask(const enum aspeed_sgpio_reg reg) +{ + switch (reg) { + case reg_val: + case reg_rdata: + return SGPIO_G7_OUT_DATA; + case reg_irq_enable: + return SGPIO_G7_IRQ_EN; + case reg_irq_type0: + return SGPIO_G7_IRQ_TYPE0; + case reg_irq_type1: + return SGPIO_G7_IRQ_TYPE1; + case reg_irq_type2: + return SGPIO_G7_IRQ_TYPE2; + case reg_irq_status: + return SGPIO_G7_IRQ_STS; + case reg_tolerance: + return SGPIO_G7_RST_TOLERANCE; + default: + WARN_ON_ONCE(1); + return 0; + } +} + #define GPIO_BANK(x) ((x) >> 6) #define GPIO_OFFSET(x) ((x) & GENMASK(5, 0)) #define GPIO_BIT(x) BIT(GPIO_OFFSET(x) >> 1) @@ -319,12 +368,13 @@ static void aspeed_sgpio_irq_handler(struct irq_desc *desc) struct gpio_chip *gc = irq_desc_get_handler_data(desc); struct irq_chip *ic = irq_desc_get_chip(desc); struct aspeed_sgpio *gpio = gpiochip_get_data(gc); - unsigned int i, p; + unsigned int i, p, banks; unsigned long reg; chained_irq_enter(ic, desc); - for (i = 0; i < ARRAY_SIZE(aspeed_sgpio_banks); i++) { + banks = DIV_ROUND_UP(gpio->chip.ngpio, 64); + for (i = 0; i < banks; i++) { reg = gpio->pdata->llops->reg_bank_get(gpio, i << 6, reg_irq_status); for_each_set_bit(p, ®, 32) @@ -456,6 +506,7 @@ static const struct aspeed_sgpio_llops aspeed_sgpio_g4_llops = { static const struct aspeed_sgpio_pdata ast2400_sgpio_pdata = { .pin_mask = GENMASK(9, 6), .llops = &aspeed_sgpio_g4_llops, + .cfg_offset = ASPEED_SGPIO_G4_CFG_OFFSET, }; static int aspeed_sgpio_reset_tolerance(struct gpio_chip *chip, @@ -485,12 +536,68 @@ static int aspeed_sgpio_set_config(struct gpio_chip *chip, unsigned int offset, static const struct aspeed_sgpio_pdata ast2600_sgpiom_pdata = { .pin_mask = GENMASK(10, 6), .llops = &aspeed_sgpio_g4_llops, + .cfg_offset = ASPEED_SGPIO_G4_CFG_OFFSET, +}; + +static void aspeed_sgpio_g7_reg_bit_set(struct aspeed_sgpio *gpio, unsigned int offset, + const enum aspeed_sgpio_reg reg, bool val) +{ + u32 mask = aspeed_sgpio_g7_reg_mask(reg); + void __iomem *addr = gpio->base + SGPIO_G7_CTRL_REG_OFFSET(offset >> 1); + u32 write_val; + + if (mask) { + write_val = (ioread32(addr) & ~(mask)) | field_prep(mask, val); + iowrite32(write_val, addr); + } +} + +static bool aspeed_sgpio_g7_reg_bit_get(struct aspeed_sgpio *gpio, unsigned int offset, + const enum aspeed_sgpio_reg reg) +{ + u32 mask = aspeed_sgpio_g7_reg_mask(reg); + void __iomem *addr; + + addr = gpio->base + SGPIO_G7_CTRL_REG_OFFSET(offset >> 1); + if (reg == reg_val) + mask = SGPIO_G7_IN_DATA; + + if (mask) + return field_get(mask, ioread32(addr)); + else + return 0; +} + +static int aspeed_sgpio_g7_reg_bank_get(struct aspeed_sgpio *gpio, unsigned int offset, + const enum aspeed_sgpio_reg reg) +{ + void __iomem *addr; + + if (reg == reg_irq_status) { + addr = gpio->base + SGPIO_G7_IRQ_STS_OFFSET(offset >> 6); + return ioread32(addr); + } else { + return -EOPNOTSUPP; + } +} + +static const struct aspeed_sgpio_llops aspeed_sgpio_g7_llops = { + .reg_bit_set = aspeed_sgpio_g7_reg_bit_set, + .reg_bit_get = aspeed_sgpio_g7_reg_bit_get, + .reg_bank_get = aspeed_sgpio_g7_reg_bank_get, +}; + +static const struct aspeed_sgpio_pdata ast2700_sgpiom_pdata = { + .pin_mask = GENMASK(11, 6), + .llops = &aspeed_sgpio_g7_llops, + .cfg_offset = ASPEED_SGPIO_G7_CFG_OFFSET, }; static const struct of_device_id aspeed_sgpio_of_table[] = { { .compatible = "aspeed,ast2400-sgpio", .data = &ast2400_sgpio_pdata, }, { .compatible = "aspeed,ast2500-sgpio", .data = &ast2400_sgpio_pdata, }, { .compatible = "aspeed,ast2600-sgpiom", .data = &ast2600_sgpiom_pdata, }, + { .compatible = "aspeed,ast2700-sgpiom", .data = &ast2700_sgpiom_pdata, }, {} }; @@ -561,7 +668,7 @@ static int aspeed_sgpio_probe(struct platform_device *pdev) gpio_cnt_regval = ((nr_gpios / 8) << ASPEED_SGPIO_PINS_SHIFT) & pin_mask; iowrite32(FIELD_PREP(ASPEED_SGPIO_CLK_DIV_MASK, sgpio_clk_div) | gpio_cnt_regval | - ASPEED_SGPIO_ENABLE, gpio->base + ASPEED_SGPIO_CTRL); + ASPEED_SGPIO_ENABLE, gpio->base + gpio->pdata->cfg_offset); raw_spin_lock_init(&gpio->lock); -- 2.34.1 ^ permalink raw reply related [flat|nested] 12+ messages in thread
* Re: [PATCH 0/5] Add Aspeed G7 sgpio support 2026-01-17 11:17 [PATCH 0/5] Add Aspeed G7 sgpio support Billy Tsai ` (4 preceding siblings ...) 2026-01-17 11:17 ` [PATCH 5/5] gpio: aspeed-sgpio: Support G7 Aspeed sgpiom controller Billy Tsai @ 2026-01-21 12:42 ` Linus Walleij 5 siblings, 0 replies; 12+ messages in thread From: Linus Walleij @ 2026-01-21 12:42 UTC (permalink / raw) To: Billy Tsai Cc: Bartosz Golaszewski, Joel Stanley, Andrew Jeffery, Rob Herring, Krzysztof Kozlowski, Conor Dooley, linux-gpio, linux-arm-kernel, linux-aspeed, linux-kernel, Andrew Jeffery, devicetree, bmc-sw On Sat, Jan 17, 2026 at 12:17 PM Billy Tsai <billy_tsai@aspeedtech.com> wrote: > The Aspeed 7th generation SoC features two SGPIO master controllers: both > with 256 serial inputs and outputs. The main difference from the previous > generation is that the control logic has been updated to support > per-pin control, allowing each pin to have its own 32-bit register for > configuring value, interrupt type, and more. > This patch serial also add low-level operations (llops) to abstract the > register access for SGPIO registers making it easier to extend the driver > to support different hardware register layouts. > > Signed-off-by: Billy Tsai <billy_tsai@aspeedtech.com> Changes look reasonable to me! Reviewed-by: Linus Walleij <linusw@kernel.org> Yours, Linus Walleij ^ permalink raw reply [flat|nested] 12+ messages in thread
end of thread, other threads:[~2026-01-21 12:42 UTC | newest]
Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-01-17 11:17 [PATCH 0/5] Add Aspeed G7 sgpio support Billy Tsai
2026-01-17 11:17 ` [PATCH 1/5] gpio: aspeed-sgpio: Change the macro to support deferred probe Billy Tsai
2026-01-17 11:17 ` [PATCH 2/5] gpio: aspeed-sgpio: Remove unused bank name field Billy Tsai
2026-01-17 11:17 ` [PATCH 3/5] gpio: aspeed-sgpio: Create llops to handle hardware access Billy Tsai
2026-01-17 15:46 ` Andrew Lunn
2026-01-19 2:39 ` Billy Tsai
2026-01-19 3:37 ` Billy Tsai
[not found] ` <OSQPR06MB725219B6ED261DBB4E8BC33D8B88A@OSQPR06MB7252.apcprd06.prod.outlook.com>
2026-01-19 14:20 ` Andrew Lunn
2026-01-17 11:17 ` [PATCH 4/5] dt-bindings: gpio: aspeed,sgpio: Support ast2700 Billy Tsai
2026-01-18 10:21 ` Krzysztof Kozlowski
2026-01-17 11:17 ` [PATCH 5/5] gpio: aspeed-sgpio: Support G7 Aspeed sgpiom controller Billy Tsai
2026-01-21 12:42 ` [PATCH 0/5] Add Aspeed G7 sgpio support Linus Walleij
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).