Пример #1
0
/* Check that two RTC devices can be used independently */
static int dm_test_rtc_dual(struct unit_test_state *uts)
{
	struct rtc_time now1, now2, cmp;
	struct udevice *dev1, *dev2;
	struct udevice *emul1, *emul2;
	long offset;

	ut_assertok(uclass_get_device(UCLASS_RTC, 0, &dev1));
	ut_assertok(dm_rtc_get(dev1, &now1));
	ut_assertok(uclass_get_device(UCLASS_RTC, 1, &dev2));
	ut_assertok(dm_rtc_get(dev2, &now2));

	ut_assertok(device_find_first_child(dev1, &emul1));
	ut_assert(emul1 != NULL);
	ut_assertok(device_find_first_child(dev2, &emul2));
	ut_assert(emul2 != NULL);

	offset = sandbox_i2c_rtc_set_offset(emul1, false, -1);
	sandbox_i2c_rtc_set_offset(emul2, false, offset + 1);
	memset(&cmp, '\0', sizeof(cmp));
	ut_assertok(dm_rtc_get(dev2, &cmp));
	ut_asserteq(-EINVAL, cmp_times(&now1, &cmp, false));

	memset(&cmp, '\0', sizeof(cmp));
	ut_assertok(dm_rtc_get(dev1, &cmp));
	ut_assertok(cmp_times(&now1, &cmp, true));

	return 0;
}
Пример #2
0
static efi_status_t EFIAPI efi_get_time(struct efi_time *time,
					struct efi_time_cap *capabilities)
{
#if defined(CONFIG_CMD_DATE) && defined(CONFIG_DM_RTC)
	struct rtc_time tm;
	int r;
	struct udevice *dev;

	EFI_ENTRY("%p %p", time, capabilities);

	r = uclass_get_device(UCLASS_RTC, 0, &dev);
	if (r)
		return EFI_EXIT(EFI_DEVICE_ERROR);

	r = dm_rtc_get(dev, &tm);
	if (r)
		return EFI_EXIT(EFI_DEVICE_ERROR);

	memset(time, 0, sizeof(*time));
	time->year = tm.tm_year;
	time->month = tm.tm_mon;
	time->day = tm.tm_mday;
	time->hour = tm.tm_hour;
	time->minute = tm.tm_min;
	time->daylight = tm.tm_isdst;

	return EFI_EXIT(EFI_SUCCESS);
#else
	return EFI_DEVICE_ERROR;
#endif
}
Пример #3
0
/* Reset the time */
static int dm_test_rtc_reset(struct dm_test_state *dms)
{
	struct rtc_time now;
	struct udevice *dev, *emul;
	long old_base_time, base_time;

	ut_assertok(uclass_get_device(UCLASS_RTC, 0, &dev));
	ut_assertok(dm_rtc_get(dev, &now));

	ut_assertok(device_find_first_child(dev, &emul));
	ut_assert(emul != NULL);

	old_base_time = sandbox_i2c_rtc_get_set_base_time(emul, 0);

	ut_asserteq(0, sandbox_i2c_rtc_get_set_base_time(emul, -1));

	/* Resetting the RTC should put he base time back to normal */
	ut_assertok(dm_rtc_reset(dev));
	base_time = sandbox_i2c_rtc_get_set_base_time(emul, -1);
	ut_asserteq(old_base_time, base_time);

	return 0;
}
Пример #4
0
static int do_date(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
{
	struct rtc_time tm;
	int rcode = 0;
	int old_bus __maybe_unused;

	/* switch to correct I2C bus */
#ifdef CONFIG_DM_RTC
	struct udevice *dev;

	rcode = uclass_get_device(UCLASS_RTC, 0, &dev);
	if (rcode) {
		printf("Cannot find RTC: err=%d\n", rcode);
		return CMD_RET_FAILURE;
	}
#elif defined(CONFIG_SYS_I2C)
	old_bus = i2c_get_bus_num();
	i2c_set_bus_num(CONFIG_SYS_RTC_BUS_NUM);
#else
	old_bus = I2C_GET_BUS();
	I2C_SET_BUS(CONFIG_SYS_RTC_BUS_NUM);
#endif

	switch (argc) {
	case 2:			/* set date & time */
		if (strcmp(argv[1],"reset") == 0) {
			puts ("Reset RTC...\n");
#ifdef CONFIG_DM_RTC
			rcode = dm_rtc_reset(dev);
			if (!rcode)
				rcode = dm_rtc_set(dev, &default_tm);
#else
			rtc_reset();
			rcode = rtc_set(&default_tm);
#endif
			if (rcode)
				puts("## Failed to set date after RTC reset\n");
		} else {
			/* initialize tm with current time */
#ifdef CONFIG_DM_RTC
			rcode = dm_rtc_get(dev, &tm);
#else
			rcode = rtc_get(&tm);
#endif
			if (!rcode) {
				/* insert new date & time */
				if (mk_date(argv[1], &tm) != 0) {
					puts ("## Bad date format\n");
					break;
				}
				/* and write to RTC */
#ifdef CONFIG_DM_RTC
				rcode = dm_rtc_set(dev, &tm);
#else
				rcode = rtc_set(&tm);
#endif
				if (rcode) {
					printf("## Set date failed: err=%d\n",
					       rcode);
				}
			} else {
				puts("## Get date failed\n");
			}
		}
		/* FALL TROUGH */
	case 1:			/* get date & time */
#ifdef CONFIG_DM_RTC
		rcode = dm_rtc_get(dev, &tm);
#else
		rcode = rtc_get(&tm);
#endif
		if (rcode) {
			puts("## Get date failed\n");
			break;
		}

		printf ("Date: %4d-%02d-%02d (%sday)    Time: %2d:%02d:%02d\n",
			tm.tm_year, tm.tm_mon, tm.tm_mday,
			(tm.tm_wday<0 || tm.tm_wday>6) ?
				"unknown " : RELOC(weekdays[tm.tm_wday]),
			tm.tm_hour, tm.tm_min, tm.tm_sec);

		break;
	default:
		rcode = CMD_RET_USAGE;
	}

	/* switch back to original I2C bus */
#ifdef CONFIG_SYS_I2C
	i2c_set_bus_num(old_bus);
#elif !defined(CONFIG_DM_RTC)
	I2C_SET_BUS(old_bus);
#endif

	return rcode ? CMD_RET_FAILURE : 0;
}
Пример #5
0
/* Set and get the time */
static int dm_test_rtc_set_get(struct dm_test_state *dms)
{
	struct rtc_time now, time, cmp;
	struct udevice *dev, *emul;
	long offset, old_offset, old_base_time;

	ut_assertok(uclass_get_device(UCLASS_RTC, 0, &dev));
	ut_assertok(dm_rtc_get(dev, &now));

	ut_assertok(device_find_first_child(dev, &emul));
	ut_assert(emul != NULL);

	/* Tell the RTC to go into manual mode */
	old_offset = sandbox_i2c_rtc_set_offset(emul, false, 0);
	old_base_time = sandbox_i2c_rtc_get_set_base_time(emul, -1);

	memset(&time, '\0', sizeof(time));
	time.tm_mday = 25;
	time.tm_mon = 8;
	time.tm_year = 2004;
	time.tm_sec = 0;
	time.tm_min = 18;
	time.tm_hour = 18;
	ut_assertok(dm_rtc_set(dev, &time));

	memset(&cmp, '\0', sizeof(cmp));
	ut_assertok(dm_rtc_get(dev, &cmp));
	ut_assertok(cmp_times(&time, &cmp, true));

	/* Increment by 1 second */
	offset = sandbox_i2c_rtc_set_offset(emul, false, 0);
	sandbox_i2c_rtc_set_offset(emul, false, offset + 1);

	memset(&cmp, '\0', sizeof(cmp));
	ut_assertok(dm_rtc_get(dev, &cmp));
	ut_asserteq(1, cmp.tm_sec);

	/* Check against original offset */
	sandbox_i2c_rtc_set_offset(emul, false, old_offset);
	ut_assertok(dm_rtc_get(dev, &cmp));
	ut_assertok(cmp_times(&now, &cmp, true));

	/* Back to the original offset */
	sandbox_i2c_rtc_set_offset(emul, false, 0);
	memset(&cmp, '\0', sizeof(cmp));
	ut_assertok(dm_rtc_get(dev, &cmp));
	ut_assertok(cmp_times(&now, &cmp, true));

	/* Increment the base time by 1 emul */
	sandbox_i2c_rtc_get_set_base_time(emul, old_base_time + 1);
	memset(&cmp, '\0', sizeof(cmp));
	ut_assertok(dm_rtc_get(dev, &cmp));
	if (now.tm_sec == 59) {
		ut_asserteq(0, cmp.tm_sec);
	} else {
		ut_asserteq(now.tm_sec + 1, cmp.tm_sec);
	}

	old_offset = sandbox_i2c_rtc_set_offset(emul, true, 0);

	return 0;
}