2019-05-27 06:55:06 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2013-05-28 01:50:11 +00:00
|
|
|
/*
|
|
|
|
* Palmas USB transceiver driver
|
|
|
|
*
|
2020-07-13 13:19:53 +00:00
|
|
|
* Copyright (C) 2013 Texas Instruments Incorporated - https://www.ti.com
|
2013-05-28 01:50:11 +00:00
|
|
|
* Author: Graeme Gregory <gg@slimlogic.co.uk>
|
|
|
|
* Author: Kishon Vijay Abraham I <kishon@ti.com>
|
|
|
|
* Based on twl6030_usb.c
|
|
|
|
* Author: Hema HK <hemahk@ti.com>
|
|
|
|
*/
|
|
|
|
|
2021-03-23 13:57:08 +00:00
|
|
|
#include <linux/devm-helpers.h>
|
2013-05-28 01:50:11 +00:00
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/interrupt.h>
|
|
|
|
#include <linux/platform_device.h>
|
2014-03-28 06:51:02 +00:00
|
|
|
#include <linux/slab.h>
|
2013-05-28 01:50:11 +00:00
|
|
|
#include <linux/err.h>
|
|
|
|
#include <linux/mfd/palmas.h>
|
|
|
|
#include <linux/of.h>
|
|
|
|
#include <linux/of_platform.h>
|
2015-08-13 00:19:43 +00:00
|
|
|
#include <linux/gpio/consumer.h>
|
2015-08-03 14:40:51 +00:00
|
|
|
#include <linux/workqueue.h>
|
|
|
|
|
|
|
|
#define USB_GPIO_DEBOUNCE_MS 20 /* ms */
|
2013-05-28 01:50:11 +00:00
|
|
|
|
2015-06-12 02:10:06 +00:00
|
|
|
static const unsigned int palmas_extcon_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 10:16:05 +00:00
|
|
|
EXTCON_USB,
|
|
|
|
EXTCON_USB_HOST,
|
|
|
|
EXTCON_NONE,
|
2013-05-28 01:50:11 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static void palmas_usb_wakeup(struct palmas *palmas, int enable)
|
|
|
|
{
|
|
|
|
if (enable)
|
|
|
|
palmas_write(palmas, PALMAS_USB_OTG_BASE, PALMAS_USB_WAKEUP,
|
|
|
|
PALMAS_USB_WAKEUP_ID_WK_UP_COMP);
|
|
|
|
else
|
|
|
|
palmas_write(palmas, PALMAS_USB_OTG_BASE, PALMAS_USB_WAKEUP, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static irqreturn_t palmas_vbus_irq_handler(int irq, void *_palmas_usb)
|
|
|
|
{
|
|
|
|
struct palmas_usb *palmas_usb = _palmas_usb;
|
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 10:16:05 +00:00
|
|
|
struct extcon_dev *edev = palmas_usb->edev;
|
2013-05-28 01:50:11 +00:00
|
|
|
unsigned int vbus_line_state;
|
|
|
|
|
|
|
|
palmas_read(palmas_usb->palmas, PALMAS_INTERRUPT_BASE,
|
|
|
|
PALMAS_INT3_LINE_STATE, &vbus_line_state);
|
|
|
|
|
|
|
|
if (vbus_line_state & PALMAS_INT3_LINE_STATE_VBUS) {
|
|
|
|
if (palmas_usb->linkstat != PALMAS_USB_STATE_VBUS) {
|
|
|
|
palmas_usb->linkstat = PALMAS_USB_STATE_VBUS;
|
2016-08-16 06:55:34 +00:00
|
|
|
extcon_set_state_sync(edev, EXTCON_USB, true);
|
2017-01-24 14:54:07 +00:00
|
|
|
dev_dbg(palmas_usb->dev, "USB cable is attached\n");
|
2013-05-28 01:50:11 +00:00
|
|
|
} else {
|
|
|
|
dev_dbg(palmas_usb->dev,
|
|
|
|
"Spurious connect event detected\n");
|
|
|
|
}
|
|
|
|
} else if (!(vbus_line_state & PALMAS_INT3_LINE_STATE_VBUS)) {
|
|
|
|
if (palmas_usb->linkstat == PALMAS_USB_STATE_VBUS) {
|
|
|
|
palmas_usb->linkstat = PALMAS_USB_STATE_DISCONNECT;
|
2016-08-16 06:55:34 +00:00
|
|
|
extcon_set_state_sync(edev, EXTCON_USB, false);
|
2017-01-24 14:54:07 +00:00
|
|
|
dev_dbg(palmas_usb->dev, "USB cable is detached\n");
|
2013-05-28 01:50:11 +00:00
|
|
|
} else {
|
|
|
|
dev_dbg(palmas_usb->dev,
|
|
|
|
"Spurious disconnect event detected\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
|
|
|
|
static irqreturn_t palmas_id_irq_handler(int irq, void *_palmas_usb)
|
|
|
|
{
|
2013-10-10 18:48:39 +00:00
|
|
|
unsigned int set, id_src;
|
2013-05-28 01:50:11 +00:00
|
|
|
struct palmas_usb *palmas_usb = _palmas_usb;
|
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 10:16:05 +00:00
|
|
|
struct extcon_dev *edev = palmas_usb->edev;
|
2013-05-28 01:50:11 +00:00
|
|
|
|
|
|
|
palmas_read(palmas_usb->palmas, PALMAS_USB_OTG_BASE,
|
|
|
|
PALMAS_USB_ID_INT_LATCH_SET, &set);
|
2013-10-10 18:48:39 +00:00
|
|
|
palmas_read(palmas_usb->palmas, PALMAS_USB_OTG_BASE,
|
|
|
|
PALMAS_USB_ID_INT_SRC, &id_src);
|
2013-05-28 01:50:11 +00:00
|
|
|
|
2013-10-10 18:48:39 +00:00
|
|
|
if ((set & PALMAS_USB_ID_INT_SRC_ID_GND) &&
|
|
|
|
(id_src & PALMAS_USB_ID_INT_SRC_ID_GND)) {
|
2013-05-28 01:50:11 +00:00
|
|
|
palmas_write(palmas_usb->palmas, PALMAS_USB_OTG_BASE,
|
|
|
|
PALMAS_USB_ID_INT_LATCH_CLR,
|
|
|
|
PALMAS_USB_ID_INT_EN_HI_CLR_ID_GND);
|
|
|
|
palmas_usb->linkstat = PALMAS_USB_STATE_ID;
|
2016-08-16 06:55:34 +00:00
|
|
|
extcon_set_state_sync(edev, EXTCON_USB_HOST, true);
|
2017-01-24 14:54:07 +00:00
|
|
|
dev_dbg(palmas_usb->dev, "USB-HOST cable is attached\n");
|
2013-10-10 18:48:39 +00:00
|
|
|
} else if ((set & PALMAS_USB_ID_INT_SRC_ID_FLOAT) &&
|
|
|
|
(id_src & PALMAS_USB_ID_INT_SRC_ID_FLOAT)) {
|
2013-05-28 01:50:11 +00:00
|
|
|
palmas_write(palmas_usb->palmas, PALMAS_USB_OTG_BASE,
|
|
|
|
PALMAS_USB_ID_INT_LATCH_CLR,
|
|
|
|
PALMAS_USB_ID_INT_EN_HI_CLR_ID_FLOAT);
|
|
|
|
palmas_usb->linkstat = PALMAS_USB_STATE_DISCONNECT;
|
2016-08-16 06:55:34 +00:00
|
|
|
extcon_set_state_sync(edev, EXTCON_USB_HOST, false);
|
2017-01-24 14:54:07 +00:00
|
|
|
dev_dbg(palmas_usb->dev, "USB-HOST cable is detached\n");
|
2013-07-09 13:04:22 +00:00
|
|
|
} else if ((palmas_usb->linkstat == PALMAS_USB_STATE_ID) &&
|
|
|
|
(!(set & PALMAS_USB_ID_INT_SRC_ID_GND))) {
|
|
|
|
palmas_usb->linkstat = PALMAS_USB_STATE_DISCONNECT;
|
2016-08-16 06:55:34 +00:00
|
|
|
extcon_set_state_sync(edev, EXTCON_USB_HOST, false);
|
2017-01-24 14:54:07 +00:00
|
|
|
dev_dbg(palmas_usb->dev, "USB-HOST cable is detached\n");
|
2013-10-10 18:48:39 +00:00
|
|
|
} else if ((palmas_usb->linkstat == PALMAS_USB_STATE_DISCONNECT) &&
|
|
|
|
(id_src & PALMAS_USB_ID_INT_SRC_ID_GND)) {
|
|
|
|
palmas_usb->linkstat = PALMAS_USB_STATE_ID;
|
2016-08-16 06:55:34 +00:00
|
|
|
extcon_set_state_sync(edev, EXTCON_USB_HOST, true);
|
2022-06-19 08:42:48 +00:00
|
|
|
dev_dbg(palmas_usb->dev, "USB-HOST cable is attached\n");
|
2013-05-28 01:50:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
|
2015-08-03 14:40:51 +00:00
|
|
|
static void palmas_gpio_id_detect(struct work_struct *work)
|
|
|
|
{
|
|
|
|
int id;
|
|
|
|
struct palmas_usb *palmas_usb = container_of(to_delayed_work(work),
|
|
|
|
struct palmas_usb,
|
|
|
|
wq_detectid);
|
|
|
|
struct extcon_dev *edev = palmas_usb->edev;
|
|
|
|
|
|
|
|
if (!palmas_usb->id_gpiod)
|
|
|
|
return;
|
|
|
|
|
|
|
|
id = gpiod_get_value_cansleep(palmas_usb->id_gpiod);
|
|
|
|
|
|
|
|
if (id) {
|
2016-08-16 06:55:34 +00:00
|
|
|
extcon_set_state_sync(edev, EXTCON_USB_HOST, false);
|
2017-01-24 14:54:07 +00:00
|
|
|
dev_dbg(palmas_usb->dev, "USB-HOST cable is detached\n");
|
2015-08-03 14:40:51 +00:00
|
|
|
} else {
|
2016-08-16 06:55:34 +00:00
|
|
|
extcon_set_state_sync(edev, EXTCON_USB_HOST, true);
|
2017-01-24 14:54:07 +00:00
|
|
|
dev_dbg(palmas_usb->dev, "USB-HOST cable is attached\n");
|
2015-08-03 14:40:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static irqreturn_t palmas_gpio_id_irq_handler(int irq, void *_palmas_usb)
|
|
|
|
{
|
|
|
|
struct palmas_usb *palmas_usb = _palmas_usb;
|
|
|
|
|
|
|
|
queue_delayed_work(system_power_efficient_wq, &palmas_usb->wq_detectid,
|
|
|
|
palmas_usb->sw_debounce_jiffies);
|
|
|
|
|
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
|
2013-05-28 01:50:11 +00:00
|
|
|
static void palmas_enable_irq(struct palmas_usb *palmas_usb)
|
|
|
|
{
|
|
|
|
palmas_write(palmas_usb->palmas, PALMAS_USB_OTG_BASE,
|
|
|
|
PALMAS_USB_VBUS_CTRL_SET,
|
|
|
|
PALMAS_USB_VBUS_CTRL_SET_VBUS_ACT_COMP);
|
|
|
|
|
2015-08-03 14:40:51 +00:00
|
|
|
if (palmas_usb->enable_id_detection) {
|
|
|
|
palmas_write(palmas_usb->palmas, PALMAS_USB_OTG_BASE,
|
|
|
|
PALMAS_USB_ID_CTRL_SET,
|
|
|
|
PALMAS_USB_ID_CTRL_SET_ID_ACT_COMP);
|
2013-05-28 01:50:11 +00:00
|
|
|
|
2015-08-03 14:40:51 +00:00
|
|
|
palmas_write(palmas_usb->palmas, PALMAS_USB_OTG_BASE,
|
|
|
|
PALMAS_USB_ID_INT_EN_HI_SET,
|
|
|
|
PALMAS_USB_ID_INT_EN_HI_SET_ID_GND |
|
|
|
|
PALMAS_USB_ID_INT_EN_HI_SET_ID_FLOAT);
|
|
|
|
}
|
2013-05-28 01:50:11 +00:00
|
|
|
|
2013-07-10 09:29:06 +00:00
|
|
|
if (palmas_usb->enable_vbus_detection)
|
|
|
|
palmas_vbus_irq_handler(palmas_usb->vbus_irq, palmas_usb);
|
2013-05-28 01:50:11 +00:00
|
|
|
|
|
|
|
/* cold plug for host mode needs this delay */
|
2013-07-10 09:29:06 +00:00
|
|
|
if (palmas_usb->enable_id_detection) {
|
|
|
|
msleep(30);
|
|
|
|
palmas_id_irq_handler(palmas_usb->id_irq, palmas_usb);
|
|
|
|
}
|
2013-05-28 01:50:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int palmas_usb_probe(struct platform_device *pdev)
|
|
|
|
{
|
|
|
|
struct palmas *palmas = dev_get_drvdata(pdev->dev.parent);
|
2013-09-11 04:22:18 +00:00
|
|
|
struct palmas_usb_platform_data *pdata = dev_get_platdata(&pdev->dev);
|
2013-05-28 01:50:11 +00:00
|
|
|
struct device_node *node = pdev->dev.of_node;
|
|
|
|
struct palmas_usb *palmas_usb;
|
|
|
|
int status;
|
|
|
|
|
2016-12-08 08:45:31 +00:00
|
|
|
if (!palmas) {
|
|
|
|
dev_err(&pdev->dev, "failed to get valid parent\n");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2013-05-28 01:50:11 +00:00
|
|
|
palmas_usb = devm_kzalloc(&pdev->dev, sizeof(*palmas_usb), GFP_KERNEL);
|
|
|
|
if (!palmas_usb)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
2013-07-10 09:29:06 +00:00
|
|
|
if (node && !pdata) {
|
|
|
|
palmas_usb->wakeup = of_property_read_bool(node, "ti,wakeup");
|
|
|
|
palmas_usb->enable_id_detection = of_property_read_bool(node,
|
|
|
|
"ti,enable-id-detection");
|
|
|
|
palmas_usb->enable_vbus_detection = of_property_read_bool(node,
|
|
|
|
"ti,enable-vbus-detection");
|
|
|
|
} else {
|
|
|
|
palmas_usb->wakeup = true;
|
|
|
|
palmas_usb->enable_id_detection = true;
|
|
|
|
palmas_usb->enable_vbus_detection = true;
|
|
|
|
|
|
|
|
if (pdata)
|
|
|
|
palmas_usb->wakeup = pdata->wakeup;
|
|
|
|
}
|
|
|
|
|
2015-08-13 00:19:43 +00:00
|
|
|
palmas_usb->id_gpiod = devm_gpiod_get_optional(&pdev->dev, "id",
|
|
|
|
GPIOD_IN);
|
2020-08-28 15:13:37 +00:00
|
|
|
if (IS_ERR(palmas_usb->id_gpiod))
|
|
|
|
return dev_err_probe(&pdev->dev, PTR_ERR(palmas_usb->id_gpiod),
|
|
|
|
"failed to get id gpio\n");
|
2015-08-03 14:40:51 +00:00
|
|
|
|
2015-12-30 00:55:45 +00:00
|
|
|
palmas_usb->vbus_gpiod = devm_gpiod_get_optional(&pdev->dev, "vbus",
|
|
|
|
GPIOD_IN);
|
2020-08-28 15:13:37 +00:00
|
|
|
if (IS_ERR(palmas_usb->vbus_gpiod))
|
|
|
|
return dev_err_probe(&pdev->dev, PTR_ERR(palmas_usb->vbus_gpiod),
|
|
|
|
"failed to get id gpio\n");
|
2015-12-30 00:55:45 +00:00
|
|
|
|
2015-08-03 14:40:51 +00:00
|
|
|
if (palmas_usb->enable_id_detection && palmas_usb->id_gpiod) {
|
|
|
|
palmas_usb->enable_id_detection = false;
|
|
|
|
palmas_usb->enable_gpio_id_detection = true;
|
|
|
|
}
|
|
|
|
|
2015-12-30 00:55:45 +00:00
|
|
|
if (palmas_usb->enable_vbus_detection && palmas_usb->vbus_gpiod) {
|
|
|
|
palmas_usb->enable_vbus_detection = false;
|
|
|
|
palmas_usb->enable_gpio_vbus_detection = true;
|
|
|
|
}
|
|
|
|
|
2015-08-03 14:40:51 +00:00
|
|
|
if (palmas_usb->enable_gpio_id_detection) {
|
|
|
|
u32 debounce;
|
|
|
|
|
|
|
|
if (of_property_read_u32(node, "debounce-delay-ms", &debounce))
|
|
|
|
debounce = USB_GPIO_DEBOUNCE_MS;
|
|
|
|
|
|
|
|
status = gpiod_set_debounce(palmas_usb->id_gpiod,
|
|
|
|
debounce * 1000);
|
|
|
|
if (status < 0)
|
|
|
|
palmas_usb->sw_debounce_jiffies = msecs_to_jiffies(debounce);
|
|
|
|
}
|
|
|
|
|
2021-03-23 13:57:08 +00:00
|
|
|
status = devm_delayed_work_autocancel(&pdev->dev,
|
|
|
|
&palmas_usb->wq_detectid,
|
|
|
|
palmas_gpio_id_detect);
|
|
|
|
if (status)
|
|
|
|
return status;
|
2015-08-03 14:40:51 +00:00
|
|
|
|
2013-05-28 01:50:11 +00:00
|
|
|
palmas->usb = palmas_usb;
|
|
|
|
palmas_usb->palmas = palmas;
|
|
|
|
|
|
|
|
palmas_usb->dev = &pdev->dev;
|
|
|
|
|
2013-07-10 09:29:06 +00:00
|
|
|
palmas_usb_wakeup(palmas, palmas_usb->wakeup);
|
2013-05-28 01:50:11 +00:00
|
|
|
|
|
|
|
platform_set_drvdata(pdev, palmas_usb);
|
|
|
|
|
2014-04-21 11:44:53 +00:00
|
|
|
palmas_usb->edev = devm_extcon_dev_allocate(&pdev->dev,
|
|
|
|
palmas_extcon_cable);
|
|
|
|
if (IS_ERR(palmas_usb->edev)) {
|
|
|
|
dev_err(&pdev->dev, "failed to allocate extcon device\n");
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
2013-05-28 01:50:11 +00:00
|
|
|
|
2014-04-21 11:44:53 +00:00
|
|
|
status = devm_extcon_dev_register(&pdev->dev, palmas_usb->edev);
|
2013-05-28 01:50:11 +00:00
|
|
|
if (status) {
|
|
|
|
dev_err(&pdev->dev, "failed to register extcon device\n");
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2013-07-10 09:29:06 +00:00
|
|
|
if (palmas_usb->enable_id_detection) {
|
2015-08-03 14:40:51 +00:00
|
|
|
palmas_usb->id_otg_irq = regmap_irq_get_virq(palmas->irq_data,
|
|
|
|
PALMAS_ID_OTG_IRQ);
|
|
|
|
palmas_usb->id_irq = regmap_irq_get_virq(palmas->irq_data,
|
|
|
|
PALMAS_ID_IRQ);
|
2013-07-10 09:29:06 +00:00
|
|
|
status = devm_request_threaded_irq(palmas_usb->dev,
|
|
|
|
palmas_usb->id_irq,
|
|
|
|
NULL, palmas_id_irq_handler,
|
|
|
|
IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING |
|
2016-02-26 15:42:51 +00:00
|
|
|
IRQF_ONESHOT,
|
2013-07-10 09:29:06 +00:00
|
|
|
"palmas_usb_id", palmas_usb);
|
|
|
|
if (status < 0) {
|
|
|
|
dev_err(&pdev->dev, "can't get IRQ %d, err %d\n",
|
2013-05-28 01:50:11 +00:00
|
|
|
palmas_usb->id_irq, status);
|
2014-04-21 10:10:14 +00:00
|
|
|
return status;
|
2013-07-10 09:29:06 +00:00
|
|
|
}
|
2015-08-03 14:40:51 +00:00
|
|
|
} else if (palmas_usb->enable_gpio_id_detection) {
|
|
|
|
palmas_usb->gpio_id_irq = gpiod_to_irq(palmas_usb->id_gpiod);
|
|
|
|
if (palmas_usb->gpio_id_irq < 0) {
|
|
|
|
dev_err(&pdev->dev, "failed to get id irq\n");
|
|
|
|
return palmas_usb->gpio_id_irq;
|
|
|
|
}
|
|
|
|
status = devm_request_threaded_irq(&pdev->dev,
|
|
|
|
palmas_usb->gpio_id_irq,
|
|
|
|
NULL,
|
|
|
|
palmas_gpio_id_irq_handler,
|
|
|
|
IRQF_TRIGGER_RISING |
|
|
|
|
IRQF_TRIGGER_FALLING |
|
|
|
|
IRQF_ONESHOT,
|
|
|
|
"palmas_usb_id",
|
|
|
|
palmas_usb);
|
|
|
|
if (status < 0) {
|
|
|
|
dev_err(&pdev->dev,
|
|
|
|
"failed to request handler for id irq\n");
|
|
|
|
return status;
|
|
|
|
}
|
2013-05-28 01:50:11 +00:00
|
|
|
}
|
|
|
|
|
2013-07-10 09:29:06 +00:00
|
|
|
if (palmas_usb->enable_vbus_detection) {
|
2015-08-03 14:40:51 +00:00
|
|
|
palmas_usb->vbus_otg_irq = regmap_irq_get_virq(palmas->irq_data,
|
|
|
|
PALMAS_VBUS_OTG_IRQ);
|
|
|
|
palmas_usb->vbus_irq = regmap_irq_get_virq(palmas->irq_data,
|
|
|
|
PALMAS_VBUS_IRQ);
|
2013-07-10 09:29:06 +00:00
|
|
|
status = devm_request_threaded_irq(palmas_usb->dev,
|
|
|
|
palmas_usb->vbus_irq, NULL,
|
|
|
|
palmas_vbus_irq_handler,
|
|
|
|
IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING |
|
2016-02-26 15:42:51 +00:00
|
|
|
IRQF_ONESHOT,
|
2013-07-10 09:29:06 +00:00
|
|
|
"palmas_usb_vbus", palmas_usb);
|
|
|
|
if (status < 0) {
|
|
|
|
dev_err(&pdev->dev, "can't get IRQ %d, err %d\n",
|
2013-05-28 01:50:11 +00:00
|
|
|
palmas_usb->vbus_irq, status);
|
2014-04-21 10:10:14 +00:00
|
|
|
return status;
|
2013-07-10 09:29:06 +00:00
|
|
|
}
|
2015-12-30 00:55:45 +00:00
|
|
|
} else if (palmas_usb->enable_gpio_vbus_detection) {
|
|
|
|
/* remux GPIO_1 as VBUSDET */
|
|
|
|
status = palmas_update_bits(palmas,
|
|
|
|
PALMAS_PU_PD_OD_BASE,
|
|
|
|
PALMAS_PRIMARY_SECONDARY_PAD1,
|
|
|
|
PALMAS_PRIMARY_SECONDARY_PAD1_GPIO_1_MASK,
|
|
|
|
(1 << PALMAS_PRIMARY_SECONDARY_PAD1_GPIO_1_SHIFT));
|
|
|
|
if (status < 0) {
|
|
|
|
dev_err(&pdev->dev, "can't remux GPIO1\n");
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
palmas_usb->vbus_otg_irq = regmap_irq_get_virq(palmas->irq_data,
|
|
|
|
PALMAS_VBUS_OTG_IRQ);
|
|
|
|
palmas_usb->gpio_vbus_irq = gpiod_to_irq(palmas_usb->vbus_gpiod);
|
|
|
|
if (palmas_usb->gpio_vbus_irq < 0) {
|
|
|
|
dev_err(&pdev->dev, "failed to get vbus irq\n");
|
|
|
|
return palmas_usb->gpio_vbus_irq;
|
|
|
|
}
|
|
|
|
status = devm_request_threaded_irq(&pdev->dev,
|
|
|
|
palmas_usb->gpio_vbus_irq,
|
|
|
|
NULL,
|
|
|
|
palmas_vbus_irq_handler,
|
|
|
|
IRQF_TRIGGER_FALLING |
|
|
|
|
IRQF_TRIGGER_RISING |
|
2016-04-01 13:52:47 +00:00
|
|
|
IRQF_ONESHOT,
|
2015-12-30 00:55:45 +00:00
|
|
|
"palmas_usb_vbus",
|
|
|
|
palmas_usb);
|
|
|
|
if (status < 0) {
|
|
|
|
dev_err(&pdev->dev,
|
|
|
|
"failed to request handler for vbus irq\n");
|
|
|
|
return status;
|
|
|
|
}
|
2013-05-28 01:50:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
palmas_enable_irq(palmas_usb);
|
2015-08-03 14:40:51 +00:00
|
|
|
/* perform initial detection */
|
2016-06-15 08:12:05 +00:00
|
|
|
if (palmas_usb->enable_gpio_vbus_detection)
|
|
|
|
palmas_vbus_irq_handler(palmas_usb->gpio_vbus_irq, palmas_usb);
|
2015-08-03 14:40:51 +00:00
|
|
|
palmas_gpio_id_detect(&palmas_usb->wq_detectid.work);
|
2013-07-09 13:04:23 +00:00
|
|
|
device_set_wakeup_capable(&pdev->dev, true);
|
2013-05-28 01:50:11 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-07-09 13:04:23 +00:00
|
|
|
#ifdef CONFIG_PM_SLEEP
|
|
|
|
static int palmas_usb_suspend(struct device *dev)
|
|
|
|
{
|
|
|
|
struct palmas_usb *palmas_usb = dev_get_drvdata(dev);
|
|
|
|
|
|
|
|
if (device_may_wakeup(dev)) {
|
2013-07-10 09:29:06 +00:00
|
|
|
if (palmas_usb->enable_vbus_detection)
|
|
|
|
enable_irq_wake(palmas_usb->vbus_irq);
|
2015-12-30 00:55:45 +00:00
|
|
|
if (palmas_usb->enable_gpio_vbus_detection)
|
|
|
|
enable_irq_wake(palmas_usb->gpio_vbus_irq);
|
2013-07-10 09:29:06 +00:00
|
|
|
if (palmas_usb->enable_id_detection)
|
|
|
|
enable_irq_wake(palmas_usb->id_irq);
|
2015-08-03 14:40:51 +00:00
|
|
|
if (palmas_usb->enable_gpio_id_detection)
|
|
|
|
enable_irq_wake(palmas_usb->gpio_id_irq);
|
2013-07-09 13:04:23 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int palmas_usb_resume(struct device *dev)
|
|
|
|
{
|
|
|
|
struct palmas_usb *palmas_usb = dev_get_drvdata(dev);
|
|
|
|
|
|
|
|
if (device_may_wakeup(dev)) {
|
2013-07-10 09:29:06 +00:00
|
|
|
if (palmas_usb->enable_vbus_detection)
|
|
|
|
disable_irq_wake(palmas_usb->vbus_irq);
|
2015-12-30 00:55:45 +00:00
|
|
|
if (palmas_usb->enable_gpio_vbus_detection)
|
|
|
|
disable_irq_wake(palmas_usb->gpio_vbus_irq);
|
2013-07-10 09:29:06 +00:00
|
|
|
if (palmas_usb->enable_id_detection)
|
|
|
|
disable_irq_wake(palmas_usb->id_irq);
|
2015-08-03 14:40:51 +00:00
|
|
|
if (palmas_usb->enable_gpio_id_detection)
|
|
|
|
disable_irq_wake(palmas_usb->gpio_id_irq);
|
2013-07-09 13:04:23 +00:00
|
|
|
}
|
2017-02-15 12:31:29 +00:00
|
|
|
|
|
|
|
/* check if GPIO states changed while suspend/resume */
|
|
|
|
if (palmas_usb->enable_gpio_vbus_detection)
|
|
|
|
palmas_vbus_irq_handler(palmas_usb->gpio_vbus_irq, palmas_usb);
|
|
|
|
palmas_gpio_id_detect(&palmas_usb->wq_detectid.work);
|
|
|
|
|
2013-07-09 13:04:23 +00:00
|
|
|
return 0;
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
2014-02-27 11:36:15 +00:00
|
|
|
static SIMPLE_DEV_PM_OPS(palmas_pm_ops, palmas_usb_suspend, palmas_usb_resume);
|
2013-07-09 13:04:23 +00:00
|
|
|
|
2014-05-23 09:03:05 +00:00
|
|
|
static const struct of_device_id of_palmas_match_tbl[] = {
|
2013-05-28 01:50:11 +00:00
|
|
|
{ .compatible = "ti,palmas-usb", },
|
2013-10-10 12:37:27 +00:00
|
|
|
{ .compatible = "ti,palmas-usb-vid", },
|
2013-05-28 01:50:11 +00:00
|
|
|
{ .compatible = "ti,twl6035-usb", },
|
2013-10-10 12:37:27 +00:00
|
|
|
{ .compatible = "ti,twl6035-usb-vid", },
|
2013-05-28 01:50:11 +00:00
|
|
|
{ /* end */ }
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct platform_driver palmas_usb_driver = {
|
|
|
|
.probe = palmas_usb_probe,
|
|
|
|
.driver = {
|
|
|
|
.name = "palmas-usb",
|
|
|
|
.of_match_table = of_palmas_match_tbl,
|
2013-07-09 13:04:23 +00:00
|
|
|
.pm = &palmas_pm_ops,
|
2013-05-28 01:50:11 +00:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
module_platform_driver(palmas_usb_driver);
|
|
|
|
|
|
|
|
MODULE_ALIAS("platform:palmas-usb");
|
|
|
|
MODULE_AUTHOR("Graeme Gregory <gg@slimlogic.co.uk>");
|
|
|
|
MODULE_DESCRIPTION("Palmas USB transceiver driver");
|
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
MODULE_DEVICE_TABLE(of, of_palmas_match_tbl);
|