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

2011-03-26 Thread Richard Cochran
On Wed, Mar 23, 2011 at 02:46:25PM -0700, John Stultz wrote:
 On Mon, 2011-02-28 at 08:58 +0100, Richard Cochran wrote:
  +static int tdr_write(int bc, struct phy_device *dev,
  +const struct timespec *ts, u16 cmd)
  +{
  +   ext_write(bc, dev, PAGE4, PTP_TDR, ts-tv_nsec  0x);/* ns[15:0]  */
  +   ext_write(bc, dev, PAGE4, PTP_TDR, ts-tv_nsec  16);   /* ns[31:16] */
  +   ext_write(bc, dev, PAGE4, PTP_TDR, ts-tv_sec  0x); /* sec[15:0] */
  +   ext_write(bc, dev, PAGE4, PTP_TDR, ts-tv_sec  16);/* sec[31:16]*/
  +
  +   ext_write(bc, dev, PAGE4, PTP_CTL, cmd);
  +
  +   return 0;
  +}
 
 The above needs to hold the extreg_lock, and should be commented as
 such.

Okay, will do.

 And again, the function names are sort of generic, and could use a
 dp83640_ prefix or something.

So, I will rename the IXP functions in the other driver to make them
more unique, but in this case I really prefer to keep the short names
for the sake of readability.

Just about every operation on this PHY requires four 16-bit writes,
where each write can really mean two writes, with the first one to set
a page register for the following write.

Keeping the tabular style (shown above) makes it much more clear what
is going on, IMHO. If the function names become longer, that would
force line breaks and spoil the nice formatting.

Also, these names are not in use anywhere else in the kernel's eight
million LOC.

Thanks,

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


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

2011-03-23 Thread John Stultz
On Mon, 2011-02-28 at 08:58 +0100, 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.

Just locking rule comment nits here.

 +static int tdr_write(int bc, struct phy_device *dev,
 +  const struct timespec *ts, u16 cmd)
 +{
 + ext_write(bc, dev, PAGE4, PTP_TDR, ts-tv_nsec  0x);/* ns[15:0]  */
 + ext_write(bc, dev, PAGE4, PTP_TDR, ts-tv_nsec  16);   /* ns[31:16] */
 + ext_write(bc, dev, PAGE4, PTP_TDR, ts-tv_sec  0x); /* sec[15:0] */
 + ext_write(bc, dev, PAGE4, PTP_TDR, ts-tv_sec  16);/* sec[31:16]*/
 +
 + ext_write(bc, dev, PAGE4, PTP_CTL, cmd);
 +
 + return 0;
 +}

The above needs to hold the extreg_lock, and should be commented as
such.

And again, the function names are sort of generic, and could use a
dp83640_ prefix or something.

thanks
-john


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


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

2011-02-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 | 1012 +
 drivers/net/phy/dp83640_reg.h |  267 +++
 drivers/ptp/Kconfig   |   19 +
 4 files changed, 1299 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..74f751e
--- /dev/null
+++ b/drivers/net/phy/dp83640.c
@@ -0,0 +1,1012 @@
+/*
+ * 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