8250_acorn.c 3.0 KB

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