Ejemplo n.º 1
0
/* 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;
}
Ejemplo n.º 2
0
void board_lcd_enable(void)
{
    int rc = -1;
    dev = qup_i2c_init(GSBI_ID_8, 100000, 24000000);

    /* Make sure dev is created and initialized properly */
    if (!dev) {
        while (1) ;
        return;
    }

    /* Store current value of these registers as to not destroy their previous
       state. */
    uint8_t open_drain_a = expander_read(GPIO_EXPANDER_REG_OPEN_DRAIN_A);
    uint8_t dir_b = expander_read(GPIO_EXPANDER_REG_DIR_B);
    uint8_t dir_a = expander_read(GPIO_EXPANDER_REG_DIR_A);
    uint8_t data_b = expander_read(GPIO_EXPANDER_REG_DATA_B);
    uint8_t data_a = expander_read(GPIO_EXPANDER_REG_DATA_A);

    /* Set the LVDS_SHUTDOWN_N to open drain and output low. */
    dprintf(INFO, "Enable lvds_shutdown_n line for Open Drain.\n");
    expander_write(GPIO_EXPANDER_REG_OPEN_DRAIN_A, 0x04 | open_drain_a);

    dprintf(INFO, "Enable lvds_shutdown_n line for output.\n");
    expander_write(GPIO_EXPANDER_REG_DIR_A, ~0x04 & dir_a);

    dprintf(INFO, "Drive the LVDS_SHUTDOWN_N pin high here.\n");
    expander_write(GPIO_EXPANDER_REG_DATA_A, 0x04 | data_a);

    /* Turn on the VREG_L2B to 3.3V. */

    /* Power on the appropiate PMIC LDO power rails */
    if (lcd_power_on())
        return;

    /* Enable the GPIO as LCDC mode LCD. */
    lcd_gpio_cfg(1);

    /* Arbitrary delay */
    udelay(20000);

    /* Set the GPIOs needed for backlight */
    bl_gpio_init();
    /* Set backlight level with API (to 8 by default) */
    rc = panel_set_backlight(8);
    if(rc)
        dprintf(CRITICAL,"Error in setting panel backlight\n");

    dprintf(INFO, "Enable BACKLIGHT_EN line for output.\n");
    expander_write(GPIO_EXPANDER_REG_DIR_B, ~0x10 & dir_b);

    dprintf(INFO, "Drive BACKLIGHT_EN to high\n");
    expander_write(GPIO_EXPANDER_REG_DATA_B, 0x10 | data_b);

}