2010-03-09 08:29:46 +00:00
|
|
|
/*
|
|
|
|
* twl4030-vibra.c - TWL4030 Vibrator driver
|
|
|
|
*
|
|
|
|
* Copyright (C) 2008-2010 Nokia Corporation
|
|
|
|
*
|
|
|
|
* Written by Henrik Saari <henrik.saari@nokia.com>
|
|
|
|
* Updates by Felipe Balbi <felipe.balbi@nokia.com>
|
|
|
|
* Input by Jari Vanhala <ext-jari.vanhala@nokia.com>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License version 2 as
|
|
|
|
* published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* 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 St, Fifth Floor, Boston, MA
|
|
|
|
* 02110-1301 USA
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/jiffies.h>
|
|
|
|
#include <linux/platform_device.h>
|
2012-09-10 10:46:26 +00:00
|
|
|
#include <linux/of.h>
|
2010-03-09 08:29:46 +00:00
|
|
|
#include <linux/workqueue.h>
|
|
|
|
#include <linux/i2c/twl.h>
|
2011-05-31 09:02:49 +00:00
|
|
|
#include <linux/mfd/twl4030-audio.h>
|
2010-03-09 08:29:46 +00:00
|
|
|
#include <linux/input.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 08:04:11 +00:00
|
|
|
#include <linux/slab.h>
|
2010-03-09 08:29:46 +00:00
|
|
|
|
|
|
|
/* MODULE ID2 */
|
|
|
|
#define LEDEN 0x00
|
|
|
|
|
|
|
|
/* ForceFeedback */
|
|
|
|
#define EFFECT_DIR_180_DEG 0x8000 /* range is 0 - 0xFFFF */
|
|
|
|
|
|
|
|
struct vibra_info {
|
|
|
|
struct device *dev;
|
|
|
|
struct input_dev *input_dev;
|
|
|
|
|
|
|
|
struct work_struct play_work;
|
|
|
|
|
|
|
|
bool enabled;
|
|
|
|
int speed;
|
|
|
|
int direction;
|
|
|
|
|
|
|
|
bool coexist;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void vibra_disable_leds(void)
|
|
|
|
{
|
|
|
|
u8 reg;
|
|
|
|
|
|
|
|
/* Disable LEDA & LEDB, cannot be used with vibra (PWM) */
|
|
|
|
twl_i2c_read_u8(TWL4030_MODULE_LED, ®, LEDEN);
|
|
|
|
reg &= ~0x03;
|
|
|
|
twl_i2c_write_u8(TWL4030_MODULE_LED, LEDEN, reg);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Powers H-Bridge and enables audio clk */
|
|
|
|
static void vibra_enable(struct vibra_info *info)
|
|
|
|
{
|
|
|
|
u8 reg;
|
|
|
|
|
2011-05-31 09:02:49 +00:00
|
|
|
twl4030_audio_enable_resource(TWL4030_AUDIO_RES_POWER);
|
2010-03-09 08:29:46 +00:00
|
|
|
|
|
|
|
/* turn H-Bridge on */
|
|
|
|
twl_i2c_read_u8(TWL4030_MODULE_AUDIO_VOICE,
|
|
|
|
®, TWL4030_REG_VIBRA_CTL);
|
|
|
|
twl_i2c_write_u8(TWL4030_MODULE_AUDIO_VOICE,
|
|
|
|
(reg | TWL4030_VIBRA_EN), TWL4030_REG_VIBRA_CTL);
|
|
|
|
|
2011-05-31 09:02:49 +00:00
|
|
|
twl4030_audio_enable_resource(TWL4030_AUDIO_RES_APLL);
|
2010-03-09 08:29:46 +00:00
|
|
|
|
|
|
|
info->enabled = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void vibra_disable(struct vibra_info *info)
|
|
|
|
{
|
|
|
|
u8 reg;
|
|
|
|
|
|
|
|
/* Power down H-Bridge */
|
|
|
|
twl_i2c_read_u8(TWL4030_MODULE_AUDIO_VOICE,
|
|
|
|
®, TWL4030_REG_VIBRA_CTL);
|
|
|
|
twl_i2c_write_u8(TWL4030_MODULE_AUDIO_VOICE,
|
|
|
|
(reg & ~TWL4030_VIBRA_EN), TWL4030_REG_VIBRA_CTL);
|
|
|
|
|
2011-05-31 09:02:49 +00:00
|
|
|
twl4030_audio_disable_resource(TWL4030_AUDIO_RES_APLL);
|
|
|
|
twl4030_audio_disable_resource(TWL4030_AUDIO_RES_POWER);
|
2010-03-09 08:29:46 +00:00
|
|
|
|
|
|
|
info->enabled = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void vibra_play_work(struct work_struct *work)
|
|
|
|
{
|
|
|
|
struct vibra_info *info = container_of(work,
|
|
|
|
struct vibra_info, play_work);
|
|
|
|
int dir;
|
|
|
|
int pwm;
|
|
|
|
u8 reg;
|
|
|
|
|
|
|
|
dir = info->direction;
|
|
|
|
pwm = info->speed;
|
|
|
|
|
|
|
|
twl_i2c_read_u8(TWL4030_MODULE_AUDIO_VOICE,
|
|
|
|
®, TWL4030_REG_VIBRA_CTL);
|
|
|
|
if (pwm && (!info->coexist || !(reg & TWL4030_VIBRA_SEL))) {
|
|
|
|
|
|
|
|
if (!info->enabled)
|
|
|
|
vibra_enable(info);
|
|
|
|
|
|
|
|
/* set vibra rotation direction */
|
|
|
|
twl_i2c_read_u8(TWL4030_MODULE_AUDIO_VOICE,
|
|
|
|
®, TWL4030_REG_VIBRA_CTL);
|
|
|
|
reg = (dir) ? (reg | TWL4030_VIBRA_DIR) :
|
|
|
|
(reg & ~TWL4030_VIBRA_DIR);
|
|
|
|
twl_i2c_write_u8(TWL4030_MODULE_AUDIO_VOICE,
|
|
|
|
reg, TWL4030_REG_VIBRA_CTL);
|
|
|
|
|
|
|
|
/* set PWM, 1 = max, 255 = min */
|
|
|
|
twl_i2c_write_u8(TWL4030_MODULE_AUDIO_VOICE,
|
|
|
|
256 - pwm, TWL4030_REG_VIBRA_SET);
|
|
|
|
} else {
|
|
|
|
if (info->enabled)
|
|
|
|
vibra_disable(info);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*** Input/ForceFeedback ***/
|
|
|
|
|
|
|
|
static int vibra_play(struct input_dev *input, void *data,
|
|
|
|
struct ff_effect *effect)
|
|
|
|
{
|
|
|
|
struct vibra_info *info = input_get_drvdata(input);
|
|
|
|
|
|
|
|
info->speed = effect->u.rumble.strong_magnitude >> 8;
|
|
|
|
if (!info->speed)
|
|
|
|
info->speed = effect->u.rumble.weak_magnitude >> 9;
|
|
|
|
info->direction = effect->direction < EFFECT_DIR_180_DEG ? 0 : 1;
|
2013-01-11 17:05:47 +00:00
|
|
|
schedule_work(&info->play_work);
|
2010-03-09 08:29:46 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void twl4030_vibra_close(struct input_dev *input)
|
|
|
|
{
|
|
|
|
struct vibra_info *info = input_get_drvdata(input);
|
|
|
|
|
|
|
|
cancel_work_sync(&info->play_work);
|
|
|
|
|
|
|
|
if (info->enabled)
|
|
|
|
vibra_disable(info);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*** Module ***/
|
2012-03-11 23:02:06 +00:00
|
|
|
#ifdef CONFIG_PM_SLEEP
|
2010-03-09 08:29:46 +00:00
|
|
|
static int twl4030_vibra_suspend(struct device *dev)
|
|
|
|
{
|
|
|
|
struct platform_device *pdev = to_platform_device(dev);
|
|
|
|
struct vibra_info *info = platform_get_drvdata(pdev);
|
|
|
|
|
|
|
|
if (info->enabled)
|
|
|
|
vibra_disable(info);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int twl4030_vibra_resume(struct device *dev)
|
|
|
|
{
|
|
|
|
vibra_disable_leds();
|
|
|
|
return 0;
|
|
|
|
}
|
2012-02-24 08:51:40 +00:00
|
|
|
#endif
|
2010-03-09 08:29:46 +00:00
|
|
|
|
|
|
|
static SIMPLE_DEV_PM_OPS(twl4030_vibra_pm_ops,
|
|
|
|
twl4030_vibra_suspend, twl4030_vibra_resume);
|
|
|
|
|
2012-09-10 10:46:26 +00:00
|
|
|
static bool twl4030_vibra_check_coexist(struct twl4030_vibra_data *pdata,
|
|
|
|
struct device_node *node)
|
|
|
|
{
|
|
|
|
if (pdata && pdata->coexist)
|
|
|
|
return true;
|
|
|
|
|
2014-01-04 07:58:32 +00:00
|
|
|
if (of_find_node_by_name(node, "codec")) {
|
|
|
|
of_node_put(node);
|
2012-09-10 10:46:26 +00:00
|
|
|
return true;
|
2014-01-04 07:58:32 +00:00
|
|
|
}
|
2012-09-10 10:46:26 +00:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-11-24 05:38:25 +00:00
|
|
|
static int twl4030_vibra_probe(struct platform_device *pdev)
|
2010-03-09 08:29:46 +00:00
|
|
|
{
|
2013-12-06 03:21:10 +00:00
|
|
|
struct twl4030_vibra_data *pdata = dev_get_platdata(&pdev->dev);
|
2012-09-10 10:46:26 +00:00
|
|
|
struct device_node *twl4030_core_node = pdev->dev.parent->of_node;
|
2010-03-09 08:29:46 +00:00
|
|
|
struct vibra_info *info;
|
|
|
|
int ret;
|
|
|
|
|
2012-09-10 10:46:26 +00:00
|
|
|
if (!pdata && !twl4030_core_node) {
|
2010-03-09 08:29:46 +00:00
|
|
|
dev_dbg(&pdev->dev, "platform_data not available\n");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2013-01-11 17:05:42 +00:00
|
|
|
info = devm_kzalloc(&pdev->dev, sizeof(*info), GFP_KERNEL);
|
2010-03-09 08:29:46 +00:00
|
|
|
if (!info)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
info->dev = &pdev->dev;
|
2012-09-10 10:46:26 +00:00
|
|
|
info->coexist = twl4030_vibra_check_coexist(pdata, twl4030_core_node);
|
2010-03-09 08:29:46 +00:00
|
|
|
INIT_WORK(&info->play_work, vibra_play_work);
|
|
|
|
|
2013-01-11 17:05:42 +00:00
|
|
|
info->input_dev = devm_input_allocate_device(&pdev->dev);
|
2010-03-09 08:29:46 +00:00
|
|
|
if (info->input_dev == NULL) {
|
|
|
|
dev_err(&pdev->dev, "couldn't allocate input device\n");
|
2013-01-11 17:05:42 +00:00
|
|
|
return -ENOMEM;
|
2010-03-09 08:29:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
input_set_drvdata(info->input_dev, info);
|
|
|
|
|
|
|
|
info->input_dev->name = "twl4030:vibrator";
|
|
|
|
info->input_dev->id.version = 1;
|
|
|
|
info->input_dev->dev.parent = pdev->dev.parent;
|
|
|
|
info->input_dev->close = twl4030_vibra_close;
|
|
|
|
__set_bit(FF_RUMBLE, info->input_dev->ffbit);
|
|
|
|
|
|
|
|
ret = input_ff_create_memless(info->input_dev, NULL, vibra_play);
|
|
|
|
if (ret < 0) {
|
|
|
|
dev_dbg(&pdev->dev, "couldn't register vibrator to FF\n");
|
2013-01-11 17:05:42 +00:00
|
|
|
return ret;
|
2010-03-09 08:29:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ret = input_register_device(info->input_dev);
|
|
|
|
if (ret < 0) {
|
|
|
|
dev_dbg(&pdev->dev, "couldn't register input device\n");
|
|
|
|
goto err_iff;
|
|
|
|
}
|
|
|
|
|
|
|
|
vibra_disable_leds();
|
|
|
|
|
|
|
|
platform_set_drvdata(pdev, info);
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
err_iff:
|
|
|
|
input_ff_destroy(info->input_dev);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct platform_driver twl4030_vibra_driver = {
|
|
|
|
.probe = twl4030_vibra_probe,
|
|
|
|
.driver = {
|
2010-03-17 20:15:21 +00:00
|
|
|
.name = "twl4030-vibra",
|
2010-03-09 08:29:46 +00:00
|
|
|
.owner = THIS_MODULE,
|
|
|
|
.pm = &twl4030_vibra_pm_ops,
|
|
|
|
},
|
|
|
|
};
|
2011-11-29 19:08:40 +00:00
|
|
|
module_platform_driver(twl4030_vibra_driver);
|
2010-03-09 08:29:46 +00:00
|
|
|
|
2010-03-17 20:15:21 +00:00
|
|
|
MODULE_ALIAS("platform:twl4030-vibra");
|
2010-03-09 08:29:46 +00:00
|
|
|
MODULE_DESCRIPTION("TWL4030 Vibra driver");
|
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
MODULE_AUTHOR("Nokia Corporation");
|