Commit c8e46bbb authored by Adam Wujek's avatar Adam Wujek 💬

Merge function to enable/disable PPS-in termination

Signed-off-by: Adam Wujek's avatarAdam Wujek <adam.wujek@cern.ch>
parents 09f7e0b5 1ec5593b
......@@ -976,6 +976,12 @@ config NIC_THROTTLING_VAL
endmenu
config PPS_IN_TERM_50OHM
bool "Enable 50ohm termination for 1-PPS input"
default n
help
Enable 50ohm termination for 1-PPS input.
menu "Custom boot script configuration"
config CUSTOM_BOOT_SCRIPT_ENABLED
bool "Execute custom script"
......
......@@ -972,6 +972,9 @@ appropriate way, before the respective service is started.
@t{CONFIG_NIC_THROTTLING_VAL} contains maximum allowed bandwidth
in KB/s.
@item CONFIG_PPS_IN_TERM_50OHM
Enable 50ohm termination for 1-PPS input.
@item CONFIG_CUSTOM_BOOT_SCRIPT_ENABLED
@itemx CONFIG_CUSTOM_BOOT_SCRIPT_SOURCE_LOCAL
@itemx CONFIG_CUSTOM_BOOT_SCRIPT_SOURCE_REMOTE
......@@ -1853,11 +1856,17 @@ The following tools and scripts are provided:
(This is probably the most important diagnostic tool on the switch.)
@item wrs_pps_control
A tool to switch the PPS output on and off. Usage: ``@t{wrs_pps_control
on}'' switches the PPS output on, and ``@t{wrs_pps_control off}''
switches the PPS output off. Switching the output on/off is independent
A tool to switch the PPS output on and off or reads its setting.
It can also on/off/read the 50ohm termination for 1-PPS input.
Usage: ``@t{wrs_pps_control pps on}'' switches the PPS output on,
``@t{wrs_pps_control pps off}'' switches the PPS output off, and
``@t{wrs_pps_control pps read}'' check whether PPS output is set to
on or off. Switching the output on/off is independent
of the PPSi process, but PPSi switches the PPS output back on when a
link restart is detected and PPSi comes into @t{'TRACK_PHASE'} state.
To on/off/read the 50ohm termination for 1-PPS input use
@t{wrs_pps_control} with a parameter @t{50ohm-term-in} followed by
@t{on}, @t{off} or @t{read}.
@item wr_date
......
......@@ -84,6 +84,9 @@
/* definitions for field: Set nanoseconds counter in reg: External sync control register */
#define PPSG_ESCR_NSEC_SET WBGEN2_GEN_MASK(4, 1)
/* definitions for field: Enable PPS_IN 50Ohm termination in reg: External sync control register */
#define PPSG_ESCR_PPS_IN_TERM WBGEN2_GEN_MASK(5, 1)
PACKED struct PPSG_WB {
/* [0x0]: REG Control Register */
uint32_t CR;
......
......@@ -210,6 +210,18 @@ peripheral {
clock = "refclk_i";
};
field {
name = "Enable PPS_IN 50Ohm termination";
description = "write 1: enable 50ohm termination for 1-PPS input \
write 0: disable 50ohm termination for 1-PPS input \
read 1: 50ohm termination for 1-PPS input enabled \
read 0: 50ohm termination for 1-PPS input disabled";
prefix = "PPS_IN_TERM";
type = BIT;
access_bus = READ_WRITE;
access_dev = READ_ONLY;
};
};
};
......@@ -9,6 +9,12 @@
#define PPSG_ADJUST_SEC 0x1
#define PPSG_ADJUST_NSEC 0x2
#define PPSG_PPS_OUT_ENABLE 0x1
#define PPSG_PPS_OUT_DISABLE 0x0
#define PPSG_PPS_IN_TERM_50OHM_ENABLE 0x1
#define PPSG_PPS_IN_TERM_50OHM_DISABLE 0x0
/* Initializes the PPS Generator. 0 on success, negative on failure. */
int shw_pps_gen_init(void);
......@@ -21,7 +27,19 @@ int shw_pps_gen_busy(void);
/* Enables/disables PPS Generator PPS output */
int shw_pps_gen_enable_output(int enable);
/* Reads PPS Generator PPS output */
int shw_pps_gen_enable_output_read(void);
/* Reads the current time and stores at <seconds,nanoseconds>. */
void shw_pps_gen_read_time(uint64_t * seconds, uint32_t * nanoseconds);
/* Enables PPS_IN 50Ohm termination */
void shw_pps_gen_in_term_enable(int enable);
/* Reads status of PPS_IN 50Ohm termination */
int shw_pps_gen_in_term_read(void);
/* Enables PPS_IN 50Ohm termination based on dot-config option */
int shw_pps_gen_in_term_init(void);
#endif /* __LIBWR_PPS_GEN_H */
......@@ -7,6 +7,7 @@
#include "i2c_sfp.h"
#include <libwr/shw_io.h>
#include <libwr/wrs-msg.h>
#include <libwr/pps_gen.h>
int shw_init()
{
......@@ -31,6 +32,9 @@ int shw_init()
/* Init the FANs */
assert_init(shw_init_fans());
/* Set 50ohm termination on 1-PPS in if needed */
assert_init(shw_pps_gen_in_term_init());
pr_info("HW initialization done!\n");
return 0;
}
......
......@@ -15,6 +15,7 @@
#include <libwr/switch_hw.h>
#include <libwr/wrs-msg.h>
#include <libwr/config.h>
/* Default width (in 8ns units) of the pulses on the PPS output */
#define PPS_WIDTH 100000
......@@ -85,6 +86,15 @@ int shw_pps_gen_enable_output(int enable)
return 0;
}
/* Enables/disables PPS output */
int shw_pps_gen_enable_output_read(void)
{
uint32_t escr = ppsg_read(ESCR);
return escr & PPSG_ESCR_PPS_VALID ?
PPSG_PPS_OUT_ENABLE : PPSG_PPS_OUT_DISABLE;
}
void shw_pps_gen_read_time(uint64_t * seconds, uint32_t * nanoseconds)
{
uint32_t ns_cnt;
......@@ -105,3 +115,50 @@ void shw_pps_gen_read_time(uint64_t * seconds, uint32_t * nanoseconds)
if (nanoseconds)
*nanoseconds = ns_cnt;
}
void shw_pps_gen_in_term_enable(int enable)
{
uint32_t escr = ppsg_read(ESCR);
if (enable)
ppsg_write(ESCR, escr | PPSG_ESCR_PPS_IN_TERM);
else
ppsg_write(ESCR, escr & ~PPSG_ESCR_PPS_IN_TERM);
}
int shw_pps_gen_in_term_read(void)
{
uint32_t escr = ppsg_read(ESCR);
return escr & PPSG_ESCR_PPS_IN_TERM ?
PPSG_PPS_IN_TERM_50OHM_ENABLE : PPSG_PPS_IN_TERM_50OHM_DISABLE;
}
/* Enable PPS_IN 50Ohm termination based on dot-config option */
int shw_pps_gen_in_term_init(void)
{
char *config_item;
config_item = libwr_cfg_get("PPS_IN_TERM_50OHM");
if ((config_item) && !strcmp(config_item, "y")) {
pr_info("Enabling 50ohm termination on 1-PPS in\n");
shw_pps_gen_in_term_enable(PPSG_PPS_IN_TERM_50OHM_ENABLE);
if (shw_pps_gen_in_term_read()
!= PPSG_PPS_IN_TERM_50OHM_ENABLE) {
pr_err("Unable to enable 50ohm termination on 1-PPS "
"in\n");
}
} else if (shw_pps_gen_in_term_read()
== PPSG_PPS_IN_TERM_50OHM_ENABLE) {
pr_info("Disabling previously enabled 50ohm termination on "
"1-PPS in\n");
shw_pps_gen_in_term_enable(PPSG_PPS_IN_TERM_50OHM_DISABLE);
if (shw_pps_gen_in_term_read()
!= PPSG_PPS_IN_TERM_50OHM_DISABLE) {
pr_err("Unable to disable 50ohm termination on 1-PPS "
"in\n");
}
}
return 0;
}
......@@ -6,9 +6,6 @@
#include <libwr/switch_hw.h>
#include <libwr/pps_gen.h>
#define PPS_ON 1
#define PPS_OFF 0
void help(char *prgname)
{
fprintf(stderr, "%s: Use: \"%s [<options>] <cmd>\n",
......@@ -18,8 +15,8 @@ void help(char *prgname)
" -h print help\n"
"\n"
" Commands are:\n"
" on - switch PPS output on.\n"
" off - switch PPS output off.\n");
" pps <on|off|read> - switch PPS output on/off.\n"
" 50ohm-term-in <on|off|read> - on/off/read 50ohm termination for 1-PPS input\n");
exit(1);
}
......@@ -36,14 +33,62 @@ int main(int argc, char *argv[])
}
if (argc > 1) {
if (strcmp(argv[1], "on") == 0) {
assert_init(shw_fpga_mmap_init());
shw_pps_gen_enable_output(PPS_ON);
exit(0);
} else if (strcmp(argv[1], "off") == 0) {
assert_init(shw_fpga_mmap_init());
shw_pps_gen_enable_output(PPS_OFF);
exit(0);
if (!strcmp(argv[1], "pps")) {
if (argc < 3) {
printf("No parameter given\n;");
exit(1);
}
if (!strcmp(argv[2], "on")) {
assert_init(shw_fpga_mmap_init());
shw_pps_gen_enable_output(PPSG_PPS_OUT_ENABLE);
exit(0);
} else if (!strcmp(argv[2], "off")) {
assert_init(shw_fpga_mmap_init());
shw_pps_gen_enable_output(PPSG_PPS_OUT_DISABLE);
exit(0);
} else if (!strcmp(argv[2], "read")) {
assert_init(shw_fpga_mmap_init());
if (shw_pps_gen_enable_output_read()
== PPSG_PPS_OUT_ENABLE) {
printf("PPS output on\n;");
} else {
printf("PPS output off\n;");
}
exit(0);
} else {
printf("Unknown parameter\n;");
exit(1);
}
} else if (!strcmp(argv[1], "50ohm-term-in")) {
if (argc < 3) {
printf("No parameter given\n;");
exit(1);
}
if (!strcmp(argv[2], "on")) {
assert_init(shw_fpga_mmap_init());
shw_pps_gen_in_term_enable(
PPSG_PPS_IN_TERM_50OHM_ENABLE);
exit(0);
} else if (!strcmp(argv[2], "off")) {
assert_init(shw_fpga_mmap_init());
shw_pps_gen_in_term_enable(
PPSG_PPS_IN_TERM_50OHM_DISABLE);
exit(0);
} else if (!strcmp(argv[2], "read")) {
assert_init(shw_fpga_mmap_init());
if (shw_pps_gen_in_term_read()
== PPSG_PPS_IN_TERM_50OHM_ENABLE) {
printf("50ohm termination enabled on "
"1-PPS\n;");
} else {
printf("50ohm termination disabled on "
"1-PPS\n;");
}
exit(0);
} else {
printf("Unknown parameter\n;");
exit(1);
}
} else {
printf("Unknown command\n;");
exit(1);
......
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