Add ENETC PTP clock driver
Subsystems (9)
Yangbo Lu
maintainerv3 cover Add ENETC PTP clock driver
There is same QorIQ 1588 timer IP block on the new ENETC Ethernet controller with eTSEC/DPAA Ethernet controllers. However it's different endianness (little-endian) and using PCI driver.
To support ENETC PTP driver, ptp_qoriq driver needed to be reworked to make functions global for reusing, to add little- endian support, to add ENETC memory map support, and to add ENETC dependency for ptp_qoriq driver.
In addition, although ENETC PTP driver is a PCI driver, the dts node still could be used. Currently the ls1028a dtsi which is the only platform by now using ENETC is not complete, so there is still dependency for ENETC PTP node upstreaming. This will be done in the near future. The hardware timestamping support for ENETC is done but needs to be reworked with new method in internal git tree, and will be sent out soon.
Yangbo Lu (9):
ptp_qoriq: make structure/function names more consistent
ptp_qoriq: make ptp operations global
ptp_qoriq: convert to use ptp_qoriq_init/free
ptp_qoriq: add little enadian support
dt-binding: ptp_qoriq: add little-endian support
ptp_qoriq: fix register memory map
ptp: add QorIQ PTP support for ENETC
enetc: add PTP clock driver
MAINTAINERS: add enetc_ptp driver into QorIQ PTP list
.../devicetree/bindings/ptp/ptp-qoriq.txt | 3 + MAINTAINERS | 1 + drivers/net/ethernet/freescale/dpaa/dpaa_ethtool.c | 2 +- drivers/net/ethernet/freescale/enetc/Kconfig | 12 + drivers/net/ethernet/freescale/enetc/Makefile | 3 + drivers/net/ethernet/freescale/enetc/enetc_hw.h | 5 +- drivers/net/ethernet/freescale/enetc/enetc_ptp.c | 144 +++++++ drivers/net/ethernet/freescale/gianfar_ethtool.c | 2 +- drivers/ptp/Kconfig | 2 +- drivers/ptp/ptp_qoriq.c | 437 +++++++++++--------- drivers/ptp/ptp_qoriq_debugfs.c | 48 ++-- include/linux/fsl/ptp_qoriq.h | 63 ++- 12 files changed, 466 insertions(+), 256 deletions(-) create mode 100644 drivers/net/ethernet/freescale/enetc/enetc_ptp.c
Yangbo Lu
maintainerPATCH v3 1/9 ptp_qoriq: make structure/function names more consistent
Strings containing "ptp_qoriq" or "qoriq_ptp" which were used for structure/function names were complained by users. Let's just use the unique "ptp_qoriq" to make these names more consistent. This patch is just to unify the names using "ptp_qoriq". It hasn't changed any functions.
---
Changes for v2:
- Fixed build issue in gianfar/dpaa ethtool driver.
Changes for v3:
- None.
--- drivers/net/ethernet/freescale/dpaa/dpaa_ethtool.c | 2 +- drivers/net/ethernet/freescale/gianfar_ethtool.c | 2 +- drivers/ptp/ptp_qoriq.c | 288 ++++++++++---------- drivers/ptp/ptp_qoriq_debugfs.c | 36 ++-- include/linux/fsl/ptp_qoriq.h | 14 +- 5 files changed, 171 insertions(+), 171 deletions(-)
drivers/net/ethernet/freescale/dpaa/dpaa_ethtool.c +1 -1
@@ -501,7 +501,7 @@ static int dpaa_get_ts_info(struct net_device *net_dev,struct device_node *mac_node = dev->of_node;struct device_node *fman_node =NULL , *ptp_node =NULL ;struct platform_device *ptp_dev =NULL ; -struct qoriq_ptp *ptp =NULL ; +struct ptp_qoriq *ptp =NULL ; info->phc_index =-1 ;
drivers/net/ethernet/freescale/gianfar_ethtool.c +1 -1
@@ -1492,7 +1492,7 @@ static int gfar_get_ts_info(struct net_device *dev,struct gfar_private *priv =netdev_priv (dev);struct platform_device *ptp_dev;struct device_node *ptp_node; -struct qoriq_ptp *ptp =NULL ; +struct ptp_qoriq *ptp =NULL ; info->phc_index =-1 ;
drivers/ptp/ptp_qoriq.c +144 -144
596 lines not on this page · raw message
drivers/ptp/ptp_qoriq_debugfs.c +18 -18
@@ -7,8 +7,8 @@static int ptp_qoriq_fiper1_lpbk_get (void *data,u64 *val) { -struct qoriq_ptp *qoriq_ptp = data; -struct qoriq_ptp_registers *regs = &qoriq_ptp->regs; +struct ptp_qoriq *ptp_qoriq = data; +struct ptp_qoriq_registers *regs = &ptp_qoriq->regs;u32 ctrl; ctrl =qoriq_read (®s->ctrl_regs->tmr_ctrl);
@@ -19,8 +19,8 @@ static int ptp_qoriq_fiper1_lpbk_get(void *data, u64 *val)static int ptp_qoriq_fiper1_lpbk_set (void *data,u64 val) { -struct qoriq_ptp *qoriq_ptp = data; -struct qoriq_ptp_registers *regs = &qoriq_ptp->regs; +struct ptp_qoriq *ptp_qoriq = data; +struct ptp_qoriq_registers *regs = &ptp_qoriq->regs;u32 ctrl; ctrl =qoriq_read (®s->ctrl_regs->tmr_ctrl);
@@ -38,8 +38,8 @@ static int ptp_qoriq_fiper1_lpbk_set(void *data, u64 val)static int ptp_qoriq_fiper2_lpbk_get (void *data,u64 *val) { -struct qoriq_ptp *qoriq_ptp = data; -struct qoriq_ptp_registers *regs = &qoriq_ptp->regs; +struct ptp_qoriq *ptp_qoriq = data; +struct ptp_qoriq_registers *regs = &ptp_qoriq->regs;u32 ctrl; ctrl =qoriq_read (®s->ctrl_regs->tmr_ctrl);
@@ -50,8 +50,8 @@ static int ptp_qoriq_fiper2_lpbk_get(void *data, u64 *val)static int ptp_qoriq_fiper2_lpbk_set (void *data,u64 val) { -struct qoriq_ptp *qoriq_ptp = data; -struct qoriq_ptp_registers *regs = &qoriq_ptp->regs; +struct ptp_qoriq *ptp_qoriq = data; +struct ptp_qoriq_registers *regs = &ptp_qoriq->regs;u32 ctrl; ctrl =qoriq_read (®s->ctrl_regs->tmr_ctrl);
@@ -67,35 +67,35 @@ static int ptp_qoriq_fiper2_lpbk_set(void *data, u64 val)DEFINE_DEBUGFS_ATTRIBUTE (ptp_qoriq_fiper2_fops, ptp_qoriq_fiper2_lpbk_get, ptp_qoriq_fiper2_lpbk_set,"%llu\n" ); -void ptp_qoriq_create_debugfs (struct qoriq_ptp *qoriq_ptp) +void ptp_qoriq_create_debugfs (struct ptp_qoriq *ptp_qoriq) {struct dentry *root; - root =debugfs_create_dir (dev_name (qoriq_ptp->dev),NULL ); + root =debugfs_create_dir (dev_name (ptp_qoriq->dev),NULL );if (IS_ERR (root))return ;if (!root) goto err_root; - qoriq_ptp->debugfs_root = root; + ptp_qoriq->debugfs_root = root;if (!debugfs_create_file_unsafe ("fiper1-loopback" ,0600 , root, - qoriq_ptp, &ptp_qoriq_fiper1_fops)) + ptp_qoriq, &ptp_qoriq_fiper1_fops)) goto err_node;if (!debugfs_create_file_unsafe ("fiper2-loopback" ,0600 , root, - qoriq_ptp, &ptp_qoriq_fiper2_fops)) + ptp_qoriq, &ptp_qoriq_fiper2_fops)) goto err_node;return ; err_node:debugfs_remove_recursive (root); - qoriq_ptp->debugfs_root =NULL ; + ptp_qoriq->debugfs_root =NULL ; err_root: -dev_err (qoriq_ptp->dev,"failed to initialize debugfs\n" ); +dev_err (ptp_qoriq->dev,"failed to initialize debugfs\n" ); } -void ptp_qoriq_remove_debugfs (struct qoriq_ptp *qoriq_ptp) +void ptp_qoriq_remove_debugfs (struct ptp_qoriq *ptp_qoriq) { -debugfs_remove_recursive (qoriq_ptp->debugfs_root); - qoriq_ptp->debugfs_root =NULL ; +debugfs_remove_recursive (ptp_qoriq->debugfs_root); + ptp_qoriq->debugfs_root =NULL ; }
include/linux/fsl/ptp_qoriq.h +7 -7
@@ -49,7 +49,7 @@ struct etts_regs {u32 tmr_etts2_l;/* Timestamp of general purpose external trigger */ }; -struct qoriq_ptp_registers { +struct ptp_qoriq_registers {struct ctrl_regs __iomem *ctrl_regs;struct alarm_regs __iomem *alarm_regs;struct fiper_regs __iomem *fiper_regs;
@@ -136,9 +136,9 @@ struct qoriq_ptp_registers {#define DEFAULT_FIPER1_PERIOD 1000000000#define DEFAULT_FIPER2_PERIOD 100000 -struct qoriq_ptp { +struct ptp_qoriq {void __iomem *base; -struct qoriq_ptp_registers regs; +struct ptp_qoriq_registers regs;spinlock_t lock;/* protects regs */ struct ptp_clock *clock;struct ptp_clock_info caps;
@@ -172,12 +172,12 @@ static inline void qoriq_write(unsigned __iomem *addr, u32 val) }#ifdef CONFIG_DEBUG_FS -void ptp_qoriq_create_debugfs (struct qoriq_ptp *qoriq_ptp); -void ptp_qoriq_remove_debugfs (struct qoriq_ptp *qoriq_ptp); +void ptp_qoriq_create_debugfs (struct ptp_qoriq *ptp_qoriq); +void ptp_qoriq_remove_debugfs (struct ptp_qoriq *ptp_qoriq);#else -static inline void ptp_qoriq_create_debugfs (struct qoriq_ptp *qoriq_ptp) +static inline void ptp_qoriq_create_debugfs (struct ptp_qoriq *ptp_qoriq) { } -static inline void ptp_qoriq_remove_debugfs (struct qoriq_ptp *qoriq_ptp) +static inline void ptp_qoriq_remove_debugfs (struct ptp_qoriq *ptp_qoriq) { }#endif
Signature · 1 line
1.7.1
Yangbo Lu
maintainerPATCH v3 2/9 ptp_qoriq: make ptp operations global
In reply to Yangbo LuThis patch is to make functions of ptp operations global, so that ENETC PTP driver which is a PCI driver for same 1588 timer IP block could reuse them.
---
Changes for v2:
- None.
Changes for v3:
- None.
--- drivers/ptp/ptp_qoriq.c | 27 ++++++++++++++++----------- include/linux/fsl/ptp_qoriq.h | 9 +++++++++ 2 files changed, 25 insertions(+), 11 deletions(-)
drivers/ptp/ptp_qoriq.c +16 -11
@@ -22,7 +22,6 @@#include <linux/device.h> #include <linux/hrtimer.h> -#include <linux/interrupt.h> #include <linux/kernel.h> #include <linux/module.h> #include <linux/of.h>
@@ -135,7 +134,7 @@ static int extts_clean_up(struct ptp_qoriq *ptp_qoriq, int index,* Interrupt service routine */ -static irqreturn_t isr (int irq,void *priv) +irqreturn_t ptp_qoriq_isr (int irq,void *priv) {struct ptp_qoriq *ptp_qoriq = priv;struct ptp_qoriq_registers *regs = &ptp_qoriq->regs;
@@ -200,12 +199,13 @@ static irqreturn_t isr(int irq, void *priv) }else return IRQ_NONE ; } +EXPORT_SYMBOL_GPL (ptp_qoriq_isr);/* * PTP clock operations */ -static int ptp_qoriq_adjfine (struct ptp_clock_info *ptp,long scaled_ppm) +int ptp_qoriq_adjfine (struct ptp_clock_info *ptp,long scaled_ppm) {u64 adj, diff;u32 tmr_add;
@@ -233,8 +233,9 @@ static int ptp_qoriq_adjfine(struct ptp_clock_info *ptp, long scaled_ppm)return 0 ; } +EXPORT_SYMBOL_GPL (ptp_qoriq_adjfine); -static int ptp_qoriq_adjtime (struct ptp_clock_info *ptp,s64 delta) +int ptp_qoriq_adjtime (struct ptp_clock_info *ptp,s64 delta) {s64 now;unsigned long flags;
@@ -251,9 +252,9 @@ static int ptp_qoriq_adjtime(struct ptp_clock_info *ptp, s64 delta)return 0 ; } +EXPORT_SYMBOL_GPL (ptp_qoriq_adjtime); -static int ptp_qoriq_gettime (struct ptp_clock_info *ptp, -struct timespec64 *ts) +int ptp_qoriq_gettime (struct ptp_clock_info *ptp,struct timespec64 *ts) {u64 ns;unsigned long flags;
@@ -269,9 +270,10 @@ static int ptp_qoriq_gettime(struct ptp_clock_info *ptp,return 0 ; } +EXPORT_SYMBOL_GPL (ptp_qoriq_gettime); -static int ptp_qoriq_settime (struct ptp_clock_info *ptp, -const struct timespec64 *ts) +int ptp_qoriq_settime (struct ptp_clock_info *ptp, +const struct timespec64 *ts) {u64 ns;unsigned long flags;
@@ -288,9 +290,10 @@ static int ptp_qoriq_settime(struct ptp_clock_info *ptp,return 0 ; } +EXPORT_SYMBOL_GPL (ptp_qoriq_settime); -static int ptp_qoriq_enable (struct ptp_clock_info *ptp, -struct ptp_clock_request *rq,int on) +int ptp_qoriq_enable (struct ptp_clock_info *ptp, +struct ptp_clock_request *rq,int on) { struct ptp_qoriq *ptp_qoriq = container_of(ptp, struct ptp_qoriq, caps);struct ptp_qoriq_registers *regs = &ptp_qoriq->regs;
@@ -336,6 +339,7 @@ static int ptp_qoriq_enable(struct ptp_clock_info *ptp,spin_unlock_irqrestore (&ptp_qoriq->lock, flags);return 0 ; } +EXPORT_SYMBOL_GPL (ptp_qoriq_enable);static const struct ptp_clock_info ptp_qoriq_caps = { .owner =THIS_MODULE ,
@@ -508,7 +512,8 @@ static int ptp_qoriq_probe(struct platform_device *dev)pr_err ("irq not in device tree\n" ); goto no_node; } -if (request_irq (ptp_qoriq->irq, isr,IRQF_SHARED ,DRIVER , ptp_qoriq)) { +if (request_irq (ptp_qoriq->irq, ptp_qoriq_isr,IRQF_SHARED , +DRIVER , ptp_qoriq)) {pr_err ("request_irq failed\n" ); goto no_node; }
include/linux/fsl/ptp_qoriq.h +9 -0
@@ -7,6 +7,7 @@#define __PTP_QORIQ_H__#include <linux/io.h> +#include <linux/interrupt.h> #include <linux/ptp_clock_kernel.h> /*
@@ -171,6 +172,14 @@ static inline void qoriq_write(unsigned __iomem *addr, u32 val)iowrite32be (val, addr); } +irqreturn_t ptp_qoriq_isr (int irq,void *priv); +int ptp_qoriq_adjfine (struct ptp_clock_info *ptp,long scaled_ppm); +int ptp_qoriq_adjtime (struct ptp_clock_info *ptp,s64 delta); +int ptp_qoriq_gettime (struct ptp_clock_info *ptp,struct timespec64 *ts); +int ptp_qoriq_settime (struct ptp_clock_info *ptp, +const struct timespec64 *ts); +int ptp_qoriq_enable (struct ptp_clock_info *ptp, +struct ptp_clock_request *rq,int on);#ifdef CONFIG_DEBUG_FS void ptp_qoriq_create_debugfs (struct ptp_qoriq *ptp_qoriq);void ptp_qoriq_remove_debugfs (struct ptp_qoriq *ptp_qoriq);
Signature · 1 line
1.7.1
Yangbo Lu
maintainerPATCH v3 3/9 ptp_qoriq: convert to use ptp_qoriq_init/free
In reply to Yangbo LuMoved QorIQ PTP clock initialization/free into new functions ptp_qoriq_init()/ptp_qoriq_free(). These functions could also be reused by ENETC PTP drvier which is a PCI driver for same 1588 timer IP block.
---
Changes for v2:
- None.
Changes for v3:
- Added ptp_qoriq_free().
--- drivers/ptp/ptp_qoriq.c | 144 ++++++++++++++++++++++------------------- include/linux/fsl/ptp_qoriq.h | 3 + 2 files changed, 80 insertions(+), 67 deletions(-)
drivers/ptp/ptp_qoriq.c +77 -67
@@ -458,25 +458,17 @@ static int ptp_qoriq_auto_config(struct ptp_qoriq *ptp_qoriq,return 0 ; } -static int ptp_qoriq_probe (struct platform_device *dev) +int ptp_qoriq_init (struct ptp_qoriq *ptp_qoriq,void __iomem *base, +const struct ptp_clock_info caps) { -struct device_node *node = dev->dev.of_node; -struct ptp_qoriq *ptp_qoriq; +struct device_node *node = ptp_qoriq->dev->of_node;struct ptp_qoriq_registers *regs;struct timespec64 now; -int err = -ENOMEM ; -u32 tmr_ctrl;unsigned long flags; -void __iomem *base; - - ptp_qoriq =kzalloc (sizeof (*ptp_qoriq),GFP_KERNEL ); -if (!ptp_qoriq) - goto no_memory; - - err = -EINVAL ; +u32 tmr_ctrl; - ptp_qoriq->dev = &dev->dev; - ptp_qoriq->caps = ptp_qoriq_caps; + ptp_qoriq->base = base; + ptp_qoriq->caps = caps;if (of_property_read_u32 (node,"fsl,cksel" , &ptp_qoriq->cksel)) ptp_qoriq->cksel =DEFAULT_CKSEL ;
@@ -501,44 +493,9 @@ static int ptp_qoriq_probe(struct platform_device *dev)pr_warn ("device tree node missing required elements, try automatic configuration\n" );if (ptp_qoriq_auto_config (ptp_qoriq, node)) - goto no_config; +return -ENODEV ; } - err = -ENODEV ; - - ptp_qoriq->irq =platform_get_irq (dev,0 ); - -if (ptp_qoriq->irq <0 ) { -pr_err ("irq not in device tree\n" ); - goto no_node; - } -if (request_irq (ptp_qoriq->irq, ptp_qoriq_isr,IRQF_SHARED , -DRIVER , ptp_qoriq)) { -pr_err ("request_irq failed\n" ); - goto no_node; - } - - ptp_qoriq->rsrc =platform_get_resource (dev,IORESOURCE_MEM ,0 ); -if (!ptp_qoriq->rsrc) { -pr_err ("no resource\n" ); - goto no_resource; - } -if (request_resource (&iomem_resource, ptp_qoriq->rsrc)) { -pr_err ("resource busy\n" ); - goto no_resource; - } - -spin_lock_init (&ptp_qoriq->lock); - - base =ioremap (ptp_qoriq->rsrc->start, -resource_size (ptp_qoriq->rsrc)); -if (!base) { -pr_err ("ioremap ptp registers failed\n" ); - goto no_ioremap; - } - - ptp_qoriq->base = base; -if (of_device_is_compatible (node,"fsl,fman-ptp-timer" )) { ptp_qoriq->regs.ctrl_regs = base +FMAN_CTRL_REGS_OFFSET ; ptp_qoriq->regs.alarm_regs = base +FMAN_ALARM_REGS_OFFSET ;
@@ -558,6 +515,7 @@ static int ptp_qoriq_probe(struct platform_device *dev) (ptp_qoriq->tclk_period &TCLK_PERIOD_MASK ) <<TCLK_PERIOD_SHIFT | (ptp_qoriq->cksel &CKSEL_MASK ) <<CKSEL_SHIFT ; +spin_lock_init (&ptp_qoriq->lock);spin_lock_irqsave (&ptp_qoriq->lock, flags); regs = &ptp_qoriq->regs;
@@ -571,16 +529,77 @@ static int ptp_qoriq_probe(struct platform_device *dev)spin_unlock_irqrestore (&ptp_qoriq->lock, flags); - ptp_qoriq->clock =ptp_clock_register (&ptp_qoriq->caps, &dev->dev); -if (IS_ERR (ptp_qoriq->clock)) { - err =PTR_ERR (ptp_qoriq->clock); - goto no_clock; - } - ptp_qoriq->phc_index =ptp_clock_index (ptp_qoriq->clock); + ptp_qoriq->clock =ptp_clock_register (&ptp_qoriq->caps, ptp_qoriq->dev); +if (IS_ERR (ptp_qoriq->clock)) +return PTR_ERR (ptp_qoriq->clock); + ptp_qoriq->phc_index =ptp_clock_index (ptp_qoriq->clock);ptp_qoriq_create_debugfs (ptp_qoriq); -platform_set_drvdata (dev, ptp_qoriq); +return 0 ; +} +EXPORT_SYMBOL_GPL (ptp_qoriq_init); + +void ptp_qoriq_free (struct ptp_qoriq *ptp_qoriq) +{ +struct ptp_qoriq_registers *regs = &ptp_qoriq->regs; + +qoriq_write (®s->ctrl_regs->tmr_temask,0 ); +qoriq_write (®s->ctrl_regs->tmr_ctrl,0 ); + +ptp_qoriq_remove_debugfs (ptp_qoriq); +ptp_clock_unregister (ptp_qoriq->clock); +iounmap (ptp_qoriq->base); +free_irq (ptp_qoriq->irq, ptp_qoriq); +} +EXPORT_SYMBOL_GPL (ptp_qoriq_free); + +static int ptp_qoriq_probe (struct platform_device *dev) +{ +struct ptp_qoriq *ptp_qoriq; +int err = -ENOMEM ; +void __iomem *base; + ptp_qoriq =kzalloc (sizeof (*ptp_qoriq),GFP_KERNEL ); +if (!ptp_qoriq) + goto no_memory; + + ptp_qoriq->dev = &dev->dev; + + err = -ENODEV ; + + ptp_qoriq->irq =platform_get_irq (dev,0 ); +if (ptp_qoriq->irq <0 ) { +pr_err ("irq not in device tree\n" ); + goto no_node; + } +if (request_irq (ptp_qoriq->irq, ptp_qoriq_isr,IRQF_SHARED , +DRIVER , ptp_qoriq)) { +pr_err ("request_irq failed\n" ); + goto no_node; + } + + ptp_qoriq->rsrc =platform_get_resource (dev,IORESOURCE_MEM ,0 ); +if (!ptp_qoriq->rsrc) { +pr_err ("no resource\n" ); + goto no_resource; + } +if (request_resource (&iomem_resource, ptp_qoriq->rsrc)) { +pr_err ("resource busy\n" ); + goto no_resource; + } + + base =ioremap (ptp_qoriq->rsrc->start, +resource_size (ptp_qoriq->rsrc)); +if (!base) { +pr_err ("ioremap ptp registers failed\n" ); + goto no_ioremap; + } + + err =ptp_qoriq_init (ptp_qoriq, base, ptp_qoriq_caps); +if (err) + goto no_clock; + +platform_set_drvdata (dev, ptp_qoriq);return 0 ; no_clock:
@@ -589,7 +608,6 @@ static int ptp_qoriq_probe(struct platform_device *dev)release_resource (ptp_qoriq->rsrc); no_resource:free_irq (ptp_qoriq->irq, ptp_qoriq); -no_config: no_node:kfree (ptp_qoriq); no_memory:
@@ -599,18 +617,10 @@ static int ptp_qoriq_probe(struct platform_device *dev)static int ptp_qoriq_remove (struct platform_device *dev) {struct ptp_qoriq *ptp_qoriq =platform_get_drvdata (dev); -struct ptp_qoriq_registers *regs = &ptp_qoriq->regs; -qoriq_write (®s->ctrl_regs->tmr_temask,0 ); -qoriq_write (®s->ctrl_regs->tmr_ctrl,0 ); - -ptp_qoriq_remove_debugfs (ptp_qoriq); -ptp_clock_unregister (ptp_qoriq->clock); -iounmap (ptp_qoriq->base); +ptp_qoriq_free (ptp_qoriq);release_resource (ptp_qoriq->rsrc); -free_irq (ptp_qoriq->irq, ptp_qoriq);kfree (ptp_qoriq); -return 0 ; }
include/linux/fsl/ptp_qoriq.h +3 -0
@@ -173,6 +173,9 @@ static inline void qoriq_write(unsigned __iomem *addr, u32 val) }irqreturn_t ptp_qoriq_isr (int irq,void *priv); +int ptp_qoriq_init (struct ptp_qoriq *ptp_qoriq,void __iomem *base, +const struct ptp_clock_info caps); +void ptp_qoriq_free (struct ptp_qoriq *ptp_qoriq);int ptp_qoriq_adjfine (struct ptp_clock_info *ptp,long scaled_ppm);int ptp_qoriq_adjtime (struct ptp_clock_info *ptp,s64 delta);int ptp_qoriq_gettime (struct ptp_clock_info *ptp,struct timespec64 *ts);
Signature · 1 line
1.7.1
Yangbo Lu
maintainerPATCH v3 4/9 ptp_qoriq: add little enadian support
In reply to Yangbo LuThere is QorIQ 1588 timer IP block on the new ENETC Ethernet controller. However it uses little endian mode which is different with before. This patch is to add little endian support for the driver by using "little-endian" dts node property.
---
Changes for v2:
- None.
Changes for v3:
- Rebased.
--- drivers/ptp/ptp_qoriq.c | 69 ++++++++++++++++++++++----------------- drivers/ptp/ptp_qoriq_debugfs.c | 12 +++--- include/linux/fsl/ptp_qoriq.h | 21 ++++++++--- 3 files changed, 60 insertions(+), 42 deletions(-)
drivers/ptp/ptp_qoriq.c +39 -30
@@ -43,8 +43,8 @@ static u64 tmr_cnt_read(struct ptp_qoriq *ptp_qoriq)u64 ns;u32 lo, hi; - lo =qoriq_read (®s->ctrl_regs->tmr_cnt_l); - hi =qoriq_read (®s->ctrl_regs->tmr_cnt_h); + lo = ptp_qoriq->read (®s->ctrl_regs->tmr_cnt_l); + hi = ptp_qoriq->read (®s->ctrl_regs->tmr_cnt_h); ns = ((u64 ) hi) <<32 ; ns |= lo;return ns;
@@ -57,8 +57,8 @@ static void tmr_cnt_write(struct ptp_qoriq *ptp_qoriq, u64 ns)u32 hi = ns >>32 ;u32 lo = ns &0xffffffff ; -qoriq_write (®s->ctrl_regs->tmr_cnt_l, lo); -qoriq_write (®s->ctrl_regs->tmr_cnt_h, hi); + ptp_qoriq->write (®s->ctrl_regs->tmr_cnt_l, lo); + ptp_qoriq->write (®s->ctrl_regs->tmr_cnt_h, hi); }/* Caller must hold ptp_qoriq->lock. */
@@ -73,8 +73,8 @@ static void set_alarm(struct ptp_qoriq *ptp_qoriq) ns -= ptp_qoriq->tclk_period; hi = ns >>32 ; lo = ns &0xffffffff ; -qoriq_write (®s->alarm_regs->tmr_alarm1_l, lo); -qoriq_write (®s->alarm_regs->tmr_alarm1_h, hi); + ptp_qoriq->write (®s->alarm_regs->tmr_alarm1_l, lo); + ptp_qoriq->write (®s->alarm_regs->tmr_alarm1_h, hi); }/* Caller must hold ptp_qoriq->lock. */
@@ -83,8 +83,8 @@ static void set_fipers(struct ptp_qoriq *ptp_qoriq)struct ptp_qoriq_registers *regs = &ptp_qoriq->regs;set_alarm (ptp_qoriq); -qoriq_write (®s->fiper_regs->tmr_fiper1, ptp_qoriq->tmr_fiper1); -qoriq_write (®s->fiper_regs->tmr_fiper2, ptp_qoriq->tmr_fiper2); + ptp_qoriq->write (®s->fiper_regs->tmr_fiper1, ptp_qoriq->tmr_fiper1); + ptp_qoriq->write (®s->fiper_regs->tmr_fiper2, ptp_qoriq->tmr_fiper2); } static int extts_clean_up(struct ptp_qoriq *ptp_qoriq, int index,
@@ -115,8 +115,8 @@ static int extts_clean_up(struct ptp_qoriq *ptp_qoriq, int index, event.index = index; do { - lo = qoriq_read(reg_etts_l); - hi = qoriq_read(reg_etts_h); + lo = ptp_qoriq->read(reg_etts_l); + hi = ptp_qoriq->read(reg_etts_h); if (update_event) { event.timestamp = ((u64) hi) << 32;
@@ -124,7 +124,7 @@ static int extts_clean_up(struct ptp_qoriq *ptp_qoriq, int index,ptp_clock_event (ptp_qoriq->clock, &event); } - stat =qoriq_read (®s->ctrl_regs->tmr_stat); + stat = ptp_qoriq->read (®s->ctrl_regs->tmr_stat); }while (ptp_qoriq->extts_fifo_support && (stat & valid));return 0 ;
@@ -144,8 +144,8 @@ irqreturn_t ptp_qoriq_isr(int irq, void *priv)spin_lock (&ptp_qoriq->lock); - val =qoriq_read (®s->ctrl_regs->tmr_tevent); - mask =qoriq_read (®s->ctrl_regs->tmr_temask); + val = ptp_qoriq->read (®s->ctrl_regs->tmr_tevent); + mask = ptp_qoriq->read (®s->ctrl_regs->tmr_temask);spin_unlock (&ptp_qoriq->lock);
@@ -173,14 +173,14 @@ irqreturn_t ptp_qoriq_isr(int irq, void *priv) ns = ptp_qoriq->alarm_value + ptp_qoriq->alarm_interval; hi = ns >>32 ; lo = ns &0xffffffff ; -qoriq_write (®s->alarm_regs->tmr_alarm2_l, lo); -qoriq_write (®s->alarm_regs->tmr_alarm2_h, hi); + ptp_qoriq->write (®s->alarm_regs->tmr_alarm2_l, lo); + ptp_qoriq->write (®s->alarm_regs->tmr_alarm2_h, hi); ptp_qoriq->alarm_value = ns; }else {spin_lock (&ptp_qoriq->lock); - mask =qoriq_read (®s->ctrl_regs->tmr_temask); + mask = ptp_qoriq->read (®s->ctrl_regs->tmr_temask); mask &= ~ALM2EN ; -qoriq_write (®s->ctrl_regs->tmr_temask, mask); + ptp_qoriq->write (®s->ctrl_regs->tmr_temask, mask);spin_unlock (&ptp_qoriq->lock); ptp_qoriq->alarm_value =0 ; ptp_qoriq->alarm_interval =0 ;
@@ -194,7 +194,7 @@ irqreturn_t ptp_qoriq_isr(int irq, void *priv) }if (ack) { -qoriq_write (®s->ctrl_regs->tmr_tevent, ack); + ptp_qoriq->write (®s->ctrl_regs->tmr_tevent, ack);return IRQ_HANDLED ; }else return IRQ_NONE ;
@@ -229,7 +229,7 @@ int ptp_qoriq_adjfine(struct ptp_clock_info *ptp, long scaled_ppm) tmr_add = neg_adj ? tmr_add - diff : tmr_add + diff; -qoriq_write (®s->ctrl_regs->tmr_add, tmr_add); + ptp_qoriq->write (®s->ctrl_regs->tmr_add, tmr_add);return 0 ; }
@@ -326,15 +326,15 @@ int ptp_qoriq_enable(struct ptp_clock_info *ptp,spin_lock_irqsave (&ptp_qoriq->lock, flags); - mask =qoriq_read (®s->ctrl_regs->tmr_temask); + mask = ptp_qoriq->read (®s->ctrl_regs->tmr_temask);if (on) { mask |= bit; -qoriq_write (®s->ctrl_regs->tmr_tevent, bit); + ptp_qoriq->write (®s->ctrl_regs->tmr_tevent, bit); }else { mask &= ~bit; } -qoriq_write (®s->ctrl_regs->tmr_temask, mask); + ptp_qoriq->write (®s->ctrl_regs->tmr_temask, mask);spin_unlock_irqrestore (&ptp_qoriq->lock, flags);return 0 ;
@@ -496,6 +496,14 @@ int ptp_qoriq_init(struct ptp_qoriq *ptp_qoriq, void __iomem *base,return -ENODEV ; } +if (of_property_read_bool (node,"little-endian" )) { + ptp_qoriq->read = qoriq_read_le; + ptp_qoriq->write = qoriq_write_le; + }else { + ptp_qoriq->read = qoriq_read_be; + ptp_qoriq->write = qoriq_write_be; + } +if (of_device_is_compatible (node,"fsl,fman-ptp-timer" )) { ptp_qoriq->regs.ctrl_regs = base +FMAN_CTRL_REGS_OFFSET ; ptp_qoriq->regs.alarm_regs = base +FMAN_ALARM_REGS_OFFSET ;
@@ -519,13 +527,14 @@ int ptp_qoriq_init(struct ptp_qoriq *ptp_qoriq, void __iomem *base,spin_lock_irqsave (&ptp_qoriq->lock, flags); regs = &ptp_qoriq->regs; -qoriq_write (®s->ctrl_regs->tmr_ctrl, tmr_ctrl); -qoriq_write (®s->ctrl_regs->tmr_add, ptp_qoriq->tmr_add); -qoriq_write (®s->ctrl_regs->tmr_prsc, ptp_qoriq->tmr_prsc); -qoriq_write (®s->fiper_regs->tmr_fiper1, ptp_qoriq->tmr_fiper1); -qoriq_write (®s->fiper_regs->tmr_fiper2, ptp_qoriq->tmr_fiper2); + ptp_qoriq->write (®s->ctrl_regs->tmr_ctrl, tmr_ctrl); + ptp_qoriq->write (®s->ctrl_regs->tmr_add, ptp_qoriq->tmr_add); + ptp_qoriq->write (®s->ctrl_regs->tmr_prsc, ptp_qoriq->tmr_prsc); + ptp_qoriq->write (®s->fiper_regs->tmr_fiper1, ptp_qoriq->tmr_fiper1); + ptp_qoriq->write (®s->fiper_regs->tmr_fiper2, ptp_qoriq->tmr_fiper2);set_alarm (ptp_qoriq); -qoriq_write (®s->ctrl_regs->tmr_ctrl, tmr_ctrl|FIPERST |RTPE |TE |FRD ); + ptp_qoriq->write (®s->ctrl_regs->tmr_ctrl, + tmr_ctrl|FIPERST |RTPE |TE |FRD );spin_unlock_irqrestore (&ptp_qoriq->lock, flags);
@@ -543,8 +552,8 @@ void ptp_qoriq_free(struct ptp_qoriq *ptp_qoriq) {struct ptp_qoriq_registers *regs = &ptp_qoriq->regs; -qoriq_write (®s->ctrl_regs->tmr_temask,0 ); -qoriq_write (®s->ctrl_regs->tmr_ctrl,0 ); + ptp_qoriq->write (®s->ctrl_regs->tmr_temask,0 ); + ptp_qoriq->write (®s->ctrl_regs->tmr_ctrl,0 );ptp_qoriq_remove_debugfs (ptp_qoriq);ptp_clock_unregister (ptp_qoriq->clock);
drivers/ptp/ptp_qoriq_debugfs.c +6 -6
@@ -11,7 +11,7 @@ static int ptp_qoriq_fiper1_lpbk_get(void *data, u64 *val)struct ptp_qoriq_registers *regs = &ptp_qoriq->regs;u32 ctrl; - ctrl =qoriq_read (®s->ctrl_regs->tmr_ctrl); + ctrl = ptp_qoriq->read (®s->ctrl_regs->tmr_ctrl); *val = ctrl &PP1L ?1 :0 ;return 0 ;
@@ -23,13 +23,13 @@ static int ptp_qoriq_fiper1_lpbk_set(void *data, u64 val)struct ptp_qoriq_registers *regs = &ptp_qoriq->regs;u32 ctrl; - ctrl =qoriq_read (®s->ctrl_regs->tmr_ctrl); + ctrl = ptp_qoriq->read (®s->ctrl_regs->tmr_ctrl);if (val ==0 ) ctrl &= ~PP1L ;else ctrl |=PP1L ; -qoriq_write (®s->ctrl_regs->tmr_ctrl, ctrl); + ptp_qoriq->write (®s->ctrl_regs->tmr_ctrl, ctrl);return 0 ; }
@@ -42,7 +42,7 @@ static int ptp_qoriq_fiper2_lpbk_get(void *data, u64 *val)struct ptp_qoriq_registers *regs = &ptp_qoriq->regs;u32 ctrl; - ctrl =qoriq_read (®s->ctrl_regs->tmr_ctrl); + ctrl = ptp_qoriq->read (®s->ctrl_regs->tmr_ctrl); *val = ctrl &PP2L ?1 :0 ;return 0 ;
@@ -54,13 +54,13 @@ static int ptp_qoriq_fiper2_lpbk_set(void *data, u64 val)struct ptp_qoriq_registers *regs = &ptp_qoriq->regs;u32 ctrl; - ctrl =qoriq_read (®s->ctrl_regs->tmr_ctrl); + ctrl = ptp_qoriq->read (®s->ctrl_regs->tmr_ctrl);if (val ==0 ) ctrl &= ~PP2L ;else ctrl |=PP2L ; -qoriq_write (®s->ctrl_regs->tmr_ctrl, ctrl); + ptp_qoriq->write (®s->ctrl_regs->tmr_ctrl, ctrl);return 0 ; }
include/linux/fsl/ptp_qoriq.h +15 -6
@@ -157,21 +157,30 @@ struct ptp_qoriq {u32 cksel;u32 tmr_fiper1;u32 tmr_fiper2; +u32 (*read)(unsigned__iomem *addr); +void (*write)(unsigned __iomem *addr,u32 val); }; -static inline u32 qoriq_read (unsigned __iomem *addr) +static inline u32 qoriq_read_be (unsigned __iomem *addr) { -u32 val; - - val =ioread32be (addr); -return val; +return ioread32be (addr); } -static inline void qoriq_write (unsigned __iomem *addr,u32 val) +static inline void qoriq_write_be (unsigned __iomem *addr,u32 val) {iowrite32be (val, addr); } +static inline u32 qoriq_read_le (unsigned __iomem *addr) +{ +return ioread32 (addr); +} + +static inline void qoriq_write_le (unsigned __iomem *addr,u32 val) +{ +iowrite32 (val, addr); +} +irqreturn_t ptp_qoriq_isr (int irq,void *priv);int ptp_qoriq_init (struct ptp_qoriq *ptp_qoriq,void __iomem *base,const struct ptp_clock_info caps);
Signature · 1 line
1.7.1
Yangbo Lu
maintainerPATCH v3 5/9 dt-binding: ptp_qoriq: add little-endian support
In reply to Yangbo LuSpecify "little-endian" property if the 1588 timer IP block is little-endian mode. The default endian mode is big-endian.
---
Changes for v2:
- None.
Changes for v3:
- None.
--- .../devicetree/bindings/ptp/ptp-qoriq.txt | 3 +++ 1 files changed, 3 insertions(+), 0 deletions(-)
Documentation/devicetree/bindings/ptp/ptp-qoriq.txt +3 -0
@@ -19,6 +19,9 @@ Clock Properties: - fsl,max-adj Maximum frequency adjustment in parts per billion. - fsl,extts-fifo The presence of this property indicates hardware support for the external trigger stamp FIFO. + - little-endian The presence of this property indicates the 1588 timer + IP block is little-endian mode. The default endian mode + is big-endian. These properties set the operational parameters for the PTP clock. You must choose these carefully for the clock to work right.
Signature · 1 line
1.7.1
Yangbo Lu
maintainerPATCH v3 6/9 ptp_qoriq: fix register memory map
In reply to Yangbo LuThe 1588 timer on eTSEC Ethernet controller uses different register memory map with DPAA Ethernet controller. Now the new ENETC Ethernet controller uses same reigster memory map with DPAA. To support ENETC, let's use register memory map of DPAA/ENETC in default.
---
Changes for v2:
- None.
Changes for v3:
- None.
--- drivers/ptp/ptp_qoriq.c | 11 ++++++----- include/linux/fsl/ptp_qoriq.h | 16 ++++++++-------- 2 files changed, 14 insertions(+), 13 deletions(-)
drivers/ptp/ptp_qoriq.c +6 -5
@@ -504,11 +504,12 @@ int ptp_qoriq_init(struct ptp_qoriq *ptp_qoriq, void __iomem *base, ptp_qoriq->write = qoriq_write_be; } -if (of_device_is_compatible (node,"fsl,fman-ptp-timer" )) { - ptp_qoriq->regs.ctrl_regs = base +FMAN_CTRL_REGS_OFFSET ; - ptp_qoriq->regs.alarm_regs = base +FMAN_ALARM_REGS_OFFSET ; - ptp_qoriq->regs.fiper_regs = base +FMAN_FIPER_REGS_OFFSET ; - ptp_qoriq->regs.etts_regs = base +FMAN_ETTS_REGS_OFFSET ; +/* The eTSEC uses differnt memory map with DPAA/ENETC */ +if (of_device_is_compatible (node,"fsl,etsec-ptp" )) { + ptp_qoriq->regs.ctrl_regs = base +ETSEC_CTRL_REGS_OFFSET ; + ptp_qoriq->regs.alarm_regs = base +ETSEC_ALARM_REGS_OFFSET ; + ptp_qoriq->regs.fiper_regs = base +ETSEC_FIPER_REGS_OFFSET ; + ptp_qoriq->regs.etts_regs = base +ETSEC_ETTS_REGS_OFFSET ; }else { ptp_qoriq->regs.ctrl_regs = base +CTRL_REGS_OFFSET ; ptp_qoriq->regs.alarm_regs = base +ALARM_REGS_OFFSET ;
include/linux/fsl/ptp_qoriq.h +9 -9
@@ -58,15 +58,15 @@ struct ptp_qoriq_registers { };/* Offset definitions for the four register groups */ -#define CTRL_REGS_OFFSET 0x0 -#define ALARM_REGS_OFFSET 0x40 -#define FIPER_REGS_OFFSET 0x80 -#define ETTS_REGS_OFFSET 0xa0 - -#define FMAN_CTRL_REGS_OFFSET 0x80 -#define FMAN_ALARM_REGS_OFFSET 0xb8 -#define FMAN_FIPER_REGS_OFFSET 0xd0 -#define FMAN_ETTS_REGS_OFFSET 0xe0 +#define ETSEC_CTRL_REGS_OFFSET 0x0 +#define ETSEC_ALARM_REGS_OFFSET 0x40 +#define ETSEC_FIPER_REGS_OFFSET 0x80 +#define ETSEC_ETTS_REGS_OFFSET 0xa0 + +#define CTRL_REGS_OFFSET 0x80 +#define ALARM_REGS_OFFSET 0xb8 +#define FIPER_REGS_OFFSET 0xd0 +#define ETTS_REGS_OFFSET 0xe0/* Bit definitions for the TMR_CTRL register */
Signature · 1 line
1.7.1
Yangbo Lu
maintainerPATCH v3 7/9 ptp: add QorIQ PTP support for ENETC
In reply to Yangbo LuThis patch is to add QorIQ PTP support for ENETC.
ENETC PTP driver which is a PCI driver for same
1588 timer IP block will reuse QorIQ PTP driver.
---
Chanbges for v2:
- None.
Chanbges for v3:
- None.
--- drivers/ptp/Kconfig | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
drivers/ptp/Kconfig +1 -1
@@ -43,7 +43,7 @@ config PTP_1588_CLOCK_DTE config PTP_1588_CLOCK_QORIQ tristate "Freescale QorIQ 1588 timer as PTP clock" - depends on GIANFAR || FSL_DPAA_ETH + depends on GIANFAR || FSL_DPAA_ETH || FSL_ENETC || FSL_ENETC_VF depends on PTP_1588_CLOCK default y help
Signature · 1 line
1.7.1
Yangbo Lu
maintainerPATCH v3 8/9 enetc: add PTP clock driver
In reply to Yangbo LuThis patch is to add PTP clock driver for ENETC.
The driver reused QorIQ PTP clock driver.
---
Changes for v2:
- None.
Changes for v3:
- Converted to use ptp_qoriq_free().
--- drivers/net/ethernet/freescale/enetc/Kconfig | 12 ++ drivers/net/ethernet/freescale/enetc/Makefile | 3 + drivers/net/ethernet/freescale/enetc/enetc_hw.h | 5 +- drivers/net/ethernet/freescale/enetc/enetc_ptp.c | 144 ++++++++++++++++++++++ 4 files changed, 162 insertions(+), 2 deletions(-) create mode 100644 drivers/net/ethernet/freescale/enetc/enetc_ptp.c
drivers/net/ethernet/freescale/enetc/Kconfig +12 -0
@@ -17,3 +17,15 @@ config FSL_ENETC_VF virtual function (VF) devices enabled by the ENETC PF driver. If compiled as module (M), the module name is fsl-enetc-vf. + +config FSL_ENETC_PTP_CLOCK + tristate "ENETC PTP clock driver" + depends on PTP_1588_CLOCK_QORIQ && (FSL_ENETC || FSL_ENETC_VF) + default y + help + This driver adds support for using the ENETC 1588 timer + as a PTP clock. This clock is only useful if your PTP + programs are getting hardware time stamps on the PTP Ethernet + packets using the SO_TIMESTAMPING API. + + If compiled as module (M), the module name is fsl-enetc-ptp.
drivers/net/ethernet/freescale/enetc/Makefile +3 -0
@@ -13,3 +13,6 @@ fsl-enetc-vf-$(CONFIG_FSL_ENETC_VF) += enetc.o enetc_cbdr.o \ enetc_ethtool.o fsl-enetc-vf-objs := enetc_vf.o $(fsl-enetc-vf-y) endif + +obj-$(CONFIG_FSL_ENETC_PTP_CLOCK) += fsl-enetc-ptp.o +fsl-enetc-ptp-$(CONFIG_FSL_ENETC_PTP_CLOCK) += enetc_ptp.o
drivers/net/ethernet/freescale/enetc/enetc_hw.h +3 -2
@@ -4,8 +4,9 @@#include <linux/bitops.h> /* ENETC device IDs */ -#define ENETC_DEV_ID_PF 0xe100 -#define ENETC_DEV_ID_VF 0xef00 +#define ENETC_DEV_ID_PF 0xe100 +#define ENETC_DEV_ID_VF 0xef00 +#define ENETC_DEV_ID_PTP 0xee02/* ENETC register block BAR */ #define ENETC_BAR_REGS 0
drivers/net/ethernet/freescale/enetc/enetc_ptp.c new file +144 -0
144 lines not on this page · raw message
Signature · 1 line
1.7.1
Yangbo Lu
maintainerPATCH v3 9/9 MAINTAINERS: add enetc_ptp driver into QorIQ PTP list
In reply to Yangbo LuThis patch to add enetc_ptp driver into QorIQ PTP list for maintaining.
---
Changes for v2:
- None.
Changes for v3:
- None.
--- MAINTAINERS | 1 + 1 files changed, 1 insertions(+), 0 deletions(-)
MAINTAINERS +1 -0
@@ -6104,6 +6104,7 @@ FREESCALE QORIQ PTP CLOCK DRIVER M: Yangbo Lu <[email protected]> L: [email protected] S: Maintained +F: drivers/net/ethernet/freescale/enetc/enetc_ptp.c F: drivers/ptp/ptp_qoriq.c F: drivers/ptp/ptp_qoriq_debugfs.c F: include/linux/fsl/ptp_qoriq.h
Signature · 1 line
1.7.1
David Miller
maintainerFrom: Yangbo Lu <[email protected]>
Date: Tue, 12 Feb 2019 12:23:55 +0800
Quoted 9 lines
There is same QorIQ 1588 timer IP block on the new ENETC Ethernet controller with eTSEC/DPAA Ethernet controllers. However it's different endianness (little-endian) and using PCI driver.
To support ENETC PTP driver,
ptp_qoriqdriver needed to be reworked to make functions global for reusing, to add little- endian support, to add ENETC memory map support, and to add ENETC dependency forptp_qoriqdriver.
Quoted 7 lines
In addition, although ENETC PTP driver is a PCI driver, the dts node still could be used. Currently the ls1028a dtsi which is the only platform by now using ENETC is not complete, so there is still dependency for ENETC PTP node upstreaming. This will be done in the near future. The hardware timestamping support for ENETC is done but needs to be reworked with new method in internal git tree, and will be sent out soon.
Series applied.
I'll push this out after my build tests pass.