smsc_sio1007.h 3.1 KB

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