From nobody Mon Feb 9 09:32:50 2026 Received: from TWMBX01.aspeed.com (mail.aspeedtech.com [211.20.114.72]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DC00713C672; Fri, 30 Aug 2024 03:41:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=211.20.114.72 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724989276; cv=none; b=Yt/1KJ7GgrWW0AhToc+i3CKxdP9IhI6ED56hiqQuGem7w/yMN1E2BhhRpQbtYSZY4RNDQvZonsUISRr2zzib7ONW3AOxb+M73q7zbLdVksAkn5iLNbOsFjk8/oKI+gotKw78zf9BOis4VB64ZkVXxSYg9+aXxSBzqHAP2lqhNqE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724989276; c=relaxed/simple; bh=bbDUZJuxl6BhnSNZqhyx6zNmudvYRof97UdKWYiiPnE=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=hu9X+WoGjww7991FZ8MF2UpAf2TXOXXgmmFucKGqKK7btVDkbJytBBwBqi/qVntRDQv51Gsb7j5RhOr42Z1mVYUlrg0nkn8xgB/44vMfYavPfHmEDd//fFGlk/pIpKsWhJiZmts5crIGyVFh0tcfkKMPkr/UVQCeU9TJIdt65mw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=aspeedtech.com; spf=pass smtp.mailfrom=aspeedtech.com; arc=none smtp.client-ip=211.20.114.72 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=aspeedtech.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=aspeedtech.com Received: from TWMBX01.aspeed.com (192.168.0.62) by TWMBX01.aspeed.com (192.168.0.62) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1258.12; Fri, 30 Aug 2024 11:40:48 +0800 Received: from mail.aspeedtech.com (192.168.10.10) by TWMBX01.aspeed.com (192.168.0.62) with Microsoft SMTP Server id 15.2.1258.12 via Frontend Transport; Fri, 30 Aug 2024 11:40:48 +0800 From: Billy Tsai To: , , , , , , , , , , , , Subject: [PATCH v2 4/4] gpio: aspeed: Support G7 Aspeed gpio controller Date: Fri, 30 Aug 2024 11:40:47 +0800 Message-ID: <20240830034047.2251482-5-billy_tsai@aspeedtech.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240830034047.2251482-1-billy_tsai@aspeedtech.com> References: <20240830034047.2251482-1-billy_tsai@aspeedtech.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable In the 7th generation of the SoC from Aspeed, the control logic of the GPIO 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=E2= =80=99s value, direction, interrupt type, and other settings. The permission for coprocessor access is supported by the hardware but hasn=E2=80=99t been implemented in the current patch. Signed-off-by: Billy Tsai --- drivers/gpio/gpio-aspeed.c | 116 +++++++++++++++++++++++++++++++++++++ 1 file changed, 116 insertions(+) diff --git a/drivers/gpio/gpio-aspeed.c b/drivers/gpio/gpio-aspeed.c index 74c4e80958bf..24f9c7312351 100644 --- a/drivers/gpio/gpio-aspeed.c +++ b/drivers/gpio/gpio-aspeed.c @@ -30,6 +30,23 @@ #include #include "gpiolib.h" =20 +#define GPIO_G7_IRQ_STS_BASE 0x100 +#define GPIO_G7_IRQ_STS_OFFSET(x) (GPIO_G7_IRQ_STS_BASE + (x) * 0x4) +#define GPIO_G7_CTRL_REG_BASE 0x180 +#define GPIO_G7_CTRL_REG_OFFSET(x) (GPIO_G7_CTRL_REG_BASE + (x) * 0x4) +#define GPIO_G7_CTRL_OUT_DATA BIT(0) +#define GPIO_G7_CTRL_DIR BIT(1) +#define GPIO_G7_CTRL_IRQ_EN BIT(2) +#define GPIO_G7_CTRL_IRQ_TYPE0 BIT(3) +#define GPIO_G7_CTRL_IRQ_TYPE1 BIT(4) +#define GPIO_G7_CTRL_IRQ_TYPE2 BIT(5) +#define GPIO_G7_CTRL_RST_TOLERANCE BIT(6) +#define GPIO_G7_CTRL_DEBOUNCE_SEL2 BIT(7) +#define GPIO_G7_CTRL_DEBOUNCE_SEL1 BIT(8) +#define GPIO_G7_CTRL_INPUT_MASK BIT(9) +#define GPIO_G7_CTRL_IRQ_STS BIT(12) +#define GPIO_G7_CTRL_IN_DATA BIT(13) + struct aspeed_bank_props { unsigned int bank; u32 input; @@ -95,6 +112,7 @@ struct aspeed_gpio_bank { */ =20 static const int debounce_timers[4] =3D { 0x00, 0x50, 0x54, 0x58 }; +static const int g7_debounce_timers[4] =3D { 0x00, 0x04, 0x00, 0x08 }; =20 static const struct aspeed_gpio_copro_ops *copro_ops; static void *copro_data; @@ -246,6 +264,39 @@ static inline void __iomem *bank_reg(struct aspeed_gpi= o *gpio, BUG(); } =20 +static inline u32 reg_mask(const enum aspeed_gpio_reg reg) +{ + switch (reg) { + case reg_val: + return GPIO_G7_CTRL_OUT_DATA; + case reg_dir: + return GPIO_G7_CTRL_DIR; + case reg_irq_enable: + return GPIO_G7_CTRL_IRQ_EN; + case reg_irq_type0: + return GPIO_G7_CTRL_IRQ_TYPE0; + case reg_irq_type1: + return GPIO_G7_CTRL_IRQ_TYPE1; + case reg_irq_type2: + return GPIO_G7_CTRL_IRQ_TYPE2; + case reg_tolerance: + return GPIO_G7_CTRL_RST_TOLERANCE; + case reg_debounce_sel1: + return GPIO_G7_CTRL_DEBOUNCE_SEL1; + case reg_debounce_sel2: + return GPIO_G7_CTRL_DEBOUNCE_SEL2; + case reg_rdata: + return GPIO_G7_CTRL_OUT_DATA; + case reg_irq_status: + return GPIO_G7_CTRL_IRQ_STS; + case reg_cmdsrc0: + case reg_cmdsrc1: + default: + WARN_ON_ONCE(1); + return 0; + } +} + #define GPIO_BANK(x) ((x) >> 5) #define GPIO_OFFSET(x) ((x) & 0x1f) #define GPIO_BIT(x) BIT(GPIO_OFFSET(x)) @@ -930,6 +981,9 @@ int aspeed_gpio_copro_grab_gpio(struct gpio_desc *desc, const struct aspeed_gpio_bank *bank =3D to_bank(offset); unsigned long flags; =20 + if (gpio->config->version =3D=3D 7) + return -EOPNOTSUPP; + if (!gpio->cf_copro_bankmap) gpio->cf_copro_bankmap =3D kzalloc(gpio->chip.ngpio >> 3, GFP_KERNEL); if (!gpio->cf_copro_bankmap) @@ -975,6 +1029,9 @@ int aspeed_gpio_copro_release_gpio(struct gpio_desc *d= esc) int rc =3D 0, bindex, offset =3D gpio_chip_hwgpio(desc); unsigned long flags; =20 + if (gpio->config->version =3D=3D 7) + return -EOPNOTSUPP; + if (!gpio->cf_copro_bankmap) return -ENXIO; =20 @@ -1069,10 +1126,27 @@ static const struct aspeed_gpio_config ast2600_conf= ig =3D */ { .nr_gpios =3D 208, .props =3D ast2600_bank_props, .version =3D 4}; =20 +static const struct aspeed_bank_props ast2700_bank_props[] =3D { + /* input output */ + { 1, 0x0fffffff, 0x0fffffff }, /* E/F/G/H, 4-GPIO hole */ + { 6, 0x00ffffff, 0x00ffffff }, /* Y/Z/AA */ + {}, +}; + +static const struct aspeed_gpio_config ast2700_config =3D + /* + * ast2700 has two controllers one with 212 GPIOs and one with 16 GPIOs. + * 216 for simplicity, actual number is 212 (4-GPIO hole in GPIOH) + * We expect ngpio being set in the device tree and this is a fallback + * option. + */ + { .nr_gpios =3D 216, .props =3D ast2700_bank_props, .version =3D 7 }; + static const struct of_device_id aspeed_gpio_of_table[] =3D { { .compatible =3D "aspeed,ast2400-gpio", .data =3D &ast2400_config, }, { .compatible =3D "aspeed,ast2500-gpio", .data =3D &ast2500_config, }, { .compatible =3D "aspeed,ast2600-gpio", .data =3D &ast2600_config, }, + { .compatible =3D "aspeed,ast2700-gpio", .data =3D &ast2700_config, }, {} }; MODULE_DEVICE_TABLE(of, aspeed_gpio_of_table); @@ -1111,6 +1185,40 @@ struct aspeed_gpio_llops aspeed_g4_llops =3D { .reg_bits_read =3D aspeed_g4_reg_bits_read, }; =20 +static void aspeed_g7_reg_bits_set(struct aspeed_gpio *gpio, unsigned int = offset, + const enum aspeed_gpio_reg reg, u32 val) +{ + u32 mask =3D reg_mask(reg); + void __iomem *addr =3D gpio->base + GPIO_G7_CTRL_REG_OFFSET(offset); + u32 write_val =3D (ioread32(addr) & ~(mask)) | (((val) << (ffs(mask) - 1)= ) & (mask)); + + iowrite32(write_val, addr); +} + +static u32 aspeed_g7_reg_bits_read(struct aspeed_gpio *gpio, unsigned int = offset, + const enum aspeed_gpio_reg reg) +{ + u32 mask =3D reg_mask(reg); + void __iomem *addr; + + if (reg =3D=3D reg_irq_status) { + addr =3D gpio->base + GPIO_G7_IRQ_STS_OFFSET(offset); + return ioread32(addr); + } + addr =3D gpio->base + GPIO_G7_CTRL_REG_OFFSET(offset); + if (reg =3D=3D reg_val) + mask =3D GPIO_G7_CTRL_IN_DATA; + + return (((ioread32(addr)) & (mask)) >> (ffs(mask) - 1)); +} + +struct aspeed_gpio_llops aspeed_g7_llops =3D { + .copro_request =3D NULL, + .copro_release =3D NULL, + .reg_bits_set =3D aspeed_g7_reg_bits_set, + .reg_bits_read =3D aspeed_g7_reg_bits_read, +}; + static int __init aspeed_gpio_probe(struct platform_device *pdev) { const struct of_device_id *gpio_id; @@ -1152,6 +1260,14 @@ static int __init aspeed_gpio_probe(struct platform_= device *pdev) gpio->debounce_timers_array =3D debounce_timers; gpio->debounce_timers_num =3D ARRAY_SIZE(debounce_timers); } + } else if (gpio->config->version =3D=3D 7) { + if (!gpio->llops) + gpio->llops =3D &aspeed_g7_llops; + + if (!gpio->debounce_timers_array) { + gpio->debounce_timers_array =3D g7_debounce_timers; + gpio->debounce_timers_num =3D ARRAY_SIZE(g7_debounce_timers); + } } else { return -EOPNOTSUPP; } --=20 2.25.1