Skip to content

Commit

Permalink
net: dsa: microchip: ptp: add support for perout programmable pins
Browse files Browse the repository at this point in the history
There are two programmable pins available for Trigger output unit to
generate periodic pulses. This patch add verify_pin for the available 2
pins and configure it with respect to GPIO index for the TOU unit.

Tested using testptp
./testptp -i 0 -L 0,2
./testptp -i 0 -d /dev/ptp0 -p 1000000000
./testptp -i 1 -L 1,2
./testptp -i 1 -d /dev/ptp0 -p 100000000

Signed-off-by: Arun Ramadoss <arun.ramadoss@microchip.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Arun Ramadoss authored and David S. Miller committed Jan 13, 2023
1 parent 1f12ae5 commit 343d3bd
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
35 changes: 35 additions & 0 deletions drivers/net/dsa/microchip/ksz_ptp.c
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,10 @@ static int ksz_ptp_enable_perout(struct ksz_device *dev,
ptp_data->tou_mode != KSZ_PTP_TOU_IDLE)
return -EBUSY;

pin = ptp_find_pin(ptp_data->clock, PTP_PF_PEROUT, request->index);
if (pin < 0)
return -EINVAL;

data32 = FIELD_PREP(PTP_GPIO_INDEX, pin) |
FIELD_PREP(PTP_TOU_INDEX, request->index);
ret = ksz_rmw32(dev, REG_PTP_UNIT_INDEX__4,
Expand Down Expand Up @@ -779,6 +783,23 @@ static int ksz_ptp_enable(struct ptp_clock_info *ptp,
return ret;
}

static int ksz_ptp_verify_pin(struct ptp_clock_info *ptp, unsigned int pin,
enum ptp_pin_function func, unsigned int chan)
{
int ret = 0;

switch (func) {
case PTP_PF_NONE:
case PTP_PF_PEROUT:
break;
default:
ret = -1;
break;
}

return ret;
}

/* Function is pointer to the do_aux_work in the ptp_clock capability */
static long ksz_ptp_do_aux_work(struct ptp_clock_info *ptp)
{
Expand Down Expand Up @@ -822,6 +843,7 @@ int ksz_ptp_clock_register(struct dsa_switch *ds)
struct ksz_device *dev = ds->priv;
struct ksz_ptp_data *ptp_data;
int ret;
u8 i;

ptp_data = &dev->ptp_data;
mutex_init(&ptp_data->lock);
Expand All @@ -836,12 +858,25 @@ int ksz_ptp_clock_register(struct dsa_switch *ds)
ptp_data->caps.adjtime = ksz_ptp_adjtime;
ptp_data->caps.do_aux_work = ksz_ptp_do_aux_work;
ptp_data->caps.enable = ksz_ptp_enable;
ptp_data->caps.verify = ksz_ptp_verify_pin;
ptp_data->caps.n_pins = KSZ_PTP_N_GPIO;
ptp_data->caps.n_per_out = 3;

ret = ksz_ptp_start_clock(dev);
if (ret)
return ret;

for (i = 0; i < KSZ_PTP_N_GPIO; i++) {
struct ptp_pin_desc *ptp_pin = &ptp_data->pin_config[i];

snprintf(ptp_pin->name,
sizeof(ptp_pin->name), "ksz_ptp_pin_%02d", i);
ptp_pin->index = i;
ptp_pin->func = PTP_PF_NONE;
}

ptp_data->caps.pin_config = ptp_data->pin_config;

/* Currently only P2P mode is supported. When 802_1AS bit is set, it
* forwards all PTP packets to host port and none to other ports.
*/
Expand Down
3 changes: 3 additions & 0 deletions drivers/net/dsa/microchip/ksz_ptp.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

#include <linux/ptp_clock_kernel.h>

#define KSZ_PTP_N_GPIO 2

enum ksz_ptp_tou_mode {
KSZ_PTP_TOU_IDLE,
KSZ_PTP_TOU_PEROUT,
Expand All @@ -20,6 +22,7 @@ enum ksz_ptp_tou_mode {
struct ksz_ptp_data {
struct ptp_clock_info caps;
struct ptp_clock *clock;
struct ptp_pin_desc pin_config[KSZ_PTP_N_GPIO];
/* Serializes all operations on the PTP hardware clock */
struct mutex lock;
/* lock for accessing the clock_time */
Expand Down

0 comments on commit 343d3bd

Please sign in to comment.