Commit 465893e1 authored by Greg Hackmann's avatar Greg Hackmann Committed by Greg Kroah-Hartman

tty: goldfish: support platform_device with id -1

When the platform bus sets the platform_device id to -1 (PLATFORM_DEVID_NONE),
use an incrementing counter for the TTY index instead
Signed-off-by: default avatarGreg Hackmann <ghackmann@google.com>
Signed-off-by: default avatarJin Qian <jinqian@android.com>
Signed-off-by: default avatarAlan Cox <alan@linux.intel.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 9b883eea
...@@ -68,8 +68,7 @@ static void goldfish_tty_do_write(int line, const char *buf, unsigned count) ...@@ -68,8 +68,7 @@ static void goldfish_tty_do_write(int line, const char *buf, unsigned count)
static irqreturn_t goldfish_tty_interrupt(int irq, void *dev_id) static irqreturn_t goldfish_tty_interrupt(int irq, void *dev_id)
{ {
struct platform_device *pdev = dev_id; struct goldfish_tty *qtty = dev_id;
struct goldfish_tty *qtty = &goldfish_ttys[pdev->id];
void __iomem *base = qtty->base; void __iomem *base = qtty->base;
unsigned long irq_flags; unsigned long irq_flags;
unsigned char *buf; unsigned char *buf;
...@@ -233,6 +232,7 @@ static int goldfish_tty_probe(struct platform_device *pdev) ...@@ -233,6 +232,7 @@ static int goldfish_tty_probe(struct platform_device *pdev)
struct device *ttydev; struct device *ttydev;
void __iomem *base; void __iomem *base;
u32 irq; u32 irq;
unsigned int line;
r = platform_get_resource(pdev, IORESOURCE_MEM, 0); r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
if (r == NULL) if (r == NULL)
...@@ -248,10 +248,16 @@ static int goldfish_tty_probe(struct platform_device *pdev) ...@@ -248,10 +248,16 @@ static int goldfish_tty_probe(struct platform_device *pdev)
irq = r->start; irq = r->start;
if (pdev->id >= goldfish_tty_line_count)
goto err_unmap;
mutex_lock(&goldfish_tty_lock); mutex_lock(&goldfish_tty_lock);
if (pdev->id == PLATFORM_DEVID_NONE)
line = goldfish_tty_current_line_count;
else
line = pdev->id;
if (line >= goldfish_tty_line_count)
goto err_create_driver_failed;
if (goldfish_tty_current_line_count == 0) { if (goldfish_tty_current_line_count == 0) {
ret = goldfish_tty_create_driver(); ret = goldfish_tty_create_driver();
if (ret) if (ret)
...@@ -259,7 +265,7 @@ static int goldfish_tty_probe(struct platform_device *pdev) ...@@ -259,7 +265,7 @@ static int goldfish_tty_probe(struct platform_device *pdev)
} }
goldfish_tty_current_line_count++; goldfish_tty_current_line_count++;
qtty = &goldfish_ttys[pdev->id]; qtty = &goldfish_ttys[line];
spin_lock_init(&qtty->lock); spin_lock_init(&qtty->lock);
tty_port_init(&qtty->port); tty_port_init(&qtty->port);
qtty->port.ops = &goldfish_port_ops; qtty->port.ops = &goldfish_port_ops;
...@@ -269,13 +275,13 @@ static int goldfish_tty_probe(struct platform_device *pdev) ...@@ -269,13 +275,13 @@ static int goldfish_tty_probe(struct platform_device *pdev)
writel(GOLDFISH_TTY_CMD_INT_DISABLE, base + GOLDFISH_TTY_CMD); writel(GOLDFISH_TTY_CMD_INT_DISABLE, base + GOLDFISH_TTY_CMD);
ret = request_irq(irq, goldfish_tty_interrupt, IRQF_SHARED, ret = request_irq(irq, goldfish_tty_interrupt, IRQF_SHARED,
"goldfish_tty", pdev); "goldfish_tty", qtty);
if (ret) if (ret)
goto err_request_irq_failed; goto err_request_irq_failed;
ttydev = tty_port_register_device(&qtty->port, goldfish_tty_driver, ttydev = tty_port_register_device(&qtty->port, goldfish_tty_driver,
pdev->id, &pdev->dev); line, &pdev->dev);
if (IS_ERR(ttydev)) { if (IS_ERR(ttydev)) {
ret = PTR_ERR(ttydev); ret = PTR_ERR(ttydev);
goto err_tty_register_device_failed; goto err_tty_register_device_failed;
...@@ -286,8 +292,9 @@ static int goldfish_tty_probe(struct platform_device *pdev) ...@@ -286,8 +292,9 @@ static int goldfish_tty_probe(struct platform_device *pdev)
qtty->console.device = goldfish_tty_console_device; qtty->console.device = goldfish_tty_console_device;
qtty->console.setup = goldfish_tty_console_setup; qtty->console.setup = goldfish_tty_console_setup;
qtty->console.flags = CON_PRINTBUFFER; qtty->console.flags = CON_PRINTBUFFER;
qtty->console.index = pdev->id; qtty->console.index = line;
register_console(&qtty->console); register_console(&qtty->console);
platform_set_drvdata(pdev, qtty);
mutex_unlock(&goldfish_tty_lock); mutex_unlock(&goldfish_tty_lock);
return 0; return 0;
...@@ -307,13 +314,12 @@ static int goldfish_tty_probe(struct platform_device *pdev) ...@@ -307,13 +314,12 @@ static int goldfish_tty_probe(struct platform_device *pdev)
static int goldfish_tty_remove(struct platform_device *pdev) static int goldfish_tty_remove(struct platform_device *pdev)
{ {
struct goldfish_tty *qtty; struct goldfish_tty *qtty = platform_get_drvdata(pdev);
mutex_lock(&goldfish_tty_lock); mutex_lock(&goldfish_tty_lock);
qtty = &goldfish_ttys[pdev->id];
unregister_console(&qtty->console); unregister_console(&qtty->console);
tty_unregister_device(goldfish_tty_driver, pdev->id); tty_unregister_device(goldfish_tty_driver, qtty->console.index);
iounmap(qtty->base); iounmap(qtty->base);
qtty->base = NULL; qtty->base = NULL;
free_irq(qtty->irq, pdev); free_irq(qtty->irq, pdev);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment