2022-05-16 03:05:48 -04:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0 */
|
|
|
|
/*
|
|
|
|
* Copyright (C) STMicroelectronics 2022 - All Rights Reserved
|
|
|
|
* Author: Gabriel Fernandez <gabriel.fernandez@foss.st.com> for STMicroelectronics.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/clk-provider.h>
|
|
|
|
|
|
|
|
struct stm32_rcc_match_data;
|
|
|
|
|
|
|
|
struct stm32_mux_cfg {
|
|
|
|
u16 offset;
|
|
|
|
u8 shift;
|
|
|
|
u8 width;
|
|
|
|
u8 flags;
|
|
|
|
u32 *table;
|
|
|
|
u8 ready;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct stm32_gate_cfg {
|
|
|
|
u16 offset;
|
|
|
|
u8 bit_idx;
|
|
|
|
u8 set_clr;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct stm32_div_cfg {
|
|
|
|
u16 offset;
|
|
|
|
u8 shift;
|
|
|
|
u8 width;
|
|
|
|
u8 flags;
|
|
|
|
u8 ready;
|
|
|
|
const struct clk_div_table *table;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct stm32_composite_cfg {
|
|
|
|
int mux;
|
|
|
|
int gate;
|
|
|
|
int div;
|
|
|
|
};
|
|
|
|
|
|
|
|
#define NO_ID 0xFFFFFFFF
|
|
|
|
|
|
|
|
#define NO_STM32_MUX 0xFFFF
|
|
|
|
#define NO_STM32_DIV 0xFFFF
|
|
|
|
#define NO_STM32_GATE 0xFFFF
|
|
|
|
|
|
|
|
struct clock_config {
|
|
|
|
unsigned long id;
|
2022-05-16 03:05:53 -04:00
|
|
|
int sec_id;
|
2022-05-16 03:05:48 -04:00
|
|
|
void *clock_cfg;
|
|
|
|
|
|
|
|
struct clk_hw *(*func)(struct device *dev,
|
|
|
|
const struct stm32_rcc_match_data *data,
|
|
|
|
void __iomem *base,
|
|
|
|
spinlock_t *lock,
|
|
|
|
const struct clock_config *cfg);
|
|
|
|
};
|
|
|
|
|
|
|
|
struct clk_stm32_clock_data {
|
|
|
|
u16 *gate_cpt;
|
|
|
|
const struct stm32_gate_cfg *gates;
|
|
|
|
const struct stm32_mux_cfg *muxes;
|
|
|
|
const struct stm32_div_cfg *dividers;
|
2022-05-16 03:05:56 -04:00
|
|
|
struct clk_hw *(*is_multi_mux)(struct clk_hw *hw);
|
2022-05-16 03:05:48 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
struct stm32_rcc_match_data {
|
|
|
|
struct clk_hw_onecell_data *hw_clks;
|
|
|
|
unsigned int num_clocks;
|
|
|
|
const struct clock_config *tab_clocks;
|
|
|
|
unsigned int maxbinding;
|
|
|
|
struct clk_stm32_clock_data *clock_data;
|
2023-12-08 09:36:57 -05:00
|
|
|
struct clk_stm32_reset_data *reset_data;
|
2022-05-16 03:05:53 -04:00
|
|
|
int (*check_security)(void __iomem *base,
|
|
|
|
const struct clock_config *cfg);
|
2022-05-16 03:05:56 -04:00
|
|
|
int (*multi_mux)(void __iomem *base, const struct clock_config *cfg);
|
2022-05-16 03:05:48 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
int stm32_rcc_init(struct device *dev, const struct of_device_id *match_data,
|
|
|
|
void __iomem *base);
|
|
|
|
|
|
|
|
/* MUX define */
|
|
|
|
#define MUX_NO_RDY 0xFF
|
2022-05-16 03:05:57 -04:00
|
|
|
#define MUX_SAFE BIT(7)
|
2022-05-16 03:05:48 -04:00
|
|
|
|
|
|
|
/* DIV define */
|
|
|
|
#define DIV_NO_RDY 0xFF
|
|
|
|
|
2022-05-16 03:05:49 -04:00
|
|
|
/* Definition of clock structure */
|
|
|
|
struct clk_stm32_mux {
|
|
|
|
u16 mux_id;
|
|
|
|
struct clk_hw hw;
|
|
|
|
void __iomem *base;
|
|
|
|
struct clk_stm32_clock_data *clock_data;
|
|
|
|
spinlock_t *lock; /* spin lock */
|
|
|
|
};
|
|
|
|
|
|
|
|
#define to_clk_stm32_mux(_hw) container_of(_hw, struct clk_stm32_mux, hw)
|
|
|
|
|
2022-05-16 03:05:50 -04:00
|
|
|
struct clk_stm32_gate {
|
|
|
|
u16 gate_id;
|
|
|
|
struct clk_hw hw;
|
|
|
|
void __iomem *base;
|
|
|
|
struct clk_stm32_clock_data *clock_data;
|
|
|
|
spinlock_t *lock; /* spin lock */
|
|
|
|
};
|
|
|
|
|
|
|
|
#define to_clk_stm32_gate(_hw) container_of(_hw, struct clk_stm32_gate, hw)
|
|
|
|
|
2022-05-16 03:05:51 -04:00
|
|
|
struct clk_stm32_div {
|
|
|
|
u16 div_id;
|
|
|
|
struct clk_hw hw;
|
|
|
|
void __iomem *base;
|
|
|
|
struct clk_stm32_clock_data *clock_data;
|
|
|
|
spinlock_t *lock; /* spin lock */
|
|
|
|
};
|
|
|
|
|
|
|
|
#define to_clk_stm32_divider(_hw) container_of(_hw, struct clk_stm32_div, hw)
|
|
|
|
|
2022-05-16 03:05:52 -04:00
|
|
|
struct clk_stm32_composite {
|
|
|
|
u16 gate_id;
|
|
|
|
u16 mux_id;
|
|
|
|
u16 div_id;
|
|
|
|
struct clk_hw hw;
|
|
|
|
void __iomem *base;
|
|
|
|
struct clk_stm32_clock_data *clock_data;
|
|
|
|
spinlock_t *lock; /* spin lock */
|
|
|
|
};
|
|
|
|
|
|
|
|
#define to_clk_stm32_composite(_hw) container_of(_hw, struct clk_stm32_composite, hw)
|
|
|
|
|
2022-05-16 03:05:49 -04:00
|
|
|
/* Clock operators */
|
|
|
|
extern const struct clk_ops clk_stm32_mux_ops;
|
2022-05-16 03:05:50 -04:00
|
|
|
extern const struct clk_ops clk_stm32_gate_ops;
|
2022-05-16 03:05:51 -04:00
|
|
|
extern const struct clk_ops clk_stm32_divider_ops;
|
2022-05-16 03:05:52 -04:00
|
|
|
extern const struct clk_ops clk_stm32_composite_ops;
|
2022-05-16 03:05:49 -04:00
|
|
|
|
2022-05-16 03:05:48 -04:00
|
|
|
/* Clock registering */
|
2022-05-16 03:05:49 -04:00
|
|
|
struct clk_hw *clk_stm32_mux_register(struct device *dev,
|
|
|
|
const struct stm32_rcc_match_data *data,
|
|
|
|
void __iomem *base,
|
|
|
|
spinlock_t *lock,
|
|
|
|
const struct clock_config *cfg);
|
|
|
|
|
2022-05-16 03:05:50 -04:00
|
|
|
struct clk_hw *clk_stm32_gate_register(struct device *dev,
|
|
|
|
const struct stm32_rcc_match_data *data,
|
|
|
|
void __iomem *base,
|
|
|
|
spinlock_t *lock,
|
|
|
|
const struct clock_config *cfg);
|
|
|
|
|
2022-05-16 03:05:51 -04:00
|
|
|
struct clk_hw *clk_stm32_div_register(struct device *dev,
|
|
|
|
const struct stm32_rcc_match_data *data,
|
|
|
|
void __iomem *base,
|
|
|
|
spinlock_t *lock,
|
|
|
|
const struct clock_config *cfg);
|
|
|
|
|
2022-05-16 03:05:52 -04:00
|
|
|
struct clk_hw *clk_stm32_composite_register(struct device *dev,
|
|
|
|
const struct stm32_rcc_match_data *data,
|
|
|
|
void __iomem *base,
|
|
|
|
spinlock_t *lock,
|
|
|
|
const struct clock_config *cfg);
|
|
|
|
|
2022-05-16 03:05:53 -04:00
|
|
|
#define STM32_CLOCK_CFG(_binding, _clk, _sec_id, _struct, _register)\
|
2022-05-16 03:05:48 -04:00
|
|
|
{\
|
|
|
|
.id = (_binding),\
|
2022-05-16 03:05:53 -04:00
|
|
|
.sec_id = (_sec_id),\
|
2022-05-16 03:05:48 -04:00
|
|
|
.clock_cfg = (_struct) {_clk},\
|
|
|
|
.func = (_register),\
|
|
|
|
}
|
2022-05-16 03:05:49 -04:00
|
|
|
|
2022-05-16 03:05:53 -04:00
|
|
|
#define STM32_MUX_CFG(_binding, _clk, _sec_id)\
|
|
|
|
STM32_CLOCK_CFG(_binding, &(_clk), _sec_id, struct clk_stm32_mux *,\
|
2022-05-16 03:05:49 -04:00
|
|
|
&clk_stm32_mux_register)
|
2022-05-16 03:05:50 -04:00
|
|
|
|
2022-05-16 03:05:53 -04:00
|
|
|
#define STM32_GATE_CFG(_binding, _clk, _sec_id)\
|
|
|
|
STM32_CLOCK_CFG(_binding, &(_clk), _sec_id, struct clk_stm32_gate *,\
|
2022-05-16 03:05:50 -04:00
|
|
|
&clk_stm32_gate_register)
|
2022-05-16 03:05:51 -04:00
|
|
|
|
2022-05-16 03:05:53 -04:00
|
|
|
#define STM32_DIV_CFG(_binding, _clk, _sec_id)\
|
|
|
|
STM32_CLOCK_CFG(_binding, &(_clk), _sec_id, struct clk_stm32_div *,\
|
2022-05-16 03:05:51 -04:00
|
|
|
&clk_stm32_div_register)
|
2022-05-16 03:05:52 -04:00
|
|
|
|
2022-05-16 03:05:53 -04:00
|
|
|
#define STM32_COMPOSITE_CFG(_binding, _clk, _sec_id)\
|
|
|
|
STM32_CLOCK_CFG(_binding, &(_clk), _sec_id, struct clk_stm32_composite *,\
|
2022-05-16 03:05:52 -04:00
|
|
|
&clk_stm32_composite_register)
|