1873e65bcSThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only 2cf4ece53SMasayuki Ohtak /* 37f2732c8STomoya MORINAGA * Copyright (C) 2011 LAPIS Semiconductor Co., Ltd. 4cf4ece53SMasayuki Ohtak */ 5cf4ece53SMasayuki Ohtak 6cf4ece53SMasayuki Ohtak #include <linux/module.h> 7cf4ece53SMasayuki Ohtak #include <linux/kernel.h> 8cf4ece53SMasayuki Ohtak #include <linux/types.h> 9cf4ece53SMasayuki Ohtak #include <linux/fs.h> 10cf4ece53SMasayuki Ohtak #include <linux/uaccess.h> 11cf4ece53SMasayuki Ohtak #include <linux/string.h> 12cf4ece53SMasayuki Ohtak #include <linux/pci.h> 13cf4ece53SMasayuki Ohtak #include <linux/io.h> 14cf4ece53SMasayuki Ohtak #include <linux/delay.h> 15cf4ece53SMasayuki Ohtak #include <linux/mutex.h> 16cf4ece53SMasayuki Ohtak #include <linux/if_ether.h> 17cf4ece53SMasayuki Ohtak #include <linux/ctype.h> 186ae705b2SDenis Turischev #include <linux/dmi.h> 19549ce8f1SZubair Lutfullah Kakakhel #include <linux/of.h> 20cf4ece53SMasayuki Ohtak 21cf4ece53SMasayuki Ohtak #define PHUB_STATUS 0x00 /* Status Register offset */ 22cf4ece53SMasayuki Ohtak #define PHUB_CONTROL 0x04 /* Control Register offset */ 23cf4ece53SMasayuki Ohtak #define PHUB_TIMEOUT 0x05 /* Time out value for Status Register */ 24cf4ece53SMasayuki Ohtak #define PCH_PHUB_ROM_WRITE_ENABLE 0x01 /* Enabling for writing ROM */ 25cf4ece53SMasayuki Ohtak #define PCH_PHUB_ROM_WRITE_DISABLE 0x00 /* Disabling for writing ROM */ 26275640b0STomoya MORINAGA #define PCH_PHUB_MAC_START_ADDR_EG20T 0x14 /* MAC data area start address 27275640b0STomoya MORINAGA offset */ 28275640b0STomoya MORINAGA #define PCH_PHUB_MAC_START_ADDR_ML7223 0x20C /* MAC data area start address 29275640b0STomoya MORINAGA offset */ 30275640b0STomoya MORINAGA #define PCH_PHUB_ROM_START_ADDR_EG20T 0x80 /* ROM data area start address offset 31c47dda7dSTomoya MORINAGA (Intel EG20T PCH)*/ 32c47dda7dSTomoya MORINAGA #define PCH_PHUB_ROM_START_ADDR_ML7213 0x400 /* ROM data area start address 337f2732c8STomoya MORINAGA offset(LAPIS Semicon ML7213) 34c47dda7dSTomoya MORINAGA */ 35275640b0STomoya MORINAGA #define PCH_PHUB_ROM_START_ADDR_ML7223 0x400 /* ROM data area start address 367f2732c8STomoya MORINAGA offset(LAPIS Semicon ML7223) 37275640b0STomoya MORINAGA */ 38cf4ece53SMasayuki Ohtak 39cf4ece53SMasayuki Ohtak /* MAX number of INT_REDUCE_CONTROL registers */ 40cf4ece53SMasayuki Ohtak #define MAX_NUM_INT_REDUCE_CONTROL_REG 128 41cf4ece53SMasayuki Ohtak #define PCI_DEVICE_ID_PCH1_PHUB 0x8801 42cf4ece53SMasayuki Ohtak #define PCH_MINOR_NOS 1 43cf4ece53SMasayuki Ohtak #define CLKCFG_CAN_50MHZ 0x12000000 44cf4ece53SMasayuki Ohtak #define CLKCFG_CANCLK_MASK 0xFF000000 456ae705b2SDenis Turischev #define CLKCFG_UART_MASK 0xFFFFFF 466ae705b2SDenis Turischev 476ae705b2SDenis Turischev /* CM-iTC */ 486ae705b2SDenis Turischev #define CLKCFG_UART_48MHZ (1 << 16) 49bed3d7baSZubair Lutfullah Kakakhel #define CLKCFG_UART_25MHZ (2 << 16) 506ae705b2SDenis Turischev #define CLKCFG_BAUDDIV (2 << 20) 516ae705b2SDenis Turischev #define CLKCFG_PLL2VCO (8 << 9) 526ae705b2SDenis Turischev #define CLKCFG_UARTCLKSEL (1 << 18) 53cf4ece53SMasayuki Ohtak 541a738dcfSTomoya MORINAGA /* Macros for ML7213 */ 551a738dcfSTomoya MORINAGA #define PCI_DEVICE_ID_ROHM_ML7213_PHUB 0x801A 56cf4ece53SMasayuki Ohtak 57275640b0STomoya MORINAGA /* Macros for ML7223 */ 58275640b0STomoya MORINAGA #define PCI_DEVICE_ID_ROHM_ML7223_mPHUB 0x8012 /* for Bus-m */ 59275640b0STomoya MORINAGA #define PCI_DEVICE_ID_ROHM_ML7223_nPHUB 0x8002 /* for Bus-n */ 60275640b0STomoya MORINAGA 61584ad00cSTomoya MORINAGA /* Macros for ML7831 */ 62584ad00cSTomoya MORINAGA #define PCI_DEVICE_ID_ROHM_ML7831_PHUB 0x8801 63584ad00cSTomoya MORINAGA 64cf4ece53SMasayuki Ohtak /* SROM ACCESS Macro */ 65cf4ece53SMasayuki Ohtak #define PCH_WORD_ADDR_MASK (~((1 << 2) - 1)) 66cf4ece53SMasayuki Ohtak 67cf4ece53SMasayuki Ohtak /* Registers address offset */ 68cf4ece53SMasayuki Ohtak #define PCH_PHUB_ID_REG 0x0000 69cf4ece53SMasayuki Ohtak #define PCH_PHUB_QUEUE_PRI_VAL_REG 0x0004 70cf4ece53SMasayuki Ohtak #define PCH_PHUB_RC_QUEUE_MAXSIZE_REG 0x0008 71cf4ece53SMasayuki Ohtak #define PCH_PHUB_BRI_QUEUE_MAXSIZE_REG 0x000C 72cf4ece53SMasayuki Ohtak #define PCH_PHUB_COMP_RESP_TIMEOUT_REG 0x0010 73cf4ece53SMasayuki Ohtak #define PCH_PHUB_BUS_SLAVE_CONTROL_REG 0x0014 74cf4ece53SMasayuki Ohtak #define PCH_PHUB_DEADLOCK_AVOID_TYPE_REG 0x0018 75cf4ece53SMasayuki Ohtak #define PCH_PHUB_INTPIN_REG_WPERMIT_REG0 0x0020 76cf4ece53SMasayuki Ohtak #define PCH_PHUB_INTPIN_REG_WPERMIT_REG1 0x0024 77cf4ece53SMasayuki Ohtak #define PCH_PHUB_INTPIN_REG_WPERMIT_REG2 0x0028 78cf4ece53SMasayuki Ohtak #define PCH_PHUB_INTPIN_REG_WPERMIT_REG3 0x002C 79cf4ece53SMasayuki Ohtak #define PCH_PHUB_INT_REDUCE_CONTROL_REG_BASE 0x0040 80cf4ece53SMasayuki Ohtak #define CLKCFG_REG_OFFSET 0x500 81dd7d7feaSTomoya MORINAGA #define FUNCSEL_REG_OFFSET 0x508 82cf4ece53SMasayuki Ohtak 83cf4ece53SMasayuki Ohtak #define PCH_PHUB_OROM_SIZE 15360 84cf4ece53SMasayuki Ohtak 85cf4ece53SMasayuki Ohtak /** 86cf4ece53SMasayuki Ohtak * struct pch_phub_reg - PHUB register structure 87cf4ece53SMasayuki Ohtak * @phub_id_reg: PHUB_ID register val 88cf4ece53SMasayuki Ohtak * @q_pri_val_reg: QUEUE_PRI_VAL register val 89cf4ece53SMasayuki Ohtak * @rc_q_maxsize_reg: RC_QUEUE_MAXSIZE register val 90cf4ece53SMasayuki Ohtak * @bri_q_maxsize_reg: BRI_QUEUE_MAXSIZE register val 91cf4ece53SMasayuki Ohtak * @comp_resp_timeout_reg: COMP_RESP_TIMEOUT register val 92cf4ece53SMasayuki Ohtak * @bus_slave_control_reg: BUS_SLAVE_CONTROL_REG register val 93cf4ece53SMasayuki Ohtak * @deadlock_avoid_type_reg: DEADLOCK_AVOID_TYPE register val 94cf4ece53SMasayuki Ohtak * @intpin_reg_wpermit_reg0: INTPIN_REG_WPERMIT register 0 val 95cf4ece53SMasayuki Ohtak * @intpin_reg_wpermit_reg1: INTPIN_REG_WPERMIT register 1 val 96cf4ece53SMasayuki Ohtak * @intpin_reg_wpermit_reg2: INTPIN_REG_WPERMIT register 2 val 97cf4ece53SMasayuki Ohtak * @intpin_reg_wpermit_reg3: INTPIN_REG_WPERMIT register 3 val 98cf4ece53SMasayuki Ohtak * @int_reduce_control_reg: INT_REDUCE_CONTROL registers val 99cf4ece53SMasayuki Ohtak * @clkcfg_reg: CLK CFG register val 100dd7d7feaSTomoya MORINAGA * @funcsel_reg: Function select register value 101cf4ece53SMasayuki Ohtak * @pch_phub_base_address: Register base address 102cf4ece53SMasayuki Ohtak * @pch_phub_extrom_base_address: external rom base address 103275640b0STomoya MORINAGA * @pch_mac_start_address: MAC address area start address 104275640b0STomoya MORINAGA * @pch_opt_rom_start_address: Option ROM start address 105275640b0STomoya MORINAGA * @ioh_type: Save IOH type 1069914a0deSTomoya MORINAGA * @pdev: pointer to pci device struct 107cf4ece53SMasayuki Ohtak */ 108cf4ece53SMasayuki Ohtak struct pch_phub_reg { 109cf4ece53SMasayuki Ohtak u32 phub_id_reg; 110cf4ece53SMasayuki Ohtak u32 q_pri_val_reg; 111cf4ece53SMasayuki Ohtak u32 rc_q_maxsize_reg; 112cf4ece53SMasayuki Ohtak u32 bri_q_maxsize_reg; 113cf4ece53SMasayuki Ohtak u32 comp_resp_timeout_reg; 114cf4ece53SMasayuki Ohtak u32 bus_slave_control_reg; 115cf4ece53SMasayuki Ohtak u32 deadlock_avoid_type_reg; 116cf4ece53SMasayuki Ohtak u32 intpin_reg_wpermit_reg0; 117cf4ece53SMasayuki Ohtak u32 intpin_reg_wpermit_reg1; 118cf4ece53SMasayuki Ohtak u32 intpin_reg_wpermit_reg2; 119cf4ece53SMasayuki Ohtak u32 intpin_reg_wpermit_reg3; 120cf4ece53SMasayuki Ohtak u32 int_reduce_control_reg[MAX_NUM_INT_REDUCE_CONTROL_REG]; 121cf4ece53SMasayuki Ohtak u32 clkcfg_reg; 122dd7d7feaSTomoya MORINAGA u32 funcsel_reg; 123cf4ece53SMasayuki Ohtak void __iomem *pch_phub_base_address; 124cf4ece53SMasayuki Ohtak void __iomem *pch_phub_extrom_base_address; 125275640b0STomoya MORINAGA u32 pch_mac_start_address; 126275640b0STomoya MORINAGA u32 pch_opt_rom_start_address; 127275640b0STomoya MORINAGA int ioh_type; 1289914a0deSTomoya MORINAGA struct pci_dev *pdev; 129cf4ece53SMasayuki Ohtak }; 130cf4ece53SMasayuki Ohtak 131cf4ece53SMasayuki Ohtak /* SROM SPEC for MAC address assignment offset */ 132cf4ece53SMasayuki Ohtak static const int pch_phub_mac_offset[ETH_ALEN] = {0x3, 0x2, 0x1, 0x0, 0xb, 0xa}; 133cf4ece53SMasayuki Ohtak 134cf4ece53SMasayuki Ohtak static DEFINE_MUTEX(pch_phub_mutex); 135cf4ece53SMasayuki Ohtak 136cf4ece53SMasayuki Ohtak /** 137cf4ece53SMasayuki Ohtak * pch_phub_read_modify_write_reg() - Reading modifying and writing register 138cf4ece53SMasayuki Ohtak * @reg_addr_offset: Register offset address value. 139cf4ece53SMasayuki Ohtak * @data: Writing value. 140cf4ece53SMasayuki Ohtak * @mask: Mask value. 141cf4ece53SMasayuki Ohtak */ 142cf4ece53SMasayuki Ohtak static void pch_phub_read_modify_write_reg(struct pch_phub_reg *chip, 143cf4ece53SMasayuki Ohtak unsigned int reg_addr_offset, 144cf4ece53SMasayuki Ohtak unsigned int data, unsigned int mask) 145cf4ece53SMasayuki Ohtak { 146cf4ece53SMasayuki Ohtak void __iomem *reg_addr = chip->pch_phub_base_address + reg_addr_offset; 147cf4ece53SMasayuki Ohtak iowrite32(((ioread32(reg_addr) & ~mask)) | data, reg_addr); 148cf4ece53SMasayuki Ohtak } 149cf4ece53SMasayuki Ohtak 150cf4ece53SMasayuki Ohtak /* pch_phub_save_reg_conf - saves register configuration */ 151*34afa1d6SVaibhav Gupta static void __maybe_unused pch_phub_save_reg_conf(struct pci_dev *pdev) 152cf4ece53SMasayuki Ohtak { 153cf4ece53SMasayuki Ohtak unsigned int i; 154cf4ece53SMasayuki Ohtak struct pch_phub_reg *chip = pci_get_drvdata(pdev); 155cf4ece53SMasayuki Ohtak 156cf4ece53SMasayuki Ohtak void __iomem *p = chip->pch_phub_base_address; 157cf4ece53SMasayuki Ohtak 158cf4ece53SMasayuki Ohtak chip->phub_id_reg = ioread32(p + PCH_PHUB_ID_REG); 159cf4ece53SMasayuki Ohtak chip->q_pri_val_reg = ioread32(p + PCH_PHUB_QUEUE_PRI_VAL_REG); 160cf4ece53SMasayuki Ohtak chip->rc_q_maxsize_reg = ioread32(p + PCH_PHUB_RC_QUEUE_MAXSIZE_REG); 161cf4ece53SMasayuki Ohtak chip->bri_q_maxsize_reg = ioread32(p + PCH_PHUB_BRI_QUEUE_MAXSIZE_REG); 162cf4ece53SMasayuki Ohtak chip->comp_resp_timeout_reg = 163cf4ece53SMasayuki Ohtak ioread32(p + PCH_PHUB_COMP_RESP_TIMEOUT_REG); 164cf4ece53SMasayuki Ohtak chip->bus_slave_control_reg = 165cf4ece53SMasayuki Ohtak ioread32(p + PCH_PHUB_BUS_SLAVE_CONTROL_REG); 166cf4ece53SMasayuki Ohtak chip->deadlock_avoid_type_reg = 167cf4ece53SMasayuki Ohtak ioread32(p + PCH_PHUB_DEADLOCK_AVOID_TYPE_REG); 168cf4ece53SMasayuki Ohtak chip->intpin_reg_wpermit_reg0 = 169cf4ece53SMasayuki Ohtak ioread32(p + PCH_PHUB_INTPIN_REG_WPERMIT_REG0); 170cf4ece53SMasayuki Ohtak chip->intpin_reg_wpermit_reg1 = 171cf4ece53SMasayuki Ohtak ioread32(p + PCH_PHUB_INTPIN_REG_WPERMIT_REG1); 172cf4ece53SMasayuki Ohtak chip->intpin_reg_wpermit_reg2 = 173cf4ece53SMasayuki Ohtak ioread32(p + PCH_PHUB_INTPIN_REG_WPERMIT_REG2); 174cf4ece53SMasayuki Ohtak chip->intpin_reg_wpermit_reg3 = 175cf4ece53SMasayuki Ohtak ioread32(p + PCH_PHUB_INTPIN_REG_WPERMIT_REG3); 176cf4ece53SMasayuki Ohtak dev_dbg(&pdev->dev, "%s : " 177cf4ece53SMasayuki Ohtak "chip->phub_id_reg=%x, " 178cf4ece53SMasayuki Ohtak "chip->q_pri_val_reg=%x, " 179cf4ece53SMasayuki Ohtak "chip->rc_q_maxsize_reg=%x, " 180cf4ece53SMasayuki Ohtak "chip->bri_q_maxsize_reg=%x, " 181cf4ece53SMasayuki Ohtak "chip->comp_resp_timeout_reg=%x, " 182cf4ece53SMasayuki Ohtak "chip->bus_slave_control_reg=%x, " 183cf4ece53SMasayuki Ohtak "chip->deadlock_avoid_type_reg=%x, " 184cf4ece53SMasayuki Ohtak "chip->intpin_reg_wpermit_reg0=%x, " 185cf4ece53SMasayuki Ohtak "chip->intpin_reg_wpermit_reg1=%x, " 186cf4ece53SMasayuki Ohtak "chip->intpin_reg_wpermit_reg2=%x, " 187cf4ece53SMasayuki Ohtak "chip->intpin_reg_wpermit_reg3=%x\n", __func__, 188cf4ece53SMasayuki Ohtak chip->phub_id_reg, 189cf4ece53SMasayuki Ohtak chip->q_pri_val_reg, 190cf4ece53SMasayuki Ohtak chip->rc_q_maxsize_reg, 191cf4ece53SMasayuki Ohtak chip->bri_q_maxsize_reg, 192cf4ece53SMasayuki Ohtak chip->comp_resp_timeout_reg, 193cf4ece53SMasayuki Ohtak chip->bus_slave_control_reg, 194cf4ece53SMasayuki Ohtak chip->deadlock_avoid_type_reg, 195cf4ece53SMasayuki Ohtak chip->intpin_reg_wpermit_reg0, 196cf4ece53SMasayuki Ohtak chip->intpin_reg_wpermit_reg1, 197cf4ece53SMasayuki Ohtak chip->intpin_reg_wpermit_reg2, 198cf4ece53SMasayuki Ohtak chip->intpin_reg_wpermit_reg3); 199cf4ece53SMasayuki Ohtak for (i = 0; i < MAX_NUM_INT_REDUCE_CONTROL_REG; i++) { 200cf4ece53SMasayuki Ohtak chip->int_reduce_control_reg[i] = 201cf4ece53SMasayuki Ohtak ioread32(p + PCH_PHUB_INT_REDUCE_CONTROL_REG_BASE + 4 * i); 202cf4ece53SMasayuki Ohtak dev_dbg(&pdev->dev, "%s : " 203cf4ece53SMasayuki Ohtak "chip->int_reduce_control_reg[%d]=%x\n", 204cf4ece53SMasayuki Ohtak __func__, i, chip->int_reduce_control_reg[i]); 205cf4ece53SMasayuki Ohtak } 206cf4ece53SMasayuki Ohtak chip->clkcfg_reg = ioread32(p + CLKCFG_REG_OFFSET); 207dd7d7feaSTomoya MORINAGA if ((chip->ioh_type == 2) || (chip->ioh_type == 4)) 208dd7d7feaSTomoya MORINAGA chip->funcsel_reg = ioread32(p + FUNCSEL_REG_OFFSET); 209cf4ece53SMasayuki Ohtak } 210cf4ece53SMasayuki Ohtak 211cf4ece53SMasayuki Ohtak /* pch_phub_restore_reg_conf - restore register configuration */ 212*34afa1d6SVaibhav Gupta static void __maybe_unused pch_phub_restore_reg_conf(struct pci_dev *pdev) 213cf4ece53SMasayuki Ohtak { 214cf4ece53SMasayuki Ohtak unsigned int i; 215cf4ece53SMasayuki Ohtak struct pch_phub_reg *chip = pci_get_drvdata(pdev); 216cf4ece53SMasayuki Ohtak void __iomem *p; 217cf4ece53SMasayuki Ohtak p = chip->pch_phub_base_address; 218cf4ece53SMasayuki Ohtak 219cf4ece53SMasayuki Ohtak iowrite32(chip->phub_id_reg, p + PCH_PHUB_ID_REG); 220cf4ece53SMasayuki Ohtak iowrite32(chip->q_pri_val_reg, p + PCH_PHUB_QUEUE_PRI_VAL_REG); 221cf4ece53SMasayuki Ohtak iowrite32(chip->rc_q_maxsize_reg, p + PCH_PHUB_RC_QUEUE_MAXSIZE_REG); 222cf4ece53SMasayuki Ohtak iowrite32(chip->bri_q_maxsize_reg, p + PCH_PHUB_BRI_QUEUE_MAXSIZE_REG); 223cf4ece53SMasayuki Ohtak iowrite32(chip->comp_resp_timeout_reg, 224cf4ece53SMasayuki Ohtak p + PCH_PHUB_COMP_RESP_TIMEOUT_REG); 225cf4ece53SMasayuki Ohtak iowrite32(chip->bus_slave_control_reg, 226cf4ece53SMasayuki Ohtak p + PCH_PHUB_BUS_SLAVE_CONTROL_REG); 227cf4ece53SMasayuki Ohtak iowrite32(chip->deadlock_avoid_type_reg, 228cf4ece53SMasayuki Ohtak p + PCH_PHUB_DEADLOCK_AVOID_TYPE_REG); 229cf4ece53SMasayuki Ohtak iowrite32(chip->intpin_reg_wpermit_reg0, 230cf4ece53SMasayuki Ohtak p + PCH_PHUB_INTPIN_REG_WPERMIT_REG0); 231cf4ece53SMasayuki Ohtak iowrite32(chip->intpin_reg_wpermit_reg1, 232cf4ece53SMasayuki Ohtak p + PCH_PHUB_INTPIN_REG_WPERMIT_REG1); 233cf4ece53SMasayuki Ohtak iowrite32(chip->intpin_reg_wpermit_reg2, 234cf4ece53SMasayuki Ohtak p + PCH_PHUB_INTPIN_REG_WPERMIT_REG2); 235cf4ece53SMasayuki Ohtak iowrite32(chip->intpin_reg_wpermit_reg3, 236cf4ece53SMasayuki Ohtak p + PCH_PHUB_INTPIN_REG_WPERMIT_REG3); 237cf4ece53SMasayuki Ohtak dev_dbg(&pdev->dev, "%s : " 238cf4ece53SMasayuki Ohtak "chip->phub_id_reg=%x, " 239cf4ece53SMasayuki Ohtak "chip->q_pri_val_reg=%x, " 240cf4ece53SMasayuki Ohtak "chip->rc_q_maxsize_reg=%x, " 241cf4ece53SMasayuki Ohtak "chip->bri_q_maxsize_reg=%x, " 242cf4ece53SMasayuki Ohtak "chip->comp_resp_timeout_reg=%x, " 243cf4ece53SMasayuki Ohtak "chip->bus_slave_control_reg=%x, " 244cf4ece53SMasayuki Ohtak "chip->deadlock_avoid_type_reg=%x, " 245cf4ece53SMasayuki Ohtak "chip->intpin_reg_wpermit_reg0=%x, " 246cf4ece53SMasayuki Ohtak "chip->intpin_reg_wpermit_reg1=%x, " 247cf4ece53SMasayuki Ohtak "chip->intpin_reg_wpermit_reg2=%x, " 248cf4ece53SMasayuki Ohtak "chip->intpin_reg_wpermit_reg3=%x\n", __func__, 249cf4ece53SMasayuki Ohtak chip->phub_id_reg, 250cf4ece53SMasayuki Ohtak chip->q_pri_val_reg, 251cf4ece53SMasayuki Ohtak chip->rc_q_maxsize_reg, 252cf4ece53SMasayuki Ohtak chip->bri_q_maxsize_reg, 253cf4ece53SMasayuki Ohtak chip->comp_resp_timeout_reg, 254cf4ece53SMasayuki Ohtak chip->bus_slave_control_reg, 255cf4ece53SMasayuki Ohtak chip->deadlock_avoid_type_reg, 256cf4ece53SMasayuki Ohtak chip->intpin_reg_wpermit_reg0, 257cf4ece53SMasayuki Ohtak chip->intpin_reg_wpermit_reg1, 258cf4ece53SMasayuki Ohtak chip->intpin_reg_wpermit_reg2, 259cf4ece53SMasayuki Ohtak chip->intpin_reg_wpermit_reg3); 260cf4ece53SMasayuki Ohtak for (i = 0; i < MAX_NUM_INT_REDUCE_CONTROL_REG; i++) { 261cf4ece53SMasayuki Ohtak iowrite32(chip->int_reduce_control_reg[i], 262cf4ece53SMasayuki Ohtak p + PCH_PHUB_INT_REDUCE_CONTROL_REG_BASE + 4 * i); 263cf4ece53SMasayuki Ohtak dev_dbg(&pdev->dev, "%s : " 264cf4ece53SMasayuki Ohtak "chip->int_reduce_control_reg[%d]=%x\n", 265cf4ece53SMasayuki Ohtak __func__, i, chip->int_reduce_control_reg[i]); 266cf4ece53SMasayuki Ohtak } 267cf4ece53SMasayuki Ohtak 268cf4ece53SMasayuki Ohtak iowrite32(chip->clkcfg_reg, p + CLKCFG_REG_OFFSET); 269dd7d7feaSTomoya MORINAGA if ((chip->ioh_type == 2) || (chip->ioh_type == 4)) 270dd7d7feaSTomoya MORINAGA iowrite32(chip->funcsel_reg, p + FUNCSEL_REG_OFFSET); 271cf4ece53SMasayuki Ohtak } 272cf4ece53SMasayuki Ohtak 273cf4ece53SMasayuki Ohtak /** 274cf4ece53SMasayuki Ohtak * pch_phub_read_serial_rom() - Reading Serial ROM 275cf4ece53SMasayuki Ohtak * @offset_address: Serial ROM offset address to read. 276cf4ece53SMasayuki Ohtak * @data: Read buffer for specified Serial ROM value. 277cf4ece53SMasayuki Ohtak */ 278cf4ece53SMasayuki Ohtak static void pch_phub_read_serial_rom(struct pch_phub_reg *chip, 279cf4ece53SMasayuki Ohtak unsigned int offset_address, u8 *data) 280cf4ece53SMasayuki Ohtak { 281cf4ece53SMasayuki Ohtak void __iomem *mem_addr = chip->pch_phub_extrom_base_address + 282cf4ece53SMasayuki Ohtak offset_address; 283cf4ece53SMasayuki Ohtak 284cf4ece53SMasayuki Ohtak *data = ioread8(mem_addr); 285cf4ece53SMasayuki Ohtak } 286cf4ece53SMasayuki Ohtak 287cf4ece53SMasayuki Ohtak /** 288cf4ece53SMasayuki Ohtak * pch_phub_write_serial_rom() - Writing Serial ROM 289cf4ece53SMasayuki Ohtak * @offset_address: Serial ROM offset address. 290cf4ece53SMasayuki Ohtak * @data: Serial ROM value to write. 291cf4ece53SMasayuki Ohtak */ 292cf4ece53SMasayuki Ohtak static int pch_phub_write_serial_rom(struct pch_phub_reg *chip, 293cf4ece53SMasayuki Ohtak unsigned int offset_address, u8 data) 294cf4ece53SMasayuki Ohtak { 295cf4ece53SMasayuki Ohtak void __iomem *mem_addr = chip->pch_phub_extrom_base_address + 296cf4ece53SMasayuki Ohtak (offset_address & PCH_WORD_ADDR_MASK); 297cf4ece53SMasayuki Ohtak int i; 298cf4ece53SMasayuki Ohtak unsigned int word_data; 299cf4ece53SMasayuki Ohtak unsigned int pos; 300cf4ece53SMasayuki Ohtak unsigned int mask; 301cf4ece53SMasayuki Ohtak pos = (offset_address % 4) * 8; 302cf4ece53SMasayuki Ohtak mask = ~(0xFF << pos); 303cf4ece53SMasayuki Ohtak 304cf4ece53SMasayuki Ohtak iowrite32(PCH_PHUB_ROM_WRITE_ENABLE, 305cf4ece53SMasayuki Ohtak chip->pch_phub_extrom_base_address + PHUB_CONTROL); 306cf4ece53SMasayuki Ohtak 307cf4ece53SMasayuki Ohtak word_data = ioread32(mem_addr); 308cf4ece53SMasayuki Ohtak iowrite32((word_data & mask) | (u32)data << pos, mem_addr); 309cf4ece53SMasayuki Ohtak 310cf4ece53SMasayuki Ohtak i = 0; 311cf4ece53SMasayuki Ohtak while (ioread8(chip->pch_phub_extrom_base_address + 312cf4ece53SMasayuki Ohtak PHUB_STATUS) != 0x00) { 313cf4ece53SMasayuki Ohtak msleep(1); 314cf4ece53SMasayuki Ohtak if (i == PHUB_TIMEOUT) 315cf4ece53SMasayuki Ohtak return -ETIMEDOUT; 316cf4ece53SMasayuki Ohtak i++; 317cf4ece53SMasayuki Ohtak } 318cf4ece53SMasayuki Ohtak 319cf4ece53SMasayuki Ohtak iowrite32(PCH_PHUB_ROM_WRITE_DISABLE, 320cf4ece53SMasayuki Ohtak chip->pch_phub_extrom_base_address + PHUB_CONTROL); 321cf4ece53SMasayuki Ohtak 322cf4ece53SMasayuki Ohtak return 0; 323cf4ece53SMasayuki Ohtak } 324cf4ece53SMasayuki Ohtak 325cf4ece53SMasayuki Ohtak /** 326cf4ece53SMasayuki Ohtak * pch_phub_read_serial_rom_val() - Read Serial ROM value 327cf4ece53SMasayuki Ohtak * @offset_address: Serial ROM address offset value. 328cf4ece53SMasayuki Ohtak * @data: Serial ROM value to read. 329cf4ece53SMasayuki Ohtak */ 330cf4ece53SMasayuki Ohtak static void pch_phub_read_serial_rom_val(struct pch_phub_reg *chip, 331cf4ece53SMasayuki Ohtak unsigned int offset_address, u8 *data) 332cf4ece53SMasayuki Ohtak { 333cf4ece53SMasayuki Ohtak unsigned int mem_addr; 334cf4ece53SMasayuki Ohtak 335275640b0STomoya MORINAGA mem_addr = chip->pch_mac_start_address + 336cf4ece53SMasayuki Ohtak pch_phub_mac_offset[offset_address]; 337cf4ece53SMasayuki Ohtak 338cf4ece53SMasayuki Ohtak pch_phub_read_serial_rom(chip, mem_addr, data); 339cf4ece53SMasayuki Ohtak } 340cf4ece53SMasayuki Ohtak 341cf4ece53SMasayuki Ohtak /** 342cf4ece53SMasayuki Ohtak * pch_phub_write_serial_rom_val() - writing Serial ROM value 343cf4ece53SMasayuki Ohtak * @offset_address: Serial ROM address offset value. 344cf4ece53SMasayuki Ohtak * @data: Serial ROM value. 345cf4ece53SMasayuki Ohtak */ 346cf4ece53SMasayuki Ohtak static int pch_phub_write_serial_rom_val(struct pch_phub_reg *chip, 347cf4ece53SMasayuki Ohtak unsigned int offset_address, u8 data) 348cf4ece53SMasayuki Ohtak { 349cf4ece53SMasayuki Ohtak int retval; 350cf4ece53SMasayuki Ohtak unsigned int mem_addr; 351cf4ece53SMasayuki Ohtak 352275640b0STomoya MORINAGA mem_addr = chip->pch_mac_start_address + 353cf4ece53SMasayuki Ohtak pch_phub_mac_offset[offset_address]; 354cf4ece53SMasayuki Ohtak 355cf4ece53SMasayuki Ohtak retval = pch_phub_write_serial_rom(chip, mem_addr, data); 356cf4ece53SMasayuki Ohtak 357cf4ece53SMasayuki Ohtak return retval; 358cf4ece53SMasayuki Ohtak } 359cf4ece53SMasayuki Ohtak 360cf4ece53SMasayuki Ohtak /* pch_phub_gbe_serial_rom_conf - makes Serial ROM header format configuration 361cf4ece53SMasayuki Ohtak * for Gigabit Ethernet MAC address 362cf4ece53SMasayuki Ohtak */ 363cf4ece53SMasayuki Ohtak static int pch_phub_gbe_serial_rom_conf(struct pch_phub_reg *chip) 364cf4ece53SMasayuki Ohtak { 365cf4ece53SMasayuki Ohtak int retval; 366cf4ece53SMasayuki Ohtak 367cf4ece53SMasayuki Ohtak retval = pch_phub_write_serial_rom(chip, 0x0b, 0xbc); 368cf4ece53SMasayuki Ohtak retval |= pch_phub_write_serial_rom(chip, 0x0a, 0x10); 369cf4ece53SMasayuki Ohtak retval |= pch_phub_write_serial_rom(chip, 0x09, 0x01); 370cf4ece53SMasayuki Ohtak retval |= pch_phub_write_serial_rom(chip, 0x08, 0x02); 371cf4ece53SMasayuki Ohtak 372cf4ece53SMasayuki Ohtak retval |= pch_phub_write_serial_rom(chip, 0x0f, 0x00); 373cf4ece53SMasayuki Ohtak retval |= pch_phub_write_serial_rom(chip, 0x0e, 0x00); 374cf4ece53SMasayuki Ohtak retval |= pch_phub_write_serial_rom(chip, 0x0d, 0x00); 375cf4ece53SMasayuki Ohtak retval |= pch_phub_write_serial_rom(chip, 0x0c, 0x80); 376cf4ece53SMasayuki Ohtak 377cf4ece53SMasayuki Ohtak retval |= pch_phub_write_serial_rom(chip, 0x13, 0xbc); 378cf4ece53SMasayuki Ohtak retval |= pch_phub_write_serial_rom(chip, 0x12, 0x10); 379cf4ece53SMasayuki Ohtak retval |= pch_phub_write_serial_rom(chip, 0x11, 0x01); 380cf4ece53SMasayuki Ohtak retval |= pch_phub_write_serial_rom(chip, 0x10, 0x18); 381cf4ece53SMasayuki Ohtak 382cf4ece53SMasayuki Ohtak retval |= pch_phub_write_serial_rom(chip, 0x1b, 0xbc); 383cf4ece53SMasayuki Ohtak retval |= pch_phub_write_serial_rom(chip, 0x1a, 0x10); 384cf4ece53SMasayuki Ohtak retval |= pch_phub_write_serial_rom(chip, 0x19, 0x01); 385cf4ece53SMasayuki Ohtak retval |= pch_phub_write_serial_rom(chip, 0x18, 0x19); 386cf4ece53SMasayuki Ohtak 387cf4ece53SMasayuki Ohtak retval |= pch_phub_write_serial_rom(chip, 0x23, 0xbc); 388cf4ece53SMasayuki Ohtak retval |= pch_phub_write_serial_rom(chip, 0x22, 0x10); 389cf4ece53SMasayuki Ohtak retval |= pch_phub_write_serial_rom(chip, 0x21, 0x01); 390cf4ece53SMasayuki Ohtak retval |= pch_phub_write_serial_rom(chip, 0x20, 0x3a); 391cf4ece53SMasayuki Ohtak 392cf4ece53SMasayuki Ohtak retval |= pch_phub_write_serial_rom(chip, 0x27, 0x01); 393cf4ece53SMasayuki Ohtak retval |= pch_phub_write_serial_rom(chip, 0x26, 0x00); 394cf4ece53SMasayuki Ohtak retval |= pch_phub_write_serial_rom(chip, 0x25, 0x00); 395cf4ece53SMasayuki Ohtak retval |= pch_phub_write_serial_rom(chip, 0x24, 0x00); 396cf4ece53SMasayuki Ohtak 397cf4ece53SMasayuki Ohtak return retval; 398cf4ece53SMasayuki Ohtak } 399cf4ece53SMasayuki Ohtak 400275640b0STomoya MORINAGA /* pch_phub_gbe_serial_rom_conf_mp - makes SerialROM header format configuration 401275640b0STomoya MORINAGA * for Gigabit Ethernet MAC address 402275640b0STomoya MORINAGA */ 403275640b0STomoya MORINAGA static int pch_phub_gbe_serial_rom_conf_mp(struct pch_phub_reg *chip) 404275640b0STomoya MORINAGA { 405275640b0STomoya MORINAGA int retval; 406275640b0STomoya MORINAGA u32 offset_addr; 407275640b0STomoya MORINAGA 408275640b0STomoya MORINAGA offset_addr = 0x200; 409275640b0STomoya MORINAGA retval = pch_phub_write_serial_rom(chip, 0x03 + offset_addr, 0xbc); 410275640b0STomoya MORINAGA retval |= pch_phub_write_serial_rom(chip, 0x02 + offset_addr, 0x00); 411275640b0STomoya MORINAGA retval |= pch_phub_write_serial_rom(chip, 0x01 + offset_addr, 0x40); 412275640b0STomoya MORINAGA retval |= pch_phub_write_serial_rom(chip, 0x00 + offset_addr, 0x02); 413275640b0STomoya MORINAGA 414275640b0STomoya MORINAGA retval |= pch_phub_write_serial_rom(chip, 0x07 + offset_addr, 0x00); 415275640b0STomoya MORINAGA retval |= pch_phub_write_serial_rom(chip, 0x06 + offset_addr, 0x00); 416275640b0STomoya MORINAGA retval |= pch_phub_write_serial_rom(chip, 0x05 + offset_addr, 0x00); 417275640b0STomoya MORINAGA retval |= pch_phub_write_serial_rom(chip, 0x04 + offset_addr, 0x80); 418275640b0STomoya MORINAGA 419275640b0STomoya MORINAGA retval |= pch_phub_write_serial_rom(chip, 0x0b + offset_addr, 0xbc); 420275640b0STomoya MORINAGA retval |= pch_phub_write_serial_rom(chip, 0x0a + offset_addr, 0x00); 421275640b0STomoya MORINAGA retval |= pch_phub_write_serial_rom(chip, 0x09 + offset_addr, 0x40); 422275640b0STomoya MORINAGA retval |= pch_phub_write_serial_rom(chip, 0x08 + offset_addr, 0x18); 423275640b0STomoya MORINAGA 424275640b0STomoya MORINAGA retval |= pch_phub_write_serial_rom(chip, 0x13 + offset_addr, 0xbc); 425275640b0STomoya MORINAGA retval |= pch_phub_write_serial_rom(chip, 0x12 + offset_addr, 0x00); 426275640b0STomoya MORINAGA retval |= pch_phub_write_serial_rom(chip, 0x11 + offset_addr, 0x40); 427275640b0STomoya MORINAGA retval |= pch_phub_write_serial_rom(chip, 0x10 + offset_addr, 0x19); 428275640b0STomoya MORINAGA 429275640b0STomoya MORINAGA retval |= pch_phub_write_serial_rom(chip, 0x1b + offset_addr, 0xbc); 430275640b0STomoya MORINAGA retval |= pch_phub_write_serial_rom(chip, 0x1a + offset_addr, 0x00); 431275640b0STomoya MORINAGA retval |= pch_phub_write_serial_rom(chip, 0x19 + offset_addr, 0x40); 432275640b0STomoya MORINAGA retval |= pch_phub_write_serial_rom(chip, 0x18 + offset_addr, 0x3a); 433275640b0STomoya MORINAGA 434275640b0STomoya MORINAGA retval |= pch_phub_write_serial_rom(chip, 0x1f + offset_addr, 0x01); 435275640b0STomoya MORINAGA retval |= pch_phub_write_serial_rom(chip, 0x1e + offset_addr, 0x00); 436275640b0STomoya MORINAGA retval |= pch_phub_write_serial_rom(chip, 0x1d + offset_addr, 0x00); 437275640b0STomoya MORINAGA retval |= pch_phub_write_serial_rom(chip, 0x1c + offset_addr, 0x00); 438275640b0STomoya MORINAGA 439275640b0STomoya MORINAGA return retval; 440275640b0STomoya MORINAGA } 441275640b0STomoya MORINAGA 442cf4ece53SMasayuki Ohtak /** 443cf4ece53SMasayuki Ohtak * pch_phub_read_gbe_mac_addr() - Read Gigabit Ethernet MAC address 444cf4ece53SMasayuki Ohtak * @offset_address: Gigabit Ethernet MAC address offset value. 445cf4ece53SMasayuki Ohtak * @data: Buffer of the Gigabit Ethernet MAC address value. 446cf4ece53SMasayuki Ohtak */ 447cf4ece53SMasayuki Ohtak static void pch_phub_read_gbe_mac_addr(struct pch_phub_reg *chip, u8 *data) 448cf4ece53SMasayuki Ohtak { 449cf4ece53SMasayuki Ohtak int i; 450cf4ece53SMasayuki Ohtak for (i = 0; i < ETH_ALEN; i++) 451cf4ece53SMasayuki Ohtak pch_phub_read_serial_rom_val(chip, i, &data[i]); 452cf4ece53SMasayuki Ohtak } 453cf4ece53SMasayuki Ohtak 454cf4ece53SMasayuki Ohtak /** 455cf4ece53SMasayuki Ohtak * pch_phub_write_gbe_mac_addr() - Write MAC address 456cf4ece53SMasayuki Ohtak * @offset_address: Gigabit Ethernet MAC address offset value. 457cf4ece53SMasayuki Ohtak * @data: Gigabit Ethernet MAC address value. 458cf4ece53SMasayuki Ohtak */ 459cf4ece53SMasayuki Ohtak static int pch_phub_write_gbe_mac_addr(struct pch_phub_reg *chip, u8 *data) 460cf4ece53SMasayuki Ohtak { 461cf4ece53SMasayuki Ohtak int retval; 462cf4ece53SMasayuki Ohtak int i; 463cf4ece53SMasayuki Ohtak 4642a988791STomoya MORINAGA if ((chip->ioh_type == 1) || (chip->ioh_type == 5)) /* EG20T or ML7831*/ 465cf4ece53SMasayuki Ohtak retval = pch_phub_gbe_serial_rom_conf(chip); 466275640b0STomoya MORINAGA else /* ML7223 */ 467275640b0STomoya MORINAGA retval = pch_phub_gbe_serial_rom_conf_mp(chip); 468cf4ece53SMasayuki Ohtak if (retval) 469cf4ece53SMasayuki Ohtak return retval; 470cf4ece53SMasayuki Ohtak 471cf4ece53SMasayuki Ohtak for (i = 0; i < ETH_ALEN; i++) { 472cf4ece53SMasayuki Ohtak retval = pch_phub_write_serial_rom_val(chip, i, data[i]); 473cf4ece53SMasayuki Ohtak if (retval) 474cf4ece53SMasayuki Ohtak return retval; 475cf4ece53SMasayuki Ohtak } 476cf4ece53SMasayuki Ohtak 477cf4ece53SMasayuki Ohtak return retval; 478cf4ece53SMasayuki Ohtak } 479cf4ece53SMasayuki Ohtak 480cf4ece53SMasayuki Ohtak static ssize_t pch_phub_bin_read(struct file *filp, struct kobject *kobj, 481cf4ece53SMasayuki Ohtak struct bin_attribute *attr, char *buf, 482cf4ece53SMasayuki Ohtak loff_t off, size_t count) 483cf4ece53SMasayuki Ohtak { 484cf4ece53SMasayuki Ohtak unsigned int rom_signature; 485cf4ece53SMasayuki Ohtak unsigned char rom_length; 486cf4ece53SMasayuki Ohtak unsigned int tmp; 487cf4ece53SMasayuki Ohtak unsigned int addr_offset; 488cf4ece53SMasayuki Ohtak unsigned int orom_size; 489cf4ece53SMasayuki Ohtak int ret; 490cf4ece53SMasayuki Ohtak int err; 4919914a0deSTomoya MORINAGA ssize_t rom_size; 492cf4ece53SMasayuki Ohtak 49385f4f39cSGeliang Tang struct pch_phub_reg *chip = dev_get_drvdata(kobj_to_dev(kobj)); 494cf4ece53SMasayuki Ohtak 495cf4ece53SMasayuki Ohtak ret = mutex_lock_interruptible(&pch_phub_mutex); 496cf4ece53SMasayuki Ohtak if (ret) { 497cf4ece53SMasayuki Ohtak err = -ERESTARTSYS; 498cf4ece53SMasayuki Ohtak goto return_err_nomutex; 499cf4ece53SMasayuki Ohtak } 500cf4ece53SMasayuki Ohtak 501cf4ece53SMasayuki Ohtak /* Get Rom signature */ 5029914a0deSTomoya MORINAGA chip->pch_phub_extrom_base_address = pci_map_rom(chip->pdev, &rom_size); 503a75fa128SColin Ian King if (!chip->pch_phub_extrom_base_address) { 504a75fa128SColin Ian King err = -ENODATA; 5059914a0deSTomoya MORINAGA goto exrom_map_err; 506a75fa128SColin Ian King } 5079914a0deSTomoya MORINAGA 508275640b0STomoya MORINAGA pch_phub_read_serial_rom(chip, chip->pch_opt_rom_start_address, 509275640b0STomoya MORINAGA (unsigned char *)&rom_signature); 510cf4ece53SMasayuki Ohtak rom_signature &= 0xff; 511275640b0STomoya MORINAGA pch_phub_read_serial_rom(chip, chip->pch_opt_rom_start_address + 1, 512275640b0STomoya MORINAGA (unsigned char *)&tmp); 513cf4ece53SMasayuki Ohtak rom_signature |= (tmp & 0xff) << 8; 514cf4ece53SMasayuki Ohtak if (rom_signature == 0xAA55) { 515275640b0STomoya MORINAGA pch_phub_read_serial_rom(chip, 516275640b0STomoya MORINAGA chip->pch_opt_rom_start_address + 2, 517275640b0STomoya MORINAGA &rom_length); 518cf4ece53SMasayuki Ohtak orom_size = rom_length * 512; 519cf4ece53SMasayuki Ohtak if (orom_size < off) { 520cf4ece53SMasayuki Ohtak addr_offset = 0; 521cf4ece53SMasayuki Ohtak goto return_ok; 522cf4ece53SMasayuki Ohtak } 523cf4ece53SMasayuki Ohtak if (orom_size < count) { 524cf4ece53SMasayuki Ohtak addr_offset = 0; 525cf4ece53SMasayuki Ohtak goto return_ok; 526cf4ece53SMasayuki Ohtak } 527cf4ece53SMasayuki Ohtak 528cf4ece53SMasayuki Ohtak for (addr_offset = 0; addr_offset < count; addr_offset++) { 529275640b0STomoya MORINAGA pch_phub_read_serial_rom(chip, 530275640b0STomoya MORINAGA chip->pch_opt_rom_start_address + addr_offset + off, 531cf4ece53SMasayuki Ohtak &buf[addr_offset]); 532cf4ece53SMasayuki Ohtak } 533cf4ece53SMasayuki Ohtak } else { 534cf4ece53SMasayuki Ohtak err = -ENODATA; 535cf4ece53SMasayuki Ohtak goto return_err; 536cf4ece53SMasayuki Ohtak } 537cf4ece53SMasayuki Ohtak return_ok: 5389914a0deSTomoya MORINAGA pci_unmap_rom(chip->pdev, chip->pch_phub_extrom_base_address); 539cf4ece53SMasayuki Ohtak mutex_unlock(&pch_phub_mutex); 540cf4ece53SMasayuki Ohtak return addr_offset; 541cf4ece53SMasayuki Ohtak 542cf4ece53SMasayuki Ohtak return_err: 5439914a0deSTomoya MORINAGA pci_unmap_rom(chip->pdev, chip->pch_phub_extrom_base_address); 5449914a0deSTomoya MORINAGA exrom_map_err: 545cf4ece53SMasayuki Ohtak mutex_unlock(&pch_phub_mutex); 546cf4ece53SMasayuki Ohtak return_err_nomutex: 547cf4ece53SMasayuki Ohtak return err; 548cf4ece53SMasayuki Ohtak } 549cf4ece53SMasayuki Ohtak 550cf4ece53SMasayuki Ohtak static ssize_t pch_phub_bin_write(struct file *filp, struct kobject *kobj, 551cf4ece53SMasayuki Ohtak struct bin_attribute *attr, 552cf4ece53SMasayuki Ohtak char *buf, loff_t off, size_t count) 553cf4ece53SMasayuki Ohtak { 554cf4ece53SMasayuki Ohtak int err; 555cf4ece53SMasayuki Ohtak unsigned int addr_offset; 556cf4ece53SMasayuki Ohtak int ret; 5579914a0deSTomoya MORINAGA ssize_t rom_size; 55885f4f39cSGeliang Tang struct pch_phub_reg *chip = dev_get_drvdata(kobj_to_dev(kobj)); 559cf4ece53SMasayuki Ohtak 560cf4ece53SMasayuki Ohtak ret = mutex_lock_interruptible(&pch_phub_mutex); 561cf4ece53SMasayuki Ohtak if (ret) 562cf4ece53SMasayuki Ohtak return -ERESTARTSYS; 563cf4ece53SMasayuki Ohtak 564cf4ece53SMasayuki Ohtak if (off > PCH_PHUB_OROM_SIZE) { 565cf4ece53SMasayuki Ohtak addr_offset = 0; 566cf4ece53SMasayuki Ohtak goto return_ok; 567cf4ece53SMasayuki Ohtak } 568cf4ece53SMasayuki Ohtak if (count > PCH_PHUB_OROM_SIZE) { 569cf4ece53SMasayuki Ohtak addr_offset = 0; 570cf4ece53SMasayuki Ohtak goto return_ok; 571cf4ece53SMasayuki Ohtak } 572cf4ece53SMasayuki Ohtak 5739914a0deSTomoya MORINAGA chip->pch_phub_extrom_base_address = pci_map_rom(chip->pdev, &rom_size); 5749914a0deSTomoya MORINAGA if (!chip->pch_phub_extrom_base_address) { 5759914a0deSTomoya MORINAGA err = -ENOMEM; 5769914a0deSTomoya MORINAGA goto exrom_map_err; 5779914a0deSTomoya MORINAGA } 5789914a0deSTomoya MORINAGA 579cf4ece53SMasayuki Ohtak for (addr_offset = 0; addr_offset < count; addr_offset++) { 580cf4ece53SMasayuki Ohtak if (PCH_PHUB_OROM_SIZE < off + addr_offset) 581cf4ece53SMasayuki Ohtak goto return_ok; 582cf4ece53SMasayuki Ohtak 583275640b0STomoya MORINAGA ret = pch_phub_write_serial_rom(chip, 584275640b0STomoya MORINAGA chip->pch_opt_rom_start_address + addr_offset + off, 585cf4ece53SMasayuki Ohtak buf[addr_offset]); 586cf4ece53SMasayuki Ohtak if (ret) { 587cf4ece53SMasayuki Ohtak err = ret; 588cf4ece53SMasayuki Ohtak goto return_err; 589cf4ece53SMasayuki Ohtak } 590cf4ece53SMasayuki Ohtak } 591cf4ece53SMasayuki Ohtak 592cf4ece53SMasayuki Ohtak return_ok: 5939914a0deSTomoya MORINAGA pci_unmap_rom(chip->pdev, chip->pch_phub_extrom_base_address); 594cf4ece53SMasayuki Ohtak mutex_unlock(&pch_phub_mutex); 595cf4ece53SMasayuki Ohtak return addr_offset; 596cf4ece53SMasayuki Ohtak 597cf4ece53SMasayuki Ohtak return_err: 5989914a0deSTomoya MORINAGA pci_unmap_rom(chip->pdev, chip->pch_phub_extrom_base_address); 5999914a0deSTomoya MORINAGA 6009914a0deSTomoya MORINAGA exrom_map_err: 601cf4ece53SMasayuki Ohtak mutex_unlock(&pch_phub_mutex); 602cf4ece53SMasayuki Ohtak return err; 603cf4ece53SMasayuki Ohtak } 604cf4ece53SMasayuki Ohtak 605cf4ece53SMasayuki Ohtak static ssize_t show_pch_mac(struct device *dev, struct device_attribute *attr, 606cf4ece53SMasayuki Ohtak char *buf) 607cf4ece53SMasayuki Ohtak { 608cf4ece53SMasayuki Ohtak u8 mac[8]; 609cf4ece53SMasayuki Ohtak struct pch_phub_reg *chip = dev_get_drvdata(dev); 6109914a0deSTomoya MORINAGA ssize_t rom_size; 6119914a0deSTomoya MORINAGA 6129914a0deSTomoya MORINAGA chip->pch_phub_extrom_base_address = pci_map_rom(chip->pdev, &rom_size); 6139914a0deSTomoya MORINAGA if (!chip->pch_phub_extrom_base_address) 6149914a0deSTomoya MORINAGA return -ENOMEM; 615cf4ece53SMasayuki Ohtak 616cf4ece53SMasayuki Ohtak pch_phub_read_gbe_mac_addr(chip, mac); 6179914a0deSTomoya MORINAGA pci_unmap_rom(chip->pdev, chip->pch_phub_extrom_base_address); 618cf4ece53SMasayuki Ohtak 61925b8a88cSAndy Shevchenko return sprintf(buf, "%pM\n", mac); 620cf4ece53SMasayuki Ohtak } 621cf4ece53SMasayuki Ohtak 622cf4ece53SMasayuki Ohtak static ssize_t store_pch_mac(struct device *dev, struct device_attribute *attr, 623cf4ece53SMasayuki Ohtak const char *buf, size_t count) 624cf4ece53SMasayuki Ohtak { 625143e9c76SAndy Shevchenko u8 mac[ETH_ALEN]; 6269914a0deSTomoya MORINAGA ssize_t rom_size; 627cf4ece53SMasayuki Ohtak struct pch_phub_reg *chip = dev_get_drvdata(dev); 628a246b973SAlexander Stein int ret; 629cf4ece53SMasayuki Ohtak 630143e9c76SAndy Shevchenko if (!mac_pton(buf, mac)) 631cf4ece53SMasayuki Ohtak return -EINVAL; 632cf4ece53SMasayuki Ohtak 6339914a0deSTomoya MORINAGA chip->pch_phub_extrom_base_address = pci_map_rom(chip->pdev, &rom_size); 6349914a0deSTomoya MORINAGA if (!chip->pch_phub_extrom_base_address) 6359914a0deSTomoya MORINAGA return -ENOMEM; 6369914a0deSTomoya MORINAGA 637a246b973SAlexander Stein ret = pch_phub_write_gbe_mac_addr(chip, mac); 6389914a0deSTomoya MORINAGA pci_unmap_rom(chip->pdev, chip->pch_phub_extrom_base_address); 639a246b973SAlexander Stein if (ret) 640a246b973SAlexander Stein return ret; 641cf4ece53SMasayuki Ohtak 642cf4ece53SMasayuki Ohtak return count; 643cf4ece53SMasayuki Ohtak } 644cf4ece53SMasayuki Ohtak 645cf4ece53SMasayuki Ohtak static DEVICE_ATTR(pch_mac, S_IRUGO | S_IWUSR, show_pch_mac, store_pch_mac); 646cf4ece53SMasayuki Ohtak 64757daedf8SBhumika Goyal static const struct bin_attribute pch_bin_attr = { 648cf4ece53SMasayuki Ohtak .attr = { 649cf4ece53SMasayuki Ohtak .name = "pch_firmware", 650cf4ece53SMasayuki Ohtak .mode = S_IRUGO | S_IWUSR, 651cf4ece53SMasayuki Ohtak }, 652cf4ece53SMasayuki Ohtak .size = PCH_PHUB_OROM_SIZE + 1, 653cf4ece53SMasayuki Ohtak .read = pch_phub_bin_read, 654cf4ece53SMasayuki Ohtak .write = pch_phub_bin_write, 655cf4ece53SMasayuki Ohtak }; 656cf4ece53SMasayuki Ohtak 65780c8ae28SBill Pemberton static int pch_phub_probe(struct pci_dev *pdev, 658cf4ece53SMasayuki Ohtak const struct pci_device_id *id) 659cf4ece53SMasayuki Ohtak { 660cf4ece53SMasayuki Ohtak int ret; 661cf4ece53SMasayuki Ohtak struct pch_phub_reg *chip; 662cf4ece53SMasayuki Ohtak 663cf4ece53SMasayuki Ohtak chip = kzalloc(sizeof(struct pch_phub_reg), GFP_KERNEL); 664cf4ece53SMasayuki Ohtak if (chip == NULL) 665cf4ece53SMasayuki Ohtak return -ENOMEM; 666cf4ece53SMasayuki Ohtak 667cf4ece53SMasayuki Ohtak ret = pci_enable_device(pdev); 668cf4ece53SMasayuki Ohtak if (ret) { 669cf4ece53SMasayuki Ohtak dev_err(&pdev->dev, 670cf4ece53SMasayuki Ohtak "%s : pci_enable_device FAILED(ret=%d)", __func__, ret); 671cf4ece53SMasayuki Ohtak goto err_pci_enable_dev; 672cf4ece53SMasayuki Ohtak } 673cf4ece53SMasayuki Ohtak dev_dbg(&pdev->dev, "%s : pci_enable_device returns %d\n", __func__, 674cf4ece53SMasayuki Ohtak ret); 675cf4ece53SMasayuki Ohtak 676cf4ece53SMasayuki Ohtak ret = pci_request_regions(pdev, KBUILD_MODNAME); 677cf4ece53SMasayuki Ohtak if (ret) { 678cf4ece53SMasayuki Ohtak dev_err(&pdev->dev, 679cf4ece53SMasayuki Ohtak "%s : pci_request_regions FAILED(ret=%d)", __func__, ret); 680cf4ece53SMasayuki Ohtak goto err_req_regions; 681cf4ece53SMasayuki Ohtak } 682cf4ece53SMasayuki Ohtak dev_dbg(&pdev->dev, "%s : " 683cf4ece53SMasayuki Ohtak "pci_request_regions returns %d\n", __func__, ret); 684cf4ece53SMasayuki Ohtak 685cf4ece53SMasayuki Ohtak chip->pch_phub_base_address = pci_iomap(pdev, 1, 0); 686cf4ece53SMasayuki Ohtak 687cf4ece53SMasayuki Ohtak 68873ac0e9eSDevendra Naga if (chip->pch_phub_base_address == NULL) { 689cf4ece53SMasayuki Ohtak dev_err(&pdev->dev, "%s : pci_iomap FAILED", __func__); 690cf4ece53SMasayuki Ohtak ret = -ENOMEM; 691cf4ece53SMasayuki Ohtak goto err_pci_iomap; 692cf4ece53SMasayuki Ohtak } 693cf4ece53SMasayuki Ohtak dev_dbg(&pdev->dev, "%s : pci_iomap SUCCESS and value " 694da0d7f98SGreg Kroah-Hartman "in pch_phub_base_address variable is %p\n", __func__, 695da0d7f98SGreg Kroah-Hartman chip->pch_phub_base_address); 696cf4ece53SMasayuki Ohtak 6979914a0deSTomoya MORINAGA chip->pdev = pdev; /* Save pci device struct */ 698cf4ece53SMasayuki Ohtak 699275640b0STomoya MORINAGA if (id->driver_data == 1) { /* EG20T PCH */ 7002b934c62SAlexander Stein const char *board_name; 701549ce8f1SZubair Lutfullah Kakakhel unsigned int prefetch = 0x000affaa; 702549ce8f1SZubair Lutfullah Kakakhel 703549ce8f1SZubair Lutfullah Kakakhel if (pdev->dev.of_node) 704549ce8f1SZubair Lutfullah Kakakhel of_property_read_u32(pdev->dev.of_node, 705549ce8f1SZubair Lutfullah Kakakhel "intel,eg20t-prefetch", 706549ce8f1SZubair Lutfullah Kakakhel &prefetch); 7072b934c62SAlexander Stein 70829ddae2aSWei Yongjun ret = sysfs_create_file(&pdev->dev.kobj, 709c47dda7dSTomoya MORINAGA &dev_attr_pch_mac.attr); 71029ddae2aSWei Yongjun if (ret) 711cf4ece53SMasayuki Ohtak goto err_sysfs_create; 712cf4ece53SMasayuki Ohtak 71329ddae2aSWei Yongjun ret = sysfs_create_bin_file(&pdev->dev.kobj, &pch_bin_attr); 71429ddae2aSWei Yongjun if (ret) 715cf4ece53SMasayuki Ohtak goto exit_bin_attr; 716cf4ece53SMasayuki Ohtak 717c47dda7dSTomoya MORINAGA pch_phub_read_modify_write_reg(chip, 718c47dda7dSTomoya MORINAGA (unsigned int)CLKCFG_REG_OFFSET, 719c47dda7dSTomoya MORINAGA CLKCFG_CAN_50MHZ, 720c47dda7dSTomoya MORINAGA CLKCFG_CANCLK_MASK); 721cf4ece53SMasayuki Ohtak 7226ae705b2SDenis Turischev /* quirk for CM-iTC board */ 7232b934c62SAlexander Stein board_name = dmi_get_system_info(DMI_BOARD_NAME); 7242b934c62SAlexander Stein if (board_name && strstr(board_name, "CM-iTC")) 7256ae705b2SDenis Turischev pch_phub_read_modify_write_reg(chip, 7266ae705b2SDenis Turischev (unsigned int)CLKCFG_REG_OFFSET, 7276ae705b2SDenis Turischev CLKCFG_UART_48MHZ | CLKCFG_BAUDDIV | 7286ae705b2SDenis Turischev CLKCFG_PLL2VCO | CLKCFG_UARTCLKSEL, 7296ae705b2SDenis Turischev CLKCFG_UART_MASK); 7306ae705b2SDenis Turischev 731cf4ece53SMasayuki Ohtak /* set the prefech value */ 732549ce8f1SZubair Lutfullah Kakakhel iowrite32(prefetch, chip->pch_phub_base_address + 0x14); 733cf4ece53SMasayuki Ohtak /* set the interrupt delay value */ 734cf4ece53SMasayuki Ohtak iowrite32(0x25, chip->pch_phub_base_address + 0x44); 735275640b0STomoya MORINAGA chip->pch_opt_rom_start_address = PCH_PHUB_ROM_START_ADDR_EG20T; 736275640b0STomoya MORINAGA chip->pch_mac_start_address = PCH_PHUB_MAC_START_ADDR_EG20T; 737bed3d7baSZubair Lutfullah Kakakhel 738bed3d7baSZubair Lutfullah Kakakhel /* quirk for MIPS Boston platform */ 739bed3d7baSZubair Lutfullah Kakakhel if (pdev->dev.of_node) { 740bed3d7baSZubair Lutfullah Kakakhel if (of_machine_is_compatible("img,boston")) { 741bed3d7baSZubair Lutfullah Kakakhel pch_phub_read_modify_write_reg(chip, 742bed3d7baSZubair Lutfullah Kakakhel (unsigned int)CLKCFG_REG_OFFSET, 743bed3d7baSZubair Lutfullah Kakakhel CLKCFG_UART_25MHZ, 744bed3d7baSZubair Lutfullah Kakakhel CLKCFG_UART_MASK); 745bed3d7baSZubair Lutfullah Kakakhel } 746bed3d7baSZubair Lutfullah Kakakhel } 747275640b0STomoya MORINAGA } else if (id->driver_data == 2) { /* ML7213 IOH */ 74829ddae2aSWei Yongjun ret = sysfs_create_bin_file(&pdev->dev.kobj, &pch_bin_attr); 74929ddae2aSWei Yongjun if (ret) 750c47dda7dSTomoya MORINAGA goto err_sysfs_create; 751c47dda7dSTomoya MORINAGA /* set the prefech value 752c47dda7dSTomoya MORINAGA * Device2(USB OHCI #1/ USB EHCI #1/ USB Device):a 753c47dda7dSTomoya MORINAGA * Device4(SDIO #0,1,2):f 754c47dda7dSTomoya MORINAGA * Device6(SATA 2):f 755c47dda7dSTomoya MORINAGA * Device8(USB OHCI #0/ USB EHCI #0):a 756c47dda7dSTomoya MORINAGA */ 757c47dda7dSTomoya MORINAGA iowrite32(0x000affa0, chip->pch_phub_base_address + 0x14); 758275640b0STomoya MORINAGA chip->pch_opt_rom_start_address =\ 759275640b0STomoya MORINAGA PCH_PHUB_ROM_START_ADDR_ML7213; 760275640b0STomoya MORINAGA } else if (id->driver_data == 3) { /* ML7223 IOH Bus-m*/ 761275640b0STomoya MORINAGA /* set the prefech value 762275640b0STomoya MORINAGA * Device8(GbE) 763275640b0STomoya MORINAGA */ 764275640b0STomoya MORINAGA iowrite32(0x000a0000, chip->pch_phub_base_address + 0x14); 76520ae6d0bSTomoya MORINAGA /* set the interrupt delay value */ 76620ae6d0bSTomoya MORINAGA iowrite32(0x25, chip->pch_phub_base_address + 0x140); 767275640b0STomoya MORINAGA chip->pch_opt_rom_start_address =\ 768275640b0STomoya MORINAGA PCH_PHUB_ROM_START_ADDR_ML7223; 769275640b0STomoya MORINAGA chip->pch_mac_start_address = PCH_PHUB_MAC_START_ADDR_ML7223; 770275640b0STomoya MORINAGA } else if (id->driver_data == 4) { /* ML7223 IOH Bus-n*/ 77129ddae2aSWei Yongjun ret = sysfs_create_file(&pdev->dev.kobj, 772275640b0STomoya MORINAGA &dev_attr_pch_mac.attr); 77329ddae2aSWei Yongjun if (ret) 774275640b0STomoya MORINAGA goto err_sysfs_create; 77529ddae2aSWei Yongjun ret = sysfs_create_bin_file(&pdev->dev.kobj, &pch_bin_attr); 77629ddae2aSWei Yongjun if (ret) 777275640b0STomoya MORINAGA goto exit_bin_attr; 778275640b0STomoya MORINAGA /* set the prefech value 779275640b0STomoya MORINAGA * Device2(USB OHCI #0,1,2,3/ USB EHCI #0):a 780275640b0STomoya MORINAGA * Device4(SDIO #0,1):f 781275640b0STomoya MORINAGA * Device6(SATA 2):f 782275640b0STomoya MORINAGA */ 783275640b0STomoya MORINAGA iowrite32(0x0000ffa0, chip->pch_phub_base_address + 0x14); 784275640b0STomoya MORINAGA chip->pch_opt_rom_start_address =\ 785275640b0STomoya MORINAGA PCH_PHUB_ROM_START_ADDR_ML7223; 786275640b0STomoya MORINAGA chip->pch_mac_start_address = PCH_PHUB_MAC_START_ADDR_ML7223; 787584ad00cSTomoya MORINAGA } else if (id->driver_data == 5) { /* ML7831 */ 78829ddae2aSWei Yongjun ret = sysfs_create_file(&pdev->dev.kobj, 789584ad00cSTomoya MORINAGA &dev_attr_pch_mac.attr); 79029ddae2aSWei Yongjun if (ret) 791584ad00cSTomoya MORINAGA goto err_sysfs_create; 792584ad00cSTomoya MORINAGA 79329ddae2aSWei Yongjun ret = sysfs_create_bin_file(&pdev->dev.kobj, &pch_bin_attr); 79429ddae2aSWei Yongjun if (ret) 795584ad00cSTomoya MORINAGA goto exit_bin_attr; 796584ad00cSTomoya MORINAGA 797584ad00cSTomoya MORINAGA /* set the prefech value */ 798584ad00cSTomoya MORINAGA iowrite32(0x000affaa, chip->pch_phub_base_address + 0x14); 799584ad00cSTomoya MORINAGA /* set the interrupt delay value */ 800584ad00cSTomoya MORINAGA iowrite32(0x25, chip->pch_phub_base_address + 0x44); 801584ad00cSTomoya MORINAGA chip->pch_opt_rom_start_address = PCH_PHUB_ROM_START_ADDR_EG20T; 802584ad00cSTomoya MORINAGA chip->pch_mac_start_address = PCH_PHUB_MAC_START_ADDR_EG20T; 803c47dda7dSTomoya MORINAGA } 804275640b0STomoya MORINAGA 805275640b0STomoya MORINAGA chip->ioh_type = id->driver_data; 806c47dda7dSTomoya MORINAGA pci_set_drvdata(pdev, chip); 807cf4ece53SMasayuki Ohtak 808cf4ece53SMasayuki Ohtak return 0; 809cf4ece53SMasayuki Ohtak exit_bin_attr: 810cf4ece53SMasayuki Ohtak sysfs_remove_file(&pdev->dev.kobj, &dev_attr_pch_mac.attr); 811cf4ece53SMasayuki Ohtak 812cf4ece53SMasayuki Ohtak err_sysfs_create: 813cf4ece53SMasayuki Ohtak pci_iounmap(pdev, chip->pch_phub_base_address); 814cf4ece53SMasayuki Ohtak err_pci_iomap: 815cf4ece53SMasayuki Ohtak pci_release_regions(pdev); 816cf4ece53SMasayuki Ohtak err_req_regions: 817cf4ece53SMasayuki Ohtak pci_disable_device(pdev); 818cf4ece53SMasayuki Ohtak err_pci_enable_dev: 819cf4ece53SMasayuki Ohtak kfree(chip); 820cf4ece53SMasayuki Ohtak dev_err(&pdev->dev, "%s returns %d\n", __func__, ret); 821cf4ece53SMasayuki Ohtak return ret; 822cf4ece53SMasayuki Ohtak } 823cf4ece53SMasayuki Ohtak 824486a5c28SBill Pemberton static void pch_phub_remove(struct pci_dev *pdev) 825cf4ece53SMasayuki Ohtak { 826cf4ece53SMasayuki Ohtak struct pch_phub_reg *chip = pci_get_drvdata(pdev); 827cf4ece53SMasayuki Ohtak 828cf4ece53SMasayuki Ohtak sysfs_remove_file(&pdev->dev.kobj, &dev_attr_pch_mac.attr); 829cf4ece53SMasayuki Ohtak sysfs_remove_bin_file(&pdev->dev.kobj, &pch_bin_attr); 830cf4ece53SMasayuki Ohtak pci_iounmap(pdev, chip->pch_phub_base_address); 831cf4ece53SMasayuki Ohtak pci_release_regions(pdev); 832cf4ece53SMasayuki Ohtak pci_disable_device(pdev); 833cf4ece53SMasayuki Ohtak kfree(chip); 834cf4ece53SMasayuki Ohtak } 835cf4ece53SMasayuki Ohtak 836*34afa1d6SVaibhav Gupta static int __maybe_unused pch_phub_suspend(struct device *dev_d) 837cf4ece53SMasayuki Ohtak { 838*34afa1d6SVaibhav Gupta device_wakeup_disable(dev_d); 839cf4ece53SMasayuki Ohtak 840cf4ece53SMasayuki Ohtak return 0; 841cf4ece53SMasayuki Ohtak } 842cf4ece53SMasayuki Ohtak 843*34afa1d6SVaibhav Gupta static int __maybe_unused pch_phub_resume(struct device *dev_d) 844cf4ece53SMasayuki Ohtak { 845*34afa1d6SVaibhav Gupta device_wakeup_disable(dev_d); 846cf4ece53SMasayuki Ohtak 847cf4ece53SMasayuki Ohtak return 0; 848cf4ece53SMasayuki Ohtak } 849cf4ece53SMasayuki Ohtak 850e3b9c5ceSArvind Yadav static const struct pci_device_id pch_phub_pcidev_id[] = { 851c47dda7dSTomoya MORINAGA { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_PCH1_PHUB), 1, }, 852c47dda7dSTomoya MORINAGA { PCI_VDEVICE(ROHM, PCI_DEVICE_ID_ROHM_ML7213_PHUB), 2, }, 853275640b0STomoya MORINAGA { PCI_VDEVICE(ROHM, PCI_DEVICE_ID_ROHM_ML7223_mPHUB), 3, }, 854275640b0STomoya MORINAGA { PCI_VDEVICE(ROHM, PCI_DEVICE_ID_ROHM_ML7223_nPHUB), 4, }, 855584ad00cSTomoya MORINAGA { PCI_VDEVICE(ROHM, PCI_DEVICE_ID_ROHM_ML7831_PHUB), 5, }, 856c47dda7dSTomoya MORINAGA { } 857cf4ece53SMasayuki Ohtak }; 858b2595142SAxel Lin MODULE_DEVICE_TABLE(pci, pch_phub_pcidev_id); 859cf4ece53SMasayuki Ohtak 860*34afa1d6SVaibhav Gupta static SIMPLE_DEV_PM_OPS(pch_phub_pm_ops, pch_phub_suspend, pch_phub_resume); 861*34afa1d6SVaibhav Gupta 862cf4ece53SMasayuki Ohtak static struct pci_driver pch_phub_driver = { 863cf4ece53SMasayuki Ohtak .name = "pch_phub", 864cf4ece53SMasayuki Ohtak .id_table = pch_phub_pcidev_id, 865cf4ece53SMasayuki Ohtak .probe = pch_phub_probe, 8662d6bed9cSBill Pemberton .remove = pch_phub_remove, 867*34afa1d6SVaibhav Gupta .driver.pm = &pch_phub_pm_ops, 868cf4ece53SMasayuki Ohtak }; 869cf4ece53SMasayuki Ohtak 870cfeb2852SDevendra Naga module_pci_driver(pch_phub_driver); 871cf4ece53SMasayuki Ohtak 8727f2732c8STomoya MORINAGA MODULE_DESCRIPTION("Intel EG20T PCH/LAPIS Semiconductor IOH(ML7213/ML7223) PHUB"); 873cf4ece53SMasayuki Ohtak MODULE_LICENSE("GPL"); 874