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

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

Merge "usb: phy: qusb: Remove usage of module params"

parents 7ea0a9b8 b51e5470
Loading
Loading
Loading
Loading
+45 −173
Original line number Original line Diff line number Diff line
@@ -11,6 +11,7 @@
#include <linux/delay.h>
#include <linux/delay.h>
#include <linux/io.h>
#include <linux/io.h>
#include <linux/of.h>
#include <linux/of.h>
#include <linux/debugfs.h>
#include <linux/platform_device.h>
#include <linux/platform_device.h>
#include <linux/power_supply.h>
#include <linux/power_supply.h>
#include <linux/regulator/consumer.h>
#include <linux/regulator/consumer.h>
@@ -91,30 +92,6 @@


#define HSTX_TRIMSIZE			4
#define HSTX_TRIMSIZE			4


static unsigned int tune1;
module_param(tune1, uint, 0644);
MODULE_PARM_DESC(tune1, "QUSB PHY TUNE1");

static unsigned int tune2;
module_param(tune2, uint, 0644);
MODULE_PARM_DESC(tune2, "QUSB PHY TUNE2");

static unsigned int tune3;
module_param(tune3, uint, 0644);
MODULE_PARM_DESC(tune3, "QUSB PHY TUNE3");

static unsigned int tune4;
module_param(tune4, uint, 0644);
MODULE_PARM_DESC(tune4, "QUSB PHY TUNE4");

static unsigned int tune5;
module_param(tune5, uint, 0644);
MODULE_PARM_DESC(tune5, "QUSB PHY TUNE5");

static bool eud_connected;
module_param(eud_connected, bool, 0644);
MODULE_PARM_DESC(eud_connected, "EUD_CONNECTED");

struct qusb_phy {
struct qusb_phy {
	struct usb_phy		phy;
	struct usb_phy		phy;
	void __iomem		*base;
	void __iomem		*base;
@@ -155,17 +132,16 @@ struct qusb_phy {
	struct regulator_desc	dpdm_rdesc;
	struct regulator_desc	dpdm_rdesc;
	struct regulator_dev	*dpdm_rdev;
	struct regulator_dev	*dpdm_rdev;


	/* emulation targets specific */
	void __iomem		*emu_phy_base;
	bool			emulation;
	int			*emu_init_seq;
	int			emu_init_seq_len;
	int			*phy_pll_reset_seq;
	int			phy_pll_reset_seq_len;
	int			*emu_dcm_reset_seq;
	int			emu_dcm_reset_seq_len;
	bool			put_into_high_z_state;
	bool			put_into_high_z_state;
	struct mutex		phy_lock;
	struct mutex		phy_lock;

	/* debugfs entries */
	struct dentry		*root;
	u8			tune1;
	u8			tune2;
	u8			tune3;
	u8			tune4;
	u8			tune5;
};
};


static void qusb_phy_enable_clocks(struct qusb_phy *qphy, bool on)
static void qusb_phy_enable_clocks(struct qusb_phy *qphy, bool on)
@@ -426,19 +402,6 @@ static int qusb_phy_init(struct usb_phy *phy)
	u8 reg;
	u8 reg;
	bool pll_lock_fail = false;
	bool pll_lock_fail = false;


	/*
	 * If eud is enabled eud_connected parameter will be set to true.
	 * Phy init will be called when spoof attach is done but it will
	 * break the eud functionality by powering down the phy and
	 * re-initializing it. Hence, bail out early from phy init when
	 * eud_connected param is set to true.
	 */
	if (eud_connected) {
		pr_debug("eud_connected is true so bailing out early from %s\n",
				__func__);
		return 0;
	}

	dev_dbg(phy->dev, "%s\n", __func__);
	dev_dbg(phy->dev, "%s\n", __func__);


	/*
	/*
@@ -467,30 +430,6 @@ static int qusb_phy_init(struct usb_phy *phy)
	if (ret)
	if (ret)
		dev_err(phy->dev, "%s: phy_reset deassert failed\n", __func__);
		dev_err(phy->dev, "%s: phy_reset deassert failed\n", __func__);


	if (qphy->emulation) {
		if (qphy->emu_init_seq)
			qusb_phy_write_seq(qphy->emu_phy_base,
				qphy->emu_init_seq, qphy->emu_init_seq_len, 0);

		if (qphy->qusb_phy_init_seq)
			qusb_phy_write_seq(qphy->base, qphy->qusb_phy_init_seq,
					qphy->init_seq_len, 0);

		/* Wait for 5ms as per QUSB2 RUMI sequence */
		usleep_range(5000, 7000);

		if (qphy->phy_pll_reset_seq)
			qusb_phy_write_seq(qphy->base, qphy->phy_pll_reset_seq,
					qphy->phy_pll_reset_seq_len, 10000);

		if (qphy->emu_dcm_reset_seq)
			qusb_phy_write_seq(qphy->emu_phy_base,
					qphy->emu_dcm_reset_seq,
					qphy->emu_dcm_reset_seq_len, 10000);

