예제 #1
0
int do_date (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
{
	struct rtc_time tm;
	int rcode = 0;
	int old_bus;

	/* switch to correct I2C bus */
	old_bus = I2C_GET_BUS();
	I2C_SET_BUS(CONFIG_SYS_RTC_BUS_NUM);

	switch (argc) {
	case 2:			/* set date & time */
		if (strcmp(argv[1],"reset") == 0) {
			puts ("Reset RTC...\n");
			rtc_reset ();
		} else {
			/* initialize tm with current time */
			rcode = rtc_get (&tm);

			if(!rcode) {
				/* insert new date & time */
				if (mk_date (argv[1], &tm) != 0) {
					puts ("## Bad date format\n");
					break;
				}
				/* and write to RTC */
				rcode = rtc_set (&tm);
				if(rcode)
					puts("## Set date failled\n");
			} else {
				puts("## Get date failled\n");
			}
		}
		/* FALL TROUGH */
	case 1:			/* get date & time */
		rcode = rtc_get (&tm);

		if (rcode) {
			puts("## Get date failled\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:
		cmd_usage(cmdtp);
		rcode = 1;
	}

	/* switch back to original I2C bus */
	I2C_SET_BUS(old_bus);

	return rcode;
}
예제 #2
0
파일: dtt.c 프로젝트: 01hyang/u-boot
void dtt_init(void)
{
	int old_bus;

	/* switch to correct I2C bus */
	old_bus = I2C_GET_BUS();
	I2C_SET_BUS(CONFIG_SYS_DTT_BUS_NUM);

	_initialize_dtt();

	/* switch back to original I2C bus */
	I2C_SET_BUS(old_bus);
}
int tps65911_read(u8 addr, u8* buf, int length)
{
	int old_bus;

	old_bus = I2C_GET_BUS();
	I2C_SET_BUS(0);
	if (i2c_read(TPS65911_SLAVE_ADDR, addr, 0x1, buf, length) != 0) {
		puts ("Error reading tps65911.\n");
		return -1;
	}
	if(old_bus != 0)
		I2C_SET_BUS(old_bus);
	return 0;
}
int tps65911_config(u8 addr, u8 val)
{
	int ret;
	int old_bus;

	old_bus = I2C_GET_BUS();
	I2C_SET_BUS(0);
	ret = i2c_write(TPS65911_SLAVE_ADDR, addr, 0x1, &val, 0x1);
	if (ret != 0) {
		puts ("Error writing tps65911.\n");
	}
	if(old_bus != 0)
		I2C_SET_BUS(old_bus);
	return ret;
}
예제 #5
0
int do_dtt (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
{
    int i;
    unsigned char sensors[] = CONFIG_DTT_SENSORS;
    int old_bus;

    /* switch to correct I2C bus */
    old_bus = I2C_GET_BUS();
    I2C_SET_BUS(CONFIG_SYS_DTT_BUS_NUM);

    /*
     * Loop through sensors, read
     * temperature, and output it.
     */
    for (i = 0; i < sizeof (sensors); i++)
        printf ("DTT%d: %i C\n", i + 1, dtt_get_temp (sensors[i]));

    /* switch back to original I2C bus */
    I2C_SET_BUS(old_bus);

    return 0;
}	/* do_dtt() */
예제 #6
0
파일: dtt.c 프로젝트: 01hyang/u-boot
int dtt_i2c(void)
{
#if defined CONFIG_DTT_SENSORS
	int i;
	unsigned char sensors[] = CONFIG_DTT_SENSORS;
	int old_bus;

	/* Force a compilation error, if there are more then 32 sensors */
	BUILD_BUG_ON(sizeof(sensors) > 32);
	/* switch to correct I2C bus */
#ifdef CONFIG_SYS_I2C
	old_bus = i2c_get_bus_num();
	i2c_set_bus_num(CONFIG_SYS_DTT_BUS_NUM);
#else
	old_bus = I2C_GET_BUS();
	I2C_SET_BUS(CONFIG_SYS_DTT_BUS_NUM);
#endif

	_initialize_dtt();

	/*
	 * Loop through sensors, read
	 * temperature, and output it.
	 */
	for (i = 0; i < sizeof(sensors); i++)
		printf("DTT%d: %i C\n", i + 1, dtt_get_temp(sensors[i]));

	/* switch back to original I2C bus */
#ifdef CONFIG_SYS_I2C
	i2c_set_bus_num(old_bus);
#else
	I2C_SET_BUS(old_bus);
#endif
#endif

	return 0;
}
예제 #7
0
파일: date.c 프로젝트: Noltari/u-boot
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;
}