Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * drivers/extcon/extcon-usb-gpio.c - USB GPIO extcon driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Copyright (C) 2015 Texas Instruments Incorporated - https://www.ti.com
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  * Author: Roger Quadros <rogerq@ti.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #include <linux/extcon-provider.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <linux/gpio.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/gpio/consumer.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/interrupt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/irq.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <linux/of_gpio.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <linux/platform_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include <linux/workqueue.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #include <linux/pinctrl/consumer.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #define USB_GPIO_DEBOUNCE_MS	20	/* ms */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) struct usb_extcon_info {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 	struct device *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 	struct extcon_dev *edev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 	struct gpio_desc *id_gpiod;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 	struct gpio_desc *vbus_gpiod;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 	int id_irq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 	int vbus_irq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 	unsigned long debounce_jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 	struct delayed_work wq_detcable;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) static const unsigned int usb_extcon_cable[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	EXTCON_USB,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	EXTCON_USB_HOST,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	EXTCON_NONE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45)  * "USB" = VBUS and "USB-HOST" = !ID, so we have:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46)  * Both "USB" and "USB-HOST" can't be set as active at the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47)  * same time so if "USB-HOST" is active (i.e. ID is 0)  we keep "USB" inactive
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48)  * even if VBUS is on.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50)  *  State              |    ID   |   VBUS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51)  * ----------------------------------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52)  *  [1] USB            |    H    |    H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53)  *  [2] none           |    H    |    L
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54)  *  [3] USB-HOST       |    L    |    H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55)  *  [4] USB-HOST       |    L    |    L
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57)  * In case we have only one of these signals:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58)  * - VBUS only - we want to distinguish between [1] and [2], so ID is always 1.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59)  * - ID only - we want to distinguish between [1] and [4], so VBUS = ID.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) static void usb_extcon_detect_cable(struct work_struct *work)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	int id, vbus;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	struct usb_extcon_info *info = container_of(to_delayed_work(work),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 						    struct usb_extcon_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 						    wq_detcable);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	/* check ID and VBUS and update cable state */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	id = info->id_gpiod ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 		gpiod_get_value_cansleep(info->id_gpiod) : 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	vbus = info->vbus_gpiod ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 		gpiod_get_value_cansleep(info->vbus_gpiod) : id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	/* at first we clean states which are no longer active */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	if (id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 		extcon_set_state_sync(info->edev, EXTCON_USB_HOST, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	if (!vbus)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 		extcon_set_state_sync(info->edev, EXTCON_USB, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	if (!id) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 		extcon_set_state_sync(info->edev, EXTCON_USB_HOST, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 		if (vbus)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 			extcon_set_state_sync(info->edev, EXTCON_USB, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) static irqreturn_t usb_irq_handler(int irq, void *dev_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	struct usb_extcon_info *info = dev_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	queue_delayed_work(system_power_efficient_wq, &info->wq_detcable,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 			   info->debounce_jiffies);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	return IRQ_HANDLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) static int usb_extcon_probe(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	struct device *dev = &pdev->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	struct device_node *np = dev->of_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	struct usb_extcon_info *info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	if (!np)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	info = devm_kzalloc(&pdev->dev, sizeof(*info), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	if (!info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	info->dev = dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	info->id_gpiod = devm_gpiod_get_optional(&pdev->dev, "id", GPIOD_IN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	info->vbus_gpiod = devm_gpiod_get_optional(&pdev->dev, "vbus",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 						   GPIOD_IN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	if (!info->id_gpiod && !info->vbus_gpiod) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 		dev_err(dev, "failed to get gpios\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	if (IS_ERR(info->id_gpiod))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 		return PTR_ERR(info->id_gpiod);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	if (IS_ERR(info->vbus_gpiod))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 		return PTR_ERR(info->vbus_gpiod);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	info->edev = devm_extcon_dev_allocate(dev, usb_extcon_cable);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	if (IS_ERR(info->edev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 		dev_err(dev, "failed to allocate extcon device\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 	ret = devm_extcon_dev_register(dev, info->edev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 		dev_err(dev, "failed to register extcon device\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	if (info->id_gpiod)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 		ret = gpiod_set_debounce(info->id_gpiod,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 					 USB_GPIO_DEBOUNCE_MS * 1000);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 	if (!ret && info->vbus_gpiod)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 		ret = gpiod_set_debounce(info->vbus_gpiod,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 					 USB_GPIO_DEBOUNCE_MS * 1000);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 		info->debounce_jiffies = msecs_to_jiffies(USB_GPIO_DEBOUNCE_MS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 	INIT_DELAYED_WORK(&info->wq_detcable, usb_extcon_detect_cable);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 	if (info->id_gpiod) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 		info->id_irq = gpiod_to_irq(info->id_gpiod);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 		if (info->id_irq < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 			dev_err(dev, "failed to get ID IRQ\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 			return info->id_irq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 		ret = devm_request_threaded_irq(dev, info->id_irq, NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 						usb_irq_handler,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 						IRQF_TRIGGER_RISING |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 						IRQF_TRIGGER_FALLING | IRQF_ONESHOT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 						pdev->name, info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 		if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 			dev_err(dev, "failed to request handler for ID IRQ\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 			return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	if (info->vbus_gpiod) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 		info->vbus_irq = gpiod_to_irq(info->vbus_gpiod);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 		if (info->vbus_irq < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 			dev_err(dev, "failed to get VBUS IRQ\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 			return info->vbus_irq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 		ret = devm_request_threaded_irq(dev, info->vbus_irq, NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 						usb_irq_handler,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 						IRQF_TRIGGER_RISING |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 						IRQF_TRIGGER_FALLING | IRQF_ONESHOT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 						pdev->name, info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 		if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 			dev_err(dev, "failed to request handler for VBUS IRQ\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 			return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 	platform_set_drvdata(pdev, info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 	device_set_wakeup_capable(&pdev->dev, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 	/* Perform initial detection */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 	usb_extcon_detect_cable(&info->wq_detcable.work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) static int usb_extcon_remove(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 	struct usb_extcon_info *info = platform_get_drvdata(pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 	cancel_delayed_work_sync(&info->wq_detcable);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 	device_init_wakeup(&pdev->dev, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) #ifdef CONFIG_PM_SLEEP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) static int usb_extcon_suspend(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 	struct usb_extcon_info *info = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 	int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 	if (device_may_wakeup(dev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 		if (info->id_gpiod) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 			ret = enable_irq_wake(info->id_irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 			if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 				return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 		if (info->vbus_gpiod) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 			ret = enable_irq_wake(info->vbus_irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 			if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 				if (info->id_gpiod)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 					disable_irq_wake(info->id_irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 				return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 	 * We don't want to process any IRQs after this point
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 	 * as GPIOs used behind I2C subsystem might not be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 	 * accessible until resume completes. So disable IRQ.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 	if (info->id_gpiod)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 		disable_irq(info->id_irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 	if (info->vbus_gpiod)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 		disable_irq(info->vbus_irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 	if (!device_may_wakeup(dev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 		pinctrl_pm_select_sleep_state(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) static int usb_extcon_resume(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 	struct usb_extcon_info *info = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 	int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 	if (!device_may_wakeup(dev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 		pinctrl_pm_select_default_state(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 	if (device_may_wakeup(dev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 		if (info->id_gpiod) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 			ret = disable_irq_wake(info->id_irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 			if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 				return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 		if (info->vbus_gpiod) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 			ret = disable_irq_wake(info->vbus_irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 			if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 				if (info->id_gpiod)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 					enable_irq_wake(info->id_irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 				return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 	if (info->id_gpiod)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 		enable_irq(info->id_irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 	if (info->vbus_gpiod)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 		enable_irq(info->vbus_irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 	queue_delayed_work(system_power_efficient_wq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 			   &info->wq_detcable, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) static SIMPLE_DEV_PM_OPS(usb_extcon_pm_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 			 usb_extcon_suspend, usb_extcon_resume);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) static const struct of_device_id usb_extcon_dt_match[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 	{ .compatible = "linux,extcon-usb-gpio", },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 	{ /* sentinel */ }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) MODULE_DEVICE_TABLE(of, usb_extcon_dt_match);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) static const struct platform_device_id usb_extcon_platform_ids[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 	{ .name = "extcon-usb-gpio", },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 	{ /* sentinel */ }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) MODULE_DEVICE_TABLE(platform, usb_extcon_platform_ids);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) static struct platform_driver usb_extcon_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 	.probe		= usb_extcon_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 	.remove		= usb_extcon_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 	.driver		= {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 		.name	= "extcon-usb-gpio",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 		.pm	= &usb_extcon_pm_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 		.of_match_table = usb_extcon_dt_match,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 	.id_table = usb_extcon_platform_ids,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) module_platform_driver(usb_extcon_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) MODULE_AUTHOR("Roger Quadros <rogerq@ti.com>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) MODULE_DESCRIPTION("USB GPIO extcon driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) MODULE_LICENSE("GPL v2");