* [RFC PATCH v3 1/7] PCI: rockchip: split out rockchip_pcie_get_phys
[not found] ` <1500364623-97041-1-git-send-email-shawn.lin-TNX95d0MmH7DzftRWevZcw@public.gmane.org>
@ 2017-07-18 7:56 ` Shawn Lin
[not found] ` <1500364623-97041-2-git-send-email-shawn.lin-TNX95d0MmH7DzftRWevZcw@public.gmane.org>
2017-07-18 7:56 ` [RFC PATCH v3 2/7] PCI: rockchip: introduce per-lanes PHYs support Shawn Lin
` (2 subsequent siblings)
3 siblings, 1 reply; 13+ messages in thread
From: Shawn Lin @ 2017-07-18 7:56 UTC (permalink / raw)
To: Bjorn Helgaas, Kishon Vijay Abraham I
Cc: Rob Herring, Heiko Stuebner, linux-pci-u79uwXL29TY76Z2rM5mHXA,
linux-rockchip-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r, Brian Norris,
Jeffy Chen, devicetree-u79uwXL29TY76Z2rM5mHXA, Shawn Lin
We plan to introduce per-lanes PHY, so split out new
function to make it easy in the future. No functional
change intended.
Signed-off-by: Shawn Lin <shawn.lin-TNX95d0MmH7DzftRWevZcw@public.gmane.org>
Tested-by: Jeffy Chen <jeffy.chen-TNX95d0MmH7DzftRWevZcw@public.gmane.org>
---
Changes in v3: None
Changes in v2: None
drivers/pci/host/pcie-rockchip.c | 19 ++++++++++++++-----
1 file changed, 14 insertions(+), 5 deletions(-)
diff --git a/drivers/pci/host/pcie-rockchip.c b/drivers/pci/host/pcie-rockchip.c
index 5acf869..6632a51 100644
--- a/drivers/pci/host/pcie-rockchip.c
+++ b/drivers/pci/host/pcie-rockchip.c
@@ -853,6 +853,19 @@ static void rockchip_pcie_legacy_int_handler(struct irq_desc *desc)
chained_irq_exit(chip, desc);
}
+static int rockchip_pcie_get_phys(struct rockchip_pcie *rockchip)
+{
+ struct device *dev = rockchip->dev;
+
+ rockchip->phy = devm_phy_get(dev, "pcie-phy");
+ if (IS_ERR(rockchip->phy)) {
+ if (PTR_ERR(rockchip->phy) != -EPROBE_DEFER)
+ dev_err(dev, "missing phy\n");
+ return PTR_ERR(rockchip->phy);
+ }
+
+ return 0;
+}
/**
* rockchip_pcie_parse_dt - Parse Device Tree
@@ -883,12 +896,8 @@ static int rockchip_pcie_parse_dt(struct rockchip_pcie *rockchip)
if (IS_ERR(rockchip->apb_base))
return PTR_ERR(rockchip->apb_base);
- rockchip->phy = devm_phy_get(dev, "pcie-phy");
- if (IS_ERR(rockchip->phy)) {
- if (PTR_ERR(rockchip->phy) != -EPROBE_DEFER)
- dev_err(dev, "missing phy\n");
+ if (rockchip_pcie_get_phys(rockchip))
return PTR_ERR(rockchip->phy);
- }
rockchip->lanes = 1;
err = of_property_read_u32(node, "num-lanes", &rockchip->lanes);
--
1.9.1
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [RFC PATCH v3 2/7] PCI: rockchip: introduce per-lanes PHYs support
[not found] ` <1500364623-97041-1-git-send-email-shawn.lin-TNX95d0MmH7DzftRWevZcw@public.gmane.org>
2017-07-18 7:56 ` [RFC PATCH v3 1/7] PCI: rockchip: split out rockchip_pcie_get_phys Shawn Lin
@ 2017-07-18 7:56 ` Shawn Lin
2017-07-18 20:33 ` Brian Norris
2017-07-18 7:56 ` [RFC PATCH v3 3/7] phy: rockcip-pcie: reconstruct driver to support per-lane PHYs Shawn Lin
2017-07-18 20:29 ` [RFC PATCH v3 0/7] Reconstruct rockchip's PCIe and PCIe-PHY driver for per-lane PHY model Brian Norris
3 siblings, 1 reply; 13+ messages in thread
From: Shawn Lin @ 2017-07-18 7:56 UTC (permalink / raw)
To: Bjorn Helgaas, Kishon Vijay Abraham I
Cc: Rob Herring, Heiko Stuebner, linux-pci-u79uwXL29TY76Z2rM5mHXA,
linux-rockchip-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r, Brian Norris,
Jeffy Chen, devicetree-u79uwXL29TY76Z2rM5mHXA, Shawn Lin
We distinguish the legacy PHY with the newer per-lane
PHYs by adding legacy_phy flag. Note that the legacy phy
is still the first option to be searched in order not to
break the backward compatibility of DTB.
Signed-off-by: Shawn Lin <shawn.lin-TNX95d0MmH7DzftRWevZcw@public.gmane.org>
Tested-by: Jeffy Chen <jeffy.chen-TNX95d0MmH7DzftRWevZcw@public.gmane.org>
---
Changes in v3:
- kill rockchip_pcie_manipulate_phys and related stuff
- use phys array
- improve the commit msg
Changes in v2: None
drivers/pci/host/pcie-rockchip.c | 100 +++++++++++++++++++++++++++------------
1 file changed, 69 insertions(+), 31 deletions(-)
diff --git a/drivers/pci/host/pcie-rockchip.c b/drivers/pci/host/pcie-rockchip.c
index 6632a51..4cc6aec 100644
--- a/drivers/pci/host/pcie-rockchip.c
+++ b/drivers/pci/host/pcie-rockchip.c
@@ -47,6 +47,7 @@
#define HIWORD_UPDATE_BIT(val) HIWORD_UPDATE(val, val)
#define ENCODE_LANES(x) ((((x) >> 1) & 3) << 4)
+#define MAX_LANE_NUM 4
#define PCIE_CLIENT_BASE 0x0
#define PCIE_CLIENT_CONFIG (PCIE_CLIENT_BASE + 0x00)
@@ -210,7 +211,8 @@
struct rockchip_pcie {
void __iomem *reg_base; /* DT axi-base */
void __iomem *apb_base; /* DT apb-base */
- struct phy *phy;
+ bool legacy_phy;
+ struct phy *phys[MAX_LANE_NUM];
struct reset_control *core_rst;
struct reset_control *mgmt_rst;
struct reset_control *mgmt_sticky_rst;
@@ -507,6 +509,46 @@ static void rockchip_pcie_set_power_limit(struct rockchip_pcie *rockchip)
rockchip_pcie_write(rockchip, status, PCIE_RC_CONFIG_DCR);
}
+static int rockchip_pcie_get_phys(struct rockchip_pcie *rockchip)
+{
+ struct device *dev = rockchip->dev;
+ struct phy *phy;
+ char *name;
+ u32 i;
+
+ rockchip->phys[0] = devm_phy_get(dev, "pcie-phy");
+ if (IS_ERR(rockchip->phys[0])) {
+ if (PTR_ERR(rockchip->phys[0]) == -EPROBE_DEFER)
+ return PTR_ERR(rockchip->phys[0]);
+ dev_dbg(dev, "missing legacy phy, and search for per-lane PHY\n");
+ } else {
+ rockchip->legacy_phy = true;
+ dev_warn(dev, "legacy phy model is deprecated!\n");
+ return 0;
+ }
+
+ for (i = 0; i < MAX_LANE_NUM; i++) {
+ name = kasprintf(GFP_KERNEL, "pcie-phy-%u", i);
+ if (!name)
+ return -ENOMEM;
+
+ phy = devm_of_phy_get(rockchip->dev,
+ rockchip->dev->of_node, name);
+ kfree(name);
+
+ if (IS_ERR(phy)) {
+ if (PTR_ERR(phy) != -EPROBE_DEFER)
+ dev_err(dev, "missing phy for lane %d: %ld\n",
+ i, PTR_ERR(phy));
+ return PTR_ERR(phy);
+ }
+
+ rockchip->phys[i] = phy;
+ }
+
+ return 0;
+}
+
/**
* rockchip_pcie_init_port - Initialize hardware
* @rockchip: PCIe port information
@@ -514,7 +556,7 @@ static void rockchip_pcie_set_power_limit(struct rockchip_pcie *rockchip)
static int rockchip_pcie_init_port(struct rockchip_pcie *rockchip)
{
struct device *dev = rockchip->dev;
- int err;
+ int err, i;
u32 status;
gpiod_set_value(rockchip->ep_gpio, 0);
@@ -537,10 +579,12 @@ static int rockchip_pcie_init_port(struct rockchip_pcie *rockchip)
return err;
}
- err = phy_init(rockchip->phy);
- if (err < 0) {
- dev_err(dev, "fail to init phy, err %d\n", err);
- return err;
+ for (i = 0; i < MAX_LANE_NUM; i++) {
+ err = phy_init(rockchip->phys[i]);
+ if (err) {
+ dev_err(dev, "init phy err %d\n", err);
+ return err;
+ }
}
err = reset_control_assert(rockchip->core_rst);
@@ -602,10 +646,12 @@ static int rockchip_pcie_init_port(struct rockchip_pcie *rockchip)
PCIE_CLIENT_MODE_RC,
PCIE_CLIENT_CONFIG);
- err = phy_power_on(rockchip->phy);
- if (err) {
- dev_err(dev, "fail to power on phy, err %d\n", err);
- return err;
+ for (i = 0; i < MAX_LANE_NUM; i++) {
+ err = phy_power_on(rockchip->phys[i]);
+ if (err) {
+ dev_err(dev, "power on phy err %d\n", err);
+ return err;
+ }
}
/*
@@ -853,20 +899,6 @@ static void rockchip_pcie_legacy_int_handler(struct irq_desc *desc)
chained_irq_exit(chip, desc);
}
-static int rockchip_pcie_get_phys(struct rockchip_pcie *rockchip)
-{
- struct device *dev = rockchip->dev;
-
- rockchip->phy = devm_phy_get(dev, "pcie-phy");
- if (IS_ERR(rockchip->phy)) {
- if (PTR_ERR(rockchip->phy) != -EPROBE_DEFER)
- dev_err(dev, "missing phy\n");
- return PTR_ERR(rockchip->phy);
- }
-
- return 0;
-}
-
/**
* rockchip_pcie_parse_dt - Parse Device Tree
* @rockchip: PCIe port information
@@ -896,8 +928,9 @@ static int rockchip_pcie_parse_dt(struct rockchip_pcie *rockchip)
if (IS_ERR(rockchip->apb_base))
return PTR_ERR(rockchip->apb_base);
- if (rockchip_pcie_get_phys(rockchip))
- return PTR_ERR(rockchip->phy);
+ err = rockchip_pcie_get_phys(rockchip);
+ if (err)
+ return err;
rockchip->lanes = 1;
err = of_property_read_u32(node, "num-lanes", &rockchip->lanes);
@@ -1282,7 +1315,7 @@ static int rockchip_pcie_wait_l2(struct rockchip_pcie *rockchip)
static int __maybe_unused rockchip_pcie_suspend_noirq(struct device *dev)
{
struct rockchip_pcie *rockchip = dev_get_drvdata(dev);
- int ret;
+ int ret, i;
/* disable core and cli int since we don't need to ack PME_ACK */
rockchip_pcie_write(rockchip, (PCIE_CLIENT_INT_CLI << 16) |
@@ -1295,8 +1328,10 @@ static int __maybe_unused rockchip_pcie_suspend_noirq(struct device *dev)
return ret;
}
- phy_power_off(rockchip->phy);
- phy_exit(rockchip->phy);
+ for (i = 0; i < MAX_LANE_NUM; i++) {
+ phy_power_off(rockchip->phys[i]);
+ phy_exit(rockchip->phys[i]);
+ }
clk_disable_unprepare(rockchip->clk_pcie_pm);
clk_disable_unprepare(rockchip->hclk_pcie);
@@ -1532,14 +1567,17 @@ static int rockchip_pcie_remove(struct platform_device *pdev)
{
struct device *dev = &pdev->dev;
struct rockchip_pcie *rockchip = dev_get_drvdata(dev);
+ int i;
pci_stop_root_bus(rockchip->root_bus);
pci_remove_root_bus(rockchip->root_bus);
pci_unmap_iospace(rockchip->io);
irq_domain_remove(rockchip->irq_domain);
- phy_power_off(rockchip->phy);
- phy_exit(rockchip->phy);
+ for (i = 0; i < MAX_LANE_NUM; i++) {
+ phy_power_off(rockchip->phys[i]);
+ phy_exit(rockchip->phys[i]);
+ }
clk_disable_unprepare(rockchip->clk_pcie_pm);
clk_disable_unprepare(rockchip->hclk_pcie);
--
1.9.1
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply related [flat|nested] 13+ messages in thread
* Re: [RFC PATCH v3 2/7] PCI: rockchip: introduce per-lanes PHYs support
2017-07-18 7:56 ` [RFC PATCH v3 2/7] PCI: rockchip: introduce per-lanes PHYs support Shawn Lin
@ 2017-07-18 20:33 ` Brian Norris
0 siblings, 0 replies; 13+ messages in thread
From: Brian Norris @ 2017-07-18 20:33 UTC (permalink / raw)
To: Shawn Lin
Cc: Bjorn Helgaas, Kishon Vijay Abraham I, Rob Herring,
Heiko Stuebner, linux-pci, linux-rockchip, Jeffy Chen, devicetree
Hi,
On Tue, Jul 18, 2017 at 03:56:58PM +0800, Shawn Lin wrote:
> We distinguish the legacy PHY with the newer per-lane
> PHYs by adding legacy_phy flag. Note that the legacy phy
> is still the first option to be searched in order not to
> break the backward compatibility of DTB.
>
> Signed-off-by: Shawn Lin <shawn.lin@rock-chips.com>
> Tested-by: Jeffy Chen <jeffy.chen@rock-chips.com>
> ---
>
> Changes in v3:
> - kill rockchip_pcie_manipulate_phys and related stuff
> - use phys array
> - improve the commit msg
>
> Changes in v2: None
>
> drivers/pci/host/pcie-rockchip.c | 100 +++++++++++++++++++++++++++------------
> 1 file changed, 69 insertions(+), 31 deletions(-)
>
> diff --git a/drivers/pci/host/pcie-rockchip.c b/drivers/pci/host/pcie-rockchip.c
> index 6632a51..4cc6aec 100644
> --- a/drivers/pci/host/pcie-rockchip.c
> +++ b/drivers/pci/host/pcie-rockchip.c
...
> @@ -537,10 +579,12 @@ static int rockchip_pcie_init_port(struct rockchip_pcie *rockchip)
> return err;
> }
>
> - err = phy_init(rockchip->phy);
> - if (err < 0) {
> - dev_err(dev, "fail to init phy, err %d\n", err);
> - return err;
> + for (i = 0; i < MAX_LANE_NUM; i++) {
> + err = phy_init(rockchip->phys[i]);
> + if (err) {
> + dev_err(dev, "init phy err %d\n", err);
Include the PHY index in the error message?
> + return err;
> + }
> }
>
> err = reset_control_assert(rockchip->core_rst);
> @@ -602,10 +646,12 @@ static int rockchip_pcie_init_port(struct rockchip_pcie *rockchip)
> PCIE_CLIENT_MODE_RC,
> PCIE_CLIENT_CONFIG);
>
> - err = phy_power_on(rockchip->phy);
> - if (err) {
> - dev_err(dev, "fail to power on phy, err %d\n", err);
> - return err;
> + for (i = 0; i < MAX_LANE_NUM; i++) {
> + err = phy_power_on(rockchip->phys[i]);
> + if (err) {
> + dev_err(dev, "power on phy err %d\n", err);
Same?
> + return err;
> + }
> }
>
> /*
...
Brian
^ permalink raw reply [flat|nested] 13+ messages in thread
* [RFC PATCH v3 3/7] phy: rockcip-pcie: reconstruct driver to support per-lane PHYs
[not found] ` <1500364623-97041-1-git-send-email-shawn.lin-TNX95d0MmH7DzftRWevZcw@public.gmane.org>
2017-07-18 7:56 ` [RFC PATCH v3 1/7] PCI: rockchip: split out rockchip_pcie_get_phys Shawn Lin
2017-07-18 7:56 ` [RFC PATCH v3 2/7] PCI: rockchip: introduce per-lanes PHYs support Shawn Lin
@ 2017-07-18 7:56 ` Shawn Lin
2017-07-18 20:29 ` [RFC PATCH v3 0/7] Reconstruct rockchip's PCIe and PCIe-PHY driver for per-lane PHY model Brian Norris
3 siblings, 0 replies; 13+ messages in thread
From: Shawn Lin @ 2017-07-18 7:56 UTC (permalink / raw)
To: Bjorn Helgaas, Kishon Vijay Abraham I
Cc: Rob Herring, Heiko Stuebner, linux-pci-u79uwXL29TY76Z2rM5mHXA,
linux-rockchip-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r, Brian Norris,
Jeffy Chen, devicetree-u79uwXL29TY76Z2rM5mHXA, Shawn Lin
This patch reconstructs the whole driver to support per-lane
PHYs. Note that we could also support the legacy PHY if you
don't provide argument to our of_xlate.
Signed-off-by: Shawn Lin <shawn.lin-TNX95d0MmH7DzftRWevZcw@public.gmane.org>
Tested-by: Jeffy Chen <jeffy.chen-TNX95d0MmH7DzftRWevZcw@public.gmane.org>
---
Changes in v3:
- remove unnecessary forward declaration
- keep mutex inside struct rockchip_pcie_phy
- fix wrong check of args number
- move de-idle lanes after deasserting the reset
Changes in v2:
- deprecate legacy PHY model
- improve rockchip_pcie_phy_of_xlate
- fix wrong calculation of pwr_cnt and add new init_cnt
- add internal locking
- introduce per-lane data to simply the code
drivers/phy/rockchip/phy-rockchip-pcie.c | 124 +++++++++++++++++++++++++++----
1 file changed, 110 insertions(+), 14 deletions(-)
diff --git a/drivers/phy/rockchip/phy-rockchip-pcie.c b/drivers/phy/rockchip/phy-rockchip-pcie.c
index 6904633..b5005a5 100644
--- a/drivers/phy/rockchip/phy-rockchip-pcie.c
+++ b/drivers/phy/rockchip/phy-rockchip-pcie.c
@@ -73,10 +73,39 @@ struct rockchip_pcie_data {
struct rockchip_pcie_phy {
struct rockchip_pcie_data *phy_data;
struct regmap *reg_base;
+ struct phy_pcie_instance {
+ struct phy *phy;
+ u32 index;
+ } phys[PHY_MAX_LANE_NUM];
+ struct mutex pcie_mutex;
struct reset_control *phy_rst;
struct clk *clk_pciephy_ref;
+ int pwr_cnt;
+ int init_cnt;
};
+static inline
+struct rockchip_pcie_phy *to_pcie_phy(struct phy_pcie_instance *inst)
+{
+ return container_of(inst, struct rockchip_pcie_phy,
+ phys[inst->index]);
+}
+
+static struct phy *rockchip_pcie_phy_of_xlate(struct device *dev,
+ struct of_phandle_args *args)
+{
+ struct rockchip_pcie_phy *rk_phy = dev_get_drvdata(dev);
+
+ if (args->args_count == 0)
+ return rk_phy->phys[0].phy;
+
+ if (WARN_ON(args->args[0] >= PHY_MAX_LANE_NUM))
+ return ERR_PTR(-ENODEV);
+
+ return rk_phy->phys[args->args[0]].phy;
+}
+
+
static inline void phy_wr_cfg(struct rockchip_pcie_phy *rk_phy,
u32 addr, u32 data)
{
@@ -116,29 +145,59 @@ static inline u32 phy_rd_cfg(struct rockchip_pcie_phy *rk_phy,
static int rockchip_pcie_phy_power_off(struct phy *phy)
{
- struct rockchip_pcie_phy *rk_phy = phy_get_drvdata(phy);
+ struct phy_pcie_instance *inst = phy_get_drvdata(phy);
+ struct rockchip_pcie_phy *rk_phy = to_pcie_phy(inst);
int err = 0;
+ mutex_lock(&rk_phy->pcie_mutex);
+
+ regmap_write(rk_phy->reg_base,
+ rk_phy->phy_data->pcie_laneoff,
+ HIWORD_UPDATE(PHY_LANE_IDLE_OFF,
+ PHY_LANE_IDLE_MASK,
+ PHY_LANE_IDLE_A_SHIFT + inst->index));
+
+ if (--rk_phy->pwr_cnt)
+ goto err_out;
+
err = reset_control_assert(rk_phy->phy_rst);
if (err) {
dev_err(&phy->dev, "assert phy_rst err %d\n", err);
- return err;
+ goto err_restore;
}
+err_out:
+ mutex_unlock(&rk_phy->pcie_mutex);
return 0;
+
+err_restore:
+ ++rk_phy->pwr_cnt;
+ regmap_write(rk_phy->reg_base,
+ rk_phy->phy_data->pcie_laneoff,
+ HIWORD_UPDATE(!PHY_LANE_IDLE_OFF,
+ PHY_LANE_IDLE_MASK,
+ PHY_LANE_IDLE_A_SHIFT + inst->index));
+ mutex_unlock(&rk_phy->pcie_mutex);
+ return err;
}
static int rockchip_pcie_phy_power_on(struct phy *phy)
{
- struct rockchip_pcie_phy *rk_phy = phy_get_drvdata(phy);
+ struct phy_pcie_instance *inst = phy_get_drvdata(phy);
+ struct rockchip_pcie_phy *rk_phy = to_pcie_phy(inst);
int err = 0;
u32 status;
unsigned long timeout;
+ mutex_lock(&rk_phy->pcie_mutex);
+
+ if (rk_phy->pwr_cnt++)
+ goto err_out;
+
err = reset_control_deassert(rk_phy->phy_rst);
if (err) {
dev_err(&phy->dev, "deassert phy_rst err %d\n", err);
- return err;
+ goto err_pwr_cnt;
}
regmap_write(rk_phy->reg_base, rk_phy->phy_data->pcie_conf,
@@ -146,6 +205,12 @@ static int rockchip_pcie_phy_power_on(struct phy *phy)
PHY_CFG_ADDR_MASK,
PHY_CFG_ADDR_SHIFT));
+ regmap_write(rk_phy->reg_base,
+ rk_phy->phy_data->pcie_laneoff,
+ HIWORD_UPDATE(!PHY_LANE_IDLE_OFF,
+ PHY_LANE_IDLE_MASK,
+ PHY_LANE_IDLE_A_SHIFT + inst->index));
+
/*
* No documented timeout value for phy operation below,
* so we make it large enough here. And we use loop-break
@@ -214,18 +279,29 @@ static int rockchip_pcie_phy_power_on(struct phy *phy)
goto err_pll_lock;
}
+err_out:
+ mutex_unlock(&rk_phy->pcie_mutex);
return 0;
err_pll_lock:
reset_control_assert(rk_phy->phy_rst);
+err_pwr_cnt:
+ --rk_phy->pwr_cnt;
+ mutex_unlock(&rk_phy->pcie_mutex);
return err;
}
static int rockchip_pcie_phy_init(struct phy *phy)
{
- struct rockchip_pcie_phy *rk_phy = phy_get_drvdata(phy);
+ struct phy_pcie_instance *inst = phy_get_drvdata(phy);
+ struct rockchip_pcie_phy *rk_phy = to_pcie_phy(inst);
int err = 0;
+ mutex_lock(&rk_phy->pcie_mutex);
+
+ if (rk_phy->init_cnt++)
+ goto err_out;
+
err = clk_prepare_enable(rk_phy->clk_pciephy_ref);
if (err) {
dev_err(&phy->dev, "Fail to enable pcie ref clock.\n");
@@ -238,20 +314,33 @@ static int rockchip_pcie_phy_init(struct phy *phy)
goto err_reset;
}
- return err;
+err_out:
+ mutex_unlock(&rk_phy->pcie_mutex);
+ return 0;
err_reset:
+
clk_disable_unprepare(rk_phy->clk_pciephy_ref);
err_refclk:
+ --rk_phy->init_cnt;
+ mutex_unlock(&rk_phy->pcie_mutex);
return err;
}
static int rockchip_pcie_phy_exit(struct phy *phy)
{
- struct rockchip_pcie_phy *rk_phy = phy_get_drvdata(phy);
+ struct phy_pcie_instance *inst = phy_get_drvdata(phy);
+ struct rockchip_pcie_phy *rk_phy = to_pcie_phy(inst);
+
+ mutex_lock(&rk_phy->pcie_mutex);
+
+ if (--rk_phy->init_cnt)
+ goto err_init_cnt;
clk_disable_unprepare(rk_phy->clk_pciephy_ref);
+err_init_cnt:
+ mutex_unlock(&rk_phy->pcie_mutex);
return 0;
}
@@ -283,10 +372,10 @@ static int rockchip_pcie_phy_probe(struct platform_device *pdev)
{
struct device *dev = &pdev->dev;
struct rockchip_pcie_phy *rk_phy;
- struct phy *generic_phy;
struct phy_provider *phy_provider;
struct regmap *grf;
const struct of_device_id *of_id;
+ int i;
grf = syscon_node_to_regmap(dev->parent->of_node);
if (IS_ERR(grf)) {
@@ -305,6 +394,8 @@ static int rockchip_pcie_phy_probe(struct platform_device *pdev)
rk_phy->phy_data = (struct rockchip_pcie_data *)of_id->data;
rk_phy->reg_base = grf;
+ mutex_init(&rk_phy->pcie_mutex);
+
rk_phy->phy_rst = devm_reset_control_get(dev, "phy");
if (IS_ERR(rk_phy->phy_rst)) {
if (PTR_ERR(rk_phy->phy_rst) != -EPROBE_DEFER)
@@ -319,14 +410,19 @@ static int rockchip_pcie_phy_probe(struct platform_device *pdev)
return PTR_ERR(rk_phy->clk_pciephy_ref);
}
- generic_phy = devm_phy_create(dev, dev->of_node, &ops);
- if (IS_ERR(generic_phy)) {
- dev_err(dev, "failed to create PHY\n");
- return PTR_ERR(generic_phy);
+ for (i = 0; i < PHY_MAX_LANE_NUM; i++) {
+ rk_phy->phys[i].phy = devm_phy_create(dev, dev->of_node, &ops);
+ if (IS_ERR(rk_phy->phys[i].phy)) {
+ dev_err(dev, "failed to create PHY%d\n", i);
+ return PTR_ERR(rk_phy->phys[i].phy);
+ }
+ rk_phy->phys[i].index = i;
+ phy_set_drvdata(rk_phy->phys[i].phy, &rk_phy->phys[i]);
}
- phy_set_drvdata(generic_phy, rk_phy);
- phy_provider = devm_of_phy_provider_register(dev, of_phy_simple_xlate);
+ platform_set_drvdata(pdev, rk_phy);
+ phy_provider = devm_of_phy_provider_register(dev,
+ rockchip_pcie_phy_of_xlate);
return PTR_ERR_OR_ZERO(phy_provider);
}
--
1.9.1
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply related [flat|nested] 13+ messages in thread
* Re: [RFC PATCH v3 0/7] Reconstruct rockchip's PCIe and PCIe-PHY driver for per-lane PHY model
[not found] ` <1500364623-97041-1-git-send-email-shawn.lin-TNX95d0MmH7DzftRWevZcw@public.gmane.org>
` (2 preceding siblings ...)
2017-07-18 7:56 ` [RFC PATCH v3 3/7] phy: rockcip-pcie: reconstruct driver to support per-lane PHYs Shawn Lin
@ 2017-07-18 20:29 ` Brian Norris
2017-07-19 0:51 ` Shawn Lin
3 siblings, 1 reply; 13+ messages in thread
From: Brian Norris @ 2017-07-18 20:29 UTC (permalink / raw)
To: Shawn Lin
Cc: Bjorn Helgaas, Kishon Vijay Abraham I, Rob Herring,
Heiko Stuebner, linux-pci-u79uwXL29TY76Z2rM5mHXA,
linux-rockchip-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r, Jeffy Chen,
devicetree-u79uwXL29TY76Z2rM5mHXA
On Tue, Jul 18, 2017 at 03:56:56PM +0800, Shawn Lin wrote:
>
> This patchset is trying to reconstruct PCIe and PCIe-PHY driver
> for rockchip platform in order to support per-lane PHY mode. And
> we could idle the inactive lane(s) finally.
>
> We deprecate the legacy PHY mode but the code could still
> support it in order not to break backware compatibility of DTB. And I
> organize the patches carefully so that we don't introduce git-bisect
> issue.
>
> Note that I carry on Jeffy's test tag from v2 as he has locally tested
> my v3 patchset.
I have a few nits for the patchset (will reply shortly), but otherwise
(if we're *really* going to go with this approach; I still would
appreciate a reply from Kishon on the original patchset, where I
suggested alternatives) at least the code is much better this time
around. So for the whole thing:
Reviewed-by: Brian Norris <briannorris-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
> Changes in v3:
> - kill rockchip_pcie_manipulate_phys and related stuff
> - use phys array
> - improve the commit msg
> - remove unnecessary forward declaration
> - keep mutex inside struct rockchip_pcie_phy
> - fix wrong check of args number
> - move de-idle lanes after deasserting the reset
> - use cached lanes_map to avoid powering off inactive
> lanes twice
> - rename the commit tile
>
> Changes in v2:
> - deprecate legacy PHY model
> - improve rockchip_pcie_phy_of_xlate
> - fix wrong calculation of pwr_cnt and add new init_cnt
> - add internal locking
> - introduce per-lane data to simply the code
>
> Shawn Lin (7):
> PCI: rockchip: split out rockchip_pcie_get_phys
> PCI: rockchip: introduce per-lanes PHYs support
> phy: rockcip-pcie: reconstruct driver to support per-lane PHYs
> PCI: rockchip: idle the inactive PHY(s)
> arm64: dts: rockchip: convert PCIe to use per-lane PHYs for rk3339
> dt-bindings: PCI: rockchip: convert to use per-lane PHY model
> dt-bindings: phy: convert to use per-lane Rockchip PCIe PHY
>
> .../devicetree/bindings/pci/rockchip-pcie.txt | 25 ++++-
> .../devicetree/bindings/phy/rockchip-pcie-phy.txt | 7 +-
> arch/arm64/boot/dts/rockchip/rk3399.dtsi | 8 +-
> drivers/pci/host/pcie-rockchip.c | 123 ++++++++++++++++----
> drivers/phy/rockchip/phy-rockchip-pcie.c | 124 ++++++++++++++++++---
> 5 files changed, 245 insertions(+), 42 deletions(-)
>
> --
> 1.9.1
>
>
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [RFC PATCH v3 0/7] Reconstruct rockchip's PCIe and PCIe-PHY driver for per-lane PHY model
2017-07-18 20:29 ` [RFC PATCH v3 0/7] Reconstruct rockchip's PCIe and PCIe-PHY driver for per-lane PHY model Brian Norris
@ 2017-07-19 0:51 ` Shawn Lin
0 siblings, 0 replies; 13+ messages in thread
From: Shawn Lin @ 2017-07-19 0:51 UTC (permalink / raw)
To: Brian Norris
Cc: shawn.lin, Bjorn Helgaas, Kishon Vijay Abraham I, Rob Herring,
Heiko Stuebner, linux-pci, linux-rockchip, Jeffy Chen, devicetree
Hi Brian,
On 2017/7/19 4:29, Brian Norris wrote:
> On Tue, Jul 18, 2017 at 03:56:56PM +0800, Shawn Lin wrote:
>>
>> This patchset is trying to reconstruct PCIe and PCIe-PHY driver
>> for rockchip platform in order to support per-lane PHY mode. And
>> we could idle the inactive lane(s) finally.
>>
>> We deprecate the legacy PHY mode but the code could still
>> support it in order not to break backware compatibility of DTB. And I
>> organize the patches carefully so that we don't introduce git-bisect
>> issue.
>>
>> Note that I carry on Jeffy's test tag from v2 as he has locally tested
>> my v3 patchset.
>
> I have a few nits for the patchset (will reply shortly), but otherwise
> (if we're *really* going to go with this approach; I still would
> appreciate a reply from Kishon on the original patchset, where I
> suggested alternatives) at least the code is much better this time
> around. So for the whole thing:
>
> Reviewed-by: Brian Norris <briannorris@chromium.org>
Thanks for your review and Jeffy's test!
I probably will respin my v4 soon and wait for Kishon's final decision.
If Kishon prefer to ack your alternative solution, I'm fine to commit
some other bits as your alternatives seem a much simpler way.
>
>> Changes in v3:
>> - kill rockchip_pcie_manipulate_phys and related stuff
>> - use phys array
>> - improve the commit msg
>> - remove unnecessary forward declaration
>> - keep mutex inside struct rockchip_pcie_phy
>> - fix wrong check of args number
>> - move de-idle lanes after deasserting the reset
>> - use cached lanes_map to avoid powering off inactive
>> lanes twice
>> - rename the commit tile
>>
>> Changes in v2:
>> - deprecate legacy PHY model
>> - improve rockchip_pcie_phy_of_xlate
>> - fix wrong calculation of pwr_cnt and add new init_cnt
>> - add internal locking
>> - introduce per-lane data to simply the code
>>
>> Shawn Lin (7):
>> PCI: rockchip: split out rockchip_pcie_get_phys
>> PCI: rockchip: introduce per-lanes PHYs support
>> phy: rockcip-pcie: reconstruct driver to support per-lane PHYs
>> PCI: rockchip: idle the inactive PHY(s)
>> arm64: dts: rockchip: convert PCIe to use per-lane PHYs for rk3339
>> dt-bindings: PCI: rockchip: convert to use per-lane PHY model
>> dt-bindings: phy: convert to use per-lane Rockchip PCIe PHY
>>
>> .../devicetree/bindings/pci/rockchip-pcie.txt | 25 ++++-
>> .../devicetree/bindings/phy/rockchip-pcie-phy.txt | 7 +-
>> arch/arm64/boot/dts/rockchip/rk3399.dtsi | 8 +-
>> drivers/pci/host/pcie-rockchip.c | 123 ++++++++++++++++----
>> drivers/phy/rockchip/phy-rockchip-pcie.c | 124 ++++++++++++++++++---
>> 5 files changed, 245 insertions(+), 42 deletions(-)
>>
>> --
>> 1.9.1
>>
>>
>
>
>
^ permalink raw reply [flat|nested] 13+ messages in thread