]> git.kernelconcepts.de Git - karo-tx-uboot.git/blobdiff - include/spi.h
Merge remote-tracking branch 'remotes/tx6/tx6' into karo-tx-uboot
[karo-tx-uboot.git] / include / spi.h
index 89949b11b70cfb02f57424f131fa10fdc66d49f3..c58e453559616eb1cbbca36ee20704afcd4ebecc 100644 (file)
@@ -34,6 +34,7 @@
 
 /* SPI TX operation modes */
 #define SPI_OPM_TX_QPP         (1 << 0)
+#define SPI_OPM_TX_BP          (1 << 1)
 
 /* SPI RX operation modes */
 #define SPI_OPM_RX_AS          (1 << 0)
 #define SPI_DEFAULT_WORDLEN 8
 
 #ifdef CONFIG_DM_SPI
+/* TODO(sjg@chromium.org): Remove this and use max_hz from struct spi_slave */
 struct dm_spi_bus {
        uint max_hz;
 };
 
+/**
+ * struct dm_spi_platdata - platform data for all SPI slaves
+ *
+ * This describes a SPI slave, a child device of the SPI bus. To obtain this
+ * struct from a spi_slave, use dev_get_parent_platdata(dev) or
+ * dev_get_parent_platdata(slave->dev).
+ *
+ * This data is immuatable. Each time the device is probed, @max_hz and @mode
+ * will be copied to struct spi_slave.
+ *
+ * @cs:                Chip select number (0..n-1)
+ * @max_hz:    Maximum bus speed that this slave can tolerate
+ * @mode:      SPI mode to use for this device (see SPI mode flags)
+ */
+struct dm_spi_slave_platdata {
+       unsigned int cs;
+       uint max_hz;
+       uint mode;
+};
+
 #endif /* CONFIG_DM_SPI */
 
 /**
  * struct spi_slave - Representation of a SPI slave
  *
  * For driver model this is the per-child data used by the SPI bus. It can
- * be accessed using dev_get_parentdata() on the slave device. Each SPI
- * driver should define this child data in its U_BOOT_DRIVER() definition:
- *
- *     .per_child_auto_alloc_size      = sizeof(struct spi_slave),
+ * be accessed using dev_get_parentdata() on the slave device. The SPI uclass
+ * sets uip per_child_auto_alloc_size to sizeof(struct spi_slave), and the
+ * driver should not override it. Two platform data fields (max_hz and mode)
+ * are copied into this structure to provide an initial value. This allows
+ * them to be changed, since we should never change platform data in drivers.
  *
  * If not using driver model, drivers are expected to extend this with
  * controller-specific data.
@@ -96,8 +119,8 @@ struct spi_slave {
        uint mode;
 #else
        unsigned int bus;
-#endif
        unsigned int cs;
+#endif
        u8 op_mode_rx;
        u8 op_mode_tx;
        unsigned int wordlen;
@@ -456,6 +479,35 @@ struct dm_spi_ops {
        int (*cs_info)(struct udevice *bus, uint cs, struct spi_cs_info *info);
 };
 
+struct dm_spi_emul_ops {
+       /**
+        * SPI transfer
+        *
+        * This writes "bitlen" bits out the SPI MOSI port and simultaneously
+        * clocks "bitlen" bits in the SPI MISO port.  That's just the way SPI
+        * works. Here the device is a slave.
+        *
+        * The source of the outgoing bits is the "dout" parameter and the
+        * destination of the input bits is the "din" parameter.  Note that
+        * "dout" and "din" can point to the same memory location, in which
+        * case the input data overwrites the output data (since both are
+        * buffered by temporary variables, this is OK).
+        *
+        * spi_xfer() interface:
+        * @slave:      The SPI slave which will be sending/receiving the data.
+        * @bitlen:     How many bits to write and read.
+        * @dout:       Pointer to a string of bits sent to the device. The
+        *              bits are held in a byte array and are sent MSB first.
+        * @din:        Pointer to a string of bits that will be sent back to
+        *              the master.
+        * @flags:      A bitwise combination of SPI_XFER_* flags.
+        *
+        * Returns: 0 on success, not -1 on failure
+        */
+       int (*xfer)(struct udevice *slave, unsigned int bitlen,
+                   const void *dout, void *din, unsigned long flags);
+};
+
 /**
  * spi_find_bus_and_cs() - Find bus and slave devices by number
  *
@@ -505,30 +557,26 @@ int spi_get_bus_and_cs(int busnum, int cs, int speed, int mode,
 int spi_chip_select(struct udevice *slave);
 
 /**
- * spi_bind_device() - bind a device to a bus's chip select
- *
- * This binds a new device to an given chip select (which must be unused).
+ * spi_find_chip_select() - Find the slave attached to chip select
  *
  * @bus:       SPI bus to search
- * @cs:                Chip select to attach to
- * @drv_name:  Name of driver to attach to this chip select
- * @dev_name:  Name of the new device thus created
- * @devp:      Returns the newly bound device
+ * @cs:                Chip select to look for
+ * @devp:      Returns the slave device if found
+ * @return 0 if found, -ENODEV on error
  */
-int spi_bind_device(struct udevice *bus, int cs, const char *drv_name,
-                   const char *dev_name, struct udevice **devp);
+int spi_find_chip_select(struct udevice *bus, int cs, struct udevice **devp);
 
 /**
- * spi_ofdata_to_platdata() - decode standard SPI platform data
+ * spi_slave_ofdata_to_platdata() - decode standard SPI platform data
  *
- * This decodes the speed and mode from a device tree node and puts it into
- * the spi_slave structure.
+ * This decodes the speed and mode for a slave from a device tree node
  *
  * @blob:      Device tree blob
  * @node:      Node offset to read from
- * @spi:       Place to put the decoded information
+ * @plat:      Place to put the decoded information
  */
-int spi_ofdata_to_platdata(const void *blob, int node, struct spi_slave *spi);
+int spi_slave_ofdata_to_platdata(const void *blob, int node,
+                                struct dm_spi_slave_platdata *plat);
 
 /**
  * spi_cs_info() - Check information on a chip select
@@ -545,12 +593,28 @@ int spi_ofdata_to_platdata(const void *blob, int node, struct spi_slave *spi);
 int spi_cs_info(struct udevice *bus, uint cs, struct spi_cs_info *info);
 
 struct sandbox_state;
+
+/**
+ * sandbox_spi_get_emul() - get an emulator for a SPI slave
+ *
+ * This provides a way to attach an emulated SPI device to a particular SPI
+ * slave, so that xfer() operations on the slave will be handled by the
+ * emulator. If a emulator already exists on that chip select it is returned.
+ * Otherwise one is created.
+ *
+ * @state:     Sandbox state
+ * @bus:       SPI bus requesting the emulator
+ * @slave:     SPI slave device requesting the emulator
+ * @emuip:     Returns pointer to emulator
+ * @return 0 if OK, -ve on error
+ */
 int sandbox_spi_get_emul(struct sandbox_state *state,
                         struct udevice *bus, struct udevice *slave,
                         struct udevice **emulp);
 
 /* Access the serial operations for a device */
 #define spi_get_ops(dev)       ((struct dm_spi_ops *)(dev)->driver->ops)
+#define spi_emul_get_ops(dev)  ((struct dm_spi_emul_ops *)(dev)->driver->ops)
 #endif /* CONFIG_DM_SPI */
 
 #endif /* _SPI_H_ */