Commit 724812d8 authored by David S. Miller's avatar David S. Miller

Merge branch 'IXP46x-PTP-Timer'

Linus Walleij says:

====================
IXP46x PTP Timer clean-up and DT

ChangeLog v2->v3:

- Dropped the patch enabling compile tests: we are still dependent
  on some machine-specific headers. The plan is to get rid of this
  after device tree conversion. We include one of the compile testing
  fixes anyway, because it is nice to have fixed.

- Rebased on the latest net-next
====================
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parents 27c77943 e9e50622
# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
# Copyright 2018 Linaro Ltd.
%YAML 1.2
---
$id: "http://devicetree.org/schemas/net/intel,ixp46x-ptp-timer.yaml#"
$schema: "http://devicetree.org/meta-schemas/core.yaml#"
title: Intel IXP46x PTP Timer (TSYNC)
maintainers:
- Linus Walleij <linus.walleij@linaro.org>
description: |
The Intel IXP46x PTP timer is known in the manual as IEEE1588 Hardware
Assist and Time Synchronization Hardware Assist TSYNC provides a PTP
timer. It exists in the Intel IXP45x and IXP46x XScale SoCs.
properties:
compatible:
const: intel,ixp46x-ptp-timer
reg:
maxItems: 1
interrupts:
items:
- description: Interrupt to trigger master mode snapshot from the
PRP timer, usually a GPIO interrupt.
- description: Interrupt to trigger slave mode snapshot from the
PRP timer, usually a GPIO interrupt.
interrupt-names:
items:
- const: master
- const: slave
required:
- compatible
- reg
- interrupts
- interrupt-names
additionalProperties: false
examples:
- |
#include <dt-bindings/interrupt-controller/irq.h>
ptp-timer@c8010000 {
compatible = "intel,ixp46x-ptp-timer";
reg = <0xc8010000 0x1000>;
interrupt-parent = <&gpio0>;
interrupts = <8 IRQ_TYPE_EDGE_FALLING>, <7 IRQ_TYPE_EDGE_FALLING>;
interrupt-names = "master", "slave";
};
...@@ -268,9 +268,23 @@ static struct platform_device ixp46x_i2c_controller = { ...@@ -268,9 +268,23 @@ static struct platform_device ixp46x_i2c_controller = {
.resource = ixp46x_i2c_resources .resource = ixp46x_i2c_resources
}; };
static struct resource ixp46x_ptp_resources[] = {
DEFINE_RES_MEM(IXP4XX_TIMESYNC_BASE_PHYS, SZ_4K),
DEFINE_RES_IRQ_NAMED(IRQ_IXP4XX_GPIO8, "master"),
DEFINE_RES_IRQ_NAMED(IRQ_IXP4XX_GPIO7, "slave"),
};
static struct platform_device ixp46x_ptp = {
.name = "ptp-ixp46x",
.id = -1,
.resource = ixp46x_ptp_resources,
.num_resources = ARRAY_SIZE(ixp46x_ptp_resources),
};
static struct platform_device *ixp46x_devices[] __initdata = { static struct platform_device *ixp46x_devices[] __initdata = {
&ixp46x_hwrandom_device, &ixp46x_hwrandom_device,
&ixp46x_i2c_controller, &ixp46x_i2c_controller,
&ixp46x_ptp,
}; };
unsigned long ixp4xx_exp_bus_size; unsigned long ixp4xx_exp_bus_size;
......
...@@ -29,9 +29,9 @@ config IXP4XX_ETH ...@@ -29,9 +29,9 @@ config IXP4XX_ETH
on IXP4xx processor. on IXP4xx processor.
config PTP_1588_CLOCK_IXP46X config PTP_1588_CLOCK_IXP46X
tristate "Intel IXP46x as PTP clock" bool "Intel IXP46x as PTP clock"
depends on IXP4XX_ETH depends on IXP4XX_ETH
depends on PTP_1588_CLOCK depends on PTP_1588_CLOCK=y || PTP_1588_CLOCK=IXP4XX_ETH
default y default y
help help
This driver adds support for using the IXP46X as a PTP This driver adds support for using the IXP46X as a PTP
......
...@@ -3,5 +3,9 @@ ...@@ -3,5 +3,9 @@
# Makefile for the Intel XScale IXP device drivers. # Makefile for the Intel XScale IXP device drivers.
# #
# Keep this link order to avoid deferred probing
ifdef CONFIG_PTP_1588_CLOCK_IXP46X
obj-$(CONFIG_IXP4XX_ETH) += ptp_ixp46x.o
endif
obj-$(CONFIG_IXP4XX_ETH) += ixp4xx_eth.o obj-$(CONFIG_IXP4XX_ETH) += ixp4xx_eth.o
obj-$(CONFIG_PTP_1588_CLOCK_IXP46X) += ptp_ixp46x.o
...@@ -62,7 +62,16 @@ struct ixp46x_ts_regs { ...@@ -62,7 +62,16 @@ struct ixp46x_ts_regs {
#define TX_SNAPSHOT_LOCKED (1<<0) #define TX_SNAPSHOT_LOCKED (1<<0)
#define RX_SNAPSHOT_LOCKED (1<<1) #define RX_SNAPSHOT_LOCKED (1<<1)
/* The ptp_ixp46x module will set this variable */ #if IS_ENABLED(CONFIG_PTP_1588_CLOCK_IXP46X)
extern int ixp46x_phc_index; int ixp46x_ptp_find(struct ixp46x_ts_regs *__iomem *regs, int *phc_index);
#else
static inline int ixp46x_ptp_find(struct ixp46x_ts_regs *__iomem *regs, int *phc_index)
{
*regs = NULL;
*phc_index = -1;
return -ENODEV;
}
#endif
#endif #endif
...@@ -37,7 +37,6 @@ ...@@ -37,7 +37,6 @@
#include <linux/module.h> #include <linux/module.h>
#include <linux/soc/ixp4xx/npe.h> #include <linux/soc/ixp4xx/npe.h>
#include <linux/soc/ixp4xx/qmgr.h> #include <linux/soc/ixp4xx/qmgr.h>
#include <mach/hardware.h>
#include <linux/soc/ixp4xx/cpu.h> #include <linux/soc/ixp4xx/cpu.h>
#include "ixp46x_ts.h" #include "ixp46x_ts.h"
...@@ -169,13 +168,15 @@ struct eth_regs { ...@@ -169,13 +168,15 @@ struct eth_regs {
struct port { struct port {
struct eth_regs __iomem *regs; struct eth_regs __iomem *regs;
struct ixp46x_ts_regs __iomem *timesync_regs;
int phc_index;
struct npe *npe; struct npe *npe;
struct net_device *netdev; struct net_device *netdev;
struct napi_struct napi; struct napi_struct napi;
struct eth_plat_info *plat; struct eth_plat_info *plat;
buffer_t *rx_buff_tab[RX_DESCS], *tx_buff_tab[TX_DESCS]; buffer_t *rx_buff_tab[RX_DESCS], *tx_buff_tab[TX_DESCS];
struct desc *desc_tab; /* coherent */ struct desc *desc_tab; /* coherent */
u32 desc_tab_phys; dma_addr_t desc_tab_phys;
int id; /* logical port ID */ int id; /* logical port ID */
int speed, duplex; int speed, duplex;
u8 firmware[4]; u8 firmware[4];
...@@ -295,7 +296,7 @@ static void ixp_rx_timestamp(struct port *port, struct sk_buff *skb) ...@@ -295,7 +296,7 @@ static void ixp_rx_timestamp(struct port *port, struct sk_buff *skb)
ch = PORT2CHANNEL(port); ch = PORT2CHANNEL(port);
regs = (struct ixp46x_ts_regs __iomem *) IXP4XX_TIMESYNC_BASE_VIRT; regs = port->timesync_regs;
val = __raw_readl(&regs->channel[ch].ch_event); val = __raw_readl(&regs->channel[ch].ch_event);
...@@ -340,7 +341,7 @@ static void ixp_tx_timestamp(struct port *port, struct sk_buff *skb) ...@@ -340,7 +341,7 @@ static void ixp_tx_timestamp(struct port *port, struct sk_buff *skb)
ch = PORT2CHANNEL(port); ch = PORT2CHANNEL(port);
regs = (struct ixp46x_ts_regs __iomem *) IXP4XX_TIMESYNC_BASE_VIRT; regs = port->timesync_regs;
/* /*
* This really stinks, but we have to poll for the Tx time stamp. * This really stinks, but we have to poll for the Tx time stamp.
...@@ -375,6 +376,7 @@ static int hwtstamp_set(struct net_device *netdev, struct ifreq *ifr) ...@@ -375,6 +376,7 @@ static int hwtstamp_set(struct net_device *netdev, struct ifreq *ifr)
struct hwtstamp_config cfg; struct hwtstamp_config cfg;
struct ixp46x_ts_regs *regs; struct ixp46x_ts_regs *regs;
struct port *port = netdev_priv(netdev); struct port *port = netdev_priv(netdev);
int ret;
int ch; int ch;
if (copy_from_user(&cfg, ifr->ifr_data, sizeof(cfg))) if (copy_from_user(&cfg, ifr->ifr_data, sizeof(cfg)))
...@@ -383,8 +385,12 @@ static int hwtstamp_set(struct net_device *netdev, struct ifreq *ifr) ...@@ -383,8 +385,12 @@ static int hwtstamp_set(struct net_device *netdev, struct ifreq *ifr)
if (cfg.flags) /* reserved for future extensions */ if (cfg.flags) /* reserved for future extensions */
return -EINVAL; return -EINVAL;
ret = ixp46x_ptp_find(&port->timesync_regs, &port->phc_index);
if (ret)
return ret;
ch = PORT2CHANNEL(port); ch = PORT2CHANNEL(port);
regs = (struct ixp46x_ts_regs __iomem *) IXP4XX_TIMESYNC_BASE_VIRT; regs = port->timesync_regs;
if (cfg.tx_type != HWTSTAMP_TX_OFF && cfg.tx_type != HWTSTAMP_TX_ON) if (cfg.tx_type != HWTSTAMP_TX_OFF && cfg.tx_type != HWTSTAMP_TX_ON)
return -ERANGE; return -ERANGE;
...@@ -850,14 +856,14 @@ static int eth_xmit(struct sk_buff *skb, struct net_device *dev) ...@@ -850,14 +856,14 @@ static int eth_xmit(struct sk_buff *skb, struct net_device *dev)
bytes = len; bytes = len;
mem = skb->data; mem = skb->data;
#else #else
offset = (int)skb->data & 3; /* keep 32-bit alignment */ offset = (uintptr_t)skb->data & 3; /* keep 32-bit alignment */
bytes = ALIGN(offset + len, 4); bytes = ALIGN(offset + len, 4);
if (!(mem = kmalloc(bytes, GFP_ATOMIC))) { if (!(mem = kmalloc(bytes, GFP_ATOMIC))) {
dev_kfree_skb(skb); dev_kfree_skb(skb);
dev->stats.tx_dropped++; dev->stats.tx_dropped++;
return NETDEV_TX_OK; return NETDEV_TX_OK;
} }
memcpy_swab32(mem, (u32 *)((int)skb->data & ~3), bytes / 4); memcpy_swab32(mem, (u32 *)((uintptr_t)skb->data & ~3), bytes / 4);
#endif #endif
phys = dma_map_single(&dev->dev, mem, bytes, DMA_TO_DEVICE); phys = dma_map_single(&dev->dev, mem, bytes, DMA_TO_DEVICE);
...@@ -988,25 +994,27 @@ static void ixp4xx_get_drvinfo(struct net_device *dev, ...@@ -988,25 +994,27 @@ static void ixp4xx_get_drvinfo(struct net_device *dev,
strlcpy(info->bus_info, "internal", sizeof(info->bus_info)); strlcpy(info->bus_info, "internal", sizeof(info->bus_info));
} }
int ixp46x_phc_index = -1;
EXPORT_SYMBOL_GPL(ixp46x_phc_index);
static int ixp4xx_get_ts_info(struct net_device *dev, static int ixp4xx_get_ts_info(struct net_device *dev,
struct ethtool_ts_info *info) struct ethtool_ts_info *info)
{ {
if (!cpu_is_ixp46x()) { struct port *port = netdev_priv(dev);
if (port->phc_index < 0)
ixp46x_ptp_find(&port->timesync_regs, &port->phc_index);
info->phc_index = port->phc_index;
if (info->phc_index < 0) {
info->so_timestamping = info->so_timestamping =
SOF_TIMESTAMPING_TX_SOFTWARE | SOF_TIMESTAMPING_TX_SOFTWARE |
SOF_TIMESTAMPING_RX_SOFTWARE | SOF_TIMESTAMPING_RX_SOFTWARE |
SOF_TIMESTAMPING_SOFTWARE; SOF_TIMESTAMPING_SOFTWARE;
info->phc_index = -1;
return 0; return 0;
} }
info->so_timestamping = info->so_timestamping =
SOF_TIMESTAMPING_TX_HARDWARE | SOF_TIMESTAMPING_TX_HARDWARE |
SOF_TIMESTAMPING_RX_HARDWARE | SOF_TIMESTAMPING_RX_HARDWARE |
SOF_TIMESTAMPING_RAW_HARDWARE; SOF_TIMESTAMPING_RAW_HARDWARE;
info->phc_index = ixp46x_phc_index;
info->tx_types = info->tx_types =
(1 << HWTSTAMP_TX_OFF) | (1 << HWTSTAMP_TX_OFF) |
(1 << HWTSTAMP_TX_ON); (1 << HWTSTAMP_TX_ON);
...@@ -1481,6 +1489,7 @@ static int ixp4xx_eth_probe(struct platform_device *pdev) ...@@ -1481,6 +1489,7 @@ static int ixp4xx_eth_probe(struct platform_device *pdev)
port = netdev_priv(ndev); port = netdev_priv(ndev);
port->netdev = ndev; port->netdev = ndev;
port->id = plat->npe; port->id = plat->npe;
port->phc_index = -1;
/* Get the port resource and remap */ /* Get the port resource and remap */
port->regs = devm_platform_get_and_ioremap_resource(pdev, 0, NULL); port->regs = devm_platform_get_and_ioremap_resource(pdev, 0, NULL);
......
...@@ -5,14 +5,16 @@ ...@@ -5,14 +5,16 @@
* Copyright (C) 2010 OMICRON electronics GmbH * Copyright (C) 2010 OMICRON electronics GmbH
*/ */
#include <linux/device.h> #include <linux/device.h>
#include <linux/module.h>
#include <linux/mod_devicetable.h>
#include <linux/err.h> #include <linux/err.h>
#include <linux/gpio.h>
#include <linux/init.h> #include <linux/init.h>
#include <linux/interrupt.h> #include <linux/interrupt.h>
#include <linux/io.h> #include <linux/io.h>
#include <linux/irq.h> #include <linux/irq.h>
#include <linux/kernel.h> #include <linux/kernel.h>
#include <linux/ptp_clock_kernel.h> #include <linux/ptp_clock_kernel.h>
#include <linux/platform_device.h>
#include <linux/soc/ixp4xx/cpu.h> #include <linux/soc/ixp4xx/cpu.h>
#include <linux/module.h> #include <linux/module.h>
#include <mach/ixp4xx-regs.h> #include <mach/ixp4xx-regs.h>
...@@ -21,10 +23,6 @@ ...@@ -21,10 +23,6 @@
#define DRIVER "ptp_ixp46x" #define DRIVER "ptp_ixp46x"
#define N_EXT_TS 2 #define N_EXT_TS 2
#define MASTER_GPIO 8
#define MASTER_IRQ 25
#define SLAVE_GPIO 7
#define SLAVE_IRQ 24
struct ixp_clock { struct ixp_clock {
struct ixp46x_ts_regs *regs; struct ixp46x_ts_regs *regs;
...@@ -32,9 +30,11 @@ struct ixp_clock { ...@@ -32,9 +30,11 @@ struct ixp_clock {
struct ptp_clock_info caps; struct ptp_clock_info caps;
int exts0_enabled; int exts0_enabled;
int exts1_enabled; int exts1_enabled;
int slave_irq;
int master_irq;
}; };
DEFINE_SPINLOCK(register_lock); static DEFINE_SPINLOCK(register_lock);
/* /*
* Register access functions * Register access functions
...@@ -243,53 +243,38 @@ static const struct ptp_clock_info ptp_ixp_caps = { ...@@ -243,53 +243,38 @@ static const struct ptp_clock_info ptp_ixp_caps = {
static struct ixp_clock ixp_clock; static struct ixp_clock ixp_clock;
static int setup_interrupt(int gpio) int ixp46x_ptp_find(struct ixp46x_ts_regs *__iomem *regs, int *phc_index)
{ {
int irq; *regs = ixp_clock.regs;
int err; *phc_index = ptp_clock_index(ixp_clock.ptp_clock);
err = gpio_request(gpio, "ixp4-ptp");
if (err)
return err;
err = gpio_direction_input(gpio);
if (err)
return err;
irq = gpio_to_irq(gpio);
if (irq < 0)
return irq;
err = irq_set_irq_type(irq, IRQF_TRIGGER_FALLING); if (!ixp_clock.ptp_clock)
if (err) { return -EPROBE_DEFER;
pr_err("cannot set trigger type for irq %d\n", irq);
return err;
}
err = request_irq(irq, isr, 0, DRIVER, &ixp_clock);
if (err) {
pr_err("request_irq failed for irq %d\n", irq);
return err;
}
return irq; return 0;
} }
EXPORT_SYMBOL_GPL(ixp46x_ptp_find);
static void __exit ptp_ixp_exit(void) /* Called from the registered devm action */
static void ptp_ixp_unregister_action(void *d)
{ {
free_irq(MASTER_IRQ, &ixp_clock); struct ptp_clock *ptp_clock = d;
free_irq(SLAVE_IRQ, &ixp_clock);
ixp46x_phc_index = -1; ptp_clock_unregister(ptp_clock);
ptp_clock_unregister(ixp_clock.ptp_clock); ixp_clock.ptp_clock = NULL;
} }
static int __init ptp_ixp_init(void) static int ptp_ixp_probe(struct platform_device *pdev)
{ {
if (!cpu_is_ixp46x()) struct device *dev = &pdev->dev;
return -ENODEV; int ret;
ixp_clock.regs = ixp_clock.regs = devm_platform_ioremap_resource(pdev, 0);
(struct ixp46x_ts_regs __iomem *) IXP4XX_TIMESYNC_BASE_VIRT; ixp_clock.master_irq = platform_get_irq(pdev, 0);
ixp_clock.slave_irq = platform_get_irq(pdev, 1);
if (IS_ERR(ixp_clock.regs) ||
!ixp_clock.master_irq || !ixp_clock.slave_irq)
return -ENXIO;
ixp_clock.caps = ptp_ixp_caps; ixp_clock.caps = ptp_ixp_caps;
...@@ -298,32 +283,51 @@ static int __init ptp_ixp_init(void) ...@@ -298,32 +283,51 @@ static int __init ptp_ixp_init(void)
if (IS_ERR(ixp_clock.ptp_clock)) if (IS_ERR(ixp_clock.ptp_clock))
return PTR_ERR(ixp_clock.ptp_clock); return PTR_ERR(ixp_clock.ptp_clock);
ixp46x_phc_index = ptp_clock_index(ixp_clock.ptp_clock); ret = devm_add_action_or_reset(dev, ptp_ixp_unregister_action,
ixp_clock.ptp_clock);
if (ret) {
dev_err(dev, "failed to install clock removal handler\n");
return ret;
}
__raw_writel(DEFAULT_ADDEND, &ixp_clock.regs->addend); __raw_writel(DEFAULT_ADDEND, &ixp_clock.regs->addend);
__raw_writel(1, &ixp_clock.regs->trgt_lo); __raw_writel(1, &ixp_clock.regs->trgt_lo);
__raw_writel(0, &ixp_clock.regs->trgt_hi); __raw_writel(0, &ixp_clock.regs->trgt_hi);
__raw_writel(TTIPEND, &ixp_clock.regs->event); __raw_writel(TTIPEND, &ixp_clock.regs->event);
if (MASTER_IRQ != setup_interrupt(MASTER_GPIO)) { ret = devm_request_irq(dev, ixp_clock.master_irq, isr,
pr_err("failed to setup gpio %d as irq\n", MASTER_GPIO); 0, DRIVER, &ixp_clock);
goto no_master; if (ret)
} return dev_err_probe(dev, ret,
if (SLAVE_IRQ != setup_interrupt(SLAVE_GPIO)) { "request_irq failed for irq %d\n",
pr_err("failed to setup gpio %d as irq\n", SLAVE_GPIO); ixp_clock.master_irq);
goto no_slave;
} ret = devm_request_irq(dev, ixp_clock.slave_irq, isr,
0, DRIVER, &ixp_clock);
if (ret)
return dev_err_probe(dev, ret,
"request_irq failed for irq %d\n",
ixp_clock.slave_irq);
return 0; return 0;
no_slave:
free_irq(MASTER_IRQ, &ixp_clock);
no_master:
ptp_clock_unregister(ixp_clock.ptp_clock);
return -ENODEV;
} }
module_init(ptp_ixp_init); static const struct of_device_id ptp_ixp_match[] = {
module_exit(ptp_ixp_exit); {
.compatible = "intel,ixp46x-ptp-timer",
},
{ },
};
static struct platform_driver ptp_ixp_driver = {
.driver = {
.name = "ptp-ixp46x",
.of_match_table = ptp_ixp_match,
.suppress_bind_attrs = true,
},
.probe = ptp_ixp_probe,
};
module_platform_driver(ptp_ixp_driver);
MODULE_AUTHOR("Richard Cochran <richardcochran@gmail.com>"); MODULE_AUTHOR("Richard Cochran <richardcochran@gmail.com>");
MODULE_DESCRIPTION("PTP clock using the IXP46X timer"); MODULE_DESCRIPTION("PTP clock using the IXP46X timer");
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment