fixup! phy: qcom: Add USB HS 7nm PHY driver cleanup n stuff
diff --git a/drivers/phy/qcom/phy-qcom-usb-hs-7nm.c b/drivers/phy/qcom/phy-qcom-usb-hs-7nm.c
index 7cb99b5..5be6a9b 100644
--- a/drivers/phy/qcom/phy-qcom-usb-hs-7nm.c
+++ b/drivers/phy/qcom/phy-qcom-usb-hs-7nm.c
@@ -108,10 +108,6 @@
 
 /* struct hs_7nm_phy_cfg - per-PHY initialization config */
 struct hs_7nm_phy_cfg {
-	/* clocks to be requested */
-	struct clk *clks;
-	int num_clks;
-
 	/* resets to be requested */
 	struct reset_ctl *resets;
 	int num_resets;
@@ -127,25 +123,14 @@
 	void __iomem *base;
 
 	/* clocks to be requested */
-	struct clk *clks;
-	int num_clks;
+	struct clk_bulk clks;
 
 	/* resets to be requested */
-	struct reset_ctl *resets;
-	int num_resets;
+	struct reset_ctl_bulk resets;
 
 	struct hs_7nm_phy_cfg *cfg;
 };
 
-/* Enable DEBUG_HS_PHY to trace hs_7nm reg read/write */
-#define DEBUG_HS_PHY
-
-#ifdef DEBUG_HS_PHY
-#define debug_hs_7nm printf
-static unsigned int writel_count = 0;
-static unsigned int readl_count = 0;
-#endif
-
 static inline void hs_7nm_write_mask(void __iomem *base, u32 offset,
 						u32 mask, u32 val)
 {
@@ -153,176 +138,17 @@
 
 	reg = readl_relaxed(base + offset);
 
-#ifdef DEBUG_HS_PHY
-	debug_hs_7nm("%s: readl_cnt=%u, reg=0x%p, val=0x%x\n",
-			__func__, readl_count++, base + offset, reg);
-#endif
-
 	reg &= ~mask;
 	reg |= val & mask;
 	writel_relaxed(reg, base + offset);
 
-#ifdef DEBUG_HS_PHY
-	debug_hs_7nm("%s: writel_cnt=%u, reg=0x%p, val=0x%x\n",
-			__func__, writel_count++, base + offset, reg);
-#endif
-
 	/* Ensure above write is completed */
 	readl_relaxed(base + offset);
 }
 
-static const struct override_param hs_disconnect_sc7280[] = {
-	{ -272, 0 },
-	{ 0, 1 },
-	{ 317, 2 },
-	{ 630, 3 },
-	{ 973, 4 },
-	{ 1332, 5 },
-	{ 1743, 6 },
-	{ 2156, 7 },
-};
-
-static const struct override_param squelch_det_threshold_sc7280[] = {
-	{ -2090, 7 },
-	{ -1560, 6 },
-	{ -1030, 5 },
-	{ -530, 4 },
-	{ 0, 3 },
-	{ 530, 2 },
-	{ 1060, 1 },
-	{ 1590, 0 },
-};
-
-static const struct override_param hs_amplitude_sc7280[] = {
-	{ -660, 0 },
-	{ -440, 1 },
-	{ -220, 2 },
-	{ 0, 3 },
-	{ 230, 4 },
-	{ 440, 5 },
-	{ 650, 6 },
-	{ 890, 7 },
-	{ 1110, 8 },
-	{ 1330, 9 },
-	{ 1560, 10 },
-	{ 1780, 11 },
-	{ 2000, 12 },
-	{ 2220, 13 },
-	{ 2430, 14 },
-	{ 2670, 15 },
-};
-
-static const struct override_param preemphasis_duration_sc7280[] = {
-	{ 10000, 1 },
-	{ 20000, 0 },
-};
-
-static const struct override_param preemphasis_amplitude_sc7280[] = {
-	{ 10000, 1 },
-	{ 20000, 2 },
-	{ 30000, 3 },
-	{ 40000, 0 },
-};
-
-static const struct override_param hs_rise_fall_time_sc7280[] = {
-	{ -4100, 3 },
-	{ 0, 2 },
-	{ 2810, 1 },
-	{ 5430, 0 },
-};
-
-static const struct override_param hs_crossover_voltage_sc7280[] = {
-	{ -31000, 1 },
-	{ 0, 3 },
-	{ 28000, 2 },
-};
-
-static const struct override_param hs_output_impedance_sc7280[] = {
-	{ -2300000, 3 },
-	{ 0, 2 },
-	{ 2600000, 1 },
-	{ 6100000, 0 },
-};
-
-static const struct override_param ls_fs_output_impedance_sc7280[] = {
-	{ -1053, 15 },
-	{ -557, 7 },
-	{ 0, 3 },
-	{ 612, 1 },
-	{ 1310, 0 },
-};
-
-static const struct override_param_map sc7280_snps_7nm_phy[] = {
-	{
-		"qcom,hs-disconnect-bp",
-		hs_disconnect_sc7280,
-		ARRAY_SIZE(hs_disconnect_sc7280),
-		USB2_PHY_USB_PHY_HS_PHY_OVERRIDE_X0,
-		HS_DISCONNECT_MASK
-	},
-	{
-		"qcom,squelch-detector-bp",
-		squelch_det_threshold_sc7280,
-		ARRAY_SIZE(squelch_det_threshold_sc7280),
-		USB2_PHY_USB_PHY_HS_PHY_OVERRIDE_X0,
-		SQUELCH_DETECTOR_MASK
-	},
-	{
-		"qcom,hs-amplitude-bp",
-		hs_amplitude_sc7280,
-		ARRAY_SIZE(hs_amplitude_sc7280),
-		USB2_PHY_USB_PHY_HS_PHY_OVERRIDE_X1,
-		HS_AMPLITUDE_MASK
-	},
-	{
-		"qcom,pre-emphasis-duration-bp",
-		preemphasis_duration_sc7280,
-		ARRAY_SIZE(preemphasis_duration_sc7280),
-		USB2_PHY_USB_PHY_HS_PHY_OVERRIDE_X1,
-		PREEMPHASIS_DURATION_MASK,
-	},
-	{
-		"qcom,pre-emphasis-amplitude-bp",
-		preemphasis_amplitude_sc7280,
-		ARRAY_SIZE(preemphasis_amplitude_sc7280),
-		USB2_PHY_USB_PHY_HS_PHY_OVERRIDE_X1,
-		PREEMPHASIS_AMPLITUDE_MASK,
-	},
-	{
-		"qcom,hs-rise-fall-time-bp",
-		hs_rise_fall_time_sc7280,
-		ARRAY_SIZE(hs_rise_fall_time_sc7280),
-		USB2_PHY_USB_PHY_HS_PHY_OVERRIDE_X2,
-		HS_RISE_FALL_MASK
-	},
-	{
-		"qcom,hs-crossover-voltage-microvolt",
-		hs_crossover_voltage_sc7280,
-		ARRAY_SIZE(hs_crossover_voltage_sc7280),
-		USB2_PHY_USB_PHY_HS_PHY_OVERRIDE_X2,
-		HS_CROSSOVER_VOLTAGE_MASK
-	},
-	{
-		"qcom,hs-output-impedance-micro-ohms",
-		hs_output_impedance_sc7280,
-		ARRAY_SIZE(hs_output_impedance_sc7280),
-		USB2_PHY_USB_PHY_HS_PHY_OVERRIDE_X2,
-		HS_OUTPUT_IMPEDANCE_MASK,
-	},
-	{
-		"qcom,ls-fs-output-impedance-bp",
-		ls_fs_output_impedance_sc7280,
-		ARRAY_SIZE(ls_fs_output_impedance_sc7280),
-		USB2_PHY_USB_PHY_HS_PHY_OVERRIDE_X3,
-		LS_FS_OUTPUT_IMPEDANCE_MASK,
-	},
-	{},
-};
-
 static int hs_7nm_usb_init(struct phy *phy)
 {
 	struct hs_7nm_phy_priv *hs_7nm = dev_get_priv(phy->dev);
-	int i;
 
 	hs_7nm_write_mask(hs_7nm->base, USB2_PHY_USB_PHY_CFG0,
 					UTMI_PHY_CMN_CTRL_OVERRIDE_EN,
@@ -343,14 +169,6 @@
 	hs_7nm_write_mask(hs_7nm->base, USB2_PHY_USB_PHY_HS_PHY_CTRL1,
 					VBUSVLDEXT0, VBUSVLDEXT0);
 
-	for (i = 0; i < ARRAY_SIZE(hs_7nm->cfg->update_seq_cfg); i++) {
-		if (hs_7nm->cfg->update_seq_cfg[i].need_update)
-			hs_7nm_write_mask(hs_7nm->base,
-					hs_7nm->cfg->update_seq_cfg[i].offset,
-					hs_7nm->cfg->update_seq_cfg[i].mask,
-					hs_7nm->cfg->update_seq_cfg[i].value);
-	}
-
 	hs_7nm_write_mask(hs_7nm->base,
 					USB2_PHY_USB_PHY_HS_PHY_CTRL_COMMON2,
 					VREGBYPASS, VREGBYPASS);
@@ -377,36 +195,17 @@
 	return 0;
 }
 
-static int hs_7nm_phy_do_reset(struct hs_7nm_phy_priv *hs_7nm)
-{
-	int i, ret;
-
-	for (i = 0; i < hs_7nm->num_resets; i++) {
-		ret = reset_assert(&hs_7nm->resets[i]);
-		if (ret)
-			return ret;
-	}
-
-	udelay(10);
-
-	for (i = 0; i < hs_7nm->num_resets; i++) {
-		ret = reset_deassert(&hs_7nm->resets[i]);
-		if (ret)
-			return ret;
-	}
-
-	return 0;
-}
-
 static int hs_7nm_phy_power_on(struct phy *phy)
 {
 	struct hs_7nm_phy_priv *hs_7nm = dev_get_priv(phy->dev);
 	int ret;
 
-	ret = hs_7nm_phy_do_reset(hs_7nm);
+	clk_enable_bulk(&hs_7nm->clks);
+
+	ret = reset_deassert_bulk(&hs_7nm->resets);
 	if (ret)
 		return ret;
-	
+
 	ret = hs_7nm_usb_init(phy);
 	if (ret)
 		return ret;
@@ -418,123 +217,28 @@
 {
 	struct hs_7nm_phy_priv *hs_7nm = dev_get_priv(phy->dev);
 
-	reset_release_all(hs_7nm->resets, hs_7nm->num_resets);
-	clk_release_all(hs_7nm->clks, hs_7nm->num_clks);
+	reset_assert_bulk(&hs_7nm->resets);
+	clk_disable_bulk(&hs_7nm->clks);
 
 	return 0;
 }
 
-static int hs_7nm_phy_reset_init(struct udevice *dev, struct hs_7nm_phy_priv *hs_7nm)
-{
-	const struct hs_7nm_phy_cfg *cfg = hs_7nm->cfg;
-	int num = cfg->num_resets;
-	int i, ret;
-
-	hs_7nm->num_resets = 0;
-	hs_7nm->resets = devm_kcalloc(dev, num, sizeof(*hs_7nm->resets), GFP_KERNEL);
-	if (!hs_7nm->resets)
-		return -ENOMEM;
-
-	for (i = 0; i < num; i++) {
-		ret = reset_get_by_index(dev, i, &hs_7nm->resets[i]);
-		if (ret < 0)
-			goto reset_get_err;
-
-		++hs_7nm->num_resets;
-	}
-
-	return 0;
-
-reset_get_err:
-	ret = reset_release_all(hs_7nm->resets, hs_7nm->num_resets);
-	if (ret)
-		debug("failed to disable all resets\n");
-
-	return ret;
-}
-
 static int hs_7nm_phy_clk_init(struct udevice *dev, struct hs_7nm_phy_priv *hs_7nm)
 {
-	const struct hs_7nm_phy_cfg *cfg = hs_7nm->cfg;
-	int num = cfg->num_clks;
-	int i, ret;
+	int ret;
 
-	hs_7nm->num_clks = 0;
-	hs_7nm->clks = devm_kcalloc(dev, num, sizeof(*hs_7nm->clks), GFP_KERNEL);
-	if (!hs_7nm->clks)
-		return -ENOMEM;
-
-	for (i = 0; i < num; i++) {
-		ret = clk_get_by_index(dev, i, &hs_7nm->clks[i]);
-		if (ret < 0)
-			goto clk_get_err;
-
-		ret = clk_enable(&hs_7nm->clks[i]);
-		if (ret && ret != -ENOSYS) {
-			debug("failed to enable clock %d\n", i);
-			clk_free(&hs_7nm->clks[i]);
-			goto clk_get_err;
-		}
-
-		++hs_7nm->num_clks;
+	ret = clk_get_bulk(dev, &hs_7nm->clks);
+	/* We may have no clocks */
+	if (ret == -ENOENT) {
+		debug("%s: no clocks\n", __func__);
+		return 0;
+	}
+	if (ret < 0) {
+		printf("%s: Failed to get clocks %d\n", __func__, ret);
+		return ret;
 	}
 
 	return 0;
-
-clk_get_err:
-	ret = clk_release_all(hs_7nm->clks, hs_7nm->num_clks);
-	if (ret)
-		debug("failed to disable all clocks\n");
-
-	return ret;
-}
-
-
-static void hs_7nm_override_param_update_val(
-			struct override_param_map map,
-			s32 dt_val, struct phy_override_seq *seq_entry)
-{
-	int i;
-
-	/*
-	 * Param table for each param is in increasing order
-	 * of dt values. We need to iterate over the list to
-	 * select the entry that matches the dt value and pick
-	 * up the corresponding register value.
-	 */
-	for (i = 0; i < map.table_size - 1; i++) {
-		if (map.param_table[i].value == dt_val)
-			break;
-	}
-
-	seq_entry->need_update = true;
-	seq_entry->offset = map.reg_offset;
-	seq_entry->mask = map.param_mask;
-	seq_entry->value = map.param_table[i].reg_val << __ffs(map.param_mask);
-}
-
-static void hs_7nm_read_override_param_seq(struct udevice *dev)
-{
-	struct hs_7nm_phy_priv *hs_7nm = dev_get_priv(dev);
-	ofnode dp = dev_ofnode(dev);
-	s32 val;
-	int ret, i;
-	const struct override_param_map *map_cfg = hs_7nm->cfg->map_cfg;
-
-	if (!map_cfg)
-		return;
-
-	for (i = 0; map_cfg[i].prop_name != NULL; i++) {
-		ret = ofnode_read_s32(dp, map_cfg[i].prop_name, &val);
-		if (ret)
-			continue;
-
-		hs_7nm_override_param_update_val(map_cfg[i], val,
-					&hs_7nm->cfg->update_seq_cfg[i]);
-		printf("Read param: %s dt_val: %d reg_val: 0x%x\n",
-			map_cfg[i].prop_name, val, hs_7nm->cfg->update_seq_cfg[i].value);
-
-	}
 }
 
 static int hs_7nm_phy_probe(struct udevice *dev)
@@ -542,33 +246,26 @@
 	struct hs_7nm_phy_priv *hs_7nm = dev_get_priv(dev);
 	int ret;
 
-#ifdef DEBUG_HS_PHY
-	debug_hs_7nm("%s: Entered function\n", __func__);
-#endif
-
 	hs_7nm->base = (void __iomem *)dev_read_addr(dev);
 	if (IS_ERR(hs_7nm->base))
 		return PTR_ERR(hs_7nm->base);
 
 	hs_7nm->cfg = (struct hs_7nm_phy_cfg *)dev_get_driver_data(dev);
-	
+
 	ret = hs_7nm_phy_clk_init(dev, hs_7nm);
-	if (ret)
+	if (ret) {
+		printf("%s: hs_7nm_phy_clk_init %d\n", __func__, ret);
 		return ret;
+	}
 
-	ret = hs_7nm_phy_reset_init(dev, hs_7nm);
-	if (ret)
+	ret = reset_get_bulk(dev, &hs_7nm->resets);
+	if (ret < 0) {
+		printf("failed to get resets, ret = %d\n", ret);
 		return ret;
+	}
 
-#ifdef DEBUG_HS_PHY
-	debug_hs_7nm("%s: Acquired clks and resets\n", __func__);
-#endif
-
-	hs_7nm_read_override_param_seq(dev);
-
-#ifdef DEBUG_HS_PHY
-	debug_hs_7nm("%s: Exiting function with success\n", __func__);
-#endif
+	clk_enable_bulk(&hs_7nm->clks);
+	reset_deassert_bulk(&hs_7nm->resets);
 
 	return 0;
 }
@@ -581,10 +278,7 @@
 static const struct udevice_id hs_7nm_phy_ids[] = {
 	{ .compatible	= "qcom,sm8150-usb-hs-phy", },
 	{ .compatible	= "qcom,usb-snps-hs-5nm-phy", },
-	{
-		.compatible	= "qcom,usb-snps-hs-7nm-phy",
-		.data		= (ulong)&sc7280_snps_7nm_phy,
-	},
+	{ .compatible	= "qcom,usb-snps-hs-7nm-phy", },
 	{ .compatible	= "qcom,usb-snps-femto-v2-phy",	},
 	{ }
 };