[U-Boot] [RFC v3 PATCH 4/4] pinctrl: sandbox: add sandbox pinctrl driver

Simon Glass sjg at chromium.org
Wed Aug 12 16:16:18 CEST 2015


Hi Marahiro,

On 10 August 2015 at 10:05, Masahiro Yamada
<yamada.masahiro at socionext.com> wrote:
> This driver actually does nothing but test pinctrl uclass, and
> demonstrate how things work.
>
> To try this driver, uncomment /* #define DEBUG */ in the
> drivers/pinctrl/pinctrl-sandbox.c, and debug messages will be
> displayed.
>
>   DRAM:  128 MiB
>   sandbox pinmux: group = 1 (serial_a), function = 1 (serial)
>   Using default environment
>
>   In:    cros-ec-keyb
>   Out:   lcd
>   Err:   lcd
>   Net:   Net Initialization Skipped
>   eth0: eth at 10002000, eth1: eth at 80000000, eth5: eth at 90000000
>   => i2c dev 0
>   Setting bus to 0
>   sandbox pinmux: group = 0 (i2c), function = 0 (i2c)
>   sandbox pinconf: group = 0 (i2c), param = 3, arg = 1
>
> Signed-off-by: Masahiro Yamada <yamada.masahiro at socionext.com>
> ---
>
>  arch/sandbox/dts/sandbox.dts      |  19 +++++
>  configs/sandbox_defconfig         |   5 ++
>  drivers/pinctrl/Kconfig           |   3 +
>  drivers/pinctrl/Makefile          |   2 +
>  drivers/pinctrl/pinctrl-sandbox.c | 157 ++++++++++++++++++++++++++++++++++++++
>  5 files changed, 186 insertions(+)
>  create mode 100644 drivers/pinctrl/pinctrl-sandbox.c

Reviewed-by: Simon Glass <sjg at chromium.org>


