/* * struct nas_led_whitelist - List of known good models * * Contains the known good models this driver is compatible with. * When adding a new model try to be as strict as possible. This * makes it possible to keep the false positives (the model is * detected as working, but in reality it is not) as low as * possible.
*/ staticconststruct dmi_system_id nas_led_whitelist[] __initconst = {
{
.callback = ss4200_led_dmi_callback,
.ident = "Intel SS4200-E",
.matches = {
DMI_MATCH(DMI_SYS_VENDOR, "Intel"),
DMI_MATCH(DMI_PRODUCT_NAME, "SS4200-E"),
DMI_MATCH(DMI_PRODUCT_VERSION, "1.00.00")
}
},
{ /* * FUJITSU SIEMENS SCALEO Home Server/SS4200-E * BIOS V090L 12/19/2007
*/
.callback = ss4200_led_dmi_callback,
.ident = "Fujitsu Siemens SCALEO Home Server",
.matches = {
DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU SIEMENS"),
DMI_MATCH(DMI_PRODUCT_NAME, "SCALEO Home Server"),
DMI_MATCH(DMI_PRODUCT_VERSION, "1.00.00")
}
},
{}
};
/* * Base I/O address assigned to the Power Management register block
*/ static u32 g_pm_io_base;
/* * Base I/O address assigned to the ICH7 GPIO register block
*/ static u32 nas_gpio_io_base;
/* * When we successfully register a region, we are returned a resource. * We use these to identify which regions we need to release on our way * back out.
*/ staticstruct resource *gp_gpio_resource;
staticstruct nasgpio_led *get_led_named(char *name)
{ int i; for (i = 0; i < ARRAY_SIZE(nasgpio_leds); i++) { if (strcmp(nasgpio_leds[i].name, name)) continue; return &nasgpio_leds[i];
} return NULL;
}
/* * This protects access to the gpio ports.
*/ static DEFINE_SPINLOCK(nasgpio_gpio_lock);
/* * There are two gpio ports, one for blinking and the other * for power. @port tells us if we're doing blinking or * power control. * * Caller must hold nasgpio_gpio_lock
*/ staticvoid __nasgpio_led_set_attr(struct led_classdev *led_cdev,
u32 port, u32 value)
{ struct nasgpio_led *led = led_classdev_to_nasgpio_led(led_cdev);
u32 gpio_out;
/* * There is actual brightness control in the hardware, * but it is via smbus commands and not implemented * in this driver.
*/ staticvoid nasgpio_led_set_brightness(struct led_classdev *led_cdev, enum led_brightness brightness)
{
u32 setting = 0; if (brightness >= LED_HALF)
setting = 1; /* * Hold the lock across both operations. This ensures * consistency so that both the "turn off blinking" * and "turn light off" operations complete as a set.
*/
spin_lock(&nasgpio_gpio_lock); /* * LED class documentation asks that past blink state * be disabled when brightness is turned to zero.
*/ if (brightness == 0)
__nasgpio_led_set_attr(led_cdev, GPO_BLINK, 0);
__nasgpio_led_set_attr(led_cdev, GP_LVL, setting);
spin_unlock(&nasgpio_gpio_lock);
}
/* * Initialize the ICH7 GPIO registers for NAS usage. The BIOS should have * already taken care of this, but we will do so in a non destructive manner * so that we have what we need whether the BIOS did it or not.
*/ staticint ich7_gpio_init(struct device *dev)
{ int i;
u32 config_data = 0;
u32 all_nas_led = 0;
for (i = 0; i < ARRAY_SIZE(nasgpio_leds); i++)
all_nas_led |= (1<<nasgpio_leds[i].gpio_bit);
spin_lock(&nasgpio_gpio_lock); /* * We need to enable all of the GPIO lines used by the NAS box, * so we will read the current Use Selection and add our usage * to it. This should be benign with regard to the original * BIOS configuration.
*/
config_data = inl(nas_gpio_io_base + GPIO_USE_SEL);
dev_dbg(dev, ": Data read from GPIO_USE_SEL = 0x%08x\n", config_data);
config_data |= all_nas_led + NAS_RECOVERY;
outl(config_data, nas_gpio_io_base + GPIO_USE_SEL);
config_data = inl(nas_gpio_io_base + GPIO_USE_SEL);
dev_dbg(dev, ": GPIO_USE_SEL = 0x%08x\n\n", config_data);
/* * The LED GPIO outputs need to be configured for output, so we * will ensure that all LED lines are cleared for output and the * RECOVERY line ready for input. This too should be benign with * regard to BIOS configuration.
*/
config_data = inl(nas_gpio_io_base + GP_IO_SEL);
dev_dbg(dev, ": Data read from GP_IO_SEL = 0x%08x\n",
config_data);
config_data &= ~all_nas_led;
config_data |= NAS_RECOVERY;
outl(config_data, nas_gpio_io_base + GP_IO_SEL);
config_data = inl(nas_gpio_io_base + GP_IO_SEL);
dev_dbg(dev, ": GP_IO_SEL = 0x%08x\n", config_data);
/* * In our final system, the BIOS will initialize the state of all * of the LEDs. For now, we turn them all off (or Low).
*/
config_data = inl(nas_gpio_io_base + GP_LVL);
dev_dbg(dev, ": Data read from GP_LVL = 0x%08x\n", config_data); /* * In our final system, the BIOS will initialize the blink state of all * of the LEDs. For now, we turn blink off for all of them.
*/
config_data = inl(nas_gpio_io_base + GPO_BLINK);
dev_dbg(dev, ": Data read from GPO_BLINK = 0x%08x\n", config_data);
/* * At this moment, I am unsure if anything needs to happen with GPI_INV
*/
config_data = inl(nas_gpio_io_base + GPI_INV);
dev_dbg(dev, ": Data read from GPI_INV = 0x%08x\n", config_data);
spin_unlock(&nasgpio_gpio_lock); return 0;
}
staticvoid ich7_lpc_cleanup(struct device *dev)
{ /* * If we were given exclusive use of the GPIO * I/O Address range, we must return it.
*/ if (gp_gpio_resource) {
dev_dbg(dev, ": Releasing GPIO I/O addresses\n");
release_region(nas_gpio_io_base, ICH7_GPIO_SIZE);
gp_gpio_resource = NULL;
}
}
/* * The OS has determined that the LPC of the Intel ICH7 Southbridge is present * so we can retrive the required operational information and prepare the GPIO.
*/ staticstruct pci_dev *nas_gpio_pci_dev; staticint ich7_lpc_probe(struct pci_dev *dev, conststruct pci_device_id *id)
{ int status;
u32 gc = 0;
status = pci_enable_device(dev); if (status) {
dev_err(&dev->dev, "pci_enable_device failed\n"); return -EIO;
}
nas_gpio_pci_dev = dev;
status = pci_read_config_dword(dev, PMBASE, &g_pm_io_base); if (status) {
status = pcibios_err_to_errno(status); goto out;
}
g_pm_io_base &= 0x00000ff80;
status = pci_read_config_dword(dev, GPIO_CTRL, &gc); if (!(GPIO_EN & gc)) {
status = -EEXIST;
dev_info(&dev->dev, "ERROR: The LPC GPIO Block has not been enabled.\n"); goto out;
}
status = pci_read_config_dword(dev, GPIO_BASE, &nas_gpio_io_base); if (status) {
dev_info(&dev->dev, "Unable to read GPIOBASE.\n");
status = pcibios_err_to_errno(status); goto out;
}
dev_dbg(&dev->dev, ": GPIOBASE = 0x%08x\n", nas_gpio_io_base);
nas_gpio_io_base &= 0x00000ffc0;
/* * Insure that we have exclusive access to the GPIO I/O address range.
*/
gp_gpio_resource = request_region(nas_gpio_io_base, ICH7_GPIO_SIZE,
KBUILD_MODNAME); if (NULL == gp_gpio_resource) {
dev_info(&dev->dev, "ERROR Unable to register GPIO I/O addresses.\n");
status = -1; goto out;
}
/* * Initialize the GPIO for NAS/Home Server Use
*/
ich7_gpio_init(&dev->dev);
out: if (status) {
ich7_lpc_cleanup(&dev->dev);
pci_disable_device(dev);
} return status;
}
staticvoid unregister_nasgpio_led(int led_nr)
{ struct led_classdev *led = get_classdev_for_led_nr(led_nr);
led_classdev_unregister(led);
} /* * module load/initialization
*/ staticint __init nas_gpio_init(void)
{ int i; int ret = 0; int nr_devices = 0;
nr_devices = dmi_check_system(nas_led_whitelist); if (nodetect) {
pr_info("skipping hardware autodetection\n");
pr_info("Please send 'dmidecode' output to dave@sr71.net\n");
nr_devices++;
}
if (nr_devices <= 0) {
pr_info("no LED devices found\n"); return -ENODEV;
}
pr_info("registering PCI driver\n");
ret = pci_register_driver(&nas_gpio_pci_driver); if (ret) return ret; for (i = 0; i < ARRAY_SIZE(nasgpio_leds); i++) {
ret = register_nasgpio_led(i); if (ret) goto out_err;
} /* * When the system powers on, the BIOS leaves the power * light blue and blinking. This will turn it solid * amber once the driver is loaded.
*/
set_power_light_amber_noblink(); return 0;
out_err: for (i--; i >= 0; i--)
unregister_nasgpio_led(i);
pci_unregister_driver(&nas_gpio_pci_driver); return ret;
}
/* * module unload
*/ staticvoid __exit nas_gpio_exit(void)
{ int i;
pr_info("Unregistering driver\n"); for (i = 0; i < ARRAY_SIZE(nasgpio_leds); i++)
unregister_nasgpio_led(i);
pci_unregister_driver(&nas_gpio_pci_driver);
}
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.