static void key_gpio_init(void) { SET_GPIO_INPUT(PIN_SW1); SET_GPIO_INPUT(PIN_SW2); SET_GPIO_INPUT(PIN_SW3); SET_GPIO_INPUT(PIN_SW4); SET_GPIO_INPUT(PIN_SW5); SET_GPIO_INPUT(PIN_SW6); }
int __init rpi_power_switch_init(void) { int ret = 0; if (gpio_pin < 0) { pr_err(POWER_SWITCH_CLASS_NAME ": missing argument: gpio_pin\n"); return -EINVAL; } old_pm_power_off = pm_power_off; pm_power_off = rpi_power_switch_power_off; pr_info("Switch driver v%s\n", RPI_POWER_SWITCH_VERSION); INIT_DELAYED_WORK(&initiate_shutdown_work, initiate_shutdown); /* Register our own class for the power switch */ ret = class_register(&power_switch_class); if (ret < 0) { pr_err("%s: Unable to register class\n", power_switch_class.name); goto out0; } /* Create devices for each PWM present */ switch_dev = device_create(&power_switch_class, &platform_bus, MKDEV(0, 0), NULL, "pswitch%u", 0); if (IS_ERR(switch_dev)) { pr_err("%s: device_create failed\n", power_switch_class.name); ret = PTR_ERR(switch_dev); goto out1; } ret = sysfs_create_group(&switch_dev->kobj, &rpi_power_switch_attribute_group); if (ret < 0) { pr_err("%s: create_group failed\n", power_switch_class.name); goto out2; } /* GPIO register memory must be mapped before doing any direct * accesses such as changing GPIO alt functions or changing GPIO * pull ups or pull downs. */ gpio_reg = ioremap(GPIO_BASE, 1024); /* Set the specified pin as a GPIO input */ SET_GPIO_INPUT(gpio_pin); /* Set the pin as a pulldown. Most pins should default to having * pulldowns, and this seems most intuitive. */ set_gpio_pull(gpio_pin, GPIO_PULL_UP); gpio_request(gpio_pin, "Power switch"); gpio_direction_input(gpio_pin); /* The targeted polarity should be the opposite of the current value. * I.e. we want the pin to transition to this state in order to * initiate a shutdown. */ gpio_pol = !gpio_get_value(gpio_pin); /* Request an interrupt to fire when the pin transitions to our * desired state. */ ret = request_irq(__gpio_to_irq(gpio_pin), power_isr, gpio_pol?IRQF_TRIGGER_RISING:IRQF_TRIGGER_FALLING, "Power button", NULL); if (ret) { pr_err("Unable to request IRQ\n"); goto out3; } return 0; /* Error handling */ out3: sysfs_remove_group(&switch_dev->kobj,&rpi_power_switch_attribute_group); out2: device_unregister(switch_dev); out1: class_unregister(&power_switch_class); out0: iounmap(gpio_reg); pm_power_off = old_pm_power_off; return ret; }