Devin Kim | 5546885 | 2012-06-19 12:01:32 -0700 | [diff] [blame] | 1 | /* |
| 2 | * android vibrator driver |
| 3 | * |
| 4 | * Copyright (C) 2009-2012 LGE, Inc. |
| 5 | * |
| 6 | * Author: Jinkyu Choi <jinkyu@lge.com> |
| 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, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License |
| 19 | * along with this program; if not, write to the Free Software |
| 20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 21 | * |
| 22 | */ |
| 23 | |
| 24 | #include <linux/kernel.h> |
| 25 | #include <linux/module.h> |
| 26 | #include <linux/init.h> |
| 27 | #include <linux/platform_device.h> |
| 28 | #include <linux/gpio.h> |
| 29 | #include <linux/delay.h> |
| 30 | #include <linux/timer.h> |
| 31 | #include <linux/err.h> |
| 32 | #include <linux/android_vibrator.h> |
Devin Kim | a66ff76 | 2012-09-13 14:44:22 -0700 | [diff] [blame^] | 33 | #include <linux/mutex.h> |
Devin Kim | 5546885 | 2012-06-19 12:01:32 -0700 | [diff] [blame] | 34 | #include "../staging/android/timed_output.h" |
| 35 | |
| 36 | #define ANDROID_VIBRATOR_USE_WORKQUEUE |
| 37 | |
| 38 | #ifdef ANDROID_VIBRATOR_USE_WORKQUEUE |
| 39 | static struct workqueue_struct *vibrator_workqueue; |
| 40 | #endif |
| 41 | |
| 42 | struct timed_vibrator_data { |
| 43 | struct timed_output_dev dev; |
| 44 | struct hrtimer timer; |
| 45 | spinlock_t lock; |
Devin Kim | 5546885 | 2012-06-19 12:01:32 -0700 | [diff] [blame] | 46 | int max_timeout; |
Devin Kim | a66ff76 | 2012-09-13 14:44:22 -0700 | [diff] [blame^] | 47 | atomic_t vib_status; /* 1:on,0:off */ |
Devin Kim | 795a9a6 | 2012-08-28 10:08:46 -0700 | [diff] [blame] | 48 | atomic_t gain; /* default max gain */ |
| 49 | atomic_t pwm; |
| 50 | atomic_t ms_time; /* vibrator duration */ |
| 51 | struct android_vibrator_platform_data *pdata; |
Devin Kim | 5546885 | 2012-06-19 12:01:32 -0700 | [diff] [blame] | 52 | struct work_struct work_vibrator_off; |
| 53 | struct work_struct work_vibrator_on; |
| 54 | }; |
| 55 | |
Devin Kim | a66ff76 | 2012-09-13 14:44:22 -0700 | [diff] [blame^] | 56 | #ifdef ANDROID_VIBRATOR_USE_WORKQUEUE |
| 57 | static inline void vibrator_work(struct work_struct *work) |
| 58 | { |
| 59 | if (!work_pending(work)) |
| 60 | queue_work(vibrator_workqueue, work); |
| 61 | } |
| 62 | |
| 63 | #else |
| 64 | static inline void vibrator_work(struct work_struct *work) |
| 65 | { |
| 66 | if (!work_pending(work)) |
| 67 | schedule_work(work); |
| 68 | } |
| 69 | #endif |
| 70 | |
| 71 | static DEFINE_MUTEX(vib_lock); |
| 72 | |
Devin Kim | 5546885 | 2012-06-19 12:01:32 -0700 | [diff] [blame] | 73 | static int android_vibrator_force_set(struct timed_vibrator_data *vib, |
Devin Kim | 795a9a6 | 2012-08-28 10:08:46 -0700 | [diff] [blame] | 74 | int intensity, int pwm) |
Devin Kim | 5546885 | 2012-06-19 12:01:32 -0700 | [diff] [blame] | 75 | { |
| 76 | /* Check the Force value with Max and Min force value */ |
Devin Kim | 795a9a6 | 2012-08-28 10:08:46 -0700 | [diff] [blame] | 77 | int vib_duration_ms = 0; |
| 78 | pr_debug("%s: intensity : %d\n", __func__, intensity); |
Devin Kim | 5546885 | 2012-06-19 12:01:32 -0700 | [diff] [blame] | 79 | |
Devin Kim | 795a9a6 | 2012-08-28 10:08:46 -0700 | [diff] [blame] | 80 | if (intensity > 127) |
| 81 | intensity = 127; |
| 82 | if (intensity < -127) |
| 83 | intensity = -127; |
Devin Kim | 5546885 | 2012-06-19 12:01:32 -0700 | [diff] [blame] | 84 | |
Devin Kim | a66ff76 | 2012-09-13 14:44:22 -0700 | [diff] [blame^] | 85 | mutex_lock(&vib_lock); |
| 86 | |
Devin Kim | 5546885 | 2012-06-19 12:01:32 -0700 | [diff] [blame] | 87 | /* TODO: control the gain of vibrator */ |
Devin Kim | 795a9a6 | 2012-08-28 10:08:46 -0700 | [diff] [blame] | 88 | if (intensity == 0) { |
| 89 | vib->pdata->ic_enable_set(0); |
| 90 | vib->pdata->pwm_set(0, 0, pwm); |
Devin Kim | 5546885 | 2012-06-19 12:01:32 -0700 | [diff] [blame] | 91 | /* should be checked for vibrator response time */ |
Devin Kim | 795a9a6 | 2012-08-28 10:08:46 -0700 | [diff] [blame] | 92 | vib->pdata->power_set(0); |
Devin Kim | a66ff76 | 2012-09-13 14:44:22 -0700 | [diff] [blame^] | 93 | atomic_set(&vib->vib_status, 0); |
Devin Kim | 5546885 | 2012-06-19 12:01:32 -0700 | [diff] [blame] | 94 | } else { |
Devin Kim | a66ff76 | 2012-09-13 14:44:22 -0700 | [diff] [blame^] | 95 | if (work_pending(&vib->work_vibrator_off)) |
| 96 | cancel_work_sync(&vib->work_vibrator_off); |
Devin Kim | 5546885 | 2012-06-19 12:01:32 -0700 | [diff] [blame] | 97 | hrtimer_cancel(&vib->timer); |
Devin Kim | a66ff76 | 2012-09-13 14:44:22 -0700 | [diff] [blame^] | 98 | |
Devin Kim | 795a9a6 | 2012-08-28 10:08:46 -0700 | [diff] [blame] | 99 | vib_duration_ms = atomic_read(&vib->ms_time); |
Devin Kim | 5546885 | 2012-06-19 12:01:32 -0700 | [diff] [blame] | 100 | /* should be checked for vibrator response time */ |
Devin Kim | 795a9a6 | 2012-08-28 10:08:46 -0700 | [diff] [blame] | 101 | vib->pdata->power_set(1); |
| 102 | vib->pdata->pwm_set(1, intensity, pwm); |
| 103 | vib->pdata->ic_enable_set(1); |
Devin Kim | a66ff76 | 2012-09-13 14:44:22 -0700 | [diff] [blame^] | 104 | atomic_set(&vib->vib_status, 1); |
Devin Kim | 5546885 | 2012-06-19 12:01:32 -0700 | [diff] [blame] | 105 | |
Devin Kim | 5546885 | 2012-06-19 12:01:32 -0700 | [diff] [blame] | 106 | hrtimer_start(&vib->timer, |
Devin Kim | 795a9a6 | 2012-08-28 10:08:46 -0700 | [diff] [blame] | 107 | ns_to_ktime((u64)vib_duration_ms * NSEC_PER_MSEC), |
Devin Kim | 5546885 | 2012-06-19 12:01:32 -0700 | [diff] [blame] | 108 | HRTIMER_MODE_REL); |
| 109 | } |
Devin Kim | a66ff76 | 2012-09-13 14:44:22 -0700 | [diff] [blame^] | 110 | |
| 111 | mutex_unlock(&vib_lock); |
| 112 | |
Devin Kim | 5546885 | 2012-06-19 12:01:32 -0700 | [diff] [blame] | 113 | return 0; |
| 114 | } |
| 115 | |
| 116 | static void android_vibrator_on(struct work_struct *work) |
| 117 | { |
| 118 | struct timed_vibrator_data *vib = |
| 119 | container_of(work, struct timed_vibrator_data, |
| 120 | work_vibrator_on); |
Devin Kim | 795a9a6 | 2012-08-28 10:08:46 -0700 | [diff] [blame] | 121 | int gain = atomic_read(&vib->gain); |
| 122 | int pwm = atomic_read(&vib->pwm); |
Devin Kim | 5546885 | 2012-06-19 12:01:32 -0700 | [diff] [blame] | 123 | /* suspend /resume logging test */ |
Devin Kim | 795a9a6 | 2012-08-28 10:08:46 -0700 | [diff] [blame] | 124 | pr_debug("%s: gain = %d pwm = %d\n", __func__, |
| 125 | gain, pwm); |
Devin Kim | 5546885 | 2012-06-19 12:01:32 -0700 | [diff] [blame] | 126 | |
Devin Kim | 795a9a6 | 2012-08-28 10:08:46 -0700 | [diff] [blame] | 127 | android_vibrator_force_set(vib, gain, pwm); |
Devin Kim | 5546885 | 2012-06-19 12:01:32 -0700 | [diff] [blame] | 128 | } |
| 129 | |
| 130 | static void android_vibrator_off(struct work_struct *work) |
| 131 | { |
| 132 | struct timed_vibrator_data *vib = |
| 133 | container_of(work, struct timed_vibrator_data, |
| 134 | work_vibrator_off); |
| 135 | |
Devin Kim | 795a9a6 | 2012-08-28 10:08:46 -0700 | [diff] [blame] | 136 | pr_debug("%s\n", __func__); |
| 137 | android_vibrator_force_set(vib, 0, vib->pdata->vibe_n_value); |
Devin Kim | 5546885 | 2012-06-19 12:01:32 -0700 | [diff] [blame] | 138 | } |
| 139 | |
| 140 | static enum hrtimer_restart vibrator_timer_func(struct hrtimer *timer) |
| 141 | { |
| 142 | struct timed_vibrator_data *vib = |
| 143 | container_of(timer, struct timed_vibrator_data, timer); |
Devin Kim | a66ff76 | 2012-09-13 14:44:22 -0700 | [diff] [blame^] | 144 | vibrator_work(&vib->work_vibrator_off); |
Devin Kim | 5546885 | 2012-06-19 12:01:32 -0700 | [diff] [blame] | 145 | return HRTIMER_NORESTART; |
| 146 | } |
| 147 | |
| 148 | static int vibrator_get_time(struct timed_output_dev *dev) |
| 149 | { |
| 150 | struct timed_vibrator_data *vib = |
| 151 | container_of(dev, struct timed_vibrator_data, dev); |
| 152 | |
| 153 | if (hrtimer_active(&vib->timer)) { |
| 154 | ktime_t r = hrtimer_get_remaining(&vib->timer); |
| 155 | return ktime_to_ms(r); |
| 156 | } |
| 157 | |
| 158 | return 0; |
| 159 | } |
| 160 | |
Devin Kim | 795a9a6 | 2012-08-28 10:08:46 -0700 | [diff] [blame] | 161 | static void vibrator_enable(struct timed_output_dev *dev, int ms_time) |
Devin Kim | 5546885 | 2012-06-19 12:01:32 -0700 | [diff] [blame] | 162 | { |
| 163 | struct timed_vibrator_data *vib = |
| 164 | container_of(dev, struct timed_vibrator_data, dev); |
| 165 | unsigned long flags; |
| 166 | |
Devin Kim | 795a9a6 | 2012-08-28 10:08:46 -0700 | [diff] [blame] | 167 | pr_debug("%s: ms_time %d \n", __func__, ms_time); |
Devin Kim | 5546885 | 2012-06-19 12:01:32 -0700 | [diff] [blame] | 168 | spin_lock_irqsave(&vib->lock, flags); |
| 169 | |
Devin Kim | 795a9a6 | 2012-08-28 10:08:46 -0700 | [diff] [blame] | 170 | if (ms_time > 0) { |
| 171 | if (ms_time > vib->max_timeout) |
| 172 | ms_time = vib->max_timeout; |
Devin Kim | 5546885 | 2012-06-19 12:01:32 -0700 | [diff] [blame] | 173 | |
Devin Kim | 795a9a6 | 2012-08-28 10:08:46 -0700 | [diff] [blame] | 174 | atomic_set(&vib->ms_time, ms_time); |
Devin Kim | 5546885 | 2012-06-19 12:01:32 -0700 | [diff] [blame] | 175 | |
Devin Kim | a66ff76 | 2012-09-13 14:44:22 -0700 | [diff] [blame^] | 176 | vibrator_work(&vib->work_vibrator_on); |
Devin Kim | 5546885 | 2012-06-19 12:01:32 -0700 | [diff] [blame] | 177 | } else { |
Devin Kim | a66ff76 | 2012-09-13 14:44:22 -0700 | [diff] [blame^] | 178 | vibrator_work(&vib->work_vibrator_off); |
Devin Kim | 5546885 | 2012-06-19 12:01:32 -0700 | [diff] [blame] | 179 | } |
| 180 | spin_unlock_irqrestore(&vib->lock, flags); |
Devin Kim | 5546885 | 2012-06-19 12:01:32 -0700 | [diff] [blame] | 181 | } |
| 182 | |
| 183 | static ssize_t vibrator_amp_show(struct device *dev, |
| 184 | struct device_attribute *attr, char *buf) |
| 185 | { |
| 186 | struct timed_output_dev *dev_ = |
| 187 | (struct timed_output_dev *)dev_get_drvdata(dev); |
| 188 | struct timed_vibrator_data *vib = |
| 189 | container_of(dev_, struct timed_vibrator_data, dev); |
Devin Kim | 795a9a6 | 2012-08-28 10:08:46 -0700 | [diff] [blame] | 190 | int gain = atomic_read(&(vib->gain)); |
Devin Kim | 5546885 | 2012-06-19 12:01:32 -0700 | [diff] [blame] | 191 | |
| 192 | return sprintf(buf, "%d\n", gain); |
| 193 | } |
| 194 | |
| 195 | static ssize_t vibrator_amp_store(struct device *dev, |
| 196 | struct device_attribute *attr, const char *buf, size_t size) |
| 197 | { |
| 198 | struct timed_output_dev *dev_ = |
| 199 | (struct timed_output_dev *)dev_get_drvdata(dev); |
| 200 | struct timed_vibrator_data *vib = |
| 201 | container_of(dev_, struct timed_vibrator_data, dev); |
| 202 | |
| 203 | int gain; |
| 204 | sscanf(buf, "%d", &gain); |
Devin Kim | 795a9a6 | 2012-08-28 10:08:46 -0700 | [diff] [blame] | 205 | atomic_set(&vib->gain, gain); |
Devin Kim | 5546885 | 2012-06-19 12:01:32 -0700 | [diff] [blame] | 206 | |
| 207 | return size; |
| 208 | } |
| 209 | |
| 210 | static ssize_t vibrator_pwm_show(struct device *dev, |
| 211 | struct device_attribute *attr, char *buf) |
| 212 | { |
| 213 | struct timed_output_dev *dev_ = |
| 214 | (struct timed_output_dev *)dev_get_drvdata(dev); |
| 215 | struct timed_vibrator_data *vib = |
| 216 | container_of(dev_, struct timed_vibrator_data, dev); |
Devin Kim | 795a9a6 | 2012-08-28 10:08:46 -0700 | [diff] [blame] | 217 | int gain = atomic_read(&(vib->pwm)); |
Devin Kim | 5546885 | 2012-06-19 12:01:32 -0700 | [diff] [blame] | 218 | |
| 219 | gain = 4800/gain; |
| 220 | |
| 221 | return sprintf(buf, "%d\n", gain); |
| 222 | } |
| 223 | |
Devin Kim | 795a9a6 | 2012-08-28 10:08:46 -0700 | [diff] [blame] | 224 | |
Devin Kim | 5546885 | 2012-06-19 12:01:32 -0700 | [diff] [blame] | 225 | static ssize_t vibrator_pwm_store(struct device *dev, |
| 226 | struct device_attribute *attr, const char *buf, size_t size) |
| 227 | { |
| 228 | struct timed_output_dev *dev_ = |
| 229 | (struct timed_output_dev *)dev_get_drvdata(dev); |
| 230 | struct timed_vibrator_data *vib = |
| 231 | container_of(dev_, struct timed_vibrator_data, dev); |
| 232 | |
| 233 | int gain; |
| 234 | sscanf(buf, "%d", &gain); |
| 235 | |
| 236 | gain = 4800/gain; |
| 237 | |
Devin Kim | 795a9a6 | 2012-08-28 10:08:46 -0700 | [diff] [blame] | 238 | atomic_set(&vib->pwm, gain); |
Devin Kim | 5546885 | 2012-06-19 12:01:32 -0700 | [diff] [blame] | 239 | |
| 240 | return size; |
| 241 | } |
| 242 | |
Devin Kim | 795a9a6 | 2012-08-28 10:08:46 -0700 | [diff] [blame] | 243 | static struct device_attribute android_vibrator_device_attrs[] = { |
Devin Kim | 5546885 | 2012-06-19 12:01:32 -0700 | [diff] [blame] | 244 | __ATTR(amp, S_IRUGO | S_IWUSR, vibrator_amp_show, vibrator_amp_store), |
| 245 | __ATTR(pwm, S_IRUGO | S_IWUSR, vibrator_pwm_show, vibrator_pwm_store), |
| 246 | }; |
| 247 | |
| 248 | struct timed_vibrator_data android_vibrator_data = { |
| 249 | .dev.name = "vibrator", |
| 250 | .dev.enable = vibrator_enable, |
| 251 | .dev.get_time = vibrator_get_time, |
| 252 | .max_timeout = 30000, /* max time for vibrator enable 30 sec. */ |
Devin Kim | 5546885 | 2012-06-19 12:01:32 -0700 | [diff] [blame] | 253 | }; |
| 254 | |
| 255 | static int android_vibrator_probe(struct platform_device *pdev) |
| 256 | { |
| 257 | |
| 258 | int i, ret = 0; |
Devin Kim | 795a9a6 | 2012-08-28 10:08:46 -0700 | [diff] [blame] | 259 | struct timed_vibrator_data *vib = &android_vibrator_data; |
| 260 | vib->pdata = pdev->dev.platform_data; |
Devin Kim | 5546885 | 2012-06-19 12:01:32 -0700 | [diff] [blame] | 261 | |
Devin Kim | 795a9a6 | 2012-08-28 10:08:46 -0700 | [diff] [blame] | 262 | if (!vib->pdata) { |
| 263 | pr_err("%s: no platform data\n", __func__); |
Devin Kim | 5546885 | 2012-06-19 12:01:32 -0700 | [diff] [blame] | 264 | return -ENODEV; |
| 265 | } |
| 266 | |
Devin Kim | 795a9a6 | 2012-08-28 10:08:46 -0700 | [diff] [blame] | 267 | if (vib->pdata->vibrator_init) { |
| 268 | ret = vib->pdata->vibrator_init(); |
| 269 | if (ret < 0) { |
| 270 | pr_err("%s: failed to vibrator init\n", __func__); |
| 271 | return ret; |
| 272 | } |
| 273 | } |
| 274 | |
| 275 | platform_set_drvdata(pdev, &android_vibrator_data); |
| 276 | |
| 277 | atomic_set(&vib->gain, vib->pdata->amp); /* max value is 128 */ |
| 278 | atomic_set(&vib->pwm, vib->pdata->vibe_n_value); |
Devin Kim | a66ff76 | 2012-09-13 14:44:22 -0700 | [diff] [blame^] | 279 | atomic_set(&vib->vib_status, 0); |
Devin Kim | 795a9a6 | 2012-08-28 10:08:46 -0700 | [diff] [blame] | 280 | pr_info("android_vibrator: default amplitude %d \n", |
| 281 | vib->pdata->amp); |
Devin Kim | 5546885 | 2012-06-19 12:01:32 -0700 | [diff] [blame] | 282 | |
| 283 | INIT_WORK(&vib->work_vibrator_off, android_vibrator_off); |
| 284 | INIT_WORK(&vib->work_vibrator_on, android_vibrator_on); |
| 285 | hrtimer_init(&vib->timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL); |
| 286 | vib->timer.function = vibrator_timer_func; |
| 287 | spin_lock_init(&vib->lock); |
| 288 | |
| 289 | ret = timed_output_dev_register(&vib->dev); |
| 290 | if (ret < 0) { |
Devin Kim | 795a9a6 | 2012-08-28 10:08:46 -0700 | [diff] [blame] | 291 | pr_err("%s: failed to register timed output device\n", |
| 292 | __func__); |
| 293 | return ret; |
Devin Kim | 5546885 | 2012-06-19 12:01:32 -0700 | [diff] [blame] | 294 | } |
Devin Kim | 795a9a6 | 2012-08-28 10:08:46 -0700 | [diff] [blame] | 295 | |
| 296 | for (i = 0; i < ARRAY_SIZE(android_vibrator_device_attrs); i++) { |
| 297 | ret = device_create_file(vib->dev.dev, |
| 298 | &android_vibrator_device_attrs[i]); |
Devin Kim | 5546885 | 2012-06-19 12:01:32 -0700 | [diff] [blame] | 299 | if (ret < 0) { |
Devin Kim | 795a9a6 | 2012-08-28 10:08:46 -0700 | [diff] [blame] | 300 | pr_err("%s: failed to create sysfs\n", __func__); |
| 301 | goto err_sysfs; |
Devin Kim | 5546885 | 2012-06-19 12:01:32 -0700 | [diff] [blame] | 302 | } |
| 303 | } |
| 304 | |
Devin Kim | 795a9a6 | 2012-08-28 10:08:46 -0700 | [diff] [blame] | 305 | pr_info("android vibrator probed\n"); |
Devin Kim | 5546885 | 2012-06-19 12:01:32 -0700 | [diff] [blame] | 306 | |
| 307 | return 0; |
Devin Kim | 795a9a6 | 2012-08-28 10:08:46 -0700 | [diff] [blame] | 308 | |
| 309 | err_sysfs: |
| 310 | for (; i >= 0; i--) { |
| 311 | device_remove_file(vib->dev.dev, |
| 312 | &android_vibrator_device_attrs[i]); |
| 313 | } |
| 314 | |
| 315 | timed_output_dev_unregister(&vib->dev); |
| 316 | return ret; |
Devin Kim | 5546885 | 2012-06-19 12:01:32 -0700 | [diff] [blame] | 317 | } |
| 318 | |
| 319 | static int android_vibrator_remove(struct platform_device *pdev) |
| 320 | { |
| 321 | struct timed_vibrator_data *vib = |
| 322 | (struct timed_vibrator_data *)platform_get_drvdata(pdev); |
Devin Kim | 795a9a6 | 2012-08-28 10:08:46 -0700 | [diff] [blame] | 323 | int i; |
Devin Kim | 5546885 | 2012-06-19 12:01:32 -0700 | [diff] [blame] | 324 | |
Devin Kim | a66ff76 | 2012-09-13 14:44:22 -0700 | [diff] [blame^] | 325 | vibrator_work(&vib->work_vibrator_off); |
Devin Kim | 795a9a6 | 2012-08-28 10:08:46 -0700 | [diff] [blame] | 326 | for (i = ARRAY_SIZE(android_vibrator_device_attrs); i >= 0; i--) { |
| 327 | device_remove_file(vib->dev.dev, |
| 328 | &android_vibrator_device_attrs[i]); |
| 329 | } |
Devin Kim | 5546885 | 2012-06-19 12:01:32 -0700 | [diff] [blame] | 330 | |
| 331 | timed_output_dev_unregister(&vib->dev); |
| 332 | |
| 333 | return 0; |
| 334 | } |
| 335 | |
Devin Kim | 5546885 | 2012-06-19 12:01:32 -0700 | [diff] [blame] | 336 | static struct platform_driver android_vibrator_driver = { |
| 337 | .probe = android_vibrator_probe, |
| 338 | .remove = android_vibrator_remove, |
Devin Kim | 5546885 | 2012-06-19 12:01:32 -0700 | [diff] [blame] | 339 | .driver = { |
| 340 | .name = "android-vibrator", |
| 341 | }, |
| 342 | }; |
| 343 | |
| 344 | static int __init android_vibrator_init(void) |
| 345 | { |
Devin Kim | 5546885 | 2012-06-19 12:01:32 -0700 | [diff] [blame] | 346 | #ifdef ANDROID_VIBRATOR_USE_WORKQUEUE |
| 347 | vibrator_workqueue = create_workqueue("vibrator"); |
Devin Kim | 795a9a6 | 2012-08-28 10:08:46 -0700 | [diff] [blame] | 348 | if (!vibrator_workqueue) { |
| 349 | pr_err("%s: out of memory\n", __func__); |
Devin Kim | 5546885 | 2012-06-19 12:01:32 -0700 | [diff] [blame] | 350 | return -ENOMEM; |
Devin Kim | 795a9a6 | 2012-08-28 10:08:46 -0700 | [diff] [blame] | 351 | } |
Devin Kim | 5546885 | 2012-06-19 12:01:32 -0700 | [diff] [blame] | 352 | #endif |
| 353 | return platform_driver_register(&android_vibrator_driver); |
Devin Kim | 5546885 | 2012-06-19 12:01:32 -0700 | [diff] [blame] | 354 | } |
| 355 | |
| 356 | static void __exit android_vibrator_exit(void) |
| 357 | { |
Devin Kim | 5546885 | 2012-06-19 12:01:32 -0700 | [diff] [blame] | 358 | #ifdef ANDROID_VIBRATOR_USE_WORKQUEUE |
| 359 | if (vibrator_workqueue) |
| 360 | destroy_workqueue(vibrator_workqueue); |
Devin Kim | 5546885 | 2012-06-19 12:01:32 -0700 | [diff] [blame] | 361 | vibrator_workqueue = NULL; |
| 362 | #endif |
| 363 | platform_driver_unregister(&android_vibrator_driver); |
Devin Kim | 5546885 | 2012-06-19 12:01:32 -0700 | [diff] [blame] | 364 | } |
| 365 | |
| 366 | late_initcall_sync(android_vibrator_init); /* to let init lately */ |
| 367 | module_exit(android_vibrator_exit); |
| 368 | |
| 369 | MODULE_AUTHOR("LG Electronics Inc."); |
| 370 | MODULE_DESCRIPTION("Android Vibrator Driver"); |
| 371 | MODULE_LICENSE("GPL"); |