1 /* $NetBSD: pioc.c,v 1.14 2009/03/14 15:35:58 dsl Exp $ */
4 * Copyright (c) 1997 Mark Brinicombe.
5 * Copyright (c) 1997 Causality Limited.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. All advertising materials mentioning features or use of this software
17 * must display the following acknowledgement:
18 * This product includes software developed by Mark Brinicombe.
19 * 4. The name of the company nor the name of the author may be used to
20 * endorse or promote products derived from this software without specific
21 * prior written permission.
23 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
24 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
25 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26 * IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
27 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
28 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
29 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 * Peripheral I/O controller - wd, fd, com, lpt Combo chip
37 * Parent device for combo chip I/O drivers
38 * Currently supports the SMC FDC37GT66[56] controllers.
41 /*#define PIOC_DEBUG*/
43 #include <sys/cdefs.h>
44 __KERNEL_RCSID(0, "$NetBSD: pioc.c,v 1.14 2009/03/14 15:35:58 dsl Exp $");
46 #include <sys/param.h>
47 #include <sys/systm.h>
48 #include <sys/kernel.h>
49 #include <sys/device.h>
51 #include <machine/bus.h>
52 #include <arm/mainbus/mainbus.h>
53 #include <acorn32/mainbus/piocreg.h>
54 #include <acorn32/mainbus/piocvar.h>
61 * This probes and attaches the top level pioc device.
62 * It then configures any children of the pioc device.
66 * pioc softc structure.
68 * Contains the device node, bus space tag, handle and address along with
69 * other global information such as id and config registers.
73 struct device sc_dev
; /* device node */
74 bus_space_tag_t sc_iot
; /* bus tag */
75 bus_space_handle_t sc_ioh
; /* bus handle */
76 bus_addr_t sc_iobase
; /* IO base address */
77 int sc_id
; /* chip ID */
78 int sc_config
[PIOC_CM_REGS
];/* config regs */
82 * The pioc device is a parent to the com device.
83 * This means that it needs to provide a bus space tag for
86 * XXX - This is not fully tested yet.
89 extern struct bus_space mainbus_bs_tag
;
90 bus_space_tag_t comconstag
= &mainbus_bs_tag
;
92 /* Prototypes for functions */
94 static int piocmatch(struct device
*, struct cfdata
*, void *);
95 static void piocattach(struct device
*, struct device
*, void *);
96 static int piocprint(void *aux
, const char *name
);
98 static int piocsearch(struct device
*, struct cfdata
*, void *);
100 static int piocsubmatch(struct device
*, struct cfdata
*,
101 const int *, void *);
102 static void piocgetid(bus_space_tag_t iot
, bus_space_handle_t ioh
,
103 int config_entry
, int *id
, int *revision
);
105 /* device attach and driver structure */
107 CFATTACH_DECL(pioc
, sizeof(struct pioc_softc
),
108 piocmatch
, piocattach
, NULL
, NULL
);
111 * void piocgetid(bus_space_tag_t iot, bus_space_handle_t ioh,
112 * int config_entry, int *id, int *revision)
114 * Enter config mode and return the id and revision
118 piocgetid(bus_space_tag_t iot
, bus_space_handle_t ioh
, int config_entry
, int *id
, int *revision
)
121 * Put the chip info configuration mode and read the ID and revision
123 bus_space_write_1(iot
, ioh
, PIOC_CM_SELECT_REG
, config_entry
);
124 bus_space_write_1(iot
, ioh
, PIOC_CM_SELECT_REG
, config_entry
);
126 bus_space_write_1(iot
, ioh
, PIOC_CM_SELECT_REG
, PIOC_CM_CRD
);
127 *id
= bus_space_read_1(iot
, ioh
, PIOC_CM_DATA_REG
);
128 bus_space_write_1(iot
, ioh
, PIOC_CM_SELECT_REG
, PIOC_CM_CRE
);
129 *revision
= bus_space_read_1(iot
, ioh
, PIOC_CM_DATA_REG
);
131 bus_space_write_1(iot
, ioh
, PIOC_CM_SELECT_REG
, PIOC_CM_EXIT
);
135 * int piocmatch(struct device *parent, struct cfdata *cf, void *aux)
137 * Put the controller into config mode and probe the ID to see if
140 * XXX - INTRUSIVE PROBE
144 piocmatch(struct device
*parent
, struct cfdata
*cf
, void *aux
)
146 struct mainbus_attach_args
*mb
= aux
;
148 bus_space_handle_t ioh
;
152 /* We need a base address */
153 if (mb
->mb_iobase
== MAINBUSCF_BASE_DEFAULT
)
157 if (bus_space_map(iot
, mb
->mb_iobase
, PIOC_SIZE
, 0, &ioh
))
160 mb
->mb_iosize
= PIOC_SIZE
;
162 piocgetid(iot
, ioh
, PIOC_CM_ENTER_665
, &id
, &rev
);
163 if (id
== PIOC_CM_ID_665
)
166 piocgetid(iot
, ioh
, PIOC_CM_ENTER_666
, &id
, &rev
);
167 if (id
== PIOC_CM_ID_666
)
173 bus_space_unmap(iot
, ioh
, PIOC_SIZE
);
178 * int piocprint(void *aux, const char *name)
180 * print routine used during child configuration
184 piocprint(void *aux
, const char *name
)
186 struct pioc_attach_args
*pa
= aux
;
190 aprint_normal(" offset 0x%x", pa
->pa_offset
>> 2);
191 if (pa
->pa_iosize
> 1)
192 aprint_normal("-0x%x",
193 ((pa
->pa_offset
>> 2) + pa
->pa_iosize
) - 1);
194 if (pa
->pa_irq
!= -1)
195 aprint_normal(" irq %d", pa
->pa_irq
);
196 if (pa
->pa_drq
!= -1)
197 aprint_normal(" drq 0x%08x", pa
->pa_drq
);
200 /* XXX print flags */
206 * int piocsearch(struct device *parent, struct cfdata *cf, void *aux)
208 * search function used to probe and attach the child devices.
210 * Note: since the offsets of the devices need to be specified in the
211 * config file we ignore the FSTAT_STAR.
215 piocsearch(struct device
*parent
, struct cfdata
*cf
, const int *ldesc
, void *aux
)
217 struct pioc_softc
*sc
= (struct pioc_softc
*)parent
;
218 struct pioc_attach_args pa
;
223 pa
.pa_iobase
= sc
->sc_iobase
;
225 pa
.pa_iot
= sc
->sc_iot
;
226 if (cf
->cf_loc
[PIOCCF_OFFSET
] == PIOCCF_OFFSET_DEFAULT
) {
227 pa
.pa_offset
= PIOCCF_OFFSET_DEFAULT
;
228 pa
.pa_drq
= PIOCCF_DACK_DEFAULT
;
229 pa
.pa_irq
= PIOCCF_IRQ_DEFAULT
;
231 pa
.pa_offset
= (cf
->cf_loc
[PIOCCF_OFFSET
] << 2);
232 pa
.pa_drq
= cf
->cf_loc
[PIOCCF_DACK
];
233 pa
.pa_irq
= cf
->cf_loc
[PIOCCF_IRQ
];
237 if (config_match(parent
, cf
, &pa
) > 0) {
238 config_attach(parent
, cf
, &pa
, piocprint
);
239 /* tryagain = (cf->cf_fstate == FSTATE_STAR);*/
248 * int piocsubmatch(struct device *parent, struct cfdata *cf, void *aux)
250 * search function used to probe and attach the child devices.
252 * Note: since the offsets of the devices need to be specified in the
253 * config file we ignore the FSTAT_STAR.
257 piocsubmatch(struct device
*parent
, struct cfdata
*cf
, const int *ldesc
, void *aux
)
259 struct pioc_attach_args
*pa
= aux
;
262 if ((pa
->pa_offset
>> 2) != cf
->cf_loc
[PIOCCF_OFFSET
])
265 if (pa
->pa_drq
== -1)
266 pa
->pa_drq
= cf
->cf_loc
[PIOCCF_DACK
];
267 if (pa
->pa_irq
== -1)
268 pa
->pa_irq
= cf
->cf_loc
[PIOCCF_IRQ
];
270 if (config_match(parent
, cf
, pa
) > 0) {
271 config_attach(parent
, cf
, pa
, piocprint
);
272 /* tryagain = (cf->cf_fstate == FSTATE_STAR);*/
280 * void piocattach(struct device *parent, struct device *dev, void *aux)
282 * Identify the PIOC and read the config registers into the softc.
283 * Search and configure all children
287 piocattach(struct device
*parent
, struct device
*self
, void *aux
)
289 struct mainbus_attach_args
*mb
= aux
;
290 struct pioc_softc
*sc
= (struct pioc_softc
*)self
;
292 bus_space_handle_t ioh
;
295 struct pioc_attach_args pa
;
297 sc
->sc_iobase
= mb
->mb_iobase
;
298 iot
= sc
->sc_iot
= mb
->mb_iot
;
300 if (bus_space_map(iot
, sc
->sc_iobase
, PIOC_SIZE
, 0, &ioh
))
301 panic("%s: couldn't map I/O space", self
->dv_xname
);
304 piocgetid(iot
, ioh
, PIOC_CM_ENTER_665
, &id
, &rev
);
305 if (id
!= PIOC_CM_ID_665
)
306 piocgetid(iot
, ioh
, PIOC_CM_ENTER_666
, &id
, &rev
);
308 printf("\n%s: ", device_xname(self
));
310 /* Do we recognise it ? */
314 printf("SMC FDC37C6%xGT peripheral controller rev %d\n", id
, rev
);
317 printf("Unrecognised peripheral controller id=%2x rev=%2x\n", id
, rev
);
324 * Put the chip info configuration mode and save all the registers
329 bus_space_write_1(iot
, ioh
, PIOC_CM_SELECT_REG
, PIOC_CM_ENTER_665
);
330 bus_space_write_1(iot
, ioh
, PIOC_CM_SELECT_REG
, PIOC_CM_ENTER_665
);
334 bus_space_write_1(iot
, ioh
, PIOC_CM_SELECT_REG
, PIOC_CM_ENTER_666
);
335 bus_space_write_1(iot
, ioh
, PIOC_CM_SELECT_REG
, PIOC_CM_ENTER_666
);
339 for (loop
= 0; loop
< PIOC_CM_REGS
; ++loop
) {
340 bus_space_write_1(iot
, ioh
, PIOC_CM_SELECT_REG
, loop
);
341 sc
->sc_config
[loop
] = bus_space_read_1(iot
, ioh
, PIOC_CM_DATA_REG
);
344 bus_space_write_1(iot
, ioh
, PIOC_CM_SELECT_REG
, PIOC_CM_EXIT
);
347 printf("%s: ", device_xname(self
));
349 for (loop
= 0; loop
< PIOC_CM_REGS
; ++loop
)
350 printf("%02x ", sc
->sc_config
[loop
]);
355 * Ok as yet we cannot do specific config_found() calls
356 * for the children yet. This is because the pioc device does
357 * not know the interrupt numbers to use.
358 * Eventually this information will have to be provided by the
359 * riscpc specific code.
360 * Until then just do a config_search_ia() and pick the info up
362 * Note the child devices require some modifications as well.
366 * Ok Now configure the child devices of the pioc device
367 * Use the pioc config registers to determine the addressing
372 * Start by configuring the IDE controller
375 if (sc
->sc_config
[PIOC_CM_CR0
] & PIOC_WDC_ENABLE
) {
377 pa
.pa_iobase
= sc
->sc_iobase
;
380 if (sc
->sc_config
[PIOC_CM_CR5
] & PIOC_WDC_SECONDARY
)
381 pa
.pa_offset
= (PIOC_WDC_SECONDARY_OFFSET
<< 2);
383 pa
.pa_offset
= (PIOC_WDC_PRIMARY_OFFSET
<< 2);
386 config_found_sm_loc(self
, "pioc", NULL
, &pa
, piocprint
,
391 * Next configure the floppy controller
394 if (sc
->sc_config
[PIOC_CM_CR0
] & PIOC_FDC_ENABLE
) {
396 pa
.pa_iobase
= sc
->sc_iobase
;
399 if (sc
->sc_config
[PIOC_CM_CR5
] & PIOC_FDC_SECONDARY
)
400 pa
.pa_offset
= (PIOC_FDC_SECONDARY_OFFSET
<< 2);
402 pa
.pa_offset
= (PIOC_FDC_PRIMARY_OFFSET
<< 2);
405 config_found_sm_loc(self
, "pioc", NULL
, &pa
, piocprint
,
410 * Next configure the serial ports
414 * XXX - There is a deficiency in the serial configuration
415 * If the PIOC has the serial ports configured for COM3 and COM4
416 * the standard COM3 and COM4 addresses are assumed rather than
417 * examining CR1 to determine the COM3 and COM4 addresses.
420 if (sc
->sc_config
[PIOC_CM_CR2
] & PIOC_UART1_ENABLE
) {
422 pa
.pa_iobase
= sc
->sc_iobase
;
425 switch (sc
->sc_config
[PIOC_CM_CR2
] & PIOC_UART1_ADDR_MASK
) {
426 case PIOC_UART1_ADDR_COM1
:
427 pa
.pa_offset
= (PIOC_COM1_OFFSET
<< 2);
429 case PIOC_UART1_ADDR_COM2
:
430 pa
.pa_offset
= (PIOC_COM2_OFFSET
<< 2);
432 case PIOC_UART1_ADDR_COM3
:
433 pa
.pa_offset
= (PIOC_COM3_OFFSET
<< 2);
435 case PIOC_UART1_ADDR_COM4
:
436 pa
.pa_offset
= (PIOC_COM4_OFFSET
<< 2);
441 config_found_sm_loc(self
, "pioc", NULL
, &pa
, piocprint
,
445 if (sc
->sc_config
[PIOC_CM_CR2
] & PIOC_UART2_ENABLE
) {
447 pa
.pa_iobase
= sc
->sc_iobase
;
450 switch (sc
->sc_config
[PIOC_CM_CR2
] & PIOC_UART2_ADDR_MASK
) {
451 case PIOC_UART2_ADDR_COM1
:
452 pa
.pa_offset
= (PIOC_COM1_OFFSET
<< 2);
454 case PIOC_UART2_ADDR_COM2
:
455 pa
.pa_offset
= (PIOC_COM2_OFFSET
<< 2);
457 case PIOC_UART2_ADDR_COM3
:
458 pa
.pa_offset
= (PIOC_COM3_OFFSET
<< 2);
460 case PIOC_UART2_ADDR_COM4
:
461 pa
.pa_offset
= (PIOC_COM4_OFFSET
<< 2);
466 config_found_sm_loc(self
, "pioc", NULL
, &pa
, piocprint
,
471 * Next configure the printer port
474 if ((sc
->sc_config
[PIOC_CM_CR1
] & PIOC_LPT_ADDR_MASK
) != PIOC_LPT_ADDR_DISABLE
) {
476 pa
.pa_iobase
= sc
->sc_iobase
;
479 switch (sc
->sc_config
[PIOC_CM_CR1
] & PIOC_LPT_ADDR_MASK
) {
480 case PIOC_LPT_ADDR_1
:
481 pa
.pa_offset
= (PIOC_LPT1_OFFSET
<< 2);
483 case PIOC_LPT_ADDR_2
:
484 pa
.pa_offset
= (PIOC_LPT2_OFFSET
<< 2);
486 case PIOC_LPT_ADDR_3
:
487 pa
.pa_offset
= (PIOC_LPT3_OFFSET
<< 2);
492 config_found_sm_loc(self
, "pioc", NULL
, &pa
, piocprint
,
497 config_search_ia(piocsearch
, self
, "pioc", NULL
);