1*83d290c5STom Rini // SPDX-License-Identifier: GPL-2.0+ 29c6a3c67SMasahiro Yamada /* 39c6a3c67SMasahiro Yamada * Copyright (C) 2015 Masahiro Yamada <yamada.masahiro@socionext.com> 49c6a3c67SMasahiro Yamada */ 59c6a3c67SMasahiro Yamada 69c6a3c67SMasahiro Yamada /* #define DEBUG */ 79c6a3c67SMasahiro Yamada 89c6a3c67SMasahiro Yamada #include <common.h> 99d922450SSimon Glass #include <dm.h> 109c6a3c67SMasahiro Yamada #include <dm/pinctrl.h> 119c6a3c67SMasahiro Yamada 129c6a3c67SMasahiro Yamada static const char * const sandbox_pins[] = { 139c6a3c67SMasahiro Yamada "SCL", 149c6a3c67SMasahiro Yamada "SDA", 159c6a3c67SMasahiro Yamada "TX", 169c6a3c67SMasahiro Yamada "RX", 179c6a3c67SMasahiro Yamada }; 189c6a3c67SMasahiro Yamada 199c6a3c67SMasahiro Yamada static const char * const sandbox_groups[] = { 209c6a3c67SMasahiro Yamada "i2c", 219c6a3c67SMasahiro Yamada "serial_a", 229c6a3c67SMasahiro Yamada "serial_b", 239c6a3c67SMasahiro Yamada "spi", 249c6a3c67SMasahiro Yamada }; 259c6a3c67SMasahiro Yamada 269c6a3c67SMasahiro Yamada static const char * const sandbox_functions[] = { 279c6a3c67SMasahiro Yamada "i2c", 289c6a3c67SMasahiro Yamada "serial", 299c6a3c67SMasahiro Yamada "spi", 309c6a3c67SMasahiro Yamada }; 319c6a3c67SMasahiro Yamada 329c6a3c67SMasahiro Yamada static const struct pinconf_param sandbox_conf_params[] = { 339c6a3c67SMasahiro Yamada { "bias-disable", PIN_CONFIG_BIAS_DISABLE, 0 }, 349c6a3c67SMasahiro Yamada { "bias-high-impedance", PIN_CONFIG_BIAS_HIGH_IMPEDANCE, 0 }, 359c6a3c67SMasahiro Yamada { "bias-bus-hold", PIN_CONFIG_BIAS_BUS_HOLD, 0 }, 369c6a3c67SMasahiro Yamada { "bias-pull-up", PIN_CONFIG_BIAS_PULL_UP, 1 }, 379c6a3c67SMasahiro Yamada { "bias-pull-down", PIN_CONFIG_BIAS_PULL_DOWN, 1 }, 389c6a3c67SMasahiro Yamada { "bias-pull-pin-default", PIN_CONFIG_BIAS_PULL_PIN_DEFAULT, 1 }, 399c6a3c67SMasahiro Yamada { "drive-open-drain", PIN_CONFIG_DRIVE_OPEN_DRAIN, 0 }, 409c6a3c67SMasahiro Yamada { "drive-open-source", PIN_CONFIG_DRIVE_OPEN_SOURCE, 0 }, 419c6a3c67SMasahiro Yamada { "drive-strength", PIN_CONFIG_DRIVE_STRENGTH, 0 }, 429c6a3c67SMasahiro Yamada { "input-enable", PIN_CONFIG_INPUT_ENABLE, 1 }, 439c6a3c67SMasahiro Yamada { "input-disable", PIN_CONFIG_INPUT_ENABLE, 0 }, 449c6a3c67SMasahiro Yamada }; 459c6a3c67SMasahiro Yamada 469c6a3c67SMasahiro Yamada static int sandbox_get_pins_count(struct udevice *dev) 479c6a3c67SMasahiro Yamada { 489c6a3c67SMasahiro Yamada return ARRAY_SIZE(sandbox_pins); 499c6a3c67SMasahiro Yamada } 509c6a3c67SMasahiro Yamada 519c6a3c67SMasahiro Yamada static const char *sandbox_get_pin_name(struct udevice *dev, unsigned selector) 529c6a3c67SMasahiro Yamada { 539c6a3c67SMasahiro Yamada return sandbox_pins[selector]; 549c6a3c67SMasahiro Yamada } 559c6a3c67SMasahiro Yamada 569c6a3c67SMasahiro Yamada static int sandbox_get_groups_count(struct udevice *dev) 579c6a3c67SMasahiro Yamada { 589c6a3c67SMasahiro Yamada return ARRAY_SIZE(sandbox_groups); 599c6a3c67SMasahiro Yamada } 609c6a3c67SMasahiro Yamada 619c6a3c67SMasahiro Yamada static const char *sandbox_get_group_name(struct udevice *dev, 629c6a3c67SMasahiro Yamada unsigned selector) 639c6a3c67SMasahiro Yamada { 649c6a3c67SMasahiro Yamada return sandbox_groups[selector]; 659c6a3c67SMasahiro Yamada } 669c6a3c67SMasahiro Yamada 679c6a3c67SMasahiro Yamada static int sandbox_get_functions_count(struct udevice *dev) 689c6a3c67SMasahiro Yamada { 699c6a3c67SMasahiro Yamada return ARRAY_SIZE(sandbox_functions); 709c6a3c67SMasahiro Yamada } 719c6a3c67SMasahiro Yamada 729c6a3c67SMasahiro Yamada static const char *sandbox_get_function_name(struct udevice *dev, 739c6a3c67SMasahiro Yamada unsigned selector) 749c6a3c67SMasahiro Yamada { 759c6a3c67SMasahiro Yamada return sandbox_functions[selector]; 769c6a3c67SMasahiro Yamada } 779c6a3c67SMasahiro Yamada 789c6a3c67SMasahiro Yamada static int sandbox_pinmux_set(struct udevice *dev, unsigned pin_selector, 799c6a3c67SMasahiro Yamada unsigned func_selector) 809c6a3c67SMasahiro Yamada { 819c6a3c67SMasahiro Yamada debug("sandbox pinmux: pin = %d (%s), function = %d (%s)\n", 829c6a3c67SMasahiro Yamada pin_selector, sandbox_get_pin_name(dev, pin_selector), 839c6a3c67SMasahiro Yamada func_selector, sandbox_get_function_name(dev, func_selector)); 849c6a3c67SMasahiro Yamada 859c6a3c67SMasahiro Yamada return 0; 869c6a3c67SMasahiro Yamada } 879c6a3c67SMasahiro Yamada 889c6a3c67SMasahiro Yamada static int sandbox_pinmux_group_set(struct udevice *dev, 899c6a3c67SMasahiro Yamada unsigned group_selector, 909c6a3c67SMasahiro Yamada unsigned func_selector) 919c6a3c67SMasahiro Yamada { 929c6a3c67SMasahiro Yamada debug("sandbox pinmux: group = %d (%s), function = %d (%s)\n", 939c6a3c67SMasahiro Yamada group_selector, sandbox_get_group_name(dev, group_selector), 949c6a3c67SMasahiro Yamada func_selector, sandbox_get_function_name(dev, func_selector)); 959c6a3c67SMasahiro Yamada 969c6a3c67SMasahiro Yamada return 0; 979c6a3c67SMasahiro Yamada } 989c6a3c67SMasahiro Yamada 999c6a3c67SMasahiro Yamada static int sandbox_pinconf_set(struct udevice *dev, unsigned pin_selector, 1009c6a3c67SMasahiro Yamada unsigned param, unsigned argument) 1019c6a3c67SMasahiro Yamada { 1029c6a3c67SMasahiro Yamada debug("sandbox pinconf: pin = %d (%s), param = %d, arg = %d\n", 1039c6a3c67SMasahiro Yamada pin_selector, sandbox_get_pin_name(dev, pin_selector), 1049c6a3c67SMasahiro Yamada param, argument); 1059c6a3c67SMasahiro Yamada 1069c6a3c67SMasahiro Yamada return 0; 1079c6a3c67SMasahiro Yamada } 1089c6a3c67SMasahiro Yamada 1099c6a3c67SMasahiro Yamada static int sandbox_pinconf_group_set(struct udevice *dev, 1109c6a3c67SMasahiro Yamada unsigned group_selector, 1119c6a3c67SMasahiro Yamada unsigned param, unsigned argument) 1129c6a3c67SMasahiro Yamada { 1139c6a3c67SMasahiro Yamada debug("sandbox pinconf: group = %d (%s), param = %d, arg = %d\n", 1149c6a3c67SMasahiro Yamada group_selector, sandbox_get_group_name(dev, group_selector), 1159c6a3c67SMasahiro Yamada param, argument); 1169c6a3c67SMasahiro Yamada 1179c6a3c67SMasahiro Yamada return 0; 1189c6a3c67SMasahiro Yamada } 1199c6a3c67SMasahiro Yamada 1209c6a3c67SMasahiro Yamada const struct pinctrl_ops sandbox_pinctrl_ops = { 1219c6a3c67SMasahiro Yamada .get_pins_count = sandbox_get_pins_count, 1229c6a3c67SMasahiro Yamada .get_pin_name = sandbox_get_pin_name, 1239c6a3c67SMasahiro Yamada .get_groups_count = sandbox_get_groups_count, 1249c6a3c67SMasahiro Yamada .get_group_name = sandbox_get_group_name, 1259c6a3c67SMasahiro Yamada .get_functions_count = sandbox_get_functions_count, 1269c6a3c67SMasahiro Yamada .get_function_name = sandbox_get_function_name, 1279c6a3c67SMasahiro Yamada .pinmux_set = sandbox_pinmux_set, 1289c6a3c67SMasahiro Yamada .pinmux_group_set = sandbox_pinmux_group_set, 1299c6a3c67SMasahiro Yamada .pinconf_num_params = ARRAY_SIZE(sandbox_conf_params), 1309c6a3c67SMasahiro Yamada .pinconf_params = sandbox_conf_params, 1319c6a3c67SMasahiro Yamada .pinconf_set = sandbox_pinconf_set, 1329c6a3c67SMasahiro Yamada .pinconf_group_set = sandbox_pinconf_group_set, 1339c6a3c67SMasahiro Yamada .set_state = pinctrl_generic_set_state, 1349c6a3c67SMasahiro Yamada }; 1359c6a3c67SMasahiro Yamada 1369c6a3c67SMasahiro Yamada static const struct udevice_id sandbox_pinctrl_match[] = { 1379c6a3c67SMasahiro Yamada { .compatible = "sandbox,pinctrl" }, 1389c6a3c67SMasahiro Yamada { /* sentinel */ } 1399c6a3c67SMasahiro Yamada }; 1409c6a3c67SMasahiro Yamada 1419c6a3c67SMasahiro Yamada U_BOOT_DRIVER(sandbox_pinctrl) = { 1429c6a3c67SMasahiro Yamada .name = "sandbox_pinctrl", 1439c6a3c67SMasahiro Yamada .id = UCLASS_PINCTRL, 1449c6a3c67SMasahiro Yamada .of_match = sandbox_pinctrl_match, 1459c6a3c67SMasahiro Yamada .ops = &sandbox_pinctrl_ops, 1469c6a3c67SMasahiro Yamada }; 147