spi: txx9: Use devm_ioremap_resource()
[linux-block.git] / drivers / spi / spi-txx9.c
index 18c9bb2b5f39108793a32a2b71624f0e59434712..5cfaafc368fcae9c28f73756c5f99313a6f99d7d 100644 (file)
@@ -80,7 +80,6 @@ struct txx9spi {
        void __iomem *membase;
        int baseclk;
        struct clk *clk;
-       u32 max_speed_hz, min_speed_hz;
        int last_chipselect;
        int last_chipselect_val;
 };
@@ -117,9 +116,7 @@ static int txx9spi_setup(struct spi_device *spi)
 {
        struct txx9spi *c = spi_master_get_devdata(spi->master);
 
-       if (!spi->max_speed_hz
-                       || spi->max_speed_hz > c->max_speed_hz
-                       || spi->max_speed_hz < c->min_speed_hz)
+       if (!spi->max_speed_hz)
                return -EINVAL;
 
        if (gpio_direction_output(spi->chip_select,
@@ -309,15 +306,12 @@ static int txx9spi_transfer(struct spi_device *spi, struct spi_message *m)
 
        /* check each transfer's parameters */
        list_for_each_entry(t, &m->transfers, transfer_list) {
-               u32 speed_hz = t->speed_hz ? : spi->max_speed_hz;
                u8 bits_per_word = t->bits_per_word;
 
                if (!t->tx_buf && !t->rx_buf && t->len)
                        return -EINVAL;
                if (t->len & ((bits_per_word >> 3) - 1))
                        return -EINVAL;
-               if (speed_hz < c->min_speed_hz || speed_hz > c->max_speed_hz)
-                       return -EINVAL;
        }
 
        spin_lock_irqsave(&c->lock, flags);
@@ -348,7 +342,7 @@ static int txx9spi_probe(struct platform_device *dev)
        INIT_LIST_HEAD(&c->queue);
        init_waitqueue_head(&c->waitq);
 
-       c->clk = clk_get(&dev->dev, "spi-baseclk");
+       c->clk = devm_clk_get(&dev->dev, "spi-baseclk");
        if (IS_ERR(c->clk)) {
                ret = PTR_ERR(c->clk);
                c->clk = NULL;
@@ -356,22 +350,16 @@ static int txx9spi_probe(struct platform_device *dev)
        }
        ret = clk_enable(c->clk);
        if (ret) {
-               clk_put(c->clk);
                c->clk = NULL;
                goto exit;
        }
        c->baseclk = clk_get_rate(c->clk);
-       c->min_speed_hz = DIV_ROUND_UP(c->baseclk, SPI_MAX_DIVIDER + 1);
-       c->max_speed_hz = c->baseclk / (SPI_MIN_DIVIDER + 1);
+       master->min_speed_hz = DIV_ROUND_UP(c->baseclk, SPI_MAX_DIVIDER + 1);
+       master->max_speed_hz = c->baseclk / (SPI_MIN_DIVIDER + 1);
 
        res = platform_get_resource(dev, IORESOURCE_MEM, 0);
-       if (!res)
-               goto exit_busy;
-       if (!devm_request_mem_region(&dev->dev, res->start, resource_size(res),
-                                    "spi_txx9"))
-               goto exit_busy;
-       c->membase = devm_ioremap(&dev->dev, res->start, resource_size(res));
-       if (!c->membase)
+       c->membase = devm_ioremap_resource(&dev->dev, res);
+       if (IS_ERR(c->membase))
                goto exit_busy;
 
        /* enter config mode */
@@ -415,10 +403,8 @@ exit_busy:
 exit:
        if (c->workqueue)
                destroy_workqueue(c->workqueue);
-       if (c->clk) {
+       if (c->clk)
                clk_disable(c->clk);
-               clk_put(c->clk);
-       }
        spi_master_put(master);
        return ret;
 }
@@ -430,7 +416,6 @@ static int txx9spi_remove(struct platform_device *dev)
 
        destroy_workqueue(c->workqueue);
        clk_disable(c->clk);
-       clk_put(c->clk);
        return 0;
 }