ichsmb_pci.c revision 321931
1119418Sobrien/*-
266703Sarchie * ichsmb_pci.c
366703Sarchie *
4119418Sobrien * Author: Archie Cobbs <archie@freebsd.org>
566703Sarchie * Copyright (c) 2000 Whistle Communications, Inc.
666703Sarchie * All rights reserved.
7119418Sobrien * Author: Archie Cobbs <archie@freebsd.org>
8284247Srpaulo *
966703Sarchie * Subject to the following obligations and disclaimer of warranty, use and
1066703Sarchie * redistribution of this software, in source or object code forms, with or
1166703Sarchie * without modifications are expressly permitted by Whistle Communications;
1266703Sarchie * provided, however, that:
1366703Sarchie * 1. Any and all reproductions of the source or object code must include the
1466703Sarchie *    copyright notice above and the following disclaimer of warranties; and
1566703Sarchie * 2. No rights are granted, in any manner or form, to use Whistle
1666703Sarchie *    Communications, Inc. trademarks, including the mark "WHISTLE
1766703Sarchie *    COMMUNICATIONS" on advertising, endorsements, or otherwise except as
1866703Sarchie *    such appears in the above copyright notice or in the software.
19284247Srpaulo *
2066703Sarchie * THIS SOFTWARE IS BEING PROVIDED BY WHISTLE COMMUNICATIONS "AS IS", AND
2166703Sarchie * TO THE MAXIMUM EXTENT PERMITTED BY LAW, WHISTLE COMMUNICATIONS MAKES NO
2266703Sarchie * REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED, REGARDING THIS SOFTWARE,
2366703Sarchie * INCLUDING WITHOUT LIMITATION, ANY AND ALL IMPLIED WARRANTIES OF
2466703Sarchie * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT.
2566703Sarchie * WHISTLE COMMUNICATIONS DOES NOT WARRANT, GUARANTEE, OR MAKE ANY
2666703Sarchie * REPRESENTATIONS REGARDING THE USE OF, OR THE RESULTS OF THE USE OF THIS
2766703Sarchie * SOFTWARE IN TERMS OF ITS CORRECTNESS, ACCURACY, RELIABILITY OR OTHERWISE.
2866703Sarchie * IN NO EVENT SHALL WHISTLE COMMUNICATIONS BE LIABLE FOR ANY DAMAGES
2966703Sarchie * RESULTING FROM OR ARISING OUT OF ANY USE OF THIS SOFTWARE, INCLUDING
3066703Sarchie * WITHOUT LIMITATION, ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
3166703Sarchie * PUNITIVE, OR CONSEQUENTIAL DAMAGES, PROCUREMENT OF SUBSTITUTE GOODS OR
3266703Sarchie * SERVICES, LOSS OF USE, DATA OR PROFITS, HOWEVER CAUSED AND UNDER ANY
3366703Sarchie * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
3466703Sarchie * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
3566703Sarchie * THIS SOFTWARE, EVEN IF WHISTLE COMMUNICATIONS IS ADVISED OF THE POSSIBILITY
3666703Sarchie * OF SUCH DAMAGE.
3766703Sarchie */
3866703Sarchie
39119418Sobrien#include <sys/cdefs.h>
40119418Sobrien__FBSDID("$FreeBSD: stable/11/sys/dev/ichsmb/ichsmb_pci.c 321931 2017-08-02 15:11:06Z gavin $");
41119418Sobrien
4266703Sarchie/*
4366703Sarchie * Support for the SMBus controller logical device which is part of the
44119618Snjl * Intel 81801AA/AB/BA/CA/DC/EB (ICH/ICH[02345]) I/O controller hub chips.
4566703Sarchie */
4666703Sarchie
4766703Sarchie#include <sys/param.h>
4866703Sarchie#include <sys/systm.h>
4966703Sarchie#include <sys/kernel.h>
50129879Sphk#include <sys/module.h>
5166703Sarchie#include <sys/errno.h>
5274914Sjhb#include <sys/lock.h>
5369734Sarchie#include <sys/mutex.h>
5466703Sarchie#include <sys/syslog.h>
5566703Sarchie#include <sys/bus.h>
5666703Sarchie
5766703Sarchie#include <machine/bus.h>
5866703Sarchie#include <sys/rman.h>
5966703Sarchie#include <machine/resource.h>
6066703Sarchie
61119280Simp#include <dev/pci/pcivar.h>
62119280Simp#include <dev/pci/pcireg.h>
6366703Sarchie
6466703Sarchie#include <dev/smbus/smbconf.h>
6566703Sarchie
6666703Sarchie#include <dev/ichsmb/ichsmb_var.h>
6766703Sarchie#include <dev/ichsmb/ichsmb_reg.h>
6866703Sarchie
6966703Sarchie/* PCI unique identifiers */
70321931Sgavin#define	PCI_VENDOR_INTEL		0x8086
71321931Sgavin#define	ID_82801AA			0x2413
72321931Sgavin#define	ID_82801AB			0x2423
73321931Sgavin#define	ID_82801BA			0x2443
74321931Sgavin#define	ID_82801CA			0x2483
75321931Sgavin#define	ID_82801DC			0x24C3
76321931Sgavin#define	ID_82801EB			0x24D3
77321931Sgavin#define	ID_82801FB			0x266A
78321931Sgavin#define	ID_82801GB			0x27da
79321931Sgavin#define	ID_82801H			0x283e
80321931Sgavin#define	ID_82801I			0x2930
81321931Sgavin#define	ID_EP80579			0x5032
82321931Sgavin#define	ID_82801JI			0x3a30
83321931Sgavin#define	ID_82801JD			0x3a60
84321931Sgavin#define	ID_PCH				0x3b30
85321931Sgavin#define	ID_6300ESB			0x25a4
86321931Sgavin#define	ID_631xESB			0x269b
87321931Sgavin#define	ID_DH89XXCC			0x2330
88321931Sgavin#define	ID_PATSBURG			0x1d22
89321931Sgavin#define	ID_CPT				0x1c22
90321931Sgavin#define	ID_PPT				0x1e22
91321931Sgavin#define	ID_AVOTON			0x1f3c
92321931Sgavin#define	ID_COLETOCRK			0x23B0
93321931Sgavin#define	ID_LPT				0x8c22
94321931Sgavin#define	ID_LPTLP			0x9c22
95321931Sgavin#define	ID_WCPT				0x8ca2
96321931Sgavin#define	ID_WCPTLP			0x9ca2
97321931Sgavin#define	ID_BAYTRAIL			0x0f12
98321931Sgavin#define	ID_BRASWELL			0x2292
99321931Sgavin#define	ID_WELLSBURG			0x8d22
100321931Sgavin#define	ID_SRPT				0xa123
101321931Sgavin#define	ID_SRPTLP			0x9d23
102321931Sgavin#define	ID_DENVERTON			0x19df
103321931Sgavin#define	ID_BROXTON			0x5ad4
104321931Sgavin#define	ID_LEWISBURG			0xa1a3
105321931Sgavin#define	ID_LEWISBURG2			0xa223
106321931Sgavin#define	ID_KABYLAKE			0xa2a3
10766703Sarchie
108321931Sgavinstatic const struct ichsmb_device {
109321931Sgavin	uint16_t	id;
110321931Sgavin	const char	*name;
111321931Sgavin} ichsmb_devices[] = {
112321931Sgavin	{ ID_82801AA,	"Intel 82801AA (ICH) SMBus controller"		},
113321931Sgavin	{ ID_82801AB,	"Intel 82801AB (ICH0) SMBus controller"		},
114321931Sgavin	{ ID_82801BA,	"Intel 82801BA (ICH2) SMBus controller"		},
115321931Sgavin	{ ID_82801CA,	"Intel 82801CA (ICH3) SMBus controller"		},
116321931Sgavin	{ ID_82801DC,	"Intel 82801DC (ICH4) SMBus controller"		},
117321931Sgavin	{ ID_82801EB,	"Intel 82801EB (ICH5) SMBus controller"		},
118321931Sgavin	{ ID_82801FB,	"Intel 82801FB (ICH6) SMBus controller"		},
119321931Sgavin	{ ID_82801GB,	"Intel 82801GB (ICH7) SMBus controller"		},
120321931Sgavin	{ ID_82801H,	"Intel 82801H (ICH8) SMBus controller"		},
121321931Sgavin	{ ID_82801I,	"Intel 82801I (ICH9) SMBus controller"		},
122321931Sgavin	{ ID_82801GB,	"Intel 82801GB (ICH7) SMBus controller"		},
123321931Sgavin	{ ID_82801H,	"Intel 82801H (ICH8) SMBus controller"		},
124321931Sgavin	{ ID_82801I,	"Intel 82801I (ICH9) SMBus controller"		},
125321931Sgavin	{ ID_EP80579,	"Intel EP80579 SMBus controller"		},
126321931Sgavin	{ ID_82801JI,	"Intel 82801JI (ICH10) SMBus controller"	},
127321931Sgavin	{ ID_82801JD,	"Intel 82801JD (ICH10) SMBus controller"	},
128321931Sgavin	{ ID_PCH,	"Intel PCH SMBus controller"			},
129321931Sgavin	{ ID_6300ESB,	"Intel 6300ESB (ICH) SMBus controller"		},
130321931Sgavin	{ ID_631xESB,	"Intel 631xESB/6321ESB (ESB2) SMBus controller"	},
131321931Sgavin	{ ID_DH89XXCC,	"Intel DH89xxCC SMBus controller"		},
132321931Sgavin	{ ID_PATSBURG,	"Intel Patsburg SMBus controller"		},
133321931Sgavin	{ ID_CPT,	"Intel Cougar Point SMBus controller"		},
134321931Sgavin	{ ID_PPT,	"Intel Panther Point SMBus controller"		},
135321931Sgavin	{ ID_AVOTON,	"Intel Avoton SMBus controller"			},
136321931Sgavin	{ ID_LPT,	"Intel Lynx Point SMBus controller"		},
137321931Sgavin	{ ID_LPTLP,	"Intel Lynx Point-LP SMBus controller"		},
138321931Sgavin	{ ID_WCPT,	"Intel Wildcat Point SMBus controller"		},
139321931Sgavin	{ ID_WCPTLP,	"Intel Wildcat Point-LP SMBus controller"	},
140321931Sgavin	{ ID_BAYTRAIL,	"Intel Baytrail SMBus controller"		},
141321931Sgavin	{ ID_BRASWELL,	"Intel Braswell SMBus controller"		},
142321931Sgavin	{ ID_COLETOCRK,	"Intel Coleto Creek SMBus controller"		},
143321931Sgavin	{ ID_WELLSBURG,	"Intel Wellsburg SMBus controller"		},
144321931Sgavin	{ ID_SRPT,	"Intel Sunrise Point-H SMBus controller"	},
145321931Sgavin	{ ID_SRPTLP,	"Intel Sunrise Point-LP SMBus controller"	},
146321931Sgavin	{ ID_DENVERTON,	"Intel Denverton SMBus controller"		},
147321931Sgavin	{ ID_BROXTON,	"Intel Broxton SMBus controller"		},
148321931Sgavin	{ ID_LEWISBURG,	"Intel Lewisburg SMBus controller"		},
149321931Sgavin	{ ID_LEWISBURG2,"Intel Lewisburg SMBus controller"		},
150321931Sgavin	{ ID_KABYLAKE,	"Intel Kaby Lake SMBus controller"		},
151321931Sgavin	{ 0, NULL },
152321931Sgavin};
15366703Sarchie
15466703Sarchie/* Internal functions */
15566703Sarchiestatic int	ichsmb_pci_probe(device_t dev);
15666703Sarchiestatic int	ichsmb_pci_attach(device_t dev);
157147253Stakawata/*Use generic one for now*/
158147253Stakawata#if 0
159147253Stakawatastatic int	ichsmb_pci_detach(device_t dev);
160147253Stakawata#endif
16166703Sarchie
16266703Sarchie/* Device methods */
16366703Sarchiestatic device_method_t ichsmb_pci_methods[] = {
16466703Sarchie	/* Device interface */
16566703Sarchie        DEVMETHOD(device_probe, ichsmb_pci_probe),
16666703Sarchie        DEVMETHOD(device_attach, ichsmb_pci_attach),
167147253Stakawata        DEVMETHOD(device_detach, ichsmb_detach),
16866703Sarchie
16966703Sarchie	/* SMBus methods */
17066703Sarchie        DEVMETHOD(smbus_callback, ichsmb_callback),
17166703Sarchie        DEVMETHOD(smbus_quick, ichsmb_quick),
17266703Sarchie        DEVMETHOD(smbus_sendb, ichsmb_sendb),
17366703Sarchie        DEVMETHOD(smbus_recvb, ichsmb_recvb),
17466703Sarchie        DEVMETHOD(smbus_writeb, ichsmb_writeb),
17566703Sarchie        DEVMETHOD(smbus_writew, ichsmb_writew),
17666703Sarchie        DEVMETHOD(smbus_readb, ichsmb_readb),
17766703Sarchie        DEVMETHOD(smbus_readw, ichsmb_readw),
17866703Sarchie        DEVMETHOD(smbus_pcall, ichsmb_pcall),
17966703Sarchie        DEVMETHOD(smbus_bwrite, ichsmb_bwrite),
18066703Sarchie        DEVMETHOD(smbus_bread, ichsmb_bread),
181227843Smarius
182227843Smarius	DEVMETHOD_END
18366703Sarchie};
18466703Sarchie
18566703Sarchiestatic driver_t ichsmb_pci_driver = {
18666703Sarchie	"ichsmb",
18766703Sarchie	ichsmb_pci_methods,
18866703Sarchie	sizeof(struct ichsmb_softc)
18966703Sarchie};
19066703Sarchie
19166703Sarchiestatic devclass_t ichsmb_pci_devclass;
19266703Sarchie
19366703SarchieDRIVER_MODULE(ichsmb, pci, ichsmb_pci_driver, ichsmb_pci_devclass, 0, 0);
19466703Sarchie
19566703Sarchiestatic int
19666703Sarchieichsmb_pci_probe(device_t dev)
19766703Sarchie{
198321931Sgavin	const struct ichsmb_device *device;
199321931Sgavin
200321931Sgavin	if (pci_get_vendor(dev) != PCI_VENDOR_INTEL)
20166703Sarchie		return (ENXIO);
202321931Sgavin
203321931Sgavin	for (device = ichsmb_devices; device->name != NULL; device++) {
204321931Sgavin		if (pci_get_device(dev) == device->id) {
205321931Sgavin			device_set_desc(dev, device->name);
206321931Sgavin			return (ichsmb_probe(dev));
207321931Sgavin		}
20866703Sarchie	}
20966703Sarchie
210321931Sgavin	return (ENXIO);
21166703Sarchie}
21266703Sarchie
21366703Sarchiestatic int
21466703Sarchieichsmb_pci_attach(device_t dev)
21566703Sarchie{
21666703Sarchie	const sc_p sc = device_get_softc(dev);
21766703Sarchie	int error;
21866703Sarchie
21966703Sarchie	/* Initialize private state */
22066703Sarchie	bzero(sc, sizeof(*sc));
22166703Sarchie	sc->ich_cmd = -1;
22266703Sarchie	sc->dev = dev;
22366703Sarchie
22466703Sarchie	/* Allocate an I/O range */
22566703Sarchie	sc->io_rid = ICH_SMB_BASE;
226296137Sjhibbits	sc->io_res = bus_alloc_resource_anywhere(dev, SYS_RES_IOPORT,
227296137Sjhibbits	    &sc->io_rid, 16, RF_ACTIVE);
228131070Sambrisko	if (sc->io_res == NULL)
229296137Sjhibbits		sc->io_res = bus_alloc_resource_anywhere(dev, SYS_RES_IOPORT,
230296137Sjhibbits		    &sc->io_rid, 32, RF_ACTIVE);
23166703Sarchie	if (sc->io_res == NULL) {
232165951Sjhb		device_printf(dev, "can't map I/O\n");
23366703Sarchie		error = ENXIO;
23466703Sarchie		goto fail;
23566703Sarchie	}
23666703Sarchie
23766703Sarchie	/* Allocate interrupt */
23866703Sarchie	sc->irq_rid = 0;
239127135Snjl	sc->irq_res = bus_alloc_resource_any(dev, SYS_RES_IRQ,
240127135Snjl	    &sc->irq_rid, RF_ACTIVE | RF_SHAREABLE);
24166703Sarchie	if (sc->irq_res == NULL) {
242165951Sjhb		device_printf(dev, "can't get IRQ\n");
24366703Sarchie		error = ENXIO;
24466703Sarchie		goto fail;
24566703Sarchie	}
24666703Sarchie
24766703Sarchie	/* Enable device */
24866703Sarchie	pci_write_config(dev, ICH_HOSTC, ICH_HOSTC_HST_EN, 1);
24966703Sarchie
25066703Sarchie	/* Done */
251165951Sjhb	error = ichsmb_attach(dev);
252165951Sjhb	if (error)
253165951Sjhb		goto fail;
254165951Sjhb	return (0);
25566703Sarchie
25666703Sarchiefail:
25766703Sarchie	/* Attach failed, release resources */
25866703Sarchie	ichsmb_release_resources(sc);
25966703Sarchie	return (error);
26066703Sarchie}
26166703Sarchie
262147253Stakawata
263146996StakawataMODULE_DEPEND(ichsmb, pci, 1, 1, 1);
264146996StakawataMODULE_DEPEND(ichsmb, smbus, SMBUS_MINVER, SMBUS_PREFVER, SMBUS_MAXVER);
265146996StakawataMODULE_VERSION(ichsmb, 1);
266