ARM: Orion: SPI: Add clk/clkdev support.
authorAndrew Lunn <andrew@lunn.ch>
Fri, 6 Apr 2012 15:17:26 +0000 (17:17 +0200)
committerMike Turquette <mturquette@linaro.org>
Tue, 8 May 2012 23:33:55 +0000 (16:33 -0700)
Remove now redundant tclk from SPI platform data. This makes the platform
data empty, so remove it.

Signed-off-by: Andrew Lunn <andrew@lunn.ch>
Tested-by: Jamie Lentin <jm@lentin.co.uk>
Signed-off-by: Mike Turquette <mturquette@linaro.org>
15 files changed:
arch/arm/mach-dove/common.c
arch/arm/mach-dove/dove-db-setup.c
arch/arm/mach-kirkwood/board-dreamplug.c
arch/arm/mach-kirkwood/common.c
arch/arm/mach-kirkwood/mv88f6281gtw_ge-setup.c
arch/arm/mach-kirkwood/rd88f6192-nas-setup.c
arch/arm/mach-kirkwood/t5325-setup.c
arch/arm/mach-kirkwood/tsx1x-common.c
arch/arm/mach-mv78xx0/common.c
arch/arm/mach-orion5x/common.c
arch/arm/mach-orion5x/rd88f6183ap-ge-setup.c
arch/arm/plat-orion/common.c
arch/arm/plat-orion/include/plat/common.h
drivers/spi/spi-orion.c
include/linux/spi/orion_spi.h [deleted file]

index 63fe6e612e98896583ea0643cf47f690b7921ca8..da5b4047464dbfefde5fec69d1a0c5501b85b9cc 100644 (file)
@@ -76,6 +76,8 @@ static void __init clk_init(void)
 {
        tclk = clk_register_fixed_rate(NULL, "tclk", NULL, CLK_IS_ROOT,
                                       get_tclk());
+
+       orion_clkdev_init(tclk);
 }
 
 /*****************************************************************************
@@ -162,12 +164,12 @@ void __init dove_uart3_init(void)
  ****************************************************************************/
 void __init dove_spi0_init(void)
 {
-       orion_spi_init(DOVE_SPI0_PHYS_BASE, get_tclk());
+       orion_spi_init(DOVE_SPI0_PHYS_BASE);
 }
 
 void __init dove_spi1_init(void)
 {
-       orion_spi_1_init(DOVE_SPI1_PHYS_BASE, get_tclk());
+       orion_spi_1_init(DOVE_SPI1_PHYS_BASE);
 }
 
 /*****************************************************************************
index ea77ae430b2d018f034f536471c306cf2a68db1b..bc2867f113460ab810be4d70b6343134abc95c0d 100644 (file)
@@ -20,7 +20,6 @@
 #include <linux/i2c.h>
 #include <linux/pci.h>
 #include <linux/spi/spi.h>
-#include <linux/spi/orion_spi.h>
 #include <linux/spi/flash.h>
 #include <linux/gpio.h>
 #include <asm/mach-types.h>
index 985453994dd3940d796df8d9bf7458e41298f87f..55e357ab2923e95db3848f177a83bb713f1c7baa 100644 (file)
@@ -27,7 +27,6 @@
 #include <linux/mtd/physmap.h>
 #include <linux/spi/flash.h>
 #include <linux/spi/spi.h>
-#include <linux/spi/orion_spi.h>
 #include <asm/mach-types.h>
 #include <asm/mach/arch.h>
 #include <asm/mach/map.h>
index 57b8d1ef3093aadea8347033f319f4cf99cf5171..476e0b941db7c74f3968244f362f1d9521e4ecd6 100644 (file)
@@ -86,10 +86,12 @@ static struct clk __init *kirkwood_register_gate(const char *name, u8 bit_idx)
 
 void __init kirkwood_clk_init(void)
 {
+       struct clk *runit;
+
        tclk = clk_register_fixed_rate(NULL, "tclk", NULL,
                                       CLK_IS_ROOT, kirkwood_tclk);
 
-       kirkwood_register_gate("runit",  CGC_BIT_RUNIT);
+       runit = kirkwood_register_gate("runit",  CGC_BIT_RUNIT);
        kirkwood_register_gate("ge0",    CGC_BIT_GE0);
        kirkwood_register_gate("ge1",    CGC_BIT_GE1);
        kirkwood_register_gate("sata0",  CGC_BIT_SATA0);
@@ -104,6 +106,10 @@ void __init kirkwood_clk_init(void)
        kirkwood_register_gate("audio",  CGC_BIT_AUDIO);
        kirkwood_register_gate("tdm",    CGC_BIT_TDM);
        kirkwood_register_gate("tsu",    CGC_BIT_TSU);
+
+       /* clkdev entries, mapping clks to devices */
+       orion_clkdev_add(NULL, "orion_spi.0", runit);
+       orion_clkdev_add(NULL, "orion_spi.1", runit);
 }
 
 /*****************************************************************************
@@ -270,7 +276,7 @@ void __init kirkwood_sdio_init(struct mvsdio_platform_data *mvsdio_data)
 void __init kirkwood_spi_init()
 {
        kirkwood_clk_ctrl |= CGC_RUNIT;
-       orion_spi_init(SPI_PHYS_BASE, kirkwood_tclk);
+       orion_spi_init(SPI_PHYS_BASE);
 }
 
 
index 85f6169c24846178570cb1cc079a12dd209fd9b3..6d8364a97810f83e897e1515be37c4ade616d45e 100644 (file)
@@ -23,7 +23,6 @@
 #include <linux/gpio_keys.h>
 #include <linux/spi/flash.h>
 #include <linux/spi/spi.h>
-#include <linux/spi/orion_spi.h>
 #include <net/dsa.h>
 #include <asm/mach-types.h>
 #include <asm/mach/arch.h>
index fd2c9c8b6831a1d0ae808bef994e691a9a38c721..f742a66a7045478a8428c35e8bc65ef65b14e23a 100644 (file)
@@ -16,7 +16,6 @@
 #include <linux/gpio.h>
 #include <linux/spi/flash.h>
 #include <linux/spi/spi.h>
-#include <linux/spi/orion_spi.h>
 #include <asm/mach-types.h>
 #include <asm/mach/arch.h>
 #include <mach/kirkwood.h>
index f9d2a11b7f9649468c26a882323df785e27783a0..bad738e440445d4d31ebc038a4cc812f64397983 100644 (file)
@@ -16,7 +16,6 @@
 #include <linux/mtd/physmap.h>
 #include <linux/spi/flash.h>
 #include <linux/spi/spi.h>
-#include <linux/spi/orion_spi.h>
 #include <linux/i2c.h>
 #include <linux/mv643xx_eth.h>
 #include <linux/ata_platform.h>
index 24294b2bc4690365b8092d6ee702738cab1c3cc5..8943ede29b4458b14217aebd0873b896eaa15df8 100644 (file)
@@ -4,7 +4,6 @@
 #include <linux/mtd/physmap.h>
 #include <linux/spi/flash.h>
 #include <linux/spi/spi.h>
-#include <linux/spi/orion_spi.h>
 #include <linux/serial_reg.h>
 #include <mach/kirkwood.h>
 #include "common.h"
index 73733207f5a9f7fb35476c3a371b7ad6c69974c5..4c24b46520aa8d5c9482b808091988aba7052a1f 100644 (file)
@@ -175,6 +175,8 @@ static void __init clk_init(void)
 {
        tclk = clk_register_fixed_rate(NULL, "tclk", NULL, CLK_IS_ROOT,
                                       get_tclk());
+
+       orion_clkdev_init(tclk);
 }
 
 /*****************************************************************************
index 81660522c6b45dd369c91b64ff1f99e8047b4e74..2ef82e2f511da78c5b4d8976228daacb67941e2c 100644 (file)
@@ -79,6 +79,8 @@ static void __init clk_init(void)
 {
        tclk = clk_register_fixed_rate(NULL, "tclk", NULL, CLK_IS_ROOT,
                                       orion5x_tclk);
+
+       orion_clkdev_init(tclk);
 }
 
 /*****************************************************************************
@@ -144,7 +146,7 @@ void __init orion5x_sata_init(struct mv_sata_platform_data *sata_data)
  ****************************************************************************/
 void __init orion5x_spi_init()
 {
-       orion_spi_init(SPI_PHYS_BASE, orion5x_tclk);
+       orion_spi_init(SPI_PHYS_BASE);
 }
 
 
index 2c5fab00d205c9414ba44483b9f896c9864e1509..7b97a9a211eda86ff23d443a585862c14f599bef 100644 (file)
@@ -16,7 +16,6 @@
 #include <linux/mtd/physmap.h>
 #include <linux/mv643xx_eth.h>
 #include <linux/spi/spi.h>
-#include <linux/spi/orion_spi.h>
 #include <linux/spi/flash.h>
 #include <linux/ethtool.h>
 #include <net/dsa.h>
index 4fdd2e7e74a1bcd9022d0d9c5141682dc2ff07d3..bbe50a94871065ed27a78e9ea8b4f4db8cd2e2fc 100644 (file)
 #include <linux/mv643xx_eth.h>
 #include <linux/mv643xx_i2c.h>
 #include <net/dsa.h>
-#include <linux/spi/orion_spi.h>
 #include <plat/orion_wdt.h>
 #include <plat/mv_xor.h>
 #include <plat/ehci-orion.h>
 #include <mach/bridge-regs.h>
 
+/* Create a clkdev entry for a given device/clk */
+void __init orion_clkdev_add(const char *con_id, const char *dev_id,
+                            struct clk *clk)
+{
+       struct clk_lookup *cl;
+
+       cl = clkdev_alloc(clk, con_id, dev_id);
+       if (cl)
+               clkdev_add(cl);
+}
+
+/* Create clkdev entries for all orion platforms except kirkwood.
+   Kirkwood has gated clocks for some of its peripherals, so creates
+   its own clkdev entries. For all the other orion devices, create
+   clkdev entries to the tclk. */
+void __init orion_clkdev_init(struct clk *tclk)
+{
+       orion_clkdev_add(NULL, "orion_spi.0", tclk);
+       orion_clkdev_add(NULL, "orion_spi.1", tclk);
+}
+
 /* Fill in the resources structure and link it into the platform
    device structure. There is always a memory region, and nearly
    always an interrupt.*/
