aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNicolas Ferre <nicolas.ferre@atmel.com>2015-03-31 09:02:03 -0400
committerDavid S. Miller <davem@davemloft.net>2015-03-31 16:51:17 -0400
commitc69618b3e4f220f4990b91596d40ea3c4cdc938a (patch)
tree08ed269c3126186d5fb9bb2c0bdfecfe5f0435f8
parentad78347f06581e445790343bc1d9e34375f11fd4 (diff)
net/macb: fix probe sequence to setup clocks earlier
As accessing the peripheral registers need the clocks to be set, we have to enable them as soon as possible. Their configuration depend on the type of device used and determined by the DT compatible string. That lead to add another initialization function in the DT configuration structure. As the device private structure length depend on an information read in the registers, we have to store the clock pointers in temporary variables before feeding the structure fields. Signed-off-by: Nicolas Ferre <nicolas.ferre@atmel.com> Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r--drivers/net/ethernet/cadence/macb.c169
-rw-r--r--drivers/net/ethernet/cadence/macb.h2
2 files changed, 104 insertions, 67 deletions
diff --git a/drivers/net/ethernet/cadence/macb.c b/drivers/net/ethernet/cadence/macb.c
index e27bc6964402..205f4b86d9da 100644
--- a/drivers/net/ethernet/cadence/macb.c
+++ b/drivers/net/ethernet/cadence/macb.c
@@ -2184,51 +2184,67 @@ static void macb_probe_queues(void __iomem *mem,
2184 (*num_queues)++; 2184 (*num_queues)++;
2185} 2185}
2186 2186
2187static int macb_init(struct platform_device *pdev) 2187static int macb_clk_init(struct platform_device *pdev, struct clk **pclk,
2188 struct clk **hclk, struct clk **tx_clk)
2188{ 2189{
2189 struct net_device *dev = platform_get_drvdata(pdev);
2190 unsigned int hw_q, q;
2191 struct macb *bp = netdev_priv(dev);
2192 struct macb_queue *queue;
2193 int err; 2190 int err;
2194 u32 val;
2195 2191
2196 bp->pclk = devm_clk_get(&pdev->dev, "pclk"); 2192 *pclk = devm_clk_get(&pdev->dev, "pclk");
2197 if (IS_ERR(bp->pclk)) { 2193 if (IS_ERR(*pclk)) {
2198 err = PTR_ERR(bp->pclk); 2194 err = PTR_ERR(*pclk);
2199 dev_err(&pdev->dev, "failed to get macb_clk (%u)\n", err); 2195 dev_err(&pdev->dev, "failed to get macb_clk (%u)\n", err);
2200 return err; 2196 return err;
2201 } 2197 }
2202 2198
2203 bp->hclk = devm_clk_get(&pdev->dev, "hclk"); 2199 *hclk = devm_clk_get(&pdev->dev, "hclk");
2204 if (IS_ERR(bp->hclk)) { 2200 if (IS_ERR(*hclk)) {
2205 err = PTR_ERR(bp->hclk); 2201 err = PTR_ERR(*hclk);
2206 dev_err(&pdev->dev, "failed to get hclk (%u)\n", err); 2202 dev_err(&pdev->dev, "failed to get hclk (%u)\n", err);
2207 return err; 2203 return err;
2208 } 2204 }
2209 2205
2210 bp->tx_clk = devm_clk_get(&pdev->dev, "tx_clk"); 2206 *tx_clk = devm_clk_get(&pdev->dev, "tx_clk");
2211 if (IS_ERR(bp->tx_clk)) 2207 if (IS_ERR(*tx_clk))
2212 bp->tx_clk = NULL; 2208 *tx_clk = NULL;
2213 2209
2214 err = clk_prepare_enable(bp->pclk); 2210 err = clk_prepare_enable(*pclk);
2215 if (err) { 2211 if (err) {
2216 dev_err(&pdev->dev, "failed to enable pclk (%u)\n", err); 2212 dev_err(&pdev->dev, "failed to enable pclk (%u)\n", err);
2217 return err; 2213 return err;
2218 } 2214 }
2219 2215
2220 err = clk_prepare_enable(bp->hclk); 2216 err = clk_prepare_enable(*hclk);
2221 if (err) { 2217 if (err) {
2222 dev_err(&pdev->dev, "failed to enable hclk (%u)\n", err); 2218 dev_err(&pdev->dev, "failed to enable hclk (%u)\n", err);
2223 goto err_disable_pclk; 2219 goto err_disable_pclk;
2224 } 2220 }
2225 2221
2226 err = clk_prepare_enable(bp->tx_clk); 2222 err = clk_prepare_enable(*tx_clk);
2227 if (err) { 2223 if (err) {
2228 dev_err(&pdev->dev, "failed to enable tx_clk (%u)\n", err); 2224 dev_err(&pdev->dev, "failed to enable tx_clk (%u)\n", err);
2229 goto err_disable_hclk; 2225 goto err_disable_hclk;
2230 } 2226 }
2231 2227
2228 return 0;
2229
2230err_disable_hclk:
2231 clk_disable_unprepare(*hclk);
2232
2233err_disable_pclk:
2234 clk_disable_unprepare(*pclk);
2235
2236 return err;
2237}
2238
2239static int macb_init(struct platform_device *pdev)
2240{
2241 struct net_device *dev = platform_get_drvdata(pdev);
2242 unsigned int hw_q, q;
2243 struct macb *bp = netdev_priv(dev);
2244 struct macb_queue *queue;
2245 int err;
2246 u32 val;
2247
2232 /* set the queue register mapping once for all: queue0 has a special 2248 /* set the queue register mapping once for all: queue0 has a special
2233 * register mapping but we don't want to test the queue index then 2249 * register mapping but we don't want to test the queue index then
2234 * compute the corresponding register offset at run time. 2250 * compute the corresponding register offset at run time.
@@ -2266,7 +2282,7 @@ static int macb_init(struct platform_device *pdev)
2266 dev_err(&pdev->dev, 2282 dev_err(&pdev->dev,
2267 "Unable to request IRQ %d (error %d)\n", 2283 "Unable to request IRQ %d (error %d)\n",
2268 queue->irq, err); 2284 queue->irq, err);
2269 goto err_disable_tx_clk; 2285 return err;
2270 } 2286 }
2271 2287
2272 INIT_WORK(&queue->tx_error_task, macb_tx_error_task); 2288 INIT_WORK(&queue->tx_error_task, macb_tx_error_task);
@@ -2322,17 +2338,6 @@ static int macb_init(struct platform_device *pdev)
2322 macb_writel(bp, NCFGR, val); 2338 macb_writel(bp, NCFGR, val);
2323 2339
2324 return 0; 2340 return 0;
2325
2326err_disable_tx_clk:
2327 clk_disable_unprepare(bp->tx_clk);
2328
2329err_disable_hclk:
2330 clk_disable_unprepare(bp->hclk);
2331
2332err_disable_pclk:
2333 clk_disable_unprepare(bp->pclk);
2334
2335 return err;
2336} 2341}
2337 2342
2338#if defined(CONFIG_OF) 2343#if defined(CONFIG_OF)
@@ -2600,30 +2605,41 @@ static const struct net_device_ops at91ether_netdev_ops = {
2600#endif 2605#endif
2601}; 2606};
2602 2607
2603static int at91ether_init(struct platform_device *pdev) 2608static int at91ether_clk_init(struct platform_device *pdev, struct clk **pclk,
2609 struct clk **hclk, struct clk **tx_clk)
2604{ 2610{
2605 struct net_device *dev = platform_get_drvdata(pdev);
2606 struct macb *bp = netdev_priv(dev);
2607 int err; 2611 int err;
2608 u32 reg;
2609 2612
2610 bp->pclk = devm_clk_get(&pdev->dev, "ether_clk"); 2613 *hclk = NULL;
2611 if (IS_ERR(bp->pclk)) 2614 *tx_clk = NULL;
2612 return PTR_ERR(bp->pclk); 2615
2616 *pclk = devm_clk_get(&pdev->dev, "ether_clk");
2617 if (IS_ERR(*pclk))
2618 return PTR_ERR(*pclk);
2613 2619
2614 err = clk_prepare_enable(bp->pclk); 2620 err = clk_prepare_enable(*pclk);
2615 if (err) { 2621 if (err) {
2616 dev_err(&pdev->dev, "failed to enable pclk (%u)\n", err); 2622 dev_err(&pdev->dev, "failed to enable pclk (%u)\n", err);
2617 return err; 2623 return err;
2618 } 2624 }
2619 2625
2626 return 0;
2627}
2628
2629static int at91ether_init(struct platform_device *pdev)
2630{
2631 struct net_device *dev = platform_get_drvdata(pdev);
2632 struct macb *bp = netdev_priv(dev);
2633 int err;
2634 u32 reg;
2635
2620 dev->netdev_ops = &at91ether_netdev_ops; 2636 dev->netdev_ops = &at91ether_netdev_ops;
2621 dev->ethtool_ops = &macb_ethtool_ops; 2637 dev->ethtool_ops = &macb_ethtool_ops;
2622 2638
2623 err = devm_request_irq(&pdev->dev, dev->irq, at91ether_interrupt, 2639 err = devm_request_irq(&pdev->dev, dev->irq, at91ether_interrupt,
2624 0, dev->name, dev); 2640 0, dev->name, dev);
2625 if (err) 2641 if (err)
2626 goto err_disable_clk; 2642 return err;
2627 2643
2628 macb_writel(bp, NCR, 0); 2644 macb_writel(bp, NCR, 0);
2629 2645
@@ -2634,37 +2650,37 @@ static int at91ether_init(struct platform_device *pdev)
2634 macb_writel(bp, NCFGR, reg); 2650 macb_writel(bp, NCFGR, reg);
2635 2651
2636 return 0; 2652 return 0;
2637
2638err_disable_clk:
2639 clk_disable_unprepare(bp->pclk);
2640
2641 return err;
2642} 2653}
2643 2654
2644static const struct macb_config at91sam9260_config = { 2655static const struct macb_config at91sam9260_config = {
2645 .caps = MACB_CAPS_USRIO_HAS_CLKEN | MACB_CAPS_USRIO_DEFAULT_IS_MII, 2656 .caps = MACB_CAPS_USRIO_HAS_CLKEN | MACB_CAPS_USRIO_DEFAULT_IS_MII,
2657 .clk_init = macb_clk_init,
2646 .init = macb_init, 2658 .init = macb_init,
2647}; 2659};
2648 2660
2649static const struct macb_config pc302gem_config = { 2661static const struct macb_config pc302gem_config = {
2650 .caps = MACB_CAPS_SG_DISABLED | MACB_CAPS_GIGABIT_MODE_AVAILABLE, 2662 .caps = MACB_CAPS_SG_DISABLED | MACB_CAPS_GIGABIT_MODE_AVAILABLE,
2651 .dma_burst_length = 16, 2663 .dma_burst_length = 16,
2664 .clk_init = macb_clk_init,
2652 .init = macb_init, 2665 .init = macb_init,
2653}; 2666};
2654 2667
2655static const struct macb_config sama5d3_config = { 2668static const struct macb_config sama5d3_config = {
2656 .caps = MACB_CAPS_SG_DISABLED | MACB_CAPS_GIGABIT_MODE_AVAILABLE, 2669 .caps = MACB_CAPS_SG_DISABLED | MACB_CAPS_GIGABIT_MODE_AVAILABLE,
2657 .dma_burst_length = 16, 2670 .dma_burst_length = 16,
2671 .clk_init = macb_clk_init,
2658 .init = macb_init, 2672 .init = macb_init,
2659}; 2673};
2660 2674
2661static const struct macb_config sama5d4_config = { 2675static const struct macb_config sama5d4_config = {
2662 .caps = 0, 2676 .caps = 0,
2663 .dma_burst_length = 4, 2677 .dma_burst_length = 4,
2678 .clk_init = macb_clk_init,
2664 .init = macb_init, 2679 .init = macb_init,
2665}; 2680};
2666 2681
2667static const struct macb_config emac_config = { 2682static const struct macb_config emac_config = {
2683 .clk_init = at91ether_clk_init,
2668 .init = at91ether_init, 2684 .init = at91ether_init,
2669}; 2685};
2670 2686
@@ -2685,9 +2701,13 @@ MODULE_DEVICE_TABLE(of, macb_dt_ids);
2685 2701
2686static int macb_probe(struct platform_device *pdev) 2702static int macb_probe(struct platform_device *pdev)
2687{ 2703{
2704 int (*clk_init)(struct platform_device *, struct clk **,
2705 struct clk **, struct clk **)
2706 = macb_clk_init;
2688 int (*init)(struct platform_device *) = macb_init; 2707 int (*init)(struct platform_device *) = macb_init;
2689 struct device_node *np = pdev->dev.of_node; 2708 struct device_node *np = pdev->dev.of_node;
2690 const struct macb_config *macb_config = NULL; 2709 const struct macb_config *macb_config = NULL;
2710 struct clk *pclk, *hclk, *tx_clk;
2691 unsigned int queue_mask, num_queues; 2711 unsigned int queue_mask, num_queues;
2692 struct macb_platform_data *pdata; 2712 struct macb_platform_data *pdata;
2693 struct phy_device *phydev; 2713 struct phy_device *phydev;
@@ -2698,15 +2718,34 @@ static int macb_probe(struct platform_device *pdev)
2698 struct macb *bp; 2718 struct macb *bp;
2699 int err; 2719 int err;
2700 2720
2721 if (np) {
2722 const struct of_device_id *match;
2723
2724 match = of_match_node(macb_dt_ids, np);
2725 if (match && match->data) {
2726 macb_config = match->data;
2727 clk_init = macb_config->clk_init;
2728 init = macb_config->init;
2729 }
2730 }
2731
2732 err = clk_init(pdev, &pclk, &hclk, &tx_clk);
2733 if (err)
2734 return err;
2735
2701 regs = platform_get_resource(pdev, IORESOURCE_MEM, 0); 2736 regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
2702 mem = devm_ioremap_resource(&pdev->dev, regs); 2737 mem = devm_ioremap_resource(&pdev->dev, regs);
2703 if (IS_ERR(mem)) 2738 if (IS_ERR(mem)) {
2704 return PTR_ERR(mem); 2739 err = PTR_ERR(mem);
2740 goto err_disable_clocks;
2741 }
2705 2742
2706 macb_probe_queues(mem, &queue_mask, &num_queues); 2743 macb_probe_queues(mem, &queue_mask, &num_queues);
2707 dev = alloc_etherdev_mq(sizeof(*bp), num_queues); 2744 dev = alloc_etherdev_mq(sizeof(*bp), num_queues);
2708 if (!dev) 2745 if (!dev) {
2709 return -ENOMEM; 2746 err = -ENOMEM;
2747 goto err_disable_clocks;
2748 }
2710 2749
2711 dev->base_addr = regs->start; 2750 dev->base_addr = regs->start;
2712 2751
@@ -2718,27 +2757,23 @@ static int macb_probe(struct platform_device *pdev)
2718 bp->regs = mem; 2757 bp->regs = mem;
2719 bp->num_queues = num_queues; 2758 bp->num_queues = num_queues;
2720 bp->queue_mask = queue_mask; 2759 bp->queue_mask = queue_mask;
2760 if (macb_config)
2761 bp->dma_burst_length = macb_config->dma_burst_length;
2762 bp->pclk = pclk;
2763 bp->hclk = hclk;
2764 bp->tx_clk = tx_clk;
2721 spin_lock_init(&bp->lock); 2765 spin_lock_init(&bp->lock);
2722 2766
2723 if (np) {
2724 const struct of_device_id *match;
2725
2726 match = of_match_node(macb_dt_ids, np);
2727 if (match && match->data) {
2728 macb_config = match->data;
2729 bp->dma_burst_length = macb_config->dma_burst_length;
2730 init = macb_config->init;
2731 }
2732 }
2733
2734 /* setup capabilities */ 2767 /* setup capabilities */
2735 macb_configure_caps(bp, macb_config); 2768 macb_configure_caps(bp, macb_config);
2736 2769
2737 platform_set_drvdata(pdev, dev); 2770 platform_set_drvdata(pdev, dev);
2738 2771
2739 dev->irq = platform_get_irq(pdev, 0); 2772 dev->irq = platform_get_irq(pdev, 0);
2740 if (dev->irq < 0) 2773 if (dev->irq < 0) {
2741 return dev->irq; 2774 err = dev->irq;
2775 goto err_disable_clocks;
2776 }
2742 2777
2743 mac = of_get_mac_address(np); 2778 mac = of_get_mac_address(np);
2744 if (mac) 2779 if (mac)
@@ -2765,7 +2800,7 @@ static int macb_probe(struct platform_device *pdev)
2765 err = register_netdev(dev); 2800 err = register_netdev(dev);
2766 if (err) { 2801 if (err) {
2767 dev_err(&pdev->dev, "Cannot register net device, aborting.\n"); 2802 dev_err(&pdev->dev, "Cannot register net device, aborting.\n");
2768 goto err_disable_clocks; 2803 goto err_out_unregister_netdev;
2769 } 2804 }
2770 2805
2771 err = macb_mii_init(bp); 2806 err = macb_mii_init(bp);
@@ -2787,14 +2822,14 @@ static int macb_probe(struct platform_device *pdev)
2787err_out_unregister_netdev: 2822err_out_unregister_netdev:
2788 unregister_netdev(dev); 2823 unregister_netdev(dev);
2789 2824
2790err_disable_clocks:
2791 clk_disable_unprepare(bp->tx_clk);
2792 clk_disable_unprepare(bp->hclk);
2793 clk_disable_unprepare(bp->pclk);
2794
2795err_out_free_netdev: 2825err_out_free_netdev:
2796 free_netdev(dev); 2826 free_netdev(dev);
2797 2827
2828err_disable_clocks:
2829 clk_disable_unprepare(tx_clk);
2830 clk_disable_unprepare(hclk);
2831 clk_disable_unprepare(pclk);
2832
2798 return err; 2833 return err;
2799} 2834}
2800 2835
diff --git a/drivers/net/ethernet/cadence/macb.h b/drivers/net/ethernet/cadence/macb.h
index 0b6afac91bfe..5f9950e84c5e 100644
--- a/drivers/net/ethernet/cadence/macb.h
+++ b/drivers/net/ethernet/cadence/macb.h
@@ -754,6 +754,8 @@ struct macb_or_gem_ops {
754struct macb_config { 754struct macb_config {
755 u32 caps; 755 u32 caps;
756 unsigned int dma_burst_length; 756 unsigned int dma_burst_length;
757 int (*clk_init)(struct platform_device *pdev, struct clk **pclk,
758 struct clk **hclk, struct clk **tx_clk);
757 int (*init)(struct platform_device *pdev); 759 int (*init)(struct platform_device *pdev);
758}; 760};
759 761