1 /***********************license start***************
2 * Copyright (c) 2003-2008 Cavium Networks (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 Networks 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 * TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED "AS IS"
24 * AND WITH ALL FAULTS AND CAVIUM NETWORKS MAKES NO PROMISES, REPRESENTATIONS
25 * OR WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, OR OTHERWISE, WITH
26 * RESPECT TO THE SOFTWARE, INCLUDING ITS CONDITION, ITS CONFORMITY TO ANY
27 * REPRESENTATION OR DESCRIPTION, OR THE EXISTENCE OF ANY LATENT OR PATENT
28 * DEFECTS, AND CAVIUM SPECIFICALLY DISCLAIMS ALL IMPLIED (IF ANY) WARRANTIES
29 * OF TITLE, MERCHANTABILITY, NONINFRINGEMENT, FITNESS FOR A PARTICULAR
30 * PURPOSE, LACK OF VIRUSES, ACCURACY OR COMPLETENESS, QUIET ENJOYMENT, QUIET
31 * POSSESSION OR CORRESPONDENCE TO DESCRIPTION. THE ENTIRE RISK ARISING OUT
32 * OF USE OR PERFORMANCE OF THE SOFTWARE LIES WITH YOU.
35 * For any questions regarding licensing please contact marketing@caviumnetworks.com
37 ***********************license end**************************************/
47 * This file contains defines for the SPI interface
49 * <hr>$Revision: 41586 $<hr>
53 #ifndef __CVMX_SPI_H__
54 #define __CVMX_SPI_H__
60 /* CSR typedefs have been moved to cvmx-csr-*.h */
64 CVMX_SPI_MODE_UNKNOWN = 0,
65 CVMX_SPI_MODE_TX_HALFPLEX = 1,
66 CVMX_SPI_MODE_RX_HALFPLEX = 2,
67 CVMX_SPI_MODE_DUPLEX = 3
70 /** Callbacks structure to customize SPI4 initialization sequence */
73 /** Called to reset SPI4 DLL */
74 int (*reset_cb)(int interface, cvmx_spi_mode_t mode);
76 /** Called to setup calendar */
77 int (*calendar_setup_cb)(int interface, cvmx_spi_mode_t mode, int num_ports);
79 /** Called for Tx and Rx clock detection */
80 int (*clock_detect_cb)(int interface, cvmx_spi_mode_t mode, int timeout);
82 /** Called to perform link training */
83 int (*training_cb)(int interface, cvmx_spi_mode_t mode, int timeout);
85 /** Called for calendar data synchronization */
86 int (*calendar_sync_cb)(int interface, cvmx_spi_mode_t mode, int timeout);
88 /** Called when interface is up */
89 int (*interface_up_cb)(int interface, cvmx_spi_mode_t mode);
91 } cvmx_spi_callbacks_t;
95 * Return true if the supplied interface is configured for SPI
97 * @param interface Interface to check
98 * @return True if interface is SPI
100 static inline int cvmx_spi_is_spi_interface(int interface)
102 uint64_t gmxState = cvmx_read_csr(CVMX_GMXX_INF_MODE(interface));
103 return ((gmxState & 0x2) && (gmxState & 0x1));
107 * Initialize and start the SPI interface.
109 * @param interface The identifier of the packet interface to configure and
110 * use as a SPI interface.
111 * @param mode The operating mode for the SPI interface. The interface
112 * can operate as a full duplex (both Tx and Rx data paths
113 * active) or as a halfplex (either the Tx data path is
114 * active or the Rx data path is active, but not both).
115 * @param timeout Timeout to wait for clock synchronization in seconds
116 * @param num_ports Number of SPI ports to configure
118 * @return Zero on success, negative of failure.
120 extern int cvmx_spi_start_interface(int interface, cvmx_spi_mode_t mode, int timeout, int num_ports);
123 * This routine restarts the SPI interface after it has lost synchronization
124 * with its corespondant system.
126 * @param interface The identifier of the packet interface to configure and
127 * use as a SPI interface.
128 * @param mode The operating mode for the SPI interface. The interface
129 * can operate as a full duplex (both Tx and Rx data paths
130 * active) or as a halfplex (either the Tx data path is
131 * active or the Rx data path is active, but not both).
132 * @param timeout Timeout to wait for clock synchronization in seconds
133 * @return Zero on success, negative of failure.
135 extern int cvmx_spi_restart_interface(int interface, cvmx_spi_mode_t mode, int timeout);
138 * Return non-zero if the SPI interface has a SPI4000 attached
140 * @param interface SPI interface the SPI4000 is connected to
144 extern int cvmx_spi4000_is_present(int interface);
147 * Initialize the SPI4000 for use
149 * @param interface SPI interface the SPI4000 is connected to
151 extern int cvmx_spi4000_initialize(int interface);
154 * Poll all the SPI4000 port and check its speed
156 * @param interface Interface the SPI4000 is on
157 * @param port Port to poll (0-9)
158 * @return Status of the port. 0=down. All other values the port is up.
160 extern cvmx_gmxx_rxx_rx_inbnd_t cvmx_spi4000_check_speed(int interface, int port);
163 * Get current SPI4 initialization callbacks
165 * @param callbacks Pointer to the callbacks structure.to fill
167 * @return Pointer to cvmx_spi_callbacks_t structure.
169 extern void cvmx_spi_get_callbacks(cvmx_spi_callbacks_t * callbacks);
172 * Set new SPI4 initialization callbacks
174 * @param new_callbacks Pointer to an updated callbacks structure.
176 extern void cvmx_spi_set_callbacks(cvmx_spi_callbacks_t * new_callbacks);
179 * Callback to perform SPI4 reset
181 * @param interface The identifier of the packet interface to configure and
182 * use as a SPI interface.
183 * @param mode The operating mode for the SPI interface. The interface
184 * can operate as a full duplex (both Tx and Rx data paths
185 * active) or as a halfplex (either the Tx data path is
186 * active or the Rx data path is active, but not both).
187 * @return Zero on success, non-zero error code on failure (will cause SPI initialization to abort)
189 extern int cvmx_spi_reset_cb(int interface, cvmx_spi_mode_t mode);
192 * Callback to setup calendar and miscellaneous settings before clock detection
194 * @param interface The identifier of the packet interface to configure and
195 * use as a SPI interface.
196 * @param mode The operating mode for the SPI interface. The interface
197 * can operate as a full duplex (both Tx and Rx data paths
198 * active) or as a halfplex (either the Tx data path is
199 * active or the Rx data path is active, but not both).
200 * @param num_ports Number of ports to configure on SPI
202 * @return Zero on success, non-zero error code on failure (will cause SPI initialization to abort)
204 extern int cvmx_spi_calendar_setup_cb(int interface, cvmx_spi_mode_t mode, int num_ports);
207 * Callback to perform clock detection
209 * @param interface The identifier of the packet interface to configure and
210 * use as a SPI interface.
211 * @param mode The operating mode for the SPI interface. The interface
212 * can operate as a full duplex (both Tx and Rx data paths
213 * active) or as a halfplex (either the Tx data path is
214 * active or the Rx data path is active, but not both).
215 * @param timeout Timeout to wait for clock synchronization in seconds
216 * @return Zero on success, non-zero error code on failure (will cause SPI initialization to abort)
218 extern int cvmx_spi_clock_detect_cb(int interface, cvmx_spi_mode_t mode, int timeout);
221 * Callback to perform link training
223 * @param interface The identifier of the packet interface to configure and
224 * use as a SPI interface.
225 * @param mode The operating mode for the SPI interface. The interface
226 * can operate as a full duplex (both Tx and Rx data paths
227 * active) or as a halfplex (either the Tx data path is
228 * active or the Rx data path is active, but not both).
229 * @param timeout Timeout to wait for link to be trained (in seconds)
230 * @return Zero on success, non-zero error code on failure (will cause SPI initialization to abort)
232 extern int cvmx_spi_training_cb(int interface, cvmx_spi_mode_t mode, int timeout);
235 * Callback to perform calendar data synchronization
237 * @param interface The identifier of the packet interface to configure and
238 * use as a SPI interface.
239 * @param mode The operating mode for the SPI interface. The interface
240 * can operate as a full duplex (both Tx and Rx data paths
241 * active) or as a halfplex (either the Tx data path is
242 * active or the Rx data path is active, but not both).
243 * @param timeout Timeout to wait for calendar data in seconds
244 * @return Zero on success, non-zero error code on failure (will cause SPI initialization to abort)
246 extern int cvmx_spi_calendar_sync_cb(int interface, cvmx_spi_mode_t mode, int timeout);
249 * Callback to handle interface up
251 * @param interface The identifier of the packet interface to configure and
252 * use as a SPI interface.
253 * @param mode The operating mode for the SPI interface. The interface
254 * can operate as a full duplex (both Tx and Rx data paths
255 * active) or as a halfplex (either the Tx data path is
256 * active or the Rx data path is active, but not both).
257 * @return Zero on success, non-zero error code on failure (will cause SPI initialization to abort)
259 extern int cvmx_spi_interface_up_cb(int interface, cvmx_spi_mode_t mode);
265 #endif /* __CVMX_SPI_H__ */