summaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
authorPatrick Wildt <patrick@cvs.openbsd.org>2023-07-22 22:43:54 +0000
committerPatrick Wildt <patrick@cvs.openbsd.org>2023-07-22 22:43:54 +0000
commit6fa3242c4b409f090e3a3defcf37726d9b74d8e7 (patch)
treed873ca29c7cfe050154191a21097ce986d80e459 /sys
parent7cfb2ecfac10c32d01ce41552d77a820c43de48a (diff)
Add qcsdam(4), a driver for the PMIC Shared Direct Access Memory found on
Qualcomm SoCs. ok kettenis@
Diffstat (limited to 'sys')
-rw-r--r--sys/arch/arm64/conf/GENERIC3
-rw-r--r--sys/arch/arm64/conf/RAMDISK3
-rw-r--r--sys/dev/fdt/files.fdt7
-rw-r--r--sys/dev/fdt/qcsdam.c119
4 files changed, 129 insertions, 3 deletions
diff --git a/sys/arch/arm64/conf/GENERIC b/sys/arch/arm64/conf/GENERIC
index 7b8e6a16422..3b6bc19cf0a 100644
--- a/sys/arch/arm64/conf/GENERIC
+++ b/sys/arch/arm64/conf/GENERIC
@@ -1,4 +1,4 @@
-# $OpenBSD: GENERIC,v 1.276 2023/07/19 20:27:20 kettenis Exp $
+# $OpenBSD: GENERIC,v 1.277 2023/07/22 22:43:53 patrick Exp $
#
# GENERIC machine description file
#
@@ -343,6 +343,7 @@ qcpon* at qcpmic?
qcpwm* at qcpmic?
qcrng* at fdt?
qcrtc* at qcpmic?
+qcsdam* at qcpmic?
# Sunxi SoCs
sxipio* at fdt? early 1 # GPIO pins for leds & PHYs
diff --git a/sys/arch/arm64/conf/RAMDISK b/sys/arch/arm64/conf/RAMDISK
index 860174ce50f..a22db00c6cc 100644
--- a/sys/arch/arm64/conf/RAMDISK
+++ b/sys/arch/arm64/conf/RAMDISK
@@ -1,4 +1,4 @@
-# $OpenBSD: RAMDISK,v 1.208 2023/07/19 20:27:20 kettenis Exp $
+# $OpenBSD: RAMDISK,v 1.209 2023/07/22 22:43:53 patrick Exp $
machine arm64
maxusers 4
@@ -266,6 +266,7 @@ qcpon* at qcpmic?
qcpwm* at qcpmic?
qcrng* at fdt?
qcrtc* at qcpmic?
+qcsdam* at qcpmic?
# Sunxi SoCs
sxipio* at fdt? early 1 # GPIO pins for leds & PHYs
diff --git a/sys/dev/fdt/files.fdt b/sys/dev/fdt/files.fdt
index fa34dd44f20..af80b6d33b6 100644
--- a/sys/dev/fdt/files.fdt
+++ b/sys/dev/fdt/files.fdt
@@ -1,4 +1,4 @@
-# $OpenBSD: files.fdt,v 1.195 2023/07/01 16:34:30 drahn Exp $
+# $OpenBSD: files.fdt,v 1.196 2023/07/22 22:43:53 patrick Exp $
#
# Config file and device description for machine-independent FDT code.
# Included by ports that need it.
@@ -761,6 +761,11 @@ device qcrtc
attach qcrtc at spmi
file dev/fdt/qcrtc.c qcrtc
+# Qualcomm PMIC Shared Direct Access Memory
+device qcsdam
+attach qcsdam at spmi
+file dev/fdt/qcsdam.c qcsdam
+
# TI TPS6598x Type-C controller
device tipd
attach tipd at i2c
diff --git a/sys/dev/fdt/qcsdam.c b/sys/dev/fdt/qcsdam.c
new file mode 100644
index 00000000000..309c889b35e
--- /dev/null
+++ b/sys/dev/fdt/qcsdam.c
@@ -0,0 +1,119 @@
+/* $OpenBSD: qcsdam.c,v 1.1 2023/07/22 22:43:53 patrick Exp $ */
+/*
+ * Copyright (c) 2023 Patrick Wildt <patrick@blueri.se>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/device.h>
+
+#include <machine/bus.h>
+#include <machine/fdt.h>
+
+#include <dev/fdt/spmivar.h>
+
+#include <dev/ofw/openfirm.h>
+#include <dev/ofw/ofw_misc.h>
+#include <dev/ofw/fdt.h>
+
+struct qcsdam_softc {
+ struct device sc_dev;
+ spmi_tag_t sc_tag;
+ int8_t sc_sid;
+ uint16_t sc_addr;
+
+ struct nvmem_device sc_nd;
+};
+
+int qcsdam_match(struct device *, void *, void *);
+void qcsdam_attach(struct device *, struct device *, void *);
+
+const struct cfattach qcsdam_ca = {
+ sizeof (struct qcsdam_softc), qcsdam_match, qcsdam_attach
+};
+
+struct cfdriver qcsdam_cd = {
+ NULL, "qcsdam", DV_DULL
+};
+
+int qcsdam_nvmem_read(void *, bus_addr_t, void *, bus_size_t);
+int qcsdam_nvmem_write(void *, bus_addr_t, const void *, bus_size_t);
+
+int
+qcsdam_match(struct device *parent, void *match, void *aux)
+{
+ struct spmi_attach_args *saa = aux;
+
+ return OF_is_compatible(saa->sa_node, "qcom,spmi-sdam");
+}
+
+void
+qcsdam_attach(struct device *parent, struct device *self, void *aux)
+{
+ struct qcsdam_softc *sc = (struct qcsdam_softc *)self;
+ struct spmi_attach_args *saa = aux;
+ uint32_t reg;
+
+ if (OF_getpropintarray(saa->sa_node, "reg",
+ &reg, sizeof(reg)) != sizeof(reg)) {
+ printf(": can't find registers\n");
+ return;
+ }
+
+ sc->sc_tag = saa->sa_tag;
+ sc->sc_sid = saa->sa_sid;
+ sc->sc_addr = reg;
+
+ printf("\n");
+
+ sc->sc_nd.nd_node = saa->sa_node;
+ sc->sc_nd.nd_cookie = sc;
+ sc->sc_nd.nd_read = qcsdam_nvmem_read;
+ sc->sc_nd.nd_write = qcsdam_nvmem_write;
+ nvmem_register(&sc->sc_nd);
+}
+
+int
+qcsdam_nvmem_read(void *cookie, bus_addr_t addr, void *data, bus_size_t size)
+{
+ struct qcsdam_softc *sc = cookie;
+ int error;
+
+ error = spmi_cmd_read(sc->sc_tag, sc->sc_sid, SPMI_CMD_EXT_READL,
+ sc->sc_addr + addr, data, size);
+ if (error) {
+ printf("%s: error reading NVMEM\n", sc->sc_dev.dv_xname);
+ return error;
+ }
+
+ return 0;
+}
+
+int
+qcsdam_nvmem_write(void *cookie, bus_addr_t addr, const void *data,
+ bus_size_t size)
+{
+ struct qcsdam_softc *sc = cookie;
+ int error;
+
+ error = spmi_cmd_write(sc->sc_tag, sc->sc_sid, SPMI_CMD_EXT_WRITEL,
+ sc->sc_addr + addr, data, size);
+ if (error) {
+ printf("%s: error reading NVMEM\n", sc->sc_dev.dv_xname);
+ return error;
+ }
+
+ return 0;
+}