MFC: r201005, r201371

- Take advantage of bus_{read,write}_*(9).
- Set dow = -1 in mk48txx_gettime() because some drivers (for example
  the NetBSD and OpenBSD mk48txx(4)) don't set it correctly.
This commit is contained in:
Marius Strobl 2010-01-15 15:47:31 +00:00
parent 1051ec0b8a
commit 2a2cbae7cb
3 changed files with 17 additions and 11 deletions

View file

@ -43,6 +43,7 @@ __FBSDID("$FreeBSD$");
#include <sys/eventhandler.h>
#include <sys/lock.h>
#include <sys/mutex.h>
#include <sys/rman.h>
#include <sys/watchdog.h>
#include <machine/bus.h>
@ -175,8 +176,16 @@ mk48txx_gettime(device_t dev, struct timespec *ts)
ct.min = FROMBCD(FROMREG(MK48TXX_IMIN, MK48TXX_MIN_MASK));
ct.hour = FROMBCD(FROMREG(MK48TXX_IHOUR, MK48TXX_HOUR_MASK));
ct.day = FROMBCD(FROMREG(MK48TXX_IDAY, MK48TXX_DAY_MASK));
#if 0
/* Map dow from 1 - 7 to 0 - 6; FROMBCD() isn't necessary here. */
ct.dow = FROMREG(MK48TXX_IWDAY, MK48TXX_WDAY_MASK) - 1;
#else
/*
* Set dow = -1 because some drivers (for example the NetBSD and
* OpenBSD mk48txx(4)) don't set it correctly.
*/
ct.dow = -1;
#endif
ct.mon = FROMBCD(FROMREG(MK48TXX_IMON, MK48TXX_MON_MASK));
year = FROMBCD(FROMREG(MK48TXX_IYEAR, MK48TXX_YEAR_MASK));
year += sc->sc_year0;
@ -266,7 +275,7 @@ mk48txx_def_nvrd(device_t dev, int off)
struct mk48txx_softc *sc;
sc = device_get_softc(dev);
return (bus_space_read_1(sc->sc_bst, sc->sc_bsh, off));
return (bus_read_1(sc->sc_res, off));
}
static void
@ -275,7 +284,7 @@ mk48txx_def_nvwr(device_t dev, int off, uint8_t v)
struct mk48txx_softc *sc;
sc = device_get_softc(dev);
bus_space_write_1(sc->sc_bst, sc->sc_bsh, off, v);
bus_write_1(sc->sc_res, off, v);
}
static void

View file

@ -35,8 +35,7 @@ typedef uint8_t (*mk48txx_nvrd_t)(device_t dev, int off);
typedef void (*mk48txx_nvwr_t)(device_t dev, int off, uint8_t v);
struct mk48txx_softc {
bus_space_tag_t sc_bst; /* bus space tag */
bus_space_handle_t sc_bsh; /* bus space handle */
struct resource *sc_res;/* bus resource */
struct mtx sc_mtx; /* hardware mutex */
eventhandler_tag sc_wet; /* watchdog event handler tag */

View file

@ -107,7 +107,7 @@ DRIVER_MODULE(eeprom, sbus, eeprom_driver, eeprom_devclass, 0, 0);
static int
eeprom_probe(device_t dev)
{
if (strcmp("eeprom", ofw_bus_get_name(dev)) == 0) {
device_set_desc(dev, "EEPROM/clock");
return (0);
@ -119,7 +119,6 @@ static int
eeprom_attach(device_t dev)
{
struct mk48txx_softc *sc;
struct resource *res;
struct timespec ts;
int error, rid;
@ -128,14 +127,13 @@ eeprom_attach(device_t dev)
mtx_init(&sc->sc_mtx, "eeprom_mtx", NULL, MTX_DEF);
rid = 0;
res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid, RF_ACTIVE);
if (res == NULL) {
sc->sc_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid,
RF_ACTIVE);
if (sc->sc_res == NULL) {
device_printf(dev, "cannot allocate resources\n");
error = ENXIO;
goto fail_mtx;
}
sc->sc_bst = rman_get_bustag(res);
sc->sc_bsh = rman_get_bushandle(res);
if ((sc->sc_model = ofw_bus_get_model(dev)) == NULL) {
device_printf(dev, "cannot determine model\n");
@ -180,7 +178,7 @@ eeprom_attach(device_t dev)
return (0);
fail_res:
bus_release_resource(dev, SYS_RES_MEMORY, rid, res);
bus_release_resource(dev, SYS_RES_MEMORY, rid, sc->sc_res);
fail_mtx:
mtx_destroy(&sc->sc_mtx);