summaryrefslogtreecommitdiffstats
path: root/src/include
diff options
context:
space:
mode:
Diffstat (limited to 'src/include')
-rw-r--r--src/include/gpxe/nvs/threewire.h102
-rw-r--r--src/include/gpxe/spi.h132
-rw-r--r--src/include/gpxe/threewire.h65
3 files changed, 197 insertions, 102 deletions
diff --git a/src/include/gpxe/nvs/threewire.h b/src/include/gpxe/nvs/threewire.h
deleted file mode 100644
index a0bb2fd39..000000000
--- a/src/include/gpxe/nvs/threewire.h
+++ /dev/null
@@ -1,102 +0,0 @@
-#ifndef _GPXE_NVS_THREEWIRE_H
-#define _GPXE_NVS_THREEWIRE_H
-
-/** @file
- *
- * Three-wire serial interface
- *
- */
-
-struct threewire;
-
-/** Three-wire interface methods */
-struct threewire_operations {
- /**
- * Set status of Chip Select line
- *
- * @v three Three-wire interface
- * @v cs New status for chip select line
- */
- void ( * setcs ) ( struct threewire *three, int cs );
- /**
- * Set status of Serial Clock line
- *
- * @v three Three-wire interface
- * @v sk New status for serial clock line
- */
- void ( * setsk ) ( struct threewire *three, int sk );
- /**
- * Set status of Data Input line
- *
- * @v three Three-wire interface
- * @v di New status for data input line
- */
- void ( * setdi ) ( struct threewire *three, int di );
- /**
- * Get status of Data Output line
- *
- * @v three Three-wire interface
- * @ret do Status of data output line
- */
- int ( * getdo ) ( struct threewire *three );
-};
-
-/**
- * A three-wire serial interface
- *
- * This interface consists of a clock line (SK), data input (DI) and
- * data output (DO). There is also a chip select line (CS) which is
- * integral to the operation of the device, but Atmel still calls it a
- * three-wire interface.
- *
- */
-struct threewire {
- /** Interface methods */
- struct threewire_operations *ops;
- /** Address size (in bits) */
- unsigned int adrsize;
- /** Data size (in bits) */
- unsigned int datasize;
- /** Delay between SK transitions (in us) */
- unsigned int udelay;
-};
-
-/**
- * Calculate read command for a specified address
- *
- * @v three Three-wire interface
- * @v address Address
- * @ret cmd Command
- */
-static inline __attribute__ (( always_inline )) unsigned long
-threewire_cmd_read ( struct threewire *three, unsigned long address ) {
- return ( ( 0x6 << three->adrsize ) | address );
-}
-
-/**
- * Calculate command length
- *
- * @v three Three-wire interface
- * @ret len Command length, in bits
- */
-static inline __attribute__ (( always_inline )) int
-threewire_cmd_len ( struct threewire *three ) {
- return ( three->adrsize + 3 );
-}
-
-/* Constants for some standard parts */
-#define AT93C46_ORG8_ADRSIZE 7
-#define AT93C46_ORG8_DATASIZE 8
-#define AT93C46_ORG16_ADRSIZE 6
-#define AT93C46_ORG16_DATASIZE 16
-#define AT93C46_UDELAY 1
-#define AT93C56_ORG8_ADRSIZE 9
-#define AT93C56_ORG8_DATASIZE 8
-#define AT93C56_ORG16_ADRSIZE 8
-#define AT93C56_ORG16_DATASIZE 16
-#define AT93C56_UDELAY 1
-
-extern unsigned long threewire_read ( struct threewire *three,
- unsigned long address );
-
-#endif /* _GPXE_NVS_THREEWIRE_H */
diff --git a/src/include/gpxe/spi.h b/src/include/gpxe/spi.h
new file mode 100644
index 000000000..3ea858467
--- /dev/null
+++ b/src/include/gpxe/spi.h
@@ -0,0 +1,132 @@
+#ifndef _GPXE_SPI_H
+#define _GPXE_SPI_H
+
+/** @file
+ *
+ * SPI interface
+ *
+ */
+
+#include <gpxe/bitbash.h>
+
+/** An SPI interface */
+struct spi_interface {
+ /** SPI interface mode
+ *
+ * This is the bitwise OR of zero or more of @c SPI_MODE_CPHA
+ * and @c SPI_MODE_CPOL. It is also the number conventionally
+ * used to describe the SPI interface mode. For example, SPI
+ * mode 1 is the mode in which CPOL=0 and CPHA=1, which
+ * therefore corresponds to a mode value of (0|SPI_MODE_CPHA)
+ * which, happily, equals 1.
+ */
+ unsigned int mode;
+ /**
+ * Select slave
+ *
+ * @v spi SPI interface
+ * @v slave Slave number
+ */
+ void ( * select_slave ) ( struct spi_interface *spi,
+ unsigned int slave );
+ /**
+ * Deselect slave
+ *
+ * @v spi SPI interface
+ */
+ void ( * deselect_slave ) ( struct spi_interface *spi );
+ /**
+ * Transfer bits over SPI bit-bashing interface
+ *
+ * @v spi SPI interface
+ * @v data_out TX data buffer (or NULL)
+ * @v data_in RX data buffer (or NULL)
+ * @v len Length of transfer (in @b bits)
+ */
+ void ( * transfer ) ( struct spi_interface *spi, const void *data_out,
+ void *data_in, unsigned int len );
+};
+
+/** Clock phase (CPHA) mode bit
+ *
+ * Phase 0 is sample on rising edge, shift data on falling edge.
+ *
+ * Phase 1 is shift data on rising edge, sample data on falling edge.
+ */
+#define SPI_MODE_CPHA 0x01
+
+/** Clock polarity (CPOL) mode bit
+ *
+ * This bit reflects the idle state of the clock line (SCLK).
+ */
+#define SPI_MODE_CPOL 0x02
+
+/** Slave select polarity mode bit
+ *
+ * This bit reflects that active state of the slave select lines. It
+ * is not part of the normal SPI mode number (which covers only @c
+ * SPI_MODE_CPOL and @c SPI_MODE_CPHA), but is included here for
+ * convenience.
+ */
+#define SPI_MODE_SSPOL 0x10
+
+/** Microwire-compatible mode
+ *
+ * This is SPI mode 1 (i.e. CPOL=0, CPHA=1), and is compatible with
+ * the original Microwire protocol.
+ */
+#define SPI_MODE_MICROWIRE 1
+
+/** Microwire/Plus-compatible mode
+ *
+ * This is SPI mode 0 (i.e. CPOL=0, CPHA=0), and is compatible with
+ * the Microwire/Plus protocol
+ */
+#define SPI_MODE_MICROWIRE_PLUS 0
+
+/** Threewire-compatible mode
+ *
+ * This mode is compatible with Atmel's series of "three-wire"
+ * interfaces.
+ */
+#define SPI_MODE_THREEWIRE ( SPI_MODE_MICROWIRE_PLUS | SPI_MODE_SSPOL )
+
+/** A bit-bashing SPI interface */
+struct spi_bit_basher {
+ /** SPI interface */
+ struct spi_interface spi;
+ /** Bit-bashing interface */
+ struct bit_basher basher;
+ /** Currently selected slave
+ *
+ * Valid only when a slave is actually selected.
+ */
+ unsigned int slave;
+};
+
+/** Bit indices used for SPI bit-bashing interface */
+enum {
+ /** Serial clock */
+ SPI_BIT_SCLK = 0,
+ /** Master Out Slave In */
+ SPI_BIT_MOSI,
+ /** Master In Slave Out */
+ SPI_BIT_MISO,
+ /** Slave 0 select */
+ SPI_BIT_SS0,
+};
+
+/**
+ * Determine bit index for a particular slave
+ *
+ * @v slave Slave number
+ * @ret index Bit index (i.e. SPI_BIT_SSN, where N=slave)
+ */
+#define SPI_BIT_SS( slave ) ( SPI_BIT_SS0 + (slave) )
+
+/** Delay between SCLK transitions */
+#define SPI_UDELAY 1
+
+extern void init_spi_bit_basher ( struct spi_bit_basher *spibit );
+
+#endif /* _GPXE_SPI_H */
diff --git a/src/include/gpxe/threewire.h b/src/include/gpxe/threewire.h
new file mode 100644
index 000000000..d9d885671
--- /dev/null
+++ b/src/include/gpxe/threewire.h
@@ -0,0 +1,65 @@
+#ifndef _GPXE_THREEWIRE_H
+#define _GPXE_THREEWIRE_H
+
+/** @file
+ *
+ * Three-wire serial interface
+ *
+ * The Atmel three-wire interface is a subset of the (newer) SPI
+ * interface, and is implemented here as a layer on top of the SPI
+ * support.
+ */
+
+struct spi_interface;
+
+/** A three-wire device */
+struct threewire_device {
+ /** SPI interface to which device is attached */
+ struct spi_interface *spi;
+ /** SPI slave number */
+ unsigned int slave;
+ /** Address size (in bits) */
+ unsigned int adrsize;
+ /** Data size (in bits) */
+ unsigned int datasize;
+};
+
+/**
+ * Calculate read command for a specified address
+ *
+ * @v three Three-wire interface
+ * @v address Address
+ * @ret cmd Command
+ */
+static inline __attribute__ (( always_inline )) unsigned long
+threewire_cmd_read ( struct threewire_device *three, unsigned long address ) {
+ return ( ( 0x6 << three->adrsize ) | address );
+}
+
+/**
+ * Calculate command length
+ *
+ * @v three Three-wire interface
+ * @ret len Command length, in bits
+ */
+static inline __attribute__ (( always_inline )) unsigned int
+threewire_cmd_len ( struct threewire_device *three ) {
+ return ( three->adrsize + 3 );
+}
+
+/* Constants for some standard parts */
+#define AT93C46_ORG8_ADRSIZE 7
+#define AT93C46_ORG8_DATASIZE 8
+#define AT93C46_ORG16_ADRSIZE 6
+#define AT93C46_ORG16_DATASIZE 16
+#define AT93C46_UDELAY 1
+#define AT93C56_ORG8_ADRSIZE 9
+#define AT93C56_ORG8_DATASIZE 8
+#define AT93C56_ORG16_ADRSIZE 8
+#define AT93C56_ORG16_DATASIZE 16
+#define AT93C56_UDELAY 1
+
+extern unsigned long threewire_read ( struct threewire_device *three,
+ unsigned long address );
+
+#endif /* _GPXE_THREEWIRE_H */