|
@@ -35,10 +35,10 @@
|
|
#include <linux/pm_domain.h>
|
|
#include <linux/pm_domain.h>
|
|
#include <linux/pm_runtime.h>
|
|
#include <linux/pm_runtime.h>
|
|
|
|
|
|
-struct sh_cmt_priv;
|
|
|
|
|
|
+struct sh_cmt_device;
|
|
|
|
|
|
struct sh_cmt_channel {
|
|
struct sh_cmt_channel {
|
|
- struct sh_cmt_priv *cmt;
|
|
|
|
|
|
+ struct sh_cmt_device *cmt;
|
|
|
|
|
|
unsigned long flags;
|
|
unsigned long flags;
|
|
unsigned long match_value;
|
|
unsigned long match_value;
|
|
@@ -52,7 +52,7 @@ struct sh_cmt_channel {
|
|
bool cs_enabled;
|
|
bool cs_enabled;
|
|
};
|
|
};
|
|
|
|
|
|
-struct sh_cmt_priv {
|
|
|
|
|
|
+struct sh_cmt_device {
|
|
struct platform_device *pdev;
|
|
struct platform_device *pdev;
|
|
|
|
|
|
void __iomem *mapbase;
|
|
void __iomem *mapbase;
|
|
@@ -693,132 +693,132 @@ static int sh_cmt_register(struct sh_cmt_channel *ch, char *name,
|
|
return 0;
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
|
|
-static int sh_cmt_setup(struct sh_cmt_priv *p, struct platform_device *pdev)
|
|
|
|
|
|
+static int sh_cmt_setup(struct sh_cmt_device *cmt, struct platform_device *pdev)
|
|
{
|
|
{
|
|
struct sh_timer_config *cfg = pdev->dev.platform_data;
|
|
struct sh_timer_config *cfg = pdev->dev.platform_data;
|
|
- struct sh_cmt_channel *ch = &p->channel;
|
|
|
|
|
|
+ struct sh_cmt_channel *ch = &cmt->channel;
|
|
struct resource *res, *res2;
|
|
struct resource *res, *res2;
|
|
int irq, ret;
|
|
int irq, ret;
|
|
ret = -ENXIO;
|
|
ret = -ENXIO;
|
|
|
|
|
|
- memset(p, 0, sizeof(*p));
|
|
|
|
- p->pdev = pdev;
|
|
|
|
|
|
+ memset(cmt, 0, sizeof(*cmt));
|
|
|
|
+ cmt->pdev = pdev;
|
|
|
|
|
|
if (!cfg) {
|
|
if (!cfg) {
|
|
- dev_err(&p->pdev->dev, "missing platform data\n");
|
|
|
|
|
|
+ dev_err(&cmt->pdev->dev, "missing platform data\n");
|
|
goto err0;
|
|
goto err0;
|
|
}
|
|
}
|
|
|
|
|
|
- res = platform_get_resource(p->pdev, IORESOURCE_MEM, 0);
|
|
|
|
|
|
+ res = platform_get_resource(cmt->pdev, IORESOURCE_MEM, 0);
|
|
if (!res) {
|
|
if (!res) {
|
|
- dev_err(&p->pdev->dev, "failed to get I/O memory\n");
|
|
|
|
|
|
+ dev_err(&cmt->pdev->dev, "failed to get I/O memory\n");
|
|
goto err0;
|
|
goto err0;
|
|
}
|
|
}
|
|
|
|
|
|
/* optional resource for the shared timer start/stop register */
|
|
/* optional resource for the shared timer start/stop register */
|
|
- res2 = platform_get_resource(p->pdev, IORESOURCE_MEM, 1);
|
|
|
|
|
|
+ res2 = platform_get_resource(cmt->pdev, IORESOURCE_MEM, 1);
|
|
|
|
|
|
- irq = platform_get_irq(p->pdev, 0);
|
|
|
|
|
|
+ irq = platform_get_irq(cmt->pdev, 0);
|
|
if (irq < 0) {
|
|
if (irq < 0) {
|
|
- dev_err(&p->pdev->dev, "failed to get irq\n");
|
|
|
|
|
|
+ dev_err(&cmt->pdev->dev, "failed to get irq\n");
|
|
goto err0;
|
|
goto err0;
|
|
}
|
|
}
|
|
|
|
|
|
/* map memory, let mapbase point to our channel */
|
|
/* map memory, let mapbase point to our channel */
|
|
- p->mapbase = ioremap_nocache(res->start, resource_size(res));
|
|
|
|
- if (p->mapbase == NULL) {
|
|
|
|
- dev_err(&p->pdev->dev, "failed to remap I/O memory\n");
|
|
|
|
|
|
+ cmt->mapbase = ioremap_nocache(res->start, resource_size(res));
|
|
|
|
+ if (cmt->mapbase == NULL) {
|
|
|
|
+ dev_err(&cmt->pdev->dev, "failed to remap I/O memory\n");
|
|
goto err0;
|
|
goto err0;
|
|
}
|
|
}
|
|
|
|
|
|
/* map second resource for CMSTR */
|
|
/* map second resource for CMSTR */
|
|
- p->mapbase_str = ioremap_nocache(res2 ? res2->start :
|
|
|
|
- res->start - cfg->channel_offset,
|
|
|
|
- res2 ? resource_size(res2) : 2);
|
|
|
|
- if (p->mapbase_str == NULL) {
|
|
|
|
- dev_err(&p->pdev->dev, "failed to remap I/O second memory\n");
|
|
|
|
|
|
+ cmt->mapbase_str = ioremap_nocache(res2 ? res2->start :
|
|
|
|
+ res->start - cfg->channel_offset,
|
|
|
|
+ res2 ? resource_size(res2) : 2);
|
|
|
|
+ if (cmt->mapbase_str == NULL) {
|
|
|
|
+ dev_err(&cmt->pdev->dev, "failed to remap I/O second memory\n");
|
|
goto err1;
|
|
goto err1;
|
|
}
|
|
}
|
|
|
|
|
|
/* get hold of clock */
|
|
/* get hold of clock */
|
|
- p->clk = clk_get(&p->pdev->dev, "cmt_fck");
|
|
|
|
- if (IS_ERR(p->clk)) {
|
|
|
|
- dev_err(&p->pdev->dev, "cannot get clock\n");
|
|
|
|
- ret = PTR_ERR(p->clk);
|
|
|
|
|
|
+ cmt->clk = clk_get(&cmt->pdev->dev, "cmt_fck");
|
|
|
|
+ if (IS_ERR(cmt->clk)) {
|
|
|
|
+ dev_err(&cmt->pdev->dev, "cannot get clock\n");
|
|
|
|
+ ret = PTR_ERR(cmt->clk);
|
|
goto err2;
|
|
goto err2;
|
|
}
|
|
}
|
|
|
|
|
|
- ret = clk_prepare(p->clk);
|
|
|
|
|
|
+ ret = clk_prepare(cmt->clk);
|
|
if (ret < 0)
|
|
if (ret < 0)
|
|
goto err3;
|
|
goto err3;
|
|
|
|
|
|
if (res2 && (resource_size(res2) == 4)) {
|
|
if (res2 && (resource_size(res2) == 4)) {
|
|
/* assume both CMSTR and CMCSR to be 32-bit */
|
|
/* assume both CMSTR and CMCSR to be 32-bit */
|
|
- p->read_control = sh_cmt_read32;
|
|
|
|
- p->write_control = sh_cmt_write32;
|
|
|
|
|
|
+ cmt->read_control = sh_cmt_read32;
|
|
|
|
+ cmt->write_control = sh_cmt_write32;
|
|
} else {
|
|
} else {
|
|
- p->read_control = sh_cmt_read16;
|
|
|
|
- p->write_control = sh_cmt_write16;
|
|
|
|
|
|
+ cmt->read_control = sh_cmt_read16;
|
|
|
|
+ cmt->write_control = sh_cmt_write16;
|
|
}
|
|
}
|
|
|
|
|
|
if (resource_size(res) == 6) {
|
|
if (resource_size(res) == 6) {
|
|
- p->width = 16;
|
|
|
|
- p->read_count = sh_cmt_read16;
|
|
|
|
- p->write_count = sh_cmt_write16;
|
|
|
|
- p->overflow_bit = 0x80;
|
|
|
|
- p->clear_bits = ~0x80;
|
|
|
|
|
|
+ cmt->width = 16;
|
|
|
|
+ cmt->read_count = sh_cmt_read16;
|
|
|
|
+ cmt->write_count = sh_cmt_write16;
|
|
|
|
+ cmt->overflow_bit = 0x80;
|
|
|
|
+ cmt->clear_bits = ~0x80;
|
|
} else {
|
|
} else {
|
|
- p->width = 32;
|
|
|
|
- p->read_count = sh_cmt_read32;
|
|
|
|
- p->write_count = sh_cmt_write32;
|
|
|
|
- p->overflow_bit = 0x8000;
|
|
|
|
- p->clear_bits = ~0xc000;
|
|
|
|
|
|
+ cmt->width = 32;
|
|
|
|
+ cmt->read_count = sh_cmt_read32;
|
|
|
|
+ cmt->write_count = sh_cmt_write32;
|
|
|
|
+ cmt->overflow_bit = 0x8000;
|
|
|
|
+ cmt->clear_bits = ~0xc000;
|
|
}
|
|
}
|
|
|
|
|
|
- if (p->width == (sizeof(ch->max_match_value) * 8))
|
|
|
|
|
|
+ if (cmt->width == (sizeof(ch->max_match_value) * 8))
|
|
ch->max_match_value = ~0;
|
|
ch->max_match_value = ~0;
|
|
else
|
|
else
|
|
- ch->max_match_value = (1 << p->width) - 1;
|
|
|
|
|
|
+ ch->max_match_value = (1 << cmt->width) - 1;
|
|
|
|
|
|
- ch->cmt = p;
|
|
|
|
|
|
+ ch->cmt = cmt;
|
|
ch->match_value = ch->max_match_value;
|
|
ch->match_value = ch->max_match_value;
|
|
raw_spin_lock_init(&ch->lock);
|
|
raw_spin_lock_init(&ch->lock);
|
|
|
|
|
|
- ret = sh_cmt_register(ch, (char *)dev_name(&p->pdev->dev),
|
|
|
|
|
|
+ ret = sh_cmt_register(ch, (char *)dev_name(&cmt->pdev->dev),
|
|
cfg->clockevent_rating,
|
|
cfg->clockevent_rating,
|
|
cfg->clocksource_rating);
|
|
cfg->clocksource_rating);
|
|
if (ret) {
|
|
if (ret) {
|
|
- dev_err(&p->pdev->dev, "registration failed\n");
|
|
|
|
|
|
+ dev_err(&cmt->pdev->dev, "registration failed\n");
|
|
goto err4;
|
|
goto err4;
|
|
}
|
|
}
|
|
ch->cs_enabled = false;
|
|
ch->cs_enabled = false;
|
|
|
|
|
|
ret = request_irq(irq, sh_cmt_interrupt,
|
|
ret = request_irq(irq, sh_cmt_interrupt,
|
|
IRQF_TIMER | IRQF_IRQPOLL | IRQF_NOBALANCING,
|
|
IRQF_TIMER | IRQF_IRQPOLL | IRQF_NOBALANCING,
|
|
- dev_name(&p->pdev->dev), ch);
|
|
|
|
|
|
+ dev_name(&cmt->pdev->dev), ch);
|
|
if (ret) {
|
|
if (ret) {
|
|
- dev_err(&p->pdev->dev, "failed to request irq %d\n", irq);
|
|
|
|
|
|
+ dev_err(&cmt->pdev->dev, "failed to request irq %d\n", irq);
|
|
goto err4;
|
|
goto err4;
|
|
}
|
|
}
|
|
|
|
|
|
- platform_set_drvdata(pdev, p);
|
|
|
|
|
|
+ platform_set_drvdata(pdev, cmt);
|
|
|
|
|
|
return 0;
|
|
return 0;
|
|
err4:
|
|
err4:
|
|
- clk_unprepare(p->clk);
|
|
|
|
|
|
+ clk_unprepare(cmt->clk);
|
|
err3:
|
|
err3:
|
|
- clk_put(p->clk);
|
|
|
|
|
|
+ clk_put(cmt->clk);
|
|
err2:
|
|
err2:
|
|
- iounmap(p->mapbase_str);
|
|
|
|
|
|
+ iounmap(cmt->mapbase_str);
|
|
err1:
|
|
err1:
|
|
- iounmap(p->mapbase);
|
|
|
|
|
|
+ iounmap(cmt->mapbase);
|
|
err0:
|
|
err0:
|
|
return ret;
|
|
return ret;
|
|
}
|
|
}
|
|
|
|
|
|
static int sh_cmt_probe(struct platform_device *pdev)
|
|
static int sh_cmt_probe(struct platform_device *pdev)
|
|
{
|
|
{
|
|
- struct sh_cmt_priv *p = platform_get_drvdata(pdev);
|
|
|
|
|
|
+ struct sh_cmt_device *cmt = platform_get_drvdata(pdev);
|
|
struct sh_timer_config *cfg = pdev->dev.platform_data;
|
|
struct sh_timer_config *cfg = pdev->dev.platform_data;
|
|
int ret;
|
|
int ret;
|
|
|
|
|
|
@@ -827,20 +827,20 @@ static int sh_cmt_probe(struct platform_device *pdev)
|
|
pm_runtime_enable(&pdev->dev);
|
|
pm_runtime_enable(&pdev->dev);
|
|
}
|
|
}
|
|
|
|
|
|
- if (p) {
|
|
|
|
|
|
+ if (cmt) {
|
|
dev_info(&pdev->dev, "kept as earlytimer\n");
|
|
dev_info(&pdev->dev, "kept as earlytimer\n");
|
|
goto out;
|
|
goto out;
|
|
}
|
|
}
|
|
|
|
|
|
- p = kmalloc(sizeof(*p), GFP_KERNEL);
|
|
|
|
- if (p == NULL) {
|
|
|
|
|
|
+ cmt = kmalloc(sizeof(*cmt), GFP_KERNEL);
|
|
|
|
+ if (cmt == NULL) {
|
|
dev_err(&pdev->dev, "failed to allocate driver data\n");
|
|
dev_err(&pdev->dev, "failed to allocate driver data\n");
|
|
return -ENOMEM;
|
|
return -ENOMEM;
|
|
}
|
|
}
|
|
|
|
|
|
- ret = sh_cmt_setup(p, pdev);
|
|
|
|
|
|
+ ret = sh_cmt_setup(cmt, pdev);
|
|
if (ret) {
|
|
if (ret) {
|
|
- kfree(p);
|
|
|
|
|
|
+ kfree(cmt);
|
|
pm_runtime_idle(&pdev->dev);
|
|
pm_runtime_idle(&pdev->dev);
|
|
return ret;
|
|
return ret;
|
|
}
|
|
}
|