Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright (C) 2010 Advanced Micro Devices, Inc. |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; version 2 of the License. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | */ |
| 15 | |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 16 | #include <device/device.h> |
| 17 | #include <device/pci.h> |
| 18 | #include <device/pci_ids.h> |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 19 | #include <device/smbus.h> |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 20 | #include <cpu/x86/lapic.h> |
| 21 | #include <arch/ioapic.h> |
Marc Jones | dfeb1c4 | 2017-08-07 19:08:24 -0600 | [diff] [blame] | 22 | #include <soc/southbridge.h> |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 23 | #include <soc/smbus.h> |
| 24 | |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 25 | /* |
Marc Jones | dfeb1c4 | 2017-08-07 19:08:24 -0600 | [diff] [blame] | 26 | * The southbridge enables all USB controllers by default in SMBUS Control. |
| 27 | * The southbridge enables SATA by default in SMBUS Control. |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 28 | */ |
| 29 | |
Elyes HAOUAS | 777ccd4 | 2018-05-22 10:52:05 +0200 | [diff] [blame] | 30 | static void sm_init(struct device *dev) |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 31 | { |
| 32 | setup_ioapic(VIO_APIC_VADDR, CONFIG_MAX_CPUS); |
| 33 | } |
| 34 | |
Richard Spiegel | b40e193 | 2018-10-24 12:51:21 -0700 | [diff] [blame] | 35 | static u32 get_sm_mmio(struct device *dev) |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 36 | { |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 37 | struct resource *res; |
| 38 | struct bus *pbus; |
| 39 | |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 40 | pbus = get_pbus_smbus(dev); |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 41 | res = find_resource(pbus->dev, 0x90); |
Richard Spiegel | b40e193 | 2018-10-24 12:51:21 -0700 | [diff] [blame] | 42 | if (res->base == SMB_BASE_ADDR) |
Marshall Dawson | 5de4771 | 2019-05-01 16:14:42 -0600 | [diff] [blame] | 43 | return ACPIMMIO_SMBUS_BASE; |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 44 | |
Marshall Dawson | 5de4771 | 2019-05-01 16:14:42 -0600 | [diff] [blame] | 45 | return ACPIMMIO_ASF_BASE; |
Richard Spiegel | b40e193 | 2018-10-24 12:51:21 -0700 | [diff] [blame] | 46 | } |
| 47 | |
| 48 | static int lsmbus_recv_byte(struct device *dev) |
| 49 | { |
| 50 | u8 device; |
| 51 | |
| 52 | device = dev->path.i2c.device; |
| 53 | return do_smbus_recv_byte(get_sm_mmio(dev), device); |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 54 | } |
| 55 | |
Elyes HAOUAS | 777ccd4 | 2018-05-22 10:52:05 +0200 | [diff] [blame] | 56 | static int lsmbus_send_byte(struct device *dev, u8 val) |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 57 | { |
Richard Spiegel | cd04e31 | 2017-11-08 14:58:30 -0700 | [diff] [blame] | 58 | u8 device; |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 59 | |
| 60 | device = dev->path.i2c.device; |
Richard Spiegel | b40e193 | 2018-10-24 12:51:21 -0700 | [diff] [blame] | 61 | return do_smbus_send_byte(get_sm_mmio(dev), device, val); |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 62 | } |
| 63 | |
Elyes HAOUAS | 777ccd4 | 2018-05-22 10:52:05 +0200 | [diff] [blame] | 64 | static int lsmbus_read_byte(struct device *dev, u8 address) |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 65 | { |
Richard Spiegel | cd04e31 | 2017-11-08 14:58:30 -0700 | [diff] [blame] | 66 | u8 device; |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 67 | |
| 68 | device = dev->path.i2c.device; |
Richard Spiegel | b40e193 | 2018-10-24 12:51:21 -0700 | [diff] [blame] | 69 | return do_smbus_read_byte(get_sm_mmio(dev), device, address); |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 70 | } |
| 71 | |
Elyes HAOUAS | 777ccd4 | 2018-05-22 10:52:05 +0200 | [diff] [blame] | 72 | static int lsmbus_write_byte(struct device *dev, u8 address, u8 val) |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 73 | { |
Richard Spiegel | cd04e31 | 2017-11-08 14:58:30 -0700 | [diff] [blame] | 74 | u8 device; |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 75 | |
| 76 | device = dev->path.i2c.device; |
Richard Spiegel | b40e193 | 2018-10-24 12:51:21 -0700 | [diff] [blame] | 77 | return do_smbus_write_byte(get_sm_mmio(dev), device, address, val); |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 78 | } |
| 79 | static struct smbus_bus_operations lops_smbus_bus = { |
| 80 | .recv_byte = lsmbus_recv_byte, |
| 81 | .send_byte = lsmbus_send_byte, |
| 82 | .read_byte = lsmbus_read_byte, |
| 83 | .write_byte = lsmbus_write_byte, |
| 84 | }; |
| 85 | |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 86 | static struct pci_operations lops_pci = { |
| 87 | .set_subsystem = pci_dev_set_subsystem, |
| 88 | }; |
| 89 | static struct device_operations smbus_ops = { |
Richard Spiegel | cd04e31 | 2017-11-08 14:58:30 -0700 | [diff] [blame] | 90 | .read_resources = DEVICE_NOOP, |
| 91 | .set_resources = DEVICE_NOOP, |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 92 | .enable_resources = pci_dev_enable_resources, |
| 93 | .init = sm_init, |
| 94 | .scan_bus = scan_smbus, |
| 95 | .ops_pci = &lops_pci, |
| 96 | .ops_smbus_bus = &lops_smbus_bus, |
| 97 | }; |
| 98 | static const struct pci_driver smbus_driver __pci_driver = { |
| 99 | .ops = &smbus_ops, |
| 100 | .vendor = PCI_VENDOR_ID_AMD, |
Martin Roth | 069ca66 | 2018-03-01 11:26:18 -0700 | [diff] [blame] | 101 | .device = PCI_DEVICE_ID_AMD_CZ_SMBUS, |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 102 | }; |