1 /* Copyright 2017 IBM Corp.
2  *
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * 	http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
12  * implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #define pr_fmt(fmt)  "PCI-QUIRK: " fmt
18 
19 #include <skiboot.h>
20 #include <pci.h>
21 #include <pci-quirk.h>
22 #include <platform.h>
23 #include <ast.h>
24 
quirk_astbmc_vga(struct phb * phb __unused,struct pci_device * pd)25 static void quirk_astbmc_vga(struct phb *phb __unused,
26 			     struct pci_device *pd)
27 {
28 	struct dt_node *np = pd->dn;
29 	uint32_t revision, mcr_configuration, mcr_scu_mpll, mcr_scu_strap;
30 
31 	if (ast_sio_is_enabled()) {
32 		revision = ast_ahb_readl(SCU_REVISION_ID);
33 		mcr_configuration = ast_ahb_readl(MCR_CONFIGURATION);
34 		mcr_scu_mpll = ast_ahb_readl(MCR_SCU_MPLL);
35 		mcr_scu_strap = ast_ahb_readl(MCR_SCU_STRAP);
36 	} else {
37 		/* Previously we would warn, now SIO disabled by design */
38 		prlog(PR_INFO, "Assumed platform default parameters for %s\n",
39 		      __func__);
40 		revision = bmc_platform->hw->scu_revision_id;
41 		mcr_configuration = bmc_platform->hw->mcr_configuration;
42 		mcr_scu_mpll = bmc_platform->hw->mcr_scu_mpll;
43 		mcr_scu_strap = bmc_platform->hw->mcr_scu_strap;
44 	}
45 
46 	dt_add_property_cells(np, "aspeed,scu-revision-id", revision);
47 	dt_add_property_cells(np, "aspeed,mcr-configuration", mcr_configuration);
48 	dt_add_property_cells(np, "aspeed,mcr-scu-mpll", mcr_scu_mpll);
49 	dt_add_property_cells(np, "aspeed,mcr-scu-strap", mcr_scu_strap);
50 }
51 
52 /* Quirks are: {fixup function, vendor ID, (device ID or PCI_ANY_ID)} */
53 static const struct pci_quirk quirk_table[] = {
54 	/* ASPEED 2400 VGA device */
55 	{ &quirk_astbmc_vga, 0x1a03, 0x2000 },
56 	{ NULL, 0, 0 }
57 };
58 
__pci_handle_quirk(struct phb * phb,struct pci_device * pd,const struct pci_quirk * quirks)59 static void __pci_handle_quirk(struct phb *phb, struct pci_device *pd,
60 			       const struct pci_quirk *quirks)
61 {
62 	while (quirks->vendor_id) {
63 		if (quirks->vendor_id == PCI_VENDOR_ID(pd->vdid) &&
64 		    (quirks->device_id == PCI_ANY_ID ||
65 		     quirks->device_id == PCI_DEVICE_ID(pd->vdid)))
66 			quirks->fixup(phb, pd);
67 		quirks++;
68 	}
69 }
70 
pci_handle_quirk(struct phb * phb,struct pci_device * pd)71 void pci_handle_quirk(struct phb *phb, struct pci_device *pd)
72 {
73 	__pci_handle_quirk(phb, pd, quirk_table);
74 }
75