blob: 9e7c347caf895757db081a589ff01d4f308a45e0 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
maxims@google.com54651aa2017-04-17 12:00:27 -07002/*
3 * Copyright 2017 Google, Inc
maxims@google.com54651aa2017-04-17 12:00:27 -07004 */
5
maxims@google.com54651aa2017-04-17 12:00:27 -07006#include <dm.h>
7#include <errno.h>
Simon Glass0f2af882020-05-10 11:40:05 -06008#include <log.h>
maxims@google.com54651aa2017-04-17 12:00:27 -07009#include <asm/io.h>
10#include <asm/arch/pinctrl.h>
11#include <asm/arch/scu_ast2500.h>
12#include <dm/pinctrl.h>
13
maxims@google.com54651aa2017-04-17 12:00:27 -070014/*
15 * This driver works with very simple configuration that has the same name
16 * for group and function. This way it is compatible with the Linux Kernel
17 * driver.
18 */
19
20struct ast2500_pinctrl_priv {
21 struct ast2500_scu *scu;
22};
23
24static int ast2500_pinctrl_probe(struct udevice *dev)
25{
26 struct ast2500_pinctrl_priv *priv = dev_get_priv(dev);
27
28 priv->scu = ast_get_scu();
29
30 return 0;
31}
32
33struct ast2500_group_config {
34 char *group_name;
35 /* Control register number (1-10) */
36 unsigned reg_num;
37 /* The mask of control bits in the register */
38 u32 ctrl_bit_mask;
39};
40
41static const struct ast2500_group_config ast2500_groups[] = {
42 { "I2C1", 8, (1 << 13) | (1 << 12) },
43 { "I2C2", 8, (1 << 15) | (1 << 14) },
44 { "I2C3", 8, (1 << 16) },
45 { "I2C4", 5, (1 << 17) },
46 { "I2C4", 5, (1 << 17) },
47 { "I2C5", 5, (1 << 18) },
48 { "I2C6", 5, (1 << 19) },
49 { "I2C7", 5, (1 << 20) },
50 { "I2C8", 5, (1 << 21) },
51 { "I2C9", 5, (1 << 22) },
52 { "I2C10", 5, (1 << 23) },
53 { "I2C11", 5, (1 << 24) },
54 { "I2C12", 5, (1 << 25) },
55 { "I2C13", 5, (1 << 26) },
56 { "I2C14", 5, (1 << 27) },
57 { "MAC1LINK", 1, (1 << 0) },
58 { "MDIO1", 3, (1 << 31) | (1 << 30) },
59 { "MAC2LINK", 1, (1 << 1) },
60 { "MDIO2", 5, (1 << 2) },
Eddie Jamesb7d76ac2019-08-15 14:29:37 -050061 { "SD1", 5, (1 << 0) },
62 { "SD2", 5, (1 << 1) },
Chin-Ting Kuoac8b2c32022-08-19 17:01:03 +080063 { "FWSPICS1", 3, (1 << 24) },
64 { "SPI1CS1", 1, (1 << 15) },
maxims@google.com54651aa2017-04-17 12:00:27 -070065};
66
67static int ast2500_pinctrl_get_groups_count(struct udevice *dev)
68{
69 debug("PINCTRL: get_(functions/groups)_count\n");
70
71 return ARRAY_SIZE(ast2500_groups);
72}
73
74static const char *ast2500_pinctrl_get_group_name(struct udevice *dev,
75 unsigned selector)
76{
77 debug("PINCTRL: get_(function/group)_name %u\n", selector);
78
79 return ast2500_groups[selector].group_name;
80}
81
82static int ast2500_pinctrl_group_set(struct udevice *dev, unsigned selector,
83 unsigned func_selector)
84{
85 struct ast2500_pinctrl_priv *priv = dev_get_priv(dev);
86 const struct ast2500_group_config *config;
87 u32 *ctrl_reg;
88
89 debug("PINCTRL: group_set <%u, %u>\n", selector, func_selector);
90 if (selector >= ARRAY_SIZE(ast2500_groups))
91 return -EINVAL;
92
93 config = &ast2500_groups[selector];
94 if (config->reg_num > 6)
95 ctrl_reg = &priv->scu->pinmux_ctrl1[config->reg_num - 7];
96 else
97 ctrl_reg = &priv->scu->pinmux_ctrl[config->reg_num - 1];
98
99 ast_scu_unlock(priv->scu);
100 setbits_le32(ctrl_reg, config->ctrl_bit_mask);
101 ast_scu_lock(priv->scu);
102
103 return 0;
104}
105
106static struct pinctrl_ops ast2500_pinctrl_ops = {
107 .set_state = pinctrl_generic_set_state,
108 .get_groups_count = ast2500_pinctrl_get_groups_count,
109 .get_group_name = ast2500_pinctrl_get_group_name,
110 .get_functions_count = ast2500_pinctrl_get_groups_count,
111 .get_function_name = ast2500_pinctrl_get_group_name,
112 .pinmux_group_set = ast2500_pinctrl_group_set,
113};
114
115static const struct udevice_id ast2500_pinctrl_ids[] = {
116 { .compatible = "aspeed,ast2500-pinctrl" },
117 { .compatible = "aspeed,g5-pinctrl" },
118 { }
119};
120
121U_BOOT_DRIVER(pinctrl_ast2500) = {
122 .name = "aspeed_ast2500_pinctrl",
123 .id = UCLASS_PINCTRL,
124 .of_match = ast2500_pinctrl_ids,
Simon Glass8a2b47f2020-12-03 16:55:17 -0700125 .priv_auto = sizeof(struct ast2500_pinctrl_priv),
maxims@google.com54651aa2017-04-17 12:00:27 -0700126 .ops = &ast2500_pinctrl_ops,
127 .probe = ast2500_pinctrl_probe,
128};