Path: blob/master/arch/mips/cavium-octeon/executive/cvmx-helper-spi.c
26481 views
/***********************license start***************1* Author: Cavium Networks2*3* Contact: [email protected]4* This file is part of the OCTEON SDK5*6* Copyright (C) 2003-2018 Cavium, Inc.7*8* This file is free software; you can redistribute it and/or modify9* it under the terms of the GNU General Public License, Version 2, as10* published by the Free Software Foundation.11*12* This file is distributed in the hope that it will be useful, but13* AS-IS and WITHOUT ANY WARRANTY; without even the implied warranty14* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, TITLE, or15* NONINFRINGEMENT. See the GNU General Public License for more16* details.17*18* You should have received a copy of the GNU General Public License19* along with this file; if not, write to the Free Software20* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA21* or visit http://www.gnu.org/licenses/.22*23* This file may also be available under a different license from Cavium.24* Contact Cavium Networks for more information25***********************license end**************************************/2627/*28* Functions for SPI initialization, configuration,29* and monitoring.30*/31#include <asm/octeon/octeon.h>3233#include <asm/octeon/cvmx-config.h>34#include <asm/octeon/cvmx-spi.h>35#include <asm/octeon/cvmx-helper.h>3637#include <asm/octeon/cvmx-pip-defs.h>38#include <asm/octeon/cvmx-pko-defs.h>39#include <asm/octeon/cvmx-spxx-defs.h>40#include <asm/octeon/cvmx-stxx-defs.h>4142/*43* CVMX_HELPER_SPI_TIMEOUT is used to determine how long the SPI44* initialization routines wait for SPI training. You can override the45* value using executive-config.h if necessary.46*/47#ifndef CVMX_HELPER_SPI_TIMEOUT48#define CVMX_HELPER_SPI_TIMEOUT 1049#endif5051int __cvmx_helper_spi_enumerate(int interface)52{53if ((cvmx_sysinfo_get()->board_type != CVMX_BOARD_TYPE_SIM) &&54cvmx_spi4000_is_present(interface)) {55return 10;56} else {57return 16;58}59}6061/**62* Probe a SPI interface and determine the number of ports63* connected to it. The SPI interface should still be down after64* this call.65*66* @interface: Interface to probe67*68* Returns Number of ports on the interface. Zero to disable.69*/70int __cvmx_helper_spi_probe(int interface)71{72int num_ports = 0;7374if ((cvmx_sysinfo_get()->board_type != CVMX_BOARD_TYPE_SIM) &&75cvmx_spi4000_is_present(interface)) {76num_ports = 10;77} else {78union cvmx_pko_reg_crc_enable enable;79num_ports = 16;80/*81* Unlike the SPI4000, most SPI devices don't82* automatically put on the L2 CRC. For everything83* except for the SPI4000 have PKO append the L2 CRC84* to the packet.85*/86enable.u64 = cvmx_read_csr(CVMX_PKO_REG_CRC_ENABLE);87enable.s.enable |= 0xffff << (interface * 16);88cvmx_write_csr(CVMX_PKO_REG_CRC_ENABLE, enable.u64);89}90__cvmx_helper_setup_gmx(interface, num_ports);91return num_ports;92}9394/**95* Bringup and enable a SPI interface. After this call packet I/O96* should be fully functional. This is called with IPD enabled but97* PKO disabled.98*99* @interface: Interface to bring up100*101* Returns Zero on success, negative on failure102*/103int __cvmx_helper_spi_enable(int interface)104{105/*106* Normally the ethernet L2 CRC is checked and stripped in the107* GMX block. When you are using SPI, this isn' the case and108* IPD needs to check the L2 CRC.109*/110int num_ports = cvmx_helper_ports_on_interface(interface);111int ipd_port;112for (ipd_port = interface * 16; ipd_port < interface * 16 + num_ports;113ipd_port++) {114union cvmx_pip_prt_cfgx port_config;115port_config.u64 = cvmx_read_csr(CVMX_PIP_PRT_CFGX(ipd_port));116port_config.s.crc_en = 1;117cvmx_write_csr(CVMX_PIP_PRT_CFGX(ipd_port), port_config.u64);118}119120if (cvmx_sysinfo_get()->board_type != CVMX_BOARD_TYPE_SIM) {121cvmx_spi_start_interface(interface, CVMX_SPI_MODE_DUPLEX,122CVMX_HELPER_SPI_TIMEOUT, num_ports);123if (cvmx_spi4000_is_present(interface))124cvmx_spi4000_initialize(interface);125}126__cvmx_interrupt_spxx_int_msk_enable(interface);127__cvmx_interrupt_stxx_int_msk_enable(interface);128__cvmx_interrupt_gmxx_enable(interface);129return 0;130}131132/**133* Return the link state of an IPD/PKO port as returned by134* auto negotiation. The result of this function may not match135* Octeon's link config if auto negotiation has changed since136* the last call to cvmx_helper_link_set().137*138* @ipd_port: IPD/PKO port to query139*140* Returns Link state141*/142union cvmx_helper_link_info __cvmx_helper_spi_link_get(int ipd_port)143{144union cvmx_helper_link_info result;145int interface = cvmx_helper_get_interface_num(ipd_port);146int index = cvmx_helper_get_interface_index_num(ipd_port);147result.u64 = 0;148149if (cvmx_sysinfo_get()->board_type == CVMX_BOARD_TYPE_SIM) {150/* The simulator gives you a simulated full duplex link */151result.s.link_up = 1;152result.s.full_duplex = 1;153result.s.speed = 10000;154} else if (cvmx_spi4000_is_present(interface)) {155union cvmx_gmxx_rxx_rx_inbnd inband =156cvmx_spi4000_check_speed(interface, index);157result.s.link_up = inband.s.status;158result.s.full_duplex = inband.s.duplex;159switch (inband.s.speed) {160case 0: /* 10 Mbps */161result.s.speed = 10;162break;163case 1: /* 100 Mbps */164result.s.speed = 100;165break;166case 2: /* 1 Gbps */167result.s.speed = 1000;168break;169case 3: /* Illegal */170result.s.speed = 0;171result.s.link_up = 0;172break;173}174} else {175/* For generic SPI we can't determine the link, just return some176sane results */177result.s.link_up = 1;178result.s.full_duplex = 1;179result.s.speed = 10000;180}181return result;182}183184/**185* Configure an IPD/PKO port for the specified link state. This186* function does not influence auto negotiation at the PHY level.187* The passed link state must always match the link state returned188* by cvmx_helper_link_get().189*190* @ipd_port: IPD/PKO port to configure191* @link_info: The new link state192*193* Returns Zero on success, negative on failure194*/195int __cvmx_helper_spi_link_set(int ipd_port, union cvmx_helper_link_info link_info)196{197/* Nothing to do. If we have a SPI4000 then the setup was already performed198by cvmx_spi4000_check_speed(). If not then there isn't any link199info */200return 0;201}202203204