8250_acorn.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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
  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_8250_port uart;
  41. unsigned long bus_addr;
  42. unsigned int i;
  43. info = kzalloc(sizeof(struct serial_card_info), GFP_KERNEL);
  44. if (!info)
  45. return -ENOMEM;
  46. info->num_ports = type->num_ports;
  47. bus_addr = ecard_resource_start(ec, type->type);
  48. info->vaddr = ecardm_iomap(ec, type->type, 0, 0);
  49. if (!info->vaddr) {
  50. kfree(info);
  51. return -ENOMEM;
  52. }
  53. ecard_set_drvdata(ec, info);
  54. memset(&uart, 0, sizeof(struct uart_8250_port));
  55. uart.port.irq = ec->irq;
  56. uart.port.flags = UPF_BOOT_AUTOCONF | UPF_SHARE_IRQ;
  57. uart.port.uartclk = type->uartclk;
  58. uart.port.iotype = UPIO_MEM;
  59. uart.port.regshift = 2;
  60. uart.port.dev = &ec->dev;
  61. for (i = 0; i < info->num_ports; i ++) {
  62. uart.port.membase = info->vaddr + type->offset[i];
  63. uart.port.mapbase = bus_addr + type->offset[i];
  64. info->ports[i] = serial8250_register_8250_port(&uart);
  65. }
  66. return 0;
  67. }
  68. static void serial_card_remove(struct expansion_card *ec)
  69. {
  70. struct serial_card_info *info = ecard_get_drvdata(ec);
  71. int i;
  72. ecard_set_drvdata(ec, NULL);
  73. for (i = 0; i < info->num_ports; i++)
  74. if (info->ports[i] > 0)
  75. serial8250_unregister_port(info->ports[i]);
  76. kfree(info);
  77. }
  78. static struct serial_card_type atomwide_type = {
  79. .num_ports = 3,
  80. .uartclk = 7372800,
  81. .type = ECARD_RES_IOCSLOW,
  82. .offset = { 0x2800, 0x2400, 0x2000 },
  83. };
  84. static struct serial_card_type serport_type = {
  85. .num_ports = 2,
  86. .uartclk = 3686400,
  87. .type = ECARD_RES_IOCSLOW,
  88. .offset = { 0x2000, 0x2020 },
  89. };
  90. static const struct ecard_id serial_cids[] = {
  91. { MANU_ATOMWIDE, PROD_ATOMWIDE_3PSERIAL, &atomwide_type },
  92. { MANU_SERPORT, PROD_SERPORT_DSPORT, &serport_type },
  93. { 0xffff, 0xffff }
  94. };
  95. static struct ecard_driver serial_card_driver = {
  96. .probe = serial_card_probe,
  97. .remove = serial_card_remove,
  98. .id_table = serial_cids,
  99. .drv = {
  100. .name = "8250_acorn",
  101. },
  102. };
  103. static int __init serial_card_init(void)
  104. {
  105. return ecard_register_driver(&serial_card_driver);
  106. }
  107. static void __exit serial_card_exit(void)
  108. {
  109. ecard_remove_driver(&serial_card_driver);
  110. }
  111. MODULE_AUTHOR("Russell King");
  112. MODULE_DESCRIPTION("Acorn 8250-compatible serial port expansion card driver");
  113. MODULE_LICENSE("GPL");
  114. module_init(serial_card_init);
  115. module_exit(serial_card_exit);