Lines Matching +full:c +full:- +full:phy
1 // SPDX-License-Identifier: GPL-2.0+
3 * ti_usb_phy.c - USB3 and USB3 PHY programming for dwc3
5 * Copyright (C) 2015 Texas Instruments Incorporated - http://www.ti.com
9 * Taken from Linux Kernel v3.16 (drivers/phy/phy-ti-pipe3.c and
10 * drivers/phy/phy-omap-usb2.c) and ported to uboot.
12 * "commit 56042e : phy: ti-pipe3: Fix suspend/resume and module reload" for
13 * phy-ti-pipe3.c
15 * "commit eb82a3 : phy: omap-usb2: Balance pm_runtime_enable() on probe failure
16 * and remove" for phy-omap-usb2.c
21 #include <ti-usb-phy-uboot.h>
27 #include "linux-compat.h"
116 static struct usb3_dpll_params *ti_usb3_get_dpll_params(struct ti_usb_phy *phy) in ti_usb3_get_dpll_params() argument
119 struct usb3_dpll_map *dpll_map = phy->dpll_map; in ti_usb3_get_dpll_params()
123 for (; dpll_map->rate; dpll_map++) { in ti_usb3_get_dpll_params()
124 if (rate == dpll_map->rate) in ti_usb3_get_dpll_params()
125 return &dpll_map->params; in ti_usb3_get_dpll_params()
128 dev_err(phy->dev, "No DPLL configuration for %lu Hz SYS CLK\n", rate); in ti_usb3_get_dpll_params()
133 static int ti_usb3_dpll_wait_lock(struct ti_usb_phy *phy) in ti_usb3_dpll_wait_lock() argument
137 val = ti_usb3_readl(phy->pll_ctrl_base, PLL_STATUS); in ti_usb3_dpll_wait_lock()
145 static int ti_usb3_dpll_program(struct ti_usb_phy *phy) in ti_usb3_dpll_program() argument
150 if (!phy->pll_ctrl_base) in ti_usb3_dpll_program()
151 return -EINVAL; in ti_usb3_dpll_program()
153 dpll_params = ti_usb3_get_dpll_params(phy); in ti_usb3_dpll_program()
155 return -EINVAL; in ti_usb3_dpll_program()
157 val = ti_usb3_readl(phy->pll_ctrl_base, PLL_CONFIGURATION1); in ti_usb3_dpll_program()
159 val |= dpll_params->n << PLL_REGN_SHIFT; in ti_usb3_dpll_program()
160 ti_usb3_writel(phy->pll_ctrl_base, PLL_CONFIGURATION1, val); in ti_usb3_dpll_program()
162 val = ti_usb3_readl(phy->pll_ctrl_base, PLL_CONFIGURATION2); in ti_usb3_dpll_program()
164 val |= dpll_params->freq << PLL_SELFREQDCO_SHIFT; in ti_usb3_dpll_program()
165 ti_usb3_writel(phy->pll_ctrl_base, PLL_CONFIGURATION2, val); in ti_usb3_dpll_program()
167 val = ti_usb3_readl(phy->pll_ctrl_base, PLL_CONFIGURATION1); in ti_usb3_dpll_program()
169 val |= dpll_params->m << PLL_REGM_SHIFT; in ti_usb3_dpll_program()
170 ti_usb3_writel(phy->pll_ctrl_base, PLL_CONFIGURATION1, val); in ti_usb3_dpll_program()
172 val = ti_usb3_readl(phy->pll_ctrl_base, PLL_CONFIGURATION4); in ti_usb3_dpll_program()
174 val |= dpll_params->mf << PLL_REGM_F_SHIFT; in ti_usb3_dpll_program()
175 ti_usb3_writel(phy->pll_ctrl_base, PLL_CONFIGURATION4, val); in ti_usb3_dpll_program()
177 val = ti_usb3_readl(phy->pll_ctrl_base, PLL_CONFIGURATION3); in ti_usb3_dpll_program()
179 val |= dpll_params->sd << PLL_SD_SHIFT; in ti_usb3_dpll_program()
180 ti_usb3_writel(phy->pll_ctrl_base, PLL_CONFIGURATION3, val); in ti_usb3_dpll_program()
182 ti_usb3_writel(phy->pll_ctrl_base, PLL_GO, SET_PLL_GO); in ti_usb3_dpll_program()
184 return ti_usb3_dpll_wait_lock(phy); in ti_usb3_dpll_program()
188 void ti_usb2_phy_power(struct ti_usb_phy *phy, int on) in ti_usb2_phy_power() argument
192 val = readl(phy->usb2_phy_power); in ti_usb2_phy_power()
196 if (phy->index == 1) in ti_usb2_phy_power()
208 if (phy->index == 1) in ti_usb2_phy_power()
220 writel(val, phy->usb2_phy_power); in ti_usb2_phy_power()
224 void ti_usb3_phy_power(struct ti_usb_phy *phy, int on) in ti_usb3_phy_power() argument
231 if (!phy->usb3_phy_power) in ti_usb3_phy_power()
234 val = readl(phy->usb3_phy_power); in ti_usb3_phy_power()
247 writel(val, phy->usb3_phy_power); in ti_usb3_phy_power()
252 * ti_usb_phy_uboot_init - usb phy uboot initialization code
255 * Entry point for ti usb phy driver. This driver handles initialization
256 * of both usb2 phy and usb3 phy. Pointer to ti_usb_phy_device should be
264 struct ti_usb_phy *phy; in ti_usb_phy_uboot_init() local
266 phy = devm_kzalloc(NULL, sizeof(*phy), GFP_KERNEL); in ti_usb_phy_uboot_init()
267 if (!phy) { in ti_usb_phy_uboot_init()
268 dev_err(NULL, "unable to alloc mem for TI USB3 PHY\n"); in ti_usb_phy_uboot_init()
269 return -ENOMEM; in ti_usb_phy_uboot_init()
272 phy->dpll_map = dpll_map_usb; in ti_usb_phy_uboot_init()
273 phy->index = dev->index; in ti_usb_phy_uboot_init()
274 phy->pll_ctrl_base = dev->pll_ctrl_base; in ti_usb_phy_uboot_init()
275 phy->usb2_phy_power = dev->usb2_phy_power; in ti_usb_phy_uboot_init()
276 phy->usb3_phy_power = dev->usb3_phy_power; in ti_usb_phy_uboot_init()
279 ti_usb3_dpll_program(phy); in ti_usb_phy_uboot_init()
280 ti_usb3_phy_power(phy, 1); in ti_usb_phy_uboot_init()
282 ti_usb2_phy_power(phy, 1); in ti_usb_phy_uboot_init()
284 list_add_tail(&phy->list, &ti_usb_phy_list); in ti_usb_phy_uboot_init()
290 * ti_usb_phy_uboot_exit - usb phy uboot cleanup code
301 struct ti_usb_phy *phy = NULL; in ti_usb_phy_uboot_exit() local
303 list_for_each_entry(phy, &ti_usb_phy_list, list) { in ti_usb_phy_uboot_exit()
304 if (phy->index != index) in ti_usb_phy_uboot_exit()
307 ti_usb2_phy_power(phy, 0); in ti_usb_phy_uboot_exit()
309 ti_usb3_phy_power(phy, 0); in ti_usb_phy_uboot_exit()
311 list_del(&phy->list); in ti_usb_phy_uboot_exit()
312 kfree(phy); in ti_usb_phy_uboot_exit()