Re: [PATCH v3 10/15] phy: tegra: xusb: Add wake/sleepwalk for Tegra210

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, Sep 09, 2020 at 04:10:36PM +0800, JC Kuo wrote:
[...]
> diff --git a/drivers/phy/tegra/xusb-tegra210.c b/drivers/phy/tegra/xusb-tegra210.c
[...]
> @@ -2096,6 +2938,96 @@ static const struct phy_ops tegra210_sata_phy_ops = {
>  	.owner = THIS_MODULE,
>  };
>  
> +static inline bool is_usb3_phy(struct phy *phy)
> +{
> +	return (phy->ops == &tegra210_pcie_phy_ops ||
> +		phy->ops == &tegra210_sata_phy_ops);
> +}
> +
> +static inline bool is_hsic_phy(struct phy *phy)
> +{
> +	return phy->ops == &tegra210_hsic_phy_ops;
> +}
> +
> +static inline bool is_utmi_phy(struct phy *phy)
> +{
> +	return phy->ops == &tegra210_usb2_phy_ops;
> +}
> +
> +static int tegra210_xusb_padctl_enable_phy_wake(struct tegra_xusb_padctl *padctl, struct phy *phy)
> +{
> +	if (is_usb3_phy(phy))
> +		return tegra210_usb3_enable_phy_wake(phy);
> +
> +	if (is_utmi_phy(phy))
> +		return tegra210_utmi_enable_phy_wake(phy);
> +
> +	if (is_hsic_phy(phy))
> +		return tegra210_hsic_enable_phy_wake(phy);
> +
> +	return -EINVAL;
> +}
> +
> +static int tegra210_xusb_padctl_disable_phy_wake(struct tegra_xusb_padctl *padctl, struct phy *phy)
> +{
> +	if (is_usb3_phy(phy))
> +		return tegra210_usb3_disable_phy_wake(phy);
> +
> +	if (is_utmi_phy(phy))
> +		return tegra210_utmi_disable_phy_wake(phy);
> +
> +	if (is_hsic_phy(phy))
> +		return tegra210_hsic_disable_phy_wake(phy);
> +
> +	return -EINVAL;
> +}
> +
> +static bool tegra210_xusb_padctl_remote_wake_detected(struct phy *phy)
> +{
> +	if (is_utmi_phy(phy))
> +		return tegra210_utmi_phy_remote_wake_detected(phy);
> +
> +	if (is_hsic_phy(phy))
> +		return tegra210_hsic_phy_remote_wake_detected(phy);
> +
> +	if (is_usb3_phy(phy))
> +		return tegra210_usb3_phy_remote_wake_detected(phy);
> +
> +	return false;
> +}
> +
> +static int tegra210_xusb_padctl_enable_phy_sleepwalk(struct tegra_xusb_padctl *padctl,
> +						     struct phy *phy,
> +						     enum usb_device_speed speed)
> +{
> +	if (is_usb3_phy(phy))
> +		return tegra210_usb3_enable_phy_sleepwalk(phy);
> +
> +	if (is_utmi_phy(phy))
> +		return tegra210_pmc_utmi_enable_phy_sleepwalk(phy, speed);
> +
> +	if (is_hsic_phy(phy))
> +		return tegra210_pmc_hsic_enable_phy_sleepwalk(phy);
> +
> +	return -EINVAL;
> +}
> +
> +static int tegra210_xusb_padctl_disable_phy_sleepwalk(struct tegra_xusb_padctl *padctl,
> +						      struct phy *phy)
> +{
> +	if (is_usb3_phy(phy))
> +		return tegra210_usb3_disable_phy_sleepwalk(phy);
> +
> +	if (is_utmi_phy(phy))
> +		return tegra210_pmc_utmi_disable_phy_sleepwalk(phy);
> +
> +	if (is_hsic_phy(phy))
> +		return tegra210_pmc_hsic_disable_phy_sleepwalk(phy);
> +
> +	return -EINVAL;
> +}

[...]

Could we add function pointers to struct tegra_xusb_lane_ops for all of
these? That would allow us to assign them once during probe and then we
don't have to bother with these is_*() functions and multiplexing but
instead just call ->enable_phy_wake() and ->disable_phy_wake() directly.

> +
> +

There's an extra blank line here.

>  static struct tegra_xusb_pad *
>  tegra210_sata_pad_probe(struct tegra_xusb_padctl *padctl,
>  			const struct tegra_xusb_pad_soc *soc,
> @@ -2293,6 +3225,8 @@ tegra210_xusb_padctl_probe(struct device *dev,
>  			   const struct tegra_xusb_padctl_soc *soc)
>  {
>  	struct tegra210_xusb_padctl *padctl;
> +	struct device_node *node, *np = dev->of_node;

We only need dev->of_node once, so I don't think we need to store it in
a local variable. Just make this:

	struct device_node *np;

> +	struct platform_device *pmc_dev;

I'd call this pdev, which is the canonical name for variables pointing
to a platform device.

>  	int err;
>  
>  	padctl = devm_kzalloc(dev, sizeof(*padctl), GFP_KERNEL);
> @@ -2306,6 +3240,23 @@ tegra210_xusb_padctl_probe(struct device *dev,
>  	if (err < 0)
>  		return ERR_PTR(err);
>  
> +	node = of_parse_phandle(np, "nvidia,pmc", 0);
> +	if (!node) {

And make this:

	np = of_parse_phandle(dev->of_node, "nvidia,pmc", 0);
	if (!np) {

> +		dev_info(dev, "nvidia,pmc property is missing\n");

It might be better for this to be a warning, to make it easier to catch.

> +		goto no_pmc;
> +	}
> +
> +	pmc_dev = of_find_device_by_node(node);
> +	if (!pmc_dev) {
> +		dev_info(dev, "pmc device is not available\n");

Same here. Also s/pmc/PMC/ in the message

> +		goto no_pmc;

Maybe call the label "out", "done" or something similar. "no_pmc" makes
it sound like it's meant for error cases, which makes it confusing when
you fallthrough for the success case as well.

Actually, in this case it might be easier to just return here instead of
using a goto.

> +	}
> +
> +	padctl->regmap = dev_get_regmap(&pmc_dev->dev, "usb_sleepwalk");
> +	if (!padctl->regmap)
> +		dev_info(dev, "pmc regmap is not available.\n");

Do we perhaps want to defer probe here?

Thierry

Attachment: signature.asc
Description: PGP signature


[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux