summaryrefstree
path: root/kernel/drivers/rtc/power-on-alarm.c
blob: 52f6e8b0264515819c755f90efe250a731d0aa3a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/*
 * /drivers/rtc/power-on-alarm.c
 *
 *  Copyright (C) 2015 Samsung Electronics
 *
 * This software is licensed under the terms of the GNU General Public
 * License version 2, as published by the Free Software Foundation, and
 * may be copied, distributed, and modified under those terms.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 */

#include <linux/time.h>
#include <linux/module.h>
#include <linux/device.h>
#include <linux/miscdevice.h>
#include <linux/fs.h>
#include <linux/platform_device.h>
#include <linux/sched.h>
#include <linux/spinlock.h>
#include <linux/uaccess.h>
#include <linux/alarmtimer.h>
#include <linux/ioctl.h>

#define ANDROID_ALARM_BASE_CMD(cmd)         (cmd & ~(_IOC(0, 0, 0xf0, 0)))
#define ANDROID_ALARM_SET_ALARM_BOOT	    _IOW('a', 7, struct timespec)

static long power_on_alarm_ioctl(struct file *file, unsigned int cmd,
		unsigned long arg)
{
	int rv = 0;
	char bootalarm_data[14];

	switch (ANDROID_ALARM_BASE_CMD(cmd)) {
	case ANDROID_ALARM_SET_ALARM_BOOT:
		if (copy_from_user(bootalarm_data, (void __user *)arg, 14)) {
			rv = -EFAULT;
			return rv;
		}
		rv = alarm_set_alarm(bootalarm_data);
		break;
	}

	return rv;
}

static int power_on_alarm_open(struct inode *inode, struct file *file)
{
	file->private_data = NULL;
	return 0;
}

static int power_on_alarm_release(struct inode *inode, struct file *file)
{
	return 0;
}

static const struct file_operations power_on_alarm_fops = {
	.owner = THIS_MODULE,
	.unlocked_ioctl = power_on_alarm_ioctl,
	.open = power_on_alarm_open,
	.release = power_on_alarm_release,
};

static struct miscdevice power_on_alarm_device = {
	.minor = MISC_DYNAMIC_MINOR,
	.name = "power_on_alarm",
	.fops = &power_on_alarm_fops,
};

static int __init power_on_alarm_dev_init(void)
{
	int err;

	err = misc_register(&power_on_alarm_device);
	if (err)
		return err;
	pr_info("%s\n", __func__);

	return 0;
}

static void  __exit power_on_alarm_dev_exit(void)
{
	misc_deregister(&power_on_alarm_device);
}

module_init(power_on_alarm_dev_init);
module_exit(power_on_alarm_dev_exit);