[PATCH 1/7] phy: ti-pipe3: cleanup ti_pipe3_probe()

2015-08-04 Thread Kishon Vijay Abraham I
No functional change. Add separate functions for pll,
clocks and syscon to make ti_pipe3_probe clean.

Signed-off-by: Kishon Vijay Abraham I 
---
 drivers/phy/phy-ti-pipe3.c |  165 
 1 file changed, 104 insertions(+), 61 deletions(-)

diff --git a/drivers/phy/phy-ti-pipe3.c b/drivers/phy/phy-ti-pipe3.c
index 08020dc..072d308 100644
--- a/drivers/phy/phy-ti-pipe3.c
+++ b/drivers/phy/phy-ti-pipe3.c
@@ -308,51 +308,45 @@ static struct phy_ops ops = {
 
 static const struct of_device_id ti_pipe3_id_table[];
 
-static int ti_pipe3_probe(struct platform_device *pdev)
+static int ti_pipe3_get_pll_base(struct ti_pipe3 *phy)
 {
-   struct ti_pipe3 *phy;
-   struct phy *generic_phy;
-   struct phy_provider *phy_provider;
struct resource *res;
-   struct device_node *node = pdev->dev.of_node;
-   struct device_node *control_node;
-   struct platform_device *control_pdev;
const struct of_device_id *match;
-   struct clk *clk;
+   struct device *dev = phy->dev;
+   struct device_node *node = dev->of_node;
+   struct platform_device *pdev = to_platform_device(dev);
 
-   phy = devm_kzalloc(&pdev->dev, sizeof(*phy), GFP_KERNEL);
-   if (!phy)
-   return -ENOMEM;
+   if (of_device_is_compatible(node, "ti,phy-pipe3-pcie"))
+   return 0;
 
-   phy->dev= &pdev->dev;
+   match = of_match_device(ti_pipe3_id_table, dev);
+   if (!match)
+   return -EINVAL;
 
-   if (!of_device_is_compatible(node, "ti,phy-pipe3-pcie")) {
-   match = of_match_device(ti_pipe3_id_table, &pdev->dev);
-   if (!match)
-   return -EINVAL;
+   phy->dpll_map = (struct pipe3_dpll_map *)match->data;
+   if (!phy->dpll_map) {
+   dev_err(dev, "no DPLL data\n");
+   return -EINVAL;
+   }
 
-   phy->dpll_map = (struct pipe3_dpll_map *)match->data;
-   if (!phy->dpll_map) {
-   dev_err(&pdev->dev, "no DPLL data\n");
-   return -EINVAL;
-   }
+   res = platform_get_resource_byname(pdev, IORESOURCE_MEM,
+  "pll_ctrl");
+   phy->pll_ctrl_base = devm_ioremap_resource(dev, res);
+   if (IS_ERR(phy->pll_ctrl_base))
+   return PTR_ERR(phy->pll_ctrl_base);
 
-   res = platform_get_resource_byname(pdev, IORESOURCE_MEM,
-  "pll_ctrl");
-   phy->pll_ctrl_base = devm_ioremap_resource(&pdev->dev, res);
-   if (IS_ERR(phy->pll_ctrl_base))
-   return PTR_ERR(phy->pll_ctrl_base);
+   return 0;
+}
 
-   phy->sys_clk = devm_clk_get(phy->dev, "sysclk");
-   if (IS_ERR(phy->sys_clk)) {
-   dev_err(&pdev->dev, "unable to get sysclk\n");
-   return -EINVAL;
-   }
-   }
+static int ti_pipe3_get_clk(struct ti_pipe3 *phy)
+{
+   struct clk *clk;
+   struct device *dev = phy->dev;
+   struct device_node *node = dev->of_node;
 
-   phy->refclk = devm_clk_get(phy->dev, "refclk");
+   phy->refclk = devm_clk_get(dev, "refclk");
if (IS_ERR(phy->refclk)) {
-   dev_err(&pdev->dev, "unable to get refclk\n");
+   dev_err(dev, "unable to get refclk\n");
/* older DTBs have missing refclk in SATA PHY
 * so don't bail out in case of SATA PHY.
 */
@@ -361,76 +355,125 @@ static int ti_pipe3_probe(struct platform_device *pdev)
}
 
if (!of_device_is_compatible(node, "ti,phy-pipe3-sata")) {
-   phy->wkupclk = devm_clk_get(phy->dev, "wkupclk");
+   phy->wkupclk = devm_clk_get(dev, "wkupclk");
if (IS_ERR(phy->wkupclk)) {
-   dev_err(&pdev->dev, "unable to get wkupclk\n");
+   dev_err(dev, "unable to get wkupclk\n");
return PTR_ERR(phy->wkupclk);
}
} else {
phy->wkupclk = ERR_PTR(-ENODEV);
-   phy->dpll_reset_syscon = syscon_regmap_lookup_by_phandle(node,
-   "syscon-pllreset");
-   if (IS_ERR(phy->dpll_reset_syscon)) {
-   dev_info(&pdev->dev,
-"can't get syscon-pllreset, sata dpll won't 
idle\n");
-   phy->dpll_reset_syscon = NULL;
-   } else {
-   if (of_property_read_u32_index(node,
-  "syscon-pllreset", 1,
-  &phy->dpll_reset_reg)) {
-   dev_err(&pdev->dev,
-   "couldn't get pllreset reg. offset\n");
-   

Re: [PATCH 1/7] phy: ti-pipe3: cleanup ti_pipe3_probe()

2015-08-04 Thread Felipe Balbi
On Tue, Aug 04, 2015 at 08:50:40PM +0530, Kishon Vijay Abraham I wrote:
> No functional change. Add separate functions for pll,
> clocks and syscon to make ti_pipe3_probe clean.
> 
> Signed-off-by: Kishon Vijay Abraham I 

I think this needs to be splitted into smaller patches.

Seems like the very first patch would be to introduce a local struct
device pointer to be used. Than add each and every new function on their
own patch. This will help big time making your refactoring a lot clearer
and, should anything go wrong, we can atomically revert a specific
change, instead of loosing the entire refactor.

-- 
balbi


signature.asc
Description: Digital signature


Re: [PATCH 1/7] phy: ti-pipe3: cleanup ti_pipe3_probe()

2015-08-05 Thread Kishon Vijay Abraham I
Hi,

On Tuesday 04 August 2015 09:30 PM, Felipe Balbi wrote:
> On Tue, Aug 04, 2015 at 08:50:40PM +0530, Kishon Vijay Abraham I wrote:
>> No functional change. Add separate functions for pll,
>> clocks and syscon to make ti_pipe3_probe clean.
>>
>> Signed-off-by: Kishon Vijay Abraham I 
> 
> I think this needs to be splitted into smaller patches.

yeah sure.

Thanks
Kishon

> 
> Seems like the very first patch would be to introduce a local struct
> device pointer to be used. Than add each and every new function on their
> own patch. This will help big time making your refactoring a lot clearer
> and, should anything go wrong, we can atomically revert a specific
> change, instead of loosing the entire refactor.
--
To unsubscribe from this list: send the line "unsubscribe linux-omap" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html