summaryrefslogtreecommitdiff
path: root/drivers/misc/max1749.c
blob: e98964289002c47fcbe708d88473881d812fe6e9 (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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/*
 * drivers/misc/max1749.c
 *
 * Driver for MAX1749, vibrator motor driver.
 *
 * Copyright (c) 2011, NVIDIA Corporation.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * 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.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */

#include <linux/regulator/consumer.h>
#include <linux/kernel.h>
#include <linux/platform_device.h>
#include <linux/err.h>
#include <linux/hrtimer.h>
#include <linux/delay.h>

#include "../staging/android/timed_output.h"

static struct regulator *regulator;
static int timeout;

static void vibrator_start(void)
{
	regulator_enable(regulator);
}

static void vibrator_stop(void)
{
	int ret;

	ret = regulator_is_enabled(regulator);
	if (ret > 0)
		regulator_disable(regulator);
}

/*
 * Timeout value can be changed from sysfs entry
 * created by timed_output_dev.
 * echo 100 > /sys/class/timed_output/vibrator/enable
 */
static void vibrator_enable(struct timed_output_dev *dev, int value)
{
	timeout = value;
	if (!regulator)
		return;

	if (value) {
		vibrator_start();
		msleep(value);
		vibrator_stop();
	} else {
		vibrator_stop();
	}
}

/*
 * Timeout value can be read from sysfs entry
 * created by timed_output_dev.
 * cat /sys/class/timed_output/vibrator/enable
 */
static int vibrator_get_time(struct timed_output_dev *dev)
{
	return timeout;
}

static struct timed_output_dev vibrator_dev = {
	.name		= "vibrator",
	.get_time	= vibrator_get_time,
	.enable		= vibrator_enable,
};

static int __init vibrator_init(void)
{
	int status;

	regulator = regulator_get(NULL, "vdd_vbrtr");
	if (IS_ERR_OR_NULL(regulator)) {
		pr_err("vibrator_init:Couldn't get regulator vdd_vbrtr\n");
		regulator = NULL;
		return PTR_ERR(regulator);
	}

	status = timed_output_dev_register(&vibrator_dev);

	if (status) {
		regulator_put(regulator);
		regulator = NULL;
	}
	return status;
}

static void __exit vibrator_exit(void)
{
	if (regulator) {
		timed_output_dev_unregister(&vibrator_dev);
		regulator_put(regulator);
		regulator = NULL;
	}
}

MODULE_DESCRIPTION("timed output vibrator device");
MODULE_AUTHOR("GPL");

module_init(vibrator_init);
module_exit(vibrator_exit);