8250_acorn.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. /*
  2. * linux/drivers/serial/acorn.c
  3. *
  4. * Copyright (C) 1996-2003 Russell King.
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License version 2 as
  8. * published by the Free Software Foundation.
  9. */
  10. #include <linux/module.h>
  11. #include <linux/types.h>
  12. #include <linux/tty.h>
  13. #include <linux/serial_core.h>
  14. #include <linux/errno.h>
  15. #include <linux/ioport.h>
  16. #include <linux/slab.h>
  17. #include <linux/device.h>
  18. #include <linux/init.h>
  19. #include <asm/io.h>
  20. #include <asm/ecard.h>
  21. #include <asm/string.h>
  22. #include "8250.h"
  23. #define MAX_PORTS 3
  24. struct serial_card_type {
  25. unsigned int num_ports;
  26. unsigned int uartclk;
  27. unsigned int type;
  28. unsigned int offset[MAX_PORTS];
  29. };
  30. struct serial_card_info {
  31. unsigned int num_ports;
  32. int ports[MAX_PORTS];
  33. void __iomem *vaddr;
  34. };
  35. static int __devinit
  36. serial_card_probe(struct expansion_card *ec, const struct ecard_id *id)
  37. {
  38. struct serial_card_info *info;
  39. struct serial_card_type *type = id->data;
  40. struct uart_port port;
  41. unsigned long bus_addr;
  42. unsigned int i;
  43. info = kmalloc(sizeof(struct serial_card_info), GFP_KERNEL);
  44. if (!info)
  45. return -ENOMEM;
  46. memset(info, 0, sizeof(struct serial_card_info));
  47. info->num_ports = type->num_ports;
  48. bus_addr = ecard_resource_start(ec, type->type);
  49. info->vaddr = ioremap(bus_addr, ecard_resource_len(ec, type->type));
  50. if (!info->vaddr) {
  51. kfree(info);
  52. return -ENOMEM;
  53. }
  54. ecard_set_drvdata(ec, info);
  55. memset(&port, 0, sizeof(struct uart_port));
  56. port.irq = ec->irq;
  57. port.flags = UPF_BOOT_AUTOCONF | UPF_SHARE_IRQ;
  58. port.uartclk = type->uartclk;
  59. port.iotype = UPIO_MEM;
  60. port.regshift = 2;
  61. port.dev = &ec->dev;
  62. for (i = 0; i < info->num_ports; i ++) {
  63. port.membase = info->vaddr + type->offset[i];
  64. port.mapbase = bus_addr + type->offset[i];
  65. info->ports[i] = serial8250_register_port(&port);
  66. }
  67. return 0;
  68. }
  69. static void __devexit serial_card_remove(struct expansion_card *ec)
  70. {
  71. struct serial_card_info *info = ecard_get_drvdata(ec);
  72. int i;
  73. ecard_set_drvdata(ec, NULL);
  74. for (i = 0; i < info->num_ports; i++)
  75. if (info->ports[i] > 0)
  76. serial8250_unregister_port(info->ports[i]);
  77. iounmap(info->vaddr);
  78. kfree(info);
  79. }
  80. static struct serial_card_type atomwide_type = {
  81. .num_ports = 3,
  82. .uartclk = 7372800,
  83. .type = ECARD_RES_IOCSLOW,
  84. .offset = { 0x2800, 0x2400, 0x2000 },
  85. };
  86. static struct serial_card_type serport_type = {
  87. .num_ports = 2,
  88. .uartclk = 3686400,
  89. .type = ECARD_RES_IOCSLOW,
  90. .offset = { 0x2000, 0x2020 },
  91. };
  92. static const struct ecard_id serial_cids[] = {
  93. { MANU_ATOMWIDE, PROD_ATOMWIDE_3PSERIAL, &atomwide_type },
  94. { MANU_SERPORT, PROD_SERPORT_DSPORT, &serport_type },
  95. { 0xffff, 0xffff }
  96. };
  97. static struct ecard_driver serial_card_driver = {
  98. .probe = serial_card_probe,
  99. .remove = __devexit_p(serial_card_remove),
  100. .id_table = serial_cids,
  101. .drv = {
  102. .name = "8250_acorn",
  103. },
  104. };
  105. static int __init serial_card_init(void)
  106. {
  107. return ecard_register_driver(&serial_card_driver);
  108. }
  109. static void __exit serial_card_exit(void)
  110. {
  111. ecard_remove_driver(&serial_card_driver);
  112. }
  113. MODULE_AUTHOR("Russell King");
  114. MODULE_DESCRIPTION("Acorn 8250-compatible serial port expansion card driver");
  115. MODULE_LICENSE("GPL");
  116. module_init(serial_card_init);
  117. module_exit(serial_card_exit);