/* * GPIO register offsets in GPIO I/O space. * Each chunk of 32 GPIOs is manipulated via its own USE_SELx, IO_SELx, and * LVLx registers. Logic in the read/write functions takes a register and * an absolute bit number and determines the proper register offset and bit * number in that register. For example, to read the value of GPIO bit 50 * the code would access offset ichx_regs[2(=GPIO_LVL)][1(=50/32)], * bit 18 (50%32).
*/ enum GPIO_REG {
GPIO_USE_SEL = 0,
GPIO_IO_SEL,
GPIO_LVL,
GPO_BLINK
};
/* GPO_BLINK is available on this chipset */ bool have_blink;
/* Whether the chipset has GPIO in GPE0_STS in the PM IO region */ bool uses_gpe0;
/* USE_SEL is bogus on some chipsets, eg 3100 */
u32 use_sel_ignore[3];
/* Some chipsets have quirks, let these use their own request/get */ int (*request)(struct gpio_chip *chip, unsignedint offset); int (*get)(struct gpio_chip *chip, unsignedint offset);
/* * Some chipsets don't let reading output values on GPIO_LVL register * this option allows driver caching written output values
*/ bool use_outlvl_cache;
};
staticstruct {
spinlock_t lock; struct device *dev; struct gpio_chip chip; struct resource *gpio_base; /* GPIO IO base */ struct resource *pm_base; /* Power Management IO base */ struct ichx_desc *desc; /* Pointer to chipset-specific description */
u32 orig_gpio_ctrl; /* Orig CTRL value, used to restore on exit */
u8 use_gpio; /* Which GPIO groups are usable */ int outlvl_cache[3]; /* cached output values */
} ichx_priv;
staticint modparam_gpiobase = -1; /* dynamic */
module_param_named(gpiobase, modparam_gpiobase, int, 0444);
MODULE_PARM_DESC(gpiobase, "The GPIO number base. -1 means dynamic, which is the default.");
staticint ichx_write_bit(int reg, unsignedint nr, int val, int verify)
{ unsignedlong flags;
u32 data, tmp; int reg_nr = nr / 32; int bit = nr & 0x1f;
spin_lock_irqsave(&ichx_priv.lock, flags);
if (reg == GPIO_LVL && ichx_priv.desc->use_outlvl_cache)
data = ichx_priv.outlvl_cache[reg_nr]; else
data = ICHX_READ(ichx_priv.desc->regs[reg][reg_nr],
ichx_priv.gpio_base);
if (val)
data |= BIT(bit); else
data &= ~BIT(bit);
ICHX_WRITE(data, ichx_priv.desc->regs[reg][reg_nr],
ichx_priv.gpio_base); if (reg == GPIO_LVL && ichx_priv.desc->use_outlvl_cache)
ichx_priv.outlvl_cache[reg_nr] = data;
staticint ichx_gpio_direction_input(struct gpio_chip *gpio, unsignedint nr)
{ /* * Try setting pin as an input and verify it worked since many pins * are output-only.
*/ return ichx_write_bit(GPIO_IO_SEL, nr, 1, 1);
}
staticint ichx_gpio_direction_output(struct gpio_chip *gpio, unsignedint nr, int val)
{ int ret;
/* Disable blink hardware which is available for GPIOs from 0 to 31. */ if (nr < 32 && ichx_priv.desc->have_blink)
ichx_write_bit(GPO_BLINK, nr, 0, 0);
/* Set GPIO output value. */
ret = ichx_write_bit(GPIO_LVL, nr, val, 0); if (ret) return ret;
/* * Try setting pin as an output and verify it worked since many pins * are input-only.
*/ return ichx_write_bit(GPIO_IO_SEL, nr, 0, 1);
}
/* * Note we assume the BIOS properly set a bridge's USE value. Some * chips (eg Intel 3100) have bogus USE values though, so first see if * the chipset's USE value can be trusted for this specific bit. * If it can't be trusted, assume that the pin can be used as a GPIO.
*/ if (ichx_priv.desc->use_sel_ignore[nr / 32] & BIT(nr & 0x1f)) return 0;
staticint ich6_gpio_request(struct gpio_chip *chip, unsignedint nr)
{ /* * Fixups for bits 16 and 17 are necessary on the Intel ICH6/3100 * bridge as they are controlled by USE register bits 0 and 1. See * "Table 704 GPIO_USE_SEL1 register" in the i3100 datasheet for * additional info.
*/ if (nr == 16 || nr == 17)
nr -= 16;
/* Intel 3100 */ staticstruct ichx_desc i3100_desc = { /* * Bits 16,17, 20 of USE_SEL and bit 16 of USE_SEL2 always read 0 on * the Intel 3100. See "Table 712. GPIO Summary Table" of 3100 * Datasheet for more info.
*/
.use_sel_ignore = {0x00130000, 0x00010000, 0x0},
/* The 3100 needs fixups for GPIO 0 - 17 */
.request = ich6_gpio_request,
.get = ich6_gpio_get,
/* GPIO 0-15 are read in the GPE0_STS PM register */
.uses_gpe0 = true,
/* Avoton */ staticstruct ichx_desc avoton_desc = { /* Avoton has only 59 GPIOs, but we assume the first set of register * (Core) has 32 instead of 31 to keep gpio-ich compliance
*/
.ngpio = 60,
.regs = avoton_regs,
.reglen = avoton_reglen,
.use_outlvl_cache = true,
};
/* * If necessary, determine the I/O address of ACPI/power management * registers which are needed to read the GPE0 register for GPI pins * 0 - 15 on some chipsets.
*/ if (!ichx_priv.desc->uses_gpe0) goto init;
res_pm = platform_get_resource(pdev, IORESOURCE_IO, ICH_RES_GPE0); if (!res_pm) {
dev_warn(dev, "ACPI BAR is unavailable, GPI 0 - 15 unavailable\n"); goto init;
}
if (!devm_request_region(dev, res_pm->start, resource_size(res_pm),
pdev->name)) {
dev_warn(dev, "ACPI BAR is busy, GPI 0 - 15 unavailable\n"); goto init;
}
ichx_priv.pm_base = res_pm;
init:
ichx_gpiolib_setup(&ichx_priv.chip);
err = devm_gpiochip_add_data(dev, &ichx_priv.chip, NULL); if (err) {
dev_err(dev, "Failed to register GPIOs\n"); return err;
}
dev_info(dev, "GPIO from %d to %d\n", ichx_priv.chip.base,
ichx_priv.chip.base + ichx_priv.chip.ngpio - 1);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.