2012-06-24 19:09:45 +08:00
|
|
|
/*
|
|
|
|
* extcon-arizona.c - Extcon driver Wolfson Arizona devices
|
|
|
|
*
|
2015-09-28 19:41:42 +08:00
|
|
|
* Copyright (C) 2012-2014 Wolfson Microelectronics plc
|
2012-06-24 19:09:45 +08:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/i2c.h>
|
|
|
|
#include <linux/slab.h>
|
|
|
|
#include <linux/interrupt.h>
|
|
|
|
#include <linux/err.h>
|
2015-06-20 00:23:31 +08:00
|
|
|
#include <linux/gpio/consumer.h>
|
2012-06-24 19:09:45 +08:00
|
|
|
#include <linux/gpio.h>
|
2012-07-21 00:07:29 +08:00
|
|
|
#include <linux/input.h>
|
2012-06-24 19:09:45 +08:00
|
|
|
#include <linux/platform_device.h>
|
|
|
|
#include <linux/pm_runtime.h>
|
2015-06-20 00:23:29 +08:00
|
|
|
#include <linux/property.h>
|
2012-06-24 19:09:45 +08:00
|
|
|
#include <linux/regulator/consumer.h>
|
2017-09-21 11:11:24 +08:00
|
|
|
#include <linux/extcon-provider.h>
|
2012-06-24 19:09:45 +08:00
|
|
|
|
2013-01-11 03:38:43 +08:00
|
|
|
#include <sound/soc.h>
|
|
|
|
|
2012-06-24 19:09:45 +08:00
|
|
|
#include <linux/mfd/arizona/core.h>
|
|
|
|
#include <linux/mfd/arizona/pdata.h>
|
|
|
|
#include <linux/mfd/arizona/registers.h>
|
2015-05-04 12:42:13 +08:00
|
|
|
#include <dt-bindings/mfd/arizona.h>
|
2012-06-24 19:09:45 +08:00
|
|
|
|
2013-04-02 05:03:06 +08:00
|
|
|
#define ARIZONA_MAX_MICD_RANGE 8
|
2012-07-21 00:07:29 +08:00
|
|
|
|
2014-05-23 19:54:57 +08:00
|
|
|
#define ARIZONA_MICD_CLAMP_MODE_JDL 0x4
|
|
|
|
#define ARIZONA_MICD_CLAMP_MODE_JDH 0x5
|
|
|
|
#define ARIZONA_MICD_CLAMP_MODE_JDL_GP5H 0x9
|
|
|
|
#define ARIZONA_MICD_CLAMP_MODE_JDH_GP5H 0xb
|
|
|
|
|
2015-09-16 17:42:18 +08:00
|
|
|
#define ARIZONA_TST_CAP_DEFAULT 0x3
|
|
|
|
#define ARIZONA_TST_CAP_CLAMP 0x1
|
|
|
|
|
2013-04-02 02:09:45 +08:00
|
|
|
#define ARIZONA_HPDET_MAX 10000
|
|
|
|
|
2013-04-02 02:07:28 +08:00
|
|
|
#define HPDET_DEBOUNCE 500
|
2013-04-02 02:25:55 +08:00
|
|
|
#define DEFAULT_MICD_TIMEOUT 2000
|
2013-04-02 02:05:27 +08:00
|
|
|
|
2017-01-25 17:34:06 +08:00
|
|
|
#define ARIZONA_HPDET_WAIT_COUNT 15
|
|
|
|
#define ARIZONA_HPDET_WAIT_DELAY_MS 20
|
|
|
|
|
2015-09-16 17:42:16 +08:00
|
|
|
#define QUICK_HEADPHONE_MAX_OHM 3
|
|
|
|
#define MICROPHONE_MIN_OHM 1257
|
|
|
|
#define MICROPHONE_MAX_OHM 30000
|
|
|
|
|
2015-06-30 20:32:39 +08:00
|
|
|
#define MICD_DBTIME_TWO_READINGS 2
|
|
|
|
#define MICD_DBTIME_FOUR_READINGS 4
|
|
|
|
|
2013-11-15 00:18:21 +08:00
|
|
|
#define MICD_LVL_1_TO_7 (ARIZONA_MICD_LVL_1 | ARIZONA_MICD_LVL_2 | \
|
|
|
|
ARIZONA_MICD_LVL_3 | ARIZONA_MICD_LVL_4 | \
|
|
|
|
ARIZONA_MICD_LVL_5 | ARIZONA_MICD_LVL_6 | \
|
|
|
|
ARIZONA_MICD_LVL_7)
|
|
|
|
|
|
|
|
#define MICD_LVL_0_TO_7 (ARIZONA_MICD_LVL_0 | MICD_LVL_1_TO_7)
|
|
|
|
|
|
|
|
#define MICD_LVL_0_TO_8 (MICD_LVL_0_TO_7 | ARIZONA_MICD_LVL_8)
|
|
|
|
|
2012-06-24 19:09:45 +08:00
|
|
|
struct arizona_extcon_info {
|
|
|
|
struct device *dev;
|
|
|
|
struct arizona *arizona;
|
|
|
|
struct mutex lock;
|
|
|
|
struct regulator *micvdd;
|
2012-07-21 00:07:29 +08:00
|
|
|
struct input_dev *input;
|
2012-06-24 19:09:45 +08:00
|
|
|
|
2013-04-02 02:05:27 +08:00
|
|
|
u16 last_jackdet;
|
|
|
|
|
2012-06-24 19:09:45 +08:00
|
|
|
int micd_mode;
|
|
|
|
const struct arizona_micd_config *micd_modes;
|
|
|
|
int micd_num_modes;
|
|
|
|
|
2013-04-02 05:03:06 +08:00
|
|
|
const struct arizona_micd_range *micd_ranges;
|
|
|
|
int num_micd_ranges;
|
|
|
|
|
2013-04-02 02:25:55 +08:00
|
|
|
int micd_timeout;
|
|
|
|
|
2012-06-24 19:09:45 +08:00
|
|
|
bool micd_reva;
|
2013-01-11 07:55:36 +08:00
|
|
|
bool micd_clamp;
|
2012-06-24 19:09:45 +08:00
|
|
|
|
2013-02-06 05:00:15 +08:00
|
|
|
struct delayed_work hpdet_work;
|
2013-04-02 02:21:48 +08:00
|
|
|
struct delayed_work micd_detect_work;
|
2013-04-02 02:17:34 +08:00
|
|
|
struct delayed_work micd_timeout_work;
|
2013-02-06 05:00:15 +08:00
|
|
|
|
2013-01-11 07:55:43 +08:00
|
|
|
bool hpdet_active;
|
2013-02-06 04:20:17 +08:00
|
|
|
bool hpdet_done;
|
2013-04-02 02:09:45 +08:00
|
|
|
bool hpdet_retried;
|
2013-01-11 07:55:43 +08:00
|
|
|
|
2013-01-11 07:55:51 +08:00
|
|
|
int num_hpdet_res;
|
2013-01-11 07:55:54 +08:00
|
|
|
unsigned int hpdet_res[3];
|
2013-01-11 07:55:51 +08:00
|
|
|
|
2012-06-24 19:09:45 +08:00
|
|
|
bool mic;
|
|
|
|
bool detecting;
|
|
|
|
int jack_flips;
|
|
|
|
|
2015-04-28 20:34:27 +08:00
|
|
|
int hpdet_ip_version;
|
2013-01-11 07:55:43 +08:00
|
|
|
|
2014-04-21 19:47:31 +08:00
|
|
|
struct extcon_dev *edev;
|
2015-06-20 00:23:31 +08:00
|
|
|
|
|
|
|
struct gpio_desc *micd_pol_gpio;
|
2012-06-24 19:09:45 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
static const struct arizona_micd_config micd_default_modes[] = {
|
2013-09-23 21:33:59 +08:00
|
|
|
{ ARIZONA_ACCDET_SRC, 1, 0 },
|
|
|
|
{ 0, 2, 1 },
|
2012-06-24 19:09:45 +08:00
|
|
|
};
|
|
|
|
|
2013-04-02 05:03:06 +08:00
|
|
|
static const struct arizona_micd_range micd_default_ranges[] = {
|
|
|
|
{ .max = 11, .key = BTN_0 },
|
|
|
|
{ .max = 28, .key = BTN_1 },
|
|
|
|
{ .max = 54, .key = BTN_2 },
|
|
|
|
{ .max = 100, .key = BTN_3 },
|
|
|
|
{ .max = 186, .key = BTN_4 },
|
|
|
|
{ .max = 430, .key = BTN_5 },
|
|
|
|
};
|
|
|
|
|
2015-09-16 17:42:16 +08:00
|
|
|
/* The number of levels in arizona_micd_levels valid for button thresholds */
|
|
|
|
#define ARIZONA_NUM_MICD_BUTTON_LEVELS 64
|
|
|
|
|
2013-04-02 05:03:06 +08:00
|
|
|
static const int arizona_micd_levels[] = {
|
|
|
|
3, 6, 8, 11, 13, 16, 18, 21, 23, 26, 28, 31, 34, 36, 39, 41, 44, 46,
|
|
|
|
49, 52, 54, 57, 60, 62, 65, 67, 70, 73, 75, 78, 81, 83, 89, 94, 100,
|
|
|
|
105, 111, 116, 122, 127, 139, 150, 161, 173, 186, 196, 209, 220, 245,
|
|
|
|
270, 295, 321, 348, 375, 402, 430, 489, 550, 614, 681, 752, 903, 1071,
|
2015-09-16 17:42:16 +08:00
|
|
|
1257, 30000,
|
2012-07-21 00:07:29 +08:00
|
|
|
};
|
|
|
|
|
2015-06-12 10:10:06 +08:00
|
|
|
static const unsigned int arizona_cable[] = {
|
extcon: Use the unique id for external connector instead of string
This patch uses the unique id to identify the type of external connector instead
of string name. The string name have the many potential issues. So, this patch
defines the 'extcon' enumeration which includes all supported external connector
on EXTCON subsystem. If new external connector is necessary, the unique id of
new connector have to be added in 'extcon' enumeration. There are current
supported external connector in 'enum extcon' as following:
enum extcon {
EXTCON_NONE = 0x0,
/* USB external connector */
EXTCON_USB = 0x1,
EXTCON_USB_HOST = 0x2,
/* Charger external connector */
EXTCON_TA = 0x10,
EXTCON_FAST_CHARGER = 0x11,
EXTCON_SLOW_CHARGER = 0x12,
EXTCON_CHARGE_DOWNSTREAM = 0x13,
/* Audio and video external connector */
EXTCON_LINE_IN = 0x20,
EXTCON_LINE_OUT = 0x21,
EXTCON_MICROPHONE = 0x22,
EXTCON_HEADPHONE = 0x23,
EXTCON_HDMI = 0x30,
EXTCON_MHL = 0x31,
EXTCON_DVI = 0x32,
EXTCON_VGA = 0x33,
EXTCON_SPDIF_IN = 0x34,
EXTCON_SPDIF_OUT = 0x35,
EXTCON_VIDEO_IN = 0x36,
EXTCON_VIDEO_OUT = 0x37,
/* Miscellaneous external connector */
EXTCON_DOCK = 0x50,
EXTCON_JIG = 0x51,
EXTCON_MECHANICAL = 0x52,
EXTCON_END,
};
For example in extcon-arizona.c:
To use unique id removes the potential issue about handling
the inconsistent name of external connector with string.
- Previously, use the string to register the type of arizona jack connector
static const char *arizona_cable[] = {
"Mechanical",
"Microphone",
"Headphone",
"Line-out",
};
- Newly, use the unique id to register the type of arizona jack connector
static const enum extcon arizona_cable[] = {
EXTCON_MECHANICAL,
EXTCON_MICROPHONE,
EXTCON_HEADPHONE,
EXTCON_LINE_OUT,
EXTCON_NONE,
};
And this patch modify the prototype of extcon_{get|set}_cable_state_() which
uses the 'enum extcon id' instead of 'cable_index'. Because although one more
extcon drivers support USB cable, each extcon driver might has the differnt
'cable_index' for USB cable. All extcon drivers can use the unique id number
for same external connector with modified extcon_{get|set}_cable_state_().
- Previously, use 'cable_index' on these functions:
extcon_get_cable_state_(struct extcon_dev*, int cable_index)
extcon_set_cable_state_(struct extcon_dev*, int cable_index, bool state)
-Newly, use 'enum extcon id' on these functions:
extcon_get_cable_state_(struct extcon_dev*, enum extcon id)
extcon_set_cable_state_(struct extcon_dev*, enum extcon id, bool state)
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Felipe Balbi <balbi@ti.com>
Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>
Acked-by: Roger Quadros <rogerq@ti.com>
Acked-by: Charles Keepax <ckeepax@opensource.wolfsonmicro.com>
Acked-by: Ramakrishna Pallala <ramakrishna.pallala@intel.com>
Reviewed-by: Krzysztof Kozlowski <k.kozlowski@samsung.com>
[arnd: Report the build break about drivers/usb/phy/phy-tahvo.c after using the
unique id for external connector insteadf of string]
Reported-by: Arnd Bergmann <arnd@arndb.de>
[dan.carpenter: Report the build warning of extcon_{set|get}_cable_state_()]
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
2015-04-24 18:16:05 +08:00
|
|
|
EXTCON_MECHANICAL,
|
2015-10-03 13:15:13 +08:00
|
|
|
EXTCON_JACK_MICROPHONE,
|
|
|
|
EXTCON_JACK_HEADPHONE,
|
|
|
|
EXTCON_JACK_LINE_OUT,
|
extcon: Use the unique id for external connector instead of string
This patch uses the unique id to identify the type of external connector instead
of string name. The string name have the many potential issues. So, this patch
defines the 'extcon' enumeration which includes all supported external connector
on EXTCON subsystem. If new external connector is necessary, the unique id of
new connector have to be added in 'extcon' enumeration. There are current
supported external connector in 'enum extcon' as following:
enum extcon {
EXTCON_NONE = 0x0,
/* USB external connector */
EXTCON_USB = 0x1,
EXTCON_USB_HOST = 0x2,
/* Charger external connector */
EXTCON_TA = 0x10,
EXTCON_FAST_CHARGER = 0x11,
EXTCON_SLOW_CHARGER = 0x12,
EXTCON_CHARGE_DOWNSTREAM = 0x13,
/* Audio and video external connector */
EXTCON_LINE_IN = 0x20,
EXTCON_LINE_OUT = 0x21,
EXTCON_MICROPHONE = 0x22,
EXTCON_HEADPHONE = 0x23,
EXTCON_HDMI = 0x30,
EXTCON_MHL = 0x31,
EXTCON_DVI = 0x32,
EXTCON_VGA = 0x33,
EXTCON_SPDIF_IN = 0x34,
EXTCON_SPDIF_OUT = 0x35,
EXTCON_VIDEO_IN = 0x36,
EXTCON_VIDEO_OUT = 0x37,
/* Miscellaneous external connector */
EXTCON_DOCK = 0x50,
EXTCON_JIG = 0x51,
EXTCON_MECHANICAL = 0x52,
EXTCON_END,
};
For example in extcon-arizona.c:
To use unique id removes the potential issue about handling
the inconsistent name of external connector with string.
- Previously, use the string to register the type of arizona jack connector
static const char *arizona_cable[] = {
"Mechanical",
"Microphone",
"Headphone",
"Line-out",
};
- Newly, use the unique id to register the type of arizona jack connector
static const enum extcon arizona_cable[] = {
EXTCON_MECHANICAL,
EXTCON_MICROPHONE,
EXTCON_HEADPHONE,
EXTCON_LINE_OUT,
EXTCON_NONE,
};
And this patch modify the prototype of extcon_{get|set}_cable_state_() which
uses the 'enum extcon id' instead of 'cable_index'. Because although one more
extcon drivers support USB cable, each extcon driver might has the differnt
'cable_index' for USB cable. All extcon drivers can use the unique id number
for same external connector with modified extcon_{get|set}_cable_state_().
- Previously, use 'cable_index' on these functions:
extcon_get_cable_state_(struct extcon_dev*, int cable_index)
extcon_set_cable_state_(struct extcon_dev*, int cable_index, bool state)
-Newly, use 'enum extcon id' on these functions:
extcon_get_cable_state_(struct extcon_dev*, enum extcon id)
extcon_set_cable_state_(struct extcon_dev*, enum extcon id, bool state)
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Felipe Balbi <balbi@ti.com>
Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>
Acked-by: Roger Quadros <rogerq@ti.com>
Acked-by: Charles Keepax <ckeepax@opensource.wolfsonmicro.com>
Acked-by: Ramakrishna Pallala <ramakrishna.pallala@intel.com>
Reviewed-by: Krzysztof Kozlowski <k.kozlowski@samsung.com>
[arnd: Report the build break about drivers/usb/phy/phy-tahvo.c after using the
unique id for external connector insteadf of string]
Reported-by: Arnd Bergmann <arnd@arndb.de>
[dan.carpenter: Report the build warning of extcon_{set|get}_cable_state_()]
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
2015-04-24 18:16:05 +08:00
|
|
|
EXTCON_NONE,
|
2012-06-24 19:09:45 +08:00
|
|
|
};
|
|
|
|
|
2013-04-02 02:09:45 +08:00
|
|
|
static void arizona_start_hpdet_acc_id(struct arizona_extcon_info *info);
|
|
|
|
|
2015-02-16 23:41:02 +08:00
|
|
|
static void arizona_extcon_hp_clamp(struct arizona_extcon_info *info,
|
|
|
|
bool clamp)
|
2013-02-12 21:00:31 +08:00
|
|
|
{
|
|
|
|
struct arizona *arizona = info->arizona;
|
2015-02-16 23:41:03 +08:00
|
|
|
unsigned int mask = 0, val = 0;
|
2015-09-16 17:42:18 +08:00
|
|
|
unsigned int cap_sel = 0;
|
2013-02-12 21:00:31 +08:00
|
|
|
int ret;
|
|
|
|
|
2015-02-16 23:41:03 +08:00
|
|
|
switch (arizona->type) {
|
2015-09-28 19:41:42 +08:00
|
|
|
case WM8998:
|
|
|
|
case WM1814:
|
|
|
|
mask = 0;
|
|
|
|
break;
|
2015-02-16 23:41:03 +08:00
|
|
|
case WM5110:
|
2015-04-30 22:43:37 +08:00
|
|
|
case WM8280:
|
2015-02-16 23:41:03 +08:00
|
|
|
mask = ARIZONA_HP1L_SHRTO | ARIZONA_HP1L_FLWR |
|
|
|
|
ARIZONA_HP1L_SHRTI;
|
2015-09-16 17:42:18 +08:00
|
|
|
if (clamp) {
|
2015-02-16 23:41:03 +08:00
|
|
|
val = ARIZONA_HP1L_SHRTO;
|
2015-09-16 17:42:18 +08:00
|
|
|
cap_sel = ARIZONA_TST_CAP_CLAMP;
|
|
|
|
} else {
|
2015-02-16 23:41:03 +08:00
|
|
|
val = ARIZONA_HP1L_FLWR | ARIZONA_HP1L_SHRTI;
|
2015-09-16 17:42:18 +08:00
|
|
|
cap_sel = ARIZONA_TST_CAP_DEFAULT;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = regmap_update_bits(arizona->regmap,
|
|
|
|
ARIZONA_HP_TEST_CTRL_1,
|
|
|
|
ARIZONA_HP1_TST_CAP_SEL_MASK,
|
|
|
|
cap_sel);
|
|
|
|
if (ret != 0)
|
|
|
|
dev_warn(arizona->dev,
|
|
|
|
"Failed to set TST_CAP_SEL: %d\n", ret);
|
2015-02-16 23:41:03 +08:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
mask = ARIZONA_RMV_SHRT_HP1L;
|
|
|
|
if (clamp)
|
|
|
|
val = ARIZONA_RMV_SHRT_HP1L;
|
|
|
|
break;
|
2016-07-19 20:23:56 +08:00
|
|
|
}
|
2015-02-16 23:41:02 +08:00
|
|
|
|
2015-12-30 00:32:03 +08:00
|
|
|
snd_soc_dapm_mutex_lock(arizona->dapm);
|
2013-02-12 21:00:31 +08:00
|
|
|
|
2015-02-16 23:41:02 +08:00
|
|
|
arizona->hpdet_clamp = clamp;
|
2013-02-12 21:00:31 +08:00
|
|
|
|
2015-02-16 23:41:02 +08:00
|
|
|
/* Keep the HP output stages disabled while doing the clamp */
|
|
|
|
if (clamp) {
|
2013-02-23 02:38:03 +08:00
|
|
|
ret = regmap_update_bits(arizona->regmap,
|
|
|
|
ARIZONA_OUTPUT_ENABLES_1,
|
|
|
|
ARIZONA_OUT1L_ENA |
|
|
|
|
ARIZONA_OUT1R_ENA, 0);
|
2013-02-12 21:00:31 +08:00
|
|
|
if (ret != 0)
|
2013-02-23 02:38:03 +08:00
|
|
|
dev_warn(arizona->dev,
|
|
|
|
"Failed to disable headphone outputs: %d\n",
|
|
|
|
ret);
|
|
|
|
}
|
|
|
|
|
2015-09-28 19:41:42 +08:00
|
|
|
if (mask) {
|
|
|
|
ret = regmap_update_bits(arizona->regmap, ARIZONA_HP_CTRL_1L,
|
|
|
|
mask, val);
|
|
|
|
if (ret != 0)
|
|
|
|
dev_warn(arizona->dev, "Failed to do clamp: %d\n",
|
2013-02-12 21:00:31 +08:00
|
|
|
ret);
|
|
|
|
|
2015-09-28 19:41:42 +08:00
|
|
|
ret = regmap_update_bits(arizona->regmap, ARIZONA_HP_CTRL_1R,
|
|
|
|
mask, val);
|
|
|
|
if (ret != 0)
|
|
|
|
dev_warn(arizona->dev, "Failed to do clamp: %d\n",
|
|
|
|
ret);
|
|
|
|
}
|
2013-02-23 02:38:03 +08:00
|
|
|
|
2015-02-16 23:41:02 +08:00
|
|
|
/* Restore the desired state while not doing the clamp */
|
|
|
|
if (!clamp) {
|
2013-02-23 02:38:03 +08:00
|
|
|
ret = regmap_update_bits(arizona->regmap,
|
|
|
|
ARIZONA_OUTPUT_ENABLES_1,
|
|
|
|
ARIZONA_OUT1L_ENA |
|
|
|
|
ARIZONA_OUT1R_ENA, arizona->hp_ena);
|
2013-02-12 21:00:31 +08:00
|
|
|
if (ret != 0)
|
2013-02-23 02:38:03 +08:00
|
|
|
dev_warn(arizona->dev,
|
|
|
|
"Failed to restore headphone outputs: %d\n",
|
2013-02-12 21:00:31 +08:00
|
|
|
ret);
|
|
|
|
}
|
|
|
|
|
2015-12-30 00:32:03 +08:00
|
|
|
snd_soc_dapm_mutex_unlock(arizona->dapm);
|
2013-02-12 21:00:31 +08:00
|
|
|
}
|
|
|
|
|
2012-06-24 19:09:45 +08:00
|
|
|
static void arizona_extcon_set_mode(struct arizona_extcon_info *info, int mode)
|
|
|
|
{
|
|
|
|
struct arizona *arizona = info->arizona;
|
|
|
|
|
2013-04-02 05:03:06 +08:00
|
|
|
mode %= info->micd_num_modes;
|
2013-01-25 20:14:44 +08:00
|
|
|
|
2016-11-25 21:44:36 +08:00
|
|
|
gpiod_set_value_cansleep(info->micd_pol_gpio,
|
|
|
|
info->micd_modes[mode].gpio);
|
2015-06-20 00:23:31 +08:00
|
|
|
|
2012-06-24 19:09:45 +08:00
|
|
|
regmap_update_bits(arizona->regmap, ARIZONA_MIC_DETECT_1,
|
|
|
|
ARIZONA_MICD_BIAS_SRC_MASK,
|
2013-09-23 21:33:59 +08:00
|
|
|
info->micd_modes[mode].bias <<
|
|
|
|
ARIZONA_MICD_BIAS_SRC_SHIFT);
|
2012-06-24 19:09:45 +08:00
|
|
|
regmap_update_bits(arizona->regmap, ARIZONA_ACCESSORY_DETECT_MODE_1,
|
|
|
|
ARIZONA_ACCDET_SRC, info->micd_modes[mode].src);
|
|
|
|
|
|
|
|
info->micd_mode = mode;
|
|
|
|
|
|
|
|
dev_dbg(arizona->dev, "Set jack polarity to %d\n", mode);
|
|
|
|
}
|
|
|
|
|
2013-01-11 03:38:43 +08:00
|
|
|
static const char *arizona_extcon_get_micbias(struct arizona_extcon_info *info)
|
|
|
|
{
|
2013-09-23 21:33:59 +08:00
|
|
|
switch (info->micd_modes[0].bias) {
|
2013-01-11 03:38:43 +08:00
|
|
|
case 1:
|
|
|
|
return "MICBIAS1";
|
|
|
|
case 2:
|
|
|
|
return "MICBIAS2";
|
|
|
|
case 3:
|
|
|
|
return "MICBIAS3";
|
|
|
|
default:
|
|
|
|
return "MICVDD";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void arizona_extcon_pulse_micbias(struct arizona_extcon_info *info)
|
|
|
|
{
|
|
|
|
struct arizona *arizona = info->arizona;
|
|
|
|
const char *widget = arizona_extcon_get_micbias(info);
|
|
|
|
struct snd_soc_dapm_context *dapm = arizona->dapm;
|
2016-11-29 23:44:41 +08:00
|
|
|
struct snd_soc_component *component = snd_soc_dapm_to_component(dapm);
|
2013-01-11 03:38:43 +08:00
|
|
|
int ret;
|
|
|
|
|
2016-11-29 23:44:41 +08:00
|
|
|
ret = snd_soc_component_force_enable_pin(component, widget);
|
2013-01-11 03:38:43 +08:00
|
|
|
if (ret != 0)
|
|
|
|
dev_warn(arizona->dev, "Failed to enable %s: %d\n",
|
|
|
|
widget, ret);
|
|
|
|
|
|
|
|
snd_soc_dapm_sync(dapm);
|
|
|
|
|
|
|
|
if (!arizona->pdata.micd_force_micbias) {
|
2016-11-29 23:44:41 +08:00
|
|
|
ret = snd_soc_component_disable_pin(component, widget);
|
2013-01-11 03:38:43 +08:00
|
|
|
if (ret != 0)
|
|
|
|
dev_warn(arizona->dev, "Failed to disable %s: %d\n",
|
|
|
|
widget, ret);
|
|
|
|
|
|
|
|
snd_soc_dapm_sync(dapm);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-11 07:55:46 +08:00
|
|
|
static void arizona_start_mic(struct arizona_extcon_info *info)
|
|
|
|
{
|
|
|
|
struct arizona *arizona = info->arizona;
|
|
|
|
bool change;
|
|
|
|
int ret;
|
2015-09-16 17:42:16 +08:00
|
|
|
unsigned int mode;
|
2013-01-11 07:55:46 +08:00
|
|
|
|
|
|
|
/* Microphone detection can't use idle mode */
|
|
|
|
pm_runtime_get(info->dev);
|
|
|
|
|
2013-01-11 03:38:43 +08:00
|
|
|
if (info->detecting) {
|
|
|
|
ret = regulator_allow_bypass(info->micvdd, false);
|
|
|
|
if (ret != 0) {
|
|
|
|
dev_err(arizona->dev,
|
|
|
|
"Failed to regulate MICVDD: %d\n",
|
|
|
|
ret);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-11 07:55:46 +08:00
|
|
|
ret = regulator_enable(info->micvdd);
|
|
|
|
if (ret != 0) {
|
|
|
|
dev_err(arizona->dev, "Failed to enable MICVDD: %d\n",
|
|
|
|
ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (info->micd_reva) {
|
|
|
|
regmap_write(arizona->regmap, 0x80, 0x3);
|
|
|
|
regmap_write(arizona->regmap, 0x294, 0);
|
|
|
|
regmap_write(arizona->regmap, 0x80, 0x0);
|
|
|
|
}
|
|
|
|
|
2015-09-16 17:42:16 +08:00
|
|
|
if (info->detecting && arizona->pdata.micd_software_compare)
|
|
|
|
mode = ARIZONA_ACCDET_MODE_ADC;
|
|
|
|
else
|
|
|
|
mode = ARIZONA_ACCDET_MODE_MIC;
|
|
|
|
|
2013-01-11 07:55:46 +08:00
|
|
|
regmap_update_bits(arizona->regmap,
|
|
|
|
ARIZONA_ACCESSORY_DETECT_MODE_1,
|
2015-09-16 17:42:16 +08:00
|
|
|
ARIZONA_ACCDET_MODE_MASK, mode);
|
2013-01-11 07:55:46 +08:00
|
|
|
|
2013-01-11 03:38:43 +08:00
|
|
|
arizona_extcon_pulse_micbias(info);
|
|
|
|
|
2013-01-11 07:55:46 +08:00
|
|
|
regmap_update_bits_check(arizona->regmap, ARIZONA_MIC_DETECT_1,
|
|
|
|
ARIZONA_MICD_ENA, ARIZONA_MICD_ENA,
|
|
|
|
&change);
|
|
|
|
if (!change) {
|
|
|
|
regulator_disable(info->micvdd);
|
|
|
|
pm_runtime_put_autosuspend(info->dev);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void arizona_stop_mic(struct arizona_extcon_info *info)
|
|
|
|
{
|
|
|
|
struct arizona *arizona = info->arizona;
|
2013-01-11 03:38:43 +08:00
|
|
|
const char *widget = arizona_extcon_get_micbias(info);
|
|
|
|
struct snd_soc_dapm_context *dapm = arizona->dapm;
|
2016-11-29 23:44:41 +08:00
|
|
|
struct snd_soc_component *component = snd_soc_dapm_to_component(dapm);
|
2013-01-11 07:55:46 +08:00
|
|
|
bool change;
|
2013-01-11 03:38:43 +08:00
|
|
|
int ret;
|
2013-01-11 07:55:46 +08:00
|
|
|
|
|
|
|
regmap_update_bits_check(arizona->regmap, ARIZONA_MIC_DETECT_1,
|
|
|
|
ARIZONA_MICD_ENA, 0,
|
|
|
|
&change);
|
|
|
|
|
2016-11-29 23:44:41 +08:00
|
|
|
ret = snd_soc_component_disable_pin(component, widget);
|
2013-01-11 03:38:43 +08:00
|
|
|
if (ret != 0)
|
|
|
|
dev_warn(arizona->dev,
|
|
|
|
"Failed to disable %s: %d\n",
|
|
|
|
widget, ret);
|
|
|
|
|
|
|
|
snd_soc_dapm_sync(dapm);
|
|
|
|
|
2013-01-11 07:55:46 +08:00
|
|
|
if (info->micd_reva) {
|
|
|
|
regmap_write(arizona->regmap, 0x80, 0x3);
|
|
|
|
regmap_write(arizona->regmap, 0x294, 2);
|
|
|
|
regmap_write(arizona->regmap, 0x80, 0x0);
|
|
|
|
}
|
|
|
|
|
2013-01-11 03:38:43 +08:00
|
|
|
ret = regulator_allow_bypass(info->micvdd, true);
|
|
|
|
if (ret != 0) {
|
|
|
|
dev_err(arizona->dev, "Failed to bypass MICVDD: %d\n",
|
|
|
|
ret);
|
|
|
|
}
|
|
|
|
|
2013-01-11 07:55:46 +08:00
|
|
|
if (change) {
|
|
|
|
regulator_disable(info->micvdd);
|
|
|
|
pm_runtime_mark_last_busy(info->dev);
|
|
|
|
pm_runtime_put_autosuspend(info->dev);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-11 07:55:43 +08:00
|
|
|
static struct {
|
2014-05-30 20:19:17 +08:00
|
|
|
unsigned int threshold;
|
2013-01-11 07:55:43 +08:00
|
|
|
unsigned int factor_a;
|
|
|
|
unsigned int factor_b;
|
|
|
|
} arizona_hpdet_b_ranges[] = {
|
2014-05-30 20:19:17 +08:00
|
|
|
{ 100, 5528, 362464 },
|
|
|
|
{ 169, 11084, 6186851 },
|
|
|
|
{ 169, 11065, 65460395 },
|
2013-01-11 07:55:43 +08:00
|
|
|
};
|
|
|
|
|
2014-05-30 20:19:17 +08:00
|
|
|
#define ARIZONA_HPDET_B_RANGE_MAX 0x3fb
|
|
|
|
|
2013-01-11 07:55:43 +08:00
|
|
|
static struct {
|
|
|
|
int min;
|
|
|
|
int max;
|
|
|
|
} arizona_hpdet_c_ranges[] = {
|
|
|
|
{ 0, 30 },
|
|
|
|
{ 8, 100 },
|
|
|
|
{ 100, 1000 },
|
|
|
|
{ 1000, 10000 },
|
|
|
|
};
|
|
|
|
|
|
|
|
static int arizona_hpdet_read(struct arizona_extcon_info *info)
|
|
|
|
{
|
|
|
|
struct arizona *arizona = info->arizona;
|
|
|
|
unsigned int val, range;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = regmap_read(arizona->regmap, ARIZONA_HEADPHONE_DETECT_2, &val);
|
|
|
|
if (ret != 0) {
|
|
|
|
dev_err(arizona->dev, "Failed to read HPDET status: %d\n",
|
|
|
|
ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2015-04-28 20:34:27 +08:00
|
|
|
switch (info->hpdet_ip_version) {
|
2013-01-11 07:55:43 +08:00
|
|
|
case 0:
|
|
|
|
if (!(val & ARIZONA_HP_DONE)) {
|
|
|
|
dev_err(arizona->dev, "HPDET did not complete: %x\n",
|
|
|
|
val);
|
2013-01-21 16:30:02 +08:00
|
|
|
return -EAGAIN;
|
2013-01-11 07:55:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
val &= ARIZONA_HP_LVL_MASK;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 1:
|
|
|
|
if (!(val & ARIZONA_HP_DONE_B)) {
|
|
|
|
dev_err(arizona->dev, "HPDET did not complete: %x\n",
|
|
|
|
val);
|
2013-01-21 16:30:02 +08:00
|
|
|
return -EAGAIN;
|
2013-01-11 07:55:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
ret = regmap_read(arizona->regmap, ARIZONA_HP_DACVAL, &val);
|
|
|
|
if (ret != 0) {
|
|
|
|
dev_err(arizona->dev, "Failed to read HP value: %d\n",
|
|
|
|
ret);
|
2013-01-21 16:30:02 +08:00
|
|
|
return -EAGAIN;
|
2013-01-11 07:55:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
regmap_read(arizona->regmap, ARIZONA_HEADPHONE_DETECT_1,
|
|
|
|
&range);
|
|
|
|
range = (range & ARIZONA_HP_IMPEDANCE_RANGE_MASK)
|
|
|
|
>> ARIZONA_HP_IMPEDANCE_RANGE_SHIFT;
|
|
|
|
|
|
|
|
if (range < ARRAY_SIZE(arizona_hpdet_b_ranges) - 1 &&
|
2014-05-30 20:19:17 +08:00
|
|
|
(val < arizona_hpdet_b_ranges[range].threshold ||
|
|
|
|
val >= ARIZONA_HPDET_B_RANGE_MAX)) {
|
2013-01-11 07:55:43 +08:00
|
|
|
range++;
|
|
|
|
dev_dbg(arizona->dev, "Moving to HPDET range %d\n",
|
|
|
|
range);
|
|
|
|
regmap_update_bits(arizona->regmap,
|
|
|
|
ARIZONA_HEADPHONE_DETECT_1,
|
|
|
|
ARIZONA_HP_IMPEDANCE_RANGE_MASK,
|
|
|
|
range <<
|
|
|
|
ARIZONA_HP_IMPEDANCE_RANGE_SHIFT);
|
|
|
|
return -EAGAIN;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If we go out of range report top of range */
|
2014-05-30 20:19:17 +08:00
|
|
|
if (val < arizona_hpdet_b_ranges[range].threshold ||
|
|
|
|
val >= ARIZONA_HPDET_B_RANGE_MAX) {
|
2013-01-11 07:55:43 +08:00
|
|
|
dev_dbg(arizona->dev, "Measurement out of range\n");
|
2013-04-02 02:09:45 +08:00
|
|
|
return ARIZONA_HPDET_MAX;
|
2013-01-11 07:55:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
dev_dbg(arizona->dev, "HPDET read %d in range %d\n",
|
|
|
|
val, range);
|
|
|
|
|
|
|
|
val = arizona_hpdet_b_ranges[range].factor_b
|
|
|
|
/ ((val * 100) -
|
|
|
|
arizona_hpdet_b_ranges[range].factor_a);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 2:
|
|
|
|
if (!(val & ARIZONA_HP_DONE_B)) {
|
|
|
|
dev_err(arizona->dev, "HPDET did not complete: %x\n",
|
|
|
|
val);
|
2013-01-21 16:30:02 +08:00
|
|
|
return -EAGAIN;
|
2013-01-11 07:55:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
val &= ARIZONA_HP_LVL_B_MASK;
|
2013-11-15 00:18:25 +08:00
|
|
|
/* Convert to ohms, the value is in 0.5 ohm increments */
|
|
|
|
val /= 2;
|
2013-01-11 07:55:43 +08:00
|
|
|
|
|
|
|
regmap_read(arizona->regmap, ARIZONA_HEADPHONE_DETECT_1,
|
|
|
|
&range);
|
|
|
|
range = (range & ARIZONA_HP_IMPEDANCE_RANGE_MASK)
|
|
|
|
>> ARIZONA_HP_IMPEDANCE_RANGE_SHIFT;
|
|
|
|
|
2013-11-15 00:18:24 +08:00
|
|
|
/* Skip up a range, or report? */
|
2013-01-11 07:55:43 +08:00
|
|
|
if (range < ARRAY_SIZE(arizona_hpdet_c_ranges) - 1 &&
|
|
|
|
(val >= arizona_hpdet_c_ranges[range].max)) {
|
|
|
|
range++;
|
|
|
|
dev_dbg(arizona->dev, "Moving to HPDET range %d-%d\n",
|
|
|
|
arizona_hpdet_c_ranges[range].min,
|
|
|
|
arizona_hpdet_c_ranges[range].max);
|
|
|
|
regmap_update_bits(arizona->regmap,
|
|
|
|
ARIZONA_HEADPHONE_DETECT_1,
|
|
|
|
ARIZONA_HP_IMPEDANCE_RANGE_MASK,
|
|
|
|
range <<
|
|
|
|
ARIZONA_HP_IMPEDANCE_RANGE_SHIFT);
|
|
|
|
return -EAGAIN;
|
|
|
|
}
|
2013-11-15 00:18:24 +08:00
|
|
|
|
|
|
|
if (range && (val < arizona_hpdet_c_ranges[range].min)) {
|
|
|
|
dev_dbg(arizona->dev, "Reporting range boundary %d\n",
|
|
|
|
arizona_hpdet_c_ranges[range].min);
|
|
|
|
val = arizona_hpdet_c_ranges[range].min;
|
|
|
|
}
|
2015-09-29 18:06:31 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
dev_warn(arizona->dev, "Unknown HPDET IP revision %d\n",
|
|
|
|
info->hpdet_ip_version);
|
|
|
|
return -EINVAL;
|
2013-01-11 07:55:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
dev_dbg(arizona->dev, "HP impedance %d ohms\n", val);
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
2013-02-26 07:42:31 +08:00
|
|
|
static int arizona_hpdet_do_id(struct arizona_extcon_info *info, int *reading,
|
|
|
|
bool *mic)
|
2013-01-11 07:55:51 +08:00
|
|
|
{
|
|
|
|
struct arizona *arizona = info->arizona;
|
2013-01-11 07:55:54 +08:00
|
|
|
int id_gpio = arizona->pdata.hpdet_id_gpio;
|
2013-01-11 07:55:51 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* If we're using HPDET for accessory identification we need
|
|
|
|
* to take multiple measurements, step through them in sequence.
|
|
|
|
*/
|
|
|
|
if (arizona->pdata.hpdet_acc_id) {
|
|
|
|
info->hpdet_res[info->num_hpdet_res++] = *reading;
|
2013-01-11 07:55:54 +08:00
|
|
|
|
|
|
|
/* Only check the mic directly if we didn't already ID it */
|
2013-02-26 07:42:31 +08:00
|
|
|
if (id_gpio && info->num_hpdet_res == 1) {
|
2013-01-11 07:55:54 +08:00
|
|
|
dev_dbg(arizona->dev, "Measuring mic\n");
|
|
|
|
|
|
|
|
regmap_update_bits(arizona->regmap,
|
|
|
|
ARIZONA_ACCESSORY_DETECT_MODE_1,
|
|
|
|
ARIZONA_ACCDET_MODE_MASK |
|
|
|
|
ARIZONA_ACCDET_SRC,
|
|
|
|
ARIZONA_ACCDET_MODE_HPR |
|
|
|
|
info->micd_modes[0].src);
|
|
|
|
|
|
|
|
gpio_set_value_cansleep(id_gpio, 1);
|
|
|
|
|
2013-01-11 07:55:51 +08:00
|
|
|
regmap_update_bits(arizona->regmap,
|
|
|
|
ARIZONA_HEADPHONE_DETECT_1,
|
|
|
|
ARIZONA_HP_POLL, ARIZONA_HP_POLL);
|
|
|
|
return -EAGAIN;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* OK, got both. Now, compare... */
|
2013-02-26 07:42:31 +08:00
|
|
|
dev_dbg(arizona->dev, "HPDET measured %d %d\n",
|
|
|
|
info->hpdet_res[0], info->hpdet_res[1]);
|
2013-02-06 01:48:49 +08:00
|
|
|
|
|
|
|
/* Take the headphone impedance for the main report */
|
|
|
|
*reading = info->hpdet_res[0];
|
|
|
|
|
2013-04-02 02:09:45 +08:00
|
|
|
/* Sometimes we get false readings due to slow insert */
|
|
|
|
if (*reading >= ARIZONA_HPDET_MAX && !info->hpdet_retried) {
|
|
|
|
dev_dbg(arizona->dev, "Retrying high impedance\n");
|
|
|
|
info->num_hpdet_res = 0;
|
|
|
|
info->hpdet_retried = true;
|
|
|
|
arizona_start_hpdet_acc_id(info);
|
|
|
|
pm_runtime_put(info->dev);
|
|
|
|
return -EAGAIN;
|
|
|
|
}
|
|
|
|
|
2013-01-11 07:55:54 +08:00
|
|
|
/*
|
2013-08-05 17:00:46 +08:00
|
|
|
* If we measure the mic as high impedance
|
2013-01-11 07:55:54 +08:00
|
|
|
*/
|
2013-02-26 07:42:31 +08:00
|
|
|
if (!id_gpio || info->hpdet_res[1] > 50) {
|
2013-01-11 07:55:51 +08:00
|
|
|
dev_dbg(arizona->dev, "Detected mic\n");
|
2013-02-26 07:42:31 +08:00
|
|
|
*mic = true;
|
2013-02-06 04:20:17 +08:00
|
|
|
info->detecting = true;
|
2013-01-11 07:55:51 +08:00
|
|
|
} else {
|
|
|
|
dev_dbg(arizona->dev, "Detected headphone\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Make sure everything is reset back to the real polarity */
|
|
|
|
regmap_update_bits(arizona->regmap,
|
|
|
|
ARIZONA_ACCESSORY_DETECT_MODE_1,
|
|
|
|
ARIZONA_ACCDET_SRC,
|
|
|
|
info->micd_modes[0].src);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-01-11 07:55:43 +08:00
|
|
|
static irqreturn_t arizona_hpdet_irq(int irq, void *data)
|
|
|
|
{
|
|
|
|
struct arizona_extcon_info *info = data;
|
|
|
|
struct arizona *arizona = info->arizona;
|
2013-01-11 07:55:54 +08:00
|
|
|
int id_gpio = arizona->pdata.hpdet_id_gpio;
|
2015-10-03 13:15:13 +08:00
|
|
|
unsigned int report = EXTCON_JACK_HEADPHONE;
|
2013-01-11 07:55:51 +08:00
|
|
|
int ret, reading;
|
2013-02-26 07:42:31 +08:00
|
|
|
bool mic = false;
|
2013-01-11 07:55:43 +08:00
|
|
|
|
|
|
|
mutex_lock(&info->lock);
|
|
|
|
|
|
|
|
/* If we got a spurious IRQ for some reason then ignore it */
|
|
|
|
if (!info->hpdet_active) {
|
|
|
|
dev_warn(arizona->dev, "Spurious HPDET IRQ\n");
|
|
|
|
mutex_unlock(&info->lock);
|
|
|
|
return IRQ_NONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If the cable was removed while measuring ignore the result */
|
2016-08-16 14:55:34 +08:00
|
|
|
ret = extcon_get_state(info->edev, EXTCON_MECHANICAL);
|
2013-01-11 07:55:43 +08:00
|
|
|
if (ret < 0) {
|
|
|
|
dev_err(arizona->dev, "Failed to check cable state: %d\n",
|
|
|
|
ret);
|
|
|
|
goto out;
|
|
|
|
} else if (!ret) {
|
|
|
|
dev_dbg(arizona->dev, "Ignoring HPDET for removed cable\n");
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = arizona_hpdet_read(info);
|
2013-08-23 09:21:39 +08:00
|
|
|
if (ret == -EAGAIN)
|
2013-01-11 07:55:43 +08:00
|
|
|
goto out;
|
2013-08-23 09:21:39 +08:00
|
|
|
else if (ret < 0)
|
2013-01-11 07:55:43 +08:00
|
|
|
goto done;
|
2013-01-11 07:55:51 +08:00
|
|
|
reading = ret;
|
2013-01-11 07:55:43 +08:00
|
|
|
|
|
|
|
/* Reset back to starting range */
|
|
|
|
regmap_update_bits(arizona->regmap,
|
|
|
|
ARIZONA_HEADPHONE_DETECT_1,
|
2013-01-11 07:55:51 +08:00
|
|
|
ARIZONA_HP_IMPEDANCE_RANGE_MASK | ARIZONA_HP_POLL,
|
|
|
|
0);
|
|
|
|
|
2013-02-26 07:42:31 +08:00
|
|
|
ret = arizona_hpdet_do_id(info, &reading, &mic);
|
2013-08-23 09:21:39 +08:00
|
|
|
if (ret == -EAGAIN)
|
2013-01-11 07:55:51 +08:00
|
|
|
goto out;
|
2013-08-23 09:21:39 +08:00
|
|
|
else if (ret < 0)
|
2013-01-11 07:55:51 +08:00
|
|
|
goto done;
|
2013-01-11 07:55:43 +08:00
|
|
|
|
|
|
|
/* Report high impedence cables as line outputs */
|
2013-01-11 07:55:51 +08:00
|
|
|
if (reading >= 5000)
|
2015-10-03 13:15:13 +08:00
|
|
|
report = EXTCON_JACK_LINE_OUT;
|
2013-01-11 07:55:43 +08:00
|
|
|
else
|
2015-10-03 13:15:13 +08:00
|
|
|
report = EXTCON_JACK_HEADPHONE;
|
2013-01-11 07:55:43 +08:00
|
|
|
|
2016-08-16 14:55:34 +08:00
|
|
|
ret = extcon_set_state_sync(info->edev, report, true);
|
2013-01-11 07:55:43 +08:00
|
|
|
if (ret != 0)
|
|
|
|
dev_err(arizona->dev, "Failed to report HP/line: %d\n",
|
|
|
|
ret);
|
|
|
|
|
2013-11-15 00:18:22 +08:00
|
|
|
done:
|
|
|
|
/* Reset back to starting range */
|
|
|
|
regmap_update_bits(arizona->regmap,
|
|
|
|
ARIZONA_HEADPHONE_DETECT_1,
|
|
|
|
ARIZONA_HP_IMPEDANCE_RANGE_MASK | ARIZONA_HP_POLL,
|
|
|
|
0);
|
|
|
|
|
2015-02-16 23:41:02 +08:00
|
|
|
arizona_extcon_hp_clamp(info, false);
|
2013-01-11 07:55:43 +08:00
|
|
|
|
2013-01-11 07:55:54 +08:00
|
|
|
if (id_gpio)
|
|
|
|
gpio_set_value_cansleep(id_gpio, 0);
|
2013-01-11 07:55:43 +08:00
|
|
|
|
|
|
|
/* Revert back to MICDET mode */
|
|
|
|
regmap_update_bits(arizona->regmap,
|
|
|
|
ARIZONA_ACCESSORY_DETECT_MODE_1,
|
|
|
|
ARIZONA_ACCDET_MODE_MASK, ARIZONA_ACCDET_MODE_MIC);
|
|
|
|
|
|
|
|
/* If we have a mic then reenable MICDET */
|
2013-02-26 07:42:31 +08:00
|
|
|
if (mic || info->mic)
|
2013-01-11 07:55:43 +08:00
|
|
|
arizona_start_mic(info);
|
|
|
|
|
|
|
|
if (info->hpdet_active) {
|
|
|
|
pm_runtime_put_autosuspend(info->dev);
|
|
|
|
info->hpdet_active = false;
|
|
|
|
}
|
|
|
|
|
2013-02-06 04:20:17 +08:00
|
|
|
info->hpdet_done = true;
|
|
|
|
|
2013-01-11 07:55:43 +08:00
|
|
|
out:
|
|
|
|
mutex_unlock(&info->lock);
|
|
|
|
|
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void arizona_identify_headphone(struct arizona_extcon_info *info)
|
|
|
|
{
|
|
|
|
struct arizona *arizona = info->arizona;
|
|
|
|
int ret;
|
|
|
|
|
2013-02-06 04:20:17 +08:00
|
|
|
if (info->hpdet_done)
|
|
|
|
return;
|
|
|
|
|
2013-01-11 07:55:43 +08:00
|
|
|
dev_dbg(arizona->dev, "Starting HPDET\n");
|
|
|
|
|
|
|
|
/* Make sure we keep the device enabled during the measurement */
|
|
|
|
pm_runtime_get(info->dev);
|
|
|
|
|
|
|
|
info->hpdet_active = true;
|
|
|
|
|
|
|
|
if (info->mic)
|
|
|
|
arizona_stop_mic(info);
|
|
|
|
|
2015-02-16 23:41:02 +08:00
|
|
|
arizona_extcon_hp_clamp(info, true);
|
2013-01-11 07:55:43 +08:00
|
|
|
|
|
|
|
ret = regmap_update_bits(arizona->regmap,
|
|
|
|
ARIZONA_ACCESSORY_DETECT_MODE_1,
|
|
|
|
ARIZONA_ACCDET_MODE_MASK,
|
2015-05-04 12:42:13 +08:00
|
|
|
arizona->pdata.hpdet_channel);
|
2013-01-11 07:55:43 +08:00
|
|
|
if (ret != 0) {
|
2015-05-04 12:42:13 +08:00
|
|
|
dev_err(arizona->dev, "Failed to set HPDET mode: %d\n", ret);
|
2013-01-11 07:55:43 +08:00
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = regmap_update_bits(arizona->regmap, ARIZONA_HEADPHONE_DETECT_1,
|
|
|
|
ARIZONA_HP_POLL, ARIZONA_HP_POLL);
|
|
|
|
if (ret != 0) {
|
|
|
|
dev_err(arizona->dev, "Can't start HPDETL measurement: %d\n",
|
|
|
|
ret);
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
err:
|
|
|
|
regmap_update_bits(arizona->regmap, ARIZONA_ACCESSORY_DETECT_MODE_1,
|
|
|
|
ARIZONA_ACCDET_MODE_MASK, ARIZONA_ACCDET_MODE_MIC);
|
|
|
|
|
|
|
|
/* Just report headphone */
|
2016-08-16 14:55:34 +08:00
|
|
|
ret = extcon_set_state_sync(info->edev, EXTCON_JACK_HEADPHONE, true);
|
2013-01-11 07:55:43 +08:00
|
|
|
if (ret != 0)
|
|
|
|
dev_err(arizona->dev, "Failed to report headphone: %d\n", ret);
|
|
|
|
|
|
|
|
if (info->mic)
|
|
|
|
arizona_start_mic(info);
|
|
|
|
|
|
|
|
info->hpdet_active = false;
|
|
|
|
}
|
2013-01-11 07:55:51 +08:00
|
|
|
|
|
|
|
static void arizona_start_hpdet_acc_id(struct arizona_extcon_info *info)
|
|
|
|
{
|
|
|
|
struct arizona *arizona = info->arizona;
|
2013-02-26 07:42:31 +08:00
|
|
|
int hp_reading = 32;
|
|
|
|
bool mic;
|
2013-01-11 07:55:51 +08:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
dev_dbg(arizona->dev, "Starting identification via HPDET\n");
|
|
|
|
|
|
|
|
/* Make sure we keep the device enabled during the measurement */
|
2013-02-06 05:00:15 +08:00
|
|
|
pm_runtime_get_sync(info->dev);
|
2013-01-11 07:55:51 +08:00
|
|
|
|
|
|
|
info->hpdet_active = true;
|
|
|
|
|
2015-02-16 23:41:02 +08:00
|
|
|
arizona_extcon_hp_clamp(info, true);
|
2013-01-11 07:55:51 +08:00
|
|
|
|
|
|
|
ret = regmap_update_bits(arizona->regmap,
|
|
|
|
ARIZONA_ACCESSORY_DETECT_MODE_1,
|
|
|
|
ARIZONA_ACCDET_SRC | ARIZONA_ACCDET_MODE_MASK,
|
|
|
|
info->micd_modes[0].src |
|
2015-05-04 12:42:13 +08:00
|
|
|
arizona->pdata.hpdet_channel);
|
2013-01-11 07:55:51 +08:00
|
|
|
if (ret != 0) {
|
2015-05-04 12:42:13 +08:00
|
|
|
dev_err(arizona->dev, "Failed to set HPDET mode: %d\n", ret);
|
2013-01-11 07:55:51 +08:00
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
2013-02-26 07:42:31 +08:00
|
|
|
if (arizona->pdata.hpdet_acc_id_line) {
|
|
|
|
ret = regmap_update_bits(arizona->regmap,
|
|
|
|
ARIZONA_HEADPHONE_DETECT_1,
|
|
|
|
ARIZONA_HP_POLL, ARIZONA_HP_POLL);
|
|
|
|
if (ret != 0) {
|
|
|
|
dev_err(arizona->dev,
|
|
|
|
"Can't start HPDETL measurement: %d\n",
|
|
|
|
ret);
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
arizona_hpdet_do_id(info, &hp_reading, &mic);
|
2013-01-11 07:55:43 +08:00
|
|
|
}
|
|
|
|
|
2013-01-11 07:55:51 +08:00
|
|
|
return;
|
|
|
|
|
|
|
|
err:
|
|
|
|
regmap_update_bits(arizona->regmap, ARIZONA_ACCESSORY_DETECT_MODE_1,
|
|
|
|
ARIZONA_ACCDET_MODE_MASK, ARIZONA_ACCDET_MODE_MIC);
|
|
|
|
|
|
|
|
/* Just report headphone */
|
2016-08-16 14:55:34 +08:00
|
|
|
ret = extcon_set_state_sync(info->edev, EXTCON_JACK_HEADPHONE, true);
|
2013-01-11 07:55:51 +08:00
|
|
|
if (ret != 0)
|
|
|
|
dev_err(arizona->dev, "Failed to report headphone: %d\n", ret);
|
|
|
|
|
2013-01-11 07:55:43 +08:00
|
|
|
info->hpdet_active = false;
|
|
|
|
}
|
|
|
|
|
2013-04-02 02:17:34 +08:00
|
|
|
static void arizona_micd_timeout_work(struct work_struct *work)
|
|
|
|
{
|
|
|
|
struct arizona_extcon_info *info = container_of(work,
|
2013-08-23 09:21:37 +08:00
|
|
|
struct arizona_extcon_info,
|
|
|
|
micd_timeout_work.work);
|
2013-04-02 02:17:34 +08:00
|
|
|
|
|
|
|
mutex_lock(&info->lock);
|
|
|
|
|
|
|
|
dev_dbg(info->arizona->dev, "MICD timed out, reporting HP\n");
|
|
|
|
|
|
|
|
info->detecting = false;
|
|
|
|
|
2015-06-20 00:23:32 +08:00
|
|
|
arizona_identify_headphone(info);
|
|
|
|
|
2013-04-02 02:17:34 +08:00
|
|
|
arizona_stop_mic(info);
|
|
|
|
|
|
|
|
mutex_unlock(&info->lock);
|
|
|
|
}
|
|
|
|
|
2013-04-02 02:21:48 +08:00
|
|
|
static void arizona_micd_detect(struct work_struct *work)
|
2012-06-24 19:09:45 +08:00
|
|
|
{
|
2013-04-02 02:21:48 +08:00
|
|
|
struct arizona_extcon_info *info = container_of(work,
|
2013-08-23 09:21:37 +08:00
|
|
|
struct arizona_extcon_info,
|
|
|
|
micd_detect_work.work);
|
2012-06-24 19:09:45 +08:00
|
|
|
struct arizona *arizona = info->arizona;
|
2013-04-02 02:06:29 +08:00
|
|
|
unsigned int val = 0, lvl;
|
2013-04-02 05:03:06 +08:00
|
|
|
int ret, i, key;
|
2012-06-24 19:09:45 +08:00
|
|
|
|
2013-04-02 02:17:34 +08:00
|
|
|
cancel_delayed_work_sync(&info->micd_timeout_work);
|
|
|
|
|
2012-06-24 19:09:45 +08:00
|
|
|
mutex_lock(&info->lock);
|
|
|
|
|
2013-11-15 00:18:23 +08:00
|
|
|
/* If the cable was removed while measuring ignore the result */
|
2016-08-16 14:55:34 +08:00
|
|
|
ret = extcon_get_state(info->edev, EXTCON_MECHANICAL);
|
2013-11-15 00:18:23 +08:00
|
|
|
if (ret < 0) {
|
|
|
|
dev_err(arizona->dev, "Failed to check cable state: %d\n",
|
|
|
|
ret);
|
|
|
|
mutex_unlock(&info->lock);
|
|
|
|
return;
|
|
|
|
} else if (!ret) {
|
|
|
|
dev_dbg(arizona->dev, "Ignoring MICDET for removed cable\n");
|
|
|
|
mutex_unlock(&info->lock);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-09-16 17:42:16 +08:00
|
|
|
if (info->detecting && arizona->pdata.micd_software_compare) {
|
|
|
|
/* Must disable MICD before we read the ADCVAL */
|
|
|
|
regmap_update_bits(arizona->regmap, ARIZONA_MIC_DETECT_1,
|
|
|
|
ARIZONA_MICD_ENA, 0);
|
|
|
|
ret = regmap_read(arizona->regmap, ARIZONA_MIC_DETECT_4, &val);
|
|
|
|
if (ret != 0) {
|
|
|
|
dev_err(arizona->dev,
|
|
|
|
"Failed to read MICDET_ADCVAL: %d\n",
|
|
|
|
ret);
|
|
|
|
mutex_unlock(&info->lock);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
dev_dbg(arizona->dev, "MICDET_ADCVAL: %x\n", val);
|
|
|
|
|
|
|
|
val &= ARIZONA_MICDET_ADCVAL_MASK;
|
|
|
|
if (val < ARRAY_SIZE(arizona_micd_levels))
|
|
|
|
val = arizona_micd_levels[val];
|
|
|
|
else
|
|
|
|
val = INT_MAX;
|
|
|
|
|
|
|
|
if (val <= QUICK_HEADPHONE_MAX_OHM)
|
|
|
|
val = ARIZONA_MICD_STS | ARIZONA_MICD_LVL_0;
|
|
|
|
else if (val <= MICROPHONE_MIN_OHM)
|
|
|
|
val = ARIZONA_MICD_STS | ARIZONA_MICD_LVL_1;
|
|
|
|
else if (val <= MICROPHONE_MAX_OHM)
|
|
|
|
val = ARIZONA_MICD_STS | ARIZONA_MICD_LVL_8;
|
|
|
|
else
|
|
|
|
val = ARIZONA_MICD_LVL_8;
|
|
|
|
}
|
|
|
|
|
2013-11-15 00:18:21 +08:00
|
|
|
for (i = 0; i < 10 && !(val & MICD_LVL_0_TO_8); i++) {
|
2013-04-02 02:06:29 +08:00
|
|
|
ret = regmap_read(arizona->regmap, ARIZONA_MIC_DETECT_3, &val);
|
|
|
|
if (ret != 0) {
|
2013-08-23 09:21:37 +08:00
|
|
|
dev_err(arizona->dev,
|
|
|
|
"Failed to read MICDET: %d\n", ret);
|
2013-04-02 02:06:29 +08:00
|
|
|
mutex_unlock(&info->lock);
|
2013-04-02 02:21:48 +08:00
|
|
|
return;
|
2013-04-02 02:06:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
dev_dbg(arizona->dev, "MICDET: %x\n", val);
|
2012-06-24 19:09:45 +08:00
|
|
|
|
2013-04-02 02:06:29 +08:00
|
|
|
if (!(val & ARIZONA_MICD_VALID)) {
|
2013-08-23 09:21:37 +08:00
|
|
|
dev_warn(arizona->dev,
|
|
|
|
"Microphone detection state invalid\n");
|
2013-04-02 02:06:29 +08:00
|
|
|
mutex_unlock(&info->lock);
|
2013-04-02 02:21:48 +08:00
|
|
|
return;
|
2013-04-02 02:06:29 +08:00
|
|
|
}
|
|
|
|
}
|
2012-06-24 19:09:45 +08:00
|
|
|
|
2013-11-15 00:18:21 +08:00
|
|
|
if (i == 10 && !(val & MICD_LVL_0_TO_8)) {
|
2013-04-02 02:06:29 +08:00
|
|
|
dev_err(arizona->dev, "Failed to get valid MICDET value\n");
|
2012-06-24 19:09:45 +08:00
|
|
|
mutex_unlock(&info->lock);
|
2013-04-02 02:21:48 +08:00
|
|
|
return;
|
2012-06-24 19:09:45 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Due to jack detect this should never happen */
|
|
|
|
if (!(val & ARIZONA_MICD_STS)) {
|
|
|
|
dev_warn(arizona->dev, "Detected open circuit\n");
|
2015-06-25 23:47:02 +08:00
|
|
|
info->mic = false;
|
|
|
|
arizona_stop_mic(info);
|
2012-06-24 19:09:45 +08:00
|
|
|
info->detecting = false;
|
2015-06-25 23:47:02 +08:00
|
|
|
arizona_identify_headphone(info);
|
2012-06-24 19:09:45 +08:00
|
|
|
goto handled;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If we got a high impedence we should have a headset, report it. */
|
2013-11-15 00:18:21 +08:00
|
|
|
if (info->detecting && (val & ARIZONA_MICD_LVL_8)) {
|
2015-06-20 00:23:32 +08:00
|
|
|
info->mic = true;
|
|
|
|
info->detecting = false;
|
|
|
|
|
2013-01-11 07:55:43 +08:00
|
|
|
arizona_identify_headphone(info);
|
|
|
|
|
2016-08-16 14:55:34 +08:00
|
|
|
ret = extcon_set_state_sync(info->edev,
|
2015-10-03 13:15:13 +08:00
|
|
|
EXTCON_JACK_MICROPHONE, true);
|
2012-06-24 19:09:45 +08:00
|
|
|
if (ret != 0)
|
|
|
|
dev_err(arizona->dev, "Headset report failed: %d\n",
|
|
|
|
ret);
|
|
|
|
|
2013-01-11 03:38:43 +08:00
|
|
|
/* Don't need to regulate for button detection */
|
2014-05-29 23:27:54 +08:00
|
|
|
ret = regulator_allow_bypass(info->micvdd, true);
|
2013-01-11 03:38:43 +08:00
|
|
|
if (ret != 0) {
|
|
|
|
dev_err(arizona->dev, "Failed to bypass MICVDD: %d\n",
|
|
|
|
ret);
|
|
|
|
}
|
|
|
|
|
2012-06-24 19:09:45 +08:00
|
|
|
goto handled;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If we detected a lower impedence during initial startup
|
|
|
|
* then we probably have the wrong polarity, flip it. Don't
|
|
|
|
* do this for the lowest impedences to speed up detection of
|
|
|
|
* plain headphones. If both polarities report a low
|
|
|
|
* impedence then give up and report headphones.
|
|
|
|
*/
|
2013-11-15 00:18:21 +08:00
|
|
|
if (info->detecting && (val & MICD_LVL_1_TO_7)) {
|
2013-01-25 20:14:44 +08:00
|
|
|
if (info->jack_flips >= info->micd_num_modes * 10) {
|
2013-01-11 07:55:43 +08:00
|
|
|
dev_dbg(arizona->dev, "Detected HP/line\n");
|
|
|
|
|
2012-06-24 19:09:45 +08:00
|
|
|
info->detecting = false;
|
2012-06-28 20:08:31 +08:00
|
|
|
|
2015-06-20 00:23:32 +08:00
|
|
|
arizona_identify_headphone(info);
|
|
|
|
|
2013-01-11 07:55:43 +08:00
|
|
|
arizona_stop_mic(info);
|
2012-06-24 19:09:45 +08:00
|
|
|
} else {
|
|
|
|
info->micd_mode++;
|
|
|
|
if (info->micd_mode == info->micd_num_modes)
|
|
|
|
info->micd_mode = 0;
|
|
|
|
arizona_extcon_set_mode(info, info->micd_mode);
|
|
|
|
|
|
|
|
info->jack_flips++;
|
|
|
|
}
|
|
|
|
|
|
|
|
goto handled;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If we're still detecting and we detect a short then we've
|
2012-07-21 00:07:29 +08:00
|
|
|
* got a headphone. Otherwise it's a button press.
|
2012-06-24 19:09:45 +08:00
|
|
|
*/
|
2013-11-15 00:18:21 +08:00
|
|
|
if (val & MICD_LVL_0_TO_7) {
|
2012-06-24 19:09:45 +08:00
|
|
|
if (info->mic) {
|
|
|
|
dev_dbg(arizona->dev, "Mic button detected\n");
|
|
|
|
|
2012-07-21 00:07:29 +08:00
|
|
|
lvl = val & ARIZONA_MICD_LVL_MASK;
|
|
|
|
lvl >>= ARIZONA_MICD_LVL_SHIFT;
|
|
|
|
|
2013-04-02 02:18:18 +08:00
|
|
|
for (i = 0; i < info->num_micd_ranges; i++)
|
|
|
|
input_report_key(info->input,
|
|
|
|
info->micd_ranges[i].key, 0);
|
|
|
|
|
2013-04-02 05:03:06 +08:00
|
|
|
WARN_ON(!lvl);
|
|
|
|
WARN_ON(ffs(lvl) - 1 >= info->num_micd_ranges);
|
|
|
|
if (lvl && ffs(lvl) - 1 < info->num_micd_ranges) {
|
|
|
|
key = info->micd_ranges[ffs(lvl) - 1].key;
|
|
|
|
input_report_key(info->input, key, 1);
|
|
|
|
input_sync(info->input);
|
|
|
|
}
|
2012-07-21 00:07:29 +08:00
|
|
|
|
2012-06-24 19:09:45 +08:00
|
|
|
} else if (info->detecting) {
|
|
|
|
dev_dbg(arizona->dev, "Headphone detected\n");
|
|
|
|
info->detecting = false;
|
|
|
|
arizona_stop_mic(info);
|
|
|
|
|
2013-01-11 07:55:43 +08:00
|
|
|
arizona_identify_headphone(info);
|
2012-06-24 19:09:45 +08:00
|
|
|
} else {
|
|
|
|
dev_warn(arizona->dev, "Button with no mic: %x\n",
|
|
|
|
val);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
dev_dbg(arizona->dev, "Mic button released\n");
|
2013-04-02 05:03:06 +08:00
|
|
|
for (i = 0; i < info->num_micd_ranges; i++)
|
2012-07-21 00:07:29 +08:00
|
|
|
input_report_key(info->input,
|
2013-04-02 05:03:06 +08:00
|
|
|
info->micd_ranges[i].key, 0);
|
2012-07-21 00:07:29 +08:00
|
|
|
input_sync(info->input);
|
2013-01-11 03:38:43 +08:00
|
|
|
arizona_extcon_pulse_micbias(info);
|
2012-06-24 19:09:45 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
handled:
|
2015-09-16 17:42:16 +08:00
|
|
|
if (info->detecting) {
|
|
|
|
if (arizona->pdata.micd_software_compare)
|
|
|
|
regmap_update_bits(arizona->regmap,
|
|
|
|
ARIZONA_MIC_DETECT_1,
|
|
|
|
ARIZONA_MICD_ENA,
|
|
|
|
ARIZONA_MICD_ENA);
|
|
|
|
|
2013-07-19 05:42:22 +08:00
|
|
|
queue_delayed_work(system_power_efficient_wq,
|
|
|
|
&info->micd_timeout_work,
|
|
|
|
msecs_to_jiffies(info->micd_timeout));
|
2015-09-16 17:42:16 +08:00
|
|
|
}
|
2013-04-02 02:17:34 +08:00
|
|
|
|
2012-06-24 19:09:45 +08:00
|
|
|
pm_runtime_mark_last_busy(info->dev);
|
|
|
|
mutex_unlock(&info->lock);
|
2013-04-02 02:21:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static irqreturn_t arizona_micdet(int irq, void *data)
|
|
|
|
{
|
|
|
|
struct arizona_extcon_info *info = data;
|
|
|
|
struct arizona *arizona = info->arizona;
|
|
|
|
int debounce = arizona->pdata.micd_detect_debounce;
|
|
|
|
|
|
|
|
cancel_delayed_work_sync(&info->micd_detect_work);
|
|
|
|
cancel_delayed_work_sync(&info->micd_timeout_work);
|
|
|
|
|
|
|
|
mutex_lock(&info->lock);
|
|
|
|
if (!info->detecting)
|
|
|
|
debounce = 0;
|
|
|
|
mutex_unlock(&info->lock);
|
|
|
|
|
|
|
|
if (debounce)
|
2013-07-19 05:42:22 +08:00
|
|
|
queue_delayed_work(system_power_efficient_wq,
|
|
|
|
&info->micd_detect_work,
|
|
|
|
msecs_to_jiffies(debounce));
|
2013-04-02 02:21:48 +08:00
|
|
|
else
|
|
|
|
arizona_micd_detect(&info->micd_detect_work.work);
|
2012-06-24 19:09:45 +08:00
|
|
|
|
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
|
2013-02-06 05:00:15 +08:00
|
|
|
static void arizona_hpdet_work(struct work_struct *work)
|
|
|
|
{
|
|
|
|
struct arizona_extcon_info *info = container_of(work,
|
2013-08-23 09:21:37 +08:00
|
|
|
struct arizona_extcon_info,
|
|
|
|
hpdet_work.work);
|
2013-02-06 05:00:15 +08:00
|
|
|
|
|
|
|
mutex_lock(&info->lock);
|
|
|
|
arizona_start_hpdet_acc_id(info);
|
|
|
|
mutex_unlock(&info->lock);
|
|
|
|
}
|
|
|
|
|
2017-01-25 17:34:06 +08:00
|
|
|
static int arizona_hpdet_wait(struct arizona_extcon_info *info)
|
|
|
|
{
|
|
|
|
struct arizona *arizona = info->arizona;
|
|
|
|
unsigned int val;
|
|
|
|
int i, ret;
|
|
|
|
|
|
|
|
for (i = 0; i < ARIZONA_HPDET_WAIT_COUNT; i++) {
|
|
|
|
ret = regmap_read(arizona->regmap, ARIZONA_HEADPHONE_DETECT_2,
|
|
|
|
&val);
|
|
|
|
if (ret) {
|
|
|
|
dev_err(arizona->dev,
|
|
|
|
"Failed to read HPDET state: %d\n", ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (info->hpdet_ip_version) {
|
|
|
|
case 0:
|
|
|
|
if (val & ARIZONA_HP_DONE)
|
|
|
|
return 0;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
if (val & ARIZONA_HP_DONE_B)
|
|
|
|
return 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
msleep(ARIZONA_HPDET_WAIT_DELAY_MS);
|
|
|
|
}
|
|
|
|
|
|
|
|
dev_warn(arizona->dev, "HPDET did not appear to complete\n");
|
|
|
|
|
|
|
|
return -ETIMEDOUT;
|
|
|
|
}
|
|
|
|
|
2012-06-24 19:09:45 +08:00
|
|
|
static irqreturn_t arizona_jackdet(int irq, void *data)
|
|
|
|
{
|
|
|
|
struct arizona_extcon_info *info = data;
|
|
|
|
struct arizona *arizona = info->arizona;
|
2013-01-11 07:55:39 +08:00
|
|
|
unsigned int val, present, mask;
|
2013-04-02 02:17:34 +08:00
|
|
|
bool cancelled_hp, cancelled_mic;
|
2012-07-21 00:07:29 +08:00
|
|
|
int ret, i;
|
2012-06-24 19:09:45 +08:00
|
|
|
|
2013-04-02 02:17:34 +08:00
|
|
|
cancelled_hp = cancel_delayed_work_sync(&info->hpdet_work);
|
|
|
|
cancelled_mic = cancel_delayed_work_sync(&info->micd_timeout_work);
|
2012-06-24 19:09:45 +08:00
|
|
|
|
2013-04-02 02:05:27 +08:00
|
|
|
pm_runtime_get_sync(info->dev);
|
2013-02-06 05:00:15 +08:00
|
|
|
|
2012-06-24 19:09:45 +08:00
|
|
|
mutex_lock(&info->lock);
|
|
|
|
|
2015-09-16 17:42:20 +08:00
|
|
|
if (info->micd_clamp) {
|
2013-01-11 07:55:39 +08:00
|
|
|
mask = ARIZONA_MICD_CLAMP_STS;
|
2015-09-16 17:42:19 +08:00
|
|
|
present = 0;
|
2013-01-11 07:55:39 +08:00
|
|
|
} else {
|
|
|
|
mask = ARIZONA_JD1_STS;
|
2014-05-23 19:54:57 +08:00
|
|
|
if (arizona->pdata.jd_invert)
|
|
|
|
present = 0;
|
|
|
|
else
|
|
|
|
present = ARIZONA_JD1_STS;
|
2013-01-11 07:55:39 +08:00
|
|
|
}
|
|
|
|
|
2012-06-24 19:09:45 +08:00
|
|
|
ret = regmap_read(arizona->regmap, ARIZONA_AOD_IRQ_RAW_STATUS, &val);
|
|
|
|
if (ret != 0) {
|
|
|
|
dev_err(arizona->dev, "Failed to read jackdet status: %d\n",
|
|
|
|
ret);
|
|
|
|
mutex_unlock(&info->lock);
|
|
|
|
pm_runtime_put_autosuspend(info->dev);
|
|
|
|
return IRQ_NONE;
|
|
|
|
}
|
|
|
|
|
2013-04-02 02:05:27 +08:00
|
|
|
val &= mask;
|
|
|
|
if (val == info->last_jackdet) {
|
|
|
|
dev_dbg(arizona->dev, "Suppressing duplicate JACKDET\n");
|
2013-04-02 02:17:34 +08:00
|
|
|
if (cancelled_hp)
|
2013-07-19 05:42:22 +08:00
|
|
|
queue_delayed_work(system_power_efficient_wq,
|
|
|
|
&info->hpdet_work,
|
|
|
|
msecs_to_jiffies(HPDET_DEBOUNCE));
|
2013-04-02 02:05:27 +08:00
|
|
|
|
2013-08-23 09:21:37 +08:00
|
|
|
if (cancelled_mic) {
|
|
|
|
int micd_timeout = info->micd_timeout;
|
|
|
|
|
2013-07-19 05:42:22 +08:00
|
|
|
queue_delayed_work(system_power_efficient_wq,
|
|
|
|
&info->micd_timeout_work,
|
2013-08-23 09:21:37 +08:00
|
|
|
msecs_to_jiffies(micd_timeout));
|
|
|
|
}
|
2013-04-02 02:17:34 +08:00
|
|
|
|
2013-04-02 02:05:27 +08:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
info->last_jackdet = val;
|
|
|
|
|
|
|
|
if (info->last_jackdet == present) {
|
2012-06-24 19:09:45 +08:00
|
|
|
dev_dbg(arizona->dev, "Detected jack\n");
|
2016-08-16 14:55:34 +08:00
|
|
|
ret = extcon_set_state_sync(info->edev,
|
extcon: Use the unique id for external connector instead of string
This patch uses the unique id to identify the type of external connector instead
of string name. The string name have the many potential issues. So, this patch
defines the 'extcon' enumeration which includes all supported external connector
on EXTCON subsystem. If new external connector is necessary, the unique id of
new connector have to be added in 'extcon' enumeration. There are current
supported external connector in 'enum extcon' as following:
enum extcon {
EXTCON_NONE = 0x0,
/* USB external connector */
EXTCON_USB = 0x1,
EXTCON_USB_HOST = 0x2,
/* Charger external connector */
EXTCON_TA = 0x10,
EXTCON_FAST_CHARGER = 0x11,
EXTCON_SLOW_CHARGER = 0x12,
EXTCON_CHARGE_DOWNSTREAM = 0x13,
/* Audio and video external connector */
EXTCON_LINE_IN = 0x20,
EXTCON_LINE_OUT = 0x21,
EXTCON_MICROPHONE = 0x22,
EXTCON_HEADPHONE = 0x23,
EXTCON_HDMI = 0x30,
EXTCON_MHL = 0x31,
EXTCON_DVI = 0x32,
EXTCON_VGA = 0x33,
EXTCON_SPDIF_IN = 0x34,
EXTCON_SPDIF_OUT = 0x35,
EXTCON_VIDEO_IN = 0x36,
EXTCON_VIDEO_OUT = 0x37,
/* Miscellaneous external connector */
EXTCON_DOCK = 0x50,
EXTCON_JIG = 0x51,
EXTCON_MECHANICAL = 0x52,
EXTCON_END,
};
For example in extcon-arizona.c:
To use unique id removes the potential issue about handling
the inconsistent name of external connector with string.
- Previously, use the string to register the type of arizona jack connector
static const char *arizona_cable[] = {
"Mechanical",
"Microphone",
"Headphone",
"Line-out",
};
- Newly, use the unique id to register the type of arizona jack connector
static const enum extcon arizona_cable[] = {
EXTCON_MECHANICAL,
EXTCON_MICROPHONE,
EXTCON_HEADPHONE,
EXTCON_LINE_OUT,
EXTCON_NONE,
};
And this patch modify the prototype of extcon_{get|set}_cable_state_() which
uses the 'enum extcon id' instead of 'cable_index'. Because although one more
extcon drivers support USB cable, each extcon driver might has the differnt
'cable_index' for USB cable. All extcon drivers can use the unique id number
for same external connector with modified extcon_{get|set}_cable_state_().
- Previously, use 'cable_index' on these functions:
extcon_get_cable_state_(struct extcon_dev*, int cable_index)
extcon_set_cable_state_(struct extcon_dev*, int cable_index, bool state)
-Newly, use 'enum extcon id' on these functions:
extcon_get_cable_state_(struct extcon_dev*, enum extcon id)
extcon_set_cable_state_(struct extcon_dev*, enum extcon id, bool state)
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Felipe Balbi <balbi@ti.com>
Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>
Acked-by: Roger Quadros <rogerq@ti.com>
Acked-by: Charles Keepax <ckeepax@opensource.wolfsonmicro.com>
Acked-by: Ramakrishna Pallala <ramakrishna.pallala@intel.com>
Reviewed-by: Krzysztof Kozlowski <k.kozlowski@samsung.com>
[arnd: Report the build break about drivers/usb/phy/phy-tahvo.c after using the
unique id for external connector insteadf of string]
Reported-by: Arnd Bergmann <arnd@arndb.de>
[dan.carpenter: Report the build warning of extcon_{set|get}_cable_state_()]
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
2015-04-24 18:16:05 +08:00
|
|
|
EXTCON_MECHANICAL, true);
|
2012-06-24 19:09:45 +08:00
|
|
|
|
|
|
|
if (ret != 0)
|
|
|
|
dev_err(arizona->dev, "Mechanical report failed: %d\n",
|
|
|
|
ret);
|
|
|
|
|
2013-01-11 07:55:51 +08:00
|
|
|
if (!arizona->pdata.hpdet_acc_id) {
|
|
|
|
info->detecting = true;
|
|
|
|
info->mic = false;
|
|
|
|
info->jack_flips = 0;
|
|
|
|
|
|
|
|
arizona_start_mic(info);
|
|
|
|
} else {
|
2013-07-19 05:42:22 +08:00
|
|
|
queue_delayed_work(system_power_efficient_wq,
|
|
|
|
&info->hpdet_work,
|
|
|
|
msecs_to_jiffies(HPDET_DEBOUNCE));
|
2013-01-11 07:55:51 +08:00
|
|
|
}
|
2013-01-15 21:09:20 +08:00
|
|
|
|
2015-09-16 17:42:21 +08:00
|
|
|
if (info->micd_clamp || !arizona->pdata.jd_invert)
|
|
|
|
regmap_update_bits(arizona->regmap,
|
|
|
|
ARIZONA_JACK_DETECT_DEBOUNCE,
|
|
|
|
ARIZONA_MICD_CLAMP_DB |
|
|
|
|
ARIZONA_JD1_DB, 0);
|
2012-06-24 19:09:45 +08:00
|
|
|
} else {
|
|
|
|
dev_dbg(arizona->dev, "Detected jack removal\n");
|
|
|
|
|
|
|
|
arizona_stop_mic(info);
|
|
|
|
|
2013-01-11 07:55:51 +08:00
|
|
|
info->num_hpdet_res = 0;
|
|
|
|
for (i = 0; i < ARRAY_SIZE(info->hpdet_res); i++)
|
|
|
|
info->hpdet_res[i] = 0;
|
|
|
|
info->mic = false;
|
2013-02-06 04:20:17 +08:00
|
|
|
info->hpdet_done = false;
|
2013-04-02 02:09:45 +08:00
|
|
|
info->hpdet_retried = false;
|
2013-01-11 07:55:39 +08:00
|
|
|
|
2013-04-02 05:03:06 +08:00
|
|
|
for (i = 0; i < info->num_micd_ranges; i++)
|
2012-07-21 00:07:29 +08:00
|
|
|
input_report_key(info->input,
|
2013-04-02 05:03:06 +08:00
|
|
|
info->micd_ranges[i].key, 0);
|
2012-07-21 00:07:29 +08:00
|
|
|
input_sync(info->input);
|
|
|
|
|
2016-07-01 01:36:49 +08:00
|
|
|
for (i = 0; i < ARRAY_SIZE(arizona_cable) - 1; i++) {
|
2016-08-16 14:55:34 +08:00
|
|
|
ret = extcon_set_state_sync(info->edev,
|
2016-07-01 01:36:49 +08:00
|
|
|
arizona_cable[i], false);
|
|
|
|
if (ret != 0)
|
|
|
|
dev_err(arizona->dev,
|
|
|
|
"Removal report failed: %d\n", ret);
|
|
|
|
}
|
2013-01-15 21:09:20 +08:00
|
|
|
|
2017-01-25 17:34:06 +08:00
|
|
|
/*
|
|
|
|
* If the jack was removed during a headphone detection we
|
|
|
|
* need to wait for the headphone detection to finish, as
|
|
|
|
* it can not be aborted. We don't want to be able to start
|
|
|
|
* a new headphone detection from a fresh insert until this
|
|
|
|
* one is finished.
|
|
|
|
*/
|
|
|
|
arizona_hpdet_wait(info);
|
|
|
|
|
2013-01-15 21:09:20 +08:00
|
|
|
regmap_update_bits(arizona->regmap,
|
|
|
|
ARIZONA_JACK_DETECT_DEBOUNCE,
|
|
|
|
ARIZONA_MICD_CLAMP_DB | ARIZONA_JD1_DB,
|
|
|
|
ARIZONA_MICD_CLAMP_DB | ARIZONA_JD1_DB);
|
2012-06-24 19:09:45 +08:00
|
|
|
}
|
|
|
|
|
2013-04-02 02:25:55 +08:00
|
|
|
if (arizona->pdata.micd_timeout)
|
|
|
|
info->micd_timeout = arizona->pdata.micd_timeout;
|
|
|
|
else
|
|
|
|
info->micd_timeout = DEFAULT_MICD_TIMEOUT;
|
|
|
|
|
2013-08-07 19:17:14 +08:00
|
|
|
out:
|
2013-02-05 18:13:38 +08:00
|
|
|
/* Clear trig_sts to make sure DCVDD is not forced up */
|
|
|
|
regmap_write(arizona->regmap, ARIZONA_AOD_WKUP_AND_TRIG,
|
|
|
|
ARIZONA_MICD_CLAMP_FALL_TRIG_STS |
|
|
|
|
ARIZONA_MICD_CLAMP_RISE_TRIG_STS |
|
|
|
|
ARIZONA_JD1_FALL_TRIG_STS |
|
|
|
|
ARIZONA_JD1_RISE_TRIG_STS);
|
|
|
|
|
2012-06-24 19:09:45 +08:00
|
|
|
mutex_unlock(&info->lock);
|
|
|
|
|
|
|
|
pm_runtime_mark_last_busy(info->dev);
|
|
|
|
pm_runtime_put_autosuspend(info->dev);
|
|
|
|
|
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
|
2013-04-02 05:03:06 +08:00
|
|
|
/* Map a level onto a slot in the register bank */
|
|
|
|
static void arizona_micd_set_level(struct arizona *arizona, int index,
|
|
|
|
unsigned int level)
|
|
|
|
{
|
|
|
|
int reg;
|
|
|
|
unsigned int mask;
|
|
|
|
|
|
|
|
reg = ARIZONA_MIC_DETECT_LEVEL_4 - (index / 2);
|
|
|
|
|
|
|
|
if (!(index % 2)) {
|
|
|
|
mask = 0x3f00;
|
|
|
|
level <<= 8;
|
|
|
|
} else {
|
|
|
|
mask = 0x3f;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Program the level itself */
|
|
|
|
regmap_update_bits(arizona->regmap, reg, mask, level);
|
|
|
|
}
|
|
|
|
|
2015-12-14 18:37:11 +08:00
|
|
|
static int arizona_extcon_get_micd_configs(struct device *dev,
|
|
|
|
struct arizona *arizona)
|
|
|
|
{
|
|
|
|
const char * const prop = "wlf,micd-configs";
|
|
|
|
const int entries_per_config = 3;
|
|
|
|
struct arizona_micd_config *micd_configs;
|
|
|
|
int nconfs, ret;
|
|
|
|
int i, j;
|
|
|
|
u32 *vals;
|
|
|
|
|
|
|
|
nconfs = device_property_read_u32_array(arizona->dev, prop, NULL, 0);
|
|
|
|
if (nconfs <= 0)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
vals = kcalloc(nconfs, sizeof(u32), GFP_KERNEL);
|
|
|
|
if (!vals)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
ret = device_property_read_u32_array(arizona->dev, prop, vals, nconfs);
|
|
|
|
if (ret < 0)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
nconfs /= entries_per_config;
|
2017-04-24 04:44:19 +08:00
|
|
|
micd_configs = devm_kcalloc(dev, nconfs, sizeof(*micd_configs),
|
2015-12-14 18:37:11 +08:00
|
|
|
GFP_KERNEL);
|
|
|
|
if (!micd_configs) {
|
|
|
|
ret = -ENOMEM;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0, j = 0; i < nconfs; ++i) {
|
|
|
|
micd_configs[i].src = vals[j++] ? ARIZONA_ACCDET_SRC : 0;
|
|
|
|
micd_configs[i].bias = vals[j++];
|
|
|
|
micd_configs[i].gpio = vals[j++];
|
|
|
|
}
|
|
|
|
|
|
|
|
arizona->pdata.micd_configs = micd_configs;
|
|
|
|
arizona->pdata.num_micd_configs = nconfs;
|
|
|
|
|
|
|
|
out:
|
|
|
|
kfree(vals);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int arizona_extcon_device_get_pdata(struct device *dev,
|
|
|
|
struct arizona *arizona)
|
2015-05-04 12:42:13 +08:00
|
|
|
{
|
|
|
|
struct arizona_pdata *pdata = &arizona->pdata;
|
|
|
|
unsigned int val = ARIZONA_ACCDET_MODE_HPL;
|
2015-12-14 18:37:11 +08:00
|
|
|
int ret;
|
2015-05-04 12:42:13 +08:00
|
|
|
|
2015-06-20 00:23:29 +08:00
|
|
|
device_property_read_u32(arizona->dev, "wlf,hpdet-channel", &val);
|
2015-05-04 12:42:13 +08:00
|
|
|
switch (val) {
|
|
|
|
case ARIZONA_ACCDET_MODE_HPL:
|
|
|
|
case ARIZONA_ACCDET_MODE_HPR:
|
|
|
|
pdata->hpdet_channel = val;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
dev_err(arizona->dev,
|
|
|
|
"Wrong wlf,hpdet-channel DT value %d\n", val);
|
|
|
|
pdata->hpdet_channel = ARIZONA_ACCDET_MODE_HPL;
|
|
|
|
}
|
|
|
|
|
2015-06-20 00:23:30 +08:00
|
|
|
device_property_read_u32(arizona->dev, "wlf,micd-detect-debounce",
|
|
|
|
&pdata->micd_detect_debounce);
|
|
|
|
|
|
|
|
device_property_read_u32(arizona->dev, "wlf,micd-bias-start-time",
|
|
|
|
&pdata->micd_bias_start_time);
|
|
|
|
|
|
|
|
device_property_read_u32(arizona->dev, "wlf,micd-rate",
|
|
|
|
&pdata->micd_rate);
|
|
|
|
|
|
|
|
device_property_read_u32(arizona->dev, "wlf,micd-dbtime",
|
|
|
|
&pdata->micd_dbtime);
|
|
|
|
|
2015-11-23 22:51:30 +08:00
|
|
|
device_property_read_u32(arizona->dev, "wlf,micd-timeout-ms",
|
2015-06-20 00:23:30 +08:00
|
|
|
&pdata->micd_timeout);
|
|
|
|
|
|
|
|
pdata->micd_force_micbias = device_property_read_bool(arizona->dev,
|
|
|
|
"wlf,micd-force-micbias");
|
|
|
|
|
2015-11-19 23:45:35 +08:00
|
|
|
pdata->micd_software_compare = device_property_read_bool(arizona->dev,
|
|
|
|
"wlf,micd-software-compare");
|
|
|
|
|
2015-11-19 23:45:37 +08:00
|
|
|
pdata->jd_invert = device_property_read_bool(arizona->dev,
|
|
|
|
"wlf,jd-invert");
|
|
|
|
|
2015-11-19 23:45:36 +08:00
|
|
|
device_property_read_u32(arizona->dev, "wlf,gpsw", &pdata->gpsw);
|
|
|
|
|
2015-11-19 23:45:38 +08:00
|
|
|
pdata->jd_gpio5 = device_property_read_bool(arizona->dev,
|
2015-11-20 16:53:59 +08:00
|
|
|
"wlf,use-jd2");
|
2015-11-19 23:45:38 +08:00
|
|
|
pdata->jd_gpio5_nopull = device_property_read_bool(arizona->dev,
|
2015-11-20 16:53:59 +08:00
|
|
|
"wlf,use-jd2-nopull");
|
2015-11-19 23:45:38 +08:00
|
|
|
|
2015-12-14 18:37:11 +08:00
|
|
|
ret = arizona_extcon_get_micd_configs(dev, arizona);
|
|
|
|
if (ret < 0)
|
|
|
|
dev_err(arizona->dev, "Failed to read micd configs: %d\n", ret);
|
|
|
|
|
2015-05-04 12:42:13 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-11-20 02:23:21 +08:00
|
|
|
static int arizona_extcon_probe(struct platform_device *pdev)
|
2012-06-24 19:09:45 +08:00
|
|
|
{
|
|
|
|
struct arizona *arizona = dev_get_drvdata(pdev->dev.parent);
|
2013-09-28 22:34:57 +08:00
|
|
|
struct arizona_pdata *pdata = &arizona->pdata;
|
2012-06-24 19:09:45 +08:00
|
|
|
struct arizona_extcon_info *info;
|
2013-04-02 02:03:52 +08:00
|
|
|
unsigned int val;
|
2014-05-23 19:54:57 +08:00
|
|
|
unsigned int clamp_mode;
|
2013-01-11 07:55:39 +08:00
|
|
|
int jack_irq_fall, jack_irq_rise;
|
2013-04-02 05:03:06 +08:00
|
|
|
int ret, mode, i, j;
|
2012-06-24 19:09:45 +08:00
|
|
|
|
2013-01-11 03:38:43 +08:00
|
|
|
if (!arizona->dapm || !arizona->dapm->card)
|
|
|
|
return -EPROBE_DEFER;
|
|
|
|
|
2012-06-24 19:09:45 +08:00
|
|
|
info = devm_kzalloc(&pdev->dev, sizeof(*info), GFP_KERNEL);
|
2014-07-23 09:07:09 +08:00
|
|
|
if (!info)
|
2014-04-21 18:10:15 +08:00
|
|
|
return -ENOMEM;
|
2012-06-24 19:09:45 +08:00
|
|
|
|
2015-06-20 00:23:29 +08:00
|
|
|
if (!dev_get_platdata(arizona->dev))
|
2015-12-14 18:37:11 +08:00
|
|
|
arizona_extcon_device_get_pdata(&pdev->dev, arizona);
|
2015-05-04 12:42:13 +08:00
|
|
|
|
2014-07-18 19:59:00 +08:00
|
|
|
info->micvdd = devm_regulator_get(&pdev->dev, "MICVDD");
|
2012-06-24 19:09:45 +08:00
|
|
|
if (IS_ERR(info->micvdd)) {
|
|
|
|
ret = PTR_ERR(info->micvdd);
|
|
|
|
dev_err(arizona->dev, "Failed to get MICVDD: %d\n", ret);
|
2014-04-21 18:10:15 +08:00
|
|
|
return ret;
|
2012-06-24 19:09:45 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
mutex_init(&info->lock);
|
|
|
|
info->arizona = arizona;
|
|
|
|
info->dev = &pdev->dev;
|
2013-04-02 02:05:27 +08:00
|
|
|
info->last_jackdet = ~(ARIZONA_MICD_CLAMP_STS | ARIZONA_JD1_STS);
|
2013-02-06 05:00:15 +08:00
|
|
|
INIT_DELAYED_WORK(&info->hpdet_work, arizona_hpdet_work);
|
2013-04-02 02:21:48 +08:00
|
|
|
INIT_DELAYED_WORK(&info->micd_detect_work, arizona_micd_detect);
|
2013-04-02 02:17:34 +08:00
|
|
|
INIT_DELAYED_WORK(&info->micd_timeout_work, arizona_micd_timeout_work);
|
2012-06-24 19:09:45 +08:00
|
|
|
platform_set_drvdata(pdev, info);
|
|
|
|
|
|
|
|
switch (arizona->type) {
|
|
|
|
case WM5102:
|
|
|
|
switch (arizona->rev) {
|
|
|
|
case 0:
|
|
|
|
info->micd_reva = true;
|
|
|
|
break;
|
|
|
|
default:
|
2013-01-11 07:55:36 +08:00
|
|
|
info->micd_clamp = true;
|
2015-04-28 20:34:27 +08:00
|
|
|
info->hpdet_ip_version = 1;
|
2012-06-24 19:09:45 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
2013-11-15 00:18:25 +08:00
|
|
|
case WM5110:
|
2015-01-17 23:21:26 +08:00
|
|
|
case WM8280:
|
2013-11-15 00:18:25 +08:00
|
|
|
switch (arizona->rev) {
|
|
|
|
case 0 ... 2:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
info->micd_clamp = true;
|
2015-04-28 20:34:27 +08:00
|
|
|
info->hpdet_ip_version = 2;
|
2013-11-15 00:18:25 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
2015-09-28 19:41:42 +08:00
|
|
|
case WM8998:
|
|
|
|
case WM1814:
|
|
|
|
info->micd_clamp = true;
|
|
|
|
info->hpdet_ip_version = 2;
|
|
|
|
break;
|
2012-06-24 19:09:45 +08:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2014-04-21 19:47:31 +08:00
|
|
|
info->edev = devm_extcon_dev_allocate(&pdev->dev, arizona_cable);
|
|
|
|
if (IS_ERR(info->edev)) {
|
|
|
|
dev_err(&pdev->dev, "failed to allocate extcon device\n");
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
2012-06-24 19:09:45 +08:00
|
|
|
|
2014-04-21 19:47:31 +08:00
|
|
|
ret = devm_extcon_dev_register(&pdev->dev, info->edev);
|
2012-06-24 19:09:45 +08:00
|
|
|
if (ret < 0) {
|
2012-08-23 08:11:50 +08:00
|
|
|
dev_err(arizona->dev, "extcon_dev_register() failed: %d\n",
|
2012-06-24 19:09:45 +08:00
|
|
|
ret);
|
2014-04-21 18:10:15 +08:00
|
|
|
return ret;
|
2012-06-24 19:09:45 +08:00
|
|
|
}
|
|
|
|
|
2013-04-02 05:03:06 +08:00
|
|
|
info->input = devm_input_allocate_device(&pdev->dev);
|
|
|
|
if (!info->input) {
|
|
|
|
dev_err(arizona->dev, "Can't allocate input dev\n");
|
|
|
|
ret = -ENOMEM;
|
|
|
|
goto err_register;
|
|
|
|
}
|
|
|
|
|
|
|
|
info->input->name = "Headset";
|
|
|
|
info->input->phys = "arizona/extcon";
|
|
|
|
|
2012-06-24 19:09:45 +08:00
|
|
|
if (pdata->num_micd_configs) {
|
|
|
|
info->micd_modes = pdata->micd_configs;
|
|
|
|
info->micd_num_modes = pdata->num_micd_configs;
|
|
|
|
} else {
|
|
|
|
info->micd_modes = micd_default_modes;
|
|
|
|
info->micd_num_modes = ARRAY_SIZE(micd_default_modes);
|
|
|
|
}
|
|
|
|
|
2015-09-16 17:42:17 +08:00
|
|
|
if (arizona->pdata.gpsw > 0)
|
|
|
|
regmap_update_bits(arizona->regmap, ARIZONA_GP_SWITCH_1,
|
|
|
|
ARIZONA_SW1_MODE_MASK, arizona->pdata.gpsw);
|
|
|
|
|
2016-11-25 21:44:36 +08:00
|
|
|
if (pdata->micd_pol_gpio > 0) {
|
2012-06-24 19:09:45 +08:00
|
|
|
if (info->micd_modes[0].gpio)
|
|
|
|
mode = GPIOF_OUT_INIT_HIGH;
|
|
|
|
else
|
|
|
|
mode = GPIOF_OUT_INIT_LOW;
|
|
|
|
|
2016-11-25 21:44:36 +08:00
|
|
|
ret = devm_gpio_request_one(&pdev->dev, pdata->micd_pol_gpio,
|
|
|
|
mode, "MICD polarity");
|
2012-06-24 19:09:45 +08:00
|
|
|
if (ret != 0) {
|
|
|
|
dev_err(arizona->dev, "Failed to request GPIO%d: %d\n",
|
2016-11-25 21:44:36 +08:00
|
|
|
pdata->micd_pol_gpio, ret);
|
2012-06-24 19:09:45 +08:00
|
|
|
goto err_register;
|
|
|
|
}
|
2016-11-25 21:44:36 +08:00
|
|
|
|
|
|
|
info->micd_pol_gpio = gpio_to_desc(pdata->micd_pol_gpio);
|
2015-06-20 00:23:31 +08:00
|
|
|
} else {
|
|
|
|
if (info->micd_modes[0].gpio)
|
|
|
|
mode = GPIOD_OUT_HIGH;
|
|
|
|
else
|
|
|
|
mode = GPIOD_OUT_LOW;
|
|
|
|
|
|
|
|
/* We can't use devm here because we need to do the get
|
|
|
|
* against the MFD device, as that is where the of_node
|
|
|
|
* will reside, but if we devm against that the GPIO
|
|
|
|
* will not be freed if the extcon driver is unloaded.
|
|
|
|
*/
|
|
|
|
info->micd_pol_gpio = gpiod_get_optional(arizona->dev,
|
|
|
|
"wlf,micd-pol",
|
|
|
|
GPIOD_OUT_LOW);
|
|
|
|
if (IS_ERR(info->micd_pol_gpio)) {
|
|
|
|
ret = PTR_ERR(info->micd_pol_gpio);
|
|
|
|
dev_err(arizona->dev,
|
|
|
|
"Failed to get microphone polarity GPIO: %d\n",
|
|
|
|
ret);
|
|
|
|
goto err_register;
|
|
|
|
}
|
2012-06-24 19:09:45 +08:00
|
|
|
}
|
|
|
|
|
2013-01-11 07:55:54 +08:00
|
|
|
if (arizona->pdata.hpdet_id_gpio > 0) {
|
|
|
|
ret = devm_gpio_request_one(&pdev->dev,
|
|
|
|
arizona->pdata.hpdet_id_gpio,
|
|
|
|
GPIOF_OUT_INIT_LOW,
|
|
|
|
"HPDET");
|
|
|
|
if (ret != 0) {
|
|
|
|
dev_err(arizona->dev, "Failed to request GPIO%d: %d\n",
|
|
|
|
arizona->pdata.hpdet_id_gpio, ret);
|
2015-06-20 00:23:31 +08:00
|
|
|
goto err_gpio;
|
2013-01-11 07:55:54 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-11 07:55:24 +08:00
|
|
|
if (arizona->pdata.micd_bias_start_time)
|
|
|
|
regmap_update_bits(arizona->regmap, ARIZONA_MIC_DETECT_1,
|
|
|
|
ARIZONA_MICD_BIAS_STARTTIME_MASK,
|
|
|
|
arizona->pdata.micd_bias_start_time
|
|
|
|
<< ARIZONA_MICD_BIAS_STARTTIME_SHIFT);
|
|
|
|
|
2013-01-21 16:36:33 +08:00
|
|
|
if (arizona->pdata.micd_rate)
|
|
|
|
regmap_update_bits(arizona->regmap, ARIZONA_MIC_DETECT_1,
|
|
|
|
ARIZONA_MICD_RATE_MASK,
|
|
|
|
arizona->pdata.micd_rate
|
|
|
|
<< ARIZONA_MICD_RATE_SHIFT);
|
|
|
|
|
2015-06-30 20:32:39 +08:00
|
|
|
switch (arizona->pdata.micd_dbtime) {
|
|
|
|
case MICD_DBTIME_FOUR_READINGS:
|
2013-01-21 16:36:33 +08:00
|
|
|
regmap_update_bits(arizona->regmap, ARIZONA_MIC_DETECT_1,
|
|
|
|
ARIZONA_MICD_DBTIME_MASK,
|
2015-06-30 20:32:39 +08:00
|
|
|
ARIZONA_MICD_DBTIME);
|
|
|
|
break;
|
|
|
|
case MICD_DBTIME_TWO_READINGS:
|
|
|
|
regmap_update_bits(arizona->regmap, ARIZONA_MIC_DETECT_1,
|
|
|
|
ARIZONA_MICD_DBTIME_MASK, 0);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2013-01-21 16:36:33 +08:00
|
|
|
|
2015-09-16 17:42:16 +08:00
|
|
|
BUILD_BUG_ON(ARRAY_SIZE(arizona_micd_levels) <
|
|
|
|
ARIZONA_NUM_MICD_BUTTON_LEVELS);
|
2013-04-02 05:03:06 +08:00
|
|
|
|
|
|
|
if (arizona->pdata.num_micd_ranges) {
|
|
|
|
info->micd_ranges = pdata->micd_ranges;
|
|
|
|
info->num_micd_ranges = pdata->num_micd_ranges;
|
|
|
|
} else {
|
|
|
|
info->micd_ranges = micd_default_ranges;
|
|
|
|
info->num_micd_ranges = ARRAY_SIZE(micd_default_ranges);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (arizona->pdata.num_micd_ranges > ARIZONA_MAX_MICD_RANGE) {
|
|
|
|
dev_err(arizona->dev, "Too many MICD ranges: %d\n",
|
|
|
|
arizona->pdata.num_micd_ranges);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (info->num_micd_ranges > 1) {
|
|
|
|
for (i = 1; i < info->num_micd_ranges; i++) {
|
|
|
|
if (info->micd_ranges[i - 1].max >
|
|
|
|
info->micd_ranges[i].max) {
|
|
|
|
dev_err(arizona->dev,
|
|
|
|
"MICD ranges must be sorted\n");
|
|
|
|
ret = -EINVAL;
|
2015-06-20 00:23:31 +08:00
|
|
|
goto err_gpio;
|
2013-04-02 05:03:06 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Disable all buttons by default */
|
|
|
|
regmap_update_bits(arizona->regmap, ARIZONA_MIC_DETECT_2,
|
|
|
|
ARIZONA_MICD_LVL_SEL_MASK, 0x81);
|
|
|
|
|
|
|
|
/* Set up all the buttons the user specified */
|
|
|
|
for (i = 0; i < info->num_micd_ranges; i++) {
|
2015-09-16 17:42:16 +08:00
|
|
|
for (j = 0; j < ARIZONA_NUM_MICD_BUTTON_LEVELS; j++)
|
2013-04-02 05:03:06 +08:00
|
|
|
if (arizona_micd_levels[j] >= info->micd_ranges[i].max)
|
|
|
|
break;
|
|
|
|
|
2015-09-16 17:42:16 +08:00
|
|
|
if (j == ARIZONA_NUM_MICD_BUTTON_LEVELS) {
|
2013-04-02 05:03:06 +08:00
|
|
|
dev_err(arizona->dev, "Unsupported MICD level %d\n",
|
|
|
|
info->micd_ranges[i].max);
|
|
|
|
ret = -EINVAL;
|
2015-06-20 00:23:31 +08:00
|
|
|
goto err_gpio;
|
2013-04-02 05:03:06 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
dev_dbg(arizona->dev, "%d ohms for MICD threshold %d\n",
|
|
|
|
arizona_micd_levels[j], i);
|
|
|
|
|
|
|
|
arizona_micd_set_level(arizona, i, j);
|
|
|
|
input_set_capability(info->input, EV_KEY,
|
|
|
|
info->micd_ranges[i].key);
|
|
|
|
|
|
|
|
/* Enable reporting of that range */
|
|
|
|
regmap_update_bits(arizona->regmap, ARIZONA_MIC_DETECT_2,
|
|
|
|
1 << i, 1 << i);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set all the remaining keys to a maximum */
|
|
|
|
for (; i < ARIZONA_MAX_MICD_RANGE; i++)
|
|
|
|
arizona_micd_set_level(arizona, i, 0x3f);
|
|
|
|
|
2013-01-11 07:55:36 +08:00
|
|
|
/*
|
2013-01-11 07:55:39 +08:00
|
|
|
* If we have a clamp use it, activating in conjunction with
|
|
|
|
* GPIO5 if that is connected for jack detect operation.
|
2013-01-11 07:55:36 +08:00
|
|
|
*/
|
|
|
|
if (info->micd_clamp) {
|
2013-01-11 07:55:39 +08:00
|
|
|
if (arizona->pdata.jd_gpio5) {
|
2013-04-02 02:03:52 +08:00
|
|
|
/* Put the GPIO into input mode with optional pull */
|
|
|
|
val = 0xc101;
|
|
|
|
if (arizona->pdata.jd_gpio5_nopull)
|
|
|
|
val &= ~ARIZONA_GPN_PU;
|
|
|
|
|
2013-01-11 07:55:39 +08:00
|
|
|
regmap_write(arizona->regmap, ARIZONA_GPIO5_CTRL,
|
2013-04-02 02:03:52 +08:00
|
|
|
val);
|
2013-01-11 07:55:39 +08:00
|
|
|
|
2014-05-23 19:54:57 +08:00
|
|
|
if (arizona->pdata.jd_invert)
|
|
|
|
clamp_mode = ARIZONA_MICD_CLAMP_MODE_JDH_GP5H;
|
|
|
|
else
|
|
|
|
clamp_mode = ARIZONA_MICD_CLAMP_MODE_JDL_GP5H;
|
2013-01-11 07:55:39 +08:00
|
|
|
} else {
|
2014-05-23 19:54:57 +08:00
|
|
|
if (arizona->pdata.jd_invert)
|
|
|
|
clamp_mode = ARIZONA_MICD_CLAMP_MODE_JDH;
|
|
|
|
else
|
|
|
|
clamp_mode = ARIZONA_MICD_CLAMP_MODE_JDL;
|
2013-01-11 07:55:39 +08:00
|
|
|
}
|
|
|
|
|
2014-05-23 19:54:57 +08:00
|
|
|
regmap_update_bits(arizona->regmap,
|
|
|
|
ARIZONA_MICD_CLAMP_CONTROL,
|
|
|
|
ARIZONA_MICD_CLAMP_MODE_MASK, clamp_mode);
|
|
|
|
|
2013-01-11 07:55:36 +08:00
|
|
|
regmap_update_bits(arizona->regmap,
|
|
|
|
ARIZONA_JACK_DETECT_DEBOUNCE,
|
|
|
|
ARIZONA_MICD_CLAMP_DB,
|
|
|
|
ARIZONA_MICD_CLAMP_DB);
|
|
|
|
}
|
|
|
|
|
2012-06-24 19:09:45 +08:00
|
|
|
arizona_extcon_set_mode(info, 0);
|
|
|
|
|
|
|
|
pm_runtime_enable(&pdev->dev);
|
|
|
|
pm_runtime_idle(&pdev->dev);
|
|
|
|
pm_runtime_get_sync(&pdev->dev);
|
|
|
|
|
2015-09-16 17:42:20 +08:00
|
|
|
if (info->micd_clamp) {
|
2013-01-11 07:55:39 +08:00
|
|
|
jack_irq_rise = ARIZONA_IRQ_MICD_CLAMP_RISE;
|
|
|
|
jack_irq_fall = ARIZONA_IRQ_MICD_CLAMP_FALL;
|
|
|
|
} else {
|
|
|
|
jack_irq_rise = ARIZONA_IRQ_JD_RISE;
|
|
|
|
jack_irq_fall = ARIZONA_IRQ_JD_FALL;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = arizona_request_irq(arizona, jack_irq_rise,
|
2012-06-24 19:09:45 +08:00
|
|
|
"JACKDET rise", arizona_jackdet, info);
|
|
|
|
if (ret != 0) {
|
|
|
|
dev_err(&pdev->dev, "Failed to get JACKDET rise IRQ: %d\n",
|
|
|
|
ret);
|
2015-06-20 00:23:31 +08:00
|
|
|
goto err_gpio;
|
2012-06-24 19:09:45 +08:00
|
|
|
}
|
|
|
|
|
2013-01-11 07:55:39 +08:00
|
|
|
ret = arizona_set_irq_wake(arizona, jack_irq_rise, 1);
|
2012-06-24 19:09:45 +08:00
|
|
|
if (ret != 0) {
|
|
|
|
dev_err(&pdev->dev, "Failed to set JD rise IRQ wake: %d\n",
|
|
|
|
ret);
|
|
|
|
goto err_rise;
|
|
|
|
}
|
|
|
|
|
2013-01-11 07:55:39 +08:00
|
|
|
ret = arizona_request_irq(arizona, jack_irq_fall,
|
2012-06-24 19:09:45 +08:00
|
|
|
"JACKDET fall", arizona_jackdet, info);
|
|
|
|
if (ret != 0) {
|
|
|
|
dev_err(&pdev->dev, "Failed to get JD fall IRQ: %d\n", ret);
|
|
|
|
goto err_rise_wake;
|
|
|
|
}
|
|
|
|
|
2013-01-11 07:55:39 +08:00
|
|
|
ret = arizona_set_irq_wake(arizona, jack_irq_fall, 1);
|
2012-06-24 19:09:45 +08:00
|
|
|
if (ret != 0) {
|
|
|
|
dev_err(&pdev->dev, "Failed to set JD fall IRQ wake: %d\n",
|
|
|
|
ret);
|
|
|
|
goto err_fall;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = arizona_request_irq(arizona, ARIZONA_IRQ_MICDET,
|
|
|
|
"MICDET", arizona_micdet, info);
|
|
|
|
if (ret != 0) {
|
|
|
|
dev_err(&pdev->dev, "Failed to get MICDET IRQ: %d\n", ret);
|
|
|
|
goto err_fall_wake;
|
|
|
|
}
|
|
|
|
|
2013-01-11 07:55:43 +08:00
|
|
|
ret = arizona_request_irq(arizona, ARIZONA_IRQ_HPDET,
|
|
|
|
"HPDET", arizona_hpdet_irq, info);
|
|
|
|
if (ret != 0) {
|
|
|
|
dev_err(&pdev->dev, "Failed to get HPDET IRQ: %d\n", ret);
|
|
|
|
goto err_micdet;
|
|
|
|
}
|
|
|
|
|
2012-06-24 19:09:45 +08:00
|
|
|
arizona_clk32k_enable(arizona);
|
|
|
|
regmap_update_bits(arizona->regmap, ARIZONA_JACK_DETECT_DEBOUNCE,
|
|
|
|
ARIZONA_JD1_DB, ARIZONA_JD1_DB);
|
|
|
|
regmap_update_bits(arizona->regmap, ARIZONA_JACK_DETECT_ANALOGUE,
|
|
|
|
ARIZONA_JD1_ENA, ARIZONA_JD1_ENA);
|
|
|
|
|
2012-09-07 17:01:15 +08:00
|
|
|
ret = regulator_allow_bypass(info->micvdd, true);
|
|
|
|
if (ret != 0)
|
|
|
|
dev_warn(arizona->dev, "Failed to set MICVDD to bypass: %d\n",
|
|
|
|
ret);
|
|
|
|
|
2012-06-24 19:09:45 +08:00
|
|
|
pm_runtime_put(&pdev->dev);
|
|
|
|
|
2012-07-21 00:07:29 +08:00
|
|
|
ret = input_register_device(info->input);
|
|
|
|
if (ret) {
|
|
|
|
dev_err(&pdev->dev, "Can't register input device: %d\n", ret);
|
2013-01-11 07:55:43 +08:00
|
|
|
goto err_hpdet;
|
2012-07-21 00:07:29 +08:00
|
|
|
}
|
|
|
|
|
2012-06-24 19:09:45 +08:00
|
|
|
return 0;
|
|
|
|
|
2013-01-11 07:55:43 +08:00
|
|
|
err_hpdet:
|
|
|
|
arizona_free_irq(arizona, ARIZONA_IRQ_HPDET, info);
|
2012-08-27 04:58:20 +08:00
|
|
|
err_micdet:
|
|
|
|
arizona_free_irq(arizona, ARIZONA_IRQ_MICDET, info);
|
2012-06-24 19:09:45 +08:00
|
|
|
err_fall_wake:
|
2013-01-11 07:55:39 +08:00
|
|
|
arizona_set_irq_wake(arizona, jack_irq_fall, 0);
|
2012-06-24 19:09:45 +08:00
|
|
|
err_fall:
|
2013-01-11 07:55:39 +08:00
|
|
|
arizona_free_irq(arizona, jack_irq_fall, info);
|
2012-06-24 19:09:45 +08:00
|
|
|
err_rise_wake:
|
2013-01-11 07:55:39 +08:00
|
|
|
arizona_set_irq_wake(arizona, jack_irq_rise, 0);
|
2012-06-24 19:09:45 +08:00
|
|
|
err_rise:
|
2013-01-11 07:55:39 +08:00
|
|
|
arizona_free_irq(arizona, jack_irq_rise, info);
|
2015-06-20 00:23:31 +08:00
|
|
|
err_gpio:
|
|
|
|
gpiod_put(info->micd_pol_gpio);
|
2012-06-24 19:09:45 +08:00
|
|
|
err_register:
|
|
|
|
pm_runtime_disable(&pdev->dev);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-11-20 02:25:49 +08:00
|
|
|
static int arizona_extcon_remove(struct platform_device *pdev)
|
2012-06-24 19:09:45 +08:00
|
|
|
{
|
|
|
|
struct arizona_extcon_info *info = platform_get_drvdata(pdev);
|
|
|
|
struct arizona *arizona = info->arizona;
|
2013-01-11 07:55:39 +08:00
|
|
|
int jack_irq_rise, jack_irq_fall;
|
2012-06-24 19:09:45 +08:00
|
|
|
|
2015-06-20 00:23:31 +08:00
|
|
|
gpiod_put(info->micd_pol_gpio);
|
|
|
|
|
2012-06-24 19:09:45 +08:00
|
|
|
pm_runtime_disable(&pdev->dev);
|
|
|
|
|
2013-01-11 07:55:36 +08:00
|
|
|
regmap_update_bits(arizona->regmap,
|
|
|
|
ARIZONA_MICD_CLAMP_CONTROL,
|
|
|
|
ARIZONA_MICD_CLAMP_MODE_MASK, 0);
|
|
|
|
|
2015-09-16 17:42:20 +08:00
|
|
|
if (info->micd_clamp) {
|
2013-01-11 07:55:39 +08:00
|
|
|
jack_irq_rise = ARIZONA_IRQ_MICD_CLAMP_RISE;
|
|
|
|
jack_irq_fall = ARIZONA_IRQ_MICD_CLAMP_FALL;
|
|
|
|
} else {
|
|
|
|
jack_irq_rise = ARIZONA_IRQ_JD_RISE;
|
|
|
|
jack_irq_fall = ARIZONA_IRQ_JD_FALL;
|
|
|
|
}
|
|
|
|
|
|
|
|
arizona_set_irq_wake(arizona, jack_irq_rise, 0);
|
|
|
|
arizona_set_irq_wake(arizona, jack_irq_fall, 0);
|
|
|
|
arizona_free_irq(arizona, ARIZONA_IRQ_HPDET, info);
|
2012-06-24 19:09:45 +08:00
|
|
|
arizona_free_irq(arizona, ARIZONA_IRQ_MICDET, info);
|
2013-01-11 07:55:39 +08:00
|
|
|
arizona_free_irq(arizona, jack_irq_rise, info);
|
|
|
|
arizona_free_irq(arizona, jack_irq_fall, info);
|
2013-02-06 05:00:15 +08:00
|
|
|
cancel_delayed_work_sync(&info->hpdet_work);
|
2012-06-24 19:09:45 +08:00
|
|
|
regmap_update_bits(arizona->regmap, ARIZONA_JACK_DETECT_ANALOGUE,
|
|
|
|
ARIZONA_JD1_ENA, 0);
|
|
|
|
arizona_clk32k_disable(arizona);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct platform_driver arizona_extcon_driver = {
|
|
|
|
.driver = {
|
|
|
|
.name = "arizona-extcon",
|
|
|
|
},
|
|
|
|
.probe = arizona_extcon_probe,
|
2012-11-20 02:20:06 +08:00
|
|
|
.remove = arizona_extcon_remove,
|
2012-06-24 19:09:45 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
module_platform_driver(arizona_extcon_driver);
|
|
|
|
|
|
|
|
MODULE_DESCRIPTION("Arizona Extcon driver");
|
|
|
|
MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>");
|
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
MODULE_ALIAS("platform:extcon-arizona");
|