本文整理汇总了C++中rtc_device_register函数的典型用法代码示例。如果您正苦于以下问题:C++ rtc_device_register函数的具体用法?C++ rtc_device_register怎么用?C++ rtc_device_register使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了rtc_device_register函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: twl_rtc_probe
static int twl_rtc_probe(struct platform_device *pdev)
{
struct rtc_device *rtc;
int ret = -EINVAL;
int irq = platform_get_irq(pdev, 0);
u8 rd_reg;
if (irq <= 0)
goto out1;
ret = twl_rtc_read_u8(&rd_reg, REG_RTC_STATUS_REG);
if (ret < 0)
goto out1;
if (rd_reg & BIT_RTC_STATUS_REG_POWER_UP_M)
dev_warn(&pdev->dev, "Power up reset detected.\n");
if (rd_reg & BIT_RTC_STATUS_REG_ALARM_M)
dev_warn(&pdev->dev, "Pending Alarm interrupt detected.\n");
/* Clear RTC Power up reset and pending alarm interrupts */
ret = twl_rtc_write_u8(rd_reg, REG_RTC_STATUS_REG);
if (ret < 0)
goto out1;
if (twl_class_is_6030()) {
twl6030_interrupt_unmask(TWL6030_RTC_INT_MASK,
REG_INT_MSK_LINE_A);
twl6030_interrupt_unmask(TWL6030_RTC_INT_MASK,
REG_INT_MSK_STS_A);
}
dev_info(&pdev->dev, "Enabling TWL-RTC\n");
ret = twl_rtc_write_u8(BIT_RTC_CTRL_REG_STOP_RTC_M, REG_RTC_CTRL_REG);
if (ret < 0)
goto out1;
/* ensure interrupts are disabled, bootloaders can be strange */
ret = twl_rtc_write_u8(0, REG_RTC_INTERRUPTS_REG);
if (ret < 0)
dev_warn(&pdev->dev, "unable to disable interrupt\n");
/* init cached IRQ enable bits */
ret = twl_rtc_read_u8(&rtc_irq_bits, REG_RTC_INTERRUPTS_REG);
if (ret < 0)
goto out1;
rtc = rtc_device_register(pdev->name,
&pdev->dev, &twl_rtc_ops, THIS_MODULE);
if (IS_ERR(rtc)) {
ret = PTR_ERR(rtc);
dev_err(&pdev->dev, "can't register RTC device, err %ld\n",
PTR_ERR(rtc));
goto out1;
}
ret = request_threaded_irq(irq, NULL, twl_rtc_interrupt,
IRQF_TRIGGER_RISING | IRQF_ONESHOT,
dev_name(&rtc->dev), rtc);
if (ret < 0) {
dev_err(&pdev->dev, "IRQ is not free.\n");
goto out2;
}
platform_set_drvdata(pdev, rtc);
device_init_wakeup(&pdev->dev, 1);
return 0;
out2:
rtc_device_unregister(rtc);
out1:
return ret;
}
示例2: AMI8563_probe
static int AMI8563_probe(struct i2c_adapter *adapter, int address, int kind)
{
struct AMI8563 *pAMI8563 = NULL;
struct i2c_client *client = NULL;
struct rtc_device *rtc = NULL;
u8 value = 0;
int err = 0;
if (!i2c_check_functionality(adapter, I2C_FUNC_I2C)) {
err = -ENODEV;
goto exit;
}
if(address != AMI8563_ADDR) {
err = -EIO;
goto exit;
}
if (!(pAMI8563 = kzalloc(sizeof(struct AMI8563), GFP_KERNEL))) {
err = -ENOMEM;
goto exit;
}
pAMI8563->alarm_status_power_on = 0;
client = &pAMI8563->client;
client->addr = address;
client->driver = &AMI8563_driver;
client->adapter = adapter;
strlcpy(client->name, AMI8563_driver.driver.name, I2C_NAME_SIZE);
/* detect chip and check the alarm status*/
err = i2c_ami8563_read(client, AMI8563_REG_ST2);
if (err<0) {
goto exit_kfree;
} else if (err&0x08) {
ami8563_info("Power up as alarm on\n");
pAMI8563->alarm_status_power_on = 1;
}
value = i2c_ami8563_read(client, AMI8563_REG_YR);
ami8563_info("current year %d\n", value);
value = bcd2bin(value);
#define CURRENT_YEAR (9) // 2009
if (value>30 || value<CURRENT_YEAR) {
ami8563_err("Detect invalid year %d, reset to default\n", value+2000);
i2c_ami8563_write(client, AMI8563_REG_YR, bin2bcd(CURRENT_YEAR));
}
if ((err = i2c_attach_client(client)))
goto exit_kfree;
rtc = rtc_device_register(AMI8563_driver.driver.name, &client->dev,
&AMI8563_rtc_ops, THIS_MODULE);
if (IS_ERR(rtc)) {
err = PTR_ERR(rtc);
goto exit_detach;
}
i2c_set_clientdata(client, rtc);
g_client = client;
/*Clear AF,enable AIE*/
//micco_enable_rtc_alarm_irq(0);
value = i2c_ami8563_read(client, AMI8563_REG_ST2);
value &= ~0x1<<3;
value |= 0x1<<1;
i2c_ami8563_write(client, AMI8563_REG_ST2, value);
micco_enable_rtc_alarm_irq(1);
//err = pmic_callback_register(PMIC_EVENT_EXTON, AMI8563_alarm_event_handler);
AMI8563_sync_pxa3xx_rtc(client);
register_reboot_notifier(&ami_sys_reboot_nb); /* for enter into recovery mode */
#ifdef CONFIG_YUHUA_MISC_DEV
set_rtc_detect(1);
#endif
printk("Rtc ami8563 drv register succ\n");
return 0;
exit_detach:
i2c_detach_client(client);
exit_kfree:
kfree(pAMI8563);
exit:
ami8563_err("err %d\n", err);
return err;
}
示例3: tps65910_rtc_probe
static int tps65910_rtc_probe(struct platform_device *pdev)
{
struct tps65910 *tps65910 = dev_get_drvdata(pdev->dev.parent);
struct tps65910_rtc *tps65910_rtc;
int per_irq;
int alm_irq;
int ret = 0;
u8 rtc_ctl;
struct rtc_time tm;
struct rtc_time tm_def = { // 2012.1.1 12:00:00 Saturday
.tm_wday = 6,
.tm_year = 111,
.tm_mon = 0,
.tm_mday = 1,
.tm_hour = 12,
.tm_min = 0,
.tm_sec = 0,
};
tps65910_rtc = kzalloc(sizeof(*tps65910_rtc), GFP_KERNEL);
if (tps65910_rtc == NULL)
return -ENOMEM;
platform_set_drvdata(pdev, tps65910_rtc);
tps65910_rtc->tps65910 = tps65910;
per_irq = tps65910->irq_base + TPS65910_IRQ_RTC_PERIOD;
alm_irq = tps65910->irq_base + TPS65910_IRQ_RTC_ALARM;
/* Take rtc out of reset */
ret = tps65910_reg_read(tps65910, TPS65910_DEVCTRL);
if (ret < 0) {
dev_err(&pdev->dev, "Failed to read TPS65910_DEVCTRL: %d\n", ret);
return ret;
}
if(ret & BIT_RTC_PWDN)
{
rtc_ctl = ret & (~BIT_RTC_PWDN);
ret = tps65910_reg_write(tps65910, TPS65910_DEVCTRL, rtc_ctl);
if (ret < 0) {
dev_err(&pdev->dev, "Failed to write RTC control: %d\n", ret);
return ret;
}
}
/*start rtc default*/
ret = tps65910_reg_read(tps65910, TPS65910_RTC_CTRL);
if (ret < 0) {
dev_err(&pdev->dev, "Failed to read RTC control: %d\n", ret);
return ret;
}
if(!(ret & BIT_RTC_CTRL_REG_STOP_RTC_M))
{
rtc_ctl = ret | BIT_RTC_CTRL_REG_STOP_RTC_M;
ret = tps65910_reg_write(tps65910, TPS65910_RTC_CTRL, rtc_ctl);
if (ret < 0) {
dev_err(&pdev->dev, "Failed to write RTC control: %d\n", ret);
return ret;
}
}
ret = tps65910_reg_read(tps65910, TPS65910_RTC_STATUS);
if (ret < 0) {
dev_err(&pdev->dev, "Failed to read RTC status: %d\n", ret);
return ret;
}
/*set init time*/
ret = tps65910_rtc_readtime(&pdev->dev, &tm);
if (ret)
{
dev_err(&pdev->dev, "Failed to read RTC time\n");
return ret;
}
ret = rtc_valid_tm(&tm);
if (ret) {
dev_err(&pdev->dev,"invalid date/time and init time\n");
tps65910_rtc_set_time(&pdev->dev, &tm_def); // 2011-01-01 12:00:00
dev_info(&pdev->dev, "set RTC date/time %4d-%02d-%02d(%d) %02d:%02d:%02d\n",
1900 + tm_def.tm_year, tm_def.tm_mon + 1, tm_def.tm_mday, tm_def.tm_wday,
tm_def.tm_hour, tm_def.tm_min, tm_def.tm_sec);
}
device_init_wakeup(&pdev->dev, 1);
tps65910_rtc->rtc = rtc_device_register("tps65910", &pdev->dev,
&tps65910_rtc_ops, THIS_MODULE);
if (IS_ERR(tps65910_rtc->rtc)) {
ret = PTR_ERR(tps65910_rtc->rtc);
goto err;
}
/*request rtc and alarm irq of tps65910*/
ret = request_threaded_irq(per_irq, NULL, tps65910_per_irq,
IRQF_TRIGGER_RISING, "RTC period",
//.........这里部分代码省略.........
示例4: s2mps11_rtc_probe
static int __devinit s2mps11_rtc_probe(struct platform_device *pdev)
{
struct sec_pmic_dev *iodev = dev_get_drvdata(pdev->dev.parent);
struct sec_pmic_platform_data *pdata = dev_get_platdata(iodev->dev);
struct s2mps11_rtc_info *s2mps11;
int ret;
s2mps11 = devm_kzalloc(&pdev->dev, sizeof(struct s2mps11_rtc_info),
GFP_KERNEL);
if (!s2mps11)
return -ENOMEM;
s2mps11->dev = &pdev->dev;
s2mps11->iodev = iodev;
s2mps11->wtsr_smpl = pdata->wtsr_smpl;
s2mps11->jig_smpl_disable = pdata->jig_smpl_disable;
s2mps11->irq = pdata->irq_base + S2MPS11_IRQ_RTCA0;
platform_set_drvdata(pdev, s2mps11);
ret = s2mps11_rtc_init_reg(s2mps11);
if (ret < 0) {
dev_err(&pdev->dev, "Failed to initialize RTC reg:%d\n", ret);
goto out_rtc;
}
pmic_is_jig_attached = s2mps11_rtc_is_jigonb_low(s2mps11);
if (s2mps11->jig_smpl_disable && pmic_is_jig_attached)
s2mps11->wtsr_smpl = false;
if (s2mps11->wtsr_smpl) {
s2mps11_rtc_enable_wtsr(s2mps11, true);
s2mps11_rtc_enable_smpl(s2mps11, true);
} else {
s2mps11_rtc_enable_wtsr(s2mps11, false);
s2mps11_rtc_enable_smpl(s2mps11, false);
}
device_init_wakeup(&pdev->dev, true);
s2mps11->rtc_dev = rtc_device_register("s2mps11-rtc", &pdev->dev,
&s2mps11_rtc_ops, THIS_MODULE);
if (IS_ERR(s2mps11->rtc_dev)) {
ret = PTR_ERR(s2mps11->rtc_dev);
dev_err(&pdev->dev, "Failed to register RTC device: %d\n", ret);
goto out_rtc;
}
ret = request_threaded_irq(s2mps11->irq, NULL, s2mps11_rtc_alarm_irq, 0,
"rtc-alarm0", s2mps11);
if (ret < 0)
dev_err(&pdev->dev, "Failed to request alarm IRQ: %d: %d\n",
s2mps11->irq, ret);
return 0;
out_rtc:
devm_kfree(&pdev->dev, s2mps11);
platform_set_drvdata(pdev, NULL);
return ret;
}
示例5: rs5c348_probe
static int __devinit rs5c348_probe(struct spi_device *spi)
{
int ret;
struct rtc_device *rtc;
struct rs5c348_plat_data *pdata;
pdata = kzalloc(sizeof(struct rs5c348_plat_data), GFP_KERNEL);
if (!pdata)
return -ENOMEM;
spi->dev.platform_data = pdata;
/* Check D7 of SECOND register */
ret = spi_w8r8(spi, RS5C348_CMD_R(RS5C348_REG_SECS));
if (ret < 0 || (ret & 0x80)) {
dev_err(&spi->dev, "not found.\n");
goto kfree_exit;
}
dev_info(&spi->dev, "chip found, driver version " DRV_VERSION "\n");
dev_info(&spi->dev, "spiclk %u KHz.\n",
(spi->max_speed_hz + 500) / 1000);
/* turn RTC on if it was not on */
ret = spi_w8r8(spi, RS5C348_CMD_R(RS5C348_REG_CTL2));
if (ret < 0)
goto kfree_exit;
if (ret & (RS5C348_BIT_XSTP | RS5C348_BIT_VDET)) {
u8 buf[2];
struct rtc_time tm;
if (ret & RS5C348_BIT_VDET)
dev_warn(&spi->dev, "voltage-low detected.\n");
if (ret & RS5C348_BIT_XSTP)
dev_warn(&spi->dev, "oscillator-stop detected.\n");
rtc_time_to_tm(0, &tm); /* 1970/1/1 */
ret = rs5c348_rtc_set_time(&spi->dev, &tm);
if (ret < 0)
goto kfree_exit;
buf[0] = RS5C348_CMD_W(RS5C348_REG_CTL2);
buf[1] = 0;
ret = spi_write_then_read(spi, buf, sizeof(buf), NULL, 0);
if (ret < 0)
goto kfree_exit;
}
ret = spi_w8r8(spi, RS5C348_CMD_R(RS5C348_REG_CTL1));
if (ret < 0)
goto kfree_exit;
if (ret & RS5C348_BIT_24H)
pdata->rtc_24h = 1;
rtc = rtc_device_register(rs5c348_driver.driver.name, &spi->dev,
&rs5c348_rtc_ops, THIS_MODULE);
if (IS_ERR(rtc)) {
ret = PTR_ERR(rtc);
goto kfree_exit;
}
pdata->rtc = rtc;
return 0;
kfree_exit:
kfree(pdata);
return ret;
}
示例6: vrtc_mrst_do_probe
static int __devinit
vrtc_mrst_do_probe(struct device *dev, struct resource *iomem, int rtc_irq)
{
int retval = 0;
unsigned char rtc_control;
/* There can be only one ... */
if (mrst_rtc.dev)
return -EBUSY;
if (!iomem)
return -ENODEV;
iomem = request_mem_region(iomem->start, resource_size(iomem),
driver_name);
if (!iomem) {
dev_dbg(dev, "i/o mem already in use.\n");
return -EBUSY;
}
mrst_rtc.irq = rtc_irq;
mrst_rtc.iomem = iomem;
mrst_rtc.dev = dev;
dev_set_drvdata(dev, &mrst_rtc);
mrst_rtc.rtc = rtc_device_register(driver_name, dev,
&mrst_rtc_ops, THIS_MODULE);
if (IS_ERR(mrst_rtc.rtc)) {
retval = PTR_ERR(mrst_rtc.rtc);
goto cleanup0;
}
rename_region(iomem, dev_name(&mrst_rtc.rtc->dev));
spin_lock_irq(&rtc_lock);
mrst_irq_disable(&mrst_rtc, RTC_PIE | RTC_AIE);
rtc_control = vrtc_cmos_read(RTC_CONTROL);
spin_unlock_irq(&rtc_lock);
if (!(rtc_control & RTC_24H) || (rtc_control & (RTC_DM_BINARY)))
dev_dbg(dev, "TODO: support more than 24-hr BCD mode\n");
if (rtc_irq) {
retval = request_irq(rtc_irq, mrst_rtc_irq,
IRQF_DISABLED, dev_name(&mrst_rtc.rtc->dev),
mrst_rtc.rtc);
if (retval < 0) {
dev_dbg(dev, "IRQ %d is already in use, err %d\n",
rtc_irq, retval);
goto cleanup1;
}
}
dev_dbg(dev, "initialised\n");
return 0;
cleanup1:
rtc_device_unregister(mrst_rtc.rtc);
cleanup0:
dev_set_drvdata(dev, NULL);
mrst_rtc.dev = NULL;
release_mem_region(iomem->start, resource_size(iomem));
dev_err(dev, "rtc-mrst: unable to initialise\n");
return retval;
}
示例7: twl4030_rtc_probe
static int __devinit twl4030_rtc_probe(struct platform_device *pdev)
{
struct rtc_device *rtc;
int ret = 0;
int irq = platform_get_irq(pdev, 0);
u8 rd_reg;
if (irq < 0)
return irq;
rtc = rtc_device_register(pdev->name,
&pdev->dev, &twl4030_rtc_ops, THIS_MODULE);
if (IS_ERR(rtc)) {
ret = -EINVAL;
dev_err(&pdev->dev, "can't register RTC device, err %ld\n",
PTR_ERR(rtc));
goto out0;
}
platform_set_drvdata(pdev, rtc);
ret = twl4030_rtc_read_u8(&rd_reg, REG_RTC_STATUS_REG);
if (ret < 0)
goto out1;
if (rd_reg & BIT_RTC_STATUS_REG_POWER_UP_M)
dev_warn(&pdev->dev, "Power up reset detected.\n");
if (rd_reg & BIT_RTC_STATUS_REG_ALARM_M)
dev_warn(&pdev->dev, "Pending Alarm interrupt detected.\n");
/* Clear RTC Power up reset and pending alarm interrupts */
ret = twl4030_rtc_write_u8(rd_reg, REG_RTC_STATUS_REG);
if (ret < 0)
goto out1;
ret = request_irq(irq, twl4030_rtc_interrupt,
IRQF_TRIGGER_RISING,
rtc->dev.bus_id, rtc);
if (ret < 0) {
dev_err(&pdev->dev, "IRQ is not free.\n");
goto out1;
}
/* Check RTC module status, Enable if it is off */
ret = twl4030_rtc_read_u8(&rd_reg, REG_RTC_CTRL_REG);
if (ret < 0)
goto out2;
if (!(rd_reg & BIT_RTC_CTRL_REG_STOP_RTC_M)) {
dev_info(&pdev->dev, "Enabling TWL4030-RTC.\n");
rd_reg = BIT_RTC_CTRL_REG_STOP_RTC_M;
ret = twl4030_rtc_write_u8(rd_reg, REG_RTC_CTRL_REG);
if (ret < 0)
goto out2;
}
/* init cached IRQ enable bits */
ret = twl4030_rtc_read_u8(&rtc_irq_bits, REG_RTC_INTERRUPTS_REG);
if (ret < 0)
goto out2;
return ret;
out2:
free_irq(irq, rtc);
out1:
rtc_device_unregister(rtc);
out0:
return ret;
}
示例8: s3c_rtc_probe
static int __devinit s3c_rtc_probe(struct platform_device *pdev)
{
struct rtc_device *rtc;
struct rtc_time rtc_tm;
struct resource *res;
int ret;
int tmp;
pr_debug("%s: probe=%p\n", __func__, pdev);
s3c_rtc_tickno = platform_get_irq(pdev, 1);
if (s3c_rtc_tickno < 0) {
dev_err(&pdev->dev, "no irq for rtc tick\n");
return -ENOENT;
}
s3c_rtc_alarmno = platform_get_irq(pdev, 0);
if (s3c_rtc_alarmno < 0) {
dev_err(&pdev->dev, "no irq for alarm\n");
return -ENOENT;
}
pr_debug("s3c2410_rtc: tick irq %d, alarm irq %d\n",
s3c_rtc_tickno, s3c_rtc_alarmno);
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
if (res == NULL) {
dev_err(&pdev->dev, "failed to get memory region resource\n");
return -ENOENT;
}
s3c_rtc_mem = request_mem_region(res->start, resource_size(res),
pdev->name);
if (s3c_rtc_mem == NULL) {
dev_err(&pdev->dev, "failed to reserve memory region\n");
ret = -ENOENT;
goto err_nores;
}
s3c_rtc_base = ioremap(res->start, resource_size(res));
if (s3c_rtc_base == NULL) {
dev_err(&pdev->dev, "failed ioremap()\n");
ret = -EINVAL;
goto err_nomap;
}
rtc_clk = clk_get(&pdev->dev, "rtc");
if (IS_ERR(rtc_clk)) {
dev_err(&pdev->dev, "failed to find rtc clock source\n");
ret = PTR_ERR(rtc_clk);
rtc_clk = NULL;
goto err_clk;
}
clk_enable(rtc_clk);
s3c_rtc_enable(pdev, 1);
pr_debug("s3c2410_rtc: RTCCON=%02x\n",
readw(s3c_rtc_base + S3C2410_RTCCON));
device_init_wakeup(&pdev->dev, 1);
rtc = rtc_device_register("s3c", &pdev->dev, &s3c_rtcops,
THIS_MODULE);
if (IS_ERR(rtc)) {
dev_err(&pdev->dev, "cannot attach rtc\n");
ret = PTR_ERR(rtc);
goto err_nortc;
}
s3c_rtc_cpu_type = s3c_rtc_get_driver_data(pdev);
s3c_rtc_gettime(NULL, &rtc_tm);
if (rtc_valid_tm(&rtc_tm)) {
rtc_tm.tm_year = 100;
rtc_tm.tm_mon = 0;
rtc_tm.tm_mday = 1;
rtc_tm.tm_hour = 0;
rtc_tm.tm_min = 0;
rtc_tm.tm_sec = 0;
s3c_rtc_settime(NULL, &rtc_tm);
dev_warn(&pdev->dev, "warning: invalid RTC value so initializing it\n");
}
//.........这里部分代码省略.........
示例9: s3c_rtc_probe
static int __devinit s3c_rtc_probe(struct platform_device *pdev)
{
struct rtc_device *rtc;
struct rtc_time rtc_tm;
struct resource *res;
int ret;
pr_debug("%s: probe=%p\n", __func__, pdev);
/* find the IRQs */
s3c_rtc_tickno = platform_get_irq(pdev, 1);
if (s3c_rtc_tickno < 0) {
dev_err(&pdev->dev, "no irq for rtc tick\n");
return -ENOENT;
}
s3c_rtc_alarmno = platform_get_irq(pdev, 0);
if (s3c_rtc_alarmno < 0) {
dev_err(&pdev->dev, "no irq for alarm\n");
return -ENOENT;
}
pr_debug("s3c2410_rtc: tick irq %d, alarm irq %d\n",
s3c_rtc_tickno, s3c_rtc_alarmno);
/* get the memory region */
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
if (res == NULL) {
dev_err(&pdev->dev, "failed to get memory region resource\n");
return -ENOENT;
}
s3c_rtc_mem = request_mem_region(res->start,
res->end-res->start+1,
pdev->name);
if (s3c_rtc_mem == NULL) {
dev_err(&pdev->dev, "failed to reserve memory region\n");
ret = -ENOENT;
goto err_nores;
}
s3c_rtc_base = ioremap(res->start, res->end - res->start + 1);
if (s3c_rtc_base == NULL) {
dev_err(&pdev->dev, "failed ioremap()\n");
ret = -EINVAL;
goto err_nomap;
}
rtc_clk = clk_get(&pdev->dev, "rtc");
if (IS_ERR(rtc_clk)) {
dev_err(&pdev->dev, "failed to find rtc clock source\n");
ret = PTR_ERR(rtc_clk);
rtc_clk = NULL;
goto err_clk;
}
clk_enable(rtc_clk);
/* check to see if everything is setup correctly */
s3c_rtc_enable(pdev, 1);
pr_debug("s3c2410_rtc: RTCCON=%02x\n",
readw(s3c_rtc_base + S3C2410_RTCCON));
device_init_wakeup(&pdev->dev, 1);
/* register RTC and exit */
rtc = rtc_device_register("s3c", &pdev->dev, &s3c_rtcops,
THIS_MODULE);
if (IS_ERR(rtc)) {
dev_err(&pdev->dev, "cannot attach rtc\n");
ret = PTR_ERR(rtc);
goto err_nortc;
}
s3c_rtc_cpu_type = platform_get_device_id(pdev)->driver_data;
/* Check RTC Time */
s3c_rtc_gettime(NULL, &rtc_tm);
if (rtc_valid_tm(&rtc_tm)) {
rtc_tm.tm_year = 100;
rtc_tm.tm_mon = 0;
rtc_tm.tm_mday = 1;
rtc_tm.tm_hour = 0;
rtc_tm.tm_min = 0;
rtc_tm.tm_sec = 0;
s3c_rtc_settime(NULL, &rtc_tm);
dev_warn(&pdev->dev, "warning: invalid RTC value so initializing it\n");
}
//.........这里部分代码省略.........
示例10: stk17ta8_rtc_probe
static int __init stk17ta8_rtc_probe(struct platform_device *pdev)
{
struct rtc_device *rtc;
struct resource *res;
unsigned int cal;
unsigned int flags;
struct rtc_plat_data *pdata;
void __iomem *ioaddr = NULL;
int ret = 0;
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
if (!res)
return -ENODEV;
pdata = kzalloc(sizeof(*pdata), GFP_KERNEL);
if (!pdata)
return -ENOMEM;
pdata->irq = -1;
if (!request_mem_region(res->start, RTC_REG_SIZE, pdev->name)) {
ret = -EBUSY;
goto out;
}
pdata->baseaddr = res->start;
ioaddr = ioremap(pdata->baseaddr, RTC_REG_SIZE);
if (!ioaddr) {
ret = -ENOMEM;
goto out;
}
pdata->ioaddr = ioaddr;
pdata->irq = platform_get_irq(pdev, 0);
/* turn RTC on if it was not on */
cal = readb(ioaddr + RTC_CALIBRATION);
if (cal & RTC_STOP) {
cal &= RTC_CAL_MASK;
flags = readb(ioaddr + RTC_FLAGS);
writeb(flags | RTC_WRITE, ioaddr + RTC_FLAGS);
writeb(cal, ioaddr + RTC_CALIBRATION);
writeb(flags & ~RTC_WRITE, ioaddr + RTC_FLAGS);
}
if (readb(ioaddr + RTC_FLAGS) & RTC_FLAGS_PF)
dev_warn(&pdev->dev, "voltage-low detected.\n");
if (pdata->irq >= 0) {
writeb(0, ioaddr + RTC_INTERRUPTS);
if (request_irq(pdata->irq, stk17ta8_rtc_interrupt,
IRQF_DISABLED | IRQF_SHARED,
pdev->name, pdev) < 0) {
dev_warn(&pdev->dev, "interrupt not available.\n");
pdata->irq = -1;
}
}
rtc = rtc_device_register(pdev->name, &pdev->dev,
&stk17ta8_rtc_ops, THIS_MODULE);
if (IS_ERR(rtc)) {
ret = PTR_ERR(rtc);
goto out;
}
pdata->rtc = rtc;
pdata->last_jiffies = jiffies;
platform_set_drvdata(pdev, pdata);
ret = sysfs_create_bin_file(&pdev->dev.kobj, &stk17ta8_nvram_attr);
if (ret)
goto out;
return 0;
out:
if (pdata->rtc)
rtc_device_unregister(pdata->rtc);
if (pdata->irq >= 0)
free_irq(pdata->irq, pdev);
if (ioaddr)
iounmap(ioaddr);
if (pdata->baseaddr)
release_mem_region(pdata->baseaddr, RTC_REG_SIZE);
kfree(pdata);
return ret;
}
示例11: ds1511_rtc_probe
static int ds1511_rtc_probe(struct platform_device *pdev)
{
struct rtc_device *rtc;
struct resource *res;
struct rtc_plat_data *pdata;
int ret = 0;
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
if (!res) {
return -ENODEV;
}
pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL);
if (!pdata)
return -ENOMEM;
pdata->size = resource_size(res);
if (!devm_request_mem_region(&pdev->dev, res->start, pdata->size,
pdev->name))
return -EBUSY;
ds1511_base = devm_ioremap(&pdev->dev, res->start, pdata->size);
if (!ds1511_base)
return -ENOMEM;
pdata->ioaddr = ds1511_base;
pdata->irq = platform_get_irq(pdev, 0);
/*
* turn on the clock and the crystal, etc.
*/
rtc_write(0, RTC_CMD);
rtc_write(0, RTC_CMD1);
/*
* clear the wdog counter
*/
rtc_write(0, DS1511_WD_MSEC);
rtc_write(0, DS1511_WD_SEC);
/*
* start the clock
*/
rtc_enable_update();
/*
* check for a dying bat-tree
*/
if (rtc_read(RTC_CMD1) & DS1511_BLF1) {
dev_warn(&pdev->dev, "voltage-low detected.\n");
}
spin_lock_init(&pdata->lock);
platform_set_drvdata(pdev, pdata);
/*
* if the platform has an interrupt in mind for this device,
* then by all means, set it
*/
if (pdata->irq > 0) {
rtc_read(RTC_CMD1);
if (devm_request_irq(&pdev->dev, pdata->irq, ds1511_interrupt,
IRQF_SHARED, pdev->name, pdev) < 0) {
dev_warn(&pdev->dev, "interrupt not available.\n");
pdata->irq = 0;
}
}
rtc = rtc_device_register(pdev->name, &pdev->dev, &ds1511_rtc_ops,
THIS_MODULE);
if (IS_ERR(rtc))
return PTR_ERR(rtc);
pdata->rtc = rtc;
ret = sysfs_create_bin_file(&pdev->dev.kobj, &ds1511_nvram_attr);
if (ret)
rtc_device_unregister(pdata->rtc);
return ret;
}
示例12: jz4740_rtc_probe
static int __devinit jz4740_rtc_probe(struct platform_device *pdev)
{
int ret;
struct jz4740_rtc *rtc;
uint32_t scratchpad;
rtc = kzalloc(sizeof(*rtc), GFP_KERNEL);
if (!rtc)
return -ENOMEM;
rtc->irq = platform_get_irq(pdev, 0);
if (rtc->irq < 0) {
ret = -ENOENT;
dev_err(&pdev->dev, "Failed to get platform irq\n");
goto err_free;
}
rtc->mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
if (!rtc->mem) {
ret = -ENOENT;
dev_err(&pdev->dev, "Failed to get platform mmio memory\n");
goto err_free;
}
rtc->mem = request_mem_region(rtc->mem->start, resource_size(rtc->mem),
pdev->name);
if (!rtc->mem) {
ret = -EBUSY;
dev_err(&pdev->dev, "Failed to request mmio memory region\n");
goto err_free;
}
rtc->base = ioremap_nocache(rtc->mem->start, resource_size(rtc->mem));
if (!rtc->base) {
ret = -EBUSY;
dev_err(&pdev->dev, "Failed to ioremap mmio memory\n");
goto err_release_mem_region;
}
spin_lock_init(&rtc->lock);
platform_set_drvdata(pdev, rtc);
device_init_wakeup(&pdev->dev, 1);
rtc->rtc = rtc_device_register(pdev->name, &pdev->dev, &jz4740_rtc_ops,
THIS_MODULE);
if (IS_ERR(rtc->rtc)) {
ret = PTR_ERR(rtc->rtc);
dev_err(&pdev->dev, "Failed to register rtc device: %d\n", ret);
goto err_iounmap;
}
ret = request_irq(rtc->irq, jz4740_rtc_irq, 0,
pdev->name, rtc);
if (ret) {
dev_err(&pdev->dev, "Failed to request rtc irq: %d\n", ret);
goto err_unregister_rtc;
}
scratchpad = jz4740_rtc_reg_read(rtc, JZ_REG_RTC_SCRATCHPAD);
if (scratchpad != 0x12345678) {
ret = jz4740_rtc_reg_write(rtc, JZ_REG_RTC_SCRATCHPAD, 0x12345678);
ret = jz4740_rtc_reg_write(rtc, JZ_REG_RTC_SEC, 0);
if (ret) {
dev_err(&pdev->dev, "Could not write write to RTC registers\n");
goto err_free_irq;
}
}
return 0;
err_free_irq:
free_irq(rtc->irq, rtc);
err_unregister_rtc:
rtc_device_unregister(rtc->rtc);
err_iounmap:
platform_set_drvdata(pdev, NULL);
iounmap(rtc->base);
err_release_mem_region:
release_mem_region(rtc->mem->start, resource_size(rtc->mem));
err_free:
kfree(rtc);
return ret;
}
示例13: mc13xxx_rtc_probe
static int __init mc13xxx_rtc_probe(struct platform_device *pdev)
{
int ret;
struct mc13xxx_rtc *priv;
struct mc13xxx *mc13xxx;
int rtcrst_pending;
priv = kzalloc(sizeof(*priv), GFP_KERNEL);
if (!priv)
return -ENOMEM;
mc13xxx = dev_get_drvdata(pdev->dev.parent);
priv->mc13xxx = mc13xxx;
platform_set_drvdata(pdev, priv);
mc13xxx_lock(mc13xxx);
ret = mc13xxx_irq_request(mc13xxx, MC13XXX_IRQ_RTCRST,
mc13xxx_rtc_reset_handler, DRIVER_NAME, priv);
if (ret)
goto err_reset_irq_request;
ret = mc13xxx_irq_status(mc13xxx, MC13XXX_IRQ_RTCRST,
NULL, &rtcrst_pending);
if (ret)
goto err_reset_irq_status;
priv->valid = !rtcrst_pending;
ret = mc13xxx_irq_request_nounmask(mc13xxx, MC13XXX_IRQ_1HZ,
mc13xxx_rtc_update_handler, DRIVER_NAME, priv);
if (ret)
goto err_update_irq_request;
ret = mc13xxx_irq_request_nounmask(mc13xxx, MC13XXX_IRQ_TODA,
mc13xxx_rtc_alarm_handler, DRIVER_NAME, priv);
if (ret)
goto err_alarm_irq_request;
mc13xxx_unlock(mc13xxx);
priv->rtc = rtc_device_register(pdev->name,
&pdev->dev, &mc13xxx_rtc_ops, THIS_MODULE);
if (IS_ERR(priv->rtc)) {
ret = PTR_ERR(priv->rtc);
mc13xxx_lock(mc13xxx);
mc13xxx_irq_free(mc13xxx, MC13XXX_IRQ_TODA, priv);
err_alarm_irq_request:
mc13xxx_irq_free(mc13xxx, MC13XXX_IRQ_1HZ, priv);
err_update_irq_request:
err_reset_irq_status:
mc13xxx_irq_free(mc13xxx, MC13XXX_IRQ_RTCRST, priv);
err_reset_irq_request:
mc13xxx_unlock(mc13xxx);
platform_set_drvdata(pdev, NULL);
kfree(priv);
}
return ret;
}
示例14: tps6591x_rtc_probe
static int tps6591x_rtc_probe(struct platform_device *pdev)
{
struct tps6591x_rtc_platform_data *pdata = pdev->dev.platform_data;
struct tps6591x_rtc *rtc;
struct rtc_time tm;
int err;
u8 reg;
rtc = kzalloc(sizeof(*rtc), GFP_KERNEL);
if (!rtc)
return -ENOMEM;
rtc->irq = -1;
if (!pdata) {
dev_err(&pdev->dev, "no platform_data specified\n");
return -EINVAL;
}
if (pdata->irq < 0)
dev_err(&pdev->dev, "\n no IRQ specified, wakeup is disabled\n");
dev_set_drvdata(&pdev->dev, rtc);
device_init_wakeup(&pdev->dev, 1);
rtc->rtc = rtc_device_register(pdev->name, &pdev->dev,
&tps6591x_rtc_ops, THIS_MODULE);
if (IS_ERR(rtc->rtc)) {
err = PTR_ERR(rtc->rtc);
goto fail;
}
if ((int)pdev && (int)&pdev->dev)
err = tps6591x_read_regs(&pdev->dev, RTC_STATUS, 1, ®);
else {
dev_err(&pdev->dev, "\n %s Input params incorrect\n", __func__);
return -EBUSY;
}
if (err) {
dev_err(&pdev->dev, "\n %s unable to read status\n", __func__);
return -EBUSY;
}
reg = RTC_BBCH_SEL | RTC_BBCH_EN;
tps6591x_write_regs(&pdev->dev, RTC_BBCH_REG, 1, ®);
if (err) {
dev_err(&pdev->dev, "unable to program Charger reg\n");
return -EBUSY;
}
err = tps6591x_rtc_start(&pdev->dev);
if (err) {
dev_err(&pdev->dev, "unable to start RTC\n");
return -EBUSY;
}
tps6591x_rtc_read_time(&pdev->dev, &tm);
if (tps6591x_rtc_valid_tm(&tm) < 0) {
if (pdata->time.tm_year < 2000 || pdata->time.tm_year >= 2100) {
memset(&pdata->time, 0, sizeof(pdata->time));
pdata->time.tm_year = 2000;
pdata->time.tm_mday = 1;
}
pdata->time.tm_year -= OS_REF_YEAR;
tps6591x_rtc_set_time(&pdev->dev, &pdata->time);
}
reg = ALARM_INT_STATUS;
err = tps6591x_write_regs(&pdev->dev, RTC_STATUS, 1, ®);
if (err) {
dev_err(&pdev->dev, "unable to program RTC_STATUS reg\n");
return -EBUSY;
}
reg = ENABLE_ALARM_INT;
tps6591x_write_regs(&pdev->dev, RTC_INT, 1, ®);
if (err) {
dev_err(&pdev->dev, "unable to program Interrupt Mask reg\n");
return -EBUSY;
}
if (pdata && (pdata->irq >= 0)) {
rtc->irq = pdata->irq;
err = request_threaded_irq(pdata->irq, NULL, tps6591x_rtc_irq,
IRQF_ONESHOT, "rtc_tps6591x",
&pdev->dev);
if (err) {
dev_err(&pdev->dev, "request IRQ:%d fail\n", rtc->irq);
rtc->irq = -1;
} else {
device_init_wakeup(&pdev->dev, 1);
enable_irq_wake(rtc->irq);
}
}
return 0;
fail:
if (!IS_ERR_OR_NULL(rtc->rtc))
//.........这里部分代码省略.........
示例15: m48t59_rtc_probe
static int __devinit m48t59_rtc_probe(struct platform_device *pdev)
{
struct m48t59_plat_data *pdata = pdev->dev.platform_data;
struct m48t59_private *m48t59 = NULL;
struct resource *res;
int ret = -ENOMEM;
char *name;
const struct rtc_class_ops *ops;
/* This chip could be memory-mapped or I/O-mapped */
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
if (!res) {
res = platform_get_resource(pdev, IORESOURCE_IO, 0);
if (!res)
return -EINVAL;
}
if (res->flags & IORESOURCE_IO) {
/* If we are I/O-mapped, the platform should provide
* the operations accessing chip registers.
*/
if (!pdata || !pdata->write_byte || !pdata->read_byte)
return -EINVAL;
} else if (res->flags & IORESOURCE_MEM) {
/* we are memory-mapped */
if (!pdata) {
pdata = kzalloc(sizeof(*pdata), GFP_KERNEL);
if (!pdata)
return -ENOMEM;
/* Ensure we only kmalloc platform data once */
pdev->dev.platform_data = pdata;
}
if (!pdata->type)
pdata->type = M48T59RTC_TYPE_M48T59;
/* Try to use the generic memory read/write ops */
if (!pdata->write_byte)
pdata->write_byte = m48t59_mem_writeb;
if (!pdata->read_byte)
pdata->read_byte = m48t59_mem_readb;
}
m48t59 = kzalloc(sizeof(*m48t59), GFP_KERNEL);
if (!m48t59)
return -ENOMEM;
m48t59->ioaddr = pdata->ioaddr;
if (!m48t59->ioaddr) {
/* ioaddr not mapped externally */
m48t59->ioaddr = ioremap(res->start, res->end - res->start + 1);
if (!m48t59->ioaddr)
goto out;
}
/* Try to get irq number. We also can work in
* the mode without IRQ.
*/
m48t59->irq = platform_get_irq(pdev, 0);
if (m48t59->irq <= 0)
m48t59->irq = NO_IRQ;
if (m48t59->irq != NO_IRQ) {
ret = request_irq(m48t59->irq, m48t59_rtc_interrupt,
IRQF_SHARED, "rtc-m48t59", &pdev->dev);
if (ret)
goto out;
}
switch (pdata->type) {
case M48T59RTC_TYPE_M48T59:
name = "m48t59";
ops = &m48t59_rtc_ops;
pdata->offset = 0x1ff0;
break;
case M48T59RTC_TYPE_M48T02:
name = "m48t02";
ops = &m48t02_rtc_ops;
pdata->offset = 0x7f0;
break;
case M48T59RTC_TYPE_M48T08:
name = "m48t08";
ops = &m48t02_rtc_ops;
pdata->offset = 0x1ff0;
break;
default:
dev_err(&pdev->dev, "Unknown RTC type\n");
ret = -ENODEV;
goto out;
}
m48t59->rtc = rtc_device_register(name, &pdev->dev, ops, THIS_MODULE);
if (IS_ERR(m48t59->rtc)) {
ret = PTR_ERR(m48t59->rtc);
goto out;
}
m48t59_nvram_attr.size = pdata->offset;
ret = sysfs_create_bin_file(&pdev->dev.kobj, &m48t59_nvram_attr);
if (ret)
//.........这里部分代码省略.........