Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Masahiro Yamada | 0b53a75 | 2015-08-27 12:44:30 +0900 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2015 Masahiro Yamada <yamada.masahiro@socionext.com> |
Masahiro Yamada | 0b53a75 | 2015-08-27 12:44:30 +0900 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | /* #define DEBUG */ |
| 7 | |
| 8 | #include <common.h> |
Simon Glass | 11c89f3 | 2017-05-17 17:18:03 -0600 | [diff] [blame] | 9 | #include <dm.h> |
Masahiro Yamada | 0b53a75 | 2015-08-27 12:44:30 +0900 | [diff] [blame] | 10 | #include <dm/pinctrl.h> |
| 11 | |
| 12 | static const char * const sandbox_pins[] = { |
| 13 | "SCL", |
| 14 | "SDA", |
| 15 | "TX", |
| 16 | "RX", |
Eugen Hristev | 200e35e | 2018-09-18 10:35:34 +0300 | [diff] [blame] | 17 | "W1" |
Masahiro Yamada | 0b53a75 | 2015-08-27 12:44:30 +0900 | [diff] [blame] | 18 | }; |
| 19 | |
Patrice Chotard | 3cd1f33 | 2018-10-24 14:10:22 +0200 | [diff] [blame] | 20 | static const char * const sandbox_pins_muxing[] = { |
| 21 | "I2C SCL", |
| 22 | "I2C SDA", |
| 23 | "Uart TX", |
| 24 | "Uart RX", |
| 25 | "1-wire gpio", |
| 26 | }; |
| 27 | |
Masahiro Yamada | 0b53a75 | 2015-08-27 12:44:30 +0900 | [diff] [blame] | 28 | static const char * const sandbox_groups[] = { |
| 29 | "i2c", |
| 30 | "serial_a", |
| 31 | "serial_b", |
| 32 | "spi", |
Eugen Hristev | 200e35e | 2018-09-18 10:35:34 +0300 | [diff] [blame] | 33 | "w1", |
Masahiro Yamada | 0b53a75 | 2015-08-27 12:44:30 +0900 | [diff] [blame] | 34 | }; |
| 35 | |
| 36 | static const char * const sandbox_functions[] = { |
| 37 | "i2c", |
| 38 | "serial", |
| 39 | "spi", |
Eugen Hristev | 200e35e | 2018-09-18 10:35:34 +0300 | [diff] [blame] | 40 | "w1", |
Masahiro Yamada | 0b53a75 | 2015-08-27 12:44:30 +0900 | [diff] [blame] | 41 | }; |
| 42 | |
| 43 | static const struct pinconf_param sandbox_conf_params[] = { |
| 44 | { "bias-disable", PIN_CONFIG_BIAS_DISABLE, 0 }, |
| 45 | { "bias-high-impedance", PIN_CONFIG_BIAS_HIGH_IMPEDANCE, 0 }, |
| 46 | { "bias-bus-hold", PIN_CONFIG_BIAS_BUS_HOLD, 0 }, |
| 47 | { "bias-pull-up", PIN_CONFIG_BIAS_PULL_UP, 1 }, |
| 48 | { "bias-pull-down", PIN_CONFIG_BIAS_PULL_DOWN, 1 }, |
| 49 | { "bias-pull-pin-default", PIN_CONFIG_BIAS_PULL_PIN_DEFAULT, 1 }, |
| 50 | { "drive-open-drain", PIN_CONFIG_DRIVE_OPEN_DRAIN, 0 }, |
| 51 | { "drive-open-source", PIN_CONFIG_DRIVE_OPEN_SOURCE, 0 }, |
| 52 | { "drive-strength", PIN_CONFIG_DRIVE_STRENGTH, 0 }, |
| 53 | { "input-enable", PIN_CONFIG_INPUT_ENABLE, 1 }, |
| 54 | { "input-disable", PIN_CONFIG_INPUT_ENABLE, 0 }, |
| 55 | }; |
| 56 | |
| 57 | static int sandbox_get_pins_count(struct udevice *dev) |
| 58 | { |
| 59 | return ARRAY_SIZE(sandbox_pins); |
| 60 | } |
| 61 | |
| 62 | static const char *sandbox_get_pin_name(struct udevice *dev, unsigned selector) |
| 63 | { |
| 64 | return sandbox_pins[selector]; |
| 65 | } |
| 66 | |
Patrice Chotard | 3cd1f33 | 2018-10-24 14:10:22 +0200 | [diff] [blame] | 67 | static int sandbox_get_pin_muxing(struct udevice *dev, |
| 68 | unsigned int selector, |
| 69 | char *buf, int size) |
| 70 | { |
| 71 | snprintf(buf, size, "%s", sandbox_pins_muxing[selector]); |
| 72 | |
| 73 | return 0; |
| 74 | } |
| 75 | |
Masahiro Yamada | 0b53a75 | 2015-08-27 12:44:30 +0900 | [diff] [blame] | 76 | static int sandbox_get_groups_count(struct udevice *dev) |
| 77 | { |
| 78 | return ARRAY_SIZE(sandbox_groups); |
| 79 | } |
| 80 | |
| 81 | static const char *sandbox_get_group_name(struct udevice *dev, |
| 82 | unsigned selector) |
| 83 | { |
| 84 | return sandbox_groups[selector]; |
| 85 | } |
| 86 | |
| 87 | static int sandbox_get_functions_count(struct udevice *dev) |
| 88 | { |
| 89 | return ARRAY_SIZE(sandbox_functions); |
| 90 | } |
| 91 | |
| 92 | static const char *sandbox_get_function_name(struct udevice *dev, |
| 93 | unsigned selector) |
| 94 | { |
| 95 | return sandbox_functions[selector]; |
| 96 | } |
| 97 | |
| 98 | static int sandbox_pinmux_set(struct udevice *dev, unsigned pin_selector, |
| 99 | unsigned func_selector) |
| 100 | { |
| 101 | debug("sandbox pinmux: pin = %d (%s), function = %d (%s)\n", |
| 102 | pin_selector, sandbox_get_pin_name(dev, pin_selector), |
| 103 | func_selector, sandbox_get_function_name(dev, func_selector)); |
| 104 | |
| 105 | return 0; |
| 106 | } |
| 107 | |
| 108 | static int sandbox_pinmux_group_set(struct udevice *dev, |
| 109 | unsigned group_selector, |
| 110 | unsigned func_selector) |
| 111 | { |
| 112 | debug("sandbox pinmux: group = %d (%s), function = %d (%s)\n", |
| 113 | group_selector, sandbox_get_group_name(dev, group_selector), |
| 114 | func_selector, sandbox_get_function_name(dev, func_selector)); |
| 115 | |
| 116 | return 0; |
| 117 | } |
| 118 | |
| 119 | static int sandbox_pinconf_set(struct udevice *dev, unsigned pin_selector, |
| 120 | unsigned param, unsigned argument) |
| 121 | { |
| 122 | debug("sandbox pinconf: pin = %d (%s), param = %d, arg = %d\n", |
| 123 | pin_selector, sandbox_get_pin_name(dev, pin_selector), |
| 124 | param, argument); |
| 125 | |
| 126 | return 0; |
| 127 | } |
| 128 | |
| 129 | static int sandbox_pinconf_group_set(struct udevice *dev, |
| 130 | unsigned group_selector, |
| 131 | unsigned param, unsigned argument) |
| 132 | { |
| 133 | debug("sandbox pinconf: group = %d (%s), param = %d, arg = %d\n", |
| 134 | group_selector, sandbox_get_group_name(dev, group_selector), |
| 135 | param, argument); |
| 136 | |
| 137 | return 0; |
| 138 | } |
| 139 | |
| 140 | const struct pinctrl_ops sandbox_pinctrl_ops = { |
| 141 | .get_pins_count = sandbox_get_pins_count, |
| 142 | .get_pin_name = sandbox_get_pin_name, |
Patrice Chotard | 3cd1f33 | 2018-10-24 14:10:22 +0200 | [diff] [blame] | 143 | .get_pin_muxing = sandbox_get_pin_muxing, |
Masahiro Yamada | 0b53a75 | 2015-08-27 12:44:30 +0900 | [diff] [blame] | 144 | .get_groups_count = sandbox_get_groups_count, |
| 145 | .get_group_name = sandbox_get_group_name, |
| 146 | .get_functions_count = sandbox_get_functions_count, |
| 147 | .get_function_name = sandbox_get_function_name, |
| 148 | .pinmux_set = sandbox_pinmux_set, |
| 149 | .pinmux_group_set = sandbox_pinmux_group_set, |
| 150 | .pinconf_num_params = ARRAY_SIZE(sandbox_conf_params), |
| 151 | .pinconf_params = sandbox_conf_params, |
| 152 | .pinconf_set = sandbox_pinconf_set, |
| 153 | .pinconf_group_set = sandbox_pinconf_group_set, |
| 154 | .set_state = pinctrl_generic_set_state, |
| 155 | }; |
| 156 | |
| 157 | static const struct udevice_id sandbox_pinctrl_match[] = { |
| 158 | { .compatible = "sandbox,pinctrl" }, |
| 159 | { /* sentinel */ } |
| 160 | }; |
| 161 | |
| 162 | U_BOOT_DRIVER(sandbox_pinctrl) = { |
| 163 | .name = "sandbox_pinctrl", |
| 164 | .id = UCLASS_PINCTRL, |
| 165 | .of_match = sandbox_pinctrl_match, |
| 166 | .ops = &sandbox_pinctrl_ops, |
| 167 | }; |