summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGregory Nutt <gnutt@nuttx.org>2014-08-17 06:54:37 -0600
committerGregory Nutt <gnutt@nuttx.org>2014-08-17 06:54:37 -0600
commit4f007a07bf643602b6f20bfe3223daa1b75b476c (patch)
treec4837441a074941e9f57b7b1c05a92010af4128a
parent18ce73493b4537b3e1e2c2bc13da1100b1e6514a (diff)
downloadpx4-nuttx-4f007a07bf643602b6f20bfe3223daa1b75b476c.tar.gz
px4-nuttx-4f007a07bf643602b6f20bfe3223daa1b75b476c.tar.bz2
px4-nuttx-4f007a07bf643602b6f20bfe3223daa1b75b476c.zip
SAM3/4 Ethernet: Clone ioctl support from the SAMA5
-rw-r--r--nuttx/arch/arm/src/sam34/sam_emac.c92
1 files changed, 91 insertions, 1 deletions
diff --git a/nuttx/arch/arm/src/sam34/sam_emac.c b/nuttx/arch/arm/src/sam34/sam_emac.c
index dc881c605..3e4a9b92d 100644
--- a/nuttx/arch/arm/src/sam34/sam_emac.c
+++ b/nuttx/arch/arm/src/sam34/sam_emac.c
@@ -67,6 +67,7 @@
#include <nuttx/net/mii.h>
#include <nuttx/net/arp.h>
#include <nuttx/net/netdev.h>
+#include <nuttx/net/phy.h>
#include "up_arch.h"
#include "up_internal.h"
@@ -370,6 +371,9 @@ static int sam_txavail(struct net_driver_s *dev);
static int sam_addmac(struct net_driver_s *dev, const uint8_t *mac);
static int sam_rmmac(struct net_driver_s *dev, const uint8_t *mac);
#endif
+#ifdef CONFIG_NETDEV_PHY_IOCTL
+static int sam_ioctl(struct net_driver_s *dev, int cmd, long arg);
+#endif
/* PHY Initialization */
@@ -1760,6 +1764,89 @@ static int sam_rmmac(struct net_driver_s *dev, const uint8_t *mac)
#endif
/****************************************************************************
+ * Function: sam_ioctl
+ *
+ * Description:
+ * Handles driver ioctl calls:
+ *
+ * SIOCMIINOTIFY - Set up to received notifications from PHY interrupting
+ * events.
+ *
+ * SIOCGMIIPHY, SIOCGMIIREG, and SIOCSMIIREG:
+ * Executes the SIOCxMIIxxx command and responds using the request struct
+ * that must be provided as its 2nd parameter.
+ *
+ * When called with SIOCGMIIPHY it will get the PHY address for the device
+ * and write it to the req->phy_id field of the request struct.
+ *
+ * When called with SIOCGMIIREG it will read a register of the PHY that is
+ * specified using the req->reg_no struct field and then write its output
+ * to the req->val_out field.
+ *
+ * When called with SIOCSMIIREG it will write to a register of the PHY that
+ * is specified using the req->reg_no struct field and use req->val_in as
+ * its input.
+ *
+ * Parameters:
+ * dev - Ethernet device structure
+ * cmd - SIOCxMIIxxx command code
+ * arg - Request structure also used to return values
+ *
+ * Returned Value: Negated errno on failure.
+ *
+ * Assumptions:
+ *
+ ****************************************************************************/
+
+#ifdef CONFIG_NETDEV_PHY_IOCTL
+static int sam_ioctl(struct net_driver_s *dev, int cmd, long arg)
+{
+ struct sam_emac_s *priv = (struct sam_emac_s *)dev->d_private;
+ int ret;
+
+ switch (cmd)
+ {
+#ifdef CONFIG_ARCH_PHY_INTERRUPT
+ case SIOCMIINOTIFY: /* Set up for PHY event notifications */
+ {
+ struct mii_iotcl_notify_s *req = (struct mii_iotcl_notify_s *)((uintptr_t)arg);
+ ret = phy_notify_subscribe(dev->d_ifname, req->pid, req->signo, req->arg);
+ }
+ break;
+#endif
+
+ case SIOCGMIIPHY: /* Get MII PHY address */
+ {
+ struct mii_ioctl_data_s *req = (struct mii_ioctl_data_s *)((uintptr_t)arg);
+ req->phy_id = priv->phyaddr;
+ ret = OK;
+ }
+ break;
+
+ case SIOCGMIIREG: /* Get register from MII PHY */
+ {
+ struct mii_ioctl_data_s *req = (struct mii_ioctl_data_s *)((uintptr_t)arg);
+ ret = sam_phyread(priv, req->phy_id, req->reg_num, &req->val_out);
+ }
+ break;
+
+ case SIOCSMIIREG: /* Set register in MII PHY */
+ {
+ struct mii_ioctl_data_s *req = (struct mii_ioctl_data_s *)((uintptr_t)arg);
+ ret = sam_phywrite(priv, req->phy_id, req->reg_num, req->val_in);
+ }
+ break;
+
+ default:
+ ret = -ENOTTY;
+ break;
+ }
+
+ return ret;
+}
+#endif /* CONFIG_NETDEV_PHY_IOCTL */
+
+/****************************************************************************
* Function: sam_phydump
*
* Description:
@@ -2843,9 +2930,12 @@ void up_netinitialize(void)
priv->dev.d_addmac = sam_addmac; /* Add multicast MAC address */
priv->dev.d_rmmac = sam_rmmac; /* Remove multicast MAC address */
#endif
+#ifdef CONFIG_NETDEV_PHY_IOCTL
+ priv->dev.d_ioctl = sam_ioctl; /* Support PHY ioctl() calls */
+#endif
priv->dev.d_private = (void*)&g_emac; /* Used to recover private state from dev */
- /* Create a watchdog for timing polling for and timing of transmisstions */
+ /* Create a watchdog for timing polling for and timing of transmissions */
priv->txpoll = wd_create();
if (!priv->txpoll)