		return 0;
	}

	/* Disable the PHY */
	/* Disable the PHY */
	if (qphy->major_rev < 2)
	if (qphy->major_rev < 2)
		writel_relaxed(CLAMP_N_EN | FREEZIO_N | POWER_DOWN,
		writel_relaxed(CLAMP_N_EN | FREEZIO_N | POWER_DOWN,
@@ -517,7 +456,7 @@ static int qusb_phy_init(struct usb_phy *phy)
	 * and try to read EFUSE value only once i.e. not every USB
	 * and try to read EFUSE value only once i.e. not every USB
	 * cable connect case.
	 * cable connect case.
	 */
	 */
	if (qphy->tune2_efuse_reg && !tune2) {
	if (qphy->tune2_efuse_reg && !qphy->tune2) {
		if (!qphy->tune2_val)
		if (!qphy->tune2_val)
			qusb_phy_get_tune2_param(qphy);
			qusb_phy_get_tune2_param(qphy);


@@ -528,28 +467,30 @@ static int qusb_phy_init(struct usb_phy *phy)
	}
	}


	/* If tune modparam set, override tune value */
	/* If tune modparam set, override tune value */

	if (qphy->tune1) {
	pr_debug("%s():userspecified modparams TUNEX val:0x%x %x %x %x %x\n",
		writel_relaxed(qphy->tune1,
				__func__, tune1, tune2, tune3, tune4, tune5);
	if (tune1)
		writel_relaxed(tune1,
				qphy->base + QUSB2PHY_PORT_TUNE1);
				qphy->base + QUSB2PHY_PORT_TUNE1);
	}


	if (tune2)
	if (qphy->tune2) {
		writel_relaxed(tune2,
		writel_relaxed(qphy->tune2,
				qphy->base + QUSB2PHY_PORT_TUNE2);
				qphy->base + QUSB2PHY_PORT_TUNE2);
	}


	if (tune3)
	if (qphy->tune3) {
		writel_relaxed(tune3,
		writel_relaxed(qphy->tune3,
				qphy->base + QUSB2PHY_PORT_TUNE3);
				qphy->base + QUSB2PHY_PORT_TUNE3);
	}


	if (tune4)
	if (qphy->tune4) {
		writel_relaxed(tune4,
		writel_relaxed(qphy->tune4,
				qphy->base + QUSB2PHY_PORT_TUNE4);
				qphy->base + QUSB2PHY_PORT_TUNE4);
	}


	if (tune5)
	if (qphy->tune5) {
		writel_relaxed(tune5,
		writel_relaxed(qphy->tune5,
				qphy->base + QUSB2PHY_PORT_TUNE5);
				qphy->base + QUSB2PHY_PORT_TUNE5);
	}


	/* ensure above writes are completed before re-enabling PHY */
	/* ensure above writes are completed before re-enabling PHY */
	wmb();
	wmb();
@@ -700,19 +641,15 @@ static int qusb_phy_set_suspend(struct usb_phy *phy, int suspend)
			writel_relaxed(0x00,
			writel_relaxed(0x00,
				qphy->base + QUSB2PHY_PORT_INTR_CTRL);
				qphy->base + QUSB2PHY_PORT_INTR_CTRL);


			if (!eud_connected) {
			/* Disable PHY */
			/* Disable PHY */
				writel_relaxed(POWER_DOWN |
			writel_relaxed(POWER_DOWN | readl_relaxed(qphy->base +
					readl_relaxed(qphy->base +
					QUSB2PHY_PORT_POWERDOWN),
					QUSB2PHY_PORT_POWERDOWN),
					qphy->base + QUSB2PHY_PORT_POWERDOWN);
					qphy->base + QUSB2PHY_PORT_POWERDOWN);
			/* Make sure that above write is completed */
			/* Make sure that above write is completed */
			wmb();
			wmb();


			if (qphy->tcsr_clamp_dig_n)
			if (qphy->tcsr_clamp_dig_n)
					writel_relaxed(0x0,
				writel_relaxed(0x0, qphy->tcsr_clamp_dig_n);
						qphy->tcsr_clamp_dig_n);
			}


			qusb_phy_enable_clocks(qphy, false);
			qusb_phy_enable_clocks(qphy, false);
			qusb_phy_enable_power(qphy, false);
			qusb_phy_enable_power(qphy, false);
@@ -910,6 +847,16 @@ static int qusb_phy_regulator_init(struct qusb_phy *qphy)


}
}


static void qusb_phy_create_debugfs(struct qusb_phy *qphy)
{
	qphy->root = debugfs_create_dir(dev_name(qphy->phy.dev), NULL);
	debugfs_create_x8("tune1", 0644, qphy->root, &qphy->tune1);
	debugfs_create_x8("tune2", 0644, qphy->root, &qphy->tune2);
	debugfs_create_x8("tune3", 0644, qphy->root, &qphy->tune3);
	debugfs_create_x8("tune4", 0644, qphy->root, &qphy->tune4);
	debugfs_create_x8("tune5", 0644, qphy->root, &qphy->tune5);
}

