21 #include <linux/kernel.h>
22 #include <linux/module.h>
24 #include <linux/errno.h>
29 #define SIO_CHIP_ID 0x8761
30 #define CHIP_ID_HIGH_BYTE 0x20
31 #define CHIP_ID_LOW_BYTE 0x21
33 static u8 ports[2] = { 0x2e, 0x4e };
38 #define GPIO_NAME "it8761-gpio"
39 #define GPIO_BA_HIGH_BYTE 0x60
40 #define GPIO_BA_LOW_BYTE 0x61
42 #define GPIO1X_IO 0xf0
43 #define GPIO2X_IO 0xf1
59 static void enter_conf_mode(
u8 port)
64 outb((port == 0x2e) ? 0x55 : 0xaa, port);
67 static void exit_conf_mode(
u8 port)
73 static void enter_gpio_mode(
u8 port)
78 static int it8761e_gpio_get(
struct gpio_chip *
gc,
unsigned gpio_num)
84 reg = (gpio_num >= 8) ? gpio_ba + 1 : gpio_ba;
86 return !!(
inb(reg) & (1 <<
bit));
89 static int it8761e_gpio_direction_in(
struct gpio_chip *
gc,
unsigned gpio_num)
99 enter_conf_mode(port);
100 enter_gpio_mode(port);
104 if (curr_dirs & (1 << bit))
105 write_reg(curr_dirs & ~(1 << bit), io_reg, port);
107 exit_conf_mode(port);
109 spin_unlock(&sio_lock);
113 static void it8761e_gpio_set(
struct gpio_chip *gc,
114 unsigned gpio_num,
int val)
120 reg = (gpio_num >= 8) ? gpio_ba + 1 : gpio_ba;
122 spin_lock(&sio_lock);
124 curr_vals =
inb(reg);
126 outb(curr_vals | (1 << bit) , reg);
128 outb(curr_vals & ~(1 << bit), reg);
130 spin_unlock(&sio_lock);
133 static int it8761e_gpio_direction_out(
struct gpio_chip *gc,
134 unsigned gpio_num,
int val)
136 u8 curr_dirs, io_reg,
bit;
141 it8761e_gpio_set(gc, gpio_num, val);
143 spin_lock(&sio_lock);
145 enter_conf_mode(port);
146 enter_gpio_mode(port);
150 if (!(curr_dirs & (1 << bit)))
151 write_reg(curr_dirs | (1 << bit), io_reg, port);
153 exit_conf_mode(port);
155 spin_unlock(&sio_lock);
159 static struct gpio_chip it8761e_gpio_chip = {
162 .get = it8761e_gpio_get,
163 .direction_input = it8761e_gpio_direction_in,
164 .set = it8761e_gpio_set,
165 .direction_output = it8761e_gpio_direction_out,
168 static int __init it8761e_gpio_init(
void)
174 spin_lock(&sio_lock);
175 enter_conf_mode(ports[i]);
180 exit_conf_mode(ports[i]);
181 spin_unlock(&sio_lock);
193 enter_conf_mode(port);
194 enter_gpio_mode(port);
197 exit_conf_mode(port);
202 it8761e_gpio_chip.base = -1;
203 it8761e_gpio_chip.ngpio = 16;
207 goto gpiochip_add_err;
217 static void __exit it8761e_gpio_exit(
void)
222 WARN(ret,
"%s(): gpiochip_remove() failed, ret=%d\n",