Skip to content

Commit e36a5d1

Browse files
ivoszbgvinodkoul
authored andcommitted
phy: phy-snps-eusb2: refactor reference clock init
Instead of matching frequencies with a switch and case, introduce a table-based lookup. This improves readability, reduces redundancy, and makes it easier to extend support for additional frequencies in the future. Signed-off-by: Ivaylo Ivanov <[email protected]> Reviewed-by: Dmitry Baryshkov <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Vinod Koul <[email protected]>
1 parent aba7a96 commit e36a5d1

File tree

1 file changed

+32
-29
lines changed

1 file changed

+32
-29
lines changed

drivers/phy/phy-snps-eusb2.c

Lines changed: 32 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -192,44 +192,47 @@ static void qcom_eusb2_default_parameters(struct snps_eusb2_hsphy *phy)
192192
FIELD_PREP(PHY_CFG_TX_HS_XV_TUNE_MASK, 0x0));
193193
}
194194

195+
struct snps_eusb2_ref_clk {
196+
unsigned long freq;
197+
u32 fsel_val;
198+
u32 div_7_0_val;
199+
u32 div_11_8_val;
200+
};
201+
202+
static const struct snps_eusb2_ref_clk qcom_eusb2_ref_clk[] = {
203+
{ 19200000, FSEL_19_2_MHZ_VAL, DIV_7_0_19_2_MHZ_VAL, DIV_11_8_19_2_MHZ_VAL },
204+
{ 38400000, FSEL_38_4_MHZ_VAL, DIV_7_0_38_4_MHZ_VAL, DIV_11_8_38_4_MHZ_VAL },
205+
};
206+
195207
static int qcom_eusb2_ref_clk_init(struct snps_eusb2_hsphy *phy)
196208
{
209+
const struct snps_eusb2_ref_clk *config = NULL;
197210
unsigned long ref_clk_freq = clk_get_rate(phy->ref_clk);
198211

199-
switch (ref_clk_freq) {
200-
case 19200000:
201-
snps_eusb2_hsphy_write_mask(phy->base, QCOM_USB_PHY_HS_PHY_CTRL_COMMON0,
202-
FSEL_MASK,
203-
FIELD_PREP(FSEL_MASK, FSEL_19_2_MHZ_VAL));
204-
205-
snps_eusb2_hsphy_write_mask(phy->base, QCOM_USB_PHY_CFG_CTRL_2,
206-
PHY_CFG_PLL_FB_DIV_7_0_MASK,
207-
DIV_7_0_19_2_MHZ_VAL);
208-
209-
snps_eusb2_hsphy_write_mask(phy->base, QCOM_USB_PHY_CFG_CTRL_3,
210-
PHY_CFG_PLL_FB_DIV_11_8_MASK,
211-
DIV_11_8_19_2_MHZ_VAL);
212-
break;
213-
214-
case 38400000:
215-
snps_eusb2_hsphy_write_mask(phy->base, QCOM_USB_PHY_HS_PHY_CTRL_COMMON0,
216-
FSEL_MASK,
217-
FIELD_PREP(FSEL_MASK, FSEL_38_4_MHZ_VAL));
218-
219-
snps_eusb2_hsphy_write_mask(phy->base, QCOM_USB_PHY_CFG_CTRL_2,
220-
PHY_CFG_PLL_FB_DIV_7_0_MASK,
221-
DIV_7_0_38_4_MHZ_VAL);
222-
223-
snps_eusb2_hsphy_write_mask(phy->base, QCOM_USB_PHY_CFG_CTRL_3,
224-
PHY_CFG_PLL_FB_DIV_11_8_MASK,
225-
DIV_11_8_38_4_MHZ_VAL);
226-
break;
212+
for (int i = 0; i < ARRAY_SIZE(qcom_eusb2_ref_clk); i++) {
213+
if (qcom_eusb2_ref_clk[i].freq == ref_clk_freq) {
214+
config = &qcom_eusb2_ref_clk[i];
215+
break;
216+
}
217+
}
227218

228-
default:
219+
if (!config) {
229220
dev_err(&phy->phy->dev, "unsupported ref_clk_freq:%lu\n", ref_clk_freq);
230221
return -EINVAL;
231222
}
232223

224+
snps_eusb2_hsphy_write_mask(phy->base, QCOM_USB_PHY_HS_PHY_CTRL_COMMON0,
225+
FSEL_MASK,
226+
FIELD_PREP(FSEL_MASK, config->fsel_val));
227+
228+
snps_eusb2_hsphy_write_mask(phy->base, QCOM_USB_PHY_CFG_CTRL_2,
229+
PHY_CFG_PLL_FB_DIV_7_0_MASK,
230+
config->div_7_0_val);
231+
232+
snps_eusb2_hsphy_write_mask(phy->base, QCOM_USB_PHY_CFG_CTRL_3,
233+
PHY_CFG_PLL_FB_DIV_11_8_MASK,
234+
config->div_11_8_val);
235+
233236
snps_eusb2_hsphy_write_mask(phy->base, QCOM_USB_PHY_CFG_CTRL_3,
234237
PHY_CFG_PLL_REF_DIV, PLL_REF_DIV_VAL);
235238

0 commit comments

Comments
 (0)