162306a36Sopenharmony_ci/***********************license start*************** 262306a36Sopenharmony_ci * Author: Cavium Networks 362306a36Sopenharmony_ci * 462306a36Sopenharmony_ci * Contact: support@caviumnetworks.com 562306a36Sopenharmony_ci * This file is part of the OCTEON SDK 662306a36Sopenharmony_ci * 762306a36Sopenharmony_ci * Copyright (c) 2003-2008 Cavium Networks 862306a36Sopenharmony_ci * 962306a36Sopenharmony_ci * This file is free software; you can redistribute it and/or modify 1062306a36Sopenharmony_ci * it under the terms of the GNU General Public License, Version 2, as 1162306a36Sopenharmony_ci * published by the Free Software Foundation. 1262306a36Sopenharmony_ci * 1362306a36Sopenharmony_ci * This file is distributed in the hope that it will be useful, but 1462306a36Sopenharmony_ci * AS-IS and WITHOUT ANY WARRANTY; without even the implied warranty 1562306a36Sopenharmony_ci * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, TITLE, or 1662306a36Sopenharmony_ci * NONINFRINGEMENT. See the GNU General Public License for more 1762306a36Sopenharmony_ci * details. 1862306a36Sopenharmony_ci * 1962306a36Sopenharmony_ci * You should have received a copy of the GNU General Public License 2062306a36Sopenharmony_ci * along with this file; if not, write to the Free Software 2162306a36Sopenharmony_ci * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 2262306a36Sopenharmony_ci * or visit http://www.gnu.org/licenses/. 2362306a36Sopenharmony_ci * 2462306a36Sopenharmony_ci * This file may also be available under a different license from Cavium. 2562306a36Sopenharmony_ci * Contact Cavium Networks for more information 2662306a36Sopenharmony_ci ***********************license end**************************************/ 2762306a36Sopenharmony_ci 2862306a36Sopenharmony_ci/* 2962306a36Sopenharmony_ci * 3062306a36Sopenharmony_ci * This file contains defines for the SPI interface 3162306a36Sopenharmony_ci */ 3262306a36Sopenharmony_ci#ifndef __CVMX_SPI_H__ 3362306a36Sopenharmony_ci#define __CVMX_SPI_H__ 3462306a36Sopenharmony_ci 3562306a36Sopenharmony_ci#include <asm/octeon/cvmx-gmxx-defs.h> 3662306a36Sopenharmony_ci 3762306a36Sopenharmony_ci/* CSR typedefs have been moved to cvmx-csr-*.h */ 3862306a36Sopenharmony_ci 3962306a36Sopenharmony_citypedef enum { 4062306a36Sopenharmony_ci CVMX_SPI_MODE_UNKNOWN = 0, 4162306a36Sopenharmony_ci CVMX_SPI_MODE_TX_HALFPLEX = 1, 4262306a36Sopenharmony_ci CVMX_SPI_MODE_RX_HALFPLEX = 2, 4362306a36Sopenharmony_ci CVMX_SPI_MODE_DUPLEX = 3 4462306a36Sopenharmony_ci} cvmx_spi_mode_t; 4562306a36Sopenharmony_ci 4662306a36Sopenharmony_ci/** Callbacks structure to customize SPI4 initialization sequence */ 4762306a36Sopenharmony_citypedef struct { 4862306a36Sopenharmony_ci /** Called to reset SPI4 DLL */ 4962306a36Sopenharmony_ci int (*reset_cb) (int interface, cvmx_spi_mode_t mode); 5062306a36Sopenharmony_ci 5162306a36Sopenharmony_ci /** Called to setup calendar */ 5262306a36Sopenharmony_ci int (*calendar_setup_cb) (int interface, cvmx_spi_mode_t mode, 5362306a36Sopenharmony_ci int num_ports); 5462306a36Sopenharmony_ci 5562306a36Sopenharmony_ci /** Called for Tx and Rx clock detection */ 5662306a36Sopenharmony_ci int (*clock_detect_cb) (int interface, cvmx_spi_mode_t mode, 5762306a36Sopenharmony_ci int timeout); 5862306a36Sopenharmony_ci 5962306a36Sopenharmony_ci /** Called to perform link training */ 6062306a36Sopenharmony_ci int (*training_cb) (int interface, cvmx_spi_mode_t mode, int timeout); 6162306a36Sopenharmony_ci 6262306a36Sopenharmony_ci /** Called for calendar data synchronization */ 6362306a36Sopenharmony_ci int (*calendar_sync_cb) (int interface, cvmx_spi_mode_t mode, 6462306a36Sopenharmony_ci int timeout); 6562306a36Sopenharmony_ci 6662306a36Sopenharmony_ci /** Called when interface is up */ 6762306a36Sopenharmony_ci int (*interface_up_cb) (int interface, cvmx_spi_mode_t mode); 6862306a36Sopenharmony_ci 6962306a36Sopenharmony_ci} cvmx_spi_callbacks_t; 7062306a36Sopenharmony_ci 7162306a36Sopenharmony_ci/** 7262306a36Sopenharmony_ci * Return true if the supplied interface is configured for SPI 7362306a36Sopenharmony_ci * 7462306a36Sopenharmony_ci * @interface: Interface to check 7562306a36Sopenharmony_ci * Returns True if interface is SPI 7662306a36Sopenharmony_ci */ 7762306a36Sopenharmony_cistatic inline int cvmx_spi_is_spi_interface(int interface) 7862306a36Sopenharmony_ci{ 7962306a36Sopenharmony_ci uint64_t gmxState = cvmx_read_csr(CVMX_GMXX_INF_MODE(interface)); 8062306a36Sopenharmony_ci return (gmxState & 0x2) && (gmxState & 0x1); 8162306a36Sopenharmony_ci} 8262306a36Sopenharmony_ci 8362306a36Sopenharmony_ci/** 8462306a36Sopenharmony_ci * Initialize and start the SPI interface. 8562306a36Sopenharmony_ci * 8662306a36Sopenharmony_ci * @interface: The identifier of the packet interface to configure and 8762306a36Sopenharmony_ci * use as a SPI interface. 8862306a36Sopenharmony_ci * @mode: The operating mode for the SPI interface. The interface 8962306a36Sopenharmony_ci * can operate as a full duplex (both Tx and Rx data paths 9062306a36Sopenharmony_ci * active) or as a halfplex (either the Tx data path is 9162306a36Sopenharmony_ci * active or the Rx data path is active, but not both). 9262306a36Sopenharmony_ci * @timeout: Timeout to wait for clock synchronization in seconds 9362306a36Sopenharmony_ci * @num_ports: Number of SPI ports to configure 9462306a36Sopenharmony_ci * 9562306a36Sopenharmony_ci * Returns Zero on success, negative of failure. 9662306a36Sopenharmony_ci */ 9762306a36Sopenharmony_ciextern int cvmx_spi_start_interface(int interface, cvmx_spi_mode_t mode, 9862306a36Sopenharmony_ci int timeout, int num_ports); 9962306a36Sopenharmony_ci 10062306a36Sopenharmony_ci/** 10162306a36Sopenharmony_ci * This routine restarts the SPI interface after it has lost synchronization 10262306a36Sopenharmony_ci * with its corespondant system. 10362306a36Sopenharmony_ci * 10462306a36Sopenharmony_ci * @interface: The identifier of the packet interface to configure and 10562306a36Sopenharmony_ci * use as a SPI interface. 10662306a36Sopenharmony_ci * @mode: The operating mode for the SPI interface. The interface 10762306a36Sopenharmony_ci * can operate as a full duplex (both Tx and Rx data paths 10862306a36Sopenharmony_ci * active) or as a halfplex (either the Tx data path is 10962306a36Sopenharmony_ci * active or the Rx data path is active, but not both). 11062306a36Sopenharmony_ci * @timeout: Timeout to wait for clock synchronization in seconds 11162306a36Sopenharmony_ci * Returns Zero on success, negative of failure. 11262306a36Sopenharmony_ci */ 11362306a36Sopenharmony_ciextern int cvmx_spi_restart_interface(int interface, cvmx_spi_mode_t mode, 11462306a36Sopenharmony_ci int timeout); 11562306a36Sopenharmony_ci 11662306a36Sopenharmony_ci/** 11762306a36Sopenharmony_ci * Return non-zero if the SPI interface has a SPI4000 attached 11862306a36Sopenharmony_ci * 11962306a36Sopenharmony_ci * @interface: SPI interface the SPI4000 is connected to 12062306a36Sopenharmony_ci * 12162306a36Sopenharmony_ci * Returns 12262306a36Sopenharmony_ci */ 12362306a36Sopenharmony_cistatic inline int cvmx_spi4000_is_present(int interface) 12462306a36Sopenharmony_ci{ 12562306a36Sopenharmony_ci return 0; 12662306a36Sopenharmony_ci} 12762306a36Sopenharmony_ci 12862306a36Sopenharmony_ci/** 12962306a36Sopenharmony_ci * Initialize the SPI4000 for use 13062306a36Sopenharmony_ci * 13162306a36Sopenharmony_ci * @interface: SPI interface the SPI4000 is connected to 13262306a36Sopenharmony_ci */ 13362306a36Sopenharmony_cistatic inline int cvmx_spi4000_initialize(int interface) 13462306a36Sopenharmony_ci{ 13562306a36Sopenharmony_ci return 0; 13662306a36Sopenharmony_ci} 13762306a36Sopenharmony_ci 13862306a36Sopenharmony_ci/** 13962306a36Sopenharmony_ci * Poll all the SPI4000 port and check its speed 14062306a36Sopenharmony_ci * 14162306a36Sopenharmony_ci * @interface: Interface the SPI4000 is on 14262306a36Sopenharmony_ci * @port: Port to poll (0-9) 14362306a36Sopenharmony_ci * Returns Status of the port. 0=down. All other values the port is up. 14462306a36Sopenharmony_ci */ 14562306a36Sopenharmony_cistatic inline union cvmx_gmxx_rxx_rx_inbnd cvmx_spi4000_check_speed( 14662306a36Sopenharmony_ci int interface, 14762306a36Sopenharmony_ci int port) 14862306a36Sopenharmony_ci{ 14962306a36Sopenharmony_ci union cvmx_gmxx_rxx_rx_inbnd r; 15062306a36Sopenharmony_ci r.u64 = 0; 15162306a36Sopenharmony_ci return r; 15262306a36Sopenharmony_ci} 15362306a36Sopenharmony_ci 15462306a36Sopenharmony_ci/** 15562306a36Sopenharmony_ci * Get current SPI4 initialization callbacks 15662306a36Sopenharmony_ci * 15762306a36Sopenharmony_ci * @callbacks: Pointer to the callbacks structure.to fill 15862306a36Sopenharmony_ci * 15962306a36Sopenharmony_ci * Returns Pointer to cvmx_spi_callbacks_t structure. 16062306a36Sopenharmony_ci */ 16162306a36Sopenharmony_ciextern void cvmx_spi_get_callbacks(cvmx_spi_callbacks_t *callbacks); 16262306a36Sopenharmony_ci 16362306a36Sopenharmony_ci/** 16462306a36Sopenharmony_ci * Set new SPI4 initialization callbacks 16562306a36Sopenharmony_ci * 16662306a36Sopenharmony_ci * @new_callbacks: Pointer to an updated callbacks structure. 16762306a36Sopenharmony_ci */ 16862306a36Sopenharmony_ciextern void cvmx_spi_set_callbacks(cvmx_spi_callbacks_t *new_callbacks); 16962306a36Sopenharmony_ci 17062306a36Sopenharmony_ci/** 17162306a36Sopenharmony_ci * Callback to perform SPI4 reset 17262306a36Sopenharmony_ci * 17362306a36Sopenharmony_ci * @interface: The identifier of the packet interface to configure and 17462306a36Sopenharmony_ci * use as a SPI interface. 17562306a36Sopenharmony_ci * @mode: The operating mode for the SPI interface. The interface 17662306a36Sopenharmony_ci * can operate as a full duplex (both Tx and Rx data paths 17762306a36Sopenharmony_ci * active) or as a halfplex (either the Tx data path is 17862306a36Sopenharmony_ci * active or the Rx data path is active, but not both). 17962306a36Sopenharmony_ci * 18062306a36Sopenharmony_ci * Returns Zero on success, non-zero error code on failure (will cause 18162306a36Sopenharmony_ci * SPI initialization to abort) 18262306a36Sopenharmony_ci */ 18362306a36Sopenharmony_ciextern int cvmx_spi_reset_cb(int interface, cvmx_spi_mode_t mode); 18462306a36Sopenharmony_ci 18562306a36Sopenharmony_ci/** 18662306a36Sopenharmony_ci * Callback to setup calendar and miscellaneous settings before clock 18762306a36Sopenharmony_ci * detection 18862306a36Sopenharmony_ci * 18962306a36Sopenharmony_ci * @interface: The identifier of the packet interface to configure and 19062306a36Sopenharmony_ci * use as a SPI interface. 19162306a36Sopenharmony_ci * @mode: The operating mode for the SPI interface. The interface 19262306a36Sopenharmony_ci * can operate as a full duplex (both Tx and Rx data paths 19362306a36Sopenharmony_ci * active) or as a halfplex (either the Tx data path is 19462306a36Sopenharmony_ci * active or the Rx data path is active, but not both). 19562306a36Sopenharmony_ci * @num_ports: Number of ports to configure on SPI 19662306a36Sopenharmony_ci * 19762306a36Sopenharmony_ci * Returns Zero on success, non-zero error code on failure (will cause 19862306a36Sopenharmony_ci * SPI initialization to abort) 19962306a36Sopenharmony_ci */ 20062306a36Sopenharmony_ciextern int cvmx_spi_calendar_setup_cb(int interface, cvmx_spi_mode_t mode, 20162306a36Sopenharmony_ci int num_ports); 20262306a36Sopenharmony_ci 20362306a36Sopenharmony_ci/** 20462306a36Sopenharmony_ci * Callback to perform clock detection 20562306a36Sopenharmony_ci * 20662306a36Sopenharmony_ci * @interface: The identifier of the packet interface to configure and 20762306a36Sopenharmony_ci * use as a SPI interface. 20862306a36Sopenharmony_ci * @mode: The operating mode for the SPI interface. The interface 20962306a36Sopenharmony_ci * can operate as a full duplex (both Tx and Rx data paths 21062306a36Sopenharmony_ci * active) or as a halfplex (either the Tx data path is 21162306a36Sopenharmony_ci * active or the Rx data path is active, but not both). 21262306a36Sopenharmony_ci * @timeout: Timeout to wait for clock synchronization in seconds 21362306a36Sopenharmony_ci * 21462306a36Sopenharmony_ci * Returns Zero on success, non-zero error code on failure (will cause 21562306a36Sopenharmony_ci * SPI initialization to abort) 21662306a36Sopenharmony_ci */ 21762306a36Sopenharmony_ciextern int cvmx_spi_clock_detect_cb(int interface, cvmx_spi_mode_t mode, 21862306a36Sopenharmony_ci int timeout); 21962306a36Sopenharmony_ci 22062306a36Sopenharmony_ci/** 22162306a36Sopenharmony_ci * Callback to perform link training 22262306a36Sopenharmony_ci * 22362306a36Sopenharmony_ci * @interface: The identifier of the packet interface to configure and 22462306a36Sopenharmony_ci * use as a SPI interface. 22562306a36Sopenharmony_ci * @mode: The operating mode for the SPI interface. The interface 22662306a36Sopenharmony_ci * can operate as a full duplex (both Tx and Rx data paths 22762306a36Sopenharmony_ci * active) or as a halfplex (either the Tx data path is 22862306a36Sopenharmony_ci * active or the Rx data path is active, but not both). 22962306a36Sopenharmony_ci * @timeout: Timeout to wait for link to be trained (in seconds) 23062306a36Sopenharmony_ci * 23162306a36Sopenharmony_ci * Returns Zero on success, non-zero error code on failure (will cause 23262306a36Sopenharmony_ci * SPI initialization to abort) 23362306a36Sopenharmony_ci */ 23462306a36Sopenharmony_ciextern int cvmx_spi_training_cb(int interface, cvmx_spi_mode_t mode, 23562306a36Sopenharmony_ci int timeout); 23662306a36Sopenharmony_ci 23762306a36Sopenharmony_ci/** 23862306a36Sopenharmony_ci * Callback to perform calendar data synchronization 23962306a36Sopenharmony_ci * 24062306a36Sopenharmony_ci * @interface: The identifier of the packet interface to configure and 24162306a36Sopenharmony_ci * use as a SPI interface. 24262306a36Sopenharmony_ci * @mode: The operating mode for the SPI interface. The interface 24362306a36Sopenharmony_ci * can operate as a full duplex (both Tx and Rx data paths 24462306a36Sopenharmony_ci * active) or as a halfplex (either the Tx data path is 24562306a36Sopenharmony_ci * active or the Rx data path is active, but not both). 24662306a36Sopenharmony_ci * @timeout: Timeout to wait for calendar data in seconds 24762306a36Sopenharmony_ci * 24862306a36Sopenharmony_ci * Returns Zero on success, non-zero error code on failure (will cause 24962306a36Sopenharmony_ci * SPI initialization to abort) 25062306a36Sopenharmony_ci */ 25162306a36Sopenharmony_ciextern int cvmx_spi_calendar_sync_cb(int interface, cvmx_spi_mode_t mode, 25262306a36Sopenharmony_ci int timeout); 25362306a36Sopenharmony_ci 25462306a36Sopenharmony_ci/** 25562306a36Sopenharmony_ci * Callback to handle interface up 25662306a36Sopenharmony_ci * 25762306a36Sopenharmony_ci * @interface: The identifier of the packet interface to configure and 25862306a36Sopenharmony_ci * use as a SPI interface. 25962306a36Sopenharmony_ci * @mode: The operating mode for the SPI interface. The interface 26062306a36Sopenharmony_ci * can operate as a full duplex (both Tx and Rx data paths 26162306a36Sopenharmony_ci * active) or as a halfplex (either the Tx data path is 26262306a36Sopenharmony_ci * active or the Rx data path is active, but not both). 26362306a36Sopenharmony_ci * 26462306a36Sopenharmony_ci * Returns Zero on success, non-zero error code on failure (will cause 26562306a36Sopenharmony_ci * SPI initialization to abort) 26662306a36Sopenharmony_ci */ 26762306a36Sopenharmony_ciextern int cvmx_spi_interface_up_cb(int interface, cvmx_spi_mode_t mode); 26862306a36Sopenharmony_ci 26962306a36Sopenharmony_ci#endif /* __CVMX_SPI_H__ */ 270