1*4882a593Smuzhiyun /***********************license start***************
2*4882a593Smuzhiyun * Author: Cavium Networks
3*4882a593Smuzhiyun *
4*4882a593Smuzhiyun * Contact: support@caviumnetworks.com
5*4882a593Smuzhiyun * This file is part of the OCTEON SDK
6*4882a593Smuzhiyun *
7*4882a593Smuzhiyun * Copyright (c) 2003-2008 Cavium Networks
8*4882a593Smuzhiyun *
9*4882a593Smuzhiyun * This file is free software; you can redistribute it and/or modify
10*4882a593Smuzhiyun * it under the terms of the GNU General Public License, Version 2, as
11*4882a593Smuzhiyun * published by the Free Software Foundation.
12*4882a593Smuzhiyun *
13*4882a593Smuzhiyun * This file is distributed in the hope that it will be useful, but
14*4882a593Smuzhiyun * AS-IS and WITHOUT ANY WARRANTY; without even the implied warranty
15*4882a593Smuzhiyun * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, TITLE, or
16*4882a593Smuzhiyun * NONINFRINGEMENT. See the GNU General Public License for more
17*4882a593Smuzhiyun * details.
18*4882a593Smuzhiyun *
19*4882a593Smuzhiyun * You should have received a copy of the GNU General Public License
20*4882a593Smuzhiyun * along with this file; if not, write to the Free Software
21*4882a593Smuzhiyun * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22*4882a593Smuzhiyun * or visit http://www.gnu.org/licenses/.
23*4882a593Smuzhiyun *
24*4882a593Smuzhiyun * This file may also be available under a different license from Cavium.
25*4882a593Smuzhiyun * Contact Cavium Networks for more information
26*4882a593Smuzhiyun ***********************license end**************************************/
27*4882a593Smuzhiyun
28*4882a593Smuzhiyun /*
29*4882a593Smuzhiyun *
30*4882a593Smuzhiyun * This file contains defines for the SPI interface
31*4882a593Smuzhiyun */
32*4882a593Smuzhiyun #ifndef __CVMX_SPI_H__
33*4882a593Smuzhiyun #define __CVMX_SPI_H__
34*4882a593Smuzhiyun
35*4882a593Smuzhiyun #include <asm/octeon/cvmx-gmxx-defs.h>
36*4882a593Smuzhiyun
37*4882a593Smuzhiyun /* CSR typedefs have been moved to cvmx-csr-*.h */
38*4882a593Smuzhiyun
39*4882a593Smuzhiyun typedef enum {
40*4882a593Smuzhiyun CVMX_SPI_MODE_UNKNOWN = 0,
41*4882a593Smuzhiyun CVMX_SPI_MODE_TX_HALFPLEX = 1,
42*4882a593Smuzhiyun CVMX_SPI_MODE_RX_HALFPLEX = 2,
43*4882a593Smuzhiyun CVMX_SPI_MODE_DUPLEX = 3
44*4882a593Smuzhiyun } cvmx_spi_mode_t;
45*4882a593Smuzhiyun
46*4882a593Smuzhiyun /** Callbacks structure to customize SPI4 initialization sequence */
47*4882a593Smuzhiyun typedef struct {
48*4882a593Smuzhiyun /** Called to reset SPI4 DLL */
49*4882a593Smuzhiyun int (*reset_cb) (int interface, cvmx_spi_mode_t mode);
50*4882a593Smuzhiyun
51*4882a593Smuzhiyun /** Called to setup calendar */
52*4882a593Smuzhiyun int (*calendar_setup_cb) (int interface, cvmx_spi_mode_t mode,
53*4882a593Smuzhiyun int num_ports);
54*4882a593Smuzhiyun
55*4882a593Smuzhiyun /** Called for Tx and Rx clock detection */
56*4882a593Smuzhiyun int (*clock_detect_cb) (int interface, cvmx_spi_mode_t mode,
57*4882a593Smuzhiyun int timeout);
58*4882a593Smuzhiyun
59*4882a593Smuzhiyun /** Called to perform link training */
60*4882a593Smuzhiyun int (*training_cb) (int interface, cvmx_spi_mode_t mode, int timeout);
61*4882a593Smuzhiyun
62*4882a593Smuzhiyun /** Called for calendar data synchronization */
63*4882a593Smuzhiyun int (*calendar_sync_cb) (int interface, cvmx_spi_mode_t mode,
64*4882a593Smuzhiyun int timeout);
65*4882a593Smuzhiyun
66*4882a593Smuzhiyun /** Called when interface is up */
67*4882a593Smuzhiyun int (*interface_up_cb) (int interface, cvmx_spi_mode_t mode);
68*4882a593Smuzhiyun
69*4882a593Smuzhiyun } cvmx_spi_callbacks_t;
70*4882a593Smuzhiyun
71*4882a593Smuzhiyun /**
72*4882a593Smuzhiyun * Return true if the supplied interface is configured for SPI
73*4882a593Smuzhiyun *
74*4882a593Smuzhiyun * @interface: Interface to check
75*4882a593Smuzhiyun * Returns True if interface is SPI
76*4882a593Smuzhiyun */
cvmx_spi_is_spi_interface(int interface)77*4882a593Smuzhiyun static inline int cvmx_spi_is_spi_interface(int interface)
78*4882a593Smuzhiyun {
79*4882a593Smuzhiyun uint64_t gmxState = cvmx_read_csr(CVMX_GMXX_INF_MODE(interface));
80*4882a593Smuzhiyun return (gmxState & 0x2) && (gmxState & 0x1);
81*4882a593Smuzhiyun }
82*4882a593Smuzhiyun
83*4882a593Smuzhiyun /**
84*4882a593Smuzhiyun * Initialize and start the SPI interface.
85*4882a593Smuzhiyun *
86*4882a593Smuzhiyun * @interface: The identifier of the packet interface to configure and
87*4882a593Smuzhiyun * use as a SPI interface.
88*4882a593Smuzhiyun * @mode: The operating mode for the SPI interface. The interface
89*4882a593Smuzhiyun * can operate as a full duplex (both Tx and Rx data paths
90*4882a593Smuzhiyun * active) or as a halfplex (either the Tx data path is
91*4882a593Smuzhiyun * active or the Rx data path is active, but not both).
92*4882a593Smuzhiyun * @timeout: Timeout to wait for clock synchronization in seconds
93*4882a593Smuzhiyun * @num_ports: Number of SPI ports to configure
94*4882a593Smuzhiyun *
95*4882a593Smuzhiyun * Returns Zero on success, negative of failure.
96*4882a593Smuzhiyun */
97*4882a593Smuzhiyun extern int cvmx_spi_start_interface(int interface, cvmx_spi_mode_t mode,
98*4882a593Smuzhiyun int timeout, int num_ports);
99*4882a593Smuzhiyun
100*4882a593Smuzhiyun /**
101*4882a593Smuzhiyun * This routine restarts the SPI interface after it has lost synchronization
102*4882a593Smuzhiyun * with its corespondant system.
103*4882a593Smuzhiyun *
104*4882a593Smuzhiyun * @interface: The identifier of the packet interface to configure and
105*4882a593Smuzhiyun * use as a SPI interface.
106*4882a593Smuzhiyun * @mode: The operating mode for the SPI interface. The interface
107*4882a593Smuzhiyun * can operate as a full duplex (both Tx and Rx data paths
108*4882a593Smuzhiyun * active) or as a halfplex (either the Tx data path is
109*4882a593Smuzhiyun * active or the Rx data path is active, but not both).
110*4882a593Smuzhiyun * @timeout: Timeout to wait for clock synchronization in seconds
111*4882a593Smuzhiyun * Returns Zero on success, negative of failure.
112*4882a593Smuzhiyun */
113*4882a593Smuzhiyun extern int cvmx_spi_restart_interface(int interface, cvmx_spi_mode_t mode,
114*4882a593Smuzhiyun int timeout);
115*4882a593Smuzhiyun
116*4882a593Smuzhiyun /**
117*4882a593Smuzhiyun * Return non-zero if the SPI interface has a SPI4000 attached
118*4882a593Smuzhiyun *
119*4882a593Smuzhiyun * @interface: SPI interface the SPI4000 is connected to
120*4882a593Smuzhiyun *
121*4882a593Smuzhiyun * Returns
122*4882a593Smuzhiyun */
cvmx_spi4000_is_present(int interface)123*4882a593Smuzhiyun static inline int cvmx_spi4000_is_present(int interface)
124*4882a593Smuzhiyun {
125*4882a593Smuzhiyun return 0;
126*4882a593Smuzhiyun }
127*4882a593Smuzhiyun
128*4882a593Smuzhiyun /**
129*4882a593Smuzhiyun * Initialize the SPI4000 for use
130*4882a593Smuzhiyun *
131*4882a593Smuzhiyun * @interface: SPI interface the SPI4000 is connected to
132*4882a593Smuzhiyun */
cvmx_spi4000_initialize(int interface)133*4882a593Smuzhiyun static inline int cvmx_spi4000_initialize(int interface)
134*4882a593Smuzhiyun {
135*4882a593Smuzhiyun return 0;
136*4882a593Smuzhiyun }
137*4882a593Smuzhiyun
138*4882a593Smuzhiyun /**
139*4882a593Smuzhiyun * Poll all the SPI4000 port and check its speed
140*4882a593Smuzhiyun *
141*4882a593Smuzhiyun * @interface: Interface the SPI4000 is on
142*4882a593Smuzhiyun * @port: Port to poll (0-9)
143*4882a593Smuzhiyun * Returns Status of the port. 0=down. All other values the port is up.
144*4882a593Smuzhiyun */
cvmx_spi4000_check_speed(int interface,int port)145*4882a593Smuzhiyun static inline union cvmx_gmxx_rxx_rx_inbnd cvmx_spi4000_check_speed(
146*4882a593Smuzhiyun int interface,
147*4882a593Smuzhiyun int port)
148*4882a593Smuzhiyun {
149*4882a593Smuzhiyun union cvmx_gmxx_rxx_rx_inbnd r;
150*4882a593Smuzhiyun r.u64 = 0;
151*4882a593Smuzhiyun return r;
152*4882a593Smuzhiyun }
153*4882a593Smuzhiyun
154*4882a593Smuzhiyun /**
155*4882a593Smuzhiyun * Get current SPI4 initialization callbacks
156*4882a593Smuzhiyun *
157*4882a593Smuzhiyun * @callbacks: Pointer to the callbacks structure.to fill
158*4882a593Smuzhiyun *
159*4882a593Smuzhiyun * Returns Pointer to cvmx_spi_callbacks_t structure.
160*4882a593Smuzhiyun */
161*4882a593Smuzhiyun extern void cvmx_spi_get_callbacks(cvmx_spi_callbacks_t *callbacks);
162*4882a593Smuzhiyun
163*4882a593Smuzhiyun /**
164*4882a593Smuzhiyun * Set new SPI4 initialization callbacks
165*4882a593Smuzhiyun *
166*4882a593Smuzhiyun * @new_callbacks: Pointer to an updated callbacks structure.
167*4882a593Smuzhiyun */
168*4882a593Smuzhiyun extern void cvmx_spi_set_callbacks(cvmx_spi_callbacks_t *new_callbacks);
169*4882a593Smuzhiyun
170*4882a593Smuzhiyun /**
171*4882a593Smuzhiyun * Callback to perform SPI4 reset
172*4882a593Smuzhiyun *
173*4882a593Smuzhiyun * @interface: The identifier of the packet interface to configure and
174*4882a593Smuzhiyun * use as a SPI interface.
175*4882a593Smuzhiyun * @mode: The operating mode for the SPI interface. The interface
176*4882a593Smuzhiyun * can operate as a full duplex (both Tx and Rx data paths
177*4882a593Smuzhiyun * active) or as a halfplex (either the Tx data path is
178*4882a593Smuzhiyun * active or the Rx data path is active, but not both).
179*4882a593Smuzhiyun *
180*4882a593Smuzhiyun * Returns Zero on success, non-zero error code on failure (will cause
181*4882a593Smuzhiyun * SPI initialization to abort)
182*4882a593Smuzhiyun */
183*4882a593Smuzhiyun extern int cvmx_spi_reset_cb(int interface, cvmx_spi_mode_t mode);
184*4882a593Smuzhiyun
185*4882a593Smuzhiyun /**
186*4882a593Smuzhiyun * Callback to setup calendar and miscellaneous settings before clock
187*4882a593Smuzhiyun * detection
188*4882a593Smuzhiyun *
189*4882a593Smuzhiyun * @interface: The identifier of the packet interface to configure and
190*4882a593Smuzhiyun * use as a SPI interface.
191*4882a593Smuzhiyun * @mode: The operating mode for the SPI interface. The interface
192*4882a593Smuzhiyun * can operate as a full duplex (both Tx and Rx data paths
193*4882a593Smuzhiyun * active) or as a halfplex (either the Tx data path is
194*4882a593Smuzhiyun * active or the Rx data path is active, but not both).
195*4882a593Smuzhiyun * @num_ports: Number of ports to configure on SPI
196*4882a593Smuzhiyun *
197*4882a593Smuzhiyun * Returns Zero on success, non-zero error code on failure (will cause
198*4882a593Smuzhiyun * SPI initialization to abort)
199*4882a593Smuzhiyun */
200*4882a593Smuzhiyun extern int cvmx_spi_calendar_setup_cb(int interface, cvmx_spi_mode_t mode,
201*4882a593Smuzhiyun int num_ports);
202*4882a593Smuzhiyun
203*4882a593Smuzhiyun /**
204*4882a593Smuzhiyun * Callback to perform clock detection
205*4882a593Smuzhiyun *
206*4882a593Smuzhiyun * @interface: The identifier of the packet interface to configure and
207*4882a593Smuzhiyun * use as a SPI interface.
208*4882a593Smuzhiyun * @mode: The operating mode for the SPI interface. The interface
209*4882a593Smuzhiyun * can operate as a full duplex (both Tx and Rx data paths
210*4882a593Smuzhiyun * active) or as a halfplex (either the Tx data path is
211*4882a593Smuzhiyun * active or the Rx data path is active, but not both).
212*4882a593Smuzhiyun * @timeout: Timeout to wait for clock synchronization in seconds
213*4882a593Smuzhiyun *
214*4882a593Smuzhiyun * Returns Zero on success, non-zero error code on failure (will cause
215*4882a593Smuzhiyun * SPI initialization to abort)
216*4882a593Smuzhiyun */
217*4882a593Smuzhiyun extern int cvmx_spi_clock_detect_cb(int interface, cvmx_spi_mode_t mode,
218*4882a593Smuzhiyun int timeout);
219*4882a593Smuzhiyun
220*4882a593Smuzhiyun /**
221*4882a593Smuzhiyun * Callback to perform link training
222*4882a593Smuzhiyun *
223*4882a593Smuzhiyun * @interface: The identifier of the packet interface to configure and
224*4882a593Smuzhiyun * use as a SPI interface.
225*4882a593Smuzhiyun * @mode: The operating mode for the SPI interface. The interface
226*4882a593Smuzhiyun * can operate as a full duplex (both Tx and Rx data paths
227*4882a593Smuzhiyun * active) or as a halfplex (either the Tx data path is
228*4882a593Smuzhiyun * active or the Rx data path is active, but not both).
229*4882a593Smuzhiyun * @timeout: Timeout to wait for link to be trained (in seconds)
230*4882a593Smuzhiyun *
231*4882a593Smuzhiyun * Returns Zero on success, non-zero error code on failure (will cause
232*4882a593Smuzhiyun * SPI initialization to abort)
233*4882a593Smuzhiyun */
234*4882a593Smuzhiyun extern int cvmx_spi_training_cb(int interface, cvmx_spi_mode_t mode,
235*4882a593Smuzhiyun int timeout);
236*4882a593Smuzhiyun
237*4882a593Smuzhiyun /**
238*4882a593Smuzhiyun * Callback to perform calendar data synchronization
239*4882a593Smuzhiyun *
240*4882a593Smuzhiyun * @interface: The identifier of the packet interface to configure and
241*4882a593Smuzhiyun * use as a SPI interface.
242*4882a593Smuzhiyun * @mode: The operating mode for the SPI interface. The interface
243*4882a593Smuzhiyun * can operate as a full duplex (both Tx and Rx data paths
244*4882a593Smuzhiyun * active) or as a halfplex (either the Tx data path is
245*4882a593Smuzhiyun * active or the Rx data path is active, but not both).
246*4882a593Smuzhiyun * @timeout: Timeout to wait for calendar data in seconds
247*4882a593Smuzhiyun *
248*4882a593Smuzhiyun * Returns Zero on success, non-zero error code on failure (will cause
249*4882a593Smuzhiyun * SPI initialization to abort)
250*4882a593Smuzhiyun */
251*4882a593Smuzhiyun extern int cvmx_spi_calendar_sync_cb(int interface, cvmx_spi_mode_t mode,
252*4882a593Smuzhiyun int timeout);
253*4882a593Smuzhiyun
254*4882a593Smuzhiyun /**
255*4882a593Smuzhiyun * Callback to handle interface up
256*4882a593Smuzhiyun *
257*4882a593Smuzhiyun * @interface: The identifier of the packet interface to configure and
258*4882a593Smuzhiyun * use as a SPI interface.
259*4882a593Smuzhiyun * @mode: The operating mode for the SPI interface. The interface
260*4882a593Smuzhiyun * can operate as a full duplex (both Tx and Rx data paths
261*4882a593Smuzhiyun * active) or as a halfplex (either the Tx data path is
262*4882a593Smuzhiyun * active or the Rx data path is active, but not both).
263*4882a593Smuzhiyun *
264*4882a593Smuzhiyun * Returns Zero on success, non-zero error code on failure (will cause
265*4882a593Smuzhiyun * SPI initialization to abort)
266*4882a593Smuzhiyun */
267*4882a593Smuzhiyun extern int cvmx_spi_interface_up_cb(int interface, cvmx_spi_mode_t mode);
268*4882a593Smuzhiyun
269*4882a593Smuzhiyun #endif /* __CVMX_SPI_H__ */
270