diff options
| author | Mark Brown <broonie@opensource.wolfsonmicro.com> | 2012-11-26 16:17:21 -0500 |
|---|---|---|
| committer | Mark Brown <broonie@opensource.wolfsonmicro.com> | 2012-11-28 08:43:52 -0500 |
| commit | 9dd555e2f4de1af1bb0f75cc84ed0708fcdb5987 (patch) | |
| tree | 1703971a7f141bfdc60ebed8e7b7f5d99e8b9e89 | |
| parent | b951b523ea45d5717377ce2216afe98440001660 (diff) | |
Input - arizona-haptics: Add driver haptics module on Arizona CODECs
The Arizona CODECs contain a haptics module providing vibration feedback
support. Implement basic support for this, providing simple start/stop and
signal magnitude control.
Since the output path for haptics is routed through the CODEC audio routing
it is modelled as a signal generator within ASoC, the haptics driver calls
DAPM to start and stop the output drivers. An appropriate output path must
be configured via ALSA to connect the haptics source to the correct output.
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
| -rw-r--r-- | drivers/input/misc/Kconfig | 10 | ||||
| -rw-r--r-- | drivers/input/misc/Makefile | 1 | ||||
| -rw-r--r-- | drivers/input/misc/arizona-haptics.c | 255 | ||||
| -rw-r--r-- | include/linux/mfd/arizona/pdata.h | 6 |
4 files changed, 272 insertions, 0 deletions
diff --git a/drivers/input/misc/Kconfig b/drivers/input/misc/Kconfig index 7c0f1ecfdd7a..104a7c3153c0 100644 --- a/drivers/input/misc/Kconfig +++ b/drivers/input/misc/Kconfig | |||
| @@ -72,6 +72,16 @@ config INPUT_AD714X_SPI | |||
| 72 | To compile this driver as a module, choose M here: the | 72 | To compile this driver as a module, choose M here: the |
| 73 | module will be called ad714x-spi. | 73 | module will be called ad714x-spi. |
| 74 | 74 | ||
| 75 | config INPUT_ARIZONA_HAPTICS | ||
| 76 | tristate "Arizona haptics support" | ||
| 77 | depends on MFD_ARIZONA && SND_SOC | ||
| 78 | select INPUT_FF_MEMLESS | ||
| 79 | help | ||
| 80 | Say Y to enable support for the haptics module in Arizona CODECs. | ||
| 81 | |||
| 82 | To compile this driver as a module, choose M here: the | ||
| 83 | module will be called arizona-haptics. | ||
| 84 | |||
| 75 | config INPUT_BMA150 | 85 | config INPUT_BMA150 |
| 76 | tristate "BMA150/SMB380 acceleration sensor support" | 86 | tristate "BMA150/SMB380 acceleration sensor support" |
| 77 | depends on I2C | 87 | depends on I2C |
diff --git a/drivers/input/misc/Makefile b/drivers/input/misc/Makefile index 83fe6f5b77d1..5ea769eda999 100644 --- a/drivers/input/misc/Makefile +++ b/drivers/input/misc/Makefile | |||
| @@ -14,6 +14,7 @@ obj-$(CONFIG_INPUT_ADXL34X) += adxl34x.o | |||
| 14 | obj-$(CONFIG_INPUT_ADXL34X_I2C) += adxl34x-i2c.o | 14 | obj-$(CONFIG_INPUT_ADXL34X_I2C) += adxl34x-i2c.o |
| 15 | obj-$(CONFIG_INPUT_ADXL34X_SPI) += adxl34x-spi.o | 15 | obj-$(CONFIG_INPUT_ADXL34X_SPI) += adxl34x-spi.o |
| 16 | obj-$(CONFIG_INPUT_APANEL) += apanel.o | 16 | obj-$(CONFIG_INPUT_APANEL) += apanel.o |
| 17 | obj-$(CONFIG_INPUT_ARIZONA_HAPTICS) += arizona-haptics.o | ||
| 17 | obj-$(CONFIG_INPUT_ATI_REMOTE2) += ati_remote2.o | 18 | obj-$(CONFIG_INPUT_ATI_REMOTE2) += ati_remote2.o |
| 18 | obj-$(CONFIG_INPUT_ATLAS_BTNS) += atlas_btns.o | 19 | obj-$(CONFIG_INPUT_ATLAS_BTNS) += atlas_btns.o |
| 19 | obj-$(CONFIG_INPUT_BFIN_ROTARY) += bfin_rotary.o | 20 | obj-$(CONFIG_INPUT_BFIN_ROTARY) += bfin_rotary.o |
diff --git a/drivers/input/misc/arizona-haptics.c b/drivers/input/misc/arizona-haptics.c new file mode 100644 index 000000000000..7a04f54ef961 --- /dev/null +++ b/drivers/input/misc/arizona-haptics.c | |||
| @@ -0,0 +1,255 @@ | |||
| 1 | /* | ||
| 2 | * Arizona haptics driver | ||
| 3 | * | ||
| 4 | * Copyright 2012 Wolfson Microelectronics plc | ||
| 5 | * | ||
| 6 | * Author: Mark Brown <broonie@opensource.wolfsonmicro.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 version 2 as | ||
| 10 | * published by the Free Software Foundation. | ||
| 11 | */ | ||
| 12 | |||
| 13 | #include <linux/module.h> | ||
| 14 | #include <linux/platform_device.h> | ||
| 15 | #include <linux/input.h> | ||
| 16 | #include <linux/slab.h> | ||
| 17 | |||
| 18 | #include <sound/soc.h> | ||
| 19 | #include <sound/soc-dapm.h> | ||
| 20 | |||
| 21 | #include <linux/mfd/arizona/core.h> | ||
| 22 | #include <linux/mfd/arizona/pdata.h> | ||
| 23 | #include <linux/mfd/arizona/registers.h> | ||
| 24 | |||
| 25 | struct arizona_haptics { | ||
| 26 | struct arizona *arizona; | ||
| 27 | struct input_dev *input_dev; | ||
| 28 | struct work_struct work; | ||
| 29 | |||
| 30 | struct mutex mutex; | ||
| 31 | u8 intensity; | ||
| 32 | }; | ||
| 33 | |||
| 34 | static void arizona_haptics_work(struct work_struct *work) | ||
| 35 | { | ||
| 36 | struct arizona_haptics *haptics = container_of(work, | ||
| 37 | struct arizona_haptics, | ||
| 38 | work); | ||
| 39 | struct arizona *arizona = haptics->arizona; | ||
| 40 | struct mutex *dapm_mutex = &arizona->dapm->card->dapm_mutex; | ||
| 41 | int ret; | ||
| 42 | |||
| 43 | if (!haptics->arizona->dapm) { | ||
| 44 | dev_err(arizona->dev, "No DAPM context\n"); | ||
| 45 | return; | ||
| 46 | } | ||
| 47 | |||
| 48 | if (haptics->intensity) { | ||
| 49 | ret = regmap_update_bits(arizona->regmap, | ||
| 50 | ARIZONA_HAPTICS_PHASE_2_INTENSITY, | ||
| 51 | ARIZONA_PHASE2_INTENSITY_MASK, | ||
| 52 | haptics->intensity); | ||
| 53 | if (ret != 0) { | ||
| 54 | dev_err(arizona->dev, "Failed to set intensity: %d\n", | ||
| 55 | ret); | ||
| 56 | return; | ||
| 57 | } | ||
| 58 | |||
| 59 | /* This enable sequence will be a noop if already enabled */ | ||
| 60 | ret = regmap_update_bits(arizona->regmap, | ||
| 61 | ARIZONA_HAPTICS_CONTROL_1, | ||
| 62 | ARIZONA_HAP_CTRL_MASK, | ||
| 63 | 1 << ARIZONA_HAP_CTRL_SHIFT); | ||
| 64 | if (ret != 0) { | ||
| 65 | dev_err(arizona->dev, "Failed to start haptics: %d\n", | ||
| 66 | ret); | ||
| 67 | return; | ||
| 68 | } | ||
| 69 | |||
| 70 | mutex_lock_nested(dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME); | ||
| 71 | |||
| 72 | ret = snd_soc_dapm_enable_pin(arizona->dapm, "HAPTICS"); | ||
| 73 | if (ret != 0) { | ||
| 74 | dev_err(arizona->dev, "Failed to start HAPTICS: %d\n", | ||
| 75 | ret); | ||
| 76 | mutex_unlock(dapm_mutex); | ||
| 77 | return; | ||
| 78 | } | ||
| 79 | |||
| 80 | ret = snd_soc_dapm_sync(arizona->dapm); | ||
| 81 | if (ret != 0) { | ||
| 82 | dev_err(arizona->dev, "Failed to sync DAPM: %d\n", | ||
| 83 | ret); | ||
| 84 | mutex_unlock(dapm_mutex); | ||
| 85 | return; | ||
| 86 | } | ||
| 87 | |||
| 88 | mutex_unlock(dapm_mutex); | ||
| 89 | |||
| 90 | } else { | ||
| 91 | /* This disable sequence will be a noop if already enabled */ | ||
| 92 | mutex_lock_nested(dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME); | ||
| 93 | |||
| 94 | ret = snd_soc_dapm_disable_pin(arizona->dapm, "HAPTICS"); | ||
| 95 | if (ret != 0) { | ||
| 96 | dev_err(arizona->dev, "Failed to disable HAPTICS: %d\n", | ||
| 97 | ret); | ||
| 98 | mutex_unlock(dapm_mutex); | ||
| 99 | return; | ||
| 100 | } | ||
| 101 | |||
| 102 | ret = snd_soc_dapm_sync(arizona->dapm); | ||
| 103 | if (ret != 0) { | ||
| 104 | dev_err(arizona->dev, "Failed to sync DAPM: %d\n", | ||
| 105 | ret); | ||
| 106 | mutex_unlock(dapm_mutex); | ||
| 107 | return; | ||
| 108 | } | ||
| 109 | |||
| 110 | mutex_unlock(dapm_mutex); | ||
| 111 | |||
| 112 | ret = regmap_update_bits(arizona->regmap, | ||
| 113 | ARIZONA_HAPTICS_CONTROL_1, | ||
| 114 | ARIZONA_HAP_CTRL_MASK, | ||
| 115 | 1 << ARIZONA_HAP_CTRL_SHIFT); | ||
| 116 | if (ret != 0) { | ||
| 117 | dev_err(arizona->dev, "Failed to stop haptics: %d\n", | ||
| 118 | ret); | ||
| 119 | return; | ||
| 120 | } | ||
| 121 | } | ||
| 122 | } | ||
| 123 | |||
| 124 | static int arizona_haptics_play(struct input_dev *input, void *data, | ||
| 125 | struct ff_effect *effect) | ||
| 126 | { | ||
| 127 | struct arizona_haptics *haptics = input_get_drvdata(input); | ||
| 128 | struct arizona *arizona = haptics->arizona; | ||
| 129 | |||
| 130 | if (!arizona->dapm) { | ||
| 131 | dev_err(arizona->dev, "No DAPM context\n"); | ||
| 132 | return -EBUSY; | ||
| 133 | } | ||
| 134 | |||
| 135 | if (effect->u.rumble.strong_magnitude) { | ||
| 136 | /* Scale the magnitude into the range the device supports */ | ||
| 137 | if (arizona->pdata.hap_act) { | ||
| 138 | haptics->intensity = | ||
| 139 | effect->u.rumble.strong_magnitude >> 9; | ||
| 140 | if (effect->direction < 0x8000) | ||
| 141 | haptics->intensity += 0x7f; | ||
| 142 | } else { | ||
| 143 | haptics->intensity = | ||
| 144 | effect->u.rumble.strong_magnitude >> 8; | ||
| 145 | } | ||
| 146 | } else { | ||
| 147 | haptics->intensity = 0; | ||
| 148 | } | ||