static int qusb_phy_probe(struct platform_device *pdev)
static int qusb_phy_probe(struct platform_device *pdev)
{
{
	struct qusb_phy *qphy;
	struct qusb_phy *qphy;
@@ -931,16 +878,6 @@ static int qusb_phy_probe(struct platform_device *pdev)
	if (IS_ERR(qphy->base))
	if (IS_ERR(qphy->base))
		return PTR_ERR(qphy->base);
		return PTR_ERR(qphy->base);


	res = platform_get_resource_byname(pdev, IORESOURCE_MEM,
							"emu_phy_base");
	if (res) {
		qphy->emu_phy_base = devm_ioremap_resource(dev, res);
		if (IS_ERR(qphy->emu_phy_base)) {
			dev_dbg(dev, "couldn't ioremap emu_phy_base\n");
			qphy->emu_phy_base = NULL;
		}
	}

	res = platform_get_resource_byname(pdev, IORESOURCE_MEM,
	res = platform_get_resource_byname(pdev, IORESOURCE_MEM,
							"tune2_efuse_addr");
							"tune2_efuse_addr");
	if (res) {
	if (res) {
@@ -1085,74 +1022,6 @@ static int qusb_phy_probe(struct platform_device *pdev)
	if (IS_ERR(qphy->gdsc))
	if (IS_ERR(qphy->gdsc))
		qphy->gdsc = NULL;
		qphy->gdsc = NULL;


	qphy->emulation = of_property_read_bool(dev->of_node,
					"qcom,emulation");

	of_get_property(dev->of_node, "qcom,emu-init-seq", &size);
	if (size) {
		qphy->emu_init_seq = devm_kzalloc(dev,
						size, GFP_KERNEL);
		if (qphy->emu_init_seq) {
			qphy->emu_init_seq_len =
				(size / sizeof(*qphy->emu_init_seq));
			if (qphy->emu_init_seq_len % 2) {
				dev_err(dev, "invalid emu_init_seq_len\n");
				return -EINVAL;
			}

			of_property_read_u32_array(dev->of_node,
				"qcom,emu-init-seq",
				qphy->emu_init_seq,
				qphy->emu_init_seq_len);
		} else {
			dev_dbg(dev, "error allocating memory for emu_init_seq\n");
		}
	}

	size = 0;
	of_get_property(dev->of_node, "qcom,phy-pll-reset-seq", &size);
	if (size) {
		qphy->phy_pll_reset_seq = devm_kzalloc(dev,
						size, GFP_KERNEL);
		if (qphy->phy_pll_reset_seq) {
			qphy->phy_pll_reset_seq_len =
				(size / sizeof(*qphy->phy_pll_reset_seq));
			if (qphy->phy_pll_reset_seq_len % 2) {
				dev_err(dev, "invalid phy_pll_reset_seq_len\n");
				return -EINVAL;
			}

			of_property_read_u32_array(dev->of_node,
				"qcom,phy-pll-reset-seq",
				qphy->phy_pll_reset_seq,
				qphy->phy_pll_reset_seq_len);
		} else {
			dev_dbg(dev, "error allocating memory for phy_pll_reset_seq\n");
		}
	}

	size = 0;
	of_get_property(dev->of_node, "qcom,emu-dcm-reset-seq", &size);
	if (size) {
		qphy->emu_dcm_reset_seq = devm_kzalloc(dev,
						size, GFP_KERNEL);
		if (qphy->emu_dcm_reset_seq) {
			qphy->emu_dcm_reset_seq_len =
				(size / sizeof(*qphy->emu_dcm_reset_seq));
			if (qphy->emu_dcm_reset_seq_len % 2) {
				dev_err(dev, "invalid emu_dcm_reset_seq_len\n");
				return -EINVAL;
			}

			of_property_read_u32_array(dev->of_node,
				"qcom,emu-dcm-reset-seq",
				qphy->emu_dcm_reset_seq,
				qphy->emu_dcm_reset_seq_len);
		} else {
			dev_dbg(dev, "error allocating memory for emu_dcm_reset_seq\n");
		}
	}

	size = 0;
	size = 0;
	of_get_property(dev->of_node, "qcom,qusb-phy-init-seq", &size);
	of_get_property(dev->of_node, "qcom,qusb-phy-init-seq", &size);
	if (size) {
	if (size) {
@@ -1266,6 +1135,8 @@ static int qusb_phy_probe(struct platform_device *pdev)


	qphy->suspended = true;
	qphy->suspended = true;


	qusb_phy_create_debugfs(qphy);

	return ret;
	return ret;
}
}


@@ -1273,6 +1144,7 @@ static int qusb_phy_remove(struct platform_device *pdev)
{
{
	struct qusb_phy *qphy = platform_get_drvdata(pdev);
	struct qusb_phy *qphy = platform_get_drvdata(pdev);


	debugfs_remove_recursive(qphy->root);
	usb_remove_phy(&qphy->phy);
	usb_remove_phy(&qphy->phy);
	qphy->cable_connected = false;
	qphy->cable_connected = false;
	qusb_phy_set_suspend(&qphy->phy, true);
	qusb_phy_set_suspend(&qphy->phy, true);