22 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
27 #include <linux/kernel.h>
29 #include <linux/module.h>
30 #include <linux/pci.h>
31 #include <linux/types.h>
42 #define GPIO_BASE 0x048
43 #define GPIO_CTRL 0x04c
49 #define ICH7_GPIO_SIZE 64
54 #define GPIO_USE_SEL 0x000
55 #define GP_IO_SEL 0x004
57 #define GPO_BLINK 0x018
59 #define GPIO_USE_SEL2 0x034
60 #define GP_IO_SEL2 0x038
97 .callback = ss4200_led_dmi_callback,
98 .ident =
"Intel SS4200-E",
111 static u32 g_pm_io_base;
116 static u32 nas_gpio_io_base;
123 static struct resource *gp_gpio_resource;
135 { .name =
"hdd1:blue:sata", .gpio_bit = 0 },
136 { .name =
"hdd1:amber:sata", .gpio_bit = 1 },
137 { .name =
"hdd2:blue:sata", .gpio_bit = 2 },
138 { .name =
"hdd2:amber:sata", .gpio_bit = 3 },
139 { .name =
"hdd3:blue:sata", .gpio_bit = 4 },
140 { .name =
"hdd3:amber:sata", .gpio_bit = 5 },
141 { .name =
"hdd4:blue:sata", .gpio_bit = 6 },
142 { .name =
"hdd4:amber:sata", .gpio_bit = 7 },
143 { .name =
"power:blue:power", .gpio_bit = 27},
144 { .name =
"power:amber:power", .gpio_bit = 28},
147 #define NAS_RECOVERY 0x00000400
158 for (i = 0; i <
ARRAY_SIZE(nasgpio_leds); i++) {
159 if (
strcmp(nasgpio_leds[i].name, name))
161 return &nasgpio_leds[
i];
184 gpio_out =
inl(nas_gpio_io_base + port);
190 outl(gpio_out, nas_gpio_io_base + port);
193 static void nasgpio_led_set_attr(
struct led_classdev *led_cdev,
196 spin_lock(&nasgpio_gpio_lock);
197 __nasgpio_led_set_attr(led_cdev, port, value);
198 spin_unlock(&nasgpio_gpio_lock);
203 struct nasgpio_led *led = led_classdev_to_nasgpio_led(led_cdev);
206 spin_lock(&nasgpio_gpio_lock);
207 gpio_in =
inl(nas_gpio_io_base + port);
208 spin_unlock(&nasgpio_gpio_lock);
219 static void nasgpio_led_set_brightness(
struct led_classdev *led_cdev,
230 spin_lock(&nasgpio_gpio_lock);
236 __nasgpio_led_set_attr(led_cdev,
GPO_BLINK, 0);
237 __nasgpio_led_set_attr(led_cdev,
GP_LVL, setting);
238 spin_unlock(&nasgpio_gpio_lock);
241 static int nasgpio_led_set_blink(
struct led_classdev *led_cdev,
242 unsigned long *delay_on,
243 unsigned long *delay_off)
246 if (!(*delay_on == 0 && *delay_off == 0) &&
247 !(*delay_on == 500 && *delay_off == 500))
255 nasgpio_led_set_attr(led_cdev,
GPO_BLINK, setting);
272 for (i = 0; i <
ARRAY_SIZE(nasgpio_leds); i++)
273 all_nas_led |= (1<<nasgpio_leds[i].
gpio_bit);
275 spin_lock(&nasgpio_gpio_lock);
283 dev_dbg(dev,
": Data read from GPIO_USE_SEL = 0x%08x\n", config_data);
287 dev_dbg(dev,
": GPIO_USE_SEL = 0x%08x\n\n", config_data);
296 dev_dbg(dev,
": Data read from GP_IO_SEL = 0x%08x\n",
298 config_data &= ~all_nas_led;
302 dev_dbg(dev,
": GP_IO_SEL = 0x%08x\n", config_data);
308 config_data =
inl(nas_gpio_io_base +
GP_LVL);
309 dev_dbg(dev,
": Data read from GP_LVL = 0x%08x\n", config_data);
315 dev_dbg(dev,
": Data read from GPO_BLINK = 0x%08x\n", config_data);
320 config_data =
inl(nas_gpio_io_base +
GPI_INV);
321 dev_dbg(dev,
": Data read from GPI_INV = 0x%08x\n", config_data);
323 spin_unlock(&nasgpio_gpio_lock);
327 static void ich7_lpc_cleanup(
struct device *dev)
333 if (gp_gpio_resource) {
334 dev_dbg(dev,
": Releasing GPIO I/O addresses\n");
336 gp_gpio_resource =
NULL;
344 static struct pci_dev *nas_gpio_pci_dev;
353 dev_err(&dev->
dev,
"pci_enable_device failed\n");
357 nas_gpio_pci_dev =
dev;
358 status = pci_read_config_dword(dev,
PMBASE, &g_pm_io_base);
361 g_pm_io_base &= 0x00000ff80;
363 status = pci_read_config_dword(dev,
GPIO_CTRL, &gc);
367 "ERROR: The LPC GPIO Block has not been enabled.\n");
371 status = pci_read_config_dword(dev,
GPIO_BASE, &nas_gpio_io_base);
376 dev_dbg(&dev->
dev,
": GPIOBASE = 0x%08x\n", nas_gpio_io_base);
377 nas_gpio_io_base &= 0x00000ffc0;
384 if (
NULL == gp_gpio_resource) {
386 "ERROR Unable to register GPIO I/O addresses.\n");
394 ich7_gpio_init(&dev->
dev);
398 ich7_lpc_cleanup(&dev->
dev);
404 static void ich7_lpc_remove(
struct pci_dev *dev)
406 ich7_lpc_cleanup(&dev->
dev);
413 static struct pci_driver nas_gpio_pci_driver = {
414 .name = KBUILD_MODNAME,
415 .id_table = ich7_lpc_pci_id,
416 .probe = ich7_lpc_probe,
417 .remove = ich7_lpc_remove,
428 static void set_power_light_amber_noblink(
void)
430 struct nasgpio_led *amber = get_led_named(
"power:amber:power");
438 pr_debug(
"setting blue off and amber on\n");
451 return sprintf(buf,
"%u\n", blinking);
456 const char *buf,
size_t size)
460 unsigned long blink_state;
466 nasgpio_led_set_attr(led,
GPO_BLINK, blink_state);
471 static DEVICE_ATTR(blink, 0644, nas_led_blink_show, nas_led_blink_store);
473 static int register_nasgpio_led(
int led_nr)
476 struct nasgpio_led *nas_led = &nasgpio_leds[led_nr];
477 struct led_classdev *led = get_classdev_for_led_nr(led_nr);
494 static void unregister_nasgpio_led(
int led_nr)
496 struct led_classdev *led = get_classdev_for_led_nr(led_nr);
503 static int __init nas_gpio_init(
void)
511 pr_info(
"skipping hardware autodetection\n");
516 if (nr_devices <= 0) {
517 pr_info(
"no LED devices found\n");
521 pr_info(
"registering PCI driver\n");
522 ret = pci_register_driver(&nas_gpio_pci_driver);
525 for (i = 0; i <
ARRAY_SIZE(nasgpio_leds); i++) {
526 ret = register_nasgpio_led(i);
535 set_power_light_amber_noblink();
538 for (i--; i >= 0; i--)
539 unregister_nasgpio_led(i);
547 static void __exit nas_gpio_exit(
void)
550 pr_info(
"Unregistering driver\n");
551 for (i = 0; i <
ARRAY_SIZE(nasgpio_leds); i++)
552 unregister_nasgpio_led(i);