1/*  *********************************************************************
2    *  Broadcom Common Firmware Environment (CFE)
3    *
4    *  Common SPI definitions			File: cfe_spi.h
5    *
6    *  Driver common data structures for SPI devices.   The
7    *  higher-level (device-specific) SPI drivers talk to this, and
8    *  via these structures we end up at platform-specific SPI
9    *  handlers.
10    *
11    *********************************************************************
12    *
13    *  Copyright 2004
14    *  Broadcom Corporation. All rights reserved.
15    *
16    *  This software is furnished under license and may be used and
17    *  copied only in accordance with the following terms and
18    *  conditions.  Subject to these conditions, you may download,
19    *  copy, install, use, modify and distribute modified or unmodified
20    *  copies of this software in source and/or binary form.  No title
21    *  or ownership is transferred hereby.
22    *
23    *  1) Any source code used, modified or distributed must reproduce
24    *     and retain this copyright notice and list of conditions
25    *     as they appear in the source file.
26    *
27    *  2) No right is granted to use any trade name, trademark, or
28    *     logo of Broadcom Corporation.  The "Broadcom Corporation"
29    *     name may not be used to endorse or promote products derived
30    *     from this software without the prior written permission of
31    *     Broadcom Corporation.
32    *
33    *  3) THIS SOFTWARE IS PROVIDED "AS-IS" AND ANY EXPRESS OR
34    *     IMPLIED WARRANTIES, INCLUDING BUT NOT LIMITED TO, ANY IMPLIED
35    *     WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
36    *     PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT
37    *     SHALL BROADCOM BE LIABLE FOR ANY DAMAGES WHATSOEVER, AND IN
38    *     PARTICULAR, BROADCOM SHALL NOT BE LIABLE FOR DIRECT, INDIRECT,
39    *     INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
40    *     (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
41    *     GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
42    *     BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
43    *     OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
44    *     TORT (INCLUDING NEGLIGENCE OR OTHERWISE), EVEN IF ADVISED OF
45    *     THE POSSIBILITY OF SUCH DAMAGE.
46    ********************************************************************* */
47
48
49typedef struct cfe_spi_channel_s cfe_spi_channel_t;
50typedef struct cfe_spi_s cfe_spi_t;
51
52struct cfe_spi_s {
53    /* Attach channel */
54    cfe_spi_channel_t * (*attach)(cfe_spi_t *,uint64_t probe_a,uint64_t probe_b);
55    /* Initialize channel */
56    int (*init)(cfe_spi_channel_t *chan);
57    /* Enable device (assert chip select) */
58    int (*enable)(cfe_spi_channel_t *chan,uint8_t slave);
59    /* Disable device (deassert chip select) */
60    int (*disable)(cfe_spi_channel_t *chan,uint8_t slave);
61    /* Write 'n' bytes to device */
62    int (*write)(cfe_spi_channel_t *chan,uint8_t *buf,int len);
63    /* Read 'n' bytes from device */
64    int (*read)(cfe_spi_channel_t *chan,uint8_t *buf,int len,uint8_t data_out);
65};
66
67struct cfe_spi_channel_s {
68    cfe_spi_t *ops;
69    void *softc;
70};
71
72#define SPI_CHANNELS_MAX	4
73
74extern cfe_spi_channel_t *cfe_spi_channels[SPI_CHANNELS_MAX];
75
76#define SPI_CHANNEL(chanidx) cfe_spi_channels[chanidx]
77#define SPI_INIT(chan) (chan)->ops->init(chan)
78#define SPI_ENABLE(chan,slave) (chan)->ops->enable(chan,slave)
79#define SPI_DISABLE(chan,slave) (chan)->ops->disable(chan,slave)
80#define SPI_WRITE(chan,buf,len) (chan)->ops->write(chan,buf,len)
81#define SPI_READ(chan,buf,len,data_out) (chan)->ops->read(chan,buf,len,data_out)
82
83
84int cfe_add_spi(cfe_spi_t *ops,uint64_t probe_a,uint64_t probe_b);
85
86
87