Skip to content

Commit bb653da

Browse files
committed
ppps: add support for separate USB-3 PPPS path
Some devices / hubs require switching both USB-2 and USB-3 ports to function correctly. Add ppps3_path device option to control USB-3 port in addition to the USB-2 port. Signed-off-by: Dmitry Baryshkov <[email protected]>
1 parent df832c0 commit bb653da

File tree

3 files changed

+33
-14
lines changed

3 files changed

+33
-14
lines changed

device.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ struct device {
3636
char *serial;
3737
char *description;
3838
char *ppps_path;
39+
char *ppps3_path;
3940
struct list_head *users;
4041
unsigned voltage;
4142
bool tickle_mmc;

device_parser.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,8 @@ static void parse_board(struct device_parser *dp)
189189
dev->usb_always_on = !strcmp(value, "true");
190190
} else if (!strcmp(key, "ppps_path")) {
191191
dev->ppps_path = strdup(value);
192+
} else if (!strcmp(key, "ppps3_path")) {
193+
dev->ppps3_path = strdup(value);
192194
} else {
193195
fprintf(stderr, "device parser: unknown key \"%s\"\n", key);
194196
exit(1);

ppps.c

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -45,33 +45,49 @@
4545

4646
#include "device.h"
4747

48-
#define PPPS_BASE_PATH "/sys/bus/usb/devices"
49-
#define PPPS_BASE_PATH_LEN strlen(PPPS_BASE_PATH)
48+
#define PPPS_BASE_PATH "/sys/bus/usb/devices/%s/disable"
5049

51-
void ppps_power(struct device *dev, bool on)
50+
void ppps_power_path(const char *ppps_path, bool on)
5251
{
53-
static char *path = NULL;
5452
int rc, fd;
5553

56-
/* Only need to figure out the whole string once */
57-
if (!path) {
58-
/* ppps_path should be like "2-2:1.0/2-2-port2" */
59-
asprintf(&path, "%s/%s/disable", PPPS_BASE_PATH, dev->ppps_path);
60-
}
61-
62-
// fprintf(stderr, "ppps_power: %-3s %s\n", on ? "on" : "off", path);
54+
//fprintf(stderr, "ppps_power: %-3s %s\n", on ? "on" : "off", path);
6355

64-
fd = open(path, O_WRONLY);
56+
fd = open(ppps_path, O_WRONLY);
6557
if (fd < 0) {
66-
fprintf(stderr, "failed to open %s: %s\n", path, strerror(errno));
58+
fprintf(stderr, "failed to open %s: %s\n", ppps_path, strerror(errno));
6759
if (errno != ENOENT)
6860
fprintf(stderr, "Maybe missing permissions (see https://git.io/JIB2Z)\n");
6961
return;
7062
}
7163

7264
rc = write(fd, on ? "0" : "1", 1);
7365
if (rc < 0)
74-
fprintf(stderr, "failed to write to %s: %s\n", path, strerror(errno));
66+
fprintf(stderr, "failed to write to %s: %s\n", ppps_path, strerror(errno));
7567

7668
close(fd);
7769
}
70+
71+
void ppps_power(struct device *dev, bool on)
72+
{
73+
/* ppps_path should be like "2-2:1.0/2-2-port2" */
74+
if (dev->ppps_path[0] != '/') {
75+
char *temp;
76+
77+
asprintf(&temp, PPPS_BASE_PATH, dev->ppps_path);
78+
free(dev->ppps_path);
79+
dev->ppps_path = temp;
80+
}
81+
82+
if (dev->ppps3_path[0] != '/') {
83+
char *temp;
84+
85+
asprintf(&temp, PPPS_BASE_PATH, dev->ppps3_path);
86+
free(dev->ppps3_path);
87+
dev->ppps3_path = temp;
88+
}
89+
90+
ppps_power_path(dev->ppps_path, on);
91+
if (dev->ppps3_path)
92+
ppps_power_path(dev->ppps3_path, on);
93+
}

0 commit comments

Comments
 (0)