Skip to content

Commit 3343b7a

Browse files
westeribroonie
authored andcommitted
spi/pxa2xx: convert to the common clk framework
Convert clk_enable() to clk_prepare_enable() and clk_disable() to clk_disable_unprepare() respectively in order to support the common clk framework. Otherwise we get warnings on the console as the clock is not prepared before it is enabled. In addition we must cache the maximum clock rate to drv_data->max_clk_rate at probe time because clk_get_rate() cannot be called in tasklet context. Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com> Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
1 parent 7f86bde commit 3343b7a

File tree

2 files changed

+20
-31
lines changed

2 files changed

+20
-31
lines changed

drivers/spi/spi-pxa2xx.c

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include <linux/delay.h>
3131
#include <linux/gpio.h>
3232
#include <linux/slab.h>
33+
#include <linux/clk.h>
3334

3435
#include <asm/io.h>
3536
#include <asm/irq.h>
@@ -114,6 +115,9 @@ struct driver_data {
114115
u32 clear_sr;
115116
u32 mask_sr;
116117

118+
/* Maximun clock rate */
119+
unsigned long max_clk_rate;
120+
117121
/* Message Transfer pump */
118122
struct tasklet_struct pump_transfers;
119123

@@ -891,9 +895,12 @@ static int set_dma_burst_and_threshold(struct chip_data *chip,
891895
return retval;
892896
}
893897

894-
static unsigned int ssp_get_clk_div(struct ssp_device *ssp, int rate)
898+
static unsigned int ssp_get_clk_div(struct driver_data *drv_data, int rate)
895899
{
896-
unsigned long ssp_clk = clk_get_rate(ssp->clk);
900+
unsigned long ssp_clk = drv_data->max_clk_rate;
901+
const struct ssp_device *ssp = drv_data->ssp;
902+
903+
rate = min_t(int, ssp_clk, rate);
897904

898905
if (ssp->type == PXA25x_SSP || ssp->type == CE4100_SSP)
899906
return ((ssp_clk / (2 * rate) - 1) & 0xff) << 8;
@@ -908,7 +915,6 @@ static void pump_transfers(unsigned long data)
908915
struct spi_transfer *transfer = NULL;
909916
struct spi_transfer *previous = NULL;
910917
struct chip_data *chip = NULL;
911-
struct ssp_device *ssp = drv_data->ssp;
912918
void __iomem *reg = drv_data->ioaddr;
913919
u32 clk_div = 0;
914920
u8 bits = 0;
@@ -1005,7 +1011,7 @@ static void pump_transfers(unsigned long data)
10051011
if (transfer->bits_per_word)
10061012
bits = transfer->bits_per_word;
10071013

1008-
clk_div = ssp_get_clk_div(ssp, speed);
1014+
clk_div = ssp_get_clk_div(drv_data, speed);
10091015

10101016
if (bits <= 8) {
10111017
drv_data->n_bytes = 1;
@@ -1214,7 +1220,6 @@ static int setup(struct spi_device *spi)
12141220
struct pxa2xx_spi_chip *chip_info = NULL;
12151221
struct chip_data *chip;
12161222
struct driver_data *drv_data = spi_master_get_devdata(spi->master);
1217-
struct ssp_device *ssp = drv_data->ssp;
12181223
unsigned int clk_div;
12191224
uint tx_thres = TX_THRESH_DFLT;
12201225
uint rx_thres = RX_THRESH_DFLT;
@@ -1296,7 +1301,7 @@ static int setup(struct spi_device *spi)
12961301
}
12971302
}
12981303

1299-
clk_div = ssp_get_clk_div(ssp, spi->max_speed_hz);
1304+
clk_div = ssp_get_clk_div(drv_data, spi->max_speed_hz);
13001305
chip->speed_hz = spi->max_speed_hz;
13011306

13021307
chip->cr0 = clk_div
@@ -1312,12 +1317,12 @@ static int setup(struct spi_device *spi)
13121317
/* NOTE: PXA25x_SSP _could_ use external clocking ... */
13131318
if (!pxa25x_ssp_comp(drv_data))
13141319
dev_dbg(&spi->dev, "%ld Hz actual, %s\n",
1315-
clk_get_rate(ssp->clk)
1320+
drv_data->max_clk_rate
13161321
/ (1 + ((chip->cr0 & SSCR0_SCR(0xfff)) >> 8)),
13171322
chip->enable_dma ? "DMA" : "PIO");
13181323
else
13191324
dev_dbg(&spi->dev, "%ld Hz actual, %s\n",
1320-
clk_get_rate(ssp->clk) / 2
1325+
drv_data->max_clk_rate / 2
13211326
/ (1 + ((chip->cr0 & SSCR0_SCR(0x0ff)) >> 8)),
13221327
chip->enable_dma ? "DMA" : "PIO");
13231328

@@ -1470,7 +1475,9 @@ static int pxa2xx_spi_probe(struct platform_device *pdev)
14701475
}
14711476

14721477
/* Enable SOC clock */
1473-
clk_enable(ssp->clk);
1478+
clk_prepare_enable(ssp->clk);
1479+
1480+
drv_data->max_clk_rate = clk_get_rate(ssp->clk);
14741481

14751482
/* Load default SSP configuration */
14761483
write_SSCR0(0, drv_data->ioaddr);
@@ -1499,7 +1506,7 @@ static int pxa2xx_spi_probe(struct platform_device *pdev)
14991506
return status;
15001507

15011508
out_error_clock_enabled:
1502-
clk_disable(ssp->clk);
1509+
clk_disable_unprepare(ssp->clk);
15031510

15041511
out_error_dma_alloc:
15051512
if (drv_data->tx_channel != -1)
@@ -1527,7 +1534,7 @@ static int pxa2xx_spi_remove(struct platform_device *pdev)
15271534

15281535
/* Disable the SSP at the peripheral and SOC level */
15291536
write_SSCR0(0, drv_data->ioaddr);
1530-
clk_disable(ssp->clk);
1537+
clk_disable_unprepare(ssp->clk);
15311538

15321539
/* Release DMA */
15331540
if (drv_data->master_info->enable_dma) {
@@ -1571,7 +1578,7 @@ static int pxa2xx_spi_suspend(struct device *dev)
15711578
if (status != 0)
15721579
return status;
15731580
write_SSCR0(0, drv_data->ioaddr);
1574-
clk_disable(ssp->clk);
1581+
clk_disable_unprepare(ssp->clk);
15751582

15761583
return 0;
15771584
}
@@ -1590,7 +1597,7 @@ static int pxa2xx_spi_resume(struct device *dev)
15901597
DRCMR_MAPVLD | drv_data->tx_channel;
15911598

15921599
/* Enable the SSP clock */
1593-
clk_enable(ssp->clk);
1600+
clk_prepare_enable(ssp->clk);
15941601

15951602
/* Start the queue running */
15961603
status = spi_master_resume(drv_data->master);

include/linux/spi/pxa2xx_spi.h

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -133,23 +133,5 @@ static inline void pxa_free_dma(int dma_ch)
133133
{
134134
}
135135

136-
/*
137-
* The CE4100 does not have the clk framework implemented and SPI clock can
138-
* not be switched on/off or the divider changed.
139-
*/
140-
static inline void clk_disable(struct clk *clk)
141-
{
142-
}
143-
144-
static inline int clk_enable(struct clk *clk)
145-
{
146-
return 0;
147-
}
148-
149-
static inline unsigned long clk_get_rate(struct clk *clk)
150-
{
151-
return 3686400;
152-
}
153-
154136
#endif
155137
#endif

0 commit comments

Comments
 (0)