smsc_sio1007.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /* SPDX-License-Identifier: GPL-2.0+ */
  2. /*
  3. * Copyright (C) 2016, Bin Meng <bmeng.cn@gmail.com>
  4. */
  5. #ifndef _SMSC_SIO1007_H_
  6. #define _SMSC_SIO1007_H_
  7. /*
  8. * The I/O base address of SIO1007 at power-up is determined by the SYSOPT0
  9. * and SYSOPT1 pins at the deasserting edge of PCIRST#. The combination of
  10. * SYSOPT0 and SYSOPT1 determines one of the following addresses.
  11. */
  12. #define SIO1007_IOPORT0 0x002e
  13. #define SIO1007_IOPORT1 0x004e
  14. #define SIO1007_IOPORT2 0x162e
  15. #define SIO1007_IOPORT3 0x164e
  16. /* SIO1007 registers */
  17. #define DEV_POWER_CTRL 0x02
  18. #define UART1_POWER_ON (1 << 3)
  19. #define UART2_POWER_ON (1 << 7)
  20. #define UART1_IOBASE 0x24
  21. #define UART2_IOBASE 0x25
  22. #define UART_IRQ 0x28
  23. #define RTR_IOBASE_HIGH 0x21
  24. #define RTR_IOBASE_LOW 0x30
  25. #define GPIO0_DIR 0x31
  26. #define GPIO1_DIR 0x35
  27. #define GPIO_DIR_INPUT 0
  28. #define GPIO_DIR_OUTPUT 1
  29. #define GPIO0_POL 0x32
  30. #define GPIO1_POL 0x36
  31. #define GPIO_POL_NO_INVERT 0
  32. #define GPIO_POL_INVERT 1
  33. #define GPIO0_TYPE 0x33
  34. #define GPIO1_TYPE 0x37
  35. #define GPIO_TYPE_PUSH_PULL 0
  36. #define GPIO_TYPE_OPEN_DRAIN 1
  37. #define DEV_ACTIVATE 0x3a
  38. #define RTR_EN (1 << 1)
  39. /* Runtime register offset */
  40. #define GPIO0_DATA 0xc
  41. #define GPIO1_DATA 0xe
  42. /* Number of serial ports supported */
  43. #define SIO1007_UART_NUM 2
  44. /* Number of gpio pins supported */
  45. #define GPIO_NUM_PER_GROUP 8
  46. #define GPIO_GROUP_NUM 2
  47. #define SIO1007_GPIO_NUM (GPIO_NUM_PER_GROUP * GPIO_GROUP_NUM)
  48. /**
  49. * Configure the I/O port address of the specified serial device and
  50. * enable the serial device.
  51. *
  52. * @port: SIO1007 I/O port address
  53. * @num: serial device number (0 or 1)
  54. * @iobase: processor I/O port address to assign to this serial device
  55. * @irq: processor IRQ number to assign to this serial device
  56. */
  57. void sio1007_enable_serial(int port, int num, int iobase, int irq);
  58. /**
  59. * Configure the I/O port address of the runtime register block and
  60. * enable the address decoding.
  61. *
  62. * @port: SIO1007 I/O port address
  63. * @iobase: processor I/O port address to assign to the runtime registers
  64. */
  65. void sio1007_enable_runtime(int port, int iobase);
  66. /**
  67. * Configure the direction/polority/type of a specified GPIO pin
  68. *
  69. * @port: SIO1007 I/O port address
  70. * @gpio: GPIO number (0-7 for GP10-GP17, 8-15 for GP30-GP37)
  71. * @dir: GPIO_DIR_INPUT or GPIO_DIR_OUTPUT
  72. * @pol: GPIO_POL_NO_INVERT or GPIO_POL_INVERT
  73. * @type: GPIO_TYPE_PUSH_PULL or GPIO_TYPE_OPEN_DRAIN
  74. */
  75. void sio1007_gpio_config(int port, int gpio, int dir, int pol, int type);
  76. /**
  77. * Get a GPIO pin value.
  78. * This will work whether the GPIO is an input or an output.
  79. *
  80. * @port: runtime register block I/O port address
  81. * @gpio: GPIO number (0-7 for GP10-GP17, 8-15 for GP30-GP37)
  82. * @return: 0 if low, 1 if high, -EINVAL if gpio number is invalid
  83. */
  84. int sio1007_gpio_get_value(int port, int gpio);
  85. /**
  86. * Set a GPIO pin value.
  87. * This will only work when the GPIO is configured as an output.
  88. *
  89. * @port: runtime register block I/O port address
  90. * @gpio: GPIO number (0-7 for GP10-GP17, 8-15 for GP30-GP37)
  91. * @val: 0 if low, 1 if high
  92. */
  93. void sio1007_gpio_set_value(int port, int gpio, int val);
  94. #endif /* _SMSC_SIO1007_H_ */