diff options
author | Aleksandar Markovic <aleksandar.markovic@imgtec.com> | 2017-08-29 09:53:18 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2017-08-31 12:58:45 -0400 |
commit | 2296eee704e70dac7fef8ac13f2716e4896dd13e (patch) | |
tree | de7658dad8634607a5110f28b54ca7c84ace35e0 | |
parent | ae28d7402a7e7cf3dd0da1f2eb6a52b337873e08 (diff) |
tty: goldfish: Refactor constants to better reflect their nature
Classify constants GOLDFISH_TTY_xxx into two groups: command ids and
register offsets. Apply different naming for register offsets (add
'REG_' after 'GOLDFISH_TTY_' in constant names). Change implementation
to use preprocessor's '#define' statements instead of 'enum'
declaration (as this is more common way of implementation in such
cases).
This makes the driver code easier to follow and hopefully prevents
future bugs.
Signed-off-by: Miodrag Dinic <miodrag.dinic@imgtec.com>
Signed-off-by: Goran Ferenc <goran.ferenc@imgtec.com>
Signed-off-by: Aleksandar Markovic <aleksandar.markovic@imgtec.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r-- | drivers/tty/goldfish.c | 52 |
1 files changed, 25 insertions, 27 deletions
diff --git a/drivers/tty/goldfish.c b/drivers/tty/goldfish.c index 996bd473dd03..011eb5322077 100644 --- a/drivers/tty/goldfish.c +++ b/drivers/tty/goldfish.c | |||
@@ -23,20 +23,18 @@ | |||
23 | #include <linux/module.h> | 23 | #include <linux/module.h> |
24 | #include <linux/goldfish.h> | 24 | #include <linux/goldfish.h> |
25 | 25 | ||
26 | enum { | 26 | /* Goldfish tty register's offsets */ |
27 | GOLDFISH_TTY_PUT_CHAR = 0x00, | 27 | #define GOLDFISH_TTY_REG_BYTES_READY 0x04 |
28 | GOLDFISH_TTY_BYTES_READY = 0x04, | 28 | #define GOLDFISH_TTY_REG_CMD 0x08 |
29 | GOLDFISH_TTY_CMD = 0x08, | 29 | #define GOLDFISH_TTY_REG_DATA_PTR 0x10 |
30 | 30 | #define GOLDFISH_TTY_REG_DATA_LEN 0x14 | |
31 | GOLDFISH_TTY_DATA_PTR = 0x10, | 31 | #define GOLDFISH_TTY_REG_DATA_PTR_HIGH 0x18 |
32 | GOLDFISH_TTY_DATA_LEN = 0x14, | 32 | |
33 | GOLDFISH_TTY_DATA_PTR_HIGH = 0x18, | 33 | /* Goldfish tty commands */ |
34 | 34 | #define GOLDFISH_TTY_CMD_INT_DISABLE 0 | |
35 | GOLDFISH_TTY_CMD_INT_DISABLE = 0, | 35 | #define GOLDFISH_TTY_CMD_INT_ENABLE 1 |
36 | GOLDFISH_TTY_CMD_INT_ENABLE = 1, | 36 | #define GOLDFISH_TTY_CMD_WRITE_BUFFER 2 |
37 | GOLDFISH_TTY_CMD_WRITE_BUFFER = 2, | 37 | #define GOLDFISH_TTY_CMD_READ_BUFFER 3 |
38 | GOLDFISH_TTY_CMD_READ_BUFFER = 3, | ||
39 | }; | ||
40 | 38 | ||
41 | struct goldfish_tty { | 39 | struct goldfish_tty { |
42 | struct tty_port port; | 40 | struct tty_port port; |
@@ -59,10 +57,10 @@ static void goldfish_tty_do_write(int line, const char *buf, unsigned count) | |||
59 | struct goldfish_tty *qtty = &goldfish_ttys[line]; | 57 | struct goldfish_tty *qtty = &goldfish_ttys[line]; |
60 | void __iomem *base = qtty->base; | 58 | void __iomem *base = qtty->base; |
61 | spin_lock_irqsave(&qtty->lock, irq_flags); | 59 | spin_lock_irqsave(&qtty->lock, irq_flags); |
62 | gf_write_ptr(buf, base + GOLDFISH_TTY_DATA_PTR, | 60 | gf_write_ptr(buf, base + GOLDFISH_TTY_REG_DATA_PTR, |
63 | base + GOLDFISH_TTY_DATA_PTR_HIGH); | 61 | base + GOLDFISH_TTY_REG_DATA_PTR_HIGH); |
64 | writel(count, base + GOLDFISH_TTY_DATA_LEN); | 62 | writel(count, base + GOLDFISH_TTY_REG_DATA_LEN); |
65 | writel(GOLDFISH_TTY_CMD_WRITE_BUFFER, base + GOLDFISH_TTY_CMD); | 63 | writel(GOLDFISH_TTY_CMD_WRITE_BUFFER, base + GOLDFISH_TTY_REG_CMD); |
66 | spin_unlock_irqrestore(&qtty->lock, irq_flags); | 64 | spin_unlock_irqrestore(&qtty->lock, irq_flags); |
67 | } | 65 | } |
68 | 66 | ||
@@ -74,16 +72,16 @@ static irqreturn_t goldfish_tty_interrupt(int irq, void *dev_id) | |||
74 | unsigned char *buf; | 72 | unsigned char *buf; |
75 | u32 count; | 73 | u32 count; |
76 | 74 | ||
77 | count = readl(base + GOLDFISH_TTY_BYTES_READY); | 75 | count = readl(base + GOLDFISH_TTY_REG_BYTES_READY); |
78 | if (count == 0) | 76 | if (count == 0) |
79 | return IRQ_NONE; | 77 | return IRQ_NONE; |
80 | 78 | ||
81 | count = tty_prepare_flip_string(&qtty->port, &buf, count); | 79 | count = tty_prepare_flip_string(&qtty->port, &buf, count); |
82 | spin_lock_irqsave(&qtty->lock, irq_flags); | 80 | spin_lock_irqsave(&qtty->lock, irq_flags); |
83 | gf_write_ptr(buf, base + GOLDFISH_TTY_DATA_PTR, | 81 | gf_write_ptr(buf, base + GOLDFISH_TTY_REG_DATA_PTR, |
84 | base + GOLDFISH_TTY_DATA_PTR_HIGH); | 82 | base + GOLDFISH_TTY_REG_DATA_PTR_HIGH); |
85 | writel(count, base + GOLDFISH_TTY_DATA_LEN); | 83 | writel(count, base + GOLDFISH_TTY_REG_DATA_LEN); |
86 | writel(GOLDFISH_TTY_CMD_READ_BUFFER, base + GOLDFISH_TTY_CMD); | 84 | writel(GOLDFISH_TTY_CMD_READ_BUFFER, base + GOLDFISH_TTY_REG_CMD); |
87 | spin_unlock_irqrestore(&qtty->lock, irq_flags); | 85 | spin_unlock_irqrestore(&qtty->lock, irq_flags); |
88 | tty_schedule_flip(&qtty->port); | 86 | tty_schedule_flip(&qtty->port); |
89 | return IRQ_HANDLED; | 87 | return IRQ_HANDLED; |
@@ -93,7 +91,7 @@ static int goldfish_tty_activate(struct tty_port *port, struct tty_struct *tty) | |||
93 | { | 91 | { |
94 | struct goldfish_tty *qtty = container_of(port, struct goldfish_tty, | 92 | struct goldfish_tty *qtty = container_of(port, struct goldfish_tty, |
95 | port); | 93 | port); |
96 | writel(GOLDFISH_TTY_CMD_INT_ENABLE, qtty->base + GOLDFISH_TTY_CMD); | 94 | writel(GOLDFISH_TTY_CMD_INT_ENABLE, qtty->base + GOLDFISH_TTY_REG_CMD); |
97 | return 0; | 95 | return 0; |
98 | } | 96 | } |
99 | 97 | ||
@@ -101,7 +99,7 @@ static void goldfish_tty_shutdown(struct tty_port *port) | |||
101 | { | 99 | { |
102 | struct goldfish_tty *qtty = container_of(port, struct goldfish_tty, | 100 | struct goldfish_tty *qtty = container_of(port, struct goldfish_tty, |
103 | port); | 101 | port); |
104 | writel(GOLDFISH_TTY_CMD_INT_DISABLE, qtty->base + GOLDFISH_TTY_CMD); | 102 | writel(GOLDFISH_TTY_CMD_INT_DISABLE, qtty->base + GOLDFISH_TTY_REG_CMD); |
105 | } | 103 | } |
106 | 104 | ||
107 | static int goldfish_tty_open(struct tty_struct *tty, struct file *filp) | 105 | static int goldfish_tty_open(struct tty_struct *tty, struct file *filp) |
@@ -136,7 +134,7 @@ static int goldfish_tty_chars_in_buffer(struct tty_struct *tty) | |||
136 | { | 134 | { |
137 | struct goldfish_tty *qtty = &goldfish_ttys[tty->index]; | 135 | struct goldfish_tty *qtty = &goldfish_ttys[tty->index]; |
138 | void __iomem *base = qtty->base; | 136 | void __iomem *base = qtty->base; |
139 | return readl(base + GOLDFISH_TTY_BYTES_READY); | 137 | return readl(base + GOLDFISH_TTY_REG_BYTES_READY); |
140 | } | 138 | } |
141 | 139 | ||
142 | static void goldfish_tty_console_write(struct console *co, const char *b, | 140 | static void goldfish_tty_console_write(struct console *co, const char *b, |
@@ -272,7 +270,7 @@ static int goldfish_tty_probe(struct platform_device *pdev) | |||
272 | qtty->base = base; | 270 | qtty->base = base; |
273 | qtty->irq = irq; | 271 | qtty->irq = irq; |
274 | 272 | ||
275 | writel(GOLDFISH_TTY_CMD_INT_DISABLE, base + GOLDFISH_TTY_CMD); | 273 | writel(GOLDFISH_TTY_CMD_INT_DISABLE, base + GOLDFISH_TTY_REG_CMD); |
276 | 274 | ||
277 | ret = request_irq(irq, goldfish_tty_interrupt, IRQF_SHARED, | 275 | ret = request_irq(irq, goldfish_tty_interrupt, IRQF_SHARED, |
278 | "goldfish_tty", qtty); | 276 | "goldfish_tty", qtty); |