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

Commit b51e5470 authored by Sriharsha Allenki's avatar Sriharsha Allenki
Browse files

usb: phy: qusb: Remove usage of module params



The values in the module params applies to all the
device instances of the module rather than a single
device. Also, use of module params is not encouraged
on latest kernels. Hence remove the module params
and add the debugfs nodes for each tune registers
to pass the override sequence through the debugfs
files.
While at it remove the code related to emulation PHY
which is not under use anymore.

Change-Id: I634ff2238542242b424fc3d3c200258bbe66bed4
Signed-off-by: default avatarSriharsha Allenki <sallenki@codeaurora.org>
parent 994ea578
Loading
Loading
Loading
Loading
+45 −173
Original line number Diff line number Diff line
@@ -11,6 +11,7 @@
#include <linux/delay.h>
#include <linux/io.h>
#include <linux/of.h>
#include <linux/debugfs.h>
#include <linux/platform_device.h>
#include <linux/power_supply.h>
#include <linux/regulator/consumer.h>
@@ -91,30 +92,6 @@

#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 usb_phy		phy;
	void __iomem		*base;
@@ -155,17 +132,16 @@ struct qusb_phy {
	struct regulator_desc	dpdm_rdesc;
	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;
	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)
@@ -426,19 +402,6 @@ static int qusb_phy_init(struct usb_phy *phy)
	u8 reg;
	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__);

	/*
@@ -467,30 +430,6 @@ static int qusb_phy_init(struct usb_phy *phy)
	if (ret)
		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 */
	if (qphy->major_rev < 2)
		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
	 * cable connect case.
	 */
	if (qphy->tune2_efuse_reg && !tune2) {
	if (qphy->tune2_efuse_reg && !qphy->tune2) {
		if (!qphy->tune2_val)
			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 */

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

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

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

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

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

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

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

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

			qusb_phy_enable_clocks(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)
{
	struct qusb_phy *qphy;
@@ -931,16 +878,6 @@ static int qusb_phy_probe(struct platform_device *pdev)
	if (IS_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,
							"tune2_efuse_addr");
	if (res) {
@@ -1085,74 +1022,6 @@ static int qusb_phy_probe(struct platform_device *pdev)
	if (IS_ERR(qphy->gdsc))
		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;
	of_get_property(dev->of_node, "qcom,qusb-phy-init-seq", &size);
	if (size) {
@@ -1266,6 +1135,8 @@ static int qusb_phy_probe(struct platform_device *pdev)

	qphy->suspended = true;

	qusb_phy_create_debugfs(qphy);

	return ret;
}

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

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