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_soc
{
63 const struct pinctrl_pin_desc
*pins
;
64 unsigned int num_pins
;
66 const struct tegra_xusb_padctl_function
*functions
;
67 unsigned int num_functions
;
69 const struct tegra_xusb_padctl_lane
*lanes
;
70 unsigned int num_lanes
;
73 struct tegra_xusb_padctl_lane
{
81 const unsigned int *funcs
;
82 unsigned int num_funcs
;
85 struct tegra_xusb_padctl
{
89 struct reset_control
*rst
;
91 const struct tegra_xusb_padctl_soc
*soc
;
92 struct pinctrl_dev
*pinctrl
;
93 struct pinctrl_desc desc
;
95 struct phy_provider
*provider
;
101 static inline void padctl_writel(struct tegra_xusb_padctl
*padctl
, u32 value
,
102 unsigned long offset
)
104 writel(value
, padctl
->regs
+ offset
);
107 static inline u32
padctl_readl(struct tegra_xusb_padctl
*padctl
,
108 unsigned long offset
)
110 return readl(padctl
->regs
+ offset
);
113 static int tegra_xusb_padctl_get_groups_count(struct pinctrl_dev
*pinctrl
)
115 struct tegra_xusb_padctl
*padctl
= pinctrl_dev_get_drvdata(pinctrl
);
117 return padctl
->soc
->num_pins
;
120 static const char *tegra_xusb_padctl_get_group_name(struct pinctrl_dev
*pinctrl
,
123 struct tegra_xusb_padctl
*padctl
= pinctrl_dev_get_drvdata(pinctrl
);
125 return padctl
->soc
->pins
[group
].name
;
128 static int tegra_xusb_padctl_get_group_pins(struct pinctrl_dev
*pinctrl
,
130 const unsigned **pins
,
134 * For the tegra-xusb pad controller groups are synonomous
135 * with lanes/pins and there is always one lane/pin per group.
137 *pins
= &pinctrl
->desc
->pins
[group
].number
;
143 enum tegra_xusb_padctl_param
{
144 TEGRA_XUSB_PADCTL_IDDQ
,
147 static const struct tegra_xusb_padctl_property
{
149 enum tegra_xusb_padctl_param param
;
151 { "nvidia,iddq", TEGRA_XUSB_PADCTL_IDDQ
},
154 #define TEGRA_XUSB_PADCTL_PACK(param, value) ((param) << 16 | (value))
155 #define TEGRA_XUSB_PADCTL_UNPACK_PARAM(config) ((config) >> 16)
156 #define TEGRA_XUSB_PADCTL_UNPACK_VALUE(config) ((config) & 0xffff)
158 static int tegra_xusb_padctl_parse_subnode(struct tegra_xusb_padctl
*padctl
,
159 struct device_node
*np
,
160 struct pinctrl_map
**maps
,
161 unsigned int *reserved_maps
,
162 unsigned int *num_maps
)
164 unsigned int i
, reserve
= 0, num_configs
= 0;
165 unsigned long config
, *configs
= NULL
;
166 const char *function
, *group
;
167 struct property
*prop
;
171 err
= of_property_read_string(np
, "nvidia,function", &function
);
179 for (i
= 0; i
< ARRAY_SIZE(properties
); i
++) {
180 err
= of_property_read_u32(np
, properties
[i
].name
, &value
);
188 config
= TEGRA_XUSB_PADCTL_PACK(properties
[i
].param
, value
);
190 err
= pinctrl_utils_add_config(padctl
->pinctrl
, &configs
,
191 &num_configs
, config
);
202 err
= of_property_count_strings(np
, "nvidia,lanes");
208 err
= pinctrl_utils_reserve_map(padctl
->pinctrl
, maps
, reserved_maps
,
213 of_property_for_each_string(np
, "nvidia,lanes", prop
, group
) {
215 err
= pinctrl_utils_add_map_mux(padctl
->pinctrl
, maps
,
216 reserved_maps
, num_maps
, group
,
223 err
= pinctrl_utils_add_map_configs(padctl
->pinctrl
,
224 maps
, reserved_maps
, num_maps
, group
,
225 configs
, num_configs
,
226 PIN_MAP_TYPE_CONFIGS_GROUP
);
239 static int tegra_xusb_padctl_dt_node_to_map(struct pinctrl_dev
*pinctrl
,
240 struct device_node
*parent
,
241 struct pinctrl_map
**maps
,
242 unsigned int *num_maps
)
244 struct tegra_xusb_padctl
*padctl
= pinctrl_dev_get_drvdata(pinctrl
);
245 unsigned int reserved_maps
= 0;
246 struct device_node
*np
;
252 for_each_child_of_node(parent
, np
) {
253 err
= tegra_xusb_padctl_parse_subnode(padctl
, np
, maps
,
265 static const struct pinctrl_ops tegra_xusb_padctl_pinctrl_ops
= {
266 .get_groups_count
= tegra_xusb_padctl_get_groups_count
,
267 .get_group_name
= tegra_xusb_padctl_get_group_name
,
268 .get_group_pins
= tegra_xusb_padctl_get_group_pins
,
269 .dt_node_to_map
= tegra_xusb_padctl_dt_node_to_map
,
270 .dt_free_map
= pinctrl_utils_dt_free_map
,
273 static int tegra_xusb_padctl_get_functions_count(struct pinctrl_dev
*pinctrl
)
275 struct tegra_xusb_padctl
*padctl
= pinctrl_dev_get_drvdata(pinctrl
);
277 return padctl
->soc
->num_functions
;
281 tegra_xusb_padctl_get_function_name(struct pinctrl_dev
*pinctrl
,
282 unsigned int function
)
284 struct tegra_xusb_padctl
*padctl
= pinctrl_dev_get_drvdata(pinctrl
);
286 return padctl
->soc
->functions
[function
].name
;
289 static int tegra_xusb_padctl_get_function_groups(struct pinctrl_dev
*pinctrl
,
290 unsigned int function
,
291 const char * const **groups
,
292 unsigned * const num_groups
)
294 struct tegra_xusb_padctl
*padctl
= pinctrl_dev_get_drvdata(pinctrl
);
296 *num_groups
= padctl
->soc
->functions
[function
].num_groups
;
297 *groups
= padctl
->soc
->functions
[function
].groups
;
302 static int tegra_xusb_padctl_pinmux_set(struct pinctrl_dev
*pinctrl
,
303 unsigned int function
,
306 struct tegra_xusb_padctl
*padctl
= pinctrl_dev_get_drvdata(pinctrl
);
307 const struct tegra_xusb_padctl_lane
*lane
;
311 lane
= &padctl
->soc
->lanes
[group
];
313 for (i
= 0; i
< lane
->num_funcs
; i
++)
314 if (lane
->funcs
[i
] == function
)
317 if (i
>= lane
->num_funcs
)
320 value
= padctl_readl(padctl
, lane
->offset
);
321 value
&= ~(lane
->mask
<< lane
->shift
);
322 value
|= i
<< lane
->shift
;
323 padctl_writel(padctl
, value
, lane
->offset
);
328 static const struct pinmux_ops tegra_xusb_padctl_pinmux_ops
= {
329 .get_functions_count
= tegra_xusb_padctl_get_functions_count
,
330 .get_function_name
= tegra_xusb_padctl_get_function_name
,
331 .get_function_groups
= tegra_xusb_padctl_get_function_groups
,
332 .set_mux
= tegra_xusb_padctl_pinmux_set
,
335 static int tegra_xusb_padctl_pinconf_group_get(struct pinctrl_dev
*pinctrl
,
337 unsigned long *config
)
339 struct tegra_xusb_padctl
*padctl
= pinctrl_dev_get_drvdata(pinctrl
);
340 const struct tegra_xusb_padctl_lane
*lane
;
341 enum tegra_xusb_padctl_param param
;
344 param
= TEGRA_XUSB_PADCTL_UNPACK_PARAM(*config
);
345 lane
= &padctl
->soc
->lanes
[group
];
348 case TEGRA_XUSB_PADCTL_IDDQ
:
349 /* lanes with iddq == 0 don't support this parameter */
353 value
= padctl_readl(padctl
, lane
->offset
);
355 if (value
& BIT(lane
->iddq
))
360 *config
= TEGRA_XUSB_PADCTL_PACK(param
, value
);
364 dev_err(padctl
->dev
, "invalid configuration parameter: %04x\n",
372 static int tegra_xusb_padctl_pinconf_group_set(struct pinctrl_dev
*pinctrl
,
374 unsigned long *configs
,
375 unsigned int num_configs
)
377 struct tegra_xusb_padctl
*padctl
= pinctrl_dev_get_drvdata(pinctrl
);
378 const struct tegra_xusb_padctl_lane
*lane
;
379 enum tegra_xusb_padctl_param param
;
384 lane
= &padctl
->soc
->lanes
[group
];
386 for (i
= 0; i
< num_configs
; i
++) {
387 param
= TEGRA_XUSB_PADCTL_UNPACK_PARAM(configs
[i
]);
388 value
= TEGRA_XUSB_PADCTL_UNPACK_VALUE(configs
[i
]);
391 case TEGRA_XUSB_PADCTL_IDDQ
:
392 /* lanes with iddq == 0 don't support this parameter */
396 regval
= padctl_readl(padctl
, lane
->offset
);
399 regval
&= ~BIT(lane
->iddq
);
401 regval
|= BIT(lane
->iddq
);
403 padctl_writel(padctl
, regval
, lane
->offset
);
408 "invalid configuration parameter: %04x\n",
417 #ifdef CONFIG_DEBUG_FS
418 static const char *strip_prefix(const char *s
)
420 const char *comma
= strchr(s
, ',');
428 tegra_xusb_padctl_pinconf_group_dbg_show(struct pinctrl_dev
*pinctrl
,
434 for (i
= 0; i
< ARRAY_SIZE(properties
); i
++) {
435 unsigned long config
, value
;
438 config
= TEGRA_XUSB_PADCTL_PACK(properties
[i
].param
, 0);
440 err
= tegra_xusb_padctl_pinconf_group_get(pinctrl
, group
,
445 value
= TEGRA_XUSB_PADCTL_UNPACK_VALUE(config
);
447 seq_printf(s
, "\n\t%s=%lu\n", strip_prefix(properties
[i
].name
),
453 tegra_xusb_padctl_pinconf_config_dbg_show(struct pinctrl_dev
*pinctrl
,
455 unsigned long config
)
457 enum tegra_xusb_padctl_param param
;
458 const char *name
= "unknown";
462 param
= TEGRA_XUSB_PADCTL_UNPACK_PARAM(config
);
463 value
= TEGRA_XUSB_PADCTL_UNPACK_VALUE(config
);
465 for (i
= 0; i
< ARRAY_SIZE(properties
); i
++) {
466 if (properties
[i
].param
== param
) {
467 name
= properties
[i
].name
;
472 seq_printf(s
, "%s=%lu", strip_prefix(name
), value
);
476 static const struct pinconf_ops tegra_xusb_padctl_pinconf_ops
= {
477 .pin_config_group_get
= tegra_xusb_padctl_pinconf_group_get
,
478 .pin_config_group_set
= tegra_xusb_padctl_pinconf_group_set
,
479 #ifdef CONFIG_DEBUG_FS
480 .pin_config_group_dbg_show
= tegra_xusb_padctl_pinconf_group_dbg_show
,
481 .pin_config_config_dbg_show
= tegra_xusb_padctl_pinconf_config_dbg_show
,
485 static int tegra_xusb_padctl_enable(struct tegra_xusb_padctl
*padctl
)
489 mutex_lock(&padctl
->lock
);
491 if (padctl
->enable
++ > 0)
494 value
= padctl_readl(padctl
, XUSB_PADCTL_ELPG_PROGRAM
);
495 value
&= ~XUSB_PADCTL_ELPG_PROGRAM_AUX_MUX_LP0_CLAMP_EN
;
496 padctl_writel(padctl
, value
, XUSB_PADCTL_ELPG_PROGRAM
);
498 usleep_range(100, 200);
500 value
= padctl_readl(padctl
, XUSB_PADCTL_ELPG_PROGRAM
);
501 value
&= ~XUSB_PADCTL_ELPG_PROGRAM_AUX_MUX_LP0_CLAMP_EN_EARLY
;
502 padctl_writel(padctl
, value
, XUSB_PADCTL_ELPG_PROGRAM
);
504 usleep_range(100, 200);
506 value
= padctl_readl(padctl
, XUSB_PADCTL_ELPG_PROGRAM
);
507 value
&= ~XUSB_PADCTL_ELPG_PROGRAM_AUX_MUX_LP0_VCORE_DOWN
;
508 padctl_writel(padctl
, value
, XUSB_PADCTL_ELPG_PROGRAM
);
511 mutex_unlock(&padctl
->lock
);
515 static int tegra_xusb_padctl_disable(struct tegra_xusb_padctl
*padctl
)
519 mutex_lock(&padctl
->lock
);
521 if (WARN_ON(padctl
->enable
== 0))
524 if (--padctl
->enable
> 0)
527 value
= padctl_readl(padctl
, XUSB_PADCTL_ELPG_PROGRAM
);
528 value
|= XUSB_PADCTL_ELPG_PROGRAM_AUX_MUX_LP0_VCORE_DOWN
;
529 padctl_writel(padctl
, value
, XUSB_PADCTL_ELPG_PROGRAM
);
531 usleep_range(100, 200);
533 value
= padctl_readl(padctl
, XUSB_PADCTL_ELPG_PROGRAM
);
534 value
|= XUSB_PADCTL_ELPG_PROGRAM_AUX_MUX_LP0_CLAMP_EN_EARLY
;
535 padctl_writel(padctl
, value
, XUSB_PADCTL_ELPG_PROGRAM
);
537 usleep_range(100, 200);
539 value
= padctl_readl(padctl
, XUSB_PADCTL_ELPG_PROGRAM
);
540 value
|= XUSB_PADCTL_ELPG_PROGRAM_AUX_MUX_LP0_CLAMP_EN
;
541 padctl_writel(padctl
, value
, XUSB_PADCTL_ELPG_PROGRAM
);
544 mutex_unlock(&padctl
->lock
);
548 static int tegra_xusb_phy_init(struct phy
*phy
)
550 struct tegra_xusb_padctl
*padctl
= phy_get_drvdata(phy
);
552 return tegra_xusb_padctl_enable(padctl
);
555 static int tegra_xusb_phy_exit(struct phy
*phy
)
557 struct tegra_xusb_padctl
*padctl
= phy_get_drvdata(phy
);
559 return tegra_xusb_padctl_disable(padctl
);
562 static int pcie_phy_power_on(struct phy
*phy
)
564 struct tegra_xusb_padctl
*padctl
= phy_get_drvdata(phy
);
565 unsigned long timeout
;
566 int err
= -ETIMEDOUT
;
569 value
= padctl_readl(padctl
, XUSB_PADCTL_IOPHY_PLL_P0_CTL1
);
570 value
&= ~XUSB_PADCTL_IOPHY_PLL_P0_CTL1_REFCLK_SEL_MASK
;
571 padctl_writel(padctl
, value
, XUSB_PADCTL_IOPHY_PLL_P0_CTL1
);
573 value
= padctl_readl(padctl
, XUSB_PADCTL_IOPHY_PLL_P0_CTL2
);
574 value
|= XUSB_PADCTL_IOPHY_PLL_P0_CTL2_REFCLKBUF_EN
|
575 XUSB_PADCTL_IOPHY_PLL_P0_CTL2_TXCLKREF_EN
|
576 XUSB_PADCTL_IOPHY_PLL_P0_CTL2_TXCLKREF_SEL
;
577 padctl_writel(padctl
, value
, XUSB_PADCTL_IOPHY_PLL_P0_CTL2
);
579 value
= padctl_readl(padctl
, XUSB_PADCTL_IOPHY_PLL_P0_CTL1
);
580 value
|= XUSB_PADCTL_IOPHY_PLL_P0_CTL1_PLL_RST
;
581 padctl_writel(padctl
, value
, XUSB_PADCTL_IOPHY_PLL_P0_CTL1
);
583 timeout
= jiffies
+ msecs_to_jiffies(50);
585 while (time_before(jiffies
, timeout
)) {
586 value
= padctl_readl(padctl
, XUSB_PADCTL_IOPHY_PLL_P0_CTL1
);
587 if (value
& XUSB_PADCTL_IOPHY_PLL_P0_CTL1_PLL0_LOCKDET
) {
592 usleep_range(100, 200);
598 static int pcie_phy_power_off(struct phy
*phy
)
600 struct tegra_xusb_padctl
*padctl
= phy_get_drvdata(phy
);
603 value
= padctl_readl(padctl
, XUSB_PADCTL_IOPHY_PLL_P0_CTL1
);
604 value
&= ~XUSB_PADCTL_IOPHY_PLL_P0_CTL1_PLL_RST
;
605 padctl_writel(padctl
, value
, XUSB_PADCTL_IOPHY_PLL_P0_CTL1
);
610 static const struct phy_ops pcie_phy_ops
= {
611 .init
= tegra_xusb_phy_init
,
612 .exit
= tegra_xusb_phy_exit
,
613 .power_on
= pcie_phy_power_on
,
614 .power_off
= pcie_phy_power_off
,
615 .owner
= THIS_MODULE
,
618 static int sata_phy_power_on(struct phy
*phy
)
620 struct tegra_xusb_padctl
*padctl
= phy_get_drvdata(phy
);
621 unsigned long timeout
;
622 int err
= -ETIMEDOUT
;
625 value
= padctl_readl(padctl
, XUSB_PADCTL_IOPHY_MISC_PAD_S0_CTL1
);
626 value
&= ~XUSB_PADCTL_IOPHY_MISC_PAD_S0_CTL1_IDDQ_OVRD
;
627 value
&= ~XUSB_PADCTL_IOPHY_MISC_PAD_S0_CTL1_IDDQ
;
628 padctl_writel(padctl
, value
, XUSB_PADCTL_IOPHY_MISC_PAD_S0_CTL1
);
630 value
= padctl_readl(padctl
, XUSB_PADCTL_IOPHY_PLL_S0_CTL1
);
631 value
&= ~XUSB_PADCTL_IOPHY_PLL_S0_CTL1_PLL_PWR_OVRD
;
632 value
&= ~XUSB_PADCTL_IOPHY_PLL_S0_CTL1_PLL_IDDQ
;
633 padctl_writel(padctl
, value
, XUSB_PADCTL_IOPHY_PLL_S0_CTL1
);
635 value
= padctl_readl(padctl
, XUSB_PADCTL_IOPHY_PLL_S0_CTL1
);
636 value
|= XUSB_PADCTL_IOPHY_PLL_S0_CTL1_PLL1_MODE
;
637 padctl_writel(padctl
, value
, XUSB_PADCTL_IOPHY_PLL_S0_CTL1
);
639 value
= padctl_readl(padctl
, XUSB_PADCTL_IOPHY_PLL_S0_CTL1
);
640 value
|= XUSB_PADCTL_IOPHY_PLL_S0_CTL1_PLL_RST
;
641 padctl_writel(padctl
, value
, XUSB_PADCTL_IOPHY_PLL_S0_CTL1
);
643 timeout
= jiffies
+ msecs_to_jiffies(50);
645 while (time_before(jiffies
, timeout
)) {
646 value
= padctl_readl(padctl
, XUSB_PADCTL_IOPHY_PLL_S0_CTL1
);
647 if (value
& XUSB_PADCTL_IOPHY_PLL_S0_CTL1_PLL1_LOCKDET
) {
652 usleep_range(100, 200);
658 static int sata_phy_power_off(struct phy
*phy
)
660 struct tegra_xusb_padctl
*padctl
= phy_get_drvdata(phy
);
663 value
= padctl_readl(padctl
, XUSB_PADCTL_IOPHY_PLL_S0_CTL1
);
664 value
&= ~XUSB_PADCTL_IOPHY_PLL_S0_CTL1_PLL_RST
;
665 padctl_writel(padctl
, value
, XUSB_PADCTL_IOPHY_PLL_S0_CTL1
);
667 value
= padctl_readl(padctl
, XUSB_PADCTL_IOPHY_PLL_S0_CTL1
);
668 value
&= ~XUSB_PADCTL_IOPHY_PLL_S0_CTL1_PLL1_MODE
;
669 padctl_writel(padctl
, value
, XUSB_PADCTL_IOPHY_PLL_S0_CTL1
);
671 value
= padctl_readl(padctl
, XUSB_PADCTL_IOPHY_PLL_S0_CTL1
);
672 value
|= XUSB_PADCTL_IOPHY_PLL_S0_CTL1_PLL_PWR_OVRD
;
673 value
|= XUSB_PADCTL_IOPHY_PLL_S0_CTL1_PLL_IDDQ
;
674 padctl_writel(padctl
, value
, XUSB_PADCTL_IOPHY_PLL_S0_CTL1
);
676 value
= padctl_readl(padctl
, XUSB_PADCTL_IOPHY_MISC_PAD_S0_CTL1
);
677 value
|= ~XUSB_PADCTL_IOPHY_MISC_PAD_S0_CTL1_IDDQ_OVRD
;
678 value
|= ~XUSB_PADCTL_IOPHY_MISC_PAD_S0_CTL1_IDDQ
;
679 padctl_writel(padctl
, value
, XUSB_PADCTL_IOPHY_MISC_PAD_S0_CTL1
);
684 static const struct phy_ops sata_phy_ops
= {
685 .init
= tegra_xusb_phy_init
,
686 .exit
= tegra_xusb_phy_exit
,
687 .power_on
= sata_phy_power_on
,
688 .power_off
= sata_phy_power_off
,
689 .owner
= THIS_MODULE
,
692 static struct phy
*tegra_xusb_padctl_xlate(struct device
*dev
,
693 struct of_phandle_args
*args
)
695 struct tegra_xusb_padctl
*padctl
= dev_get_drvdata(dev
);
696 unsigned int index
= args
->args
[0];
698 if (args
->args_count
<= 0)
699 return ERR_PTR(-EINVAL
);
701 if (index
>= ARRAY_SIZE(padctl
->phys
))
702 return ERR_PTR(-EINVAL
);
704 return padctl
->phys
[index
];
717 #define PIN_PCIE_4 10
718 #define PIN_SATA_0 11
720 static const struct pinctrl_pin_desc tegra124_pins
[] = {
721 PINCTRL_PIN(PIN_OTG_0
, "otg-0"),
722 PINCTRL_PIN(PIN_OTG_1
, "otg-1"),
723 PINCTRL_PIN(PIN_OTG_2
, "otg-2"),
724 PINCTRL_PIN(PIN_ULPI_0
, "ulpi-0"),
725 PINCTRL_PIN(PIN_HSIC_0
, "hsic-0"),
726 PINCTRL_PIN(PIN_HSIC_1
, "hsic-1"),
727 PINCTRL_PIN(PIN_PCIE_0
, "pcie-0"),
728 PINCTRL_PIN(PIN_PCIE_1
, "pcie-1"),
729 PINCTRL_PIN(PIN_PCIE_2
, "pcie-2"),
730 PINCTRL_PIN(PIN_PCIE_3
, "pcie-3"),
731 PINCTRL_PIN(PIN_PCIE_4
, "pcie-4"),
732 PINCTRL_PIN(PIN_SATA_0
, "sata-0"),
735 static const char * const tegra124_snps_groups
[] = {
744 static const char * const tegra124_xusb_groups
[] = {
753 static const char * const tegra124_uart_groups
[] = {
759 static const char * const tegra124_pcie_groups
[] = {
767 static const char * const tegra124_usb3_groups
[] = {
773 static const char * const tegra124_sata_groups
[] = {
777 static const char * const tegra124_rsvd_groups
[] = {
789 #define TEGRA124_FUNCTION(_name) \
792 .num_groups = ARRAY_SIZE(tegra124_##_name##_groups), \
793 .groups = tegra124_##_name##_groups, \
796 static struct tegra_xusb_padctl_function tegra124_functions
[] = {
797 TEGRA124_FUNCTION(snps
),
798 TEGRA124_FUNCTION(xusb
),
799 TEGRA124_FUNCTION(uart
),
800 TEGRA124_FUNCTION(pcie
),
801 TEGRA124_FUNCTION(usb3
),
802 TEGRA124_FUNCTION(sata
),
803 TEGRA124_FUNCTION(rsvd
),
806 enum tegra124_function
{
816 static const unsigned int tegra124_otg_functions
[] = {
823 static const unsigned int tegra124_usb_functions
[] = {
828 static const unsigned int tegra124_pci_functions
[] = {
835 #define TEGRA124_LANE(_name, _offset, _shift, _mask, _iddq, _funcs) \
842 .num_funcs = ARRAY_SIZE(tegra124_##_funcs##_functions), \
843 .funcs = tegra124_##_funcs##_functions, \
846 static const struct tegra_xusb_padctl_lane tegra124_lanes
[] = {
847 TEGRA124_LANE("otg-0", 0x004, 0, 0x3, 0, otg
),
848 TEGRA124_LANE("otg-1", 0x004, 2, 0x3, 0, otg
),
849 TEGRA124_LANE("otg-2", 0x004, 4, 0x3, 0, otg
),
850 TEGRA124_LANE("ulpi-0", 0x004, 12, 0x1, 0, usb
),
851 TEGRA124_LANE("hsic-0", 0x004, 14, 0x1, 0, usb
),
852 TEGRA124_LANE("hsic-1", 0x004, 15, 0x1, 0, usb
),
853 TEGRA124_LANE("pcie-0", 0x134, 16, 0x3, 1, pci
),
854 TEGRA124_LANE("pcie-1", 0x134, 18, 0x3, 2, pci
),
855 TEGRA124_LANE("pcie-2", 0x134, 20, 0x3, 3, pci
),
856 TEGRA124_LANE("pcie-3", 0x134, 22, 0x3, 4, pci
),
857 TEGRA124_LANE("pcie-4", 0x134, 24, 0x3, 5, pci
),
858 TEGRA124_LANE("sata-0", 0x134, 26, 0x3, 6, pci
),
861 static const struct tegra_xusb_padctl_soc tegra124_soc
= {
862 .num_pins
= ARRAY_SIZE(tegra124_pins
),
863 .pins
= tegra124_pins
,
864 .num_functions
= ARRAY_SIZE(tegra124_functions
),
865 .functions
= tegra124_functions
,
866 .num_lanes
= ARRAY_SIZE(tegra124_lanes
),
867 .lanes
= tegra124_lanes
,
870 static const struct of_device_id tegra_xusb_padctl_of_match
[] = {
871 { .compatible
= "nvidia,tegra124-xusb-padctl", .data
= &tegra124_soc
},
874 MODULE_DEVICE_TABLE(of
, tegra_xusb_padctl_of_match
);
876 static int tegra_xusb_padctl_probe(struct platform_device
*pdev
)
878 struct tegra_xusb_padctl
*padctl
;
879 const struct of_device_id
*match
;
880 struct resource
*res
;
884 padctl
= devm_kzalloc(&pdev
->dev
, sizeof(*padctl
), GFP_KERNEL
);
888 platform_set_drvdata(pdev
, padctl
);
889 mutex_init(&padctl
->lock
);
890 padctl
->dev
= &pdev
->dev
;
892 match
= of_match_node(tegra_xusb_padctl_of_match
, pdev
->dev
.of_node
);
893 padctl
->soc
= match
->data
;
895 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
896 padctl
->regs
= devm_ioremap_resource(&pdev
->dev
, res
);
897 if (IS_ERR(padctl
->regs
))
898 return PTR_ERR(padctl
->regs
);
900 padctl
->rst
= devm_reset_control_get(&pdev
->dev
, NULL
);
901 if (IS_ERR(padctl
->rst
))
902 return PTR_ERR(padctl
->rst
);
904 err
= reset_control_deassert(padctl
->rst
);
908 memset(&padctl
->desc
, 0, sizeof(padctl
->desc
));
909 padctl
->desc
.name
= dev_name(padctl
->dev
);
910 padctl
->desc
.pins
= tegra124_pins
;
911 padctl
->desc
.npins
= ARRAY_SIZE(tegra124_pins
);
912 padctl
->desc
.pctlops
= &tegra_xusb_padctl_pinctrl_ops
;
913 padctl
->desc
.pmxops
= &tegra_xusb_padctl_pinmux_ops
;
914 padctl
->desc
.confops
= &tegra_xusb_padctl_pinconf_ops
;
915 padctl
->desc
.owner
= THIS_MODULE
;
917 padctl
->pinctrl
= pinctrl_register(&padctl
->desc
, &pdev
->dev
, padctl
);
918 if (IS_ERR(padctl
->pinctrl
)) {
919 dev_err(&pdev
->dev
, "failed to register pincontrol\n");
920 err
= PTR_ERR(padctl
->pinctrl
);
924 phy
= devm_phy_create(&pdev
->dev
, NULL
, &pcie_phy_ops
);
930 padctl
->phys
[TEGRA_XUSB_PADCTL_PCIE
] = phy
;
931 phy_set_drvdata(phy
, padctl
);
933 phy
= devm_phy_create(&pdev
->dev
, NULL
, &sata_phy_ops
);
939 padctl
->phys
[TEGRA_XUSB_PADCTL_SATA
] = phy
;
940 phy_set_drvdata(phy
, padctl
);
942 padctl
->provider
= devm_of_phy_provider_register(&pdev
->dev
,
943 tegra_xusb_padctl_xlate
);
944 if (IS_ERR(padctl
->provider
)) {
945 err
= PTR_ERR(padctl
->provider
);
946 dev_err(&pdev
->dev
, "failed to register PHYs: %d\n", err
);
953 pinctrl_unregister(padctl
->pinctrl
);
955 reset_control_assert(padctl
->rst
);
959 static int tegra_xusb_padctl_remove(struct platform_device
*pdev
)
961 struct tegra_xusb_padctl
*padctl
= platform_get_drvdata(pdev
);
964 pinctrl_unregister(padctl
->pinctrl
);
966 err
= reset_control_assert(padctl
->rst
);
968 dev_err(&pdev
->dev
, "failed to assert reset: %d\n", err
);
973 static struct platform_driver tegra_xusb_padctl_driver
= {
975 .name
= "tegra-xusb-padctl",
976 .of_match_table
= tegra_xusb_padctl_of_match
,
978 .probe
= tegra_xusb_padctl_probe
,
979 .remove
= tegra_xusb_padctl_remove
,
981 module_platform_driver(tegra_xusb_padctl_driver
);
983 MODULE_AUTHOR("Thierry Reding <treding@nvidia.com>");
984 MODULE_DESCRIPTION("Tegra 124 XUSB Pad Control driver");
985 MODULE_LICENSE("GPL v2");