diff options
| -rw-r--r-- | drivers/tty/goldfish.c | 60 |
1 files changed, 34 insertions, 26 deletions
diff --git a/drivers/tty/goldfish.c b/drivers/tty/goldfish.c index 7eaafe3c80dc..09495f515fa9 100644 --- a/drivers/tty/goldfish.c +++ b/drivers/tty/goldfish.c | |||
| @@ -76,7 +76,7 @@ static irqreturn_t goldfish_tty_interrupt(int irq, void *dev_id) | |||
| 76 | u32 count; | 76 | u32 count; |
| 77 | 77 | ||
| 78 | count = readl(base + GOLDFISH_TTY_BYTES_READY); | 78 | count = readl(base + GOLDFISH_TTY_BYTES_READY); |
| 79 | if(count == 0) | 79 | if (count == 0) |
| 80 | return IRQ_NONE; | 80 | return IRQ_NONE; |
| 81 | 81 | ||
| 82 | count = tty_prepare_flip_string(&qtty->port, &buf, count); | 82 | count = tty_prepare_flip_string(&qtty->port, &buf, count); |
| @@ -92,24 +92,26 @@ static irqreturn_t goldfish_tty_interrupt(int irq, void *dev_id) | |||
| 92 | 92 | ||
| 93 | static int goldfish_tty_activate(struct tty_port *port, struct tty_struct *tty) | 93 | static int goldfish_tty_activate(struct tty_port *port, struct tty_struct *tty) |
| 94 | { | 94 | { |
| 95 | struct goldfish_tty *qtty = container_of(port, struct goldfish_tty, port); | 95 | struct goldfish_tty *qtty = container_of(port, struct goldfish_tty, |
| 96 | port); | ||
| 96 | writel(GOLDFISH_TTY_CMD_INT_ENABLE, qtty->base + GOLDFISH_TTY_CMD); | 97 | writel(GOLDFISH_TTY_CMD_INT_ENABLE, qtty->base + GOLDFISH_TTY_CMD); |
| 97 | return 0; | 98 | return 0; |
| 98 | } | 99 | } |
| 99 | 100 | ||
| 100 | static void goldfish_tty_shutdown(struct tty_port *port) | 101 | static void goldfish_tty_shutdown(struct tty_port *port) |
| 101 | { | 102 | { |
| 102 | struct goldfish_tty *qtty = container_of(port, struct goldfish_tty, port); | 103 | struct goldfish_tty *qtty = container_of(port, struct goldfish_tty, |
| 104 | port); | ||
| 103 | writel(GOLDFISH_TTY_CMD_INT_DISABLE, qtty->base + GOLDFISH_TTY_CMD); | 105 | writel(GOLDFISH_TTY_CMD_INT_DISABLE, qtty->base + GOLDFISH_TTY_CMD); |
| 104 | } | 106 | } |
| 105 | 107 | ||
| 106 | static int goldfish_tty_open(struct tty_struct * tty, struct file * filp) | 108 | static int goldfish_tty_open(struct tty_struct *tty, struct file *filp) |
| 107 | { | 109 | { |
| 108 | struct goldfish_tty *qtty = &goldfish_ttys[tty->index]; | 110 | struct goldfish_tty *qtty = &goldfish_ttys[tty->index]; |
| 109 | return tty_port_open(&qtty->port, tty, filp); | 111 | return tty_port_open(&qtty->port, tty, filp); |
| 110 | } | 112 | } |
| 111 | 113 | ||
| 112 | static void goldfish_tty_close(struct tty_struct * tty, struct file * filp) | 114 | static void goldfish_tty_close(struct tty_struct *tty, struct file *filp) |
| 113 | { | 115 | { |
| 114 | tty_port_close(tty->port, tty, filp); | 116 | tty_port_close(tty->port, tty, filp); |
| 115 | } | 117 | } |
| @@ -119,7 +121,8 @@ static void goldfish_tty_hangup(struct tty_struct *tty) | |||
| 119 | tty_port_hangup(tty->port); | 121 | tty_port_hangup(tty->port); |
| 120 | } | 122 | } |
| 121 | 123 | ||
| 122 | static int goldfish_tty_write(struct tty_struct * tty, const unsigned char *buf, int count) | 124 | static int goldfish_tty_write(struct tty_struct *tty, const unsigned char *buf, |
| 125 | int count) | ||
| 123 | { | 126 | { |
| 124 | goldfish_tty_do_write(tty->index, buf, count); | 127 | goldfish_tty_do_write(tty->index, buf, count); |
| 125 | return count; | 128 | return count; |
| @@ -137,12 +140,14 @@ static int goldfish_tty_chars_in_buffer(struct tty_struct *tty) | |||
| 137 | return readl(base + GOLDFISH_TTY_BYTES_READY); | 140 | return readl(base + GOLDFISH_TTY_BYTES_READY); |
| 138 | } | 141 | } |
| 139 | 142 | ||
| 140 | static void goldfish_tty_console_write(struct console *co, const char *b, unsigned count) | 143 | static void goldfish_tty_console_write(struct console *co, const char *b, |
| 144 | unsigned count) | ||
| 141 | { | 145 | { |
| 142 | goldfish_tty_do_write(co->index, b, count); | 146 | goldfish_tty_do_write(co->index, b, count); |
| 143 | } | 147 | } |
| 144 | 148 | ||
| 145 | static struct tty_driver *goldfish_tty_console_device(struct console *c, int *index) | 149 | static struct tty_driver *goldfish_tty_console_device(struct console *c, |
| 150 | int *index) | ||
| 146 | { | 151 | { |
| 147 | *index = c->index; | 152 | *index = c->index; |
| 148 | return goldfish_tty_driver; | 153 | return goldfish_tty_driver; |
| @@ -150,9 +155,9 @@ static struct tty_driver *goldfish_tty_console_device(struct console *c, int *in | |||
| 150 | 155 | ||
| 151 | static int goldfish_tty_console_setup(struct console *co, char *options) | 156 | static int goldfish_tty_console_setup(struct console *co, char *options) |
| 152 | { | 157 | { |
| 153 | if((unsigned)co->index > goldfish_tty_line_count) | 158 | if ((unsigned)co->index > goldfish_tty_line_count) |
| 154 | return -ENODEV; | 159 | return -ENODEV; |
| 155 | if(goldfish_ttys[co->index].base == 0) | 160 | if (goldfish_ttys[co->index].base == 0) |
| 156 | return -ENODEV; | 161 | return -ENODEV; |
| 157 | return 0; | 162 | return 0; |
| 158 | } | 163 | } |
| @@ -162,7 +167,7 @@ static struct tty_port_operations goldfish_port_ops = { | |||
| 162 | .shutdown = goldfish_tty_shutdown | 167 | .shutdown = goldfish_tty_shutdown |
| 163 | }; | 168 | }; |
| 164 | 169 | ||
| 165 | static struct tty_operations goldfish_tty_ops = { | 170 | static const struct tty_operations goldfish_tty_ops = { |
| 166 | .open = goldfish_tty_open, | 171 | .open = goldfish_tty_open, |
| 167 | .close = goldfish_tty_close, | 172 | .close = goldfish_tty_close, |
| 168 | .hangup = goldfish_tty_hangup, | 173 | .hangup = goldfish_tty_hangup, |
| @@ -176,13 +181,14 @@ static int goldfish_tty_create_driver(void) | |||
| 176 | int ret; | 181 | int ret; |
| 177 | struct tty_driver *tty; | 182 | struct tty_driver *tty; |
| 178 | 183 | ||
| 179 | goldfish_ttys = kzalloc(sizeof(*goldfish_ttys) * goldfish_tty_line_count, GFP_KERNEL); | 184 | goldfish_ttys = kzalloc(sizeof(*goldfish_ttys) * |
| 180 | if(goldfish_ttys == NULL) { | 185 | goldfish_tty_line_count, GFP_KERNEL); |
| 186 | if (goldfish_ttys == NULL) { | ||
| 181 | ret = -ENOMEM; | 187 | ret = -ENOMEM; |
| 182 | goto err_alloc_goldfish_ttys_failed; | 188 | goto err_alloc_goldfish_ttys_failed; |
| 183 | } | 189 | } |
| 184 | tty = alloc_tty_driver(goldfish_tty_line_count); | 190 | tty = alloc_tty_driver(goldfish_tty_line_count); |
| 185 | if(tty == NULL) { | 191 | if (tty == NULL) { |
| 186 | ret = -ENOMEM; | 192 | ret = -ENOMEM; |
| 187 | goto err_alloc_tty_driver_failed; | 193 | goto err_alloc_tty_driver_failed; |
| 188 | } | 194 | } |
| @@ -191,10 +197,11 @@ static int goldfish_tty_create_driver(void) | |||
| 191 | tty->type = TTY_DRIVER_TYPE_SERIAL; | 197 | tty->type = TTY_DRIVER_TYPE_SERIAL; |
| 192 | tty->subtype = SERIAL_TYPE_NORMAL; | 198 | tty->subtype = SERIAL_TYPE_NORMAL; |
| 193 | tty->init_termios = tty_std_termios; | 199 | tty->init_termios = tty_std_termios; |
| 194 | tty->flags = TTY_DRIVER_RESET_TERMIOS | TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV; | 200 | tty->flags = TTY_DRIVER_RESET_TERMIOS | TTY_DRIVER_REAL_RAW | |
| 201 | TTY_DRIVER_DYNAMIC_DEV; | ||
| 195 | tty_set_operations(tty, &goldfish_tty_ops); | 202 | tty_set_operations(tty, &goldfish_tty_ops); |
| 196 | ret = tty_register_driver(tty); | 203 | ret = tty_register_driver(tty); |
| 197 | if(ret) | 204 | if (ret) |
| 198 | goto err_tty_register_driver_failed; | 205 | goto err_tty_register_driver_failed; |
| 199 | 206 | ||
| 200 | goldfish_tty_driver = tty; | 207 | goldfish_tty_driver = tty; |
| @@ -229,7 +236,7 @@ static int goldfish_tty_probe(struct platform_device *pdev) | |||
| 229 | u32 irq; | 236 | u32 irq; |
| 230 | 237 | ||
| 231 | r = platform_get_resource(pdev, IORESOURCE_MEM, 0); | 238 | r = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 232 | if(r == NULL) | 239 | if (r == NULL) |
| 233 | return -EINVAL; | 240 | return -EINVAL; |
| 234 | 241 | ||
| 235 | base = ioremap(r->start, 0x1000); | 242 | base = ioremap(r->start, 0x1000); |
| @@ -237,18 +244,18 @@ static int goldfish_tty_probe(struct platform_device *pdev) | |||
| 237 | pr_err("goldfish_tty: unable to remap base\n"); | 244 | pr_err("goldfish_tty: unable to remap base\n"); |
| 238 | 245 | ||
| 239 | r = platform_get_resource(pdev, IORESOURCE_IRQ, 0); | 246 | r = platform_get_resource(pdev, IORESOURCE_IRQ, 0); |
| 240 | if(r == NULL) | 247 | if (r == NULL) |
| 241 | goto err_unmap; | 248 | goto err_unmap; |
| 242 | 249 | ||
| 243 | irq = r->start; | 250 | irq = r->start; |
| 244 | 251 | ||
| 245 | if(pdev->id >= goldfish_tty_line_count) | 252 | if (pdev->id >= goldfish_tty_line_count) |
| 246 | goto err_unmap; | 253 | goto err_unmap; |
| 247 | 254 | ||
| 248 | mutex_lock(&goldfish_tty_lock); | 255 | mutex_lock(&goldfish_tty_lock); |
| 249 | if(goldfish_tty_current_line_count == 0) { | 256 | if (goldfish_tty_current_line_count == 0) { |
| 250 | ret = goldfish_tty_create_driver(); | 257 | ret = goldfish_tty_create_driver(); |
| 251 | if(ret) | 258 | if (ret) |
| 252 | goto err_create_driver_failed; | 259 | goto err_create_driver_failed; |
| 253 | } | 260 | } |
| 254 | goldfish_tty_current_line_count++; | 261 | goldfish_tty_current_line_count++; |
| @@ -262,14 +269,15 @@ static int goldfish_tty_probe(struct platform_device *pdev) | |||
| 262 | 269 | ||
| 263 | writel(GOLDFISH_TTY_CMD_INT_DISABLE, base + GOLDFISH_TTY_CMD); | 270 | writel(GOLDFISH_TTY_CMD_INT_DISABLE, base + GOLDFISH_TTY_CMD); |
| 264 | 271 | ||
| 265 | ret = request_irq(irq, goldfish_tty_interrupt, IRQF_SHARED, "goldfish_tty", pdev); | 272 | ret = request_irq(irq, goldfish_tty_interrupt, IRQF_SHARED, |
| 266 | if(ret) | 273 | "goldfish_tty", pdev); |
| 274 | if (ret) | ||
| 267 | goto err_request_irq_failed; | 275 | goto err_request_irq_failed; |
| 268 | 276 | ||
| 269 | 277 | ||
| 270 | ttydev = tty_port_register_device(&qtty->port, goldfish_tty_driver, | 278 | ttydev = tty_port_register_device(&qtty->port, goldfish_tty_driver, |
| 271 | pdev->id, &pdev->dev); | 279 | pdev->id, &pdev->dev); |
| 272 | if(IS_ERR(ttydev)) { | 280 | if (IS_ERR(ttydev)) { |
| 273 | ret = PTR_ERR(ttydev); | 281 | ret = PTR_ERR(ttydev); |
| 274 | goto err_tty_register_device_failed; | 282 | goto err_tty_register_device_failed; |
| 275 | } | 283 | } |
| @@ -290,7 +298,7 @@ err_tty_register_device_failed: | |||
| 290 | free_irq(irq, pdev); | 298 | free_irq(irq, pdev); |
| 291 | err_request_irq_failed: | 299 | err_request_irq_failed: |
| 292 | goldfish_tty_current_line_count--; | 300 | goldfish_tty_current_line_count--; |
| 293 | if(goldfish_tty_current_line_count == 0) | 301 | if (goldfish_tty_current_line_count == 0) |
| 294 | goldfish_tty_delete_driver(); | 302 | goldfish_tty_delete_driver(); |
| 295 | err_create_driver_failed: | 303 | err_create_driver_failed: |
| 296 | mutex_unlock(&goldfish_tty_lock); | 304 | mutex_unlock(&goldfish_tty_lock); |
| @@ -312,7 +320,7 @@ static int goldfish_tty_remove(struct platform_device *pdev) | |||
| 312 | qtty->base = 0; | 320 | qtty->base = 0; |
| 313 | free_irq(qtty->irq, pdev); | 321 | free_irq(qtty->irq, pdev); |
| 314 | goldfish_tty_current_line_count--; | 322 | goldfish_tty_current_line_count--; |
| 315 | if(goldfish_tty_current_line_count == 0) | 323 | if (goldfish_tty_current_line_count == 0) |
| 316 | goldfish_tty_delete_driver(); | 324 | goldfish_tty_delete_driver(); |
| 317 | mutex_unlock(&goldfish_tty_lock); | 325 | mutex_unlock(&goldfish_tty_lock); |
| 318 | return 0; | 326 | return 0; |
