1 /* SPDX-License-Identifier: BSD-3-Clause */ 2 /* 3 * Minimal PSC driver for AM62L BL1. 4 * 5 * Provides a lightweight set_main_psc_state() for use during BL1 before the 6 * full ti-am62l-clk driver is available. Once that driver is integrated this 7 * header (and its companion .c) should be retired in favour of the shared PSC 8 * API. 9 * 10 * Copyright (C) 2025-2026 Texas Instruments Incorporated - https://www.ti.com/ 11 */ 12 13 #ifndef AM62L_PSC_MINIMAL_H 14 #define AM62L_PSC_MINIMAL_H 15 16 #include <stdint.h> 17 18 #include <lib/utils_def.h> 19 20 #ifndef bf_shf 21 #define bf_shf(x) (__builtin_ffsll(x) - 1U) 22 #endif 23 24 #ifndef FIELD_GET 25 #define FIELD_GET(_mask, _reg) \ 26 ({ \ 27 (typeof(_mask))(((_reg) & (_mask)) >> bf_shf(_mask)); \ 28 }) 29 #endif 30 31 #ifndef FIELD_PREP 32 #define FIELD_PREP(_mask, _val) \ 33 ({ \ 34 ((typeof(_mask))(_val) << bf_shf(_mask)) & (_mask); \ 35 }) 36 #endif 37 38 /* PSC module / power-domain next-state values */ 39 #define PSC_MD_SWRESETDISABLE (0x0U) 40 #define PSC_MD_ENABLE (0x3U) 41 #define PSC_PD_OFF (0x0U) 42 #define PSC_PD_ON (0x1U) 43 44 /* Main PSC register base addresses */ 45 #define MAIN_PSC_BASE UL(0x00400000) 46 #define MAIN_PSC_MDCTL_BASE UL(0x00400A00) 47 #define MAIN_PSC_MDSTAT_BASE UL(0x00400800) 48 #define MAIN_PSC_PDCTL_BASE UL(0x00400300) 49 #define MAIN_PSC_PDSTAT_BASE UL(0x00400200) 50 51 #define PSC_PTCMD 0x120 52 #define PSC_PTSTAT 0x128 53 54 #define MAIN_PSC_PTSTAT (MAIN_PSC_BASE + PSC_PTSTAT) 55 #define MAIN_PSC_PTCMD (MAIN_PSC_BASE + PSC_PTCMD) 56 57 /* PSC register field masks */ 58 #define MDSTAT_STATE_MASK GENMASK(5, 0) 59 #define PDSTAT_STATE_MASK GENMASK(5, 0) 60 #define PTSTAT_DOMAIN_GOSTAT 0x1U 61 #define PDCTL_NEXT_STATE_MASK GENMASK(0, 0) 62 #define MDCTL_NEXT_STATE_MASK GENMASK(5, 0) 63 #define PTCMD_DOMAIN_GO 0x1U 64 #define PSC_GOSTAT_RETRY_COUNT 100000U 65 66 int set_main_psc_state(uint32_t pd_id, uint32_t md_id, 67 uint32_t pd_state, uint32_t md_state); 68 69 #endif /* AM62L_PSC_MINIMAL_H */ 70