@@ -523,44 +543,32 @@ void __init orion_i2c_1_init(unsigned long mapbase,
 /*****************************************************************************
  * SPI
  ****************************************************************************/
-static struct orion_spi_info orion_spi_plat_data;
 static struct resource orion_spi_resources;
 
 static struct platform_device orion_spi = {
        .name           = "orion_spi",
        .id             = 0,
-       .dev            = {
-               .platform_data  = &orion_spi_plat_data,
-       },
 };
 
-static struct orion_spi_info orion_spi_1_plat_data;
 static struct resource orion_spi_1_resources;
 
 static struct platform_device orion_spi_1 = {
        .name           = "orion_spi",
        .id             = 1,
-       .dev            = {
-               .platform_data  = &orion_spi_1_plat_data,
-       },
 };
 
 /* Note: The SPI silicon core does have interrupts. However the
  * current Linux software driver does not use interrupts. */
 
-void __init orion_spi_init(unsigned long mapbase,
-                          unsigned long tclk)
+void __init orion_spi_init(unsigned long mapbase)
 {
-       orion_spi_plat_data.tclk = tclk;
        fill_resources(&orion_spi, &orion_spi_resources,
                       mapbase, SZ_512 - 1, NO_IRQ);
        platform_device_register(&orion_spi);
 }
 
-void __init orion_spi_1_init(unsigned long mapbase,
-                            unsigned long tclk)
+void __init orion_spi_1_init(unsigned long mapbase)
 {
-       orion_spi_1_plat_data.tclk = tclk;
        fill_resources(&orion_spi_1, &orion_spi_1_resources,
                       mapbase, SZ_512 - 1, NO_IRQ);
        platform_device_register(&orion_spi_1);
index a7fa005a5a0eb335e6b0267a090664a5a9d86ae7..d188a1aa6f56a0fe2cc691e82d0a486d5dbf549f 100644 (file)
@@ -70,11 +70,9 @@ void __init orion_i2c_1_init(unsigned long mapbase,
                             unsigned long irq,
                             unsigned long freq_m);
 
-void __init orion_spi_init(unsigned long mapbase,
-                          unsigned long tclk);
+void __init orion_spi_init(unsigned long mapbase);
 
-void __init orion_spi_1_init(unsigned long mapbase,
-                            unsigned long tclk);
+void __init orion_spi_1_init(unsigned long mapbase);
 
 void __init orion_wdt_init(unsigned long tclk);
 
@@ -106,4 +104,9 @@ void __init orion_crypto_init(unsigned long mapbase,
                              unsigned long srambase,
                              unsigned long sram_size,
                              unsigned long irq);
+
+void __init orion_clkdev_add(const char *con_id, const char *dev_id,
+                            struct clk *clk);
+
+void __init orion_clkdev_init(struct clk *tclk);
 #endif
index e496f799b7a9053326a1f68f82a67b49a36eaaea..dfd04e91fa6da35d14c89f3aeb874935d41da339 100644 (file)
@@ -16,8 +16,8 @@
 #include <linux/err.h>
 #include <linux/io.h>
 #include <linux/spi/spi.h>
-#include <linux/spi/orion_spi.h>
 #include <linux/module.h>
+#include <linux/clk.h>
 #include <asm/unaligned.h>
 
 #define DRIVER_NAME                    "orion_spi"
@@ -46,6 +46,7 @@ struct orion_spi {
        unsigned int            max_speed;
        unsigned int            min_speed;
        struct orion_spi_info   *spi_info;
+       struct clk              *clk;
 };
 
 static struct workqueue_struct *orion_spi_wq;
@@ -104,7 +105,7 @@ static int orion_spi_baudrate_set(struct spi_device *spi, unsigned int speed)
 
        orion_spi = spi_master_get_devdata(spi->master);
 
-       tclk_hz = orion_spi->spi_info->tclk;
+       tclk_hz = clk_get_rate(orion_spi->clk);
 
        /*
         * the supported rates are: 4,6,8...30
@@ -450,6 +451,7 @@ static int __init orion_spi_probe(struct platform_device *pdev)
        struct orion_spi *spi;
        struct resource *r;
        struct orion_spi_info *spi_info;
+       unsigned long tclk_hz;
        int status = 0;
 
        spi_info = pdev->dev.platform_data;
@@ -476,19 +478,28 @@ static int __init orion_spi_probe(struct platform_device *pdev)
        spi->master = master;
        spi->spi_info = spi_info;
 
-       spi->max_speed = DIV_ROUND_UP(spi_info->tclk, 4);
-       spi->min_speed = DIV_ROUND_UP(spi_info->tclk, 30);
+       spi->clk = clk_get(&pdev->dev, NULL);
+       if (IS_ERR(spi->clk)) {
+               status = PTR_ERR(spi->clk);
+               goto out;
+       }
+
+       clk_prepare(spi->clk);
+       clk_enable(spi->clk);
+       tclk_hz = clk_get_rate(spi->clk);
+       spi->max_speed = DIV_ROUND_UP(tclk_hz, 4);
+       spi->min_speed = DIV_ROUND_UP(tclk_hz, 30);
 
        r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
        if (r == NULL) {
                status = -ENODEV;
-               goto out;
+               goto out_rel_clk;
        }
 
        if (!request_mem_region(r->start, resource_size(r),
                                dev_name(&pdev->dev))) {
                status = -EBUSY;
-               goto out;
+               goto out_rel_clk;
        }
        spi->base = ioremap(r->start, SZ_1K);
 
@@ -508,7 +519,9 @@ static int __init orion_spi_probe(struct platform_device *pdev)
 
 out_rel_mem:
        release_mem_region(r->start, resource_size(r));
-
+out_rel_clk:
+       clk_disable_unprepare(spi->clk);
+       clk_put(spi->clk);
 out:
        spi_master_put(master);
        return status;
@@ -526,6 +539,9 @@ static int __exit orion_spi_remove(struct platform_device *pdev)
 
        cancel_work_sync(&spi->work);
 
+       clk_disable_unprepare(spi->clk);
+       clk_put(spi->clk);
+
        r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
        release_mem_region(r->start, resource_size(r));
 
diff --git a/include/linux/spi/orion_spi.h b/include/linux/spi/orion_spi.h
deleted file mode 100644 (file)
index b4d9fa6..0000000
+++ /dev/null
@@ -1,17 +0,0 @@
-/*
- * orion_spi.h
- *
- * This file is licensed under the terms of the GNU General Public
- * License version 2. This program is licensed "as is" without any
- * warranty of any kind, whether express or implied.
- */
-
-#ifndef __LINUX_SPI_ORION_SPI_H
-#define __LINUX_SPI_ORION_SPI_H
-
-struct orion_spi_info {
-       u32     tclk;           /* no <linux/clk.h> support yet */
-};
-
-
-#endif