FreeBSD Bugzilla – Attachment 155663 Details for
Bug 199496
Patch for pcf8563 (driver update)
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
patch
pcf8536-rpi-patch-4.txt (text/plain), 4.34 KB, created by
Juraj Lutter
on 2015-04-17 07:20:51 UTC
(
hide
)
Description:
patch
Filename:
MIME Type:
Creator:
Juraj Lutter
Created:
2015-04-17 07:20:51 UTC
Size:
4.34 KB
patch
obsolete
>Index: pcf8563.c >=================================================================== >--- pcf8563.c (revision 281616) >+++ pcf8563.c (working copy) >@@ -1,5 +1,6 @@ > /*- > * Copyright (c) 2012 Marius Strobl <marius@FreeBSD.org> >+ * Copyright (c) 2015 Juraj Lutter <otis@sk.FreeBSD.org> > * All rights reserved. > * > * Redistribution and use in source and binary forms, with or without >@@ -31,6 +32,8 @@ > * Driver for NXP PCF8563 real-time clock/calendar > */ > >+#include "opt_platform.h" >+ > #include <sys/param.h> > #include <sys/systm.h> > #include <sys/bus.h> >@@ -41,6 +44,11 @@ > #include <dev/iicbus/iicbus.h> > #include <dev/iicbus/iiconf.h> > #include <dev/iicbus/pcf8563reg.h> >+#ifdef FDT >+#include <dev/ofw/openfirm.h> >+#include <dev/ofw/ofw_bus.h> >+#include <dev/ofw/ofw_bus_subr.h> >+#endif > > #include "clock_if.h" > #include "iicbus_if.h" >@@ -48,6 +56,8 @@ > #define PCF8563_NCLOCKREGS (PCF8563_R_YEAR - PCF8563_R_CS1 + 1) > > struct pcf8563_softc { >+ device_t sc_dev; >+ struct intr_config_hook enum_hook; > uint32_t sc_flags; > #define PCF8563_CPOL (1 << 0) /* PCF8563_R_MONTH_C means 19xx */ > uint16_t sc_addr; /* PCF8563 slave address */ >@@ -59,17 +69,50 @@ > static clock_gettime_t pcf8563_gettime; > static clock_settime_t pcf8563_settime; > >+static void pcf8563_start(void *); >+ > static int > pcf8563_probe(device_t dev) > { > >+#ifdef FDT >+ if (!ofw_bus_status_okay(dev)) >+ return (ENXIO); >+ if (!ofw_bus_is_compatible(dev, "nxp,pcf8563") && >+ !ofw_bus_is_compatible(dev, "philips,pcf8563") && >+ !ofw_bus_is_compatible(dev, "pcf8563")) >+ return (ENXIO); >+#endif > device_set_desc(dev, "NXP PCF8563 RTC"); >- return (BUS_PROBE_NOWILDCARD); >+ return (BUS_PROBE_DEFAULT); > } > > static int > pcf8563_attach(device_t dev) > { >+ struct pcf8563_softc *sc; >+ >+ sc = device_get_softc(dev); >+ sc->sc_dev = dev; >+ sc->sc_addr = iicbus_get_addr(dev); >+ sc->sc_year0 = 1900; >+ sc->enum_hook.ich_func = pcf8563_start; >+ sc->enum_hook.ich_arg = dev; >+ >+ /* >+ * We have to wait until interrupts are enabled. Usually I2C read >+ * and write only works when the interrupts are available. >+ */ >+ if (config_intrhook_establish(&sc->enum_hook) != 0) >+ return (ENOMEM); >+ >+ >+ return (0); >+} >+ >+static void >+pcf8563_start(void *xdev) >+{ > uint8_t reg = PCF8563_R_SECOND, val; > struct iic_msg msgs[] = { > { 0, IIC_M_WR, sizeof(reg), ® }, >@@ -76,13 +119,16 @@ > { 0, IIC_M_RD, sizeof(val), &val } > }; > struct pcf8563_softc *sc; >+ device_t dev; > int error; > >+ dev = (device_t)xdev; > sc = device_get_softc(dev); >- sc->sc_addr = iicbus_get_addr(dev); > if (sc->sc_addr == 0) > sc->sc_addr = PCF8563_ADDR; > >+ config_intrhook_disestablish(&sc->enum_hook); >+ > /* > * NB: PCF8563_R_SECOND_VL doesn't automatically clear when VDD > * rises above Vlow again and needs to be cleared manually. >@@ -94,18 +140,16 @@ > * as a side-effect. > */ > msgs[0].slave = msgs[1].slave = sc->sc_addr; >- error = iicbus_transfer(device_get_parent(dev), msgs, sizeof(msgs) / >- sizeof(*msgs)); >+ error = iicbus_transfer(device_get_parent(dev), msgs, nitems(msgs)); > if (error != 0) { > device_printf(dev, "%s: cannot read RTC\n", __func__); >- return (error); >+ return; > } > if ((val & PCF8563_R_SECOND_VL) != 0) > device_printf(dev, "%s: battery low\n", __func__); > >- sc->sc_year0 = 1900; > clock_register(dev, 1000000); /* 1 second resolution */ >- return (0); >+ return; > } > > static int >@@ -122,8 +166,7 @@ > > sc = device_get_softc(dev); > msgs[0].slave = msgs[1].slave = sc->sc_addr; >- error = iicbus_transfer(device_get_parent(dev), msgs, sizeof(msgs) / >- sizeof(*msgs)); >+ error = iicbus_transfer(dev, msgs, nitems(msgs)); > if (error != 0) { > device_printf(dev, "%s: cannot read RTC\n", __func__); > return (error); >@@ -145,6 +188,8 @@ > sc->sc_flags |= PCF8563_CPOL; > } else if (ct.year < 100 + sc->sc_year0) > sc->sc_flags |= PCF8563_CPOL; >+ if (bootverbose) >+ device_printf(dev, "Date and time from RTC: (Day %d (Day of week %d) Month %d Year %d Hour %d Minute %d Second %d) \n", ct.day, ct.dow, ct.mon, ct.year, ct.hour, ct.min, ct.sec); > return (clock_ct_to_ts(&ct, ts)); > } > >@@ -180,8 +225,7 @@ > val[PCF8563_R_MONTH] |= PCF8563_R_MONTH_C; > > msgs[0].slave = sc->sc_addr; >- error = iicbus_transfer(device_get_parent(dev), msgs, sizeof(msgs) / >- sizeof(*msgs)); >+ error = iicbus_transfer(dev, msgs, nitems(msgs)); > if (error != 0) > device_printf(dev, "%s: cannot write RTC\n", __func__); > return (error);
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 199496
: 155663