18c2ecf20Sopenharmony_ci/***********************license start*************** 28c2ecf20Sopenharmony_ci * Author: Cavium Networks 38c2ecf20Sopenharmony_ci * 48c2ecf20Sopenharmony_ci * Contact: support@caviumnetworks.com 58c2ecf20Sopenharmony_ci * This file is part of the OCTEON SDK 68c2ecf20Sopenharmony_ci * 78c2ecf20Sopenharmony_ci * Copyright (c) 2003-2008 Cavium Networks 88c2ecf20Sopenharmony_ci * 98c2ecf20Sopenharmony_ci * This file is free software; you can redistribute it and/or modify 108c2ecf20Sopenharmony_ci * it under the terms of the GNU General Public License, Version 2, as 118c2ecf20Sopenharmony_ci * published by the Free Software Foundation. 128c2ecf20Sopenharmony_ci * 138c2ecf20Sopenharmony_ci * This file is distributed in the hope that it will be useful, but 148c2ecf20Sopenharmony_ci * AS-IS and WITHOUT ANY WARRANTY; without even the implied warranty 158c2ecf20Sopenharmony_ci * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, TITLE, or 168c2ecf20Sopenharmony_ci * NONINFRINGEMENT. See the GNU General Public License for more 178c2ecf20Sopenharmony_ci * details. 188c2ecf20Sopenharmony_ci * 198c2ecf20Sopenharmony_ci * You should have received a copy of the GNU General Public License 208c2ecf20Sopenharmony_ci * along with this file; if not, write to the Free Software 218c2ecf20Sopenharmony_ci * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 228c2ecf20Sopenharmony_ci * or visit http://www.gnu.org/licenses/. 238c2ecf20Sopenharmony_ci * 248c2ecf20Sopenharmony_ci * This file may also be available under a different license from Cavium. 258c2ecf20Sopenharmony_ci * Contact Cavium Networks for more information 268c2ecf20Sopenharmony_ci ***********************license end**************************************/ 278c2ecf20Sopenharmony_ci 288c2ecf20Sopenharmony_ci/* 298c2ecf20Sopenharmony_ci * 308c2ecf20Sopenharmony_ci * This file contains defines for the SPI interface 318c2ecf20Sopenharmony_ci */ 328c2ecf20Sopenharmony_ci#ifndef __CVMX_SPI_H__ 338c2ecf20Sopenharmony_ci#define __CVMX_SPI_H__ 348c2ecf20Sopenharmony_ci 358c2ecf20Sopenharmony_ci#include <asm/octeon/cvmx-gmxx-defs.h> 368c2ecf20Sopenharmony_ci 378c2ecf20Sopenharmony_ci/* CSR typedefs have been moved to cvmx-csr-*.h */ 388c2ecf20Sopenharmony_ci 398c2ecf20Sopenharmony_citypedef enum { 408c2ecf20Sopenharmony_ci CVMX_SPI_MODE_UNKNOWN = 0, 418c2ecf20Sopenharmony_ci CVMX_SPI_MODE_TX_HALFPLEX = 1, 428c2ecf20Sopenharmony_ci CVMX_SPI_MODE_RX_HALFPLEX = 2, 438c2ecf20Sopenharmony_ci CVMX_SPI_MODE_DUPLEX = 3 448c2ecf20Sopenharmony_ci} cvmx_spi_mode_t; 458c2ecf20Sopenharmony_ci 468c2ecf20Sopenharmony_ci/** Callbacks structure to customize SPI4 initialization sequence */ 478c2ecf20Sopenharmony_citypedef struct { 488c2ecf20Sopenharmony_ci /** Called to reset SPI4 DLL */ 498c2ecf20Sopenharmony_ci int (*reset_cb) (int interface, cvmx_spi_mode_t mode); 508c2ecf20Sopenharmony_ci 518c2ecf20Sopenharmony_ci /** Called to setup calendar */ 528c2ecf20Sopenharmony_ci int (*calendar_setup_cb) (int interface, cvmx_spi_mode_t mode, 538c2ecf20Sopenharmony_ci int num_ports); 548c2ecf20Sopenharmony_ci 558c2ecf20Sopenharmony_ci /** Called for Tx and Rx clock detection */ 568c2ecf20Sopenharmony_ci int (*clock_detect_cb) (int interface, cvmx_spi_mode_t mode, 578c2ecf20Sopenharmony_ci int timeout); 588c2ecf20Sopenharmony_ci 598c2ecf20Sopenharmony_ci /** Called to perform link training */ 608c2ecf20Sopenharmony_ci int (*training_cb) (int interface, cvmx_spi_mode_t mode, int timeout); 618c2ecf20Sopenharmony_ci 628c2ecf20Sopenharmony_ci /** Called for calendar data synchronization */ 638c2ecf20Sopenharmony_ci int (*calendar_sync_cb) (int interface, cvmx_spi_mode_t mode, 648c2ecf20Sopenharmony_ci int timeout); 658c2ecf20Sopenharmony_ci 668c2ecf20Sopenharmony_ci /** Called when interface is up */ 678c2ecf20Sopenharmony_ci int (*interface_up_cb) (int interface, cvmx_spi_mode_t mode); 688c2ecf20Sopenharmony_ci 698c2ecf20Sopenharmony_ci} cvmx_spi_callbacks_t; 708c2ecf20Sopenharmony_ci 718c2ecf20Sopenharmony_ci/** 728c2ecf20Sopenharmony_ci * Return true if the supplied interface is configured for SPI 738c2ecf20Sopenharmony_ci * 748c2ecf20Sopenharmony_ci * @interface: Interface to check 758c2ecf20Sopenharmony_ci * Returns True if interface is SPI 768c2ecf20Sopenharmony_ci */ 778c2ecf20Sopenharmony_cistatic inline int cvmx_spi_is_spi_interface(int interface) 788c2ecf20Sopenharmony_ci{ 798c2ecf20Sopenharmony_ci uint64_t gmxState = cvmx_read_csr(CVMX_GMXX_INF_MODE(interface)); 808c2ecf20Sopenharmony_ci return (gmxState & 0x2) && (gmxState & 0x1); 818c2ecf20Sopenharmony_ci} 828c2ecf20Sopenharmony_ci 838c2ecf20Sopenharmony_ci/** 848c2ecf20Sopenharmony_ci * Initialize and start the SPI interface. 858c2ecf20Sopenharmony_ci * 868c2ecf20Sopenharmony_ci * @interface: The identifier of the packet interface to configure and 878c2ecf20Sopenharmony_ci * use as a SPI interface. 888c2ecf20Sopenharmony_ci * @mode: The operating mode for the SPI interface. The interface 898c2ecf20Sopenharmony_ci * can operate as a full duplex (both Tx and Rx data paths 908c2ecf20Sopenharmony_ci * active) or as a halfplex (either the Tx data path is 918c2ecf20Sopenharmony_ci * active or the Rx data path is active, but not both). 928c2ecf20Sopenharmony_ci * @timeout: Timeout to wait for clock synchronization in seconds 938c2ecf20Sopenharmony_ci * @num_ports: Number of SPI ports to configure 948c2ecf20Sopenharmony_ci * 958c2ecf20Sopenharmony_ci * Returns Zero on success, negative of failure. 968c2ecf20Sopenharmony_ci */ 978c2ecf20Sopenharmony_ciextern int cvmx_spi_start_interface(int interface, cvmx_spi_mode_t mode, 988c2ecf20Sopenharmony_ci int timeout, int num_ports); 998c2ecf20Sopenharmony_ci 1008c2ecf20Sopenharmony_ci/** 1018c2ecf20Sopenharmony_ci * This routine restarts the SPI interface after it has lost synchronization 1028c2ecf20Sopenharmony_ci * with its corespondant system. 1038c2ecf20Sopenharmony_ci * 1048c2ecf20Sopenharmony_ci * @interface: The identifier of the packet interface to configure and 1058c2ecf20Sopenharmony_ci * use as a SPI interface. 1068c2ecf20Sopenharmony_ci * @mode: The operating mode for the SPI interface. The interface 1078c2ecf20Sopenharmony_ci * can operate as a full duplex (both Tx and Rx data paths 1088c2ecf20Sopenharmony_ci * active) or as a halfplex (either the Tx data path is 1098c2ecf20Sopenharmony_ci * active or the Rx data path is active, but not both). 1108c2ecf20Sopenharmony_ci * @timeout: Timeout to wait for clock synchronization in seconds 1118c2ecf20Sopenharmony_ci * Returns Zero on success, negative of failure. 1128c2ecf20Sopenharmony_ci */ 1138c2ecf20Sopenharmony_ciextern int cvmx_spi_restart_interface(int interface, cvmx_spi_mode_t mode, 1148c2ecf20Sopenharmony_ci int timeout); 1158c2ecf20Sopenharmony_ci 1168c2ecf20Sopenharmony_ci/** 1178c2ecf20Sopenharmony_ci * Return non-zero if the SPI interface has a SPI4000 attached 1188c2ecf20Sopenharmony_ci * 1198c2ecf20Sopenharmony_ci * @interface: SPI interface the SPI4000 is connected to 1208c2ecf20Sopenharmony_ci * 1218c2ecf20Sopenharmony_ci * Returns 1228c2ecf20Sopenharmony_ci */ 1238c2ecf20Sopenharmony_cistatic inline int cvmx_spi4000_is_present(int interface) 1248c2ecf20Sopenharmony_ci{ 1258c2ecf20Sopenharmony_ci return 0; 1268c2ecf20Sopenharmony_ci} 1278c2ecf20Sopenharmony_ci 1288c2ecf20Sopenharmony_ci/** 1298c2ecf20Sopenharmony_ci * Initialize the SPI4000 for use 1308c2ecf20Sopenharmony_ci * 1318c2ecf20Sopenharmony_ci * @interface: SPI interface the SPI4000 is connected to 1328c2ecf20Sopenharmony_ci */ 1338c2ecf20Sopenharmony_cistatic inline int cvmx_spi4000_initialize(int interface) 1348c2ecf20Sopenharmony_ci{ 1358c2ecf20Sopenharmony_ci return 0; 1368c2ecf20Sopenharmony_ci} 1378c2ecf20Sopenharmony_ci 1388c2ecf20Sopenharmony_ci/** 1398c2ecf20Sopenharmony_ci * Poll all the SPI4000 port and check its speed 1408c2ecf20Sopenharmony_ci * 1418c2ecf20Sopenharmony_ci * @interface: Interface the SPI4000 is on 1428c2ecf20Sopenharmony_ci * @port: Port to poll (0-9) 1438c2ecf20Sopenharmony_ci * Returns Status of the port. 0=down. All other values the port is up. 1448c2ecf20Sopenharmony_ci */ 1458c2ecf20Sopenharmony_cistatic inline union cvmx_gmxx_rxx_rx_inbnd cvmx_spi4000_check_speed( 1468c2ecf20Sopenharmony_ci int interface, 1478c2ecf20Sopenharmony_ci int port) 1488c2ecf20Sopenharmony_ci{ 1498c2ecf20Sopenharmony_ci union cvmx_gmxx_rxx_rx_inbnd r; 1508c2ecf20Sopenharmony_ci r.u64 = 0; 1518c2ecf20Sopenharmony_ci return r; 1528c2ecf20Sopenharmony_ci} 1538c2ecf20Sopenharmony_ci 1548c2ecf20Sopenharmony_ci/** 1558c2ecf20Sopenharmony_ci * Get current SPI4 initialization callbacks 1568c2ecf20Sopenharmony_ci * 1578c2ecf20Sopenharmony_ci * @callbacks: Pointer to the callbacks structure.to fill 1588c2ecf20Sopenharmony_ci * 1598c2ecf20Sopenharmony_ci * Returns Pointer to cvmx_spi_callbacks_t structure. 1608c2ecf20Sopenharmony_ci */ 1618c2ecf20Sopenharmony_ciextern void cvmx_spi_get_callbacks(cvmx_spi_callbacks_t *callbacks); 1628c2ecf20Sopenharmony_ci 1638c2ecf20Sopenharmony_ci/** 1648c2ecf20Sopenharmony_ci * Set new SPI4 initialization callbacks 1658c2ecf20Sopenharmony_ci * 1668c2ecf20Sopenharmony_ci * @new_callbacks: Pointer to an updated callbacks structure. 1678c2ecf20Sopenharmony_ci */ 1688c2ecf20Sopenharmony_ciextern void cvmx_spi_set_callbacks(cvmx_spi_callbacks_t *new_callbacks); 1698c2ecf20Sopenharmony_ci 1708c2ecf20Sopenharmony_ci/** 1718c2ecf20Sopenharmony_ci * Callback to perform SPI4 reset 1728c2ecf20Sopenharmony_ci * 1738c2ecf20Sopenharmony_ci * @interface: The identifier of the packet interface to configure and 1748c2ecf20Sopenharmony_ci * use as a SPI interface. 1758c2ecf20Sopenharmony_ci * @mode: The operating mode for the SPI interface. The interface 1768c2ecf20Sopenharmony_ci * can operate as a full duplex (both Tx and Rx data paths 1778c2ecf20Sopenharmony_ci * active) or as a halfplex (either the Tx data path is 1788c2ecf20Sopenharmony_ci * active or the Rx data path is active, but not both). 1798c2ecf20Sopenharmony_ci * 1808c2ecf20Sopenharmony_ci * Returns Zero on success, non-zero error code on failure (will cause 1818c2ecf20Sopenharmony_ci * SPI initialization to abort) 1828c2ecf20Sopenharmony_ci */ 1838c2ecf20Sopenharmony_ciextern int cvmx_spi_reset_cb(int interface, cvmx_spi_mode_t mode); 1848c2ecf20Sopenharmony_ci 1858c2ecf20Sopenharmony_ci/** 1868c2ecf20Sopenharmony_ci * Callback to setup calendar and miscellaneous settings before clock 1878c2ecf20Sopenharmony_ci * detection 1888c2ecf20Sopenharmony_ci * 1898c2ecf20Sopenharmony_ci * @interface: The identifier of the packet interface to configure and 1908c2ecf20Sopenharmony_ci * use as a SPI interface. 1918c2ecf20Sopenharmony_ci * @mode: The operating mode for the SPI interface. The interface 1928c2ecf20Sopenharmony_ci * can operate as a full duplex (both Tx and Rx data paths 1938c2ecf20Sopenharmony_ci * active) or as a halfplex (either the Tx data path is 1948c2ecf20Sopenharmony_ci * active or the Rx data path is active, but not both). 1958c2ecf20Sopenharmony_ci * @num_ports: Number of ports to configure on SPI 1968c2ecf20Sopenharmony_ci * 1978c2ecf20Sopenharmony_ci * Returns Zero on success, non-zero error code on failure (will cause 1988c2ecf20Sopenharmony_ci * SPI initialization to abort) 1998c2ecf20Sopenharmony_ci */ 2008c2ecf20Sopenharmony_ciextern int cvmx_spi_calendar_setup_cb(int interface, cvmx_spi_mode_t mode, 2018c2ecf20Sopenharmony_ci int num_ports); 2028c2ecf20Sopenharmony_ci 2038c2ecf20Sopenharmony_ci/** 2048c2ecf20Sopenharmony_ci * Callback to perform clock detection 2058c2ecf20Sopenharmony_ci * 2068c2ecf20Sopenharmony_ci * @interface: The identifier of the packet interface to configure and 2078c2ecf20Sopenharmony_ci * use as a SPI interface. 2088c2ecf20Sopenharmony_ci * @mode: The operating mode for the SPI interface. The interface 2098c2ecf20Sopenharmony_ci * can operate as a full duplex (both Tx and Rx data paths 2108c2ecf20Sopenharmony_ci * active) or as a halfplex (either the Tx data path is 2118c2ecf20Sopenharmony_ci * active or the Rx data path is active, but not both). 2128c2ecf20Sopenharmony_ci * @timeout: Timeout to wait for clock synchronization in seconds 2138c2ecf20Sopenharmony_ci * 2148c2ecf20Sopenharmony_ci * Returns Zero on success, non-zero error code on failure (will cause 2158c2ecf20Sopenharmony_ci * SPI initialization to abort) 2168c2ecf20Sopenharmony_ci */ 2178c2ecf20Sopenharmony_ciextern int cvmx_spi_clock_detect_cb(int interface, cvmx_spi_mode_t mode, 2188c2ecf20Sopenharmony_ci int timeout); 2198c2ecf20Sopenharmony_ci 2208c2ecf20Sopenharmony_ci/** 2218c2ecf20Sopenharmony_ci * Callback to perform link training 2228c2ecf20Sopenharmony_ci * 2238c2ecf20Sopenharmony_ci * @interface: The identifier of the packet interface to configure and 2248c2ecf20Sopenharmony_ci * use as a SPI interface. 2258c2ecf20Sopenharmony_ci * @mode: The operating mode for the SPI interface. The interface 2268c2ecf20Sopenharmony_ci * can operate as a full duplex (both Tx and Rx data paths 2278c2ecf20Sopenharmony_ci * active) or as a halfplex (either the Tx data path is 2288c2ecf20Sopenharmony_ci * active or the Rx data path is active, but not both). 2298c2ecf20Sopenharmony_ci * @timeout: Timeout to wait for link to be trained (in seconds) 2308c2ecf20Sopenharmony_ci * 2318c2ecf20Sopenharmony_ci * Returns Zero on success, non-zero error code on failure (will cause 2328c2ecf20Sopenharmony_ci * SPI initialization to abort) 2338c2ecf20Sopenharmony_ci */ 2348c2ecf20Sopenharmony_ciextern int cvmx_spi_training_cb(int interface, cvmx_spi_mode_t mode, 2358c2ecf20Sopenharmony_ci int timeout); 2368c2ecf20Sopenharmony_ci 2378c2ecf20Sopenharmony_ci/** 2388c2ecf20Sopenharmony_ci * Callback to perform calendar data synchronization 2398c2ecf20Sopenharmony_ci * 2408c2ecf20Sopenharmony_ci * @interface: The identifier of the packet interface to configure and 2418c2ecf20Sopenharmony_ci * use as a SPI interface. 2428c2ecf20Sopenharmony_ci * @mode: The operating mode for the SPI interface. The interface 2438c2ecf20Sopenharmony_ci * can operate as a full duplex (both Tx and Rx data paths 2448c2ecf20Sopenharmony_ci * active) or as a halfplex (either the Tx data path is 2458c2ecf20Sopenharmony_ci * active or the Rx data path is active, but not both). 2468c2ecf20Sopenharmony_ci * @timeout: Timeout to wait for calendar data in seconds 2478c2ecf20Sopenharmony_ci * 2488c2ecf20Sopenharmony_ci * Returns Zero on success, non-zero error code on failure (will cause 2498c2ecf20Sopenharmony_ci * SPI initialization to abort) 2508c2ecf20Sopenharmony_ci */ 2518c2ecf20Sopenharmony_ciextern int cvmx_spi_calendar_sync_cb(int interface, cvmx_spi_mode_t mode, 2528c2ecf20Sopenharmony_ci int timeout); 2538c2ecf20Sopenharmony_ci 2548c2ecf20Sopenharmony_ci/** 2558c2ecf20Sopenharmony_ci * Callback to handle interface up 2568c2ecf20Sopenharmony_ci * 2578c2ecf20Sopenharmony_ci * @interface: The identifier of the packet interface to configure and 2588c2ecf20Sopenharmony_ci * use as a SPI interface. 2598c2ecf20Sopenharmony_ci * @mode: The operating mode for the SPI interface. The interface 2608c2ecf20Sopenharmony_ci * can operate as a full duplex (both Tx and Rx data paths 2618c2ecf20Sopenharmony_ci * active) or as a halfplex (either the Tx data path is 2628c2ecf20Sopenharmony_ci * active or the Rx data path is active, but not both). 2638c2ecf20Sopenharmony_ci * 2648c2ecf20Sopenharmony_ci * Returns Zero on success, non-zero error code on failure (will cause 2658c2ecf20Sopenharmony_ci * SPI initialization to abort) 2668c2ecf20Sopenharmony_ci */ 2678c2ecf20Sopenharmony_ciextern int cvmx_spi_interface_up_cb(int interface, cvmx_spi_mode_t mode); 2688c2ecf20Sopenharmony_ci 2698c2ecf20Sopenharmony_ci#endif /* __CVMX_SPI_H__ */ 270