Rockbox open source high quality audio player as a Music Player Daemon
mpris rockbox mpd libadwaita audio rust zig deno
2
fork

Configure Feed

Select the types of activity you want to include in your feed.

stm32h7: add clock enable/disable callbacks

Change-Id: I4c135ba9cbed2c8e607c5f191bb9d82638f9b6b3

authored by

Aidan MacDonald and committed by
Solomon Peachy
ddb3bb35 23448a13

+103 -1
+1
firmware/SOURCES
··· 2019 2019 target/arm/stm32/crt0-stm32h7.S 2020 2020 target/arm/stm32/vectors-stm32h7.S 2021 2021 target/arm/stm32/adc-stm32h7.c 2022 + target/arm/stm32/clock-stm32h7.c 2022 2023 target/arm/stm32/debug-stm32h7.c 2023 2024 target/arm/stm32/gpio-stm32h7.c 2024 2025 target/arm/stm32/i2c-stm32h7.c
+65
firmware/target/arm/stm32/clock-stm32h7.c
··· 1 + /*************************************************************************** 2 + * __________ __ ___. 3 + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ 4 + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / 5 + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < 6 + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ 7 + * \/ \/ \/ \/ \/ 8 + * $Id$ 9 + * 10 + * Copyright (C) 2025 Aidan MacDonald 11 + * 12 + * This program is free software; you can redistribute it and/or 13 + * modify it under the terms of the GNU General Public License 14 + * as published by the Free Software Foundation; either version 2 15 + * of the License, or (at your option) any later version. 16 + * 17 + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY 18 + * KIND, either express or implied. 19 + * 20 + ****************************************************************************/ 21 + #include "clock-stm32h7.h" 22 + #include "mutex.h" 23 + #include "panic.h" 24 + #include <stdint.h> 25 + 26 + struct stm_clock_state 27 + { 28 + struct mutex mutex; 29 + uint8_t refcount[STM_NUM_CLOCKS]; 30 + }; 31 + 32 + static struct stm_clock_state stm_clocks; 33 + 34 + void stm_clock_init(void) 35 + { 36 + mutex_init(&stm_clocks.mutex); 37 + 38 + stm_target_clock_init(); 39 + } 40 + 41 + void stm_clock_enable(enum stm_clock clock) 42 + { 43 + mutex_lock(&stm_clocks.mutex); 44 + 45 + if (stm_clocks.refcount[clock] == UINT8_MAX) 46 + panicf("%s: clock %d overflow", __func__, (int)clock); 47 + 48 + if (stm_clocks.refcount[clock]++ == 0) 49 + stm_target_clock_enable(clock, true); 50 + 51 + mutex_unlock(&stm_clocks.mutex); 52 + } 53 + 54 + void stm_clock_disable(enum stm_clock clock) 55 + { 56 + mutex_lock(&stm_clocks.mutex); 57 + 58 + if (stm_clocks.refcount[clock] == 0) 59 + panicf("%s: clock %d underflow", __func__, (int)clock); 60 + 61 + if (--stm_clocks.refcount[clock] == 0) 62 + stm_target_clock_enable(clock, false); 63 + 64 + mutex_unlock(&stm_clocks.mutex); 65 + }
+36
firmware/target/arm/stm32/clock-stm32h7.h
··· 22 22 #define __CLOCK_STM32H7_H__ 23 23 24 24 #include "system.h" 25 + #include <stdbool.h> 26 + 27 + enum stm_clock 28 + { 29 + STM_CLOCK_SPI1_KER, 30 + STM_CLOCK_SPI2_KER, 31 + STM_CLOCK_SPI3_KER, 32 + STM_CLOCK_SPI4_KER, 33 + STM_CLOCK_SPI5_KER, 34 + STM_CLOCK_SPI6_KER, 35 + STM_NUM_CLOCKS, 36 + }; 25 37 26 38 /* 27 39 * Implemented by the target to initialize all oscillators, ··· 29 41 * early boot. 30 42 */ 31 43 void stm_target_clock_init(void) INIT_ATTR; 44 + 45 + /* 46 + * Callback to be implemented by the target when the hardware 47 + * clock needs to be turned on or off. Clocks are internally 48 + * reference counted so only the first / last user will change 49 + * the hardware state. 50 + * 51 + * Only clocks that are actually used need to be implemented, 52 + * and unless otherwise noted it is allowed for enable/disable 53 + * to be a no-op if the clock is always enabled. 54 + */ 55 + void stm_target_clock_enable(enum stm_clock clock, bool enable); 56 + 57 + /* 58 + * Called from system_init(). Sets up internal book-keeping 59 + * and then calls stm_target_clock_init(). 60 + */ 61 + void stm_clock_init(void) INIT_ATTR; 62 + 63 + /* 64 + * Enable or disable a clock. Not safe to call from an IRQ handler. 65 + */ 66 + void stm_clock_enable(enum stm_clock clock); 67 + void stm_clock_disable(enum stm_clock clock); 32 68 33 69 #endif /* __CLOCK_STM32H7_H__ */
+1 -1
firmware/target/arm/stm32/system-stm32h7.c
··· 69 69 stm_enable_caches(); 70 70 71 71 /* Initialize system clocks */ 72 - stm_target_clock_init(); 72 + stm_clock_init(); 73 73 74 74 /* TODO: move this */ 75 75 systick_init(1000/HZ);