diff options
| author | Jonathan Herman <hermanjl@cs.unc.edu> | 2013-01-22 10:38:37 -0500 |
|---|---|---|
| committer | Jonathan Herman <hermanjl@cs.unc.edu> | 2013-01-22 10:38:37 -0500 |
| commit | fcc9d2e5a6c89d22b8b773a64fb4ad21ac318446 (patch) | |
| tree | a57612d1888735a2ec7972891b68c1ac5ec8faea /drivers/misc/max1749.c | |
| parent | 8dea78da5cee153b8af9c07a2745f6c55057fe12 (diff) | |
Diffstat (limited to 'drivers/misc/max1749.c')
| -rw-r--r-- | drivers/misc/max1749.c | 118 |
1 files changed, 118 insertions, 0 deletions
diff --git a/drivers/misc/max1749.c b/drivers/misc/max1749.c new file mode 100644 index 00000000000..e9896428900 --- /dev/null +++ b/drivers/misc/max1749.c | |||
| @@ -0,0 +1,118 @@ | |||
| 1 | /* | ||
| 2 | * drivers/misc/max1749.c | ||
| 3 | * | ||
| 4 | * Driver for MAX1749, vibrator motor driver. | ||
| 5 | * | ||
| 6 | * Copyright (c) 2011, NVIDIA Corporation. | ||
| 7 | * | ||
| 8 | * This program is free software; you can redistribute it and/or modify | ||
| 9 | * it under the terms of the GNU General Public License as published by | ||
| 10 | * the Free Software Foundation; either version 2 of the License, or | ||
| 11 | * (at your option) any later version. | ||
| 12 | * | ||
| 13 | * This program is distributed in the hope that it will be useful, but WITHOUT | ||
| 14 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
| 15 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
| 16 | * more details. | ||
| 17 | * | ||
| 18 | * You should have received a copy of the GNU General Public License along | ||
| 19 | * with this program; if not, write to the Free Software Foundation, Inc., | ||
| 20 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
| 21 | */ | ||
| 22 | |||
| 23 | #include <linux/regulator/consumer.h> | ||
| 24 | #include <linux/kernel.h> | ||
| 25 | #include <linux/platform_device.h> | ||
| 26 | #include <linux/err.h> | ||
| 27 | #include <linux/hrtimer.h> | ||
| 28 | #include <linux/delay.h> | ||
| 29 | |||
| 30 | #include "../staging/android/timed_output.h" | ||
| 31 | |||
| 32 | static struct regulator *regulator; | ||
| 33 | static int timeout; | ||
| 34 | |||
| 35 | static void vibrator_start(void) | ||
| 36 | { | ||
| 37 | regulator_enable(regulator); | ||
| 38 | } | ||
| 39 | |||
| 40 | static void vibrator_stop(void) | ||
| 41 | { | ||
| 42 | int ret; | ||
| 43 | |||
| 44 | ret = regulator_is_enabled(regulator); | ||
| 45 | if (ret > 0) | ||
| 46 | regulator_disable(regulator); | ||
| 47 | } | ||
| 48 | |||
| 49 | /* | ||
| 50 | * Timeout value can be changed from sysfs entry | ||
| 51 | * created by timed_output_dev. | ||
| 52 | * echo 100 > /sys/class/timed_output/vibrator/enable | ||
| 53 | */ | ||
| 54 | static void vibrator_enable(struct timed_output_dev *dev, int value) | ||
| 55 | { | ||
| 56 | timeout = value; | ||
| 57 | if (!regulator) | ||
| 58 | return; | ||
| 59 | |||
| 60 | if (value) { | ||
| 61 | vibrator_start(); | ||
| 62 | msleep(value); | ||
| 63 | vibrator_stop(); | ||
| 64 | } else { | ||
| 65 | vibrator_stop(); | ||
| 66 | } | ||
| 67 | } | ||
| 68 | |||
| 69 | /* | ||
| 70 | * Timeout value can be read from sysfs entry | ||
| 71 | * created by timed_output_dev. | ||
| 72 | * cat /sys/class/timed_output/vibrator/enable | ||
| 73 | */ | ||
| 74 | static int vibrator_get_time(struct timed_output_dev *dev) | ||
| 75 | { | ||
| 76 | return timeout; | ||
| 77 | } | ||
| 78 | |||
| 79 | static struct timed_output_dev vibrator_dev = { | ||
| 80 | .name = "vibrator", | ||
| 81 | .get_time = vibrator_get_time, | ||
| 82 | .enable = vibrator_enable, | ||
| 83 | }; | ||
| 84 | |||
| 85 | static int __init vibrator_init(void) | ||
| 86 | { | ||
| 87 | int status; | ||
| 88 | |||
| 89 | regulator = regulator_get(NULL, "vdd_vbrtr"); | ||
| 90 | if (IS_ERR_OR_NULL(regulator)) { | ||
| 91 | pr_err("vibrator_init:Couldn't get regulator vdd_vbrtr\n"); | ||
| 92 | regulator = NULL; | ||
| 93 | return PTR_ERR(regulator); | ||
| 94 | } | ||
| 95 | |||
| 96 | status = timed_output_dev_register(&vibrator_dev); | ||
| 97 | |||
| 98 | if (status) { | ||
| 99 | regulator_put(regulator); | ||
| 100 | regulator = NULL; | ||
| 101 | } | ||
| 102 | return status; | ||
| 103 | } | ||
| 104 | |||
| 105 | static void __exit vibrator_exit(void) | ||
| 106 | { | ||
| 107 | if (regulator) { | ||
| 108 | timed_output_dev_unregister(&vibrator_dev); | ||
| 109 | regulator_put(regulator); | ||
| 110 | regulator = NULL; | ||
| 111 | } | ||
| 112 | } | ||
| 113 | |||
| 114 | MODULE_DESCRIPTION("timed output vibrator device"); | ||
| 115 | MODULE_AUTHOR("GPL"); | ||
| 116 | |||
| 117 | module_init(vibrator_init); | ||
| 118 | module_exit(vibrator_exit); | ||
