From 77188e41f5c9966432a0fbb3bffd2069d53cc608 Mon Sep 17 00:00:00 2001 From: Aidan MacDonald Date: Sun, 25 Apr 2021 14:17:45 +0100 Subject: X1000: remove bogus GPIO Z mutex There's absolutely no way for gpio_config() to get called from two different threads due to the co-operative threading model, and it is unsafe to call from IRQ context no matter what we do. Change-Id: I58f7d1f68c7a414610bb020e26b774cb1015a3b0 --- firmware/target/mips/ingenic_x1000/gpio-x1000.c | 24 ------------------------ firmware/target/mips/ingenic_x1000/gpio-x1000.h | 11 ++++------- 2 files changed, 4 insertions(+), 31 deletions(-) diff --git a/firmware/target/mips/ingenic_x1000/gpio-x1000.c b/firmware/target/mips/ingenic_x1000/gpio-x1000.c index 8e93f865bf..40e4c5e631 100644 --- a/firmware/target/mips/ingenic_x1000/gpio-x1000.c +++ b/firmware/target/mips/ingenic_x1000/gpio-x1000.c @@ -22,16 +22,8 @@ #include "gpio-x1000.h" #include "kernel.h" -#ifndef BOOTLOADER_SPL -struct mutex gpio_z_mutex; -#endif - void gpio_init(void) { -#ifndef BOOTLOADER_SPL - mutex_init(&gpio_z_mutex); -#endif - /* Any GPIO pins left in an IRQ trigger state need to be switched off, * because the drivers won't be ready to handle the interrupts until they * get initialized later in the boot. */ @@ -44,20 +36,6 @@ void gpio_init(void) } } -void gpio_lock(void) -{ -#ifndef BOOTLOADER_SPL - mutex_lock(&gpio_z_mutex); -#endif -} - -void gpio_unlock(void) -{ -#ifndef BOOTLOADER_SPL - mutex_unlock(&gpio_z_mutex); -#endif -} - void gpio_config(int port, unsigned pinmask, int func) { unsigned intr = REG_GPIO_INT(port); @@ -65,7 +43,6 @@ void gpio_config(int port, unsigned pinmask, int func) unsigned pat1 = REG_GPIO_PAT1(port); unsigned pat0 = REG_GPIO_PAT0(port); - gpio_lock(); if(func & 8) jz_set(GPIO_INT(GPIO_Z), (intr & pinmask) ^ pinmask); else jz_clr(GPIO_INT(GPIO_Z), (~intr & pinmask) ^ pinmask); if(func & 4) jz_set(GPIO_MSK(GPIO_Z), (mask & pinmask) ^ pinmask); @@ -75,6 +52,5 @@ void gpio_config(int port, unsigned pinmask, int func) if(func & 1) jz_set(GPIO_PAT0(GPIO_Z), (pat0 & pinmask) ^ pinmask); else jz_clr(GPIO_PAT0(GPIO_Z), (~pat0 & pinmask) ^ pinmask); REG_GPIO_Z_GID2LD = port; - gpio_unlock(); gpio_set_pull(port, pinmask, func & 16); } diff --git a/firmware/target/mips/ingenic_x1000/gpio-x1000.h b/firmware/target/mips/ingenic_x1000/gpio-x1000.h index f1a65b37b5..cfbe86338a 100644 --- a/firmware/target/mips/ingenic_x1000/gpio-x1000.h +++ b/firmware/target/mips/ingenic_x1000/gpio-x1000.h @@ -26,12 +26,11 @@ * -------- * * To assign a new function to a GPIO, call gpio_config(). This uses the - * hardware's GPIO Z facility to atomically most GPIO registers at once, + * hardware's GPIO Z facility to atomically set most GPIO registers at once, * so it can be used to make any state transition safely. Since GPIO Z is - * protected by a mutex, you can't call gpio_config() from interrupt context. - * - * If you need to use GPIO Z directly, then use gpio_lock() and gpio_unlock() - * to acquire the mutex. + * a global hardware resource, it is unsafe to call gpio_config() from IRQ + * context -- if the interrupted code was also running gpio_config(), then + * the results would be unpredictable. * * Depending on the current GPIO state, certain state transitions are safe to * perform without locking, as they only change one register: @@ -74,8 +73,6 @@ #define GPIO_IRQ_EDGE(i) (0x1e|((i)&1)) extern void gpio_init(void); -extern void gpio_lock(void); -extern void gpio_unlock(void); extern void gpio_config(int port, unsigned pinmask, int func); static inline void gpio_out_level(int port, unsigned pinmask, int level) -- cgit v1.2.3