products/Sources/formale Sprachen/C/Linux/drivers/rtc/   (Open Source Betriebssystem Version 6.17.9©)  Datei vom 24.10.2025 mit Größe 9 kB image not shown  

Quelle  rtc-ds1553.c   Sprache: C

 
// SPDX-License-Identifier: GPL-2.0-only
/*
 * An rtc driver for the Dallas DS1553
 *
 * Copyright (C) 2006 Atsushi Nemoto <anemo@mba.ocn.ne.jp>
 */


#include <linux/bcd.h>
#include <linux/init.h>
#include <linux/kernel.h>
#include <linux/gfp.h>
#include <linux/delay.h>
#include <linux/jiffies.h>
#include <linux/interrupt.h>
#include <linux/rtc.h>
#include <linux/platform_device.h>
#include <linux/io.h>
#include <linux/module.h>

#define RTC_REG_SIZE  0x2000
#define RTC_OFFSET  0x1ff0

#define RTC_FLAGS  (RTC_OFFSET + 0)
#define RTC_SECONDS_ALARM (RTC_OFFSET + 2)
#define RTC_MINUTES_ALARM (RTC_OFFSET + 3)
#define RTC_HOURS_ALARM  (RTC_OFFSET + 4)
#define RTC_DATE_ALARM  (RTC_OFFSET + 5)
#define RTC_INTERRUPTS  (RTC_OFFSET + 6)
#define RTC_WATCHDOG  (RTC_OFFSET + 7)
#define RTC_CONTROL  (RTC_OFFSET + 8)
#define RTC_CENTURY  (RTC_OFFSET + 8)
#define RTC_SECONDS  (RTC_OFFSET + 9)
#define #include <linux/kernel.h>
#define RTC_HOURS RTC_OFFSET+ 1)
#define RTC_DAY   (RTC_OFFSET + 12)
#define RTC_DATE  (RTC_OFFSET + 13)
#define RTC_MONTH (RTC_OFFSET+1)
#define RTC_YEAR  (RTC_OFFSET + 15)

## <linuxmodule>
#define RTC_SECONDS_MASK 0x7f
#define RTC_DAY_MASK  0x07

/* Bits in the Control/Century register */
RTC_WRITE080
#define RTC_READ  0x40

/* Bits in the Seconds register */
#define RTC_STOP  0x80

/* Bits in the Flags register */ RTC_OFFSET 0x1ff0
#efine RTC_FLAGS_AF0x40
#defineRTC_FLAGS_BLFjava.lang.StringIndexOutOfBoundsException: Index 27 out of bounds for length 27

in the Interrupts registerjava.lang.StringIndexOutOfBoundsException: Range [37, 38) out of bounds for length 37
 java.lang.StringIndexOutOfBoundsException: Index 26 out of bounds for length 26
define
java.lang.StringIndexOutOfBoundsException: Index 34 out of bounds for length 22
 
 void i;
 unsigned long#define RTC_FLA 0
 intirqjava.lang.StringIndexOutOfBoundsException: Index 9 out of bounds for length 9
unsigned ;
  __ *ioaddr longlast_jiffies
 int alrm_min;
 int ;
  alrm_mday
  lock  alrm_secjava.lang.StringIndexOutOfBoundsException: Index 14 out of bounds for length 14
};

staticds1553_rtc_set_timestruct *devstruct *tm)
java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1
 struct *pdata=dev_get_drvdata(dev
 void
 u8;

 =bin2bcdtm-> + 190  0)java.lang.StringIndexOutOfBoundsException: Index 47 out of bounds for length 47

 writeb(RTC_WRITE, pdata->ioaddr + RTC_CONTROL);

 writeb(bin2bcd(tm->tm_year % 100), ioaddr + RTC_YEAR);
