1 /***********************license start***************
2 * Copyright (c) 2003-2010 Cavium Networks (support@cavium.com). All rights
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are
10 * * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above
14 * copyright notice, this list of conditions and the following
15 * disclaimer in the documentation and/or other materials provided
16 * with the distribution.
18 * * Neither the name of Cavium Networks nor the names of
19 * its contributors may be used to endorse or promote products
20 * derived from this software without specific prior written
23 * This Software, including technical data, may be subject to U.S. export control
24 * laws, including the U.S. Export Administration Act and its associated
25 * regulations, and may be subject to export or import regulations in other
28 * TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED "AS IS"
29 * AND WITH ALL FAULTS AND CAVIUM NETWORKS MAKES NO PROMISES, REPRESENTATIONS OR
30 * WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, OR OTHERWISE, WITH RESPECT TO
31 * THE SOFTWARE, INCLUDING ITS CONDITION, ITS CONFORMITY TO ANY REPRESENTATION OR
32 * DESCRIPTION, OR THE EXISTENCE OF ANY LATENT OR PATENT DEFECTS, AND CAVIUM
33 * SPECIFICALLY DISCLAIMS ALL IMPLIED (IF ANY) WARRANTIES OF TITLE,
34 * MERCHANTABILITY, NONINFRINGEMENT, FITNESS FOR A PARTICULAR PURPOSE, LACK OF
35 * VIRUSES, ACCURACY OR COMPLETENESS, QUIET ENJOYMENT, QUIET POSSESSION OR
36 * CORRESPONDENCE TO DESCRIPTION. THE ENTIRE RISK ARISING OUT OF USE OR
37 * PERFORMANCE OF THE SOFTWARE LIES WITH YOU.
38 ***********************license end**************************************/
47 * Functions for SPI initialization, configuration,
50 * <hr>$Revision: 49448 $<hr>
52 #ifdef CVMX_BUILD_FOR_LINUX_KERNEL
53 #include <asm/octeon/cvmx.h>
54 #include <asm/octeon/cvmx-config.h>
55 #ifdef CVMX_ENABLE_PKO_FUNCTIONS
56 #include <asm/octeon/cvmx-spi.h>
57 #include <asm/octeon/cvmx-helper.h>
59 #include <asm/octeon/cvmx-pko-defs.h>
60 #include <asm/octeon/cvmx-pip-defs.h>
62 #if !defined(__FreeBSD__) || !defined(_KERNEL)
63 #include "executive-config.h"
64 #include "cvmx-config.h"
65 #ifdef CVMX_ENABLE_PKO_FUNCTIONS
69 #include "cvmx-sysinfo.h"
70 #include "cvmx-helper.h"
75 #include "cvmx-sysinfo.h"
76 #include "cvmx-helper.h"
80 #ifdef CVMX_ENABLE_PKO_FUNCTIONS
82 /* CVMX_HELPER_SPI_TIMEOUT is used to determine how long the SPI initialization
83 routines wait for SPI training. You can override the value using
84 executive-config.h if necessary */
85 #ifndef CVMX_HELPER_SPI_TIMEOUT
86 #define CVMX_HELPER_SPI_TIMEOUT 10
92 * Probe a SPI interface and determine the number of ports
93 * connected to it. The SPI interface should still be down after
96 * @param interface Interface to probe
98 * @return Number of ports on the interface. Zero to disable.
100 int __cvmx_helper_spi_probe(int interface)
104 if ((cvmx_sysinfo_get()->board_type != CVMX_BOARD_TYPE_SIM) &&
105 cvmx_spi4000_is_present(interface))
109 #if defined(OCTEON_VENDOR_LANNER)
110 else if (cvmx_sysinfo_get()->board_type == CVMX_BOARD_TYPE_CUST_LANNER_MR955)
112 cvmx_pko_reg_crc_enable_t enable;
113 if (interface == 1) {
116 /* XXX This is not entirely true. */
119 enable.u64 = cvmx_read_csr(CVMX_PKO_REG_CRC_ENABLE);
120 enable.s.enable &= 0xffff << (16 - (interface*16));
121 cvmx_write_csr(CVMX_PKO_REG_CRC_ENABLE, enable.u64);
126 cvmx_pko_reg_crc_enable_t enable;
128 /* Unlike the SPI4000, most SPI devices don't automatically
129 put on the L2 CRC. For everything except for the SPI4000
130 have PKO append the L2 CRC to the packet */
131 enable.u64 = cvmx_read_csr(CVMX_PKO_REG_CRC_ENABLE);
132 enable.s.enable |= 0xffff << (interface*16);
133 cvmx_write_csr(CVMX_PKO_REG_CRC_ENABLE, enable.u64);
135 __cvmx_helper_setup_gmx(interface, num_ports);
142 * Bringup and enable a SPI interface. After this call packet I/O
143 * should be fully functional. This is called with IPD enabled but
146 * @param interface Interface to bring up
148 * @return Zero on success, negative on failure
150 int __cvmx_helper_spi_enable(int interface)
152 /* Normally the ethernet L2 CRC is checked and stripped in the GMX block.
153 When you are using SPI, this isn' the case and IPD needs to check
155 int num_ports = cvmx_helper_ports_on_interface(interface);
157 for (ipd_port=interface*16; ipd_port<interface*16+num_ports; ipd_port++)
159 cvmx_pip_prt_cfgx_t port_config;
160 port_config.u64 = cvmx_read_csr(CVMX_PIP_PRT_CFGX(ipd_port));
161 port_config.s.crc_en = 1;
162 cvmx_write_csr(CVMX_PIP_PRT_CFGX(ipd_port), port_config.u64);
165 if (cvmx_sysinfo_get()->board_type != CVMX_BOARD_TYPE_SIM)
167 cvmx_spi_start_interface(interface, CVMX_SPI_MODE_DUPLEX, CVMX_HELPER_SPI_TIMEOUT, num_ports);
168 if (cvmx_spi4000_is_present(interface))
169 cvmx_spi4000_initialize(interface);
176 * Return the link state of an IPD/PKO port as returned by
177 * auto negotiation. The result of this function may not match
178 * Octeon's link config if auto negotiation has changed since
179 * the last call to cvmx_helper_link_set().
181 * @param ipd_port IPD/PKO port to query
185 cvmx_helper_link_info_t __cvmx_helper_spi_link_get(int ipd_port)
187 cvmx_helper_link_info_t result;
188 int interface = cvmx_helper_get_interface_num(ipd_port);
189 int index = cvmx_helper_get_interface_index_num(ipd_port);
192 if (cvmx_sysinfo_get()->board_type == CVMX_BOARD_TYPE_SIM)
194 /* The simulator gives you a simulated full duplex link */
195 result.s.link_up = 1;
196 result.s.full_duplex = 1;
197 result.s.speed = 10000;
199 else if (cvmx_spi4000_is_present(interface))
201 cvmx_gmxx_rxx_rx_inbnd_t inband = cvmx_spi4000_check_speed(interface, index);
202 result.s.link_up = inband.s.status;
203 result.s.full_duplex = inband.s.duplex;
204 switch (inband.s.speed)
206 case 0: /* 10 Mbps */
209 case 1: /* 100 Mbps */
210 result.s.speed = 100;
213 result.s.speed = 1000;
215 case 3: /* Illegal */
217 result.s.link_up = 0;
223 /* For generic SPI we can't determine the link, just return some
225 result.s.link_up = 1;
226 result.s.full_duplex = 1;
227 result.s.speed = 10000;
235 * Configure an IPD/PKO port for the specified link state. This
236 * function does not influence auto negotiation at the PHY level.
237 * The passed link state must always match the link state returned
238 * by cvmx_helper_link_get(). It is normally best to use
239 * cvmx_helper_link_autoconf() instead.
241 * @param ipd_port IPD/PKO port to configure
242 * @param link_info The new link state
244 * @return Zero on success, negative on failure
246 int __cvmx_helper_spi_link_set(int ipd_port, cvmx_helper_link_info_t link_info)
248 /* Nothing to do. If we have a SPI4000 then the setup was already performed
249 by cvmx_spi4000_check_speed(). If not then there isn't any link
254 #endif /* CVMX_ENABLE_PKO_FUNCTIONS */