示例#1
0
文件: panel.c 项目: Noltari/u-boot
/* Basic test of the panel uclass */
static int dm_test_panel(struct unit_test_state *uts)
{
	struct udevice *dev, *pwm, *gpio, *reg;
	uint period_ns;
	uint duty_ns;
	bool enable;
	bool polarity;

	ut_assertok(uclass_first_device_err(UCLASS_PANEL, &dev));
	ut_assertok(uclass_first_device_err(UCLASS_PWM, &pwm));
	ut_assertok(uclass_get_device(UCLASS_GPIO, 1, &gpio));
	ut_assertok(regulator_get_by_platname("VDD_EMMC_1.8V", &reg));
	ut_assertok(sandbox_pwm_get_config(pwm, 0, &period_ns, &duty_ns,
					   &enable, &polarity));
	ut_asserteq(false, enable);
	ut_asserteq(false, regulator_get_enable(reg));

	ut_assertok(panel_enable_backlight(dev));
	ut_assertok(sandbox_pwm_get_config(pwm, 0, &period_ns, &duty_ns,
					   &enable, &polarity));
	ut_asserteq(1000, period_ns);
	ut_asserteq(170 * 1000 / 256, duty_ns);
	ut_asserteq(true, enable);
	ut_asserteq(false, polarity);
	ut_asserteq(1, sandbox_gpio_get_value(gpio, 1));
	ut_asserteq(true, regulator_get_enable(reg));

	ut_assertok(panel_set_backlight(dev, 40));
	ut_assertok(sandbox_pwm_get_config(pwm, 0, &period_ns, &duty_ns,
					   &enable, &polarity));
	ut_asserteq(64 * 1000 / 256, duty_ns);

	ut_assertok(panel_set_backlight(dev, BACKLIGHT_MAX));
	ut_assertok(sandbox_pwm_get_config(pwm, 0, &period_ns, &duty_ns,
					   &enable, &polarity));
	ut_asserteq(255 * 1000 / 256, duty_ns);

	ut_assertok(panel_set_backlight(dev, BACKLIGHT_MIN));
	ut_assertok(sandbox_pwm_get_config(pwm, 0, &period_ns, &duty_ns,
					   &enable, &polarity));
	ut_asserteq(0 * 1000 / 256, duty_ns);
	ut_asserteq(1, sandbox_gpio_get_value(gpio, 1));

	ut_assertok(panel_set_backlight(dev, BACKLIGHT_DEFAULT));
	ut_assertok(sandbox_pwm_get_config(pwm, 0, &period_ns, &duty_ns,
					   &enable, &polarity));
	ut_asserteq(true, enable);
	ut_asserteq(170 * 1000 / 256, duty_ns);

	ut_assertok(panel_set_backlight(dev, BACKLIGHT_OFF));
	ut_assertok(sandbox_pwm_get_config(pwm, 0, &period_ns, &duty_ns,
					   &enable, &polarity));
	ut_asserteq(0 * 1000 / 256, duty_ns);
	ut_asserteq(0, sandbox_gpio_get_value(gpio, 1));
	ut_asserteq(false, regulator_get_enable(reg));

	return 0;
}
示例#2
0
/* read GPIO IN value of port 'offset' */
static int sb_gpio_get_value(struct udevice *dev, unsigned offset)
{
	debug("%s: offset:%u\n", __func__, offset);

	if (check_reserved(dev, offset, __func__))
		return -1;

	return sandbox_gpio_get_value(dev, offset);
}
示例#3
0
文件: led.c 项目: axxia/axxia_u-boot
static int dm_test_led_blink(struct unit_test_state *uts)
{
	const int offset = 1;
	struct udevice *dev, *gpio;

	/*
	 * Check that we get an error when trying to blink an LED, since it is
	 * not supported by the GPIO LED driver.
	 */
	ut_assertok(uclass_get_device(UCLASS_LED, 1, &dev));
	ut_assertok(uclass_get_device(UCLASS_GPIO, 1, &gpio));
	ut_asserteq(0, sandbox_gpio_get_value(gpio, offset));
	ut_asserteq(-ENOSYS, led_set_state(dev, LEDST_BLINK));
	ut_asserteq(0, sandbox_gpio_get_value(gpio, offset));
	ut_asserteq(LEDST_OFF, led_get_state(dev));
	ut_asserteq(-ENOSYS, led_set_period(dev, 100));

	return 0;
}
示例#4
0
文件: led.c 项目: axxia/axxia_u-boot
/* Test that we can toggle LEDs */
static int dm_test_led_toggle(struct unit_test_state *uts)
{
	const int offset = 1;
	struct udevice *dev, *gpio;

	/*
	 * Check that we can manipulate an LED. LED 1 is connected to GPIO
	 * bank gpio_a, offset 1.
	 */
	ut_assertok(uclass_get_device(UCLASS_LED, 1, &dev));
	ut_assertok(uclass_get_device(UCLASS_GPIO, 1, &gpio));
	ut_asserteq(0, sandbox_gpio_get_value(gpio, offset));
	ut_assertok(led_set_state(dev, LEDST_TOGGLE));
	ut_asserteq(1, sandbox_gpio_get_value(gpio, offset));
	ut_asserteq(LEDST_ON, led_get_state(dev));

	ut_assertok(led_set_state(dev, LEDST_TOGGLE));
	ut_asserteq(0, sandbox_gpio_get_value(gpio, offset));
	ut_asserteq(LEDST_OFF, led_get_state(dev));

	return 0;
}
示例#5
0
static int sb_gpio_get_state(struct udevice *dev, unsigned int offset,
			     char *buf, int bufsize)
{
	struct gpio_dev_priv *uc_priv = dev->uclass_priv;
	struct gpio_state *state = dev_get_priv(dev);
	const char *label;

	label = state[offset].label;
	snprintf(buf, bufsize, "%s%d: %s: %d [%c]%s%s",
		 uc_priv->bank_name ? uc_priv->bank_name : "", offset,
		 sandbox_gpio_get_direction(dev, offset) ? "out" : " in",
		 sandbox_gpio_get_value(dev, offset),
		 get_gpio_flag(dev, offset, GPIOF_RESERVED) ? 'x' : ' ',
		 label ? " " : "",
		 label ? label : "");

	return 0;
}
示例#6
0
/* Test that sandbox GPIOs work correctly */
static int dm_test_gpio(struct dm_test_state *dms)
{
	unsigned int offset, gpio;
	struct dm_gpio_ops *ops;
	struct udevice *dev;
	const char *name;
	int offset_count;
	char buf[80];

	/*
	 * We expect to get 3 banks. One is anonymous (just numbered) and
	 * comes from platdata. The other two are named a (20 gpios)
	 * and b (10 gpios) and come from the device tree. See
	 * test/dm/test.dts.
	 */
	ut_assertok(gpio_lookup_name("b4", &dev, &offset, &gpio));
	ut_asserteq_str(dev->name, "extra-gpios");
	ut_asserteq(4, offset);
	ut_asserteq(CONFIG_SANDBOX_GPIO_COUNT + 20 + 4, gpio);

	name = gpio_get_bank_info(dev, &offset_count);
	ut_asserteq_str("b", name);
	ut_asserteq(10, offset_count);

	/* Get the operations for this device */
	ops = gpio_get_ops(dev);
	ut_assert(ops->get_state);

	/* Cannot get a value until it is reserved */
	ut_asserteq(-1, ops->get_value(dev, offset));

	/*
	 * Now some tests that use the 'sandbox' back door. All GPIOs
	 * should default to input, include b4 that we are using here.
	 */
	ut_assertok(ops->get_state(dev, offset, buf, sizeof(buf)));
	ut_asserteq_str("b4:  in: 0 [ ]", buf);

	/* Change it to an output */
	sandbox_gpio_set_direction(dev, offset, 1);
	ut_assertok(ops->get_state(dev, offset, buf, sizeof(buf)));
	ut_asserteq_str("b4: out: 0 [ ]", buf);

	sandbox_gpio_set_value(dev, offset, 1);
	ut_assertok(ops->get_state(dev, offset, buf, sizeof(buf)));
	ut_asserteq_str("b4: out: 1 [ ]", buf);

	ut_assertok(ops->request(dev, offset, "testing"));
	ut_assertok(ops->get_state(dev, offset, buf, sizeof(buf)));
	ut_asserteq_str("b4: out: 1 [x] testing", buf);

	/* Change the value a bit */
	ut_asserteq(1, ops->get_value(dev, offset));
	ut_assertok(ops->set_value(dev, offset, 0));
	ut_asserteq(0, ops->get_value(dev, offset));
	ut_assertok(ops->get_state(dev, offset, buf, sizeof(buf)));
	ut_asserteq_str("b4: out: 0 [x] testing", buf);
	ut_assertok(ops->set_value(dev, offset, 1));
	ut_asserteq(1, ops->get_value(dev, offset));

	/* Make it an input */
	ut_assertok(ops->direction_input(dev, offset));
	ut_assertok(ops->get_state(dev, offset, buf, sizeof(buf)));
	ut_asserteq_str("b4:  in: 1 [x] testing", buf);
	sandbox_gpio_set_value(dev, offset, 0);
	ut_asserteq(0, sandbox_gpio_get_value(dev, offset));
	ut_assertok(ops->get_state(dev, offset, buf, sizeof(buf)));
	ut_asserteq_str("b4:  in: 0 [x] testing", buf);

	ut_assertok(ops->free(dev, offset));
	ut_assertok(ops->get_state(dev, offset, buf, sizeof(buf)));
	ut_asserteq_str("b4:  in: 0 [ ]", buf);

	/* Check the 'a' bank also */
	ut_assertok(gpio_lookup_name("a15", &dev, &offset, &gpio));
	ut_asserteq_str(dev->name, "base-gpios");
	ut_asserteq(15, offset);
	ut_asserteq(CONFIG_SANDBOX_GPIO_COUNT + 15, gpio);

	name = gpio_get_bank_info(dev, &offset_count);
	ut_asserteq_str("a", name);
	ut_asserteq(20, offset_count);

	/* And the anonymous bank */
	ut_assertok(gpio_lookup_name("14", &dev, &offset, &gpio));
	ut_asserteq_str(dev->name, "gpio_sandbox");
	ut_asserteq(14, offset);
	ut_asserteq(14, gpio);

	name = gpio_get_bank_info(dev, &offset_count);
	ut_asserteq_ptr(NULL, name);
	ut_asserteq(CONFIG_SANDBOX_GPIO_COUNT, offset_count);

	return 0;
}
示例#7
0
/* read GPIO IN value of port 'offset' */
static int sb_gpio_get_value(struct udevice *dev, unsigned offset)
{
	debug("%s: offset:%u\n", __func__, offset);

	return sandbox_gpio_get_value(dev, offset);
}