Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
cvmx-helper-spi.c
Go to the documentation of this file.
1 /***********************license start***************
2  * Author: Cavium Networks
3  *
4  * Contact: [email protected]
5  * This file is part of the OCTEON SDK
6  *
7  * Copyright (c) 2003-2008 Cavium Networks
8  *
9  * This file is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License, Version 2, as
11  * published by the Free Software Foundation.
12  *
13  * This file is distributed in the hope that it will be useful, but
14  * AS-IS and WITHOUT ANY WARRANTY; without even the implied warranty
15  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, TITLE, or
16  * NONINFRINGEMENT. See the GNU General Public License for more
17  * details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this file; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22  * or visit http://www.gnu.org/licenses/.
23  *
24  * This file may also be available under a different license from Cavium.
25  * Contact Cavium Networks for more information
26  ***********************license end**************************************/
27 
31 
32 /*
33  * Functions for SPI initialization, configuration,
34  * and monitoring.
35  */
36 #include <asm/octeon/octeon.h>
37 
38 #include <asm/octeon/cvmx-config.h>
39 #include <asm/octeon/cvmx-spi.h>
40 #include <asm/octeon/cvmx-helper.h>
41 
44 
45 /*
46  * CVMX_HELPER_SPI_TIMEOUT is used to determine how long the SPI
47  * initialization routines wait for SPI training. You can override the
48  * value using executive-config.h if necessary.
49  */
50 #ifndef CVMX_HELPER_SPI_TIMEOUT
51 #define CVMX_HELPER_SPI_TIMEOUT 10
52 #endif
53 
55 {
57  cvmx_spi4000_is_present(interface)) {
58  return 10;
59  } else {
60  return 16;
61  }
62 }
63 
74 {
75  int num_ports = 0;
76 
78  cvmx_spi4000_is_present(interface)) {
79  num_ports = 10;
80  } else {
81  union cvmx_pko_reg_crc_enable enable;
82  num_ports = 16;
83  /*
84  * Unlike the SPI4000, most SPI devices don't
85  * automatically put on the L2 CRC. For everything
86  * except for the SPI4000 have PKO append the L2 CRC
87  * to the packet.
88  */
89  enable.u64 = cvmx_read_csr(CVMX_PKO_REG_CRC_ENABLE);
90  enable.s.enable |= 0xffff << (interface * 16);
91  cvmx_write_csr(CVMX_PKO_REG_CRC_ENABLE, enable.u64);
92  }
93  __cvmx_helper_setup_gmx(interface, num_ports);
94  return num_ports;
95 }
96 
107 {
108  /*
109  * Normally the ethernet L2 CRC is checked and stripped in the
110  * GMX block. When you are using SPI, this isn' the case and
111  * IPD needs to check the L2 CRC.
112  */
113  int num_ports = cvmx_helper_ports_on_interface(interface);
114  int ipd_port;
115  for (ipd_port = interface * 16; ipd_port < interface * 16 + num_ports;
116  ipd_port++) {
117  union cvmx_pip_prt_cfgx port_config;
118  port_config.u64 = cvmx_read_csr(CVMX_PIP_PRT_CFGX(ipd_port));
119  port_config.s.crc_en = 1;
120  cvmx_write_csr(CVMX_PIP_PRT_CFGX(ipd_port), port_config.u64);
121  }
122 
125  CVMX_HELPER_SPI_TIMEOUT, num_ports);
126  if (cvmx_spi4000_is_present(interface))
127  cvmx_spi4000_initialize(interface);
128  }
131  __cvmx_interrupt_gmxx_enable(interface);
132  return 0;
133 }
134 
146 {
148  int interface = cvmx_helper_get_interface_num(ipd_port);
150  result.u64 = 0;
151 
153  /* The simulator gives you a simulated full duplex link */
154  result.s.link_up = 1;
155  result.s.full_duplex = 1;
156  result.s.speed = 10000;
157  } else if (cvmx_spi4000_is_present(interface)) {
158  union cvmx_gmxx_rxx_rx_inbnd inband =
159  cvmx_spi4000_check_speed(interface, index);
160  result.s.link_up = inband.s.status;
161  result.s.full_duplex = inband.s.duplex;
162  switch (inband.s.speed) {
163  case 0: /* 10 Mbps */
164  result.s.speed = 10;
165  break;
166  case 1: /* 100 Mbps */
167  result.s.speed = 100;
168  break;
169  case 2: /* 1 Gbps */
170  result.s.speed = 1000;
171  break;
172  case 3: /* Illegal */
173  result.s.speed = 0;
174  result.s.link_up = 0;
175  break;
176  }
177  } else {
178  /* For generic SPI we can't determine the link, just return some
179  sane results */
180  result.s.link_up = 1;
181  result.s.full_duplex = 1;
182  result.s.speed = 10000;
183  }
184  return result;
185 }
186 
200 {
201  /* Nothing to do. If we have a SPI4000 then the setup was already performed
202  by cvmx_spi4000_check_speed(). If not then there isn't any link
203  info */
204  return 0;
205 }