Skip to content

Commit

Permalink
Merge remote-tracking branch 'asoc/topic/arizona' into asoc-next
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark Brown committed Dec 2, 2012
2 parents b72ea21 + e436cad commit 9d3493e
Show file tree
Hide file tree
Showing 11 changed files with 477 additions and 58 deletions.
10 changes: 10 additions & 0 deletions drivers/input/misc/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,16 @@ config INPUT_AD714X_SPI
To compile this driver as a module, choose M here: the
module will be called ad714x-spi.

config INPUT_ARIZONA_HAPTICS
tristate "Arizona haptics support"
depends on MFD_ARIZONA && SND_SOC
select INPUT_FF_MEMLESS
help
Say Y to enable support for the haptics module in Arizona CODECs.

To compile this driver as a module, choose M here: the
module will be called arizona-haptics.

config INPUT_BMA150
tristate "BMA150/SMB380 acceleration sensor support"
depends on I2C
Expand Down
1 change: 1 addition & 0 deletions drivers/input/misc/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ obj-$(CONFIG_INPUT_ADXL34X) += adxl34x.o
obj-$(CONFIG_INPUT_ADXL34X_I2C) += adxl34x-i2c.o
obj-$(CONFIG_INPUT_ADXL34X_SPI) += adxl34x-spi.o
obj-$(CONFIG_INPUT_APANEL) += apanel.o
obj-$(CONFIG_INPUT_ARIZONA_HAPTICS) += arizona-haptics.o
obj-$(CONFIG_INPUT_ATI_REMOTE2) += ati_remote2.o
obj-$(CONFIG_INPUT_ATLAS_BTNS) += atlas_btns.o
obj-$(CONFIG_INPUT_BFIN_ROTARY) += bfin_rotary.o
Expand Down
255 changes: 255 additions & 0 deletions drivers/input/misc/arizona-haptics.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,255 @@
/*
* Arizona haptics driver
*
* Copyright 2012 Wolfson Microelectronics plc
*
* Author: Mark Brown <broonie@opensource.wolfsonmicro.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.
*/

#include <linux/module.h>
#include <linux/platform_device.h>
#include <linux/input.h>
#include <linux/slab.h>

#include <sound/soc.h>
#include <sound/soc-dapm.h>

#include <linux/mfd/arizona/core.h>
#include <linux/mfd/arizona/pdata.h>
#include <linux/mfd/arizona/registers.h>

struct arizona_haptics {
struct arizona *arizona;
struct input_dev *input_dev;
struct work_struct work;

struct mutex mutex;
u8 intensity;
};

static void arizona_haptics_work(struct work_struct *work)
{
struct arizona_haptics *haptics = container_of(work,
struct arizona_haptics,
work);
struct arizona *arizona = haptics->arizona;
struct mutex *dapm_mutex = &arizona->dapm->card->dapm_mutex;
int ret;

if (!haptics->arizona->dapm) {
dev_err(arizona->dev, "No DAPM context\n");
return;
}

if (haptics->intensity) {
ret = regmap_update_bits(arizona->regmap,
ARIZONA_HAPTICS_PHASE_2_INTENSITY,
ARIZONA_PHASE2_INTENSITY_MASK,
haptics->intensity);
if (ret != 0) {
dev_err(arizona->dev, "Failed to set intensity: %d\n",
ret);
return;
}

/* This enable sequence will be a noop if already enabled */
ret = regmap_update_bits(arizona->regmap,
ARIZONA_HAPTICS_CONTROL_1,
ARIZONA_HAP_CTRL_MASK,
1 << ARIZONA_HAP_CTRL_SHIFT);
if (ret != 0) {
dev_err(arizona->dev, "Failed to start haptics: %d\n",
ret);
return;
}

mutex_lock_nested(dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME);

ret = snd_soc_dapm_enable_pin(arizona->dapm, "HAPTICS");
if (ret != 0) {
dev_err(arizona->dev, "Failed to start HAPTICS: %d\n",
ret);
mutex_unlock(dapm_mutex);
return;
}

ret = snd_soc_dapm_sync(arizona->dapm);
if (ret != 0) {
dev_err(arizona->dev, "Failed to sync DAPM: %d\n",
ret);
mutex_unlock(dapm_mutex);
return;
}

mutex_unlock(dapm_mutex);

} else {
/* This disable sequence will be a noop if already enabled */
mutex_lock_nested(dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME);

ret = snd_soc_dapm_disable_pin(arizona->dapm, "HAPTICS");
if (ret != 0) {
dev_err(arizona->dev, "Failed to disable HAPTICS: %d\n",
ret);
mutex_unlock(dapm_mutex);
return;
}

ret = snd_soc_dapm_sync(arizona->dapm);
if (ret != 0) {
dev_err(arizona->dev, "Failed to sync DAPM: %d\n",
ret);
mutex_unlock(dapm_mutex);
return;
}

mutex_unlock(dapm_mutex);

ret = regmap_update_bits(arizona->regmap,
ARIZONA_HAPTICS_CONTROL_1,
ARIZONA_HAP_CTRL_MASK,
1 << ARIZONA_HAP_CTRL_SHIFT);
if (ret != 0) {
dev_err(arizona->dev, "Failed to stop haptics: %d\n",
ret);
return;
}
}
}

