1/***********************license start*************** 2 * Copyright (c) 2003-2010 Cavium Inc. (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 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 21 * permission. 22 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 26 * countries. 27 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**************************************/ 39 40 41 42 43 44 45 46/** 47 * @file 48 * 49 * This file contains defines for the SPI interface 50 51 * <hr>$Revision: 70030 $<hr> 52 * 53 * 54 */ 55#ifndef __CVMX_SPI_H__ 56#define __CVMX_SPI_H__ 57 58#ifdef CVMX_BUILD_FOR_LINUX_KERNEL 59#include "cvmx-gmxx-defs.h" 60#endif 61 62#ifdef __cplusplus 63extern "C" { 64#endif 65 66/* CSR typedefs have been moved to cvmx-spi-defs.h */ 67 68typedef enum 69{ 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 74} cvmx_spi_mode_t; 75 76/** Callbacks structure to customize SPI4 initialization sequence */ 77typedef struct 78{ 79 /** Called to reset SPI4 DLL */ 80 int (*reset_cb)(int interface, cvmx_spi_mode_t mode); 81 82 /** Called to setup calendar */ 83 int (*calendar_setup_cb)(int interface, cvmx_spi_mode_t mode, int num_ports); 84 85 /** Called for Tx and Rx clock detection */ 86 int (*clock_detect_cb)(int interface, cvmx_spi_mode_t mode, int timeout); 87 88 /** Called to perform link training */ 89 int (*training_cb)(int interface, cvmx_spi_mode_t mode, int timeout); 90 91 /** Called for calendar data synchronization */ 92 int (*calendar_sync_cb)(int interface, cvmx_spi_mode_t mode, int timeout); 93 94 /** Called when interface is up */ 95 int (*interface_up_cb)(int interface, cvmx_spi_mode_t mode); 96 97} cvmx_spi_callbacks_t; 98 99 100/** 101 * Return true if the supplied interface is configured for SPI 102 * 103 * @param interface Interface to check 104 * @return True if interface is SPI 105 */ 106static inline int cvmx_spi_is_spi_interface(int interface) 107{ 108 uint64_t gmxState = cvmx_read_csr(CVMX_GMXX_INF_MODE(interface)); 109 return ((gmxState & 0x2) && (gmxState & 0x1)); 110} 111 112/** 113 * Initialize and start the SPI interface. 114 * 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 123 * 124 * @return Zero on success, negative of failure. 125 */ 126extern int cvmx_spi_start_interface(int interface, cvmx_spi_mode_t mode, int timeout, int num_ports); 127 128/** 129 * This routine restarts the SPI interface after it has lost synchronization 130 * with its corespondant system. 131 * 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. 140 */ 141extern int cvmx_spi_restart_interface(int interface, cvmx_spi_mode_t mode, int timeout); 142 143/** 144 * Return non-zero if the SPI interface has a SPI4000 attached 145 * 146 * @param interface SPI interface the SPI4000 is connected to 147 * 148 * @return 149 */ 150extern int cvmx_spi4000_is_present(int interface); 151 152/** 153 * Initialize the SPI4000 for use 154 * 155 * @param interface SPI interface the SPI4000 is connected to 156 */ 157extern int cvmx_spi4000_initialize(int interface); 158 159/** 160 * Poll all the SPI4000 port and check its speed 161 * 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. 165 */ 166extern cvmx_gmxx_rxx_rx_inbnd_t cvmx_spi4000_check_speed(int interface, int port); 167 168/** 169 * Get current SPI4 initialization callbacks 170 * 171 * @param callbacks Pointer to the callbacks structure.to fill 172 * 173 * @return Pointer to cvmx_spi_callbacks_t structure. 174 */ 175extern void cvmx_spi_get_callbacks(cvmx_spi_callbacks_t * callbacks); 176 177/** 178 * Set new SPI4 initialization callbacks 179 * 180 * @param new_callbacks Pointer to an updated callbacks structure. 181 */ 182extern void cvmx_spi_set_callbacks(cvmx_spi_callbacks_t * new_callbacks); 183 184/** 185 * Callback to perform SPI4 reset 186 * 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) 194 */ 195extern int cvmx_spi_reset_cb(int interface, cvmx_spi_mode_t mode); 196 197/** 198 * Callback to setup calendar and miscellaneous settings before clock detection 199 * 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 207 * 208 * @return Zero on success, non-zero error code on failure (will cause SPI initialization to abort) 209 */ 210extern int cvmx_spi_calendar_setup_cb(int interface, cvmx_spi_mode_t mode, int num_ports); 211 212/** 213 * Callback to perform clock detection 214 * 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) 223 */ 224extern int cvmx_spi_clock_detect_cb(int interface, cvmx_spi_mode_t mode, int timeout); 225 226/** 227 * Callback to perform link training 228 * 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) 237 */ 238extern int cvmx_spi_training_cb(int interface, cvmx_spi_mode_t mode, int timeout); 239 240/** 241 * Callback to perform calendar data synchronization 242 * 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) 251 */ 252extern int cvmx_spi_calendar_sync_cb(int interface, cvmx_spi_mode_t mode, int timeout); 253 254/** 255 * Callback to handle interface up 256 * 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) 264 */ 265extern int cvmx_spi_interface_up_cb(int interface, cvmx_spi_mode_t mode); 266 267#ifdef __cplusplus 268} 269#endif 270 271#endif /* __CVMX_SPI_H__ */ 272