This is an automated email from Gerrit.

"Vincent Fazio <vfa...@gmail.com>" just uploaded a new patch set to Gerrit, 
which you can find at https://review.openocd.org/c/openocd/+/7734

-- gerrit

commit f4a91f924355d74fbf73cac818acd648e57c4cf9
Author: Jacob Zarnstorff <jacobzarnsto...@gmail.com>
Date:   Wed Mar 22 10:27:05 2023 -0500

    jtag/drivers/bcm2835gpio: Configure all GPIO pads
    
    Add support for configuring all pad registers for all supported GPIO pins.
    
    Change-Id: Id0d6e94ae43e811cee1eb5248e841a0ee21427e0
    Signed-off-by: Jacob Zarnstorff <jacobzarnsto...@gmail.com>
    Signed-off-by: Vincent Fazio <vfa...@gmail.com>

diff --git a/src/jtag/drivers/bcm2835gpio.c b/src/jtag/drivers/bcm2835gpio.c
index 83d9323834..b972b70de4 100644
--- a/src/jtag/drivers/bcm2835gpio.c
+++ b/src/jtag/drivers/bcm2835gpio.c
@@ -23,8 +23,27 @@ static char *bcm2835_peri_mem_dev;
 static off_t bcm2835_peri_base = 0x20000000;
 #define BCM2835_GPIO_BASE      (bcm2835_peri_base + 0x200000) /* GPIO 
controller */
 
-#define BCM2835_PADS_GPIO_0_27         (bcm2835_peri_base + 0x100000)
-#define BCM2835_PADS_GPIO_0_27_OFFSET  (0x2c / 4)
+#define BCM2835_PADS_GPIO_BASE          (bcm2835_peri_base + 0x100000)
+#define BCM2835_PADS_GPIO_0_27_OFFSET   (0x2c / 4)
+#define BCM2835_PADS_GPIO_28_45_OFFSET  (0x30 / 4)
+#define BCM2835_PADS_GPIO_46_53_OFFSET  (0x34 / 4)
+
+#define BCM2835_PADS_GPIO_PASSWORD          (0x5a << 24)
+#define BCM2835_PADS_GPIO_SLEW_LIMITED      (0 << 4)
+#define BCM2835_PADS_GPIO_SLEW_NOT_LIMITED  (1 << 4)
+#define BCM2835_PADS_GPIO_HYST_DISABLED     (0 << 3)
+#define BCM2835_PADS_GPIO_HYST_ENABLED      (1 << 3)
+
+enum bcm2835_pads_gpio_drv {
+       DRIVE_STRENGTH_2MA,
+       DRIVE_STRENGTH_4MA,
+       DRIVE_STRENGTH_6MA,
+       DRIVE_STRENGTH_8MA,
+       DRIVE_STRENGTH_10MA,
+       DRIVE_STRENGTH_12MA,
+       DRIVE_STRENGTH_14MA,
+       DRIVE_STRENGTH_16MA,
+};
 
 /* See "GPIO Function Select Registers (GPFSELn)" in "Broadcom BCM2835 ARM 
Peripherals" datasheet. */
 #define BCM2835_GPIO_MODE_INPUT 0
@@ -94,7 +113,7 @@ static struct initial_gpio_state {
        unsigned int mode;
        unsigned int output_level;
 } initial_gpio_state[ADAPTER_GPIO_IDX_NUM];