static int arizona_haptics_play(struct input_dev *input, void *data,
struct ff_effect *effect)
{
struct arizona_haptics *haptics = input_get_drvdata(input);
struct arizona *arizona = haptics->arizona;

if (!arizona->dapm) {
dev_err(arizona->dev, "No DAPM context\n");
return -EBUSY;
}

if (effect->u.rumble.strong_magnitude) {
/* Scale the magnitude into the range the device supports */
if (arizona->pdata.hap_act) {
haptics->intensity =
effect->u.rumble.strong_magnitude >> 9;
if (effect->direction < 0x8000)
haptics->intensity += 0x7f;
} else {
haptics->intensity =
effect->u.rumble.strong_magnitude >> 8;
}
} else {
haptics->intensity = 0;
}

schedule_work(&haptics->work);

return 0;
}

static void arizona_haptics_close(struct input_dev *input)
{
struct arizona_haptics *haptics = input_get_drvdata(input);
struct mutex *dapm_mutex = &haptics->arizona->dapm->card->dapm_mutex;

cancel_work_sync(&haptics->work);

mutex_lock_nested(dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME);

if (haptics->arizona->dapm)
snd_soc_dapm_disable_pin(haptics->arizona->dapm, "HAPTICS");

mutex_unlock(dapm_mutex);
}

static int arizona_haptics_probe(struct platform_device *pdev)
{
struct arizona *arizona = dev_get_drvdata(pdev->dev.parent);
struct arizona_haptics *haptics;
int ret;

haptics = devm_kzalloc(&pdev->dev, sizeof(*haptics), GFP_KERNEL);
if (!haptics)
return -ENOMEM;

haptics->arizona = arizona;

ret = regmap_update_bits(arizona->regmap, ARIZONA_HAPTICS_CONTROL_1,
ARIZONA_HAP_ACT, arizona->pdata.hap_act);
if (ret != 0) {
dev_err(arizona->dev, "Failed to set haptics actuator: %d\n",
ret);
return ret;
}

INIT_WORK(&haptics->work, arizona_haptics_work);

haptics->input_dev = input_allocate_device();
if (haptics->input_dev == NULL) {
dev_err(arizona->dev, "Failed to allocate input device\n");
return -ENOMEM;
}

input_set_drvdata(haptics->input_dev, haptics);

haptics->input_dev->name = "arizona:haptics";
haptics->input_dev->dev.parent = pdev->dev.parent;
haptics->input_dev->close = arizona_haptics_close;
__set_bit(FF_RUMBLE, haptics->input_dev->ffbit);

ret = input_ff_create_memless(haptics->input_dev, NULL,
arizona_haptics_play);
if (ret < 0) {
dev_err(arizona->dev, "input_ff_create_memless() failed: %d\n",
ret);
goto err_ialloc;
}

ret = input_register_device(haptics->input_dev);
if (ret < 0) {
dev_err(arizona->dev, "couldn't register input device: %d\n",
ret);
goto err_iff;
}

platform_set_drvdata(pdev, haptics);

return 0;

err_iff:
if (haptics->input_dev)
input_ff_destroy(haptics->input_dev);
err_ialloc:
input_free_device(haptics->input_dev);

return ret;
}

static int arizona_haptics_remove(struct platform_device *pdev)
{
struct arizona_haptics *haptics = platform_get_drvdata(pdev);

input_unregister_device(haptics->input_dev);

return 0;
}

static struct platform_driver arizona_haptics_driver = {
.probe = arizona_haptics_probe,
.remove = arizona_haptics_remove,
.driver = {
.name = "arizona-haptics",
.owner = THIS_MODULE,
},
};
module_platform_driver(arizona_haptics_driver);

