xref: /openbmc/u-boot/drivers/pinctrl/aspeed/pinctrl_ast2600.c (revision 39283ea71d1556dd24ac2a1fd61905e017e1f518)
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * Copyright (C) ASPEED Technology Inc.
4  */
5 
6 #include <common.h>
7 #include <dm.h>
8 #include <errno.h>
9 #include <asm/io.h>
10 #include <linux/bitops.h>
11 #include <asm/arch/pinctrl.h>
12 #include <asm/arch/scu_ast2600.h>
13 #include <dm/pinctrl.h>
14 #include "pinctrl-aspeed.h"
15 
16 /*
17  * This driver works with very simple configuration that has the same name
18  * for group and function. This way it is compatible with the Linux Kernel
19  * driver.
20  */
21 
22 struct ast2600_pinctrl_priv {
23 	struct ast2600_scu *scu;
24 };
25 
26 static int ast2600_pinctrl_probe(struct udevice *dev)
27 {
28 	struct ast2600_pinctrl_priv *priv = dev_get_priv(dev);
29 
30 	priv->scu = ast_get_scu();
31 
32 	return 0;
33 }
34 
35 static struct aspeed_sig_desc mac1_link[] = {
36 	{ 0x410, BIT(4), 0	},
37 };
38 
39 static struct aspeed_sig_desc mac2_link[] = {
40 	{ 0x410, BIT(5), 0	},
41 };
42 
43 static struct aspeed_sig_desc mac3_link[] = {
44 	{ 0x410, BIT(6), 0	},
45 };
46 
47 static struct aspeed_sig_desc mac4_link[] = {
48 	{ 0x410, BIT(7), 0	},
49 };
50 
51 static struct aspeed_sig_desc mdio1_link[] = {
52 	{ 0x430, BIT(17), 0	},
53 };
54 
55 static struct aspeed_sig_desc mdio2_link[] = {
56 	{ 0x410, BIT(14) | BIT(13), 0	},
57 };
58 
59 static struct aspeed_sig_desc mdio3_link[] = {
60 	{ 0x410, BIT(1) | BIT(0), 0	},
61 };
62 
63 static struct aspeed_sig_desc mdio4_link[] = {
64 	{ 0x410, BIT(3) | BIT(2), 0	},
65 };
66 
67 //8bit mode offset 0x414 (21~18) 0x450 bit0: sd0 bit1: sd1,  bit3: sd0 8bits
68 
69 
70 static struct aspeed_sig_desc sdio2_link[] = {
71 	{ 0x4B4, GENMASK(23, 16), 0	},
72 	{ 0x450, BIT(1), 0		},
73 	{ 0x414, GENMASK(23, 16), 0	},
74 };
75 
76 //sdio1 414 (23~16) = 0, 4b4 (23~16) = 1, 450 bit1 = 1
77 static struct aspeed_sig_desc sdio1_link[] = {
78 	{ 0x414, GENMASK(15, 8), 0	},
79 	{ 0x4b4, GENMASK(23, 16), 0	},
80 	{ 0x450, BIT(0), 0	},
81 };
82 
83 static struct aspeed_sig_desc emmc_link[] = {
84 	{ 0x400, GENMASK(31, 24), 0 },
85 	{ 0x404, GENMASK(3, 0), 0 },
86 };
87 
88 static const struct aspeed_group_config ast2600_groups[] = {
89 	{ "MAC1LINK", 1, mac1_link },
90 	{ "MAC2LINK", 1, mac2_link },
91 	{ "MAC3LINK", 1, mac3_link },
92 	{ "MAC4LINK", 1, mac4_link },
93 	{ "MDIO1LINK", 1, mdio1_link },
94 	{ "MDIO2LINK", 1, mdio2_link },
95 	{ "MDIO3LINK", 1, mdio3_link },
96 	{ "MDIO4LINK", 1, mdio4_link },
97 	{ "SDIO1", ARRAY_SIZE(sdio2_link), sdio2_link },
98 	{ "SDIO0", ARRAY_SIZE(sdio1_link), sdio1_link },
99 	{ "EMMC", ARRAY_SIZE(emmc_link), emmc_link },
100 };
101 
102 static int ast2600_pinctrl_get_groups_count(struct udevice *dev)
103 {
104 	printf("PINCTRL: get_(functions/groups)_count\n");
105 
106 	return ARRAY_SIZE(ast2600_groups);
107 }
108 
109 static const char *ast2600_pinctrl_get_group_name(struct udevice *dev,
110 						  unsigned selector)
111 {
112 	printf("PINCTRL: get_(function/group)_name %u\n", selector);
113 
114 	return ast2600_groups[selector].group_name;
115 }
116 
117 static int ast2600_pinctrl_group_set(struct udevice *dev, unsigned selector,
118 				     unsigned func_selector)
119 {
120 	struct ast2600_pinctrl_priv *priv = dev_get_priv(dev);
121 	const struct aspeed_group_config *config;
122 	const struct aspeed_sig_desc *descs;
123 	u32 ctrl_reg = (u32)&priv->scu;
124 
125 	printf("PINCTRL: group_set <%u, %u>\n", selector, func_selector);
126 	if (selector >= ARRAY_SIZE(ast2600_groups))
127 		return -EINVAL;
128 
129 	config = &ast2600_groups[selector];
130 	descs = config->descs;
131 
132 	setbits_le32(ctrl_reg + descs->offset, descs->reg_set);
133 
134 	return 0;
135 }
136 
137 static struct pinctrl_ops ast2600_pinctrl_ops = {
138 	.set_state = pinctrl_generic_set_state,
139 	.get_groups_count = ast2600_pinctrl_get_groups_count,
140 	.get_group_name = ast2600_pinctrl_get_group_name,
141 	.get_functions_count = ast2600_pinctrl_get_groups_count,
142 	.get_function_name = ast2600_pinctrl_get_group_name,
143 	.pinmux_group_set = ast2600_pinctrl_group_set,
144 };
145 
146 static const struct udevice_id ast2600_pinctrl_ids[] = {
147 	{ .compatible = "aspeed,g6-pinctrl" },
148 	{ }
149 };
150 
151 U_BOOT_DRIVER(pinctrl_aspeed) = {
152 	.name = "aspeed_ast2600_pinctrl",
153 	.id = UCLASS_PINCTRL,
154 	.of_match = ast2600_pinctrl_ids,
155 	.priv_auto_alloc_size = sizeof(struct ast2600_pinctrl_priv),
156 	.ops = &ast2600_pinctrl_ops,
157 	.probe = ast2600_pinctrl_probe,
158 };
159