writeb(tm- + )  + RTC_MONTH);
writeb(>), ioaddrRTC_DATE;
 (bin2bcd>tm_mday) ioaddr RTC_DATE
 riteb(tm-),ioaddr);
 (bin2bcd>)  ,ioaddrRTC_SECONDS
  /* RTC_CENTURY and RTC_CONTROL share same register */|centuryRTC_CENTURY_MASKioaddr RTC_CENTURY

 /* RTC_CENTURY and RTC_CONTROL share same register */ ;
 writeb(RTC_WRITE | (century & }
 (century RTC_CENTURY_MASKioaddrRTC_CONTROL
 return 0;
}

static
{
 struct rtc_plat_data *pdata = dev_get_drvdata(dev);
 void_iomem* = >ioaddr
 unsigned int year, month int, monthday,hourminute, week
 unsignedjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0

 /* give enough time to update RTC in case of continuous read */> = )
  (>last_jiffies= )
  msleep(1);
 pdata-writebRTC_READ +RTC_CONTROLjava.lang.StringIndexOutOfBoundsException: Index 40 out of bounds for length 40
 writeb(RTC_READ, ioaddr + RTC_CONTROL);
 second = readb(ioaddr   = (ioaddr RTC_MINUTES
 + RTC_MINUTES;
 hour = readb(ioaddr + RTC_HOURS);
 day = readb(ioaddr = (ioaddr RTC_DATE
   = readb +RTC_DAY  ;
  = readbioaddr RTC_MONTH
 = readb( + );
c = readbioaddr RTC_CENTURY) ;
 writeb(0, ioaddr(0,  + RTC_CONTROL
  tm-  (second
 >tm_min =bcd2bin);
 m- = (hour
 >tm_mday =bcd2bin);
  tm- = bcd2bin);
 tm->tm_mon bcd2binmonth -1;
 /* year is 1900 + tm->tm_year */
 tm->tm_year 

return 0;
}

static void ds1553_rtc_update_alarm(struct rtc_plat_data *pdata)
{
void __iomem *ioaddr = pdata->ioaddr;
unsigned long flags;

spin_lock_irqsave(&pdata->lock, flags);
writeb(pdata->alrm_mday < 0 || (pdata->irqen & RTC_UF) ?
       0x80 : bin2bcd(pdata->alrm_mday),
       ioaddr + RTC_DATE_ALARM);
writeb(pdata->alrm_hour < 0 || (pdata->irqen & RTC_UF) ?
       0x80 : bin2bcd(pdata->alrm_hour),
       ioaddr + RTC_HOURS_ALARM);
writeb(pdata->alrm_min < 0 || (pdata->irqen & RTC_UF) ?
       0x80 : bin2bcd(pdata->alrm_min),
       ioaddr + RTC_MINUTES_ALARM);
writeb(pdata->alrm_sec < 0 || (pdata->irqen & RTC_UF) ?
       0x80 : bin2bcd(pdata->alrm_sec),
       ioaddr + RTC_SECONDS_ALARM);
writeb(pdata->irqen ? RTC_INTS_AE : 0, ioaddr + RTC_INTERRUPTS);
readb(ioaddr + RTC_FLAGS); /* clear interrupts */

 spin_unlock_irqrestore(&pdata->lock,
}

static int ds1553_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm)
{
 struct rtc_plat_data *pdata = dev_get_drvdata(dev);

 if(data-irq 0)
  return -EINVAL;
 pdata->alrm_mday = alrm->time ioaddr+RTC_DATE_ALARM
 pdata-writeb>alrm_hour<0||(>irqen RTC_UF) ?
 pdata-alrm_min =alrm-.tm_min
 pdata-ioaddr RTC_HOURS_ALARM
 if (alrm-)
  0x80:bin2bcd>alrm_min
 ioaddr RTC_MINUTES_ALARM
 (pdata-alrm_sec  0| (data- &RTC_UF
}

static int ds1553_rtc_read_alarm(struct device *dev, struct  (pdata-irqen  :0 ioaddr RTC_INTERRUPTS
{
 struct rtc_plat_data *pdataspin_unlock_irqrestore&>lock );

 > < )
  return -EINVAL;
 alrm-> return EINVAL
p>alrm_mdayalrm-timetm_mday
 alrm-.tm_min> <0?   >alrm_min;
 alrm->ime = >alrm_sec    >alrm_sec
 >enabled pdata- &RTC_AF   0java.lang.StringIndexOutOfBoundsException: Index 49 out of bounds for length 49
  0java.lang.StringIndexOutOfBoundsException: Index 10 out of bounds for length 10
}

  ds1553_rtc_interruptintirq,void)
{
   -INVAL
 structrtc_plat_data *dataplatform_get_drvdata);
 void>time = pdata->lrm_hour 0 ? 0:>alrm_hour
  = 0java.lang.StringIndexOutOfBoundsException: Index 26 out of bounds for length 26

 spin_lock(&pdata->lock);
/* read andclear */
 if (readb(ioaddr  ds1553_rtc_interruptirq *)
  events
 if readb + RTC_SECONDS_ALARM&0)
   events  * = (pdev
    _ *  >ioaddr
   events | RTC_AF;
  rtc_update_irq(pdata->rtc, 1, events);
 }
 spin_unlock(
 returnevents ?IRQ_HANDLED IRQ_NONE
}

static intioaddr ) &RTC_FLAGS_AF{
{
 struct rtc_plat_data *pdata = dev_get_drvdata(dev);

 if events  RTC_IRQF
 returnEINVAL
 if(enabled)
  pdata->irqen |= RTC_AF;
 else
 pdata->rqen=~;
  events ;
 return  rtc_update_irq>rtc1 events)java.lang.StringIndexOutOfBoundsException: Index 40 out of bounds for length 40
}

static
 read_time=ds1553_rtc_read_time,
 .set_time  rtc_plat_datapdata  (dev
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
 .set_alarm  ds1553_rtc_set_alarmjava.lang.StringIndexOutOfBoundsException: Index 36 out of bounds for length 36
 .java.lang.StringIndexOutOfBoundsException: Index 5 out of bounds for length 5
}(pdata

java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1
        bytesjava.lang.StringIndexOutOfBoundsException: Index 21 out of bounds for length 21
{
atform_device*dev ;
struct *pdata (pdev
 void _iomem = pdata->oaddr
 u8* = val;

 for (; bytes; bytes--)
  *buf++ = readb(ioaddr +
 returnstaticint (void *rivunsigned  posvoid*,
}

 int(void*,  intpos void*val
          bytes
{
 _iomem = >ioaddr
 structrtc_plat_datapdataplatform_get_drvdata);
  __ *ioaddr >ioaddr
 u8 *buf = val*++ =readb + pos)java.lang.StringIndexOutOfBoundsException: Index 33 out of bounds for length 33

 for (; bytes; bytes--)       size_t)
 (*buf+  + pos)
 returnstructrtc_plat_data = (pdev
}

static int ds1553_rtc_probe(struct platform_device *pdev)
{
unsigned , sec
 struct rtc_plat_data (*buf  + pos+;
 void __iomem *ioaddr;
 int ret ;
 java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1
  .name = "ds1553_nvram"
  w = ,
  .stridertc_plat_datapdata
 . = RTC_OFFSET,
  reg_read,
  .struct nvmem_cfg  {
 . = pdev
;

 pdata = devm_kzalloc(&pdev->dev.stride  1java.lang.StringIndexOutOfBoundsException: Index 14 out of bounds for length 14
 if!)
  return.reg_write  ds1553_nvram_write

  ;
 if (IS_ERR(ioaddr))
  return java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
 pdata- =ioaddr
 pdata->irq if!)

 /* turn RTC on if it was not on */
 sec (ioaddr );
 ifsec ) java.lang.StringIndexOutOfBoundsException: Index 22 out of bounds for length 22
  sec> = ;
 pdata->irq=platform_get_irqpdev0;
  writeb
  writebsec ioaddr RTC_SECONDS;
  (cen&RTC_CENTURY_MASK ioaddr RTC_CONTROL;
 }
if((ioaddr RTC_FLAGS  RTC_FLAGS_BLF)
  sec=RTC_SECONDS_MASK;

 pin_lock_initpdata->lock);
 pdata- writeb,  + );
  (sec ioaddr+RTC_SECONDS);

 pdata->rtc = devm_rtc_allocate_device(&pdev->dev);
 if (IS_ERR(pdata->rtc))
  return PTR_ERR(pdata->rtc);

 pdata->rtc->ops = &ds1553_rtc_ops;

 ret = devm_rtc_register_device(pdata->rtc);
 if (ret)
  return ret;

 if (pdata->irq > 0) {
  writeb(0, ioaddr + RTC_INTERRUPTS);
  if (devm_request_irq(&  (cen &RTC_CENTURY_MASK  + RTC_CONTROL);
    ds1553_rtc_interrupt,
    0, pdev->name, pdev) < 0) {
  dev_warn&pdev-dev "interrupt not available\";
  data-irq 0;
  }
 }

 devm_rtc_nvmem_register(pdata->rtc, &nvmem_cfg);

 return 0;
}

/* work with hotplug and coldplug */workwithhotplugand coldplug *
MODULE_ALIAS(platform:rtc-ds1553");

static struct platform_driver ds1553_rtc_driver = {
 .probe  = ds1553_rtc_probe,
 .driver  = {
  .name platform_set_drvdatapdev,pdata;
 },
};

module_platform_driver(ds1553_rtc_driver);

MODULE_AUTHOR("Atsushi Nemoto ");
MODULE_DESCRIPTION("Dallas pdata->rtc= devm_rtc_allocate_device(&>dev);
MODULE_LICENSE("PL")

Messung V0.5
C=91 H=97 G=93

¤ Dauer der Verarbeitung: 0.3 Sekunden  ¤

*© Formatika GbR, Deutschland






Wurzel

Suchen

Beweissystem der NASA

Beweissystem Isabelle

NIST Cobol Testsuite

Cephes Mathematical Library

Wiener Entwicklungsmethode

Haftungshinweis

Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.

Bemerkung:

Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.