Back to home page

OSCL-LXR

 
 

    


0001 /***********************license start***************
0002  * Author: Cavium Networks
0003  *
0004  * Contact: support@caviumnetworks.com
0005  * This file is part of the OCTEON SDK
0006  *
0007  * Copyright (c) 2003-2008 Cavium Networks
0008  *
0009  * This file is free software; you can redistribute it and/or modify
0010  * it under the terms of the GNU General Public License, Version 2, as
0011  * published by the Free Software Foundation.
0012  *
0013  * This file is distributed in the hope that it will be useful, but
0014  * AS-IS and WITHOUT ANY WARRANTY; without even the implied warranty
0015  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, TITLE, or
0016  * NONINFRINGEMENT.  See the GNU General Public License for more
0017  * details.
0018  *
0019  * You should have received a copy of the GNU General Public License
0020  * along with this file; if not, write to the Free Software
0021  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
0022  * or visit http://www.gnu.org/licenses/.
0023  *
0024  * This file may also be available under a different license from Cavium.
0025  * Contact Cavium Networks for more information
0026  ***********************license end**************************************/
0027 
0028 /*
0029  *
0030  * This file contains defines for the SPI interface
0031  */
0032 #ifndef __CVMX_SPI_H__
0033 #define __CVMX_SPI_H__
0034 
0035 #include <asm/octeon/cvmx-gmxx-defs.h>
0036 
0037 /* CSR typedefs have been moved to cvmx-csr-*.h */
0038 
0039 typedef enum {
0040     CVMX_SPI_MODE_UNKNOWN = 0,
0041     CVMX_SPI_MODE_TX_HALFPLEX = 1,
0042     CVMX_SPI_MODE_RX_HALFPLEX = 2,
0043     CVMX_SPI_MODE_DUPLEX = 3
0044 } cvmx_spi_mode_t;
0045 
0046 /** Callbacks structure to customize SPI4 initialization sequence */
0047 typedef struct {
0048     /** Called to reset SPI4 DLL */
0049     int (*reset_cb) (int interface, cvmx_spi_mode_t mode);
0050 
0051     /** Called to setup calendar */
0052     int (*calendar_setup_cb) (int interface, cvmx_spi_mode_t mode,
0053                   int num_ports);
0054 
0055     /** Called for Tx and Rx clock detection */
0056     int (*clock_detect_cb) (int interface, cvmx_spi_mode_t mode,
0057                 int timeout);
0058 
0059     /** Called to perform link training */
0060     int (*training_cb) (int interface, cvmx_spi_mode_t mode, int timeout);
0061 
0062     /** Called for calendar data synchronization */
0063     int (*calendar_sync_cb) (int interface, cvmx_spi_mode_t mode,
0064                  int timeout);
0065 
0066     /** Called when interface is up */
0067     int (*interface_up_cb) (int interface, cvmx_spi_mode_t mode);
0068 
0069 } cvmx_spi_callbacks_t;
0070 
0071 /**
0072  * Return true if the supplied interface is configured for SPI
0073  *
0074  * @interface: Interface to check
0075  * Returns True if interface is SPI
0076  */
0077 static inline int cvmx_spi_is_spi_interface(int interface)
0078 {
0079     uint64_t gmxState = cvmx_read_csr(CVMX_GMXX_INF_MODE(interface));
0080     return (gmxState & 0x2) && (gmxState & 0x1);
0081 }
0082 
0083 /**
0084  * Initialize and start the SPI interface.
0085  *
0086  * @interface: The identifier of the packet interface to configure and
0087  *          use as a SPI interface.
0088  * @mode:      The operating mode for the SPI interface. The interface
0089  *          can operate as a full duplex (both Tx and Rx data paths
0090  *          active) or as a halfplex (either the Tx data path is
0091  *          active or the Rx data path is active, but not both).
0092  * @timeout:   Timeout to wait for clock synchronization in seconds
0093  * @num_ports: Number of SPI ports to configure
0094  *
0095  * Returns Zero on success, negative of failure.
0096  */
0097 extern int cvmx_spi_start_interface(int interface, cvmx_spi_mode_t mode,
0098                     int timeout, int num_ports);
0099 
0100 /**
0101  * This routine restarts the SPI interface after it has lost synchronization
0102  * with its corespondant system.
0103  *
0104  * @interface: The identifier of the packet interface to configure and
0105  *          use as a SPI interface.
0106  * @mode:      The operating mode for the SPI interface. The interface
0107  *          can operate as a full duplex (both Tx and Rx data paths
0108  *          active) or as a halfplex (either the Tx data path is
0109  *          active or the Rx data path is active, but not both).
0110  * @timeout:   Timeout to wait for clock synchronization in seconds
0111  * Returns Zero on success, negative of failure.
0112  */
0113 extern int cvmx_spi_restart_interface(int interface, cvmx_spi_mode_t mode,
0114                       int timeout);
0115 
0116 /**
0117  * Return non-zero if the SPI interface has a SPI4000 attached
0118  *
0119  * @interface: SPI interface the SPI4000 is connected to
0120  *
0121  * Returns
0122  */
0123 static inline int cvmx_spi4000_is_present(int interface)
0124 {
0125     return 0;
0126 }
0127 
0128 /**
0129  * Initialize the SPI4000 for use
0130  *
0131  * @interface: SPI interface the SPI4000 is connected to
0132  */
0133 static inline int cvmx_spi4000_initialize(int interface)
0134 {
0135     return 0;
0136 }
0137 
0138 /**
0139  * Poll all the SPI4000 port and check its speed
0140  *
0141  * @interface: Interface the SPI4000 is on
0142  * @port:      Port to poll (0-9)
0143  * Returns Status of the port. 0=down. All other values the port is up.
0144  */
0145 static inline union cvmx_gmxx_rxx_rx_inbnd cvmx_spi4000_check_speed(
0146     int interface,
0147     int port)
0148 {
0149     union cvmx_gmxx_rxx_rx_inbnd r;
0150     r.u64 = 0;
0151     return r;
0152 }
0153 
0154 /**
0155  * Get current SPI4 initialization callbacks
0156  *
0157  * @callbacks:  Pointer to the callbacks structure.to fill
0158  *
0159  * Returns Pointer to cvmx_spi_callbacks_t structure.
0160  */
0161 extern void cvmx_spi_get_callbacks(cvmx_spi_callbacks_t *callbacks);
0162 
0163 /**
0164  * Set new SPI4 initialization callbacks
0165  *
0166  * @new_callbacks:  Pointer to an updated callbacks structure.
0167  */
0168 extern void cvmx_spi_set_callbacks(cvmx_spi_callbacks_t *new_callbacks);
0169 
0170 /**
0171  * Callback to perform SPI4 reset
0172  *
0173  * @interface: The identifier of the packet interface to configure and
0174  *          use as a SPI interface.
0175  * @mode:      The operating mode for the SPI interface. The interface
0176  *          can operate as a full duplex (both Tx and Rx data paths
0177  *          active) or as a halfplex (either the Tx data path is
0178  *          active or the Rx data path is active, but not both).
0179  *
0180  * Returns Zero on success, non-zero error code on failure (will cause
0181  * SPI initialization to abort)
0182  */
0183 extern int cvmx_spi_reset_cb(int interface, cvmx_spi_mode_t mode);
0184 
0185 /**
0186  * Callback to setup calendar and miscellaneous settings before clock
0187  * detection
0188  *
0189  * @interface: The identifier of the packet interface to configure and
0190  *          use as a SPI interface.
0191  * @mode:      The operating mode for the SPI interface. The interface
0192  *          can operate as a full duplex (both Tx and Rx data paths
0193  *          active) or as a halfplex (either the Tx data path is
0194  *          active or the Rx data path is active, but not both).
0195  * @num_ports: Number of ports to configure on SPI
0196  *
0197  * Returns Zero on success, non-zero error code on failure (will cause
0198  * SPI initialization to abort)
0199  */
0200 extern int cvmx_spi_calendar_setup_cb(int interface, cvmx_spi_mode_t mode,
0201                       int num_ports);
0202 
0203 /**
0204  * Callback to perform clock detection
0205  *
0206  * @interface: The identifier of the packet interface to configure and
0207  *          use as a SPI interface.
0208  * @mode:      The operating mode for the SPI interface. The interface
0209  *          can operate as a full duplex (both Tx and Rx data paths
0210  *          active) or as a halfplex (either the Tx data path is
0211  *          active or the Rx data path is active, but not both).
0212  * @timeout:   Timeout to wait for clock synchronization in seconds
0213  *
0214  * Returns Zero on success, non-zero error code on failure (will cause
0215  * SPI initialization to abort)
0216  */
0217 extern int cvmx_spi_clock_detect_cb(int interface, cvmx_spi_mode_t mode,
0218                     int timeout);
0219 
0220 /**
0221  * Callback to perform link training
0222  *
0223  * @interface: The identifier of the packet interface to configure and
0224  *          use as a SPI interface.
0225  * @mode:      The operating mode for the SPI interface. The interface
0226  *          can operate as a full duplex (both Tx and Rx data paths
0227  *          active) or as a halfplex (either the Tx data path is
0228  *          active or the Rx data path is active, but not both).
0229  * @timeout:   Timeout to wait for link to be trained (in seconds)
0230  *
0231  * Returns Zero on success, non-zero error code on failure (will cause
0232  * SPI initialization to abort)
0233  */
0234 extern int cvmx_spi_training_cb(int interface, cvmx_spi_mode_t mode,
0235                 int timeout);
0236 
0237 /**
0238  * Callback to perform calendar data synchronization
0239  *
0240  * @interface: The identifier of the packet interface to configure and
0241  *          use as a SPI interface.
0242  * @mode:      The operating mode for the SPI interface. The interface
0243  *          can operate as a full duplex (both Tx and Rx data paths
0244  *          active) or as a halfplex (either the Tx data path is
0245  *          active or the Rx data path is active, but not both).
0246  * @timeout:   Timeout to wait for calendar data in seconds
0247  *
0248  * Returns Zero on success, non-zero error code on failure (will cause
0249  * SPI initialization to abort)
0250  */
0251 extern int cvmx_spi_calendar_sync_cb(int interface, cvmx_spi_mode_t mode,
0252                      int timeout);
0253 
0254 /**
0255  * Callback to handle interface up
0256  *
0257  * @interface: The identifier of the packet interface to configure and
0258  *          use as a SPI interface.
0259  * @mode:      The operating mode for the SPI interface. The interface
0260  *          can operate as a full duplex (both Tx and Rx data paths
0261  *          active) or as a halfplex (either the Tx data path is
0262  *          active or the Rx data path is active, but not both).
0263  *
0264  * Returns Zero on success, non-zero error code on failure (will cause
0265  * SPI initialization to abort)
0266  */
0267 extern int cvmx_spi_interface_up_cb(int interface, cvmx_spi_mode_t mode);
0268 
0269 #endif /* __CVMX_SPI_H__ */