Yinghai Lu | afd34e6 | 2006-02-16 17:22:19 +0000 | [diff] [blame] | 1 | /* |
Uwe Hermann | c6a1062 | 2010-10-17 19:30:58 +0000 | [diff] [blame] | 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright (C) 2005 AMD |
| 5 | * Written by Yinghai Lu <yinghai.lu@amd.com> for AMD. |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; version 2 of the License. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
Yinghai Lu | afd34e6 | 2006-02-16 17:22:19 +0000 | [diff] [blame] | 15 | */ |
| 16 | |
| 17 | #include <console/console.h> |
| 18 | #include <device/device.h> |
| 19 | #include <device/pci.h> |
| 20 | #include <device/pnp.h> |
| 21 | #include <device/pci_ids.h> |
| 22 | #include <device/pci_ops.h> |
| 23 | #include <pc80/mc146818rtc.h> |
| 24 | #include <pc80/isa-dma.h> |
Yinghai Lu | afd34e6 | 2006-02-16 17:22:19 +0000 | [diff] [blame] | 25 | #include <arch/io.h> |
| 26 | #include <device/smbus.h> |
| 27 | #include "bcm5785.h" |
stepan | 836ae29 | 2010-12-08 05:42:47 +0000 | [diff] [blame] | 28 | #include "smbus.h" |
Yinghai Lu | afd34e6 | 2006-02-16 17:22:19 +0000 | [diff] [blame] | 29 | |
| 30 | #define NMI_OFF 0 |
| 31 | |
| 32 | static void sb_init(device_t dev) |
| 33 | { |
| 34 | uint8_t byte; |
| 35 | uint8_t byte_old; |
Luc Verhaegen | a9c5ea0 | 2009-06-03 14:19:33 +0000 | [diff] [blame] | 36 | int nmi_option; |
Yinghai Lu | afd34e6 | 2006-02-16 17:22:19 +0000 | [diff] [blame] | 37 | |
Yinghai Lu | afd34e6 | 2006-02-16 17:22:19 +0000 | [diff] [blame] | 38 | /* Set up NMI on errors */ |
| 39 | byte = inb(0x70); // RTC70 |
| 40 | byte_old = byte; |
| 41 | nmi_option = NMI_OFF; |
Luc Verhaegen | a9c5ea0 | 2009-06-03 14:19:33 +0000 | [diff] [blame] | 42 | get_option(&nmi_option, "nmi"); |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 43 | if (nmi_option) { |
Yinghai Lu | afd34e6 | 2006-02-16 17:22:19 +0000 | [diff] [blame] | 44 | byte &= ~(1 << 7); /* set NMI */ |
| 45 | } else { |
| 46 | byte |= ( 1 << 7); // Can not mask NMI from PCI-E and NMI_NOW |
| 47 | } |
| 48 | if( byte != byte_old) { |
Ed Swierk | e42e142 | 2009-07-10 15:05:35 +0000 | [diff] [blame] | 49 | outb(byte, 0x70); |
Yinghai Lu | afd34e6 | 2006-02-16 17:22:19 +0000 | [diff] [blame] | 50 | } |
| 51 | |
| 52 | |
| 53 | } |
| 54 | |
| 55 | static void bcm5785_sb_read_resources(device_t dev) |
| 56 | { |
| 57 | struct resource *res; |
Yinghai Lu | afd34e6 | 2006-02-16 17:22:19 +0000 | [diff] [blame] | 58 | |
| 59 | /* Get the normal pci resources of this device */ |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 60 | pci_dev_read_resources(dev); |
| 61 | /* Get Resource for SMBUS */ |
| 62 | pci_get_resource(dev, 0x90); |
Yinghai Lu | afd34e6 | 2006-02-16 17:22:19 +0000 | [diff] [blame] | 63 | |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 64 | compact_resources(dev); |
Yinghai Lu | afd34e6 | 2006-02-16 17:22:19 +0000 | [diff] [blame] | 65 | |
| 66 | /* Add an extra subtractive resource for both memory and I/O */ |
| 67 | res = new_resource(dev, IOINDEX_SUBTRACTIVE(0, 0)); |
| 68 | res->flags = IORESOURCE_IO | IORESOURCE_SUBTRACTIVE | IORESOURCE_ASSIGNED; |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 69 | |
Yinghai Lu | afd34e6 | 2006-02-16 17:22:19 +0000 | [diff] [blame] | 70 | res = new_resource(dev, IOINDEX_SUBTRACTIVE(1, 0)); |
| 71 | res->flags = IORESOURCE_MEM | IORESOURCE_SUBTRACTIVE | IORESOURCE_ASSIGNED; |
| 72 | |
| 73 | } |
Stefan Reinauer | c51dc44 | 2010-04-07 01:44:04 +0000 | [diff] [blame] | 74 | |
Yinghai Lu | afd34e6 | 2006-02-16 17:22:19 +0000 | [diff] [blame] | 75 | static int lsmbus_recv_byte(device_t dev) |
| 76 | { |
| 77 | unsigned device; |
| 78 | struct resource *res; |
| 79 | struct bus *pbus; |
| 80 | |
Stefan Reinauer | 2b34db8 | 2009-02-28 20:10:20 +0000 | [diff] [blame] | 81 | device = dev->path.i2c.device; |
Yinghai Lu | afd34e6 | 2006-02-16 17:22:19 +0000 | [diff] [blame] | 82 | pbus = get_pbus_smbus(dev); |
| 83 | |
| 84 | res = find_resource(pbus->dev, 0x90); |
| 85 | |
| 86 | return do_smbus_recv_byte(res->base, device); |
| 87 | } |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 88 | |
Yinghai Lu | afd34e6 | 2006-02-16 17:22:19 +0000 | [diff] [blame] | 89 | static int lsmbus_send_byte(device_t dev, uint8_t val) |
| 90 | { |
| 91 | unsigned device; |
| 92 | struct resource *res; |
| 93 | struct bus *pbus; |
| 94 | |
Stefan Reinauer | 2b34db8 | 2009-02-28 20:10:20 +0000 | [diff] [blame] | 95 | device = dev->path.i2c.device; |
Yinghai Lu | afd34e6 | 2006-02-16 17:22:19 +0000 | [diff] [blame] | 96 | pbus = get_pbus_smbus(dev); |
| 97 | |
| 98 | res = find_resource(pbus->dev, 0x90); |
| 99 | |
| 100 | return do_smbus_send_byte(res->base, device, val); |
| 101 | } |
Uwe Hermann | c6a1062 | 2010-10-17 19:30:58 +0000 | [diff] [blame] | 102 | |
Yinghai Lu | afd34e6 | 2006-02-16 17:22:19 +0000 | [diff] [blame] | 103 | static int lsmbus_read_byte(device_t dev, uint8_t address) |
| 104 | { |
| 105 | unsigned device; |
| 106 | struct resource *res; |
| 107 | struct bus *pbus; |
| 108 | |
Stefan Reinauer | 2b34db8 | 2009-02-28 20:10:20 +0000 | [diff] [blame] | 109 | device = dev->path.i2c.device; |
Yinghai Lu | afd34e6 | 2006-02-16 17:22:19 +0000 | [diff] [blame] | 110 | pbus = get_pbus_smbus(dev); |
| 111 | |
| 112 | res = find_resource(pbus->dev, 0x90); |
| 113 | |
| 114 | return do_smbus_read_byte(res->base, device, address); |
| 115 | } |
Uwe Hermann | c6a1062 | 2010-10-17 19:30:58 +0000 | [diff] [blame] | 116 | |
Yinghai Lu | afd34e6 | 2006-02-16 17:22:19 +0000 | [diff] [blame] | 117 | static int lsmbus_write_byte(device_t dev, uint8_t address, uint8_t val) |
| 118 | { |
| 119 | unsigned device; |
| 120 | struct resource *res; |
| 121 | struct bus *pbus; |
| 122 | |
Stefan Reinauer | 2b34db8 | 2009-02-28 20:10:20 +0000 | [diff] [blame] | 123 | device = dev->path.i2c.device; |
Yinghai Lu | afd34e6 | 2006-02-16 17:22:19 +0000 | [diff] [blame] | 124 | pbus = get_pbus_smbus(dev); |
| 125 | |
| 126 | res = find_resource(pbus->dev, 0x90); |
| 127 | |
| 128 | return do_smbus_write_byte(res->base, device, address, val); |
| 129 | } |
Uwe Hermann | c6a1062 | 2010-10-17 19:30:58 +0000 | [diff] [blame] | 130 | |
Yinghai Lu | afd34e6 | 2006-02-16 17:22:19 +0000 | [diff] [blame] | 131 | static struct smbus_bus_operations lops_smbus_bus = { |
| 132 | .recv_byte = lsmbus_recv_byte, |
| 133 | .send_byte = lsmbus_send_byte, |
| 134 | .read_byte = lsmbus_read_byte, |
| 135 | .write_byte = lsmbus_write_byte, |
| 136 | }; |
| 137 | |
| 138 | static void lpci_set_subsystem(device_t dev, unsigned vendor, unsigned device) |
| 139 | { |
| 140 | pci_write_config32(dev, 0x2c, |
| 141 | ((device & 0xffff) << 16) | (vendor & 0xffff)); |
| 142 | } |
| 143 | |
| 144 | static struct pci_operations lops_pci = { |
| 145 | .set_subsystem = lpci_set_subsystem, |
| 146 | }; |
| 147 | |
| 148 | static struct device_operations sb_ops = { |
| 149 | .read_resources = bcm5785_sb_read_resources, |
| 150 | .set_resources = pci_dev_set_resources, |
| 151 | .enable_resources = pci_dev_enable_resources, |
| 152 | .init = sb_init, |
Kyösti Mälkki | d0e212c | 2015-02-26 20:47:47 +0200 | [diff] [blame] | 153 | .scan_bus = scan_smbus, |
Yinghai Lu | afd34e6 | 2006-02-16 17:22:19 +0000 | [diff] [blame] | 154 | // .enable = bcm5785_enable, |
| 155 | .ops_pci = &lops_pci, |
| 156 | .ops_smbus_bus = &lops_smbus_bus, |
| 157 | }; |
Uwe Hermann | c6a1062 | 2010-10-17 19:30:58 +0000 | [diff] [blame] | 158 | |
Stefan Reinauer | f1cf1f7 | 2007-10-24 09:08:58 +0000 | [diff] [blame] | 159 | static const struct pci_driver sb_driver __pci_driver = { |
Yinghai Lu | afd34e6 | 2006-02-16 17:22:19 +0000 | [diff] [blame] | 160 | .ops = &sb_ops, |
| 161 | .vendor = PCI_VENDOR_ID_SERVERWORKS, |
| 162 | .device = PCI_DEVICE_ID_SERVERWORKS_BCM5785_SB_PCI_MAIN, |
| 163 | }; |