blob: 0402dba3bd96f823c392547819bdb49bd258d4bb [file] [log] [blame]
From 0c05eaf306975e0280189d9aec5d6af9dee4f8ed Mon Sep 17 00:00:00 2001
From: Shao-Chieh Chao <jieh.sc.chao@fii-na.corp-partner.google.com>
Date: Mon, 17 Mar 2025 17:27:37 +0800
Subject: [PATCH] Add setting SGPIO default value
---
drivers/gpio/gpio-aspeed-sgpio.c | 28 ++++++++++++++++++++++++----
1 file changed, 24 insertions(+), 4 deletions(-)
diff --git a/drivers/gpio/gpio-aspeed-sgpio.c b/drivers/gpio/gpio-aspeed-sgpio.c
index bf47a2489..7e79b580f 100644
--- a/drivers/gpio/gpio-aspeed-sgpio.c
+++ b/drivers/gpio/gpio-aspeed-sgpio.c
@@ -819,12 +819,13 @@ 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;
+ u32 nr_gpios, sgpio_freq, sgpio_clk_div, gpio_cnt_regval, pin_mask, initial_val;
const struct aspeed_sgpio_pdata *pdata;
struct aspeed_sgpio *gpio;
unsigned long apb_freq;
void __iomem *addr;
int rc, i;
+ int has_default = 1;
gpio = devm_kzalloc(&pdev->dev, sizeof(*gpio), GFP_KERNEL);
if (!gpio)
@@ -853,12 +854,31 @@ static int aspeed_sgpio_probe(struct platform_device *pdev)
return -EINVAL;
}
- if (gpio->version == 7 && !pdata->slave)
+ u32 Byte_configs[nr_gpios / 8];
+
+ for (i = 0; i < nr_gpios / 8; i++) {
+ char prop_name[16];
+ snprintf(prop_name, sizeof(prop_name), "Byte%d_default", i);
+ rc = device_property_read_u32(&pdev->dev, prop_name, &Byte_configs[i]);
+ if (rc < 0) {
+ has_default = 0;
+ break;
+ }
+ }
+
+ if (gpio->version == 7 && !pdata->slave) {
for (i = 0; i < nr_gpios; i++) {
addr = gpio->base + SGPIO_G7_CTRL_REG_OFFSET(i);
- ast_clr_bits(addr, SGPIO_G7_HW_BYPASS_EN |
- SGPIO_G7_HW_IN_SEL);
+ ast_clr_bits(addr, SGPIO_G7_HW_BYPASS_EN | SGPIO_G7_HW_IN_SEL);
+
+ if (has_default) {
+ int byte_index = i / 8;
+ int bit_index = i % 8;
+ initial_val = (Byte_configs[byte_index] >> bit_index) & 1;
+ ast_write_bits(addr, SGPIO_G7_OUT_DATA, initial_val);
+ }
}
+ }
if (!pdata->slave) {
rc = device_property_read_u32(&pdev->dev, "bus-frequency", &sgpio_freq);
--
2.34.1