Kyösti Mälkki | e8b4da2 | 2014-10-21 18:22:32 +0300 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright (C) 2013 Sage Electronic Engineering, LLC |
| 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. |
Kyösti Mälkki | e8b4da2 | 2014-10-21 18:22:32 +0300 | [diff] [blame] | 14 | */ |
| 15 | |
| 16 | #include <device/device.h> |
Kyösti Mälkki | e8b4da2 | 2014-10-21 18:22:32 +0300 | [diff] [blame] | 17 | #include <device/pci.h> |
| 18 | #include <device/pci_ids.h> |
| 19 | #include <device/pci_ops.h> |
Elyes HAOUAS | bf0970e | 2019-03-21 11:10:03 +0100 | [diff] [blame] | 20 | |
Kyösti Mälkki | 830e0de | 2019-08-19 13:29:46 +0300 | [diff] [blame^] | 21 | #include "chip.h" |
Kyösti Mälkki | e8b4da2 | 2014-10-21 18:22:32 +0300 | [diff] [blame] | 22 | #include "hudson.h" |
| 23 | |
| 24 | static void sd_init(struct device *dev) |
| 25 | { |
Kyösti Mälkki | 830e0de | 2019-08-19 13:29:46 +0300 | [diff] [blame^] | 26 | struct southbridge_amd_pi_hudson_config *sd_chip = dev->chip_info; |
| 27 | u32 stepping = pci_read_config32(pcidev_on_root(0x18, 3), 0xFC); |
| 28 | u8 sd_mode = 0; |
Kyösti Mälkki | e8b4da2 | 2014-10-21 18:22:32 +0300 | [diff] [blame] | 29 | |
Kyösti Mälkki | 830e0de | 2019-08-19 13:29:46 +0300 | [diff] [blame^] | 30 | if (sd_chip) |
| 31 | sd_mode = sd_chip->sd_mode; |
Kyösti Mälkki | e8b4da2 | 2014-10-21 18:22:32 +0300 | [diff] [blame] | 32 | |
Kyösti Mälkki | 830e0de | 2019-08-19 13:29:46 +0300 | [diff] [blame^] | 33 | if (sd_mode == 3) { /* SD 3.0 mode */ |
Kyösti Mälkki | e8b4da2 | 2014-10-21 18:22:32 +0300 | [diff] [blame] | 34 | pci_write_config32(dev, 0xA4, 0x31FEC8B2); |
| 35 | pci_write_config32(dev, 0xA8, 0x00002503); |
| 36 | pci_write_config32(dev, 0xB0, 0x02180C19); |
| 37 | pci_write_config32(dev, 0xD0, 0x0000078B); |
| 38 | } |
| 39 | else { /* SD 2.0 mode */ |
| 40 | if ((stepping & 0x0000000F) == 0) { /* Stepping A0 */ |
| 41 | pci_write_config32(dev, 0xA4, 0x31DE32B2); |
| 42 | pci_write_config32(dev, 0xB0, 0x01180C19); |
| 43 | pci_write_config32(dev, 0xD0, 0x0000058B); |
| 44 | } |
| 45 | else { /* Stepping >= A1 */ |
Michał Żygowski | 654a45d | 2018-07-05 16:53:44 +0200 | [diff] [blame] | 46 | pci_write_config32(dev, 0xA4, 0x31FE32B2); |
| 47 | pci_write_config32(dev, 0xA8, 0x00000070); |
Kyösti Mälkki | e8b4da2 | 2014-10-21 18:22:32 +0300 | [diff] [blame] | 48 | pci_write_config32(dev, 0xB0, 0x01180C19); |
| 49 | pci_write_config32(dev, 0xD0, 0x0000078B); |
| 50 | } |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | static struct device_operations sd_ops = { |
| 55 | .read_resources = pci_dev_read_resources, |
| 56 | .set_resources = pci_dev_set_resources, |
| 57 | .enable_resources = pci_dev_enable_resources, |
| 58 | .init = sd_init, |
| 59 | .scan_bus = 0, |
| 60 | }; |
| 61 | |
| 62 | static const struct pci_driver sd_driver __pci_driver = { |
| 63 | .ops = &sd_ops, |
| 64 | .vendor = PCI_VENDOR_ID_AMD, |
| 65 | .device = PCI_DEVICE_ID_AMD_YANGTZE_SD, |
| 66 | }; |