10050ea24SMichal Meloun /*- 24d846d26SWarner Losh * SPDX-License-Identifier: BSD-2-Clause 30050ea24SMichal Meloun * 40050ea24SMichal Meloun * Copyright (c) 2017 Emmanuel Vadot <manu@freebsd.org> 50050ea24SMichal Meloun * 60050ea24SMichal Meloun * Copyright (c) 2020 Oskar Holmlund <oskar.holmlund@ohdata.se> 70050ea24SMichal Meloun * 80050ea24SMichal Meloun * Redistribution and use in source and binary forms, with or without 90050ea24SMichal Meloun * modification, are permitted provided that the following conditions 100050ea24SMichal Meloun * are met: 110050ea24SMichal Meloun * 1. Redistributions of source code must retain the above copyright 120050ea24SMichal Meloun * notice, this list of conditions and the following disclaimer. 130050ea24SMichal Meloun * 2. Redistributions in binary form must reproduce the above copyright 140050ea24SMichal Meloun * notice, this list of conditions and the following disclaimer in the 150050ea24SMichal Meloun * documentation and/or other materials provided with the distribution. 160050ea24SMichal Meloun * 170050ea24SMichal Meloun * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 180050ea24SMichal Meloun * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 190050ea24SMichal Meloun * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 200050ea24SMichal Meloun * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 210050ea24SMichal Meloun * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 220050ea24SMichal Meloun * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 230050ea24SMichal Meloun * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 240050ea24SMichal Meloun * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 250050ea24SMichal Meloun * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 260050ea24SMichal Meloun * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 270050ea24SMichal Meloun * SUCH DAMAGE. 280050ea24SMichal Meloun */ 290050ea24SMichal Meloun 300050ea24SMichal Meloun #ifndef _TI_DPLL_CLOCK_H_ 310050ea24SMichal Meloun #define _TI_DPLL_CLOCK_H_ 320050ea24SMichal Meloun 33*be82b3a0SEmmanuel Vadot #include <dev/clk/clk.h> 340050ea24SMichal Meloun 350050ea24SMichal Meloun /* Registers are described in AM335x TRM chapter 8.1.12.2.* */ 360050ea24SMichal Meloun 370050ea24SMichal Meloun /* Register offsets */ 380050ea24SMichal Meloun #define CM_CLKSEL_DPLL_PERIPH 0x49C 390050ea24SMichal Meloun 400050ea24SMichal Meloun /* CM_IDLEST_DPLL_xxx */ 410050ea24SMichal Meloun #define ST_MN_BYPASS_MASK 0x0100 420050ea24SMichal Meloun #define ST_MN_BYPASS_SHIFT 8 430050ea24SMichal Meloun #define ST_DPLL_CLK_MASK 0x0001 440050ea24SMichal Meloun 450050ea24SMichal Meloun /* CM_CLKMODE_DPLL_DPLL_EN feature flag */ 460050ea24SMichal Meloun #define LOW_POWER_STOP_MODE_FLAG 0x01 470050ea24SMichal Meloun #define MN_BYPASS_MODE_FLAG 0x02 480050ea24SMichal Meloun #define IDLE_BYPASS_LOW_POWER_MODE_FLAG 0x04 490050ea24SMichal Meloun #define IDLE_BYPASS_FAST_RELOCK_MODE_FLAG 0x08 500050ea24SMichal Meloun #define LOCK_MODE_FLAG 0x10 510050ea24SMichal Meloun 520050ea24SMichal Meloun /* CM_CLKMODE_DPLL_xxx */ 530050ea24SMichal Meloun #define DPLL_EN_LOW_POWER_STOP_MODE 0x01 540050ea24SMichal Meloun #define DPLL_EN_MN_BYPASS_MODE 0x04 550050ea24SMichal Meloun #define DPLL_EN_IDLE_BYPASS_LOW_POWER_MODE 0x05 560050ea24SMichal Meloun #define DPLL_EN_IDLE_BYPASS_FAST_RELOCK_MODE 0x06 570050ea24SMichal Meloun #define DPLL_EN_LOCK_MODE 0x07 580050ea24SMichal Meloun 590050ea24SMichal Meloun #define TI_CLK_FACTOR_ZERO_BASED 0x0002 600050ea24SMichal Meloun #define TI_CLK_FACTOR_FIXED 0x0008 610050ea24SMichal Meloun #define TI_CLK_FACTOR_MIN_VALUE 0x0020 620050ea24SMichal Meloun #define TI_CLK_FACTOR_MAX_VALUE 0x0040 630050ea24SMichal Meloun 640050ea24SMichal Meloun /* Based on aw_clk_factor sys/arm/allwinner/clkng/aw_clk.h */ 650050ea24SMichal Meloun struct ti_clk_factor { 660050ea24SMichal Meloun uint32_t shift; /* Shift bits for the factor */ 670050ea24SMichal Meloun uint32_t mask; /* Mask to get the factor */ 680050ea24SMichal Meloun uint32_t width; /* Number of bits for the factor */ 690050ea24SMichal Meloun uint32_t value; /* Fixed value */ 700050ea24SMichal Meloun 710050ea24SMichal Meloun uint32_t min_value; 720050ea24SMichal Meloun uint32_t max_value; 730050ea24SMichal Meloun 740050ea24SMichal Meloun uint32_t flags; /* Flags */ 750050ea24SMichal Meloun }; 760050ea24SMichal Meloun 770050ea24SMichal Meloun struct ti_clk_dpll_def { 780050ea24SMichal Meloun struct clknode_init_def clkdef; 790050ea24SMichal Meloun 800050ea24SMichal Meloun uint32_t ti_clkmode_offset; /* control */ 810050ea24SMichal Meloun uint8_t ti_clkmode_flags; 820050ea24SMichal Meloun 830050ea24SMichal Meloun uint32_t ti_idlest_offset; 840050ea24SMichal Meloun 850050ea24SMichal Meloun uint32_t ti_clksel_offset; /* mult-div1 */ 860050ea24SMichal Meloun struct ti_clk_factor ti_clksel_mult; 870050ea24SMichal Meloun struct ti_clk_factor ti_clksel_div; 880050ea24SMichal Meloun 890050ea24SMichal Meloun uint32_t ti_autoidle_offset; 900050ea24SMichal Meloun }; 910050ea24SMichal Meloun 920050ea24SMichal Meloun int ti_clknode_dpll_register(struct clkdom *clkdom, struct ti_clk_dpll_def *clkdef); 930050ea24SMichal Meloun 940050ea24SMichal Meloun #endif /* _TI_DPLL_CLOCK_H_ */ 95