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 345820 2019-04-03 01:29:54Z mav $"); 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 107345820Smav#define ID_CANNONLAKE 0xa323 10866703Sarchie 109321931Sgavinstatic const struct ichsmb_device { 110321931Sgavin uint16_t id; 111321931Sgavin const char *name; 112321931Sgavin} ichsmb_devices[] = { 113321931Sgavin { ID_82801AA, "Intel 82801AA (ICH) SMBus controller" }, 114321931Sgavin { ID_82801AB, "Intel 82801AB (ICH0) SMBus controller" }, 115321931Sgavin { ID_82801BA, "Intel 82801BA (ICH2) SMBus controller" }, 116321931Sgavin { ID_82801CA, "Intel 82801CA (ICH3) SMBus controller" }, 117321931Sgavin { ID_82801DC, "Intel 82801DC (ICH4) SMBus controller" }, 118321931Sgavin { ID_82801EB, "Intel 82801EB (ICH5) SMBus controller" }, 119321931Sgavin { ID_82801FB, "Intel 82801FB (ICH6) SMBus controller" }, 120321931Sgavin { ID_82801GB, "Intel 82801GB (ICH7) SMBus controller" }, 121321931Sgavin { ID_82801H, "Intel 82801H (ICH8) SMBus controller" }, 122321931Sgavin { ID_82801I, "Intel 82801I (ICH9) SMBus controller" }, 123321931Sgavin { ID_82801GB, "Intel 82801GB (ICH7) SMBus controller" }, 124321931Sgavin { ID_82801H, "Intel 82801H (ICH8) SMBus controller" }, 125321931Sgavin { ID_82801I, "Intel 82801I (ICH9) SMBus controller" }, 126321931Sgavin { ID_EP80579, "Intel EP80579 SMBus controller" }, 127321931Sgavin { ID_82801JI, "Intel 82801JI (ICH10) SMBus controller" }, 128321931Sgavin { ID_82801JD, "Intel 82801JD (ICH10) SMBus controller" }, 129321931Sgavin { ID_PCH, "Intel PCH SMBus controller" }, 130321931Sgavin { ID_6300ESB, "Intel 6300ESB (ICH) SMBus controller" }, 131321931Sgavin { ID_631xESB, "Intel 631xESB/6321ESB (ESB2) SMBus controller" }, 132321931Sgavin { ID_DH89XXCC, "Intel DH89xxCC SMBus controller" }, 133321931Sgavin { ID_PATSBURG, "Intel Patsburg SMBus controller" }, 134321931Sgavin { ID_CPT, "Intel Cougar Point SMBus controller" }, 135321931Sgavin { ID_PPT, "Intel Panther Point SMBus controller" }, 136321931Sgavin { ID_AVOTON, "Intel Avoton SMBus controller" }, 137321931Sgavin { ID_LPT, "Intel Lynx Point SMBus controller" }, 138321931Sgavin { ID_LPTLP, "Intel Lynx Point-LP SMBus controller" }, 139321931Sgavin { ID_WCPT, "Intel Wildcat Point SMBus controller" }, 140321931Sgavin { ID_WCPTLP, "Intel Wildcat Point-LP SMBus controller" }, 141321931Sgavin { ID_BAYTRAIL, "Intel Baytrail SMBus controller" }, 142321931Sgavin { ID_BRASWELL, "Intel Braswell SMBus controller" }, 143321931Sgavin { ID_COLETOCRK, "Intel Coleto Creek SMBus controller" }, 144321931Sgavin { ID_WELLSBURG, "Intel Wellsburg SMBus controller" }, 145321931Sgavin { ID_SRPT, "Intel Sunrise Point-H SMBus controller" }, 146321931Sgavin { ID_SRPTLP, "Intel Sunrise Point-LP SMBus controller" }, 147321931Sgavin { ID_DENVERTON, "Intel Denverton SMBus controller" }, 148321931Sgavin { ID_BROXTON, "Intel Broxton SMBus controller" }, 149321931Sgavin { ID_LEWISBURG, "Intel Lewisburg SMBus controller" }, 150321931Sgavin { ID_LEWISBURG2,"Intel Lewisburg SMBus controller" }, 151321931Sgavin { ID_KABYLAKE, "Intel Kaby Lake SMBus controller" }, 152345820Smav { ID_CANNONLAKE,"Intel Cannon Lake SMBus controller" }, 153321931Sgavin { 0, NULL }, 154321931Sgavin}; 15566703Sarchie 15666703Sarchie/* Internal functions */ 15766703Sarchiestatic int ichsmb_pci_probe(device_t dev); 15866703Sarchiestatic int ichsmb_pci_attach(device_t dev); 159147253Stakawata/*Use generic one for now*/ 160147253Stakawata#if 0 161147253Stakawatastatic int ichsmb_pci_detach(device_t dev); 162147253Stakawata#endif 16366703Sarchie 16466703Sarchie/* Device methods */ 16566703Sarchiestatic device_method_t ichsmb_pci_methods[] = { 16666703Sarchie /* Device interface */ 16766703Sarchie DEVMETHOD(device_probe, ichsmb_pci_probe), 16866703Sarchie DEVMETHOD(device_attach, ichsmb_pci_attach), 169147253Stakawata DEVMETHOD(device_detach, ichsmb_detach), 17066703Sarchie 17166703Sarchie /* SMBus methods */ 17266703Sarchie DEVMETHOD(smbus_callback, ichsmb_callback), 17366703Sarchie DEVMETHOD(smbus_quick, ichsmb_quick), 17466703Sarchie DEVMETHOD(smbus_sendb, ichsmb_sendb), 17566703Sarchie DEVMETHOD(smbus_recvb, ichsmb_recvb), 17666703Sarchie DEVMETHOD(smbus_writeb, ichsmb_writeb), 17766703Sarchie DEVMETHOD(smbus_writew, ichsmb_writew), 17866703Sarchie DEVMETHOD(smbus_readb, ichsmb_readb), 17966703Sarchie DEVMETHOD(smbus_readw, ichsmb_readw), 18066703Sarchie DEVMETHOD(smbus_pcall, ichsmb_pcall), 18166703Sarchie DEVMETHOD(smbus_bwrite, ichsmb_bwrite), 18266703Sarchie DEVMETHOD(smbus_bread, ichsmb_bread), 183227843Smarius 184227843Smarius DEVMETHOD_END 18566703Sarchie}; 18666703Sarchie 18766703Sarchiestatic driver_t ichsmb_pci_driver = { 18866703Sarchie "ichsmb", 18966703Sarchie ichsmb_pci_methods, 19066703Sarchie sizeof(struct ichsmb_softc) 19166703Sarchie}; 19266703Sarchie 19366703Sarchiestatic devclass_t ichsmb_pci_devclass; 19466703Sarchie 19566703SarchieDRIVER_MODULE(ichsmb, pci, ichsmb_pci_driver, ichsmb_pci_devclass, 0, 0); 19666703Sarchie 19766703Sarchiestatic int 19866703Sarchieichsmb_pci_probe(device_t dev) 19966703Sarchie{ 200321931Sgavin const struct ichsmb_device *device; 201321931Sgavin 202321931Sgavin if (pci_get_vendor(dev) != PCI_VENDOR_INTEL) 20366703Sarchie return (ENXIO); 204321931Sgavin 205321931Sgavin for (device = ichsmb_devices; device->name != NULL; device++) { 206321931Sgavin if (pci_get_device(dev) == device->id) { 207321931Sgavin device_set_desc(dev, device->name); 208321931Sgavin return (ichsmb_probe(dev)); 209321931Sgavin } 21066703Sarchie } 21166703Sarchie 212321931Sgavin return (ENXIO); 21366703Sarchie} 21466703Sarchie 21566703Sarchiestatic int 21666703Sarchieichsmb_pci_attach(device_t dev) 21766703Sarchie{ 21866703Sarchie const sc_p sc = device_get_softc(dev); 21966703Sarchie int error; 22066703Sarchie 22166703Sarchie /* Initialize private state */ 22266703Sarchie bzero(sc, sizeof(*sc)); 22366703Sarchie sc->ich_cmd = -1; 22466703Sarchie sc->dev = dev; 22566703Sarchie 22666703Sarchie /* Allocate an I/O range */ 22766703Sarchie sc->io_rid = ICH_SMB_BASE; 228296137Sjhibbits sc->io_res = bus_alloc_resource_anywhere(dev, SYS_RES_IOPORT, 229296137Sjhibbits &sc->io_rid, 16, RF_ACTIVE); 230131070Sambrisko if (sc->io_res == NULL) 231296137Sjhibbits sc->io_res = bus_alloc_resource_anywhere(dev, SYS_RES_IOPORT, 232296137Sjhibbits &sc->io_rid, 32, RF_ACTIVE); 23366703Sarchie if (sc->io_res == NULL) { 234165951Sjhb device_printf(dev, "can't map I/O\n"); 23566703Sarchie error = ENXIO; 23666703Sarchie goto fail; 23766703Sarchie } 23866703Sarchie 23966703Sarchie /* Allocate interrupt */ 24066703Sarchie sc->irq_rid = 0; 241127135Snjl sc->irq_res = bus_alloc_resource_any(dev, SYS_RES_IRQ, 242127135Snjl &sc->irq_rid, RF_ACTIVE | RF_SHAREABLE); 24366703Sarchie if (sc->irq_res == NULL) { 244165951Sjhb device_printf(dev, "can't get IRQ\n"); 24566703Sarchie error = ENXIO; 24666703Sarchie goto fail; 24766703Sarchie } 24866703Sarchie 24966703Sarchie /* Enable device */ 25066703Sarchie pci_write_config(dev, ICH_HOSTC, ICH_HOSTC_HST_EN, 1); 25166703Sarchie 25266703Sarchie /* Done */ 253165951Sjhb error = ichsmb_attach(dev); 254165951Sjhb if (error) 255165951Sjhb goto fail; 256165951Sjhb return (0); 25766703Sarchie 25866703Sarchiefail: 25966703Sarchie /* Attach failed, release resources */ 26066703Sarchie ichsmb_release_resources(sc); 26166703Sarchie return (error); 26266703Sarchie} 26366703Sarchie 264147253Stakawata 265146996StakawataMODULE_DEPEND(ichsmb, pci, 1, 1, 1); 266146996StakawataMODULE_DEPEND(ichsmb, smbus, SMBUS_MINVER, SMBUS_PREFVER, SMBUS_MAXVER); 267146996StakawataMODULE_VERSION(ichsmb, 1); 268