8250.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /*
  2. * Copyright (c) 2006-2024 RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2022-11-16 GuEe-GUI first version
  9. */
  10. #ifndef __SERIAL_8250_H__
  11. #define __SERIAL_8250_H__
  12. #include <rthw.h>
  13. #include <rtthread.h>
  14. #include <rtdevice.h>
  15. #include <ioremap.h>
  16. #include "regs.h"
  17. #include "serial_dm.h"
  18. enum
  19. {
  20. PORT_IO,
  21. PORT_MMIO,
  22. PORT_MMIO16,
  23. PORT_MMIO32,
  24. PORT_MMIO32BE,
  25. };
  26. struct serial8250
  27. {
  28. struct rt_serial_device parent;
  29. struct rt_clk *clk;
  30. int irq;
  31. void *base;
  32. rt_size_t size;
  33. rt_uint32_t freq; /* frequency */
  34. rt_uint32_t regshift; /* reg offset shift */
  35. rt_uint8_t iotype; /* io access style */
  36. struct rt_spinlock spinlock;
  37. rt_uint32_t (*serial_in)(struct serial8250 *, int offset);
  38. void (*serial_out)(struct serial8250 *, int offset, int value);
  39. rt_err_t (*handle_irq)(struct serial8250 *, int irq);
  40. /* Free all resource (and parent) by child */
  41. void (*remove)(struct serial8250 *);
  42. void *data;
  43. };
  44. #define serial8250_alloc(obj) rt_calloc(1, sizeof(typeof(*obj)))
  45. #define raw_to_serial8250(raw_serial) rt_container_of(raw_serial, struct serial8250, parent)
  46. rt_err_t serial8250_config(struct serial8250 *serial, const char *options);
  47. rt_err_t serial8250_setup(struct serial8250 *serial);
  48. rt_err_t serial8250_remove(struct serial8250 *serial);
  49. rt_uint32_t serial8250_in(struct serial8250 *serial, int offset);
  50. void serial8250_out(struct serial8250 *serial, int offset, int value);
  51. rt_err_t serial8250_uart_configure(struct rt_serial_device *raw_serial, struct serial_configure *cfg);
  52. rt_err_t serial8250_uart_control(struct rt_serial_device *raw_serial, int cmd, void *arg);
  53. int serial8250_uart_putc(struct rt_serial_device *raw_serial, char c);
  54. int serial8250_uart_getc(struct rt_serial_device *raw_serial);
  55. int serial8250_early_putc(struct rt_serial_device *raw_serial, char c);
  56. rt_err_t serial8250_early_fdt_setup(struct serial8250 *serial, struct rt_fdt_earlycon *con, const char *options);
  57. extern struct serial8250 early_serial8250;
  58. extern const struct rt_uart_ops serial8250_uart_ops;
  59. #endif /* __SERIAL_8250_H__ */