2018-05-06 21:58:06 +00:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0+ */
|
2002-09-26 02:01:47 +00:00
|
|
|
/*
|
2013-10-10 16:44:09 +00:00
|
|
|
* Common SPI Interface: Controller-specific definitions
|
|
|
|
*
|
2002-09-26 02:01:47 +00:00
|
|
|
* (C) Copyright 2001
|
|
|
|
* Gerald Van Baren, Custom IDEAS, vanbaren@cideas.com.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _SPI_H_
|
|
|
|
#define _SPI_H_
|
|
|
|
|
2018-08-16 15:30:11 +00:00
|
|
|
#include <common.h>
|
2020-05-10 17:40:13 +00:00
|
|
|
#include <linux/bitops.h>
|
2018-08-16 15:30:11 +00:00
|
|
|
|
2008-04-15 12:14:25 +00:00
|
|
|
/* SPI mode flags */
|
2020-07-07 19:11:49 +00:00
|
|
|
#define SPI_CPHA BIT(0) /* clock phase (1 = SPI_CLOCK_PHASE_SECOND) */
|
|
|
|
#define SPI_CPOL BIT(1) /* clock polarity (1 = SPI_POLARITY_HIGH) */
|
2015-12-29 06:42:30 +00:00
|
|
|
#define SPI_MODE_0 (0|0) /* (original MicroWire) */
|
|
|
|
#define SPI_MODE_1 (0|SPI_CPHA)
|
|
|
|
#define SPI_MODE_2 (SPI_CPOL|0)
|
|
|
|
#define SPI_MODE_3 (SPI_CPOL|SPI_CPHA)
|
|
|
|
#define SPI_CS_HIGH BIT(2) /* CS active high */
|
|
|
|
#define SPI_LSB_FIRST BIT(3) /* per-word bits-on-wire */
|
|
|
|
#define SPI_3WIRE BIT(4) /* SI/SO signals shared */
|
|
|
|
#define SPI_LOOP BIT(5) /* loopback mode */
|
|
|
|
#define SPI_SLAVE BIT(6) /* slave mode */
|
|
|
|
#define SPI_PREAMBLE BIT(7) /* Skip preamble bytes */
|
2015-12-28 16:54:08 +00:00
|
|
|
#define SPI_TX_BYTE BIT(8) /* transmit with 1 wire byte */
|
2015-12-28 17:25:50 +00:00
|
|
|
#define SPI_TX_DUAL BIT(9) /* transmit with 2 wires */
|
|
|
|
#define SPI_TX_QUAD BIT(10) /* transmit with 4 wires */
|
2016-08-08 11:42:12 +00:00
|
|
|
#define SPI_RX_SLOW BIT(11) /* receive with 1 wire slow */
|
2016-08-10 15:18:14 +00:00
|
|
|
#define SPI_RX_DUAL BIT(12) /* receive with 2 wires */
|
|
|
|
#define SPI_RX_QUAD BIT(13) /* receive with 4 wires */
|
2019-12-05 10:16:05 +00:00
|
|
|
#define SPI_TX_OCTAL BIT(14) /* transmit with 8 wires */
|
|
|
|
#define SPI_RX_OCTAL BIT(15) /* receive with 8 wires */
|
2014-01-11 09:40:28 +00:00
|
|
|
|
2013-05-28 20:10:37 +00:00
|
|
|
/* Header byte that marks the start of the message */
|
2013-10-07 14:04:56 +00:00
|
|
|
#define SPI_PREAMBLE_END_BYTE 0xec
|
2013-05-28 20:10:37 +00:00
|
|
|
|
2015-06-26 19:21:30 +00:00
|
|
|
#define SPI_DEFAULT_WORDLEN 8
|
2013-10-16 14:23:25 +00:00
|
|
|
|
2020-12-14 17:06:50 +00:00
|
|
|
/**
|
|
|
|
* struct dm_spi_bus - SPI bus info
|
|
|
|
*
|
|
|
|
* This contains information about a SPI bus. To obtain this structure, use
|
|
|
|
* dev_get_uclass_priv(bus) where bus is the SPI bus udevice.
|
|
|
|
*
|
|
|
|
* @max_hz: Maximum speed that the bus can tolerate.
|
|
|
|
* @speed: Current bus speed. This is 0 until the bus is first claimed.
|
|
|
|
* @mode: Current bus mode. This is 0 until the bus is first claimed.
|
|
|
|
*
|
|
|
|
* TODO(sjg@chromium.org): Remove this and use max_hz from struct spi_slave.
|
|
|
|
*/
|
2014-10-14 05:41:52 +00:00
|
|
|
struct dm_spi_bus {
|
|
|
|
uint max_hz;
|
2020-12-14 17:06:50 +00:00
|
|
|
uint speed;
|
|
|
|
uint mode;
|
2014-10-14 05:41:52 +00:00
|
|
|
};
|
|
|
|
|
2015-01-25 15:27:12 +00:00
|
|
|
/**
|
2020-12-03 23:55:23 +00:00
|
|
|
* struct dm_spi_plat - platform data for all SPI slaves
|
2015-01-25 15:27:12 +00:00
|
|
|
*
|
|
|
|
* This describes a SPI slave, a child device of the SPI bus. To obtain this
|
2020-12-03 23:55:18 +00:00
|
|
|
* struct from a spi_slave, use dev_get_parent_plat(dev) or
|
|
|
|
* dev_get_parent_plat(slave->dev).
|
2015-01-25 15:27:12 +00:00
|
|
|
*
|
2020-08-07 17:13:34 +00:00
|
|
|
* This data is immutable. Each time the device is probed, @max_hz and @mode
|
2015-01-25 15:27:12 +00:00
|
|
|
* 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)
|
|
|
|
*/
|
2020-12-03 23:55:23 +00:00
|
|
|
struct dm_spi_slave_plat {
|
2015-01-25 15:27:12 +00:00
|
|
|
unsigned int cs;
|
|
|
|
uint max_hz;
|
|
|
|
uint mode;
|
|
|
|
};
|
|
|
|
|
2020-04-08 22:57:21 +00:00
|
|
|
/**
|
|
|
|
* enum spi_clock_phase - indicates the clock phase to use for SPI (CPHA)
|
|
|
|
*
|
|
|
|
* @SPI_CLOCK_PHASE_FIRST: Data sampled on the first phase
|
|
|
|
* @SPI_CLOCK_PHASE_SECOND: Data sampled on the second phase
|
|
|
|
*/
|
|
|
|
enum spi_clock_phase {
|
|
|
|
SPI_CLOCK_PHASE_FIRST,
|
|
|
|
SPI_CLOCK_PHASE_SECOND,
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* enum spi_wire_mode - indicates the number of wires used for SPI
|
|
|
|
*
|
|
|
|
* @SPI_4_WIRE_MODE: Normal bidirectional mode with MOSI and MISO
|
|
|
|
* @SPI_3_WIRE_MODE: Unidirectional version with a single data line SISO
|
|
|
|
*/
|
|
|
|
enum spi_wire_mode {
|
|
|
|
SPI_4_WIRE_MODE,
|
|
|
|
SPI_3_WIRE_MODE,
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* enum spi_polarity - indicates the polarity of the SPI bus (CPOL)
|
|
|
|
*
|
|
|
|
* @SPI_POLARITY_LOW: Clock is low in idle state
|
|
|
|
* @SPI_POLARITY_HIGH: Clock is high in idle state
|
|
|
|
*/
|
|
|
|
enum spi_polarity {
|
|
|
|
SPI_POLARITY_LOW,
|
|
|
|
SPI_POLARITY_HIGH,
|
|
|
|
};
|
|
|
|
|
2013-09-25 10:17:36 +00:00
|
|
|
/**
|
2013-10-07 14:04:56 +00:00
|
|
|
* struct spi_slave - Representation of a SPI slave
|
SPI API improvements
This patch gets rid of the spi_chipsel table and adds a handful of new
functions that makes the SPI layer cleaner and more flexible.
Instead of the spi_chipsel table, each board that wants to use SPI
gets to implement three hooks:
* spi_cs_activate(): Activates the chipselect for a given slave
* spi_cs_deactivate(): Deactivates the chipselect for a given slave
* spi_cs_is_valid(): Determines if the given bus/chipselect
combination can be activated.
Not all drivers may need those extra functions however. If that's the
case, the board code may just leave them out (assuming they know what
the driver needs) or rely on the linker to strip them out (assuming
--gc-sections is being used.)
To set up communication parameters for a given slave, the driver needs
to call spi_setup_slave(). This returns a pointer to an opaque
spi_slave struct which must be passed as a parameter to subsequent SPI
calls. This struct can be freed by calling spi_free_slave(), but most
driver probably don't want to do this.
Before starting one or more SPI transfers, the driver must call
spi_claim_bus() to gain exclusive access to the SPI bus and initialize
the hardware. When all transfers are done, the driver must call
spi_release_bus() to make the bus available to others, and possibly
shut down the SPI controller hardware.
spi_xfer() behaves mostly the same as before, but it now takes a
spi_slave parameter instead of a spi_chipsel function pointer. It also
got a new parameter, flags, which is used to specify chip select
behaviour. This may be extended with other flags in the future.
This patch has been build-tested on all powerpc and arm boards
involved. I have not tested NIOS since I don't have a toolchain for it
installed, so I expect some breakage there even though I've tried
fixing up everything I could find by visual inspection.
I have run-time tested this on AVR32 ATNGW100 using the atmel_spi and
DataFlash drivers posted as a follow-up. I'd like some help testing
other boards that use the existing SPI API.
But most of all, I'd like some comments on the new API. Is this stuff
usable for everyone? If not, why?
Changed in v4:
- Build fixes for various boards, drivers and commands
- Provide common struct spi_slave definition that can be extended by
drivers
- Pass a struct spi_slave * to spi_cs_activate and spi_cs_deactivate
- Make default bus and mode build-time configurable
- Override default SPI bus ID and mode on mx32ads and imx31_litekit.
Changed in v3:
- Add opaque struct spi_slave for controller-specific data associated
with a slave.
- Add spi_claim_bus() and spi_release_bus()
- Add spi_free_slave()
- spi_setup() is now called spi_setup_slave() and returns a
struct spi_slave
- soft_spi now supports four SPI modes (CPOL|CPHA)
- Add bus parameter to spi_setup_slave()
- Convert the new i.MX32 SPI driver
- Convert the new MC13783 RTC driver
Changed in v2:
- Convert the mpc8xxx_spi driver and the mpc8349emds board to the
new API.
Signed-off-by: Haavard Skinnemoen <hskinnemoen@atmel.com>
Tested-by: Guennadi Liakhovetski <lg@denx.de>
2008-05-16 09:10:31 +00:00
|
|
|
*
|
2014-10-14 05:41:52 +00:00
|
|
|
* For driver model this is the per-child data used by the SPI bus. It can
|
2015-09-29 05:32:01 +00:00
|
|
|
* be accessed using dev_get_parent_priv() on the slave device. The SPI uclass
|
2020-12-03 23:55:17 +00:00
|
|
|
* sets up per_child_auto to sizeof(struct spi_slave), and the
|
2015-01-25 15:27:12 +00:00
|
|
|
* 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.
|
SPI API improvements
This patch gets rid of the spi_chipsel table and adds a handful of new
functions that makes the SPI layer cleaner and more flexible.
Instead of the spi_chipsel table, each board that wants to use SPI
gets to implement three hooks:
* spi_cs_activate(): Activates the chipselect for a given slave
* spi_cs_deactivate(): Deactivates the chipselect for a given slave
* spi_cs_is_valid(): Determines if the given bus/chipselect
combination can be activated.
Not all drivers may need those extra functions however. If that's the
case, the board code may just leave them out (assuming they know what
the driver needs) or rely on the linker to strip them out (assuming
--gc-sections is being used.)
To set up communication parameters for a given slave, the driver needs
to call spi_setup_slave(). This returns a pointer to an opaque
spi_slave struct which must be passed as a parameter to subsequent SPI
calls. This struct can be freed by calling spi_free_slave(), but most
driver probably don't want to do this.
Before starting one or more SPI transfers, the driver must call
spi_claim_bus() to gain exclusive access to the SPI bus and initialize
the hardware. When all transfers are done, the driver must call
spi_release_bus() to make the bus available to others, and possibly
shut down the SPI controller hardware.
spi_xfer() behaves mostly the same as before, but it now takes a
spi_slave parameter instead of a spi_chipsel function pointer. It also
got a new parameter, flags, which is used to specify chip select
behaviour. This may be extended with other flags in the future.
This patch has been build-tested on all powerpc and arm boards
involved. I have not tested NIOS since I don't have a toolchain for it
installed, so I expect some breakage there even though I've tried
fixing up everything I could find by visual inspection.
I have run-time tested this on AVR32 ATNGW100 using the atmel_spi and
DataFlash drivers posted as a follow-up. I'd like some help testing
other boards that use the existing SPI API.
But most of all, I'd like some comments on the new API. Is this stuff
usable for everyone? If not, why?
Changed in v4:
- Build fixes for various boards, drivers and commands
- Provide common struct spi_slave definition that can be extended by
drivers
- Pass a struct spi_slave * to spi_cs_activate and spi_cs_deactivate
- Make default bus and mode build-time configurable
- Override default SPI bus ID and mode on mx32ads and imx31_litekit.
Changed in v3:
- Add opaque struct spi_slave for controller-specific data associated
with a slave.
- Add spi_claim_bus() and spi_release_bus()
- Add spi_free_slave()
- spi_setup() is now called spi_setup_slave() and returns a
struct spi_slave
- soft_spi now supports four SPI modes (CPOL|CPHA)
- Add bus parameter to spi_setup_slave()
- Convert the new i.MX32 SPI driver
- Convert the new MC13783 RTC driver
Changed in v2:
- Convert the mpc8xxx_spi driver and the mpc8349emds board to the
new API.
Signed-off-by: Haavard Skinnemoen <hskinnemoen@atmel.com>
Tested-by: Guennadi Liakhovetski <lg@denx.de>
2008-05-16 09:10:31 +00:00
|
|
|
*
|
2014-10-14 05:41:52 +00:00
|
|
|
* If not using driver model, drivers are expected to extend this with
|
|
|
|
* controller-specific data.
|
|
|
|
*
|
|
|
|
* @dev: SPI slave device
|
|
|
|
* @max_hz: Maximum speed for this slave
|
|
|
|
* @bus: ID of the bus that the slave is attached to. For
|
|
|
|
* driver model this is the sequence number of the SPI
|
2020-12-17 04:20:07 +00:00
|
|
|
* bus (dev_seq(bus)) so does not need to be stored
|
2013-10-07 14:04:56 +00:00
|
|
|
* @cs: ID of the chip select connected to the slave.
|
2015-12-14 06:45:17 +00:00
|
|
|
* @mode: SPI mode to use for this slave (see SPI mode flags)
|
2013-10-16 14:23:25 +00:00
|
|
|
* @wordlen: Size of SPI word in number of bits
|
2018-01-23 16:14:56 +00:00
|
|
|
* @max_read_size: If non-zero, the maximum number of bytes which can
|
|
|
|
* be read at once.
|
2013-10-07 14:04:56 +00:00
|
|
|
* @max_write_size: If non-zero, the maximum number of bytes which can
|
2018-01-23 16:14:57 +00:00
|
|
|
* be written at once.
|
2013-10-07 14:04:56 +00:00
|
|
|
* @memory_map: Address of read-only SPI flash access.
|
2014-01-12 16:10:11 +00:00
|
|
|
* @flags: Indication of SPI flags.
|
SPI API improvements
This patch gets rid of the spi_chipsel table and adds a handful of new
functions that makes the SPI layer cleaner and more flexible.
Instead of the spi_chipsel table, each board that wants to use SPI
gets to implement three hooks:
* spi_cs_activate(): Activates the chipselect for a given slave
* spi_cs_deactivate(): Deactivates the chipselect for a given slave
* spi_cs_is_valid(): Determines if the given bus/chipselect
combination can be activated.
Not all drivers may need those extra functions however. If that's the
case, the board code may just leave them out (assuming they know what
the driver needs) or rely on the linker to strip them out (assuming
--gc-sections is being used.)
To set up communication parameters for a given slave, the driver needs
to call spi_setup_slave(). This returns a pointer to an opaque
spi_slave struct which must be passed as a parameter to subsequent SPI
calls. This struct can be freed by calling spi_free_slave(), but most
driver probably don't want to do this.
Before starting one or more SPI transfers, the driver must call
spi_claim_bus() to gain exclusive access to the SPI bus and initialize
the hardware. When all transfers are done, the driver must call
spi_release_bus() to make the bus available to others, and possibly
shut down the SPI controller hardware.
spi_xfer() behaves mostly the same as before, but it now takes a
spi_slave parameter instead of a spi_chipsel function pointer. It also
got a new parameter, flags, which is used to specify chip select
behaviour. This may be extended with other flags in the future.
This patch has been build-tested on all powerpc and arm boards
involved. I have not tested NIOS since I don't have a toolchain for it
installed, so I expect some breakage there even though I've tried
fixing up everything I could find by visual inspection.
I have run-time tested this on AVR32 ATNGW100 using the atmel_spi and
DataFlash drivers posted as a follow-up. I'd like some help testing
other boards that use the existing SPI API.
But most of all, I'd like some comments on the new API. Is this stuff
usable for everyone? If not, why?
Changed in v4:
- Build fixes for various boards, drivers and commands
- Provide common struct spi_slave definition that can be extended by
drivers
- Pass a struct spi_slave * to spi_cs_activate and spi_cs_deactivate
- Make default bus and mode build-time configurable
- Override default SPI bus ID and mode on mx32ads and imx31_litekit.
Changed in v3:
- Add opaque struct spi_slave for controller-specific data associated
with a slave.
- Add spi_claim_bus() and spi_release_bus()
- Add spi_free_slave()
- spi_setup() is now called spi_setup_slave() and returns a
struct spi_slave
- soft_spi now supports four SPI modes (CPOL|CPHA)
- Add bus parameter to spi_setup_slave()
- Convert the new i.MX32 SPI driver
- Convert the new MC13783 RTC driver
Changed in v2:
- Convert the mpc8xxx_spi driver and the mpc8349emds board to the
new API.
Signed-off-by: Haavard Skinnemoen <hskinnemoen@atmel.com>
Tested-by: Guennadi Liakhovetski <lg@denx.de>
2008-05-16 09:10:31 +00:00
|
|
|
*/
|
|
|
|
struct spi_slave {
|
2020-06-04 15:11:53 +00:00
|
|
|
#if CONFIG_IS_ENABLED(DM_SPI)
|
2014-10-14 05:41:52 +00:00
|
|
|
struct udevice *dev; /* struct spi_slave is dev->parentdata */
|
|
|
|
uint max_hz;
|
|
|
|
#else
|
2013-09-25 10:17:36 +00:00
|
|
|
unsigned int bus;
|
|
|
|
unsigned int cs;
|
2015-01-25 15:27:12 +00:00
|
|
|
#endif
|
2015-12-14 06:45:17 +00:00
|
|
|
uint mode;
|
2013-10-16 14:23:25 +00:00
|
|
|
unsigned int wordlen;
|
2018-01-23 16:14:56 +00:00
|
|
|
unsigned int max_read_size;
|
2013-03-11 06:08:05 +00:00
|
|
|
unsigned int max_write_size;
|
2013-10-07 10:23:01 +00:00
|
|
|
void *memory_map;
|
2015-12-28 16:53:14 +00:00
|
|
|
|
2014-01-12 16:10:11 +00:00
|
|
|
u8 flags;
|
2015-12-28 16:54:08 +00:00
|
|
|
#define SPI_XFER_BEGIN BIT(0) /* Assert CS before transfer */
|
|
|
|
#define SPI_XFER_END BIT(1) /* Deassert CS after transfer */
|
2015-12-28 16:53:14 +00:00
|
|
|
#define SPI_XFER_ONCE (SPI_XFER_BEGIN | SPI_XFER_END)
|
SPI API improvements
This patch gets rid of the spi_chipsel table and adds a handful of new
functions that makes the SPI layer cleaner and more flexible.
Instead of the spi_chipsel table, each board that wants to use SPI
gets to implement three hooks:
* spi_cs_activate(): Activates the chipselect for a given slave
* spi_cs_deactivate(): Deactivates the chipselect for a given slave
* spi_cs_is_valid(): Determines if the given bus/chipselect
combination can be activated.
Not all drivers may need those extra functions however. If that's the
case, the board code may just leave them out (assuming they know what
the driver needs) or rely on the linker to strip them out (assuming
--gc-sections is being used.)
To set up communication parameters for a given slave, the driver needs
to call spi_setup_slave(). This returns a pointer to an opaque
spi_slave struct which must be passed as a parameter to subsequent SPI
calls. This struct can be freed by calling spi_free_slave(), but most
driver probably don't want to do this.
Before starting one or more SPI transfers, the driver must call
spi_claim_bus() to gain exclusive access to the SPI bus and initialize
the hardware. When all transfers are done, the driver must call
spi_release_bus() to make the bus available to others, and possibly
shut down the SPI controller hardware.
spi_xfer() behaves mostly the same as before, but it now takes a
spi_slave parameter instead of a spi_chipsel function pointer. It also
got a new parameter, flags, which is used to specify chip select
behaviour. This may be extended with other flags in the future.
This patch has been build-tested on all powerpc and arm boards
involved. I have not tested NIOS since I don't have a toolchain for it
installed, so I expect some breakage there even though I've tried
fixing up everything I could find by visual inspection.
I have run-time tested this on AVR32 ATNGW100 using the atmel_spi and
DataFlash drivers posted as a follow-up. I'd like some help testing
other boards that use the existing SPI API.
But most of all, I'd like some comments on the new API. Is this stuff
usable for everyone? If not, why?
Changed in v4:
- Build fixes for various boards, drivers and commands
- Provide common struct spi_slave definition that can be extended by
drivers
- Pass a struct spi_slave * to spi_cs_activate and spi_cs_deactivate
- Make default bus and mode build-time configurable
- Override default SPI bus ID and mode on mx32ads and imx31_litekit.
Changed in v3:
- Add opaque struct spi_slave for controller-specific data associated
with a slave.
- Add spi_claim_bus() and spi_release_bus()
- Add spi_free_slave()
- spi_setup() is now called spi_setup_slave() and returns a
struct spi_slave
- soft_spi now supports four SPI modes (CPOL|CPHA)
- Add bus parameter to spi_setup_slave()
- Convert the new i.MX32 SPI driver
- Convert the new MC13783 RTC driver
Changed in v2:
- Convert the mpc8xxx_spi driver and the mpc8349emds board to the
new API.
Signed-off-by: Haavard Skinnemoen <hskinnemoen@atmel.com>
Tested-by: Guennadi Liakhovetski <lg@denx.de>
2008-05-16 09:10:31 +00:00
|
|
|
};
|
2002-09-26 02:01:47 +00:00
|
|
|
|
2013-03-11 06:08:00 +00:00
|
|
|
/**
|
|
|
|
* spi_do_alloc_slave - Allocate a new SPI slave (internal)
|
|
|
|
*
|
|
|
|
* Allocate and zero all fields in the spi slave, and set the bus/chip
|
|
|
|
* select. Use the helper macro spi_alloc_slave() to call this.
|
|
|
|
*
|
2013-09-25 10:17:36 +00:00
|
|
|
* @offset: Offset of struct spi_slave within slave structure.
|
|
|
|
* @size: Size of slave structure.
|
|
|
|
* @bus: Bus ID of the slave chip.
|
|
|
|
* @cs: Chip select ID of the slave chip on the specified bus.
|
2013-03-11 06:08:00 +00:00
|
|
|
*/
|
|
|
|
void *spi_do_alloc_slave(int offset, int size, unsigned int bus,
|
|
|
|
unsigned int cs);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* spi_alloc_slave - Allocate a new SPI slave
|
|
|
|
*
|
|
|
|
* Allocate and zero all fields in the spi slave, and set the bus/chip
|
|
|
|
* select.
|
|
|
|
*
|
2013-09-25 10:17:36 +00:00
|
|
|
* @_struct: Name of structure to allocate (e.g. struct tegra_spi).
|
|
|
|
* This structure must contain a member 'struct spi_slave *slave'.
|
|
|
|
* @bus: Bus ID of the slave chip.
|
|
|
|
* @cs: Chip select ID of the slave chip on the specified bus.
|
2013-03-11 06:08:00 +00:00
|
|
|
*/
|
|
|
|
#define spi_alloc_slave(_struct, bus, cs) \
|
|
|
|
spi_do_alloc_slave(offsetof(_struct, slave), \
|
|
|
|
sizeof(_struct), bus, cs)
|
|
|
|
|
|
|
|
/**
|
|
|
|
* spi_alloc_slave_base - Allocate a new SPI slave with no private data
|
|
|
|
*
|
|
|
|
* Allocate and zero all fields in the spi slave, and set the bus/chip
|
|
|
|
* select.
|
|
|
|
*
|
2013-09-25 10:17:36 +00:00
|
|
|
* @bus: Bus ID of the slave chip.
|
|
|
|
* @cs: Chip select ID of the slave chip on the specified bus.
|
2013-03-11 06:08:00 +00:00
|
|
|
*/
|
|
|
|
#define spi_alloc_slave_base(bus, cs) \
|
|
|
|
spi_do_alloc_slave(0, sizeof(struct spi_slave), bus, cs)
|
|
|
|
|
2013-09-25 10:17:36 +00:00
|
|
|
/**
|
SPI API improvements
This patch gets rid of the spi_chipsel table and adds a handful of new
functions that makes the SPI layer cleaner and more flexible.
Instead of the spi_chipsel table, each board that wants to use SPI
gets to implement three hooks:
* spi_cs_activate(): Activates the chipselect for a given slave
* spi_cs_deactivate(): Deactivates the chipselect for a given slave
* spi_cs_is_valid(): Determines if the given bus/chipselect
combination can be activated.
Not all drivers may need those extra functions however. If that's the
case, the board code may just leave them out (assuming they know what
the driver needs) or rely on the linker to strip them out (assuming
--gc-sections is being used.)
To set up communication parameters for a given slave, the driver needs
to call spi_setup_slave(). This returns a pointer to an opaque
spi_slave struct which must be passed as a parameter to subsequent SPI
calls. This struct can be freed by calling spi_free_slave(), but most
driver probably don't want to do this.
Before starting one or more SPI transfers, the driver must call
spi_claim_bus() to gain exclusive access to the SPI bus and initialize
the hardware. When all transfers are done, the driver must call
spi_release_bus() to make the bus available to others, and possibly
shut down the SPI controller hardware.
spi_xfer() behaves mostly the same as before, but it now takes a
spi_slave parameter instead of a spi_chipsel function pointer. It also
got a new parameter, flags, which is used to specify chip select
behaviour. This may be extended with other flags in the future.
This patch has been build-tested on all powerpc and arm boards
involved. I have not tested NIOS since I don't have a toolchain for it
installed, so I expect some breakage there even though I've tried
fixing up everything I could find by visual inspection.
I have run-time tested this on AVR32 ATNGW100 using the atmel_spi and
DataFlash drivers posted as a follow-up. I'd like some help testing
other boards that use the existing SPI API.
But most of all, I'd like some comments on the new API. Is this stuff
usable for everyone? If not, why?
Changed in v4:
- Build fixes for various boards, drivers and commands
- Provide common struct spi_slave definition that can be extended by
drivers
- Pass a struct spi_slave * to spi_cs_activate and spi_cs_deactivate
- Make default bus and mode build-time configurable
- Override default SPI bus ID and mode on mx32ads and imx31_litekit.
Changed in v3:
- Add opaque struct spi_slave for controller-specific data associated
with a slave.
- Add spi_claim_bus() and spi_release_bus()
- Add spi_free_slave()
- spi_setup() is now called spi_setup_slave() and returns a
struct spi_slave
- soft_spi now supports four SPI modes (CPOL|CPHA)
- Add bus parameter to spi_setup_slave()
- Convert the new i.MX32 SPI driver
- Convert the new MC13783 RTC driver
Changed in v2:
- Convert the mpc8xxx_spi driver and the mpc8349emds board to the
new API.
Signed-off-by: Haavard Skinnemoen <hskinnemoen@atmel.com>
Tested-by: Guennadi Liakhovetski <lg@denx.de>
2008-05-16 09:10:31 +00:00
|
|
|
* Set up communications parameters for a SPI slave.
|
|
|
|
*
|
|
|
|
* This must be called once for each slave. Note that this function
|
|
|
|
* usually doesn't touch any actual hardware, it only initializes the
|
|
|
|
* contents of spi_slave so that the hardware can be easily
|
|
|
|
* initialized later.
|
|
|
|
*
|
2013-09-25 10:17:36 +00:00
|
|
|
* @bus: Bus ID of the slave chip.
|
|
|
|
* @cs: Chip select ID of the slave chip on the specified bus.
|
|
|
|
* @max_hz: Maximum SCK rate in Hz.
|
|
|
|
* @mode: Clock polarity, clock phase and other parameters.
|
SPI API improvements
This patch gets rid of the spi_chipsel table and adds a handful of new
functions that makes the SPI layer cleaner and more flexible.
Instead of the spi_chipsel table, each board that wants to use SPI
gets to implement three hooks:
* spi_cs_activate(): Activates the chipselect for a given slave
* spi_cs_deactivate(): Deactivates the chipselect for a given slave
* spi_cs_is_valid(): Determines if the given bus/chipselect
combination can be activated.
Not all drivers may need those extra functions however. If that's the
case, the board code may just leave them out (assuming they know what
the driver needs) or rely on the linker to strip them out (assuming
--gc-sections is being used.)
To set up communication parameters for a given slave, the driver needs
to call spi_setup_slave(). This returns a pointer to an opaque
spi_slave struct which must be passed as a parameter to subsequent SPI
calls. This struct can be freed by calling spi_free_slave(), but most
driver probably don't want to do this.
Before starting one or more SPI transfers, the driver must call
spi_claim_bus() to gain exclusive access to the SPI bus and initialize
the hardware. When all transfers are done, the driver must call
spi_release_bus() to make the bus available to others, and possibly
shut down the SPI controller hardware.
spi_xfer() behaves mostly the same as before, but it now takes a
spi_slave parameter instead of a spi_chipsel function pointer. It also
got a new parameter, flags, which is used to specify chip select
behaviour. This may be extended with other flags in the future.
This patch has been build-tested on all powerpc and arm boards
involved. I have not tested NIOS since I don't have a toolchain for it
installed, so I expect some breakage there even though I've tried
fixing up everything I could find by visual inspection.
I have run-time tested this on AVR32 ATNGW100 using the atmel_spi and
DataFlash drivers posted as a follow-up. I'd like some help testing
other boards that use the existing SPI API.
But most of all, I'd like some comments on the new API. Is this stuff
usable for everyone? If not, why?
Changed in v4:
- Build fixes for various boards, drivers and commands
- Provide common struct spi_slave definition that can be extended by
drivers
- Pass a struct spi_slave * to spi_cs_activate and spi_cs_deactivate
- Make default bus and mode build-time configurable
- Override default SPI bus ID and mode on mx32ads and imx31_litekit.
Changed in v3:
- Add opaque struct spi_slave for controller-specific data associated
with a slave.
- Add spi_claim_bus() and spi_release_bus()
- Add spi_free_slave()
- spi_setup() is now called spi_setup_slave() and returns a
struct spi_slave
- soft_spi now supports four SPI modes (CPOL|CPHA)
- Add bus parameter to spi_setup_slave()
- Convert the new i.MX32 SPI driver
- Convert the new MC13783 RTC driver
Changed in v2:
- Convert the mpc8xxx_spi driver and the mpc8349emds board to the
new API.
Signed-off-by: Haavard Skinnemoen <hskinnemoen@atmel.com>
Tested-by: Guennadi Liakhovetski <lg@denx.de>
2008-05-16 09:10:31 +00:00
|
|
|
*
|
|
|
|
* Returns: A spi_slave reference that can be used in subsequent SPI
|
|
|
|
* calls, or NULL if one or more of the parameters are not supported.
|
|
|
|
*/
|
|
|
|
struct spi_slave *spi_setup_slave(unsigned int bus, unsigned int cs,
|
|
|
|
unsigned int max_hz, unsigned int mode);
|
|
|
|
|
2013-09-25 10:17:36 +00:00
|
|
|
/**
|
SPI API improvements
This patch gets rid of the spi_chipsel table and adds a handful of new
functions that makes the SPI layer cleaner and more flexible.
Instead of the spi_chipsel table, each board that wants to use SPI
gets to implement three hooks:
* spi_cs_activate(): Activates the chipselect for a given slave
* spi_cs_deactivate(): Deactivates the chipselect for a given slave
* spi_cs_is_valid(): Determines if the given bus/chipselect
combination can be activated.
Not all drivers may need those extra functions however. If that's the
case, the board code may just leave them out (assuming they know what
the driver needs) or rely on the linker to strip them out (assuming
--gc-sections is being used.)
To set up communication parameters for a given slave, the driver needs
to call spi_setup_slave(). This returns a pointer to an opaque
spi_slave struct which must be passed as a parameter to subsequent SPI
calls. This struct can be freed by calling spi_free_slave(), but most
driver probably don't want to do this.
Before starting one or more SPI transfers, the driver must call
spi_claim_bus() to gain exclusive access to the SPI bus and initialize
the hardware. When all transfers are done, the driver must call
spi_release_bus() to make the bus available to others, and possibly
shut down the SPI controller hardware.
spi_xfer() behaves mostly the same as before, but it now takes a
spi_slave parameter instead of a spi_chipsel function pointer. It also
got a new parameter, flags, which is used to specify chip select
behaviour. This may be extended with other flags in the future.
This patch has been build-tested on all powerpc and arm boards
involved. I have not tested NIOS since I don't have a toolchain for it
installed, so I expect some breakage there even though I've tried
fixing up everything I could find by visual inspection.
I have run-time tested this on AVR32 ATNGW100 using the atmel_spi and
DataFlash drivers posted as a follow-up. I'd like some help testing
other boards that use the existing SPI API.
But most of all, I'd like some comments on the new API. Is this stuff
usable for everyone? If not, why?
Changed in v4:
- Build fixes for various boards, drivers and commands
- Provide common struct spi_slave definition that can be extended by
drivers
- Pass a struct spi_slave * to spi_cs_activate and spi_cs_deactivate
- Make default bus and mode build-time configurable
- Override default SPI bus ID and mode on mx32ads and imx31_litekit.
Changed in v3:
- Add opaque struct spi_slave for controller-specific data associated
with a slave.
- Add spi_claim_bus() and spi_release_bus()
- Add spi_free_slave()
- spi_setup() is now called spi_setup_slave() and returns a
struct spi_slave
- soft_spi now supports four SPI modes (CPOL|CPHA)
- Add bus parameter to spi_setup_slave()
- Convert the new i.MX32 SPI driver
- Convert the new MC13783 RTC driver
Changed in v2:
- Convert the mpc8xxx_spi driver and the mpc8349emds board to the
new API.
Signed-off-by: Haavard Skinnemoen <hskinnemoen@atmel.com>
Tested-by: Guennadi Liakhovetski <lg@denx.de>
2008-05-16 09:10:31 +00:00
|
|
|
* Free any memory associated with a SPI slave.
|
|
|
|
*
|
2013-09-25 10:17:36 +00:00
|
|
|
* @slave: The SPI slave
|
SPI API improvements
This patch gets rid of the spi_chipsel table and adds a handful of new
functions that makes the SPI layer cleaner and more flexible.
Instead of the spi_chipsel table, each board that wants to use SPI
gets to implement three hooks:
* spi_cs_activate(): Activates the chipselect for a given slave
* spi_cs_deactivate(): Deactivates the chipselect for a given slave
* spi_cs_is_valid(): Determines if the given bus/chipselect
combination can be activated.
Not all drivers may need those extra functions however. If that's the
case, the board code may just leave them out (assuming they know what
the driver needs) or rely on the linker to strip them out (assuming
--gc-sections is being used.)
To set up communication parameters for a given slave, the driver needs
to call spi_setup_slave(). This returns a pointer to an opaque
spi_slave struct which must be passed as a parameter to subsequent SPI
calls. This struct can be freed by calling spi_free_slave(), but most
driver probably don't want to do this.
Before starting one or more SPI transfers, the driver must call
spi_claim_bus() to gain exclusive access to the SPI bus and initialize
the hardware. When all transfers are done, the driver must call
spi_release_bus() to make the bus available to others, and possibly
shut down the SPI controller hardware.
spi_xfer() behaves mostly the same as before, but it now takes a
spi_slave parameter instead of a spi_chipsel function pointer. It also
got a new parameter, flags, which is used to specify chip select
behaviour. This may be extended with other flags in the future.
This patch has been build-tested on all powerpc and arm boards
involved. I have not tested NIOS since I don't have a toolchain for it
installed, so I expect some breakage there even though I've tried
fixing up everything I could find by visual inspection.
I have run-time tested this on AVR32 ATNGW100 using the atmel_spi and
DataFlash drivers posted as a follow-up. I'd like some help testing
other boards that use the existing SPI API.
But most of all, I'd like some comments on the new API. Is this stuff
usable for everyone? If not, why?
Changed in v4:
- Build fixes for various boards, drivers and commands
- Provide common struct spi_slave definition that can be extended by
drivers
- Pass a struct spi_slave * to spi_cs_activate and spi_cs_deactivate
- Make default bus and mode build-time configurable
- Override default SPI bus ID and mode on mx32ads and imx31_litekit.
Changed in v3:
- Add opaque struct spi_slave for controller-specific data associated
with a slave.
- Add spi_claim_bus() and spi_release_bus()
- Add spi_free_slave()
- spi_setup() is now called spi_setup_slave() and returns a
struct spi_slave
- soft_spi now supports four SPI modes (CPOL|CPHA)
- Add bus parameter to spi_setup_slave()
- Convert the new i.MX32 SPI driver
- Convert the new MC13783 RTC driver
Changed in v2:
- Convert the mpc8xxx_spi driver and the mpc8349emds board to the
new API.
Signed-off-by: Haavard Skinnemoen <hskinnemoen@atmel.com>
Tested-by: Guennadi Liakhovetski <lg@denx.de>
2008-05-16 09:10:31 +00:00
|
|
|
*/
|
|
|
|
void spi_free_slave(struct spi_slave *slave);
|
|
|
|
|
2013-09-25 10:17:36 +00:00
|
|
|
/**
|
SPI API improvements
This patch gets rid of the spi_chipsel table and adds a handful of new
functions that makes the SPI layer cleaner and more flexible.
Instead of the spi_chipsel table, each board that wants to use SPI
gets to implement three hooks:
* spi_cs_activate(): Activates the chipselect for a given slave
* spi_cs_deactivate(): Deactivates the chipselect for a given slave
* spi_cs_is_valid(): Determines if the given bus/chipselect
combination can be activated.
Not all drivers may need those extra functions however. If that's the
case, the board code may just leave them out (assuming they know what
the driver needs) or rely on the linker to strip them out (assuming
--gc-sections is being used.)
To set up communication parameters for a given slave, the driver needs
to call spi_setup_slave(). This returns a pointer to an opaque
spi_slave struct which must be passed as a parameter to subsequent SPI
calls. This struct can be freed by calling spi_free_slave(), but most
driver probably don't want to do this.
Before starting one or more SPI transfers, the driver must call
spi_claim_bus() to gain exclusive access to the SPI bus and initialize
the hardware. When all transfers are done, the driver must call
spi_release_bus() to make the bus available to others, and possibly
shut down the SPI controller hardware.
spi_xfer() behaves mostly the same as before, but it now takes a
spi_slave parameter instead of a spi_chipsel function pointer. It also
got a new parameter, flags, which is used to specify chip select
behaviour. This may be extended with other flags in the future.
This patch has been build-tested on all powerpc and arm boards
involved. I have not tested NIOS since I don't have a toolchain for it
installed, so I expect some breakage there even though I've tried
fixing up everything I could find by visual inspection.
I have run-time tested this on AVR32 ATNGW100 using the atmel_spi and
DataFlash drivers posted as a follow-up. I'd like some help testing
other boards that use the existing SPI API.
But most of all, I'd like some comments on the new API. Is this stuff
usable for everyone? If not, why?
Changed in v4:
- Build fixes for various boards, drivers and commands
- Provide common struct spi_slave definition that can be extended by
drivers
- Pass a struct spi_slave * to spi_cs_activate and spi_cs_deactivate
- Make default bus and mode build-time configurable
- Override default SPI bus ID and mode on mx32ads and imx31_litekit.
Changed in v3:
- Add opaque struct spi_slave for controller-specific data associated
with a slave.
- Add spi_claim_bus() and spi_release_bus()
- Add spi_free_slave()
- spi_setup() is now called spi_setup_slave() and returns a
struct spi_slave
- soft_spi now supports four SPI modes (CPOL|CPHA)
- Add bus parameter to spi_setup_slave()
- Convert the new i.MX32 SPI driver
- Convert the new MC13783 RTC driver
Changed in v2:
- Convert the mpc8xxx_spi driver and the mpc8349emds board to the
new API.
Signed-off-by: Haavard Skinnemoen <hskinnemoen@atmel.com>
Tested-by: Guennadi Liakhovetski <lg@denx.de>
2008-05-16 09:10:31 +00:00
|
|
|
* Claim the bus and prepare it for communication with a given slave.
|
|
|
|
*
|
|
|
|
* This must be called before doing any transfers with a SPI slave. It
|
|
|
|
* will enable and initialize any SPI hardware as necessary, and make
|
|
|
|
* sure that the SCK line is in the correct idle state. It is not
|
|
|
|
* allowed to claim the same bus for several slaves without releasing
|
|
|
|
* the bus in between.
|
|
|
|
*
|
2013-09-25 10:17:36 +00:00
|
|
|
* @slave: The SPI slave
|
SPI API improvements
This patch gets rid of the spi_chipsel table and adds a handful of new
functions that makes the SPI layer cleaner and more flexible.
Instead of the spi_chipsel table, each board that wants to use SPI
gets to implement three hooks:
* spi_cs_activate(): Activates the chipselect for a given slave
* spi_cs_deactivate(): Deactivates the chipselect for a given slave
* spi_cs_is_valid(): Determines if the given bus/chipselect
combination can be activated.
Not all drivers may need those extra functions however. If that's the
case, the board code may just leave them out (assuming they know what
the driver needs) or rely on the linker to strip them out (assuming
--gc-sections is being used.)
To set up communication parameters for a given slave, the driver needs
to call spi_setup_slave(). This returns a pointer to an opaque
spi_slave struct which must be passed as a parameter to subsequent SPI
calls. This struct can be freed by calling spi_free_slave(), but most
driver probably don't want to do this.
Before starting one or more SPI transfers, the driver must call
spi_claim_bus() to gain exclusive access to the SPI bus and initialize
the hardware. When all transfers are done, the driver must call
spi_release_bus() to make the bus available to others, and possibly
shut down the SPI controller hardware.
spi_xfer() behaves mostly the same as before, but it now takes a
spi_slave parameter instead of a spi_chipsel function pointer. It also
got a new parameter, flags, which is used to specify chip select
behaviour. This may be extended with other flags in the future.
This patch has been build-tested on all powerpc and arm boards
involved. I have not tested NIOS since I don't have a toolchain for it
installed, so I expect some breakage there even though I've tried
fixing up everything I could find by visual inspection.
I have run-time tested this on AVR32 ATNGW100 using the atmel_spi and
DataFlash drivers posted as a follow-up. I'd like some help testing
other boards that use the existing SPI API.
But most of all, I'd like some comments on the new API. Is this stuff
usable for everyone? If not, why?
Changed in v4:
- Build fixes for various boards, drivers and commands
- Provide common struct spi_slave definition that can be extended by
drivers
- Pass a struct spi_slave * to spi_cs_activate and spi_cs_deactivate
- Make default bus and mode build-time configurable
- Override default SPI bus ID and mode on mx32ads and imx31_litekit.
Changed in v3:
- Add opaque struct spi_slave for controller-specific data associated
with a slave.
- Add spi_claim_bus() and spi_release_bus()
- Add spi_free_slave()
- spi_setup() is now called spi_setup_slave() and returns a
struct spi_slave
- soft_spi now supports four SPI modes (CPOL|CPHA)
- Add bus parameter to spi_setup_slave()
- Convert the new i.MX32 SPI driver
- Convert the new MC13783 RTC driver
Changed in v2:
- Convert the mpc8xxx_spi driver and the mpc8349emds board to the
new API.
Signed-off-by: Haavard Skinnemoen <hskinnemoen@atmel.com>
Tested-by: Guennadi Liakhovetski <lg@denx.de>
2008-05-16 09:10:31 +00:00
|
|
|
*
|
|
|
|
* Returns: 0 if the bus was claimed successfully, or a negative value
|
|
|
|
* if it wasn't.
|
|
|
|
*/
|
|
|
|
int spi_claim_bus(struct spi_slave *slave);
|
|
|
|
|
2013-09-25 10:17:36 +00:00
|
|
|
/**
|
SPI API improvements
This patch gets rid of the spi_chipsel table and adds a handful of new
functions that makes the SPI layer cleaner and more flexible.
Instead of the spi_chipsel table, each board that wants to use SPI
gets to implement three hooks:
* spi_cs_activate(): Activates the chipselect for a given slave
* spi_cs_deactivate(): Deactivates the chipselect for a given slave
* spi_cs_is_valid(): Determines if the given bus/chipselect
combination can be activated.
Not all drivers may need those extra functions however. If that's the
case, the board code may just leave them out (assuming they know what
the driver needs) or rely on the linker to strip them out (assuming
--gc-sections is being used.)
To set up communication parameters for a given slave, the driver needs
to call spi_setup_slave(). This returns a pointer to an opaque
spi_slave struct which must be passed as a parameter to subsequent SPI
calls. This struct can be freed by calling spi_free_slave(), but most
driver probably don't want to do this.
Before starting one or more SPI transfers, the driver must call
spi_claim_bus() to gain exclusive access to the SPI bus and initialize
the hardware. When all transfers are done, the driver must call
spi_release_bus() to make the bus available to others, and possibly
shut down the SPI controller hardware.
spi_xfer() behaves mostly the same as before, but it now takes a
spi_slave parameter instead of a spi_chipsel function pointer. It also
got a new parameter, flags, which is used to specify chip select
behaviour. This may be extended with other flags in the future.
This patch has been build-tested on all powerpc and arm boards
involved. I have not tested NIOS since I don't have a toolchain for it
installed, so I expect some breakage there even though I've tried
fixing up everything I could find by visual inspection.
I have run-time tested this on AVR32 ATNGW100 using the atmel_spi and
DataFlash drivers posted as a follow-up. I'd like some help testing
other boards that use the existing SPI API.
But most of all, I'd like some comments on the new API. Is this stuff
usable for everyone? If not, why?
Changed in v4:
- Build fixes for various boards, drivers and commands
- Provide common struct spi_slave definition that can be extended by
drivers
- Pass a struct spi_slave * to spi_cs_activate and spi_cs_deactivate
- Make default bus and mode build-time configurable
- Override default SPI bus ID and mode on mx32ads and imx31_litekit.
Changed in v3:
- Add opaque struct spi_slave for controller-specific data associated
with a slave.
- Add spi_claim_bus() and spi_release_bus()
- Add spi_free_slave()
- spi_setup() is now called spi_setup_slave() and returns a
struct spi_slave
- soft_spi now supports four SPI modes (CPOL|CPHA)
- Add bus parameter to spi_setup_slave()
- Convert the new i.MX32 SPI driver
- Convert the new MC13783 RTC driver
Changed in v2:
- Convert the mpc8xxx_spi driver and the mpc8349emds board to the
new API.
Signed-off-by: Haavard Skinnemoen <hskinnemoen@atmel.com>
Tested-by: Guennadi Liakhovetski <lg@denx.de>
2008-05-16 09:10:31 +00:00
|
|
|
* Release the SPI bus
|
|
|
|
*
|
|
|
|
* This must be called once for every call to spi_claim_bus() after
|
|
|
|
* all transfers have finished. It may disable any SPI hardware as
|
|
|
|
* appropriate.
|
|
|
|
*
|
2013-09-25 10:17:36 +00:00
|
|
|
* @slave: The SPI slave
|
SPI API improvements
This patch gets rid of the spi_chipsel table and adds a handful of new
functions that makes the SPI layer cleaner and more flexible.
Instead of the spi_chipsel table, each board that wants to use SPI
gets to implement three hooks:
* spi_cs_activate(): Activates the chipselect for a given slave
* spi_cs_deactivate(): Deactivates the chipselect for a given slave
* spi_cs_is_valid(): Determines if the given bus/chipselect
combination can be activated.
Not all drivers may need those extra functions however. If that's the
case, the board code may just leave them out (assuming they know what
the driver needs) or rely on the linker to strip them out (assuming
--gc-sections is being used.)
To set up communication parameters for a given slave, the driver needs
to call spi_setup_slave(). This returns a pointer to an opaque
spi_slave struct which must be passed as a parameter to subsequent SPI
calls. This struct can be freed by calling spi_free_slave(), but most
driver probably don't want to do this.
Before starting one or more SPI transfers, the driver must call
spi_claim_bus() to gain exclusive access to the SPI bus and initialize
the hardware. When all transfers are done, the driver must call
spi_release_bus() to make the bus available to others, and possibly
shut down the SPI controller hardware.
spi_xfer() behaves mostly the same as before, but it now takes a
spi_slave parameter instead of a spi_chipsel function pointer. It also
got a new parameter, flags, which is used to specify chip select
behaviour. This may be extended with other flags in the future.
This patch has been build-tested on all powerpc and arm boards
involved. I have not tested NIOS since I don't have a toolchain for it
installed, so I expect some breakage there even though I've tried
fixing up everything I could find by visual inspection.
I have run-time tested this on AVR32 ATNGW100 using the atmel_spi and
DataFlash drivers posted as a follow-up. I'd like some help testing
other boards that use the existing SPI API.
But most of all, I'd like some comments on the new API. Is this stuff
usable for everyone? If not, why?
Changed in v4:
- Build fixes for various boards, drivers and commands
- Provide common struct spi_slave definition that can be extended by
drivers
- Pass a struct spi_slave * to spi_cs_activate and spi_cs_deactivate
- Make default bus and mode build-time configurable
- Override default SPI bus ID and mode on mx32ads and imx31_litekit.
Changed in v3:
- Add opaque struct spi_slave for controller-specific data associated
with a slave.
- Add spi_claim_bus() and spi_release_bus()
- Add spi_free_slave()
- spi_setup() is now called spi_setup_slave() and returns a
struct spi_slave
- soft_spi now supports four SPI modes (CPOL|CPHA)
- Add bus parameter to spi_setup_slave()
- Convert the new i.MX32 SPI driver
- Convert the new MC13783 RTC driver
Changed in v2:
- Convert the mpc8xxx_spi driver and the mpc8349emds board to the
new API.
Signed-off-by: Haavard Skinnemoen <hskinnemoen@atmel.com>
Tested-by: Guennadi Liakhovetski <lg@denx.de>
2008-05-16 09:10:31 +00:00
|
|
|
*/
|
|
|
|
void spi_release_bus(struct spi_slave *slave);
|
2002-09-26 02:01:47 +00:00
|
|
|
|
2013-10-16 14:23:25 +00:00
|
|
|
/**
|
|
|
|
* Set the word length for SPI transactions
|
|
|
|
*
|
|
|
|
* Set the word length (number of bits per word) for SPI transactions.
|
|
|
|
*
|
|
|
|
* @slave: The SPI slave
|
|
|
|
* @wordlen: The number of bits in a word
|
|
|
|
*
|
|
|
|
* Returns: 0 on success, -1 on failure.
|
|
|
|
*/
|
|
|
|
int spi_set_wordlen(struct spi_slave *slave, unsigned int wordlen);
|
|
|
|
|
2013-09-25 10:17:36 +00:00
|
|
|
/**
|
2019-12-07 04:42:35 +00:00
|
|
|
* SPI transfer (optional if mem_ops is used)
|
2002-09-26 02:01:47 +00:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* 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:
|
2013-09-25 10:17:36 +00:00
|
|
|
* @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 to send out. The bits are
|
SPI API improvements
This patch gets rid of the spi_chipsel table and adds a handful of new
functions that makes the SPI layer cleaner and more flexible.
Instead of the spi_chipsel table, each board that wants to use SPI
gets to implement three hooks:
* spi_cs_activate(): Activates the chipselect for a given slave
* spi_cs_deactivate(): Deactivates the chipselect for a given slave
* spi_cs_is_valid(): Determines if the given bus/chipselect
combination can be activated.
Not all drivers may need those extra functions however. If that's the
case, the board code may just leave them out (assuming they know what
the driver needs) or rely on the linker to strip them out (assuming
--gc-sections is being used.)
To set up communication parameters for a given slave, the driver needs
to call spi_setup_slave(). This returns a pointer to an opaque
spi_slave struct which must be passed as a parameter to subsequent SPI
calls. This struct can be freed by calling spi_free_slave(), but most
driver probably don't want to do this.
Before starting one or more SPI transfers, the driver must call
spi_claim_bus() to gain exclusive access to the SPI bus and initialize
the hardware. When all transfers are done, the driver must call
spi_release_bus() to make the bus available to others, and possibly
shut down the SPI controller hardware.
spi_xfer() behaves mostly the same as before, but it now takes a
spi_slave parameter instead of a spi_chipsel function pointer. It also
got a new parameter, flags, which is used to specify chip select
behaviour. This may be extended with other flags in the future.
This patch has been build-tested on all powerpc and arm boards
involved. I have not tested NIOS since I don't have a toolchain for it
installed, so I expect some breakage there even though I've tried
fixing up everything I could find by visual inspection.
I have run-time tested this on AVR32 ATNGW100 using the atmel_spi and
DataFlash drivers posted as a follow-up. I'd like some help testing
other boards that use the existing SPI API.
But most of all, I'd like some comments on the new API. Is this stuff
usable for everyone? If not, why?
Changed in v4:
- Build fixes for various boards, drivers and commands
- Provide common struct spi_slave definition that can be extended by
drivers
- Pass a struct spi_slave * to spi_cs_activate and spi_cs_deactivate
- Make default bus and mode build-time configurable
- Override default SPI bus ID and mode on mx32ads and imx31_litekit.
Changed in v3:
- Add opaque struct spi_slave for controller-specific data associated
with a slave.
- Add spi_claim_bus() and spi_release_bus()
- Add spi_free_slave()
- spi_setup() is now called spi_setup_slave() and returns a
struct spi_slave
- soft_spi now supports four SPI modes (CPOL|CPHA)
- Add bus parameter to spi_setup_slave()
- Convert the new i.MX32 SPI driver
- Convert the new MC13783 RTC driver
Changed in v2:
- Convert the mpc8xxx_spi driver and the mpc8349emds board to the
new API.
Signed-off-by: Haavard Skinnemoen <hskinnemoen@atmel.com>
Tested-by: Guennadi Liakhovetski <lg@denx.de>
2008-05-16 09:10:31 +00:00
|
|
|
* held in a byte array and are sent MSB first.
|
2013-09-25 10:17:36 +00:00
|
|
|
* @din: Pointer to a string of bits that will be filled in.
|
|
|
|
* @flags: A bitwise combination of SPI_XFER_* flags.
|
2002-09-26 02:01:47 +00:00
|
|
|
*
|
2013-09-25 10:17:36 +00:00
|
|
|
* Returns: 0 on success, not 0 on failure
|
2002-09-26 02:01:47 +00:00
|
|
|
*/
|
SPI API improvements
This patch gets rid of the spi_chipsel table and adds a handful of new
functions that makes the SPI layer cleaner and more flexible.
Instead of the spi_chipsel table, each board that wants to use SPI
gets to implement three hooks:
* spi_cs_activate(): Activates the chipselect for a given slave
* spi_cs_deactivate(): Deactivates the chipselect for a given slave
* spi_cs_is_valid(): Determines if the given bus/chipselect
combination can be activated.
Not all drivers may need those extra functions however. If that's the
case, the board code may just leave them out (assuming they know what
the driver needs) or rely on the linker to strip them out (assuming
--gc-sections is being used.)
To set up communication parameters for a given slave, the driver needs
to call spi_setup_slave(). This returns a pointer to an opaque
spi_slave struct which must be passed as a parameter to subsequent SPI
calls. This struct can be freed by calling spi_free_slave(), but most
driver probably don't want to do this.
Before starting one or more SPI transfers, the driver must call
spi_claim_bus() to gain exclusive access to the SPI bus and initialize
the hardware. When all transfers are done, the driver must call
spi_release_bus() to make the bus available to others, and possibly
shut down the SPI controller hardware.
spi_xfer() behaves mostly the same as before, but it now takes a
spi_slave parameter instead of a spi_chipsel function pointer. It also
got a new parameter, flags, which is used to specify chip select
behaviour. This may be extended with other flags in the future.
This patch has been build-tested on all powerpc and arm boards
involved. I have not tested NIOS since I don't have a toolchain for it
installed, so I expect some breakage there even though I've tried
fixing up everything I could find by visual inspection.
I have run-time tested this on AVR32 ATNGW100 using the atmel_spi and
DataFlash drivers posted as a follow-up. I'd like some help testing
other boards that use the existing SPI API.
But most of all, I'd like some comments on the new API. Is this stuff
usable for everyone? If not, why?
Changed in v4:
- Build fixes for various boards, drivers and commands
- Provide common struct spi_slave definition that can be extended by
drivers
- Pass a struct spi_slave * to spi_cs_activate and spi_cs_deactivate
- Make default bus and mode build-time configurable
- Override default SPI bus ID and mode on mx32ads and imx31_litekit.
Changed in v3:
- Add opaque struct spi_slave for controller-specific data associated
with a slave.
- Add spi_claim_bus() and spi_release_bus()
- Add spi_free_slave()
- spi_setup() is now called spi_setup_slave() and returns a
struct spi_slave
- soft_spi now supports four SPI modes (CPOL|CPHA)
- Add bus parameter to spi_setup_slave()
- Convert the new i.MX32 SPI driver
- Convert the new MC13783 RTC driver
Changed in v2:
- Convert the mpc8xxx_spi driver and the mpc8349emds board to the
new API.
Signed-off-by: Haavard Skinnemoen <hskinnemoen@atmel.com>
Tested-by: Guennadi Liakhovetski <lg@denx.de>
2008-05-16 09:10:31 +00:00
|
|
|
int spi_xfer(struct spi_slave *slave, unsigned int bitlen, const void *dout,
|
|
|
|
void *din, unsigned long flags);
|
|
|
|
|
2019-07-22 11:52:56 +00:00
|
|
|
/**
|
|
|
|
* spi_write_then_read - SPI synchronous write followed by read
|
|
|
|
*
|
|
|
|
* This performs a half duplex transaction in which the first transaction
|
|
|
|
* is to send the opcode and if the length of buf is non-zero then it start
|
|
|
|
* the second transaction as tx or rx based on the need from respective slave.
|
|
|
|
*
|
|
|
|
* @slave: The SPI slave device with which opcode/data will be exchanged
|
|
|
|
* @opcode: opcode used for specific transfer
|
|
|
|
* @n_opcode: size of opcode, in bytes
|
|
|
|
* @txbuf: buffer into which data to be written
|
|
|
|
* @rxbuf: buffer into which data will be read
|
|
|
|
* @n_buf: size of buf (whether it's [tx|rx]buf), in bytes
|
|
|
|
*
|
|
|
|
* Returns: 0 on success, not 0 on failure
|
|
|
|
*/
|
|
|
|
int spi_write_then_read(struct spi_slave *slave, const u8 *opcode,
|
|
|
|
size_t n_opcode, const u8 *txbuf, u8 *rxbuf,
|
|
|
|
size_t n_buf);
|
|
|
|
|
2015-08-17 07:59:54 +00:00
|
|
|
/* Copy memory mapped data */
|
|
|
|
void spi_flash_copy_mmap(void *data, void *offset, size_t len);
|
|
|
|
|
2013-09-25 10:17:36 +00:00
|
|
|
/**
|
SPI API improvements
This patch gets rid of the spi_chipsel table and adds a handful of new
functions that makes the SPI layer cleaner and more flexible.
Instead of the spi_chipsel table, each board that wants to use SPI
gets to implement three hooks:
* spi_cs_activate(): Activates the chipselect for a given slave
* spi_cs_deactivate(): Deactivates the chipselect for a given slave
* spi_cs_is_valid(): Determines if the given bus/chipselect
combination can be activated.
Not all drivers may need those extra functions however. If that's the
case, the board code may just leave them out (assuming they know what
the driver needs) or rely on the linker to strip them out (assuming
--gc-sections is being used.)
To set up communication parameters for a given slave, the driver needs
to call spi_setup_slave(). This returns a pointer to an opaque
spi_slave struct which must be passed as a parameter to subsequent SPI
calls. This struct can be freed by calling spi_free_slave(), but most
driver probably don't want to do this.
Before starting one or more SPI transfers, the driver must call
spi_claim_bus() to gain exclusive access to the SPI bus and initialize
the hardware. When all transfers are done, the driver must call
spi_release_bus() to make the bus available to others, and possibly
shut down the SPI controller hardware.
spi_xfer() behaves mostly the same as before, but it now takes a
spi_slave parameter instead of a spi_chipsel function pointer. It also
got a new parameter, flags, which is used to specify chip select
behaviour. This may be extended with other flags in the future.
This patch has been build-tested on all powerpc and arm boards
involved. I have not tested NIOS since I don't have a toolchain for it
installed, so I expect some breakage there even though I've tried
fixing up everything I could find by visual inspection.
I have run-time tested this on AVR32 ATNGW100 using the atmel_spi and
DataFlash drivers posted as a follow-up. I'd like some help testing
other boards that use the existing SPI API.
But most of all, I'd like some comments on the new API. Is this stuff
usable for everyone? If not, why?
Changed in v4:
- Build fixes for various boards, drivers and commands
- Provide common struct spi_slave definition that can be extended by
drivers
- Pass a struct spi_slave * to spi_cs_activate and spi_cs_deactivate
- Make default bus and mode build-time configurable
- Override default SPI bus ID and mode on mx32ads and imx31_litekit.
Changed in v3:
- Add opaque struct spi_slave for controller-specific data associated
with a slave.
- Add spi_claim_bus() and spi_release_bus()
- Add spi_free_slave()
- spi_setup() is now called spi_setup_slave() and returns a
struct spi_slave
- soft_spi now supports four SPI modes (CPOL|CPHA)
- Add bus parameter to spi_setup_slave()
- Convert the new i.MX32 SPI driver
- Convert the new MC13783 RTC driver
Changed in v2:
- Convert the mpc8xxx_spi driver and the mpc8349emds board to the
new API.
Signed-off-by: Haavard Skinnemoen <hskinnemoen@atmel.com>
Tested-by: Guennadi Liakhovetski <lg@denx.de>
2008-05-16 09:10:31 +00:00
|
|
|
* Determine if a SPI chipselect is valid.
|
|
|
|
* This function is provided by the board if the low-level SPI driver
|
|
|
|
* needs it to determine if a given chipselect is actually valid.
|
|
|
|
*
|
|
|
|
* Returns: 1 if bus:cs identifies a valid chip on this board, 0
|
|
|
|
* otherwise.
|
|
|
|
*/
|
2014-10-14 05:41:52 +00:00
|
|
|
int spi_cs_is_valid(unsigned int bus, unsigned int cs);
|
SPI API improvements
This patch gets rid of the spi_chipsel table and adds a handful of new
functions that makes the SPI layer cleaner and more flexible.
Instead of the spi_chipsel table, each board that wants to use SPI
gets to implement three hooks:
* spi_cs_activate(): Activates the chipselect for a given slave
* spi_cs_deactivate(): Deactivates the chipselect for a given slave
* spi_cs_is_valid(): Determines if the given bus/chipselect
combination can be activated.
Not all drivers may need those extra functions however. If that's the
case, the board code may just leave them out (assuming they know what
the driver needs) or rely on the linker to strip them out (assuming
--gc-sections is being used.)
To set up communication parameters for a given slave, the driver needs
to call spi_setup_slave(). This returns a pointer to an opaque
spi_slave struct which must be passed as a parameter to subsequent SPI
calls. This struct can be freed by calling spi_free_slave(), but most
driver probably don't want to do this.
Before starting one or more SPI transfers, the driver must call
spi_claim_bus() to gain exclusive access to the SPI bus and initialize
the hardware. When all transfers are done, the driver must call
spi_release_bus() to make the bus available to others, and possibly
shut down the SPI controller hardware.
spi_xfer() behaves mostly the same as before, but it now takes a
spi_slave parameter instead of a spi_chipsel function pointer. It also
got a new parameter, flags, which is used to specify chip select
behaviour. This may be extended with other flags in the future.
This patch has been build-tested on all powerpc and arm boards
involved. I have not tested NIOS since I don't have a toolchain for it
installed, so I expect some breakage there even though I've tried
fixing up everything I could find by visual inspection.
I have run-time tested this on AVR32 ATNGW100 using the atmel_spi and
DataFlash drivers posted as a follow-up. I'd like some help testing
other boards that use the existing SPI API.
But most of all, I'd like some comments on the new API. Is this stuff
usable for everyone? If not, why?
Changed in v4:
- Build fixes for various boards, drivers and commands
- Provide common struct spi_slave definition that can be extended by
drivers
- Pass a struct spi_slave * to spi_cs_activate and spi_cs_deactivate
- Make default bus and mode build-time configurable
- Override default SPI bus ID and mode on mx32ads and imx31_litekit.
Changed in v3:
- Add opaque struct spi_slave for controller-specific data associated
with a slave.
- Add spi_claim_bus() and spi_release_bus()
- Add spi_free_slave()
- spi_setup() is now called spi_setup_slave() and returns a
struct spi_slave
- soft_spi now supports four SPI modes (CPOL|CPHA)
- Add bus parameter to spi_setup_slave()
- Convert the new i.MX32 SPI driver
- Convert the new MC13783 RTC driver
Changed in v2:
- Convert the mpc8xxx_spi driver and the mpc8349emds board to the
new API.
Signed-off-by: Haavard Skinnemoen <hskinnemoen@atmel.com>
Tested-by: Guennadi Liakhovetski <lg@denx.de>
2008-05-16 09:10:31 +00:00
|
|
|
|
2020-07-08 15:02:14 +00:00
|
|
|
/*
|
|
|
|
* These names are used in several drivers and these declarations will be
|
|
|
|
* removed soon as part of the SPI DM migration. Drop them if driver model is
|
|
|
|
* enabled for SPI.
|
|
|
|
*/
|
2020-06-04 15:11:53 +00:00
|
|
|
#if !CONFIG_IS_ENABLED(DM_SPI)
|
2013-09-25 10:17:36 +00:00
|
|
|
/**
|
SPI API improvements
This patch gets rid of the spi_chipsel table and adds a handful of new
functions that makes the SPI layer cleaner and more flexible.
Instead of the spi_chipsel table, each board that wants to use SPI
gets to implement three hooks:
* spi_cs_activate(): Activates the chipselect for a given slave
* spi_cs_deactivate(): Deactivates the chipselect for a given slave
* spi_cs_is_valid(): Determines if the given bus/chipselect
combination can be activated.
Not all drivers may need those extra functions however. If that's the
case, the board code may just leave them out (assuming they know what
the driver needs) or rely on the linker to strip them out (assuming
--gc-sections is being used.)
To set up communication parameters for a given slave, the driver needs
to call spi_setup_slave(). This returns a pointer to an opaque
spi_slave struct which must be passed as a parameter to subsequent SPI
calls. This struct can be freed by calling spi_free_slave(), but most
driver probably don't want to do this.
Before starting one or more SPI transfers, the driver must call
spi_claim_bus() to gain exclusive access to the SPI bus and initialize
the hardware. When all transfers are done, the driver must call
spi_release_bus() to make the bus available to others, and possibly
shut down the SPI controller hardware.
spi_xfer() behaves mostly the same as before, but it now takes a
spi_slave parameter instead of a spi_chipsel function pointer. It also
got a new parameter, flags, which is used to specify chip select
behaviour. This may be extended with other flags in the future.
This patch has been build-tested on all powerpc and arm boards
involved. I have not tested NIOS since I don't have a toolchain for it
installed, so I expect some breakage there even though I've tried
fixing up everything I could find by visual inspection.
I have run-time tested this on AVR32 ATNGW100 using the atmel_spi and
DataFlash drivers posted as a follow-up. I'd like some help testing
other boards that use the existing SPI API.
But most of all, I'd like some comments on the new API. Is this stuff
usable for everyone? If not, why?
Changed in v4:
- Build fixes for various boards, drivers and commands
- Provide common struct spi_slave definition that can be extended by
drivers
- Pass a struct spi_slave * to spi_cs_activate and spi_cs_deactivate
- Make default bus and mode build-time configurable
- Override default SPI bus ID and mode on mx32ads and imx31_litekit.
Changed in v3:
- Add opaque struct spi_slave for controller-specific data associated
with a slave.
- Add spi_claim_bus() and spi_release_bus()
- Add spi_free_slave()
- spi_setup() is now called spi_setup_slave() and returns a
struct spi_slave
- soft_spi now supports four SPI modes (CPOL|CPHA)
- Add bus parameter to spi_setup_slave()
- Convert the new i.MX32 SPI driver
- Convert the new MC13783 RTC driver
Changed in v2:
- Convert the mpc8xxx_spi driver and the mpc8349emds board to the
new API.
Signed-off-by: Haavard Skinnemoen <hskinnemoen@atmel.com>
Tested-by: Guennadi Liakhovetski <lg@denx.de>
2008-05-16 09:10:31 +00:00
|
|
|
* Activate a SPI chipselect.
|
|
|
|
* This function is provided by the board code when using a driver
|
|
|
|
* that can't control its chipselects automatically (e.g.
|
|
|
|
* common/soft_spi.c). When called, it should activate the chip select
|
|
|
|
* to the device identified by "slave".
|
|
|
|
*/
|
|
|
|
void spi_cs_activate(struct spi_slave *slave);
|
|
|
|
|
2013-09-25 10:17:36 +00:00
|
|
|
/**
|
SPI API improvements
This patch gets rid of the spi_chipsel table and adds a handful of new
functions that makes the SPI layer cleaner and more flexible.
Instead of the spi_chipsel table, each board that wants to use SPI
gets to implement three hooks:
* spi_cs_activate(): Activates the chipselect for a given slave
* spi_cs_deactivate(): Deactivates the chipselect for a given slave
* spi_cs_is_valid(): Determines if the given bus/chipselect
combination can be activated.
Not all drivers may need those extra functions however. If that's the
case, the board code may just leave them out (assuming they know what
the driver needs) or rely on the linker to strip them out (assuming
--gc-sections is being used.)
To set up communication parameters for a given slave, the driver needs
to call spi_setup_slave(). This returns a pointer to an opaque
spi_slave struct which must be passed as a parameter to subsequent SPI
calls. This struct can be freed by calling spi_free_slave(), but most
driver probably don't want to do this.
Before starting one or more SPI transfers, the driver must call
spi_claim_bus() to gain exclusive access to the SPI bus and initialize
the hardware. When all transfers are done, the driver must call
spi_release_bus() to make the bus available to others, and possibly
shut down the SPI controller hardware.
spi_xfer() behaves mostly the same as before, but it now takes a
spi_slave parameter instead of a spi_chipsel function pointer. It also
got a new parameter, flags, which is used to specify chip select
behaviour. This may be extended with other flags in the future.
This patch has been build-tested on all powerpc and arm boards
involved. I have not tested NIOS since I don't have a toolchain for it
installed, so I expect some breakage there even though I've tried
fixing up everything I could find by visual inspection.
I have run-time tested this on AVR32 ATNGW100 using the atmel_spi and
DataFlash drivers posted as a follow-up. I'd like some help testing
other boards that use the existing SPI API.
But most of all, I'd like some comments on the new API. Is this stuff
usable for everyone? If not, why?
Changed in v4:
- Build fixes for various boards, drivers and commands
- Provide common struct spi_slave definition that can be extended by
drivers
- Pass a struct spi_slave * to spi_cs_activate and spi_cs_deactivate
- Make default bus and mode build-time configurable
- Override default SPI bus ID and mode on mx32ads and imx31_litekit.
Changed in v3:
- Add opaque struct spi_slave for controller-specific data associated
with a slave.
- Add spi_claim_bus() and spi_release_bus()
- Add spi_free_slave()
- spi_setup() is now called spi_setup_slave() and returns a
struct spi_slave
- soft_spi now supports four SPI modes (CPOL|CPHA)
- Add bus parameter to spi_setup_slave()
- Convert the new i.MX32 SPI driver
- Convert the new MC13783 RTC driver
Changed in v2:
- Convert the mpc8xxx_spi driver and the mpc8349emds board to the
new API.
Signed-off-by: Haavard Skinnemoen <hskinnemoen@atmel.com>
Tested-by: Guennadi Liakhovetski <lg@denx.de>
2008-05-16 09:10:31 +00:00
|
|
|
* Deactivate a SPI chipselect.
|
|
|
|
* This function is provided by the board code when using a driver
|
|
|
|
* that can't control its chipselects automatically (e.g.
|
|
|
|
* common/soft_spi.c). When called, it should deactivate the chip
|
|
|
|
* select to the device identified by "slave".
|
|
|
|
*/
|
|
|
|
void spi_cs_deactivate(struct spi_slave *slave);
|
2020-07-08 15:02:14 +00:00
|
|
|
#endif
|
SPI API improvements
This patch gets rid of the spi_chipsel table and adds a handful of new
functions that makes the SPI layer cleaner and more flexible.
Instead of the spi_chipsel table, each board that wants to use SPI
gets to implement three hooks:
* spi_cs_activate(): Activates the chipselect for a given slave
* spi_cs_deactivate(): Deactivates the chipselect for a given slave
* spi_cs_is_valid(): Determines if the given bus/chipselect
combination can be activated.
Not all drivers may need those extra functions however. If that's the
case, the board code may just leave them out (assuming they know what
the driver needs) or rely on the linker to strip them out (assuming
--gc-sections is being used.)
To set up communication parameters for a given slave, the driver needs
to call spi_setup_slave(). This returns a pointer to an opaque
spi_slave struct which must be passed as a parameter to subsequent SPI
calls. This struct can be freed by calling spi_free_slave(), but most
driver probably don't want to do this.
Before starting one or more SPI transfers, the driver must call
spi_claim_bus() to gain exclusive access to the SPI bus and initialize
the hardware. When all transfers are done, the driver must call
spi_release_bus() to make the bus available to others, and possibly
shut down the SPI controller hardware.
spi_xfer() behaves mostly the same as before, but it now takes a
spi_slave parameter instead of a spi_chipsel function pointer. It also
got a new parameter, flags, which is used to specify chip select
behaviour. This may be extended with other flags in the future.
This patch has been build-tested on all powerpc and arm boards
involved. I have not tested NIOS since I don't have a toolchain for it
installed, so I expect some breakage there even though I've tried
fixing up everything I could find by visual inspection.
I have run-time tested this on AVR32 ATNGW100 using the atmel_spi and
DataFlash drivers posted as a follow-up. I'd like some help testing
other boards that use the existing SPI API.
But most of all, I'd like some comments on the new API. Is this stuff
usable for everyone? If not, why?
Changed in v4:
- Build fixes for various boards, drivers and commands
- Provide common struct spi_slave definition that can be extended by
drivers
- Pass a struct spi_slave * to spi_cs_activate and spi_cs_deactivate
- Make default bus and mode build-time configurable
- Override default SPI bus ID and mode on mx32ads and imx31_litekit.
Changed in v3:
- Add opaque struct spi_slave for controller-specific data associated
with a slave.
- Add spi_claim_bus() and spi_release_bus()
- Add spi_free_slave()
- spi_setup() is now called spi_setup_slave() and returns a
struct spi_slave
- soft_spi now supports four SPI modes (CPOL|CPHA)
- Add bus parameter to spi_setup_slave()
- Convert the new i.MX32 SPI driver
- Convert the new MC13783 RTC driver
Changed in v2:
- Convert the mpc8xxx_spi driver and the mpc8349emds board to the
new API.
Signed-off-by: Haavard Skinnemoen <hskinnemoen@atmel.com>
Tested-by: Guennadi Liakhovetski <lg@denx.de>
2008-05-16 09:10:31 +00:00
|
|
|
|
2013-09-25 10:17:36 +00:00
|
|
|
/**
|
2010-12-24 07:16:07 +00:00
|
|
|
* Set transfer speed.
|
|
|
|
* This sets a new speed to be applied for next spi_xfer().
|
2013-09-25 10:17:36 +00:00
|
|
|
* @slave: The SPI slave
|
|
|
|
* @hz: The transfer speed
|
2010-12-24 07:16:07 +00:00
|
|
|
*/
|
|
|
|
void spi_set_speed(struct spi_slave *slave, uint hz);
|
|
|
|
|
2013-09-25 10:17:36 +00:00
|
|
|
/**
|
SPI API improvements
This patch gets rid of the spi_chipsel table and adds a handful of new
functions that makes the SPI layer cleaner and more flexible.
Instead of the spi_chipsel table, each board that wants to use SPI
gets to implement three hooks:
* spi_cs_activate(): Activates the chipselect for a given slave
* spi_cs_deactivate(): Deactivates the chipselect for a given slave
* spi_cs_is_valid(): Determines if the given bus/chipselect
combination can be activated.
Not all drivers may need those extra functions however. If that's the
case, the board code may just leave them out (assuming they know what
the driver needs) or rely on the linker to strip them out (assuming
--gc-sections is being used.)
To set up communication parameters for a given slave, the driver needs
to call spi_setup_slave(). This returns a pointer to an opaque
spi_slave struct which must be passed as a parameter to subsequent SPI
calls. This struct can be freed by calling spi_free_slave(), but most
driver probably don't want to do this.
Before starting one or more SPI transfers, the driver must call
spi_claim_bus() to gain exclusive access to the SPI bus and initialize
the hardware. When all transfers are done, the driver must call
spi_release_bus() to make the bus available to others, and possibly
shut down the SPI controller hardware.
spi_xfer() behaves mostly the same as before, but it now takes a
spi_slave parameter instead of a spi_chipsel function pointer. It also
got a new parameter, flags, which is used to specify chip select
behaviour. This may be extended with other flags in the future.
This patch has been build-tested on all powerpc and arm boards
involved. I have not tested NIOS since I don't have a toolchain for it
installed, so I expect some breakage there even though I've tried
fixing up everything I could find by visual inspection.
I have run-time tested this on AVR32 ATNGW100 using the atmel_spi and
DataFlash drivers posted as a follow-up. I'd like some help testing
other boards that use the existing SPI API.
But most of all, I'd like some comments on the new API. Is this stuff
usable for everyone? If not, why?
Changed in v4:
- Build fixes for various boards, drivers and commands
- Provide common struct spi_slave definition that can be extended by
drivers
- Pass a struct spi_slave * to spi_cs_activate and spi_cs_deactivate
- Make default bus and mode build-time configurable
- Override default SPI bus ID and mode on mx32ads and imx31_litekit.
Changed in v3:
- Add opaque struct spi_slave for controller-specific data associated
with a slave.
- Add spi_claim_bus() and spi_release_bus()
- Add spi_free_slave()
- spi_setup() is now called spi_setup_slave() and returns a
struct spi_slave
- soft_spi now supports four SPI modes (CPOL|CPHA)
- Add bus parameter to spi_setup_slave()
- Convert the new i.MX32 SPI driver
- Convert the new MC13783 RTC driver
Changed in v2:
- Convert the mpc8xxx_spi driver and the mpc8349emds board to the
new API.
Signed-off-by: Haavard Skinnemoen <hskinnemoen@atmel.com>
Tested-by: Guennadi Liakhovetski <lg@denx.de>
2008-05-16 09:10:31 +00:00
|
|
|
* Write 8 bits, then read 8 bits.
|
2013-09-25 10:17:36 +00:00
|
|
|
* @slave: The SPI slave we're communicating with
|
|
|
|
* @byte: Byte to be written
|
SPI API improvements
This patch gets rid of the spi_chipsel table and adds a handful of new
functions that makes the SPI layer cleaner and more flexible.
Instead of the spi_chipsel table, each board that wants to use SPI
gets to implement three hooks:
* spi_cs_activate(): Activates the chipselect for a given slave
* spi_cs_deactivate(): Deactivates the chipselect for a given slave
* spi_cs_is_valid(): Determines if the given bus/chipselect
combination can be activated.
Not all drivers may need those extra functions however. If that's the
case, the board code may just leave them out (assuming they know what
the driver needs) or rely on the linker to strip them out (assuming
--gc-sections is being used.)
To set up communication parameters for a given slave, the driver needs
to call spi_setup_slave(). This returns a pointer to an opaque
spi_slave struct which must be passed as a parameter to subsequent SPI
calls. This struct can be freed by calling spi_free_slave(), but most
driver probably don't want to do this.
Before starting one or more SPI transfers, the driver must call
spi_claim_bus() to gain exclusive access to the SPI bus and initialize
the hardware. When all transfers are done, the driver must call
spi_release_bus() to make the bus available to others, and possibly
shut down the SPI controller hardware.
spi_xfer() behaves mostly the same as before, but it now takes a
spi_slave parameter instead of a spi_chipsel function pointer. It also
got a new parameter, flags, which is used to specify chip select
behaviour. This may be extended with other flags in the future.
This patch has been build-tested on all powerpc and arm boards
involved. I have not tested NIOS since I don't have a toolchain for it
installed, so I expect some breakage there even though I've tried
fixing up everything I could find by visual inspection.
I have run-time tested this on AVR32 ATNGW100 using the atmel_spi and
DataFlash drivers posted as a follow-up. I'd like some help testing
other boards that use the existing SPI API.
But most of all, I'd like some comments on the new API. Is this stuff
usable for everyone? If not, why?
Changed in v4:
- Build fixes for various boards, drivers and commands
- Provide common struct spi_slave definition that can be extended by
drivers
- Pass a struct spi_slave * to spi_cs_activate and spi_cs_deactivate
- Make default bus and mode build-time configurable
- Override default SPI bus ID and mode on mx32ads and imx31_litekit.
Changed in v3:
- Add opaque struct spi_slave for controller-specific data associated
with a slave.
- Add spi_claim_bus() and spi_release_bus()
- Add spi_free_slave()
- spi_setup() is now called spi_setup_slave() and returns a
struct spi_slave
- soft_spi now supports four SPI modes (CPOL|CPHA)
- Add bus parameter to spi_setup_slave()
- Convert the new i.MX32 SPI driver
- Convert the new MC13783 RTC driver
Changed in v2:
- Convert the mpc8xxx_spi driver and the mpc8349emds board to the
new API.
Signed-off-by: Haavard Skinnemoen <hskinnemoen@atmel.com>
Tested-by: Guennadi Liakhovetski <lg@denx.de>
2008-05-16 09:10:31 +00:00
|
|
|
*
|
|
|
|
* Returns: The value that was read, or a negative value on error.
|
|
|
|
*
|
|
|
|
* TODO: This function probably shouldn't be inlined.
|
|
|
|
*/
|
|
|
|
static inline int spi_w8r8(struct spi_slave *slave, unsigned char byte)
|
|
|
|
{
|
|
|
|
unsigned char dout[2];
|
|
|
|
unsigned char din[2];
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
dout[0] = byte;
|
|
|
|
dout[1] = 0;
|
2008-04-15 12:14:25 +00:00
|
|
|
|
SPI API improvements
This patch gets rid of the spi_chipsel table and adds a handful of new
functions that makes the SPI layer cleaner and more flexible.
Instead of the spi_chipsel table, each board that wants to use SPI
gets to implement three hooks:
* spi_cs_activate(): Activates the chipselect for a given slave
* spi_cs_deactivate(): Deactivates the chipselect for a given slave
* spi_cs_is_valid(): Determines if the given bus/chipselect
combination can be activated.
Not all drivers may need those extra functions however. If that's the
case, the board code may just leave them out (assuming they know what
the driver needs) or rely on the linker to strip them out (assuming
--gc-sections is being used.)
To set up communication parameters for a given slave, the driver needs
to call spi_setup_slave(). This returns a pointer to an opaque
spi_slave struct which must be passed as a parameter to subsequent SPI
calls. This struct can be freed by calling spi_free_slave(), but most
driver probably don't want to do this.
Before starting one or more SPI transfers, the driver must call
spi_claim_bus() to gain exclusive access to the SPI bus and initialize
the hardware. When all transfers are done, the driver must call
spi_release_bus() to make the bus available to others, and possibly
shut down the SPI controller hardware.
spi_xfer() behaves mostly the same as before, but it now takes a
spi_slave parameter instead of a spi_chipsel function pointer. It also
got a new parameter, flags, which is used to specify chip select
behaviour. This may be extended with other flags in the future.
This patch has been build-tested on all powerpc and arm boards
involved. I have not tested NIOS since I don't have a toolchain for it
installed, so I expect some breakage there even though I've tried
fixing up everything I could find by visual inspection.
I have run-time tested this on AVR32 ATNGW100 using the atmel_spi and
DataFlash drivers posted as a follow-up. I'd like some help testing
other boards that use the existing SPI API.
But most of all, I'd like some comments on the new API. Is this stuff
usable for everyone? If not, why?
Changed in v4:
- Build fixes for various boards, drivers and commands
- Provide common struct spi_slave definition that can be extended by
drivers
- Pass a struct spi_slave * to spi_cs_activate and spi_cs_deactivate
- Make default bus and mode build-time configurable
- Override default SPI bus ID and mode on mx32ads and imx31_litekit.
Changed in v3:
- Add opaque struct spi_slave for controller-specific data associated
with a slave.
- Add spi_claim_bus() and spi_release_bus()
- Add spi_free_slave()
- spi_setup() is now called spi_setup_slave() and returns a
struct spi_slave
- soft_spi now supports four SPI modes (CPOL|CPHA)
- Add bus parameter to spi_setup_slave()
- Convert the new i.MX32 SPI driver
- Convert the new MC13783 RTC driver
Changed in v2:
- Convert the mpc8xxx_spi driver and the mpc8349emds board to the
new API.
Signed-off-by: Haavard Skinnemoen <hskinnemoen@atmel.com>
Tested-by: Guennadi Liakhovetski <lg@denx.de>
2008-05-16 09:10:31 +00:00
|
|
|
ret = spi_xfer(slave, 16, dout, din, SPI_XFER_BEGIN | SPI_XFER_END);
|
|
|
|
return ret < 0 ? ret : din[1];
|
|
|
|
}
|
2002-09-26 02:01:47 +00:00
|
|
|
|
2014-10-14 05:41:52 +00:00
|
|
|
/**
|
|
|
|
* struct spi_cs_info - Information about a bus chip select
|
|
|
|
*
|
|
|
|
* @dev: Connected device, or NULL if none
|
|
|
|
*/
|
|
|
|
struct spi_cs_info {
|
|
|
|
struct udevice *dev;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* struct struct dm_spi_ops - Driver model SPI operations
|
|
|
|
*
|
|
|
|
* The uclass interface is implemented by all SPI devices which use
|
|
|
|
* driver model.
|
|
|
|
*/
|
|
|
|
struct dm_spi_ops {
|
|
|
|
/**
|
|
|
|
* Claim the bus and prepare it for communication.
|
|
|
|
*
|
|
|
|
* The device provided is the slave device. It's parent controller
|
|
|
|
* will be used to provide the communication.
|
|
|
|
*
|
|
|
|
* This must be called before doing any transfers with a SPI slave. It
|
|
|
|
* will enable and initialize any SPI hardware as necessary, and make
|
|
|
|
* sure that the SCK line is in the correct idle state. It is not
|
|
|
|
* allowed to claim the same bus for several slaves without releasing
|
|
|
|
* the bus in between.
|
|
|
|
*
|
2015-04-19 15:05:40 +00:00
|
|
|
* @dev: The SPI slave
|
2014-10-14 05:41:52 +00:00
|
|
|
*
|
|
|
|
* Returns: 0 if the bus was claimed successfully, or a negative value
|
|
|
|
* if it wasn't.
|
|
|
|
*/
|
2015-04-19 15:05:40 +00:00
|
|
|
int (*claim_bus)(struct udevice *dev);
|
2014-10-14 05:41:52 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Release the SPI bus
|
|
|
|
*
|
|
|
|
* This must be called once for every call to spi_claim_bus() after
|
|
|
|
* all transfers have finished. It may disable any SPI hardware as
|
|
|
|
* appropriate.
|
|
|
|
*
|
2015-04-19 15:05:40 +00:00
|
|
|
* @dev: The SPI slave
|
2014-10-14 05:41:52 +00:00
|
|
|
*/
|
2015-04-19 15:05:40 +00:00
|
|
|
int (*release_bus)(struct udevice *dev);
|
2014-10-14 05:41:52 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the word length for SPI transactions
|
|
|
|
*
|
|
|
|
* Set the word length (number of bits per word) for SPI transactions.
|
|
|
|
*
|
|
|
|
* @bus: The SPI slave
|
|
|
|
* @wordlen: The number of bits in a word
|
|
|
|
*
|
|
|
|
* Returns: 0 on success, -ve on failure.
|
|
|
|
*/
|
2015-04-19 15:05:40 +00:00
|
|
|
int (*set_wordlen)(struct udevice *dev, unsigned int wordlen);
|
2014-10-14 05:41:52 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* 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:
|
|
|
|
* @dev: The slave device to communicate with
|
|
|
|
* @bitlen: How many bits to write and read.
|
|
|
|
* @dout: Pointer to a string of bits to send out. The bits are
|
|
|
|
* held in a byte array and are sent MSB first.
|
|
|
|
* @din: Pointer to a string of bits that will be filled in.
|
|
|
|
* @flags: A bitwise combination of SPI_XFER_* flags.
|
|
|
|
*
|
|
|
|
* Returns: 0 on success, not -1 on failure
|
|
|
|
*/
|
|
|
|
int (*xfer)(struct udevice *dev, unsigned int bitlen, const void *dout,
|
|
|
|
void *din, unsigned long flags);
|
|
|
|
|
2018-08-16 15:30:11 +00:00
|
|
|
/**
|
|
|
|
* Optimized handlers for SPI memory-like operations.
|
|
|
|
*
|
|
|
|
* Optimized/dedicated operations for interactions with SPI memory. This
|
|
|
|
* field is optional and should only be implemented if the controller
|
|
|
|
* has native support for memory like operations.
|
|
|
|
*/
|
|
|
|
const struct spi_controller_mem_ops *mem_ops;
|
|
|
|
|
2014-10-14 05:41:52 +00:00
|
|
|
/**
|
|
|
|
* Set transfer speed.
|
|
|
|
* This sets a new speed to be applied for next spi_xfer().
|
|
|
|
* @bus: The SPI bus
|
|
|
|
* @hz: The transfer speed
|
|
|
|
* @return 0 if OK, -ve on error
|
|
|
|
*/
|
|
|
|
int (*set_speed)(struct udevice *bus, uint hz);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the SPI mode/flags
|
|
|
|
*
|
|
|
|
* It is unclear if we want to set speed and mode together instead
|
|
|
|
* of separately.
|
|
|
|
*
|
|
|
|
* @bus: The SPI bus
|
|
|
|
* @mode: Requested SPI mode (SPI_... flags)
|
|
|
|
* @return 0 if OK, -ve on error
|
|
|
|
*/
|
|
|
|
int (*set_mode)(struct udevice *bus, uint mode);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get information on a chip select
|
|
|
|
*
|
|
|
|
* This is only called when the SPI uclass does not know about a
|
|
|
|
* chip select, i.e. it has no attached device. It gives the driver
|
|
|
|
* a chance to allow activity on that chip select even so.
|
|
|
|
*
|
|
|
|
* @bus: The SPI bus
|
|
|
|
* @cs: The chip select (0..n-1)
|
|
|
|
* @info: Returns information about the chip select, if valid.
|
|
|
|
* On entry info->dev is NULL
|
2019-09-09 13:00:01 +00:00
|
|
|
* @return 0 if OK (and @info is set up), -EINVAL if the chip select
|
2014-10-14 05:41:52 +00:00
|
|
|
* is invalid, other -ve value on error
|
|
|
|
*/
|
|
|
|
int (*cs_info)(struct udevice *bus, uint cs, struct spi_cs_info *info);
|
2019-10-21 03:31:47 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* get_mmap() - Get memory-mapped SPI
|
|
|
|
*
|
|
|
|
* @dev: The SPI flash slave device
|
|
|
|
* @map_basep: Returns base memory address for mapped SPI
|
|
|
|
* @map_sizep: Returns size of mapped SPI
|
|
|
|
* @offsetp: Returns start offset of SPI flash where the map works
|
|
|
|
* correctly (offsets before this are not visible)
|
|
|
|
* @return 0 if OK, -EFAULT if memory mapping is not available
|
|
|
|
*/
|
|
|
|
int (*get_mmap)(struct udevice *dev, ulong *map_basep,
|
|
|
|
uint *map_sizep, uint *offsetp);
|
2014-10-14 05:41:52 +00:00
|
|
|
};
|
|
|
|
|
2014-10-14 05:41:53 +00:00
|
|
|
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);
|
|
|
|
};
|
|
|
|
|
2014-10-14 05:41:52 +00:00
|
|
|
/**
|
|
|
|
* spi_find_bus_and_cs() - Find bus and slave devices by number
|
|
|
|
*
|
|
|
|
* Given a bus number and chip select, this finds the corresponding bus
|
|
|
|
* device and slave device. Neither device is activated by this function,
|
|
|
|
* although they may have been activated previously.
|
|
|
|
*
|
|
|
|
* @busnum: SPI bus number
|
|
|
|
* @cs: Chip select to look for
|
|
|
|
* @busp: Returns bus device
|
|
|
|
* @devp: Return slave device
|
2022-01-19 17:05:50 +00:00
|
|
|
* Return: 0 if found, -ENODEV on error
|
2014-10-14 05:41:52 +00:00
|
|
|
*/
|
|
|
|
int spi_find_bus_and_cs(int busnum, int cs, struct udevice **busp,
|
|
|
|
struct udevice **devp);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* spi_get_bus_and_cs() - Find and activate bus and slave devices by number
|
|
|
|
*
|
|
|
|
* Given a bus number and chip select, this finds the corresponding bus
|
|
|
|
* device and slave device.
|
|
|
|
*
|
2022-03-30 07:33:13 +00:00
|
|
|
* @busnum: SPI bus number
|
|
|
|
* @cs: Chip select to look for
|
|
|
|
* @busp: Returns bus device
|
|
|
|
* @devp: Return slave device
|
|
|
|
* @return 0 if found, -ve on error
|
|
|
|
*/
|
|
|
|
int spi_get_bus_and_cs(int busnum, int cs,
|
|
|
|
struct udevice **busp, struct spi_slave **devp);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* _spi_get_bus_and_cs() - Find and activate bus and slave devices by number
|
|
|
|
* As spi_flash_probe(), This is an old-style function. We should remove
|
|
|
|
* it when all SPI flash drivers use dm
|
|
|
|
*
|
|
|
|
* Given a bus number and chip select, this finds the corresponding bus
|
|
|
|
* device and slave device.
|
|
|
|
*
|
2014-10-14 05:41:52 +00:00
|
|
|
* If no such slave exists, and drv_name is not NULL, then a new slave device
|
2019-02-27 14:36:44 +00:00
|
|
|
* is automatically bound on this chip select with requested speed and mode.
|
2014-10-14 05:41:52 +00:00
|
|
|
*
|
2019-02-27 14:36:44 +00:00
|
|
|
* Ths new slave device is probed ready for use with the speed and mode
|
2020-12-03 23:55:18 +00:00
|
|
|
* from plat when available or the requested values.
|
2014-10-14 05:41:52 +00:00
|
|
|
*
|
|
|
|
* @busnum: SPI bus number
|
|
|
|
* @cs: Chip select to look for
|
2020-12-03 23:55:18 +00:00
|
|
|
* @speed: SPI speed to use for this slave when not available in plat
|
|
|
|
* @mode: SPI mode to use for this slave when not available in plat
|
2014-10-14 05:41:52 +00:00
|
|
|
* @drv_name: Name of driver to attach to this chip select
|
|
|
|
* @dev_name: Name of the new device thus created
|
|
|
|
* @busp: Returns bus device
|
|
|
|
* @devp: Return slave device
|
2022-01-19 17:05:50 +00:00
|
|
|
* Return: 0 if found, -ve on error
|
2014-10-14 05:41:52 +00:00
|
|
|
*/
|
2022-03-30 07:33:13 +00:00
|
|
|
int _spi_get_bus_and_cs(int busnum, int cs, int speed, int mode,
|
2014-10-14 05:41:52 +00:00
|
|
|
const char *drv_name, const char *dev_name,
|
|
|
|
struct udevice **busp, struct spi_slave **devp);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* spi_chip_select() - Get the chip select for a slave
|
|
|
|
*
|
2022-01-19 17:05:50 +00:00
|
|
|
* Return: the chip select this slave is attached to
|
2014-10-14 05:41:52 +00:00
|
|
|
*/
|
|
|
|
int spi_chip_select(struct udevice *slave);
|
|
|
|
|
2014-11-11 17:46:22 +00:00
|
|
|
/**
|
|
|
|
* spi_find_chip_select() - Find the slave attached to chip select
|
|
|
|
*
|
|
|
|
* @bus: SPI bus to search
|
|
|
|
* @cs: Chip select to look for
|
|
|
|
* @devp: Returns the slave device if found
|
2022-01-19 17:05:50 +00:00
|
|
|
* Return: 0 if found, -EINVAL if cs is invalid, -ENODEV if no device attached,
|
2019-09-09 13:00:02 +00:00
|
|
|
* other -ve value on error
|
2014-11-11 17:46:22 +00:00
|
|
|
*/
|
|
|
|
int spi_find_chip_select(struct udevice *bus, int cs, struct udevice **devp);
|
|
|
|
|
2014-10-14 05:41:52 +00:00
|
|
|
/**
|
2020-12-03 23:55:21 +00:00
|
|
|
* spi_slave_of_to_plat() - decode standard SPI platform data
|
2014-10-14 05:41:52 +00:00
|
|
|
*
|
2015-01-25 15:27:12 +00:00
|
|
|
* This decodes the speed and mode for a slave from a device tree node
|
2014-10-14 05:41:52 +00:00
|
|
|
*
|
|
|
|
* @blob: Device tree blob
|
|
|
|
* @node: Node offset to read from
|
2015-01-25 15:27:12 +00:00
|
|
|
* @plat: Place to put the decoded information
|
2014-10-14 05:41:52 +00:00
|
|
|
*/
|
2020-12-03 23:55:23 +00:00
|
|
|
int spi_slave_of_to_plat(struct udevice *dev, struct dm_spi_slave_plat *plat);
|
2014-10-14 05:41:52 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* spi_cs_info() - Check information on a chip select
|
|
|
|
*
|
|
|
|
* This checks a particular chip select on a bus to see if it has a device
|
|
|
|
* attached, or is even valid.
|
|
|
|
*
|
|
|
|
* @bus: The SPI bus
|
|
|
|
* @cs: The chip select (0..n-1)
|
|
|
|
* @info: Returns information about the chip select, if valid
|
2022-01-19 17:05:50 +00:00
|
|
|
* Return: 0 if OK (and @info is set up), -ENODEV if the chip select
|
2014-10-14 05:41:52 +00:00
|
|
|
* is invalid, other -ve value on error
|
|
|
|
*/
|
|
|
|
int spi_cs_info(struct udevice *bus, uint cs, struct spi_cs_info *info);
|
|
|
|
|
|
|
|
struct sandbox_state;
|
2014-10-14 05:41:53 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
2022-01-19 17:05:50 +00:00
|
|
|
* Return: 0 if OK, -ve on error
|
2014-10-14 05:41:53 +00:00
|
|
|
*/
|
2014-10-14 05:41:52 +00:00
|
|
|
int sandbox_spi_get_emul(struct sandbox_state *state,
|
|
|
|
struct udevice *bus, struct udevice *slave,
|
|
|
|
struct udevice **emulp);
|
|
|
|
|
2016-05-03 02:02:22 +00:00
|
|
|
/**
|
|
|
|
* Claim the bus and prepare it for communication with a given slave.
|
|
|
|
*
|
|
|
|
* This must be called before doing any transfers with a SPI slave. It
|
|
|
|
* will enable and initialize any SPI hardware as necessary, and make
|
|
|
|
* sure that the SCK line is in the correct idle state. It is not
|
|
|
|
* allowed to claim the same bus for several slaves without releasing
|
|
|
|
* the bus in between.
|
|
|
|
*
|
|
|
|
* @dev: The SPI slave device
|
|
|
|
*
|
|
|
|
* Returns: 0 if the bus was claimed successfully, or a negative value
|
|
|
|
* if it wasn't.
|
|
|
|
*/
|
|
|
|
int dm_spi_claim_bus(struct udevice *dev);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Release the SPI bus
|
|
|
|
*
|
|
|
|
* This must be called once for every call to dm_spi_claim_bus() after
|
|
|
|
* all transfers have finished. It may disable any SPI hardware as
|
|
|
|
* appropriate.
|
|
|
|
*
|
|
|
|
* @slave: The SPI slave device
|
|
|
|
*/
|
|
|
|
void dm_spi_release_bus(struct udevice *dev);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* 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).
|
|
|
|
*
|
|
|
|
* dm_spi_xfer() interface:
|
|
|
|
* @dev: The SPI slave device which will be sending/receiving the data.
|
|
|
|
* @bitlen: How many bits to write and read.
|
|
|
|
* @dout: Pointer to a string of bits to send out. The bits are
|
|
|
|
* held in a byte array and are sent MSB first.
|
|
|
|
* @din: Pointer to a string of bits that will be filled in.
|
|
|
|
* @flags: A bitwise combination of SPI_XFER_* flags.
|
|
|
|
*
|
|
|
|
* Returns: 0 on success, not 0 on failure
|
|
|
|
*/
|
|
|
|
int dm_spi_xfer(struct udevice *dev, unsigned int bitlen,
|
|
|
|
const void *dout, void *din, unsigned long flags);
|
|
|
|
|
2019-10-21 03:31:47 +00:00
|
|
|
/**
|
|
|
|
* spi_get_mmap() - Get memory-mapped SPI
|
|
|
|
*
|
|
|
|
* @dev: SPI slave device to check
|
|
|
|
* @map_basep: Returns base memory address for mapped SPI
|
|
|
|
* @map_sizep: Returns size of mapped SPI
|
|
|
|
* @offsetp: Returns start offset of SPI flash where the map works
|
|
|
|
* correctly (offsets before this are not visible)
|
2022-01-19 17:05:50 +00:00
|
|
|
* Return: 0 if OK, -ENOSYS if no operation, -EFAULT if memory mapping is not
|
2019-10-21 03:31:47 +00:00
|
|
|
* available
|
|
|
|
*/
|
|
|
|
int dm_spi_get_mmap(struct udevice *dev, ulong *map_basep, uint *map_sizep,
|
|
|
|
uint *offsetp);
|
|
|
|
|
2015-04-20 18:37:12 +00:00
|
|
|
/* Access the operations for a SPI device */
|
2014-10-14 05:41:52 +00:00
|
|
|
#define spi_get_ops(dev) ((struct dm_spi_ops *)(dev)->driver->ops)
|
2014-10-14 05:41:53 +00:00
|
|
|
#define spi_emul_get_ops(dev) ((struct dm_spi_emul_ops *)(dev)->driver->ops)
|
2014-10-14 05:41:52 +00:00
|
|
|
|
2002-09-26 02:01:47 +00:00
|
|
|
#endif /* _SPI_H_ */
|