Beispiel #1
0
static int __init ds1302_rtc_probe(struct platform_device *pdev)
{
	struct rtc_device *rtc;

	if (ds1302_hw_init()) {
		dev_err(&pdev->dev, "Failed to init communication channel");
		return -EINVAL;
	}

	/* Reset */
	ds1302_reset();

	/* Write a magic value to the DS1302 RAM, and see if it sticks. */
	ds1302_writebyte(RTC_ADDR_RAM0, 0x42);
	if (ds1302_readbyte(RTC_ADDR_RAM0) != 0x42) {
		dev_err(&pdev->dev, "Failed to probe");
		return -ENODEV;
	}

	rtc = rtc_device_register("ds1302", &pdev->dev,
					   &ds1302_rtc_ops, THIS_MODULE);
	if (IS_ERR(rtc))
		return PTR_ERR(rtc);

	platform_set_drvdata(pdev, rtc);

	return 0;
}
Beispiel #2
0
void __init secureedge5410_rtc_init(void)
{
	unsigned char *test = "snapgear";
	int i;

	ds1302_reset();

	use_ds1302 = 1;

	for (i = 0; test[i]; i++)
		ds1302_writebyte(32 + i, test[i]);

	for (i = 0; test[i]; i++)
		if (ds1302_readbyte(32 + i) != test[i]) {
			use_ds1302 = 0;
			break;
		}

	if (use_ds1302) {
		rtc_sh_get_time = snapgear_rtc_gettimeofday;
		rtc_sh_set_time = snapgear_rtc_settimeofday;
	}
		
	printk("SnapGear RTC: using %s rtc.\n", use_ds1302 ? "ds1302" : "internal");
}
Beispiel #3
0
static void ds1302_writebyte(unsigned int addr, unsigned int val)
{
	ds1302_reset();

	ds1302_start();
	ds1302_sendbits(((addr & 0x3f) << 1) | RTC_CMD_WRITE);
	ds1302_sendbits(val);
	ds1302_stop();
}
Beispiel #4
0
static int __init ds1302_init(void)
{
	misc_register(&ds1302_dev);

	printk ("DS1302: Copyright (C) 2001, Greg Ungerer "
		"([email protected])\n");

	ds1302_reset();
	return 0;
}
Beispiel #5
0
static unsigned int ds1302_readbyte(unsigned int addr)
{
	unsigned int val;

	ds1302_reset();

	ds1302_start();
	ds1302_sendbits(((addr & 0x3f) << 1) | RTC_CMD_READ);
	val = ds1302_recvbits();
	ds1302_stop();

	return val;
}
Beispiel #6
0
static int16 ds1302_read_temp(void)
{
	uint8 temp_data[2]; // ¶Á³öζÈÔÝ·Å
	int16 temp;

	ds1302_reset();
	ds1302_write_byte(0xCC); // Skip ROM cmd
	ds1302_write_byte(0xBE); // read
	temp_data[0] = ds1302_read_byte();  // low 8 bits
	temp_data[1] = ds1302_read_byte();  // high 8 bits

	temp = temp_data[1];
	temp <<= 8;
	temp |= temp_data[0];
	temp >>= 4;

	return temp;
}
Beispiel #7
0
static void ds1302_start(void)
{
	ds1302_reset();
	ds1302_write_byte(0xCC); // Skip ROM cmd
	ds1302_write_byte(0x44); // convert cmd
}