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-2018 Cavium, Inc.
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  * Functions for SPI initialization, configuration,
0030  * and monitoring.
0031  */
0032 #include <asm/octeon/octeon.h>
0033 
0034 #include <asm/octeon/cvmx-config.h>
0035 #include <asm/octeon/cvmx-spi.h>
0036 #include <asm/octeon/cvmx-helper.h>
0037 
0038 #include <asm/octeon/cvmx-pip-defs.h>
0039 #include <asm/octeon/cvmx-pko-defs.h>
0040 #include <asm/octeon/cvmx-spxx-defs.h>
0041 #include <asm/octeon/cvmx-stxx-defs.h>
0042 
0043 /*
0044  * CVMX_HELPER_SPI_TIMEOUT is used to determine how long the SPI
0045  * initialization routines wait for SPI training. You can override the
0046  * value using executive-config.h if necessary.
0047  */
0048 #ifndef CVMX_HELPER_SPI_TIMEOUT
0049 #define CVMX_HELPER_SPI_TIMEOUT 10
0050 #endif
0051 
0052 int __cvmx_helper_spi_enumerate(int interface)
0053 {
0054     if ((cvmx_sysinfo_get()->board_type != CVMX_BOARD_TYPE_SIM) &&
0055         cvmx_spi4000_is_present(interface)) {
0056         return 10;
0057     } else {
0058         return 16;
0059     }
0060 }
0061 
0062 /**
0063  * Probe a SPI interface and determine the number of ports
0064  * connected to it. The SPI interface should still be down after
0065  * this call.
0066  *
0067  * @interface: Interface to probe
0068  *
0069  * Returns Number of ports on the interface. Zero to disable.
0070  */
0071 int __cvmx_helper_spi_probe(int interface)
0072 {
0073     int num_ports = 0;
0074 
0075     if ((cvmx_sysinfo_get()->board_type != CVMX_BOARD_TYPE_SIM) &&
0076         cvmx_spi4000_is_present(interface)) {
0077         num_ports = 10;
0078     } else {
0079         union cvmx_pko_reg_crc_enable enable;
0080         num_ports = 16;
0081         /*
0082          * Unlike the SPI4000, most SPI devices don't
0083          * automatically put on the L2 CRC. For everything
0084          * except for the SPI4000 have PKO append the L2 CRC
0085          * to the packet.
0086          */
0087         enable.u64 = cvmx_read_csr(CVMX_PKO_REG_CRC_ENABLE);
0088         enable.s.enable |= 0xffff << (interface * 16);
0089         cvmx_write_csr(CVMX_PKO_REG_CRC_ENABLE, enable.u64);
0090     }
0091     __cvmx_helper_setup_gmx(interface, num_ports);
0092     return num_ports;
0093 }
0094 
0095 /**
0096  * Bringup and enable a SPI interface. After this call packet I/O
0097  * should be fully functional. This is called with IPD enabled but
0098  * PKO disabled.
0099  *
0100  * @interface: Interface to bring up
0101  *
0102  * Returns Zero on success, negative on failure
0103  */
0104 int __cvmx_helper_spi_enable(int interface)
0105 {
0106     /*
0107      * Normally the ethernet L2 CRC is checked and stripped in the
0108      * GMX block.  When you are using SPI, this isn' the case and
0109      * IPD needs to check the L2 CRC.
0110      */
0111     int num_ports = cvmx_helper_ports_on_interface(interface);
0112     int ipd_port;
0113     for (ipd_port = interface * 16; ipd_port < interface * 16 + num_ports;
0114          ipd_port++) {
0115         union cvmx_pip_prt_cfgx port_config;
0116         port_config.u64 = cvmx_read_csr(CVMX_PIP_PRT_CFGX(ipd_port));
0117         port_config.s.crc_en = 1;
0118         cvmx_write_csr(CVMX_PIP_PRT_CFGX(ipd_port), port_config.u64);
0119     }
0120 
0121     if (cvmx_sysinfo_get()->board_type != CVMX_BOARD_TYPE_SIM) {
0122         cvmx_spi_start_interface(interface, CVMX_SPI_MODE_DUPLEX,
0123                      CVMX_HELPER_SPI_TIMEOUT, num_ports);
0124         if (cvmx_spi4000_is_present(interface))
0125             cvmx_spi4000_initialize(interface);
0126     }
0127     __cvmx_interrupt_spxx_int_msk_enable(interface);
0128     __cvmx_interrupt_stxx_int_msk_enable(interface);
0129     __cvmx_interrupt_gmxx_enable(interface);
0130     return 0;
0131 }
0132 
0133 /**
0134  * Return the link state of an IPD/PKO port as returned by
0135  * auto negotiation. The result of this function may not match
0136  * Octeon's link config if auto negotiation has changed since
0137  * the last call to cvmx_helper_link_set().
0138  *
0139  * @ipd_port: IPD/PKO port to query
0140  *
0141  * Returns Link state
0142  */
0143 union cvmx_helper_link_info __cvmx_helper_spi_link_get(int ipd_port)
0144 {
0145     union cvmx_helper_link_info result;
0146     int interface = cvmx_helper_get_interface_num(ipd_port);
0147     int index = cvmx_helper_get_interface_index_num(ipd_port);
0148     result.u64 = 0;
0149 
0150     if (cvmx_sysinfo_get()->board_type == CVMX_BOARD_TYPE_SIM) {
0151         /* The simulator gives you a simulated full duplex link */
0152         result.s.link_up = 1;
0153         result.s.full_duplex = 1;
0154         result.s.speed = 10000;
0155     } else if (cvmx_spi4000_is_present(interface)) {
0156         union cvmx_gmxx_rxx_rx_inbnd inband =
0157             cvmx_spi4000_check_speed(interface, index);
0158         result.s.link_up = inband.s.status;
0159         result.s.full_duplex = inband.s.duplex;
0160         switch (inband.s.speed) {
0161         case 0: /* 10 Mbps */
0162             result.s.speed = 10;
0163             break;
0164         case 1: /* 100 Mbps */
0165             result.s.speed = 100;
0166             break;
0167         case 2: /* 1 Gbps */
0168             result.s.speed = 1000;
0169             break;
0170         case 3: /* Illegal */
0171             result.s.speed = 0;
0172             result.s.link_up = 0;
0173             break;
0174         }
0175     } else {
0176         /* For generic SPI we can't determine the link, just return some
0177            sane results */
0178         result.s.link_up = 1;
0179         result.s.full_duplex = 1;
0180         result.s.speed = 10000;
0181     }
0182     return result;
0183 }
0184 
0185 /**
0186  * Configure an IPD/PKO port for the specified link state. This
0187  * function does not influence auto negotiation at the PHY level.
0188  * The passed link state must always match the link state returned
0189  * by cvmx_helper_link_get().
0190  *
0191  * @ipd_port:  IPD/PKO port to configure
0192  * @link_info: The new link state
0193  *
0194  * Returns Zero on success, negative on failure
0195  */
0196 int __cvmx_helper_spi_link_set(int ipd_port, union cvmx_helper_link_info link_info)
0197 {
0198     /* Nothing to do. If we have a SPI4000 then the setup was already performed
0199        by cvmx_spi4000_check_speed(). If not then there isn't any link
0200        info */
0201     return 0;
0202 }