Path: blob/master/drivers/firmware/samsung/exynos-acpm-dvfs.c
38189 views
// SPDX-License-Identifier: GPL-2.0-only1/*2* Copyright 2020 Samsung Electronics Co., Ltd.3* Copyright 2020 Google LLC.4* Copyright 2025 Linaro Ltd.5*/67#include <linux/bitfield.h>8#include <linux/firmware/samsung/exynos-acpm-protocol.h>9#include <linux/ktime.h>10#include <linux/types.h>11#include <linux/units.h>1213#include "exynos-acpm.h"14#include "exynos-acpm-dvfs.h"1516#define ACPM_DVFS_ID GENMASK(11, 0)17#define ACPM_DVFS_REQ_TYPE GENMASK(15, 0)1819#define ACPM_DVFS_FREQ_REQ 020#define ACPM_DVFS_FREQ_GET 12122static void acpm_dvfs_set_xfer(struct acpm_xfer *xfer, u32 *cmd, size_t cmdlen,23unsigned int acpm_chan_id, bool response)24{25xfer->acpm_chan_id = acpm_chan_id;26xfer->txd = cmd;27xfer->txlen = cmdlen;2829if (response) {30xfer->rxd = cmd;31xfer->rxlen = cmdlen;32}33}3435static void acpm_dvfs_init_set_rate_cmd(u32 cmd[4], unsigned int clk_id,36unsigned long rate)37{38cmd[0] = FIELD_PREP(ACPM_DVFS_ID, clk_id);39cmd[1] = rate / HZ_PER_KHZ;40cmd[2] = FIELD_PREP(ACPM_DVFS_REQ_TYPE, ACPM_DVFS_FREQ_REQ);41cmd[3] = ktime_to_ms(ktime_get());42}4344int acpm_dvfs_set_rate(const struct acpm_handle *handle,45unsigned int acpm_chan_id, unsigned int clk_id,46unsigned long rate)47{48struct acpm_xfer xfer = {0};49u32 cmd[4];5051acpm_dvfs_init_set_rate_cmd(cmd, clk_id, rate);52acpm_dvfs_set_xfer(&xfer, cmd, sizeof(cmd), acpm_chan_id, false);5354return acpm_do_xfer(handle, &xfer);55}5657static void acpm_dvfs_init_get_rate_cmd(u32 cmd[4], unsigned int clk_id)58{59cmd[0] = FIELD_PREP(ACPM_DVFS_ID, clk_id);60cmd[2] = FIELD_PREP(ACPM_DVFS_REQ_TYPE, ACPM_DVFS_FREQ_GET);61cmd[3] = ktime_to_ms(ktime_get());62}6364unsigned long acpm_dvfs_get_rate(const struct acpm_handle *handle,65unsigned int acpm_chan_id, unsigned int clk_id)66{67struct acpm_xfer xfer;68unsigned int cmd[4] = {0};69int ret;7071acpm_dvfs_init_get_rate_cmd(cmd, clk_id);72acpm_dvfs_set_xfer(&xfer, cmd, sizeof(cmd), acpm_chan_id, true);7374ret = acpm_do_xfer(handle, &xfer);75if (ret)76return 0;7778return xfer.rxd[1] * HZ_PER_KHZ;79}808182