aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGreg Hackmann <ghackmann@google.com>2016-02-26 14:01:05 -0500
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2016-03-07 19:11:14 -0500
commit465893e18878e119d8d0255439fad8debbd646fd (patch)
treecfd5c2c6c14f61a82aed73a19a896cbc0fc28310
parent9b883eea26ccf043b608e398cf6a26231d44f5fb (diff)
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: Greg Hackmann <ghackmann@google.com> Signed-off-by: Jin Qian <jinqian@android.com> Signed-off-by: Alan Cox <alan@linux.intel.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r--drivers/tty/goldfish.c30
1 files changed, 18 insertions, 12 deletions
diff --git a/drivers/tty/goldfish.c b/drivers/tty/goldfish.c
index 1b3142cdb27d..3fc912373adf 100644
--- a/drivers/tty/goldfish.c
+++ b/drivers/tty/goldfish.c
@@ -68,8 +68,7 @@ static void goldfish_tty_do_write(int line, const char *buf, unsigned count)
68 68
69static irqreturn_t goldfish_tty_interrupt(int irq, void *dev_id) 69static irqreturn_t goldfish_tty_interrupt(int irq, void *dev_id)
70{ 70{
71 struct platform_device *pdev = dev_id; 71 struct goldfish_tty *qtty = dev_id;
72 struct goldfish_tty *qtty = &goldfish_ttys[pdev->id];
73 void __iomem *base = qtty->base; 72 void __iomem *base = qtty->base;
74 unsigned long irq_flags; 73 unsigned long irq_flags;
75 unsigned char *buf; 74 unsigned char *buf;
@@ -233,6 +232,7 @@ static int goldfish_tty_probe(struct platform_device *pdev)
233 struct device *ttydev; 232 struct device *ttydev;
234 void __iomem *base; 233 void __iomem *base;
235 u32 irq; 234 u32 irq;
235 unsigned int line;
236 236
237 r = platform_get_resource(pdev, IORESOURCE_MEM, 0); 237 r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
238 if (r == NULL) 238 if (r == NULL)
@@ -248,10 +248,16 @@ static int goldfish_tty_probe(struct platform_device *pdev)
248 248
249 irq = r->start; 249 irq = r->start;
250 250
251 if (pdev->id >= goldfish_tty_line_count)
252 goto err_unmap;
253
254 mutex_lock(&goldfish_tty_lock); 251 mutex_lock(&goldfish_tty_lock);
252
253 if (pdev->id == PLATFORM_DEVID_NONE)
254 line = goldfish_tty_current_line_count;
255 else
256 line = pdev->id;
257
258 if (line >= goldfish_tty_line_count)
259 goto err_create_driver_failed;
260
255 if (goldfish_tty_current_line_count == 0) { 261 if (goldfish_tty_current_line_count == 0) {
256 ret = goldfish_tty_create_driver(); 262 ret = goldfish_tty_create_driver();
257 if (ret) 263 if (ret)
@@ -259,7 +265,7 @@ static int goldfish_tty_probe(struct platform_device *pdev)
259 } 265 }
260 goldfish_tty_current_line_count++; 266 goldfish_tty_current_line_count++;
261 267
262 qtty = &goldfish_ttys[pdev->id]; 268 qtty = &goldfish_ttys[line];
263 spin_lock_init(&qtty->lock); 269 spin_lock_init(&qtty->lock);
264 tty_port_init(&qtty->port); 270 tty_port_init(&qtty->port);
265 qtty->port.ops = &goldfish_port_ops; 271 qtty->port.ops = &goldfish_port_ops;
@@ -269,13 +275,13 @@ static int goldfish_tty_probe(struct platform_device *pdev)
269 writel(GOLDFISH_TTY_CMD_INT_DISABLE, base + GOLDFISH_TTY_CMD); 275 writel(GOLDFISH_TTY_CMD_INT_DISABLE, base + GOLDFISH_TTY_CMD);
270 276
271 ret = request_irq(irq, goldfish_tty_interrupt, IRQF_SHARED, 277 ret = request_irq(irq, goldfish_tty_interrupt, IRQF_SHARED,
272 "goldfish_tty", pdev); 278 "goldfish_tty", qtty);
273 if (ret) 279 if (ret)
274 goto err_request_irq_failed; 280 goto err_request_irq_failed;
275 281
276 282
277 ttydev = tty_port_register_device(&qtty->port, goldfish_tty_driver, 283 ttydev = tty_port_register_device(&qtty->port, goldfish_tty_driver,
278 pdev->id, &pdev->dev); 284 line, &pdev->dev);
279 if (IS_ERR(ttydev)) { 285 if (IS_ERR(ttydev)) {
280 ret = PTR_ERR(ttydev); 286 ret = PTR_ERR(ttydev);
281 goto err_tty_register_device_failed; 287 goto err_tty_register_device_failed;
@@ -286,8 +292,9 @@ static int goldfish_tty_probe(struct platform_device *pdev)
286 qtty->console.device = goldfish_tty_console_device; 292 qtty->console.device = goldfish_tty_console_device;
287 qtty->console.setup = goldfish_tty_console_setup; 293 qtty->console.setup = goldfish_tty_console_setup;
288 qtty->console.flags = CON_PRINTBUFFER; 294 qtty->console.flags = CON_PRINTBUFFER;
289 qtty->console.index = pdev->id; 295 qtty->console.index = line;
290 register_console(&qtty->console); 296 register_console(&qtty->console);
297 platform_set_drvdata(pdev, qtty);
291 298
292 mutex_unlock(&goldfish_tty_lock); 299 mutex_unlock(&goldfish_tty_lock);
293 return 0; 300 return 0;
@@ -307,13 +314,12 @@ err_unmap:
307 314
308static int goldfish_tty_remove(struct platform_device *pdev) 315static int goldfish_tty_remove(struct platform_device *pdev)
309{ 316{
310 struct goldfish_tty *qtty; 317 struct goldfish_tty *qtty = platform_get_drvdata(pdev);
311 318
312 mutex_lock(&goldfish_tty_lock); 319 mutex_lock(&goldfish_tty_lock);
313 320
314 qtty = &goldfish_ttys[pdev->id];
315 unregister_console(&qtty->console); 321 unregister_console(&qtty->console);
316 tty_unregister_device(goldfish_tty_driver, pdev->id); 322 tty_unregister_device(goldfish_tty_driver, qtty->console.index);
317 iounmap(qtty->base); 323 iounmap(qtty->base);
318 qtty->base = NULL; 324 qtty->base = NULL;
319 free_irq(qtty->irq, pdev); 325 free_irq(qtty->irq, pdev);