diff options
Diffstat (limited to 'drivers/input/keyboard/spear-keyboard.c')
-rw-r--r-- | drivers/input/keyboard/spear-keyboard.c | 137 |
1 files changed, 92 insertions, 45 deletions
diff --git a/drivers/input/keyboard/spear-keyboard.c b/drivers/input/keyboard/spear-keyboard.c index 6f287f7e153..72ef01be336 100644 --- a/drivers/input/keyboard/spear-keyboard.c +++ b/drivers/input/keyboard/spear-keyboard.c @@ -27,33 +27,31 @@ #include <plat/keyboard.h> /* Keyboard Registers */ -#define MODE_REG 0x00 /* 16 bit reg */ -#define STATUS_REG 0x0C /* 2 bit reg */ -#define DATA_REG 0x10 /* 8 bit reg */ +#define MODE_CTL_REG 0x00 +#define STATUS_REG 0x0C +#define DATA_REG 0x10 #define INTR_MASK 0x54 /* Register Values */ -/* - * pclk freq mask = (APB FEQ -1)= 82 MHZ.Programme bit 15-9 in mode - * control register as 1010010(82MHZ) - */ -#define PCLK_FREQ_MSK 0xA400 /* 82 MHz */ -#define START_SCAN 0x0100 -#define SCAN_RATE_10 0x0000 -#define SCAN_RATE_20 0x0004 -#define SCAN_RATE_40 0x0008 -#define SCAN_RATE_80 0x000C -#define MODE_KEYBOARD 0x0002 -#define DATA_AVAIL 0x2 - -#define KEY_MASK 0xFF000000 -#define KEY_VALUE 0x00FFFFFF -#define ROW_MASK 0xF0 -#define COLUMN_MASK 0x0F #define NUM_ROWS 16 #define NUM_COLS 16 +#define MODE_CTL_PCLK_FREQ_SHIFT 9 +#define MODE_CTL_PCLK_FREQ_MSK 0x7F + +#define MODE_CTL_KEYBOARD (0x2 << 0) +#define MODE_CTL_SCAN_RATE_10 (0x0 << 2) +#define MODE_CTL_SCAN_RATE_20 (0x1 << 2) +#define MODE_CTL_SCAN_RATE_40 (0x2 << 2) +#define MODE_CTL_SCAN_RATE_80 (0x3 << 2) +#define MODE_CTL_KEYNUM_SHIFT 6 +#define MODE_CTL_START_SCAN (0x1 << 8) -#define KEY_MATRIX_SHIFT 6 +#define STATUS_DATA_AVAIL (0x1 << 1) + +#define DATA_ROW_MASK 0xF0 +#define DATA_COLUMN_MASK 0x0F + +#define ROW_SHIFT 4 struct spear_kbd { struct input_dev *input; @@ -65,6 +63,8 @@ struct spear_kbd { unsigned short last_key; unsigned short keycodes[NUM_ROWS * NUM_COLS]; bool rep; + unsigned int suspended_rate; + u32 mode_ctl_reg; }; static irqreturn_t spear_kbd_interrupt(int irq, void *dev_id) @@ -72,10 +72,10 @@ static irqreturn_t spear_kbd_interrupt(int irq, void *dev_id) struct spear_kbd *kbd = dev_id; struct input_dev *input = kbd->input; unsigned int key; - u8 sts, val; + u32 sts, val; - sts = readb(kbd->io_base + STATUS_REG); - if (!(sts & DATA_AVAIL)) + sts = readl_relaxed(kbd->io_base + STATUS_REG); + if (!(sts & STATUS_DATA_AVAIL)) return IRQ_NONE; if (kbd->last_key != KEY_RESERVED) { @@ -84,7 +84,8 @@ static irqreturn_t spear_kbd_interrupt(int irq, void *dev_id) } /* following reads active (row, col) pair */ - val = readb(kbd->io_base + DATA_REG); + val = readl_relaxed(kbd->io_base + DATA_REG) & + (DATA_ROW_MASK | DATA_COLUMN_MASK); key = kbd->keycodes[val]; input_event(input, EV_MSC, MSC_SCAN, val); @@ -94,7 +95,7 @@ static irqreturn_t spear_kbd_interrupt(int irq, void *dev_id) kbd->last_key = key; /* clear interrupt */ - writeb(0, kbd->io_base + STATUS_REG); + writel_relaxed(0, kbd->io_base + STATUS_REG); return IRQ_HANDLED; } @@ -103,7 +104,7 @@ static int spear_kbd_open(struct input_dev *dev) { struct spear_kbd *kbd = input_get_drvdata(dev); int error; - u16 val; + u32 val; kbd->last_key = KEY_RESERVED; @@ -111,16 +112,20 @@ static int spear_kbd_open(struct input_dev *dev) if (error) return error; + /* keyboard rate to be programmed is input clock (in MHz) - 1 */ + val = clk_get_rate(kbd->clk) / 1000000 - 1; + val = (val & MODE_CTL_PCLK_FREQ_MSK) << MODE_CTL_PCLK_FREQ_SHIFT; + /* program keyboard */ - val = SCAN_RATE_80 | MODE_KEYBOARD | PCLK_FREQ_MSK | - (kbd->mode << KEY_MATRIX_SHIFT); - writew(val, kbd->io_base + MODE_REG); - writeb(1, kbd->io_base + STATUS_REG); + val = MODE_CTL_SCAN_RATE_80 | MODE_CTL_KEYBOARD | val | + (kbd->mode << MODE_CTL_KEYNUM_SHIFT); + writel_relaxed(val, kbd->io_base + MODE_CTL_REG); + writel_relaxed(1, kbd->io_base + STATUS_REG); /* start key scan */ - val = readw(kbd->io_base + MODE_REG); - val |= START_SCAN; - writew(val, kbd->io_base + MODE_REG); + val = readl_relaxed(kbd->io_base + MODE_CTL_REG); + val |= MODE_CTL_START_SCAN; + writel_relaxed(val, kbd->io_base + MODE_CTL_REG); return 0; } @@ -128,12 +133,12 @@ static int spear_kbd_open(struct input_dev *dev) static void spear_kbd_close(struct input_dev *dev) { struct spear_kbd *kbd = input_get_drvdata(dev); - u16 val; + u32 val; /* stop key scan */ - val = readw(kbd->io_base + MODE_REG); - val &= ~START_SCAN; - writew(val, kbd->io_base + MODE_REG); + val = readl_relaxed(kbd->io_base + MODE_CTL_REG); + val &= ~MODE_CTL_START_SCAN; + writel_relaxed(val, kbd->io_base + MODE_CTL_REG); clk_disable(kbd->clk); @@ -146,7 +151,7 @@ static int __devinit spear_kbd_parse_dt(struct platform_device *pdev, { struct device_node *np = pdev->dev.of_node; int error; - u32 val; + u32 val, suspended_rate; if (!np) { dev_err(&pdev->dev, "Missing DT data\n"); @@ -156,6 +161,9 @@ static int __devinit spear_kbd_parse_dt(struct platform_device *pdev, if (of_property_read_bool(np, "autorepeat")) kbd->rep = true; + if (of_property_read_u32(np, "suspended_rate", &suspended_rate)) + kbd->suspended_rate = suspended_rate; + error = of_property_read_u32(np, "st,mode", &val); if (error) { dev_err(&pdev->dev, "DT: Invalid or missing mode\n"); @@ -213,6 +221,7 @@ static int __devinit spear_kbd_probe(struct platform_device *pdev) } else { kbd->mode = pdata->mode; kbd->rep = pdata->rep; + kbd->suspended_rate = pdata->suspended_rate; } kbd->res = request_mem_region(res->start, resource_size(res), @@ -302,7 +311,7 @@ static int __devexit spear_kbd_remove(struct platform_device *pdev) release_mem_region(kbd->res->start, resource_size(kbd->res)); kfree(kbd); - device_init_wakeup(&pdev->dev, 1); + device_init_wakeup(&pdev->dev, 0); platform_set_drvdata(pdev, NULL); return 0; @@ -314,15 +323,48 @@ static int spear_kbd_suspend(struct device *dev) struct platform_device *pdev = to_platform_device(dev); struct spear_kbd *kbd = platform_get_drvdata(pdev); struct input_dev *input_dev = kbd->input; + unsigned int rate = 0, mode_ctl_reg, val; mutex_lock(&input_dev->mutex); - if (input_dev->users) - clk_enable(kbd->clk); + /* explicitly enable clock as we may program device */ + clk_enable(kbd->clk); - if (device_may_wakeup(&pdev->dev)) + mode_ctl_reg = readl_relaxed(kbd->io_base + MODE_CTL_REG); + + if (device_may_wakeup(&pdev->dev)) { enable_irq_wake(kbd->irq); + /* + * reprogram the keyboard operating frequency as on some + * platform it may change during system suspended + */ + if (kbd->suspended_rate) + rate = kbd->suspended_rate / 1000000 - 1; + else + rate = clk_get_rate(kbd->clk) / 1000000 - 1; + + val = mode_ctl_reg & + ~(MODE_CTL_PCLK_FREQ_MSK << MODE_CTL_PCLK_FREQ_SHIFT); + val |= (rate & MODE_CTL_PCLK_FREQ_MSK) + << MODE_CTL_PCLK_FREQ_SHIFT; + writel_relaxed(val, kbd->io_base + MODE_CTL_REG); + + } else { + if (input_dev->users) { + writel_relaxed(mode_ctl_reg & ~MODE_CTL_START_SCAN, + kbd->io_base + MODE_CTL_REG); + clk_disable(kbd->clk); + } + } + + /* store current configuration */ + if (input_dev->users) + kbd->mode_ctl_reg = mode_ctl_reg; + + /* restore previous clk state */ + clk_disable(kbd->clk); + mutex_unlock(&input_dev->mutex); return 0; @@ -336,11 +378,16 @@ static int spear_kbd_resume(struct device *dev) mutex_lock(&input_dev->mutex); - if (device_may_wakeup(&pdev->dev)) + if (device_may_wakeup(&pdev->dev)) { disable_irq_wake(kbd->irq); + } else { + if (input_dev->users) + clk_enable(kbd->clk); + } + /* restore current configuration */ if (input_dev->users) - clk_enable(kbd->clk); + writel_relaxed(kbd->mode_ctl_reg, kbd->io_base + MODE_CTL_REG); mutex_unlock(&input_dev->mutex); |