All of lore.kernel.org
 help / color / mirror / Atom feed
From: Stephen Boyd <sboyd@codeaurora.org>
To: Kiran Gunda <kgunda@codeaurora.org>
Cc: Abhijeet Dharmapurikar <adharmap@codeaurora.org>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Subbaraman Narayanamurthy <subbaram@codeaurora.org>,
	David Collins <collinsd@codeaurora.org>,
	Christophe JAILLET <christophe.jaillet@wanadoo.fr>,
	linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org,
	adharmap@quicinc.com, aghayal@qti.qualcomm.com
Subject: Re: [PATCH V1 13/15] spmi: pmic-arb: add support for HW version 5
Date: Wed, 31 May 2017 23:08:59 -0700	[thread overview]
Message-ID: <20170601060859.GK20170@codeaurora.org> (raw)
In-Reply-To: <1496147943-25822-14-git-send-email-kgunda@codeaurora.org>

On 05/30, Kiran Gunda wrote:
> diff --git a/drivers/spmi/spmi-pmic-arb.c b/drivers/spmi/spmi-pmic-arb.c
> index 412481d..b755c24 100644
> --- a/drivers/spmi/spmi-pmic-arb.c
> +++ b/drivers/spmi/spmi-pmic-arb.c
> @@ -112,7 +123,8 @@ enum pmic_arb_cmd_op_code {
>  
>  struct apid_data {
>  	u16		ppid;
> -	u8		owner;
> +	u8		write_owner;
> +	u8		irq_owner;

How about irq_ee and write_ee instead?

>  };
>  
>  /**
>  static inline void pmic_arb_base_write(struct spmi_pmic_arb *pa,
> @@ -705,11 +724,18 @@ static int qpnpint_irq_domain_dt_translate(struct irq_domain *d,
>  			(intspec[1] << 8), &apid);
>  	if (rc < 0) {
>  		dev_err(&pa->spmic->dev,
> -		"failed to xlate sid = 0x%x, periph = 0x%x, irq = %x rc = %d\n",
> +		"failed to xlate sid = 0x%x, periph = 0x%x, irq = %u rc = %d\n",

What is this change? Also, use %#x instead of 0x%x and the "
should line up with the ( on the previous line.

>  		intspec[0], intspec[1], intspec[2], rc);
>  		return rc;
>  	}
>  
> +	if (pa->apid_data[apid].irq_owner != pa->ee) {
> +		dev_err(&pa->spmic->dev, "failed to xlate sid = 0x%x, periph = 0x%x, irq = %u: ee=%u but owner=%u\n",
> +			intspec[0], intspec[1], intspec[2], pa->ee,
> +			pa->apid_data[apid].irq_owner);
> +		return -ENODEV;
> +	}
> +
>  	/* Keep track of {max,min}_apid for bounding search during interrupt */
>  	if (apid > pa->max_apid)
>  		pa->max_apid = apid;
> @@ -814,9 +841,11 @@ static u16 pmic_arb_find_apid(struct spmi_pmic_arb *pa, u16 ppid)
>  	for (apid = pa->last_apid; apid < pa->max_periph; apid++) {
>  		regval = readl_relaxed(pa->cnfg +
>  				      SPMI_OWNERSHIP_TABLE_REG(apid));
> -		pa->apid_data[apid].owner = SPMI_OWNERSHIP_PERIPH2OWNER(regval);
> +		pa->apid_data[apid].irq_owner
> +			= SPMI_OWNERSHIP_PERIPH2OWNER(regval);
> +		pa->apid_data[apid].write_owner = pa->apid_data[apid].irq_owner;

Please use a local variable pointer *apid.

>  
> -		offset = PMIC_ARB_REG_CHNL(apid);
> +		offset = pa->ver_ops->channel_map_offset(apid);
>  		if (offset >= pa->core_size)
>  			break;
>  
> @@ -854,27 +883,110 @@ static u16 pmic_arb_find_apid(struct spmi_pmic_arb *pa, u16 ppid)
>  	return 0;
>  }
>  
> +static int pmic_arb_read_apid_map_v5(struct spmi_pmic_arb *pa)
> +{
> +	u32 regval, offset;
> +	u16 apid, prev_apid, ppid;
> +	bool valid, is_irq_owner;
> +
> +	/*
> +	 * PMIC_ARB_REG_CHNL is a table in HW mapping APID (channel) to PPID.
> +	 * ppid_to_apid is an in-memory invert of that table.  In order to allow
> +	 * multiple EE's to write to a single PPID in arbiter version 5, there

Drop the apostrophe   ^

> +	 * is more than one APID mapped to each PPID.  The owner field for each
> +	 * of these mappings specifies the EE which is allowed to write to the
> +	 * APID.  The owner of the last (highest) APID for a given PPID will
> +	 * receive interrupts from the PPID.
> +	 */
> +	for (apid = 0; apid < pa->max_periph; apid++) {
> +		offset = pa->ver_ops->channel_map_offset(apid);
> +		if (offset >= pa->core_size)
> +			break;
> +
> +		regval = readl_relaxed(pa->core + offset);
> +		if (!regval)
> +			continue;
> +		ppid = (regval >> 8) & PMIC_ARB_PPID_MASK;
> +		is_irq_owner = PMIC_ARB_CHAN_IS_IRQ_OWNER(regval);
> +
> +		regval = readl_relaxed(pa->cnfg +
> +				      SPMI_OWNERSHIP_TABLE_REG(apid));
> +		pa->apid_data[apid].write_owner
> +			= SPMI_OWNERSHIP_PERIPH2OWNER(regval);

Please use a pointer like *apid and *prev where *apid is
incremented during the for-loop. That way we have shorter lines
of code:

		apid->write_owner = SPMI_OWNERSHIP_TABLE_REG(regval);

and

		if (valid && is_irq_owner && prev->write_owner == pa->ee) {

obviously the existing apid will need to be renamed to i, but
that's ok because it's a counter.

> +
> +		pa->apid_data[apid].irq_owner = is_irq_owner ?
> +			pa->apid_data[apid].write_owner : INVALID_EE;
> +
> +		valid = pa->ppid_to_apid[ppid] & PMIC_ARB_CHAN_VALID;
> +		prev_apid = pa->ppid_to_apid[ppid] & ~PMIC_ARB_CHAN_VALID;
> +
> +		if (valid && is_irq_owner &&
> +		    pa->apid_data[prev_apid].write_owner == pa->ee) {
> +			/*
> +			 * Duplicate PPID mapping after the one for this EE;
> +			 * override the irq owner
> +			 */
> +			pa->apid_data[prev_apid].irq_owner
> +				= pa->apid_data[apid].irq_owner;
> +		} else if (!valid || is_irq_owner) {
> +			/* First PPID mapping or duplicate for another EE */
> +			pa->ppid_to_apid[ppid] = apid | PMIC_ARB_CHAN_VALID;
> +		}
> +
> +		pa->apid_data[apid].ppid = ppid;
> +		pa->last_apid = apid;
> +	}
> +
> +	/* Dump the mapping table for debug purposes. */
> +	dev_dbg(&pa->spmic->dev, "PPID APID Write-EE IRQ-EE\n");
> +	for (ppid = 0; ppid < PMIC_ARB_MAX_PPID; ppid++) {
> +		valid = pa->ppid_to_apid[ppid] & PMIC_ARB_CHAN_VALID;
> +		apid = pa->ppid_to_apid[ppid] & ~PMIC_ARB_CHAN_VALID;
> +
> +		if (valid)
> +			dev_dbg(&pa->spmic->dev, "0x%03X %3u %2u %2u\n",

Same %#x story here.

> +				ppid, apid, pa->apid_data[apid].write_owner,
> +				pa->apid_data[apid].irq_owner);
> +	}
> +
> +	return 0;
> +}
> +
>  
> @@ -887,6 +999,27 @@ static u16 pmic_arb_find_apid(struct spmi_pmic_arb *pa, u16 ppid)
>  	return 0;
>  }
>  
> +/*
> + * v5 offset per ee and per apid for observer channels and per apid for
> + * read/write channels.
> + */
> +static int
> +pmic_arb_offset_v5(struct spmi_pmic_arb *pa, u8 sid, u16 addr,
> +		   enum pmic_arb_channel ch_type, u32 *offset)
> +{
> +	u16 apid;
> +	int rc;
> +
> +	rc = pmic_arb_ppid_to_apid_v5(pa, sid, addr, &apid);
> +	if (rc < 0)
> +		return rc;
> +
> +	*offset = (ch_type == PMIC_ARB_CHANNEL_OBS)
> +			? 0x10000 * pa->ee + 0x80 * apid
> +			: 0x10000 * apid;

Please use a switch statement to handle the enum here. That way
we can get compiler checking to make sure all enumerations are
handled.

> +	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);
> @@ -1033,11 +1213,14 @@ static int spmi_pmic_arb_probe(struct platform_device *pdev)
>  
>  		if (hw_ver < PMIC_ARB_VERSION_V3_MIN)
>  			pa->ver_ops = &pmic_arb_v2;
> -		else
> +		else if (hw_ver < PMIC_ARB_VERSION_V5_MIN)
>  			pa->ver_ops = &pmic_arb_v3;
> +		else
> +			pa->ver_ops = &pmic_arb_v5;
>  
> -		/* the apid to ppid table starts at PMIC_ARB_REG_CHNL(0) */
> -		pa->max_periph = (pa->core_size - PMIC_ARB_REG_CHNL(0)) / 4;
> +		/* the apid to ppid table starts at PMIC_ARB_REG_CHNL0 */
> +		pa->max_periph
> +		     = (pa->core_size - pa->ver_ops->channel_map_offset(0)) / 4;

This is really ugly. Please grow a local variable so we can keep
things on one line.

>  
>  		res = platform_get_resource_byname(pdev, IORESOURCE_MEM,
>  						   "obsrvr");
> @@ -1074,6 +1257,14 @@ static int spmi_pmic_arb_probe(struct platform_device *pdev)
>  		err = PTR_ERR(pa->intr);
>  		goto err_put_ctrl;
>  	}
> +	pa->acc_status = pa->intr;
> +
> +	/*
> +	 * PMIC arbiter v5 groups the IRQ control registers in the same hardware
> +	 * module as the read/write channels.
> +	 */
> +	if (hw_ver >= PMIC_ARB_VERSION_V5_MIN)
> +		pa->intr = pa->wr_base;

