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