18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-or-later 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * read/write operation to the PCI config space of CS5536 48c2ecf20Sopenharmony_ci * 58c2ecf20Sopenharmony_ci * Copyright (C) 2007 Lemote, Inc. 68c2ecf20Sopenharmony_ci * Author : jlliu, liujl@lemote.com 78c2ecf20Sopenharmony_ci * 88c2ecf20Sopenharmony_ci * Copyright (C) 2009 Lemote, Inc. 98c2ecf20Sopenharmony_ci * Author: Wu Zhangjin, wuzhangjin@gmail.com 108c2ecf20Sopenharmony_ci * 118c2ecf20Sopenharmony_ci * the Virtual Support Module(VSM) for virtulizing the PCI 128c2ecf20Sopenharmony_ci * configure space are defined in cs5536_modulename.c respectively, 138c2ecf20Sopenharmony_ci * 148c2ecf20Sopenharmony_ci * after this virtulizing, user can access the PCI configure space 158c2ecf20Sopenharmony_ci * directly as a normal multi-function PCI device which follows 168c2ecf20Sopenharmony_ci * the PCI-2.2 spec. 178c2ecf20Sopenharmony_ci */ 188c2ecf20Sopenharmony_ci 198c2ecf20Sopenharmony_ci#include <linux/types.h> 208c2ecf20Sopenharmony_ci#include <cs5536/cs5536_pci.h> 218c2ecf20Sopenharmony_ci#include <cs5536/cs5536_vsm.h> 228c2ecf20Sopenharmony_ci 238c2ecf20Sopenharmony_cienum { 248c2ecf20Sopenharmony_ci CS5536_FUNC_START = -1, 258c2ecf20Sopenharmony_ci CS5536_ISA_FUNC, 268c2ecf20Sopenharmony_ci reserved_func, 278c2ecf20Sopenharmony_ci CS5536_IDE_FUNC, 288c2ecf20Sopenharmony_ci CS5536_ACC_FUNC, 298c2ecf20Sopenharmony_ci CS5536_OHCI_FUNC, 308c2ecf20Sopenharmony_ci CS5536_EHCI_FUNC, 318c2ecf20Sopenharmony_ci CS5536_FUNC_END, 328c2ecf20Sopenharmony_ci}; 338c2ecf20Sopenharmony_ci 348c2ecf20Sopenharmony_cistatic const cs5536_pci_vsm_write vsm_conf_write[] = { 358c2ecf20Sopenharmony_ci [CS5536_ISA_FUNC] = pci_isa_write_reg, 368c2ecf20Sopenharmony_ci [reserved_func] = NULL, 378c2ecf20Sopenharmony_ci [CS5536_IDE_FUNC] = pci_ide_write_reg, 388c2ecf20Sopenharmony_ci [CS5536_ACC_FUNC] = pci_acc_write_reg, 398c2ecf20Sopenharmony_ci [CS5536_OHCI_FUNC] = pci_ohci_write_reg, 408c2ecf20Sopenharmony_ci [CS5536_EHCI_FUNC] = pci_ehci_write_reg, 418c2ecf20Sopenharmony_ci}; 428c2ecf20Sopenharmony_ci 438c2ecf20Sopenharmony_cistatic const cs5536_pci_vsm_read vsm_conf_read[] = { 448c2ecf20Sopenharmony_ci [CS5536_ISA_FUNC] = pci_isa_read_reg, 458c2ecf20Sopenharmony_ci [reserved_func] = NULL, 468c2ecf20Sopenharmony_ci [CS5536_IDE_FUNC] = pci_ide_read_reg, 478c2ecf20Sopenharmony_ci [CS5536_ACC_FUNC] = pci_acc_read_reg, 488c2ecf20Sopenharmony_ci [CS5536_OHCI_FUNC] = pci_ohci_read_reg, 498c2ecf20Sopenharmony_ci [CS5536_EHCI_FUNC] = pci_ehci_read_reg, 508c2ecf20Sopenharmony_ci}; 518c2ecf20Sopenharmony_ci 528c2ecf20Sopenharmony_ci/* 538c2ecf20Sopenharmony_ci * write to PCI config space and transfer it to MSR write. 548c2ecf20Sopenharmony_ci */ 558c2ecf20Sopenharmony_civoid cs5536_pci_conf_write4(int function, int reg, u32 value) 568c2ecf20Sopenharmony_ci{ 578c2ecf20Sopenharmony_ci if ((function <= CS5536_FUNC_START) || (function >= CS5536_FUNC_END)) 588c2ecf20Sopenharmony_ci return; 598c2ecf20Sopenharmony_ci if ((reg < 0) || (reg > 0x100) || ((reg & 0x03) != 0)) 608c2ecf20Sopenharmony_ci return; 618c2ecf20Sopenharmony_ci 628c2ecf20Sopenharmony_ci if (vsm_conf_write[function] != NULL) 638c2ecf20Sopenharmony_ci vsm_conf_write[function](reg, value); 648c2ecf20Sopenharmony_ci} 658c2ecf20Sopenharmony_ci 668c2ecf20Sopenharmony_ci/* 678c2ecf20Sopenharmony_ci * read PCI config space and transfer it to MSR access. 688c2ecf20Sopenharmony_ci */ 698c2ecf20Sopenharmony_ciu32 cs5536_pci_conf_read4(int function, int reg) 708c2ecf20Sopenharmony_ci{ 718c2ecf20Sopenharmony_ci u32 data = 0; 728c2ecf20Sopenharmony_ci 738c2ecf20Sopenharmony_ci if ((function <= CS5536_FUNC_START) || (function >= CS5536_FUNC_END)) 748c2ecf20Sopenharmony_ci return 0; 758c2ecf20Sopenharmony_ci if ((reg < 0) || ((reg & 0x03) != 0)) 768c2ecf20Sopenharmony_ci return 0; 778c2ecf20Sopenharmony_ci if (reg > 0x100) 788c2ecf20Sopenharmony_ci return 0xffffffff; 798c2ecf20Sopenharmony_ci 808c2ecf20Sopenharmony_ci if (vsm_conf_read[function] != NULL) 818c2ecf20Sopenharmony_ci data = vsm_conf_read[function](reg); 828c2ecf20Sopenharmony_ci 838c2ecf20Sopenharmony_ci return data; 848c2ecf20Sopenharmony_ci} 85