-static uint32_t initial_drive_strength_etc;
+static uint32_t initial_drive_strengths[3];
 
 static inline const char *bcm2835_get_mem_dev(void)
 {
@@ -521,7 +540,7 @@ static int bcm2835gpio_init(void)
        /* TODO: move pads config to a separate utility */
        if (pad_mapping_possible) {
                pads_base = mmap(NULL, sysconf(_SC_PAGE_SIZE), PROT_READ | 
PROT_WRITE,
-                               MAP_SHARED, dev_mem_fd, BCM2835_PADS_GPIO_0_27);
+                               MAP_SHARED, dev_mem_fd, BCM2835_PADS_GPIO_BASE);
 
                if (pads_base == MAP_FAILED) {
                        LOG_ERROR("mmap pads: %s", strerror(errno));
@@ -535,10 +554,24 @@ static int bcm2835gpio_init(void)
 
        if (pads_base != MAP_FAILED) {
                /* set 4mA drive strength, slew rate limited, hysteresis on */
-               initial_drive_strength_etc = 
pads_base[BCM2835_PADS_GPIO_0_27_OFFSET] & 0x1f;
-LOG_INFO("initial pads conf %08x", pads_base[BCM2835_PADS_GPIO_0_27_OFFSET]);
-               pads_base[BCM2835_PADS_GPIO_0_27_OFFSET] = 0x5a000008 + 1;
-LOG_INFO("pads conf set to %08x", pads_base[BCM2835_PADS_GPIO_0_27_OFFSET]);
+               initial_drive_strengths[0] = 
pads_base[BCM2835_PADS_GPIO_0_27_OFFSET] & 0x1f;
+               LOG_INFO("initial gpio [0-27] pads conf %08x", 
pads_base[BCM2835_PADS_GPIO_0_27_OFFSET]);
+               pads_base[BCM2835_PADS_GPIO_0_27_OFFSET] = 
BCM2835_PADS_GPIO_PASSWORD | BCM2835_PADS_GPIO_SLEW_LIMITED | \
+                               BCM2835_PADS_GPIO_HYST_ENABLED | 
DRIVE_STRENGTH_4MA;
+               LOG_INFO("pads conf set to %08x", 
pads_base[BCM2835_PADS_GPIO_0_27_OFFSET]);
+#ifdef BCM2835GPIO_ALL_GPIO
+               initial_drive_strengths[1] = 
pads_base[BCM2835_PADS_GPIO_28_45_OFFSET] & 0x1f;
+               LOG_INFO("initial gpio [28-45] pads conf %08x", 
pads_base[BCM2835_PADS_GPIO_28_45_OFFSET]);
+               pads_base[BCM2835_PADS_GPIO_28_45_OFFSET] = 
BCM2835_PADS_GPIO_PASSWORD | BCM2835_PADS_GPIO_SLEW_LIMITED | \
+                               BCM2835_PADS_GPIO_HYST_ENABLED | 
DRIVE_STRENGTH_4MA;
+               LOG_INFO("pads conf set to %08x", 
pads_base[BCM2835_PADS_GPIO_28_45_OFFSET]);
+
+               initial_drive_strengths[2] = 
pads_base[BCM2835_PADS_GPIO_46_53_OFFSET] & 0x1f;
+               LOG_INFO("initial gpio [46-53] pads conf %08x", 
pads_base[BCM2835_PADS_GPIO_46_53_OFFSET]);
+               pads_base[BCM2835_PADS_GPIO_46_53_OFFSET] = 
BCM2835_PADS_GPIO_PASSWORD | BCM2835_PADS_GPIO_SLEW_LIMITED | \
+                               BCM2835_PADS_GPIO_HYST_ENABLED | 
DRIVE_STRENGTH_4MA;
+               LOG_INFO("pads conf set to %08x", 
pads_base[BCM2835_PADS_GPIO_46_53_OFFSET]);
+#endif
        }
 
        /* Configure JTAG/SWD signals. Default directions and initial states 
are handled
@@ -612,7 +645,11 @@ static int bcm2835gpio_quit(void)
 
        if (pads_base != MAP_FAILED) {
                /* Restore drive strength. MSB is password ("5A") */
-               pads_base[BCM2835_PADS_GPIO_0_27_OFFSET] = 0x5A000000 | 
initial_drive_strength_etc;
+               pads_base[BCM2835_PADS_GPIO_0_27_OFFSET] = 
BCM2835_PADS_GPIO_PASSWORD | initial_drive_strengths[0];
+#ifdef BCM2835GPIO_ALL_GPIO
+               pads_base[BCM2835_PADS_GPIO_28_45_OFFSET] = 
BCM2835_PADS_GPIO_PASSWORD | initial_drive_strengths[1];
+               pads_base[BCM2835_PADS_GPIO_46_53_OFFSET] = 
BCM2835_PADS_GPIO_PASSWORD | initial_drive_strengths[2];
+#endif
        }
        bcm2835gpio_munmap();
        free(bcm2835_peri_mem_dev);

-- 

Reply via email to