Skip to content

Commit 24346dc

Browse files
tlebgregkh
authored andcommitted
usb: cdns3-ti: move reg writes to separate function
The device probe function mixes management code and hardware initialisation code. Extract the latter into an explicitly named cdns_ti_reset_and_init_hw() function to clarify intent. It also will allow easier transition to using runtime PM for triggering HW init. Reviewed-by: Roger Quadros <rogerq@kernel.org> Signed-off-by: Théo Lebrun <theo.lebrun@bootlin.com> Link: https://lore.kernel.org/r/20250205-s2r-cdns-v7-5-13658a271c3c@bootlin.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 17c6526 commit 24346dc

File tree

1 file changed

+44
-38
lines changed

1 file changed

+44
-38
lines changed

drivers/usb/cdns3/cdns3-ti.c

Lines changed: 44 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ struct cdns_ti {
5858
unsigned vbus_divider:1;
5959
struct clk *usb2_refclk;
6060
struct clk *lpm_clk;
61+
int usb2_refclk_rate_code;
6162
};
6263

6364
static const int cdns_ti_rate_table[] = { /* in KHZ */
@@ -98,15 +99,50 @@ static const struct of_dev_auxdata cdns_ti_auxdata[] = {
9899
{},
99100
};
100101

102+
static void cdns_ti_reset_and_init_hw(struct cdns_ti *data)
103+
{
104+
u32 reg;
105+
106+
/* assert RESET */
107+
reg = cdns_ti_readl(data, USBSS_W1);
108+
reg &= ~USBSS_W1_PWRUP_RST;
109+
cdns_ti_writel(data, USBSS_W1, reg);
110+
111+
/* set static config */
112+
reg = cdns_ti_readl(data, USBSS_STATIC_CONFIG);
113+
reg &= ~USBSS1_STATIC_PLL_REF_SEL_MASK;
114+
reg |= data->usb2_refclk_rate_code << USBSS1_STATIC_PLL_REF_SEL_SHIFT;
115+
116+
reg &= ~USBSS1_STATIC_VBUS_SEL_MASK;
117+
if (data->vbus_divider)
118+
reg |= 1 << USBSS1_STATIC_VBUS_SEL_SHIFT;
119+
120+
cdns_ti_writel(data, USBSS_STATIC_CONFIG, reg);
121+
reg = cdns_ti_readl(data, USBSS_STATIC_CONFIG);
122+
123+
/* set USB2_ONLY mode if requested */
124+
reg = cdns_ti_readl(data, USBSS_W1);
125+
if (data->usb2_only)
126+
reg |= USBSS_W1_USB2_ONLY;
127+
128+
/* set default modestrap */
129+
reg |= USBSS_W1_MODESTRAP_SEL;
130+
reg &= ~USBSS_W1_MODESTRAP_MASK;
131+
reg |= USBSS_MODESTRAP_MODE_NONE << USBSS_W1_MODESTRAP_SHIFT;
132+
cdns_ti_writel(data, USBSS_W1, reg);
133+
134+
/* de-assert RESET */
135+
reg |= USBSS_W1_PWRUP_RST;
136+
cdns_ti_writel(data, USBSS_W1, reg);
137+
}
138+
101139
static int cdns_ti_probe(struct platform_device *pdev)
102140
{
103141
struct device *dev = &pdev->dev;
104142
struct device_node *node = pdev->dev.of_node;
105143
struct cdns_ti *data;
106-
int error;
107-
u32 reg;
108-
int rate_code, i;
109144
unsigned long rate;
145+
int error, i;
110146

111147
data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL);
112148
if (!data)
@@ -146,7 +182,11 @@ static int cdns_ti_probe(struct platform_device *pdev)
146182
return -EINVAL;
147183
}
148184

149-
rate_code = i;
185+
data->usb2_refclk_rate_code = i;
186+
data->vbus_divider = device_property_read_bool(dev, "ti,vbus-divider");
187+
data->usb2_only = device_property_read_bool(dev, "ti,usb2-only");
188+
189+
cdns_ti_reset_and_init_hw(data);
150190

151191
pm_runtime_enable(dev);
152192
error = pm_runtime_get_sync(dev);
@@ -155,40 +195,6 @@ static int cdns_ti_probe(struct platform_device *pdev)
155195
goto err;
156196
}
157197

158-
/* assert RESET */
159-
reg = cdns_ti_readl(data, USBSS_W1);
160-
reg &= ~USBSS_W1_PWRUP_RST;
161-
cdns_ti_writel(data, USBSS_W1, reg);
162-
163-
/* set static config */
164-
reg = cdns_ti_readl(data, USBSS_STATIC_CONFIG);
165-
reg &= ~USBSS1_STATIC_PLL_REF_SEL_MASK;
166-
reg |= rate_code << USBSS1_STATIC_PLL_REF_SEL_SHIFT;
167-
168-
reg &= ~USBSS1_STATIC_VBUS_SEL_MASK;
169-
data->vbus_divider = device_property_read_bool(dev, "ti,vbus-divider");
170-
if (data->vbus_divider)
171-
reg |= 1 << USBSS1_STATIC_VBUS_SEL_SHIFT;
172-
173-
cdns_ti_writel(data, USBSS_STATIC_CONFIG, reg);
174-
reg = cdns_ti_readl(data, USBSS_STATIC_CONFIG);
175-
176-
/* set USB2_ONLY mode if requested */
177-
reg = cdns_ti_readl(data, USBSS_W1);
178-
data->usb2_only = device_property_read_bool(dev, "ti,usb2-only");
179-
if (data->usb2_only)
180-
reg |= USBSS_W1_USB2_ONLY;
181-
182-
/* set default modestrap */
183-
reg |= USBSS_W1_MODESTRAP_SEL;
184-
reg &= ~USBSS_W1_MODESTRAP_MASK;
185-
reg |= USBSS_MODESTRAP_MODE_NONE << USBSS_W1_MODESTRAP_SHIFT;
186-
cdns_ti_writel(data, USBSS_W1, reg);
187-
188-
/* de-assert RESET */
189-
reg |= USBSS_W1_PWRUP_RST;
190-
cdns_ti_writel(data, USBSS_W1, reg);
191-
192198
error = of_platform_populate(node, NULL, cdns_ti_auxdata, dev);
193199
if (error) {
194200
dev_err(dev, "failed to create children: %d\n", error);

0 commit comments

Comments
 (0)