Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
maxims@google.com | 54651aa | 2017-04-17 12:00:27 -0700 | [diff] [blame] | 2 | /* |
| 3 | * Copyright 2017 Google, Inc |
maxims@google.com | 54651aa | 2017-04-17 12:00:27 -0700 | [diff] [blame] | 4 | */ |
| 5 | |
maxims@google.com | 54651aa | 2017-04-17 12:00:27 -0700 | [diff] [blame] | 6 | #include <dm.h> |
| 7 | #include <errno.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 8 | #include <log.h> |
maxims@google.com | 54651aa | 2017-04-17 12:00:27 -0700 | [diff] [blame] | 9 | #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.com | 54651aa | 2017-04-17 12:00:27 -0700 | [diff] [blame] | 14 | /* |
| 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 | |
| 20 | struct ast2500_pinctrl_priv { |
| 21 | struct ast2500_scu *scu; |
| 22 | }; |
| 23 | |
| 24 | static 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 | |
| 33 | struct 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 | |
| 41 | static 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 James | b7d76ac | 2019-08-15 14:29:37 -0500 | [diff] [blame] | 61 | { "SD1", 5, (1 << 0) }, |
| 62 | { "SD2", 5, (1 << 1) }, |
Chin-Ting Kuo | ac8b2c3 | 2022-08-19 17:01:03 +0800 | [diff] [blame] | 63 | { "FWSPICS1", 3, (1 << 24) }, |
| 64 | { "SPI1CS1", 1, (1 << 15) }, |
maxims@google.com | 54651aa | 2017-04-17 12:00:27 -0700 | [diff] [blame] | 65 | }; |
| 66 | |
| 67 | static 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 | |
| 74 | static 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 | |
| 82 | static 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 | |
| 106 | static 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 | |
| 115 | static const struct udevice_id ast2500_pinctrl_ids[] = { |
| 116 | { .compatible = "aspeed,ast2500-pinctrl" }, |
| 117 | { .compatible = "aspeed,g5-pinctrl" }, |
| 118 | { } |
| 119 | }; |
| 120 | |
| 121 | U_BOOT_DRIVER(pinctrl_ast2500) = { |
| 122 | .name = "aspeed_ast2500_pinctrl", |
| 123 | .id = UCLASS_PINCTRL, |
| 124 | .of_match = ast2500_pinctrl_ids, |
Simon Glass | 8a2b47f | 2020-12-03 16:55:17 -0700 | [diff] [blame] | 125 | .priv_auto = sizeof(struct ast2500_pinctrl_priv), |
maxims@google.com | 54651aa | 2017-04-17 12:00:27 -0700 | [diff] [blame] | 126 | .ops = &ast2500_pinctrl_ops, |
| 127 | .probe = ast2500_pinctrl_probe, |
| 128 | }; |