Commit ff615ed9 authored by Kiran Gunda's avatar Kiran Gunda Committed by Greg Kroah-Hartman

spmi: pmic-arb: return the value instead of passing by pointer

Returning the output value from a function, when it is possible, is the
better and cleaner way than passing it by the pointer. Hence, modify
the ppid_to_apid mapping function to return apid instead of passing
it by a pointer. While at it, pass the ppid as function parameter to
ppid_to_apid mapping function instead of passing the sid and addr.
Signed-off-by: default avatarKiran Gunda <kgunda@codeaurora.org>
Reviewed-by: default avatarStephen Boyd <sboyd@codeaurora.org>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 9f7a9a44
...@@ -178,11 +178,9 @@ struct spmi_pmic_arb { ...@@ -178,11 +178,9 @@ struct spmi_pmic_arb {
*/ */
struct pmic_arb_ver_ops { struct pmic_arb_ver_ops {
const char *ver_str; const char *ver_str;
int (*ppid_to_apid)(struct spmi_pmic_arb *pmic_arb, u8 sid, u16 addr, int (*ppid_to_apid)(struct spmi_pmic_arb *pmic_arb, u16 ppid);
u16 *apid);
/* spmi commands (read_cmd, write_cmd, cmd) functionality */ /* spmi commands (read_cmd, write_cmd, cmd) functionality */
int (*offset)(struct spmi_pmic_arb *pmic_arb, u8 sid, u16 addr, int (*offset)(struct spmi_pmic_arb *pmic_arb, u8 sid, u16 addr);
u32 *offset);
u32 (*fmt_cmd)(u8 opc, u8 sid, u16 addr, u8 bc); u32 (*fmt_cmd)(u8 opc, u8 sid, u16 addr, u8 bc);
int (*non_data_cmd)(struct spmi_controller *ctrl, u8 opc, u8 sid); int (*non_data_cmd)(struct spmi_controller *ctrl, u8 opc, u8 sid);
/* Interrupts controller functionality (offset of PIC registers) */ /* Interrupts controller functionality (offset of PIC registers) */
...@@ -242,10 +240,11 @@ static int pmic_arb_wait_for_done(struct spmi_controller *ctrl, ...@@ -242,10 +240,11 @@ static int pmic_arb_wait_for_done(struct spmi_controller *ctrl,
u32 offset; u32 offset;
int rc; int rc;
rc = pmic_arb->ver_ops->offset(pmic_arb, sid, addr, &offset); rc = pmic_arb->ver_ops->offset(pmic_arb, sid, addr);
if (rc) if (rc < 0)
return rc; return rc;
offset = rc;
offset += PMIC_ARB_STATUS; offset += PMIC_ARB_STATUS;
while (timeout--) { while (timeout--) {
...@@ -289,10 +288,11 @@ pmic_arb_non_data_cmd_v1(struct spmi_controller *ctrl, u8 opc, u8 sid) ...@@ -289,10 +288,11 @@ pmic_arb_non_data_cmd_v1(struct spmi_controller *ctrl, u8 opc, u8 sid)
int rc; int rc;
u32 offset; u32 offset;
rc = pmic_arb->ver_ops->offset(pmic_arb, sid, 0, &offset); rc = pmic_arb->ver_ops->offset(pmic_arb, sid, 0);
if (rc) if (rc < 0)
return rc; return rc;
offset = rc;
cmd = ((opc | 0x40) << 27) | ((sid & 0xf) << 20); cmd = ((opc | 0x40) << 27) | ((sid & 0xf) << 20);
raw_spin_lock_irqsave(&pmic_arb->lock, flags); raw_spin_lock_irqsave(&pmic_arb->lock, flags);
...@@ -333,10 +333,11 @@ static int pmic_arb_read_cmd(struct spmi_controller *ctrl, u8 opc, u8 sid, ...@@ -333,10 +333,11 @@ static int pmic_arb_read_cmd(struct spmi_controller *ctrl, u8 opc, u8 sid,
int rc; int rc;
u32 offset; u32 offset;
rc = pmic_arb->ver_ops->offset(pmic_arb, sid, addr, &offset); rc = pmic_arb->ver_ops->offset(pmic_arb, sid, addr);
if (rc) if (rc < 0)
return rc; return rc;
offset = rc;
if (bc >= PMIC_ARB_MAX_TRANS_BYTES) { if (bc >= PMIC_ARB_MAX_TRANS_BYTES) {
dev_err(&ctrl->dev, "pmic-arb supports 1..%d bytes per trans, but:%zu requested", dev_err(&ctrl->dev, "pmic-arb supports 1..%d bytes per trans, but:%zu requested",
PMIC_ARB_MAX_TRANS_BYTES, len); PMIC_ARB_MAX_TRANS_BYTES, len);
...@@ -383,10 +384,11 @@ static int pmic_arb_write_cmd(struct spmi_controller *ctrl, u8 opc, u8 sid, ...@@ -383,10 +384,11 @@ static int pmic_arb_write_cmd(struct spmi_controller *ctrl, u8 opc, u8 sid,
int rc; int rc;
u32 offset; u32 offset;
rc = pmic_arb->ver_ops->offset(pmic_arb, sid, addr, &offset); rc = pmic_arb->ver_ops->offset(pmic_arb, sid, addr);
if (rc) if (rc < 0)
return rc; return rc;
offset = rc;
if (bc >= PMIC_ARB_MAX_TRANS_BYTES) { if (bc >= PMIC_ARB_MAX_TRANS_BYTES) {
dev_err(&ctrl->dev, "pmic-arb supports 1..%d bytes per trans, but:%zu requested", dev_err(&ctrl->dev, "pmic-arb supports 1..%d bytes per trans, but:%zu requested",
PMIC_ARB_MAX_TRANS_BYTES, len); PMIC_ARB_MAX_TRANS_BYTES, len);
...@@ -655,8 +657,8 @@ static int qpnpint_irq_domain_dt_translate(struct irq_domain *d, ...@@ -655,8 +657,8 @@ static int qpnpint_irq_domain_dt_translate(struct irq_domain *d,
unsigned int *out_type) unsigned int *out_type)
{ {
struct spmi_pmic_arb *pmic_arb = d->host_data; struct spmi_pmic_arb *pmic_arb = d->host_data;
u16 apid, ppid;
int rc; int rc;
u16 apid;
dev_dbg(&pmic_arb->spmic->dev, "intspec[0] 0x%1x intspec[1] 0x%02x intspec[2] 0x%02x\n", dev_dbg(&pmic_arb->spmic->dev, "intspec[0] 0x%1x intspec[1] 0x%02x intspec[2] 0x%02x\n",
intspec[0], intspec[1], intspec[2]); intspec[0], intspec[1], intspec[2]);
...@@ -668,14 +670,15 @@ static int qpnpint_irq_domain_dt_translate(struct irq_domain *d, ...@@ -668,14 +670,15 @@ static int qpnpint_irq_domain_dt_translate(struct irq_domain *d,
if (intspec[0] > 0xF || intspec[1] > 0xFF || intspec[2] > 0x7) if (intspec[0] > 0xF || intspec[1] > 0xFF || intspec[2] > 0x7)
return -EINVAL; return -EINVAL;
rc = pmic_arb->ver_ops->ppid_to_apid(pmic_arb, intspec[0], ppid = intspec[0] << 8 | intspec[1];
(intspec[1] << 8), &apid); rc = pmic_arb->ver_ops->ppid_to_apid(pmic_arb, ppid);
if (rc < 0) { if (rc < 0) {
dev_err(&pmic_arb->spmic->dev, "failed to xlate sid = 0x%x, periph = 0x%x, irq = %x rc = %d\n", dev_err(&pmic_arb->spmic->dev, "failed to xlate sid = 0x%x, periph = 0x%x, irq = %x rc = %d\n",
intspec[0], intspec[1], intspec[2], rc); intspec[0], intspec[1], intspec[2], rc);
return rc; return rc;
} }
apid = rc;
/* Keep track of {max,min}_apid for bounding search during interrupt */ /* Keep track of {max,min}_apid for bounding search during interrupt */
if (apid > pmic_arb->max_apid) if (apid > pmic_arb->max_apid)
pmic_arb->max_apid = apid; pmic_arb->max_apid = apid;
...@@ -704,19 +707,18 @@ static int qpnpint_irq_domain_map(struct irq_domain *d, ...@@ -704,19 +707,18 @@ static int qpnpint_irq_domain_map(struct irq_domain *d,
return 0; return 0;
} }
static int pmic_arb_ppid_to_apid_v1(struct spmi_pmic_arb *pmic_arb, u8 sid, static int pmic_arb_ppid_to_apid_v1(struct spmi_pmic_arb *pmic_arb, u16 ppid)
u16 addr, u16 *apid)
{ {
u16 ppid = sid << 8 | ((addr >> 8) & 0xFF);
u32 *mapping_table = pmic_arb->mapping_table; u32 *mapping_table = pmic_arb->mapping_table;
int index = 0, i; int index = 0, i;
u16 apid_valid; u16 apid_valid;
u16 apid;
u32 data; u32 data;
apid_valid = pmic_arb->ppid_to_apid[ppid]; apid_valid = pmic_arb->ppid_to_apid[ppid];
if (apid_valid & PMIC_ARB_APID_VALID) { if (apid_valid & PMIC_ARB_APID_VALID) {
*apid = apid_valid & ~PMIC_ARB_APID_VALID; apid = apid_valid & ~PMIC_ARB_APID_VALID;
return 0; return apid;
} }
for (i = 0; i < SPMI_MAPPING_TABLE_TREE_DEPTH; ++i) { for (i = 0; i < SPMI_MAPPING_TABLE_TREE_DEPTH; ++i) {
...@@ -730,21 +732,21 @@ static int pmic_arb_ppid_to_apid_v1(struct spmi_pmic_arb *pmic_arb, u8 sid, ...@@ -730,21 +732,21 @@ static int pmic_arb_ppid_to_apid_v1(struct spmi_pmic_arb *pmic_arb, u8 sid,
if (SPMI_MAPPING_BIT_IS_1_FLAG(data)) { if (SPMI_MAPPING_BIT_IS_1_FLAG(data)) {
index = SPMI_MAPPING_BIT_IS_1_RESULT(data); index = SPMI_MAPPING_BIT_IS_1_RESULT(data);
} else { } else {
*apid = SPMI_MAPPING_BIT_IS_1_RESULT(data); apid = SPMI_MAPPING_BIT_IS_1_RESULT(data);
pmic_arb->ppid_to_apid[ppid] pmic_arb->ppid_to_apid[ppid]
= *apid | PMIC_ARB_APID_VALID; = apid | PMIC_ARB_APID_VALID;
pmic_arb->apid_data[*apid].ppid = ppid; pmic_arb->apid_data[apid].ppid = ppid;
return 0; return apid;
} }
} else { } else {
if (SPMI_MAPPING_BIT_IS_0_FLAG(data)) { if (SPMI_MAPPING_BIT_IS_0_FLAG(data)) {
index = SPMI_MAPPING_BIT_IS_0_RESULT(data); index = SPMI_MAPPING_BIT_IS_0_RESULT(data);
} else { } else {
*apid = SPMI_MAPPING_BIT_IS_0_RESULT(data); apid = SPMI_MAPPING_BIT_IS_0_RESULT(data);
pmic_arb->ppid_to_apid[ppid] pmic_arb->ppid_to_apid[ppid]
= *apid | PMIC_ARB_APID_VALID; = apid | PMIC_ARB_APID_VALID;
pmic_arb->apid_data[*apid].ppid = ppid; pmic_arb->apid_data[apid].ppid = ppid;
return 0; return apid;
} }
} }
} }
...@@ -753,11 +755,9 @@ static int pmic_arb_ppid_to_apid_v1(struct spmi_pmic_arb *pmic_arb, u8 sid, ...@@ -753,11 +755,9 @@ static int pmic_arb_ppid_to_apid_v1(struct spmi_pmic_arb *pmic_arb, u8 sid,
} }
/* v1 offset per ee */ /* v1 offset per ee */
static int pmic_arb_offset_v1(struct spmi_pmic_arb *pmic_arb, u8 sid, u16 addr, static int pmic_arb_offset_v1(struct spmi_pmic_arb *pmic_arb, u8 sid, u16 addr)
u32 *offset)
{ {
*offset = 0x800 + 0x80 * pmic_arb->channel; return 0x800 + 0x80 * pmic_arb->channel;
return 0;
} }
static u16 pmic_arb_find_apid(struct spmi_pmic_arb *pmic_arb, u16 ppid) static u16 pmic_arb_find_apid(struct spmi_pmic_arb *pmic_arb, u16 ppid)
...@@ -796,10 +796,8 @@ static u16 pmic_arb_find_apid(struct spmi_pmic_arb *pmic_arb, u16 ppid) ...@@ -796,10 +796,8 @@ static u16 pmic_arb_find_apid(struct spmi_pmic_arb *pmic_arb, u16 ppid)
return apid; return apid;
} }
static int pmic_arb_ppid_to_apid_v2(struct spmi_pmic_arb *pmic_arb, u8 sid, static int pmic_arb_ppid_to_apid_v2(struct spmi_pmic_arb *pmic_arb, u16 ppid)
u16 addr, u16 *apid)
{ {
u16 ppid = (sid << 8) | (addr >> 8);
u16 apid_valid; u16 apid_valid;
apid_valid = pmic_arb->ppid_to_apid[ppid]; apid_valid = pmic_arb->ppid_to_apid[ppid];
...@@ -808,23 +806,23 @@ static int pmic_arb_ppid_to_apid_v2(struct spmi_pmic_arb *pmic_arb, u8 sid, ...@@ -808,23 +806,23 @@ static int pmic_arb_ppid_to_apid_v2(struct spmi_pmic_arb *pmic_arb, u8 sid,
if (!(apid_valid & PMIC_ARB_APID_VALID)) if (!(apid_valid & PMIC_ARB_APID_VALID))
return -ENODEV; return -ENODEV;
*apid = apid_valid & ~PMIC_ARB_APID_VALID; return apid_valid & ~PMIC_ARB_APID_VALID;
return 0;
} }
/* v2 offset per ppid and per ee */ /* v2 offset per ppid and per ee */
static int pmic_arb_offset_v2(struct spmi_pmic_arb *pmic_arb, u8 sid, u16 addr, static int pmic_arb_offset_v2(struct spmi_pmic_arb *pmic_arb, u8 sid, u16 addr)
u32 *offset)
{ {
u16 apid; u16 apid;
u16 ppid;
int rc; int rc;
rc = pmic_arb_ppid_to_apid_v2(pmic_arb, sid, addr, &apid); ppid = sid << 8 | ((addr >> 8) & 0xFF);
rc = pmic_arb_ppid_to_apid_v2(pmic_arb, ppid);
if (rc < 0) if (rc < 0)
return rc; return rc;
*offset = 0x1000 * pmic_arb->ee + 0x8000 * apid; apid = rc;
return 0; return 0x1000 * pmic_arb->ee + 0x8000 * apid;
} }
static u32 pmic_arb_fmt_cmd_v1(u8 opc, u8 sid, u16 addr, u8 bc) static u32 pmic_arb_fmt_cmd_v1(u8 opc, u8 sid, u16 addr, u8 bc)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment