All of lore.kernel.org
 help / color / mirror / Atom feed
From: Guenter Roeck <linux@roeck-us.net>
To: "shufan_lee(李書帆)" <shufan_lee@richtek.com>
Cc: "Heikki Krogerus" <heikki.krogerus@linux.intel.com>,
	"'Jun Li'" <jun.li@nxp.com>, ShuFanLee <leechu729@gmail.com>,
	"cy_huang(黃啟原)" <cy_huang@richtek.com>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"linux-usb@vger.kernel.org" <linux-usb@vger.kernel.org>
Subject: Re: [PATCH] USB TYPEC: RT1711H Type-C Chip Driver
Date: Mon, 29 Jan 2018 11:57:52 -0800	[thread overview]
Message-ID: <20180129195752.GA24352@roeck-us.net> (raw)
In-Reply-To: <b7e6482007584692972ffbdfd4238e6c@ex1.rt.l>

On Mon, Jan 29, 2018 at 07:19:06AM +0000, shufan_lee(李書帆) wrote:
> Hi Guenter,
> 
>   We try to use the TCPCI driver on RT1711H and here are some questions.
> 
>   Q1. Is current TCPCI driver written according to TypeC Port Controller Interface Specification Revision 1.0 & Version 1.2?

Revision 1.0. Note that I did not find revision 1.2, only
Revision 1.0 and Revision 2.0 version 1.0.

>   Q2. Because 0x80~0xFF are vendor defined registers. Some of them are needed to be initialized in tcpci_init for RT1711H (or other chips also).
> In the future TCPCI driver, will an initial interface that is called in tcpci_init be released for different vendors to implement.

My suggestion would be to provide an API for vendor specific code.

> Or, we should directly copy tcpci.c to tcpci_rt1711h.c and add the different parts?

That would defeat the purpose. It would be better to implement vendor
specific code in tcpci_rt1711h.c and call it from tcpci.c

Possible example:

struct tcpci_vendor_data {
	int (*init)(...);
	int (*irq_handler)(...);
	...
}

static irqreturn_t tcpci_irq(...)
{
	struct tcpci *tcpci = dev_id;

	...
	if (tcpci->vendor_data->irq_handler) {
		ret = (*tcpci->vendor_data->irq_handler)(...);
		...
	}
	...
}

tcpci_init()
{
	struct tcpci_vendor_data *vendor_data = &tcpci_rt1711h_data;
				// eg from devicetree compatible property

	...
	if (vendor_data->init) {
		ret = (*vendor_data->init)(...);
		if (ret)
			return ret;
	}
	...
}

>   Q3. If there are IRQs defined in vendor defined registers, will an interface that is called in tcpci_irq be released for different vendors to implement.
> So that they can handle their own IRQs first?

If there are vendor specific interrupts, I would assume that vendor specific
code will have to be called. Either the generic interrupt handler can call
vendor specific code, or the vendor specific code handles the interrupt and
calls the generic handler. I don't know at this point which one is better.

> If the suggestion of Q2 is to copy tcpci.c to tcpci_rt1711h.c, then Q3 will not be a problem.
>   Q4. According to TCPCI Specification Revision 1.0, we should set DRP = 1 and role to Rp/Rp or Rd/Rd and set LOOK4CONNECTION command to start toggle.
> So we modify the tcpci_start_drp_toggling in TCPCI driver as following. Here we write Rd/Rd and DRP = 0 simultaneously so that Rd/Rd takes effect.
> Then we write DRP = 1 and set LOOK4CONNECTION command to start toggling.
> 
SGTM.

> static int tcpci_start_drp_toggling(struct tcpc_dev *tcpc,
>      enum typec_cc_status cc)
>  {
> +int ret = 0;
>  struct tcpci *tcpci = tcpc_to_tcpci(tcpc);
> -unsigned int reg = TCPC_ROLE_CTRL_DRP;
> +u32 reg = (TCPC_ROLE_CTRL_CC_RD << TCPC_ROLE_CTRL_CC1_SHIFT) |
> +(TCPC_ROLE_CTRL_CC_RD << TCPC_ROLE_CTRL_CC2_SHIFT);
> 
>  switch (cc) {
>  default:
> @@ -125,8 +672,19 @@ static int tcpci_start_drp_toggling(stru
>  TCPC_ROLE_CTRL_RP_VAL_SHIFT);
>  break;
>  }
> -
> -return regmap_write(tcpci->regmap, TCPC_ROLE_CTRL, reg);
> +ret = regmap_write(tcpci->regmap, TCPC_ROLE_CTRL, reg);
> +if (ret < 0)
> +return ret;
> +mdelay(1);

That is bad; you don't want to hold up teh system for that much.
Try to use usleep_range().

> +reg |= TCPC_ROLE_CTRL_DRP;
> +ret = regmap_write(tcpci->regmap, TCPC_ROLE_CTRL, reg);
> +if (ret < 0)
> +return ret;
> +ret = regmap_write(tcpci->regmap, TCPC_COMMAND,
> +TCPC_CMD_LOOK4CONNECTION);
> +if (ret < 0)
> +return ret;
> +return 0;
>  }
> 
>   Q5. The tcpci_set_vbus in TCPCI driver uses command to control Sink/Source VBUS.
> If our chip does not support power path, i.e. Sink & Source are controlled by other charger IC. Our chip will do nothing while setting these commands.
> In the future TCPCI driver, will a framework be applied to notify these events. i.g. power_supply or notifier.
> 
I would think so.

Note that the driver is, at this point, fair game to change to
make it work with your chip. The only condition is that a standard
chip should still work, ie you should not make any changes which
would cause the driver to _only_ work with your chip. Everything else
is fair game.

Thanks,
Guenter

WARNING: multiple messages have this Message-ID (diff)
From: Guenter Roeck <linux@roeck-us.net>
To: "shufan_lee(李書帆)" <shufan_lee@richtek.com>
Cc: "Heikki Krogerus" <heikki.krogerus@linux.intel.com>,
	"'Jun Li'" <jun.li@nxp.com>, ShuFanLee <leechu729@gmail.com>,
	"cy_huang(黃啟原)" <cy_huang@richtek.com>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"linux-usb@vger.kernel.org" <linux-usb@vger.kernel.org>
Subject: USB TYPEC: RT1711H Type-C Chip Driver
Date: Mon, 29 Jan 2018 11:57:52 -0800	[thread overview]
Message-ID: <20180129195752.GA24352@roeck-us.net> (raw)

On Mon, Jan 29, 2018 at 07:19:06AM +0000, shufan_lee(李書帆) wrote:
> Hi Guenter,
> 
>   We try to use the TCPCI driver on RT1711H and here are some questions.
> 
>   Q1. Is current TCPCI driver written according to TypeC Port Controller Interface Specification Revision 1.0 & Version 1.2?

Revision 1.0. Note that I did not find revision 1.2, only
Revision 1.0 and Revision 2.0 version 1.0.

>   Q2. Because 0x80~0xFF are vendor defined registers. Some of them are needed to be initialized in tcpci_init for RT1711H (or other chips also).
> In the future TCPCI driver, will an initial interface that is called in tcpci_init be released for different vendors to implement.

My suggestion would be to provide an API for vendor specific code.

> Or, we should directly copy tcpci.c to tcpci_rt1711h.c and add the different parts?

That would defeat the purpose. It would be better to implement vendor
specific code in tcpci_rt1711h.c and call it from tcpci.c

Possible example:

struct tcpci_vendor_data {
	int (*init)(...);
	int (*irq_handler)(...);
	...
}

static irqreturn_t tcpci_irq(...)
{
	struct tcpci *tcpci = dev_id;

	...
	if (tcpci->vendor_data->irq_handler) {
		ret = (*tcpci->vendor_data->irq_handler)(...);
		...
	}
	...
}

tcpci_init()
{
	struct tcpci_vendor_data *vendor_data = &tcpci_rt1711h_data;
				// eg from devicetree compatible property

	...
	if (vendor_data->init) {
		ret = (*vendor_data->init)(...);
		if (ret)
			return ret;
	}
	...
}

>   Q3. If there are IRQs defined in vendor defined registers, will an interface that is called in tcpci_irq be released for different vendors to implement.
> So that they can handle their own IRQs first?

If there are vendor specific interrupts, I would assume that vendor specific
code will have to be called. Either the generic interrupt handler can call
vendor specific code, or the vendor specific code handles the interrupt and
calls the generic handler. I don't know at this point which one is better.

> If the suggestion of Q2 is to copy tcpci.c to tcpci_rt1711h.c, then Q3 will not be a problem.
>   Q4. According to TCPCI Specification Revision 1.0, we should set DRP = 1 and role to Rp/Rp or Rd/Rd and set LOOK4CONNECTION command to start toggle.
> So we modify the tcpci_start_drp_toggling in TCPCI driver as following. Here we write Rd/Rd and DRP = 0 simultaneously so that Rd/Rd takes effect.
> Then we write DRP = 1 and set LOOK4CONNECTION command to start toggling.
> 
SGTM.

> static int tcpci_start_drp_toggling(struct tcpc_dev *tcpc,
>      enum typec_cc_status cc)
>  {
> +int ret = 0;
>  struct tcpci *tcpci = tcpc_to_tcpci(tcpc);
> -unsigned int reg = TCPC_ROLE_CTRL_DRP;
> +u32 reg = (TCPC_ROLE_CTRL_CC_RD << TCPC_ROLE_CTRL_CC1_SHIFT) |
> +(TCPC_ROLE_CTRL_CC_RD << TCPC_ROLE_CTRL_CC2_SHIFT);
> 
>  switch (cc) {
>  default:
> @@ -125,8 +672,19 @@ static int tcpci_start_drp_toggling(stru
>  TCPC_ROLE_CTRL_RP_VAL_SHIFT);
>  break;
>  }
> -
> -return regmap_write(tcpci->regmap, TCPC_ROLE_CTRL, reg);
> +ret = regmap_write(tcpci->regmap, TCPC_ROLE_CTRL, reg);
> +if (ret < 0)
> +return ret;
> +mdelay(1);

That is bad; you don't want to hold up teh system for that much.
Try to use usleep_range().

> +reg |= TCPC_ROLE_CTRL_DRP;
> +ret = regmap_write(tcpci->regmap, TCPC_ROLE_CTRL, reg);
> +if (ret < 0)
> +return ret;
> +ret = regmap_write(tcpci->regmap, TCPC_COMMAND,
> +TCPC_CMD_LOOK4CONNECTION);
> +if (ret < 0)
> +return ret;
> +return 0;
>  }
> 
>   Q5. The tcpci_set_vbus in TCPCI driver uses command to control Sink/Source VBUS.
> If our chip does not support power path, i.e. Sink & Source are controlled by other charger IC. Our chip will do nothing while setting these commands.
> In the future TCPCI driver, will a framework be applied to notify these events. i.g. power_supply or notifier.
> 
I would think so.

Note that the driver is, at this point, fair game to change to
make it work with your chip. The only condition is that a standard
chip should still work, ie you should not make any changes which
would cause the driver to _only_ work with your chip. Everything else
is fair game.

Thanks,
Guenter
---
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

  reply	other threads:[~2018-01-29 19:57 UTC|newest]

Thread overview: 51+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-01-10  6:59 [PATCH] USB TYPEC: RT1711H Type-C Chip Driver ShuFanLee
2018-01-10  6:59 ` ShuFanLee
2018-01-17  9:30 ` [PATCH] " shufan_lee(李書帆)
2018-01-17  9:30   ` shufan_lee(李書帆)
2018-01-17 11:08   ` [PATCH] " Heikki Krogerus
2018-01-17 11:08     ` Heikki Krogerus
2018-01-17 11:14     ` [PATCH] " Greg KH
2018-01-17 11:14       ` Greg Kroah-Hartman
2018-01-17 12:00       ` [PATCH] " Heikki Krogerus
2018-01-17 12:00         ` Heikki Krogerus
2018-01-17 13:31         ` [PATCH] " Greg KH
2018-01-17 13:31           ` Greg Kroah-Hartman
2018-01-17 13:33 ` [PATCH] " Greg KH
2018-01-17 13:33   ` Greg KH
2018-01-17 13:33 ` [PATCH] " Greg KH
2018-01-17 13:33   ` Greg KH
2018-01-17 13:42 ` [PATCH] " Greg KH
2018-01-17 13:42   ` Greg KH
2018-01-18 13:13   ` [PATCH] " shufan_lee(李書帆)
2018-01-18 13:13     ` shufan_lee(李書帆)
2018-01-19  8:03     ` [PATCH] " 'Greg KH'
2018-01-19  8:03       ` Greg KH
2018-01-19  3:09 ` [PATCH] " Jun Li
2018-01-19  3:09   ` Jun Li
2018-01-19  5:48   ` [PATCH] " shufan_lee(李書帆)
2018-01-19  5:48     ` shufan_lee(李書帆)
2018-01-19  8:22     ` [PATCH] " Heikki Krogerus
2018-01-19  8:22       ` Heikki Krogerus
2018-01-19  9:01       ` [PATCH] " shufan_lee(李書帆)
2018-01-19  9:01         ` shufan_lee(李書帆)
2018-01-19  9:24         ` [PATCH] " Heikki Krogerus
2018-01-19  9:24           ` Heikki Krogerus
2018-01-19 16:02           ` [PATCH] " Guenter Roeck
2018-01-19 16:02             ` Guenter Roeck
2018-01-22  2:01             ` [PATCH] " shufan_lee(李書帆)
2018-01-22  2:01               ` shufan_lee(李書帆)
2018-01-22 18:50               ` [PATCH] " Guenter Roeck
2018-01-22 18:50                 ` Guenter Roeck
2018-01-29  7:19                 ` [PATCH] " shufan_lee(李書帆)
2018-01-29  7:19                   ` shufan_lee(李書帆)
2018-01-29 19:57                   ` Guenter Roeck [this message]
2018-01-29 19:57                     ` Guenter Roeck
2018-01-30 13:21                     ` [PATCH] " shufan_lee(李書帆)
2018-01-30 13:21                       ` shufan_lee(李書帆)
2018-01-30 23:25                       ` [PATCH] " Guenter Roeck
2018-01-30 23:25                         ` Guenter Roeck
  -- strict thread matches above, loose matches on Subject: below --
2018-01-09  3:13 [PATCH] " shufan_lee(李書帆)
2018-01-09  6:18 ` Randy Dunlap
2018-01-09  8:45   ` shufan_lee(李書帆)
2018-01-09 17:26     ` Randy Dunlap
2018-01-10  2:49       ` shufan_lee(李書帆)

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=20180129195752.GA24352@roeck-us.net \
    --to=linux@roeck-us.net \
    --cc=cy_huang@richtek.com \
    --cc=heikki.krogerus@linux.intel.com \
    --cc=jun.li@nxp.com \
    --cc=leechu729@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=shufan_lee@richtek.com \
    /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.