cvmx-spi.h revision 210286
1/***********************license start*************** 2 * Copyright (c) 2003-2008 Cavium Networks (support@cavium.com). All rights 3 * reserved. 4 * 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions are 8 * met: 9 * 10 * * Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 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. 17 * 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 21 * permission. 22 * 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. 33 * 34 * 35 * For any questions regarding licensing please contact marketing@caviumnetworks.com 36 * 37 ***********************license end**************************************/ 38 39 40 41 42 43 44/** 45 * @file 46 * 47 * This file contains defines for the SPI interface 48 49 * <hr>$Revision: 41586 $<hr> 50 * 51 * 52 */ 53#ifndef __CVMX_SPI_H__ 54#define __CVMX_SPI_H__ 55 56#ifdef __cplusplus 57extern "C" { 58#endif 59 60/* CSR typedefs have been moved to cvmx-csr-*.h */ 61 62typedef enum 63{ 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 68} cvmx_spi_mode_t; 69 70/** Callbacks structure to customize SPI4 initialization sequence */ 71typedef struct 72{ 73 /** Called to reset SPI4 DLL */ 74 int (*reset_cb)(int interface, cvmx_spi_mode_t mode); 75 76 /** Called to setup calendar */ 77 int (*calendar_setup_cb)(int interface, cvmx_spi_mode_t mode, int num_ports); 78 79 /** Called for Tx and Rx clock detection */ 80 int (*clock_detect_cb)(int interface, cvmx_spi_mode_t mode, int timeout); 81 82 /** Called to perform link training */ 83 int (*training_cb)(int interface, cvmx_spi_mode_t mode, int timeout); 84 85 /** Called for calendar data synchronization */ 86 int (*calendar_sync_cb)(int interface, cvmx_spi_mode_t mode, int timeout); 87 88 /** Called when interface is up */ 89 int (*interface_up_cb)(int interface, cvmx_spi_mode_t mode); 90 91} cvmx_spi_callbacks_t; 92 93 94/** 95 * Return true if the supplied interface is configured for SPI 96 * 97 * @param interface Interface to check 98 * @return True if interface is SPI 99 */ 100static inline int cvmx_spi_is_spi_interface(int interface) 101{ 102 uint64_t gmxState = cvmx_read_csr(CVMX_GMXX_INF_MODE(interface)); 103 return ((gmxState & 0x2) && (gmxState & 0x1)); 104} 105 106/** 107 * Initialize and start the SPI interface. 108 * 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 117 * 118 * @return Zero on success, negative of failure. 119 */ 120extern int cvmx_spi_start_interface(int interface, cvmx_spi_mode_t mode, int timeout, int num_ports); 121 122/** 123 * This routine restarts the SPI interface after it has lost synchronization 124 * with its corespondant system. 125 * 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. 134 */ 135extern int cvmx_spi_restart_interface(int interface, cvmx_spi_mode_t mode, int timeout); 136 137/** 138 * Return non-zero if the SPI interface has a SPI4000 attached 139 * 140 * @param interface SPI interface the SPI4000 is connected to 141 * 142 * @return 143 */ 144extern int cvmx_spi4000_is_present(int interface); 145 146/** 147 * Initialize the SPI4000 for use 148 * 149 * @param interface SPI interface the SPI4000 is connected to 150 */ 151extern int cvmx_spi4000_initialize(int interface); 152 153/** 154 * Poll all the SPI4000 port and check its speed 155 * 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. 159 */ 160extern cvmx_gmxx_rxx_rx_inbnd_t cvmx_spi4000_check_speed(int interface, int port); 161 162/** 163 * Get current SPI4 initialization callbacks 164 * 165 * @param callbacks Pointer to the callbacks structure.to fill 166 * 167 * @return Pointer to cvmx_spi_callbacks_t structure. 168 */ 169extern void cvmx_spi_get_callbacks(cvmx_spi_callbacks_t * callbacks); 170 171/** 172 * Set new SPI4 initialization callbacks 173 * 174 * @param new_callbacks Pointer to an updated callbacks structure. 175 */ 176extern void cvmx_spi_set_callbacks(cvmx_spi_callbacks_t * new_callbacks); 177 178/** 179 * Callback to perform SPI4 reset 180 * 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) 188 */ 189extern int cvmx_spi_reset_cb(int interface, cvmx_spi_mode_t mode); 190 191/** 192 * Callback to setup calendar and miscellaneous settings before clock detection 193 * 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 201 * 202 * @return Zero on success, non-zero error code on failure (will cause SPI initialization to abort) 203 */ 204extern int cvmx_spi_calendar_setup_cb(int interface, cvmx_spi_mode_t mode, int num_ports); 205 206/** 207 * Callback to perform clock detection 208 * 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) 217 */ 218extern int cvmx_spi_clock_detect_cb(int interface, cvmx_spi_mode_t mode, int timeout); 219 220/** 221 * Callback to perform link training 222 * 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) 231 */ 232extern int cvmx_spi_training_cb(int interface, cvmx_spi_mode_t mode, int timeout); 233 234/** 235 * Callback to perform calendar data synchronization 236 * 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) 245 */ 246extern int cvmx_spi_calendar_sync_cb(int interface, cvmx_spi_mode_t mode, int timeout); 247 248/** 249 * Callback to handle interface up 250 * 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) 258 */ 259extern int cvmx_spi_interface_up_cb(int interface, cvmx_spi_mode_t mode); 260 261#ifdef __cplusplus 262} 263#endif 264 265#endif /* __CVMX_SPI_H__ */ 266