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> |
| 19 | #include <device/pci_ops.h> |
| 20 | #include <device/smbus.h> |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 21 | #include <arch/io.h> |
| 22 | #include <cpu/x86/lapic.h> |
| 23 | #include <arch/ioapic.h> |
| 24 | #include <stdlib.h> |
Marc Jones | dfeb1c4 | 2017-08-07 19:08:24 -0600 | [diff] [blame] | 25 | #include <soc/southbridge.h> |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 26 | #include <soc/smbus.h> |
| 27 | |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 28 | /* |
Marc Jones | dfeb1c4 | 2017-08-07 19:08:24 -0600 | [diff] [blame] | 29 | * The southbridge enables all USB controllers by default in SMBUS Control. |
| 30 | * The southbridge enables SATA by default in SMBUS Control. |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 31 | */ |
| 32 | |
Elyes HAOUAS | 777ccd4 | 2018-05-22 10:52:05 +0200 | [diff] [blame] | 33 | static void sm_init(struct device *dev) |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 34 | { |
| 35 | setup_ioapic(VIO_APIC_VADDR, CONFIG_MAX_CPUS); |
| 36 | } |
| 37 | |
Richard Spiegel | b40e193 | 2018-10-24 12:51:21 -0700 | [diff] [blame^] | 38 | static u32 get_sm_mmio(struct device *dev) |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 39 | { |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 40 | struct resource *res; |
| 41 | struct bus *pbus; |
| 42 | |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 43 | pbus = get_pbus_smbus(dev); |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 44 | res = find_resource(pbus->dev, 0x90); |
Richard Spiegel | b40e193 | 2018-10-24 12:51:21 -0700 | [diff] [blame^] | 45 | if (res->base == SMB_BASE_ADDR) |
| 46 | return SMBUS_MMIO_BASE; |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 47 | |
Richard Spiegel | b40e193 | 2018-10-24 12:51:21 -0700 | [diff] [blame^] | 48 | return ASF_MMIO_BASE; |
| 49 | } |
| 50 | |
| 51 | static int lsmbus_recv_byte(struct device *dev) |
| 52 | { |
| 53 | u8 device; |
| 54 | |
| 55 | device = dev->path.i2c.device; |
| 56 | return do_smbus_recv_byte(get_sm_mmio(dev), device); |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 57 | } |
| 58 | |
Elyes HAOUAS | 777ccd4 | 2018-05-22 10:52:05 +0200 | [diff] [blame] | 59 | static int lsmbus_send_byte(struct device *dev, u8 val) |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 60 | { |
Richard Spiegel | cd04e31 | 2017-11-08 14:58:30 -0700 | [diff] [blame] | 61 | u8 device; |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 62 | |
| 63 | device = dev->path.i2c.device; |
Richard Spiegel | b40e193 | 2018-10-24 12:51:21 -0700 | [diff] [blame^] | 64 | return do_smbus_send_byte(get_sm_mmio(dev), device, val); |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 65 | } |
| 66 | |
Elyes HAOUAS | 777ccd4 | 2018-05-22 10:52:05 +0200 | [diff] [blame] | 67 | static int lsmbus_read_byte(struct device *dev, u8 address) |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 68 | { |
Richard Spiegel | cd04e31 | 2017-11-08 14:58:30 -0700 | [diff] [blame] | 69 | u8 device; |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 70 | |
| 71 | device = dev->path.i2c.device; |
Richard Spiegel | b40e193 | 2018-10-24 12:51:21 -0700 | [diff] [blame^] | 72 | return do_smbus_read_byte(get_sm_mmio(dev), device, address); |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 73 | } |
| 74 | |
Elyes HAOUAS | 777ccd4 | 2018-05-22 10:52:05 +0200 | [diff] [blame] | 75 | static int lsmbus_write_byte(struct device *dev, u8 address, u8 val) |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 76 | { |
Richard Spiegel | cd04e31 | 2017-11-08 14:58:30 -0700 | [diff] [blame] | 77 | u8 device; |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 78 | |
| 79 | device = dev->path.i2c.device; |
Richard Spiegel | b40e193 | 2018-10-24 12:51:21 -0700 | [diff] [blame^] | 80 | return do_smbus_write_byte(get_sm_mmio(dev), device, address, val); |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 81 | } |
| 82 | static struct smbus_bus_operations lops_smbus_bus = { |
| 83 | .recv_byte = lsmbus_recv_byte, |
| 84 | .send_byte = lsmbus_send_byte, |
| 85 | .read_byte = lsmbus_read_byte, |
| 86 | .write_byte = lsmbus_write_byte, |
| 87 | }; |
| 88 | |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 89 | static struct pci_operations lops_pci = { |
| 90 | .set_subsystem = pci_dev_set_subsystem, |
| 91 | }; |
| 92 | static struct device_operations smbus_ops = { |
Richard Spiegel | cd04e31 | 2017-11-08 14:58:30 -0700 | [diff] [blame] | 93 | .read_resources = DEVICE_NOOP, |
| 94 | .set_resources = DEVICE_NOOP, |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 95 | .enable_resources = pci_dev_enable_resources, |
| 96 | .init = sm_init, |
| 97 | .scan_bus = scan_smbus, |
| 98 | .ops_pci = &lops_pci, |
| 99 | .ops_smbus_bus = &lops_smbus_bus, |
| 100 | }; |
| 101 | static const struct pci_driver smbus_driver __pci_driver = { |
| 102 | .ops = &smbus_ops, |
| 103 | .vendor = PCI_VENDOR_ID_AMD, |
Martin Roth | 069ca66 | 2018-03-01 11:26:18 -0700 | [diff] [blame] | 104 | .device = PCI_DEVICE_ID_AMD_CZ_SMBUS, |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 105 | }; |