Misael Lopez Cruz | cc697d38 | 2011-05-01 03:51:24 -0500 | [diff] [blame] | 1 | /* |
| 2 | * twl6040-vibra.c - TWL6040 Vibrator driver |
| 3 | * |
| 4 | * Author: Jorge Eduardo Candelaria <jorge.candelaria@ti.com> |
| 5 | * Author: Misael Lopez Cruz <misael.lopez@ti.com> |
| 6 | * |
| 7 | * Copyright: (C) 2011 Texas Instruments, Inc. |
| 8 | * |
| 9 | * Based on twl4030-vibra.c by Henrik Saari <henrik.saari@nokia.com> |
| 10 | * Felipe Balbi <felipe.balbi@nokia.com> |
| 11 | * Jari Vanhala <ext-javi.vanhala@nokia.com> |
| 12 | * |
| 13 | * This program is free software; you can redistribute it and/or modify |
| 14 | * it under the terms of the GNU General Public License version 2 as |
| 15 | * published by the Free Software Foundation. |
| 16 | * |
| 17 | * This program is distributed in the hope that it will be useful, but |
| 18 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 20 | * General Public License for more details. |
| 21 | * |
| 22 | * You should have received a copy of the GNU General Public License |
| 23 | * along with this program; if not, write to the Free Software |
| 24 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA |
| 25 | * 02110-1301 USA |
| 26 | * |
| 27 | */ |
| 28 | #include <linux/module.h> |
| 29 | #include <linux/platform_device.h> |
Peter Ujfalusi | 9ac7b1a | 2012-05-07 08:45:50 -0700 | [diff] [blame] | 30 | #include <linux/of.h> |
Misael Lopez Cruz | cc697d38 | 2011-05-01 03:51:24 -0500 | [diff] [blame] | 31 | #include <linux/workqueue.h> |
Peter Ujfalusi | 8eaeb93 | 2012-04-03 11:56:51 +0300 | [diff] [blame] | 32 | #include <linux/input.h> |
Misael Lopez Cruz | cc697d38 | 2011-05-01 03:51:24 -0500 | [diff] [blame] | 33 | #include <linux/mfd/twl6040.h> |
| 34 | #include <linux/slab.h> |
| 35 | #include <linux/delay.h> |
| 36 | #include <linux/regulator/consumer.h> |
| 37 | |
| 38 | #define EFFECT_DIR_180_DEG 0x8000 |
| 39 | |
| 40 | /* Recommended modulation index 85% */ |
| 41 | #define TWL6040_VIBRA_MOD 85 |
| 42 | |
| 43 | #define TWL6040_NUM_SUPPLIES 2 |
| 44 | |
| 45 | struct vibra_info { |
| 46 | struct device *dev; |
| 47 | struct input_dev *input_dev; |
| 48 | struct workqueue_struct *workqueue; |
| 49 | struct work_struct play_work; |
H. Nikolaus Schaller | 9e4cc25 | 2016-04-25 14:02:16 -0700 | [diff] [blame^] | 50 | |
Peter Ujfalusi | 625cbe4 | 2011-07-04 19:50:02 +0300 | [diff] [blame] | 51 | int irq; |
Misael Lopez Cruz | cc697d38 | 2011-05-01 03:51:24 -0500 | [diff] [blame] | 52 | |
| 53 | bool enabled; |
| 54 | int weak_speed; |
| 55 | int strong_speed; |
| 56 | int direction; |
| 57 | |
| 58 | unsigned int vibldrv_res; |
| 59 | unsigned int vibrdrv_res; |
| 60 | unsigned int viblmotor_res; |
| 61 | unsigned int vibrmotor_res; |
| 62 | |
| 63 | struct regulator_bulk_data supplies[TWL6040_NUM_SUPPLIES]; |
| 64 | |
| 65 | struct twl6040 *twl6040; |
| 66 | }; |
| 67 | |
| 68 | static irqreturn_t twl6040_vib_irq_handler(int irq, void *data) |
| 69 | { |
| 70 | struct vibra_info *info = data; |
| 71 | struct twl6040 *twl6040 = info->twl6040; |
| 72 | u8 status; |
| 73 | |
| 74 | status = twl6040_reg_read(twl6040, TWL6040_REG_STATUS); |
| 75 | if (status & TWL6040_VIBLOCDET) { |
| 76 | dev_warn(info->dev, "Left Vibrator overcurrent detected\n"); |
| 77 | twl6040_clear_bits(twl6040, TWL6040_REG_VIBCTLL, |
Peter Ujfalusi | 1e036f6 | 2011-10-12 11:57:53 +0300 | [diff] [blame] | 78 | TWL6040_VIBENA); |
Misael Lopez Cruz | cc697d38 | 2011-05-01 03:51:24 -0500 | [diff] [blame] | 79 | } |
| 80 | if (status & TWL6040_VIBROCDET) { |
| 81 | dev_warn(info->dev, "Right Vibrator overcurrent detected\n"); |
| 82 | twl6040_clear_bits(twl6040, TWL6040_REG_VIBCTLR, |
Peter Ujfalusi | 1e036f6 | 2011-10-12 11:57:53 +0300 | [diff] [blame] | 83 | TWL6040_VIBENA); |
Misael Lopez Cruz | cc697d38 | 2011-05-01 03:51:24 -0500 | [diff] [blame] | 84 | } |
| 85 | |
| 86 | return IRQ_HANDLED; |
| 87 | } |
| 88 | |
| 89 | static void twl6040_vibra_enable(struct vibra_info *info) |
| 90 | { |
| 91 | struct twl6040 *twl6040 = info->twl6040; |
| 92 | int ret; |
| 93 | |
| 94 | ret = regulator_bulk_enable(ARRAY_SIZE(info->supplies), info->supplies); |
| 95 | if (ret) { |
| 96 | dev_err(info->dev, "failed to enable regulators %d\n", ret); |
| 97 | return; |
| 98 | } |
| 99 | |
| 100 | twl6040_power(info->twl6040, 1); |
Peter Ujfalusi | 7e96898 | 2011-09-15 15:39:25 +0300 | [diff] [blame] | 101 | if (twl6040_get_revid(twl6040) <= TWL6040_REV_ES1_1) { |
Misael Lopez Cruz | cc697d38 | 2011-05-01 03:51:24 -0500 | [diff] [blame] | 102 | /* |
| 103 | * ERRATA: Disable overcurrent protection for at least |
| 104 | * 3ms when enabling vibrator drivers to avoid false |
| 105 | * overcurrent detection |
| 106 | */ |
| 107 | twl6040_reg_write(twl6040, TWL6040_REG_VIBCTLL, |
Peter Ujfalusi | 1e036f6 | 2011-10-12 11:57:53 +0300 | [diff] [blame] | 108 | TWL6040_VIBENA | TWL6040_VIBCTRL); |
Misael Lopez Cruz | cc697d38 | 2011-05-01 03:51:24 -0500 | [diff] [blame] | 109 | twl6040_reg_write(twl6040, TWL6040_REG_VIBCTLR, |
Peter Ujfalusi | 1e036f6 | 2011-10-12 11:57:53 +0300 | [diff] [blame] | 110 | TWL6040_VIBENA | TWL6040_VIBCTRL); |
Misael Lopez Cruz | cc697d38 | 2011-05-01 03:51:24 -0500 | [diff] [blame] | 111 | usleep_range(3000, 3500); |
| 112 | } |
| 113 | |
| 114 | twl6040_reg_write(twl6040, TWL6040_REG_VIBCTLL, |
Peter Ujfalusi | 1e036f6 | 2011-10-12 11:57:53 +0300 | [diff] [blame] | 115 | TWL6040_VIBENA); |
Misael Lopez Cruz | cc697d38 | 2011-05-01 03:51:24 -0500 | [diff] [blame] | 116 | twl6040_reg_write(twl6040, TWL6040_REG_VIBCTLR, |
Peter Ujfalusi | 1e036f6 | 2011-10-12 11:57:53 +0300 | [diff] [blame] | 117 | TWL6040_VIBENA); |
Misael Lopez Cruz | cc697d38 | 2011-05-01 03:51:24 -0500 | [diff] [blame] | 118 | |
| 119 | info->enabled = true; |
| 120 | } |
| 121 | |
| 122 | static void twl6040_vibra_disable(struct vibra_info *info) |
| 123 | { |
| 124 | struct twl6040 *twl6040 = info->twl6040; |
| 125 | |
| 126 | twl6040_reg_write(twl6040, TWL6040_REG_VIBCTLL, 0x00); |
| 127 | twl6040_reg_write(twl6040, TWL6040_REG_VIBCTLR, 0x00); |
| 128 | twl6040_power(info->twl6040, 0); |
| 129 | |
| 130 | regulator_bulk_disable(ARRAY_SIZE(info->supplies), info->supplies); |
| 131 | |
| 132 | info->enabled = false; |
| 133 | } |
| 134 | |
| 135 | static u8 twl6040_vibra_code(int vddvib, int vibdrv_res, int motor_res, |
| 136 | int speed, int direction) |
| 137 | { |
| 138 | int vpk, max_code; |
| 139 | u8 vibdat; |
| 140 | |
| 141 | /* output swing */ |
| 142 | vpk = (vddvib * motor_res * TWL6040_VIBRA_MOD) / |
| 143 | (100 * (vibdrv_res + motor_res)); |
| 144 | |
| 145 | /* 50mV per VIBDAT code step */ |
| 146 | max_code = vpk / 50; |
| 147 | if (max_code > TWL6040_VIBDAT_MAX) |
| 148 | max_code = TWL6040_VIBDAT_MAX; |
| 149 | |
| 150 | /* scale speed to max allowed code */ |
| 151 | vibdat = (u8)((speed * max_code) / USHRT_MAX); |
| 152 | |
| 153 | /* 2's complement for direction > 180 degrees */ |
| 154 | vibdat *= direction; |
| 155 | |
| 156 | return vibdat; |
| 157 | } |
| 158 | |
| 159 | static void twl6040_vibra_set_effect(struct vibra_info *info) |
| 160 | { |
| 161 | struct twl6040 *twl6040 = info->twl6040; |
| 162 | u8 vibdatl, vibdatr; |
| 163 | int volt; |
| 164 | |
| 165 | /* weak motor */ |
| 166 | volt = regulator_get_voltage(info->supplies[0].consumer) / 1000; |
| 167 | vibdatl = twl6040_vibra_code(volt, info->vibldrv_res, |
| 168 | info->viblmotor_res, |
| 169 | info->weak_speed, info->direction); |
| 170 | |
| 171 | /* strong motor */ |
| 172 | volt = regulator_get_voltage(info->supplies[1].consumer) / 1000; |
| 173 | vibdatr = twl6040_vibra_code(volt, info->vibrdrv_res, |
| 174 | info->vibrmotor_res, |
| 175 | info->strong_speed, info->direction); |
| 176 | |
| 177 | twl6040_reg_write(twl6040, TWL6040_REG_VIBDATL, vibdatl); |
| 178 | twl6040_reg_write(twl6040, TWL6040_REG_VIBDATR, vibdatr); |
| 179 | } |
| 180 | |
| 181 | static void vibra_play_work(struct work_struct *work) |
| 182 | { |
| 183 | struct vibra_info *info = container_of(work, |
| 184 | struct vibra_info, play_work); |
| 185 | |
Misael Lopez Cruz | cc697d38 | 2011-05-01 03:51:24 -0500 | [diff] [blame] | 186 | if (info->weak_speed || info->strong_speed) { |
| 187 | if (!info->enabled) |
| 188 | twl6040_vibra_enable(info); |
| 189 | |
| 190 | twl6040_vibra_set_effect(info); |
| 191 | } else if (info->enabled) |
| 192 | twl6040_vibra_disable(info); |
| 193 | |
Misael Lopez Cruz | cc697d38 | 2011-05-01 03:51:24 -0500 | [diff] [blame] | 194 | } |
| 195 | |
| 196 | static int vibra_play(struct input_dev *input, void *data, |
| 197 | struct ff_effect *effect) |
| 198 | { |
| 199 | struct vibra_info *info = input_get_drvdata(input); |
| 200 | int ret; |
| 201 | |
Peter Ujfalusi | 5f07c32 | 2011-10-12 11:57:56 +0300 | [diff] [blame] | 202 | /* Do not allow effect, while the routing is set to use audio */ |
| 203 | ret = twl6040_get_vibralr_status(info->twl6040); |
| 204 | if (ret & TWL6040_VIBSEL) { |
| 205 | dev_info(&input->dev, "Vibra is configured for audio\n"); |
| 206 | return -EBUSY; |
| 207 | } |
| 208 | |
Misael Lopez Cruz | cc697d38 | 2011-05-01 03:51:24 -0500 | [diff] [blame] | 209 | info->weak_speed = effect->u.rumble.weak_magnitude; |
| 210 | info->strong_speed = effect->u.rumble.strong_magnitude; |
| 211 | info->direction = effect->direction < EFFECT_DIR_180_DEG ? 1 : -1; |
| 212 | |
| 213 | ret = queue_work(info->workqueue, &info->play_work); |
| 214 | if (!ret) { |
| 215 | dev_info(&input->dev, "work is already on queue\n"); |
| 216 | return ret; |
| 217 | } |
| 218 | |
| 219 | return 0; |
| 220 | } |
| 221 | |
| 222 | static void twl6040_vibra_close(struct input_dev *input) |
| 223 | { |
| 224 | struct vibra_info *info = input_get_drvdata(input); |
| 225 | |
| 226 | cancel_work_sync(&info->play_work); |
| 227 | |
Misael Lopez Cruz | cc697d38 | 2011-05-01 03:51:24 -0500 | [diff] [blame] | 228 | if (info->enabled) |
| 229 | twl6040_vibra_disable(info); |
Misael Lopez Cruz | cc697d38 | 2011-05-01 03:51:24 -0500 | [diff] [blame] | 230 | } |
| 231 | |
Jingoo Han | 97a652a | 2014-11-02 00:02:46 -0700 | [diff] [blame] | 232 | static int __maybe_unused twl6040_vibra_suspend(struct device *dev) |
Misael Lopez Cruz | cc697d38 | 2011-05-01 03:51:24 -0500 | [diff] [blame] | 233 | { |
| 234 | struct platform_device *pdev = to_platform_device(dev); |
| 235 | struct vibra_info *info = platform_get_drvdata(pdev); |
| 236 | |
H. Nikolaus Schaller | 9e4cc25 | 2016-04-25 14:02:16 -0700 | [diff] [blame^] | 237 | cancel_work_sync(&info->play_work); |
Misael Lopez Cruz | cc697d38 | 2011-05-01 03:51:24 -0500 | [diff] [blame] | 238 | |
| 239 | if (info->enabled) |
| 240 | twl6040_vibra_disable(info); |
| 241 | |
Misael Lopez Cruz | cc697d38 | 2011-05-01 03:51:24 -0500 | [diff] [blame] | 242 | return 0; |
| 243 | } |
Misael Lopez Cruz | cc697d38 | 2011-05-01 03:51:24 -0500 | [diff] [blame] | 244 | |
| 245 | static SIMPLE_DEV_PM_OPS(twl6040_vibra_pm_ops, twl6040_vibra_suspend, NULL); |
| 246 | |
Bill Pemberton | 5298cc4 | 2012-11-23 21:38:25 -0800 | [diff] [blame] | 247 | static int twl6040_vibra_probe(struct platform_device *pdev) |
Misael Lopez Cruz | cc697d38 | 2011-05-01 03:51:24 -0500 | [diff] [blame] | 248 | { |
Peter Ujfalusi | e7ec014 | 2012-06-12 01:10:02 -0700 | [diff] [blame] | 249 | struct device *twl6040_core_dev = pdev->dev.parent; |
Dmitry Torokhov | 32e573c | 2014-01-04 00:08:49 -0800 | [diff] [blame] | 250 | struct device_node *twl6040_core_node; |
Misael Lopez Cruz | cc697d38 | 2011-05-01 03:51:24 -0500 | [diff] [blame] | 251 | struct vibra_info *info; |
Peter Ujfalusi | 9ac7b1a | 2012-05-07 08:45:50 -0700 | [diff] [blame] | 252 | int vddvibl_uV = 0; |
| 253 | int vddvibr_uV = 0; |
Fabio Estevam | 1f9e147 | 2014-04-25 09:21:12 -0700 | [diff] [blame] | 254 | int error; |
Misael Lopez Cruz | cc697d38 | 2011-05-01 03:51:24 -0500 | [diff] [blame] | 255 | |
Peter Ujfalusi | e7ec014 | 2012-06-12 01:10:02 -0700 | [diff] [blame] | 256 | twl6040_core_node = of_find_node_by_name(twl6040_core_dev->of_node, |
| 257 | "vibra"); |
Peter Ujfalusi | 7bf2a98 | 2013-07-13 13:36:19 -0700 | [diff] [blame] | 258 | if (!twl6040_core_node) { |
| 259 | dev_err(&pdev->dev, "parent of node is missing?\n"); |
Misael Lopez Cruz | cc697d38 | 2011-05-01 03:51:24 -0500 | [diff] [blame] | 260 | return -EINVAL; |
| 261 | } |
| 262 | |
Peter Ujfalusi | b2ebcc1 | 2013-01-25 00:03:50 -0800 | [diff] [blame] | 263 | info = devm_kzalloc(&pdev->dev, sizeof(*info), GFP_KERNEL); |
Misael Lopez Cruz | cc697d38 | 2011-05-01 03:51:24 -0500 | [diff] [blame] | 264 | if (!info) { |
Libo Chen | f048dd1 | 2014-01-04 00:00:30 -0800 | [diff] [blame] | 265 | of_node_put(twl6040_core_node); |
Misael Lopez Cruz | cc697d38 | 2011-05-01 03:51:24 -0500 | [diff] [blame] | 266 | dev_err(&pdev->dev, "couldn't allocate memory\n"); |
| 267 | return -ENOMEM; |
| 268 | } |
| 269 | |
| 270 | info->dev = &pdev->dev; |
Peter Ujfalusi | 9ac7b1a | 2012-05-07 08:45:50 -0700 | [diff] [blame] | 271 | |
Misael Lopez Cruz | cc697d38 | 2011-05-01 03:51:24 -0500 | [diff] [blame] | 272 | info->twl6040 = dev_get_drvdata(pdev->dev.parent); |
Peter Ujfalusi | 7bf2a98 | 2013-07-13 13:36:19 -0700 | [diff] [blame] | 273 | |
| 274 | of_property_read_u32(twl6040_core_node, "ti,vibldrv-res", |
| 275 | &info->vibldrv_res); |
| 276 | of_property_read_u32(twl6040_core_node, "ti,vibrdrv-res", |
| 277 | &info->vibrdrv_res); |
| 278 | of_property_read_u32(twl6040_core_node, "ti,viblmotor-res", |
| 279 | &info->viblmotor_res); |
| 280 | of_property_read_u32(twl6040_core_node, "ti,vibrmotor-res", |
| 281 | &info->vibrmotor_res); |
| 282 | of_property_read_u32(twl6040_core_node, "ti,vddvibl-uV", &vddvibl_uV); |
| 283 | of_property_read_u32(twl6040_core_node, "ti,vddvibr-uV", &vddvibr_uV); |
Peter Ujfalusi | 9ac7b1a | 2012-05-07 08:45:50 -0700 | [diff] [blame] | 284 | |
Libo Chen | f048dd1 | 2014-01-04 00:00:30 -0800 | [diff] [blame] | 285 | of_node_put(twl6040_core_node); |
| 286 | |
Misael Lopez Cruz | cc697d38 | 2011-05-01 03:51:24 -0500 | [diff] [blame] | 287 | if ((!info->vibldrv_res && !info->viblmotor_res) || |
| 288 | (!info->vibrdrv_res && !info->vibrmotor_res)) { |
| 289 | dev_err(info->dev, "invalid vibra driver/motor resistance\n"); |
Peter Ujfalusi | b2ebcc1 | 2013-01-25 00:03:50 -0800 | [diff] [blame] | 290 | return -EINVAL; |
Misael Lopez Cruz | cc697d38 | 2011-05-01 03:51:24 -0500 | [diff] [blame] | 291 | } |
| 292 | |
Peter Ujfalusi | 625cbe4 | 2011-07-04 19:50:02 +0300 | [diff] [blame] | 293 | info->irq = platform_get_irq(pdev, 0); |
| 294 | if (info->irq < 0) { |
| 295 | dev_err(info->dev, "invalid irq\n"); |
Peter Ujfalusi | b2ebcc1 | 2013-01-25 00:03:50 -0800 | [diff] [blame] | 296 | return -EINVAL; |
Peter Ujfalusi | 625cbe4 | 2011-07-04 19:50:02 +0300 | [diff] [blame] | 297 | } |
| 298 | |
Fabio Estevam | 1f9e147 | 2014-04-25 09:21:12 -0700 | [diff] [blame] | 299 | error = devm_request_threaded_irq(&pdev->dev, info->irq, NULL, |
Fabio Estevam | 4be01a2 | 2015-05-15 15:55:42 -0700 | [diff] [blame] | 300 | twl6040_vib_irq_handler, |
| 301 | IRQF_ONESHOT, |
Fabio Estevam | 1f9e147 | 2014-04-25 09:21:12 -0700 | [diff] [blame] | 302 | "twl6040_irq_vib", info); |
| 303 | if (error) { |
| 304 | dev_err(info->dev, "VIB IRQ request failed: %d\n", error); |
| 305 | return error; |
Peter Ujfalusi | b2ebcc1 | 2013-01-25 00:03:50 -0800 | [diff] [blame] | 306 | } |
| 307 | |
| 308 | info->supplies[0].supply = "vddvibl"; |
| 309 | info->supplies[1].supply = "vddvibr"; |
| 310 | /* |
| 311 | * When booted with Device tree the regulators are attached to the |
| 312 | * parent device (twl6040 MFD core) |
| 313 | */ |
Fabio Estevam | 1f9e147 | 2014-04-25 09:21:12 -0700 | [diff] [blame] | 314 | error = devm_regulator_bulk_get(twl6040_core_dev, |
| 315 | ARRAY_SIZE(info->supplies), |
| 316 | info->supplies); |
| 317 | if (error) { |
| 318 | dev_err(info->dev, "couldn't get regulators %d\n", error); |
| 319 | return error; |
Peter Ujfalusi | b2ebcc1 | 2013-01-25 00:03:50 -0800 | [diff] [blame] | 320 | } |
| 321 | |
| 322 | if (vddvibl_uV) { |
Fabio Estevam | 1f9e147 | 2014-04-25 09:21:12 -0700 | [diff] [blame] | 323 | error = regulator_set_voltage(info->supplies[0].consumer, |
| 324 | vddvibl_uV, vddvibl_uV); |
| 325 | if (error) { |
Peter Ujfalusi | b2ebcc1 | 2013-01-25 00:03:50 -0800 | [diff] [blame] | 326 | dev_err(info->dev, "failed to set VDDVIBL volt %d\n", |
Fabio Estevam | 1f9e147 | 2014-04-25 09:21:12 -0700 | [diff] [blame] | 327 | error); |
| 328 | return error; |
Peter Ujfalusi | b2ebcc1 | 2013-01-25 00:03:50 -0800 | [diff] [blame] | 329 | } |
| 330 | } |
| 331 | |
| 332 | if (vddvibr_uV) { |
Fabio Estevam | 1f9e147 | 2014-04-25 09:21:12 -0700 | [diff] [blame] | 333 | error = regulator_set_voltage(info->supplies[1].consumer, |
| 334 | vddvibr_uV, vddvibr_uV); |
| 335 | if (error) { |
Peter Ujfalusi | b2ebcc1 | 2013-01-25 00:03:50 -0800 | [diff] [blame] | 336 | dev_err(info->dev, "failed to set VDDVIBR volt %d\n", |
Fabio Estevam | 1f9e147 | 2014-04-25 09:21:12 -0700 | [diff] [blame] | 337 | error); |
| 338 | return error; |
Peter Ujfalusi | b2ebcc1 | 2013-01-25 00:03:50 -0800 | [diff] [blame] | 339 | } |
| 340 | } |
| 341 | |
Peter Ujfalusi | b2ebcc1 | 2013-01-25 00:03:50 -0800 | [diff] [blame] | 342 | INIT_WORK(&info->play_work, vibra_play_work); |
| 343 | |
Fabio Estevam | 1f9e147 | 2014-04-25 09:21:12 -0700 | [diff] [blame] | 344 | info->input_dev = devm_input_allocate_device(&pdev->dev); |
| 345 | if (!info->input_dev) { |
Misael Lopez Cruz | cc697d38 | 2011-05-01 03:51:24 -0500 | [diff] [blame] | 346 | dev_err(info->dev, "couldn't allocate input device\n"); |
Fabio Estevam | 1f9e147 | 2014-04-25 09:21:12 -0700 | [diff] [blame] | 347 | return -ENOMEM; |
Misael Lopez Cruz | cc697d38 | 2011-05-01 03:51:24 -0500 | [diff] [blame] | 348 | } |
| 349 | |
| 350 | input_set_drvdata(info->input_dev, info); |
| 351 | |
| 352 | info->input_dev->name = "twl6040:vibrator"; |
| 353 | info->input_dev->id.version = 1; |
| 354 | info->input_dev->dev.parent = pdev->dev.parent; |
| 355 | info->input_dev->close = twl6040_vibra_close; |
| 356 | __set_bit(FF_RUMBLE, info->input_dev->ffbit); |
| 357 | |
Fabio Estevam | 1f9e147 | 2014-04-25 09:21:12 -0700 | [diff] [blame] | 358 | error = input_ff_create_memless(info->input_dev, NULL, vibra_play); |
| 359 | if (error) { |
Misael Lopez Cruz | cc697d38 | 2011-05-01 03:51:24 -0500 | [diff] [blame] | 360 | dev_err(info->dev, "couldn't register vibrator to FF\n"); |
Fabio Estevam | 1f9e147 | 2014-04-25 09:21:12 -0700 | [diff] [blame] | 361 | return error; |
Misael Lopez Cruz | cc697d38 | 2011-05-01 03:51:24 -0500 | [diff] [blame] | 362 | } |
| 363 | |
Fabio Estevam | 1f9e147 | 2014-04-25 09:21:12 -0700 | [diff] [blame] | 364 | error = input_register_device(info->input_dev); |
| 365 | if (error) { |
Misael Lopez Cruz | cc697d38 | 2011-05-01 03:51:24 -0500 | [diff] [blame] | 366 | dev_err(info->dev, "couldn't register input device\n"); |
Fabio Estevam | 1f9e147 | 2014-04-25 09:21:12 -0700 | [diff] [blame] | 367 | return error; |
Misael Lopez Cruz | cc697d38 | 2011-05-01 03:51:24 -0500 | [diff] [blame] | 368 | } |
| 369 | |
| 370 | platform_set_drvdata(pdev, info); |
| 371 | |
Misael Lopez Cruz | cc697d38 | 2011-05-01 03:51:24 -0500 | [diff] [blame] | 372 | return 0; |
Misael Lopez Cruz | cc697d38 | 2011-05-01 03:51:24 -0500 | [diff] [blame] | 373 | } |
| 374 | |
| 375 | static struct platform_driver twl6040_vibra_driver = { |
| 376 | .probe = twl6040_vibra_probe, |
Misael Lopez Cruz | cc697d38 | 2011-05-01 03:51:24 -0500 | [diff] [blame] | 377 | .driver = { |
| 378 | .name = "twl6040-vibra", |
Misael Lopez Cruz | cc697d38 | 2011-05-01 03:51:24 -0500 | [diff] [blame] | 379 | .pm = &twl6040_vibra_pm_ops, |
| 380 | }, |
| 381 | }; |
JJ Ding | 840a746 | 2011-11-29 11:08:40 -0800 | [diff] [blame] | 382 | module_platform_driver(twl6040_vibra_driver); |
Misael Lopez Cruz | cc697d38 | 2011-05-01 03:51:24 -0500 | [diff] [blame] | 383 | |
| 384 | MODULE_ALIAS("platform:twl6040-vibra"); |
| 385 | MODULE_DESCRIPTION("TWL6040 Vibra driver"); |
| 386 | MODULE_LICENSE("GPL"); |
| 387 | MODULE_AUTHOR("Jorge Eduardo Candelaria <jorge.candelaria@ti.com>"); |
| 388 | MODULE_AUTHOR("Misael Lopez Cruz <misael.lopez@ti.com>"); |