There's some weird things going on here. How about we make the
version ops return an __iomem pointer to the address instead of
an offset? That way we don't need to care what pa->intr is or add
pa->acc_status? That could be a patch early in the series that
adjusts the ops to return an iomem pointer, and perhaps also
update the 'n' variable to be 16 instead of 8 bits. We can also
express errors through iomem pointers with IS_ERR() checks, so it
nicely removes the need to retrieve offsets through references
sometimes too.

-- 
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
a Linux Foundation Collaborative Project

  reply	other threads:[~2017-06-01  6:08 UTC|newest]

Thread overview: 62+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-05-30 12:38 [PATCH V1 00/15]: support for spmi_pmic_arb v3/v5 and bug fixes Kiran Gunda
2017-05-30 12:38 ` Kiran Gunda
2017-05-30 12:38 ` [PATCH V1 01/15] spmi: pmic_arb: block access of invalid read and writes Kiran Gunda
2017-05-31  0:33   ` Stephen Boyd
2017-06-12 11:26     ` kgunda
2017-06-13  2:09       ` Stephen Boyd
2017-06-14 15:09         ` kgunda
2017-05-30 12:38 ` [PATCH V1 02/15] spmi: pmic-arb: rename spmi_pmic_arb_dev to spmi_pmic_arb Kiran Gunda
2017-05-31  0:46   ` Stephen Boyd
2017-06-01 16:11     ` kgunda
2017-06-02 18:29       ` Stephen Boyd
2017-06-05  6:28         ` kgunda
2017-05-30 12:38 ` [PATCH V1 03/15] spmi: pmic-arb: fix inconsistent use of apid and chan Kiran Gunda
2017-05-31  1:31   ` Stephen Boyd
2017-06-01 16:37     ` kgunda
2017-05-30 12:38 ` [PATCH V1 04/15] spmi: pmic-arb: optimize table lookups Kiran Gunda
2017-05-31  1:44   ` Stephen Boyd
2017-06-01 16:53     ` kgunda
2017-06-02 18:31       ` Stephen Boyd
2017-06-05  6:33         ` kgunda
2017-05-30 12:38 ` [PATCH V1 05/15] spmi: pmic-arb: cleanup unrequested irqs Kiran Gunda
2017-05-31  1:57   ` Stephen Boyd
2017-06-06 10:50     ` kgunda
2017-06-13  2:11       ` Stephen Boyd
2017-06-14 15:04         ` kgunda
2017-05-30 12:38 ` [PATCH V1 06/15] spmi: pmic-arb: fix missing interrupts Kiran Gunda
2017-05-31  2:00   ` Stephen Boyd
2017-06-01 17:06     ` kgunda
2017-05-30 12:38 ` [PATCH V1 07/15] spmi: pmic-arb: clear the latched status of the interrupt Kiran Gunda
2017-05-31 22:03   ` Stephen Boyd
2017-06-06 10:55     ` kgunda
2017-05-30 12:38 ` [PATCH V1 08/15] spmi: pmic_arb: use appropriate flow handler Kiran Gunda
2017-05-31 19:03   ` Stephen Boyd
2017-06-06 10:57     ` kgunda
2017-05-30 12:38 ` [PATCH V1 09/15] spmi: pmic-arb: check apid enabled before calling the handler Kiran Gunda
2017-05-31 20:39   ` Stephen Boyd
2017-06-14 15:38     ` kgunda
2017-06-16 21:11       ` Stephen Boyd
2017-06-21  5:02         ` kgunda
2017-05-30 12:38 ` [PATCH V1 10/15] spmi: pmic_arb: add support for PMIC bus arbiter v3 Kiran Gunda
2017-05-31 22:18   ` Stephen Boyd
2017-06-06 11:10     ` kgunda
2017-05-30 12:38 ` [PATCH V1 11/15] spmi: spmi-pmic-arb: enable the SPMI interrupt as a wakeup source Kiran Gunda
2017-05-31 17:13   ` Stephen Boyd
2017-06-08 11:30     ` kgunda
2017-05-30 12:39 ` [PATCH V1 12/15] spmi-pmic-arb: fix a possible null pointer dereference Kiran Gunda
2017-05-31 17:29   ` Stephen Boyd
2017-06-02  7:13     ` kgunda
2017-05-30 12:39 ` [PATCH V1 13/15] spmi: pmic-arb: add support for HW version 5 Kiran Gunda
2017-06-01  6:08   ` Stephen Boyd [this message]
2017-06-08 11:28     ` kgunda
2017-05-30 12:39 ` [PATCH V1 14/15] spmi: pmic-arb: do not ack and clear peripheral interrupts in cleanup_irq Kiran Gunda
2017-05-30 22:23   ` kbuild test robot
2017-05-30 22:23     ` kbuild test robot
2017-05-31 17:53   ` Stephen Boyd
2017-06-02  7:26     ` kgunda
2017-06-06 11:27       ` kgunda
2017-06-13  2:10         ` Stephen Boyd
2017-07-18 11:53           ` kgunda
2017-05-30 12:39 ` [PATCH V1 15/15] spmi: pmic-arb: instantiate spmi_devices at arch_initcall Kiran Gunda
2017-05-31 22:07   ` Stephen Boyd
2017-07-18 11:49     ` kgunda

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170601060859.GK20170@codeaurora.org \
    --to=sboyd@codeaurora.org \
    --cc=adharmap@codeaurora.org \
    --cc=adharmap@quicinc.com \
    --cc=aghayal@qti.qualcomm.com \
    --cc=christophe.jaillet@wanadoo.fr \
    --cc=collinsd@codeaurora.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=kgunda@codeaurora.org \
    --cc=linux-arm-msm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=subbaram@codeaurora.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.