Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 17ee7774 authored by qctecmdr's avatar qctecmdr Committed by Gerrit - the friendly Code Review server
Browse files

Merge "extcon: storage-cd-gpio: Remove storage card detect gpio based extcon"

parents 1bc43271 11e4af08
Loading
Loading
Loading
Loading
+0 −9
Original line number Diff line number Diff line
@@ -43,15 +43,6 @@ config EXTCON_GPIO
	  Say Y here to enable GPIO based extcon support. Note that GPIO
	  extcon supports single state per extcon instance.

config EXTCON_STORAGE_CD_GPIO
	tristate "Storage card detect GPIO extcon support"
	depends on GPIOLIB || COMPILE_TEST
	help
	  Say Y here to enable removable storage card detect GPIO based
	  extcon support. It helps when different kinds of storage cards
	  share one detect GPIO. Note that storage card detect GPIO extcon
	  supports single state per extcon instance.

config EXTCON_INTEL_INT3496
	tristate "Intel INT3496 ACPI device extcon driver"
	depends on GPIOLIB && ACPI && (X86 || COMPILE_TEST)
+0 −1
Original line number Diff line number Diff line
@@ -9,7 +9,6 @@ obj-$(CONFIG_EXTCON_ADC_JACK) += extcon-adc-jack.o
obj-$(CONFIG_EXTCON_ARIZONA)	+= extcon-arizona.o
obj-$(CONFIG_EXTCON_AXP288)	+= extcon-axp288.o
obj-$(CONFIG_EXTCON_GPIO)	+= extcon-gpio.o
obj-$(CONFIG_EXTCON_STORAGE_CD_GPIO)	+= extcon-storage-cd-gpio.o
obj-$(CONFIG_EXTCON_INTEL_INT3496) += extcon-intel-int3496.o
obj-$(CONFIG_EXTCON_INTEL_CHT_WC) += extcon-intel-cht-wc.o
obj-$(CONFIG_EXTCON_MAX14577)	+= extcon-max14577.o
+0 −211
Original line number Diff line number Diff line
// SPDX-License-Identifier: GPL-2.0-only
/*
 * Copyright (c) 2019, The Linux Foundation. All rights reserved.
 *
 */

#include <linux/extcon-provider.h>
#include <linux/gpio/consumer.h>
#include <linux/init.h>
#include <linux/interrupt.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/platform_device.h>
#include <linux/slab.h>
#include <linux/of_gpio.h>

struct cd_gpio_extcon_data {
	struct extcon_dev *edev;
	int irq;
	struct gpio_desc *gpiod;
	unsigned int extcon_id;
	unsigned long irq_flags;
	struct pinctrl *pctrl;
	struct pinctrl_state *pins_default;
	unsigned int *supported_cable;
};

static irqreturn_t cd_gpio_threaded_irq_handler(int irq, void *dev_id)
{
	int state;
	struct cd_gpio_extcon_data *data = dev_id;

	state = gpiod_get_value_cansleep(data->gpiod);
	extcon_set_state_sync(data->edev, data->extcon_id, state);

	return IRQ_HANDLED;
}

static int extcon_parse_pinctrl_data(struct device *dev,
				     struct cd_gpio_extcon_data *data)
{
	struct pinctrl *pctrl;
	int ret = 0;

	/* Try to obtain pinctrl handle */
	pctrl = devm_pinctrl_get(dev);
	if (IS_ERR(pctrl)) {
		ret = PTR_ERR(pctrl);
		goto out;
	}
	data->pctrl = pctrl;

	/* Look-up and keep the state handy to be used later */
	data->pins_default = pinctrl_lookup_state(data->pctrl, "default");
	if (IS_ERR(data->pins_default)) {
		ret = PTR_ERR(data->pins_default);
		dev_err(dev, "Can't get default pinctrl state, ret %d\n", ret);
	}
out:
	return ret;
}

static int extcon_populate_data(struct device *dev,
				struct cd_gpio_extcon_data *data)
{
	struct device_node *np = dev->of_node;
	u32 val;
	int ret = 0;

	ret = of_property_read_u32(np, "extcon-id", &data->extcon_id);
	if (ret) {
		dev_err(dev, "failed to read extcon-id property, %d\n", ret);
		goto out;
	}

	ret = of_property_read_u32(np, "irq-flags", &val);
	if (ret) {
		dev_err(dev, "failed to read irq-flags property, %d\n", ret);
		goto out;
	}
	data->irq_flags = val;

	ret = extcon_parse_pinctrl_data(dev, data);
	if (ret)
		dev_err(dev, "failed to parse pinctrl data\n");

out:
	return ret;
}

