2 * Copyright (c) 2014, NVIDIA CORPORATION. All rights reserved.
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms and conditions of the GNU General Public License,
6 * version 2, as published by the Free Software Foundation.
8 * This program is distributed in the hope it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 #include <linux/delay.h>
16 #include <linux/module.h>
18 #include <linux/phy/phy.h>
19 #include <linux/pinctrl/pinctrl.h>
20 #include <linux/pinctrl/pinmux.h>
21 #include <linux/platform_device.h>
22 #include <linux/reset.h>
23 #include <linux/slab.h>
25 #include <dt-bindings/pinctrl/pinctrl-tegra-xusb.h>
28 #include "pinctrl-utils.h"
30 #define XUSB_PADCTL_ELPG_PROGRAM 0x01c
31 #define XUSB_PADCTL_ELPG_PROGRAM_AUX_MUX_LP0_VCORE_DOWN (1 << 26)
32 #define XUSB_PADCTL_ELPG_PROGRAM_AUX_MUX_LP0_CLAMP_EN_EARLY (1 << 25)
33 #define XUSB_PADCTL_ELPG_PROGRAM_AUX_MUX_LP0_CLAMP_EN (1 << 24)
35 #define XUSB_PADCTL_IOPHY_PLL_P0_CTL1 0x040
36 #define XUSB_PADCTL_IOPHY_PLL_P0_CTL1_PLL0_LOCKDET (1 << 19)
37 #define XUSB_PADCTL_IOPHY_PLL_P0_CTL1_REFCLK_SEL_MASK (0xf << 12)
38 #define XUSB_PADCTL_IOPHY_PLL_P0_CTL1_PLL_RST (1 << 1)
40 #define XUSB_PADCTL_IOPHY_PLL_P0_CTL2 0x044
41 #define XUSB_PADCTL_IOPHY_PLL_P0_CTL2_REFCLKBUF_EN (1 << 6)
42 #define XUSB_PADCTL_IOPHY_PLL_P0_CTL2_TXCLKREF_EN (1 << 5)
43 #define XUSB_PADCTL_IOPHY_PLL_P0_CTL2_TXCLKREF_SEL (1 << 4)
45 #define XUSB_PADCTL_IOPHY_PLL_S0_CTL1 0x138
46 #define XUSB_PADCTL_IOPHY_PLL_S0_CTL1_PLL1_LOCKDET (1 << 27)
47 #define XUSB_PADCTL_IOPHY_PLL_S0_CTL1_PLL1_MODE (1 << 24)
48 #define XUSB_PADCTL_IOPHY_PLL_S0_CTL1_PLL_PWR_OVRD (1 << 3)
49 #define XUSB_PADCTL_IOPHY_PLL_S0_CTL1_PLL_RST (1 << 1)
50 #define XUSB_PADCTL_IOPHY_PLL_S0_CTL1_PLL_IDDQ (1 << 0)
52 #define XUSB_PADCTL_IOPHY_MISC_PAD_S0_CTL1 0x148
53 #define XUSB_PADCTL_IOPHY_MISC_PAD_S0_CTL1_IDDQ_OVRD (1 << 1)
54 #define XUSB_PADCTL_IOPHY_MISC_PAD_S0_CTL1_IDDQ (1 << 0)
56 struct tegra_xusb_padctl_function
{
58 const char * const *groups
;
59 unsigned int num_groups
;
62 struct tegra_xusb_padctl_group
{
63 const unsigned int *funcs
;
64 unsigned int num_funcs
;
67 struct tegra_xusb_padctl_soc
{
68 const struct pinctrl_pin_desc
*pins
;
69 unsigned int num_pins
;
71 const struct tegra_xusb_padctl_function
*functions
;
72 unsigned int num_functions
;
74 const struct tegra_xusb_padctl_lane
*lanes
;
75 unsigned int num_lanes
;
78 struct tegra_xusb_padctl_lane
{
86 const unsigned int *funcs
;
87 unsigned int num_funcs
;
90 struct tegra_xusb_padctl
{
94 struct reset_control
*rst
;
96 const struct tegra_xusb_padctl_soc
*soc
;
97 struct pinctrl_dev
*pinctrl
;
98 struct pinctrl_desc desc
;
100 struct phy_provider
*provider
;
106 static inline void padctl_writel(struct tegra_xusb_padctl
*padctl
, u32 value
,
107 unsigned long offset
)
109 writel(value
, padctl
->regs
+ offset
);
112 static inline u32
padctl_readl(struct tegra_xusb_padctl
*padctl
,
113 unsigned long offset
)
115 return readl(padctl
->regs
+ offset
);
118 static int tegra_xusb_padctl_get_groups_count(struct pinctrl_dev
*pinctrl
)
120 struct tegra_xusb_padctl
*padctl
= pinctrl_dev_get_drvdata(pinctrl
);
122 return padctl
->soc
->num_pins
;
125 static const char *tegra_xusb_padctl_get_group_name(struct pinctrl_dev
*pinctrl
,
128 struct tegra_xusb_padctl
*padctl
= pinctrl_dev_get_drvdata(pinctrl
);
130 return padctl
->soc
->pins
[group
].name
;
133 enum tegra_xusb_padctl_param
{
134 TEGRA_XUSB_PADCTL_IDDQ
,
137 static const struct tegra_xusb_padctl_property
{
139 enum tegra_xusb_padctl_param param
;
141 { "nvidia,iddq", TEGRA_XUSB_PADCTL_IDDQ
},
144 #define TEGRA_XUSB_PADCTL_PACK(param, value) ((param) << 16 | (value))
145 #define TEGRA_XUSB_PADCTL_UNPACK_PARAM(config) ((config) >> 16)
146 #define TEGRA_XUSB_PADCTL_UNPACK_VALUE(config) ((config) & 0xffff)
148 static int tegra_xusb_padctl_parse_subnode(struct tegra_xusb_padctl
*padctl
,
149 struct device_node
*np
,
150 struct pinctrl_map
**maps
,
151 unsigned int *reserved_maps
,
152 unsigned int *num_maps
)
154 unsigned int i
, reserve
= 0, num_configs
= 0;
155 unsigned long config
, *configs
= NULL
;
156 const char *function
, *group
;
157 struct property
*prop
;
161 err
= of_property_read_string(np
, "nvidia,function", &function
);
169 for (i
= 0; i
< ARRAY_SIZE(properties
); i
++) {
170 err
= of_property_read_u32(np
, properties
[i
].name
, &value
);
178 config
= TEGRA_XUSB_PADCTL_PACK(properties
[i
].param
, value
);
180 err
= pinctrl_utils_add_config(padctl
->pinctrl
, &configs
,
181 &num_configs
, config
);
192 err
= of_property_count_strings(np
, "nvidia,lanes");
198 err
= pinctrl_utils_reserve_map(padctl
->pinctrl
, maps
, reserved_maps
,
203 of_property_for_each_string(np
, "nvidia,lanes", prop
, group
) {
205 err
= pinctrl_utils_add_map_mux(padctl
->pinctrl
, maps
,
206 reserved_maps
, num_maps
, group
,
213 err
= pinctrl_utils_add_map_configs(padctl
->pinctrl
,
214 maps
, reserved_maps
, num_maps
, group
,
215 configs
, num_configs
,
216 PIN_MAP_TYPE_CONFIGS_GROUP
);
229 static int tegra_xusb_padctl_dt_node_to_map(struct pinctrl_dev
*pinctrl
,
230 struct device_node
*parent
,
231 struct pinctrl_map
**maps
,
232 unsigned int *num_maps
)
234 struct tegra_xusb_padctl
*padctl
= pinctrl_dev_get_drvdata(pinctrl
);
235 unsigned int reserved_maps
= 0;
236 struct device_node
*np
;
242 for_each_child_of_node(parent
, np
) {
243 err
= tegra_xusb_padctl_parse_subnode(padctl
, np
, maps
,
253 static const struct pinctrl_ops tegra_xusb_padctl_pinctrl_ops
= {
254 .get_groups_count
= tegra_xusb_padctl_get_groups_count
,
255 .get_group_name
= tegra_xusb_padctl_get_group_name
,
256 .dt_node_to_map
= tegra_xusb_padctl_dt_node_to_map
,
257 .dt_free_map
= pinctrl_utils_dt_free_map
,
260 static int tegra_xusb_padctl_get_functions_count(struct pinctrl_dev
*pinctrl
)
262 struct tegra_xusb_padctl
*padctl
= pinctrl_dev_get_drvdata(pinctrl
);
264 return padctl
->soc
->num_functions
;
268 tegra_xusb_padctl_get_function_name(struct pinctrl_dev
*pinctrl
,
269 unsigned int function
)
271 struct tegra_xusb_padctl
*padctl
= pinctrl_dev_get_drvdata(pinctrl
);
273 return padctl
->soc
->functions
[function
].name
;
276 static int tegra_xusb_padctl_get_function_groups(struct pinctrl_dev
*pinctrl
,
277 unsigned int function
,
278 const char * const **groups
,
279 unsigned * const num_groups
)
281 struct tegra_xusb_padctl
*padctl
= pinctrl_dev_get_drvdata(pinctrl
);
283 *num_groups
= padctl
->soc
->functions
[function
].num_groups
;
284 *groups
= padctl
->soc
->functions
[function
].groups
;
289 static int tegra_xusb_padctl_pinmux_set(struct pinctrl_dev
*pinctrl
,
290 unsigned int function
,
293 struct tegra_xusb_padctl
*padctl
= pinctrl_dev_get_drvdata(pinctrl
);
294 const struct tegra_xusb_padctl_lane
*lane
;
298 lane
= &padctl
->soc
->lanes
[group
];
300 for (i
= 0; i
< lane
->num_funcs
; i
++)
301 if (lane
->funcs
[i
] == function
)
304 if (i
>= lane
->num_funcs
)
307 value
= padctl_readl(padctl
, lane
->offset
);
308 value
&= ~(lane
->mask
<< lane
->shift
);
309 value
|= i
<< lane
->shift
;
310 padctl_writel(padctl
, value
, lane
->offset
);
315 static const struct pinmux_ops tegra_xusb_padctl_pinmux_ops
= {
316 .get_functions_count
= tegra_xusb_padctl_get_functions_count
,
317 .get_function_name
= tegra_xusb_padctl_get_function_name
,
318 .get_function_groups
= tegra_xusb_padctl_get_function_groups
,
319 .set_mux
= tegra_xusb_padctl_pinmux_set
,
322 static int tegra_xusb_padctl_pinconf_group_get(struct pinctrl_dev
*pinctrl
,
324 unsigned long *config
)
326 struct tegra_xusb_padctl
*padctl
= pinctrl_dev_get_drvdata(pinctrl
);
327 const struct tegra_xusb_padctl_lane
*lane
;
328 enum tegra_xusb_padctl_param param
;
331 param
= TEGRA_XUSB_PADCTL_UNPACK_PARAM(*config
);
332 lane
= &padctl
->soc
->lanes
[group
];
335 case TEGRA_XUSB_PADCTL_IDDQ
:
336 /* lanes with iddq == 0 don't support this parameter */
340 value
= padctl_readl(padctl
, lane
->offset
);
342 if (value
& BIT(lane
->iddq
))
347 *config
= TEGRA_XUSB_PADCTL_PACK(param
, value
);
351 dev_err(padctl
->dev
, "invalid configuration parameter: %04x\n",
359 static int tegra_xusb_padctl_pinconf_group_set(struct pinctrl_dev
*pinctrl
,
361 unsigned long *configs
,
362 unsigned int num_configs
)
364 struct tegra_xusb_padctl
*padctl
= pinctrl_dev_get_drvdata(pinctrl
);
365 const struct tegra_xusb_padctl_lane
*lane
;
366 enum tegra_xusb_padctl_param param
;
371 lane
= &padctl
->soc
->lanes
[group
];
373 for (i
= 0; i
< num_configs
; i
++) {
374 param
= TEGRA_XUSB_PADCTL_UNPACK_PARAM(configs
[i
]);
375 value
= TEGRA_XUSB_PADCTL_UNPACK_VALUE(configs
[i
]);
378 case TEGRA_XUSB_PADCTL_IDDQ
:
379 /* lanes with iddq == 0 don't support this parameter */
383 regval
= padctl_readl(padctl
, lane
->offset
);
386 regval
&= ~BIT(lane
->iddq
);
388 regval
|= BIT(lane
->iddq
);
390 padctl_writel(padctl
, regval
, lane
->offset
);
395 "invalid configuration parameter: %04x\n",
404 #ifdef CONFIG_DEBUG_FS
405 static const char *strip_prefix(const char *s
)
407 const char *comma
= strchr(s
, ',');
415 tegra_xusb_padctl_pinconf_group_dbg_show(struct pinctrl_dev
*pinctrl
,
421 for (i
= 0; i
< ARRAY_SIZE(properties
); i
++) {
422 unsigned long config
, value
;
425 config
= TEGRA_XUSB_PADCTL_PACK(properties
[i
].param
, 0);
427 err
= tegra_xusb_padctl_pinconf_group_get(pinctrl
, group
,
432 value
= TEGRA_XUSB_PADCTL_UNPACK_VALUE(config
);
434 seq_printf(s
, "\n\t%s=%lu\n", strip_prefix(properties
[i
].name
),
440 tegra_xusb_padctl_pinconf_config_dbg_show(struct pinctrl_dev
*pinctrl
,
442 unsigned long config
)
444 enum tegra_xusb_padctl_param param
;
445 const char *name
= "unknown";
449 param
= TEGRA_XUSB_PADCTL_UNPACK_PARAM(config
);
450 value
= TEGRA_XUSB_PADCTL_UNPACK_VALUE(config
);
452 for (i
= 0; i
< ARRAY_SIZE(properties
); i
++) {
453 if (properties
[i
].param
== param
) {
454 name
= properties
[i
].name
;
459 seq_printf(s
, "%s=%lu", strip_prefix(name
), value
);
463 static const struct pinconf_ops tegra_xusb_padctl_pinconf_ops
= {
464 .pin_config_group_get
= tegra_xusb_padctl_pinconf_group_get
,
465 .pin_config_group_set
= tegra_xusb_padctl_pinconf_group_set
,
466 #ifdef CONFIG_DEBUG_FS
467 .pin_config_group_dbg_show
= tegra_xusb_padctl_pinconf_group_dbg_show
,
468 .pin_config_config_dbg_show
= tegra_xusb_padctl_pinconf_config_dbg_show
,
472 static int tegra_xusb_padctl_enable(struct tegra_xusb_padctl
*padctl
)
476 mutex_lock(&padctl
->lock
);
478 if (padctl
->enable
++ > 0)
481 value
= padctl_readl(padctl
, XUSB_PADCTL_ELPG_PROGRAM
);
482 value
&= ~XUSB_PADCTL_ELPG_PROGRAM_AUX_MUX_LP0_CLAMP_EN
;
483 padctl_writel(padctl
, value
, XUSB_PADCTL_ELPG_PROGRAM
);
485 usleep_range(100, 200);
487 value
= padctl_readl(padctl
, XUSB_PADCTL_ELPG_PROGRAM
);
488 value
&= ~XUSB_PADCTL_ELPG_PROGRAM_AUX_MUX_LP0_CLAMP_EN_EARLY
;
489 padctl_writel(padctl
, value
, XUSB_PADCTL_ELPG_PROGRAM
);
491 usleep_range(100, 200);
493 value
= padctl_readl(padctl
, XUSB_PADCTL_ELPG_PROGRAM
);
494 value
&= ~XUSB_PADCTL_ELPG_PROGRAM_AUX_MUX_LP0_VCORE_DOWN
;
495 padctl_writel(padctl
, value
, XUSB_PADCTL_ELPG_PROGRAM
);
498 mutex_unlock(&padctl
->lock
);
502 static int tegra_xusb_padctl_disable(struct tegra_xusb_padctl
*padctl
)
506 mutex_lock(&padctl
->lock
);
508 if (WARN_ON(padctl
->enable
== 0))
511 if (--padctl
->enable
> 0)
514 value
= padctl_readl(padctl
, XUSB_PADCTL_ELPG_PROGRAM
);
515 value
|= XUSB_PADCTL_ELPG_PROGRAM_AUX_MUX_LP0_VCORE_DOWN
;
516 padctl_writel(padctl
, value
, XUSB_PADCTL_ELPG_PROGRAM
);
518 usleep_range(100, 200);
520 value
= padctl_readl(padctl
, XUSB_PADCTL_ELPG_PROGRAM
);
521 value
|= XUSB_PADCTL_ELPG_PROGRAM_AUX_MUX_LP0_CLAMP_EN_EARLY
;
522 padctl_writel(padctl
, value
, XUSB_PADCTL_ELPG_PROGRAM
);
524 usleep_range(100, 200);
526 value
= padctl_readl(padctl
, XUSB_PADCTL_ELPG_PROGRAM
);
527 value
|= XUSB_PADCTL_ELPG_PROGRAM_AUX_MUX_LP0_CLAMP_EN
;
528 padctl_writel(padctl
, value
, XUSB_PADCTL_ELPG_PROGRAM
);
531 mutex_unlock(&padctl
->lock
);
535 static int tegra_xusb_phy_init(struct phy
*phy
)
537 struct tegra_xusb_padctl
*padctl
= phy_get_drvdata(phy
);
539 return tegra_xusb_padctl_enable(padctl
);
542 static int tegra_xusb_phy_exit(struct phy
*phy
)
544 struct tegra_xusb_padctl
*padctl
= phy_get_drvdata(phy
);
546 return tegra_xusb_padctl_disable(padctl
);
549 static int pcie_phy_power_on(struct phy
*phy
)
551 struct tegra_xusb_padctl
*padctl
= phy_get_drvdata(phy
);
552 unsigned long timeout
;
553 int err
= -ETIMEDOUT
;
556 value
= padctl_readl(padctl
, XUSB_PADCTL_IOPHY_PLL_P0_CTL1
);
557 value
&= ~XUSB_PADCTL_IOPHY_PLL_P0_CTL1_REFCLK_SEL_MASK
;
558 padctl_writel(padctl
, value
, XUSB_PADCTL_IOPHY_PLL_P0_CTL1
);
560 value
= padctl_readl(padctl
, XUSB_PADCTL_IOPHY_PLL_P0_CTL2
);
561 value
|= XUSB_PADCTL_IOPHY_PLL_P0_CTL2_REFCLKBUF_EN
|
562 XUSB_PADCTL_IOPHY_PLL_P0_CTL2_TXCLKREF_EN
|
563 XUSB_PADCTL_IOPHY_PLL_P0_CTL2_TXCLKREF_SEL
;
564 padctl_writel(padctl
, value
, XUSB_PADCTL_IOPHY_PLL_P0_CTL2
);
566 value
= padctl_readl(padctl
, XUSB_PADCTL_IOPHY_PLL_P0_CTL1
);
567 value
|= XUSB_PADCTL_IOPHY_PLL_P0_CTL1_PLL_RST
;
568 padctl_writel(padctl
, value
, XUSB_PADCTL_IOPHY_PLL_P0_CTL1
);
570 timeout
= jiffies
+ msecs_to_jiffies(50);
572 while (time_before(jiffies
, timeout
)) {
573 value
= padctl_readl(padctl
, XUSB_PADCTL_IOPHY_PLL_P0_CTL1
);
574 if (value
& XUSB_PADCTL_IOPHY_PLL_P0_CTL1_PLL0_LOCKDET
) {
579 usleep_range(100, 200);
585 static int pcie_phy_power_off(struct phy
*phy
)
587 struct tegra_xusb_padctl
*padctl
= phy_get_drvdata(phy
);
590 value
= padctl_readl(padctl
, XUSB_PADCTL_IOPHY_PLL_P0_CTL1
);
591 value
&= ~XUSB_PADCTL_IOPHY_PLL_P0_CTL1_PLL_RST
;
592 padctl_writel(padctl
, value
, XUSB_PADCTL_IOPHY_PLL_P0_CTL1
);
597 static const struct phy_ops pcie_phy_ops
= {
598 .init
= tegra_xusb_phy_init
,
599 .exit
= tegra_xusb_phy_exit
,
600 .power_on
= pcie_phy_power_on
,
601 .power_off
= pcie_phy_power_off
,
602 .owner
= THIS_MODULE
,
605 static int sata_phy_power_on(struct phy
*phy
)
607 struct tegra_xusb_padctl
*padctl
= phy_get_drvdata(phy
);
608 unsigned long timeout
;
609 int err
= -ETIMEDOUT
;
612 value
= padctl_readl(padctl
, XUSB_PADCTL_IOPHY_MISC_PAD_S0_CTL1
);
613 value
&= ~XUSB_PADCTL_IOPHY_MISC_PAD_S0_CTL1_IDDQ_OVRD
;
614 value
&= ~XUSB_PADCTL_IOPHY_MISC_PAD_S0_CTL1_IDDQ
;
615 padctl_writel(padctl
, value
, XUSB_PADCTL_IOPHY_MISC_PAD_S0_CTL1
);
617 value
= padctl_readl(padctl
, XUSB_PADCTL_IOPHY_PLL_S0_CTL1
);
618 value
&= ~XUSB_PADCTL_IOPHY_PLL_S0_CTL1_PLL_PWR_OVRD
;
619 value
&= ~XUSB_PADCTL_IOPHY_PLL_S0_CTL1_PLL_IDDQ
;
620 padctl_writel(padctl
, value
, XUSB_PADCTL_IOPHY_PLL_S0_CTL1
);
622 value
= padctl_readl(padctl
, XUSB_PADCTL_IOPHY_PLL_S0_CTL1
);
623 value
|= XUSB_PADCTL_IOPHY_PLL_S0_CTL1_PLL1_MODE
;
624 padctl_writel(padctl
, value
, XUSB_PADCTL_IOPHY_PLL_S0_CTL1
);
626 value
= padctl_readl(padctl
, XUSB_PADCTL_IOPHY_PLL_S0_CTL1
);
627 value
|= XUSB_PADCTL_IOPHY_PLL_S0_CTL1_PLL_RST
;
628 padctl_writel(padctl
, value
, XUSB_PADCTL_IOPHY_PLL_S0_CTL1
);
630 timeout
= jiffies
+ msecs_to_jiffies(50);
632 while (time_before(jiffies
, timeout
)) {
633 value
= padctl_readl(padctl
, XUSB_PADCTL_IOPHY_PLL_S0_CTL1
);
634 if (value
& XUSB_PADCTL_IOPHY_PLL_S0_CTL1_PLL1_LOCKDET
) {
639 usleep_range(100, 200);
645 static int sata_phy_power_off(struct phy
*phy
)
647 struct tegra_xusb_padctl
*padctl
= phy_get_drvdata(phy
);
650 value
= padctl_readl(padctl
, XUSB_PADCTL_IOPHY_PLL_S0_CTL1
);
651 value
&= ~XUSB_PADCTL_IOPHY_PLL_S0_CTL1_PLL_RST
;
652 padctl_writel(padctl
, value
, XUSB_PADCTL_IOPHY_PLL_S0_CTL1
);
654 value
= padctl_readl(padctl
, XUSB_PADCTL_IOPHY_PLL_S0_CTL1
);
655 value
&= ~XUSB_PADCTL_IOPHY_PLL_S0_CTL1_PLL1_MODE
;
656 padctl_writel(padctl
, value
, XUSB_PADCTL_IOPHY_PLL_S0_CTL1
);
658 value
= padctl_readl(padctl
, XUSB_PADCTL_IOPHY_PLL_S0_CTL1
);
659 value
|= XUSB_PADCTL_IOPHY_PLL_S0_CTL1_PLL_PWR_OVRD
;
660 value
|= XUSB_PADCTL_IOPHY_PLL_S0_CTL1_PLL_IDDQ
;
661 padctl_writel(padctl
, value
, XUSB_PADCTL_IOPHY_PLL_S0_CTL1
);
663 value
= padctl_readl(padctl
, XUSB_PADCTL_IOPHY_MISC_PAD_S0_CTL1
);
664 value
|= ~XUSB_PADCTL_IOPHY_MISC_PAD_S0_CTL1_IDDQ_OVRD
;
665 value
|= ~XUSB_PADCTL_IOPHY_MISC_PAD_S0_CTL1_IDDQ
;
666 padctl_writel(padctl
, value
, XUSB_PADCTL_IOPHY_MISC_PAD_S0_CTL1
);
671 static const struct phy_ops sata_phy_ops
= {
672 .init
= tegra_xusb_phy_init
,
673 .exit
= tegra_xusb_phy_exit
,
674 .power_on
= sata_phy_power_on
,
675 .power_off
= sata_phy_power_off
,
676 .owner
= THIS_MODULE
,
679 static struct phy
*tegra_xusb_padctl_xlate(struct device
*dev
,
680 struct of_phandle_args
*args
)
682 struct tegra_xusb_padctl
*padctl
= dev_get_drvdata(dev
);
683 unsigned int index
= args
->args
[0];
685 if (args
->args_count
<= 0)
686 return ERR_PTR(-EINVAL
);
688 if (index
>= ARRAY_SIZE(padctl
->phys
))
689 return ERR_PTR(-EINVAL
);
691 return padctl
->phys
[index
];
704 #define PIN_PCIE_4 10
705 #define PIN_SATA_0 11
707 static const struct pinctrl_pin_desc tegra124_pins
[] = {
708 PINCTRL_PIN(PIN_OTG_0
, "otg-0"),
709 PINCTRL_PIN(PIN_OTG_1
, "otg-1"),
710 PINCTRL_PIN(PIN_OTG_2
, "otg-2"),
711 PINCTRL_PIN(PIN_ULPI_0
, "ulpi-0"),
712 PINCTRL_PIN(PIN_HSIC_0
, "hsic-0"),
713 PINCTRL_PIN(PIN_HSIC_1
, "hsic-1"),
714 PINCTRL_PIN(PIN_PCIE_0
, "pcie-0"),
715 PINCTRL_PIN(PIN_PCIE_1
, "pcie-1"),
716 PINCTRL_PIN(PIN_PCIE_2
, "pcie-2"),
717 PINCTRL_PIN(PIN_PCIE_3
, "pcie-3"),
718 PINCTRL_PIN(PIN_PCIE_4
, "pcie-4"),
719 PINCTRL_PIN(PIN_SATA_0
, "sata-0"),
722 static const char * const tegra124_snps_groups
[] = {
731 static const char * const tegra124_xusb_groups
[] = {
740 static const char * const tegra124_uart_groups
[] = {
746 static const char * const tegra124_pcie_groups
[] = {
755 static const char * const tegra124_usb3_groups
[] = {
764 static const char * const tegra124_sata_groups
[] = {
773 static const char * const tegra124_rsvd_groups
[] = {
785 #define TEGRA124_FUNCTION(_name) \
788 .num_groups = ARRAY_SIZE(tegra124_##_name##_groups), \
789 .groups = tegra124_##_name##_groups, \
792 static struct tegra_xusb_padctl_function tegra124_functions
[] = {
793 TEGRA124_FUNCTION(snps
),
794 TEGRA124_FUNCTION(xusb
),
795 TEGRA124_FUNCTION(uart
),
796 TEGRA124_FUNCTION(pcie
),
797 TEGRA124_FUNCTION(usb3
),
798 TEGRA124_FUNCTION(sata
),
799 TEGRA124_FUNCTION(rsvd
),
802 enum tegra124_function
{
812 static const unsigned int tegra124_otg_functions
[] = {
819 static const unsigned int tegra124_usb_functions
[] = {
824 static const unsigned int tegra124_pci_functions
[] = {
831 #define TEGRA124_LANE(_name, _offset, _shift, _mask, _iddq, _funcs) \
838 .num_funcs = ARRAY_SIZE(tegra124_##_funcs##_functions), \
839 .funcs = tegra124_##_funcs##_functions, \
842 static const struct tegra_xusb_padctl_lane tegra124_lanes
[] = {
843 TEGRA124_LANE("otg-0", 0x004, 0, 0x3, 0, otg
),
844 TEGRA124_LANE("otg-1", 0x004, 2, 0x3, 0, otg
),
845 TEGRA124_LANE("otg-2", 0x004, 4, 0x3, 0, otg
),
846 TEGRA124_LANE("ulpi-0", 0x004, 12, 0x1, 0, usb
),
847 TEGRA124_LANE("hsic-0", 0x004, 14, 0x1, 0, usb
),
848 TEGRA124_LANE("hsic-1", 0x004, 15, 0x1, 0, usb
),
849 TEGRA124_LANE("pcie-0", 0x134, 16, 0x3, 1, pci
),
850 TEGRA124_LANE("pcie-1", 0x134, 18, 0x3, 2, pci
),
851 TEGRA124_LANE("pcie-2", 0x134, 20, 0x3, 3, pci
),
852 TEGRA124_LANE("pcie-3", 0x134, 22, 0x3, 4, pci
),
853 TEGRA124_LANE("pcie-4", 0x134, 24, 0x3, 5, pci
),
854 TEGRA124_LANE("sata-0", 0x134, 26, 0x3, 6, pci
),
857 static const struct tegra_xusb_padctl_soc tegra124_soc
= {
858 .num_pins
= ARRAY_SIZE(tegra124_pins
),
859 .pins
= tegra124_pins
,
860 .num_functions
= ARRAY_SIZE(tegra124_functions
),
861 .functions
= tegra124_functions
,
862 .num_lanes
= ARRAY_SIZE(tegra124_lanes
),
863 .lanes
= tegra124_lanes
,
866 static const struct of_device_id tegra_xusb_padctl_of_match
[] = {
867 { .compatible
= "nvidia,tegra124-xusb-padctl", .data
= &tegra124_soc
},
870 MODULE_DEVICE_TABLE(of
, tegra_xusb_padctl_of_match
);
872 static int tegra_xusb_padctl_probe(struct platform_device
*pdev
)
874 struct tegra_xusb_padctl
*padctl
;
875 const struct of_device_id
*match
;
876 struct resource
*res
;
880 padctl
= devm_kzalloc(&pdev
->dev
, sizeof(*padctl
), GFP_KERNEL
);
884 platform_set_drvdata(pdev
, padctl
);
885 mutex_init(&padctl
->lock
);
886 padctl
->dev
= &pdev
->dev
;
888 match
= of_match_node(tegra_xusb_padctl_of_match
, pdev
->dev
.of_node
);
889 padctl
->soc
= match
->data
;
891 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
892 padctl
->regs
= devm_ioremap_resource(&pdev
->dev
, res
);
893 if (IS_ERR(padctl
->regs
))
894 return PTR_ERR(padctl
->regs
);
896 padctl
->rst
= devm_reset_control_get(&pdev
->dev
, NULL
);
897 if (IS_ERR(padctl
->rst
))
898 return PTR_ERR(padctl
->rst
);
900 err
= reset_control_deassert(padctl
->rst
);
904 memset(&padctl
->desc
, 0, sizeof(padctl
->desc
));
905 padctl
->desc
.name
= dev_name(padctl
->dev
);
906 padctl
->desc
.pctlops
= &tegra_xusb_padctl_pinctrl_ops
;
907 padctl
->desc
.pmxops
= &tegra_xusb_padctl_pinmux_ops
;
908 padctl
->desc
.confops
= &tegra_xusb_padctl_pinconf_ops
;
909 padctl
->desc
.owner
= THIS_MODULE
;
911 padctl
->pinctrl
= pinctrl_register(&padctl
->desc
, &pdev
->dev
, padctl
);
912 if (!padctl
->pinctrl
) {
913 dev_err(&pdev
->dev
, "failed to register pincontrol\n");
918 phy
= devm_phy_create(&pdev
->dev
, NULL
, &pcie_phy_ops
);
924 padctl
->phys
[TEGRA_XUSB_PADCTL_PCIE
] = phy
;
925 phy_set_drvdata(phy
, padctl
);
927 phy
= devm_phy_create(&pdev
->dev
, NULL
, &sata_phy_ops
);
933 padctl
->phys
[TEGRA_XUSB_PADCTL_SATA
] = phy
;
934 phy_set_drvdata(phy
, padctl
);
936 padctl
->provider
= devm_of_phy_provider_register(&pdev
->dev
,
937 tegra_xusb_padctl_xlate
);
938 if (IS_ERR(padctl
->provider
)) {
939 err
= PTR_ERR(padctl
->provider
);
940 dev_err(&pdev
->dev
, "failed to register PHYs: %d\n", err
);
947 pinctrl_unregister(padctl
->pinctrl
);
949 reset_control_assert(padctl
->rst
);
953 static int tegra_xusb_padctl_remove(struct platform_device
*pdev
)
955 struct tegra_xusb_padctl
*padctl
= platform_get_drvdata(pdev
);
958 pinctrl_unregister(padctl
->pinctrl
);
960 err
= reset_control_assert(padctl
->rst
);
962 dev_err(&pdev
->dev
, "failed to assert reset: %d\n", err
);
967 static struct platform_driver tegra_xusb_padctl_driver
= {
969 .name
= "tegra-xusb-padctl",
970 .of_match_table
= tegra_xusb_padctl_of_match
,
972 .probe
= tegra_xusb_padctl_probe
,
973 .remove
= tegra_xusb_padctl_remove
,
975 module_platform_driver(tegra_xusb_padctl_driver
);
977 MODULE_AUTHOR("Thierry Reding <treding@nvidia.com>");
978 MODULE_DESCRIPTION("Tegra 124 XUSB Pad Control driver");
979 MODULE_LICENSE("GPL v2");