Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- From 862430cade964180c8087717537d87ff0bb9a804 Mon Sep 17 00:00:00 2001
- From: Daniel Hilst SellI <danielhilst@gmail.com>
- Date: Thu, 6 Nov 2014 15:20:10 -0200
- Subject: [PATCH] Powerfailure: powerfailure module implemented.
- ---
- drivers/Kconfig | 2 +
- drivers/csi/Makefile | 1 +
- drivers/csi/powerfailure/Kconfig | 8 +++
- drivers/csi/powerfailure/Makefile | 2 +
- drivers/csi/powerfailure/powerfailure.c | 114 ++++++++++++++++++++++++++++++++
- include/linux/powerfailure.h | 12 ++++
- 6 files changed, 139 insertions(+)
- create mode 100644 drivers/csi/powerfailure/Kconfig
- create mode 100644 drivers/csi/powerfailure/Makefile
- create mode 100644 drivers/csi/powerfailure/powerfailure.c
- create mode 100644 include/linux/powerfailure.h
- diff --git a/drivers/Kconfig b/drivers/Kconfig
- index bdc84f7..2a60123 100644
- --- a/drivers/Kconfig
- +++ b/drivers/Kconfig
- @@ -132,6 +132,8 @@ menu "CSI Drivers"
- source "drivers/csi/nrf24/Kconfig"
- +source "drivers/csi/powerfailure/Kconfig"
- +
- endmenu
- endmenu
- diff --git a/drivers/csi/Makefile b/drivers/csi/Makefile
- index 4c47723..22db5cd 100644
- --- a/drivers/csi/Makefile
- +++ b/drivers/csi/Makefile
- @@ -1 +1,2 @@
- obj-y += nrf24/
- +obj-y += powerfailure/
- diff --git a/drivers/csi/powerfailure/Kconfig b/drivers/csi/powerfailure/Kconfig
- new file mode 100644
- index 0000000..a609efc
- --- /dev/null
- +++ b/drivers/csi/powerfailure/Kconfig
- @@ -0,0 +1,8 @@
- +config POWERFAILURE
- + tristate "Build Power Failure module"
- + depends on m
- + help
- + This builds the Power Failure module, named
- + powerfailure.ko. The Power Failure module is in charge to
- + detect that main power supply is out and brings a clean shutdown.
- +
- \ No newline at end of file
- diff --git a/drivers/csi/powerfailure/Makefile b/drivers/csi/powerfailure/Makefile
- new file mode 100644
- index 0000000..58fb0ec
- --- /dev/null
- +++ b/drivers/csi/powerfailure/Makefile
- @@ -0,0 +1,2 @@
- +CFLAGS_powerfailure.o += -DDEBUG
- +obj-$(CONFIG_POWERFAILURE) += powerfailure.o
- diff --git a/drivers/csi/powerfailure/powerfailure.c b/drivers/csi/powerfailure/powerfailure.c
- new file mode 100644
- index 0000000..b0c0235
- --- /dev/null
- +++ b/drivers/csi/powerfailure/powerfailure.c
- @@ -0,0 +1,114 @@
- +#include <linux/module.h>
- +#include <linux/interrupt.h>
- +#include <linux/platform_device.h>
- +#include <linux/powerfailure.h>
- +#include <linux/gpio.h>
- +#include <linux/reboot.h>
- +
- +#define MODULE_NAME "powerfailure"
- +#define _DEBUG(fmt, msg...) \
- + do { \
- + pr_debug("%s:%s@%d: " \
- + fmt, MODULE_NAME, __func__, __LINE__, ##msg); \
- + } while (0);
- +
- +static int at_pfail_gpio;
- +
- +static void pf_power_off(void)
- +{
- + printk(KERN_EMERG "powerfailure: POWER OFF");
- + gpio_set_value(at_pfail_gpio, 1);
- +}
- +
- +static irqreturn_t pf_hard_irq(int irq, void *handle)
- +{
- + _DEBUG("");
- + return IRQ_WAKE_THREAD;
- +}
- +
- +static irqreturn_t pf_irq(int irq, void *handle)
- +{
- + _DEBUG("");
- +
- + orderly_poweroff(1);
- + return IRQ_HANDLED;
- +}
- +
- +static int pf_probe(struct platform_device *dev)
- +{
- + int error;
- + int irq;
- + struct pf_pdata_s *pdata = dev->dev.platform_data;
- +
- + _DEBUG("");
- +
- + if (!pdata) {
- + dev_err(&dev->dev, "powerfailure driver probed without platform data, aborting");
- + return -1;
- + }
- +
- + error = gpio_request(pdata->gpio_at_pfail, "powerfailure");
- + if (error)
- + return -1;
- + gpio_direction_output(pdata->gpio_at_pfail, 0);
- + at_pfail_gpio = pdata->gpio_at_pfail; /* save globally */
- +
- + irq = gpio_to_irq(pdata->gpio_pfail);
- + error = request_threaded_irq(irq, pf_hard_irq, pf_irq, IRQF_TRIGGER_FALLING, "powerfailure irq", pdata);
- + if (error) {
- + dev_err(&dev->dev, "Can't register powerfailure IRQ");
- + goto free_gpio;
- + }
- +
- + pm_power_off = pf_power_off;
- +
- + return 0;
- +
- +free_gpio:
- + gpio_free(pdata->gpio_at_pfail);
- +
- + return 0;
- +}
- +
- +static int pf_remove(struct platform_device *dev)
- +{
- + int irq;
- + struct pf_pdata_s *pdata = dev->dev.platform_data;
- +
- + BUG_ON(!pdata);
- +
- + irq = gpio_to_irq(pdata->gpio_pfail);
- + free_irq(irq, pdata);
- + gpio_free(pdata->gpio_at_pfail);
- +
- + return 0;
- +}
- +
- +struct platform_driver pf_driver = {
- + .driver = {
- + .name = "powerfailure",
- + .owner = THIS_MODULE,
- + },
- + .probe = pf_probe,
- + .remove = __devexit_p(pf_remove),
- +};
- +
- +static int __init pf_init(void)
- +{
- + _DEBUG("");
- + return platform_driver_register(&pf_driver);
- +}
- +
- +
- +static void __exit pf_exit(void)
- +{
- + _DEBUG("");
- +
- + platform_driver_unregister(&pf_driver);
- +}
- +
- +module_init(pf_init);
- +module_exit(pf_exit);
- +MODULE_AUTHOR("Daniel Hilst Selli <daniel.hilst@csi.ind.br>");
- +MODULE_LICENSE("GPL");
- +MODULE_DESCRIPTION("Power Failure module");
- diff --git a/include/linux/powerfailure.h b/include/linux/powerfailure.h
- new file mode 100644
- index 0000000..fd62f0b
- --- /dev/null
- +++ b/include/linux/powerfailure.h
- @@ -0,0 +1,12 @@
- +#ifndef POWERFAILURE_H
- +#define POWERFAILURE_H
- +
- +#define PWRF_GPIO_PFAIL IMX_GPIO_NR(5, 17)
- +#define PWRF_GPIO_AT_PFAIL IMX_GPIO_NR(5, 12)
- +
- +struct pf_pdata_s {
- + int gpio_pfail;
- + int gpio_at_pfail;
- +};
- +
- +#endif
- --
- 2.1.2
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement