Deleted Added
sdiff udiff text old ( 166914 ) new ( 202870 )
full compact
1/*-
2 * Copyright (c) 2005 Poul-Henning Kamp <phk@FreeBSD.org>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright

--- 17 unchanged lines hidden (view full) ---

28 * This driver just hooks up to the hardware and leaves all the interesting
29 * stuff to upd7210.c.
30 *
31 * Supported hardware:
32 * PCIIA compatible cards.
33 *
34 * Tested and known working:
35 * "B&C Microsystems PC488A-0"
36 *
37 */
38
39#include <sys/cdefs.h>
40__FBSDID("$FreeBSD: head/sys/dev/ieee488/pcii.c 166914 2007-02-23 19:34:52Z imp $");
41
42#include <sys/param.h>
43#include <sys/systm.h>
44#include <sys/lock.h>
45#include <sys/mutex.h>
46#include <sys/kernel.h>
47#include <sys/module.h>
48#include <sys/bus.h>
49#include <machine/bus.h>
50#include <machine/resource.h>
51#include <sys/rman.h>
52#include <isa/isavar.h>
53
54#define UPD7210_HW_DRIVER
55#include <dev/ieee488/upd7210.h>
56
57struct pcii_softc {
58 int foo;
59 struct resource *res[3];
60 void *intr_handler;
61 struct upd7210 upd7210;
62};
63
64static devclass_t pcii_devclass;
65
66static int pcii_probe(device_t dev);
67static int pcii_attach(device_t dev);

--- 6 unchanged lines hidden (view full) ---

74
75 { 0, 0 }
76};
77
78static struct resource_spec pcii_res_spec[] = {
79 { SYS_RES_IRQ, 0, RF_ACTIVE | RF_SHAREABLE},
80 { SYS_RES_DRQ, 0, RF_ACTIVE | RF_SHAREABLE | RF_OPTIONAL},
81 { SYS_RES_IOPORT, 0, RF_ACTIVE},
82 { -1, 0, 0 }
83};
84
85static driver_t pcii_driver = {
86 "pcii",
87 pcii_methods,
88 sizeof(struct pcii_softc),
89};
90
91static int
92pcii_probe(device_t dev)
93{
94 int rid, i, j;
95 u_long start, count;
96 int error = 0;
97 struct pcii_softc *sc;
98
99 device_set_desc(dev, "PCII IEEE-4888 controller");
100 sc = device_get_softc(dev);
101
102 rid = 0;
103 if (bus_get_resource(dev, SYS_RES_IOPORT, rid, &start, &count) != 0)
104 return ENXIO;
105 if ((start & 0x3ff) != 0x2e1)
106 return (ENXIO);
107 count = 1;
108 if (bus_set_resource(dev, SYS_RES_IOPORT, rid, start, count) != 0)
109 return ENXIO;
110 error = bus_alloc_resources(dev, pcii_res_spec, sc->res);
111 if (error)
112 return (error);
113 error = ENXIO;
114 for (i = 0; i < 8; i++) {
115 j = bus_read_1(sc->res[2], i * 0x400);
116 if (j != 0x00 && j != 0xff)
117 error = 0;
118 }
119 if (!error) {
120 bus_write_1(sc->res[2], 3 * 0x400, 0x55);
121 if (bus_read_1(sc->res[2], 3 * 0x400) != 0x55)
122 error = ENXIO;
123 }
124 if (!error) {
125 bus_write_1(sc->res[2], 3 * 0x400, 0xaa);
126 if (bus_read_1(sc->res[2], 3 * 0x400) != 0xaa)
127 error = ENXIO;
128 }
129 bus_release_resources(dev, pcii_res_spec, sc->res);
130 return (error);
131}
132
133static int
134pcii_attach(device_t dev)
135{
136 struct pcii_softc *sc;
137 int unit;
138 int rid;
139 int error = 0;
140
141 unit = device_get_unit(dev);
142 sc = device_get_softc(dev);
143 memset(sc, 0, sizeof *sc);
144
145 device_set_desc(dev, "PCII IEEE-4888 controller");
146
147 error = bus_alloc_resources(dev, pcii_res_spec, sc->res);
148 if (error)
149 return (error);
150
151 error = bus_setup_intr(dev, sc->res[0],
152 INTR_TYPE_MISC | INTR_MPSAFE, NULL,
153 upd7210intr, &sc->upd7210, &sc->intr_handler);
154 if (error) {
155 bus_release_resources(dev, pcii_res_spec, sc->res);
156 return (error);
157 }
158
159 for (rid = 0; rid < 8; rid++) {
160 sc->upd7210.reg_res[rid] = sc->res[2];
161 sc->upd7210.reg_offset[rid] = 0x400 * rid;
162 }
163
164 if (sc->res[1] == NULL)
165 sc->upd7210.dmachan = -1;
166 else
167 sc->upd7210.dmachan = rman_get_start(sc->res[1]);
168
169 upd7210attach(&sc->upd7210);
170 return (error);
171}
172
173DRIVER_MODULE(pcii, isa, pcii_driver, pcii_devclass, 0, 0);
174DRIVER_MODULE(pcii, acpi, pcii_driver, pcii_devclass, 0, 0);