From 7b28cdbae57bec87a7c399415f36306030637852 Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Wed, 25 Nov 2020 19:39:02 -0500 Subject: [PATCH] pru: Disable gpio mux configuration code The code isn't actually capable of altering the mux registers due to hardware checks enforced by the chip. Disable that code to save a few bytes in the final binary. Signed-off-by: Kevin O'Connor --- src/pru/gpio.c | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/src/pru/gpio.c b/src/pru/gpio.c index 1e298657..2f77a071 100644 --- a/src/pru/gpio.c +++ b/src/pru/gpio.c @@ -1,6 +1,6 @@ // GPIO functions on PRU // -// Copyright (C) 2017 Kevin O'Connor +// Copyright (C) 2017-2020 Kevin O'Connor // // This file may be distributed under the terms of the GNU GPLv3 license. @@ -38,6 +38,11 @@ static struct gpio_regs *digital_regs[] = { (void*)0x44e07000, (void*)0x4804c000, (void*)0x481ac000, (void*)0x481ae000 }; + +/**************************************************************** + * Pin mux handling + ****************************************************************/ + #define MUXPORT(offset) (((offset)-0x800) / 4) static uint8_t gpio_mux_offset[32 * ARRAY_SIZE(digital_regs)] = { @@ -84,6 +89,17 @@ static uint8_t gpio_mux_offset[32 * ARRAY_SIZE(digital_regs)] = { #define MUXREG(mux_offset) ((volatile uint32_t *)0x44e10800 + mux_offset) +static void +set_pin_mux(uint8_t pin, uint8_t val) +{ + return; // XXX - can not set mux value from PRU + + uint8_t mux_offset = gpio_mux_offset[pin]; + if (mux_offset == 0xff) + shutdown("Invalid mux pin"); + *MUXREG(mux_offset) = val; +} + /**************************************************************** * General Purpose Input Output (GPIO) pins @@ -94,15 +110,12 @@ gpio_out_setup(uint8_t pin, uint8_t val) { if (GPIO2PORT(pin) >= ARRAY_SIZE(digital_regs)) goto fail; - uint8_t mux_offset = gpio_mux_offset[pin]; - if (mux_offset == 0xff) - goto fail; struct gpio_regs *regs = digital_regs[GPIO2PORT(pin)]; uint32_t bit = GPIO2BIT(pin); struct gpio_out rv = (struct gpio_out){.reg=®s->cleardataout, .bit=bit}; gpio_out_write(rv, val); regs->oe &= ~bit; - *MUXREG(mux_offset) = 0x0f; + set_pin_mux(pin, 0x0f); return rv; fail: shutdown("Not an output pin"); @@ -141,13 +154,10 @@ gpio_in_setup(uint8_t pin, int8_t pull_up) { if (GPIO2PORT(pin) >= ARRAY_SIZE(digital_regs)) goto fail; - uint8_t mux_offset = gpio_mux_offset[pin]; - if (mux_offset == 0xff) - goto fail; struct gpio_regs *regs = digital_regs[GPIO2PORT(pin)]; uint32_t bit = GPIO2BIT(pin); regs->oe |= bit; - *MUXREG(mux_offset) = pull_up > 0 ? 0x37 : (pull_up < 0 ? 0x27 : 0x2f); + set_pin_mux(pin, pull_up > 0 ? 0x37 : (pull_up < 0 ? 0x27 : 0x2f)); return (struct gpio_in){ .reg=®s->datain, .bit=bit }; fail: shutdown("Not an input pin");