Commit 71adf22f authored by Sonic Zhang's avatar Sonic Zhang Committed by Dmitry Torokhov

Input: bfin_rotary - use generic IO functions

Instead of using arch-specific accessors remap rotary register physical
address into kernel space in probe and use standard readw and writew to
access rotary MMRs.
Signed-off-by: default avatarSonic Zhang <sonic.zhang@analog.com>
Signed-off-by: default avatarDmitry Torokhov <dmitry.torokhov@gmail.com>
parent 5ea0699a
...@@ -687,6 +687,11 @@ static struct bfin_rotary_platform_data bfin_rotary_data = { ...@@ -687,6 +687,11 @@ static struct bfin_rotary_platform_data bfin_rotary_data = {
}; };
static struct resource bfin_rotary_resources[] = { static struct resource bfin_rotary_resources[] = {
{
.start = CNT_CONFIG,
.end = CNT_CONFIG + 0xff,
.flags = IORESOURCE_MEM,
},
{ {
.start = IRQ_CNT, .start = IRQ_CNT,
.end = IRQ_CNT, .end = IRQ_CNT,
......
...@@ -1113,6 +1113,11 @@ static struct bfin_rotary_platform_data bfin_rotary_data = { ...@@ -1113,6 +1113,11 @@ static struct bfin_rotary_platform_data bfin_rotary_data = {
}; };
static struct resource bfin_rotary_resources[] = { static struct resource bfin_rotary_resources[] = {
{
.start = CNT_CONFIG,
.end = CNT_CONFIG + 0xff,
.flags = IORESOURCE_MEM,
},
{ {
.start = IRQ_CNT, .start = IRQ_CNT,
.end = IRQ_CNT, .end = IRQ_CNT,
......
...@@ -172,6 +172,11 @@ static struct bfin_rotary_platform_data bfin_rotary_data = { ...@@ -172,6 +172,11 @@ static struct bfin_rotary_platform_data bfin_rotary_data = {
}; };
static struct resource bfin_rotary_resources[] = { static struct resource bfin_rotary_resources[] = {
{
.start = CNT_CONFIG,
.end = CNT_CONFIG + 0xff,
.flags = IORESOURCE_MEM,
},
{ {
.start = IRQ_CNT, .start = IRQ_CNT,
.end = IRQ_CNT, .end = IRQ_CNT,
......
...@@ -87,6 +87,11 @@ static struct bfin_rotary_platform_data bfin_rotary_data = { ...@@ -87,6 +87,11 @@ static struct bfin_rotary_platform_data bfin_rotary_data = {
}; };
static struct resource bfin_rotary_resources[] = { static struct resource bfin_rotary_resources[] = {
{
.start = CNT_CONFIG,
.end = CNT_CONFIG + 0xff,
.flags = IORESOURCE_MEM,
},
{ {
.start = IRQ_CNT, .start = IRQ_CNT,
.end = IRQ_CNT, .end = IRQ_CNT,
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include <linux/module.h> #include <linux/module.h>
#include <linux/interrupt.h> #include <linux/interrupt.h>
#include <linux/io.h>
#include <linux/irq.h> #include <linux/irq.h>
#include <linux/pm.h> #include <linux/pm.h>
#include <linux/platform_device.h> #include <linux/platform_device.h>
...@@ -16,8 +17,18 @@ ...@@ -16,8 +17,18 @@
#include <asm/portmux.h> #include <asm/portmux.h>
#define CNT_CONFIG_OFF 0 /* CNT Config Offset */
#define CNT_IMASK_OFF 4 /* CNT Interrupt Mask Offset */
#define CNT_STATUS_OFF 8 /* CNT Status Offset */
#define CNT_COMMAND_OFF 12 /* CNT Command Offset */
#define CNT_DEBOUNCE_OFF 16 /* CNT Debounce Offset */
#define CNT_COUNTER_OFF 20 /* CNT Counter Offset */
#define CNT_MAX_OFF 24 /* CNT Maximum Count Offset */
#define CNT_MIN_OFF 28 /* CNT Minimum Count Offset */
struct bfin_rot { struct bfin_rot {
struct input_dev *input; struct input_dev *input;
void __iomem *base;
int irq; int irq;
unsigned int up_key; unsigned int up_key;
unsigned int down_key; unsigned int down_key;
...@@ -55,14 +66,14 @@ static irqreturn_t bfin_rotary_isr(int irq, void *dev_id) ...@@ -55,14 +66,14 @@ static irqreturn_t bfin_rotary_isr(int irq, void *dev_id)
struct bfin_rot *rotary = dev_id; struct bfin_rot *rotary = dev_id;
int delta; int delta;
switch (bfin_read_CNT_STATUS()) { switch (readw(rotary->base + CNT_STATUS_OFF)) {
case ICII: case ICII:
break; break;
case UCII: case UCII:
case DCII: case DCII:
delta = bfin_read_CNT_COUNTER(); delta = readl(rotary->base + CNT_COUNTER_OFF);
if (delta) if (delta)
report_rotary_event(rotary, delta); report_rotary_event(rotary, delta);
break; break;
...@@ -75,8 +86,8 @@ static irqreturn_t bfin_rotary_isr(int irq, void *dev_id) ...@@ -75,8 +86,8 @@ static irqreturn_t bfin_rotary_isr(int irq, void *dev_id)
break; break;
} }
bfin_write_CNT_COMMAND(W1LCNT_ZERO); /* Clear COUNTER */ writew(W1LCNT_ZERO, rotary->base + CNT_COMMAND_OFF); /* Clear COUNTER */
bfin_write_CNT_STATUS(-1); /* Clear STATUS */ writew(-1, rotary->base + CNT_STATUS_OFF); /* Clear STATUS */
return IRQ_HANDLED; return IRQ_HANDLED;
} }
...@@ -85,7 +96,9 @@ static int bfin_rotary_probe(struct platform_device *pdev) ...@@ -85,7 +96,9 @@ static int bfin_rotary_probe(struct platform_device *pdev)
{ {
const struct bfin_rotary_platform_data *pdata = const struct bfin_rotary_platform_data *pdata =
dev_get_platdata(&pdev->dev); dev_get_platdata(&pdev->dev);
struct device *dev = &pdev->dev;
struct bfin_rot *rotary; struct bfin_rot *rotary;
struct resource *res;
struct input_dev *input; struct input_dev *input;
int error; int error;
...@@ -111,6 +124,13 @@ static int bfin_rotary_probe(struct platform_device *pdev) ...@@ -111,6 +124,13 @@ static int bfin_rotary_probe(struct platform_device *pdev)
goto out1; goto out1;
} }
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
rotary->base = devm_ioremap_resource(dev, res);
if (IS_ERR(rotary->base)) {
error = PTR_ERR(rotary->base);
goto out1;
}
rotary->input = input; rotary->input = input;
rotary->up_key = pdata->rotary_up_key; rotary->up_key = pdata->rotary_up_key;
...@@ -164,17 +184,21 @@ static int bfin_rotary_probe(struct platform_device *pdev) ...@@ -164,17 +184,21 @@ static int bfin_rotary_probe(struct platform_device *pdev)
} }
if (pdata->rotary_button_key) if (pdata->rotary_button_key)
bfin_write_CNT_IMASK(CZMIE); writew(CZMIE, rotary->base + CNT_IMASK_OFF);
if (pdata->mode & ROT_DEBE) if (pdata->mode & ROT_DEBE)
bfin_write_CNT_DEBOUNCE(pdata->debounce & DPRESCALE); writew(pdata->debounce & DPRESCALE,
rotary->base + CNT_DEBOUNCE_OFF);
if (pdata->mode) if (pdata->mode)
bfin_write_CNT_CONFIG(bfin_read_CNT_CONFIG() | writew(readw(rotary->base + CNT_CONFIG_OFF) |
(pdata->mode & ~CNTE)); (pdata->mode & ~CNTE),
rotary->base + CNT_CONFIG_OFF);
bfin_write_CNT_IMASK(bfin_read_CNT_IMASK() | UCIE | DCIE); writew(readw(rotary->base + CNT_IMASK_OFF) | UCIE | DCIE,
bfin_write_CNT_CONFIG(bfin_read_CNT_CONFIG() | CNTE); rotary->base + CNT_IMASK_OFF);
writew(readw(rotary->base + CNT_CONFIG_OFF) | CNTE,
rotary->base + CNT_CONFIG_OFF);
platform_set_drvdata(pdev, rotary); platform_set_drvdata(pdev, rotary);
device_init_wakeup(&pdev->dev, 1); device_init_wakeup(&pdev->dev, 1);
...@@ -198,8 +222,8 @@ static int bfin_rotary_remove(struct platform_device *pdev) ...@@ -198,8 +222,8 @@ static int bfin_rotary_remove(struct platform_device *pdev)
dev_get_platdata(&pdev->dev); dev_get_platdata(&pdev->dev);
struct bfin_rot *rotary = platform_get_drvdata(pdev); struct bfin_rot *rotary = platform_get_drvdata(pdev);
bfin_write_CNT_CONFIG(0); writew(0, rotary->base + CNT_CONFIG_OFF);
bfin_write_CNT_IMASK(0); writew(0, rotary->base + CNT_IMASK_OFF);
free_irq(rotary->irq, rotary); free_irq(rotary->irq, rotary);
input_unregister_device(rotary->input); input_unregister_device(rotary->input);
...@@ -217,9 +241,9 @@ static int __maybe_unused bfin_rotary_suspend(struct device *dev) ...@@ -217,9 +241,9 @@ static int __maybe_unused bfin_rotary_suspend(struct device *dev)
struct platform_device *pdev = to_platform_device(dev); struct platform_device *pdev = to_platform_device(dev);
struct bfin_rot *rotary = platform_get_drvdata(pdev); struct bfin_rot *rotary = platform_get_drvdata(pdev);
rotary->cnt_config = bfin_read_CNT_CONFIG(); rotary->cnt_config = readw(rotary->base + CNT_CONFIG_OFF);
rotary->cnt_imask = bfin_read_CNT_IMASK(); rotary->cnt_imask = readw(rotary->base + CNT_IMASK_OFF);
rotary->cnt_debounce = bfin_read_CNT_DEBOUNCE(); rotary->cnt_debounce = readw(rotary->base + CNT_DEBOUNCE_OFF);
if (device_may_wakeup(&pdev->dev)) if (device_may_wakeup(&pdev->dev))
enable_irq_wake(rotary->irq); enable_irq_wake(rotary->irq);
...@@ -232,15 +256,15 @@ static int __maybe_unused bfin_rotary_resume(struct device *dev) ...@@ -232,15 +256,15 @@ static int __maybe_unused bfin_rotary_resume(struct device *dev)
struct platform_device *pdev = to_platform_device(dev); struct platform_device *pdev = to_platform_device(dev);
struct bfin_rot *rotary = platform_get_drvdata(pdev); struct bfin_rot *rotary = platform_get_drvdata(pdev);
bfin_write_CNT_DEBOUNCE(rotary->cnt_debounce); writew(rotary->cnt_debounce, rotary->base + CNT_DEBOUNCE_OFF);
bfin_write_CNT_IMASK(rotary->cnt_imask); writew(rotary->cnt_imask, rotary->base + CNT_IMASK_OFF);
bfin_write_CNT_CONFIG(rotary->cnt_config & ~CNTE); writew(rotary->cnt_config & ~CNTE, rotary->base + CNT_CONFIG_OFF);
if (device_may_wakeup(&pdev->dev)) if (device_may_wakeup(&pdev->dev))
disable_irq_wake(rotary->irq); disable_irq_wake(rotary->irq);
if (rotary->cnt_config & CNTE) if (rotary->cnt_config & CNTE)
bfin_write_CNT_CONFIG(rotary->cnt_config); writew(rotary->cnt_config, rotary->base + CNT_CONFIG_OFF);
return 0; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment