linux/drivers/cpufreq/brcmstb-avs-cpufreq.c

/*
 * CPU frequency scaling for Broadcom SoCs with AVS firmware that
 * supports DVS or DVFS
 *
 * Copyright (c) 2016 Broadcom
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation version 2.
 *
 * This program is distributed "as is" WITHOUT ANY WARRANTY of any
 * kind, whether express or implied; without even the implied warranty
 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 */

/*
 * "AVS" is the name of a firmware developed at Broadcom. It derives
 * its name from the technique called "Adaptive Voltage Scaling".
 * Adaptive voltage scaling was the original purpose of this firmware.
 * The AVS firmware still supports "AVS mode", where all it does is
 * adaptive voltage scaling. However, on some newer Broadcom SoCs, the
 * AVS Firmware, despite its unchanged name, also supports DFS mode and
 * DVFS mode.
 *
 * In the context of this document and the related driver, "AVS" by
 * itself always means the Broadcom firmware and never refers to the
 * technique called "Adaptive Voltage Scaling".
 *
 * The Broadcom STB AVS CPUfreq driver provides voltage and frequency
 * scaling on Broadcom SoCs using AVS firmware with support for DFS and
 * DVFS. The AVS firmware is running on its own co-processor. The
 * driver supports both uniprocessor (UP) and symmetric multiprocessor
 * (SMP) systems which share clock and voltage across all CPUs.
 *
 * Actual voltage and frequency scaling is done solely by the AVS
 * firmware. This driver does not change frequency or voltage itself.
 * It provides a standard CPUfreq interface to the rest of the kernel
 * and to userland. It interfaces with the AVS firmware to effect the
 * requested changes and to report back the current system status in a
 * way that is expected by existing tools.
 */

#include <linux/cpufreq.h>
#include <linux/delay.h>
#include <linux/interrupt.h>
#include <linux/io.h>
#include <linux/module.h>
#include <linux/of_address.h>
#include <linux/platform_device.h>
#include <linux/semaphore.h>

/* Max number of arguments AVS calls take */
#define AVS_MAX_CMD_ARGS
/*
 * This macro is used to generate AVS parameter register offsets. For
 * x >= AVS_MAX_CMD_ARGS, it returns 0 to protect against accidental memory
 * access outside of the parameter range. (Offset 0 is the first parameter.)
 */
#define AVS_PARAM_MULT(x)

/* AVS Mailbox Register offsets */
#define AVS_MBOX_COMMAND
#define AVS_MBOX_STATUS
#define AVS_MBOX_VOLTAGE0
#define AVS_MBOX_TEMP0
#define AVS_MBOX_PV0
#define AVS_MBOX_MV0
#define AVS_MBOX_PARAM(x)
#define AVS_MBOX_REVISION
#define AVS_MBOX_PSTATE
#define AVS_MBOX_HEARTBEAT
#define AVS_MBOX_MAGIC
#define AVS_MBOX_SIGMA_HVT
#define AVS_MBOX_SIGMA_SVT
#define AVS_MBOX_VOLTAGE1
#define AVS_MBOX_TEMP1
#define AVS_MBOX_PV1
#define AVS_MBOX_MV1
#define AVS_MBOX_FREQUENCY

/* AVS Commands */
#define AVS_CMD_AVAILABLE
#define AVS_CMD_DISABLE
#define AVS_CMD_ENABLE
#define AVS_CMD_S2_ENTER
#define AVS_CMD_S2_EXIT
#define AVS_CMD_BBM_ENTER
#define AVS_CMD_BBM_EXIT
#define AVS_CMD_S3_ENTER
#define AVS_CMD_S3_EXIT
#define AVS_CMD_BALANCE
/* PMAP and P-STATE commands */
#define AVS_CMD_GET_PMAP
#define AVS_CMD_SET_PMAP
#define AVS_CMD_GET_PSTATE
#define AVS_CMD_SET_PSTATE

/* Different modes AVS supports (for GET_PMAP/SET_PMAP) */
#define AVS_MODE_AVS
#define AVS_MODE_DFS
#define AVS_MODE_DVS
#define AVS_MODE_DVFS

/*
 * PMAP parameter p1
 * unused:31-24, mdiv_p0:23-16, unused:15-14, pdiv:13-10 , ndiv_int:9-0
 */
#define NDIV_INT_SHIFT
#define NDIV_INT_MASK
#define PDIV_SHIFT
#define PDIV_MASK
#define MDIV_P0_SHIFT
#define MDIV_P0_MASK
/*
 * PMAP parameter p2
 * mdiv_p4:31-24, mdiv_p3:23-16, mdiv_p2:15:8, mdiv_p1:7:0
 */
#define MDIV_P1_SHIFT
#define MDIV_P1_MASK
#define MDIV_P2_SHIFT
#define MDIV_P2_MASK
#define MDIV_P3_SHIFT
#define MDIV_P3_MASK
#define MDIV_P4_SHIFT
#define MDIV_P4_MASK

/* Different P-STATES AVS supports (for GET_PSTATE/SET_PSTATE) */
#define AVS_PSTATE_P0
#define AVS_PSTATE_P1
#define AVS_PSTATE_P2
#define AVS_PSTATE_P3
#define AVS_PSTATE_P4
#define AVS_PSTATE_MAX

