// SPDX-License-Identifier: GPL-2.0 /* * Qualcomm Ramp Controller driver * Copyright (c) 2022, AngeloGioacchino Del Regno * <[email protected]> */ #include <linux/bitfield.h> #include <linux/kernel.h> #include <linux/module.h> #include <linux/of.h> #include <linux/of_platform.h> #include <linux/platform_device.h> #include <linux/regmap.h> #include <linux/types.h> #define RC_UPDATE_EN … #define RC_ROOT_EN … #define RC_REG_CFG_UPDATE … #define RC_CFG_UPDATE_EN … #define RC_CFG_ACK … #define RC_DCVS_CFG_SID … #define RC_LINK_SID … #define RC_LMH_SID … #define RC_DFS_SID … #define RC_UPDATE_TIMEOUT_US … /** * struct qcom_ramp_controller_desc - SoC specific parameters * @cfg_dfs_sid: Dynamic Frequency Scaling SID configuration * @cfg_link_sid: Link SID configuration * @cfg_lmh_sid: Limits Management hardware SID configuration * @cfg_ramp_en: Ramp Controller enable sequence * @cfg_ramp_dis: Ramp Controller disable sequence * @cmd_reg: Command register offset * @num_dfs_sids: Number of DFS SIDs (max 8) * @num_link_sids: Number of Link SIDs (max 3) * @num_lmh_sids: Number of LMh SIDs (max 8) * @num_ramp_en: Number of entries in enable sequence * @num_ramp_dis: Number of entries in disable sequence */ struct qcom_ramp_controller_desc { … }; /** * struct qcom_ramp_controller - Main driver structure * @regmap: Regmap handle * @desc: SoC specific parameters */ struct qcom_ramp_controller { … }; /** * rc_wait_for_update() - Wait for Ramp Controller root update * @qrc: Main driver structure * * Return: Zero for success or negative number for failure */ static int rc_wait_for_update(struct qcom_ramp_controller *qrc) { … } /** * rc_set_cfg_update() - Ramp Controller configuration update * @qrc: Main driver structure * @ce: Configuration entry to update * * Return: Zero for success or negative number for failure */ static int rc_set_cfg_update(struct qcom_ramp_controller *qrc, u8 ce) { … } /** * rc_write_cfg - Send configuration sequence * @qrc: Main driver structure * @seq: Register sequence to send before asking for update * @ce: Configuration SID * @nsids: Total number of SIDs * * Returns: Zero for success or negative number for error */ static int rc_write_cfg(struct qcom_ramp_controller *qrc, const struct reg_sequence *seq, u16 ce, u8 nsids) { … } /** * rc_ramp_ctrl_enable() - Enable Ramp up/down Control * @qrc: Main driver structure * * Return: Zero for success or negative number for error */ static int rc_ramp_ctrl_enable(struct qcom_ramp_controller *qrc) { … } /** * qcom_ramp_controller_start() - Initialize and start the ramp controller * @qrc: Main driver structure * * The Ramp Controller needs to be initialized by programming the relevant * registers with SoC-specific configuration: once programming is done, * the hardware will take care of the rest (no further handling required). * * Return: Zero for success or negative number for error */ static int qcom_ramp_controller_start(struct qcom_ramp_controller *qrc) { … } static const struct regmap_config qrc_regmap_config = …; static const struct reg_sequence msm8976_cfg_dfs_sid[] = …; static const struct reg_sequence msm8976_cfg_link_sid[] = …; static const struct reg_sequence msm8976_cfg_lmh_sid[] = …; static const struct reg_sequence msm8976_cfg_ramp_en[] = …; static const struct reg_sequence msm8976_cfg_ramp_dis[] = …; static const struct qcom_ramp_controller_desc msm8976_rc_cfg = …; static int qcom_ramp_controller_probe(struct platform_device *pdev) { … } static void qcom_ramp_controller_remove(struct platform_device *pdev) { … } static const struct of_device_id qcom_ramp_controller_match_table[] = …; MODULE_DEVICE_TABLE(of, qcom_ramp_controller_match_table); static struct platform_driver qcom_ramp_controller_driver = …; static int __init qcom_ramp_controller_init(void) { … } arch_initcall(qcom_ramp_controller_init); MODULE_AUTHOR(…) …; MODULE_DESCRIPTION(…) …; MODULE_LICENSE(…) …;