static int cd_gpio_extcon_probe(struct platform_device *pdev)
{
	struct cd_gpio_extcon_data *data;
	struct device *dev = &pdev->dev;
	int state, ret;

	data = devm_kzalloc(dev, sizeof(struct cd_gpio_extcon_data),
			    GFP_KERNEL);
	if (!data)
		return -ENOMEM;

	if (!data->irq_flags) {
		/* try populating cd gpio extcon data from device tree */
		ret = extcon_populate_data(dev, data);
		if (ret)
			return ret;
	}
	if (!data->irq_flags || data->extcon_id >= EXTCON_NUM)
		return -EINVAL;

	ret = pinctrl_select_state(data->pctrl, data->pins_default);
	if (ret < 0)
		dev_err(dev, "pinctrl state select failed, ret %d\n", ret);

	data->gpiod = devm_gpiod_get(dev, "extcon", GPIOD_IN);
	if (IS_ERR(data->gpiod))
		return PTR_ERR(data->gpiod);

	data->irq = gpiod_to_irq(data->gpiod);
	if (data->irq <= 0)
		return data->irq;

	data->supported_cable = devm_kzalloc(dev,
					     sizeof(*data->supported_cable) * 2,
					     GFP_KERNEL);
	if (!data->supported_cable)
		return -ENOMEM;

	data->supported_cable[0] = data->extcon_id;
	data->supported_cable[1] = EXTCON_NONE;
	/* Allocate the memory of extcon devie and register extcon device */
	data->edev = devm_extcon_dev_allocate(dev, data->supported_cable);
	if (IS_ERR(data->edev)) {
		dev_err(dev, "failed to allocate extcon device\n");
		return -ENOMEM;
	}

	ret = devm_extcon_dev_register(dev, data->edev);
	if (ret < 0)
		return ret;

	ret = devm_request_threaded_irq(dev, data->irq, NULL,
				  cd_gpio_threaded_irq_handler,
				  data->irq_flags | IRQF_ONESHOT,
				  pdev->name, data);
	if (ret < 0)
		return ret;

	ret = enable_irq_wake(data->irq);
	if (ret)
		return ret;

	platform_set_drvdata(pdev, data);

	/* Update initial state */
	state = gpiod_get_value_cansleep(data->gpiod);
	extcon_set_state(data->edev, data->extcon_id, state);

	return 0;
}

static int cd_gpio_extcon_remove(struct platform_device *pdev)
{
	return 0;
}

#ifdef CONFIG_PM_SLEEP
static int cd_gpio_extcon_resume(struct device *dev)
{
	struct cd_gpio_extcon_data *data;
	int state, ret = 0;

	data = dev_get_drvdata(dev);
	state = gpiod_get_value_cansleep(data->gpiod);
	ret = extcon_set_state_sync(data->edev, data->extcon_id, state);
	if (ret)
		dev_err(dev, "%s: Failed to set extcon gpio state\n",
				__func__);

	return ret;
}

static const struct dev_pm_ops cd_gpio_extcon_pm_ops = {
	SET_LATE_SYSTEM_SLEEP_PM_OPS(NULL, cd_gpio_extcon_resume)
};

#define EXTCON_GPIO_PMOPS (&cd_gpio_extcon_pm_ops)

#else
#define EXTCON_GPIO_PMOPS NULL
#endif

static const struct of_device_id extcon_cd_gpio_of_match[] = {
	{ .compatible = "extcon-storage-cd-gpio"},
	{},
};

static struct platform_driver cd_gpio_extcon_driver = {
	.probe		= cd_gpio_extcon_probe,
	.remove		= cd_gpio_extcon_remove,
	.driver		= {
		.name	= "extcon-storage-cd-gpio",
		.pm	= EXTCON_GPIO_PMOPS,
		.of_match_table = of_match_ptr(extcon_cd_gpio_of_match),
	},
};

module_platform_driver(cd_gpio_extcon_driver);

MODULE_DESCRIPTION("Storage card detect GPIO based extcon driver");
MODULE_LICENSE("GPL v2");
+0 −2
Original line number Diff line number Diff line
@@ -92,8 +92,6 @@ config SCSI_UFS_QCOM
	tristate "QCOM specific hooks to UFS controller platform driver"
	depends on SCSI_UFSHCD_PLATFORM && ARCH_QCOM
	select PHY_QCOM_UFS
	select EXTCON
	select EXTCON_STORAGE_CD_GPIO
	help
	  This selects the QCOM specific additions to UFSHCD platform driver.
	  UFS host on QCOM needs some vendor specific configuration before
+0 −17
Original line number Diff line number Diff line
@@ -304,20 +304,6 @@ static int ufshcd_parse_pinctrl_info(struct ufs_hba *hba)
	return ret;
}

static int ufshcd_parse_extcon_info(struct ufs_hba *hba)
{
	struct extcon_dev *extcon;

	extcon = extcon_get_edev_by_phandle(hba->dev, 0);
	if (IS_ERR(extcon) && PTR_ERR(extcon) != -ENODEV)
		return PTR_ERR(extcon);

	if (!IS_ERR(extcon))
		hba->extcon = extcon;

	return 0;
}

static void ufshcd_parse_gear_limits(struct ufs_hba *hba)
{
	struct device *dev = hba->dev;
@@ -527,9 +513,6 @@ int ufshcd_pltfrm_init(struct platform_device *pdev,
	ufshcd_parse_gear_limits(hba);
	ufshcd_parse_cmd_timeout(hba);
	ufshcd_parse_force_g4_flag(hba);
	err = ufshcd_parse_extcon_info(hba);
	if (err)
		goto dealloc_host;

	if (!dev->dma_mask)
		dev->dma_mask = &dev->coherent_dma_mask;
Loading