From: Yangbo Lu <yangbo.lu@nxp.com>
To: linux-kernel@vger.kernel.org, netdev@vger.kernel.org
Cc: Yangbo Lu <yangbo.lu@nxp.com>,
"David S . Miller" <davem@davemloft.net>,
Richard Cochran <richardcochran@gmail.com>,
Vladimir Oltean <vladimir.oltean@nxp.com>,
Claudiu Manoil <claudiu.manoil@nxp.com>,
Andrew Lunn <andrew@lunn.ch>,
Vivien Didelot <vivien.didelot@gmail.com>,
Florian Fainelli <f.fainelli@gmail.com>,
Alexandre Belloni <alexandre.belloni@bootlin.com>,
Microchip Linux Driver Support <UNGLinuxDriver@microchip.com>
Subject: [PATCH 6/6] ptp_ocelot: support 4 programmable pins
Date: Fri, 20 Mar 2020 18:37:26 +0800 [thread overview]
Message-ID: <20200320103726.32559-7-yangbo.lu@nxp.com> (raw)
In-Reply-To: <20200320103726.32559-1-yangbo.lu@nxp.com>
Support 4 programmable pins for only one function periodic
signal for now. Since the hardware is not able to support
absolute start time, driver starts periodic signal immediately.
Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com>
---
drivers/ptp/ptp_ocelot.c | 97 ++++++++++++++++++++++++++++++++++++++++++++++-
include/soc/mscc/ocelot.h | 3 ++
2 files changed, 98 insertions(+), 2 deletions(-)
diff --git a/drivers/ptp/ptp_ocelot.c b/drivers/ptp/ptp_ocelot.c
index 59420a7..299928e 100644
--- a/drivers/ptp/ptp_ocelot.c
+++ b/drivers/ptp/ptp_ocelot.c
@@ -164,26 +164,119 @@ static int ocelot_ptp_adjfine(struct ptp_clock_info *ptp, long scaled_ppm)
return 0;
}
+static int ocelot_ptp_verify(struct ptp_clock_info *ptp, unsigned int pin,
+ enum ptp_pin_function func, unsigned int chan)
+{
+ switch (func) {
+ case PTP_PF_NONE:
+ case PTP_PF_PEROUT:
+ break;
+ case PTP_PF_EXTTS:
+ case PTP_PF_PHYSYNC:
+ return -1;
+ }
+ return 0;
+}
+
+static int ocelot_ptp_enable(struct ptp_clock_info *ptp,
+ struct ptp_clock_request *rq, int on)
+{
+ struct ocelot *ocelot = container_of(ptp, struct ocelot, ptp_info);
+ enum ocelot_ptp_pins ptp_pin;
+ struct timespec64 ts;
+ unsigned long flags;
+ int pin = -1;
+ u32 val;
+ s64 ns;
+
+ switch (rq->type) {
+ case PTP_CLK_REQ_PEROUT:
+ /* Reject requests with unsupported flags */
+ if (rq->perout.flags)
+ return -EOPNOTSUPP;
+
+ /*
+ * TODO: support disabling function
+ * When ptp_disable_pinfunc() is to disable function,
+ * it has already held pincfg_mux.
+ * However ptp_find_pin() in .enable() called also needs
+ * to hold pincfg_mux.
+ * This causes dead lock. So, just return for function
+ * disabling, and this needs fix-up.
+ */
+ if (!on)
+ break;
+
+ pin = ptp_find_pin(ocelot->ptp_clock, PTP_PF_PEROUT,
+ rq->perout.index);
+ if (pin == 0)
+ ptp_pin = PTP_PIN_0;
+ else if (pin == 1)
+ ptp_pin = PTP_PIN_1;
+ else if (pin == 2)
+ ptp_pin = PTP_PIN_2;
+ else if (pin == 3)
+ ptp_pin = PTP_PIN_3;
+ else
+ return -EINVAL;
+
+ ts.tv_sec = rq->perout.period.sec;
+ ts.tv_nsec = rq->perout.period.nsec;
+ ns = timespec64_to_ns(&ts);
+ ns = ns >> 1;
+ if (ns > 0x3fffffff || ns <= 0x6)
+ return -EINVAL;
+
+ spin_lock_irqsave(&ocelot->ptp_clock_lock, flags);
+ ocelot_write_rix(ocelot, ns, PTP_PIN_WF_LOW_PERIOD, ptp_pin);
+ ocelot_write_rix(ocelot, ns, PTP_PIN_WF_HIGH_PERIOD, ptp_pin);
+
+ val = PTP_PIN_CFG_ACTION(PTP_PIN_ACTION_CLOCK);
+ ocelot_write_rix(ocelot, val, PTP_PIN_CFG, ptp_pin);
+ spin_unlock_irqrestore(&ocelot->ptp_clock_lock, flags);
+ dev_warn(ocelot->dev,
+ "Starting periodic signal now! (absolute start time not supported)\n");
+ break;
+ default:
+ return -EOPNOTSUPP;
+ }
+ return 0;
+}
+
static struct ptp_clock_info ocelot_ptp_clock_info = {
.owner = THIS_MODULE,
.name = "ocelot ptp",
.max_adj = 0x7fffffff,
.n_alarm = 0,
.n_ext_ts = 0,
- .n_per_out = 0,
- .n_pins = 0,
+ .n_per_out = OCELOT_PTP_PINS_NUM,
+ .n_pins = OCELOT_PTP_PINS_NUM,
.pps = 0,
.gettime64 = ocelot_ptp_gettime64,
.settime64 = ocelot_ptp_settime64,
.adjtime = ocelot_ptp_adjtime,
.adjfine = ocelot_ptp_adjfine,
+ .verify = ocelot_ptp_verify,
+ .enable = ocelot_ptp_enable,
};
int ocelot_init_timestamp(struct ocelot *ocelot)
{
struct ptp_clock *ptp_clock;
+ int i;
ocelot->ptp_info = ocelot_ptp_clock_info;
+
+ for (i = 0; i < OCELOT_PTP_PINS_NUM; i++) {
+ struct ptp_pin_desc *p = &ocelot->ptp_pins[i];
+
+ snprintf(p->name, sizeof(p->name), "switch_1588_dat%d", i);
+ p->index = i;
+ p->func = PTP_PF_NONE;
+ }
+
+ ocelot->ptp_info.pin_config = &ocelot->ptp_pins[0];
+
ptp_clock = ptp_clock_register(&ocelot->ptp_info, ocelot->dev);
if (IS_ERR(ptp_clock))
return PTR_ERR(ptp_clock);
diff --git a/include/soc/mscc/ocelot.h b/include/soc/mscc/ocelot.h
index bcce278..db2fb14 100644
--- a/include/soc/mscc/ocelot.h
+++ b/include/soc/mscc/ocelot.h
@@ -92,6 +92,8 @@
#define OCELOT_SPEED_100 2
#define OCELOT_SPEED_10 3
+#define OCELOT_PTP_PINS_NUM 4
+
#define TARGET_OFFSET 24
#define REG_MASK GENMASK(TARGET_OFFSET - 1, 0)
#define REG(reg, offset) [reg & REG_MASK] = offset
@@ -544,6 +546,7 @@ struct ocelot {
struct mutex ptp_lock;
/* Protects the PTP clock */
spinlock_t ptp_clock_lock;
+ struct ptp_pin_desc ptp_pins[OCELOT_PTP_PINS_NUM];
};
#define ocelot_read_ix(ocelot, reg, gi, ri) __ocelot_read_ix(ocelot, reg, reg##_GSZ * (gi) + reg##_RSZ * (ri))
--
2.7.4
next prev parent reply other threads:[~2020-03-20 10:41 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-03-20 10:37 [PATCH 0/6] Support programmable pins for Ocelot PTP driver Yangbo Lu
2020-03-20 10:37 ` [PATCH 1/6] ptp: move ocelot ptp clock code out of Ethernet driver Yangbo Lu
2020-03-20 16:37 ` Vladimir Oltean
2020-03-24 4:46 ` Y.b. Lu
2020-03-20 21:31 ` kbuild test robot
2020-03-20 23:03 ` kbuild test robot
2020-03-20 10:37 ` [PATCH 2/6] MAINTAINERS: add entry for Microsemi Ocelot PTP driver Yangbo Lu
2020-03-20 17:28 ` Alexandre Belloni
2020-03-24 4:50 ` Y.b. Lu
2020-03-20 10:37 ` [PATCH 3/6] net: mscc: ocelot: fix timestamp info if ptp clock does not work Yangbo Lu
2020-03-20 10:37 ` [PATCH 4/6] net: mscc: ocelot: redefine PTP pins Yangbo Lu
2020-03-20 10:37 ` [PATCH 5/6] net: mscc: ocelot: add wave programming registers definitions Yangbo Lu
2020-03-20 10:37 ` Yangbo Lu [this message]
2020-03-20 13:20 ` [PATCH 6/6] ptp_ocelot: support 4 programmable pins Vladimir Oltean
2020-03-24 5:21 ` Y.b. Lu
2020-03-24 13:19 ` Richard Cochran
2020-03-25 3:20 ` Y.b. Lu
2020-03-24 9:24 ` Horatiu Vultur
2020-03-24 13:07 ` Richard Cochran
2020-03-25 3:08 ` Y.b. Lu
2020-03-25 13:41 ` Richard Cochran
2020-03-26 9:34 ` Y.b. Lu
2020-03-26 13:59 ` Richard Cochran
2020-03-27 5:47 ` Y.b. Lu
2020-03-31 4:18 ` Y.b. Lu
2020-03-25 13:15 ` Richard Cochran
2020-03-26 9:25 ` Y.b. Lu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200320103726.32559-7-yangbo.lu@nxp.com \
--to=yangbo.lu@nxp.com \
--cc=UNGLinuxDriver@microchip.com \
--cc=alexandre.belloni@bootlin.com \
--cc=andrew@lunn.ch \
--cc=claudiu.manoil@nxp.com \
--cc=davem@davemloft.net \
--cc=f.fainelli@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=richardcochran@gmail.com \
--cc=vivien.didelot@gmail.com \
--cc=vladimir.oltean@nxp.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).