aboutsummaryrefslogtreecommitdiff
path: root/sys/powerpc/powernv/powernv_xscom.c
diff options
context:
space:
mode:
authorWojciech Macek <wma@FreeBSD.org>2018-03-01 14:11:07 +0000
committerWojciech Macek <wma@FreeBSD.org>2018-03-01 14:11:07 +0000
commit4ffd72e34cb3f45ede886c9e30b2a5f705b33132 (patch)
treec900c08ea768ff57e238ca59e6f0d7d238458b3c /sys/powerpc/powernv/powernv_xscom.c
parent023b850b62481007dd3bf305026e12845a4c189c (diff)
downloadsrc-4ffd72e34cb3f45ede886c9e30b2a5f705b33132.tar.gz
src-4ffd72e34cb3f45ede886c9e30b2a5f705b33132.zip
PowerNV: Initial support for OPAL I2C transfers
Add I2C OPAL driver and a set of dummy-ones to allow all I2C things on Power8 to attach. TODO: better async token management Submitted by: Wojciech Macek <wma@semihalf.com> Obtained from: Semihalf Sponsored by: IBM, QCM Technologies
Notes
Notes: svn path=/head/; revision=330240
Diffstat (limited to 'sys/powerpc/powernv/powernv_xscom.c')
-rw-r--r--sys/powerpc/powernv/powernv_xscom.c130
1 files changed, 130 insertions, 0 deletions
diff --git a/sys/powerpc/powernv/powernv_xscom.c b/sys/powerpc/powernv/powernv_xscom.c
new file mode 100644
index 000000000000..669599e3a547
--- /dev/null
+++ b/sys/powerpc/powernv/powernv_xscom.c
@@ -0,0 +1,130 @@
+/*-
+ * Copyright (c) 2017-2018 QCM Technologies.
+ * Copyright (c) 2017-2018 Semihalf.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD$
+ */
+
+#include "opt_platform.h"
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/bus.h>
+#include <sys/conf.h>
+#include <sys/kernel.h>
+#include <sys/lock.h>
+#include <sys/mbuf.h>
+#include <sys/malloc.h>
+#include <sys/module.h>
+#include <sys/mutex.h>
+#include <sys/rman.h>
+#include <machine/bus.h>
+
+#ifdef FDT
+#include <dev/ofw/ofw_bus.h>
+#include <dev/ofw/ofw_bus_subr.h>
+#endif
+
+struct powernv_xscom_softc
+{
+
+};
+
+static int powernv_xscom_attach(device_t);
+static int powernv_xscom_probe(device_t);
+static const struct ofw_bus_devinfo *
+ powernv_xscom_get_devinfo(device_t, device_t);
+
+static device_method_t powernv_xscom_methods[] = {
+ /* Device interface */
+ DEVMETHOD(device_probe, powernv_xscom_probe),
+ DEVMETHOD(device_attach, powernv_xscom_attach),
+
+ /* ofw_bus interface */
+ DEVMETHOD(ofw_bus_get_devinfo, powernv_xscom_get_devinfo),
+ DEVMETHOD(ofw_bus_get_compat, ofw_bus_gen_get_compat),
+ DEVMETHOD(ofw_bus_get_model, ofw_bus_gen_get_model),
+ DEVMETHOD(ofw_bus_get_name, ofw_bus_gen_get_name),
+ DEVMETHOD(ofw_bus_get_node, ofw_bus_gen_get_node),
+ DEVMETHOD(ofw_bus_get_type, ofw_bus_gen_get_type),
+
+ DEVMETHOD_END
+};
+
+static devclass_t powernv_xscom_devclass;
+
+static int
+powernv_xscom_probe(device_t dev)
+{
+
+ if (!(ofw_bus_is_compatible(dev, "ibm,xscom")))
+ return (ENXIO);
+
+ device_set_desc(dev, "xscom");
+ return (0);
+}
+
+static int
+powernv_xscom_attach(device_t dev)
+{
+ phandle_t child;
+ device_t cdev;
+ struct ofw_bus_devinfo *dinfo;
+
+ for (child = OF_child(ofw_bus_get_node(dev)); child != 0;
+ child = OF_peer(child)) {
+ dinfo = malloc(sizeof(*dinfo), M_DEVBUF, M_WAITOK | M_ZERO);
+ if (ofw_bus_gen_setup_devinfo(dinfo, child) != 0) {
+ free(dinfo, M_DEVBUF);
+ continue;
+ }
+ cdev = device_add_child(dev, NULL, -1);
+ if (cdev == NULL) {
+ device_printf(dev, "<%s>: device_add_child failed\n",
+ dinfo->obd_name);
+ ofw_bus_gen_destroy_devinfo(dinfo);
+ free(dinfo, M_DEVBUF);
+ continue;
+ }
+ device_set_ivars(cdev, dinfo);
+ }
+
+ return (bus_generic_attach(dev));
+}
+
+static const struct ofw_bus_devinfo *
+powernv_xscom_get_devinfo(device_t dev, device_t child)
+{
+ return (device_get_ivars(child));
+}
+
+DEFINE_CLASS_0(powernv_xscom, powernv_xscom_driver, powernv_xscom_methods,
+ sizeof(struct powernv_xscom_softc));
+DRIVER_MODULE(powernv_xscom, ofwbus, powernv_xscom_driver, powernv_xscom_devclass, NULL,
+ NULL);
+