summaryrefslogtreecommitdiffstats
path: root/sys/pci/alpm.c
diff options
context:
space:
mode:
authornsouch <nsouch@FreeBSD.org>2001-01-02 21:19:32 +0000
committernsouch <nsouch@FreeBSD.org>2001-01-02 21:19:32 +0000
commit9c04e548706bbf146959103a7688790e78e87e27 (patch)
tree92be442cb2d0660baec96f95064791f70ef0ea11 /sys/pci/alpm.c
parentc0bd1292218f26528657aa0ac9393c87bf68c3de (diff)
downloadFreeBSD-src-9c04e548706bbf146959103a7688790e78e87e27.zip
FreeBSD-src-9c04e548706bbf146959103a7688790e78e87e27.tar.gz
Remove old PCI compatibility.
Submitted by: Andrew Gallatin <gallatin@freebsd.org>
Diffstat (limited to 'sys/pci/alpm.c')
-rw-r--r--sys/pci/alpm.c134
1 files changed, 77 insertions, 57 deletions
diff --git a/sys/pci/alpm.c b/sys/pci/alpm.c
index 315bdec..673e964 100644
--- a/sys/pci/alpm.c
+++ b/sys/pci/alpm.c
@@ -1,5 +1,5 @@
/*-
- * Copyright (c) 1998, 1999 Nicolas Souchu
+ * Copyright (c) 1998, 1999, 2001 Nicolas Souchu
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -41,6 +41,8 @@
#include <machine/bus_pio.h>
#include <machine/bus_memio.h>
#include <machine/bus.h>
+#include <machine/resource.h>
+#include <sys/rman.h>
#include <pci/pcivar.h>
#include <pci/pcireg.h>
@@ -51,10 +53,6 @@
#include "alpm.h"
-#ifndef COMPAT_OLDPCI
-#error "The alpm device requires the old pci compatibility shims"
-#endif
-
#define ALPM_DEBUG(x) if (alpm_debug) (x)
#ifdef DEBUG
@@ -110,7 +108,7 @@ static int alpm_debug = 0;
#define SMBBA 0x14
#define ATPC 0x5b
-#define ATPC_SMBCTRL 0x04
+#define ATPC_SMBCTRL 0x04 /* XX linux has this as 0x6 */
#define SMBHSI 0xe0
#define SMBHSI_SLAVE 0x2
@@ -130,9 +128,7 @@ struct alpm_data {
int base;
bus_space_tag_t smbst;
bus_space_handle_t smbsh;
- pcici_t tag;
};
-struct alpm_data alpmdata[NALPM];
struct alsmb_softc {
int base;
@@ -189,55 +185,69 @@ static driver_t alsmb_driver = {
sizeof(struct alsmb_softc),
};
-static const char* alpm_pci_probe(pcici_t tag, pcidi_t type);
-static void alpm_pci_attach(pcici_t tag, int unit);
+static int alpm_pci_probe(device_t dev);
+static int alpm_pci_attach(device_t dev);
-static u_long alpm_count;
+static devclass_t alpm_devclass;
+
+static device_method_t alpm_pci_methods[] = {
+ /* device interface */
+ DEVMETHOD(device_probe, alpm_pci_probe),
+ DEVMETHOD(device_attach, alpm_pci_attach),
+
+ { 0, 0 }
+};
-static struct pci_device alpm_device = {
+static driver_t alpm_pci_driver = {
"alpm",
- alpm_pci_probe,
- alpm_pci_attach,
- &alpm_count
+ alpm_pci_methods,
+ sizeof(struct alpm_data)
};
-COMPAT_PCI_DRIVER (alpm, alpm_device);
-static const char*
-alpm_pci_probe(pcici_t tag, pcidi_t type)
+static int
+alpm_pci_probe(device_t dev)
{
- if (type == ACER_M1543_PMU_ID)
- return ("AcerLabs M15x3 Power Management Unit");
-
- return ((char *)0);
+ if (pci_get_devid(dev) == ACER_M1543_PMU_ID) {
+ device_set_desc(dev,
+ "AcerLabs M15x3 Power Management Unit");
+ return 0;
+ } else {
+ return ENXIO;
+ }
}
-static void
-alpm_pci_attach(pcici_t tag, int unit)
+static int
+alpm_pci_attach(device_t dev)
{
+ int rid, unit;
+ u_int32_t l;
struct alpm_data *alpm;
- u_long l;
+ struct resource *res;
+ device_t smbinterface;
- if (unit >= NALPM) {
- printf("alpm%d: attach: only %d units configured.\n",
- unit, NALPM);
- return;
- }
- alpm = &alpmdata[unit];
-
- alpm->tag = tag;
+ alpm = device_get_softc(dev);
+ unit = device_get_unit(dev);
/* Unlock SMBIO base register access */
- l = pci_cfgread(tag, ATPC, 1);
- pci_cfgwrite(tag, ATPC, l & ~ATPC_SMBCTRL, 1);
+ l = pci_read_config(dev, ATPC, 1);
+ pci_write_config(dev, ATPC, l & ~ATPC_SMBCTRL, 1);
+
+ /*
+ * XX linux sets clock to 74k, should we?
+ l = pci_read_config(dev, SMBHCBC, 1);
+ l &= 0x1f;
+ l |= SMBCLOCK_74K;
+ pci_write_config(dev, SMBHCBC, l, 1);
+ */
if (bootverbose) {
- l = pci_cfgread(tag, SMBHSI, 1);
+ l = pci_read_config(dev, SMBHSI, 1);
printf("alsmb%d: %s/%s", unit,
(l & SMBHSI_HOST) ? "host":"nohost",
(l & SMBHSI_SLAVE) ? "slave":"noslave");
- l = pci_cfgread(tag, SMBHCBC, 1);
+ l = pci_read_config(dev, SMBHCBC, 1);
switch (l & SMBHCBC_CLOCK) {
case SMBCLOCK_149K:
printf(" 149K");
@@ -260,30 +270,38 @@ alpm_pci_attach(pcici_t tag, int unit)
}
}
- alpm->smbst = I386_BUS_SPACE_IO;
-
#ifdef ALPM_SMBIO_BASE_ADDR
+ /* XX will this even work anymore? */
/* disable I/O */
- l = pci_cfgread(tag, COM, 2);
- pci_cfgwrite(tag, COM, l & ~COM_ENABLE_IO, 2);
+ l = pci_read_config(dev, COM, 2);
+ pci_write_config(dev, COM, l & ~COM_ENABLE_IO, 2);
/* set the I/O base address */
- pci_cfgwrite(tag, SMBBA, ALPM_SMBIO_BASE_ADDR | 0x1, 4);
+ pci_write_config(dev, SMBBA, ALPM_SMBIO_BASE_ADDR | 0x1, 4);
/* enable I/O */
- pci_cfgwrite(tag, COM, l | COM_ENABLE_IO, 2);
+ pci_write_config(dev, COM, l | COM_ENABLE_IO, 2);
- alpm->smbsh = ALPM_SMBIO_BASE_ADDR;
-#else
- alpm->smbsh = pci_cfgread(tag, SMBBA, 4) & ~0x1;
#endif
+ rid = SMBBA;
+ res = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid,
+ 0,~0,1,RF_ACTIVE);
+ if (res == NULL) {
+ device_printf(dev,"Could not allocate Bus space\n");
+ return ENXIO;
+ }
+ alpm->smbst = rman_get_bustag(res);
+ alpm->smbsh = rman_get_bushandle(res);
+
if (bootverbose)
printf(" at 0x%x\n", alpm->smbsh);
-
- /* XXX add the I2C interface to the root_bus until pcibus is ready */
- device_add_child(root_bus, "alsmb", unit);
-
- return;
+
+ smbinterface = device_add_child(dev, "alsmb", unit);
+ if (!smbinterface)
+ device_printf(dev, "could not add SMBus device\n");
+ else
+ device_probe_and_attach(smbinterface);
+ return 0;
}
/*
@@ -295,8 +313,10 @@ alsmb_probe(device_t dev)
{
struct alsmb_softc *sc = (struct alsmb_softc *)device_get_softc(dev);
- sc->alpm = &alpmdata[device_get_unit(dev)];
-
+ /* allocate a new smbus device */
+ sc->smbus = smbus_alloc_bus(dev);
+ if (!sc->smbus)
+ return (EINVAL);
device_set_desc(dev, "Aladdin IV/V/Pro2 SMBus controller");
return (0);
@@ -307,8 +327,7 @@ alsmb_attach(device_t dev)
{
struct alsmb_softc *sc = (struct alsmb_softc *)device_get_softc(dev);
- /* allocate a new smbus device */
- sc->smbus = smbus_alloc_bus(dev);
+ sc->alpm = device_get_softc(device_get_parent(dev));
/* probe and attach the smbus */
device_probe_and_attach(sc->smbus);
@@ -371,7 +390,7 @@ static int
alsmb_wait(struct alsmb_softc *sc)
{
int count = 10000;
- u_char sts;
+ u_char sts = 0;
int error;
/* wait for command to complete and SMBus controller is idle */
@@ -663,4 +682,5 @@ error:
return (error);
}
-DRIVER_MODULE(alsmb, root, alsmb_driver, alsmb_devclass, 0, 0);
+DRIVER_MODULE(alpm, pci, alpm_pci_driver, alpm_devclass, 0, 0);
+DRIVER_MODULE(alsmb, alpm, alsmb_driver, alsmb_devclass, 0, 0);
OpenPOWER on IntegriCloud