spi: spi-ep93xx: use devm_clk_get()
[deliverable/linux.git] / drivers / spi / spi-ep93xx.c
index cad30b8a1d71cb7b573879ae21814c49758419a3..cc2a2405bd1df5a2c28d519a0b2cf20328c0fe5d 100644 (file)
@@ -139,7 +139,6 @@ struct ep93xx_spi {
  * @rate: max rate in hz this chip supports
  * @div_cpsr: cpsr (pre-scaler) divider
  * @div_scr: scr divider
- * @dss: bits per word (4 - 16 bits)
  * @ops: private chip operations
  *
  * This structure is used to store hardware register specific settings for each
@@ -151,35 +150,32 @@ struct ep93xx_spi_chip {
        unsigned long                   rate;
        u8                              div_cpsr;
        u8                              div_scr;
-       u8                              dss;
        struct ep93xx_spi_chip_ops      *ops;
 };
 
 /* converts bits per word to CR0.DSS value */
 #define bits_per_word_to_dss(bpw)      ((bpw) - 1)
 
-static inline void
-ep93xx_spi_write_u8(const struct ep93xx_spi *espi, u16 reg, u8 value)
+static void ep93xx_spi_write_u8(const struct ep93xx_spi *espi,
+                               u16 reg, u8 value)
 {
-       __raw_writeb(value, espi->regs_base + reg);
+       writeb(value, espi->regs_base + reg);
 }
 
-static inline u8
-ep93xx_spi_read_u8(const struct ep93xx_spi *spi, u16 reg)
+static u8 ep93xx_spi_read_u8(const struct ep93xx_spi *spi, u16 reg)
 {
-       return __raw_readb(spi->regs_base + reg);
+       return readb(spi->regs_base + reg);
 }
 
-static inline void
-ep93xx_spi_write_u16(const struct ep93xx_spi *espi, u16 reg, u16 value)
+static void ep93xx_spi_write_u16(const struct ep93xx_spi *espi,
+                                u16 reg, u16 value)
 {
-       __raw_writew(value, espi->regs_base + reg);
+       writew(value, espi->regs_base + reg);
 }
 
-static inline u16
-ep93xx_spi_read_u16(const struct ep93xx_spi *spi, u16 reg)
+static u16 ep93xx_spi_read_u16(const struct ep93xx_spi *spi, u16 reg)
 {
-       return __raw_readw(spi->regs_base + reg);
+       return readw(spi->regs_base + reg);
 }
 
 static int ep93xx_spi_enable(const struct ep93xx_spi *espi)
@@ -331,8 +327,6 @@ static int ep93xx_spi_setup(struct spi_device *spi)
                chip->rate = spi->max_speed_hz;
        }
 
-       chip->dss = bits_per_word_to_dss(spi->bits_per_word);
-
        ep93xx_spi_cs_control(spi, false);
        return 0;
 }
@@ -409,39 +403,34 @@ static void ep93xx_spi_cleanup(struct spi_device *spi)
  * ep93xx_spi_chip_setup() - configures hardware according to given @chip
  * @espi: ep93xx SPI controller struct
  * @chip: chip specific settings
+ * @bits_per_word: transfer bits_per_word
  *
  * This function sets up the actual hardware registers with settings given in
  * @chip. Note that no validation is done so make sure that callers validate
  * settings before calling this.
  */
 static void ep93xx_spi_chip_setup(const struct ep93xx_spi *espi,
-                                 const struct ep93xx_spi_chip *chip)
+                                 const struct ep93xx_spi_chip *chip,
+                                 u8 bits_per_word)
 {
+       u8 dss = bits_per_word_to_dss(bits_per_word);
        u16 cr0;
 
        cr0 = chip->div_scr << SSPCR0_SCR_SHIFT;
        cr0 |= (chip->spi->mode & (SPI_CPHA|SPI_CPOL)) << SSPCR0_MODE_SHIFT;
-       cr0 |= chip->dss;
+       cr0 |= dss;
 
        dev_dbg(&espi->pdev->dev, "setup: mode %d, cpsr %d, scr %d, dss %d\n",
-               chip->spi->mode, chip->div_cpsr, chip->div_scr, chip->dss);
+               chip->spi->mode, chip->div_cpsr, chip->div_scr, dss);
        dev_dbg(&espi->pdev->dev, "setup: cr0 %#x", cr0);
 
        ep93xx_spi_write_u8(espi, SSPCPSR, chip->div_cpsr);
        ep93xx_spi_write_u16(espi, SSPCR0, cr0);
 }
 