/* CPU L2 Interrupt Controller Registers */
#define AVS_CPU_L2_SET0
#define AVS_CPU_L2_INT_MASK

/* AVS Command Status Values */
#define AVS_STATUS_CLEAR
/* Command/notification accepted */
#define AVS_STATUS_SUCCESS
/* Command/notification rejected */
#define AVS_STATUS_FAILURE
/* Invalid command/notification (unknown) */
#define AVS_STATUS_INVALID
/* Non-AVS modes are not supported */
#define AVS_STATUS_NO_SUPP
/* Cannot set P-State until P-Map supplied */
#define AVS_STATUS_NO_MAP
/* Cannot change P-Map after initial P-Map set */
#define AVS_STATUS_MAP_SET
/* Max AVS status; higher numbers are used for debugging */
#define AVS_STATUS_MAX

/* Other AVS related constants */
#define AVS_LOOP_LIMIT
#define AVS_TIMEOUT
#define AVS_FIRMWARE_MAGIC

#define BRCM_AVS_CPUFREQ_PREFIX
#define BRCM_AVS_CPUFREQ_NAME
#define BRCM_AVS_CPU_DATA
#define BRCM_AVS_CPU_INTR
#define BRCM_AVS_HOST_INTR

struct pmap {};

struct private_data {};

static void __iomem *__map_region(const char *name)
{}

static unsigned long wait_for_avs_command(struct private_data *priv,
					  unsigned long timeout)
{}

static int __issue_avs_command(struct private_data *priv, unsigned int cmd,
			       unsigned int num_in, unsigned int num_out,
			       u32 args[])
{}

static irqreturn_t irq_handler(int irq, void *data)
{}

static char *brcm_avs_mode_to_string(unsigned int mode)
{}

static void brcm_avs_parse_p1(u32 p1, unsigned int *mdiv_p0, unsigned int *pdiv,
			      unsigned int *ndiv)
{}

static void brcm_avs_parse_p2(u32 p2, unsigned int *mdiv_p1,
			      unsigned int *mdiv_p2, unsigned int *mdiv_p3,
			      unsigned int *mdiv_p4)
{}

static int brcm_avs_get_pmap(struct private_data *priv, struct pmap *pmap)
{}

static int brcm_avs_set_pmap(struct private_data *priv, struct pmap *pmap)
{}

static int brcm_avs_get_pstate(struct private_data *priv, unsigned int *pstate)
{}

static int brcm_avs_set_pstate(struct private_data *priv, unsigned int pstate)
{}

static u32 brcm_avs_get_voltage(void __iomem *base)
{}

static u32 brcm_avs_get_frequency(void __iomem *base)
{}

/*
 * We determine which frequencies are supported by cycling through all P-states
 * and reading back what frequency we are running at for each P-state.
 */
static struct cpufreq_frequency_table *
brcm_avs_get_freq_table(struct device *dev, struct private_data *priv)
{}

/*
 * To ensure the right firmware is running we need to
 *    - check the MAGIC matches what we expect
 *    - brcm_avs_get_pmap() doesn't return -ENOTSUPP or -EINVAL
 * We need to set up our interrupt handling before calling brcm_avs_get_pmap()!
 */
static bool brcm_avs_is_firmware_loaded(struct private_data *priv)
{}

static unsigned int brcm_avs_cpufreq_get(unsigned int cpu)
{}

static int brcm_avs_target_index(struct cpufreq_policy *policy,
				 unsigned int index)
{}

static int brcm_avs_suspend(struct cpufreq_policy *policy)
{}

static int brcm_avs_resume(struct cpufreq_policy *policy)
{}

/*
 * All initialization code that we only want to execute once goes here. Setup
 * code that can be re-tried on every core (if it failed before) can go into
 * brcm_avs_cpufreq_init().
 */
static int brcm_avs_prepare_init(struct platform_device *pdev)
{}

static void brcm_avs_prepare_uninit(struct platform_device *pdev)
{}

static int brcm_avs_cpufreq_init(struct cpufreq_policy *policy)
{}

static ssize_t show_brcm_avs_pstate(struct cpufreq_policy *policy, char *buf)
{}

static ssize_t show_brcm_avs_mode(struct cpufreq_policy *policy, char *buf)
{}

static ssize_t show_brcm_avs_pmap(struct cpufreq_policy *policy, char *buf)
{}

static ssize_t show_brcm_avs_voltage(struct cpufreq_policy *policy, char *buf)
{}

static ssize_t show_brcm_avs_frequency(struct cpufreq_policy *policy, char *buf)
{}

cpufreq_freq_attr_ro();
cpufreq_freq_attr_ro();
cpufreq_freq_attr_ro();
cpufreq_freq_attr_ro();
cpufreq_freq_attr_ro();

static struct freq_attr *brcm_avs_cpufreq_attr[] =;

static struct cpufreq_driver brcm_avs_driver =;

static int brcm_avs_cpufreq_probe(struct platform_device *pdev)
{}

static void brcm_avs_cpufreq_remove(struct platform_device *pdev)
{}

static const struct of_device_id brcm_avs_cpufreq_match[] =;
MODULE_DEVICE_TABLE(of, brcm_avs_cpufreq_match);

static struct platform_driver brcm_avs_cpufreq_platdrv =;
module_platform_driver();

MODULE_AUTHOR();
MODULE_DESCRIPTION();
MODULE_LICENSE();