cvmx-spi.h revision 210284
1210284Sjmallett/***********************license start*************** 2210284Sjmallett * Copyright (c) 2003-2008 Cavium Networks (support@cavium.com). All rights 3210284Sjmallett * reserved. 4210284Sjmallett * 5210284Sjmallett * 6210284Sjmallett * Redistribution and use in source and binary forms, with or without 7210284Sjmallett * modification, are permitted provided that the following conditions are 8210284Sjmallett * met: 9210284Sjmallett * 10210284Sjmallett * * Redistributions of source code must retain the above copyright 11210284Sjmallett * notice, this list of conditions and the following disclaimer. 12210284Sjmallett * 13210284Sjmallett * * Redistributions in binary form must reproduce the above 14210284Sjmallett * copyright notice, this list of conditions and the following 15210284Sjmallett * disclaimer in the documentation and/or other materials provided 16210284Sjmallett * with the distribution. 17210284Sjmallett * 18210284Sjmallett * * Neither the name of Cavium Networks nor the names of 19210284Sjmallett * its contributors may be used to endorse or promote products 20210284Sjmallett * derived from this software without specific prior written 21210284Sjmallett * permission. 22210284Sjmallett * 23210284Sjmallett * TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED "AS IS" 24210284Sjmallett * AND WITH ALL FAULTS AND CAVIUM NETWORKS MAKES NO PROMISES, REPRESENTATIONS 25210284Sjmallett * OR WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, OR OTHERWISE, WITH 26210284Sjmallett * RESPECT TO THE SOFTWARE, INCLUDING ITS CONDITION, ITS CONFORMITY TO ANY 27210284Sjmallett * REPRESENTATION OR DESCRIPTION, OR THE EXISTENCE OF ANY LATENT OR PATENT 28210284Sjmallett * DEFECTS, AND CAVIUM SPECIFICALLY DISCLAIMS ALL IMPLIED (IF ANY) WARRANTIES 29210284Sjmallett * OF TITLE, MERCHANTABILITY, NONINFRINGEMENT, FITNESS FOR A PARTICULAR 30210284Sjmallett * PURPOSE, LACK OF VIRUSES, ACCURACY OR COMPLETENESS, QUIET ENJOYMENT, QUIET 31210284Sjmallett * POSSESSION OR CORRESPONDENCE TO DESCRIPTION. THE ENTIRE RISK ARISING OUT 32210284Sjmallett * OF USE OR PERFORMANCE OF THE SOFTWARE LIES WITH YOU. 33210284Sjmallett * 34210284Sjmallett * 35210284Sjmallett * For any questions regarding licensing please contact marketing@caviumnetworks.com 36210284Sjmallett * 37210284Sjmallett ***********************license end**************************************/ 38210284Sjmallett 39210284Sjmallett 40210284Sjmallett 41210284Sjmallett 42210284Sjmallett 43210284Sjmallett 44210284Sjmallett/** 45210284Sjmallett * @file 46210284Sjmallett * 47210284Sjmallett * This file contains defines for the SPI interface 48210284Sjmallett 49210284Sjmallett * <hr>$Revision: 41586 $<hr> 50210284Sjmallett * 51210284Sjmallett * 52210284Sjmallett */ 53210284Sjmallett#ifndef __CVMX_SPI_H__ 54210284Sjmallett#define __CVMX_SPI_H__ 55210284Sjmallett 56210284Sjmallett#ifdef __cplusplus 57210284Sjmallettextern "C" { 58210284Sjmallett#endif 59210284Sjmallett 60210284Sjmallett/* CSR typedefs have been moved to cvmx-csr-*.h */ 61210284Sjmallett 62210284Sjmalletttypedef enum 63210284Sjmallett{ 64210284Sjmallett CVMX_SPI_MODE_UNKNOWN = 0, 65210284Sjmallett CVMX_SPI_MODE_TX_HALFPLEX = 1, 66210284Sjmallett CVMX_SPI_MODE_RX_HALFPLEX = 2, 67210284Sjmallett CVMX_SPI_MODE_DUPLEX = 3 68210284Sjmallett} cvmx_spi_mode_t; 69210284Sjmallett 70210284Sjmallett/** Callbacks structure to customize SPI4 initialization sequence */ 71210284Sjmalletttypedef struct 72210284Sjmallett{ 73210284Sjmallett /** Called to reset SPI4 DLL */ 74210284Sjmallett int (*reset_cb)(int interface, cvmx_spi_mode_t mode); 75210284Sjmallett 76210284Sjmallett /** Called to setup calendar */ 77210284Sjmallett int (*calendar_setup_cb)(int interface, cvmx_spi_mode_t mode, int num_ports); 78210284Sjmallett 79210284Sjmallett /** Called for Tx and Rx clock detection */ 80210284Sjmallett int (*clock_detect_cb)(int interface, cvmx_spi_mode_t mode, int timeout); 81210284Sjmallett 82210284Sjmallett /** Called to perform link training */ 83210284Sjmallett int (*training_cb)(int interface, cvmx_spi_mode_t mode, int timeout); 84210284Sjmallett 85210284Sjmallett /** Called for calendar data synchronization */ 86210284Sjmallett int (*calendar_sync_cb)(int interface, cvmx_spi_mode_t mode, int timeout); 87210284Sjmallett 88210284Sjmallett /** Called when interface is up */ 89210284Sjmallett int (*interface_up_cb)(int interface, cvmx_spi_mode_t mode); 90210284Sjmallett 91210284Sjmallett} cvmx_spi_callbacks_t; 92210284Sjmallett 93210284Sjmallett 94210284Sjmallett/** 95210284Sjmallett * Return true if the supplied interface is configured for SPI 96210284Sjmallett * 97210284Sjmallett * @param interface Interface to check 98210284Sjmallett * @return True if interface is SPI 99210284Sjmallett */ 100210284Sjmallettstatic inline int cvmx_spi_is_spi_interface(int interface) 101210284Sjmallett{ 102210284Sjmallett uint64_t gmxState = cvmx_read_csr(CVMX_GMXX_INF_MODE(interface)); 103210284Sjmallett return ((gmxState & 0x2) && (gmxState & 0x1)); 104210284Sjmallett} 105210284Sjmallett 106210284Sjmallett/** 107210284Sjmallett * Initialize and start the SPI interface. 108210284Sjmallett * 109210284Sjmallett * @param interface The identifier of the packet interface to configure and 110210284Sjmallett * use as a SPI interface. 111210284Sjmallett * @param mode The operating mode for the SPI interface. The interface 112210284Sjmallett * can operate as a full duplex (both Tx and Rx data paths 113210284Sjmallett * active) or as a halfplex (either the Tx data path is 114210284Sjmallett * active or the Rx data path is active, but not both). 115210284Sjmallett * @param timeout Timeout to wait for clock synchronization in seconds 116210284Sjmallett * @param num_ports Number of SPI ports to configure 117210284Sjmallett * 118210284Sjmallett * @return Zero on success, negative of failure. 119210284Sjmallett */ 120210284Sjmallettextern int cvmx_spi_start_interface(int interface, cvmx_spi_mode_t mode, int timeout, int num_ports); 121210284Sjmallett 122210284Sjmallett/** 123210284Sjmallett * This routine restarts the SPI interface after it has lost synchronization 124210284Sjmallett * with its corespondant system. 125210284Sjmallett * 126210284Sjmallett * @param interface The identifier of the packet interface to configure and 127210284Sjmallett * use as a SPI interface. 128210284Sjmallett * @param mode The operating mode for the SPI interface. The interface 129210284Sjmallett * can operate as a full duplex (both Tx and Rx data paths 130210284Sjmallett * active) or as a halfplex (either the Tx data path is 131210284Sjmallett * active or the Rx data path is active, but not both). 132210284Sjmallett * @param timeout Timeout to wait for clock synchronization in seconds 133210284Sjmallett * @return Zero on success, negative of failure. 134210284Sjmallett */ 135210284Sjmallettextern int cvmx_spi_restart_interface(int interface, cvmx_spi_mode_t mode, int timeout); 136210284Sjmallett 137210284Sjmallett/** 138210284Sjmallett * Return non-zero if the SPI interface has a SPI4000 attached 139210284Sjmallett * 140210284Sjmallett * @param interface SPI interface the SPI4000 is connected to 141210284Sjmallett * 142210284Sjmallett * @return 143210284Sjmallett */ 144210284Sjmallettextern int cvmx_spi4000_is_present(int interface); 145210284Sjmallett 146210284Sjmallett/** 147210284Sjmallett * Initialize the SPI4000 for use 148210284Sjmallett * 149210284Sjmallett * @param interface SPI interface the SPI4000 is connected to 150210284Sjmallett */ 151210284Sjmallettextern int cvmx_spi4000_initialize(int interface); 152210284Sjmallett 153210284Sjmallett/** 154210284Sjmallett * Poll all the SPI4000 port and check its speed 155210284Sjmallett * 156210284Sjmallett * @param interface Interface the SPI4000 is on 157210284Sjmallett * @param port Port to poll (0-9) 158210284Sjmallett * @return Status of the port. 0=down. All other values the port is up. 159210284Sjmallett */ 160210284Sjmallettextern cvmx_gmxx_rxx_rx_inbnd_t cvmx_spi4000_check_speed(int interface, int port); 161210284Sjmallett 162210284Sjmallett/** 163210284Sjmallett * Get current SPI4 initialization callbacks 164210284Sjmallett * 165210284Sjmallett * @param callbacks Pointer to the callbacks structure.to fill 166210284Sjmallett * 167210284Sjmallett * @return Pointer to cvmx_spi_callbacks_t structure. 168210284Sjmallett */ 169210284Sjmallettextern void cvmx_spi_get_callbacks(cvmx_spi_callbacks_t * callbacks); 170210284Sjmallett 171210284Sjmallett/** 172210284Sjmallett * Set new SPI4 initialization callbacks 173210284Sjmallett * 174210284Sjmallett * @param new_callbacks Pointer to an updated callbacks structure. 175210284Sjmallett */ 176210284Sjmallettextern void cvmx_spi_set_callbacks(cvmx_spi_callbacks_t * new_callbacks); 177210284Sjmallett 178210284Sjmallett/** 179210284Sjmallett * Callback to perform SPI4 reset 180210284Sjmallett * 181210284Sjmallett * @param interface The identifier of the packet interface to configure and 182210284Sjmallett * use as a SPI interface. 183210284Sjmallett * @param mode The operating mode for the SPI interface. The interface 184210284Sjmallett * can operate as a full duplex (both Tx and Rx data paths 185210284Sjmallett * active) or as a halfplex (either the Tx data path is 186210284Sjmallett * active or the Rx data path is active, but not both). 187210284Sjmallett * @return Zero on success, non-zero error code on failure (will cause SPI initialization to abort) 188210284Sjmallett */ 189210284Sjmallettextern int cvmx_spi_reset_cb(int interface, cvmx_spi_mode_t mode); 190210284Sjmallett 191210284Sjmallett/** 192210284Sjmallett * Callback to setup calendar and miscellaneous settings before clock detection 193210284Sjmallett * 194210284Sjmallett * @param interface The identifier of the packet interface to configure and 195210284Sjmallett * use as a SPI interface. 196210284Sjmallett * @param mode The operating mode for the SPI interface. The interface 197210284Sjmallett * can operate as a full duplex (both Tx and Rx data paths 198210284Sjmallett * active) or as a halfplex (either the Tx data path is 199210284Sjmallett * active or the Rx data path is active, but not both). 200210284Sjmallett * @param num_ports Number of ports to configure on SPI 201210284Sjmallett * 202210284Sjmallett * @return Zero on success, non-zero error code on failure (will cause SPI initialization to abort) 203210284Sjmallett */ 204210284Sjmallettextern int cvmx_spi_calendar_setup_cb(int interface, cvmx_spi_mode_t mode, int num_ports); 205210284Sjmallett 206210284Sjmallett/** 207210284Sjmallett * Callback to perform clock detection 208210284Sjmallett * 209210284Sjmallett * @param interface The identifier of the packet interface to configure and 210210284Sjmallett * use as a SPI interface. 211210284Sjmallett * @param mode The operating mode for the SPI interface. The interface 212210284Sjmallett * can operate as a full duplex (both Tx and Rx data paths 213210284Sjmallett * active) or as a halfplex (either the Tx data path is 214210284Sjmallett * active or the Rx data path is active, but not both). 215210284Sjmallett * @param timeout Timeout to wait for clock synchronization in seconds 216210284Sjmallett * @return Zero on success, non-zero error code on failure (will cause SPI initialization to abort) 217210284Sjmallett */ 218210284Sjmallettextern int cvmx_spi_clock_detect_cb(int interface, cvmx_spi_mode_t mode, int timeout); 219210284Sjmallett 220210284Sjmallett/** 221210284Sjmallett * Callback to perform link training 222210284Sjmallett * 223210284Sjmallett * @param interface The identifier of the packet interface to configure and 224210284Sjmallett * use as a SPI interface. 225210284Sjmallett * @param mode The operating mode for the SPI interface. The interface 226210284Sjmallett * can operate as a full duplex (both Tx and Rx data paths 227210284Sjmallett * active) or as a halfplex (either the Tx data path is 228210284Sjmallett * active or the Rx data path is active, but not both). 229210284Sjmallett * @param timeout Timeout to wait for link to be trained (in seconds) 230210284Sjmallett * @return Zero on success, non-zero error code on failure (will cause SPI initialization to abort) 231210284Sjmallett */ 232210284Sjmallettextern int cvmx_spi_training_cb(int interface, cvmx_spi_mode_t mode, int timeout); 233210284Sjmallett 234210284Sjmallett/** 235210284Sjmallett * Callback to perform calendar data synchronization 236210284Sjmallett * 237210284Sjmallett * @param interface The identifier of the packet interface to configure and 238210284Sjmallett * use as a SPI interface. 239210284Sjmallett * @param mode The operating mode for the SPI interface. The interface 240210284Sjmallett * can operate as a full duplex (both Tx and Rx data paths 241210284Sjmallett * active) or as a halfplex (either the Tx data path is 242210284Sjmallett * active or the Rx data path is active, but not both). 243210284Sjmallett * @param timeout Timeout to wait for calendar data in seconds 244210284Sjmallett * @return Zero on success, non-zero error code on failure (will cause SPI initialization to abort) 245210284Sjmallett */ 246210284Sjmallettextern int cvmx_spi_calendar_sync_cb(int interface, cvmx_spi_mode_t mode, int timeout); 247210284Sjmallett 248210284Sjmallett/** 249210284Sjmallett * Callback to handle interface up 250210284Sjmallett * 251210284Sjmallett * @param interface The identifier of the packet interface to configure and 252210284Sjmallett * use as a SPI interface. 253210284Sjmallett * @param mode The operating mode for the SPI interface. The interface 254210284Sjmallett * can operate as a full duplex (both Tx and Rx data paths 255210284Sjmallett * active) or as a halfplex (either the Tx data path is 256210284Sjmallett * active or the Rx data path is active, but not both). 257210284Sjmallett * @return Zero on success, non-zero error code on failure (will cause SPI initialization to abort) 258210284Sjmallett */ 259210284Sjmallettextern int cvmx_spi_interface_up_cb(int interface, cvmx_spi_mode_t mode); 260210284Sjmallett 261210284Sjmallett#ifdef __cplusplus 262210284Sjmallett} 263210284Sjmallett#endif 264210284Sjmallett 265210284Sjmallett#endif /* __CVMX_SPI_H__ */ 266