From: Eric Chung <eric.chung@riscstar.com>
To: u-boot-spacemit@groups.io, u-boot@lists.denx.de
Cc: Tom Rini <trini@konsulko.com>, Peng Fan <peng.fan@nxp.com>,
Huan Zhou <pericycle.cc@gmail.com>,
Raymond Mao <raymond.mao@riscstar.com>,
Jaehoon Chung <jh80.chung@samsung.com>,
Bhimeswararao Matsa <bhimeswararao.matsa@gmail.com>,
Tanmay Kathpalia <tanmay.kathpalia@altera.com>,
Kaustabh Chakraborty <kauschluss@disroot.org>,
Han Xu <han.xu@nxp.com>, Yanir Levin <yanir.levin@tandemg.com>,
Christoph Stoidner <c.stoidner@phytec.de>,
Balsundar Ponnusamy <balsundar.ponnusamy@altera.com>,
Daniel Palmer <daniel@thingy.jp>, Anshul Dalal <anshuld@ti.com>,
Bastien Curutchet <bastien.curutchet@bootlin.com>,
Angelo Dureghello <angelo@kernel-space.org>,
Johan Jonker <jbx6244@gmail.com>, Rick Chen <rick@andestech.com>,
Leo <ycliang@andestech.com>,
Sam Protsenko <semen.protsenko@linaro.org>,
Guodong Xu <guodong.xu@riscstar.com>,
Eric Chung <eric.chung@riscstar.com>
Subject: [PATCH v2 v2 1/8] pinctrl: k1: add IO power domain configuration support
Date: Mon, 29 Jun 2026 23:51:15 +0800 [thread overview]
Message-ID: <20260629-m4-v2-1-cbc91c6b83d8@riscstar.com> (raw)
In-Reply-To: <20260629-m4-v2-0-cbc91c6b83d8@riscstar.com>
Dual-voltage GPIO banks default to 3.3V, but when externally supplied
with 1.8V the internal logic must be explicitly reconfigured to match.
Add the ability to program IO power domain control registers through the
APBC block. These registers require unlocking the AIB Secure Access
Register (ASAR) before every read/write, since configuring a 1.8V domain
while 3.3V is externally supplied can cause back-powering and pin damage.
Signed-off-by: Eric Chung <eric.chung@riscstar.com>
---
drivers/pinctrl/spacemit/pinctrl-k1.c | 84 ++++++++++++++++++++++++++++++++++-
1 file changed, 82 insertions(+), 2 deletions(-)
diff --git a/drivers/pinctrl/spacemit/pinctrl-k1.c b/drivers/pinctrl/spacemit/pinctrl-k1.c
index 3ebc397213b..5d3236aac94 100644
--- a/drivers/pinctrl/spacemit/pinctrl-k1.c
+++ b/drivers/pinctrl/spacemit/pinctrl-k1.c
@@ -12,6 +12,8 @@
#include <linux/bitops.h>
#include <linux/errno.h>
#include <linux/io.h>
+#include <regmap.h>
+#include <syscon.h>
/*
* +---------+----------+-----------+--------+--------+----------+--------+
@@ -34,8 +36,24 @@
#define PAD_PULLUP BIT(14)
#define PAD_PULL_EN BIT(15)
-#define PIN_POWER_STATE_1V8 1800
-#define PIN_POWER_STATE_3V3 3300
+#define IO_PWR_DOMAIN_OFFSET 0x800
+
+#define IO_PWR_DOMAIN_GPIO2_Kx 0x0c
+#define IO_PWR_DOMAIN_MMC_Kx 0x1c
+
+#define IO_PWR_DOMAIN_GPIO3_K1 0x10
+#define IO_PWR_DOMAIN_QSPI_K1 0x20
+
+#define IO_PWR_DOMAIN_V18EN BIT(2)
+
+#define APBC_ASFAR 0x50
+#define APBC_ASSAR 0x54
+
+#define APBC_ASFAR_AKEY 0xbaba
+#define APBC_ASSAR_AKEY 0xeb10
+
+#define PIN_POWER_STATE_1V8 1800
+#define PIN_POWER_STATE_3V3 3300
enum spacemit_pin_io_type {
IO_TYPE_NONE = 0,
@@ -60,12 +78,14 @@ struct spacemit_pinctrl_data {
int (*get_pins)(struct udevice *dev);
int (*get_functions)(struct udevice *dev);
int (*get_io_type)(struct udevice *dev, unsigned int pin);
+ unsigned int (*pin_to_io_pd_offset)(unsigned int pin);
};
struct spacemit_pinctrl_priv {
void __iomem *regs;
struct spacemit_pin_io *io_pins;
int nr_io_pins;
+ struct regmap *regmap;
};
struct spacemit_pin_mux_config {
@@ -196,6 +216,28 @@ static int k1_get_io_type(struct udevice *dev, unsigned int selector)
return -EINVAL;
}
+static unsigned int spacemit_k1_pin_to_io_pd_offset(unsigned int pin)
+{
+ unsigned int offset = 0;
+
+ switch (pin) {
+ case 47 ... 52:
+ offset = IO_PWR_DOMAIN_GPIO3_K1;
+ break;
+ case 75 ... 80:
+ offset = IO_PWR_DOMAIN_GPIO2_Kx;
+ break;
+ case 98 ... 103:
+ offset = IO_PWR_DOMAIN_QSPI_K1;
+ break;
+ case 104 ... 109:
+ offset = IO_PWR_DOMAIN_MMC_Kx;
+ break;
+ }
+
+ return offset;
+}
+
/* use IO high level output current as the table */
static struct spacemit_pin_drv_strength spacemit_ds_1v8_tbl[4] = {
{ 0, 11 },
@@ -400,6 +442,35 @@ static const struct pinconf_param spacemit_pinconf_params[] = {
{ "power-source", PIN_CONFIG_POWER_SOURCE, U32_MAX },
};
+static void spacemit_set_io_power_domain(struct udevice *dev,
+ unsigned int pin,
+ unsigned int io_type)
+{
+ struct spacemit_pinctrl_priv *priv = dev_get_priv(dev);
+ struct spacemit_pinctrl_data *data;
+ unsigned int offset;
+ u32 val = 0;
+
+ if (!priv->regmap)
+ return;
+
+ data = (struct spacemit_pinctrl_data *)dev_get_driver_data(dev);
+ if (!data || !data->pin_to_io_pd_offset)
+ return;
+
+ offset = data->pin_to_io_pd_offset(pin);
+ if (!offset)
+ return;
+
+ if (io_type == IO_TYPE_1V8)
+ val = IO_PWR_DOMAIN_V18EN;
+
+ regmap_write(priv->regmap, APBC_ASFAR, APBC_ASFAR_AKEY);
+ regmap_write(priv->regmap, APBC_ASSAR, APBC_ASSAR_AKEY);
+
+ writel(val, priv->regs + IO_PWR_DOMAIN_OFFSET + offset);
+}
+
static int spacemit_pinconf_set(struct udevice *dev, unsigned int pin_selector,
unsigned int param, unsigned int argument)
{
@@ -456,6 +527,9 @@ static int spacemit_pinconf_set(struct udevice *dev, unsigned int pin_selector,
dev_err(dev, "Invalid power source (%d)\n", argument);
return -EINVAL;
}
+ if (found)
+ spacemit_set_io_power_domain(dev, pin_selector,
+ priv->io_pins[i].io_type);
break;
default:
return -EOPNOTSUPP;
@@ -485,6 +559,11 @@ static int spacemit_pinctrl_probe(struct udevice *dev)
dev_err(dev, "Fail to allocate memory\n");
return -ENOMEM;
}
+ priv->regmap = syscon_regmap_lookup_by_phandle(dev, "spacemit,apbc");
+ if (IS_ERR(priv->regmap)) {
+ dev_warn(dev, "no syscon found, disable IO power domain switching\n");
+ priv->regmap = NULL;
+ }
ret = clk_get_bulk(dev, &clks);
if (ret) {
@@ -512,6 +591,7 @@ static const struct spacemit_pinctrl_data k1_pinctrl_data = {
.get_pins = k1_get_pins,
.get_functions = k1_get_functions,
.get_io_type = k1_get_io_type,
+ .pin_to_io_pd_offset = spacemit_k1_pin_to_io_pd_offset,
};
static const struct udevice_id spacemit_pinctrl_ids[] = {
--
2.51.0
next prev parent reply other threads:[~2026-06-29 15:52 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-29 15:51 [PATCH v2 0/8] spacemit mmc driver Eric Chung
2026-06-29 15:51 ` Eric Chung [this message]
2026-06-30 8:55 ` [PATCH v2 v2 1/8] pinctrl: k1: add IO power domain configuration support Yao Zi
2026-06-29 15:51 ` [PATCH v2 v2 2/8] mmc: sdhci: add quirk to enable CMD23 for multi-block transfers Eric Chung
2026-06-30 2:47 ` Peng Fan
2026-06-29 15:51 ` [PATCH v2 v2 3/8] mmc: k1: add sdhci platform driver Eric Chung
2026-06-30 2:52 ` Peng Fan
2026-06-29 15:51 ` [PATCH v2 v2 4/8] dts: k1: add SD card support in u-boot overlay Eric Chung
2026-06-30 2:56 ` Peng Fan
2026-06-29 15:51 ` [PATCH v2 v2 5/8] configs: k1: enable SD and eMMC support Eric Chung
2026-06-29 15:51 ` [PATCH v2 v2 6/8] doc: spacemit: flash on K1 SoC based boards Eric Chung
2026-06-29 15:51 ` [PATCH v2 v2 7/8] config: k1: enable ENV support for eMMC Eric Chung
2026-06-29 15:51 ` [PATCH v2 v2 8/8] spacemit: k1: load product name from environment variable Eric Chung
2026-06-30 2:55 ` Peng Fan
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260629-m4-v2-1-cbc91c6b83d8@riscstar.com \
--to=eric.chung@riscstar.com \
--cc=angelo@kernel-space.org \
--cc=anshuld@ti.com \
--cc=balsundar.ponnusamy@altera.com \
--cc=bastien.curutchet@bootlin.com \
--cc=bhimeswararao.matsa@gmail.com \
--cc=c.stoidner@phytec.de \
--cc=daniel@thingy.jp \
--cc=guodong.xu@riscstar.com \
--cc=han.xu@nxp.com \
--cc=jbx6244@gmail.com \
--cc=jh80.chung@samsung.com \
--cc=kauschluss@disroot.org \
--cc=peng.fan@nxp.com \
--cc=pericycle.cc@gmail.com \
--cc=raymond.mao@riscstar.com \
--cc=rick@andestech.com \
--cc=semen.protsenko@linaro.org \
--cc=tanmay.kathpalia@altera.com \
--cc=trini@konsulko.com \
--cc=u-boot-spacemit@groups.io \
--cc=u-boot@lists.denx.de \
--cc=yanir.levin@tandemg.com \
--cc=ycliang@andestech.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox