summaryrefslogtreecommitdiff
path: root/drivers
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2008-07-05 10:02:46 +0200
committerRobert Schwebel <r.schwebel@pengutronix.de>2008-07-05 10:02:46 +0200
commit38a41fdf94c449c165213e4665c3f8a0d30f8aba (patch)
treecde7f6c0da8c9877736a6b66f245e163fa21c2f7 /drivers
parentdbff4e9ea2e83fda89143389bfb229cb29425a32 (diff)
IMX: introduce clock API
This patch introduces the clock API for i.MX and converts all in-Kernel drivers to use it. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/mmc/host/imxmmc.c19
-rw-r--r--drivers/serial/imx.c25
-rw-r--r--drivers/spi/spi_imx.c38
3 files changed, 67 insertions, 15 deletions
diff --git a/drivers/mmc/host/imxmmc.c b/drivers/mmc/host/imxmmc.c
index 95f33e87a99c..ef2f6fc86541 100644
--- a/drivers/mmc/host/imxmmc.c
+++ b/drivers/mmc/host/imxmmc.c
@@ -42,6 +42,7 @@
#include <linux/mmc/host.h>
#include <linux/mmc/card.h>
#include <linux/delay.h>
+#include <linux/clk.h>
#include <asm/dma.h>
#include <asm/io.h>
@@ -92,6 +93,8 @@ struct imxmci_host {
unsigned char actual_bus_width;
int prev_cmd_code;
+
+ struct clk *clk;
};
#define IMXMCI_PEND_IRQ_b 0
@@ -841,7 +844,7 @@ static void imxmci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
/* The prescaler is 5 for PERCLK2 equal to 96MHz
* then 96MHz / 5 = 19.2 MHz
*/
- clk=imx_get_perclk2();
+ clk = clk_get_rate(host->clk);
prescaler=(clk+(CLK_RATE*7)/8)/CLK_RATE;
switch(prescaler) {
case 0:
@@ -994,6 +997,13 @@ static int imxmci_probe(struct platform_device *pdev)
host->res = r;
host->irq = irq;
+ host->clk = clk_get(&pdev->dev, "perclk2");
+ if (IS_ERR(host->clk)) {
+ ret = PTR_ERR(host->clk);
+ goto out;
+ }
+ clk_enable(host->clk);
+
imx_gpio_mode(PB8_PF_SD_DAT0);
imx_gpio_mode(PB9_PF_SD_DAT1);
imx_gpio_mode(PB10_PF_SD_DAT2);
@@ -1053,6 +1063,10 @@ out:
imx_dma_free(host->dma);
host->dma_allocated=0;
}
+ if (host->clk) {
+ clk_disable(host->clk);
+ clk_put(host->clk);
+ }
}
if (mmc)
mmc_free_host(mmc);
@@ -1082,6 +1096,9 @@ static int imxmci_remove(struct platform_device *pdev)
tasklet_kill(&host->tasklet);
+ clk_disable(host->clk);
+ clk_put(host->clk);
+
release_resource(host->res);
mmc_free_host(mmc);
diff --git a/drivers/serial/imx.c b/drivers/serial/imx.c
index 8d6cb745bd93..9e2162ebf1bb 100644
--- a/drivers/serial/imx.c
+++ b/drivers/serial/imx.c
@@ -40,6 +40,7 @@
#include <linux/tty_flip.h>
#include <linux/serial_core.h>
#include <linux/serial.h>
+#include <linux/clk.h>
#include <asm/io.h>
#include <asm/irq.h>
@@ -184,6 +185,7 @@ struct imx_port {
unsigned int old_status;
int txirq,rxirq,rtsirq;
int have_rtscts:1;
+ struct clk *clk;
};
/*
@@ -479,7 +481,8 @@ static int imx_setup_ufcr(struct imx_port *sport, unsigned int mode)
* RFDIV is set such way to satisfy requested uartclk value
*/
val = TXTL << 10 | RXTL;
- ufcr_rfdiv = (imx_get_perclk1() + sport->port.uartclk / 2) / sport->port.uartclk;
+ ufcr_rfdiv = (clk_get_rate(sport->clk) + sport->port.uartclk / 2)
+ / sport->port.uartclk;
if(!ufcr_rfdiv)
ufcr_rfdiv = 1;
@@ -916,7 +919,7 @@ imx_console_get_options(struct imx_port *sport, int *baud,
else
ucfr_rfdiv = 6 - ucfr_rfdiv;
- uartclk = imx_get_perclk1();
+ uartclk = clk_get_rate(sport->clk);
uartclk /= ucfr_rfdiv;
{ /*
@@ -1054,7 +1057,15 @@ static int serial_imx_probe(struct platform_device *pdev)
init_timer(&sport->timer);
sport->timer.function = imx_timeout;
sport->timer.data = (unsigned long)sport;
- sport->port.uartclk = imx_get_perclk1();
+
+ sport->clk = clk_get(&pdev->dev, "uart_clk");
+ if (IS_ERR(sport->clk)) {
+ ret = PTR_ERR(sport->clk);
+ goto unmap;
+ }
+ clk_enable(sport->clk);
+
+ sport->port.uartclk = clk_get_rate(sport->clk);
imx_ports[pdev->id] = sport;
@@ -1069,6 +1080,8 @@ static int serial_imx_probe(struct platform_device *pdev)
platform_set_drvdata(pdev, &sport->port);
return 0;
+unmap:
+ iounmap(sport->port.membase);
free:
kfree(sport);
@@ -1084,8 +1097,12 @@ static int serial_imx_remove(struct platform_device *pdev)
platform_set_drvdata(pdev, NULL);
- if (sport)
+ if (sport) {
uart_remove_one_port(&imx_reg, &sport->port);
+ clk_put(sport->clk);
+ }
+
+ clk_disable(sport->clk);
if (pdata->exit)
pdata->exit(pdev);
diff --git a/drivers/spi/spi_imx.c b/drivers/spi/spi_imx.c
index c730d05bfeb6..bd0729b6b6ed 100644
--- a/drivers/spi/spi_imx.c
+++ b/drivers/spi/spi_imx.c
@@ -29,6 +29,7 @@
#include <linux/spi/spi.h>
#include <linux/workqueue.h>
#include <linux/delay.h>
+#include <linux/clk.h>
#include <asm/io.h>
#include <asm/irq.h>
@@ -250,6 +251,8 @@ struct driver_data {
int tx_dma_needs_unmap;
size_t tx_map_len;
u32 dummy_dma_buf ____cacheline_aligned;
+
+ struct clk *clk;
};
/* Runtime state */
@@ -855,15 +858,15 @@ static irqreturn_t spi_int(int irq, void *dev_id)
return drv_data->transfer_handler(drv_data);
}
-static inline u32 spi_speed_hz(u32 data_rate)
+static inline u32 spi_speed_hz(struct driver_data *drv_data, u32 data_rate)
{
- return imx_get_perclk2() / (4 << ((data_rate) >> 13));
+ return clk_get_rate(drv_data->clk) / (4 << ((data_rate) >> 13));
}
-static u32 spi_data_rate(u32 speed_hz)
+static u32 spi_data_rate(struct driver_data *drv_data, u32 speed_hz)
{
u32 div;
- u32 quantized_hz = imx_get_perclk2() >> 2;
+ u32 quantized_hz = clk_get_rate(drv_data->clk) >> 2;
for (div = SPI_PERCLK2_DIV_MIN;
div <= SPI_PERCLK2_DIV_MAX;
@@ -947,7 +950,7 @@ static void pump_transfers(unsigned long data)
tmp = transfer->speed_hz;
if (tmp == 0)
tmp = chip->max_speed_hz;
- tmp = spi_data_rate(tmp);
+ tmp = spi_data_rate(drv_data, tmp);
u32_EDIT(control, SPI_CONTROL_DATARATE, tmp);
writel(control, regs + SPI_CONTROL);
@@ -1109,7 +1112,7 @@ static int transfer(struct spi_device *spi, struct spi_message *msg)
msg->actual_length = 0;
/* Per transfer setup check */
- min_speed_hz = spi_speed_hz(SPI_CONTROL_DATARATE_MIN);
+ min_speed_hz = spi_speed_hz(drv_data, SPI_CONTROL_DATARATE_MIN);
max_speed_hz = spi->max_speed_hz;
list_for_each_entry(trans, &msg->transfers, transfer_list) {
tmp = trans->bits_per_word;
@@ -1176,6 +1179,7 @@ msg_rejected:
applied and notified to the calling driver. */
static int setup(struct spi_device *spi)
{
+ struct driver_data *drv_data = spi_master_get_devdata(spi->master);
struct spi_imx_chip *chip_info;
struct chip_data *chip;
int first_setup = 0;
@@ -1304,14 +1308,14 @@ static int setup(struct spi_device *spi)
chip->n_bytes = (tmp <= 8) ? 1 : 2;
/* SPI datarate */
- tmp = spi_data_rate(spi->max_speed_hz);
+ tmp = spi_data_rate(drv_data, spi->max_speed_hz);
if (tmp == SPI_CONTROL_DATARATE_BAD) {
status = -EINVAL;
dev_err(&spi->dev,
"setup - "
"HW min speed (%d Hz) exceeds required "
"max speed (%d Hz)\n",
- spi_speed_hz(SPI_CONTROL_DATARATE_MIN),
+ spi_speed_hz(drv_data, SPI_CONTROL_DATARATE_MIN),
spi->max_speed_hz);
if (first_setup)
goto err_first_setup;
@@ -1321,7 +1325,7 @@ static int setup(struct spi_device *spi)
} else {
u32_EDIT(chip->control, SPI_CONTROL_DATARATE, tmp);
/* Actual rounded max_speed_hz */
- tmp = spi_speed_hz(tmp);
+ tmp = spi_speed_hz(drv_data, tmp);
spi->max_speed_hz = tmp;
chip->max_speed_hz = tmp;
}
@@ -1352,7 +1356,7 @@ static int setup(struct spi_device *spi)
chip->period & SPI_PERIOD_WAIT,
spi->mode,
spi->bits_per_word,
- spi_speed_hz(SPI_CONTROL_DATARATE_MIN),
+ spi_speed_hz(drv_data, SPI_CONTROL_DATARATE_MIN),
spi->max_speed_hz);
return status;
@@ -1465,6 +1469,14 @@ static int __init spi_imx_probe(struct platform_device *pdev)
goto err_no_pdata;
}
+ drv_data->clk = clk_get(&pdev->dev, "perclk2");
+ if (IS_ERR(drv_data->clk)) {
+ dev_err(&pdev->dev, "probe - cannot get get\n");
+ status = PTR_ERR(drv_data->clk);
+ goto err_no_clk;
+ }
+ clk_enable(drv_data->clk);
+
/* Allocate master with space for drv_data */
master = spi_alloc_master(dev, sizeof(struct driver_data));
if (!master) {
@@ -1623,6 +1635,9 @@ err_no_iores:
spi_master_put(master);
err_no_pdata:
+ clk_disable(drv_data->clk);
+ clk_put(drv_data->clk);
+err_no_clk:
err_no_mem:
return status;
}
@@ -1662,6 +1677,9 @@ static int __exit spi_imx_remove(struct platform_device *pdev)
if (irq >= 0)
free_irq(irq, drv_data);
+ clk_disable(drv_data->clk);
+ clk_put(drv_data->clk);
+
/* Release map resources */
iounmap(drv_data->regs);
release_resource(drv_data->ioarea);