21 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
23 #include <linux/module.h>
24 #include <linux/pci.h>
29 #define DRV_NAME "gpio_ich"
46 static const u8 ichx_regs[3][3] = {
52 static const u8 ichx_reglen[3] = {
56 #define ICHX_WRITE(val, reg, base_res) outl(val, (reg) + (base_res)->start)
57 #define ICHX_READ(reg, base_res) inl((reg) + (base_res)->start)
85 static int modparam_gpiobase = -1;
88 "which is the default.");
90 static int ichx_write_bit(
int reg,
unsigned nr,
int val,
int verify)
100 data =
ICHX_READ(ichx_regs[reg][reg_nr], ichx_priv.gpio_base);
105 ICHX_WRITE(data, ichx_regs[reg][reg_nr], ichx_priv.gpio_base);
106 tmp =
ICHX_READ(ichx_regs[reg][reg_nr], ichx_priv.gpio_base);
107 if (verify && data != tmp)
110 spin_unlock_irqrestore(&ichx_priv.lock, flags);
115 static int ichx_read_bit(
int reg,
unsigned nr)
119 int reg_nr = nr / 32;
124 data =
ICHX_READ(ichx_regs[reg][reg_nr], ichx_priv.gpio_base);
126 spin_unlock_irqrestore(&ichx_priv.lock, flags);
128 return data & (1 <<
bit) ? 1 : 0;
131 static int ichx_gpio_check_available(
struct gpio_chip *
gpio,
unsigned nr)
133 return (ichx_priv.use_gpio & (1 << (nr / 32))) ? 0 : -
ENXIO;
136 static int ichx_gpio_direction_input(
struct gpio_chip *gpio,
unsigned nr)
138 if (!ichx_gpio_check_available(gpio, nr))
151 static int ichx_gpio_direction_output(
struct gpio_chip *gpio,
unsigned nr,
154 if (!ichx_gpio_check_available(gpio, nr))
158 ichx_write_bit(
GPIO_LVL, nr, val, 0);
170 static int ichx_gpio_get(
struct gpio_chip *
chip,
unsigned nr)
172 if (!ichx_gpio_check_available(chip, nr))
178 static int ich6_gpio_get(
struct gpio_chip *chip,
unsigned nr)
183 if (!ichx_gpio_check_available(chip, nr))
191 if (!ichx_priv.pm_base)
197 ICHX_WRITE(1 << (16 + nr), 0, ichx_priv.pm_base);
200 spin_unlock_irqrestore(&ichx_priv.lock, flags);
202 return (data >> 16) & (1 <<
nr) ? 1 : 0;
204 return ichx_gpio_get(chip, nr);
208 static int ichx_gpio_request(
struct gpio_chip *chip,
unsigned nr)
216 if (ichx_priv.desc->use_sel_ignore[nr / 32] & (1 << (nr & 0x1f)))
222 static int ich6_gpio_request(
struct gpio_chip *chip,
unsigned nr)
230 if (nr == 16 || nr == 17)
233 return ichx_gpio_request(chip, nr);
236 static void ichx_gpio_set(
struct gpio_chip *chip,
unsigned nr,
int val)
238 ichx_write_bit(
GPIO_LVL, nr, val, 0);
241 static void __devinit ichx_gpiolib_setup(
struct gpio_chip *chip)
245 chip->dev = &ichx_priv.dev->dev;
248 chip->request = ichx_priv.desc->request ?
249 ichx_priv.desc->request : ichx_gpio_request;
250 chip->get = ichx_priv.desc->get ?
251 ichx_priv.desc->get : ichx_gpio_get;
253 chip->set = ichx_gpio_set;
254 chip->direction_input = ichx_gpio_direction_input;
255 chip->direction_output = ichx_gpio_direction_output;
256 chip->base = modparam_gpiobase;
257 chip->ngpio = ichx_priv.desc->ngpio;
259 chip->dbg_show =
NULL;
265 .request = ich6_gpio_request,
266 .get = ich6_gpio_get,
281 .use_sel_ignore = {0x00130000, 0x00010000, 0x0},
284 .request = ich6_gpio_request,
285 .get = ich6_gpio_get,
304 static struct ichx_desc ich10_cons_desc = {
307 static struct ichx_desc ich10_corp_desc = {
321 if (!res_base || !res_base->
start || !res_base->
end)
324 for (i = 0; i <
ARRAY_SIZE(ichx_regs[0]); i++) {
325 if (!(use_gpio & (1 << i)))
328 ichx_reglen[i], name))
335 for (i--; i >= 0; i--) {
336 if (!(use_gpio & (1 << i)))
344 static void ichx_gpio_release_regions(
struct resource *res_base,
u8 use_gpio)
348 for (i = 0; i <
ARRAY_SIZE(ichx_regs[0]); i++) {
349 if (!(use_gpio & (1 << i)))
365 ichx_priv.dev = pdev;
369 ichx_priv.desc = &i3100_desc;
372 ichx_priv.desc = &intel5_desc;
375 ichx_priv.desc = &ich6_desc;
378 ichx_priv.desc = &ich7_desc;
381 ichx_priv.desc = &ich9_desc;
384 ichx_priv.desc = &ich10_corp_desc;
387 ichx_priv.desc = &ich10_cons_desc;
394 ichx_priv.use_gpio = ich_info->
use_gpio;
395 err = ichx_gpio_request_regions(res_base, pdev->
name,
400 ichx_priv.gpio_base = res_base;
407 if (!ichx_priv.desc->uses_gpe0)
412 pr_warn(
"ACPI BAR is unavailable, GPI 0 - 15 unavailable\n");
418 pr_warn(
"ACPI BAR is busy, GPI 0 - 15 unavailable\n");
422 ichx_priv.pm_base = res_pm;
425 ichx_gpiolib_setup(&ichx_priv.chip);
428 pr_err(
"Failed to register GPIOs\n");
432 pr_info(
"GPIO from %d to %d on %s\n", ichx_priv.chip.base,
433 ichx_priv.chip.base + ichx_priv.chip.ngpio - 1,
DRV_NAME);
438 ichx_gpio_release_regions(ichx_priv.gpio_base, ichx_priv.use_gpio);
439 if (ichx_priv.pm_base)
441 resource_size(ichx_priv.pm_base));
452 "gpiochip_remove()", err);
456 ichx_gpio_release_regions(ichx_priv.gpio_base, ichx_priv.use_gpio);
457 if (ichx_priv.pm_base)
459 resource_size(ichx_priv.pm_base));
469 .probe = ichx_gpio_probe,