Skip to content

Commit 41094a2

Browse files
authored
Merge pull request #173 from RobertCNelson/PocketBeagle
source/common.c: add initial PocketBeagle values
2 parents ff0684a + c35e4cb commit 41094a2

File tree

2 files changed

+139
-12
lines changed

2 files changed

+139
-12
lines changed

source/c_pwm.c

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -313,10 +313,11 @@ BBIO_err pwm_setup(const char *key, __attribute__ ((unused)) float duty, __attri
313313
char pwm_addr_path[60]; // "/sys/devices/platform/ocp/48300000.epwmss/48300200.ehrpwm"
314314
char pwm_chip_path[75]; // "/sys/devices/platform/ocp/48300000.epwmss/48300200.ehrpwm/pwm/pwmchip0"
315315
char pwm_export_path[80]; // "/sys/devices/platform/ocp/48300000.epwmss/48300200.ehrpwm/pwm/pwmchip0/export"
316-
char pwm_path[80]; // "/sys/devices/platform/ocp/48300000.epwmss/48300200.ehrpwm/pwm/pwmchip0/pwm1"
317-
char duty_path[90]; // "/sys/devices/platform/ocp/48300000.epwmss/48300200.ehrpwm/pwm/pwmchip0/pwm1/duty_cycle"
318-
char period_path[90];
319-
char polarity_path[90];
316+
char pwm_path[85]; // "/sys/devices/platform/ocp/48300000.epwmss/48300200.ehrpwm/pwm/pwmchip0/pwm1"
317+
char pwm_path_udev[85]; // "/sys/devices/platform/ocp/48300000.epwmss/48300200.ehrpwm/pwm/pwmchip0/pwm-0:1"
318+
char duty_path[95]; // "/sys/devices/platform/ocp/48300000.epwmss/48300200.ehrpwm/pwm/pwmchip0/pwm1/duty_cycle"
319+
char period_path[95];
320+
char polarity_path[95];
320321
char enable_path[90];
321322
char pin_mode[PIN_MODE_LEN]; // "pwm" or "pwm2"
322323

@@ -348,7 +349,8 @@ BBIO_err pwm_setup(const char *key, __attribute__ ((unused)) float duty, __attri
348349
|| device_tree_loaded("univ-nhdmi"))) // ""
349350
{
350351
syslog(LOG_ERR, "pwm_setup: %s no suitable cape loaded", key);
351-
return BBIO_CAPE;
352+
//FIXME; Assume U-Boot did the work...
353+
//return BBIO_CAPE;
352354
}
353355
// Do pinmuxing
354356
if(!strcmp(key, "P9_28")) {
@@ -386,6 +388,11 @@ BBIO_err pwm_setup(const char *key, __attribute__ ((unused)) float duty, __attri
386388
}
387389

388390
snprintf(pwm_path, sizeof(pwm_path), "%s/pwm%d", pwm_chip_path, p->index);
391+
syslog(LOG_DEBUG, "pwm_start: %s, %s", key, pwm_path);
392+
393+
//pwm with udev patch
394+
snprintf(pwm_path_udev, sizeof(pwm_path_udev), "%s/pwm-%c:%d", pwm_chip_path, pwm_path[66], p->index);
395+
syslog(LOG_DEBUG, "pwm_start: %s, %s", key, pwm_path_udev);
389396

390397
// Export PWM if hasn't already been
391398
e = stat(pwm_path, &s);
@@ -421,7 +428,17 @@ BBIO_err pwm_setup(const char *key, __attribute__ ((unused)) float duty, __attri
421428
if (ENOENT == errno) {
422429
// Directory still doesn't exist, exit with error
423430
syslog(LOG_ERR, "pwm_setup: %s %s doesn't exist", key, pwm_path);
424-
return BBIO_GEN;
431+
//return BBIO_GEN;
432+
433+
e = stat(pwm_path_udev, &s);
434+
if (-1 == e) {
435+
if (ENOENT == errno) {
436+
// Directory still doesn't exist, exit with error
437+
syslog(LOG_ERR, "pwm_setup: %s %s doesn't exist", key, pwm_path_udev);
438+
return BBIO_GEN;
439+
}
440+
}
441+
strncpy(pwm_path, pwm_path_udev, sizeof(pwm_path_udev));
425442
}
426443
}
427444

@@ -564,11 +581,12 @@ BBIO_err pwm_start(const char *key, float duty, float freq, int polarity)
564581
return BBIO_GEN;
565582
}
566583

