0001
0002
0003
0004
0005
0006 #include <linux/delay.h>
0007 #include <linux/io.h>
0008 #include <linux/module.h>
0009 #include <linux/of.h>
0010 #include <linux/phy/phy.h>
0011 #include <linux/pinctrl/pinctrl.h>
0012 #include <linux/pinctrl/pinmux.h>
0013 #include <linux/platform_device.h>
0014 #include <linux/reset.h>
0015 #include <linux/slab.h>
0016
0017 #include <dt-bindings/pinctrl/pinctrl-tegra-xusb.h>
0018
0019 #include "../core.h"
0020 #include "../pinctrl-utils.h"
0021
0022 #define XUSB_PADCTL_ELPG_PROGRAM 0x01c
0023 #define XUSB_PADCTL_ELPG_PROGRAM_AUX_MUX_LP0_VCORE_DOWN (1 << 26)
0024 #define XUSB_PADCTL_ELPG_PROGRAM_AUX_MUX_LP0_CLAMP_EN_EARLY (1 << 25)
0025 #define XUSB_PADCTL_ELPG_PROGRAM_AUX_MUX_LP0_CLAMP_EN (1 << 24)
0026
0027 #define XUSB_PADCTL_IOPHY_PLL_P0_CTL1 0x040
0028 #define XUSB_PADCTL_IOPHY_PLL_P0_CTL1_PLL0_LOCKDET (1 << 19)
0029 #define XUSB_PADCTL_IOPHY_PLL_P0_CTL1_REFCLK_SEL_MASK (0xf << 12)
0030 #define XUSB_PADCTL_IOPHY_PLL_P0_CTL1_PLL_RST (1 << 1)
0031
0032 #define XUSB_PADCTL_IOPHY_PLL_P0_CTL2 0x044
0033 #define XUSB_PADCTL_IOPHY_PLL_P0_CTL2_REFCLKBUF_EN (1 << 6)
0034 #define XUSB_PADCTL_IOPHY_PLL_P0_CTL2_TXCLKREF_EN (1 << 5)
0035 #define XUSB_PADCTL_IOPHY_PLL_P0_CTL2_TXCLKREF_SEL (1 << 4)
0036
0037 #define XUSB_PADCTL_IOPHY_PLL_S0_CTL1 0x138
0038 #define XUSB_PADCTL_IOPHY_PLL_S0_CTL1_PLL1_LOCKDET (1 << 27)
0039 #define XUSB_PADCTL_IOPHY_PLL_S0_CTL1_PLL1_MODE (1 << 24)
0040 #define XUSB_PADCTL_IOPHY_PLL_S0_CTL1_PLL_PWR_OVRD (1 << 3)
0041 #define XUSB_PADCTL_IOPHY_PLL_S0_CTL1_PLL_RST (1 << 1)
0042 #define XUSB_PADCTL_IOPHY_PLL_S0_CTL1_PLL_IDDQ (1 << 0)
0043
0044 #define XUSB_PADCTL_IOPHY_MISC_PAD_S0_CTL1 0x148
0045 #define XUSB_PADCTL_IOPHY_MISC_PAD_S0_CTL1_IDDQ_OVRD (1 << 1)
0046 #define XUSB_PADCTL_IOPHY_MISC_PAD_S0_CTL1_IDDQ (1 << 0)
0047
0048 struct tegra_xusb_padctl_function {
0049 const char *name;
0050 const char * const *groups;
0051 unsigned int num_groups;
0052 };
0053
0054 struct tegra_xusb_padctl_soc {
0055 const struct pinctrl_pin_desc *pins;
0056 unsigned int num_pins;
0057
0058 const struct tegra_xusb_padctl_function *functions;
0059 unsigned int num_functions;
0060
0061 const struct tegra_xusb_padctl_lane *lanes;
0062 unsigned int num_lanes;
0063 };
0064
0065 struct tegra_xusb_padctl_lane {
0066 const char *name;
0067
0068 unsigned int offset;
0069 unsigned int shift;
0070 unsigned int mask;
0071 unsigned int iddq;
0072
0073 const unsigned int *funcs;
0074 unsigned int num_funcs;
0075 };
0076
0077 struct tegra_xusb_padctl {
0078 struct device *dev;
0079 void __iomem *regs;
0080 struct mutex lock;
0081 struct reset_control *rst;
0082
0083 const struct tegra_xusb_padctl_soc *soc;
0084 struct pinctrl_dev *pinctrl;
0085 struct pinctrl_desc desc;
0086
0087 struct phy_provider *provider;
0088 struct phy *phys[2];
0089
0090 unsigned int enable;
0091 };
0092
0093 static inline void padctl_writel(struct tegra_xusb_padctl *padctl, u32 value,
0094 unsigned long offset)
0095 {
0096 writel(value, padctl->regs + offset);
0097 }
0098
0099 static inline u32 padctl_readl(struct tegra_xusb_padctl *padctl,
0100 unsigned long offset)
0101 {
0102 return readl(padctl->regs + offset);
0103 }
0104
0105 static int tegra_xusb_padctl_get_groups_count(struct pinctrl_dev *pinctrl)
0106 {
0107 struct tegra_xusb_padctl *padctl = pinctrl_dev_get_drvdata(pinctrl);
0108
0109 return padctl->soc->num_pins;
0110 }
0111
0112 static const char *tegra_xusb_padctl_get_group_name(struct pinctrl_dev *pinctrl,
0113 unsigned int group)
0114 {
0115 struct tegra_xusb_padctl *padctl = pinctrl_dev_get_drvdata(pinctrl);
0116
0117 return padctl->soc->pins[group].name;
0118 }
0119
0120 static int tegra_xusb_padctl_get_group_pins(struct pinctrl_dev *pinctrl,
0121 unsigned group,
0122 const unsigned **pins,
0123 unsigned *num_pins)
0124 {
0125
0126
0127
0128
0129 *pins = &pinctrl->desc->pins[group].number;
0130 *num_pins = 1;
0131
0132 return 0;
0133 }
0134
0135 enum tegra_xusb_padctl_param {
0136 TEGRA_XUSB_PADCTL_IDDQ,
0137 };
0138
0139 static const struct tegra_xusb_padctl_property {
0140 const char *name;
0141 enum tegra_xusb_padctl_param param;
0142 } properties[] = {
0143 { "nvidia,iddq", TEGRA_XUSB_PADCTL_IDDQ },
0144 };
0145
0146 #define TEGRA_XUSB_PADCTL_PACK(param, value) ((param) << 16 | (value))
0147 #define TEGRA_XUSB_PADCTL_UNPACK_PARAM(config) ((config) >> 16)
0148 #define TEGRA_XUSB_PADCTL_UNPACK_VALUE(config) ((config) & 0xffff)
0149
0150 static int tegra_xusb_padctl_parse_subnode(struct tegra_xusb_padctl *padctl,
0151 struct device_node *np,
0152 struct pinctrl_map **maps,
0153 unsigned int *reserved_maps,
0154 unsigned int *num_maps)
0155 {
0156 unsigned int i, reserve = 0, num_configs = 0;
0157 unsigned long config, *configs = NULL;
0158 const char *function, *group;
0159 struct property *prop;
0160 int err = 0;
0161 u32 value;
0162
0163 err = of_property_read_string(np, "nvidia,function", &function);
0164 if (err < 0) {
0165 if (err != -EINVAL)
0166 return err;
0167
0168 function = NULL;
0169 }
0170
0171 for (i = 0; i < ARRAY_SIZE(properties); i++) {
0172 err = of_property_read_u32(np, properties[i].name, &value);
0173 if (err < 0) {
0174 if (err == -EINVAL)
0175 continue;
0176
0177 goto out;
0178 }
0179
0180 config = TEGRA_XUSB_PADCTL_PACK(properties[i].param, value);
0181
0182 err = pinctrl_utils_add_config(padctl->pinctrl, &configs,
0183 &num_configs, config);
0184 if (err < 0)
0185 goto out;
0186 }
0187
0188 if (function)
0189 reserve++;
0190
0191 if (num_configs)
0192 reserve++;
0193
0194 err = of_property_count_strings(np, "nvidia,lanes");
0195 if (err < 0)
0196 goto out;
0197
0198 reserve *= err;
0199
0200 err = pinctrl_utils_reserve_map(padctl->pinctrl, maps, reserved_maps,
0201 num_maps, reserve);
0202 if (err < 0)
0203 goto out;
0204
0205 of_property_for_each_string(np, "nvidia,lanes", prop, group) {
0206 if (function) {
0207 err = pinctrl_utils_add_map_mux(padctl->pinctrl, maps,
0208 reserved_maps, num_maps, group,
0209 function);
0210 if (err < 0)
0211 goto out;
0212 }
0213
0214 if (num_configs) {
0215 err = pinctrl_utils_add_map_configs(padctl->pinctrl,
0216 maps, reserved_maps, num_maps, group,
0217 configs, num_configs,
0218 PIN_MAP_TYPE_CONFIGS_GROUP);
0219 if (err < 0)
0220 goto out;
0221 }
0222 }
0223
0224 err = 0;
0225
0226 out:
0227 kfree(configs);
0228 return err;
0229 }
0230
0231 static int tegra_xusb_padctl_dt_node_to_map(struct pinctrl_dev *pinctrl,
0232 struct device_node *parent,
0233 struct pinctrl_map **maps,
0234 unsigned int *num_maps)
0235 {
0236 struct tegra_xusb_padctl *padctl = pinctrl_dev_get_drvdata(pinctrl);
0237 unsigned int reserved_maps = 0;
0238 struct device_node *np;
0239 int err;
0240
0241 *num_maps = 0;
0242 *maps = NULL;
0243
0244 for_each_child_of_node(parent, np) {
0245 err = tegra_xusb_padctl_parse_subnode(padctl, np, maps,
0246 &reserved_maps,
0247 num_maps);
0248 if (err < 0) {
0249 of_node_put(np);
0250 return err;
0251 }
0252 }
0253
0254 return 0;
0255 }
0256
0257 static const struct pinctrl_ops tegra_xusb_padctl_pinctrl_ops = {
0258 .get_groups_count = tegra_xusb_padctl_get_groups_count,
0259 .get_group_name = tegra_xusb_padctl_get_group_name,
0260 .get_group_pins = tegra_xusb_padctl_get_group_pins,
0261 .dt_node_to_map = tegra_xusb_padctl_dt_node_to_map,
0262 .dt_free_map = pinctrl_utils_free_map,
0263 };
0264
0265 static int tegra_xusb_padctl_get_functions_count(struct pinctrl_dev *pinctrl)
0266 {
0267 struct tegra_xusb_padctl *padctl = pinctrl_dev_get_drvdata(pinctrl);
0268
0269 return padctl->soc->num_functions;
0270 }
0271
0272 static const char *
0273 tegra_xusb_padctl_get_function_name(struct pinctrl_dev *pinctrl,
0274 unsigned int function)
0275 {
0276 struct tegra_xusb_padctl *padctl = pinctrl_dev_get_drvdata(pinctrl);
0277
0278 return padctl->soc->functions[function].name;
0279 }
0280
0281 static int tegra_xusb_padctl_get_function_groups(struct pinctrl_dev *pinctrl,
0282 unsigned int function,
0283 const char * const **groups,
0284 unsigned * const num_groups)
0285 {
0286 struct tegra_xusb_padctl *padctl = pinctrl_dev_get_drvdata(pinctrl);
0287
0288 *num_groups = padctl->soc->functions[function].num_groups;
0289 *groups = padctl->soc->functions[function].groups;
0290
0291 return 0;
0292 }
0293
0294 static int tegra_xusb_padctl_pinmux_set(struct pinctrl_dev *pinctrl,
0295 unsigned int function,
0296 unsigned int group)
0297 {
0298 struct tegra_xusb_padctl *padctl = pinctrl_dev_get_drvdata(pinctrl);
0299 const struct tegra_xusb_padctl_lane *lane;
0300 unsigned int i;
0301 u32 value;
0302
0303 lane = &padctl->soc->lanes[group];
0304
0305 for (i = 0; i < lane->num_funcs; i++)
0306 if (lane->funcs[i] == function)
0307 break;
0308
0309 if (i >= lane->num_funcs)
0310 return -EINVAL;
0311
0312 value = padctl_readl(padctl, lane->offset);
0313 value &= ~(lane->mask << lane->shift);
0314 value |= i << lane->shift;
0315 padctl_writel(padctl, value, lane->offset);
0316
0317 return 0;
0318 }
0319
0320 static const struct pinmux_ops tegra_xusb_padctl_pinmux_ops = {
0321 .get_functions_count = tegra_xusb_padctl_get_functions_count,
0322 .get_function_name = tegra_xusb_padctl_get_function_name,
0323 .get_function_groups = tegra_xusb_padctl_get_function_groups,
0324 .set_mux = tegra_xusb_padctl_pinmux_set,
0325 };
0326
0327 static int tegra_xusb_padctl_pinconf_group_get(struct pinctrl_dev *pinctrl,
0328 unsigned int group,
0329 unsigned long *config)
0330 {
0331 struct tegra_xusb_padctl *padctl = pinctrl_dev_get_drvdata(pinctrl);
0332 const struct tegra_xusb_padctl_lane *lane;
0333 enum tegra_xusb_padctl_param param;
0334 u32 value;
0335
0336 param = TEGRA_XUSB_PADCTL_UNPACK_PARAM(*config);
0337 lane = &padctl->soc->lanes[group];
0338
0339 switch (param) {
0340 case TEGRA_XUSB_PADCTL_IDDQ:
0341
0342 if (lane->iddq == 0)
0343 return -EINVAL;
0344
0345 value = padctl_readl(padctl, lane->offset);
0346
0347 if (value & BIT(lane->iddq))
0348 value = 0;
0349 else
0350 value = 1;
0351
0352 *config = TEGRA_XUSB_PADCTL_PACK(param, value);
0353 break;
0354
0355 default:
0356 dev_err(padctl->dev, "invalid configuration parameter: %04x\n",
0357 param);
0358 return -ENOTSUPP;
0359 }
0360
0361 return 0;
0362 }
0363
0364 static int tegra_xusb_padctl_pinconf_group_set(struct pinctrl_dev *pinctrl,
0365 unsigned int group,
0366 unsigned long *configs,
0367 unsigned int num_configs)
0368 {
0369 struct tegra_xusb_padctl *padctl = pinctrl_dev_get_drvdata(pinctrl);
0370 const struct tegra_xusb_padctl_lane *lane;
0371 enum tegra_xusb_padctl_param param;
0372 unsigned long value;
0373 unsigned int i;
0374 u32 regval;
0375
0376 lane = &padctl->soc->lanes[group];
0377
0378 for (i = 0; i < num_configs; i++) {
0379 param = TEGRA_XUSB_PADCTL_UNPACK_PARAM(configs[i]);
0380 value = TEGRA_XUSB_PADCTL_UNPACK_VALUE(configs[i]);
0381
0382 switch (param) {
0383 case TEGRA_XUSB_PADCTL_IDDQ:
0384
0385 if (lane->iddq == 0)
0386 return -EINVAL;
0387
0388 regval = padctl_readl(padctl, lane->offset);
0389
0390 if (value)
0391 regval &= ~BIT(lane->iddq);
0392 else
0393 regval |= BIT(lane->iddq);
0394
0395 padctl_writel(padctl, regval, lane->offset);
0396 break;
0397
0398 default:
0399 dev_err(padctl->dev,
0400 "invalid configuration parameter: %04x\n",
0401 param);
0402 return -ENOTSUPP;
0403 }
0404 }
0405
0406 return 0;
0407 }
0408
0409 #ifdef CONFIG_DEBUG_FS
0410 static const char *strip_prefix(const char *s)
0411 {
0412 const char *comma = strchr(s, ',');
0413 if (!comma)
0414 return s;
0415
0416 return comma + 1;
0417 }
0418
0419 static void
0420 tegra_xusb_padctl_pinconf_group_dbg_show(struct pinctrl_dev *pinctrl,
0421 struct seq_file *s,
0422 unsigned int group)
0423 {
0424 unsigned int i;
0425
0426 for (i = 0; i < ARRAY_SIZE(properties); i++) {
0427 unsigned long config, value;
0428 int err;
0429
0430 config = TEGRA_XUSB_PADCTL_PACK(properties[i].param, 0);
0431
0432 err = tegra_xusb_padctl_pinconf_group_get(pinctrl, group,
0433 &config);
0434 if (err < 0)
0435 continue;
0436
0437 value = TEGRA_XUSB_PADCTL_UNPACK_VALUE(config);
0438
0439 seq_printf(s, "\n\t%s=%lu\n", strip_prefix(properties[i].name),
0440 value);
0441 }
0442 }
0443
0444 static void
0445 tegra_xusb_padctl_pinconf_config_dbg_show(struct pinctrl_dev *pinctrl,
0446 struct seq_file *s,
0447 unsigned long config)
0448 {
0449 enum tegra_xusb_padctl_param param;
0450 const char *name = "unknown";
0451 unsigned long value;
0452 unsigned int i;
0453
0454 param = TEGRA_XUSB_PADCTL_UNPACK_PARAM(config);
0455 value = TEGRA_XUSB_PADCTL_UNPACK_VALUE(config);
0456
0457 for (i = 0; i < ARRAY_SIZE(properties); i++) {
0458 if (properties[i].param == param) {
0459 name = properties[i].name;
0460 break;
0461 }
0462 }
0463
0464 seq_printf(s, "%s=%lu", strip_prefix(name), value);
0465 }
0466 #endif
0467
0468 static const struct pinconf_ops tegra_xusb_padctl_pinconf_ops = {
0469 .pin_config_group_get = tegra_xusb_padctl_pinconf_group_get,
0470 .pin_config_group_set = tegra_xusb_padctl_pinconf_group_set,
0471 #ifdef CONFIG_DEBUG_FS
0472 .pin_config_group_dbg_show = tegra_xusb_padctl_pinconf_group_dbg_show,
0473 .pin_config_config_dbg_show = tegra_xusb_padctl_pinconf_config_dbg_show,
0474 #endif
0475 };
0476
0477 static int tegra_xusb_padctl_enable(struct tegra_xusb_padctl *padctl)
0478 {
0479 u32 value;
0480
0481 mutex_lock(&padctl->lock);
0482
0483 if (padctl->enable++ > 0)
0484 goto out;
0485
0486 value = padctl_readl(padctl, XUSB_PADCTL_ELPG_PROGRAM);
0487 value &= ~XUSB_PADCTL_ELPG_PROGRAM_AUX_MUX_LP0_CLAMP_EN;
0488 padctl_writel(padctl, value, XUSB_PADCTL_ELPG_PROGRAM);
0489
0490 usleep_range(100, 200);
0491
0492 value = padctl_readl(padctl, XUSB_PADCTL_ELPG_PROGRAM);
0493 value &= ~XUSB_PADCTL_ELPG_PROGRAM_AUX_MUX_LP0_CLAMP_EN_EARLY;
0494 padctl_writel(padctl, value, XUSB_PADCTL_ELPG_PROGRAM);
0495
0496 usleep_range(100, 200);
0497
0498 value = padctl_readl(padctl, XUSB_PADCTL_ELPG_PROGRAM);
0499 value &= ~XUSB_PADCTL_ELPG_PROGRAM_AUX_MUX_LP0_VCORE_DOWN;
0500 padctl_writel(padctl, value, XUSB_PADCTL_ELPG_PROGRAM);
0501
0502 out:
0503 mutex_unlock(&padctl->lock);
0504 return 0;
0505 }
0506
0507 static int tegra_xusb_padctl_disable(struct tegra_xusb_padctl *padctl)
0508 {
0509 u32 value;
0510
0511 mutex_lock(&padctl->lock);
0512
0513 if (WARN_ON(padctl->enable == 0))
0514 goto out;
0515
0516 if (--padctl->enable > 0)
0517 goto out;
0518
0519 value = padctl_readl(padctl, XUSB_PADCTL_ELPG_PROGRAM);
0520 value |= XUSB_PADCTL_ELPG_PROGRAM_AUX_MUX_LP0_VCORE_DOWN;
0521 padctl_writel(padctl, value, XUSB_PADCTL_ELPG_PROGRAM);
0522
0523 usleep_range(100, 200);
0524
0525 value = padctl_readl(padctl, XUSB_PADCTL_ELPG_PROGRAM);
0526 value |= XUSB_PADCTL_ELPG_PROGRAM_AUX_MUX_LP0_CLAMP_EN_EARLY;
0527 padctl_writel(padctl, value, XUSB_PADCTL_ELPG_PROGRAM);
0528
0529 usleep_range(100, 200);
0530
0531 value = padctl_readl(padctl, XUSB_PADCTL_ELPG_PROGRAM);
0532 value |= XUSB_PADCTL_ELPG_PROGRAM_AUX_MUX_LP0_CLAMP_EN;
0533 padctl_writel(padctl, value, XUSB_PADCTL_ELPG_PROGRAM);
0534
0535 out:
0536 mutex_unlock(&padctl->lock);
0537 return 0;
0538 }
0539
0540 static int tegra_xusb_phy_init(struct phy *phy)
0541 {
0542 struct tegra_xusb_padctl *padctl = phy_get_drvdata(phy);
0543
0544 return tegra_xusb_padctl_enable(padctl);
0545 }
0546
0547 static int tegra_xusb_phy_exit(struct phy *phy)
0548 {
0549 struct tegra_xusb_padctl *padctl = phy_get_drvdata(phy);
0550
0551 return tegra_xusb_padctl_disable(padctl);
0552 }
0553
0554 static int pcie_phy_power_on(struct phy *phy)
0555 {
0556 struct tegra_xusb_padctl *padctl = phy_get_drvdata(phy);
0557 unsigned long timeout;
0558 int err = -ETIMEDOUT;
0559 u32 value;
0560
0561 value = padctl_readl(padctl, XUSB_PADCTL_IOPHY_PLL_P0_CTL1);
0562 value &= ~XUSB_PADCTL_IOPHY_PLL_P0_CTL1_REFCLK_SEL_MASK;
0563 padctl_writel(padctl, value, XUSB_PADCTL_IOPHY_PLL_P0_CTL1);
0564
0565 value = padctl_readl(padctl, XUSB_PADCTL_IOPHY_PLL_P0_CTL2);
0566 value |= XUSB_PADCTL_IOPHY_PLL_P0_CTL2_REFCLKBUF_EN |
0567 XUSB_PADCTL_IOPHY_PLL_P0_CTL2_TXCLKREF_EN |
0568 XUSB_PADCTL_IOPHY_PLL_P0_CTL2_TXCLKREF_SEL;
0569 padctl_writel(padctl, value, XUSB_PADCTL_IOPHY_PLL_P0_CTL2);
0570
0571 value = padctl_readl(padctl, XUSB_PADCTL_IOPHY_PLL_P0_CTL1);
0572 value |= XUSB_PADCTL_IOPHY_PLL_P0_CTL1_PLL_RST;
0573 padctl_writel(padctl, value, XUSB_PADCTL_IOPHY_PLL_P0_CTL1);
0574
0575 timeout = jiffies + msecs_to_jiffies(50);
0576
0577 while (time_before(jiffies, timeout)) {
0578 value = padctl_readl(padctl, XUSB_PADCTL_IOPHY_PLL_P0_CTL1);
0579 if (value & XUSB_PADCTL_IOPHY_PLL_P0_CTL1_PLL0_LOCKDET) {
0580 err = 0;
0581 break;
0582 }
0583
0584 usleep_range(100, 200);
0585 }
0586
0587 return err;
0588 }
0589
0590 static int pcie_phy_power_off(struct phy *phy)
0591 {
0592 struct tegra_xusb_padctl *padctl = phy_get_drvdata(phy);
0593 u32 value;
0594
0595 value = padctl_readl(padctl, XUSB_PADCTL_IOPHY_PLL_P0_CTL1);
0596 value &= ~XUSB_PADCTL_IOPHY_PLL_P0_CTL1_PLL_RST;
0597 padctl_writel(padctl, value, XUSB_PADCTL_IOPHY_PLL_P0_CTL1);
0598
0599 return 0;
0600 }
0601
0602 static const struct phy_ops pcie_phy_ops = {
0603 .init = tegra_xusb_phy_init,
0604 .exit = tegra_xusb_phy_exit,
0605 .power_on = pcie_phy_power_on,
0606 .power_off = pcie_phy_power_off,
0607 .owner = THIS_MODULE,
0608 };
0609
0610 static int sata_phy_power_on(struct phy *phy)
0611 {
0612 struct tegra_xusb_padctl *padctl = phy_get_drvdata(phy);
0613 unsigned long timeout;
0614 int err = -ETIMEDOUT;
0615 u32 value;
0616
0617 value = padctl_readl(padctl, XUSB_PADCTL_IOPHY_MISC_PAD_S0_CTL1);
0618 value &= ~XUSB_PADCTL_IOPHY_MISC_PAD_S0_CTL1_IDDQ_OVRD;
0619 value &= ~XUSB_PADCTL_IOPHY_MISC_PAD_S0_CTL1_IDDQ;
0620 padctl_writel(padctl, value, XUSB_PADCTL_IOPHY_MISC_PAD_S0_CTL1);
0621
0622 value = padctl_readl(padctl, XUSB_PADCTL_IOPHY_PLL_S0_CTL1);
0623 value &= ~XUSB_PADCTL_IOPHY_PLL_S0_CTL1_PLL_PWR_OVRD;
0624 value &= ~XUSB_PADCTL_IOPHY_PLL_S0_CTL1_PLL_IDDQ;
0625 padctl_writel(padctl, value, XUSB_PADCTL_IOPHY_PLL_S0_CTL1);
0626
0627 value = padctl_readl(padctl, XUSB_PADCTL_IOPHY_PLL_S0_CTL1);
0628 value |= XUSB_PADCTL_IOPHY_PLL_S0_CTL1_PLL1_MODE;
0629 padctl_writel(padctl, value, XUSB_PADCTL_IOPHY_PLL_S0_CTL1);
0630
0631 value = padctl_readl(padctl, XUSB_PADCTL_IOPHY_PLL_S0_CTL1);
0632 value |= XUSB_PADCTL_IOPHY_PLL_S0_CTL1_PLL_RST;
0633 padctl_writel(padctl, value, XUSB_PADCTL_IOPHY_PLL_S0_CTL1);
0634
0635 timeout = jiffies + msecs_to_jiffies(50);
0636
0637 while (time_before(jiffies, timeout)) {
0638 value = padctl_readl(padctl, XUSB_PADCTL_IOPHY_PLL_S0_CTL1);
0639 if (value & XUSB_PADCTL_IOPHY_PLL_S0_CTL1_PLL1_LOCKDET) {
0640 err = 0;
0641 break;
0642 }
0643
0644 usleep_range(100, 200);
0645 }
0646
0647 return err;
0648 }
0649
0650 static int sata_phy_power_off(struct phy *phy)
0651 {
0652 struct tegra_xusb_padctl *padctl = phy_get_drvdata(phy);
0653 u32 value;
0654
0655 value = padctl_readl(padctl, XUSB_PADCTL_IOPHY_PLL_S0_CTL1);
0656 value &= ~XUSB_PADCTL_IOPHY_PLL_S0_CTL1_PLL_RST;
0657 padctl_writel(padctl, value, XUSB_PADCTL_IOPHY_PLL_S0_CTL1);
0658
0659 value = padctl_readl(padctl, XUSB_PADCTL_IOPHY_PLL_S0_CTL1);
0660 value &= ~XUSB_PADCTL_IOPHY_PLL_S0_CTL1_PLL1_MODE;
0661 padctl_writel(padctl, value, XUSB_PADCTL_IOPHY_PLL_S0_CTL1);
0662
0663 value = padctl_readl(padctl, XUSB_PADCTL_IOPHY_PLL_S0_CTL1);
0664 value |= XUSB_PADCTL_IOPHY_PLL_S0_CTL1_PLL_PWR_OVRD;
0665 value |= XUSB_PADCTL_IOPHY_PLL_S0_CTL1_PLL_IDDQ;
0666 padctl_writel(padctl, value, XUSB_PADCTL_IOPHY_PLL_S0_CTL1);
0667
0668 value = padctl_readl(padctl, XUSB_PADCTL_IOPHY_MISC_PAD_S0_CTL1);
0669 value |= ~XUSB_PADCTL_IOPHY_MISC_PAD_S0_CTL1_IDDQ_OVRD;
0670 value |= ~XUSB_PADCTL_IOPHY_MISC_PAD_S0_CTL1_IDDQ;
0671 padctl_writel(padctl, value, XUSB_PADCTL_IOPHY_MISC_PAD_S0_CTL1);
0672
0673 return 0;
0674 }
0675
0676 static const struct phy_ops sata_phy_ops = {
0677 .init = tegra_xusb_phy_init,
0678 .exit = tegra_xusb_phy_exit,
0679 .power_on = sata_phy_power_on,
0680 .power_off = sata_phy_power_off,
0681 .owner = THIS_MODULE,
0682 };
0683
0684 static struct phy *tegra_xusb_padctl_xlate(struct device *dev,
0685 struct of_phandle_args *args)
0686 {
0687 struct tegra_xusb_padctl *padctl = dev_get_drvdata(dev);
0688 unsigned int index = args->args[0];
0689
0690 if (args->args_count <= 0)
0691 return ERR_PTR(-EINVAL);
0692
0693 if (index >= ARRAY_SIZE(padctl->phys))
0694 return ERR_PTR(-EINVAL);
0695
0696 return padctl->phys[index];
0697 }
0698
0699 #define PIN_OTG_0 0
0700 #define PIN_OTG_1 1
0701 #define PIN_OTG_2 2
0702 #define PIN_ULPI_0 3
0703 #define PIN_HSIC_0 4
0704 #define PIN_HSIC_1 5
0705 #define PIN_PCIE_0 6
0706 #define PIN_PCIE_1 7
0707 #define PIN_PCIE_2 8
0708 #define PIN_PCIE_3 9
0709 #define PIN_PCIE_4 10
0710 #define PIN_SATA_0 11
0711
0712 static const struct pinctrl_pin_desc tegra124_pins[] = {
0713 PINCTRL_PIN(PIN_OTG_0, "otg-0"),
0714 PINCTRL_PIN(PIN_OTG_1, "otg-1"),
0715 PINCTRL_PIN(PIN_OTG_2, "otg-2"),
0716 PINCTRL_PIN(PIN_ULPI_0, "ulpi-0"),
0717 PINCTRL_PIN(PIN_HSIC_0, "hsic-0"),
0718 PINCTRL_PIN(PIN_HSIC_1, "hsic-1"),
0719 PINCTRL_PIN(PIN_PCIE_0, "pcie-0"),
0720 PINCTRL_PIN(PIN_PCIE_1, "pcie-1"),
0721 PINCTRL_PIN(PIN_PCIE_2, "pcie-2"),
0722 PINCTRL_PIN(PIN_PCIE_3, "pcie-3"),
0723 PINCTRL_PIN(PIN_PCIE_4, "pcie-4"),
0724 PINCTRL_PIN(PIN_SATA_0, "sata-0"),
0725 };
0726
0727 static const char * const tegra124_snps_groups[] = {
0728 "otg-0",
0729 "otg-1",
0730 "otg-2",
0731 "ulpi-0",
0732 "hsic-0",
0733 "hsic-1",
0734 };
0735
0736 static const char * const tegra124_xusb_groups[] = {
0737 "otg-0",
0738 "otg-1",
0739 "otg-2",
0740 "ulpi-0",
0741 "hsic-0",
0742 "hsic-1",
0743 };
0744
0745 static const char * const tegra124_uart_groups[] = {
0746 "otg-0",
0747 "otg-1",
0748 "otg-2",
0749 };
0750
0751 static const char * const tegra124_pcie_groups[] = {
0752 "pcie-0",
0753 "pcie-1",
0754 "pcie-2",
0755 "pcie-3",
0756 "pcie-4",
0757 };
0758
0759 static const char * const tegra124_usb3_groups[] = {
0760 "pcie-0",
0761 "pcie-1",
0762 "sata-0",
0763 };
0764
0765 static const char * const tegra124_sata_groups[] = {
0766 "sata-0",
0767 };
0768
0769 static const char * const tegra124_rsvd_groups[] = {
0770 "otg-0",
0771 "otg-1",
0772 "otg-2",
0773 "pcie-0",
0774 "pcie-1",
0775 "pcie-2",
0776 "pcie-3",
0777 "pcie-4",
0778 "sata-0",
0779 };
0780
0781 #define TEGRA124_FUNCTION(_name) \
0782 { \
0783 .name = #_name, \
0784 .num_groups = ARRAY_SIZE(tegra124_##_name##_groups), \
0785 .groups = tegra124_##_name##_groups, \
0786 }
0787
0788 static struct tegra_xusb_padctl_function tegra124_functions[] = {
0789 TEGRA124_FUNCTION(snps),
0790 TEGRA124_FUNCTION(xusb),
0791 TEGRA124_FUNCTION(uart),
0792 TEGRA124_FUNCTION(pcie),
0793 TEGRA124_FUNCTION(usb3),
0794 TEGRA124_FUNCTION(sata),
0795 TEGRA124_FUNCTION(rsvd),
0796 };
0797
0798 enum tegra124_function {
0799 TEGRA124_FUNC_SNPS,
0800 TEGRA124_FUNC_XUSB,
0801 TEGRA124_FUNC_UART,
0802 TEGRA124_FUNC_PCIE,
0803 TEGRA124_FUNC_USB3,
0804 TEGRA124_FUNC_SATA,
0805 TEGRA124_FUNC_RSVD,
0806 };
0807
0808 static const unsigned int tegra124_otg_functions[] = {
0809 TEGRA124_FUNC_SNPS,
0810 TEGRA124_FUNC_XUSB,
0811 TEGRA124_FUNC_UART,
0812 TEGRA124_FUNC_RSVD,
0813 };
0814
0815 static const unsigned int tegra124_usb_functions[] = {
0816 TEGRA124_FUNC_SNPS,
0817 TEGRA124_FUNC_XUSB,
0818 };
0819
0820 static const unsigned int tegra124_pci_functions[] = {
0821 TEGRA124_FUNC_PCIE,
0822 TEGRA124_FUNC_USB3,
0823 TEGRA124_FUNC_SATA,
0824 TEGRA124_FUNC_RSVD,
0825 };
0826
0827 #define TEGRA124_LANE(_name, _offset, _shift, _mask, _iddq, _funcs) \
0828 { \
0829 .name = _name, \
0830 .offset = _offset, \
0831 .shift = _shift, \
0832 .mask = _mask, \
0833 .iddq = _iddq, \
0834 .num_funcs = ARRAY_SIZE(tegra124_##_funcs##_functions), \
0835 .funcs = tegra124_##_funcs##_functions, \
0836 }
0837
0838 static const struct tegra_xusb_padctl_lane tegra124_lanes[] = {
0839 TEGRA124_LANE("otg-0", 0x004, 0, 0x3, 0, otg),
0840 TEGRA124_LANE("otg-1", 0x004, 2, 0x3, 0, otg),
0841 TEGRA124_LANE("otg-2", 0x004, 4, 0x3, 0, otg),
0842 TEGRA124_LANE("ulpi-0", 0x004, 12, 0x1, 0, usb),
0843 TEGRA124_LANE("hsic-0", 0x004, 14, 0x1, 0, usb),
0844 TEGRA124_LANE("hsic-1", 0x004, 15, 0x1, 0, usb),
0845 TEGRA124_LANE("pcie-0", 0x134, 16, 0x3, 1, pci),
0846 TEGRA124_LANE("pcie-1", 0x134, 18, 0x3, 2, pci),
0847 TEGRA124_LANE("pcie-2", 0x134, 20, 0x3, 3, pci),
0848 TEGRA124_LANE("pcie-3", 0x134, 22, 0x3, 4, pci),
0849 TEGRA124_LANE("pcie-4", 0x134, 24, 0x3, 5, pci),
0850 TEGRA124_LANE("sata-0", 0x134, 26, 0x3, 6, pci),
0851 };
0852
0853 static const struct tegra_xusb_padctl_soc tegra124_soc = {
0854 .num_pins = ARRAY_SIZE(tegra124_pins),
0855 .pins = tegra124_pins,
0856 .num_functions = ARRAY_SIZE(tegra124_functions),
0857 .functions = tegra124_functions,
0858 .num_lanes = ARRAY_SIZE(tegra124_lanes),
0859 .lanes = tegra124_lanes,
0860 };
0861
0862 static const struct of_device_id tegra_xusb_padctl_of_match[] = {
0863 { .compatible = "nvidia,tegra124-xusb-padctl", .data = &tegra124_soc },
0864 { }
0865 };
0866 MODULE_DEVICE_TABLE(of, tegra_xusb_padctl_of_match);
0867
0868
0869 int tegra_xusb_padctl_legacy_probe(struct platform_device *pdev);
0870 int tegra_xusb_padctl_legacy_remove(struct platform_device *pdev);
0871
0872 int tegra_xusb_padctl_legacy_probe(struct platform_device *pdev)
0873 {
0874 struct tegra_xusb_padctl *padctl;
0875 const struct of_device_id *match;
0876 struct phy *phy;
0877 int err;
0878
0879 padctl = devm_kzalloc(&pdev->dev, sizeof(*padctl), GFP_KERNEL);
0880 if (!padctl)
0881 return -ENOMEM;
0882
0883 platform_set_drvdata(pdev, padctl);
0884 mutex_init(&padctl->lock);
0885 padctl->dev = &pdev->dev;
0886
0887
0888
0889
0890
0891
0892
0893 match = of_match_node(tegra_xusb_padctl_of_match, pdev->dev.of_node);
0894 padctl->soc = match->data;
0895
0896 padctl->regs = devm_platform_ioremap_resource(pdev, 0);
0897 if (IS_ERR(padctl->regs))
0898 return PTR_ERR(padctl->regs);
0899
0900 padctl->rst = devm_reset_control_get_exclusive(&pdev->dev, NULL);
0901 if (IS_ERR(padctl->rst))
0902 return PTR_ERR(padctl->rst);
0903
0904 err = reset_control_deassert(padctl->rst);
0905 if (err < 0)
0906 return err;
0907
0908 memset(&padctl->desc, 0, sizeof(padctl->desc));
0909 padctl->desc.name = dev_name(padctl->dev);
0910 padctl->desc.pins = tegra124_pins;
0911 padctl->desc.npins = ARRAY_SIZE(tegra124_pins);
0912 padctl->desc.pctlops = &tegra_xusb_padctl_pinctrl_ops;
0913 padctl->desc.pmxops = &tegra_xusb_padctl_pinmux_ops;
0914 padctl->desc.confops = &tegra_xusb_padctl_pinconf_ops;
0915 padctl->desc.owner = THIS_MODULE;
0916
0917 padctl->pinctrl = devm_pinctrl_register(&pdev->dev, &padctl->desc,
0918 padctl);
0919 if (IS_ERR(padctl->pinctrl)) {
0920 dev_err(&pdev->dev, "failed to register pincontrol\n");
0921 err = PTR_ERR(padctl->pinctrl);
0922 goto reset;
0923 }
0924
0925 phy = devm_phy_create(&pdev->dev, NULL, &pcie_phy_ops);
0926 if (IS_ERR(phy)) {
0927 err = PTR_ERR(phy);
0928 goto reset;
0929 }
0930
0931 padctl->phys[TEGRA_XUSB_PADCTL_PCIE] = phy;
0932 phy_set_drvdata(phy, padctl);
0933
0934 phy = devm_phy_create(&pdev->dev, NULL, &sata_phy_ops);
0935 if (IS_ERR(phy)) {
0936 err = PTR_ERR(phy);
0937 goto reset;
0938 }
0939
0940 padctl->phys[TEGRA_XUSB_PADCTL_SATA] = phy;
0941 phy_set_drvdata(phy, padctl);
0942
0943 padctl->provider = devm_of_phy_provider_register(&pdev->dev,
0944 tegra_xusb_padctl_xlate);
0945 if (IS_ERR(padctl->provider)) {
0946 err = PTR_ERR(padctl->provider);
0947 dev_err(&pdev->dev, "failed to register PHYs: %d\n", err);
0948 goto reset;
0949 }
0950
0951 return 0;
0952
0953 reset:
0954 reset_control_assert(padctl->rst);
0955 return err;
0956 }
0957 EXPORT_SYMBOL_GPL(tegra_xusb_padctl_legacy_probe);
0958
0959 int tegra_xusb_padctl_legacy_remove(struct platform_device *pdev)
0960 {
0961 struct tegra_xusb_padctl *padctl = platform_get_drvdata(pdev);
0962 int err;
0963
0964 err = reset_control_assert(padctl->rst);
0965 if (err < 0)
0966 dev_err(&pdev->dev, "failed to assert reset: %d\n", err);
0967
0968 return err;
0969 }
0970 EXPORT_SYMBOL_GPL(tegra_xusb_padctl_legacy_remove);