mirror of
https://github.com/AuxXxilium/linux_dsm_epyc7002.git
synced 2024-12-26 16:15:05 +07:00
e661d0a044
Fix following: [ 8.862274] ERROR: Bad of_node_put() on /ocp/i2c@48070000/twl@48/audio [ 8.869293] CPU: 0 PID: 1003 Comm: modprobe Not tainted 4.2.0-rc2-letux+ #1175 [ 8.876922] Hardware name: Generic OMAP36xx (Flattened Device Tree) [ 8.883514] [<c00159e0>] (unwind_backtrace) from [<c0012488>] (show_stack+0x10/0x14) [ 8.891693] [<c0012488>] (show_stack) from [<c05cb810>] (dump_stack+0x78/0x94) [ 8.899322] [<c05cb810>] (dump_stack) from [<c02cfd5c>] (kobject_release+0x68/0x7c) [ 8.907409] [<c02cfd5c>] (kobject_release) from [<bf0040c4>] (twl4030_vibra_probe+0x74/0x188 [twl4030_vibra]) [ 8.917877] [<bf0040c4>] (twl4030_vibra_probe [twl4030_vibra]) from [<c03816ac>] (platform_drv_probe+0x48/0x90) [ 8.928497] [<c03816ac>] (platform_drv_probe) from [<c037feb4>] (really_probe+0xd4/0x238) [ 8.937103] [<c037feb4>] (really_probe) from [<c0380160>] (driver_probe_device+0x30/0x48) [ 8.945678] [<c0380160>] (driver_probe_device) from [<c03801e0>] (__driver_attach+0x68/0x8c) [ 8.954589] [<c03801e0>] (__driver_attach) from [<c037ea60>] (bus_for_each_dev+0x50/0x84) [ 8.963226] [<c037ea60>] (bus_for_each_dev) from [<c037f828>] (bus_add_driver+0xcc/0x1e4) [ 8.971832] [<c037f828>] (bus_add_driver) from [<c0380b60>] (driver_register+0x9c/0xe0) [ 8.980255] [<c0380b60>] (driver_register) from [<c00097e0>] (do_one_initcall+0x100/0x1b8) [ 8.988983] [<c00097e0>] (do_one_initcall) from [<c00b8008>] (do_init_module+0x58/0x1c0) [ 8.997497] [<c00b8008>] (do_init_module) from [<c00b8cac>] (SyS_init_module+0x54/0x64) [ 9.005950] [<c00b8cac>] (SyS_init_module) from [<c000ed20>] (ret_fast_syscall+0x0/0x54) [ 9.015838] input: twl4030:vibrator as /devices/platform/68000000.ocp/48070000.i2c/i2c-0/0-0048/48070000.i2c:twl@48:audio/input/input2 node passed to of_find_node_by_name is put inside that function and new node is returned if found. Free returned node not already freed node. Signed-off-by: Marek Belisko <marek@goldelico.com> Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
264 lines
6.4 KiB
C
264 lines
6.4 KiB
C
/*
|
|
* 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>
|
|
#include <linux/of.h>
|
|
#include <linux/workqueue.h>
|
|
#include <linux/i2c/twl.h>
|
|
#include <linux/mfd/twl4030-audio.h>
|
|
#include <linux/input.h>
|
|
#include <linux/slab.h>
|
|
|
|
/* 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;
|
|
|
|
twl4030_audio_enable_resource(TWL4030_AUDIO_RES_POWER);
|
|
|
|
/* 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);
|
|
|
|
twl4030_audio_enable_resource(TWL4030_AUDIO_RES_APLL);
|
|
|
|
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);
|
|
|
|
twl4030_audio_disable_resource(TWL4030_AUDIO_RES_APLL);
|
|
twl4030_audio_disable_resource(TWL4030_AUDIO_RES_POWER);
|
|
|
|
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;
|
|
schedule_work(&info->play_work);
|
|
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 ***/
|
|
static int __maybe_unused 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 __maybe_unused twl4030_vibra_resume(struct device *dev)
|
|
{
|
|
vibra_disable_leds();
|
|
return 0;
|
|
}
|
|
|
|
static SIMPLE_DEV_PM_OPS(twl4030_vibra_pm_ops,
|
|
twl4030_vibra_suspend, twl4030_vibra_resume);
|
|
|
|
static bool twl4030_vibra_check_coexist(struct twl4030_vibra_data *pdata,
|
|
struct device_node *node)
|
|
{
|
|
if (pdata && pdata->coexist)
|
|
return true;
|
|
|
|
node = of_find_node_by_name(node, "codec");
|
|
if (node) {
|
|
of_node_put(node);
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
static int twl4030_vibra_probe(struct platform_device *pdev)
|
|
{
|
|
struct twl4030_vibra_data *pdata = dev_get_platdata(&pdev->dev);
|
|
struct device_node *twl4030_core_node = pdev->dev.parent->of_node;
|
|
struct vibra_info *info;
|
|
int ret;
|
|
|
|
if (!pdata && !twl4030_core_node) {
|
|
dev_dbg(&pdev->dev, "platform_data not available\n");
|
|
return -EINVAL;
|
|
}
|
|
|
|
info = devm_kzalloc(&pdev->dev, sizeof(*info), GFP_KERNEL);
|
|
if (!info)
|
|
return -ENOMEM;
|
|
|
|
info->dev = &pdev->dev;
|
|
info->coexist = twl4030_vibra_check_coexist(pdata, twl4030_core_node);
|
|
INIT_WORK(&info->play_work, vibra_play_work);
|
|
|
|
info->input_dev = devm_input_allocate_device(&pdev->dev);
|
|
if (info->input_dev == NULL) {
|
|
dev_err(&pdev->dev, "couldn't allocate input device\n");
|
|
return -ENOMEM;
|
|
}
|
|
|
|
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");
|
|
return ret;
|
|
}
|
|
|
|
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 = {
|
|
.name = "twl4030-vibra",
|
|
.pm = &twl4030_vibra_pm_ops,
|
|
},
|
|
};
|
|
module_platform_driver(twl4030_vibra_driver);
|
|
|
|
MODULE_ALIAS("platform:twl4030-vibra");
|
|
MODULE_DESCRIPTION("TWL4030 Vibra driver");
|
|
MODULE_LICENSE("GPL");
|
|
MODULE_AUTHOR("Nokia Corporation");
|