Skip to content

Commit 847505a

Browse files
jimliu3trini
authored andcommitted
misc: nuvoton: Add host interface configuration driver
add nuvoton BMC npcm750 host configuration driver Signed-off-by: Jim Liu <[email protected]>
1 parent b24087a commit 847505a

File tree

3 files changed

+117
-0
lines changed

3 files changed

+117
-0
lines changed

drivers/misc/Kconfig

+6
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,12 @@ config MXC_OCOTP
326326
Programmable memory pages that are stored on the some
327327
Freescale i.MX processors.
328328

329+
config NPCM_HOST
330+
bool "Enable support espi or LPC for Host"
331+
depends on REGMAP && SYSCON
332+
help
333+
Enable NPCM BMC espi or LPC support for Host reading and writing.
334+
329335
config SPL_MXC_OCOTP
330336
bool "Enable MXC OCOTP driver in SPL"
331337
depends on SPL_MISC && (ARCH_IMX8M || ARCH_MX6 || ARCH_MX7 || ARCH_MX7ULP || ARCH_VF610)

drivers/misc/Makefile

+1
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ obj-$(CONFIG_$(SPL_TPL_)LS2_SFP) += ls2_sfp.o
5757
obj-$(CONFIG_$(SPL_)MXC_OCOTP) += mxc_ocotp.o
5858
obj-$(CONFIG_MXS_OCOTP) += mxs_ocotp.o
5959
obj-$(CONFIG_NPCM_OTP) += npcm_otp.o
60+
obj-$(CONFIG_NPCM_HOST) += npcm_host_intf.o
6061
obj-$(CONFIG_NUVOTON_NCT6102D) += nuvoton_nct6102d.o
6162
obj-$(CONFIG_P2SB) += p2sb-uclass.o
6263
obj-$(CONFIG_PCA9551_LED) += pca9551_led.o

drivers/misc/npcm_host_intf.c

+110
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
// SPDX-License-Identifier: GPL-2.0+
2+
/*
3+
* Host interface (LPC or eSPI) configuration on Nuvoton BMC
4+
* Copyright (c) 2022 Nuvoton Technology Corp.
5+
*/
6+
7+
#include <common.h>
8+
#include <dm.h>
9+
#include <regmap.h>
10+
#include <syscon.h>
11+
#include <asm/io.h>
12+
#include <dm/device_compat.h>
13+
#include <linux/bitfield.h>
14+
15+
#define SMC_CTL_REG_ADDR 0xc0001001
16+
#define SMC_CTL_HOSTWAIT 0x80
17+
18+
/* GCR Register Offsets */
19+
#define HIFCR 0x50
20+
#define MFSEL1 0x260
21+
#define MFSEL4 0x26c
22+
23+
/* ESPI Register offsets */
24+
#define ESPICFG 0x4
25+
#define ESPIHINDP 0x80
26+
27+
/* MFSEL bit fileds */
28+
#define MFSEL1_LPCSEL BIT(26)
29+
#define MFSEL4_ESPISEL BIT(8)
30+
31+
/* ESPICFG bit fileds */
32+
#define CHSUPP_MASK GENMASK(27, 24)
33+
#define IOMODE_MASK GENMASK(9, 8)
34+
#define IOMODE_SDQ FIELD_PREP(IOMODE_MASK, 3)
35+
#define MAXFREQ_MASK GENMASK(12, 10)
36+
#define MAXFREQ_33MHZ FIELD_PREP(MAXFREQ_MASK, 2)
37+
38+
/* ESPIHINDP bit fileds */
39+
#define AUTO_SBLD BIT(4)
40+
#define AUTO_HS1 BIT(8)
41+
#define AUTO_HS2 BIT(12)
42+
#define AUTO_HS3 BIT(16)
43+
44+
static int npcm_host_intf_bind(struct udevice *dev)
45+
{
46+
struct regmap *syscon;
47+
void __iomem *base;
48+
u32 ch_supp, val;
49+
u32 ioaddr;
50+
const char *type;
51+
int ret;
52+
53+
/* Release host wait */
54+
setbits_8(SMC_CTL_REG_ADDR, SMC_CTL_HOSTWAIT);
55+
56+
syscon = syscon_regmap_lookup_by_phandle(dev, "syscon");
57+
if (IS_ERR(syscon)) {
58+
dev_err(dev, "%s: unable to get syscon, dev %s\n", __func__, dev->name);
59+
return PTR_ERR(syscon);
60+
}
61+
62+
ioaddr = dev_read_u32_default(dev, "ioaddr", 0);
63+
if (ioaddr)
64+
regmap_write(syscon, HIFCR, ioaddr);
65+
66+
type = dev_read_string(dev, "type");
67+
if (!type)
68+
return -EINVAL;
69+
70+
if (!strcmp(type, "espi")) {
71+
base = dev_read_addr_ptr(dev);
72+
if (!base)
73+
return -EINVAL;
74+
75+
ret = dev_read_u32(dev, "channel-support", &ch_supp);
76+
if (ret)
77+
return ret;
78+
79+
/* Select eSPI pins function */
80+
regmap_update_bits(syscon, MFSEL1, MFSEL1_LPCSEL, 0);
81+
regmap_update_bits(syscon, MFSEL4, MFSEL4_ESPISEL, MFSEL4_ESPISEL);
82+
83+
val = AUTO_SBLD | AUTO_HS1 | AUTO_HS2 | AUTO_HS3 | ch_supp;
84+
writel(val, base + ESPIHINDP);
85+
86+
val = readl(base + ESPICFG);
87+
val &= ~(CHSUPP_MASK | IOMODE_MASK | MAXFREQ_MASK);
88+
val |= IOMODE_SDQ | MAXFREQ_33MHZ | FIELD_PREP(CHSUPP_MASK, ch_supp);
89+
writel(val, base + ESPICFG);
90+
} else if (!strcmp(type, "lpc")) {
91+
/* Select LPC pin function */
92+
regmap_update_bits(syscon, MFSEL4, MFSEL4_ESPISEL, 0);
93+
regmap_update_bits(syscon, MFSEL1, MFSEL1_LPCSEL, MFSEL1_LPCSEL);
94+
}
95+
96+
return 0;
97+
}
98+
99+
static const struct udevice_id npcm_hostintf_ids[] = {
100+
{ .compatible = "nuvoton,npcm750-host-intf" },
101+
{ .compatible = "nuvoton,npcm845-host-intf" },
102+
{ }
103+
};
104+
105+
U_BOOT_DRIVER(npcm_host_intf) = {
106+
.name = "npcm_host_intf",
107+
.id = UCLASS_MISC,
108+
.of_match = npcm_hostintf_ids,
109+
.bind = npcm_host_intf_bind,
110+
};

0 commit comments

Comments
 (0)