MODULE_ALIAS("platform:arizona-haptics");
MODULE_DESCRIPTION("Arizona haptics driver");
MODULE_LICENSE("GPL");
MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>");
2 changes: 2 additions & 0 deletions drivers/mfd/arizona-core.c
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ static struct mfd_cell early_devs[] = {
static struct mfd_cell wm5102_devs[] = {
{ .name = "arizona-extcon" },
{ .name = "arizona-gpio" },
{ .name = "arizona-haptics" },
{ .name = "arizona-micsupp" },
{ .name = "arizona-pwm" },
{ .name = "wm5102-codec" },
Expand All @@ -280,6 +281,7 @@ static struct mfd_cell wm5102_devs[] = {
static struct mfd_cell wm5110_devs[] = {
{ .name = "arizona-extcon" },
{ .name = "arizona-gpio" },
{ .name = "arizona-haptics" },
{ .name = "arizona-micsupp" },
{ .name = "arizona-pwm" },
{ .name = "wm5110-codec" },
Expand Down
4 changes: 4 additions & 0 deletions include/linux/mfd/arizona/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ enum arizona_type {

#define ARIZONA_NUM_IRQ 50

struct snd_soc_dapm_context;

struct arizona {
struct regmap *regmap;
struct device *dev;
Expand All @@ -98,6 +100,8 @@ struct arizona {

struct mutex clk_lock;
int clk32k_ref;

struct snd_soc_dapm_context *dapm;
};

int arizona_clk32k_enable(struct arizona *arizona);
Expand Down
6 changes: 6 additions & 0 deletions include/linux/mfd/arizona/pdata.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@

#define ARIZONA_MAX_OUTPUT 6

#define ARIZONA_HAP_ACT_ERM 0
#define ARIZONA_HAP_ACT_LRA 2

#define ARIZONA_MAX_PDM_SPK 2

struct regulator_init_data;
Expand Down Expand Up @@ -114,6 +117,9 @@ struct arizona_pdata {

/** PDM speaker format */
unsigned int spk_fmt[ARIZONA_MAX_PDM_SPK];

/** Haptic actuator type */
unsigned int hap_act;
};

#endif
2 changes: 2 additions & 0 deletions sound/soc/codecs/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,9 @@ config SND_SOC_WM_HUBS

config SND_SOC_WM_ADSP
tristate
default y if SND_SOC_WM5102=y
default y if SND_SOC_WM2200=y
default m if SND_SOC_WM5102=m
default m if SND_SOC_WM2200=m

config SND_SOC_AB8500_CODEC
Expand Down
21 changes: 21 additions & 0 deletions sound/soc/codecs/arizona.c
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,18 @@ int arizona_set_sysclk(struct snd_soc_codec *codec, int clk_id,
case 49152000:
val |= 3 << ARIZONA_SYSCLK_FREQ_SHIFT;
break;
case 67737600:
case 73728000:
val |= 4 << ARIZONA_SYSCLK_FREQ_SHIFT;
break;
case 90316800:
case 98304000:
val |= 5 << ARIZONA_SYSCLK_FREQ_SHIFT;
break;
case 135475200:
case 147456000:
val |= 6 << ARIZONA_SYSCLK_FREQ_SHIFT;
break;
default:
return -EINVAL;
}
Expand Down Expand Up @@ -925,6 +937,9 @@ int arizona_set_fll(struct arizona_fll *fll, int source,
bool ena;
int ret;

if (fll->fref == Fref && fll->fout == Fout)
return 0;

ret = regmap_read(arizona->regmap, fll->base + 1, &reg);
if (ret != 0) {
arizona_fll_err(fll, "Failed to read current state: %d\n",
Expand Down Expand Up @@ -970,6 +985,9 @@ int arizona_set_fll(struct arizona_fll *fll, int source,
if (ena)
pm_runtime_put_autosuspend(arizona->dev);

fll->fref = Fref;
fll->fout = Fout;

return 0;
}

Expand Down Expand Up @@ -1002,6 +1020,9 @@ int arizona_set_fll(struct arizona_fll *fll, int source,
if (ret == 0)
arizona_fll_warn(fll, "Timed out waiting for lock\n");

fll->fref = Fref;
fll->fout = Fout;

return 0;
}
EXPORT_SYMBOL_GPL(arizona_set_fll);
Expand Down
Loading

0 comments on commit 9d3493e

Please sign in to comment.