183d290c5STom 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",
170523a6c6SEugen Hristev "W1"
189c6a3c67SMasahiro Yamada };
199c6a3c67SMasahiro Yamada
20*21e23aafSPatrice Chotard static const char * const sandbox_pins_muxing[] = {
21*21e23aafSPatrice Chotard "I2C SCL",
22*21e23aafSPatrice Chotard "I2C SDA",
23*21e23aafSPatrice Chotard "Uart TX",
24*21e23aafSPatrice Chotard "Uart RX",
25*21e23aafSPatrice Chotard "1-wire gpio",
26*21e23aafSPatrice Chotard };
27*21e23aafSPatrice Chotard
289c6a3c67SMasahiro Yamada static const char * const sandbox_groups[] = {
299c6a3c67SMasahiro Yamada "i2c",
309c6a3c67SMasahiro Yamada "serial_a",
319c6a3c67SMasahiro Yamada "serial_b",
329c6a3c67SMasahiro Yamada "spi",
330523a6c6SEugen Hristev "w1",
349c6a3c67SMasahiro Yamada };
359c6a3c67SMasahiro Yamada
369c6a3c67SMasahiro Yamada static const char * const sandbox_functions[] = {
379c6a3c67SMasahiro Yamada "i2c",
389c6a3c67SMasahiro Yamada "serial",
399c6a3c67SMasahiro Yamada "spi",
400523a6c6SEugen Hristev "w1",
419c6a3c67SMasahiro Yamada };
429c6a3c67SMasahiro Yamada
439c6a3c67SMasahiro Yamada static const struct pinconf_param sandbox_conf_params[] = {
449c6a3c67SMasahiro Yamada { "bias-disable", PIN_CONFIG_BIAS_DISABLE, 0 },
459c6a3c67SMasahiro Yamada { "bias-high-impedance", PIN_CONFIG_BIAS_HIGH_IMPEDANCE, 0 },
469c6a3c67SMasahiro Yamada { "bias-bus-hold", PIN_CONFIG_BIAS_BUS_HOLD, 0 },
479c6a3c67SMasahiro Yamada { "bias-pull-up", PIN_CONFIG_BIAS_PULL_UP, 1 },
489c6a3c67SMasahiro Yamada { "bias-pull-down", PIN_CONFIG_BIAS_PULL_DOWN, 1 },
499c6a3c67SMasahiro Yamada { "bias-pull-pin-default", PIN_CONFIG_BIAS_PULL_PIN_DEFAULT, 1 },
509c6a3c67SMasahiro Yamada { "drive-open-drain", PIN_CONFIG_DRIVE_OPEN_DRAIN, 0 },
519c6a3c67SMasahiro Yamada { "drive-open-source", PIN_CONFIG_DRIVE_OPEN_SOURCE, 0 },
529c6a3c67SMasahiro Yamada { "drive-strength", PIN_CONFIG_DRIVE_STRENGTH, 0 },
539c6a3c67SMasahiro Yamada { "input-enable", PIN_CONFIG_INPUT_ENABLE, 1 },
549c6a3c67SMasahiro Yamada { "input-disable", PIN_CONFIG_INPUT_ENABLE, 0 },
559c6a3c67SMasahiro Yamada };
569c6a3c67SMasahiro Yamada
sandbox_get_pins_count(struct udevice * dev)579c6a3c67SMasahiro Yamada static int sandbox_get_pins_count(struct udevice *dev)
589c6a3c67SMasahiro Yamada {
599c6a3c67SMasahiro Yamada return ARRAY_SIZE(sandbox_pins);
609c6a3c67SMasahiro Yamada }
619c6a3c67SMasahiro Yamada
sandbox_get_pin_name(struct udevice * dev,unsigned selector)629c6a3c67SMasahiro Yamada static const char *sandbox_get_pin_name(struct udevice *dev, unsigned selector)
639c6a3c67SMasahiro Yamada {
649c6a3c67SMasahiro Yamada return sandbox_pins[selector];
659c6a3c67SMasahiro Yamada }
669c6a3c67SMasahiro Yamada
sandbox_get_pin_muxing(struct udevice * dev,unsigned int selector,char * buf,int size)67*21e23aafSPatrice Chotard static int sandbox_get_pin_muxing(struct udevice *dev,
68*21e23aafSPatrice Chotard unsigned int selector,
69*21e23aafSPatrice Chotard char *buf, int size)
70*21e23aafSPatrice Chotard {
71*21e23aafSPatrice Chotard snprintf(buf, size, "%s", sandbox_pins_muxing[selector]);
72*21e23aafSPatrice Chotard
73*21e23aafSPatrice Chotard return 0;
74*21e23aafSPatrice Chotard }
75*21e23aafSPatrice Chotard
sandbox_get_groups_count(struct udevice * dev)769c6a3c67SMasahiro Yamada static int sandbox_get_groups_count(struct udevice *dev)
779c6a3c67SMasahiro Yamada {
789c6a3c67SMasahiro Yamada return ARRAY_SIZE(sandbox_groups);
799c6a3c67SMasahiro Yamada }
809c6a3c67SMasahiro Yamada
sandbox_get_group_name(struct udevice * dev,unsigned selector)819c6a3c67SMasahiro Yamada static const char *sandbox_get_group_name(struct udevice *dev,
829c6a3c67SMasahiro Yamada unsigned selector)
839c6a3c67SMasahiro Yamada {
849c6a3c67SMasahiro Yamada return sandbox_groups[selector];
859c6a3c67SMasahiro Yamada }
869c6a3c67SMasahiro Yamada
sandbox_get_functions_count(struct udevice * dev)879c6a3c67SMasahiro Yamada static int sandbox_get_functions_count(struct udevice *dev)
889c6a3c67SMasahiro Yamada {
899c6a3c67SMasahiro Yamada return ARRAY_SIZE(sandbox_functions);
909c6a3c67SMasahiro Yamada }
919c6a3c67SMasahiro Yamada
sandbox_get_function_name(struct udevice * dev,unsigned selector)929c6a3c67SMasahiro Yamada static const char *sandbox_get_function_name(struct udevice *dev,
939c6a3c67SMasahiro Yamada unsigned selector)
949c6a3c67SMasahiro Yamada {
959c6a3c67SMasahiro Yamada return sandbox_functions[selector];
969c6a3c67SMasahiro Yamada }
979c6a3c67SMasahiro Yamada
sandbox_pinmux_set(struct udevice * dev,unsigned pin_selector,unsigned func_selector)989c6a3c67SMasahiro Yamada static int sandbox_pinmux_set(struct udevice *dev, unsigned pin_selector,
999c6a3c67SMasahiro Yamada unsigned func_selector)
1009c6a3c67SMasahiro Yamada {
1019c6a3c67SMasahiro Yamada debug("sandbox pinmux: pin = %d (%s), function = %d (%s)\n",
1029c6a3c67SMasahiro Yamada pin_selector, sandbox_get_pin_name(dev, pin_selector),
1039c6a3c67SMasahiro Yamada func_selector, sandbox_get_function_name(dev, func_selector));
1049c6a3c67SMasahiro Yamada
1059c6a3c67SMasahiro Yamada return 0;
1069c6a3c67SMasahiro Yamada }
1079c6a3c67SMasahiro Yamada
sandbox_pinmux_group_set(struct udevice * dev,unsigned group_selector,unsigned func_selector)1089c6a3c67SMasahiro Yamada static int sandbox_pinmux_group_set(struct udevice *dev,
1099c6a3c67SMasahiro Yamada unsigned group_selector,
1109c6a3c67SMasahiro Yamada unsigned func_selector)
1119c6a3c67SMasahiro Yamada {
1129c6a3c67SMasahiro Yamada debug("sandbox pinmux: group = %d (%s), function = %d (%s)\n",
1139c6a3c67SMasahiro Yamada group_selector, sandbox_get_group_name(dev, group_selector),
1149c6a3c67SMasahiro Yamada func_selector, sandbox_get_function_name(dev, func_selector));
1159c6a3c67SMasahiro Yamada
1169c6a3c67SMasahiro Yamada return 0;
1179c6a3c67SMasahiro Yamada }
1189c6a3c67SMasahiro Yamada
sandbox_pinconf_set(struct udevice * dev,unsigned pin_selector,unsigned param,unsigned argument)1199c6a3c67SMasahiro Yamada static int sandbox_pinconf_set(struct udevice *dev, unsigned pin_selector,
1209c6a3c67SMasahiro Yamada unsigned param, unsigned argument)
1219c6a3c67SMasahiro Yamada {
1229c6a3c67SMasahiro Yamada debug("sandbox pinconf: pin = %d (%s), param = %d, arg = %d\n",
1239c6a3c67SMasahiro Yamada pin_selector, sandbox_get_pin_name(dev, pin_selector),
1249c6a3c67SMasahiro Yamada param, argument);
1259c6a3c67SMasahiro Yamada
1269c6a3c67SMasahiro Yamada return 0;
1279c6a3c67SMasahiro Yamada }
1289c6a3c67SMasahiro Yamada
sandbox_pinconf_group_set(struct udevice * dev,unsigned group_selector,unsigned param,unsigned argument)1299c6a3c67SMasahiro Yamada static int sandbox_pinconf_group_set(struct udevice *dev,
1309c6a3c67SMasahiro Yamada unsigned group_selector,
1319c6a3c67SMasahiro Yamada unsigned param, unsigned argument)
1329c6a3c67SMasahiro Yamada {
1339c6a3c67SMasahiro Yamada debug("sandbox pinconf: group = %d (%s), param = %d, arg = %d\n",
1349c6a3c67SMasahiro Yamada group_selector, sandbox_get_group_name(dev, group_selector),
1359c6a3c67SMasahiro Yamada param, argument);
1369c6a3c67SMasahiro Yamada
1379c6a3c67SMasahiro Yamada return 0;
1389c6a3c67SMasahiro Yamada }
1399c6a3c67SMasahiro Yamada
1409c6a3c67SMasahiro Yamada const struct pinctrl_ops sandbox_pinctrl_ops = {
1419c6a3c67SMasahiro Yamada .get_pins_count = sandbox_get_pins_count,
1429c6a3c67SMasahiro Yamada .get_pin_name = sandbox_get_pin_name,
143*21e23aafSPatrice Chotard .get_pin_muxing = sandbox_get_pin_muxing,
1449c6a3c67SMasahiro Yamada .get_groups_count = sandbox_get_groups_count,
1459c6a3c67SMasahiro Yamada .get_group_name = sandbox_get_group_name,
1469c6a3c67SMasahiro Yamada .get_functions_count = sandbox_get_functions_count,
1479c6a3c67SMasahiro Yamada .get_function_name = sandbox_get_function_name,
1489c6a3c67SMasahiro Yamada .pinmux_set = sandbox_pinmux_set,
1499c6a3c67SMasahiro Yamada .pinmux_group_set = sandbox_pinmux_group_set,
1509c6a3c67SMasahiro Yamada .pinconf_num_params = ARRAY_SIZE(sandbox_conf_params),
1519c6a3c67SMasahiro Yamada .pinconf_params = sandbox_conf_params,
1529c6a3c67SMasahiro Yamada .pinconf_set = sandbox_pinconf_set,
1539c6a3c67SMasahiro Yamada .pinconf_group_set = sandbox_pinconf_group_set,
1549c6a3c67SMasahiro Yamada .set_state = pinctrl_generic_set_state,
1559c6a3c67SMasahiro Yamada };
1569c6a3c67SMasahiro Yamada
1579c6a3c67SMasahiro Yamada static const struct udevice_id sandbox_pinctrl_match[] = {
1589c6a3c67SMasahiro Yamada { .compatible = "sandbox,pinctrl" },
1599c6a3c67SMasahiro Yamada { /* sentinel */ }
1609c6a3c67SMasahiro Yamada };
1619c6a3c67SMasahiro Yamada
1629c6a3c67SMasahiro Yamada U_BOOT_DRIVER(sandbox_pinctrl) = {
1639c6a3c67SMasahiro Yamada .name = "sandbox_pinctrl",
1649c6a3c67SMasahiro Yamada .id = UCLASS_PINCTRL,
1659c6a3c67SMasahiro Yamada .of_match = sandbox_pinctrl_match,
1669c6a3c67SMasahiro Yamada .ops = &sandbox_pinctrl_ops,
1679c6a3c67SMasahiro Yamada };
168