>
> diff --git a/arch/sandbox/dts/sandbox.dts b/arch/sandbox/dts/sandbox.dts
> index 8927527..9aad39c 100644
> --- a/arch/sandbox/dts/sandbox.dts
> +++ b/arch/sandbox/dts/sandbox.dts
> @@ -92,6 +92,8 @@
>                 reg = <0 0>;
>                 compatible = "sandbox,i2c";
>                 clock-frequency = <400000>;
> +               pinctrl-names = "default";
> +               pinctrl-0 = <&pinctrl_i2c0>;
>                 eeprom at 2c {
>                         reg = <0x2c>;
>                         compatible = "i2c-eeprom";
> @@ -136,6 +138,21 @@
>                 };
>         };
>
> +       pinctrl {
> +               compatible = "sandbox,pinctrl";
> +
> +               pinctrl_i2c0: i2c0 {
> +                       groups = "i2c";
> +                       function = "i2c";
> +                       bias-pull-up;
> +               };
> +
> +               pinctrl_serial0: uart0 {
> +                       groups = "serial_a";
> +                       function = "serial";
> +               };
> +       };
> +
>         spi at 0 {
>                 #address-cells = <1>;
>                 #size-cells = <0>;
> @@ -168,6 +185,8 @@
>         uart0: serial {
>                 compatible = "sandbox,serial";
>                 sandbox,text-colour = "cyan";
> +               pinctrl-names = "default";
> +               pinctrl-0 = <&pinctrl_serial0>;
>         };
>

Should also have some definitions in test.fdt and a test for pinctrl.

>         usb at 0 {
> diff --git a/configs/sandbox_defconfig b/configs/sandbox_defconfig
> index 874a26b..85693f0 100644
> --- a/configs/sandbox_defconfig
> +++ b/configs/sandbox_defconfig
> @@ -27,6 +27,11 @@ CONFIG_SANDBOX_SERIAL=y
>  CONFIG_TPM_TIS_SANDBOX=y
>  CONFIG_SYS_I2C_SANDBOX=y
>  CONFIG_SANDBOX_SPI=y
> +CONFIG_PINCTRL=y
> +CONFIG_PINCTRL_GENERIC=y
> +CONFIG_PINMUX=y
> +CONFIG_PINCONF=y
> +CONFIG_PINCTRL_SANDBOX=y
>  CONFIG_SANDBOX_GPIO=y
>  CONFIG_DM_PMIC=y
>  CONFIG_DM_PMIC_SANDBOX=y
> diff --git a/drivers/pinctrl/Kconfig b/drivers/pinctrl/Kconfig
> index eca83fe..c6229d9 100644
> --- a/drivers/pinctrl/Kconfig
> +++ b/drivers/pinctrl/Kconfig
> @@ -45,6 +45,9 @@ config SPL_PINCONF
>
>  if PINCTRL || SPL_PINCTRL
>
> +config PINCTRL_SANDBOX
> +       bool "Sandbox pinctrl driver"

help - what does this support / do?

> +
>  endif
>
>  endmenu
> diff --git a/drivers/pinctrl/Makefile b/drivers/pinctrl/Makefile
> index a713c7d..35decf4 100644
> --- a/drivers/pinctrl/Makefile
> +++ b/drivers/pinctrl/Makefile
> @@ -1,2 +1,4 @@
>  obj-y                                  += pinctrl-uclass.o
>  obj-$(CONFIG_$(SPL_)PINCTRL_GENERIC)   += pinctrl-generic.o
> +
> +obj-$(CONFIG_PINCTRL_SANDBOX)  += pinctrl-sandbox.o
> diff --git a/drivers/pinctrl/pinctrl-sandbox.c b/drivers/pinctrl/pinctrl-sandbox.c
> new file mode 100644
> index 0000000..1f02bf2
> --- /dev/null
> +++ b/drivers/pinctrl/pinctrl-sandbox.c
> @@ -0,0 +1,157 @@
> +/*
> + * SPDX-License-Identifier:    GPL-2.0+

(C)?

> + */
> +
> +/* #define DEBUG */
> +
> +#include <common.h>
> +#include <dm/device.h>
> +#include <dm/pinctrl.h>
> +
> +static const char * const sandbox_pins[] = {
> +       "SCL",
> +       "SDA",
> +       "TX",
> +       "RX",
> +};
> +
> +static const char * const sandbox_groups[] = {
> +       "i2c",
> +       "serial_a",
> +       "serial_b",
> +       "spi",
> +};
> +
> +static const char * const sandbox_functions[] = {
> +       "i2c",
> +       "serial",
> +       "spi",
> +};
> +
> +static const struct pinconf_param sandbox_conf_params[] = {
> +       { "bias-disable", PIN_CONFIG_BIAS_DISABLE, 0 },
> +       { "bias-high-impedance", PIN_CONFIG_BIAS_HIGH_IMPEDANCE, 0 },
> +       { "bias-bus-hold", PIN_CONFIG_BIAS_BUS_HOLD, 0 },
> +       { "bias-pull-up", PIN_CONFIG_BIAS_PULL_UP, 1 },
> +       { "bias-pull-down", PIN_CONFIG_BIAS_PULL_DOWN, 1 },
> +       { "bias-pull-pin-default", PIN_CONFIG_BIAS_PULL_PIN_DEFAULT, 1 },
> +       { "drive-open-drain", PIN_CONFIG_DRIVE_OPEN_DRAIN, 0 },
> +       { "drive-open-source", PIN_CONFIG_DRIVE_OPEN_SOURCE, 0 },
> +       { "drive-strength", PIN_CONFIG_DRIVE_STRENGTH, 0 },
> +       { "input-enable", PIN_CONFIG_INPUT_ENABLE, 1 },
> +       { "input-disable", PIN_CONFIG_INPUT_ENABLE, 0 },
> +};
> +
> +static int sandbox_pinctrl_probe(struct udevice *dev)
> +{
> +       return 0;
> +}
> +
> +static int sandbox_pinctrl_remove(struct udevice *dev)
> +{
> +       return 0;
> +}

Drop those two functions?

> +
> +static int sandbox_get_pins_count(struct udevice *dev)
> +{
> +       return ARRAY_SIZE(sandbox_pins);
> +}
> +
> +static const char *sandbox_get_pin_name(struct udevice *dev, unsigned selector)
> +{
> +       return sandbox_pins[selector];
> +}
> +
> +static int sandbox_get_groups_count(struct udevice *dev)
> +{
> +       return ARRAY_SIZE(sandbox_groups);
> +}
> +
> +static const char *sandbox_get_group_name(struct udevice *dev,
> +                                         unsigned selector)
> +{
> +       return sandbox_groups[selector];
> +}
> +
> +static int sandbox_get_functions_count(struct udevice *dev)
> +{
> +       return ARRAY_SIZE(sandbox_functions);
> +}
> +
> +static const char *sandbox_get_function_name(struct udevice *dev,
> +                                            unsigned selector)
> +{
> +       return sandbox_functions[selector];
> +}
> +
> +static int sandbox_pinmux_set(struct udevice *dev, unsigned pin_selector,
> +                             unsigned func_selector)
> +{
> +       debug("sandbox pinmux: pin = %d (%s), function = %d (%s)\n",
> +             pin_selector, sandbox_get_pin_name(dev, pin_selector),
> +             func_selector, sandbox_get_function_name(dev, func_selector));
> +
> +       return 0;
> +}
> +
> +static int sandbox_pinmux_group_set(struct udevice *dev,
> +                                   unsigned group_selector,
> +                                   unsigned func_selector)
> +{
> +       debug("sandbox pinmux: group = %d (%s), function = %d (%s)\n",
> +             group_selector, sandbox_get_group_name(dev, group_selector),
> +             func_selector, sandbox_get_function_name(dev, func_selector));
> +
> +       return 0;
> +}
> +
> +static int sandbox_pinconf_set(struct udevice *dev, unsigned pin_selector,
> +                              unsigned param, unsigned argument)
> +{
> +       debug("sandbox pinconf: pin = %d (%s), param = %d, arg = %d\n",
> +             pin_selector, sandbox_get_pin_name(dev, pin_selector),
> +             param, argument);
> +
> +       return 0;
> +}
> +
> +static int sandbox_pinconf_group_set(struct udevice *dev,
> +                                    unsigned group_selector,
> +                                    unsigned param, unsigned argument)
> +{
> +       debug("sandbox pinconf: group = %d (%s), param = %d, arg = %d\n",
> +             group_selector, sandbox_get_group_name(dev, group_selector),
> +             param, argument);
> +
> +       return 0;
> +}
> +
> +const struct pinctrl_ops sandbox_pinctrl_ops = {
> +       .get_pins_count = sandbox_get_pins_count,
> +       .get_pin_name = sandbox_get_pin_name,
> +       .get_groups_count = sandbox_get_groups_count,
> +       .get_group_name = sandbox_get_group_name,
> +       .get_functions_count = sandbox_get_functions_count,
> +       .get_function_name = sandbox_get_function_name,
> +       .pinmux_set = sandbox_pinmux_set,
> +       .pinmux_group_set = sandbox_pinmux_group_set,
> +       .pinconf_num_params = ARRAY_SIZE(sandbox_conf_params),
> +       .pinconf_params = sandbox_conf_params,
> +       .pinconf_set = sandbox_pinconf_set,
> +       .pinconf_group_set = sandbox_pinconf_group_set,
> +       .set_state = pinctrl_generic_set_state,
> +};
> +
> +static const struct udevice_id sandbox_pinctrl_match[] = {
> +       { .compatible = "sandbox,pinctrl" },
> +       { /* sentinel */ }
> +};
> +
> +U_BOOT_DRIVER(sandbox_pinctrl) = {
> +       .name = "sandbox_pinctrl",
> +       .id = UCLASS_PINCTRL,
> +       .of_match = sandbox_pinctrl_match,
> +       .probe = sandbox_pinctrl_probe,
> +       .remove = sandbox_pinctrl_remove,
> +       .ops = &sandbox_pinctrl_ops,
> +};
> --
> 1.9.1
>

Regards,
Simon


More information about the U-Boot mailing list