Commit c1fc20aa authored by David S. Miller's avatar David S. Miller

Merge branch 'for-davem' of git://gitorious.org/linux-can/linux-can-next

Marc Kleine-Budde says:

====================
this is a pull-request for net-next/master. It consists of two patches
by Fabio Estevam. Them first convert the flexcan driver to use
devm_ioremap_resource(), the second adds return value checking for
clk_prepare_enable().
====================
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parents 8b09be5f aa10181b
...@@ -850,12 +850,17 @@ static int flexcan_open(struct net_device *dev) ...@@ -850,12 +850,17 @@ static int flexcan_open(struct net_device *dev)
struct flexcan_priv *priv = netdev_priv(dev); struct flexcan_priv *priv = netdev_priv(dev);
int err; int err;
clk_prepare_enable(priv->clk_ipg); err = clk_prepare_enable(priv->clk_ipg);
clk_prepare_enable(priv->clk_per); if (err)
return err;
err = clk_prepare_enable(priv->clk_per);
if (err)
goto out_disable_ipg;
err = open_candev(dev); err = open_candev(dev);
if (err) if (err)
goto out; goto out_disable_per;
err = request_irq(dev->irq, flexcan_irq, IRQF_SHARED, dev->name, dev); err = request_irq(dev->irq, flexcan_irq, IRQF_SHARED, dev->name, dev);
if (err) if (err)
...@@ -875,8 +880,9 @@ static int flexcan_open(struct net_device *dev) ...@@ -875,8 +880,9 @@ static int flexcan_open(struct net_device *dev)
out_close: out_close:
close_candev(dev); close_candev(dev);
out: out_disable_per:
clk_disable_unprepare(priv->clk_per); clk_disable_unprepare(priv->clk_per);
out_disable_ipg:
clk_disable_unprepare(priv->clk_ipg); clk_disable_unprepare(priv->clk_ipg);
return err; return err;
...@@ -933,8 +939,13 @@ static int register_flexcandev(struct net_device *dev) ...@@ -933,8 +939,13 @@ static int register_flexcandev(struct net_device *dev)
struct flexcan_regs __iomem *regs = priv->base; struct flexcan_regs __iomem *regs = priv->base;
u32 reg, err; u32 reg, err;
clk_prepare_enable(priv->clk_ipg); err = clk_prepare_enable(priv->clk_ipg);
clk_prepare_enable(priv->clk_per); if (err)
return err;
err = clk_prepare_enable(priv->clk_per);
if (err)
goto out_disable_ipg;
/* select "bus clock", chip must be disabled */ /* select "bus clock", chip must be disabled */
flexcan_chip_disable(priv); flexcan_chip_disable(priv);
...@@ -959,15 +970,16 @@ static int register_flexcandev(struct net_device *dev) ...@@ -959,15 +970,16 @@ static int register_flexcandev(struct net_device *dev)
if (!(reg & FLEXCAN_MCR_FEN)) { if (!(reg & FLEXCAN_MCR_FEN)) {
netdev_err(dev, "Could not enable RX FIFO, unsupported core\n"); netdev_err(dev, "Could not enable RX FIFO, unsupported core\n");
err = -ENODEV; err = -ENODEV;
goto out; goto out_disable_per;
} }
err = register_candev(dev); err = register_candev(dev);
out: out_disable_per:
/* disable core and turn off clocks */ /* disable core and turn off clocks */
flexcan_chip_disable(priv); flexcan_chip_disable(priv);
clk_disable_unprepare(priv->clk_per); clk_disable_unprepare(priv->clk_per);
out_disable_ipg:
clk_disable_unprepare(priv->clk_ipg); clk_disable_unprepare(priv->clk_ipg);
return err; return err;
...@@ -1001,7 +1013,6 @@ static int flexcan_probe(struct platform_device *pdev) ...@@ -1001,7 +1013,6 @@ static int flexcan_probe(struct platform_device *pdev)
struct resource *mem; struct resource *mem;
struct clk *clk_ipg = NULL, *clk_per = NULL; struct clk *clk_ipg = NULL, *clk_per = NULL;
void __iomem *base; void __iomem *base;
resource_size_t mem_size;
int err, irq; int err, irq;
u32 clock_freq = 0; u32 clock_freq = 0;
...@@ -1013,43 +1024,25 @@ static int flexcan_probe(struct platform_device *pdev) ...@@ -1013,43 +1024,25 @@ static int flexcan_probe(struct platform_device *pdev)
clk_ipg = devm_clk_get(&pdev->dev, "ipg"); clk_ipg = devm_clk_get(&pdev->dev, "ipg");
if (IS_ERR(clk_ipg)) { if (IS_ERR(clk_ipg)) {
dev_err(&pdev->dev, "no ipg clock defined\n"); dev_err(&pdev->dev, "no ipg clock defined\n");
err = PTR_ERR(clk_ipg); return PTR_ERR(clk_ipg);
goto failed_clock;
} }
clock_freq = clk_get_rate(clk_ipg); clock_freq = clk_get_rate(clk_ipg);
clk_per = devm_clk_get(&pdev->dev, "per"); clk_per = devm_clk_get(&pdev->dev, "per");
if (IS_ERR(clk_per)) { if (IS_ERR(clk_per)) {
dev_err(&pdev->dev, "no per clock defined\n"); dev_err(&pdev->dev, "no per clock defined\n");
err = PTR_ERR(clk_per); return PTR_ERR(clk_per);
goto failed_clock;
} }
} }
mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
irq = platform_get_irq(pdev, 0); irq = platform_get_irq(pdev, 0);
if (!mem || irq <= 0) { if (irq <= 0)
err = -ENODEV; return -ENODEV;
goto failed_get;
}
mem_size = resource_size(mem); base = devm_ioremap_resource(&pdev->dev, mem);
if (!request_mem_region(mem->start, mem_size, pdev->name)) { if (IS_ERR(base))
err = -EBUSY; return PTR_ERR(base);
goto failed_get;
}
base = ioremap(mem->start, mem_size);
if (!base) {
err = -ENOMEM;
goto failed_map;
}
dev = alloc_candev(sizeof(struct flexcan_priv), 1);
if (!dev) {
err = -ENOMEM;
goto failed_alloc;
}
of_id = of_match_device(flexcan_of_match, &pdev->dev); of_id = of_match_device(flexcan_of_match, &pdev->dev);
if (of_id) { if (of_id) {
...@@ -1058,10 +1051,13 @@ static int flexcan_probe(struct platform_device *pdev) ...@@ -1058,10 +1051,13 @@ static int flexcan_probe(struct platform_device *pdev)
devtype_data = (struct flexcan_devtype_data *) devtype_data = (struct flexcan_devtype_data *)
pdev->id_entry->driver_data; pdev->id_entry->driver_data;
} else { } else {
err = -ENODEV; return -ENODEV;
goto failed_devtype;
} }
dev = alloc_candev(sizeof(struct flexcan_priv), 1);
if (!dev)
return -ENOMEM;
dev->netdev_ops = &flexcan_netdev_ops; dev->netdev_ops = &flexcan_netdev_ops;
dev->irq = irq; dev->irq = irq;
dev->flags |= IFF_ECHO; dev->flags |= IFF_ECHO;
...@@ -1104,28 +1100,15 @@ static int flexcan_probe(struct platform_device *pdev) ...@@ -1104,28 +1100,15 @@ static int flexcan_probe(struct platform_device *pdev)
return 0; return 0;
failed_register: failed_register:
failed_devtype:
free_candev(dev); free_candev(dev);
failed_alloc:
iounmap(base);
failed_map:
release_mem_region(mem->start, mem_size);
failed_get:
failed_clock:
return err; return err;
} }
static int flexcan_remove(struct platform_device *pdev) static int flexcan_remove(struct platform_device *pdev)
{ {
struct net_device *dev = platform_get_drvdata(pdev); struct net_device *dev = platform_get_drvdata(pdev);
struct flexcan_priv *priv = netdev_priv(dev);
struct resource *mem;
unregister_flexcandev(dev); unregister_flexcandev(dev);
iounmap(priv->base);
mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
release_mem_region(mem->start, resource_size(mem));
free_candev(dev); free_candev(dev);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment