summaryrefslogtreecommitdiff
path: root/sys/dev/spi
diff options
context:
space:
mode:
authorPatrick Wildt <patrick@cvs.openbsd.org>2018-07-26 10:59:08 +0000
committerPatrick Wildt <patrick@cvs.openbsd.org>2018-07-26 10:59:08 +0000
commit6a34b1a6a53923739b47509f6ced423c3327d111 (patch)
treebd98821a9cbc5550d0fdd2787a4ea23e792957f4 /sys/dev/spi
parent8aa9665a23235730cc82ca6708422be083b7b4a6 (diff)
Add imxspi(4), a driver for the i.MX SPI controller. This is the first
SPI controller in our tree. Add a basic generic SPI infrastructure as well. ok kettenis@
Diffstat (limited to 'sys/dev/spi')
-rw-r--r--sys/dev/spi/spivar.h53
1 files changed, 53 insertions, 0 deletions
diff --git a/sys/dev/spi/spivar.h b/sys/dev/spi/spivar.h
new file mode 100644
index 00000000000..986bc7f602d
--- /dev/null
+++ b/sys/dev/spi/spivar.h
@@ -0,0 +1,53 @@
+/* $OpenBSD: spivar.h,v 1.1 2018/07/26 10:59:07 patrick Exp $ */
+/*
+ * Copyright (c) 2018 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.
+ */
+
+struct spi_config {
+ int sc_cs;
+ int sc_flags;
+#define SPI_CONFIG_CPOL (1 << 0)
+#define SPI_CONFIG_CPHA (1 << 1)
+#define SPI_CONFIG_CS_HIGH (1 << 2)
+ int sc_bpw;
+ uint32_t sc_freq;
+};
+
+typedef struct spi_controller {
+ void *sc_cookie;
+ void (*sc_config)(void *, struct spi_config *);
+ int (*sc_transfer)(void *, char *, char *, int);
+ int (*sc_acquire_bus)(void *, int);
+ void (*sc_release_bus)(void *, int);
+} *spi_tag_t;
+
+struct spi_attach_args {
+ spi_tag_t sa_tag;
+ char *sa_name;
+ void *sa_cookie;
+};
+
+#define spi_config(sc, config) \
+ (*(sc)->sc_config)((sc)->sc_cookie, (config))
+#define spi_read(sc, data, len) \
+ (*(sc)->sc_transfer)((sc)->sc_cookie, NULL, (data), (len))
+#define spi_write(sc, data, len) \
+ (*(sc)->sc_transfer)((sc)->sc_cookie, (data), NULL, (len))
+#define spi_transfer(sc, out, in, len) \
+ (*(sc)->sc_transfer)((sc)->sc_cookie, (out), (in), (len))
+#define spi_acquire_bus(sc, flags) \
+ (*(sc)->sc_acquire_bus)((sc)->sc_cookie, (flags))
+#define spi_release_bus(sc, flags) \
+ (*(sc)->sc_release_bus)((sc)->sc_cookie, (flags))