Skip to content

Commit

Permalink
[ARM] pxa: convert to clkdev and match clocks by struct device where …
Browse files Browse the repository at this point in the history
…possible

Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
  • Loading branch information
Russell King authored and Russell King committed Nov 27, 2008
1 parent 71a06da commit 8c3abc7
Show file tree
Hide file tree
Showing 9 changed files with 201 additions and 205 deletions.
1 change: 1 addition & 0 deletions arch/arm/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,7 @@ config ARCH_PXA
select ARCH_MTD_XIP
select GENERIC_GPIO
select HAVE_CLK
select COMMON_CLKDEV
select ARCH_REQUIRE_GPIOLIB
select GENERIC_TIME
select GENERIC_CLOCKEVENTS
Expand Down
66 changes: 10 additions & 56 deletions arch/arm/mach-pxa/clock.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <linux/platform_device.h>
#include <linux/delay.h>

#include <asm/clkdev.h>
#include <mach/pxa2xx-regs.h>
#include <mach/pxa2xx-gpio.h>
#include <mach/hardware.h>
Expand All @@ -20,45 +21,8 @@
#include "generic.h"
#include "clock.h"

static LIST_HEAD(clocks);
static DEFINE_MUTEX(clocks_mutex);
static DEFINE_SPINLOCK(clocks_lock);

static struct clk *clk_lookup(struct device *dev, const char *id)
{
struct clk *p;

list_for_each_entry(p, &clocks, node)
if (strcmp(id, p->name) == 0 && p->dev == dev)
return p;

return NULL;
}

struct clk *clk_get(struct device *dev, const char *id)
{
struct clk *p, *clk = ERR_PTR(-ENOENT);

mutex_lock(&clocks_mutex);
p = clk_lookup(dev, id);
if (!p)
p = clk_lookup(NULL, id);
if (p)
clk = p;
mutex_unlock(&clocks_mutex);

if (!IS_ERR(clk) && clk->ops == NULL)
clk = clk->other;

return clk;
}
EXPORT_SYMBOL(clk_get);

void clk_put(struct clk *clk)
{
}
EXPORT_SYMBOL(clk_put);

