Re: [PATCH V13 4/4] ptp: Added a clock driver for the National Semiconductor PHYTER.

2011-03-28 Thread John Stultz
On Sun, 2011-03-27 at 08:39 +0200, Richard Cochran wrote:
 This patch adds support for the PTP clock found on the DP83640.
 The basic clock operations and one external time stamp have
 been implemented.
 
 Signed-off-by: Richard Cochran richard.coch...@omicron.at

Acked-by: John Stultz john.stu...@linaro.org



___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev


[PATCH V13 4/4] ptp: Added a clock driver for the National Semiconductor PHYTER.

2011-03-27 Thread Richard Cochran
This patch adds support for the PTP clock found on the DP83640.
The basic clock operations and one external time stamp have
been implemented.

Signed-off-by: Richard Cochran richard.coch...@omicron.at
---
 drivers/net/phy/Makefile  |1 +
 drivers/net/phy/dp83640.c | 1015 +
 drivers/net/phy/dp83640_reg.h |  267 +++
 drivers/ptp/Kconfig   |   19 +
 4 files changed, 1302 insertions(+), 0 deletions(-)
 create mode 100644 drivers/net/phy/dp83640.c
 create mode 100644 drivers/net/phy/dp83640_reg.h

diff --git a/drivers/net/phy/Makefile b/drivers/net/phy/Makefile
index 13bebab..2333215 100644
--- a/drivers/net/phy/Makefile
+++ b/drivers/net/phy/Makefile
@@ -19,6 +19,7 @@ obj-$(CONFIG_FIXED_PHY)   += fixed.o
 obj-$(CONFIG_MDIO_BITBANG) += mdio-bitbang.o
 obj-$(CONFIG_MDIO_GPIO)+= mdio-gpio.o
 obj-$(CONFIG_NATIONAL_PHY) += national.o
+obj-$(CONFIG_DP83640_PHY)  += dp83640.o
 obj-$(CONFIG_STE10XP)  += ste10Xp.o
 obj-$(CONFIG_MICREL_PHY)   += micrel.o
 obj-$(CONFIG_MDIO_OCTEON)  += mdio-octeon.o
diff --git a/drivers/net/phy/dp83640.c b/drivers/net/phy/dp83640.c
new file mode 100644
index 000..61d682d
--- /dev/null
+++ b/drivers/net/phy/dp83640.c
@@ -0,0 +1,1015 @@
+/*
+ * Driver for the National Semiconductor DP83640 PHYTER
+ *
+ * Copyright (C) 2010 OMICRON electronics GmbH
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+#include linux/ethtool.h
+#include linux/kernel.h
+#include linux/list.h
+#include linux/mii.h
+#include linux/module.h
+#include linux/net_tstamp.h
+#include linux/netdevice.h
+#include linux/phy.h
+#include linux/ptp_classify.h
+#include linux/ptp_clock_kernel.h
+
+#include dp83640_reg.h
+
+#define DP83640_PHY_ID 0x20005ce1
+#define PAGESEL0x13
+#define LAYER4 0x02
+#define LAYER2 0x01
+#define MAX_RXTS   4
+#define MAX_TXTS   4
+#define N_EXT_TS   1
+#define PSF_PTPVER 2
+#define PSF_EVNT   0x4000
+#define PSF_RX 0x2000
+#define PSF_TX 0x1000
+#define EXT_EVENT  1
+#define EXT_GPIO   1
+#define CAL_EVENT  2
+#define CAL_GPIO   9
+#define CAL_TRIGGER2
+
+/* phyter seems to miss the mark by 16 ns */
+#define ADJTIME_FIX16
+
+#if defined(__BIG_ENDIAN)
+#define ENDIAN_FLAG0
+#elif defined(__LITTLE_ENDIAN)
+#define ENDIAN_FLAGPSF_ENDIAN
+#endif
+
+#define SKB_PTP_TYPE(__skb) (*(unsigned int *)((__skb)-cb))
+
+struct phy_rxts {
+   u16 ns_lo;   /* ns[15:0] */
+   u16 ns_hi;   /* overflow[1:0], ns[29:16] */
+   u16 sec_lo;  /* sec[15:0] */
+   u16 sec_hi;  /* sec[31:16] */
+   u16 seqid;   /* sequenceId[15:0] */
+   u16 msgtype; /* messageType[3:0], hash[11:0] */
+};
+
+struct phy_txts {
+   u16 ns_lo;   /* ns[15:0] */
+   u16 ns_hi;   /* overflow[1:0], ns[29:16] */
+   u16 sec_lo;  /* sec[15:0] */
+   u16 sec_hi;  /* sec[31:16] */
+};
+
+struct rxts {
+   struct list_head list;
+   unsigned long tmo;
+   u64 ns;
+   u16 seqid;
+   u8  msgtype;
+   u16 hash;
+};
+
+struct dp83640_clock;
+
+struct dp83640_private {
+   struct list_head list;
+   struct dp83640_clock *clock;
+   struct phy_device *phydev;
+   struct work_struct ts_work;
+   int hwts_tx_en;
+   int hwts_rx_en;
+   int layer;
+   int version;
+   /* remember state of cfg0 during calibration */
+   int cfg0;
+   /* remember the last event time stamp */
+   struct phy_txts edata;
+   /* list of rx timestamps */
+   struct list_head rxts;
+   struct list_head rxpool;
+   struct rxts rx_pool_data[MAX_RXTS];
+   /* protects above three fields from concurrent access */
+   spinlock_t rx_lock;
+   /* queues of incoming and outgoing packets */
+   struct sk_buff_head rx_queue;
+   struct sk_buff_head tx_queue;
+};
+
+struct dp83640_clock {
+   /* protects extended registers from concurrent access */
+   struct mutex extreg_lock;
+   /* remembers which page was last selected */
+   int page;
+   /* our advertised capabilities */
+   struct ptp_clock_info caps;
+   /* the one phyter from which we shall read */
+   struct dp83640_private *chosen;
+   /* list of the other