18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0 28c2ecf20Sopenharmony_ci/** 38c2ecf20Sopenharmony_ci * Wrapper driver for SERDES used in J721E 48c2ecf20Sopenharmony_ci * 58c2ecf20Sopenharmony_ci * Copyright (C) 2019 Texas Instruments Incorporated - http://www.ti.com/ 68c2ecf20Sopenharmony_ci * Author: Kishon Vijay Abraham I <kishon@ti.com> 78c2ecf20Sopenharmony_ci */ 88c2ecf20Sopenharmony_ci 98c2ecf20Sopenharmony_ci#include <dt-bindings/phy/phy.h> 108c2ecf20Sopenharmony_ci#include <linux/clk.h> 118c2ecf20Sopenharmony_ci#include <linux/clk-provider.h> 128c2ecf20Sopenharmony_ci#include <linux/gpio.h> 138c2ecf20Sopenharmony_ci#include <linux/gpio/consumer.h> 148c2ecf20Sopenharmony_ci#include <linux/io.h> 158c2ecf20Sopenharmony_ci#include <linux/module.h> 168c2ecf20Sopenharmony_ci#include <linux/mux/consumer.h> 178c2ecf20Sopenharmony_ci#include <linux/of_address.h> 188c2ecf20Sopenharmony_ci#include <linux/of_platform.h> 198c2ecf20Sopenharmony_ci#include <linux/platform_device.h> 208c2ecf20Sopenharmony_ci#include <linux/pm_runtime.h> 218c2ecf20Sopenharmony_ci#include <linux/regmap.h> 228c2ecf20Sopenharmony_ci#include <linux/reset-controller.h> 238c2ecf20Sopenharmony_ci 248c2ecf20Sopenharmony_ci#define WIZ_SERDES_CTRL 0x404 258c2ecf20Sopenharmony_ci#define WIZ_SERDES_TOP_CTRL 0x408 268c2ecf20Sopenharmony_ci#define WIZ_SERDES_RST 0x40c 278c2ecf20Sopenharmony_ci#define WIZ_SERDES_TYPEC 0x410 288c2ecf20Sopenharmony_ci#define WIZ_LANECTL(n) (0x480 + (0x40 * (n))) 298c2ecf20Sopenharmony_ci 308c2ecf20Sopenharmony_ci#define WIZ_MAX_LANES 4 318c2ecf20Sopenharmony_ci#define WIZ_MUX_NUM_CLOCKS 3 328c2ecf20Sopenharmony_ci#define WIZ_DIV_NUM_CLOCKS_16G 2 338c2ecf20Sopenharmony_ci#define WIZ_DIV_NUM_CLOCKS_10G 1 348c2ecf20Sopenharmony_ci 358c2ecf20Sopenharmony_ci#define WIZ_SERDES_TYPEC_LN10_SWAP BIT(30) 368c2ecf20Sopenharmony_ci 378c2ecf20Sopenharmony_cienum wiz_lane_standard_mode { 388c2ecf20Sopenharmony_ci LANE_MODE_GEN1, 398c2ecf20Sopenharmony_ci LANE_MODE_GEN2, 408c2ecf20Sopenharmony_ci LANE_MODE_GEN3, 418c2ecf20Sopenharmony_ci LANE_MODE_GEN4, 428c2ecf20Sopenharmony_ci}; 438c2ecf20Sopenharmony_ci 448c2ecf20Sopenharmony_cienum wiz_refclk_mux_sel { 458c2ecf20Sopenharmony_ci PLL0_REFCLK, 468c2ecf20Sopenharmony_ci PLL1_REFCLK, 478c2ecf20Sopenharmony_ci REFCLK_DIG, 488c2ecf20Sopenharmony_ci}; 498c2ecf20Sopenharmony_ci 508c2ecf20Sopenharmony_cienum wiz_refclk_div_sel { 518c2ecf20Sopenharmony_ci CMN_REFCLK_DIG_DIV, 528c2ecf20Sopenharmony_ci CMN_REFCLK1_DIG_DIV, 538c2ecf20Sopenharmony_ci}; 548c2ecf20Sopenharmony_ci 558c2ecf20Sopenharmony_cistatic const struct reg_field por_en = REG_FIELD(WIZ_SERDES_CTRL, 31, 31); 568c2ecf20Sopenharmony_cistatic const struct reg_field phy_reset_n = REG_FIELD(WIZ_SERDES_RST, 31, 31); 578c2ecf20Sopenharmony_cistatic const struct reg_field pll1_refclk_mux_sel = 588c2ecf20Sopenharmony_ci REG_FIELD(WIZ_SERDES_RST, 29, 29); 598c2ecf20Sopenharmony_cistatic const struct reg_field pll0_refclk_mux_sel = 608c2ecf20Sopenharmony_ci REG_FIELD(WIZ_SERDES_RST, 28, 28); 618c2ecf20Sopenharmony_cistatic const struct reg_field refclk_dig_sel_16g = 628c2ecf20Sopenharmony_ci REG_FIELD(WIZ_SERDES_RST, 24, 25); 638c2ecf20Sopenharmony_cistatic const struct reg_field refclk_dig_sel_10g = 648c2ecf20Sopenharmony_ci REG_FIELD(WIZ_SERDES_RST, 24, 24); 658c2ecf20Sopenharmony_cistatic const struct reg_field pma_cmn_refclk_int_mode = 668c2ecf20Sopenharmony_ci REG_FIELD(WIZ_SERDES_TOP_CTRL, 28, 29); 678c2ecf20Sopenharmony_cistatic const struct reg_field pma_cmn_refclk_mode = 688c2ecf20Sopenharmony_ci REG_FIELD(WIZ_SERDES_TOP_CTRL, 30, 31); 698c2ecf20Sopenharmony_cistatic const struct reg_field pma_cmn_refclk_dig_div = 708c2ecf20Sopenharmony_ci REG_FIELD(WIZ_SERDES_TOP_CTRL, 26, 27); 718c2ecf20Sopenharmony_cistatic const struct reg_field pma_cmn_refclk1_dig_div = 728c2ecf20Sopenharmony_ci REG_FIELD(WIZ_SERDES_TOP_CTRL, 24, 25); 738c2ecf20Sopenharmony_ci 748c2ecf20Sopenharmony_cistatic const struct reg_field p_enable[WIZ_MAX_LANES] = { 758c2ecf20Sopenharmony_ci REG_FIELD(WIZ_LANECTL(0), 30, 31), 768c2ecf20Sopenharmony_ci REG_FIELD(WIZ_LANECTL(1), 30, 31), 778c2ecf20Sopenharmony_ci REG_FIELD(WIZ_LANECTL(2), 30, 31), 788c2ecf20Sopenharmony_ci REG_FIELD(WIZ_LANECTL(3), 30, 31), 798c2ecf20Sopenharmony_ci}; 808c2ecf20Sopenharmony_ci 818c2ecf20Sopenharmony_cienum p_enable { P_ENABLE = 2, P_ENABLE_FORCE = 1, P_ENABLE_DISABLE = 0 }; 828c2ecf20Sopenharmony_ci 838c2ecf20Sopenharmony_cistatic const struct reg_field p_align[WIZ_MAX_LANES] = { 848c2ecf20Sopenharmony_ci REG_FIELD(WIZ_LANECTL(0), 29, 29), 858c2ecf20Sopenharmony_ci REG_FIELD(WIZ_LANECTL(1), 29, 29), 868c2ecf20Sopenharmony_ci REG_FIELD(WIZ_LANECTL(2), 29, 29), 878c2ecf20Sopenharmony_ci REG_FIELD(WIZ_LANECTL(3), 29, 29), 888c2ecf20Sopenharmony_ci}; 898c2ecf20Sopenharmony_ci 908c2ecf20Sopenharmony_cistatic const struct reg_field p_raw_auto_start[WIZ_MAX_LANES] = { 918c2ecf20Sopenharmony_ci REG_FIELD(WIZ_LANECTL(0), 28, 28), 928c2ecf20Sopenharmony_ci REG_FIELD(WIZ_LANECTL(1), 28, 28), 938c2ecf20Sopenharmony_ci REG_FIELD(WIZ_LANECTL(2), 28, 28), 948c2ecf20Sopenharmony_ci REG_FIELD(WIZ_LANECTL(3), 28, 28), 958c2ecf20Sopenharmony_ci}; 968c2ecf20Sopenharmony_ci 978c2ecf20Sopenharmony_cistatic const struct reg_field p_standard_mode[WIZ_MAX_LANES] = { 988c2ecf20Sopenharmony_ci REG_FIELD(WIZ_LANECTL(0), 24, 25), 998c2ecf20Sopenharmony_ci REG_FIELD(WIZ_LANECTL(1), 24, 25), 1008c2ecf20Sopenharmony_ci REG_FIELD(WIZ_LANECTL(2), 24, 25), 1018c2ecf20Sopenharmony_ci REG_FIELD(WIZ_LANECTL(3), 24, 25), 1028c2ecf20Sopenharmony_ci}; 1038c2ecf20Sopenharmony_ci 1048c2ecf20Sopenharmony_cistatic const struct reg_field typec_ln10_swap = 1058c2ecf20Sopenharmony_ci REG_FIELD(WIZ_SERDES_TYPEC, 30, 30); 1068c2ecf20Sopenharmony_ci 1078c2ecf20Sopenharmony_cistruct wiz_clk_mux { 1088c2ecf20Sopenharmony_ci struct clk_hw hw; 1098c2ecf20Sopenharmony_ci struct regmap_field *field; 1108c2ecf20Sopenharmony_ci u32 *table; 1118c2ecf20Sopenharmony_ci struct clk_init_data clk_data; 1128c2ecf20Sopenharmony_ci}; 1138c2ecf20Sopenharmony_ci 1148c2ecf20Sopenharmony_ci#define to_wiz_clk_mux(_hw) container_of(_hw, struct wiz_clk_mux, hw) 1158c2ecf20Sopenharmony_ci 1168c2ecf20Sopenharmony_cistruct wiz_clk_divider { 1178c2ecf20Sopenharmony_ci struct clk_hw hw; 1188c2ecf20Sopenharmony_ci struct regmap_field *field; 1198c2ecf20Sopenharmony_ci const struct clk_div_table *table; 1208c2ecf20Sopenharmony_ci struct clk_init_data clk_data; 1218c2ecf20Sopenharmony_ci}; 1228c2ecf20Sopenharmony_ci 1238c2ecf20Sopenharmony_ci#define to_wiz_clk_div(_hw) container_of(_hw, struct wiz_clk_divider, hw) 1248c2ecf20Sopenharmony_ci 1258c2ecf20Sopenharmony_cistruct wiz_clk_mux_sel { 1268c2ecf20Sopenharmony_ci struct regmap_field *field; 1278c2ecf20Sopenharmony_ci u32 table[4]; 1288c2ecf20Sopenharmony_ci const char *node_name; 1298c2ecf20Sopenharmony_ci}; 1308c2ecf20Sopenharmony_ci 1318c2ecf20Sopenharmony_cistruct wiz_clk_div_sel { 1328c2ecf20Sopenharmony_ci struct regmap_field *field; 1338c2ecf20Sopenharmony_ci const struct clk_div_table *table; 1348c2ecf20Sopenharmony_ci const char *node_name; 1358c2ecf20Sopenharmony_ci}; 1368c2ecf20Sopenharmony_ci 1378c2ecf20Sopenharmony_cistatic struct wiz_clk_mux_sel clk_mux_sel_16g[] = { 1388c2ecf20Sopenharmony_ci { 1398c2ecf20Sopenharmony_ci /* 1408c2ecf20Sopenharmony_ci * Mux value to be configured for each of the input clocks 1418c2ecf20Sopenharmony_ci * in the order populated in device tree 1428c2ecf20Sopenharmony_ci */ 1438c2ecf20Sopenharmony_ci .table = { 1, 0 }, 1448c2ecf20Sopenharmony_ci .node_name = "pll0-refclk", 1458c2ecf20Sopenharmony_ci }, 1468c2ecf20Sopenharmony_ci { 1478c2ecf20Sopenharmony_ci .table = { 1, 0 }, 1488c2ecf20Sopenharmony_ci .node_name = "pll1-refclk", 1498c2ecf20Sopenharmony_ci }, 1508c2ecf20Sopenharmony_ci { 1518c2ecf20Sopenharmony_ci .table = { 1, 3, 0, 2 }, 1528c2ecf20Sopenharmony_ci .node_name = "refclk-dig", 1538c2ecf20Sopenharmony_ci }, 1548c2ecf20Sopenharmony_ci}; 1558c2ecf20Sopenharmony_ci 1568c2ecf20Sopenharmony_cistatic struct wiz_clk_mux_sel clk_mux_sel_10g[] = { 1578c2ecf20Sopenharmony_ci { 1588c2ecf20Sopenharmony_ci /* 1598c2ecf20Sopenharmony_ci * Mux value to be configured for each of the input clocks 1608c2ecf20Sopenharmony_ci * in the order populated in device tree 1618c2ecf20Sopenharmony_ci */ 1628c2ecf20Sopenharmony_ci .table = { 1, 0 }, 1638c2ecf20Sopenharmony_ci .node_name = "pll0-refclk", 1648c2ecf20Sopenharmony_ci }, 1658c2ecf20Sopenharmony_ci { 1668c2ecf20Sopenharmony_ci .table = { 1, 0 }, 1678c2ecf20Sopenharmony_ci .node_name = "pll1-refclk", 1688c2ecf20Sopenharmony_ci }, 1698c2ecf20Sopenharmony_ci { 1708c2ecf20Sopenharmony_ci .table = { 1, 0 }, 1718c2ecf20Sopenharmony_ci .node_name = "refclk-dig", 1728c2ecf20Sopenharmony_ci }, 1738c2ecf20Sopenharmony_ci}; 1748c2ecf20Sopenharmony_ci 1758c2ecf20Sopenharmony_cistatic const struct clk_div_table clk_div_table[] = { 1768c2ecf20Sopenharmony_ci { .val = 0, .div = 1, }, 1778c2ecf20Sopenharmony_ci { .val = 1, .div = 2, }, 1788c2ecf20Sopenharmony_ci { .val = 2, .div = 4, }, 1798c2ecf20Sopenharmony_ci { .val = 3, .div = 8, }, 1808c2ecf20Sopenharmony_ci { /* sentinel */ }, 1818c2ecf20Sopenharmony_ci}; 1828c2ecf20Sopenharmony_ci 1838c2ecf20Sopenharmony_cistatic struct wiz_clk_div_sel clk_div_sel[] = { 1848c2ecf20Sopenharmony_ci { 1858c2ecf20Sopenharmony_ci .table = clk_div_table, 1868c2ecf20Sopenharmony_ci .node_name = "cmn-refclk-dig-div", 1878c2ecf20Sopenharmony_ci }, 1888c2ecf20Sopenharmony_ci { 1898c2ecf20Sopenharmony_ci .table = clk_div_table, 1908c2ecf20Sopenharmony_ci .node_name = "cmn-refclk1-dig-div", 1918c2ecf20Sopenharmony_ci }, 1928c2ecf20Sopenharmony_ci}; 1938c2ecf20Sopenharmony_ci 1948c2ecf20Sopenharmony_cienum wiz_type { 1958c2ecf20Sopenharmony_ci J721E_WIZ_16G, 1968c2ecf20Sopenharmony_ci J721E_WIZ_10G, 1978c2ecf20Sopenharmony_ci}; 1988c2ecf20Sopenharmony_ci 1998c2ecf20Sopenharmony_ci#define WIZ_TYPEC_DIR_DEBOUNCE_MIN 100 /* ms */ 2008c2ecf20Sopenharmony_ci#define WIZ_TYPEC_DIR_DEBOUNCE_MAX 1000 2018c2ecf20Sopenharmony_ci 2028c2ecf20Sopenharmony_cistruct wiz { 2038c2ecf20Sopenharmony_ci struct regmap *regmap; 2048c2ecf20Sopenharmony_ci enum wiz_type type; 2058c2ecf20Sopenharmony_ci struct wiz_clk_mux_sel *clk_mux_sel; 2068c2ecf20Sopenharmony_ci struct wiz_clk_div_sel *clk_div_sel; 2078c2ecf20Sopenharmony_ci unsigned int clk_div_sel_num; 2088c2ecf20Sopenharmony_ci struct regmap_field *por_en; 2098c2ecf20Sopenharmony_ci struct regmap_field *phy_reset_n; 2108c2ecf20Sopenharmony_ci struct regmap_field *p_enable[WIZ_MAX_LANES]; 2118c2ecf20Sopenharmony_ci struct regmap_field *p_align[WIZ_MAX_LANES]; 2128c2ecf20Sopenharmony_ci struct regmap_field *p_raw_auto_start[WIZ_MAX_LANES]; 2138c2ecf20Sopenharmony_ci struct regmap_field *p_standard_mode[WIZ_MAX_LANES]; 2148c2ecf20Sopenharmony_ci struct regmap_field *pma_cmn_refclk_int_mode; 2158c2ecf20Sopenharmony_ci struct regmap_field *pma_cmn_refclk_mode; 2168c2ecf20Sopenharmony_ci struct regmap_field *pma_cmn_refclk_dig_div; 2178c2ecf20Sopenharmony_ci struct regmap_field *pma_cmn_refclk1_dig_div; 2188c2ecf20Sopenharmony_ci struct regmap_field *typec_ln10_swap; 2198c2ecf20Sopenharmony_ci 2208c2ecf20Sopenharmony_ci struct device *dev; 2218c2ecf20Sopenharmony_ci u32 num_lanes; 2228c2ecf20Sopenharmony_ci struct platform_device *serdes_pdev; 2238c2ecf20Sopenharmony_ci struct reset_controller_dev wiz_phy_reset_dev; 2248c2ecf20Sopenharmony_ci struct gpio_desc *gpio_typec_dir; 2258c2ecf20Sopenharmony_ci int typec_dir_delay; 2268c2ecf20Sopenharmony_ci u32 lane_phy_type[WIZ_MAX_LANES]; 2278c2ecf20Sopenharmony_ci}; 2288c2ecf20Sopenharmony_ci 2298c2ecf20Sopenharmony_cistatic int wiz_reset(struct wiz *wiz) 2308c2ecf20Sopenharmony_ci{ 2318c2ecf20Sopenharmony_ci int ret; 2328c2ecf20Sopenharmony_ci 2338c2ecf20Sopenharmony_ci ret = regmap_field_write(wiz->por_en, 0x1); 2348c2ecf20Sopenharmony_ci if (ret) 2358c2ecf20Sopenharmony_ci return ret; 2368c2ecf20Sopenharmony_ci 2378c2ecf20Sopenharmony_ci mdelay(1); 2388c2ecf20Sopenharmony_ci 2398c2ecf20Sopenharmony_ci ret = regmap_field_write(wiz->por_en, 0x0); 2408c2ecf20Sopenharmony_ci if (ret) 2418c2ecf20Sopenharmony_ci return ret; 2428c2ecf20Sopenharmony_ci 2438c2ecf20Sopenharmony_ci return 0; 2448c2ecf20Sopenharmony_ci} 2458c2ecf20Sopenharmony_ci 2468c2ecf20Sopenharmony_cistatic int wiz_mode_select(struct wiz *wiz) 2478c2ecf20Sopenharmony_ci{ 2488c2ecf20Sopenharmony_ci u32 num_lanes = wiz->num_lanes; 2498c2ecf20Sopenharmony_ci enum wiz_lane_standard_mode mode; 2508c2ecf20Sopenharmony_ci int ret; 2518c2ecf20Sopenharmony_ci int i; 2528c2ecf20Sopenharmony_ci 2538c2ecf20Sopenharmony_ci for (i = 0; i < num_lanes; i++) { 2548c2ecf20Sopenharmony_ci if (wiz->lane_phy_type[i] == PHY_TYPE_DP) 2558c2ecf20Sopenharmony_ci mode = LANE_MODE_GEN1; 2568c2ecf20Sopenharmony_ci else 2578c2ecf20Sopenharmony_ci mode = LANE_MODE_GEN4; 2588c2ecf20Sopenharmony_ci 2598c2ecf20Sopenharmony_ci ret = regmap_field_write(wiz->p_standard_mode[i], mode); 2608c2ecf20Sopenharmony_ci if (ret) 2618c2ecf20Sopenharmony_ci return ret; 2628c2ecf20Sopenharmony_ci } 2638c2ecf20Sopenharmony_ci 2648c2ecf20Sopenharmony_ci return 0; 2658c2ecf20Sopenharmony_ci} 2668c2ecf20Sopenharmony_ci 2678c2ecf20Sopenharmony_cistatic int wiz_init_raw_interface(struct wiz *wiz, bool enable) 2688c2ecf20Sopenharmony_ci{ 2698c2ecf20Sopenharmony_ci u32 num_lanes = wiz->num_lanes; 2708c2ecf20Sopenharmony_ci int i; 2718c2ecf20Sopenharmony_ci int ret; 2728c2ecf20Sopenharmony_ci 2738c2ecf20Sopenharmony_ci for (i = 0; i < num_lanes; i++) { 2748c2ecf20Sopenharmony_ci ret = regmap_field_write(wiz->p_align[i], enable); 2758c2ecf20Sopenharmony_ci if (ret) 2768c2ecf20Sopenharmony_ci return ret; 2778c2ecf20Sopenharmony_ci 2788c2ecf20Sopenharmony_ci ret = regmap_field_write(wiz->p_raw_auto_start[i], enable); 2798c2ecf20Sopenharmony_ci if (ret) 2808c2ecf20Sopenharmony_ci return ret; 2818c2ecf20Sopenharmony_ci } 2828c2ecf20Sopenharmony_ci 2838c2ecf20Sopenharmony_ci return 0; 2848c2ecf20Sopenharmony_ci} 2858c2ecf20Sopenharmony_ci 2868c2ecf20Sopenharmony_cistatic int wiz_init(struct wiz *wiz) 2878c2ecf20Sopenharmony_ci{ 2888c2ecf20Sopenharmony_ci struct device *dev = wiz->dev; 2898c2ecf20Sopenharmony_ci int ret; 2908c2ecf20Sopenharmony_ci 2918c2ecf20Sopenharmony_ci ret = wiz_reset(wiz); 2928c2ecf20Sopenharmony_ci if (ret) { 2938c2ecf20Sopenharmony_ci dev_err(dev, "WIZ reset failed\n"); 2948c2ecf20Sopenharmony_ci return ret; 2958c2ecf20Sopenharmony_ci } 2968c2ecf20Sopenharmony_ci 2978c2ecf20Sopenharmony_ci ret = wiz_mode_select(wiz); 2988c2ecf20Sopenharmony_ci if (ret) { 2998c2ecf20Sopenharmony_ci dev_err(dev, "WIZ mode select failed\n"); 3008c2ecf20Sopenharmony_ci return ret; 3018c2ecf20Sopenharmony_ci } 3028c2ecf20Sopenharmony_ci 3038c2ecf20Sopenharmony_ci ret = wiz_init_raw_interface(wiz, true); 3048c2ecf20Sopenharmony_ci if (ret) { 3058c2ecf20Sopenharmony_ci dev_err(dev, "WIZ interface initialization failed\n"); 3068c2ecf20Sopenharmony_ci return ret; 3078c2ecf20Sopenharmony_ci } 3088c2ecf20Sopenharmony_ci 3098c2ecf20Sopenharmony_ci return 0; 3108c2ecf20Sopenharmony_ci} 3118c2ecf20Sopenharmony_ci 3128c2ecf20Sopenharmony_cistatic int wiz_regfield_init(struct wiz *wiz) 3138c2ecf20Sopenharmony_ci{ 3148c2ecf20Sopenharmony_ci struct wiz_clk_mux_sel *clk_mux_sel; 3158c2ecf20Sopenharmony_ci struct wiz_clk_div_sel *clk_div_sel; 3168c2ecf20Sopenharmony_ci struct regmap *regmap = wiz->regmap; 3178c2ecf20Sopenharmony_ci int num_lanes = wiz->num_lanes; 3188c2ecf20Sopenharmony_ci struct device *dev = wiz->dev; 3198c2ecf20Sopenharmony_ci int i; 3208c2ecf20Sopenharmony_ci 3218c2ecf20Sopenharmony_ci wiz->por_en = devm_regmap_field_alloc(dev, regmap, por_en); 3228c2ecf20Sopenharmony_ci if (IS_ERR(wiz->por_en)) { 3238c2ecf20Sopenharmony_ci dev_err(dev, "POR_EN reg field init failed\n"); 3248c2ecf20Sopenharmony_ci return PTR_ERR(wiz->por_en); 3258c2ecf20Sopenharmony_ci } 3268c2ecf20Sopenharmony_ci 3278c2ecf20Sopenharmony_ci wiz->phy_reset_n = devm_regmap_field_alloc(dev, regmap, 3288c2ecf20Sopenharmony_ci phy_reset_n); 3298c2ecf20Sopenharmony_ci if (IS_ERR(wiz->phy_reset_n)) { 3308c2ecf20Sopenharmony_ci dev_err(dev, "PHY_RESET_N reg field init failed\n"); 3318c2ecf20Sopenharmony_ci return PTR_ERR(wiz->phy_reset_n); 3328c2ecf20Sopenharmony_ci } 3338c2ecf20Sopenharmony_ci 3348c2ecf20Sopenharmony_ci wiz->pma_cmn_refclk_int_mode = 3358c2ecf20Sopenharmony_ci devm_regmap_field_alloc(dev, regmap, pma_cmn_refclk_int_mode); 3368c2ecf20Sopenharmony_ci if (IS_ERR(wiz->pma_cmn_refclk_int_mode)) { 3378c2ecf20Sopenharmony_ci dev_err(dev, "PMA_CMN_REFCLK_INT_MODE reg field init failed\n"); 3388c2ecf20Sopenharmony_ci return PTR_ERR(wiz->pma_cmn_refclk_int_mode); 3398c2ecf20Sopenharmony_ci } 3408c2ecf20Sopenharmony_ci 3418c2ecf20Sopenharmony_ci wiz->pma_cmn_refclk_mode = 3428c2ecf20Sopenharmony_ci devm_regmap_field_alloc(dev, regmap, pma_cmn_refclk_mode); 3438c2ecf20Sopenharmony_ci if (IS_ERR(wiz->pma_cmn_refclk_mode)) { 3448c2ecf20Sopenharmony_ci dev_err(dev, "PMA_CMN_REFCLK_MODE reg field init failed\n"); 3458c2ecf20Sopenharmony_ci return PTR_ERR(wiz->pma_cmn_refclk_mode); 3468c2ecf20Sopenharmony_ci } 3478c2ecf20Sopenharmony_ci 3488c2ecf20Sopenharmony_ci clk_div_sel = &wiz->clk_div_sel[CMN_REFCLK_DIG_DIV]; 3498c2ecf20Sopenharmony_ci clk_div_sel->field = devm_regmap_field_alloc(dev, regmap, 3508c2ecf20Sopenharmony_ci pma_cmn_refclk_dig_div); 3518c2ecf20Sopenharmony_ci if (IS_ERR(clk_div_sel->field)) { 3528c2ecf20Sopenharmony_ci dev_err(dev, "PMA_CMN_REFCLK_DIG_DIV reg field init failed\n"); 3538c2ecf20Sopenharmony_ci return PTR_ERR(clk_div_sel->field); 3548c2ecf20Sopenharmony_ci } 3558c2ecf20Sopenharmony_ci 3568c2ecf20Sopenharmony_ci if (wiz->type == J721E_WIZ_16G) { 3578c2ecf20Sopenharmony_ci clk_div_sel = &wiz->clk_div_sel[CMN_REFCLK1_DIG_DIV]; 3588c2ecf20Sopenharmony_ci clk_div_sel->field = 3598c2ecf20Sopenharmony_ci devm_regmap_field_alloc(dev, regmap, 3608c2ecf20Sopenharmony_ci pma_cmn_refclk1_dig_div); 3618c2ecf20Sopenharmony_ci if (IS_ERR(clk_div_sel->field)) { 3628c2ecf20Sopenharmony_ci dev_err(dev, "PMA_CMN_REFCLK1_DIG_DIV reg field init failed\n"); 3638c2ecf20Sopenharmony_ci return PTR_ERR(clk_div_sel->field); 3648c2ecf20Sopenharmony_ci } 3658c2ecf20Sopenharmony_ci } 3668c2ecf20Sopenharmony_ci 3678c2ecf20Sopenharmony_ci clk_mux_sel = &wiz->clk_mux_sel[PLL0_REFCLK]; 3688c2ecf20Sopenharmony_ci clk_mux_sel->field = devm_regmap_field_alloc(dev, regmap, 3698c2ecf20Sopenharmony_ci pll0_refclk_mux_sel); 3708c2ecf20Sopenharmony_ci if (IS_ERR(clk_mux_sel->field)) { 3718c2ecf20Sopenharmony_ci dev_err(dev, "PLL0_REFCLK_SEL reg field init failed\n"); 3728c2ecf20Sopenharmony_ci return PTR_ERR(clk_mux_sel->field); 3738c2ecf20Sopenharmony_ci } 3748c2ecf20Sopenharmony_ci 3758c2ecf20Sopenharmony_ci clk_mux_sel = &wiz->clk_mux_sel[PLL1_REFCLK]; 3768c2ecf20Sopenharmony_ci clk_mux_sel->field = devm_regmap_field_alloc(dev, regmap, 3778c2ecf20Sopenharmony_ci pll1_refclk_mux_sel); 3788c2ecf20Sopenharmony_ci if (IS_ERR(clk_mux_sel->field)) { 3798c2ecf20Sopenharmony_ci dev_err(dev, "PLL1_REFCLK_SEL reg field init failed\n"); 3808c2ecf20Sopenharmony_ci return PTR_ERR(clk_mux_sel->field); 3818c2ecf20Sopenharmony_ci } 3828c2ecf20Sopenharmony_ci 3838c2ecf20Sopenharmony_ci clk_mux_sel = &wiz->clk_mux_sel[REFCLK_DIG]; 3848c2ecf20Sopenharmony_ci if (wiz->type == J721E_WIZ_10G) 3858c2ecf20Sopenharmony_ci clk_mux_sel->field = 3868c2ecf20Sopenharmony_ci devm_regmap_field_alloc(dev, regmap, 3878c2ecf20Sopenharmony_ci refclk_dig_sel_10g); 3888c2ecf20Sopenharmony_ci else 3898c2ecf20Sopenharmony_ci clk_mux_sel->field = 3908c2ecf20Sopenharmony_ci devm_regmap_field_alloc(dev, regmap, 3918c2ecf20Sopenharmony_ci refclk_dig_sel_16g); 3928c2ecf20Sopenharmony_ci 3938c2ecf20Sopenharmony_ci if (IS_ERR(clk_mux_sel->field)) { 3948c2ecf20Sopenharmony_ci dev_err(dev, "REFCLK_DIG_SEL reg field init failed\n"); 3958c2ecf20Sopenharmony_ci return PTR_ERR(clk_mux_sel->field); 3968c2ecf20Sopenharmony_ci } 3978c2ecf20Sopenharmony_ci 3988c2ecf20Sopenharmony_ci for (i = 0; i < num_lanes; i++) { 3998c2ecf20Sopenharmony_ci wiz->p_enable[i] = devm_regmap_field_alloc(dev, regmap, 4008c2ecf20Sopenharmony_ci p_enable[i]); 4018c2ecf20Sopenharmony_ci if (IS_ERR(wiz->p_enable[i])) { 4028c2ecf20Sopenharmony_ci dev_err(dev, "P%d_ENABLE reg field init failed\n", i); 4038c2ecf20Sopenharmony_ci return PTR_ERR(wiz->p_enable[i]); 4048c2ecf20Sopenharmony_ci } 4058c2ecf20Sopenharmony_ci 4068c2ecf20Sopenharmony_ci wiz->p_align[i] = devm_regmap_field_alloc(dev, regmap, 4078c2ecf20Sopenharmony_ci p_align[i]); 4088c2ecf20Sopenharmony_ci if (IS_ERR(wiz->p_align[i])) { 4098c2ecf20Sopenharmony_ci dev_err(dev, "P%d_ALIGN reg field init failed\n", i); 4108c2ecf20Sopenharmony_ci return PTR_ERR(wiz->p_align[i]); 4118c2ecf20Sopenharmony_ci } 4128c2ecf20Sopenharmony_ci 4138c2ecf20Sopenharmony_ci wiz->p_raw_auto_start[i] = 4148c2ecf20Sopenharmony_ci devm_regmap_field_alloc(dev, regmap, p_raw_auto_start[i]); 4158c2ecf20Sopenharmony_ci if (IS_ERR(wiz->p_raw_auto_start[i])) { 4168c2ecf20Sopenharmony_ci dev_err(dev, "P%d_RAW_AUTO_START reg field init fail\n", 4178c2ecf20Sopenharmony_ci i); 4188c2ecf20Sopenharmony_ci return PTR_ERR(wiz->p_raw_auto_start[i]); 4198c2ecf20Sopenharmony_ci } 4208c2ecf20Sopenharmony_ci 4218c2ecf20Sopenharmony_ci wiz->p_standard_mode[i] = 4228c2ecf20Sopenharmony_ci devm_regmap_field_alloc(dev, regmap, p_standard_mode[i]); 4238c2ecf20Sopenharmony_ci if (IS_ERR(wiz->p_standard_mode[i])) { 4248c2ecf20Sopenharmony_ci dev_err(dev, "P%d_STANDARD_MODE reg field init fail\n", 4258c2ecf20Sopenharmony_ci i); 4268c2ecf20Sopenharmony_ci return PTR_ERR(wiz->p_standard_mode[i]); 4278c2ecf20Sopenharmony_ci } 4288c2ecf20Sopenharmony_ci } 4298c2ecf20Sopenharmony_ci 4308c2ecf20Sopenharmony_ci wiz->typec_ln10_swap = devm_regmap_field_alloc(dev, regmap, 4318c2ecf20Sopenharmony_ci typec_ln10_swap); 4328c2ecf20Sopenharmony_ci if (IS_ERR(wiz->typec_ln10_swap)) { 4338c2ecf20Sopenharmony_ci dev_err(dev, "LN10_SWAP reg field init failed\n"); 4348c2ecf20Sopenharmony_ci return PTR_ERR(wiz->typec_ln10_swap); 4358c2ecf20Sopenharmony_ci } 4368c2ecf20Sopenharmony_ci 4378c2ecf20Sopenharmony_ci return 0; 4388c2ecf20Sopenharmony_ci} 4398c2ecf20Sopenharmony_ci 4408c2ecf20Sopenharmony_cistatic u8 wiz_clk_mux_get_parent(struct clk_hw *hw) 4418c2ecf20Sopenharmony_ci{ 4428c2ecf20Sopenharmony_ci struct wiz_clk_mux *mux = to_wiz_clk_mux(hw); 4438c2ecf20Sopenharmony_ci struct regmap_field *field = mux->field; 4448c2ecf20Sopenharmony_ci unsigned int val; 4458c2ecf20Sopenharmony_ci 4468c2ecf20Sopenharmony_ci regmap_field_read(field, &val); 4478c2ecf20Sopenharmony_ci return clk_mux_val_to_index(hw, mux->table, 0, val); 4488c2ecf20Sopenharmony_ci} 4498c2ecf20Sopenharmony_ci 4508c2ecf20Sopenharmony_cistatic int wiz_clk_mux_set_parent(struct clk_hw *hw, u8 index) 4518c2ecf20Sopenharmony_ci{ 4528c2ecf20Sopenharmony_ci struct wiz_clk_mux *mux = to_wiz_clk_mux(hw); 4538c2ecf20Sopenharmony_ci struct regmap_field *field = mux->field; 4548c2ecf20Sopenharmony_ci int val; 4558c2ecf20Sopenharmony_ci 4568c2ecf20Sopenharmony_ci val = mux->table[index]; 4578c2ecf20Sopenharmony_ci return regmap_field_write(field, val); 4588c2ecf20Sopenharmony_ci} 4598c2ecf20Sopenharmony_ci 4608c2ecf20Sopenharmony_cistatic const struct clk_ops wiz_clk_mux_ops = { 4618c2ecf20Sopenharmony_ci .set_parent = wiz_clk_mux_set_parent, 4628c2ecf20Sopenharmony_ci .get_parent = wiz_clk_mux_get_parent, 4638c2ecf20Sopenharmony_ci}; 4648c2ecf20Sopenharmony_ci 4658c2ecf20Sopenharmony_cistatic int wiz_mux_clk_register(struct wiz *wiz, struct device_node *node, 4668c2ecf20Sopenharmony_ci struct regmap_field *field, u32 *table) 4678c2ecf20Sopenharmony_ci{ 4688c2ecf20Sopenharmony_ci struct device *dev = wiz->dev; 4698c2ecf20Sopenharmony_ci struct clk_init_data *init; 4708c2ecf20Sopenharmony_ci const char **parent_names; 4718c2ecf20Sopenharmony_ci unsigned int num_parents; 4728c2ecf20Sopenharmony_ci struct wiz_clk_mux *mux; 4738c2ecf20Sopenharmony_ci char clk_name[100]; 4748c2ecf20Sopenharmony_ci struct clk *clk; 4758c2ecf20Sopenharmony_ci int ret; 4768c2ecf20Sopenharmony_ci 4778c2ecf20Sopenharmony_ci mux = devm_kzalloc(dev, sizeof(*mux), GFP_KERNEL); 4788c2ecf20Sopenharmony_ci if (!mux) 4798c2ecf20Sopenharmony_ci return -ENOMEM; 4808c2ecf20Sopenharmony_ci 4818c2ecf20Sopenharmony_ci num_parents = of_clk_get_parent_count(node); 4828c2ecf20Sopenharmony_ci if (num_parents < 2) { 4838c2ecf20Sopenharmony_ci dev_err(dev, "SERDES clock must have parents\n"); 4848c2ecf20Sopenharmony_ci return -EINVAL; 4858c2ecf20Sopenharmony_ci } 4868c2ecf20Sopenharmony_ci 4878c2ecf20Sopenharmony_ci parent_names = devm_kzalloc(dev, (sizeof(char *) * num_parents), 4888c2ecf20Sopenharmony_ci GFP_KERNEL); 4898c2ecf20Sopenharmony_ci if (!parent_names) 4908c2ecf20Sopenharmony_ci return -ENOMEM; 4918c2ecf20Sopenharmony_ci 4928c2ecf20Sopenharmony_ci of_clk_parent_fill(node, parent_names, num_parents); 4938c2ecf20Sopenharmony_ci 4948c2ecf20Sopenharmony_ci snprintf(clk_name, sizeof(clk_name), "%s_%s", dev_name(dev), 4958c2ecf20Sopenharmony_ci node->name); 4968c2ecf20Sopenharmony_ci 4978c2ecf20Sopenharmony_ci init = &mux->clk_data; 4988c2ecf20Sopenharmony_ci 4998c2ecf20Sopenharmony_ci init->ops = &wiz_clk_mux_ops; 5008c2ecf20Sopenharmony_ci init->flags = CLK_SET_RATE_NO_REPARENT; 5018c2ecf20Sopenharmony_ci init->parent_names = parent_names; 5028c2ecf20Sopenharmony_ci init->num_parents = num_parents; 5038c2ecf20Sopenharmony_ci init->name = clk_name; 5048c2ecf20Sopenharmony_ci 5058c2ecf20Sopenharmony_ci mux->field = field; 5068c2ecf20Sopenharmony_ci mux->table = table; 5078c2ecf20Sopenharmony_ci mux->hw.init = init; 5088c2ecf20Sopenharmony_ci 5098c2ecf20Sopenharmony_ci clk = devm_clk_register(dev, &mux->hw); 5108c2ecf20Sopenharmony_ci if (IS_ERR(clk)) 5118c2ecf20Sopenharmony_ci return PTR_ERR(clk); 5128c2ecf20Sopenharmony_ci 5138c2ecf20Sopenharmony_ci ret = of_clk_add_provider(node, of_clk_src_simple_get, clk); 5148c2ecf20Sopenharmony_ci if (ret) 5158c2ecf20Sopenharmony_ci dev_err(dev, "Failed to add clock provider: %s\n", clk_name); 5168c2ecf20Sopenharmony_ci 5178c2ecf20Sopenharmony_ci return ret; 5188c2ecf20Sopenharmony_ci} 5198c2ecf20Sopenharmony_ci 5208c2ecf20Sopenharmony_cistatic unsigned long wiz_clk_div_recalc_rate(struct clk_hw *hw, 5218c2ecf20Sopenharmony_ci unsigned long parent_rate) 5228c2ecf20Sopenharmony_ci{ 5238c2ecf20Sopenharmony_ci struct wiz_clk_divider *div = to_wiz_clk_div(hw); 5248c2ecf20Sopenharmony_ci struct regmap_field *field = div->field; 5258c2ecf20Sopenharmony_ci int val; 5268c2ecf20Sopenharmony_ci 5278c2ecf20Sopenharmony_ci regmap_field_read(field, &val); 5288c2ecf20Sopenharmony_ci 5298c2ecf20Sopenharmony_ci return divider_recalc_rate(hw, parent_rate, val, div->table, 0x0, 2); 5308c2ecf20Sopenharmony_ci} 5318c2ecf20Sopenharmony_ci 5328c2ecf20Sopenharmony_cistatic long wiz_clk_div_round_rate(struct clk_hw *hw, unsigned long rate, 5338c2ecf20Sopenharmony_ci unsigned long *prate) 5348c2ecf20Sopenharmony_ci{ 5358c2ecf20Sopenharmony_ci struct wiz_clk_divider *div = to_wiz_clk_div(hw); 5368c2ecf20Sopenharmony_ci 5378c2ecf20Sopenharmony_ci return divider_round_rate(hw, rate, prate, div->table, 2, 0x0); 5388c2ecf20Sopenharmony_ci} 5398c2ecf20Sopenharmony_ci 5408c2ecf20Sopenharmony_cistatic int wiz_clk_div_set_rate(struct clk_hw *hw, unsigned long rate, 5418c2ecf20Sopenharmony_ci unsigned long parent_rate) 5428c2ecf20Sopenharmony_ci{ 5438c2ecf20Sopenharmony_ci struct wiz_clk_divider *div = to_wiz_clk_div(hw); 5448c2ecf20Sopenharmony_ci struct regmap_field *field = div->field; 5458c2ecf20Sopenharmony_ci int val; 5468c2ecf20Sopenharmony_ci 5478c2ecf20Sopenharmony_ci val = divider_get_val(rate, parent_rate, div->table, 2, 0x0); 5488c2ecf20Sopenharmony_ci if (val < 0) 5498c2ecf20Sopenharmony_ci return val; 5508c2ecf20Sopenharmony_ci 5518c2ecf20Sopenharmony_ci return regmap_field_write(field, val); 5528c2ecf20Sopenharmony_ci} 5538c2ecf20Sopenharmony_ci 5548c2ecf20Sopenharmony_cistatic const struct clk_ops wiz_clk_div_ops = { 5558c2ecf20Sopenharmony_ci .recalc_rate = wiz_clk_div_recalc_rate, 5568c2ecf20Sopenharmony_ci .round_rate = wiz_clk_div_round_rate, 5578c2ecf20Sopenharmony_ci .set_rate = wiz_clk_div_set_rate, 5588c2ecf20Sopenharmony_ci}; 5598c2ecf20Sopenharmony_ci 5608c2ecf20Sopenharmony_cistatic int wiz_div_clk_register(struct wiz *wiz, struct device_node *node, 5618c2ecf20Sopenharmony_ci struct regmap_field *field, 5628c2ecf20Sopenharmony_ci const struct clk_div_table *table) 5638c2ecf20Sopenharmony_ci{ 5648c2ecf20Sopenharmony_ci struct device *dev = wiz->dev; 5658c2ecf20Sopenharmony_ci struct wiz_clk_divider *div; 5668c2ecf20Sopenharmony_ci struct clk_init_data *init; 5678c2ecf20Sopenharmony_ci const char **parent_names; 5688c2ecf20Sopenharmony_ci char clk_name[100]; 5698c2ecf20Sopenharmony_ci struct clk *clk; 5708c2ecf20Sopenharmony_ci int ret; 5718c2ecf20Sopenharmony_ci 5728c2ecf20Sopenharmony_ci div = devm_kzalloc(dev, sizeof(*div), GFP_KERNEL); 5738c2ecf20Sopenharmony_ci if (!div) 5748c2ecf20Sopenharmony_ci return -ENOMEM; 5758c2ecf20Sopenharmony_ci 5768c2ecf20Sopenharmony_ci snprintf(clk_name, sizeof(clk_name), "%s_%s", dev_name(dev), 5778c2ecf20Sopenharmony_ci node->name); 5788c2ecf20Sopenharmony_ci 5798c2ecf20Sopenharmony_ci parent_names = devm_kzalloc(dev, sizeof(char *), GFP_KERNEL); 5808c2ecf20Sopenharmony_ci if (!parent_names) 5818c2ecf20Sopenharmony_ci return -ENOMEM; 5828c2ecf20Sopenharmony_ci 5838c2ecf20Sopenharmony_ci of_clk_parent_fill(node, parent_names, 1); 5848c2ecf20Sopenharmony_ci 5858c2ecf20Sopenharmony_ci init = &div->clk_data; 5868c2ecf20Sopenharmony_ci 5878c2ecf20Sopenharmony_ci init->ops = &wiz_clk_div_ops; 5888c2ecf20Sopenharmony_ci init->flags = 0; 5898c2ecf20Sopenharmony_ci init->parent_names = parent_names; 5908c2ecf20Sopenharmony_ci init->num_parents = 1; 5918c2ecf20Sopenharmony_ci init->name = clk_name; 5928c2ecf20Sopenharmony_ci 5938c2ecf20Sopenharmony_ci div->field = field; 5948c2ecf20Sopenharmony_ci div->table = table; 5958c2ecf20Sopenharmony_ci div->hw.init = init; 5968c2ecf20Sopenharmony_ci 5978c2ecf20Sopenharmony_ci clk = devm_clk_register(dev, &div->hw); 5988c2ecf20Sopenharmony_ci if (IS_ERR(clk)) 5998c2ecf20Sopenharmony_ci return PTR_ERR(clk); 6008c2ecf20Sopenharmony_ci 6018c2ecf20Sopenharmony_ci ret = of_clk_add_provider(node, of_clk_src_simple_get, clk); 6028c2ecf20Sopenharmony_ci if (ret) 6038c2ecf20Sopenharmony_ci dev_err(dev, "Failed to add clock provider: %s\n", clk_name); 6048c2ecf20Sopenharmony_ci 6058c2ecf20Sopenharmony_ci return ret; 6068c2ecf20Sopenharmony_ci} 6078c2ecf20Sopenharmony_ci 6088c2ecf20Sopenharmony_cistatic void wiz_clock_cleanup(struct wiz *wiz, struct device_node *node) 6098c2ecf20Sopenharmony_ci{ 6108c2ecf20Sopenharmony_ci struct wiz_clk_mux_sel *clk_mux_sel = wiz->clk_mux_sel; 6118c2ecf20Sopenharmony_ci struct device_node *clk_node; 6128c2ecf20Sopenharmony_ci int i; 6138c2ecf20Sopenharmony_ci 6148c2ecf20Sopenharmony_ci for (i = 0; i < WIZ_MUX_NUM_CLOCKS; i++) { 6158c2ecf20Sopenharmony_ci clk_node = of_get_child_by_name(node, clk_mux_sel[i].node_name); 6168c2ecf20Sopenharmony_ci of_clk_del_provider(clk_node); 6178c2ecf20Sopenharmony_ci of_node_put(clk_node); 6188c2ecf20Sopenharmony_ci } 6198c2ecf20Sopenharmony_ci 6208c2ecf20Sopenharmony_ci for (i = 0; i < wiz->clk_div_sel_num; i++) { 6218c2ecf20Sopenharmony_ci clk_node = of_get_child_by_name(node, clk_div_sel[i].node_name); 6228c2ecf20Sopenharmony_ci of_clk_del_provider(clk_node); 6238c2ecf20Sopenharmony_ci of_node_put(clk_node); 6248c2ecf20Sopenharmony_ci } 6258c2ecf20Sopenharmony_ci} 6268c2ecf20Sopenharmony_ci 6278c2ecf20Sopenharmony_cistatic int wiz_clock_init(struct wiz *wiz, struct device_node *node) 6288c2ecf20Sopenharmony_ci{ 6298c2ecf20Sopenharmony_ci struct wiz_clk_mux_sel *clk_mux_sel = wiz->clk_mux_sel; 6308c2ecf20Sopenharmony_ci struct device *dev = wiz->dev; 6318c2ecf20Sopenharmony_ci struct device_node *clk_node; 6328c2ecf20Sopenharmony_ci const char *node_name; 6338c2ecf20Sopenharmony_ci unsigned long rate; 6348c2ecf20Sopenharmony_ci struct clk *clk; 6358c2ecf20Sopenharmony_ci int ret; 6368c2ecf20Sopenharmony_ci int i; 6378c2ecf20Sopenharmony_ci 6388c2ecf20Sopenharmony_ci clk = devm_clk_get(dev, "core_ref_clk"); 6398c2ecf20Sopenharmony_ci if (IS_ERR(clk)) { 6408c2ecf20Sopenharmony_ci dev_err(dev, "core_ref_clk clock not found\n"); 6418c2ecf20Sopenharmony_ci ret = PTR_ERR(clk); 6428c2ecf20Sopenharmony_ci return ret; 6438c2ecf20Sopenharmony_ci } 6448c2ecf20Sopenharmony_ci 6458c2ecf20Sopenharmony_ci rate = clk_get_rate(clk); 6468c2ecf20Sopenharmony_ci if (rate >= 100000000) 6478c2ecf20Sopenharmony_ci regmap_field_write(wiz->pma_cmn_refclk_int_mode, 0x1); 6488c2ecf20Sopenharmony_ci else 6498c2ecf20Sopenharmony_ci regmap_field_write(wiz->pma_cmn_refclk_int_mode, 0x3); 6508c2ecf20Sopenharmony_ci 6518c2ecf20Sopenharmony_ci clk = devm_clk_get(dev, "ext_ref_clk"); 6528c2ecf20Sopenharmony_ci if (IS_ERR(clk)) { 6538c2ecf20Sopenharmony_ci dev_err(dev, "ext_ref_clk clock not found\n"); 6548c2ecf20Sopenharmony_ci ret = PTR_ERR(clk); 6558c2ecf20Sopenharmony_ci return ret; 6568c2ecf20Sopenharmony_ci } 6578c2ecf20Sopenharmony_ci 6588c2ecf20Sopenharmony_ci rate = clk_get_rate(clk); 6598c2ecf20Sopenharmony_ci if (rate >= 100000000) 6608c2ecf20Sopenharmony_ci regmap_field_write(wiz->pma_cmn_refclk_mode, 0x0); 6618c2ecf20Sopenharmony_ci else 6628c2ecf20Sopenharmony_ci regmap_field_write(wiz->pma_cmn_refclk_mode, 0x2); 6638c2ecf20Sopenharmony_ci 6648c2ecf20Sopenharmony_ci for (i = 0; i < WIZ_MUX_NUM_CLOCKS; i++) { 6658c2ecf20Sopenharmony_ci node_name = clk_mux_sel[i].node_name; 6668c2ecf20Sopenharmony_ci clk_node = of_get_child_by_name(node, node_name); 6678c2ecf20Sopenharmony_ci if (!clk_node) { 6688c2ecf20Sopenharmony_ci dev_err(dev, "Unable to get %s node\n", node_name); 6698c2ecf20Sopenharmony_ci ret = -EINVAL; 6708c2ecf20Sopenharmony_ci goto err; 6718c2ecf20Sopenharmony_ci } 6728c2ecf20Sopenharmony_ci 6738c2ecf20Sopenharmony_ci ret = wiz_mux_clk_register(wiz, clk_node, clk_mux_sel[i].field, 6748c2ecf20Sopenharmony_ci clk_mux_sel[i].table); 6758c2ecf20Sopenharmony_ci if (ret) { 6768c2ecf20Sopenharmony_ci dev_err(dev, "Failed to register %s clock\n", 6778c2ecf20Sopenharmony_ci node_name); 6788c2ecf20Sopenharmony_ci of_node_put(clk_node); 6798c2ecf20Sopenharmony_ci goto err; 6808c2ecf20Sopenharmony_ci } 6818c2ecf20Sopenharmony_ci 6828c2ecf20Sopenharmony_ci of_node_put(clk_node); 6838c2ecf20Sopenharmony_ci } 6848c2ecf20Sopenharmony_ci 6858c2ecf20Sopenharmony_ci for (i = 0; i < wiz->clk_div_sel_num; i++) { 6868c2ecf20Sopenharmony_ci node_name = clk_div_sel[i].node_name; 6878c2ecf20Sopenharmony_ci clk_node = of_get_child_by_name(node, node_name); 6888c2ecf20Sopenharmony_ci if (!clk_node) { 6898c2ecf20Sopenharmony_ci dev_err(dev, "Unable to get %s node\n", node_name); 6908c2ecf20Sopenharmony_ci ret = -EINVAL; 6918c2ecf20Sopenharmony_ci goto err; 6928c2ecf20Sopenharmony_ci } 6938c2ecf20Sopenharmony_ci 6948c2ecf20Sopenharmony_ci ret = wiz_div_clk_register(wiz, clk_node, clk_div_sel[i].field, 6958c2ecf20Sopenharmony_ci clk_div_sel[i].table); 6968c2ecf20Sopenharmony_ci if (ret) { 6978c2ecf20Sopenharmony_ci dev_err(dev, "Failed to register %s clock\n", 6988c2ecf20Sopenharmony_ci node_name); 6998c2ecf20Sopenharmony_ci of_node_put(clk_node); 7008c2ecf20Sopenharmony_ci goto err; 7018c2ecf20Sopenharmony_ci } 7028c2ecf20Sopenharmony_ci 7038c2ecf20Sopenharmony_ci of_node_put(clk_node); 7048c2ecf20Sopenharmony_ci } 7058c2ecf20Sopenharmony_ci 7068c2ecf20Sopenharmony_ci return 0; 7078c2ecf20Sopenharmony_cierr: 7088c2ecf20Sopenharmony_ci wiz_clock_cleanup(wiz, node); 7098c2ecf20Sopenharmony_ci 7108c2ecf20Sopenharmony_ci return ret; 7118c2ecf20Sopenharmony_ci} 7128c2ecf20Sopenharmony_ci 7138c2ecf20Sopenharmony_cistatic int wiz_phy_reset_assert(struct reset_controller_dev *rcdev, 7148c2ecf20Sopenharmony_ci unsigned long id) 7158c2ecf20Sopenharmony_ci{ 7168c2ecf20Sopenharmony_ci struct device *dev = rcdev->dev; 7178c2ecf20Sopenharmony_ci struct wiz *wiz = dev_get_drvdata(dev); 7188c2ecf20Sopenharmony_ci int ret = 0; 7198c2ecf20Sopenharmony_ci 7208c2ecf20Sopenharmony_ci if (id == 0) { 7218c2ecf20Sopenharmony_ci ret = regmap_field_write(wiz->phy_reset_n, false); 7228c2ecf20Sopenharmony_ci return ret; 7238c2ecf20Sopenharmony_ci } 7248c2ecf20Sopenharmony_ci 7258c2ecf20Sopenharmony_ci ret = regmap_field_write(wiz->p_enable[id - 1], P_ENABLE_DISABLE); 7268c2ecf20Sopenharmony_ci return ret; 7278c2ecf20Sopenharmony_ci} 7288c2ecf20Sopenharmony_ci 7298c2ecf20Sopenharmony_cistatic int wiz_phy_reset_deassert(struct reset_controller_dev *rcdev, 7308c2ecf20Sopenharmony_ci unsigned long id) 7318c2ecf20Sopenharmony_ci{ 7328c2ecf20Sopenharmony_ci struct device *dev = rcdev->dev; 7338c2ecf20Sopenharmony_ci struct wiz *wiz = dev_get_drvdata(dev); 7348c2ecf20Sopenharmony_ci int ret; 7358c2ecf20Sopenharmony_ci 7368c2ecf20Sopenharmony_ci /* if typec-dir gpio was specified, set LN10 SWAP bit based on that */ 7378c2ecf20Sopenharmony_ci if (id == 0 && wiz->gpio_typec_dir) { 7388c2ecf20Sopenharmony_ci if (wiz->typec_dir_delay) 7398c2ecf20Sopenharmony_ci msleep_interruptible(wiz->typec_dir_delay); 7408c2ecf20Sopenharmony_ci 7418c2ecf20Sopenharmony_ci if (gpiod_get_value_cansleep(wiz->gpio_typec_dir)) 7428c2ecf20Sopenharmony_ci regmap_field_write(wiz->typec_ln10_swap, 1); 7438c2ecf20Sopenharmony_ci else 7448c2ecf20Sopenharmony_ci regmap_field_write(wiz->typec_ln10_swap, 0); 7458c2ecf20Sopenharmony_ci } 7468c2ecf20Sopenharmony_ci 7478c2ecf20Sopenharmony_ci if (id == 0) { 7488c2ecf20Sopenharmony_ci ret = regmap_field_write(wiz->phy_reset_n, true); 7498c2ecf20Sopenharmony_ci return ret; 7508c2ecf20Sopenharmony_ci } 7518c2ecf20Sopenharmony_ci 7528c2ecf20Sopenharmony_ci if (wiz->lane_phy_type[id - 1] == PHY_TYPE_DP) 7538c2ecf20Sopenharmony_ci ret = regmap_field_write(wiz->p_enable[id - 1], P_ENABLE); 7548c2ecf20Sopenharmony_ci else 7558c2ecf20Sopenharmony_ci ret = regmap_field_write(wiz->p_enable[id - 1], P_ENABLE_FORCE); 7568c2ecf20Sopenharmony_ci 7578c2ecf20Sopenharmony_ci return ret; 7588c2ecf20Sopenharmony_ci} 7598c2ecf20Sopenharmony_ci 7608c2ecf20Sopenharmony_cistatic const struct reset_control_ops wiz_phy_reset_ops = { 7618c2ecf20Sopenharmony_ci .assert = wiz_phy_reset_assert, 7628c2ecf20Sopenharmony_ci .deassert = wiz_phy_reset_deassert, 7638c2ecf20Sopenharmony_ci}; 7648c2ecf20Sopenharmony_ci 7658c2ecf20Sopenharmony_cistatic const struct regmap_config wiz_regmap_config = { 7668c2ecf20Sopenharmony_ci .reg_bits = 32, 7678c2ecf20Sopenharmony_ci .val_bits = 32, 7688c2ecf20Sopenharmony_ci .reg_stride = 4, 7698c2ecf20Sopenharmony_ci .fast_io = true, 7708c2ecf20Sopenharmony_ci}; 7718c2ecf20Sopenharmony_ci 7728c2ecf20Sopenharmony_cistatic const struct of_device_id wiz_id_table[] = { 7738c2ecf20Sopenharmony_ci { 7748c2ecf20Sopenharmony_ci .compatible = "ti,j721e-wiz-16g", .data = (void *)J721E_WIZ_16G 7758c2ecf20Sopenharmony_ci }, 7768c2ecf20Sopenharmony_ci { 7778c2ecf20Sopenharmony_ci .compatible = "ti,j721e-wiz-10g", .data = (void *)J721E_WIZ_10G 7788c2ecf20Sopenharmony_ci }, 7798c2ecf20Sopenharmony_ci {} 7808c2ecf20Sopenharmony_ci}; 7818c2ecf20Sopenharmony_ciMODULE_DEVICE_TABLE(of, wiz_id_table); 7828c2ecf20Sopenharmony_ci 7838c2ecf20Sopenharmony_cistatic int wiz_get_lane_phy_types(struct device *dev, struct wiz *wiz) 7848c2ecf20Sopenharmony_ci{ 7858c2ecf20Sopenharmony_ci struct device_node *serdes, *subnode; 7868c2ecf20Sopenharmony_ci 7878c2ecf20Sopenharmony_ci serdes = of_get_child_by_name(dev->of_node, "serdes"); 7888c2ecf20Sopenharmony_ci if (!serdes) { 7898c2ecf20Sopenharmony_ci dev_err(dev, "%s: Getting \"serdes\"-node failed\n", __func__); 7908c2ecf20Sopenharmony_ci return -EINVAL; 7918c2ecf20Sopenharmony_ci } 7928c2ecf20Sopenharmony_ci 7938c2ecf20Sopenharmony_ci for_each_child_of_node(serdes, subnode) { 7948c2ecf20Sopenharmony_ci u32 reg, num_lanes = 1, phy_type = PHY_NONE; 7958c2ecf20Sopenharmony_ci int ret, i; 7968c2ecf20Sopenharmony_ci 7978c2ecf20Sopenharmony_ci ret = of_property_read_u32(subnode, "reg", ®); 7988c2ecf20Sopenharmony_ci if (ret) { 7998c2ecf20Sopenharmony_ci dev_err(dev, 8008c2ecf20Sopenharmony_ci "%s: Reading \"reg\" from \"%s\" failed: %d\n", 8018c2ecf20Sopenharmony_ci __func__, subnode->name, ret); 8028c2ecf20Sopenharmony_ci return ret; 8038c2ecf20Sopenharmony_ci } 8048c2ecf20Sopenharmony_ci of_property_read_u32(subnode, "cdns,num-lanes", &num_lanes); 8058c2ecf20Sopenharmony_ci of_property_read_u32(subnode, "cdns,phy-type", &phy_type); 8068c2ecf20Sopenharmony_ci 8078c2ecf20Sopenharmony_ci dev_dbg(dev, "%s: Lanes %u-%u have phy-type %u\n", __func__, 8088c2ecf20Sopenharmony_ci reg, reg + num_lanes - 1, phy_type); 8098c2ecf20Sopenharmony_ci 8108c2ecf20Sopenharmony_ci for (i = reg; i < reg + num_lanes; i++) 8118c2ecf20Sopenharmony_ci wiz->lane_phy_type[i] = phy_type; 8128c2ecf20Sopenharmony_ci } 8138c2ecf20Sopenharmony_ci 8148c2ecf20Sopenharmony_ci return 0; 8158c2ecf20Sopenharmony_ci} 8168c2ecf20Sopenharmony_ci 8178c2ecf20Sopenharmony_cistatic int wiz_probe(struct platform_device *pdev) 8188c2ecf20Sopenharmony_ci{ 8198c2ecf20Sopenharmony_ci struct reset_controller_dev *phy_reset_dev; 8208c2ecf20Sopenharmony_ci struct device *dev = &pdev->dev; 8218c2ecf20Sopenharmony_ci struct device_node *node = dev->of_node; 8228c2ecf20Sopenharmony_ci struct platform_device *serdes_pdev; 8238c2ecf20Sopenharmony_ci struct device_node *child_node; 8248c2ecf20Sopenharmony_ci struct regmap *regmap; 8258c2ecf20Sopenharmony_ci struct resource res; 8268c2ecf20Sopenharmony_ci void __iomem *base; 8278c2ecf20Sopenharmony_ci struct wiz *wiz; 8288c2ecf20Sopenharmony_ci u32 num_lanes; 8298c2ecf20Sopenharmony_ci int ret; 8308c2ecf20Sopenharmony_ci 8318c2ecf20Sopenharmony_ci wiz = devm_kzalloc(dev, sizeof(*wiz), GFP_KERNEL); 8328c2ecf20Sopenharmony_ci if (!wiz) 8338c2ecf20Sopenharmony_ci return -ENOMEM; 8348c2ecf20Sopenharmony_ci 8358c2ecf20Sopenharmony_ci wiz->type = (enum wiz_type)of_device_get_match_data(dev); 8368c2ecf20Sopenharmony_ci 8378c2ecf20Sopenharmony_ci child_node = of_get_child_by_name(node, "serdes"); 8388c2ecf20Sopenharmony_ci if (!child_node) { 8398c2ecf20Sopenharmony_ci dev_err(dev, "Failed to get SERDES child DT node\n"); 8408c2ecf20Sopenharmony_ci return -ENODEV; 8418c2ecf20Sopenharmony_ci } 8428c2ecf20Sopenharmony_ci 8438c2ecf20Sopenharmony_ci ret = of_address_to_resource(child_node, 0, &res); 8448c2ecf20Sopenharmony_ci if (ret) { 8458c2ecf20Sopenharmony_ci dev_err(dev, "Failed to get memory resource\n"); 8468c2ecf20Sopenharmony_ci goto err_addr_to_resource; 8478c2ecf20Sopenharmony_ci } 8488c2ecf20Sopenharmony_ci 8498c2ecf20Sopenharmony_ci base = devm_ioremap(dev, res.start, resource_size(&res)); 8508c2ecf20Sopenharmony_ci if (!base) { 8518c2ecf20Sopenharmony_ci ret = -ENOMEM; 8528c2ecf20Sopenharmony_ci goto err_addr_to_resource; 8538c2ecf20Sopenharmony_ci } 8548c2ecf20Sopenharmony_ci 8558c2ecf20Sopenharmony_ci regmap = devm_regmap_init_mmio(dev, base, &wiz_regmap_config); 8568c2ecf20Sopenharmony_ci if (IS_ERR(regmap)) { 8578c2ecf20Sopenharmony_ci dev_err(dev, "Failed to initialize regmap\n"); 8588c2ecf20Sopenharmony_ci ret = PTR_ERR(regmap); 8598c2ecf20Sopenharmony_ci goto err_addr_to_resource; 8608c2ecf20Sopenharmony_ci } 8618c2ecf20Sopenharmony_ci 8628c2ecf20Sopenharmony_ci ret = of_property_read_u32(node, "num-lanes", &num_lanes); 8638c2ecf20Sopenharmony_ci if (ret) { 8648c2ecf20Sopenharmony_ci dev_err(dev, "Failed to read num-lanes property\n"); 8658c2ecf20Sopenharmony_ci goto err_addr_to_resource; 8668c2ecf20Sopenharmony_ci } 8678c2ecf20Sopenharmony_ci 8688c2ecf20Sopenharmony_ci if (num_lanes > WIZ_MAX_LANES) { 8698c2ecf20Sopenharmony_ci dev_err(dev, "Cannot support %d lanes\n", num_lanes); 8708c2ecf20Sopenharmony_ci ret = -ENODEV; 8718c2ecf20Sopenharmony_ci goto err_addr_to_resource; 8728c2ecf20Sopenharmony_ci } 8738c2ecf20Sopenharmony_ci 8748c2ecf20Sopenharmony_ci wiz->gpio_typec_dir = devm_gpiod_get_optional(dev, "typec-dir", 8758c2ecf20Sopenharmony_ci GPIOD_IN); 8768c2ecf20Sopenharmony_ci if (IS_ERR(wiz->gpio_typec_dir)) { 8778c2ecf20Sopenharmony_ci ret = PTR_ERR(wiz->gpio_typec_dir); 8788c2ecf20Sopenharmony_ci if (ret != -EPROBE_DEFER) 8798c2ecf20Sopenharmony_ci dev_err(dev, "Failed to request typec-dir gpio: %d\n", 8808c2ecf20Sopenharmony_ci ret); 8818c2ecf20Sopenharmony_ci goto err_addr_to_resource; 8828c2ecf20Sopenharmony_ci } 8838c2ecf20Sopenharmony_ci 8848c2ecf20Sopenharmony_ci if (wiz->gpio_typec_dir) { 8858c2ecf20Sopenharmony_ci ret = of_property_read_u32(node, "typec-dir-debounce-ms", 8868c2ecf20Sopenharmony_ci &wiz->typec_dir_delay); 8878c2ecf20Sopenharmony_ci if (ret && ret != -EINVAL) { 8888c2ecf20Sopenharmony_ci dev_err(dev, "Invalid typec-dir-debounce property\n"); 8898c2ecf20Sopenharmony_ci goto err_addr_to_resource; 8908c2ecf20Sopenharmony_ci } 8918c2ecf20Sopenharmony_ci 8928c2ecf20Sopenharmony_ci /* use min. debounce from Type-C spec if not provided in DT */ 8938c2ecf20Sopenharmony_ci if (ret == -EINVAL) 8948c2ecf20Sopenharmony_ci wiz->typec_dir_delay = WIZ_TYPEC_DIR_DEBOUNCE_MIN; 8958c2ecf20Sopenharmony_ci 8968c2ecf20Sopenharmony_ci if (wiz->typec_dir_delay < WIZ_TYPEC_DIR_DEBOUNCE_MIN || 8978c2ecf20Sopenharmony_ci wiz->typec_dir_delay > WIZ_TYPEC_DIR_DEBOUNCE_MAX) { 8988c2ecf20Sopenharmony_ci ret = -EINVAL; 8998c2ecf20Sopenharmony_ci dev_err(dev, "Invalid typec-dir-debounce property\n"); 9008c2ecf20Sopenharmony_ci goto err_addr_to_resource; 9018c2ecf20Sopenharmony_ci } 9028c2ecf20Sopenharmony_ci } 9038c2ecf20Sopenharmony_ci 9048c2ecf20Sopenharmony_ci ret = wiz_get_lane_phy_types(dev, wiz); 9058c2ecf20Sopenharmony_ci if (ret) 9068c2ecf20Sopenharmony_ci return ret; 9078c2ecf20Sopenharmony_ci 9088c2ecf20Sopenharmony_ci wiz->dev = dev; 9098c2ecf20Sopenharmony_ci wiz->regmap = regmap; 9108c2ecf20Sopenharmony_ci wiz->num_lanes = num_lanes; 9118c2ecf20Sopenharmony_ci if (wiz->type == J721E_WIZ_10G) 9128c2ecf20Sopenharmony_ci wiz->clk_mux_sel = clk_mux_sel_10g; 9138c2ecf20Sopenharmony_ci else 9148c2ecf20Sopenharmony_ci wiz->clk_mux_sel = clk_mux_sel_16g; 9158c2ecf20Sopenharmony_ci 9168c2ecf20Sopenharmony_ci wiz->clk_div_sel = clk_div_sel; 9178c2ecf20Sopenharmony_ci 9188c2ecf20Sopenharmony_ci if (wiz->type == J721E_WIZ_10G) 9198c2ecf20Sopenharmony_ci wiz->clk_div_sel_num = WIZ_DIV_NUM_CLOCKS_10G; 9208c2ecf20Sopenharmony_ci else 9218c2ecf20Sopenharmony_ci wiz->clk_div_sel_num = WIZ_DIV_NUM_CLOCKS_16G; 9228c2ecf20Sopenharmony_ci 9238c2ecf20Sopenharmony_ci platform_set_drvdata(pdev, wiz); 9248c2ecf20Sopenharmony_ci 9258c2ecf20Sopenharmony_ci ret = wiz_regfield_init(wiz); 9268c2ecf20Sopenharmony_ci if (ret) { 9278c2ecf20Sopenharmony_ci dev_err(dev, "Failed to initialize regfields\n"); 9288c2ecf20Sopenharmony_ci goto err_addr_to_resource; 9298c2ecf20Sopenharmony_ci } 9308c2ecf20Sopenharmony_ci 9318c2ecf20Sopenharmony_ci phy_reset_dev = &wiz->wiz_phy_reset_dev; 9328c2ecf20Sopenharmony_ci phy_reset_dev->dev = dev; 9338c2ecf20Sopenharmony_ci phy_reset_dev->ops = &wiz_phy_reset_ops, 9348c2ecf20Sopenharmony_ci phy_reset_dev->owner = THIS_MODULE, 9358c2ecf20Sopenharmony_ci phy_reset_dev->of_node = node; 9368c2ecf20Sopenharmony_ci /* Reset for each of the lane and one for the entire SERDES */ 9378c2ecf20Sopenharmony_ci phy_reset_dev->nr_resets = num_lanes + 1; 9388c2ecf20Sopenharmony_ci 9398c2ecf20Sopenharmony_ci ret = devm_reset_controller_register(dev, phy_reset_dev); 9408c2ecf20Sopenharmony_ci if (ret < 0) { 9418c2ecf20Sopenharmony_ci dev_warn(dev, "Failed to register reset controller\n"); 9428c2ecf20Sopenharmony_ci goto err_addr_to_resource; 9438c2ecf20Sopenharmony_ci } 9448c2ecf20Sopenharmony_ci 9458c2ecf20Sopenharmony_ci pm_runtime_enable(dev); 9468c2ecf20Sopenharmony_ci ret = pm_runtime_get_sync(dev); 9478c2ecf20Sopenharmony_ci if (ret < 0) { 9488c2ecf20Sopenharmony_ci dev_err(dev, "pm_runtime_get_sync failed\n"); 9498c2ecf20Sopenharmony_ci goto err_get_sync; 9508c2ecf20Sopenharmony_ci } 9518c2ecf20Sopenharmony_ci 9528c2ecf20Sopenharmony_ci ret = wiz_clock_init(wiz, node); 9538c2ecf20Sopenharmony_ci if (ret < 0) { 9548c2ecf20Sopenharmony_ci dev_warn(dev, "Failed to initialize clocks\n"); 9558c2ecf20Sopenharmony_ci goto err_get_sync; 9568c2ecf20Sopenharmony_ci } 9578c2ecf20Sopenharmony_ci 9588c2ecf20Sopenharmony_ci ret = wiz_init(wiz); 9598c2ecf20Sopenharmony_ci if (ret) { 9608c2ecf20Sopenharmony_ci dev_err(dev, "WIZ initialization failed\n"); 9618c2ecf20Sopenharmony_ci goto err_wiz_init; 9628c2ecf20Sopenharmony_ci } 9638c2ecf20Sopenharmony_ci 9648c2ecf20Sopenharmony_ci serdes_pdev = of_platform_device_create(child_node, NULL, dev); 9658c2ecf20Sopenharmony_ci if (!serdes_pdev) { 9668c2ecf20Sopenharmony_ci dev_WARN(dev, "Unable to create SERDES platform device\n"); 9678c2ecf20Sopenharmony_ci ret = -ENOMEM; 9688c2ecf20Sopenharmony_ci goto err_wiz_init; 9698c2ecf20Sopenharmony_ci } 9708c2ecf20Sopenharmony_ci wiz->serdes_pdev = serdes_pdev; 9718c2ecf20Sopenharmony_ci 9728c2ecf20Sopenharmony_ci of_node_put(child_node); 9738c2ecf20Sopenharmony_ci return 0; 9748c2ecf20Sopenharmony_ci 9758c2ecf20Sopenharmony_cierr_wiz_init: 9768c2ecf20Sopenharmony_ci wiz_clock_cleanup(wiz, node); 9778c2ecf20Sopenharmony_ci 9788c2ecf20Sopenharmony_cierr_get_sync: 9798c2ecf20Sopenharmony_ci pm_runtime_put(dev); 9808c2ecf20Sopenharmony_ci pm_runtime_disable(dev); 9818c2ecf20Sopenharmony_ci 9828c2ecf20Sopenharmony_cierr_addr_to_resource: 9838c2ecf20Sopenharmony_ci of_node_put(child_node); 9848c2ecf20Sopenharmony_ci 9858c2ecf20Sopenharmony_ci return ret; 9868c2ecf20Sopenharmony_ci} 9878c2ecf20Sopenharmony_ci 9888c2ecf20Sopenharmony_cistatic int wiz_remove(struct platform_device *pdev) 9898c2ecf20Sopenharmony_ci{ 9908c2ecf20Sopenharmony_ci struct device *dev = &pdev->dev; 9918c2ecf20Sopenharmony_ci struct device_node *node = dev->of_node; 9928c2ecf20Sopenharmony_ci struct platform_device *serdes_pdev; 9938c2ecf20Sopenharmony_ci struct wiz *wiz; 9948c2ecf20Sopenharmony_ci 9958c2ecf20Sopenharmony_ci wiz = dev_get_drvdata(dev); 9968c2ecf20Sopenharmony_ci serdes_pdev = wiz->serdes_pdev; 9978c2ecf20Sopenharmony_ci 9988c2ecf20Sopenharmony_ci of_platform_device_destroy(&serdes_pdev->dev, NULL); 9998c2ecf20Sopenharmony_ci wiz_clock_cleanup(wiz, node); 10008c2ecf20Sopenharmony_ci pm_runtime_put(dev); 10018c2ecf20Sopenharmony_ci pm_runtime_disable(dev); 10028c2ecf20Sopenharmony_ci 10038c2ecf20Sopenharmony_ci return 0; 10048c2ecf20Sopenharmony_ci} 10058c2ecf20Sopenharmony_ci 10068c2ecf20Sopenharmony_cistatic struct platform_driver wiz_driver = { 10078c2ecf20Sopenharmony_ci .probe = wiz_probe, 10088c2ecf20Sopenharmony_ci .remove = wiz_remove, 10098c2ecf20Sopenharmony_ci .driver = { 10108c2ecf20Sopenharmony_ci .name = "wiz", 10118c2ecf20Sopenharmony_ci .of_match_table = wiz_id_table, 10128c2ecf20Sopenharmony_ci }, 10138c2ecf20Sopenharmony_ci}; 10148c2ecf20Sopenharmony_cimodule_platform_driver(wiz_driver); 10158c2ecf20Sopenharmony_ci 10168c2ecf20Sopenharmony_ciMODULE_AUTHOR("Texas Instruments Inc."); 10178c2ecf20Sopenharmony_ciMODULE_DESCRIPTION("TI J721E WIZ driver"); 10188c2ecf20Sopenharmony_ciMODULE_LICENSE("GPL v2"); 1019