10 #include <linux/kernel.h>
11 #include <linux/module.h>
12 #include <linux/device.h>
14 #include <linux/serio.h>
21 #include <linux/slab.h>
34 #define PSIF_CR_RXDIS_OFFSET 1
35 #define PSIF_CR_RXDIS_SIZE 1
36 #define PSIF_CR_RXEN_OFFSET 0
37 #define PSIF_CR_RXEN_SIZE 1
38 #define PSIF_CR_SWRST_OFFSET 15
39 #define PSIF_CR_SWRST_SIZE 1
40 #define PSIF_CR_TXDIS_OFFSET 9
41 #define PSIF_CR_TXDIS_SIZE 1
42 #define PSIF_CR_TXEN_OFFSET 8
43 #define PSIF_CR_TXEN_SIZE 1
46 #define PSIF_NACK_OFFSET 8
47 #define PSIF_NACK_SIZE 1
48 #define PSIF_OVRUN_OFFSET 5
49 #define PSIF_OVRUN_SIZE 1
50 #define PSIF_PARITY_OFFSET 9
51 #define PSIF_PARITY_SIZE 1
52 #define PSIF_RXRDY_OFFSET 4
53 #define PSIF_RXRDY_SIZE 1
54 #define PSIF_TXEMPTY_OFFSET 1
55 #define PSIF_TXEMPTY_SIZE 1
56 #define PSIF_TXRDY_OFFSET 0
57 #define PSIF_TXRDY_SIZE 1
60 #define PSIF_PSR_PRSCV_OFFSET 0
61 #define PSIF_PSR_PRSCV_SIZE 12
64 #define PSIF_RHR_RXDATA_OFFSET 0
65 #define PSIF_RHR_RXDATA_SIZE 8
68 #define PSIF_THR_TXDATA_OFFSET 0
69 #define PSIF_THR_TXDATA_SIZE 8
72 #define PSIF_BIT(name) \
73 (1 << PSIF_##name##_OFFSET)
75 #define PSIF_BF(name, value) \
76 (((value) & ((1 << PSIF_##name##_SIZE) - 1)) \
77 << PSIF_##name##_OFFSET)
79 #define PSIF_BFEXT(name, value) \
80 (((value) >> PSIF_##name##_OFFSET) \
81 & ((1 << PSIF_##name##_SIZE) - 1))
83 #define PSIF_BFINS(name, value, old) \
84 (((old) & ~(((1 << PSIF_##name##_SIZE) - 1) \
85 << PSIF_##name##_OFFSET)) \
86 | PSIF_BF(name, value))
89 #define psif_readl(port, reg) \
90 __raw_readl((port)->regs + PSIF_##reg)
92 #define psif_writel(port, reg, value) \
93 __raw_writel((value), (port)->regs + PSIF_##reg)
106 static irqreturn_t psif_interrupt(
int irq,
void *_ptr)
110 unsigned int io_flags = 0;
131 static int psif_write(
struct serio *
io,
unsigned char val)
146 dev_dbg(&psif->
pdev->dev,
"timeout writing to THR\n");
150 spin_unlock_irqrestore(&psif->
lock, flags);
155 static int psif_open(
struct serio *io)
172 static void psif_close(
struct serio *io)
184 static void psif_set_prescaler(
struct psif *psif)
190 prscv = 100 * (rate / 1000000
UL);
195 "prescaler set to max\n");
212 psif = kzalloc(
sizeof(
struct psif),
GFP_KERNEL);
230 dev_dbg(&pdev->
dev,
"no mmio resources defined\n");
238 dev_dbg(&pdev->
dev,
"could not map I/O memory\n");
244 dev_dbg(&pdev->
dev,
"could not get peripheral clock\n");
253 dev_dbg(&pdev->
dev,
"could not enable pclk\n");
267 dev_dbg(&pdev->
dev,
"could not request irq %d\n", irq);
273 io->
write = psif_write;
274 io->
open = psif_open;
275 io->
close = psif_close;
279 io->
dev.parent = &pdev->
dev;
281 psif_set_prescaler(psif);
285 platform_set_drvdata(pdev, psif);
287 dev_info(&pdev->
dev,
"Atmel AVR32 PSIF PS/2 driver on 0x%08x irq %d\n",
306 struct psif *psif = platform_get_drvdata(pdev);
317 platform_set_drvdata(pdev,
NULL);
322 #ifdef CONFIG_PM_SLEEP
323 static int psif_suspend(
struct device *
dev)
326 struct psif *psif = platform_get_drvdata(pdev);
336 static int psif_resume(
struct device *dev)
339 struct psif *psif = platform_get_drvdata(pdev);
343 psif_set_prescaler(psif);
356 .name =
"atmel_psif",
362 static int __init psif_init(
void)
367 static void __exit psif_exit(
void)