FreeBSD kernel IICBUS device code
ds13rtc.c File Reference
#include <sys/cdefs.h>
#include "opt_platform.h"
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/bus.h>
#include <sys/clock.h>
#include <sys/endian.h>
#include <sys/kernel.h>
#include <sys/libkern.h>
#include <sys/module.h>
#include <dev/iicbus/iicbus.h>
#include <dev/iicbus/iiconf.h>
#include "clock_if.h"
#include "iicbus_if.h"
Include dependency graph for ds13rtc.c:

Go to the source code of this file.

Data Structures

struct  time_regs
 
struct  ds13rtc_softc
 
struct  ds13_compat_data
 

Macros

#define DS13xx_ADDR   0xd0
 
#define DS13xx_R_NONE   0xff /* Placeholder */
 
#define DS130x_R_CONTROL   0x07
 
#define DS133x_R_CONTROL   0x0e
 
#define DS1340_R_CONTROL   0x07
 
#define DS1341_R_CONTROL   0x0e
 
#define DS1371_R_CONTROL   0x07
 
#define DS1372_R_CONTROL   0x07
 
#define DS1374_R_CONTROL   0x07
 
#define DS1375_R_CONTROL   0x0e
 
#define DS1388_R_CONTROL   0x0c
 
#define DS13xx_R_SECOND   0x00
 
#define DS1388_R_SECOND   0x01
 
#define DS130x_R_STATUS   DS13xx_R_NONE
 
#define DS133x_R_STATUS   0x0f
 
#define DS1340_R_STATUS   0x09
 
#define DS137x_R_STATUS   0x08
 
#define DS1388_R_STATUS   0x0b
 
#define DS13xx_B_STATUS_OSF   0x80 /* OSF is 1<<7 in status and sec regs */
 
#define DS13xx_B_HOUR_AMPM   0x40 /* AMPM mode is bit 1<<6 */
 
#define DS13xx_B_HOUR_PM   0x20 /* PM hours indicated by 1<<5 */
 
#define DS13xx_B_MONTH_CENTURY   0x80 /* 21st century indicated by 1<<7 */
 
#define DS13xx_M_SECOND   0x7f /* Masks for all BCD time regs... */
 
#define DS13xx_M_MINUTE   0x7f
 
#define DS13xx_M_12HOUR   0x1f
 
#define DS13xx_M_24HOUR   0x3f
 
#define DS13xx_M_DAY   0x3f
 
#define DS13xx_M_MONTH   0x1f
 
#define DS13xx_M_YEAR   0xff
 

Enumerations

enum  {
  TYPE_NONE , TYPE_DS1307 , TYPE_DS1308 , TYPE_DS1337 ,
  TYPE_DS1338 , TYPE_DS1339 , TYPE_DS1340 , TYPE_DS1341 ,
  TYPE_DS1342 , TYPE_DS1371 , TYPE_DS1372 , TYPE_DS1374 ,
  TYPE_DS1375 , TYPE_DS1388 , TYPE_COUNT
}
 

Functions

 __FBSDID ("$FreeBSD$")
 
 CTASSERT (nitems(desc_strings)==TYPE_COUNT)
 
static int read_reg (struct ds13rtc_softc *sc, uint8_t reg, uint8_t *val)
 
static int write_reg (struct ds13rtc_softc *sc, uint8_t reg, uint8_t val)
 
static int read_timeregs (struct ds13rtc_softc *sc, struct time_regs *tregs)
 
static int write_timeregs (struct ds13rtc_softc *sc, struct time_regs *tregs)
 
static int read_timeword (struct ds13rtc_softc *sc, time_t *secs)
 
static int write_timeword (struct ds13rtc_softc *sc, time_t secs)
 
static void ds13rtc_start (void *arg)
 
static int ds13rtc_gettime (device_t dev, struct timespec *ts)
 
static int ds13rtc_settime (device_t dev, struct timespec *ts)
 
static int ds13rtc_get_chiptype (device_t dev)
 
static int ds13rtc_probe (device_t dev)
 
static int ds13rtc_attach (device_t dev)
 
static int ds13rtc_detach (device_t dev)
 
 DRIVER_MODULE (ds13rtc, iicbus, ds13rtc_driver, ds13rtc_devclass, NULL, NULL)
 
 MODULE_VERSION (ds13rtc, 1)
 
 MODULE_DEPEND (ds13rtc, iicbus, IICBB_MINVER, IICBB_PREFVER, IICBB_MAXVER)
 
 IICBUS_FDT_PNP_INFO (compat_data)
 

