test: pinmux: add test for 'pinctrl-single' driver
The test adds two pinmux nodes to the device tree, one to test when a register changes only one pin's mux (pinctrl-single,pins), and the other to test when more than one pin's mux is changed (pinctrl-single,bits). This required replacing the controller's register access functions when the driver is used on sandbox. Signed-off-by: Dario Binacchi <dariobin@libero.it> Reviewed-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
parent
76d470de1a
commit
5532262d46
@ -569,6 +569,9 @@
|
|||||||
reg = <0 1>;
|
reg = <0 1>;
|
||||||
compatible = "sandbox,i2c";
|
compatible = "sandbox,i2c";
|
||||||
clock-frequency = <100000>;
|
clock-frequency = <100000>;
|
||||||
|
pinctrl-names = "default";
|
||||||
|
pinctrl-0 = <&pinmux_i2c0_pins>;
|
||||||
|
|
||||||
eeprom@2c {
|
eeprom@2c {
|
||||||
reg = <0x2c>;
|
reg = <0x2c>;
|
||||||
compatible = "i2c-eeprom";
|
compatible = "i2c-eeprom";
|
||||||
@ -649,6 +652,8 @@
|
|||||||
lcd {
|
lcd {
|
||||||
u-boot,dm-pre-reloc;
|
u-boot,dm-pre-reloc;
|
||||||
compatible = "sandbox,lcd-sdl";
|
compatible = "sandbox,lcd-sdl";
|
||||||
|
pinctrl-names = "default";
|
||||||
|
pinctrl-0 = <&pinmux_lcd_pins>;
|
||||||
xres = <1366>;
|
xres = <1366>;
|
||||||
yres = <768>;
|
yres = <768>;
|
||||||
};
|
};
|
||||||
@ -899,6 +904,8 @@
|
|||||||
pwm: pwm {
|
pwm: pwm {
|
||||||
compatible = "sandbox,pwm";
|
compatible = "sandbox,pwm";
|
||||||
#pwm-cells = <2>;
|
#pwm-cells = <2>;
|
||||||
|
pinctrl-names = "default";
|
||||||
|
pinctrl-0 = <&pinmux_pwm_pins>;
|
||||||
};
|
};
|
||||||
|
|
||||||
pwm2 {
|
pwm2 {
|
||||||
@ -970,6 +977,9 @@
|
|||||||
reg = <0 1>;
|
reg = <0 1>;
|
||||||
compatible = "sandbox,spi";
|
compatible = "sandbox,spi";
|
||||||
cs-gpios = <0>, <0>, <&gpio_a 0>;
|
cs-gpios = <0>, <0>, <&gpio_a 0>;
|
||||||
|
pinctrl-names = "default";
|
||||||
|
pinctrl-0 = <&pinmux_spi0_pins>;
|
||||||
|
|
||||||
spi.bin@0 {
|
spi.bin@0 {
|
||||||
reg = <0>;
|
reg = <0>;
|
||||||
compatible = "spansion,m25p16", "jedec,spi-nor";
|
compatible = "spansion,m25p16", "jedec,spi-nor";
|
||||||
@ -1059,6 +1069,8 @@
|
|||||||
uart0: serial {
|
uart0: serial {
|
||||||
compatible = "sandbox,serial";
|
compatible = "sandbox,serial";
|
||||||
u-boot,dm-pre-reloc;
|
u-boot,dm-pre-reloc;
|
||||||
|
pinctrl-names = "default";
|
||||||
|
pinctrl-0 = <&pinmux_uart0_pins>;
|
||||||
};
|
};
|
||||||
|
|
||||||
usb_0: usb@0 {
|
usb_0: usb@0 {
|
||||||
@ -1325,6 +1337,66 @@
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
pinctrl-single-no-width {
|
||||||
|
compatible = "pinctrl-single";
|
||||||
|
reg = <0x0000 0x238>;
|
||||||
|
#pinctrl-cells = <1>;
|
||||||
|
pinctrl-single,function-mask = <0x7f>;
|
||||||
|
};
|
||||||
|
|
||||||
|
pinctrl-single-pins {
|
||||||
|
compatible = "pinctrl-single";
|
||||||
|
reg = <0x0000 0x238>;
|
||||||
|
#pinctrl-cells = <1>;
|
||||||
|
pinctrl-single,register-width = <32>;
|
||||||
|
pinctrl-single,function-mask = <0x7f>;
|
||||||
|
|
||||||
|
pinmux_pwm_pins: pinmux_pwm_pins {
|
||||||
|
pinctrl-single,pins = < 0x48 0x06 >;
|
||||||
|
};
|
||||||
|
|
||||||
|
pinmux_spi0_pins: pinmux_spi0_pins {
|
||||||
|
pinctrl-single,pins = <
|
||||||
|
0x190 0x0c
|
||||||
|
0x194 0x0c
|
||||||
|
0x198 0x23
|
||||||
|
0x19c 0x0c
|
||||||
|
>;
|
||||||
|
};
|
||||||
|
|
||||||
|
pinmux_uart0_pins: pinmux_uart0_pins {
|
||||||
|
pinctrl-single,pins = <
|
||||||
|
0x70 0x30
|
||||||
|
0x74 0x00
|
||||||
|
>;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
pinctrl-single-bits {
|
||||||
|
compatible = "pinctrl-single";
|
||||||
|
reg = <0x0000 0x50>;
|
||||||
|
#pinctrl-cells = <2>;
|
||||||
|
pinctrl-single,bit-per-mux;
|
||||||
|
pinctrl-single,register-width = <32>;
|
||||||
|
pinctrl-single,function-mask = <0xf>;
|
||||||
|
|
||||||
|
pinmux_i2c0_pins: pinmux_i2c0_pins {
|
||||||
|
pinctrl-single,bits = <
|
||||||
|
0x10 0x00002200 0x0000ff00
|
||||||
|
>;
|
||||||
|
};
|
||||||
|
|
||||||
|
pinmux_lcd_pins: pinmux_lcd_pins {
|
||||||
|
pinctrl-single,bits = <
|
||||||
|
0x40 0x22222200 0xffffff00
|
||||||
|
0x44 0x22222222 0xffffffff
|
||||||
|
0x48 0x00000022 0x000000ff
|
||||||
|
0x48 0x02000000 0x0f000000
|
||||||
|
0x4c 0x02000022 0x0f0000ff
|
||||||
|
>;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
hwspinlock@0 {
|
hwspinlock@0 {
|
||||||
compatible = "sandbox,hwspinlock";
|
compatible = "sandbox,hwspinlock";
|
||||||
};
|
};
|
||||||
|
@ -197,6 +197,7 @@ CONFIG_PHY_SANDBOX=y
|
|||||||
CONFIG_PINCTRL=y
|
CONFIG_PINCTRL=y
|
||||||
CONFIG_PINCONF=y
|
CONFIG_PINCONF=y
|
||||||
CONFIG_PINCTRL_SANDBOX=y
|
CONFIG_PINCTRL_SANDBOX=y
|
||||||
|
CONFIG_PINCTRL_SINGLE=y
|
||||||
CONFIG_POWER_DOMAIN=y
|
CONFIG_POWER_DOMAIN=y
|
||||||
CONFIG_SANDBOX_POWER_DOMAIN=y
|
CONFIG_SANDBOX_POWER_DOMAIN=y
|
||||||
CONFIG_DM_PMIC=y
|
CONFIG_DM_PMIC=y
|
||||||
|
@ -142,6 +142,7 @@ CONFIG_PHY_SANDBOX=y
|
|||||||
CONFIG_PINCTRL=y
|
CONFIG_PINCTRL=y
|
||||||
CONFIG_PINCONF=y
|
CONFIG_PINCONF=y
|
||||||
CONFIG_PINCTRL_SANDBOX=y
|
CONFIG_PINCTRL_SANDBOX=y
|
||||||
|
CONFIG_PINCTRL_SINGLE=y
|
||||||
CONFIG_POWER_DOMAIN=y
|
CONFIG_POWER_DOMAIN=y
|
||||||
CONFIG_SANDBOX_POWER_DOMAIN=y
|
CONFIG_SANDBOX_POWER_DOMAIN=y
|
||||||
CONFIG_DM_PMIC=y
|
CONFIG_DM_PMIC=y
|
||||||
|
@ -51,6 +51,9 @@ struct single_func {
|
|||||||
* @pin_name: temporary buffer to store the pin name
|
* @pin_name: temporary buffer to store the pin name
|
||||||
*/
|
*/
|
||||||
struct single_priv {
|
struct single_priv {
|
||||||
|
#if (IS_ENABLED(CONFIG_SANDBOX))
|
||||||
|
u32 *sandbox_regs;
|
||||||
|
#endif
|
||||||
unsigned int bits_per_pin;
|
unsigned int bits_per_pin;
|
||||||
unsigned int npins;
|
unsigned int npins;
|
||||||
char pin_name[PINNAME_SIZE];
|
char pin_name[PINNAME_SIZE];
|
||||||
@ -87,6 +90,8 @@ struct single_fdt_bits_cfg {
|
|||||||
fdt32_t mask;
|
fdt32_t mask;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#if (!IS_ENABLED(CONFIG_SANDBOX))
|
||||||
|
|
||||||
static unsigned int single_read(struct udevice *dev, fdt_addr_t reg)
|
static unsigned int single_read(struct udevice *dev, fdt_addr_t reg)
|
||||||
{
|
{
|
||||||
struct single_pdata *pdata = dev_get_plat(dev);
|
struct single_pdata *pdata = dev_get_plat(dev);
|
||||||
@ -119,6 +124,24 @@ static void single_write(struct udevice *dev, unsigned int val, fdt_addr_t reg)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#else /* CONFIG_SANDBOX */
|
||||||
|
|
||||||
|
static unsigned int single_read(struct udevice *dev, fdt_addr_t reg)
|
||||||
|
{
|
||||||
|
struct single_priv *priv = dev_get_priv(dev);
|
||||||
|
|
||||||
|
return priv->sandbox_regs[reg];
|
||||||
|
}
|
||||||
|
|
||||||
|
static void single_write(struct udevice *dev, unsigned int val, fdt_addr_t reg)
|
||||||
|
{
|
||||||
|
struct single_priv *priv = dev_get_priv(dev);
|
||||||
|
|
||||||
|
priv->sandbox_regs[reg] = val;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* CONFIG_SANDBOX */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* single_get_pin_by_offset() - get a pin based on the register offset
|
* single_get_pin_by_offset() - get a pin based on the register offset
|
||||||
* @dev: single driver instance
|
* @dev: single driver instance
|
||||||
@ -436,6 +459,14 @@ static int single_probe(struct udevice *dev)
|
|||||||
INIT_LIST_HEAD(&priv->functions);
|
INIT_LIST_HEAD(&priv->functions);
|
||||||
|
|
||||||
size = pdata->offset + pdata->width / BITS_PER_BYTE;
|
size = pdata->offset + pdata->width / BITS_PER_BYTE;
|
||||||
|
#if (CONFIG_IS_ENABLED(SANDBOX))
|
||||||
|
priv->sandbox_regs =
|
||||||
|
devm_kzalloc(dev, size * sizeof(*priv->sandbox_regs),
|
||||||
|
GFP_KERNEL);
|
||||||
|
if (!priv->sandbox_regs)
|
||||||
|
return -ENOMEM;
|
||||||
|
#endif
|
||||||
|
|
||||||
priv->npins = size / (pdata->width / BITS_PER_BYTE);
|
priv->npins = size / (pdata->width / BITS_PER_BYTE);
|
||||||
if (pdata->bits_per_mux) {
|
if (pdata->bits_per_mux) {
|
||||||
priv->bits_per_pin = fls(pdata->mask);
|
priv->bits_per_pin = fls(pdata->mask);
|
||||||
|
@ -9,16 +9,21 @@
|
|||||||
#include <dm/test.h>
|
#include <dm/test.h>
|
||||||
#include <test/ut.h>
|
#include <test/ut.h>
|
||||||
|
|
||||||
static int dm_test_pinmux(struct unit_test_state *uts)
|
static char buf[64];
|
||||||
{
|
|
||||||
char buf[64];
|
|
||||||
struct udevice *dev;
|
|
||||||
|
|
||||||
#define test_muxing(selector, expected) do { \
|
#define test_muxing(selector, expected) do { \
|
||||||
ut_assertok(pinctrl_get_pin_muxing(dev, selector, buf, sizeof(buf))); \
|
ut_assertok(pinctrl_get_pin_muxing(dev, selector, buf, sizeof(buf))); \
|
||||||
ut_asserteq_str(expected, (char *)&buf); \
|
ut_asserteq_str(expected, (char *)&buf); \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
|
#define test_name(selector, expected) do { \
|
||||||
|
ut_assertok(pinctrl_get_pin_name(dev, selector, buf, sizeof(buf))); \
|
||||||
|
ut_asserteq_str(expected, (char *)&buf); \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
|
static int dm_test_pinmux(struct unit_test_state *uts)
|
||||||
|
{
|
||||||
|
struct udevice *dev;
|
||||||
|
|
||||||
ut_assertok(uclass_get_device_by_name(UCLASS_PINCTRL, "pinctrl", &dev));
|
ut_assertok(uclass_get_device_by_name(UCLASS_PINCTRL, "pinctrl", &dev));
|
||||||
test_muxing(0, "UART TX.");
|
test_muxing(0, "UART TX.");
|
||||||
test_muxing(1, "UART RX.");
|
test_muxing(1, "UART RX.");
|
||||||
@ -54,4 +59,80 @@ static int dm_test_pinmux(struct unit_test_state *uts)
|
|||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
DM_TEST(dm_test_pinmux, UT_TESTF_SCAN_FDT);
|
DM_TEST(dm_test_pinmux, UT_TESTF_SCAN_FDT);
|
||||||
|
|
||||||
|
static int dm_test_pinctrl_single(struct unit_test_state *uts)
|
||||||
|
{
|
||||||
|
struct udevice *dev;
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
ret = uclass_get_device_by_name(UCLASS_PINCTRL,
|
||||||
|
"pinctrl-single-no-width", &dev);
|
||||||
|
ut_asserteq(-EINVAL, ret);
|
||||||
|
ut_assertok(uclass_get_device_by_name(UCLASS_PWM, "pwm", &dev));
|
||||||
|
ut_assertok(uclass_get_device_by_name(UCLASS_SERIAL, "serial", &dev));
|
||||||
|
ut_assertok(uclass_get_device_by_name(UCLASS_SPI, "spi@0", &dev));
|
||||||
|
ut_assertok(uclass_get_device_by_name(UCLASS_PINCTRL,
|
||||||
|
"pinctrl-single-pins", &dev));
|
||||||
|
ut_asserteq(142, pinctrl_get_pins_count(dev));
|
||||||
|
test_name(0, "PIN0");
|
||||||
|
test_name(141, "PIN141");
|
||||||
|
test_name(142, "Error");
|
||||||
|
test_muxing(0, "0x00000000 0x00000000 UNCLAIMED");
|
||||||
|
test_muxing(18, "0x00000048 0x00000006 pinmux_pwm_pins");
|
||||||
|
test_muxing(28, "0x00000070 0x00000030 pinmux_uart0_pins");
|
||||||
|
test_muxing(29, "0x00000074 0x00000000 pinmux_uart0_pins");
|
||||||
|
test_muxing(100, "0x00000190 0x0000000c pinmux_spi0_pins");
|
||||||
|
test_muxing(101, "0x00000194 0x0000000c pinmux_spi0_pins");
|
||||||
|
test_muxing(102, "0x00000198 0x00000023 pinmux_spi0_pins");
|
||||||
|
test_muxing(103, "0x0000019c 0x0000000c pinmux_spi0_pins");
|
||||||
|
ret = pinctrl_get_pin_muxing(dev, 142, buf, sizeof(buf));
|
||||||
|
ut_asserteq(-EINVAL, ret);
|
||||||
|
ut_assertok(uclass_get_device_by_name(UCLASS_I2C, "i2c@0", &dev));
|
||||||
|
ut_assertok(uclass_get_device_by_name(UCLASS_VIDEO, "lcd", &dev));
|
||||||
|
ut_assertok(uclass_get_device_by_name(UCLASS_PINCTRL,
|
||||||
|
"pinctrl-single-bits", &dev));
|
||||||
|
ut_asserteq(160, pinctrl_get_pins_count(dev));
|
||||||
|
test_name(0, "PIN0");
|
||||||
|
test_name(159, "PIN159");
|
||||||
|
test_name(160, "Error");
|
||||||
|
test_muxing(0, "0x00000000 0x00000000 UNCLAIMED");
|
||||||
|
test_muxing(34, "0x00000010 0x00000200 pinmux_i2c0_pins");
|
||||||
|
test_muxing(35, "0x00000010 0x00002000 pinmux_i2c0_pins");
|
||||||
|
test_muxing(130, "0x00000040 0x00000200 pinmux_lcd_pins");
|
||||||
|
test_muxing(131, "0x00000040 0x00002000 pinmux_lcd_pins");
|
||||||
|
test_muxing(132, "0x00000040 0x00020000 pinmux_lcd_pins");
|
||||||
|
test_muxing(133, "0x00000040 0x00200000 pinmux_lcd_pins");
|
||||||
|
test_muxing(134, "0x00000040 0x02000000 pinmux_lcd_pins");
|
||||||
|
test_muxing(135, "0x00000040 0x20000000 pinmux_lcd_pins");
|
||||||
|
test_muxing(136, "0x00000044 0x00000002 pinmux_lcd_pins");
|
||||||
|
test_muxing(137, "0x00000044 0x00000020 pinmux_lcd_pins");
|
||||||
|
test_muxing(138, "0x00000044 0x00000200 pinmux_lcd_pins");
|
||||||
|
test_muxing(139, "0x00000044 0x00002000 pinmux_lcd_pins");
|
||||||
|
test_muxing(140, "0x00000044 0x00020000 pinmux_lcd_pins");
|
||||||
|
test_muxing(141, "0x00000044 0x00200000 pinmux_lcd_pins");
|
||||||
|
test_muxing(142, "0x00000044 0x02000000 pinmux_lcd_pins");
|
||||||
|
test_muxing(143, "0x00000044 0x20000000 pinmux_lcd_pins");
|
||||||
|
test_muxing(144, "0x00000048 0x00000002 pinmux_lcd_pins");
|
||||||
|
test_muxing(145, "0x00000048 0x00000020 pinmux_lcd_pins");
|
||||||
|
test_muxing(146, "0x00000048 0x00000000 UNCLAIMED");
|
||||||
|
test_muxing(147, "0x00000048 0x00000000 UNCLAIMED");
|
||||||
|
test_muxing(148, "0x00000048 0x00000000 UNCLAIMED");
|
||||||
|
test_muxing(149, "0x00000048 0x00000000 UNCLAIMED");
|
||||||
|
test_muxing(150, "0x00000048 0x02000000 pinmux_lcd_pins");
|
||||||
|
test_muxing(151, "0x00000048 0x00000000 UNCLAIMED");
|
||||||
|
test_muxing(152, "0x0000004c 0x00000002 pinmux_lcd_pins");
|
||||||
|
test_muxing(153, "0x0000004c 0x00000020 pinmux_lcd_pins");
|
||||||
|
test_muxing(154, "0x0000004c 0x00000000 UNCLAIMED");
|
||||||
|
test_muxing(155, "0x0000004c 0x00000000 UNCLAIMED");
|
||||||
|
test_muxing(156, "0x0000004c 0x00000000 UNCLAIMED");
|
||||||
|
test_muxing(157, "0x0000004c 0x00000000 UNCLAIMED");
|
||||||
|
test_muxing(158, "0x0000004c 0x02000000 pinmux_lcd_pins");
|
||||||
|
test_muxing(159, "0x0000004c 0x00000000 UNCLAIMED");
|
||||||
|
ret = pinctrl_get_pin_muxing(dev, 160, buf, sizeof(buf));
|
||||||
|
ut_asserteq(-EINVAL, ret);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
DM_TEST(dm_test_pinctrl_single, UT_TESTF_SCAN_FDT);
|
||||||
|
Loading…
Reference in New Issue
Block a user