int clk_enable(struct clk *clk)
{
unsigned long flags;
Expand Down Expand Up @@ -116,37 +80,27 @@ const struct clkops clk_cken_ops = {
.disable = clk_cken_disable,
};

void clks_register(struct clk *clks, size_t num)
void clks_register(struct clk_lookup *clks, size_t num)
{
int i;

mutex_lock(&clocks_mutex);
for (i = 0; i < num; i++)
list_add(&clks[i].node, &clocks);
mutex_unlock(&clocks_mutex);
clkdev_add(&clks[i]);
}

int clk_add_alias(char *alias, struct device *alias_dev, char *id,
struct device *dev)
{
struct clk *r = clk_lookup(dev, id);
struct clk *new;
struct clk *r = clk_get(dev, id);
struct clk_lookup *l;

if (!r)
return -ENODEV;

new = kzalloc(sizeof(struct clk), GFP_KERNEL);

if (!new)
return -ENOMEM;

new->name = alias;
new->dev = alias_dev;
new->other = r;

mutex_lock(&clocks_mutex);
list_add(&new->node, &clocks);
mutex_unlock(&clocks_mutex);

l = clkdev_alloc(r, alias, alias_dev ? dev_name(alias_dev) : NULL);
clk_put(r);
if (!l)
return -ENODEV;
clkdev_add(l);
return 0;
}
59 changes: 20 additions & 39 deletions arch/arm/mach-pxa/clock.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
#include <linux/list.h>

struct clk;
#include <asm/clkdev.h>

struct clkops {
void (*enable)(struct clk *);
Expand All @@ -9,9 +7,6 @@ struct clkops {
};

struct clk {
struct list_head node;
const char *name;
struct device *dev;
const struct clkops *ops;
unsigned long rate;
unsigned int cken;
Expand All @@ -20,41 +15,31 @@ struct clk {
struct clk *other;
};

#define INIT_CKEN(_name, _cken, _rate, _delay, _dev) \
#define INIT_CLKREG(_clk,_devname,_conname) \
{ \
.name = _name, \
.dev = _dev, \
.clk = _clk, \
.dev_id = _devname, \
.con_id = _conname, \
}

#define DEFINE_CKEN(_name, _cken, _rate, _delay) \
struct clk clk_##_name = { \
.ops = &clk_cken_ops, \
.rate = _rate, \
.cken = CKEN_##_cken, \
.delay = _delay, \
}

#define INIT_CK(_name, _cken, _ops, _dev) \
{ \
.name = _name, \
.dev = _dev, \
#define DEFINE_CK(_name, _cken, _ops) \
struct clk clk_##_name = { \
.ops = _ops, \
.cken = CKEN_##_cken, \
}

/*
* This is a placeholder to alias one clock device+name pair
* to another struct clk.
*/
#define INIT_CKOTHER(_name, _other, _dev) \
{ \
.name = _name, \
.dev = _dev, \
.other = _other, \
}

#define INIT_CLK(_name, _ops, _rate, _delay, _dev) \
{ \
.name = _name, \
.dev = _dev, \
.ops = _ops, \
.rate = _rate, \
#define DEFINE_CLK(_name, _ops, _rate, _delay) \
struct clk clk_##_name = { \
.ops = _ops, \
.rate = _rate, \
.delay = _delay, \
}

Expand All @@ -64,20 +49,16 @@ void clk_cken_enable(struct clk *clk);
void clk_cken_disable(struct clk *clk);

#ifdef CONFIG_PXA3xx
#define PXA3xx_CKEN(_name, _cken, _rate, _delay, _dev) \
{ \
.name = _name, \
.dev = _dev, \
#define DEFINE_PXA3_CKEN(_name, _cken, _rate, _delay) \
struct clk clk_##_name = { \
.ops = &clk_pxa3xx_cken_ops, \
.rate = _rate, \
.cken = CKEN_##_cken, \
.delay = _delay, \
}

#define PXA3xx_CK(_name, _cken, _ops, _dev) \
{ \
.name = _name, \
.dev = _dev, \
#define DEFINE_PXA3_CK(_name, _cken, _ops) \
struct clk clk_##_name = { \
.ops = _ops, \
.cken = CKEN_##_cken, \
}
Expand All @@ -87,7 +68,7 @@ extern void clk_pxa3xx_cken_enable(struct clk *);
extern void clk_pxa3xx_cken_disable(struct clk *);
#endif

void clks_register(struct clk *clks, size_t num);
void clks_register(struct clk_lookup *clks, size_t num);
int clk_add_alias(char *alias, struct device *alias_dev, char *id,
struct device *dev);

7 changes: 7 additions & 0 deletions arch/arm/mach-pxa/include/mach/clkdev.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#ifndef __ASM_MACH_CLKDEV_H
#define __ASM_MACH_CLKDEV_H

#define __clk_get(clk) ({ 1; })
#define __clk_put(clk) do { } while (0)

#endif
71 changes: 43 additions & 28 deletions arch/arm/mach-pxa/pxa25x.c
Original file line number Diff line number Diff line change
Expand Up @@ -167,36 +167,51 @@ static const struct clkops clk_pxa25x_gpio11_ops = {
* 95.842MHz -> MMC 19.169MHz, I2C 31.949MHz, FICP 47.923MHz, USB 47.923MHz
* 147.456MHz -> UART 14.7456MHz, AC97 12.288MHz, I2S 5.672MHz (allegedly)
*/
static struct clk pxa25x_hwuart_clk =
INIT_CKEN("UARTCLK", HWUART, 14745600, 1, &pxa_device_hwuart.dev)
;
static DEFINE_CKEN(pxa25x_hwuart, HWUART, 14745600, 1);

static struct clk_lookup pxa25x_hwuart_clkreg =
INIT_CLKREG(&clk_pxa25x_hwuart, "pxa2xx-uart.3", NULL);

/*
* PXA 2xx clock declarations.
*/
static struct clk pxa25x_clks[] = {
INIT_CK("LCDCLK", LCD, &clk_pxa25x_lcd_ops, &pxa_device_fb.dev),
INIT_CKEN("UARTCLK", FFUART, 14745600, 1, &pxa_device_ffuart.dev),
INIT_CKEN("UARTCLK", BTUART, 14745600, 1, &pxa_device_btuart.dev),
INIT_CKEN("UARTCLK", STUART, 14745600, 1, NULL),
INIT_CKEN("UDCCLK", USB, 47923000, 5, &pxa25x_device_udc.dev),
INIT_CLK("GPIO11_CLK", &clk_pxa25x_gpio11_ops, 3686400, 0, NULL),
INIT_CLK("GPIO12_CLK", &clk_pxa25x_gpio12_ops, 32768, 0, NULL),
INIT_CKEN("MMCCLK", MMC, 19169000, 0, &pxa_device_mci.dev),
INIT_CKEN("I2CCLK", I2C, 31949000, 0, &pxa_device_i2c.dev),

INIT_CKEN("SSPCLK", SSP, 3686400, 0, &pxa25x_device_ssp.dev),
INIT_CKEN("SSPCLK", NSSP, 3686400, 0, &pxa25x_device_nssp.dev),
INIT_CKEN("SSPCLK", ASSP, 3686400, 0, &pxa25x_device_assp.dev),
INIT_CKEN("PWMCLK", PWM0, 3686400, 0, &pxa25x_device_pwm0.dev),
INIT_CKEN("PWMCLK", PWM1, 3686400, 0, &pxa25x_device_pwm1.dev),

INIT_CKEN("AC97CLK", AC97, 24576000, 0, NULL),

/*
INIT_CKEN("I2SCLK", I2S, 14745600, 0, NULL),
*/
INIT_CKEN("FICPCLK", FICP, 47923000, 0, NULL),
static DEFINE_CK(pxa25x_lcd, LCD, &clk_pxa25x_lcd_ops);
static DEFINE_CKEN(pxa25x_ffuart, FFUART, 14745600, 1);
static DEFINE_CKEN(pxa25x_btuart, BTUART, 14745600, 1);
static DEFINE_CKEN(pxa25x_stuart, STUART, 14745600, 1);
static DEFINE_CKEN(pxa25x_usb, USB, 47923000, 5);
static DEFINE_CLK(pxa25x_gpio11, &clk_pxa25x_gpio11_ops, 3686400, 0);
static DEFINE_CLK(pxa25x_gpio12, &clk_pxa25x_gpio12_ops, 32768, 0);
static DEFINE_CKEN(pxa25x_mmc, MMC, 19169000, 0);
static DEFINE_CKEN(pxa25x_i2c, I2C, 31949000, 0);
static DEFINE_CKEN(pxa25x_ssp, SSP, 3686400, 0);
static DEFINE_CKEN(pxa25x_nssp, NSSP, 3686400, 0);
static DEFINE_CKEN(pxa25x_assp, ASSP, 3686400, 0);
static DEFINE_CKEN(pxa25x_pwm0, PWM0, 3686400, 0);
static DEFINE_CKEN(pxa25x_pwm1, PWM1, 3686400, 0);
static DEFINE_CKEN(pxa25x_ac97, AC97, 24576000, 0);
static DEFINE_CKEN(pxa25x_i2s, I2S, 14745600, 0);
static DEFINE_CKEN(pxa25x_ficp, FICP, 47923000, 0);

static struct clk_lookup pxa25x_clkregs[] = {
INIT_CLKREG(&clk_pxa25x_lcd, "pxa2xx-fb", NULL),
INIT_CLKREG(&clk_pxa25x_ffuart, "pxa2xx-uart.0", NULL),
INIT_CLKREG(&clk_pxa25x_btuart, "pxa2xx-uart.1", NULL),
INIT_CLKREG(&clk_pxa25x_stuart, "pxa2xx-uart.2", NULL),
INIT_CLKREG(&clk_pxa25x_usb, "pxa25x-udc", NULL),
INIT_CLKREG(&clk_pxa25x_mmc, "pxa2xx-mci.0", NULL),
INIT_CLKREG(&clk_pxa25x_i2c, "pxa2xx-i2c.0", NULL),
INIT_CLKREG(&clk_pxa25x_ssp, "pxa25x-ssp.0", NULL),
INIT_CLKREG(&clk_pxa25x_nssp, "pxa25x-nssp.1", NULL),
INIT_CLKREG(&clk_pxa25x_assp, "pxa25x-nssp.2", NULL),
INIT_CLKREG(&clk_pxa25x_pwm0, "pxa25x-pwm.0", NULL),
INIT_CLKREG(&clk_pxa25x_pwm1, "pxa25x-pwm.1", NULL),
INIT_CLKREG(&clk_pxa25x_i2s, "pxa2xx-i2s", NULL),
INIT_CLKREG(&clk_pxa25x_stuart, "pxa2xx-ir", "UARTCLK"),
INIT_CLKREG(&clk_pxa25x_ficp, "pxa2xx-ir", "FICPCLK"),
INIT_CLKREG(&clk_pxa25x_ac97, NULL, "AC97CLK"),
INIT_CLKREG(&clk_pxa25x_gpio11, NULL, "GPIO11_CLK"),
INIT_CLKREG(&clk_pxa25x_gpio12, NULL, "GPIO12_CLK"),
};

#ifdef CONFIG_PM
Expand Down Expand Up @@ -336,7 +351,7 @@ static int __init pxa25x_init(void)

reset_status = RCSR;

clks_register(pxa25x_clks, ARRAY_SIZE(pxa25x_clks));
clks_register(pxa25x_clkregs, ARRAY_SIZE(pxa25x_clkregs));

if ((ret = pxa_init_dma(16)))
return ret;
Expand All @@ -357,7 +372,7 @@ static int __init pxa25x_init(void)

/* Only add HWUART for PXA255/26x; PXA210/250 do not have it. */
if (cpu_is_pxa255() || cpu_is_pxa26x()) {
clks_register(&pxa25x_hwuart_clk, 1);
clks_register(&pxa25x_hwuart_clkreg, 1);
ret = platform_device_register(&pxa_device_hwuart);
}

Expand Down
Loading

0 comments on commit 8c3abc7

Please sign in to comment.