Variables

static const char * desc_strings []
 
static ds13_compat_data compat_data []
 
static device_method_t ds13rtc_methods []
 
static driver_t ds13rtc_driver
 
static devclass_t ds13rtc_devclass
 

Macro Definition Documentation

◆ DS130x_R_CONTROL

#define DS130x_R_CONTROL   0x07

Definition at line 85 of file ds13rtc.c.

◆ DS130x_R_STATUS

#define DS130x_R_STATUS   DS13xx_R_NONE

Definition at line 98 of file ds13rtc.c.

◆ DS133x_R_CONTROL

#define DS133x_R_CONTROL   0x0e

Definition at line 86 of file ds13rtc.c.

◆ DS133x_R_STATUS

#define DS133x_R_STATUS   0x0f

Definition at line 99 of file ds13rtc.c.

◆ DS1340_R_CONTROL

#define DS1340_R_CONTROL   0x07

Definition at line 87 of file ds13rtc.c.

◆ DS1340_R_STATUS

#define DS1340_R_STATUS   0x09

Definition at line 100 of file ds13rtc.c.

◆ DS1341_R_CONTROL

#define DS1341_R_CONTROL   0x0e

Definition at line 88 of file ds13rtc.c.

◆ DS1371_R_CONTROL

#define DS1371_R_CONTROL   0x07

Definition at line 89 of file ds13rtc.c.

◆ DS1372_R_CONTROL

#define DS1372_R_CONTROL   0x07

Definition at line 90 of file ds13rtc.c.

◆ DS1374_R_CONTROL

#define DS1374_R_CONTROL   0x07

Definition at line 91 of file ds13rtc.c.

◆ DS1375_R_CONTROL

#define DS1375_R_CONTROL   0x0e

Definition at line 92 of file ds13rtc.c.

◆ DS137x_R_STATUS

#define DS137x_R_STATUS   0x08

Definition at line 101 of file ds13rtc.c.

◆ DS1388_R_CONTROL

#define DS1388_R_CONTROL   0x0c

Definition at line 93 of file ds13rtc.c.

◆ DS1388_R_SECOND

#define DS1388_R_SECOND   0x01

Definition at line 96 of file ds13rtc.c.

◆ DS1388_R_STATUS

#define DS1388_R_STATUS   0x0b

Definition at line 102 of file ds13rtc.c.

◆ DS13xx_ADDR

#define DS13xx_ADDR   0xd0

Definition at line 77 of file ds13rtc.c.

◆ DS13xx_B_HOUR_AMPM

#define DS13xx_B_HOUR_AMPM   0x40 /* AMPM mode is bit 1<<6 */

Definition at line 105 of file ds13rtc.c.

◆ DS13xx_B_HOUR_PM

#define DS13xx_B_HOUR_PM   0x20 /* PM hours indicated by 1<<5 */

Definition at line 106 of file ds13rtc.c.

◆ DS13xx_B_MONTH_CENTURY

#define DS13xx_B_MONTH_CENTURY   0x80 /* 21st century indicated by 1<<7 */

Definition at line 107 of file ds13rtc.c.

◆ DS13xx_B_STATUS_OSF

#define DS13xx_B_STATUS_OSF   0x80 /* OSF is 1<<7 in status and sec regs */

Definition at line 104 of file ds13rtc.c.

◆ DS13xx_M_12HOUR

#define DS13xx_M_12HOUR   0x1f

Definition at line 111 of file ds13rtc.c.

◆ DS13xx_M_24HOUR

#define DS13xx_M_24HOUR   0x3f

Definition at line 112 of file ds13rtc.c.

◆ DS13xx_M_DAY

#define DS13xx_M_DAY   0x3f

Definition at line 113 of file ds13rtc.c.

◆ DS13xx_M_MINUTE

#define DS13xx_M_MINUTE   0x7f

Definition at line 110 of file ds13rtc.c.

◆ DS13xx_M_MONTH

#define DS13xx_M_MONTH   0x1f

Definition at line 114 of file ds13rtc.c.

◆ DS13xx_M_SECOND

#define DS13xx_M_SECOND   0x7f /* Masks for all BCD time regs... */

Definition at line 109 of file ds13rtc.c.

◆ DS13xx_M_YEAR

#define DS13xx_M_YEAR   0xff

Definition at line 115 of file ds13rtc.c.

◆ DS13xx_R_NONE

#define DS13xx_R_NONE   0xff /* Placeholder */

Definition at line 83 of file ds13rtc.c.