567-
err = pwm_set_polarity(key, polarity);
568-
if (err != BBIO_OK) {
569-
syslog(LOG_ERR, "pwm_start: %s couldn't set polarity: %i", key, err);
570-
return err;
571-
}
584+
//FIXME: polarity set broken in v4.9.x/v4.14.x
585+
// err = pwm_set_polarity(key, polarity);
586+
// if (err != BBIO_OK) {
587+
// syslog(LOG_ERR, "pwm_start: %s couldn't set polarity: %i", key, err);
588+
// return err;
589+
// }
572590

573591
// Read out current period_ns from the file, in order for it to behave
574592
// properly

source/common.c

Lines changed: 110 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,80 @@ pins_t table[] = {
180180

181181
{ "PAUSE", "P8_9", 69, 1, -1},
182182
{ "MODE", "P8_10", 68, 1, -1},
183-
183+
184+
// These are for the PocketBeagle
185+
{ "VIN_AC", "P1_1", 0, -1, -1},
186+
{ "GPIO2_23", "P1_2", 87, -1, -1},
187+
{ "USB1_VBUS_OUT", "P1_3", 0, -1, -1},
188+
{ "GPIO2_25", "P1_4", 89, -1, -1},
189+
{ "USB1_VBUS_IN", "P1_5", 0, -1, -1},
190+
{ "SPI0_CS0", "P1_6", 5, -1, -1},
191+
{ "VIN-USB", "P1_7", 0, -1, -1},
192+
{ "SPI0_SCLK", "P1_8", 2, 3, -1},
193+
{ "USB1-DN", "P1_9", 0, -1, -1},
194+
{ "SPI0_D0", "P1_10", 3, 3, -1},
195+
{ "USB1-DP", "P1_11", 0, -1, -1},
196+
{ "SPI0_D1", "P1_12", 4, -1, -1},
197+
{ "USB1-ID", "P1_13", 0, -1, -1},
198+
{ "VOUT-3.3V", "P1_14", 0, -1, -1},
199+
{ "GND", "P1_15", 0, -1, -1},
200+
{ "GND", "P1_16", 0, -1, -1},
201+
{ "VREFN", "P1_17", 0, -1, -1},
202+
{ "VREFP", "P1_18", 0, -1, -1},
203+
{ "AIN0", "P1_19", 0, -1, 0},
204+
{ "GPIO0_20", "P1_20", 20, -1, -1},
205+
{ "AIN1", "P1_21", 0, -1, 1},
206+
{ "GND", "P1_22", 0, -1, -1},
207+
{ "AIN2", "P1_23", 0, -1, 2},
208+
{ "VOUT-5V", "P1_24", 0, -1, -1},
209+
{ "AIN3", "P1_25", 0, -1, 3},
210+
{ "I2C2_SDA", "P1_26", 12, -1, -1},
211+
{ "AIN4", "P1_27", 0, -1, 4},
212+
{ "I2C2_SCL", "P1_28", 13, -1, -1},
213+
{ "GPIO3_21", "P1_29", 117, -1, -1},
214+
{ "UART0_TXD", "P1_30", 43, -1, -1},
215+
{ "GPIO3_18", "P1_31", 114, -1, -1},
216+
{ "UART0_RXD", "P1_32", 42, -1, -1},
217+
{ "GPIO3_15", "P1_33", 111, 1, -1},
218+
{ "GPIO0_26", "P1_34", 26, -1, -1},
219+
{ "GPIO2_24", "P1_35", 88, -1, -1},
220+
{ "EHRPWM0A", "P1_36", 110, 1, -1},
221+
{ "EHRPWM1A", "P2_1", 50, 6, -1},
222+
{ "GPIO1_27", "P2_2", 59, -1, -1},
223+
{ "GPIO0_23", "P2_3", 23, 4, -1},
224+
{ "GPIO1_26", "P2_4", 58, -1, -1},
225+
{ "UART4_RXD", "P2_5", 30, -1, -1},
226+
{ "GPIO1_25", "P2_6", 57, -1, -1},
227+
{ "UART4_TXD", "P2_7", 31, -1, -1},
228+
{ "GPIO1_28", "P2_8", 60, -1, -1},
229+
{ "I2C1_SCL", "P2_9", 15, -1, -1},
230+
{ "GPIO1_20", "P2_10", 52, -1, -1},
231+
{ "I2C1_SDA", "P2_11", 14, -1, -1},
232+
{ "POWER_BUTTON", "P2_12", 0, -1, -1},
233+
{ "VOUT-5V", "P2_13", 0, -1, -1},
234+
{ "BAT-VIN", "P2_14", 0, -1, -1},
235+
{ "GND", "P2_15", 0, -1, -1},
236+
{ "BAT-TEMP", "P2_16", 0, -1, -1},
237+
{ "GPIO2_1", "P2_17", 65, -1, -1},
238+
{ "GPIO1_15", "P2_18", 47, -1, -1},
239+
{ "GPIO0_27", "P2_19", 27, -1, -1},
240+
{ "GPIO2_0", "P2_20", 64, -1, -1},
241+
{ "GND", "P2_21", 0, -1, -1},
242+
{ "GPIO1_14", "P2_22", 46, -1, -1},
243+
{ "VOUT-3.3V", "P2_23", 0, -1, -1},
244+
{ "GPIO1_16", "P2_24", 48, -1, -1},
245+
{ "SPI1_CS0", "P2_25", 41, -1, -1},
246+
{ "RESET#", "P2_26", 0, -1, -1},
247+
{ "SPI1_D0", "P2_27", 40, -1, -1},
248+
{ "GPIO3_20", "P2_28", 116, -1, -1},
249+
{ "SPI1_SCLK", "P2_29", 7, -1, -1},
250+
{ "GPIO3_17", "P2_30", 113, -1, -1},
251+
{ "SPI1_CS1", "P2_31", 19, -1, -1},
252+
{ "GPIO3_16", "P2_32", 112, -1, -1},
253+
{ "GPIO1_13", "P2_33", 45, -1, -1},
254+
{ "GPIO3_19", "P2_34", 115, -1, -1},
255+
{ "GPIO2_22", "P2_35", 86, -1, -1},
256+
{ "AIN7", "P2_36", 0, -1, 7},
184257

185258
{ NULL, NULL, 0, 0, 0 }
186259
};
@@ -220,6 +293,12 @@ pwm_t pwm_table[] = {
220293
{ "ehrpwm0", 1, 1, 1, "ehrpwm.0:1", "EHRPWM0B", "48300000", "48300200", "P9_29"},
221294
{ "ehrpwm0", 0, 0, 1, "ehrpwm.0:0", "EHRPWM0A", "48300000", "48300200", "P9_31"},
222295
{ "ecap0", 2, 0, 0, "ecap.0", "ECAPPWM0", "48300000", "48300100", "P9_42"},
296+
{ "ehrpwm0", 0, 0, 1, "ehrpwm.0:0", "EHRPWM0A", "48300000", "48300200", "P1_8"},
297+
{ "ehrpwm0", 0, 0, 1, "ehrpwm.0:0", "EHRPWM0A", "48300000", "48300200", "P1_36"},
298+
{ "ehrpwm0", 1, 1, 1, "ehrpwm.0:1", "EHRPWM0B", "48300000", "48300200", "P1_10"},
299+
{ "ehrpwm0", 1, 1, 1, "ehrpwm.0:1", "EHRPWM0B", "48300000", "48300200", "P1_13"},
300+
{ "ehrpwm1", 3, 0, 6, "ehrpwm.1:0", "EHRPWM1A", "48302000", "48302200", "P2_1"},
301+
{ "ehrpwm2", 6, 1, 3, "ehrpwm.2:1", "EHRPWM2B", "48304000", "48304200", "P2_3"},
223302
{ NULL, 0, 0, 0, NULL, NULL, NULL, NULL, NULL }
224303
};
225304

