Add samsung specific changes
This commit is contained in:
@@ -34,6 +34,16 @@ config SPMI_MSM_PMIC_ARB
|
||||
This is required for communicating with Qualcomm PMICs and
|
||||
other devices that have the SPMI interface.
|
||||
|
||||
config SPMI_MSM_PMIC_ARB_DEBUG
|
||||
tristate "QTI SPMI Debug Controller (PMIC Arbiter)"
|
||||
depends on ARCH_QCOM || COMPILE_TEST
|
||||
depends on HAS_IOMEM
|
||||
help
|
||||
If you say yes to this option, support will be included for the
|
||||
built-in SPMI PMIC Arbiter debug interface on Qualcomm Technologies,
|
||||
Inc. (QTI) MSM family processors. This feature is available on chips
|
||||
with PMIC arbiter version 5 and above.
|
||||
|
||||
config SPMI_MTK_PMIF
|
||||
tristate "Mediatek SPMI Controller (PMIC Arbiter)"
|
||||
depends on ARCH_MEDIATEK || COMPILE_TEST
|
||||
|
@@ -6,4 +6,5 @@ obj-$(CONFIG_SPMI) += spmi.o
|
||||
|
||||
obj-$(CONFIG_SPMI_HISI3670) += hisi-spmi-controller.o
|
||||
obj-$(CONFIG_SPMI_MSM_PMIC_ARB) += spmi-pmic-arb.o
|
||||
obj-$(CONFIG_SPMI_MSM_PMIC_ARB_DEBUG) += spmi-pmic-arb-debug.o
|
||||
obj-$(CONFIG_SPMI_MTK_PMIF) += spmi-mtk-pmif.o
|
||||
|
372
drivers/spmi/spmi-pmic-arb-debug.c
Normal file
372
drivers/spmi/spmi-pmic-arb-debug.c
Normal file
@@ -0,0 +1,372 @@
|
||||
// SPDX-License-Identifier: GPL-2.0-only
|
||||
/*
|
||||
* Copyright (c) 2012-2018, 2020, The Linux Foundation. All rights reserved.
|
||||
* Copyright (c) 2023, Qualcomm Innovation Center, Inc. All rights reserved.
|
||||
*/
|
||||
|
||||
#include <linux/clk.h>
|
||||
#include <linux/delay.h>
|
||||
#include <linux/err.h>
|
||||
#include <linux/io.h>
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/module.h>
|
||||
#include <linux/of.h>
|
||||
#include <linux/platform_device.h>
|
||||
#include <linux/slab.h>
|
||||
#include <linux/spmi.h>
|
||||
|
||||
/* PMIC Arbiter debug register offsets */
|
||||
#define PMIC_ARB_DEBUG_CMD0 0x00
|
||||
#define PMIC_ARB_DEBUG_CMD1 0x04
|
||||
#define PMIC_ARB_DEBUG_CMD2 0x08
|
||||
#define PMIC_ARB_DEBUG_CMD3 0x0C
|
||||
#define PMIC_ARB_DEBUG_STATUS 0x14
|
||||
#define PMIC_ARB_DEBUG_WDATA(n) (0x18 + 4 * (n))
|
||||
#define PMIC_ARB_DEBUG_RDATA(n) (0x38 + 4 * (n))
|
||||
|
||||
/* Transaction status flag bits */
|
||||
enum pmic_arb_chnl_status {
|
||||
PMIC_ARB_STATUS_DONE = BIT(0),
|
||||
PMIC_ARB_STATUS_FAILURE = BIT(1),
|
||||
PMIC_ARB_STATUS_DENIED = BIT(2),
|
||||
PMIC_ARB_STATUS_DROPPED = BIT(3),
|
||||
};
|
||||
|
||||
/* Command Opcodes */
|
||||
enum pmic_arb_cmd_op_code {
|
||||
PMIC_ARB_OP_EXT_WRITEL = 0,
|
||||
PMIC_ARB_OP_EXT_READL = 1,
|
||||
PMIC_ARB_OP_EXT_WRITE = 2,
|
||||
PMIC_ARB_OP_RESET = 3,
|
||||
PMIC_ARB_OP_SLEEP = 4,
|
||||
PMIC_ARB_OP_SHUTDOWN = 5,
|
||||
PMIC_ARB_OP_WAKEUP = 6,
|
||||
PMIC_ARB_OP_AUTHENTICATE = 7,
|
||||
PMIC_ARB_OP_MSTR_READ = 8,
|
||||
PMIC_ARB_OP_MSTR_WRITE = 9,
|
||||
PMIC_ARB_OP_EXT_READ = 13,
|
||||
PMIC_ARB_OP_WRITE = 14,
|
||||
PMIC_ARB_OP_READ = 15,
|
||||
PMIC_ARB_OP_ZERO_WRITE = 16,
|
||||
};
|
||||
|
||||
#define PMIC_ARB_TIMEOUT_US 100
|
||||
#define PMIC_ARB_MAX_TRANS_BYTES 8
|
||||
#define PMIC_ARB_MAX_SID 0xF
|
||||
|
||||
/**
|
||||
* spmi_pmic_arb_debug - SPMI PMIC Arbiter debug object
|
||||
*
|
||||
* @addr: base address of SPMI PMIC arbiter debug module
|
||||
* @lock: lock to synchronize accesses.
|
||||
*/
|
||||
struct spmi_pmic_arb_debug {
|
||||
void __iomem *addr;
|
||||
raw_spinlock_t lock;
|
||||
struct clk *clock;
|
||||
};
|
||||
|
||||
static inline void pmic_arb_debug_write(struct spmi_pmic_arb_debug *pa,
|
||||
u32 offset, u32 val)
|
||||
{
|
||||
writel_relaxed(val, pa->addr + offset);
|
||||
}
|
||||
|
||||
static inline u32 pmic_arb_debug_read(struct spmi_pmic_arb_debug *pa,
|
||||
u32 offset)
|
||||
{
|
||||
return readl_relaxed(pa->addr + offset);
|
||||
}
|
||||
|
||||
/* pa->lock must be held by the caller. */
|
||||
static int pmic_arb_debug_wait_for_done(struct spmi_controller *ctrl)
|
||||
{
|
||||
struct spmi_pmic_arb_debug *pa = spmi_controller_get_drvdata(ctrl);
|
||||
u32 status = 0;
|
||||
u32 timeout = PMIC_ARB_TIMEOUT_US;
|
||||
|
||||
while (timeout--) {
|
||||
status = pmic_arb_debug_read(pa, PMIC_ARB_DEBUG_STATUS);
|
||||
|
||||
if (status & PMIC_ARB_STATUS_DONE) {
|
||||
if (status & PMIC_ARB_STATUS_DENIED) {
|
||||
dev_err(&ctrl->dev, "%s: transaction denied (0x%x)\n",
|
||||
__func__, status);
|
||||
return -EPERM;
|
||||
}
|
||||
|
||||
if (status & PMIC_ARB_STATUS_FAILURE) {
|
||||
dev_err(&ctrl->dev, "%s: transaction failed (0x%x)\n",
|
||||
__func__, status);
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
if (status & PMIC_ARB_STATUS_DROPPED) {
|
||||
dev_err(&ctrl->dev, "%s: transaction dropped (0x%x)\n",
|
||||
__func__, status);
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
udelay(1);
|
||||
}
|
||||
|
||||
dev_err(&ctrl->dev, "%s: timeout, status 0x%x\n", __func__, status);
|
||||
return -ETIMEDOUT;
|
||||
}
|
||||
|
||||
/* pa->lock must be held by the caller. */
|
||||
static int pmic_arb_debug_issue_command(struct spmi_controller *ctrl, u8 opc,
|
||||
u8 sid, u16 addr, size_t len)
|
||||
{
|
||||
struct spmi_pmic_arb_debug *pa = spmi_controller_get_drvdata(ctrl);
|
||||
u16 pid = (addr >> 8) & 0xFF;
|
||||
u16 offset = addr & 0xFF;
|
||||
u8 byte_count = len - 1;
|
||||
|
||||
if (byte_count >= PMIC_ARB_MAX_TRANS_BYTES) {
|
||||
dev_err(&ctrl->dev, "pmic-arb supports 1 to %d bytes per transaction, but %zu requested\n",
|
||||
PMIC_ARB_MAX_TRANS_BYTES, len);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (sid > PMIC_ARB_MAX_SID) {
|
||||
dev_err(&ctrl->dev, "pmic-arb supports sid 0 to %u, but %u requested\n",
|
||||
PMIC_ARB_MAX_SID, sid);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
pmic_arb_debug_write(pa, PMIC_ARB_DEBUG_CMD3, offset);
|
||||
pmic_arb_debug_write(pa, PMIC_ARB_DEBUG_CMD2, pid);
|
||||
pmic_arb_debug_write(pa, PMIC_ARB_DEBUG_CMD1, (byte_count << 4) | sid);
|
||||
|
||||
/* Start the transaction */
|
||||
pmic_arb_debug_write(pa, PMIC_ARB_DEBUG_CMD0, opc << 1);
|
||||
|
||||
return pmic_arb_debug_wait_for_done(ctrl);
|
||||
}
|
||||
|
||||
/* Non-data command */
|
||||
static int pmic_arb_debug_cmd(struct spmi_controller *ctrl, u8 opc, u8 sid)
|
||||
{
|
||||
dev_dbg(&ctrl->dev, "cmd op:0x%x sid:%d\n", opc, sid);
|
||||
|
||||
/* Check for valid non-data command */
|
||||
if (opc < SPMI_CMD_RESET || opc > SPMI_CMD_WAKEUP)
|
||||
return -EINVAL;
|
||||
|
||||
return -EOPNOTSUPP;
|
||||
}
|
||||
|
||||
static int pmic_arb_debug_read_cmd(struct spmi_controller *ctrl, u8 opc, u8 sid,
|
||||
u16 addr, u8 *buf, size_t len)
|
||||
{
|
||||
struct spmi_pmic_arb_debug *pa = spmi_controller_get_drvdata(ctrl);
|
||||
unsigned long flags;
|
||||
int i, rc;
|
||||
|
||||
/* Check the opcode */
|
||||
if (opc >= 0x60 && opc <= 0x7F)
|
||||
opc = PMIC_ARB_OP_READ;
|
||||
else if (opc >= 0x20 && opc <= 0x2F)
|
||||
opc = PMIC_ARB_OP_EXT_READ;
|
||||
else if (opc >= 0x38 && opc <= 0x3F)
|
||||
opc = PMIC_ARB_OP_EXT_READL;
|
||||
else
|
||||
return -EINVAL;
|
||||
|
||||
rc = clk_prepare_enable(pa->clock);
|
||||
if (rc) {
|
||||
pr_err("%s: failed to enable core clock, rc=%d\n",
|
||||
__func__, rc);
|
||||
return rc;
|
||||
}
|
||||
raw_spin_lock_irqsave(&pa->lock, flags);
|
||||
|
||||
rc = pmic_arb_debug_issue_command(ctrl, opc, sid, addr, len);
|
||||
if (rc)
|
||||
goto done;
|
||||
|
||||
/* Read data from FIFO */
|
||||
for (i = 0; i < len; i++)
|
||||
buf[i] = pmic_arb_debug_read(pa, PMIC_ARB_DEBUG_RDATA(i));
|
||||
done:
|
||||
raw_spin_unlock_irqrestore(&pa->lock, flags);
|
||||
clk_disable_unprepare(pa->clock);
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
static int pmic_arb_debug_write_cmd(struct spmi_controller *ctrl, u8 opc,
|
||||
u8 sid, u16 addr, const u8 *buf, size_t len)
|
||||
{
|
||||
struct spmi_pmic_arb_debug *pa = spmi_controller_get_drvdata(ctrl);
|
||||
unsigned long flags;
|
||||
int i, rc;
|
||||
|
||||
if (len > PMIC_ARB_MAX_TRANS_BYTES) {
|
||||
dev_err(&ctrl->dev, "pmic-arb supports 1 to %d bytes per transaction, but %zu requested\n",
|
||||
PMIC_ARB_MAX_TRANS_BYTES, len);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
/* Check the opcode */
|
||||
if (opc >= 0x40 && opc <= 0x5F)
|
||||
opc = PMIC_ARB_OP_WRITE;
|
||||
else if (opc >= 0x00 && opc <= 0x0F)
|
||||
opc = PMIC_ARB_OP_EXT_WRITE;
|
||||
else if (opc >= 0x30 && opc <= 0x37)
|
||||
opc = PMIC_ARB_OP_EXT_WRITEL;
|
||||
else if (opc >= 0x80)
|
||||
opc = PMIC_ARB_OP_ZERO_WRITE;
|
||||
else
|
||||
return -EINVAL;
|
||||
|
||||
rc = clk_prepare_enable(pa->clock);
|
||||
if (rc) {
|
||||
pr_err("%s: failed to enable core clock, rc=%d\n",
|
||||
__func__, rc);
|
||||
return rc;
|
||||
}
|
||||
raw_spin_lock_irqsave(&pa->lock, flags);
|
||||
|
||||
/* Write data to FIFO */
|
||||
for (i = 0; i < len; i++)
|
||||
pmic_arb_debug_write(pa, PMIC_ARB_DEBUG_WDATA(i), buf[i]);
|
||||
|
||||
rc = pmic_arb_debug_issue_command(ctrl, opc, sid, addr, len);
|
||||
|
||||
raw_spin_unlock_irqrestore(&pa->lock, flags);
|
||||
clk_disable_unprepare(pa->clock);
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
static int spmi_pmic_arb_debug_probe(struct platform_device *pdev)
|
||||
{
|
||||
struct spmi_pmic_arb_debug *pa;
|
||||
struct spmi_controller *ctrl;
|
||||
struct resource *res;
|
||||
int rc;
|
||||
u32 fuse_val, fuse_bit;
|
||||
void __iomem *fuse_addr;
|
||||
bool is_disable_fuse = true;
|
||||
|
||||
/* Check if the debug bus is enabled or disabled by a fuse. */
|
||||
rc = of_property_read_u32(pdev->dev.of_node, "qcom,fuse-disable-bit",
|
||||
&fuse_bit);
|
||||
if (rc) {
|
||||
is_disable_fuse = false;
|
||||
rc = of_property_read_u32(pdev->dev.of_node,
|
||||
"qcom,fuse-enable-bit",
|
||||
&fuse_bit);
|
||||
}
|
||||
if (!rc) {
|
||||
if (fuse_bit > 31) {
|
||||
dev_err(&pdev->dev, "qcom,fuse-%s-bit supports values 0 to 31, but %u specified\n",
|
||||
is_disable_fuse ? "disable" : "enable",
|
||||
fuse_bit);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
res = platform_get_resource_byname(pdev, IORESOURCE_MEM,
|
||||
"fuse");
|
||||
if (!res) {
|
||||
dev_err(&pdev->dev, "fuse address not specified\n");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
fuse_addr = ioremap(res->start, resource_size(res));
|
||||
if (!fuse_addr)
|
||||
return -EINVAL;
|
||||
|
||||
fuse_val = readl_relaxed(fuse_addr);
|
||||
iounmap(fuse_addr);
|
||||
|
||||
if (!!(fuse_val & BIT(fuse_bit)) == is_disable_fuse) {
|
||||
dev_err(&pdev->dev, "SPMI PMIC arbiter debug bus disabled by fuse\n");
|
||||
return -ENODEV;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
ctrl = spmi_controller_alloc(&pdev->dev, sizeof(*pa));
|
||||
if (!ctrl)
|
||||
return -ENOMEM;
|
||||
|
||||
pa = spmi_controller_get_drvdata(ctrl);
|
||||
|
||||
res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "core");
|
||||
if (!res) {
|
||||
dev_err(&pdev->dev, "core address not specified\n");
|
||||
rc = -EINVAL;
|
||||
goto err_put_ctrl;
|
||||
}
|
||||
|
||||
pa->addr = devm_ioremap_resource(&ctrl->dev, res);
|
||||
if (IS_ERR(pa->addr)) {
|
||||
rc = PTR_ERR(pa->addr);
|
||||
goto err_put_ctrl;
|
||||
}
|
||||
|
||||
if (of_find_property(pdev->dev.of_node, "clock-names", NULL)) {
|
||||
pa->clock = devm_clk_get(&pdev->dev, "core_clk");
|
||||
if (IS_ERR(pa->clock)) {
|
||||
rc = PTR_ERR(pa->clock);
|
||||
if (rc != -EPROBE_DEFER)
|
||||
dev_err(&pdev->dev, "unable to request core clock, rc=%d\n",
|
||||
rc);
|
||||
goto err_put_ctrl;
|
||||
}
|
||||
}
|
||||
|
||||
platform_set_drvdata(pdev, ctrl);
|
||||
raw_spin_lock_init(&pa->lock);
|
||||
|
||||
ctrl->cmd = pmic_arb_debug_cmd;
|
||||
ctrl->read_cmd = pmic_arb_debug_read_cmd;
|
||||
ctrl->write_cmd = pmic_arb_debug_write_cmd;
|
||||
|
||||
rc = spmi_controller_add(ctrl);
|
||||
if (rc)
|
||||
goto err_put_ctrl;
|
||||
|
||||
dev_info(&ctrl->dev, "SPMI PMIC arbiter debug bus controller added\n");
|
||||
|
||||
return 0;
|
||||
|
||||
err_put_ctrl:
|
||||
spmi_controller_put(ctrl);
|
||||
return rc;
|
||||
}
|
||||
|
||||
static int spmi_pmic_arb_debug_remove(struct platform_device *pdev)
|
||||
{
|
||||
struct spmi_controller *ctrl = platform_get_drvdata(pdev);
|
||||
|
||||
spmi_controller_remove(ctrl);
|
||||
spmi_controller_put(ctrl);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const struct of_device_id spmi_pmic_arb_debug_match_table[] = {
|
||||
{ .compatible = "qcom,spmi-pmic-arb-debug", },
|
||||
{},
|
||||
};
|
||||
MODULE_DEVICE_TABLE(of, spmi_pmic_arb_debug_match_table);
|
||||
|
||||
static struct platform_driver spmi_pmic_arb_debug_driver = {
|
||||
.probe = spmi_pmic_arb_debug_probe,
|
||||
.remove = spmi_pmic_arb_debug_remove,
|
||||
.driver = {
|
||||
.name = "spmi_pmic_arb_debug",
|
||||
.of_match_table = spmi_pmic_arb_debug_match_table,
|
||||
},
|
||||
};
|
||||
|
||||
module_platform_driver(spmi_pmic_arb_debug_driver);
|
||||
|
||||
MODULE_LICENSE("GPL");
|
||||
MODULE_ALIAS("platform:spmi_pmic_arb_debug");
|
@@ -1,8 +1,9 @@
|
||||
// SPDX-License-Identifier: GPL-2.0-only
|
||||
/*
|
||||
* Copyright (c) 2012-2015, 2017, 2021, The Linux Foundation. All rights reserved.
|
||||
*/
|
||||
/* Copyright (c) 2012-2021, The Linux Foundation. All rights reserved. */
|
||||
/* Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved. */
|
||||
|
||||
#include <linux/bitmap.h>
|
||||
#include <linux/debugfs.h>
|
||||
#include <linux/delay.h>
|
||||
#include <linux/err.h>
|
||||
#include <linux/interrupt.h>
|
||||
@@ -13,9 +14,12 @@
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/module.h>
|
||||
#include <linux/of.h>
|
||||
#include <linux/of_platform.h>
|
||||
#include <linux/platform_device.h>
|
||||
#include <linux/slab.h>
|
||||
#include <linux/spmi.h>
|
||||
#include <linux/string.h>
|
||||
#include <linux/soc/qcom/spmi-pmic-arb.h>
|
||||
|
||||
/* PMIC Arbiter configuration registers */
|
||||
#define PMIC_ARB_VERSION 0x0000
|
||||
@@ -130,6 +134,8 @@ struct apid_data {
|
||||
*
|
||||
* @rd_base: on v1 "core", on v2 "observer" register base off DT.
|
||||
* @wr_base: on v1 "core", on v2 "chnls" register base off DT.
|
||||
* @wr_base_phys: Base physical address of the register range used for
|
||||
* SPMI write commands.
|
||||
* @intr: address of the SPMI interrupt control registers.
|
||||
* @cnfg: address of the PMIC Arbiter configuration registers.
|
||||
* @lock: lock to synchronize accesses.
|
||||
@@ -151,10 +157,13 @@ struct apid_data {
|
||||
* @last_apid: Highest value APID in use
|
||||
* @apid_data: Table of data for all APIDs
|
||||
* @max_periphs: Number of elements in apid_data[]
|
||||
* @debugfs: debugfs directory pointer
|
||||
* @debug_spmi_addr: SPMI address used for debugfs operations
|
||||
*/
|
||||
struct spmi_pmic_arb {
|
||||
void __iomem *rd_base;
|
||||
void __iomem *wr_base;
|
||||
phys_addr_t wr_base_phys;
|
||||
void __iomem *intr;
|
||||
void __iomem *cnfg;
|
||||
void __iomem *core;
|
||||
@@ -177,6 +186,8 @@ struct spmi_pmic_arb {
|
||||
u16 last_apid;
|
||||
struct apid_data *apid_data;
|
||||
int max_periphs;
|
||||
struct dentry *debugfs;
|
||||
u32 debug_spmi_addr;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -199,6 +210,9 @@ struct spmi_pmic_arb {
|
||||
* on v2 address of SPMI_PIC_IRQ_CLEARn.
|
||||
* @apid_map_offset: offset of PMIC_ARB_REG_CHNLn
|
||||
* @apid_owner: on v2 and later address of SPMI_PERIPHn_2OWNER_TABLE_REG
|
||||
* @wr_addr_map: maps from an SPMI address to the physical address
|
||||
* range of the registers used to perform an SPMI write
|
||||
* command to the SPMI address.
|
||||
*/
|
||||
struct pmic_arb_ver_ops {
|
||||
const char *ver_str;
|
||||
@@ -216,6 +230,8 @@ struct pmic_arb_ver_ops {
|
||||
void __iomem *(*irq_clear)(struct spmi_pmic_arb *pmic_arb, u16 n);
|
||||
u32 (*apid_map_offset)(u16 n);
|
||||
void __iomem *(*apid_owner)(struct spmi_pmic_arb *pmic_arb, u16 n);
|
||||
int (*wr_addr_map)(struct spmi_pmic_arb *pmic_arb, u8 sid, u16 addr,
|
||||
struct resource *res_out);
|
||||
};
|
||||
|
||||
static inline void pmic_arb_base_write(struct spmi_pmic_arb *pmic_arb,
|
||||
@@ -996,6 +1012,21 @@ static int pmic_arb_offset_v1(struct spmi_pmic_arb *pmic_arb, u8 sid, u16 addr,
|
||||
return 0x800 + 0x80 * pmic_arb->channel;
|
||||
}
|
||||
|
||||
static int pmic_arb_wr_addr_map_v1(struct spmi_pmic_arb *pmic_arb, u8 sid,
|
||||
u16 addr, struct resource *res_out)
|
||||
{
|
||||
int rc;
|
||||
|
||||
rc = pmic_arb_offset_v1(pmic_arb, sid, addr, PMIC_ARB_CHANNEL_RW);
|
||||
if (rc < 0)
|
||||
return rc;
|
||||
|
||||
res_out->start = pmic_arb->wr_base_phys + rc;
|
||||
res_out->end = res_out->start + 0x80 - 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static u16 pmic_arb_find_apid(struct spmi_pmic_arb *pmic_arb, u16 ppid)
|
||||
{
|
||||
struct apid_data *apidd = &pmic_arb->apid_data[pmic_arb->last_apid];
|
||||
@@ -1144,6 +1175,21 @@ static int pmic_arb_offset_v2(struct spmi_pmic_arb *pmic_arb, u8 sid, u16 addr,
|
||||
return 0x1000 * pmic_arb->ee + 0x8000 * apid;
|
||||
}
|
||||
|
||||
static int pmic_arb_wr_addr_map_v2(struct spmi_pmic_arb *pmic_arb, u8 sid,
|
||||
u16 addr, struct resource *res_out)
|
||||
{
|
||||
int rc;
|
||||
|
||||
rc = pmic_arb_offset_v2(pmic_arb, sid, addr, PMIC_ARB_CHANNEL_RW);
|
||||
if (rc < 0)
|
||||
return rc;
|
||||
|
||||
res_out->start = pmic_arb->wr_base_phys + rc;
|
||||
res_out->end = res_out->start + 0x1000 - 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* v5 offset per ee and per apid for observer channels and per apid for
|
||||
* read/write channels.
|
||||
@@ -1178,6 +1224,21 @@ static int pmic_arb_offset_v5(struct spmi_pmic_arb *pmic_arb, u8 sid, u16 addr,
|
||||
return offset;
|
||||
}
|
||||
|
||||
static int pmic_arb_wr_addr_map_v5(struct spmi_pmic_arb *pmic_arb, u8 sid,
|
||||
u16 addr, struct resource *res_out)
|
||||
{
|
||||
int rc;
|
||||
|
||||
rc = pmic_arb_offset_v5(pmic_arb, sid, addr, PMIC_ARB_CHANNEL_RW);
|
||||
if (rc < 0)
|
||||
return rc;
|
||||
|
||||
res_out->start = pmic_arb->wr_base_phys + rc;
|
||||
res_out->end = res_out->start + 0x10000 - 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* v7 offset per ee and per apid for observer channels and per apid for
|
||||
* read/write channels.
|
||||
@@ -1212,6 +1273,21 @@ static int pmic_arb_offset_v7(struct spmi_pmic_arb *pmic_arb, u8 sid, u16 addr,
|
||||
return offset;
|
||||
}
|
||||
|
||||
static int pmic_arb_wr_addr_map_v7(struct spmi_pmic_arb *pmic_arb, u8 sid,
|
||||
u16 addr, struct resource *res_out)
|
||||
{
|
||||
int rc;
|
||||
|
||||
rc = pmic_arb_offset_v7(pmic_arb, sid, addr, PMIC_ARB_CHANNEL_RW);
|
||||
if (rc < 0)
|
||||
return rc;
|
||||
|
||||
res_out->start = pmic_arb->wr_base_phys + rc;
|
||||
res_out->end = res_out->start + 0x1000 - 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static u32 pmic_arb_fmt_cmd_v1(u8 opc, u8 sid, u16 addr, u8 bc)
|
||||
{
|
||||
return (opc << 27) | ((sid & 0xf) << 20) | (addr << 4) | (bc & 0x7);
|
||||
@@ -1368,6 +1444,7 @@ static const struct pmic_arb_ver_ops pmic_arb_v1 = {
|
||||
.irq_clear = pmic_arb_irq_clear_v1,
|
||||
.apid_map_offset = pmic_arb_apid_map_offset_v2,
|
||||
.apid_owner = pmic_arb_apid_owner_v2,
|
||||
.wr_addr_map = pmic_arb_wr_addr_map_v1,
|
||||
};
|
||||
|
||||
static const struct pmic_arb_ver_ops pmic_arb_v2 = {
|
||||
@@ -1382,6 +1459,7 @@ static const struct pmic_arb_ver_ops pmic_arb_v2 = {
|
||||
.irq_clear = pmic_arb_irq_clear_v2,
|
||||
.apid_map_offset = pmic_arb_apid_map_offset_v2,
|
||||
.apid_owner = pmic_arb_apid_owner_v2,
|
||||
.wr_addr_map = pmic_arb_wr_addr_map_v2,
|
||||
};
|
||||
|
||||
static const struct pmic_arb_ver_ops pmic_arb_v3 = {
|
||||
@@ -1396,6 +1474,7 @@ static const struct pmic_arb_ver_ops pmic_arb_v3 = {
|
||||
.irq_clear = pmic_arb_irq_clear_v2,
|
||||
.apid_map_offset = pmic_arb_apid_map_offset_v2,
|
||||
.apid_owner = pmic_arb_apid_owner_v2,
|
||||
.wr_addr_map = pmic_arb_wr_addr_map_v2,
|
||||
};
|
||||
|
||||
static const struct pmic_arb_ver_ops pmic_arb_v5 = {
|
||||
@@ -1410,6 +1489,7 @@ static const struct pmic_arb_ver_ops pmic_arb_v5 = {
|
||||
.irq_clear = pmic_arb_irq_clear_v5,
|
||||
.apid_map_offset = pmic_arb_apid_map_offset_v5,
|
||||
.apid_owner = pmic_arb_apid_owner_v2,
|
||||
.wr_addr_map = pmic_arb_wr_addr_map_v5,
|
||||
};
|
||||
|
||||
static const struct pmic_arb_ver_ops pmic_arb_v7 = {
|
||||
@@ -1424,6 +1504,7 @@ static const struct pmic_arb_ver_ops pmic_arb_v7 = {
|
||||
.irq_clear = pmic_arb_irq_clear_v7,
|
||||
.apid_map_offset = pmic_arb_apid_map_offset_v7,
|
||||
.apid_owner = pmic_arb_apid_owner_v7,
|
||||
.wr_addr_map = pmic_arb_wr_addr_map_v7,
|
||||
};
|
||||
|
||||
static const struct irq_domain_ops pmic_arb_irq_domain_ops = {
|
||||
@@ -1433,6 +1514,180 @@ static const struct irq_domain_ops pmic_arb_irq_domain_ops = {
|
||||
.translate = qpnpint_irq_domain_translate,
|
||||
};
|
||||
|
||||
static int _spmi_pmic_arb_map_address(struct spmi_pmic_arb *pmic_arb,
|
||||
u32 spmi_address, struct resource *res_out)
|
||||
{
|
||||
u32 sid, addr;
|
||||
|
||||
sid = (spmi_address >> 16) & 0xF;
|
||||
addr = spmi_address & 0xFFFF;
|
||||
|
||||
return pmic_arb->ver_ops->wr_addr_map(pmic_arb, sid, addr, res_out);
|
||||
}
|
||||
|
||||
/**
|
||||
* spmi_pmic_arb_map_address() - returns physical addresses of registers used to
|
||||
* write to the PMIC peripheral at spmi_address
|
||||
* @dev: Consumer device pointer
|
||||
* @spmi_address: 20-bit SPMI address of the form: 0xSPPPP
|
||||
* where S = global PMIC SID and
|
||||
* PPPP = SPMI address within the slave
|
||||
* @res_out: Resource struct (allocated by the caller) in which
|
||||
* physical addresses for the range are passed via start
|
||||
* and end elements
|
||||
*
|
||||
* Returns: 0 on success or an errno on failure.
|
||||
*/
|
||||
int spmi_pmic_arb_map_address(const struct device *dev, u32 spmi_address,
|
||||
struct resource *res_out)
|
||||
{
|
||||
struct device_node *ctrl_node;
|
||||
struct platform_device *ctrl_pdev;
|
||||
struct spmi_controller *ctrl;
|
||||
struct spmi_pmic_arb *pmic_arb;
|
||||
|
||||
if (!dev || !dev->of_node || !res_out) {
|
||||
pr_err("%s: Invalid pointer\n", __func__);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
ctrl_node = of_parse_phandle(dev->of_node, "qcom,pmic-arb", 0);
|
||||
if (!ctrl_node) {
|
||||
pr_err("%s: Could not find PMIC arbiter node via qcom,pmic-arb property\n",
|
||||
__func__);
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
ctrl_pdev = of_find_device_by_node(ctrl_node);
|
||||
of_node_put(ctrl_node);
|
||||
if (!ctrl_pdev)
|
||||
return -EPROBE_DEFER;
|
||||
|
||||
ctrl = platform_get_drvdata(ctrl_pdev);
|
||||
if (!ctrl)
|
||||
return -EPROBE_DEFER;
|
||||
|
||||
pmic_arb = spmi_controller_get_drvdata(ctrl);
|
||||
if (!pmic_arb) {
|
||||
pr_err("Missing PMIC arbiter device\n");
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
return _spmi_pmic_arb_map_address(pmic_arb, spmi_address, res_out);
|
||||
}
|
||||
EXPORT_SYMBOL(spmi_pmic_arb_map_address);
|
||||
|
||||
#ifdef CONFIG_DEBUG_FS
|
||||
static int debug_spmi_addr_get(void *data, u64 *val)
|
||||
{
|
||||
struct spmi_pmic_arb *pmic_arb = data;
|
||||
|
||||
*val = pmic_arb->debug_spmi_addr;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int debug_spmi_addr_set(void *data, u64 val)
|
||||
{
|
||||
struct spmi_pmic_arb *pmic_arb = data;
|
||||
|
||||
pmic_arb->debug_spmi_addr = val;
|
||||
|
||||
return 0;
|
||||
}
|
||||
DEFINE_DEBUGFS_ATTRIBUTE(debug_spmi_addr_fops, debug_spmi_addr_get,
|
||||
debug_spmi_addr_set, "0x%05llX\n");
|
||||
|
||||
static int debug_soc_start_addr_get(void *data, u64 *val)
|
||||
{
|
||||
struct spmi_pmic_arb *pmic_arb = data;
|
||||
struct resource res = {0};
|
||||
int err;
|
||||
|
||||
err = _spmi_pmic_arb_map_address(pmic_arb, pmic_arb->debug_spmi_addr,
|
||||
&res);
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
*val = res.start;
|
||||
|
||||
return 0;
|
||||
}
|
||||
DEFINE_DEBUGFS_ATTRIBUTE(debug_soc_start_addr_fops, debug_soc_start_addr_get,
|
||||
NULL, "0x%llX\n");
|
||||
|
||||
static int debug_soc_end_addr_get(void *data, u64 *val)
|
||||
{
|
||||
struct spmi_pmic_arb *pmic_arb = data;
|
||||
struct resource res = {0};
|
||||
int err;
|
||||
|
||||
err = _spmi_pmic_arb_map_address(pmic_arb, pmic_arb->debug_spmi_addr,
|
||||
&res);
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
*val = res.end;
|
||||
|
||||
return 0;
|
||||
}
|
||||
DEFINE_DEBUGFS_ATTRIBUTE(debug_soc_end_addr_fops, debug_soc_end_addr_get,
|
||||
NULL, "0x%llX\n");
|
||||
|
||||
static void spmi_pmic_arb_debugfs_init(struct spmi_pmic_arb *pmic_arb)
|
||||
{
|
||||
struct dentry *dir, *file;
|
||||
char buf[10];
|
||||
|
||||
scnprintf(buf, sizeof(buf), "spmi%u", pmic_arb->spmic->nr);
|
||||
|
||||
dir = debugfs_create_dir(buf, NULL);
|
||||
if (IS_ERR(dir)) {
|
||||
dev_err(&pmic_arb->spmic->dev, "Could not create %s debugfs directory, rc=%ld\n",
|
||||
buf, PTR_ERR(dir));
|
||||
return;
|
||||
}
|
||||
pmic_arb->debugfs = dir;
|
||||
|
||||
dir = debugfs_create_dir("address_map", pmic_arb->debugfs);
|
||||
if (IS_ERR(dir)) {
|
||||
dev_err(&pmic_arb->spmic->dev, "Could not create address_map debugfs directory, rc=%ld\n",
|
||||
PTR_ERR(dir));
|
||||
goto error;
|
||||
}
|
||||
|
||||
file = debugfs_create_file_unsafe("spmi_addr", 0600, dir, pmic_arb,
|
||||
&debug_spmi_addr_fops);
|
||||
if (IS_ERR(file)) {
|
||||
dev_err(&pmic_arb->spmic->dev, "Could not create spmi_addr debugfs file, rc=%ld\n",
|
||||
PTR_ERR(file));
|
||||
goto error;
|
||||
}
|
||||
|
||||
file = debugfs_create_file_unsafe("soc_addr_start", 0400, dir, pmic_arb,
|
||||
&debug_soc_start_addr_fops);
|
||||
if (IS_ERR(file)) {
|
||||
dev_err(&pmic_arb->spmic->dev, "Could not create soc_addr_start debugfs file, rc=%ld\n",
|
||||
PTR_ERR(file));
|
||||
goto error;
|
||||
}
|
||||
|
||||
file = debugfs_create_file_unsafe("soc_addr_end", 0400, dir, pmic_arb,
|
||||
&debug_soc_end_addr_fops);
|
||||
if (IS_ERR(file)) {
|
||||
dev_err(&pmic_arb->spmic->dev, "Could not create soc_addr_end debugfs file, rc=%ld\n",
|
||||
PTR_ERR(file));
|
||||
goto error;
|
||||
}
|
||||
|
||||
return;
|
||||
error:
|
||||
debugfs_remove_recursive(pmic_arb->debugfs);
|
||||
}
|
||||
#else
|
||||
static void spmi_pmic_arb_debugfs_init(struct spmi_pmic_arb *pmic_arb) { }
|
||||
#endif
|
||||
|
||||
static int spmi_pmic_arb_probe(struct platform_device *pdev)
|
||||
{
|
||||
struct spmi_pmic_arb *pmic_arb;
|
||||
@@ -1461,6 +1716,11 @@ static int spmi_pmic_arb_probe(struct platform_device *pdev)
|
||||
* which does not result in a devm_request_mem_region() call.
|
||||
*/
|
||||
res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "core");
|
||||
if (!res) {
|
||||
err = -EINVAL;
|
||||
goto err_put_ctrl;
|
||||
}
|
||||
|
||||
core = devm_ioremap(&ctrl->dev, res->start, resource_size(res));
|
||||
if (IS_ERR(core)) {
|
||||
err = PTR_ERR(core);
|
||||
@@ -1482,6 +1742,7 @@ static int spmi_pmic_arb_probe(struct platform_device *pdev)
|
||||
if (hw_ver < PMIC_ARB_VERSION_V2_MIN) {
|
||||
pmic_arb->ver_ops = &pmic_arb_v1;
|
||||
pmic_arb->wr_base = core;
|
||||
pmic_arb->wr_base_phys = res->start;
|
||||
pmic_arb->rd_base = core;
|
||||
} else {
|
||||
pmic_arb->core = core;
|
||||
@@ -1497,6 +1758,11 @@ static int spmi_pmic_arb_probe(struct platform_device *pdev)
|
||||
|
||||
res = platform_get_resource_byname(pdev, IORESOURCE_MEM,
|
||||
"obsrvr");
|
||||
if (!res) {
|
||||
err = -EINVAL;
|
||||
goto err_put_ctrl;
|
||||
}
|
||||
|
||||
pmic_arb->rd_base = devm_ioremap(&ctrl->dev, res->start,
|
||||
resource_size(res));
|
||||
if (IS_ERR(pmic_arb->rd_base)) {
|
||||
@@ -1506,12 +1772,18 @@ static int spmi_pmic_arb_probe(struct platform_device *pdev)
|
||||
|
||||
res = platform_get_resource_byname(pdev, IORESOURCE_MEM,
|
||||
"chnls");
|
||||
if (!res) {
|
||||
err = -EINVAL;
|
||||
goto err_put_ctrl;
|
||||
}
|
||||
|
||||
pmic_arb->wr_base = devm_ioremap(&ctrl->dev, res->start,
|
||||
resource_size(res));
|
||||
if (IS_ERR(pmic_arb->wr_base)) {
|
||||
err = PTR_ERR(pmic_arb->wr_base);
|
||||
goto err_put_ctrl;
|
||||
}
|
||||
pmic_arb->wr_base_phys = res->start;
|
||||
}
|
||||
|
||||
pmic_arb->max_periphs = PMIC_ARB_MAX_PERIPHS;
|
||||
@@ -1573,6 +1845,11 @@ static int spmi_pmic_arb_probe(struct platform_device *pdev)
|
||||
pmic_arb->ver_ops->ver_str, hw_ver);
|
||||
|
||||
res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "intr");
|
||||
if (!res) {
|
||||
err = -EINVAL;
|
||||
goto err_put_ctrl;
|
||||
}
|
||||
|
||||
pmic_arb->intr = devm_ioremap_resource(&ctrl->dev, res);
|
||||
if (IS_ERR(pmic_arb->intr)) {
|
||||
err = PTR_ERR(pmic_arb->intr);
|
||||
@@ -1580,16 +1857,23 @@ static int spmi_pmic_arb_probe(struct platform_device *pdev)
|
||||
}
|
||||
|
||||
res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "cnfg");
|
||||
if (!res) {
|
||||
err = -EINVAL;
|
||||
goto err_put_ctrl;
|
||||
}
|
||||
|
||||
pmic_arb->cnfg = devm_ioremap_resource(&ctrl->dev, res);
|
||||
if (IS_ERR(pmic_arb->cnfg)) {
|
||||
err = PTR_ERR(pmic_arb->cnfg);
|
||||
goto err_put_ctrl;
|
||||
}
|
||||
|
||||
pmic_arb->irq = platform_get_irq_byname(pdev, "periph_irq");
|
||||
if (pmic_arb->irq < 0) {
|
||||
err = pmic_arb->irq;
|
||||
goto err_put_ctrl;
|
||||
if (of_find_property(pdev->dev.of_node, "interrupt-names", NULL)) {
|
||||
pmic_arb->irq = platform_get_irq_byname(pdev, "periph_irq");
|
||||
if (pmic_arb->irq < 0) {
|
||||
err = pmic_arb->irq;
|
||||
goto err_put_ctrl;
|
||||
}
|
||||
}
|
||||
|
||||
err = of_property_read_u32(pdev->dev.of_node, "qcom,channel", &channel);
|
||||
@@ -1649,26 +1933,35 @@ static int spmi_pmic_arb_probe(struct platform_device *pdev)
|
||||
}
|
||||
}
|
||||
|
||||
dev_dbg(&pdev->dev, "adding irq domain\n");
|
||||
pmic_arb->domain = irq_domain_add_tree(pdev->dev.of_node,
|
||||
&pmic_arb_irq_domain_ops, pmic_arb);
|
||||
if (!pmic_arb->domain) {
|
||||
dev_err(&pdev->dev, "unable to create irq_domain\n");
|
||||
err = -ENOMEM;
|
||||
goto err_put_ctrl;
|
||||
if (pmic_arb->irq > 0) {
|
||||
dev_dbg(&pdev->dev, "adding irq domain\n");
|
||||
pmic_arb->domain = irq_domain_add_tree(pdev->dev.of_node,
|
||||
&pmic_arb_irq_domain_ops, pmic_arb);
|
||||
if (!pmic_arb->domain) {
|
||||
dev_err(&pdev->dev, "unable to create irq_domain\n");
|
||||
err = -ENOMEM;
|
||||
goto err_put_ctrl;
|
||||
}
|
||||
|
||||
irq_set_chained_handler_and_data(pmic_arb->irq,
|
||||
pmic_arb_chained_irq, pmic_arb);
|
||||
} else {
|
||||
dev_dbg(&pdev->dev, "not supporting PMIC interrupts\n");
|
||||
}
|
||||
|
||||
irq_set_chained_handler_and_data(pmic_arb->irq, pmic_arb_chained_irq,
|
||||
pmic_arb);
|
||||
err = spmi_controller_add(ctrl);
|
||||
if (err)
|
||||
goto err_domain_remove;
|
||||
|
||||
spmi_pmic_arb_debugfs_init(pmic_arb);
|
||||
|
||||
return 0;
|
||||
|
||||
err_domain_remove:
|
||||
irq_set_chained_handler_and_data(pmic_arb->irq, NULL, NULL);
|
||||
irq_domain_remove(pmic_arb->domain);
|
||||
if (pmic_arb->irq > 0) {
|
||||
irq_set_chained_handler_and_data(pmic_arb->irq, NULL, NULL);
|
||||
irq_domain_remove(pmic_arb->domain);
|
||||
}
|
||||
err_put_ctrl:
|
||||
spmi_controller_put(ctrl);
|
||||
return err;
|
||||
@@ -1678,9 +1971,12 @@ static void spmi_pmic_arb_remove(struct platform_device *pdev)
|
||||
{
|
||||
struct spmi_controller *ctrl = platform_get_drvdata(pdev);
|
||||
struct spmi_pmic_arb *pmic_arb = spmi_controller_get_drvdata(ctrl);
|
||||
debugfs_remove_recursive(pmic_arb->debugfs);
|
||||
spmi_controller_remove(ctrl);
|
||||
irq_set_chained_handler_and_data(pmic_arb->irq, NULL, NULL);
|
||||
irq_domain_remove(pmic_arb->domain);
|
||||
if (pmic_arb->irq > 0) {
|
||||
irq_set_chained_handler_and_data(pmic_arb->irq, NULL, NULL);
|
||||
irq_domain_remove(pmic_arb->domain);
|
||||
}
|
||||
spmi_controller_put(ctrl);
|
||||
}
|
||||
|
||||
@@ -1696,6 +1992,7 @@ static struct platform_driver spmi_pmic_arb_driver = {
|
||||
.driver = {
|
||||
.name = "spmi_pmic_arb",
|
||||
.of_match_table = spmi_pmic_arb_match_table,
|
||||
.probe_type = PROBE_PREFER_ASYNCHRONOUS,
|
||||
},
|
||||
};
|
||||
module_platform_driver(spmi_pmic_arb_driver);
|
||||
|
Reference in New Issue
Block a user