◆ DS13xx_R_SECOND

#define DS13xx_R_SECOND   0x00

Definition at line 95 of file ds13rtc.c.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
TYPE_NONE 
TYPE_DS1307 
TYPE_DS1308 
TYPE_DS1337 
TYPE_DS1338 
TYPE_DS1339 
TYPE_DS1340 
TYPE_DS1341 
TYPE_DS1342 
TYPE_DS1371 
TYPE_DS1372 
TYPE_DS1374 
TYPE_DS1375 
TYPE_DS1388 
TYPE_COUNT 

Definition at line 120 of file ds13rtc.c.

Function Documentation

◆ __FBSDID()

__FBSDID ( "$FreeBSD$"  )

◆ CTASSERT()

CTASSERT ( nitems(desc_strings = =TYPE_COUNT)

◆ DRIVER_MODULE()

DRIVER_MODULE ( ds13rtc  ,
iicbus  ,
ds13rtc_driver  ,
ds13rtc_devclass  ,
NULL  ,
NULL   
)

◆ ds13rtc_attach()

◆ ds13rtc_detach()

static int ds13rtc_detach ( device_t  dev)
static

Definition at line 592 of file ds13rtc.c.

References dev.

◆ ds13rtc_get_chiptype()

static int ds13rtc_get_chiptype ( device_t  dev)
static

Definition at line 476 of file ds13rtc.c.

References compat_data, dev, ds13_compat_data::ocd_data, ds13_compat_data::ocd_str, and TYPE_NONE.

Referenced by ds13rtc_attach(), and ds13rtc_probe().

Here is the caller graph for this function:

◆ ds13rtc_gettime()

◆ ds13rtc_probe()

static int ds13rtc_probe ( device_t  dev)
static

Definition at line 505 of file ds13rtc.c.

References ds13rtc_softc::chiptype, desc_strings, dev, ds13rtc_get_chiptype(), and TYPE_NONE.

Here is the call graph for this function:

◆ ds13rtc_settime()

◆ ds13rtc_start()

◆ IICBUS_FDT_PNP_INFO()

IICBUS_FDT_PNP_INFO ( compat_data  )

◆ MODULE_DEPEND()

MODULE_DEPEND ( ds13rtc  ,
iicbus  ,
IICBB_MINVER  ,
IICBB_PREFVER  ,
IICBB_MAXVER   
)

◆ MODULE_VERSION()

MODULE_VERSION ( ds13rtc  ,
 
)

◆ read_reg()

static int read_reg ( struct ds13rtc_softc sc,
uint8_t  reg,
uint8_t *  val 
)
static

Definition at line 206 of file ds13rtc.c.

References ds13rtc_softc::dev, IIC_WAIT, iicdev_readfrom(), and val.

Referenced by ds13rtc_gettime(), ds13rtc_settime(), and ds13rtc_start().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ read_timeregs()

static int read_timeregs ( struct ds13rtc_softc sc,
struct time_regs tregs 
)
static

Definition at line 220 of file ds13rtc.c.

References ds13rtc_softc::dev, IIC_WAIT, iicdev_readfrom(), and ds13rtc_softc::secaddr.

Referenced by ds13rtc_gettime().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ read_timeword()

static int read_timeword ( struct ds13rtc_softc sc,
time_t *  secs 
)
static

Definition at line 240 of file ds13rtc.c.

References buf, ds13rtc_softc::dev, IIC_WAIT, iicdev_readfrom(), and ds13rtc_softc::secaddr.

Referenced by ds13rtc_gettime().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ write_reg()

static int write_reg ( struct ds13rtc_softc sc,
uint8_t  reg,
uint8_t  val 
)
static

Definition at line 213 of file ds13rtc.c.

References ds13rtc_softc::dev, IIC_WAIT, iicdev_writeto(), and val.

Referenced by ds13rtc_settime(), and ds13rtc_start().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ write_timeregs()

static int write_timeregs ( struct ds13rtc_softc sc,
struct time_regs tregs 
)
static

Definition at line 232 of file ds13rtc.c.

References ds13rtc_softc::dev, IIC_WAIT, iicdev_writeto(), and ds13rtc_softc::secaddr.

Referenced by ds13rtc_settime().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ write_timeword()

static int write_timeword ( struct ds13rtc_softc sc,
time_t  secs 
)
static

Definition at line 253 of file ds13rtc.c.

References buf, ds13rtc_softc::dev, IIC_WAIT, iicdev_writeto(), and ds13rtc_softc::secaddr.

Referenced by ds13rtc_settime().

Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ compat_data

ds13_compat_data compat_data[]
static
Initial value:
= {
{"dallas,ds1307", TYPE_DS1307},
{"dallas,ds1308", TYPE_DS1308},
{"dallas,ds1337", TYPE_DS1337},
{"dallas,ds1338", TYPE_DS1338},
{"dallas,ds1339", TYPE_DS1339},
{"dallas,ds1340", TYPE_DS1340},
{"dallas,ds1341", TYPE_DS1341},
{"dallas,ds1342", TYPE_DS1342},
{"dallas,ds1371", TYPE_DS1371},
{"dallas,ds1372", TYPE_DS1372},
{"dallas,ds1374", TYPE_DS1374},
{"dallas,ds1375", TYPE_DS1375},
{"dallas,ds1388", TYPE_DS1388},
{NULL, TYPE_NONE},
}
@ TYPE_NONE
Definition: ds13rtc.c:121
@ TYPE_DS1307
Definition: ds13rtc.c:122
@ TYPE_DS1372
Definition: ds13rtc.c:131
@ TYPE_DS1371
Definition: ds13rtc.c:130
@ TYPE_DS1308
Definition: ds13rtc.c:123
@ TYPE_DS1339
Definition: ds13rtc.c:126
@ TYPE_DS1340
Definition: ds13rtc.c:127
@ TYPE_DS1341
Definition: ds13rtc.c:128
@ TYPE_DS1342
Definition: ds13rtc.c:129
@ TYPE_DS1388
Definition: ds13rtc.c:134
@ TYPE_DS1337
Definition: ds13rtc.c:124
@ TYPE_DS1375
Definition: ds13rtc.c:133
@ TYPE_DS1338
Definition: ds13rtc.c:125
@ TYPE_DS1374
Definition: ds13rtc.c:132

Definition at line 187 of file ds13rtc.c.

Referenced by ads111x_find_chipinfo(), ds13rtc_get_chiptype(), gpiomux_probe(), htu21_probe(), hym8563_probe(), icee_init(), icee_probe(), isl12xx_probe(), ltc430x_find_chiptype(), max44009_probe(), pca954x_find_chip(), pcf8574_probe(), pcf8591_probe(), and rtc8583_probe().

◆ desc_strings

const char* desc_strings[]
static
Initial value:
= {
"",
"Dallas/Maxim DS1307 RTC",
"Dallas/Maxim DS1308 RTC",
"Dallas/Maxim DS1337 RTC",
"Dallas/Maxim DS1338 RTC",
"Dallas/Maxim DS1339 RTC",
"Dallas/Maxim DS1340 RTC",
"Dallas/Maxim DS1341 RTC",
"Dallas/Maxim DS1342 RTC",
"Dallas/Maxim DS1371 RTC",
"Dallas/Maxim DS1372 RTC",
"Dallas/Maxim DS1374 RTC",
"Dallas/Maxim DS1375 RTC",
"Dallas/Maxim DS1388 RTC",
}

Definition at line 138 of file ds13rtc.c.

Referenced by ds13rtc_probe().

◆ ds13rtc_devclass

devclass_t ds13rtc_devclass
static

Definition at line 616 of file ds13rtc.c.

◆ ds13rtc_driver

driver_t ds13rtc_driver
static
Initial value:
= {
"ds13rtc",
sizeof(struct ds13rtc_softc),
}
static device_method_t ds13rtc_methods[]
Definition: ds13rtc.c:599

Definition at line 610 of file ds13rtc.c.

◆ ds13rtc_methods

device_method_t ds13rtc_methods[]
static
Initial value:
= {
DEVMETHOD(device_probe, ds13rtc_probe),
DEVMETHOD(device_attach, ds13rtc_attach),
DEVMETHOD(device_detach, ds13rtc_detach),
DEVMETHOD(clock_gettime, ds13rtc_gettime),
DEVMETHOD(clock_settime, ds13rtc_settime),
DEVMETHOD_END
}
static int ds13rtc_attach(device_t dev)
Definition: ds13rtc.c:526
static int ds13rtc_probe(device_t dev)
Definition: ds13rtc.c:505
static int ds13rtc_settime(device_t dev, struct timespec *ts)
Definition: ds13rtc.c:406
static int ds13rtc_gettime(device_t dev, struct timespec *ts)
Definition: ds13rtc.c:347
static int ds13rtc_detach(device_t dev)
Definition: ds13rtc.c:592

Definition at line 599 of file ds13rtc.c.