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