Thu Dec 20 21:36:53 2018 UTC ()
make DSRTC_FLAG_YEAR_START_2K settable by device property


(macallan)
diff -r1.30 -r1.31 src/sys/dev/i2c/ds1307.c

cvs diff -r1.30 -r1.31 src/sys/dev/i2c/ds1307.c (expand / switch to unified diff)

--- src/sys/dev/i2c/ds1307.c 2018/12/14 22:05:36 1.30
+++ src/sys/dev/i2c/ds1307.c 2018/12/20 21:36:53 1.31
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: ds1307.c,v 1.30 2018/12/14 22:05:36 macallan Exp $ */ 1/* $NetBSD: ds1307.c,v 1.31 2018/12/20 21:36:53 macallan Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 2003 Wasabi Systems, Inc. 4 * Copyright (c) 2003 Wasabi Systems, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Written by Steve C. Woodford and Jason R. Thorpe for Wasabi Systems, Inc. 7 * Written by Steve C. Woodford and Jason R. Thorpe for Wasabi Systems, Inc.
8 * 8 *
9 * Redistribution and use in source and binary forms, with or without 9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions 10 * modification, are permitted provided that the following conditions
11 * are met: 11 * are met:
12 * 1. Redistributions of source code must retain the above copyright 12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer. 13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright 14 * 2. Redistributions in binary form must reproduce the above copyright
@@ -26,27 +26,27 @@ @@ -26,27 +26,27 @@
26 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 26 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
27 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 27 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC 28 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC
29 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 29 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 32 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 33 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 34 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 * POSSIBILITY OF SUCH DAMAGE. 35 * POSSIBILITY OF SUCH DAMAGE.
36 */ 36 */
37 37
38#include <sys/cdefs.h> 38#include <sys/cdefs.h>
39__KERNEL_RCSID(0, "$NetBSD: ds1307.c,v 1.30 2018/12/14 22:05:36 macallan Exp $"); 39__KERNEL_RCSID(0, "$NetBSD: ds1307.c,v 1.31 2018/12/20 21:36:53 macallan Exp $");
40 40
41#include <sys/param.h> 41#include <sys/param.h>
42#include <sys/systm.h> 42#include <sys/systm.h>
43#include <sys/device.h> 43#include <sys/device.h>
44#include <sys/kernel.h> 44#include <sys/kernel.h>
45#include <sys/fcntl.h> 45#include <sys/fcntl.h>
46#include <sys/uio.h> 46#include <sys/uio.h>
47#include <sys/conf.h> 47#include <sys/conf.h>
48#include <sys/event.h> 48#include <sys/event.h>
49 49
50#include <dev/clock_subr.h> 50#include <dev/clock_subr.h>
51 51
52#include <dev/i2c/i2cvar.h> 52#include <dev/i2c/i2cvar.h>
@@ -287,26 +287,28 @@ dsrtc_match(device_t parent, cfdata_t cf @@ -287,26 +287,28 @@ dsrtc_match(device_t parent, cfdata_t cf
287 287
288 if (dsrtc_is_valid_addr_for_model(dm, ia->ia_addr)) 288 if (dsrtc_is_valid_addr_for_model(dm, ia->ia_addr))
289 return I2C_MATCH_ADDRESS_ONLY; 289 return I2C_MATCH_ADDRESS_ONLY;
290 290
291 return 0; 291 return 0;
292} 292}
293 293
294static void 294static void
295dsrtc_attach(device_t parent, device_t self, void *arg) 295dsrtc_attach(device_t parent, device_t self, void *arg)
296{ 296{
297 struct dsrtc_softc *sc = device_private(self); 297 struct dsrtc_softc *sc = device_private(self);
298 struct i2c_attach_args *ia = arg; 298 struct i2c_attach_args *ia = arg;
299 const struct dsrtc_model *dm; 299 const struct dsrtc_model *dm;
 300 prop_dictionary_t dict = device_properties(self);
 301 bool base_2k = FALSE;
300 302
301 if ((dm = dsrtc_model_by_compat(ia)) == NULL) 303 if ((dm = dsrtc_model_by_compat(ia)) == NULL)
302 dm = dsrtc_model_by_number(device_cfdata(self)->cf_flags); 304 dm = dsrtc_model_by_number(device_cfdata(self)->cf_flags);
303 305
304 if (dm == NULL) { 306 if (dm == NULL) {
305 aprint_error(": unable to determine model!\n"); 307 aprint_error(": unable to determine model!\n");
306 return; 308 return;
307 } 309 }
308 310
309 aprint_naive(": Real-time Clock%s\n", 311 aprint_naive(": Real-time Clock%s\n",
310 dm->dm_nvram_size > 0 ? "/NVRAM" : ""); 312 dm->dm_nvram_size > 0 ? "/NVRAM" : "");
311 aprint_normal(": DS%u Real-time Clock%s\n", dm->dm_model, 313 aprint_normal(": DS%u Real-time Clock%s\n", dm->dm_model,
312 dm->dm_nvram_size > 0 ? "/NVRAM" : ""); 314 dm->dm_nvram_size > 0 ? "/NVRAM" : "");
@@ -321,26 +323,30 @@ dsrtc_attach(device_t parent, device_t s @@ -321,26 +323,30 @@ dsrtc_attach(device_t parent, device_t s
321 if (dm->dm_flags & DSRTC_FLAG_BCD) { 323 if (dm->dm_flags & DSRTC_FLAG_BCD) {
322 sc->sc_todr.todr_gettime_ymdhms = dsrtc_gettime_ymdhms; 324 sc->sc_todr.todr_gettime_ymdhms = dsrtc_gettime_ymdhms;
323 sc->sc_todr.todr_settime_ymdhms = dsrtc_settime_ymdhms; 325 sc->sc_todr.todr_settime_ymdhms = dsrtc_settime_ymdhms;
324 } else { 326 } else {
325 sc->sc_todr.todr_gettime = dsrtc_gettime_timeval; 327 sc->sc_todr.todr_gettime = dsrtc_gettime_timeval;
326 sc->sc_todr.todr_settime = dsrtc_settime_timeval; 328 sc->sc_todr.todr_settime = dsrtc_settime_timeval;
327 } 329 }
328 sc->sc_todr.todr_setwen = NULL; 330 sc->sc_todr.todr_setwen = NULL;
329 331
330#ifdef DSRTC_YEAR_START_2K 332#ifdef DSRTC_YEAR_START_2K
331 sc->sc_model.dm_flags |= DSRTC_FLAG_YEAR_START_2K; 333 sc->sc_model.dm_flags |= DSRTC_FLAG_YEAR_START_2K;
332#endif 334#endif
333 335
 336 prop_dictionary_get_bool(dict, "base_year_is_2000", &base_2k);
 337 if (base_2k) sc->sc_model.dm_flags |= DSRTC_FLAG_YEAR_START_2K;
 338
 339
334 todr_attach(&sc->sc_todr); 340 todr_attach(&sc->sc_todr);
335 if ((sc->sc_model.dm_flags & DSRTC_FLAG_TEMP) != 0) { 341 if ((sc->sc_model.dm_flags & DSRTC_FLAG_TEMP) != 0) {
336 int error; 342 int error;
337 343
338 sc->sc_sme = sysmon_envsys_create(); 344 sc->sc_sme = sysmon_envsys_create();
339 sc->sc_sme->sme_name = device_xname(self); 345 sc->sc_sme->sme_name = device_xname(self);
340 sc->sc_sme->sme_cookie = sc; 346 sc->sc_sme->sme_cookie = sc;
341 sc->sc_sme->sme_refresh = dsrtc_refresh; 347 sc->sc_sme->sme_refresh = dsrtc_refresh;
342 348
343 sc->sc_sensor.units = ENVSYS_STEMP; 349 sc->sc_sensor.units = ENVSYS_STEMP;
344 sc->sc_sensor.state = ENVSYS_SINVALID; 350 sc->sc_sensor.state = ENVSYS_SINVALID;
345 sc->sc_sensor.flags = 0; 351 sc->sc_sensor.flags = 0;
346 (void)strlcpy(sc->sc_sensor.desc, "temperature", 352 (void)strlcpy(sc->sc_sensor.desc, "temperature",