215 lines
6.6 KiB
C
215 lines
6.6 KiB
C
// SPDX-License-Identifier: GPL-2.0-only
|
|
/*
|
|
* Read-only register snapshot for the platina IPA v2.6L port.
|
|
*
|
|
* Register locations: Xiaomi platina-o-oss commit
|
|
* 0bb2780bccb9c7e05f0edf5db8860e779179b5f9, ipa_v2/ipa_reg.h and
|
|
* drivers/platform/msm/sps/bam.c (SPS_BAM_NDP_4K).
|
|
*
|
|
* No device alias, driver binding, reset, DMA, IRQ acknowledgement, or QMI
|
|
* messages. Clock references and MMIO reservations exist only during init.
|
|
*/
|
|
#include <linux/clk.h>
|
|
#include <linux/err.h>
|
|
#include <linux/init.h>
|
|
#include <linux/io.h>
|
|
#include <linux/ioport.h>
|
|
#include <linux/module.h>
|
|
#include <linux/of.h>
|
|
#include <linux/of_platform.h>
|
|
#include <linux/platform_device.h>
|
|
#include <linux/sysfs.h>
|
|
|
|
#define IPA_WRAPPER_BASE 0x14780000
|
|
#define IPA_REG_OFFSET 0x40000
|
|
#define IPA_REG_BASE (IPA_WRAPPER_BASE + IPA_REG_OFFSET)
|
|
#define IPA_REG_SIZE 0x1000
|
|
#define IPA_BAM_BASE 0x14784000
|
|
#define IPA_BAM_SIZE 0x26934
|
|
/* Original driver's SVS vote; RPM does not expose a measured frequency. */
|
|
#define IPA_SVS_RATE 75000000
|
|
|
|
#define IPA_COMP_HW_VERSION 0x30
|
|
#define IPA_VERSION 0x34
|
|
#define IPA_COMP_CFG 0x38
|
|
#define IPA_SHARED_MEM_SIZE 0x50
|
|
#define IPA_ENABLED_PIPES 0x5dc
|
|
#define BAM_CTRL 0x0
|
|
#define BAM_DESC_THRESHOLD 0x8
|
|
#define BAM_IRQ_STATUS 0x14
|
|
#define BAM_CNFG_BITS 0x7c
|
|
#define BAM_REVISION 0x1000
|
|
#define BAM_NUM_PIPES 0x1008
|
|
#define BAM_AHB_ERR_CTRL 0x1024
|
|
#define BAM_AHB_ERR_ADDR 0x1028
|
|
#define BAM_PIPE_ATTR_EE0 0x300c
|
|
#define BAM_PIPE_CTRL(n) (0x13000 + 0x1000 * (n))
|
|
#define BAM_PIPE_SW_OFSTS(n) (0x13800 + 0x1000 * (n))
|
|
|
|
static char snapshot[1024];
|
|
|
|
static int snapshot_get(char *buffer, const struct kernel_param *kp)
|
|
{
|
|
return sysfs_emit(buffer, "%s\n", snapshot);
|
|
}
|
|
|
|
static const struct kernel_param_ops snapshot_ops = {
|
|
.get = snapshot_get,
|
|
};
|
|
module_param_cb(snapshot, &snapshot_ops, NULL, 0400);
|
|
MODULE_PARM_DESC(snapshot, "Read-only IPA/BAM snapshot; does not prove datapath readiness");
|
|
|
|
static int __init platina_ipa_v2_probe_init(void)
|
|
{
|
|
struct platform_device *pdev;
|
|
struct device_node *node;
|
|
struct resource *resource;
|
|
struct clk *clock;
|
|
void __iomem *ipa, *bam;
|
|
u32 version, hardware, memory, bam_revision, bam_info, num_pipes;
|
|
unsigned long clock_rate, old_rate;
|
|
int ret, restore_ret;
|
|
|
|
if (!of_machine_is_compatible("xiaomi,platina"))
|
|
return -ENODEV;
|
|
|
|
node = of_find_compatible_node(NULL, NULL, "qcom,sdm660-ipa");
|
|
if (!node)
|
|
return -ENODEV;
|
|
pdev = of_find_device_by_node(node);
|
|
of_node_put(node);
|
|
if (!pdev)
|
|
return -EPROBE_DEFER;
|
|
|
|
/* Serialize against driver binding for the entire snapshot. */
|
|
device_lock(&pdev->dev);
|
|
if (pdev->dev.driver) {
|
|
ret = -EBUSY;
|
|
goto out_device;
|
|
}
|
|
resource = platform_get_resource(pdev, IORESOURCE_MEM, 0);
|
|
if (!resource || (resource->start != IPA_WRAPPER_BASE &&
|
|
resource->start != IPA_REG_BASE)) {
|
|
ret = -EINVAL;
|
|
goto out_device;
|
|
}
|
|
|
|
/* The old DT maps the wrapper, not the actual IPA register aperture. */
|
|
if (!request_mem_region(IPA_REG_BASE, IPA_REG_SIZE, KBUILD_MODNAME)) {
|
|
ret = -EBUSY;
|
|
goto out_device;
|
|
}
|
|
if (!request_mem_region(IPA_BAM_BASE, IPA_BAM_SIZE, KBUILD_MODNAME)) {
|
|
ret = -EBUSY;
|
|
goto out_ipa_region;
|
|
}
|
|
clock = clk_get(&pdev->dev, "core");
|
|
if (IS_ERR(clock)) {
|
|
ret = PTR_ERR(clock);
|
|
goto out_bam_region;
|
|
}
|
|
old_rate = clk_get_rate(clock);
|
|
/*
|
|
* Follow the vendor prepare-before-set order. This RPM provider ignores
|
|
* set_rate while unprepared, so an earlier successful call is no vote.
|
|
*/
|
|
ret = clk_prepare_enable(clock);
|
|
if (ret)
|
|
goto out_clock;
|
|
ret = clk_set_rate(clock, IPA_SVS_RATE);
|
|
if (ret)
|
|
goto out_restore_rate;
|
|
clock_rate = clk_get_rate(clock);
|
|
if (clock_rate != IPA_SVS_RATE) {
|
|
ret = -ENODEV;
|
|
goto out_restore_rate;
|
|
}
|
|
ipa = ioremap(IPA_REG_BASE, IPA_REG_SIZE);
|
|
if (!ipa) {
|
|
ret = -ENOMEM;
|
|
goto out_restore_rate;
|
|
}
|
|
bam = ioremap(IPA_BAM_BASE, IPA_BAM_SIZE);
|
|
if (!bam) {
|
|
ret = -ENOMEM;
|
|
goto out_unmap_ipa;
|
|
}
|
|
|
|
version = readl(ipa + IPA_VERSION);
|
|
hardware = readl(ipa + IPA_COMP_HW_VERSION);
|
|
memory = readl(ipa + IPA_SHARED_MEM_SIZE);
|
|
bam_revision = readl(bam + BAM_REVISION);
|
|
bam_info = readl(bam + BAM_NUM_PIPES);
|
|
num_pipes = bam_info & 0xff;
|
|
if (!version || version == U32_MAX || !bam_revision ||
|
|
bam_revision == U32_MAX || num_pipes < 10 || num_pipes > 20) {
|
|
dev_err(&pdev->dev,
|
|
"invalid snapshot: version=%#x hardware=%#x BAM=%#x pipes=%u\n",
|
|
version, hardware, bam_revision, num_pipes);
|
|
ret = -ENODEV;
|
|
goto out_unmap_bam;
|
|
}
|
|
|
|
scnprintf(snapshot, sizeof(snapshot),
|
|
"{\"datapath_ready\":false,\"core_vote_hz\":%u,"
|
|
"\"core_cached_hz\":%lu,"
|
|
"\"ipa_version\":%u,\"ipa_hw_version\":%u,\"ipa_cfg\":%u,"
|
|
"\"sram_size\":%u,\"sram_restricted\":%u,\"ipa_num_pipes\":%u,"
|
|
"\"bam_revision\":%u,\"bam_pipes\":%u,\"bam_ctrl\":%u,"
|
|
"\"bam_cfg_bits\":%u,\"bam_desc_threshold\":%u,"
|
|
"\"bam_ahb_err_ctrl\":%u,\"bam_ahb_err_addr\":%u,"
|
|
"\"bam_num_pipes_raw\":%u,"
|
|
"\"bam_irq_status\":%u,\"bam_ee0_pipes\":%u,"
|
|
"\"ap_lan_rx\":{\"pipe\":2,\"ctrl\":%u,\"offsets\":%u},"
|
|
"\"ap_command_tx\":{\"pipe\":3,\"ctrl\":%u,\"offsets\":%u},"
|
|
"\"ap_tx\":{\"pipe\":4,\"ctrl\":%u,\"offsets\":%u},"
|
|
"\"ap_wan_rx\":{\"pipe\":5,\"ctrl\":%u,\"offsets\":%u}}",
|
|
IPA_SVS_RATE, clock_rate, version, hardware, readl(ipa + IPA_COMP_CFG),
|
|
memory & 0xffff, memory >> 16, readl(ipa + IPA_ENABLED_PIPES),
|
|
bam_revision, num_pipes, readl(bam + BAM_CTRL),
|
|
readl(bam + BAM_CNFG_BITS), readl(bam + BAM_DESC_THRESHOLD),
|
|
readl(bam + BAM_AHB_ERR_CTRL), readl(bam + BAM_AHB_ERR_ADDR),
|
|
bam_info,
|
|
readl(bam + BAM_IRQ_STATUS), readl(bam + BAM_PIPE_ATTR_EE0),
|
|
readl(bam + BAM_PIPE_CTRL(2)), readl(bam + BAM_PIPE_SW_OFSTS(2)),
|
|
readl(bam + BAM_PIPE_CTRL(3)), readl(bam + BAM_PIPE_SW_OFSTS(3)),
|
|
readl(bam + BAM_PIPE_CTRL(4)), readl(bam + BAM_PIPE_SW_OFSTS(4)),
|
|
readl(bam + BAM_PIPE_CTRL(5)), readl(bam + BAM_PIPE_SW_OFSTS(5)));
|
|
dev_info(&pdev->dev, "read-only snapshot: %s\n", snapshot);
|
|
ret = 0;
|
|
|
|
out_unmap_bam:
|
|
iounmap(bam);
|
|
out_unmap_ipa:
|
|
iounmap(ipa);
|
|
out_restore_rate:
|
|
/* Restore while prepared: the RPM provider ignores an unprepared set. */
|
|
restore_ret = clk_set_rate(clock, old_rate);
|
|
if (restore_ret) {
|
|
dev_err(&pdev->dev, "could not restore IPA clock rate: %d\n",
|
|
restore_ret);
|
|
if (!ret)
|
|
ret = restore_ret;
|
|
}
|
|
clk_disable_unprepare(clock);
|
|
out_clock:
|
|
clk_put(clock);
|
|
out_bam_region:
|
|
release_mem_region(IPA_BAM_BASE, IPA_BAM_SIZE);
|
|
out_ipa_region:
|
|
release_mem_region(IPA_REG_BASE, IPA_REG_SIZE);
|
|
out_device:
|
|
device_unlock(&pdev->dev);
|
|
put_device(&pdev->dev);
|
|
return ret;
|
|
}
|
|
|
|
static void __exit platina_ipa_v2_probe_exit(void)
|
|
{
|
|
}
|
|
|
|
module_init(platina_ipa_v2_probe_init);
|
|
module_exit(platina_ipa_v2_probe_exit);
|
|
MODULE_LICENSE("GPL");
|
|
MODULE_DESCRIPTION("Platina IPA v2.6L read-only bring-up diagnostic");
|