1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0-only */ 2*4882a593Smuzhiyun /* 3*4882a593Smuzhiyun * Definitions for the registers, addresses, and platform data of the 4*4882a593Smuzhiyun * DS1685/DS1687-series RTC chips. 5*4882a593Smuzhiyun * 6*4882a593Smuzhiyun * This Driver also works for the DS17X85/DS17X87 RTC chips. Functionally 7*4882a593Smuzhiyun * similar to the DS1685/DS1687, they support a few extra features which 8*4882a593Smuzhiyun * include larger, battery-backed NV-SRAM, burst-mode access, and an RTC 9*4882a593Smuzhiyun * write counter. 10*4882a593Smuzhiyun * 11*4882a593Smuzhiyun * Copyright (C) 2011-2014 Joshua Kinard <kumba@gentoo.org>. 12*4882a593Smuzhiyun * Copyright (C) 2009 Matthias Fuchs <matthias.fuchs@esd-electronics.com>. 13*4882a593Smuzhiyun * 14*4882a593Smuzhiyun * References: 15*4882a593Smuzhiyun * DS1685/DS1687 3V/5V Real-Time Clocks, 19-5215, Rev 4/10. 16*4882a593Smuzhiyun * DS17x85/DS17x87 3V/5V Real-Time Clocks, 19-5222, Rev 4/10. 17*4882a593Smuzhiyun * DS1689/DS1693 3V/5V Serialized Real-Time Clocks, Rev 112105. 18*4882a593Smuzhiyun * Application Note 90, Using the Multiplex Bus RTC Extended Features. 19*4882a593Smuzhiyun */ 20*4882a593Smuzhiyun 21*4882a593Smuzhiyun #ifndef _LINUX_RTC_DS1685_H_ 22*4882a593Smuzhiyun #define _LINUX_RTC_DS1685_H_ 23*4882a593Smuzhiyun 24*4882a593Smuzhiyun #include <linux/rtc.h> 25*4882a593Smuzhiyun #include <linux/platform_device.h> 26*4882a593Smuzhiyun #include <linux/workqueue.h> 27*4882a593Smuzhiyun 28*4882a593Smuzhiyun /** 29*4882a593Smuzhiyun * struct ds1685_priv - DS1685 private data structure. 30*4882a593Smuzhiyun * @dev: pointer to the rtc_device structure. 31*4882a593Smuzhiyun * @regs: iomapped base address pointer of the RTC registers. 32*4882a593Smuzhiyun * @regstep: padding/step size between registers (optional). 33*4882a593Smuzhiyun * @baseaddr: base address of the RTC device. 34*4882a593Smuzhiyun * @size: resource size. 35*4882a593Smuzhiyun * @lock: private lock variable for spin locking/unlocking. 36*4882a593Smuzhiyun * @work: private workqueue. 37*4882a593Smuzhiyun * @irq: IRQ number assigned to the RTC device. 38*4882a593Smuzhiyun * @prepare_poweroff: pointer to platform pre-poweroff function. 39*4882a593Smuzhiyun * @wake_alarm: pointer to platform wake alarm function. 40*4882a593Smuzhiyun * @post_ram_clear: pointer to platform post ram-clear function. 41*4882a593Smuzhiyun */ 42*4882a593Smuzhiyun struct ds1685_priv { 43*4882a593Smuzhiyun struct rtc_device *dev; 44*4882a593Smuzhiyun void __iomem *regs; 45*4882a593Smuzhiyun void __iomem *data; 46*4882a593Smuzhiyun u32 regstep; 47*4882a593Smuzhiyun int irq_num; 48*4882a593Smuzhiyun bool bcd_mode; 49*4882a593Smuzhiyun bool no_irq; 50*4882a593Smuzhiyun u8 (*read)(struct ds1685_priv *, int); 51*4882a593Smuzhiyun void (*write)(struct ds1685_priv *, int, u8); 52*4882a593Smuzhiyun void (*prepare_poweroff)(void); 53*4882a593Smuzhiyun void (*wake_alarm)(void); 54*4882a593Smuzhiyun void (*post_ram_clear)(void); 55*4882a593Smuzhiyun }; 56*4882a593Smuzhiyun 57*4882a593Smuzhiyun 58*4882a593Smuzhiyun /** 59*4882a593Smuzhiyun * struct ds1685_rtc_platform_data - platform data structure. 60*4882a593Smuzhiyun * @plat_prepare_poweroff: platform-specific pre-poweroff function. 61*4882a593Smuzhiyun * @plat_wake_alarm: platform-specific wake alarm function. 62*4882a593Smuzhiyun * @plat_post_ram_clear: platform-specific post ram-clear function. 63*4882a593Smuzhiyun * 64*4882a593Smuzhiyun * If your platform needs to use a custom padding/step size between 65*4882a593Smuzhiyun * registers, or uses one or more of the extended interrupts and needs special 66*4882a593Smuzhiyun * handling, then include this header file in your platform definition and 67*4882a593Smuzhiyun * set regstep and the plat_* pointers as appropriate. 68*4882a593Smuzhiyun */ 69*4882a593Smuzhiyun struct ds1685_rtc_platform_data { 70*4882a593Smuzhiyun const u32 regstep; 71*4882a593Smuzhiyun const bool bcd_mode; 72*4882a593Smuzhiyun const bool no_irq; 73*4882a593Smuzhiyun const bool uie_unsupported; 74*4882a593Smuzhiyun void (*plat_prepare_poweroff)(void); 75*4882a593Smuzhiyun void (*plat_wake_alarm)(void); 76*4882a593Smuzhiyun void (*plat_post_ram_clear)(void); 77*4882a593Smuzhiyun enum { 78*4882a593Smuzhiyun ds1685_reg_direct, 79*4882a593Smuzhiyun ds1685_reg_indirect 80*4882a593Smuzhiyun } access_type; 81*4882a593Smuzhiyun }; 82*4882a593Smuzhiyun 83*4882a593Smuzhiyun 84*4882a593Smuzhiyun /* 85*4882a593Smuzhiyun * Time Registers. 86*4882a593Smuzhiyun */ 87*4882a593Smuzhiyun #define RTC_SECS 0x00 /* Seconds 00-59 */ 88*4882a593Smuzhiyun #define RTC_SECS_ALARM 0x01 /* Alarm Seconds 00-59 */ 89*4882a593Smuzhiyun #define RTC_MINS 0x02 /* Minutes 00-59 */ 90*4882a593Smuzhiyun #define RTC_MINS_ALARM 0x03 /* Alarm Minutes 00-59 */ 91*4882a593Smuzhiyun #define RTC_HRS 0x04 /* Hours 01-12 AM/PM || 00-23 */ 92*4882a593Smuzhiyun #define RTC_HRS_ALARM 0x05 /* Alarm Hours 01-12 AM/PM || 00-23 */ 93*4882a593Smuzhiyun #define RTC_WDAY 0x06 /* Day of Week 01-07 */ 94*4882a593Smuzhiyun #define RTC_MDAY 0x07 /* Day of Month 01-31 */ 95*4882a593Smuzhiyun #define RTC_MONTH 0x08 /* Month 01-12 */ 96*4882a593Smuzhiyun #define RTC_YEAR 0x09 /* Year 00-99 */ 97*4882a593Smuzhiyun #define RTC_CENTURY 0x48 /* Century 00-99 */ 98*4882a593Smuzhiyun #define RTC_MDAY_ALARM 0x49 /* Alarm Day of Month 01-31 */ 99*4882a593Smuzhiyun 100*4882a593Smuzhiyun 101*4882a593Smuzhiyun /* 102*4882a593Smuzhiyun * Bit masks for the Time registers in BCD Mode (DM = 0). 103*4882a593Smuzhiyun */ 104*4882a593Smuzhiyun #define RTC_SECS_BCD_MASK 0x7f /* - x x x x x x x */ 105*4882a593Smuzhiyun #define RTC_MINS_BCD_MASK 0x7f /* - x x x x x x x */ 106*4882a593Smuzhiyun #define RTC_HRS_12_BCD_MASK 0x1f /* - - - x x x x x */ 107*4882a593Smuzhiyun #define RTC_HRS_24_BCD_MASK 0x3f /* - - x x x x x x */ 108*4882a593Smuzhiyun #define RTC_MDAY_BCD_MASK 0x3f /* - - x x x x x x */ 109*4882a593Smuzhiyun #define RTC_MONTH_BCD_MASK 0x1f /* - - - x x x x x */ 110*4882a593Smuzhiyun #define RTC_YEAR_BCD_MASK 0xff /* x x x x x x x x */ 111*4882a593Smuzhiyun 112*4882a593Smuzhiyun /* 113*4882a593Smuzhiyun * Bit masks for the Time registers in BIN Mode (DM = 1). 114*4882a593Smuzhiyun */ 115*4882a593Smuzhiyun #define RTC_SECS_BIN_MASK 0x3f /* - - x x x x x x */ 116*4882a593Smuzhiyun #define RTC_MINS_BIN_MASK 0x3f /* - - x x x x x x */ 117*4882a593Smuzhiyun #define RTC_HRS_12_BIN_MASK 0x0f /* - - - - x x x x */ 118*4882a593Smuzhiyun #define RTC_HRS_24_BIN_MASK 0x1f /* - - - x x x x x */ 119*4882a593Smuzhiyun #define RTC_MDAY_BIN_MASK 0x1f /* - - - x x x x x */ 120*4882a593Smuzhiyun #define RTC_MONTH_BIN_MASK 0x0f /* - - - - x x x x */ 121*4882a593Smuzhiyun #define RTC_YEAR_BIN_MASK 0x7f /* - x x x x x x x */ 122*4882a593Smuzhiyun 123*4882a593Smuzhiyun /* 124*4882a593Smuzhiyun * Bit masks common for the Time registers in BCD or BIN Mode. 125*4882a593Smuzhiyun */ 126*4882a593Smuzhiyun #define RTC_WDAY_MASK 0x07 /* - - - - - x x x */ 127*4882a593Smuzhiyun #define RTC_CENTURY_MASK 0xff /* x x x x x x x x */ 128*4882a593Smuzhiyun #define RTC_MDAY_ALARM_MASK 0xff /* x x x x x x x x */ 129*4882a593Smuzhiyun #define RTC_HRS_AMPM_MASK BIT(7) /* Mask for the AM/PM bit */ 130*4882a593Smuzhiyun 131*4882a593Smuzhiyun 132*4882a593Smuzhiyun 133*4882a593Smuzhiyun /* 134*4882a593Smuzhiyun * Control Registers. 135*4882a593Smuzhiyun */ 136*4882a593Smuzhiyun #define RTC_CTRL_A 0x0a /* Control Register A */ 137*4882a593Smuzhiyun #define RTC_CTRL_B 0x0b /* Control Register B */ 138*4882a593Smuzhiyun #define RTC_CTRL_C 0x0c /* Control Register C */ 139*4882a593Smuzhiyun #define RTC_CTRL_D 0x0d /* Control Register D */ 140*4882a593Smuzhiyun #define RTC_EXT_CTRL_4A 0x4a /* Extended Control Register 4A */ 141*4882a593Smuzhiyun #define RTC_EXT_CTRL_4B 0x4b /* Extended Control Register 4B */ 142*4882a593Smuzhiyun 143*4882a593Smuzhiyun 144*4882a593Smuzhiyun /* 145*4882a593Smuzhiyun * Bit names in Control Register A. 146*4882a593Smuzhiyun */ 147*4882a593Smuzhiyun #define RTC_CTRL_A_UIP BIT(7) /* Update In Progress */ 148*4882a593Smuzhiyun #define RTC_CTRL_A_DV2 BIT(6) /* Countdown Chain */ 149*4882a593Smuzhiyun #define RTC_CTRL_A_DV1 BIT(5) /* Oscillator Enable */ 150*4882a593Smuzhiyun #define RTC_CTRL_A_DV0 BIT(4) /* Bank Select */ 151*4882a593Smuzhiyun #define RTC_CTRL_A_RS2 BIT(2) /* Rate-Selection Bit 2 */ 152*4882a593Smuzhiyun #define RTC_CTRL_A_RS3 BIT(3) /* Rate-Selection Bit 3 */ 153*4882a593Smuzhiyun #define RTC_CTRL_A_RS1 BIT(1) /* Rate-Selection Bit 1 */ 154*4882a593Smuzhiyun #define RTC_CTRL_A_RS0 BIT(0) /* Rate-Selection Bit 0 */ 155*4882a593Smuzhiyun #define RTC_CTRL_A_RS_MASK 0x0f /* RS3 + RS2 + RS1 + RS0 */ 156*4882a593Smuzhiyun 157*4882a593Smuzhiyun /* 158*4882a593Smuzhiyun * Bit names in Control Register B. 159*4882a593Smuzhiyun */ 160*4882a593Smuzhiyun #define RTC_CTRL_B_SET BIT(7) /* SET Bit */ 161*4882a593Smuzhiyun #define RTC_CTRL_B_PIE BIT(6) /* Periodic-Interrupt Enable */ 162*4882a593Smuzhiyun #define RTC_CTRL_B_AIE BIT(5) /* Alarm-Interrupt Enable */ 163*4882a593Smuzhiyun #define RTC_CTRL_B_UIE BIT(4) /* Update-Ended Interrupt-Enable */ 164*4882a593Smuzhiyun #define RTC_CTRL_B_SQWE BIT(3) /* Square-Wave Enable */ 165*4882a593Smuzhiyun #define RTC_CTRL_B_DM BIT(2) /* Data Mode */ 166*4882a593Smuzhiyun #define RTC_CTRL_B_2412 BIT(1) /* 12-Hr/24-Hr Mode */ 167*4882a593Smuzhiyun #define RTC_CTRL_B_DSE BIT(0) /* Daylight Savings Enable */ 168*4882a593Smuzhiyun #define RTC_CTRL_B_PAU_MASK 0x70 /* PIE + AIE + UIE */ 169*4882a593Smuzhiyun 170*4882a593Smuzhiyun 171*4882a593Smuzhiyun /* 172*4882a593Smuzhiyun * Bit names in Control Register C. 173*4882a593Smuzhiyun * 174*4882a593Smuzhiyun * BIT(0), BIT(1), BIT(2), & BIT(3) are unused, always return 0, and cannot 175*4882a593Smuzhiyun * be written to. 176*4882a593Smuzhiyun */ 177*4882a593Smuzhiyun #define RTC_CTRL_C_IRQF BIT(7) /* Interrupt-Request Flag */ 178*4882a593Smuzhiyun #define RTC_CTRL_C_PF BIT(6) /* Periodic-Interrupt Flag */ 179*4882a593Smuzhiyun #define RTC_CTRL_C_AF BIT(5) /* Alarm-Interrupt Flag */ 180*4882a593Smuzhiyun #define RTC_CTRL_C_UF BIT(4) /* Update-Ended Interrupt Flag */ 181*4882a593Smuzhiyun #define RTC_CTRL_C_PAU_MASK 0x70 /* PF + AF + UF */ 182*4882a593Smuzhiyun 183*4882a593Smuzhiyun 184*4882a593Smuzhiyun /* 185*4882a593Smuzhiyun * Bit names in Control Register D. 186*4882a593Smuzhiyun * 187*4882a593Smuzhiyun * BIT(0) through BIT(6) are unused, always return 0, and cannot 188*4882a593Smuzhiyun * be written to. 189*4882a593Smuzhiyun */ 190*4882a593Smuzhiyun #define RTC_CTRL_D_VRT BIT(7) /* Valid RAM and Time */ 191*4882a593Smuzhiyun 192*4882a593Smuzhiyun 193*4882a593Smuzhiyun /* 194*4882a593Smuzhiyun * Bit names in Extended Control Register 4A. 195*4882a593Smuzhiyun * 196*4882a593Smuzhiyun * On the DS1685/DS1687/DS1689/DS1693, BIT(4) and BIT(5) are reserved for 197*4882a593Smuzhiyun * future use. They can be read from and written to, but have no effect 198*4882a593Smuzhiyun * on the RTC's operation. 199*4882a593Smuzhiyun * 200*4882a593Smuzhiyun * On the DS17x85/DS17x87, BIT(5) is Burst-Mode Enable (BME), and allows 201*4882a593Smuzhiyun * access to the extended NV-SRAM by automatically incrementing the address 202*4882a593Smuzhiyun * register when they are read from or written to. 203*4882a593Smuzhiyun */ 204*4882a593Smuzhiyun #define RTC_CTRL_4A_VRT2 BIT(7) /* Auxillary Battery Status */ 205*4882a593Smuzhiyun #define RTC_CTRL_4A_INCR BIT(6) /* Increment-in-Progress Status */ 206*4882a593Smuzhiyun #define RTC_CTRL_4A_PAB BIT(3) /* Power-Active Bar Control */ 207*4882a593Smuzhiyun #define RTC_CTRL_4A_RF BIT(2) /* RAM-Clear Flag */ 208*4882a593Smuzhiyun #define RTC_CTRL_4A_WF BIT(1) /* Wake-Up Alarm Flag */ 209*4882a593Smuzhiyun #define RTC_CTRL_4A_KF BIT(0) /* Kickstart Flag */ 210*4882a593Smuzhiyun #if !defined(CONFIG_RTC_DRV_DS1685) && !defined(CONFIG_RTC_DRV_DS1689) 211*4882a593Smuzhiyun #define RTC_CTRL_4A_BME BIT(5) /* Burst-Mode Enable */ 212*4882a593Smuzhiyun #endif 213*4882a593Smuzhiyun #define RTC_CTRL_4A_RWK_MASK 0x07 /* RF + WF + KF */ 214*4882a593Smuzhiyun 215*4882a593Smuzhiyun 216*4882a593Smuzhiyun /* 217*4882a593Smuzhiyun * Bit names in Extended Control Register 4B. 218*4882a593Smuzhiyun */ 219*4882a593Smuzhiyun #define RTC_CTRL_4B_ABE BIT(7) /* Auxillary Battery Enable */ 220*4882a593Smuzhiyun #define RTC_CTRL_4B_E32K BIT(6) /* Enable 32.768Hz on SQW Pin */ 221*4882a593Smuzhiyun #define RTC_CTRL_4B_CS BIT(5) /* Crystal Select */ 222*4882a593Smuzhiyun #define RTC_CTRL_4B_RCE BIT(4) /* RAM Clear-Enable */ 223*4882a593Smuzhiyun #define RTC_CTRL_4B_PRS BIT(3) /* PAB Reset-Select */ 224*4882a593Smuzhiyun #define RTC_CTRL_4B_RIE BIT(2) /* RAM Clear-Interrupt Enable */ 225*4882a593Smuzhiyun #define RTC_CTRL_4B_WIE BIT(1) /* Wake-Up Alarm-Interrupt Enable */ 226*4882a593Smuzhiyun #define RTC_CTRL_4B_KSE BIT(0) /* Kickstart Interrupt-Enable */ 227*4882a593Smuzhiyun #define RTC_CTRL_4B_RWK_MASK 0x07 /* RIE + WIE + KSE */ 228*4882a593Smuzhiyun 229*4882a593Smuzhiyun 230*4882a593Smuzhiyun /* 231*4882a593Smuzhiyun * Misc register names in Bank 1. 232*4882a593Smuzhiyun * 233*4882a593Smuzhiyun * The DV0 bit in Control Register A must be set to 1 for these registers 234*4882a593Smuzhiyun * to become available, including Extended Control Registers 4A & 4B. 235*4882a593Smuzhiyun */ 236*4882a593Smuzhiyun #define RTC_BANK1_SSN_MODEL 0x40 /* Model Number */ 237*4882a593Smuzhiyun #define RTC_BANK1_SSN_BYTE_1 0x41 /* 1st Byte of Serial Number */ 238*4882a593Smuzhiyun #define RTC_BANK1_SSN_BYTE_2 0x42 /* 2nd Byte of Serial Number */ 239*4882a593Smuzhiyun #define RTC_BANK1_SSN_BYTE_3 0x43 /* 3rd Byte of Serial Number */ 240*4882a593Smuzhiyun #define RTC_BANK1_SSN_BYTE_4 0x44 /* 4th Byte of Serial Number */ 241*4882a593Smuzhiyun #define RTC_BANK1_SSN_BYTE_5 0x45 /* 5th Byte of Serial Number */ 242*4882a593Smuzhiyun #define RTC_BANK1_SSN_BYTE_6 0x46 /* 6th Byte of Serial Number */ 243*4882a593Smuzhiyun #define RTC_BANK1_SSN_CRC 0x47 /* Serial CRC Byte */ 244*4882a593Smuzhiyun #define RTC_BANK1_RAM_DATA_PORT 0x53 /* Extended RAM Data Port */ 245*4882a593Smuzhiyun 246*4882a593Smuzhiyun 247*4882a593Smuzhiyun /* 248*4882a593Smuzhiyun * Model-specific registers in Bank 1. 249*4882a593Smuzhiyun * 250*4882a593Smuzhiyun * The addresses below differ depending on the model of the RTC chip 251*4882a593Smuzhiyun * selected in the kernel configuration. Not all of these features are 252*4882a593Smuzhiyun * supported in the main driver at present. 253*4882a593Smuzhiyun * 254*4882a593Smuzhiyun * DS1685/DS1687 - Extended NV-SRAM address (LSB only). 255*4882a593Smuzhiyun * DS1689/DS1693 - Vcc, Vbat, Pwr Cycle Counters & Customer-specific S/N. 256*4882a593Smuzhiyun * DS17x85/DS17x87 - Extended NV-SRAM addresses (MSB & LSB) & Write counter. 257*4882a593Smuzhiyun */ 258*4882a593Smuzhiyun #if defined(CONFIG_RTC_DRV_DS1685) 259*4882a593Smuzhiyun #define RTC_BANK1_RAM_ADDR 0x50 /* NV-SRAM Addr */ 260*4882a593Smuzhiyun #elif defined(CONFIG_RTC_DRV_DS1689) 261*4882a593Smuzhiyun #define RTC_BANK1_VCC_CTR_LSB 0x54 /* Vcc Counter Addr (LSB) */ 262*4882a593Smuzhiyun #define RTC_BANK1_VCC_CTR_MSB 0x57 /* Vcc Counter Addr (MSB) */ 263*4882a593Smuzhiyun #define RTC_BANK1_VBAT_CTR_LSB 0x58 /* Vbat Counter Addr (LSB) */ 264*4882a593Smuzhiyun #define RTC_BANK1_VBAT_CTR_MSB 0x5b /* Vbat Counter Addr (MSB) */ 265*4882a593Smuzhiyun #define RTC_BANK1_PWR_CTR_LSB 0x5c /* Pwr Cycle Counter Addr (LSB) */ 266*4882a593Smuzhiyun #define RTC_BANK1_PWR_CTR_MSB 0x5d /* Pwr Cycle Counter Addr (MSB) */ 267*4882a593Smuzhiyun #define RTC_BANK1_UNIQ_SN 0x60 /* Customer-specific S/N */ 268*4882a593Smuzhiyun #else /* DS17x85/DS17x87 */ 269*4882a593Smuzhiyun #define RTC_BANK1_RAM_ADDR_LSB 0x50 /* NV-SRAM Addr (LSB) */ 270*4882a593Smuzhiyun #define RTC_BANK1_RAM_ADDR_MSB 0x51 /* NV-SRAM Addr (MSB) */ 271*4882a593Smuzhiyun #define RTC_BANK1_WRITE_CTR 0x5e /* RTC Write Counter */ 272*4882a593Smuzhiyun #endif 273*4882a593Smuzhiyun 274*4882a593Smuzhiyun 275*4882a593Smuzhiyun /* 276*4882a593Smuzhiyun * Model numbers. 277*4882a593Smuzhiyun * 278*4882a593Smuzhiyun * The DS1688/DS1691 and DS1689/DS1693 chips share the same model number 279*4882a593Smuzhiyun * and the manual doesn't indicate any major differences. As such, they 280*4882a593Smuzhiyun * are regarded as the same chip in this driver. 281*4882a593Smuzhiyun */ 282*4882a593Smuzhiyun #define RTC_MODEL_DS1685 0x71 /* DS1685/DS1687 */ 283*4882a593Smuzhiyun #define RTC_MODEL_DS17285 0x72 /* DS17285/DS17287 */ 284*4882a593Smuzhiyun #define RTC_MODEL_DS1689 0x73 /* DS1688/DS1691/DS1689/DS1693 */ 285*4882a593Smuzhiyun #define RTC_MODEL_DS17485 0x74 /* DS17485/DS17487 */ 286*4882a593Smuzhiyun #define RTC_MODEL_DS17885 0x78 /* DS17885/DS17887 */ 287*4882a593Smuzhiyun 288*4882a593Smuzhiyun 289*4882a593Smuzhiyun /* 290*4882a593Smuzhiyun * Periodic Interrupt Rates / Square-Wave Output Frequency 291*4882a593Smuzhiyun * 292*4882a593Smuzhiyun * Periodic rates are selected by setting the RS3-RS0 bits in Control 293*4882a593Smuzhiyun * Register A and enabled via either the E32K bit in Extended Control 294*4882a593Smuzhiyun * Register 4B or the SQWE bit in Control Register B. 295*4882a593Smuzhiyun * 296*4882a593Smuzhiyun * E32K overrides the settings of RS3-RS0 and outputs a frequency of 32768Hz 297*4882a593Smuzhiyun * on the SQW pin of the RTC chip. While there are 16 possible selections, 298*4882a593Smuzhiyun * the 1-of-16 decoder is only able to divide the base 32768Hz signal into 13 299*4882a593Smuzhiyun * smaller frequencies. The values 0x01 and 0x02 are not used and are 300*4882a593Smuzhiyun * synonymous with 0x08 and 0x09, respectively. 301*4882a593Smuzhiyun * 302*4882a593Smuzhiyun * When E32K is set to a logic 1, periodic interrupts are disabled and reading 303*4882a593Smuzhiyun * /dev/rtc will return -EINVAL. This also applies if the periodic interrupt 304*4882a593Smuzhiyun * frequency is set to 0Hz. 305*4882a593Smuzhiyun * 306*4882a593Smuzhiyun * Not currently used by the rtc-ds1685 driver because the RTC core removed 307*4882a593Smuzhiyun * support for hardware-generated periodic-interrupts in favour of 308*4882a593Smuzhiyun * hrtimer-generated interrupts. But these defines are kept around for use 309*4882a593Smuzhiyun * in userland, as documentation to the hardware, and possible future use if 310*4882a593Smuzhiyun * hardware-generated periodic interrupts are ever added back. 311*4882a593Smuzhiyun */ 312*4882a593Smuzhiyun /* E32K RS3 RS2 RS1 RS0 */ 313*4882a593Smuzhiyun #define RTC_SQW_8192HZ 0x03 /* 0 0 0 1 1 */ 314*4882a593Smuzhiyun #define RTC_SQW_4096HZ 0x04 /* 0 0 1 0 0 */ 315*4882a593Smuzhiyun #define RTC_SQW_2048HZ 0x05 /* 0 0 1 0 1 */ 316*4882a593Smuzhiyun #define RTC_SQW_1024HZ 0x06 /* 0 0 1 1 0 */ 317*4882a593Smuzhiyun #define RTC_SQW_512HZ 0x07 /* 0 0 1 1 1 */ 318*4882a593Smuzhiyun #define RTC_SQW_256HZ 0x08 /* 0 1 0 0 0 */ 319*4882a593Smuzhiyun #define RTC_SQW_128HZ 0x09 /* 0 1 0 0 1 */ 320*4882a593Smuzhiyun #define RTC_SQW_64HZ 0x0a /* 0 1 0 1 0 */ 321*4882a593Smuzhiyun #define RTC_SQW_32HZ 0x0b /* 0 1 0 1 1 */ 322*4882a593Smuzhiyun #define RTC_SQW_16HZ 0x0c /* 0 1 1 0 0 */ 323*4882a593Smuzhiyun #define RTC_SQW_8HZ 0x0d /* 0 1 1 0 1 */ 324*4882a593Smuzhiyun #define RTC_SQW_4HZ 0x0e /* 0 1 1 1 0 */ 325*4882a593Smuzhiyun #define RTC_SQW_2HZ 0x0f /* 0 1 1 1 1 */ 326*4882a593Smuzhiyun #define RTC_SQW_0HZ 0x00 /* 0 0 0 0 0 */ 327*4882a593Smuzhiyun #define RTC_SQW_32768HZ 32768 /* 1 - - - - */ 328*4882a593Smuzhiyun #define RTC_MAX_USER_FREQ 8192 329*4882a593Smuzhiyun 330*4882a593Smuzhiyun 331*4882a593Smuzhiyun /* 332*4882a593Smuzhiyun * NVRAM data & addresses: 333*4882a593Smuzhiyun * - 50 bytes of NVRAM are available just past the clock registers. 334*4882a593Smuzhiyun * - 64 additional bytes are available in Bank0. 335*4882a593Smuzhiyun * 336*4882a593Smuzhiyun * Extended, battery-backed NV-SRAM: 337*4882a593Smuzhiyun * - DS1685/DS1687 - 128 bytes. 338*4882a593Smuzhiyun * - DS1689/DS1693 - 0 bytes. 339*4882a593Smuzhiyun * - DS17285/DS17287 - 2048 bytes. 340*4882a593Smuzhiyun * - DS17485/DS17487 - 4096 bytes. 341*4882a593Smuzhiyun * - DS17885/DS17887 - 8192 bytes. 342*4882a593Smuzhiyun */ 343*4882a593Smuzhiyun #define NVRAM_TIME_BASE 0x0e /* NVRAM Addr in Time regs */ 344*4882a593Smuzhiyun #define NVRAM_BANK0_BASE 0x40 /* NVRAM Addr in Bank0 regs */ 345*4882a593Smuzhiyun #define NVRAM_SZ_TIME 50 346*4882a593Smuzhiyun #define NVRAM_SZ_BANK0 64 347*4882a593Smuzhiyun #if defined(CONFIG_RTC_DRV_DS1685) 348*4882a593Smuzhiyun # define NVRAM_SZ_EXTND 128 349*4882a593Smuzhiyun #elif defined(CONFIG_RTC_DRV_DS1689) 350*4882a593Smuzhiyun # define NVRAM_SZ_EXTND 0 351*4882a593Smuzhiyun #elif defined(CONFIG_RTC_DRV_DS17285) 352*4882a593Smuzhiyun # define NVRAM_SZ_EXTND 2048 353*4882a593Smuzhiyun #elif defined(CONFIG_RTC_DRV_DS17485) 354*4882a593Smuzhiyun # define NVRAM_SZ_EXTND 4096 355*4882a593Smuzhiyun #elif defined(CONFIG_RTC_DRV_DS17885) 356*4882a593Smuzhiyun # define NVRAM_SZ_EXTND 8192 357*4882a593Smuzhiyun #endif 358*4882a593Smuzhiyun #define NVRAM_TOTAL_SZ_BANK0 (NVRAM_SZ_TIME + NVRAM_SZ_BANK0) 359*4882a593Smuzhiyun #define NVRAM_TOTAL_SZ (NVRAM_TOTAL_SZ_BANK0 + NVRAM_SZ_EXTND) 360*4882a593Smuzhiyun 361*4882a593Smuzhiyun 362*4882a593Smuzhiyun /* 363*4882a593Smuzhiyun * Function Prototypes. 364*4882a593Smuzhiyun */ 365*4882a593Smuzhiyun extern void __noreturn 366*4882a593Smuzhiyun ds1685_rtc_poweroff(struct platform_device *pdev); 367*4882a593Smuzhiyun 368*4882a593Smuzhiyun #endif /* _LINUX_RTC_DS1685_H_ */ 369