1158005Smarcel/*-
2158005Smarcel * Copyright (c) 2006 Marcel Moolenaar
3158005Smarcel * All rights reserved.
4158005Smarcel *
5158005Smarcel * Redistribution and use in source and binary forms, with or without
6158005Smarcel * modification, are permitted provided that the following conditions
7158005Smarcel * are met:
8158005Smarcel * 1. Redistributions of source code must retain the above copyright
9158005Smarcel *    notice, this list of conditions and the following disclaimer.
10158005Smarcel * 2. Redistributions in binary form must reproduce the above copyright
11158005Smarcel *    notice, this list of conditions and the following disclaimer in the
12158005Smarcel *    documentation and/or other materials provided with the distribution.
13158005Smarcel *
14158005Smarcel * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15158005Smarcel * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16158005Smarcel * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17158005Smarcel * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18158005Smarcel * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19158005Smarcel * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20158005Smarcel * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21158005Smarcel * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22158005Smarcel * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23158005Smarcel * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24158005Smarcel * SUCH DAMAGE.
25158005Smarcel */
26158005Smarcel
27158005Smarcel#include <sys/cdefs.h>
28158005Smarcel__FBSDID("$FreeBSD$");
29158005Smarcel
30158005Smarcel#include <sys/param.h>
31158005Smarcel#include <sys/kernel.h>
32158005Smarcel#include <sys/module.h>
33158005Smarcel#include <sys/bus.h>
34158005Smarcel
35158005Smarcel#include <machine/bus.h>
36158005Smarcel
37158005Smarcel#include <dev/pci/pcivar.h>
38158005Smarcel
39158005Smarcel#include <dev/ppbus/ppbconf.h>
40158005Smarcel#include <dev/ppbus/ppb_msq.h>
41158005Smarcel#include <dev/ppc/ppcvar.h>
42158005Smarcel#include <dev/ppc/ppcreg.h>
43158005Smarcel
44158005Smarcel#include "ppbus_if.h"
45158005Smarcel
46158005Smarcelstatic int ppc_pci_probe(device_t dev);
47158005Smarcel
48158005Smarcelstatic device_method_t ppc_pci_methods[] = {
49158005Smarcel	/* device interface */
50158005Smarcel	DEVMETHOD(device_probe,		ppc_pci_probe),
51158005Smarcel	DEVMETHOD(device_attach,	ppc_attach),
52158005Smarcel	DEVMETHOD(device_detach,	ppc_detach),
53158005Smarcel
54158005Smarcel	/* bus interface */
55158005Smarcel	DEVMETHOD(bus_read_ivar,	ppc_read_ivar),
56187576Sjhb	DEVMETHOD(bus_write_ivar,	ppc_write_ivar),
57183053Sjhb	DEVMETHOD(bus_alloc_resource,	ppc_alloc_resource),
58183053Sjhb	DEVMETHOD(bus_release_resource,	ppc_release_resource),
59158005Smarcel
60158005Smarcel	/* ppbus interface */
61158005Smarcel	DEVMETHOD(ppbus_io,		ppc_io),
62158005Smarcel	DEVMETHOD(ppbus_exec_microseq,	ppc_exec_microseq),
63158005Smarcel	DEVMETHOD(ppbus_reset_epp,	ppc_reset_epp),
64158005Smarcel	DEVMETHOD(ppbus_setmode,	ppc_setmode),
65158005Smarcel	DEVMETHOD(ppbus_ecp_sync,	ppc_ecp_sync),
66158005Smarcel	DEVMETHOD(ppbus_read,		ppc_read),
67158005Smarcel	DEVMETHOD(ppbus_write,		ppc_write),
68158005Smarcel
69158005Smarcel	{ 0, 0 }
70158005Smarcel};
71158005Smarcel
72158005Smarcelstatic driver_t ppc_pci_driver = {
73158005Smarcel	ppc_driver_name,
74158005Smarcel	ppc_pci_methods,
75158005Smarcel	sizeof(struct ppc_data),
76158005Smarcel};
77158005Smarcel
78158005Smarcelstruct pci_id {
79158005Smarcel	uint32_t	type;
80158005Smarcel	const char	*desc;
81158005Smarcel	int		rid;
82158005Smarcel};
83158005Smarcel
84158005Smarcelstatic struct pci_id pci_ids[] = {
85158005Smarcel	{ 0x1020131f, "SIIG Cyber Parallel PCI (10x family)", 0x18 },
86158005Smarcel	{ 0x2020131f, "SIIG Cyber Parallel PCI (20x family)", 0x10 },
87188472Skaiw	{ 0x05111407, "Lava SP BIDIR Parallel PCI", 0x10 },
88158005Smarcel	{ 0x80001407, "Lava Computers 2SP-PCI parallel port", 0x10 },
89158005Smarcel	{ 0x84031415, "Oxford Semiconductor OX12PCI840 Parallel port", 0x10 },
90158005Smarcel	{ 0x95131415, "Oxford Semiconductor OX16PCI954 Parallel port", 0x10 },
91158005Smarcel	{ 0x98059710, "NetMos NM9805 1284 Printer port", 0x10 },
92218861Smiwi	{ 0x98659710, "MosChip MCS9865 1284 Printer port", 0x10 },
93205534Sdelphij	{ 0x99019710, "MosChip MCS9901 PCIe to Peripheral Controller", 0x10 },
94158005Smarcel	{ 0xffff }
95158005Smarcel};
96158005Smarcel
97158005Smarcelstatic int
98158005Smarcelppc_pci_probe(device_t dev)
99158005Smarcel{
100158005Smarcel	struct pci_id *id;
101158005Smarcel	uint32_t type;
102158005Smarcel
103158005Smarcel	type = pci_get_devid(dev);
104158005Smarcel	id = pci_ids;
105158005Smarcel	while (id->type != 0xffff && id->type != type)
106158005Smarcel		id++;
107158005Smarcel	if (id->type == 0xffff)
108158005Smarcel		return (ENXIO);
109158005Smarcel	device_set_desc(dev, id->desc);
110158005Smarcel	return (ppc_probe(dev, id->rid));
111158005Smarcel}
112158005Smarcel
113158005SmarcelDRIVER_MODULE(ppc, pci, ppc_pci_driver, ppc_devclass, 0, 0);
114