-static inline int bits_per_word(const struct ep93xx_spi *espi)
-{
-       struct spi_message *msg = espi->current_msg;
-       struct spi_transfer *t = msg->state;
-
-       return t->bits_per_word;
-}
-
 static void ep93xx_do_write(struct ep93xx_spi *espi, struct spi_transfer *t)
 {
-       if (bits_per_word(espi) > 8) {
+       if (t->bits_per_word > 8) {
                u16 tx_val = 0;
 
                if (t->tx_buf)
@@ -460,7 +449,7 @@ static void ep93xx_do_write(struct ep93xx_spi *espi, struct spi_transfer *t)
 
 static void ep93xx_do_read(struct ep93xx_spi *espi, struct spi_transfer *t)
 {
-       if (bits_per_word(espi) > 8) {
+       if (t->bits_per_word > 8) {
                u16 rx_val;
 
                rx_val = ep93xx_spi_read_u16(espi, SSPDR);
@@ -546,7 +535,7 @@ ep93xx_spi_dma_prepare(struct ep93xx_spi *espi, enum dma_transfer_direction dir)
        size_t len = t->len;
        int i, ret, nents;
 
-       if (bits_per_word(espi) > 8)
+       if (t->bits_per_word > 8)
                buswidth = DMA_SLAVE_BUSWIDTH_2_BYTES;
        else
                buswidth = DMA_SLAVE_BUSWIDTH_1_BYTE;
@@ -708,39 +697,19 @@ static void ep93xx_spi_process_transfer(struct ep93xx_spi *espi,
                                        struct spi_transfer *t)
 {
        struct ep93xx_spi_chip *chip = spi_get_ctldata(msg->spi);
+       int err;
 
        msg->state = t;
 
-       /*
-        * Handle any transfer specific settings if needed. We use
-        * temporary chip settings here and restore original later when
-        * the transfer is finished.
-        */
-       if (t->speed_hz || t->bits_per_word) {
-               struct ep93xx_spi_chip tmp_chip = *chip;
-
-               if (t->speed_hz) {
-                       int err;
-
-                       err = ep93xx_spi_calc_divisors(espi, &tmp_chip,
-                                                      t->speed_hz);
-                       if (err) {
-                               dev_err(&espi->pdev->dev,
-                                       "failed to adjust speed\n");
-                               msg->status = err;
-                               return;
-                       }
-               }
-
-               if (t->bits_per_word)
-                       tmp_chip.dss = bits_per_word_to_dss(t->bits_per_word);
-
-               /*
-                * Set up temporary new hw settings for this transfer.
-                */
-               ep93xx_spi_chip_setup(espi, &tmp_chip);
+       err = ep93xx_spi_calc_divisors(espi, chip, t->speed_hz);
+       if (err) {
+               dev_err(&espi->pdev->dev, "failed to adjust speed\n");
+               msg->status = err;
+               return;
        }
 
+       ep93xx_spi_chip_setup(espi, chip, t->bits_per_word);
+
        espi->rx = 0;
        espi->tx = 0;
 
@@ -783,9 +752,6 @@ static void ep93xx_spi_process_transfer(struct ep93xx_spi *espi,
                        ep93xx_spi_cs_control(msg->spi, true);
                }
        }
-
-       if (t->speed_hz || t->bits_per_word)
-               ep93xx_spi_chip_setup(espi, chip);
 }
 
 /*
@@ -838,10 +804,8 @@ static void ep93xx_spi_process_message(struct ep93xx_spi *espi,
        espi->fifo_level = 0;
 
        /*
-        * Update SPI controller registers according to spi device and assert
-        * the chipselect.
+        * Assert the chipselect.
         */
-       ep93xx_spi_chip_setup(espi, spi_get_ctldata(msg->spi));
        ep93xx_spi_cs_control(msg->spi, true);
 
        list_for_each_entry(t, &msg->transfers, transfer_list) {
@@ -1024,11 +988,21 @@ static int ep93xx_spi_probe(struct platform_device *pdev)
 
        info = pdev->dev.platform_data;
 
+       irq = platform_get_irq(pdev, 0);
+       if (irq < 0) {
+               dev_err(&pdev->dev, "failed to get irq resources\n");
+               return -EBUSY;
+       }
+
+       res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+       if (!res) {
+               dev_err(&pdev->dev, "unable to get iomem resource\n");
+               return -ENODEV;
+       }
+
        master = spi_alloc_master(&pdev->dev, sizeof(*espi));
-       if (!master) {
-               dev_err(&pdev->dev, "failed to allocate spi master\n");
+       if (!master)
                return -ENOMEM;
-       }
 
        master->setup = ep93xx_spi_setup;
        master->transfer = ep93xx_spi_transfer;
@@ -1042,7 +1016,7 @@ static int ep93xx_spi_probe(struct platform_device *pdev)
 
        espi = spi_master_get_devdata(master);
 
-       espi->clk = clk_get(&pdev->dev, NULL);
+       espi->clk = devm_clk_get(&pdev->dev, NULL);
        if (IS_ERR(espi->clk)) {
                dev_err(&pdev->dev, "unable to get spi clock\n");
                error = PTR_ERR(espi->clk);
@@ -1060,33 +1034,19 @@ static int ep93xx_spi_probe(struct platform_device *pdev)
        espi->min_rate = clk_get_rate(espi->clk) / (254 * 256);
        espi->pdev = pdev;
 
-       irq = platform_get_irq(pdev, 0);
-       if (irq < 0) {
-               error = -EBUSY;
-               dev_err(&pdev->dev, "failed to get irq resources\n");
-               goto fail_put_clock;
-       }
-
-       res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
-       if (!res) {
-               dev_err(&pdev->dev, "unable to get iomem resource\n");
-               error = -ENODEV;
-               goto fail_put_clock;
-       }
-
        espi->sspdr_phys = res->start + SSPDR;
 
        espi->regs_base = devm_ioremap_resource(&pdev->dev, res);
        if (IS_ERR(espi->regs_base)) {
                error = PTR_ERR(espi->regs_base);
-               goto fail_put_clock;
+               goto fail_release_master;
        }
 
        error = devm_request_irq(&pdev->dev, irq, ep93xx_spi_interrupt,
                                0, "ep93xx-spi", espi);
        if (error) {
                dev_err(&pdev->dev, "failed to request irq\n");
-               goto fail_put_clock;
+               goto fail_release_master;
        }
 
        if (info->use_dma && ep93xx_spi_setup_dma(espi))
@@ -1120,8 +1080,6 @@ fail_free_queue:
        destroy_workqueue(espi->wq);
 fail_free_dma:
        ep93xx_spi_release_dma(espi);
-fail_put_clock:
-       clk_put(espi->clk);
 fail_release_master:
        spi_master_put(master);
 
@@ -1157,7 +1115,6 @@ static int ep93xx_spi_remove(struct platform_device *pdev)
        spin_unlock_irq(&espi->lock);
 
        ep93xx_spi_release_dma(espi);
-       clk_put(espi->clk);
 
        spi_unregister_master(master);
        return 0;
This page took 0.027013 seconds and 5 git commands to generate.