@@ -482,6 +561,28 @@ int uboot_overlay_enabled(void) {
482561
}
483562
}
484563

564+
/*
565+
PocketBeagle has everything built-in to the main dtb
566+
*/
567+
int pocketbeagle(void) {
568+
const char *cmd = "/bin/grep -c 'TI AM335x PocketBeagle' /proc/device-tree/model";
569+
char pocketbeagle;
570+
FILE *file = NULL;
571+
572+
file = popen(cmd, "r");
573+
if (file == NULL) {
574+
fprintf(stderr, "error: pocketbeagle() failed to run cmd=%s\n", cmd);
575+
return -1;
576+
}
577+
pocketbeagle = fgetc(file);
578+
pclose(file);
579+
580+
if(pocketbeagle == '1') {
581+
return 1;
582+
} else {
583+
return 0;
584+
}
585+
}
485586

486587
BBIO_err load_device_tree(const char *name)
487588
{
@@ -504,6 +605,10 @@ BBIO_err load_device_tree(const char *name)
504605
return BBIO_OK;
505606
}
506607

608+
if(pocketbeagle()) {
609+
return BBIO_OK;
610+
}
611+
507612
snprintf(slots, sizeof(slots), "%s/slots", ctrl_dir);
508613

509614
file = fopen(slots, "r+");
@@ -554,6 +659,10 @@ int device_tree_loaded(const char *name)
554659
return 1;
555660
}
556661

662+
if(pocketbeagle()) {
663+
return BBIO_OK;
664+
}
665+
557666
snprintf(slots, sizeof(slots), "%s/slots", ctrl_dir);
558667

559668

0 commit comments

Comments
 (0)