SAMA5 Ethernet: Add support for PHY interrupts

This commit is contained in:
Gregory Nutt 2013-09-15 12:24:42 -06:00
parent bb73395c1d
commit 6a01d80bb2
5 changed files with 270 additions and 1 deletions

View File

@ -182,6 +182,19 @@ extern "C" {
void sam_boardinitialize(void);
/************************************************************************************
* Name: sam_phyirq
*
* Description:
* This function may be called to register an interrupt handler that will be
* called when an interrupt is received from a PHY.
*
************************************************************************************/
#if defined(CONFIG_NET) && (defined(CONFIG_SAMA5_EMAC) || defined(CONFIG_SAMA5_GMAC))
xcpt_t sam_phyirq(int intf, xcpt_t irqhandler);
#endif
/************************************************************************************
* Name: sam_ledinit, sam_setled, and sam_setleds
*

View File

@ -94,6 +94,14 @@ CSRCS += sam_usb.c
endif
endif
ifeq ($(CONFIG_SAMA5_EMAC),y)
CSRCS += sam_ethernet.c
else
ifeq ($(CONFIG_SAMA5_GMAC),y)
CSRCS += sam_ethernet.c
endif
endif
ifeq ($(CONFIG_NSH_ARCHINIT),y)
CSRCS += sam_nsh.c
endif

View File

@ -44,7 +44,7 @@
#include "sama5d3x-ek.h"
/************************************************************************************
* Definitions
* Pre-processor Definitions
************************************************************************************/
/************************************************************************************
@ -103,6 +103,18 @@ void sam_boardinitialize(void)
}
#endif
/* Configure board resources to support networkingif the 1) networking is enabled,
* 2) the EMAC or GMAC module is enabled, and 2) the weak function
* sam_netinitialize() has been brought into the build.
*/
#ifdef HAVE_NETWORK
if (sam_netinitialize)
{
sam_netinitialize();
}
#endif
#ifdef CONFIG_ARCH_LEDS
/* Configure on-board LEDs if LED support has been selected. */

View File

@ -0,0 +1,170 @@
/************************************************************************************
* configs/sama5d3x-ek/src/sam_ethernet.c
*
* Copyright (C) 2010 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name NuttX nor the names of its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
************************************************************************************/
/************************************************************************************
* Included Files
************************************************************************************/
#include <nuttx/config.h>
#include <nuttx/irq.h>
#include "sam_pio.h"
#include "sam_ethernet.h"
#ifdef HAVE_NETWORK
/************************************************************************************
* Definitions
************************************************************************************/
/************************************************************************************
* Private Functions
************************************************************************************/
/************************************************************************************
* Public Functions
************************************************************************************/
/************************************************************************************
* Name: sam_netinitialize
*
* Description:
* Configure board resources to support networking.
*
************************************************************************************/
void weak_function sam_netinitialize(void)
{
#ifdef CONFIG_SAMA4_EMAC
/* Ethernet 10/100 (EMAC) Port
*
* The main board contains a MICREL PHY device (KSZ8051) operating at 10/100 Mbps.
* The board supports MII and RMII interface modes.
*
* The two independent PHY devices embedded on CM and MB boards are connected to
* independent RJ-45 connectors with built-in magnetic and status LEDs.
*
* At the De-Assertion of Reset:
* PHY ADD[2:0]:001
* CONFIG[2:0]:001,Mode:RMII
* Duplex Mode:Half Duplex
* Isolate Mode:Disable
* Speed Mode:100Mbps
* Nway Auto-Negotiation:Enable
*
* The KSZ8051 PHY interrtup is available on PE30 INT_ETH1
*/
sam_configpio(PIO_INT_ETH1);
#endif
#ifdef CONFIG_SAMA4_GMAC
/* Tri-Speed Ethernet PHY
*
* The SAMA5D3 series-CM board is equipped with a MICREL PHY devices (MICREL
* KSZ9021/31) operating at 10/100/1000 Mbps. The board supports RGMII interface
* mode. The Ethernet interface consists of 4 pairs of low voltage differential
* pair signals designated from GRX± and GTx± plus control signals for link
* activity indicators. These signals can be used to connect to a 10/100/1000
* BaseT RJ45 connector integrated on the main board.
*
* The KSZ9021/31 interrupt is available on PB35 INT_GETH0
*/
sam_configpio(PIO_INT_ETH0);
#endif
}
/************************************************************************************
* Name: sam_phyirq
*
* Description:
* This function may be called to register an interrupt handler that will be
* called when an interrupt is received from a PHY.
*
************************************************************************************/
xcpt_t sam_phyirq(int intf, xcpt_t irqhandler)
{
irqstate_t flags;
xcpt_t *handler;
xcpt_t oldhandler;
int irq;
#ifdef CONFIG_SAMA5_EMAC
if (intf == EMAC_INTF)
{
handler = &g_emac_handler;
irq = IRQ_INT_ETH1;
}
else
#endif
#ifdef CONFIG_SAMA5_GMAC
if (intf == GMAC_INTF)
{
handler = &g_gmac_handler;
irq = IRQ_INT_ETH0;
}
else
#endif
{
ndbg("Unsupported interface: %d\n", intf);
return NULL;
}
/* Disable interrupts until we are done. This guarantees that the
* following operations are atomic.
*/
flags = irqsave();
/* Get the old button interrupt handler and save the new one */
oldhandler = *handler;
*handler = irqhandler;
/* Configure the interrupt */
sam_pioirq(irq);
(void)irq_attach(irq, irqhandler);
sam_pioirqenable(irq);
/* Return the old button handler (so that it can be restored) */
return oldhandler;
}
#endif /* HAVE_NETWORK */

View File

@ -61,6 +61,7 @@
#define HAVE_USBHOST 1
#define HAVE_USBDEV 1
#define HAVE_USBMONITOR 1
#define HAVE_NETWORK 1
/* HSMCI */
/* Can't support MMC/SD if the card interface(s) are not enable */
@ -251,6 +252,12 @@
# undef HAVE_USBMONITOR
#endif
/* Networking */
#if !defined(CONFIG_NET) || (!defined(CONFIG_SAMA5_EMAC) && !defined(CONFIG_SAMA5_GMAC))
# undef HAVE_NETWORK
#endif
/* LEDs *****************************************************************************/
/* There are two LEDs on the SAMA5D3 series-CM board that can be controlled
* by software. A blue LED is controlled via PIO pins. A red LED normally
@ -410,6 +417,53 @@
#define IRQ_USBBC_VBUS_OVERCURRENT \
SAM_IRQ_PD28
/* Ethernet */
#ifdef CONFIG_SAMA4_EMAC
/* ETH1: Ethernet 10/100 (EMAC) Port
*
* The main board contains a MICREL PHY device (KSZ8051) operating at 10/100 Mbps.
* The board supports MII and RMII interface modes.
*
* The two independent PHY devices embedded on CM and MB boards are connected to
* independent RJ-45 connectors with built-in magnetic and status LEDs.
*
* At the De-Assertion of Reset:
* PHY ADD[2:0]:001
* CONFIG[2:0]:001,Mode:RMII
* Duplex Mode:Half Duplex
* Isolate Mode:Disable
* Speed Mode:100Mbps
* Nway Auto-Negotiation:Enable
*
* The KSZ8051 PHY interrtup is available on PE30 INT_ETH1
*/
#define PIO_INT_ETH1 (PIO_INPUT | PIO_CFG_PULLUP | PIO_CFG_DEGLITCH | \
PIO_INT_BOTHEDGES | PIO_PORT_PIOE | PIO_PIN30)
#define IRQ_INT_ETH1 SAM_IRQ_PE30
#endif
#ifdef CONFIG_SAMA4_GMAC
/* ETH0: Tri-Speed Ethernet PHY
*
* The SAMA5D3 series-CM board is equipped with a MICREL PHY devices (MICREL
* KSZ9021/31) operating at 10/100/1000 Mbps. The board supports RGMII interface
* mode. The Ethernet interface consists of 4 pairs of low voltage differential
* pair signals designated from GRX± and GTx± plus control signals for link
* activity indicators. These signals can be used to connect to a 10/100/1000
* BaseT RJ45 connector integrated on the main board.
*
* The KSZ9021/31 interrupt is available on PB35 INT_GETH0
*/
#define PIO_INT_ETH0 (PIO_INPUT | PIO_CFG_PULLUP | PIO_CFG_DEGLITCH | \
PIO_INT_BOTHEDGES | PIO_PORT_PIOB | PIO_PIN25)
#define IRQ_INT_ETH0 SAM_IRQ_PB25
#endif
/* SPI Chip Selects *****************************************************************/
/* Both the Ronetix and Embest versions of the SAMAD3x CPU modules include an
* Atmel AT25DF321A, 32-megabit, 2.7-volt SPI serial flash. The SPI
@ -580,6 +634,18 @@ void weak_function sam_usbinitialize(void);
int sam_usbhost_initialize(void);
#endif
/************************************************************************************
* Name: sam_netinitialize
*
* Description:
* Configure board resources to support networking.
*
************************************************************************************/
#ifdef HAVE_NETWORK
void weak_function sam_netinitialize(void);
#endif
/************************************************************************************
* Name: up_ledinit
************************************************************************************/