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