blob: 1c1bd0afcd489e5eef35d6c4b32a8d018e1cc25c [file] [log] [blame]
Greg Kroah-Hartmane3b3d0f2017-11-06 18:11:51 +01001// SPDX-License-Identifier: GPL-2.0
Arve Hjønnevåg666b7792013-01-21 23:38:47 +00002/*
3 * Copyright (C) 2007 Google, Inc.
4 * Copyright (C) 2012 Intel, Inc.
Miodrag Dinic3840ed92017-08-29 15:53:20 +02005 * Copyright (C) 2017 Imagination Technologies Ltd.
Arve Hjønnevåg666b7792013-01-21 23:38:47 +00006 */
7
8#include <linux/console.h>
Arve Hjønnevåg666b7792013-01-21 23:38:47 +00009#include <linux/interrupt.h>
10#include <linux/platform_device.h>
11#include <linux/tty.h>
12#include <linux/tty_flip.h>
13#include <linux/slab.h>
14#include <linux/io.h>
15#include <linux/module.h>
Alane0f682e2014-05-12 16:57:05 +010016#include <linux/goldfish.h>
Miodrag Dinic7157d2b2017-08-29 15:53:19 +020017#include <linux/mm.h>
18#include <linux/dma-mapping.h>
Miodrag Dinic3840ed92017-08-29 15:53:20 +020019#include <linux/serial_core.h>
Arve Hjønnevåg666b7792013-01-21 23:38:47 +000020
Aleksandar Markovic2296eee2017-08-29 15:53:18 +020021/* Goldfish tty register's offsets */
22#define GOLDFISH_TTY_REG_BYTES_READY 0x04
23#define GOLDFISH_TTY_REG_CMD 0x08
24#define GOLDFISH_TTY_REG_DATA_PTR 0x10
25#define GOLDFISH_TTY_REG_DATA_LEN 0x14
26#define GOLDFISH_TTY_REG_DATA_PTR_HIGH 0x18
Miodrag Dinic7157d2b2017-08-29 15:53:19 +020027#define GOLDFISH_TTY_REG_VERSION 0x20
Arve Hjønnevåg666b7792013-01-21 23:38:47 +000028
Aleksandar Markovic2296eee2017-08-29 15:53:18 +020029/* Goldfish tty commands */
30#define GOLDFISH_TTY_CMD_INT_DISABLE 0
31#define GOLDFISH_TTY_CMD_INT_ENABLE 1
32#define GOLDFISH_TTY_CMD_WRITE_BUFFER 2
33#define GOLDFISH_TTY_CMD_READ_BUFFER 3
Arve Hjønnevåg666b7792013-01-21 23:38:47 +000034
35struct goldfish_tty {
36 struct tty_port port;
37 spinlock_t lock;
38 void __iomem *base;
39 u32 irq;
40 int opencount;
41 struct console console;
Miodrag Dinic7157d2b2017-08-29 15:53:19 +020042 u32 version;
43 struct device *dev;
Arve Hjønnevåg666b7792013-01-21 23:38:47 +000044};
45
46static DEFINE_MUTEX(goldfish_tty_lock);
47static struct tty_driver *goldfish_tty_driver;
48static u32 goldfish_tty_line_count = 8;
49static u32 goldfish_tty_current_line_count;
50static struct goldfish_tty *goldfish_ttys;
51
Miodrag Dinic7157d2b2017-08-29 15:53:19 +020052static void do_rw_io(struct goldfish_tty *qtty,
53 unsigned long address,
54 unsigned int count,
55 int is_write)
Arve Hjønnevåg666b7792013-01-21 23:38:47 +000056{
57 unsigned long irq_flags;
Arve Hjønnevåg666b7792013-01-21 23:38:47 +000058 void __iomem *base = qtty->base;
Miodrag Dinic7157d2b2017-08-29 15:53:19 +020059
Arve Hjønnevåg666b7792013-01-21 23:38:47 +000060 spin_lock_irqsave(&qtty->lock, irq_flags);
Miodrag Dinic7157d2b2017-08-29 15:53:19 +020061 gf_write_ptr((void *)address, base + GOLDFISH_TTY_REG_DATA_PTR,
Aleksandar Markovic2296eee2017-08-29 15:53:18 +020062 base + GOLDFISH_TTY_REG_DATA_PTR_HIGH);
63 writel(count, base + GOLDFISH_TTY_REG_DATA_LEN);
Miodrag Dinic7157d2b2017-08-29 15:53:19 +020064
65 if (is_write)
66 writel(GOLDFISH_TTY_CMD_WRITE_BUFFER,
67 base + GOLDFISH_TTY_REG_CMD);
68 else
69 writel(GOLDFISH_TTY_CMD_READ_BUFFER,
70 base + GOLDFISH_TTY_REG_CMD);
71
Arve Hjønnevåg666b7792013-01-21 23:38:47 +000072 spin_unlock_irqrestore(&qtty->lock, irq_flags);
73}
74
Miodrag Dinic7157d2b2017-08-29 15:53:19 +020075static void goldfish_tty_rw(struct goldfish_tty *qtty,
76 unsigned long addr,
77 unsigned int count,
78 int is_write)
79{
80 dma_addr_t dma_handle;
81 enum dma_data_direction dma_dir;
82
83 dma_dir = (is_write ? DMA_TO_DEVICE : DMA_FROM_DEVICE);
84 if (qtty->version > 0) {
85 /*
86 * Goldfish TTY for Ranchu platform uses
87 * physical addresses and DMA for read/write operations
88 */
89 unsigned long addr_end = addr + count;
90
91 while (addr < addr_end) {
92 unsigned long pg_end = (addr & PAGE_MASK) + PAGE_SIZE;
93 unsigned long next =
94 pg_end < addr_end ? pg_end : addr_end;
95 unsigned long avail = next - addr;
96
97 /*
98 * Map the buffer's virtual address to the DMA address
99 * so the buffer can be accessed by the device.
100 */
101 dma_handle = dma_map_single(qtty->dev, (void *)addr,
102 avail, dma_dir);
103
104 if (dma_mapping_error(qtty->dev, dma_handle)) {
105 dev_err(qtty->dev, "tty: DMA mapping error.\n");
106 return;
107 }
108 do_rw_io(qtty, dma_handle, avail, is_write);
109
110 /*
111 * Unmap the previously mapped region after
112 * the completion of the read/write operation.
113 */
114 dma_unmap_single(qtty->dev, dma_handle, avail, dma_dir);
115
116 addr += avail;
117 }
118 } else {
119 /*
120 * Old style Goldfish TTY used on the Goldfish platform
121 * uses virtual addresses.
122 */
123 do_rw_io(qtty, addr, count, is_write);
124 }
125}
126
127static void goldfish_tty_do_write(int line, const char *buf,
128 unsigned int count)
129{
130 struct goldfish_tty *qtty = &goldfish_ttys[line];
131 unsigned long address = (unsigned long)(void *)buf;
132
133 goldfish_tty_rw(qtty, address, count, 1);
134}
135
Arve Hjønnevåg666b7792013-01-21 23:38:47 +0000136static irqreturn_t goldfish_tty_interrupt(int irq, void *dev_id)
137{
Greg Hackmann465893e2016-02-26 19:01:05 +0000138 struct goldfish_tty *qtty = dev_id;
Arve Hjønnevåg666b7792013-01-21 23:38:47 +0000139 void __iomem *base = qtty->base;
Miodrag Dinic7157d2b2017-08-29 15:53:19 +0200140 unsigned long address;
Arve Hjønnevåg666b7792013-01-21 23:38:47 +0000141 unsigned char *buf;
142 u32 count;
Arve Hjønnevåg666b7792013-01-21 23:38:47 +0000143
Aleksandar Markovic2296eee2017-08-29 15:53:18 +0200144 count = readl(base + GOLDFISH_TTY_REG_BYTES_READY);
Aland78055d2014-05-12 16:57:14 +0100145 if (count == 0)
Arve Hjønnevåg666b7792013-01-21 23:38:47 +0000146 return IRQ_NONE;
147
Alan Coxebcf0982013-01-25 15:05:30 +0000148 count = tty_prepare_flip_string(&qtty->port, &buf, count);
Miodrag Dinic7157d2b2017-08-29 15:53:19 +0200149
150 address = (unsigned long)(void *)buf;
151 goldfish_tty_rw(qtty, address, count, 0);
152
Alan Coxebcf0982013-01-25 15:05:30 +0000153 tty_schedule_flip(&qtty->port);
Arve Hjønnevåg666b7792013-01-21 23:38:47 +0000154 return IRQ_HANDLED;
155}
156
157static int goldfish_tty_activate(struct tty_port *port, struct tty_struct *tty)
158{
Aland78055d2014-05-12 16:57:14 +0100159 struct goldfish_tty *qtty = container_of(port, struct goldfish_tty,
160 port);
Aleksandar Markovic2296eee2017-08-29 15:53:18 +0200161 writel(GOLDFISH_TTY_CMD_INT_ENABLE, qtty->base + GOLDFISH_TTY_REG_CMD);
Arve Hjønnevåg666b7792013-01-21 23:38:47 +0000162 return 0;
163}
164
165static void goldfish_tty_shutdown(struct tty_port *port)
166{
Aland78055d2014-05-12 16:57:14 +0100167 struct goldfish_tty *qtty = container_of(port, struct goldfish_tty,
168 port);
Aleksandar Markovic2296eee2017-08-29 15:53:18 +0200169 writel(GOLDFISH_TTY_CMD_INT_DISABLE, qtty->base + GOLDFISH_TTY_REG_CMD);
Arve Hjønnevåg666b7792013-01-21 23:38:47 +0000170}
171
Aland78055d2014-05-12 16:57:14 +0100172static int goldfish_tty_open(struct tty_struct *tty, struct file *filp)
Arve Hjønnevåg666b7792013-01-21 23:38:47 +0000173{
174 struct goldfish_tty *qtty = &goldfish_ttys[tty->index];
175 return tty_port_open(&qtty->port, tty, filp);
176}
177
Aland78055d2014-05-12 16:57:14 +0100178static void goldfish_tty_close(struct tty_struct *tty, struct file *filp)
Arve Hjønnevåg666b7792013-01-21 23:38:47 +0000179{
180 tty_port_close(tty->port, tty, filp);
181}
182
183static void goldfish_tty_hangup(struct tty_struct *tty)
184{
185 tty_port_hangup(tty->port);
186}
187
Aland78055d2014-05-12 16:57:14 +0100188static int goldfish_tty_write(struct tty_struct *tty, const unsigned char *buf,
189 int count)
Arve Hjønnevåg666b7792013-01-21 23:38:47 +0000190{
191 goldfish_tty_do_write(tty->index, buf, count);
192 return count;
193}
194
195static int goldfish_tty_write_room(struct tty_struct *tty)
196{
197 return 0x10000;
198}
199
200static int goldfish_tty_chars_in_buffer(struct tty_struct *tty)
201{
202 struct goldfish_tty *qtty = &goldfish_ttys[tty->index];
203 void __iomem *base = qtty->base;
Aleksandar Markovic2296eee2017-08-29 15:53:18 +0200204 return readl(base + GOLDFISH_TTY_REG_BYTES_READY);
Arve Hjønnevåg666b7792013-01-21 23:38:47 +0000205}
206
Aland78055d2014-05-12 16:57:14 +0100207static void goldfish_tty_console_write(struct console *co, const char *b,
208 unsigned count)
Arve Hjønnevåg666b7792013-01-21 23:38:47 +0000209{
210 goldfish_tty_do_write(co->index, b, count);
211}
212
Aland78055d2014-05-12 16:57:14 +0100213static struct tty_driver *goldfish_tty_console_device(struct console *c,
214 int *index)
Arve Hjønnevåg666b7792013-01-21 23:38:47 +0000215{
216 *index = c->index;
217 return goldfish_tty_driver;
218}
219
220static int goldfish_tty_console_setup(struct console *co, char *options)
221{
Dan Carpenterfda2b412014-10-29 11:43:25 +0300222 if ((unsigned)co->index >= goldfish_tty_line_count)
Arve Hjønnevåg666b7792013-01-21 23:38:47 +0000223 return -ENODEV;
Fabian Fredericka4dc9232014-09-28 20:10:17 +0200224 if (!goldfish_ttys[co->index].base)
Arve Hjønnevåg666b7792013-01-21 23:38:47 +0000225 return -ENODEV;
226 return 0;
227}
228
Aya Mahfouz04b757d2015-12-15 01:53:36 +0200229static const struct tty_port_operations goldfish_port_ops = {
Arve Hjønnevåg666b7792013-01-21 23:38:47 +0000230 .activate = goldfish_tty_activate,
231 .shutdown = goldfish_tty_shutdown
232};
233
Aland78055d2014-05-12 16:57:14 +0100234static const struct tty_operations goldfish_tty_ops = {
Arve Hjønnevåg666b7792013-01-21 23:38:47 +0000235 .open = goldfish_tty_open,
236 .close = goldfish_tty_close,
237 .hangup = goldfish_tty_hangup,
238 .write = goldfish_tty_write,
239 .write_room = goldfish_tty_write_room,
240 .chars_in_buffer = goldfish_tty_chars_in_buffer,
241};
242
243static int goldfish_tty_create_driver(void)
244{
245 int ret;
246 struct tty_driver *tty;
247
Aland78055d2014-05-12 16:57:14 +0100248 goldfish_ttys = kzalloc(sizeof(*goldfish_ttys) *
249 goldfish_tty_line_count, GFP_KERNEL);
250 if (goldfish_ttys == NULL) {
Arve Hjønnevåg666b7792013-01-21 23:38:47 +0000251 ret = -ENOMEM;
252 goto err_alloc_goldfish_ttys_failed;
253 }
254 tty = alloc_tty_driver(goldfish_tty_line_count);
Aland78055d2014-05-12 16:57:14 +0100255 if (tty == NULL) {
Arve Hjønnevåg666b7792013-01-21 23:38:47 +0000256 ret = -ENOMEM;
257 goto err_alloc_tty_driver_failed;
258 }
259 tty->driver_name = "goldfish";
260 tty->name = "ttyGF";
261 tty->type = TTY_DRIVER_TYPE_SERIAL;
262 tty->subtype = SERIAL_TYPE_NORMAL;
263 tty->init_termios = tty_std_termios;
Aland78055d2014-05-12 16:57:14 +0100264 tty->flags = TTY_DRIVER_RESET_TERMIOS | TTY_DRIVER_REAL_RAW |
265 TTY_DRIVER_DYNAMIC_DEV;
Arve Hjønnevåg666b7792013-01-21 23:38:47 +0000266 tty_set_operations(tty, &goldfish_tty_ops);
267 ret = tty_register_driver(tty);
Aland78055d2014-05-12 16:57:14 +0100268 if (ret)
Arve Hjønnevåg666b7792013-01-21 23:38:47 +0000269 goto err_tty_register_driver_failed;
270
271 goldfish_tty_driver = tty;
272 return 0;
273
274err_tty_register_driver_failed:
275 put_tty_driver(tty);
276err_alloc_tty_driver_failed:
277 kfree(goldfish_ttys);
278 goldfish_ttys = NULL;
279err_alloc_goldfish_ttys_failed:
280 return ret;
281}
282
283static void goldfish_tty_delete_driver(void)
284{
285 tty_unregister_driver(goldfish_tty_driver);
286 put_tty_driver(goldfish_tty_driver);
287 goldfish_tty_driver = NULL;
288 kfree(goldfish_ttys);
289 goldfish_ttys = NULL;
290}
291
292static int goldfish_tty_probe(struct platform_device *pdev)
293{
294 struct goldfish_tty *qtty;
Miodrag Dinic7157d2b2017-08-29 15:53:19 +0200295 int ret = -ENODEV;
Arve Hjønnevåg666b7792013-01-21 23:38:47 +0000296 struct resource *r;
297 struct device *ttydev;
298 void __iomem *base;
299 u32 irq;
Greg Hackmann465893e2016-02-26 19:01:05 +0000300 unsigned int line;
Arve Hjønnevåg666b7792013-01-21 23:38:47 +0000301
302 r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
Miodrag Dinic7157d2b2017-08-29 15:53:19 +0200303 if (!r) {
304 pr_err("goldfish_tty: No MEM resource available!\n");
305 return -ENOMEM;
306 }
Arve Hjønnevåg666b7792013-01-21 23:38:47 +0000307
308 base = ioremap(r->start, 0x1000);
Miodrag Dinic7157d2b2017-08-29 15:53:19 +0200309 if (!base) {
310 pr_err("goldfish_tty: Unable to ioremap base!\n");
311 return -ENOMEM;
312 }
Arve Hjønnevåg666b7792013-01-21 23:38:47 +0000313
314 r = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
Miodrag Dinic7157d2b2017-08-29 15:53:19 +0200315 if (!r) {
316 pr_err("goldfish_tty: No IRQ resource available!\n");
Arve Hjønnevåg666b7792013-01-21 23:38:47 +0000317 goto err_unmap;
Miodrag Dinic7157d2b2017-08-29 15:53:19 +0200318 }
Arve Hjønnevåg666b7792013-01-21 23:38:47 +0000319
320 irq = r->start;
321
Arve Hjønnevåg666b7792013-01-21 23:38:47 +0000322 mutex_lock(&goldfish_tty_lock);
Greg Hackmann465893e2016-02-26 19:01:05 +0000323
324 if (pdev->id == PLATFORM_DEVID_NONE)
325 line = goldfish_tty_current_line_count;
326 else
327 line = pdev->id;
328
Miodrag Dinic7157d2b2017-08-29 15:53:19 +0200329 if (line >= goldfish_tty_line_count) {
330 pr_err("goldfish_tty: Reached maximum tty number of %d.\n",
331 goldfish_tty_current_line_count);
332 ret = -ENOMEM;
333 goto err_unlock;
334 }
Greg Hackmann465893e2016-02-26 19:01:05 +0000335
Aland78055d2014-05-12 16:57:14 +0100336 if (goldfish_tty_current_line_count == 0) {
Arve Hjønnevåg666b7792013-01-21 23:38:47 +0000337 ret = goldfish_tty_create_driver();
Aland78055d2014-05-12 16:57:14 +0100338 if (ret)
Miodrag Dinic7157d2b2017-08-29 15:53:19 +0200339 goto err_unlock;
Arve Hjønnevåg666b7792013-01-21 23:38:47 +0000340 }
341 goldfish_tty_current_line_count++;
342
Greg Hackmann465893e2016-02-26 19:01:05 +0000343 qtty = &goldfish_ttys[line];
Arve Hjønnevåg666b7792013-01-21 23:38:47 +0000344 spin_lock_init(&qtty->lock);
345 tty_port_init(&qtty->port);
346 qtty->port.ops = &goldfish_port_ops;
347 qtty->base = base;
348 qtty->irq = irq;
Miodrag Dinic7157d2b2017-08-29 15:53:19 +0200349 qtty->dev = &pdev->dev;
350
351 /*
352 * Goldfish TTY device used by the Goldfish emulator
353 * should identify itself with 0, forcing the driver
354 * to use virtual addresses. Goldfish TTY device
355 * on Ranchu emulator (qemu2) returns 1 here and
356 * driver will use physical addresses.
357 */
358 qtty->version = readl(base + GOLDFISH_TTY_REG_VERSION);
359
360 /*
361 * Goldfish TTY device on Ranchu emulator (qemu2)
362 * will use DMA for read/write IO operations.
363 */
364 if (qtty->version > 0) {
365 /*
366 * Initialize dma_mask to 32-bits.
367 */
368 if (!pdev->dev.dma_mask)
369 pdev->dev.dma_mask = &pdev->dev.coherent_dma_mask;
370 ret = dma_set_mask(&pdev->dev, DMA_BIT_MASK(32));
371 if (ret) {
372 dev_err(&pdev->dev, "No suitable DMA available.\n");
373 goto err_dec_line_count;
374 }
375 }
Arve Hjønnevåg666b7792013-01-21 23:38:47 +0000376
Aleksandar Markovic2296eee2017-08-29 15:53:18 +0200377 writel(GOLDFISH_TTY_CMD_INT_DISABLE, base + GOLDFISH_TTY_REG_CMD);
Arve Hjønnevåg666b7792013-01-21 23:38:47 +0000378
Aland78055d2014-05-12 16:57:14 +0100379 ret = request_irq(irq, goldfish_tty_interrupt, IRQF_SHARED,
Miodrag Dinic7157d2b2017-08-29 15:53:19 +0200380 "goldfish_tty", qtty);
381 if (ret) {
382 pr_err("goldfish_tty: No IRQ available!\n");
383 goto err_dec_line_count;
384 }
Arve Hjønnevåg666b7792013-01-21 23:38:47 +0000385
386 ttydev = tty_port_register_device(&qtty->port, goldfish_tty_driver,
Miodrag Dinic7157d2b2017-08-29 15:53:19 +0200387 line, &pdev->dev);
Aland78055d2014-05-12 16:57:14 +0100388 if (IS_ERR(ttydev)) {
Arve Hjønnevåg666b7792013-01-21 23:38:47 +0000389 ret = PTR_ERR(ttydev);
390 goto err_tty_register_device_failed;
391 }
392
393 strcpy(qtty->console.name, "ttyGF");
394 qtty->console.write = goldfish_tty_console_write;
395 qtty->console.device = goldfish_tty_console_device;
396 qtty->console.setup = goldfish_tty_console_setup;
397 qtty->console.flags = CON_PRINTBUFFER;
Greg Hackmann465893e2016-02-26 19:01:05 +0000398 qtty->console.index = line;
Arve Hjønnevåg666b7792013-01-21 23:38:47 +0000399 register_console(&qtty->console);
Greg Hackmann465893e2016-02-26 19:01:05 +0000400 platform_set_drvdata(pdev, qtty);
Arve Hjønnevåg666b7792013-01-21 23:38:47 +0000401
402 mutex_unlock(&goldfish_tty_lock);
403 return 0;
404
Arve Hjønnevåg666b7792013-01-21 23:38:47 +0000405err_tty_register_device_failed:
Christophe JAILLET1a5c2d12017-01-09 01:26:37 +0100406 free_irq(irq, qtty);
Miodrag Dinic7157d2b2017-08-29 15:53:19 +0200407err_dec_line_count:
Arve Hjønnevåg666b7792013-01-21 23:38:47 +0000408 goldfish_tty_current_line_count--;
Aland78055d2014-05-12 16:57:14 +0100409 if (goldfish_tty_current_line_count == 0)
Arve Hjønnevåg666b7792013-01-21 23:38:47 +0000410 goldfish_tty_delete_driver();
Miodrag Dinic7157d2b2017-08-29 15:53:19 +0200411err_unlock:
Arve Hjønnevåg666b7792013-01-21 23:38:47 +0000412 mutex_unlock(&goldfish_tty_lock);
413err_unmap:
414 iounmap(base);
415 return ret;
416}
417
418static int goldfish_tty_remove(struct platform_device *pdev)
419{
Greg Hackmann465893e2016-02-26 19:01:05 +0000420 struct goldfish_tty *qtty = platform_get_drvdata(pdev);
Arve Hjønnevåg666b7792013-01-21 23:38:47 +0000421
422 mutex_lock(&goldfish_tty_lock);
423
Arve Hjønnevåg666b7792013-01-21 23:38:47 +0000424 unregister_console(&qtty->console);
Greg Hackmann465893e2016-02-26 19:01:05 +0000425 tty_unregister_device(goldfish_tty_driver, qtty->console.index);
Arve Hjønnevåg666b7792013-01-21 23:38:47 +0000426 iounmap(qtty->base);
Fabian Fredericka4dc9232014-09-28 20:10:17 +0200427 qtty->base = NULL;
Arve Hjønnevåg666b7792013-01-21 23:38:47 +0000428 free_irq(qtty->irq, pdev);
429 goldfish_tty_current_line_count--;
Aland78055d2014-05-12 16:57:14 +0100430 if (goldfish_tty_current_line_count == 0)
Arve Hjønnevåg666b7792013-01-21 23:38:47 +0000431 goldfish_tty_delete_driver();
432 mutex_unlock(&goldfish_tty_lock);
433 return 0;
434}
435
Sebastian Andrzej Siewior6a28fd22017-11-30 09:16:31 +0100436#ifdef CONFIG_GOLDFISH_TTY_EARLY_CONSOLE
Miodrag Dinic3840ed92017-08-29 15:53:20 +0200437static void gf_early_console_putchar(struct uart_port *port, int ch)
438{
439 __raw_writel(ch, port->membase);
440}
441
442static void gf_early_write(struct console *con, const char *s, unsigned int n)
443{
444 struct earlycon_device *dev = con->data;
445
446 uart_console_write(&dev->port, s, n, gf_early_console_putchar);
447}
448
449static int __init gf_earlycon_setup(struct earlycon_device *device,
450 const char *opt)
451{
452 if (!device->port.membase)
453 return -ENODEV;
454
455 device->con->write = gf_early_write;
456 return 0;
457}
458
459OF_EARLYCON_DECLARE(early_gf_tty, "google,goldfish-tty", gf_earlycon_setup);
Sebastian Andrzej Siewior6a28fd22017-11-30 09:16:31 +0100460#endif
Miodrag Dinic3840ed92017-08-29 15:53:20 +0200461
Miodrag Dinic9b883ee2016-02-26 19:00:44 +0000462static const struct of_device_id goldfish_tty_of_match[] = {
463 { .compatible = "google,goldfish-tty", },
464 {},
465};
466
467MODULE_DEVICE_TABLE(of, goldfish_tty_of_match);
468
Arve Hjønnevåg666b7792013-01-21 23:38:47 +0000469static struct platform_driver goldfish_tty_platform_driver = {
470 .probe = goldfish_tty_probe,
471 .remove = goldfish_tty_remove,
472 .driver = {
Miodrag Dinic9b883ee2016-02-26 19:00:44 +0000473 .name = "goldfish_tty",
474 .of_match_table = goldfish_tty_of_match,
Arve Hjønnevåg666b7792013-01-21 23:38:47 +0000475 }
476};
477
478module_platform_driver(goldfish_tty_platform_driver);
479
480MODULE_LICENSE("GPL v2");