Angel Pons | 182dbde | 2020-04-02 23:49:05 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Arthur Heymans | 7b9c139 | 2017-04-09 20:40:39 +0200 | [diff] [blame] | 2 | |
| 3 | #include <console/console.h> |
| 4 | #include <device/device.h> |
| 5 | #include <device/pci.h> |
| 6 | #include <device/pci_ids.h> |
| 7 | #include <device/pci_ops.h> |
Kyösti Mälkki | 13f6650 | 2019-03-03 08:01:05 +0200 | [diff] [blame] | 8 | #include <device/mmio.h> |
Arthur Heymans | 7b9c139 | 2017-04-09 20:40:39 +0200 | [diff] [blame] | 9 | #include <device/azalia_device.h> |
Kyösti Mälkki | 12b121c | 2019-08-18 16:33:39 +0300 | [diff] [blame] | 10 | #include "chip.h" |
Arthur Heymans | 349e085 | 2017-04-09 20:48:37 +0200 | [diff] [blame] | 11 | #include "i82801jx.h" |
Arthur Heymans | 7b9c139 | 2017-04-09 20:40:39 +0200 | [diff] [blame] | 12 | |
Arthur Heymans | 7b9c139 | 2017-04-09 20:40:39 +0200 | [diff] [blame] | 13 | static int codec_detect(u8 *base) |
| 14 | { |
| 15 | u32 reg32; |
| 16 | |
Angel Pons | 2e0053b | 2020-12-05 19:06:55 +0100 | [diff] [blame] | 17 | if (azalia_enter_reset(base) < 0) |
Arthur Heymans | 7b9c139 | 2017-04-09 20:40:39 +0200 | [diff] [blame] | 18 | goto no_codec; |
| 19 | |
Angel Pons | 7f839f6 | 2020-12-05 19:02:14 +0100 | [diff] [blame] | 20 | if (azalia_exit_reset(base) < 0) |
Arthur Heymans | 7b9c139 | 2017-04-09 20:40:39 +0200 | [diff] [blame] | 21 | goto no_codec; |
| 22 | |
Elyes HAOUAS | 6ea24ff | 2020-08-11 09:21:24 +0200 | [diff] [blame] | 23 | /* Read in Codec location (BAR + 0xe)[2..0] */ |
Elyes HAOUAS | 388c88b | 2020-08-03 15:36:20 +0200 | [diff] [blame] | 24 | reg32 = read32(base + HDA_STATESTS_REG); |
Arthur Heymans | 7b9c139 | 2017-04-09 20:40:39 +0200 | [diff] [blame] | 25 | reg32 &= 0x0f; |
| 26 | if (!reg32) |
| 27 | goto no_codec; |
| 28 | |
| 29 | return reg32; |
| 30 | |
| 31 | no_codec: |
Angel Pons | 2e0053b | 2020-12-05 19:06:55 +0100 | [diff] [blame] | 32 | /* Codec not found, put HDA back in reset */ |
| 33 | azalia_enter_reset(base); |
Arthur Heymans | 7b9c139 | 2017-04-09 20:40:39 +0200 | [diff] [blame] | 34 | printk(BIOS_DEBUG, "Azalia: No codec!\n"); |
| 35 | return 0; |
| 36 | } |
| 37 | |
Arthur Heymans | 7b9c139 | 2017-04-09 20:40:39 +0200 | [diff] [blame] | 38 | static void azalia_init(struct device *dev) |
| 39 | { |
| 40 | u8 *base; |
| 41 | struct resource *res; |
| 42 | u32 codec_mask; |
Arthur Heymans | 7b9c139 | 2017-04-09 20:40:39 +0200 | [diff] [blame] | 43 | |
| 44 | // ESD |
Angel Pons | 2048cb4 | 2020-06-08 02:09:33 +0200 | [diff] [blame] | 45 | pci_update_config32(dev, 0x134, ~0x00ff0000, 2 << 16); |
Arthur Heymans | 7b9c139 | 2017-04-09 20:40:39 +0200 | [diff] [blame] | 46 | |
| 47 | // Link1 description |
Angel Pons | 2048cb4 | 2020-06-08 02:09:33 +0200 | [diff] [blame] | 48 | pci_update_config32(dev, 0x140, ~0x00ff0000, 2 << 16); |
Arthur Heymans | 7b9c139 | 2017-04-09 20:40:39 +0200 | [diff] [blame] | 49 | |
| 50 | // Port VC0 Resource Control Register |
Angel Pons | 2048cb4 | 2020-06-08 02:09:33 +0200 | [diff] [blame] | 51 | pci_update_config32(dev, 0x114, ~0x000000ff, 1); |
Arthur Heymans | 7b9c139 | 2017-04-09 20:40:39 +0200 | [diff] [blame] | 52 | |
| 53 | // VCi traffic class |
Angel Pons | 7a2864b | 2020-06-21 13:29:28 +0200 | [diff] [blame] | 54 | pci_or_config8(dev, 0x44, 7 << 0); // TC7 |
Arthur Heymans | 7b9c139 | 2017-04-09 20:40:39 +0200 | [diff] [blame] | 55 | |
| 56 | // VCi Resource Control |
Angel Pons | 2048cb4 | 2020-06-08 02:09:33 +0200 | [diff] [blame] | 57 | pci_or_config32(dev, 0x120, (1 << 31) | (1 << 24) | (0x80 << 0)); /* VCi ID and map */ |
Arthur Heymans | 7b9c139 | 2017-04-09 20:40:39 +0200 | [diff] [blame] | 58 | |
| 59 | /* Set Bus Master */ |
Elyes HAOUAS | ca4ff25 | 2020-04-28 10:29:11 +0200 | [diff] [blame] | 60 | pci_or_config16(dev, PCI_COMMAND, PCI_COMMAND_MASTER); |
Arthur Heymans | 7b9c139 | 2017-04-09 20:40:39 +0200 | [diff] [blame] | 61 | |
Angel Pons | 2048cb4 | 2020-06-08 02:09:33 +0200 | [diff] [blame] | 62 | // Docking not supported |
| 63 | pci_and_config8(dev, 0x4d, (u8)~(1 << 7)); // Docking Status |
Arthur Heymans | 7b9c139 | 2017-04-09 20:40:39 +0200 | [diff] [blame] | 64 | |
| 65 | /* Lock some R/WO bits by writing their current value. */ |
Angel Pons | 2048cb4 | 2020-06-08 02:09:33 +0200 | [diff] [blame] | 66 | pci_update_config32(dev, 0x74, ~0, 0); |
Arthur Heymans | 7b9c139 | 2017-04-09 20:40:39 +0200 | [diff] [blame] | 67 | |
Angel Pons | f32ae10 | 2021-11-03 13:07:14 +0100 | [diff] [blame] | 68 | res = probe_resource(dev, PCI_BASE_ADDRESS_0); |
Arthur Heymans | 7b9c139 | 2017-04-09 20:40:39 +0200 | [diff] [blame] | 69 | if (!res) |
| 70 | return; |
| 71 | |
Martin Roth | 26f97f9 | 2021-10-01 14:53:22 -0600 | [diff] [blame] | 72 | // NOTE this will break as soon as the Azalia gets a bar above 4G. |
Elyes HAOUAS | 6ea24ff | 2020-08-11 09:21:24 +0200 | [diff] [blame] | 73 | // Is there anything we can do about it? |
Arthur Heymans | 7b9c139 | 2017-04-09 20:40:39 +0200 | [diff] [blame] | 74 | base = res2mmio(res, 0, 0); |
Angel Pons | 7a2864b | 2020-06-21 13:29:28 +0200 | [diff] [blame] | 75 | printk(BIOS_DEBUG, "Azalia: base = %p\n", base); |
Arthur Heymans | 7b9c139 | 2017-04-09 20:40:39 +0200 | [diff] [blame] | 76 | codec_mask = codec_detect(base); |
| 77 | |
| 78 | if (codec_mask) { |
| 79 | printk(BIOS_DEBUG, "Azalia: codec_mask = %02x\n", codec_mask); |
Angel Pons | aae6b55 | 2021-11-10 18:10:38 +0100 | [diff] [blame] | 80 | azalia_codecs_init(base, codec_mask); |
Arthur Heymans | 7b9c139 | 2017-04-09 20:40:39 +0200 | [diff] [blame] | 81 | } |
| 82 | } |
| 83 | |
Arthur Heymans | 7b9c139 | 2017-04-09 20:40:39 +0200 | [diff] [blame] | 84 | static struct device_operations azalia_ops = { |
| 85 | .read_resources = pci_dev_read_resources, |
| 86 | .set_resources = pci_dev_set_resources, |
| 87 | .enable_resources = pci_dev_enable_resources, |
| 88 | .init = azalia_init, |
Angel Pons | 1fc0edd | 2020-05-31 00:03:28 +0200 | [diff] [blame] | 89 | .ops_pci = &pci_dev_ops_pci, |
Arthur Heymans | 7b9c139 | 2017-04-09 20:40:39 +0200 | [diff] [blame] | 90 | }; |
| 91 | |
Arthur Heymans | 349e085 | 2017-04-09 20:48:37 +0200 | [diff] [blame] | 92 | static const unsigned short pci_device_ids[] = { |
| 93 | 0x3a3e, |
| 94 | 0x3a6e, |
| 95 | 0 |
| 96 | }; |
| 97 | |
| 98 | static const struct pci_driver i82801jx_azalia __pci_driver = { |
Arthur Heymans | 7b9c139 | 2017-04-09 20:40:39 +0200 | [diff] [blame] | 99 | .ops = &azalia_ops, |
Felix Singer | 43b7f41 | 2022-03-07 04:34:52 +0100 | [diff] [blame] | 100 | .vendor = PCI_VID_INTEL, |
Arthur Heymans | 349e085 | 2017-04-09 20:48:37 +0200 | [diff] [blame] | 101 | .devices = pci_device_ids, |
Arthur Heymans | 7b9c139 | 2017-04-09 20:40:39 +0200 | [diff] [blame] | 102 | }; |