1 /***********************license start***************
2 * Copyright (c) 2003-2010 Cavium Inc. (support@cavium.com). All rights
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are
10 * * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above
14 * copyright notice, this list of conditions and the following
15 * disclaimer in the documentation and/or other materials provided
16 * with the distribution.
18 * * Neither the name of Cavium Inc. nor the names of
19 * its contributors may be used to endorse or promote products
20 * derived from this software without specific prior written
23 * This Software, including technical data, may be subject to U.S. export control
24 * laws, including the U.S. Export Administration Act and its associated
25 * regulations, and may be subject to export or import regulations in other
28 * TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED "AS IS"
29 * AND WITH ALL FAULTS AND CAVIUM INC. MAKES NO PROMISES, REPRESENTATIONS OR
30 * WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, OR OTHERWISE, WITH RESPECT TO
31 * THE SOFTWARE, INCLUDING ITS CONDITION, ITS CONFORMITY TO ANY REPRESENTATION OR
32 * DESCRIPTION, OR THE EXISTENCE OF ANY LATENT OR PATENT DEFECTS, AND CAVIUM
33 * SPECIFICALLY DISCLAIMS ALL IMPLIED (IF ANY) WARRANTIES OF TITLE,
34 * MERCHANTABILITY, NONINFRINGEMENT, FITNESS FOR A PARTICULAR PURPOSE, LACK OF
35 * VIRUSES, ACCURACY OR COMPLETENESS, QUIET ENJOYMENT, QUIET POSSESSION OR
36 * CORRESPONDENCE TO DESCRIPTION. THE ENTIRE RISK ARISING OUT OF USE OR
37 * PERFORMANCE OF THE SOFTWARE LIES WITH YOU.
38 ***********************license end**************************************/
49 * This file contains defines for the SPI interface
51 * <hr>$Revision: 70030 $<hr>
55 #ifndef __CVMX_SPI_H__
56 #define __CVMX_SPI_H__
58 #ifdef CVMX_BUILD_FOR_LINUX_KERNEL
59 #include "cvmx-gmxx-defs.h"
66 /* CSR typedefs have been moved to cvmx-spi-defs.h */
70 CVMX_SPI_MODE_UNKNOWN = 0,
71 CVMX_SPI_MODE_TX_HALFPLEX = 1,
72 CVMX_SPI_MODE_RX_HALFPLEX = 2,
73 CVMX_SPI_MODE_DUPLEX = 3
76 /** Callbacks structure to customize SPI4 initialization sequence */
79 /** Called to reset SPI4 DLL */
80 int (*reset_cb)(int interface, cvmx_spi_mode_t mode);
82 /** Called to setup calendar */
83 int (*calendar_setup_cb)(int interface, cvmx_spi_mode_t mode, int num_ports);
85 /** Called for Tx and Rx clock detection */
86 int (*clock_detect_cb)(int interface, cvmx_spi_mode_t mode, int timeout);
88 /** Called to perform link training */
89 int (*training_cb)(int interface, cvmx_spi_mode_t mode, int timeout);
91 /** Called for calendar data synchronization */
92 int (*calendar_sync_cb)(int interface, cvmx_spi_mode_t mode, int timeout);
94 /** Called when interface is up */
95 int (*interface_up_cb)(int interface, cvmx_spi_mode_t mode);
97 } cvmx_spi_callbacks_t;
101 * Return true if the supplied interface is configured for SPI
103 * @param interface Interface to check
104 * @return True if interface is SPI
106 static inline int cvmx_spi_is_spi_interface(int interface)
108 uint64_t gmxState = cvmx_read_csr(CVMX_GMXX_INF_MODE(interface));
109 return ((gmxState & 0x2) && (gmxState & 0x1));
113 * Initialize and start the SPI interface.
115 * @param interface The identifier of the packet interface to configure and
116 * use as a SPI interface.
117 * @param mode The operating mode for the SPI interface. The interface
118 * can operate as a full duplex (both Tx and Rx data paths
119 * active) or as a halfplex (either the Tx data path is
120 * active or the Rx data path is active, but not both).
121 * @param timeout Timeout to wait for clock synchronization in seconds
122 * @param num_ports Number of SPI ports to configure
124 * @return Zero on success, negative of failure.
126 extern int cvmx_spi_start_interface(int interface, cvmx_spi_mode_t mode, int timeout, int num_ports);
129 * This routine restarts the SPI interface after it has lost synchronization
130 * with its corespondant system.
132 * @param interface The identifier of the packet interface to configure and
133 * use as a SPI interface.
134 * @param mode The operating mode for the SPI interface. The interface
135 * can operate as a full duplex (both Tx and Rx data paths
136 * active) or as a halfplex (either the Tx data path is
137 * active or the Rx data path is active, but not both).
138 * @param timeout Timeout to wait for clock synchronization in seconds
139 * @return Zero on success, negative of failure.
141 extern int cvmx_spi_restart_interface(int interface, cvmx_spi_mode_t mode, int timeout);
144 * Return non-zero if the SPI interface has a SPI4000 attached
146 * @param interface SPI interface the SPI4000 is connected to
150 extern int cvmx_spi4000_is_present(int interface);
153 * Initialize the SPI4000 for use
155 * @param interface SPI interface the SPI4000 is connected to
157 extern int cvmx_spi4000_initialize(int interface);
160 * Poll all the SPI4000 port and check its speed
162 * @param interface Interface the SPI4000 is on
163 * @param port Port to poll (0-9)
164 * @return Status of the port. 0=down. All other values the port is up.
166 extern cvmx_gmxx_rxx_rx_inbnd_t cvmx_spi4000_check_speed(int interface, int port);
169 * Get current SPI4 initialization callbacks
171 * @param callbacks Pointer to the callbacks structure.to fill
173 * @return Pointer to cvmx_spi_callbacks_t structure.
175 extern void cvmx_spi_get_callbacks(cvmx_spi_callbacks_t * callbacks);
178 * Set new SPI4 initialization callbacks
180 * @param new_callbacks Pointer to an updated callbacks structure.
182 extern void cvmx_spi_set_callbacks(cvmx_spi_callbacks_t * new_callbacks);
185 * Callback to perform SPI4 reset
187 * @param interface The identifier of the packet interface to configure and
188 * use as a SPI interface.
189 * @param mode The operating mode for the SPI interface. The interface
190 * can operate as a full duplex (both Tx and Rx data paths
191 * active) or as a halfplex (either the Tx data path is
192 * active or the Rx data path is active, but not both).
193 * @return Zero on success, non-zero error code on failure (will cause SPI initialization to abort)
195 extern int cvmx_spi_reset_cb(int interface, cvmx_spi_mode_t mode);
198 * Callback to setup calendar and miscellaneous settings before clock detection
200 * @param interface The identifier of the packet interface to configure and
201 * use as a SPI interface.
202 * @param mode The operating mode for the SPI interface. The interface
203 * can operate as a full duplex (both Tx and Rx data paths
204 * active) or as a halfplex (either the Tx data path is
205 * active or the Rx data path is active, but not both).
206 * @param num_ports Number of ports to configure on SPI
208 * @return Zero on success, non-zero error code on failure (will cause SPI initialization to abort)
210 extern int cvmx_spi_calendar_setup_cb(int interface, cvmx_spi_mode_t mode, int num_ports);
213 * Callback to perform clock detection
215 * @param interface The identifier of the packet interface to configure and
216 * use as a SPI interface.
217 * @param mode The operating mode for the SPI interface. The interface
218 * can operate as a full duplex (both Tx and Rx data paths
219 * active) or as a halfplex (either the Tx data path is
220 * active or the Rx data path is active, but not both).
221 * @param timeout Timeout to wait for clock synchronization in seconds
222 * @return Zero on success, non-zero error code on failure (will cause SPI initialization to abort)
224 extern int cvmx_spi_clock_detect_cb(int interface, cvmx_spi_mode_t mode, int timeout);
227 * Callback to perform link training
229 * @param interface The identifier of the packet interface to configure and
230 * use as a SPI interface.
231 * @param mode The operating mode for the SPI interface. The interface
232 * can operate as a full duplex (both Tx and Rx data paths
233 * active) or as a halfplex (either the Tx data path is
234 * active or the Rx data path is active, but not both).
235 * @param timeout Timeout to wait for link to be trained (in seconds)
236 * @return Zero on success, non-zero error code on failure (will cause SPI initialization to abort)
238 extern int cvmx_spi_training_cb(int interface, cvmx_spi_mode_t mode, int timeout);
241 * Callback to perform calendar data synchronization
243 * @param interface The identifier of the packet interface to configure and
244 * use as a SPI interface.
245 * @param mode The operating mode for the SPI interface. The interface
246 * can operate as a full duplex (both Tx and Rx data paths
247 * active) or as a halfplex (either the Tx data path is
248 * active or the Rx data path is active, but not both).
249 * @param timeout Timeout to wait for calendar data in seconds
250 * @return Zero on success, non-zero error code on failure (will cause SPI initialization to abort)
252 extern int cvmx_spi_calendar_sync_cb(int interface, cvmx_spi_mode_t mode, int timeout);
255 * Callback to handle interface up
257 * @param interface The identifier of the packet interface to configure and
258 * use as a SPI interface.
259 * @param mode The operating mode for the SPI interface. The interface
260 * can operate as a full duplex (both Tx and Rx data paths
261 * active) or as a halfplex (either the Tx data path is
262 * active or the Rx data path is active, but not both).
263 * @return Zero on success, non-zero error code on failure (will cause SPI initialization to abort)
265 extern int cvmx_spi_interface_up_cb(int interface, cvmx_spi_mode_t mode);
271 #endif /* __CVMX_SPI_H__ */