1cf4ece53SMasayuki Ohtak /* 2c47dda7dSTomoya MORINAGA * Copyright (C) 2010 OKI SEMICONDUCTOR CO., LTD. 3cf4ece53SMasayuki Ohtak * 4cf4ece53SMasayuki Ohtak * This program is free software; you can redistribute it and/or modify 5cf4ece53SMasayuki Ohtak * it under the terms of the GNU General Public License as published by 6cf4ece53SMasayuki Ohtak * the Free Software Foundation; version 2 of the License. 7cf4ece53SMasayuki Ohtak * 8cf4ece53SMasayuki Ohtak * This program is distributed in the hope that it will be useful, 9cf4ece53SMasayuki Ohtak * but WITHOUT ANY WARRANTY; without even the implied warranty of 10cf4ece53SMasayuki Ohtak * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11cf4ece53SMasayuki Ohtak * GNU General Public License for more details. 12cf4ece53SMasayuki Ohtak * 13cf4ece53SMasayuki Ohtak * You should have received a copy of the GNU General Public License 14cf4ece53SMasayuki Ohtak * along with this program; if not, write to the Free Software 15cf4ece53SMasayuki Ohtak * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. 16cf4ece53SMasayuki Ohtak */ 17cf4ece53SMasayuki Ohtak 18cf4ece53SMasayuki Ohtak #include <linux/module.h> 19cf4ece53SMasayuki Ohtak #include <linux/kernel.h> 20cf4ece53SMasayuki Ohtak #include <linux/types.h> 21cf4ece53SMasayuki Ohtak #include <linux/fs.h> 22cf4ece53SMasayuki Ohtak #include <linux/uaccess.h> 23cf4ece53SMasayuki Ohtak #include <linux/string.h> 24cf4ece53SMasayuki Ohtak #include <linux/pci.h> 25cf4ece53SMasayuki Ohtak #include <linux/io.h> 26cf4ece53SMasayuki Ohtak #include <linux/delay.h> 27cf4ece53SMasayuki Ohtak #include <linux/mutex.h> 28cf4ece53SMasayuki Ohtak #include <linux/if_ether.h> 29cf4ece53SMasayuki Ohtak #include <linux/ctype.h> 306ae705b2SDenis Turischev #include <linux/dmi.h> 31cf4ece53SMasayuki Ohtak 32cf4ece53SMasayuki Ohtak #define PHUB_STATUS 0x00 /* Status Register offset */ 33cf4ece53SMasayuki Ohtak #define PHUB_CONTROL 0x04 /* Control Register offset */ 34cf4ece53SMasayuki Ohtak #define PHUB_TIMEOUT 0x05 /* Time out value for Status Register */ 35cf4ece53SMasayuki Ohtak #define PCH_PHUB_ROM_WRITE_ENABLE 0x01 /* Enabling for writing ROM */ 36cf4ece53SMasayuki Ohtak #define PCH_PHUB_ROM_WRITE_DISABLE 0x00 /* Disabling for writing ROM */ 37275640b0STomoya MORINAGA #define PCH_PHUB_MAC_START_ADDR_EG20T 0x14 /* MAC data area start address 38275640b0STomoya MORINAGA offset */ 39275640b0STomoya MORINAGA #define PCH_PHUB_MAC_START_ADDR_ML7223 0x20C /* MAC data area start address 40275640b0STomoya MORINAGA offset */ 41275640b0STomoya MORINAGA #define PCH_PHUB_ROM_START_ADDR_EG20T 0x80 /* ROM data area start address offset 42c47dda7dSTomoya MORINAGA (Intel EG20T PCH)*/ 43c47dda7dSTomoya MORINAGA #define PCH_PHUB_ROM_START_ADDR_ML7213 0x400 /* ROM data area start address 44c47dda7dSTomoya MORINAGA offset(OKI SEMICONDUCTOR ML7213) 45c47dda7dSTomoya MORINAGA */ 46275640b0STomoya MORINAGA #define PCH_PHUB_ROM_START_ADDR_ML7223 0x400 /* ROM data area start address 47275640b0STomoya MORINAGA offset(OKI SEMICONDUCTOR ML7223) 48275640b0STomoya MORINAGA */ 49cf4ece53SMasayuki Ohtak 50cf4ece53SMasayuki Ohtak /* MAX number of INT_REDUCE_CONTROL registers */ 51cf4ece53SMasayuki Ohtak #define MAX_NUM_INT_REDUCE_CONTROL_REG 128 52cf4ece53SMasayuki Ohtak #define PCI_DEVICE_ID_PCH1_PHUB 0x8801 53cf4ece53SMasayuki Ohtak #define PCH_MINOR_NOS 1 54cf4ece53SMasayuki Ohtak #define CLKCFG_CAN_50MHZ 0x12000000 55cf4ece53SMasayuki Ohtak #define CLKCFG_CANCLK_MASK 0xFF000000 566ae705b2SDenis Turischev #define CLKCFG_UART_MASK 0xFFFFFF 576ae705b2SDenis Turischev 586ae705b2SDenis Turischev /* CM-iTC */ 596ae705b2SDenis Turischev #define CLKCFG_UART_48MHZ (1 << 16) 606ae705b2SDenis Turischev #define CLKCFG_BAUDDIV (2 << 20) 616ae705b2SDenis Turischev #define CLKCFG_PLL2VCO (8 << 9) 626ae705b2SDenis Turischev #define CLKCFG_UARTCLKSEL (1 << 18) 63cf4ece53SMasayuki Ohtak 641a738dcfSTomoya MORINAGA /* Macros for ML7213 */ 651a738dcfSTomoya MORINAGA #define PCI_VENDOR_ID_ROHM 0x10db 661a738dcfSTomoya MORINAGA #define PCI_DEVICE_ID_ROHM_ML7213_PHUB 0x801A 67cf4ece53SMasayuki Ohtak 68c47dda7dSTomoya MORINAGA /* Macros for ML7213 */ 69c47dda7dSTomoya MORINAGA #define PCI_VENDOR_ID_ROHM 0x10db 70c47dda7dSTomoya MORINAGA #define PCI_DEVICE_ID_ROHM_ML7213_PHUB 0x801A 71c47dda7dSTomoya MORINAGA 72275640b0STomoya MORINAGA /* Macros for ML7223 */ 73275640b0STomoya MORINAGA #define PCI_DEVICE_ID_ROHM_ML7223_mPHUB 0x8012 /* for Bus-m */ 74275640b0STomoya MORINAGA #define PCI_DEVICE_ID_ROHM_ML7223_nPHUB 0x8002 /* for Bus-n */ 75275640b0STomoya MORINAGA 76cf4ece53SMasayuki Ohtak /* SROM ACCESS Macro */ 77cf4ece53SMasayuki Ohtak #define PCH_WORD_ADDR_MASK (~((1 << 2) - 1)) 78cf4ece53SMasayuki Ohtak 79cf4ece53SMasayuki Ohtak /* Registers address offset */ 80cf4ece53SMasayuki Ohtak #define PCH_PHUB_ID_REG 0x0000 81cf4ece53SMasayuki Ohtak #define PCH_PHUB_QUEUE_PRI_VAL_REG 0x0004 82cf4ece53SMasayuki Ohtak #define PCH_PHUB_RC_QUEUE_MAXSIZE_REG 0x0008 83cf4ece53SMasayuki Ohtak #define PCH_PHUB_BRI_QUEUE_MAXSIZE_REG 0x000C 84cf4ece53SMasayuki Ohtak #define PCH_PHUB_COMP_RESP_TIMEOUT_REG 0x0010 85cf4ece53SMasayuki Ohtak #define PCH_PHUB_BUS_SLAVE_CONTROL_REG 0x0014 86cf4ece53SMasayuki Ohtak #define PCH_PHUB_DEADLOCK_AVOID_TYPE_REG 0x0018 87cf4ece53SMasayuki Ohtak #define PCH_PHUB_INTPIN_REG_WPERMIT_REG0 0x0020 88cf4ece53SMasayuki Ohtak #define PCH_PHUB_INTPIN_REG_WPERMIT_REG1 0x0024 89cf4ece53SMasayuki Ohtak #define PCH_PHUB_INTPIN_REG_WPERMIT_REG2 0x0028 90cf4ece53SMasayuki Ohtak #define PCH_PHUB_INTPIN_REG_WPERMIT_REG3 0x002C 91cf4ece53SMasayuki Ohtak #define PCH_PHUB_INT_REDUCE_CONTROL_REG_BASE 0x0040 92cf4ece53SMasayuki Ohtak #define CLKCFG_REG_OFFSET 0x500 93cf4ece53SMasayuki Ohtak 94cf4ece53SMasayuki Ohtak #define PCH_PHUB_OROM_SIZE 15360 95cf4ece53SMasayuki Ohtak 96cf4ece53SMasayuki Ohtak /** 97cf4ece53SMasayuki Ohtak * struct pch_phub_reg - PHUB register structure 98cf4ece53SMasayuki Ohtak * @phub_id_reg: PHUB_ID register val 99cf4ece53SMasayuki Ohtak * @q_pri_val_reg: QUEUE_PRI_VAL register val 100cf4ece53SMasayuki Ohtak * @rc_q_maxsize_reg: RC_QUEUE_MAXSIZE register val 101cf4ece53SMasayuki Ohtak * @bri_q_maxsize_reg: BRI_QUEUE_MAXSIZE register val 102cf4ece53SMasayuki Ohtak * @comp_resp_timeout_reg: COMP_RESP_TIMEOUT register val 103cf4ece53SMasayuki Ohtak * @bus_slave_control_reg: BUS_SLAVE_CONTROL_REG register val 104cf4ece53SMasayuki Ohtak * @deadlock_avoid_type_reg: DEADLOCK_AVOID_TYPE register val 105cf4ece53SMasayuki Ohtak * @intpin_reg_wpermit_reg0: INTPIN_REG_WPERMIT register 0 val 106cf4ece53SMasayuki Ohtak * @intpin_reg_wpermit_reg1: INTPIN_REG_WPERMIT register 1 val 107cf4ece53SMasayuki Ohtak * @intpin_reg_wpermit_reg2: INTPIN_REG_WPERMIT register 2 val 108cf4ece53SMasayuki Ohtak * @intpin_reg_wpermit_reg3: INTPIN_REG_WPERMIT register 3 val 109cf4ece53SMasayuki Ohtak * @int_reduce_control_reg: INT_REDUCE_CONTROL registers val 110cf4ece53SMasayuki Ohtak * @clkcfg_reg: CLK CFG register val 111cf4ece53SMasayuki Ohtak * @pch_phub_base_address: Register base address 112cf4ece53SMasayuki Ohtak * @pch_phub_extrom_base_address: external rom base address 113275640b0STomoya MORINAGA * @pch_mac_start_address: MAC address area start address 114275640b0STomoya MORINAGA * @pch_opt_rom_start_address: Option ROM start address 115275640b0STomoya MORINAGA * @ioh_type: Save IOH type 116cf4ece53SMasayuki Ohtak */ 117cf4ece53SMasayuki Ohtak struct pch_phub_reg { 118cf4ece53SMasayuki Ohtak u32 phub_id_reg; 119cf4ece53SMasayuki Ohtak u32 q_pri_val_reg; 120cf4ece53SMasayuki Ohtak u32 rc_q_maxsize_reg; 121cf4ece53SMasayuki Ohtak u32 bri_q_maxsize_reg; 122cf4ece53SMasayuki Ohtak u32 comp_resp_timeout_reg; 123cf4ece53SMasayuki Ohtak u32 bus_slave_control_reg; 124cf4ece53SMasayuki Ohtak u32 deadlock_avoid_type_reg; 125cf4ece53SMasayuki Ohtak u32 intpin_reg_wpermit_reg0; 126cf4ece53SMasayuki Ohtak u32 intpin_reg_wpermit_reg1; 127cf4ece53SMasayuki Ohtak u32 intpin_reg_wpermit_reg2; 128cf4ece53SMasayuki Ohtak u32 intpin_reg_wpermit_reg3; 129cf4ece53SMasayuki Ohtak u32 int_reduce_control_reg[MAX_NUM_INT_REDUCE_CONTROL_REG]; 130cf4ece53SMasayuki Ohtak u32 clkcfg_reg; 131cf4ece53SMasayuki Ohtak void __iomem *pch_phub_base_address; 132cf4ece53SMasayuki Ohtak void __iomem *pch_phub_extrom_base_address; 133275640b0STomoya MORINAGA u32 pch_mac_start_address; 134275640b0STomoya MORINAGA u32 pch_opt_rom_start_address; 135275640b0STomoya MORINAGA int ioh_type; 136cf4ece53SMasayuki Ohtak }; 137cf4ece53SMasayuki Ohtak 138cf4ece53SMasayuki Ohtak /* SROM SPEC for MAC address assignment offset */ 139cf4ece53SMasayuki Ohtak static const int pch_phub_mac_offset[ETH_ALEN] = {0x3, 0x2, 0x1, 0x0, 0xb, 0xa}; 140cf4ece53SMasayuki Ohtak 141cf4ece53SMasayuki Ohtak static DEFINE_MUTEX(pch_phub_mutex); 142cf4ece53SMasayuki Ohtak 143cf4ece53SMasayuki Ohtak /** 144cf4ece53SMasayuki Ohtak * pch_phub_read_modify_write_reg() - Reading modifying and writing register 145cf4ece53SMasayuki Ohtak * @reg_addr_offset: Register offset address value. 146cf4ece53SMasayuki Ohtak * @data: Writing value. 147cf4ece53SMasayuki Ohtak * @mask: Mask value. 148cf4ece53SMasayuki Ohtak */ 149cf4ece53SMasayuki Ohtak static void pch_phub_read_modify_write_reg(struct pch_phub_reg *chip, 150cf4ece53SMasayuki Ohtak unsigned int reg_addr_offset, 151cf4ece53SMasayuki Ohtak unsigned int data, unsigned int mask) 152cf4ece53SMasayuki Ohtak { 153cf4ece53SMasayuki Ohtak void __iomem *reg_addr = chip->pch_phub_base_address + reg_addr_offset; 154cf4ece53SMasayuki Ohtak iowrite32(((ioread32(reg_addr) & ~mask)) | data, reg_addr); 155cf4ece53SMasayuki Ohtak } 156cf4ece53SMasayuki Ohtak 157cf4ece53SMasayuki Ohtak /* pch_phub_save_reg_conf - saves register configuration */ 158cf4ece53SMasayuki Ohtak static void pch_phub_save_reg_conf(struct pci_dev *pdev) 159cf4ece53SMasayuki Ohtak { 160cf4ece53SMasayuki Ohtak unsigned int i; 161cf4ece53SMasayuki Ohtak struct pch_phub_reg *chip = pci_get_drvdata(pdev); 162cf4ece53SMasayuki Ohtak 163cf4ece53SMasayuki Ohtak void __iomem *p = chip->pch_phub_base_address; 164cf4ece53SMasayuki Ohtak 165cf4ece53SMasayuki Ohtak chip->phub_id_reg = ioread32(p + PCH_PHUB_ID_REG); 166cf4ece53SMasayuki Ohtak chip->q_pri_val_reg = ioread32(p + PCH_PHUB_QUEUE_PRI_VAL_REG); 167cf4ece53SMasayuki Ohtak chip->rc_q_maxsize_reg = ioread32(p + PCH_PHUB_RC_QUEUE_MAXSIZE_REG); 168cf4ece53SMasayuki Ohtak chip->bri_q_maxsize_reg = ioread32(p + PCH_PHUB_BRI_QUEUE_MAXSIZE_REG); 169cf4ece53SMasayuki Ohtak chip->comp_resp_timeout_reg = 170cf4ece53SMasayuki Ohtak ioread32(p + PCH_PHUB_COMP_RESP_TIMEOUT_REG); 171cf4ece53SMasayuki Ohtak chip->bus_slave_control_reg = 172cf4ece53SMasayuki Ohtak ioread32(p + PCH_PHUB_BUS_SLAVE_CONTROL_REG); 173cf4ece53SMasayuki Ohtak chip->deadlock_avoid_type_reg = 174cf4ece53SMasayuki Ohtak ioread32(p + PCH_PHUB_DEADLOCK_AVOID_TYPE_REG); 175cf4ece53SMasayuki Ohtak chip->intpin_reg_wpermit_reg0 = 176cf4ece53SMasayuki Ohtak ioread32(p + PCH_PHUB_INTPIN_REG_WPERMIT_REG0); 177cf4ece53SMasayuki Ohtak chip->intpin_reg_wpermit_reg1 = 178cf4ece53SMasayuki Ohtak ioread32(p + PCH_PHUB_INTPIN_REG_WPERMIT_REG1); 179cf4ece53SMasayuki Ohtak chip->intpin_reg_wpermit_reg2 = 180cf4ece53SMasayuki Ohtak ioread32(p + PCH_PHUB_INTPIN_REG_WPERMIT_REG2); 181cf4ece53SMasayuki Ohtak chip->intpin_reg_wpermit_reg3 = 182cf4ece53SMasayuki Ohtak ioread32(p + PCH_PHUB_INTPIN_REG_WPERMIT_REG3); 183cf4ece53SMasayuki Ohtak dev_dbg(&pdev->dev, "%s : " 184cf4ece53SMasayuki Ohtak "chip->phub_id_reg=%x, " 185cf4ece53SMasayuki Ohtak "chip->q_pri_val_reg=%x, " 186cf4ece53SMasayuki Ohtak "chip->rc_q_maxsize_reg=%x, " 187cf4ece53SMasayuki Ohtak "chip->bri_q_maxsize_reg=%x, " 188cf4ece53SMasayuki Ohtak "chip->comp_resp_timeout_reg=%x, " 189cf4ece53SMasayuki Ohtak "chip->bus_slave_control_reg=%x, " 190cf4ece53SMasayuki Ohtak "chip->deadlock_avoid_type_reg=%x, " 191cf4ece53SMasayuki Ohtak "chip->intpin_reg_wpermit_reg0=%x, " 192cf4ece53SMasayuki Ohtak "chip->intpin_reg_wpermit_reg1=%x, " 193cf4ece53SMasayuki Ohtak "chip->intpin_reg_wpermit_reg2=%x, " 194cf4ece53SMasayuki Ohtak "chip->intpin_reg_wpermit_reg3=%x\n", __func__, 195cf4ece53SMasayuki Ohtak chip->phub_id_reg, 196cf4ece53SMasayuki Ohtak chip->q_pri_val_reg, 197cf4ece53SMasayuki Ohtak chip->rc_q_maxsize_reg, 198cf4ece53SMasayuki Ohtak chip->bri_q_maxsize_reg, 199cf4ece53SMasayuki Ohtak chip->comp_resp_timeout_reg, 200cf4ece53SMasayuki Ohtak chip->bus_slave_control_reg, 201cf4ece53SMasayuki Ohtak chip->deadlock_avoid_type_reg, 202cf4ece53SMasayuki Ohtak chip->intpin_reg_wpermit_reg0, 203cf4ece53SMasayuki Ohtak chip->intpin_reg_wpermit_reg1, 204cf4ece53SMasayuki Ohtak chip->intpin_reg_wpermit_reg2, 205cf4ece53SMasayuki Ohtak chip->intpin_reg_wpermit_reg3); 206cf4ece53SMasayuki Ohtak for (i = 0; i < MAX_NUM_INT_REDUCE_CONTROL_REG; i++) { 207cf4ece53SMasayuki Ohtak chip->int_reduce_control_reg[i] = 208cf4ece53SMasayuki Ohtak ioread32(p + PCH_PHUB_INT_REDUCE_CONTROL_REG_BASE + 4 * i); 209cf4ece53SMasayuki Ohtak dev_dbg(&pdev->dev, "%s : " 210cf4ece53SMasayuki Ohtak "chip->int_reduce_control_reg[%d]=%x\n", 211cf4ece53SMasayuki Ohtak __func__, i, chip->int_reduce_control_reg[i]); 212cf4ece53SMasayuki Ohtak } 213cf4ece53SMasayuki Ohtak chip->clkcfg_reg = ioread32(p + CLKCFG_REG_OFFSET); 214cf4ece53SMasayuki Ohtak } 215cf4ece53SMasayuki Ohtak 216cf4ece53SMasayuki Ohtak /* pch_phub_restore_reg_conf - restore register configuration */ 217cf4ece53SMasayuki Ohtak static void pch_phub_restore_reg_conf(struct pci_dev *pdev) 218cf4ece53SMasayuki Ohtak { 219cf4ece53SMasayuki Ohtak unsigned int i; 220cf4ece53SMasayuki Ohtak struct pch_phub_reg *chip = pci_get_drvdata(pdev); 221cf4ece53SMasayuki Ohtak void __iomem *p; 222cf4ece53SMasayuki Ohtak p = chip->pch_phub_base_address; 223cf4ece53SMasayuki Ohtak 224cf4ece53SMasayuki Ohtak iowrite32(chip->phub_id_reg, p + PCH_PHUB_ID_REG); 225cf4ece53SMasayuki Ohtak iowrite32(chip->q_pri_val_reg, p + PCH_PHUB_QUEUE_PRI_VAL_REG); 226cf4ece53SMasayuki Ohtak iowrite32(chip->rc_q_maxsize_reg, p + PCH_PHUB_RC_QUEUE_MAXSIZE_REG); 227cf4ece53SMasayuki Ohtak iowrite32(chip->bri_q_maxsize_reg, p + PCH_PHUB_BRI_QUEUE_MAXSIZE_REG); 228cf4ece53SMasayuki Ohtak iowrite32(chip->comp_resp_timeout_reg, 229cf4ece53SMasayuki Ohtak p + PCH_PHUB_COMP_RESP_TIMEOUT_REG); 230cf4ece53SMasayuki Ohtak iowrite32(chip->bus_slave_control_reg, 231cf4ece53SMasayuki Ohtak p + PCH_PHUB_BUS_SLAVE_CONTROL_REG); 232cf4ece53SMasayuki Ohtak iowrite32(chip->deadlock_avoid_type_reg, 233cf4ece53SMasayuki Ohtak p + PCH_PHUB_DEADLOCK_AVOID_TYPE_REG); 234cf4ece53SMasayuki Ohtak iowrite32(chip->intpin_reg_wpermit_reg0, 235cf4ece53SMasayuki Ohtak p + PCH_PHUB_INTPIN_REG_WPERMIT_REG0); 236cf4ece53SMasayuki Ohtak iowrite32(chip->intpin_reg_wpermit_reg1, 237cf4ece53SMasayuki Ohtak p + PCH_PHUB_INTPIN_REG_WPERMIT_REG1); 238cf4ece53SMasayuki Ohtak iowrite32(chip->intpin_reg_wpermit_reg2, 239cf4ece53SMasayuki Ohtak p + PCH_PHUB_INTPIN_REG_WPERMIT_REG2); 240cf4ece53SMasayuki Ohtak iowrite32(chip->intpin_reg_wpermit_reg3, 241cf4ece53SMasayuki Ohtak p + PCH_PHUB_INTPIN_REG_WPERMIT_REG3); 242cf4ece53SMasayuki Ohtak dev_dbg(&pdev->dev, "%s : " 243cf4ece53SMasayuki Ohtak "chip->phub_id_reg=%x, " 244cf4ece53SMasayuki Ohtak "chip->q_pri_val_reg=%x, " 245cf4ece53SMasayuki Ohtak "chip->rc_q_maxsize_reg=%x, " 246cf4ece53SMasayuki Ohtak "chip->bri_q_maxsize_reg=%x, " 247cf4ece53SMasayuki Ohtak "chip->comp_resp_timeout_reg=%x, " 248cf4ece53SMasayuki Ohtak "chip->bus_slave_control_reg=%x, " 249cf4ece53SMasayuki Ohtak "chip->deadlock_avoid_type_reg=%x, " 250cf4ece53SMasayuki Ohtak "chip->intpin_reg_wpermit_reg0=%x, " 251cf4ece53SMasayuki Ohtak "chip->intpin_reg_wpermit_reg1=%x, " 252cf4ece53SMasayuki Ohtak "chip->intpin_reg_wpermit_reg2=%x, " 253cf4ece53SMasayuki Ohtak "chip->intpin_reg_wpermit_reg3=%x\n", __func__, 254cf4ece53SMasayuki Ohtak chip->phub_id_reg, 255cf4ece53SMasayuki Ohtak chip->q_pri_val_reg, 256cf4ece53SMasayuki Ohtak chip->rc_q_maxsize_reg, 257cf4ece53SMasayuki Ohtak chip->bri_q_maxsize_reg, 258cf4ece53SMasayuki Ohtak chip->comp_resp_timeout_reg, 259cf4ece53SMasayuki Ohtak chip->bus_slave_control_reg, 260cf4ece53SMasayuki Ohtak chip->deadlock_avoid_type_reg, 261cf4ece53SMasayuki Ohtak chip->intpin_reg_wpermit_reg0, 262cf4ece53SMasayuki Ohtak chip->intpin_reg_wpermit_reg1, 263cf4ece53SMasayuki Ohtak chip->intpin_reg_wpermit_reg2, 264cf4ece53SMasayuki Ohtak chip->intpin_reg_wpermit_reg3); 265cf4ece53SMasayuki Ohtak for (i = 0; i < MAX_NUM_INT_REDUCE_CONTROL_REG; i++) { 266cf4ece53SMasayuki Ohtak iowrite32(chip->int_reduce_control_reg[i], 267cf4ece53SMasayuki Ohtak p + PCH_PHUB_INT_REDUCE_CONTROL_REG_BASE + 4 * i); 268cf4ece53SMasayuki Ohtak dev_dbg(&pdev->dev, "%s : " 269cf4ece53SMasayuki Ohtak "chip->int_reduce_control_reg[%d]=%x\n", 270cf4ece53SMasayuki Ohtak __func__, i, chip->int_reduce_control_reg[i]); 271cf4ece53SMasayuki Ohtak } 272cf4ece53SMasayuki Ohtak 273cf4ece53SMasayuki Ohtak iowrite32(chip->clkcfg_reg, p + CLKCFG_REG_OFFSET); 274cf4ece53SMasayuki Ohtak } 275cf4ece53SMasayuki Ohtak 276cf4ece53SMasayuki Ohtak /** 277cf4ece53SMasayuki Ohtak * pch_phub_read_serial_rom() - Reading Serial ROM 278cf4ece53SMasayuki Ohtak * @offset_address: Serial ROM offset address to read. 279cf4ece53SMasayuki Ohtak * @data: Read buffer for specified Serial ROM value. 280cf4ece53SMasayuki Ohtak */ 281cf4ece53SMasayuki Ohtak static void pch_phub_read_serial_rom(struct pch_phub_reg *chip, 282cf4ece53SMasayuki Ohtak unsigned int offset_address, u8 *data) 283cf4ece53SMasayuki Ohtak { 284cf4ece53SMasayuki Ohtak void __iomem *mem_addr = chip->pch_phub_extrom_base_address + 285cf4ece53SMasayuki Ohtak offset_address; 286cf4ece53SMasayuki Ohtak 287cf4ece53SMasayuki Ohtak *data = ioread8(mem_addr); 288cf4ece53SMasayuki Ohtak } 289cf4ece53SMasayuki Ohtak 290cf4ece53SMasayuki Ohtak /** 291cf4ece53SMasayuki Ohtak * pch_phub_write_serial_rom() - Writing Serial ROM 292cf4ece53SMasayuki Ohtak * @offset_address: Serial ROM offset address. 293cf4ece53SMasayuki Ohtak * @data: Serial ROM value to write. 294cf4ece53SMasayuki Ohtak */ 295cf4ece53SMasayuki Ohtak static int pch_phub_write_serial_rom(struct pch_phub_reg *chip, 296cf4ece53SMasayuki Ohtak unsigned int offset_address, u8 data) 297cf4ece53SMasayuki Ohtak { 298cf4ece53SMasayuki Ohtak void __iomem *mem_addr = chip->pch_phub_extrom_base_address + 299cf4ece53SMasayuki Ohtak (offset_address & PCH_WORD_ADDR_MASK); 300cf4ece53SMasayuki Ohtak int i; 301cf4ece53SMasayuki Ohtak unsigned int word_data; 302cf4ece53SMasayuki Ohtak unsigned int pos; 303cf4ece53SMasayuki Ohtak unsigned int mask; 304cf4ece53SMasayuki Ohtak pos = (offset_address % 4) * 8; 305cf4ece53SMasayuki Ohtak mask = ~(0xFF << pos); 306cf4ece53SMasayuki Ohtak 307cf4ece53SMasayuki Ohtak iowrite32(PCH_PHUB_ROM_WRITE_ENABLE, 308cf4ece53SMasayuki Ohtak chip->pch_phub_extrom_base_address + PHUB_CONTROL); 309cf4ece53SMasayuki Ohtak 310cf4ece53SMasayuki Ohtak word_data = ioread32(mem_addr); 311cf4ece53SMasayuki Ohtak iowrite32((word_data & mask) | (u32)data << pos, mem_addr); 312cf4ece53SMasayuki Ohtak 313cf4ece53SMasayuki Ohtak i = 0; 314cf4ece53SMasayuki Ohtak while (ioread8(chip->pch_phub_extrom_base_address + 315cf4ece53SMasayuki Ohtak PHUB_STATUS) != 0x00) { 316cf4ece53SMasayuki Ohtak msleep(1); 317cf4ece53SMasayuki Ohtak if (i == PHUB_TIMEOUT) 318cf4ece53SMasayuki Ohtak return -ETIMEDOUT; 319cf4ece53SMasayuki Ohtak i++; 320cf4ece53SMasayuki Ohtak } 321cf4ece53SMasayuki Ohtak 322cf4ece53SMasayuki Ohtak iowrite32(PCH_PHUB_ROM_WRITE_DISABLE, 323cf4ece53SMasayuki Ohtak chip->pch_phub_extrom_base_address + PHUB_CONTROL); 324cf4ece53SMasayuki Ohtak 325cf4ece53SMasayuki Ohtak return 0; 326cf4ece53SMasayuki Ohtak } 327cf4ece53SMasayuki Ohtak 328cf4ece53SMasayuki Ohtak /** 329cf4ece53SMasayuki Ohtak * pch_phub_read_serial_rom_val() - Read Serial ROM value 330cf4ece53SMasayuki Ohtak * @offset_address: Serial ROM address offset value. 331cf4ece53SMasayuki Ohtak * @data: Serial ROM value to read. 332cf4ece53SMasayuki Ohtak */ 333cf4ece53SMasayuki Ohtak static void pch_phub_read_serial_rom_val(struct pch_phub_reg *chip, 334cf4ece53SMasayuki Ohtak unsigned int offset_address, u8 *data) 335cf4ece53SMasayuki Ohtak { 336cf4ece53SMasayuki Ohtak unsigned int mem_addr; 337cf4ece53SMasayuki Ohtak 338275640b0STomoya MORINAGA mem_addr = chip->pch_mac_start_address + 339cf4ece53SMasayuki Ohtak pch_phub_mac_offset[offset_address]; 340cf4ece53SMasayuki Ohtak 341cf4ece53SMasayuki Ohtak pch_phub_read_serial_rom(chip, mem_addr, data); 342cf4ece53SMasayuki Ohtak } 343cf4ece53SMasayuki Ohtak 344cf4ece53SMasayuki Ohtak /** 345cf4ece53SMasayuki Ohtak * pch_phub_write_serial_rom_val() - writing Serial ROM value 346cf4ece53SMasayuki Ohtak * @offset_address: Serial ROM address offset value. 347cf4ece53SMasayuki Ohtak * @data: Serial ROM value. 348cf4ece53SMasayuki Ohtak */ 349cf4ece53SMasayuki Ohtak static int pch_phub_write_serial_rom_val(struct pch_phub_reg *chip, 350cf4ece53SMasayuki Ohtak unsigned int offset_address, u8 data) 351cf4ece53SMasayuki Ohtak { 352cf4ece53SMasayuki Ohtak int retval; 353cf4ece53SMasayuki Ohtak unsigned int mem_addr; 354cf4ece53SMasayuki Ohtak 355275640b0STomoya MORINAGA mem_addr = chip->pch_mac_start_address + 356cf4ece53SMasayuki Ohtak pch_phub_mac_offset[offset_address]; 357cf4ece53SMasayuki Ohtak 358cf4ece53SMasayuki Ohtak retval = pch_phub_write_serial_rom(chip, mem_addr, data); 359cf4ece53SMasayuki Ohtak 360cf4ece53SMasayuki Ohtak return retval; 361cf4ece53SMasayuki Ohtak } 362cf4ece53SMasayuki Ohtak 363cf4ece53SMasayuki Ohtak /* pch_phub_gbe_serial_rom_conf - makes Serial ROM header format configuration 364cf4ece53SMasayuki Ohtak * for Gigabit Ethernet MAC address 365cf4ece53SMasayuki Ohtak */ 366cf4ece53SMasayuki Ohtak static int pch_phub_gbe_serial_rom_conf(struct pch_phub_reg *chip) 367cf4ece53SMasayuki Ohtak { 368cf4ece53SMasayuki Ohtak int retval; 369cf4ece53SMasayuki Ohtak 370cf4ece53SMasayuki Ohtak retval = pch_phub_write_serial_rom(chip, 0x0b, 0xbc); 371cf4ece53SMasayuki Ohtak retval |= pch_phub_write_serial_rom(chip, 0x0a, 0x10); 372cf4ece53SMasayuki Ohtak retval |= pch_phub_write_serial_rom(chip, 0x09, 0x01); 373cf4ece53SMasayuki Ohtak retval |= pch_phub_write_serial_rom(chip, 0x08, 0x02); 374cf4ece53SMasayuki Ohtak 375cf4ece53SMasayuki Ohtak retval |= pch_phub_write_serial_rom(chip, 0x0f, 0x00); 376cf4ece53SMasayuki Ohtak retval |= pch_phub_write_serial_rom(chip, 0x0e, 0x00); 377cf4ece53SMasayuki Ohtak retval |= pch_phub_write_serial_rom(chip, 0x0d, 0x00); 378cf4ece53SMasayuki Ohtak retval |= pch_phub_write_serial_rom(chip, 0x0c, 0x80); 379cf4ece53SMasayuki Ohtak 380cf4ece53SMasayuki Ohtak retval |= pch_phub_write_serial_rom(chip, 0x13, 0xbc); 381cf4ece53SMasayuki Ohtak retval |= pch_phub_write_serial_rom(chip, 0x12, 0x10); 382cf4ece53SMasayuki Ohtak retval |= pch_phub_write_serial_rom(chip, 0x11, 0x01); 383cf4ece53SMasayuki Ohtak retval |= pch_phub_write_serial_rom(chip, 0x10, 0x18); 384cf4ece53SMasayuki Ohtak 385cf4ece53SMasayuki Ohtak retval |= pch_phub_write_serial_rom(chip, 0x1b, 0xbc); 386cf4ece53SMasayuki Ohtak retval |= pch_phub_write_serial_rom(chip, 0x1a, 0x10); 387cf4ece53SMasayuki Ohtak retval |= pch_phub_write_serial_rom(chip, 0x19, 0x01); 388cf4ece53SMasayuki Ohtak retval |= pch_phub_write_serial_rom(chip, 0x18, 0x19); 389cf4ece53SMasayuki Ohtak 390cf4ece53SMasayuki Ohtak retval |= pch_phub_write_serial_rom(chip, 0x23, 0xbc); 391cf4ece53SMasayuki Ohtak retval |= pch_phub_write_serial_rom(chip, 0x22, 0x10); 392cf4ece53SMasayuki Ohtak retval |= pch_phub_write_serial_rom(chip, 0x21, 0x01); 393cf4ece53SMasayuki Ohtak retval |= pch_phub_write_serial_rom(chip, 0x20, 0x3a); 394cf4ece53SMasayuki Ohtak 395cf4ece53SMasayuki Ohtak retval |= pch_phub_write_serial_rom(chip, 0x27, 0x01); 396cf4ece53SMasayuki Ohtak retval |= pch_phub_write_serial_rom(chip, 0x26, 0x00); 397cf4ece53SMasayuki Ohtak retval |= pch_phub_write_serial_rom(chip, 0x25, 0x00); 398cf4ece53SMasayuki Ohtak retval |= pch_phub_write_serial_rom(chip, 0x24, 0x00); 399cf4ece53SMasayuki Ohtak 400cf4ece53SMasayuki Ohtak return retval; 401cf4ece53SMasayuki Ohtak } 402cf4ece53SMasayuki Ohtak 403275640b0STomoya MORINAGA /* pch_phub_gbe_serial_rom_conf_mp - makes SerialROM header format configuration 404275640b0STomoya MORINAGA * for Gigabit Ethernet MAC address 405275640b0STomoya MORINAGA */ 406275640b0STomoya MORINAGA static int pch_phub_gbe_serial_rom_conf_mp(struct pch_phub_reg *chip) 407275640b0STomoya MORINAGA { 408275640b0STomoya MORINAGA int retval; 409275640b0STomoya MORINAGA u32 offset_addr; 410275640b0STomoya MORINAGA 411275640b0STomoya MORINAGA offset_addr = 0x200; 412275640b0STomoya MORINAGA retval = pch_phub_write_serial_rom(chip, 0x03 + offset_addr, 0xbc); 413275640b0STomoya MORINAGA retval |= pch_phub_write_serial_rom(chip, 0x02 + offset_addr, 0x00); 414275640b0STomoya MORINAGA retval |= pch_phub_write_serial_rom(chip, 0x01 + offset_addr, 0x40); 415275640b0STomoya MORINAGA retval |= pch_phub_write_serial_rom(chip, 0x00 + offset_addr, 0x02); 416275640b0STomoya MORINAGA 417275640b0STomoya MORINAGA retval |= pch_phub_write_serial_rom(chip, 0x07 + offset_addr, 0x00); 418275640b0STomoya MORINAGA retval |= pch_phub_write_serial_rom(chip, 0x06 + offset_addr, 0x00); 419275640b0STomoya MORINAGA retval |= pch_phub_write_serial_rom(chip, 0x05 + offset_addr, 0x00); 420275640b0STomoya MORINAGA retval |= pch_phub_write_serial_rom(chip, 0x04 + offset_addr, 0x80); 421275640b0STomoya MORINAGA 422275640b0STomoya MORINAGA retval |= pch_phub_write_serial_rom(chip, 0x0b + offset_addr, 0xbc); 423275640b0STomoya MORINAGA retval |= pch_phub_write_serial_rom(chip, 0x0a + offset_addr, 0x00); 424275640b0STomoya MORINAGA retval |= pch_phub_write_serial_rom(chip, 0x09 + offset_addr, 0x40); 425275640b0STomoya MORINAGA retval |= pch_phub_write_serial_rom(chip, 0x08 + offset_addr, 0x18); 426275640b0STomoya MORINAGA 427275640b0STomoya MORINAGA retval |= pch_phub_write_serial_rom(chip, 0x13 + offset_addr, 0xbc); 428275640b0STomoya MORINAGA retval |= pch_phub_write_serial_rom(chip, 0x12 + offset_addr, 0x00); 429275640b0STomoya MORINAGA retval |= pch_phub_write_serial_rom(chip, 0x11 + offset_addr, 0x40); 430275640b0STomoya MORINAGA retval |= pch_phub_write_serial_rom(chip, 0x10 + offset_addr, 0x19); 431275640b0STomoya MORINAGA 432275640b0STomoya MORINAGA retval |= pch_phub_write_serial_rom(chip, 0x1b + offset_addr, 0xbc); 433275640b0STomoya MORINAGA retval |= pch_phub_write_serial_rom(chip, 0x1a + offset_addr, 0x00); 434275640b0STomoya MORINAGA retval |= pch_phub_write_serial_rom(chip, 0x19 + offset_addr, 0x40); 435275640b0STomoya MORINAGA retval |= pch_phub_write_serial_rom(chip, 0x18 + offset_addr, 0x3a); 436275640b0STomoya MORINAGA 437275640b0STomoya MORINAGA retval |= pch_phub_write_serial_rom(chip, 0x1f + offset_addr, 0x01); 438275640b0STomoya MORINAGA retval |= pch_phub_write_serial_rom(chip, 0x1e + offset_addr, 0x00); 439275640b0STomoya MORINAGA retval |= pch_phub_write_serial_rom(chip, 0x1d + offset_addr, 0x00); 440275640b0STomoya MORINAGA retval |= pch_phub_write_serial_rom(chip, 0x1c + offset_addr, 0x00); 441275640b0STomoya MORINAGA 442275640b0STomoya MORINAGA return retval; 443275640b0STomoya MORINAGA } 444275640b0STomoya MORINAGA 445cf4ece53SMasayuki Ohtak /** 446cf4ece53SMasayuki Ohtak * pch_phub_read_gbe_mac_addr() - Read Gigabit Ethernet MAC address 447cf4ece53SMasayuki Ohtak * @offset_address: Gigabit Ethernet MAC address offset value. 448cf4ece53SMasayuki Ohtak * @data: Buffer of the Gigabit Ethernet MAC address value. 449cf4ece53SMasayuki Ohtak */ 450cf4ece53SMasayuki Ohtak static void pch_phub_read_gbe_mac_addr(struct pch_phub_reg *chip, u8 *data) 451cf4ece53SMasayuki Ohtak { 452cf4ece53SMasayuki Ohtak int i; 453cf4ece53SMasayuki Ohtak for (i = 0; i < ETH_ALEN; i++) 454cf4ece53SMasayuki Ohtak pch_phub_read_serial_rom_val(chip, i, &data[i]); 455cf4ece53SMasayuki Ohtak } 456cf4ece53SMasayuki Ohtak 457cf4ece53SMasayuki Ohtak /** 458cf4ece53SMasayuki Ohtak * pch_phub_write_gbe_mac_addr() - Write MAC address 459cf4ece53SMasayuki Ohtak * @offset_address: Gigabit Ethernet MAC address offset value. 460cf4ece53SMasayuki Ohtak * @data: Gigabit Ethernet MAC address value. 461cf4ece53SMasayuki Ohtak */ 462cf4ece53SMasayuki Ohtak static int pch_phub_write_gbe_mac_addr(struct pch_phub_reg *chip, u8 *data) 463cf4ece53SMasayuki Ohtak { 464cf4ece53SMasayuki Ohtak int retval; 465cf4ece53SMasayuki Ohtak int i; 466cf4ece53SMasayuki Ohtak 467275640b0STomoya MORINAGA if (chip->ioh_type == 1) /* EG20T */ 468cf4ece53SMasayuki Ohtak retval = pch_phub_gbe_serial_rom_conf(chip); 469275640b0STomoya MORINAGA else /* ML7223 */ 470275640b0STomoya MORINAGA retval = pch_phub_gbe_serial_rom_conf_mp(chip); 471cf4ece53SMasayuki Ohtak if (retval) 472cf4ece53SMasayuki Ohtak return retval; 473cf4ece53SMasayuki Ohtak 474cf4ece53SMasayuki Ohtak for (i = 0; i < ETH_ALEN; i++) { 475cf4ece53SMasayuki Ohtak retval = pch_phub_write_serial_rom_val(chip, i, data[i]); 476cf4ece53SMasayuki Ohtak if (retval) 477cf4ece53SMasayuki Ohtak return retval; 478cf4ece53SMasayuki Ohtak } 479cf4ece53SMasayuki Ohtak 480cf4ece53SMasayuki Ohtak return retval; 481cf4ece53SMasayuki Ohtak } 482cf4ece53SMasayuki Ohtak 483cf4ece53SMasayuki Ohtak static ssize_t pch_phub_bin_read(struct file *filp, struct kobject *kobj, 484cf4ece53SMasayuki Ohtak struct bin_attribute *attr, char *buf, 485cf4ece53SMasayuki Ohtak loff_t off, size_t count) 486cf4ece53SMasayuki Ohtak { 487cf4ece53SMasayuki Ohtak unsigned int rom_signature; 488cf4ece53SMasayuki Ohtak unsigned char rom_length; 489cf4ece53SMasayuki Ohtak unsigned int tmp; 490cf4ece53SMasayuki Ohtak unsigned int addr_offset; 491cf4ece53SMasayuki Ohtak unsigned int orom_size; 492cf4ece53SMasayuki Ohtak int ret; 493cf4ece53SMasayuki Ohtak int err; 494cf4ece53SMasayuki Ohtak 495cf4ece53SMasayuki Ohtak struct pch_phub_reg *chip = 496cf4ece53SMasayuki Ohtak dev_get_drvdata(container_of(kobj, struct device, kobj)); 497cf4ece53SMasayuki Ohtak 498cf4ece53SMasayuki Ohtak ret = mutex_lock_interruptible(&pch_phub_mutex); 499cf4ece53SMasayuki Ohtak if (ret) { 500cf4ece53SMasayuki Ohtak err = -ERESTARTSYS; 501cf4ece53SMasayuki Ohtak goto return_err_nomutex; 502cf4ece53SMasayuki Ohtak } 503cf4ece53SMasayuki Ohtak 504cf4ece53SMasayuki Ohtak /* Get Rom signature */ 505275640b0STomoya MORINAGA pch_phub_read_serial_rom(chip, chip->pch_opt_rom_start_address, 506275640b0STomoya MORINAGA (unsigned char *)&rom_signature); 507cf4ece53SMasayuki Ohtak rom_signature &= 0xff; 508275640b0STomoya MORINAGA pch_phub_read_serial_rom(chip, chip->pch_opt_rom_start_address + 1, 509275640b0STomoya MORINAGA (unsigned char *)&tmp); 510cf4ece53SMasayuki Ohtak rom_signature |= (tmp & 0xff) << 8; 511cf4ece53SMasayuki Ohtak if (rom_signature == 0xAA55) { 512275640b0STomoya MORINAGA pch_phub_read_serial_rom(chip, 513275640b0STomoya MORINAGA chip->pch_opt_rom_start_address + 2, 514275640b0STomoya MORINAGA &rom_length); 515cf4ece53SMasayuki Ohtak orom_size = rom_length * 512; 516cf4ece53SMasayuki Ohtak if (orom_size < off) { 517cf4ece53SMasayuki Ohtak addr_offset = 0; 518cf4ece53SMasayuki Ohtak goto return_ok; 519cf4ece53SMasayuki Ohtak } 520cf4ece53SMasayuki Ohtak if (orom_size < count) { 521cf4ece53SMasayuki Ohtak addr_offset = 0; 522cf4ece53SMasayuki Ohtak goto return_ok; 523cf4ece53SMasayuki Ohtak } 524cf4ece53SMasayuki Ohtak 525cf4ece53SMasayuki Ohtak for (addr_offset = 0; addr_offset < count; addr_offset++) { 526275640b0STomoya MORINAGA pch_phub_read_serial_rom(chip, 527275640b0STomoya MORINAGA chip->pch_opt_rom_start_address + addr_offset + off, 528cf4ece53SMasayuki Ohtak &buf[addr_offset]); 529cf4ece53SMasayuki Ohtak } 530cf4ece53SMasayuki Ohtak } else { 531cf4ece53SMasayuki Ohtak err = -ENODATA; 532cf4ece53SMasayuki Ohtak goto return_err; 533cf4ece53SMasayuki Ohtak } 534cf4ece53SMasayuki Ohtak return_ok: 535cf4ece53SMasayuki Ohtak mutex_unlock(&pch_phub_mutex); 536cf4ece53SMasayuki Ohtak return addr_offset; 537cf4ece53SMasayuki Ohtak 538cf4ece53SMasayuki Ohtak return_err: 539cf4ece53SMasayuki Ohtak mutex_unlock(&pch_phub_mutex); 540cf4ece53SMasayuki Ohtak return_err_nomutex: 541cf4ece53SMasayuki Ohtak return err; 542cf4ece53SMasayuki Ohtak } 543cf4ece53SMasayuki Ohtak 544cf4ece53SMasayuki Ohtak static ssize_t pch_phub_bin_write(struct file *filp, struct kobject *kobj, 545cf4ece53SMasayuki Ohtak struct bin_attribute *attr, 546cf4ece53SMasayuki Ohtak char *buf, loff_t off, size_t count) 547cf4ece53SMasayuki Ohtak { 548cf4ece53SMasayuki Ohtak int err; 549cf4ece53SMasayuki Ohtak unsigned int addr_offset; 550cf4ece53SMasayuki Ohtak int ret; 551cf4ece53SMasayuki Ohtak struct pch_phub_reg *chip = 552cf4ece53SMasayuki Ohtak dev_get_drvdata(container_of(kobj, struct device, kobj)); 553cf4ece53SMasayuki Ohtak 554cf4ece53SMasayuki Ohtak ret = mutex_lock_interruptible(&pch_phub_mutex); 555cf4ece53SMasayuki Ohtak if (ret) 556cf4ece53SMasayuki Ohtak return -ERESTARTSYS; 557cf4ece53SMasayuki Ohtak 558cf4ece53SMasayuki Ohtak if (off > PCH_PHUB_OROM_SIZE) { 559cf4ece53SMasayuki Ohtak addr_offset = 0; 560cf4ece53SMasayuki Ohtak goto return_ok; 561cf4ece53SMasayuki Ohtak } 562cf4ece53SMasayuki Ohtak if (count > PCH_PHUB_OROM_SIZE) { 563cf4ece53SMasayuki Ohtak addr_offset = 0; 564cf4ece53SMasayuki Ohtak goto return_ok; 565cf4ece53SMasayuki Ohtak } 566cf4ece53SMasayuki Ohtak 567cf4ece53SMasayuki Ohtak for (addr_offset = 0; addr_offset < count; addr_offset++) { 568cf4ece53SMasayuki Ohtak if (PCH_PHUB_OROM_SIZE < off + addr_offset) 569cf4ece53SMasayuki Ohtak goto return_ok; 570cf4ece53SMasayuki Ohtak 571275640b0STomoya MORINAGA ret = pch_phub_write_serial_rom(chip, 572275640b0STomoya MORINAGA chip->pch_opt_rom_start_address + addr_offset + off, 573cf4ece53SMasayuki Ohtak buf[addr_offset]); 574cf4ece53SMasayuki Ohtak if (ret) { 575cf4ece53SMasayuki Ohtak err = ret; 576cf4ece53SMasayuki Ohtak goto return_err; 577cf4ece53SMasayuki Ohtak } 578cf4ece53SMasayuki Ohtak } 579cf4ece53SMasayuki Ohtak 580cf4ece53SMasayuki Ohtak return_ok: 581cf4ece53SMasayuki Ohtak mutex_unlock(&pch_phub_mutex); 582cf4ece53SMasayuki Ohtak return addr_offset; 583cf4ece53SMasayuki Ohtak 584cf4ece53SMasayuki Ohtak return_err: 585cf4ece53SMasayuki Ohtak mutex_unlock(&pch_phub_mutex); 586cf4ece53SMasayuki Ohtak return err; 587cf4ece53SMasayuki Ohtak } 588cf4ece53SMasayuki Ohtak 589cf4ece53SMasayuki Ohtak static ssize_t show_pch_mac(struct device *dev, struct device_attribute *attr, 590cf4ece53SMasayuki Ohtak char *buf) 591cf4ece53SMasayuki Ohtak { 592cf4ece53SMasayuki Ohtak u8 mac[8]; 593cf4ece53SMasayuki Ohtak struct pch_phub_reg *chip = dev_get_drvdata(dev); 594cf4ece53SMasayuki Ohtak 595cf4ece53SMasayuki Ohtak pch_phub_read_gbe_mac_addr(chip, mac); 596cf4ece53SMasayuki Ohtak 597cf4ece53SMasayuki Ohtak return sprintf(buf, "%02x:%02x:%02x:%02x:%02x:%02x\n", 598cf4ece53SMasayuki Ohtak mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); 599cf4ece53SMasayuki Ohtak } 600cf4ece53SMasayuki Ohtak 601cf4ece53SMasayuki Ohtak static ssize_t store_pch_mac(struct device *dev, struct device_attribute *attr, 602cf4ece53SMasayuki Ohtak const char *buf, size_t count) 603cf4ece53SMasayuki Ohtak { 604cf4ece53SMasayuki Ohtak u8 mac[6]; 605cf4ece53SMasayuki Ohtak struct pch_phub_reg *chip = dev_get_drvdata(dev); 606cf4ece53SMasayuki Ohtak 607cf4ece53SMasayuki Ohtak if (count != 18) 608cf4ece53SMasayuki Ohtak return -EINVAL; 609cf4ece53SMasayuki Ohtak 610cf4ece53SMasayuki Ohtak sscanf(buf, "%02x:%02x:%02x:%02x:%02x:%02x", 611cf4ece53SMasayuki Ohtak (u32 *)&mac[0], (u32 *)&mac[1], (u32 *)&mac[2], (u32 *)&mac[3], 612cf4ece53SMasayuki Ohtak (u32 *)&mac[4], (u32 *)&mac[5]); 613cf4ece53SMasayuki Ohtak 614cf4ece53SMasayuki Ohtak pch_phub_write_gbe_mac_addr(chip, mac); 615cf4ece53SMasayuki Ohtak 616cf4ece53SMasayuki Ohtak return count; 617cf4ece53SMasayuki Ohtak } 618cf4ece53SMasayuki Ohtak 619cf4ece53SMasayuki Ohtak static DEVICE_ATTR(pch_mac, S_IRUGO | S_IWUSR, show_pch_mac, store_pch_mac); 620cf4ece53SMasayuki Ohtak 621cf4ece53SMasayuki Ohtak static struct bin_attribute pch_bin_attr = { 622cf4ece53SMasayuki Ohtak .attr = { 623cf4ece53SMasayuki Ohtak .name = "pch_firmware", 624cf4ece53SMasayuki Ohtak .mode = S_IRUGO | S_IWUSR, 625cf4ece53SMasayuki Ohtak }, 626cf4ece53SMasayuki Ohtak .size = PCH_PHUB_OROM_SIZE + 1, 627cf4ece53SMasayuki Ohtak .read = pch_phub_bin_read, 628cf4ece53SMasayuki Ohtak .write = pch_phub_bin_write, 629cf4ece53SMasayuki Ohtak }; 630cf4ece53SMasayuki Ohtak 631cf4ece53SMasayuki Ohtak static int __devinit pch_phub_probe(struct pci_dev *pdev, 632cf4ece53SMasayuki Ohtak const struct pci_device_id *id) 633cf4ece53SMasayuki Ohtak { 634cf4ece53SMasayuki Ohtak int retval; 635cf4ece53SMasayuki Ohtak 636cf4ece53SMasayuki Ohtak int ret; 637da0d7f98SGreg Kroah-Hartman ssize_t rom_size; 638cf4ece53SMasayuki Ohtak struct pch_phub_reg *chip; 639cf4ece53SMasayuki Ohtak 640cf4ece53SMasayuki Ohtak chip = kzalloc(sizeof(struct pch_phub_reg), GFP_KERNEL); 641cf4ece53SMasayuki Ohtak if (chip == NULL) 642cf4ece53SMasayuki Ohtak return -ENOMEM; 643cf4ece53SMasayuki Ohtak 644cf4ece53SMasayuki Ohtak ret = pci_enable_device(pdev); 645cf4ece53SMasayuki Ohtak if (ret) { 646cf4ece53SMasayuki Ohtak dev_err(&pdev->dev, 647cf4ece53SMasayuki Ohtak "%s : pci_enable_device FAILED(ret=%d)", __func__, ret); 648cf4ece53SMasayuki Ohtak goto err_pci_enable_dev; 649cf4ece53SMasayuki Ohtak } 650cf4ece53SMasayuki Ohtak dev_dbg(&pdev->dev, "%s : pci_enable_device returns %d\n", __func__, 651cf4ece53SMasayuki Ohtak ret); 652cf4ece53SMasayuki Ohtak 653cf4ece53SMasayuki Ohtak ret = pci_request_regions(pdev, KBUILD_MODNAME); 654cf4ece53SMasayuki Ohtak if (ret) { 655cf4ece53SMasayuki Ohtak dev_err(&pdev->dev, 656cf4ece53SMasayuki Ohtak "%s : pci_request_regions FAILED(ret=%d)", __func__, ret); 657cf4ece53SMasayuki Ohtak goto err_req_regions; 658cf4ece53SMasayuki Ohtak } 659cf4ece53SMasayuki Ohtak dev_dbg(&pdev->dev, "%s : " 660cf4ece53SMasayuki Ohtak "pci_request_regions returns %d\n", __func__, ret); 661cf4ece53SMasayuki Ohtak 662cf4ece53SMasayuki Ohtak chip->pch_phub_base_address = pci_iomap(pdev, 1, 0); 663cf4ece53SMasayuki Ohtak 664cf4ece53SMasayuki Ohtak 665cf4ece53SMasayuki Ohtak if (chip->pch_phub_base_address == 0) { 666cf4ece53SMasayuki Ohtak dev_err(&pdev->dev, "%s : pci_iomap FAILED", __func__); 667cf4ece53SMasayuki Ohtak ret = -ENOMEM; 668cf4ece53SMasayuki Ohtak goto err_pci_iomap; 669cf4ece53SMasayuki Ohtak } 670cf4ece53SMasayuki Ohtak dev_dbg(&pdev->dev, "%s : pci_iomap SUCCESS and value " 671da0d7f98SGreg Kroah-Hartman "in pch_phub_base_address variable is %p\n", __func__, 672da0d7f98SGreg Kroah-Hartman chip->pch_phub_base_address); 673cf4ece53SMasayuki Ohtak 674275640b0STomoya MORINAGA if (id->driver_data != 3) { 675275640b0STomoya MORINAGA chip->pch_phub_extrom_base_address =\ 676275640b0STomoya MORINAGA pci_map_rom(pdev, &rom_size); 677cf4ece53SMasayuki Ohtak if (chip->pch_phub_extrom_base_address == 0) { 678cf4ece53SMasayuki Ohtak dev_err(&pdev->dev, "%s: pci_map_rom FAILED", __func__); 679cf4ece53SMasayuki Ohtak ret = -ENOMEM; 680cf4ece53SMasayuki Ohtak goto err_pci_map; 681cf4ece53SMasayuki Ohtak } 682cf4ece53SMasayuki Ohtak dev_dbg(&pdev->dev, "%s : " 683cf4ece53SMasayuki Ohtak "pci_map_rom SUCCESS and value in " 684275640b0STomoya MORINAGA "pch_phub_extrom_base_address variable is %p\n", 685275640b0STomoya MORINAGA __func__, chip->pch_phub_extrom_base_address); 686275640b0STomoya MORINAGA } 687cf4ece53SMasayuki Ohtak 688275640b0STomoya MORINAGA if (id->driver_data == 1) { /* EG20T PCH */ 689*2b934c62SAlexander Stein const char *board_name; 690*2b934c62SAlexander Stein 691c47dda7dSTomoya MORINAGA retval = sysfs_create_file(&pdev->dev.kobj, 692c47dda7dSTomoya MORINAGA &dev_attr_pch_mac.attr); 693cf4ece53SMasayuki Ohtak if (retval) 694cf4ece53SMasayuki Ohtak goto err_sysfs_create; 695cf4ece53SMasayuki Ohtak 696cf4ece53SMasayuki Ohtak retval = sysfs_create_bin_file(&pdev->dev.kobj, &pch_bin_attr); 697cf4ece53SMasayuki Ohtak if (retval) 698cf4ece53SMasayuki Ohtak goto exit_bin_attr; 699cf4ece53SMasayuki Ohtak 700c47dda7dSTomoya MORINAGA pch_phub_read_modify_write_reg(chip, 701c47dda7dSTomoya MORINAGA (unsigned int)CLKCFG_REG_OFFSET, 702c47dda7dSTomoya MORINAGA CLKCFG_CAN_50MHZ, 703c47dda7dSTomoya MORINAGA CLKCFG_CANCLK_MASK); 704cf4ece53SMasayuki Ohtak 7056ae705b2SDenis Turischev /* quirk for CM-iTC board */ 706*2b934c62SAlexander Stein board_name = dmi_get_system_info(DMI_BOARD_NAME); 707*2b934c62SAlexander Stein if (board_name && strstr(board_name, "CM-iTC")) 7086ae705b2SDenis Turischev pch_phub_read_modify_write_reg(chip, 7096ae705b2SDenis Turischev (unsigned int)CLKCFG_REG_OFFSET, 7106ae705b2SDenis Turischev CLKCFG_UART_48MHZ | CLKCFG_BAUDDIV | 7116ae705b2SDenis Turischev CLKCFG_PLL2VCO | CLKCFG_UARTCLKSEL, 7126ae705b2SDenis Turischev CLKCFG_UART_MASK); 7136ae705b2SDenis Turischev 714cf4ece53SMasayuki Ohtak /* set the prefech value */ 715cf4ece53SMasayuki Ohtak iowrite32(0x000affaa, chip->pch_phub_base_address + 0x14); 716cf4ece53SMasayuki Ohtak /* set the interrupt delay value */ 717cf4ece53SMasayuki Ohtak iowrite32(0x25, chip->pch_phub_base_address + 0x44); 718275640b0STomoya MORINAGA chip->pch_opt_rom_start_address = PCH_PHUB_ROM_START_ADDR_EG20T; 719275640b0STomoya MORINAGA chip->pch_mac_start_address = PCH_PHUB_MAC_START_ADDR_EG20T; 720275640b0STomoya MORINAGA } else if (id->driver_data == 2) { /* ML7213 IOH */ 721c47dda7dSTomoya MORINAGA retval = sysfs_create_bin_file(&pdev->dev.kobj, &pch_bin_attr); 722c47dda7dSTomoya MORINAGA if (retval) 723c47dda7dSTomoya MORINAGA goto err_sysfs_create; 724c47dda7dSTomoya MORINAGA /* set the prefech value 725c47dda7dSTomoya MORINAGA * Device2(USB OHCI #1/ USB EHCI #1/ USB Device):a 726c47dda7dSTomoya MORINAGA * Device4(SDIO #0,1,2):f 727c47dda7dSTomoya MORINAGA * Device6(SATA 2):f 728c47dda7dSTomoya MORINAGA * Device8(USB OHCI #0/ USB EHCI #0):a 729c47dda7dSTomoya MORINAGA */ 730c47dda7dSTomoya MORINAGA iowrite32(0x000affa0, chip->pch_phub_base_address + 0x14); 731275640b0STomoya MORINAGA chip->pch_opt_rom_start_address =\ 732275640b0STomoya MORINAGA PCH_PHUB_ROM_START_ADDR_ML7213; 733275640b0STomoya MORINAGA } else if (id->driver_data == 3) { /* ML7223 IOH Bus-m*/ 734275640b0STomoya MORINAGA /* set the prefech value 735275640b0STomoya MORINAGA * Device8(GbE) 736275640b0STomoya MORINAGA */ 737275640b0STomoya MORINAGA iowrite32(0x000a0000, chip->pch_phub_base_address + 0x14); 738275640b0STomoya MORINAGA chip->pch_opt_rom_start_address =\ 739275640b0STomoya MORINAGA PCH_PHUB_ROM_START_ADDR_ML7223; 740275640b0STomoya MORINAGA chip->pch_mac_start_address = PCH_PHUB_MAC_START_ADDR_ML7223; 741275640b0STomoya MORINAGA } else if (id->driver_data == 4) { /* ML7223 IOH Bus-n*/ 742275640b0STomoya MORINAGA retval = sysfs_create_file(&pdev->dev.kobj, 743275640b0STomoya MORINAGA &dev_attr_pch_mac.attr); 744275640b0STomoya MORINAGA if (retval) 745275640b0STomoya MORINAGA goto err_sysfs_create; 746275640b0STomoya MORINAGA retval = sysfs_create_bin_file(&pdev->dev.kobj, &pch_bin_attr); 747275640b0STomoya MORINAGA if (retval) 748275640b0STomoya MORINAGA goto exit_bin_attr; 749275640b0STomoya MORINAGA /* set the prefech value 750275640b0STomoya MORINAGA * Device2(USB OHCI #0,1,2,3/ USB EHCI #0):a 751275640b0STomoya MORINAGA * Device4(SDIO #0,1):f 752275640b0STomoya MORINAGA * Device6(SATA 2):f 753275640b0STomoya MORINAGA */ 754275640b0STomoya MORINAGA iowrite32(0x0000ffa0, chip->pch_phub_base_address + 0x14); 755275640b0STomoya MORINAGA /* set the interrupt delay value */ 756275640b0STomoya MORINAGA iowrite32(0x25, chip->pch_phub_base_address + 0x140); 757275640b0STomoya MORINAGA chip->pch_opt_rom_start_address =\ 758275640b0STomoya MORINAGA PCH_PHUB_ROM_START_ADDR_ML7223; 759275640b0STomoya MORINAGA chip->pch_mac_start_address = PCH_PHUB_MAC_START_ADDR_ML7223; 760c47dda7dSTomoya MORINAGA } 761275640b0STomoya MORINAGA 762275640b0STomoya MORINAGA chip->ioh_type = id->driver_data; 763c47dda7dSTomoya MORINAGA pci_set_drvdata(pdev, chip); 764cf4ece53SMasayuki Ohtak 765cf4ece53SMasayuki Ohtak return 0; 766cf4ece53SMasayuki Ohtak exit_bin_attr: 767cf4ece53SMasayuki Ohtak sysfs_remove_file(&pdev->dev.kobj, &dev_attr_pch_mac.attr); 768cf4ece53SMasayuki Ohtak 769cf4ece53SMasayuki Ohtak err_sysfs_create: 770cf4ece53SMasayuki Ohtak pci_unmap_rom(pdev, chip->pch_phub_extrom_base_address); 771cf4ece53SMasayuki Ohtak err_pci_map: 772cf4ece53SMasayuki Ohtak pci_iounmap(pdev, chip->pch_phub_base_address); 773cf4ece53SMasayuki Ohtak err_pci_iomap: 774cf4ece53SMasayuki Ohtak pci_release_regions(pdev); 775cf4ece53SMasayuki Ohtak err_req_regions: 776cf4ece53SMasayuki Ohtak pci_disable_device(pdev); 777cf4ece53SMasayuki Ohtak err_pci_enable_dev: 778cf4ece53SMasayuki Ohtak kfree(chip); 779cf4ece53SMasayuki Ohtak dev_err(&pdev->dev, "%s returns %d\n", __func__, ret); 780cf4ece53SMasayuki Ohtak return ret; 781cf4ece53SMasayuki Ohtak } 782cf4ece53SMasayuki Ohtak 783cf4ece53SMasayuki Ohtak static void __devexit pch_phub_remove(struct pci_dev *pdev) 784cf4ece53SMasayuki Ohtak { 785cf4ece53SMasayuki Ohtak struct pch_phub_reg *chip = pci_get_drvdata(pdev); 786cf4ece53SMasayuki Ohtak 787cf4ece53SMasayuki Ohtak sysfs_remove_file(&pdev->dev.kobj, &dev_attr_pch_mac.attr); 788cf4ece53SMasayuki Ohtak sysfs_remove_bin_file(&pdev->dev.kobj, &pch_bin_attr); 789cf4ece53SMasayuki Ohtak pci_unmap_rom(pdev, chip->pch_phub_extrom_base_address); 790cf4ece53SMasayuki Ohtak pci_iounmap(pdev, chip->pch_phub_base_address); 791cf4ece53SMasayuki Ohtak pci_release_regions(pdev); 792cf4ece53SMasayuki Ohtak pci_disable_device(pdev); 793cf4ece53SMasayuki Ohtak kfree(chip); 794cf4ece53SMasayuki Ohtak } 795cf4ece53SMasayuki Ohtak 796cf4ece53SMasayuki Ohtak #ifdef CONFIG_PM 797cf4ece53SMasayuki Ohtak 798cf4ece53SMasayuki Ohtak static int pch_phub_suspend(struct pci_dev *pdev, pm_message_t state) 799cf4ece53SMasayuki Ohtak { 800cf4ece53SMasayuki Ohtak int ret; 801cf4ece53SMasayuki Ohtak 802cf4ece53SMasayuki Ohtak pch_phub_save_reg_conf(pdev); 803cf4ece53SMasayuki Ohtak ret = pci_save_state(pdev); 804cf4ece53SMasayuki Ohtak if (ret) { 805cf4ece53SMasayuki Ohtak dev_err(&pdev->dev, 806cf4ece53SMasayuki Ohtak " %s -pci_save_state returns %d\n", __func__, ret); 807cf4ece53SMasayuki Ohtak return ret; 808cf4ece53SMasayuki Ohtak } 809cf4ece53SMasayuki Ohtak pci_enable_wake(pdev, PCI_D3hot, 0); 810cf4ece53SMasayuki Ohtak pci_disable_device(pdev); 811cf4ece53SMasayuki Ohtak pci_set_power_state(pdev, pci_choose_state(pdev, state)); 812cf4ece53SMasayuki Ohtak 813cf4ece53SMasayuki Ohtak return 0; 814cf4ece53SMasayuki Ohtak } 815cf4ece53SMasayuki Ohtak 816cf4ece53SMasayuki Ohtak static int pch_phub_resume(struct pci_dev *pdev) 817cf4ece53SMasayuki Ohtak { 818cf4ece53SMasayuki Ohtak int ret; 819cf4ece53SMasayuki Ohtak 820cf4ece53SMasayuki Ohtak pci_set_power_state(pdev, PCI_D0); 821cf4ece53SMasayuki Ohtak pci_restore_state(pdev); 822cf4ece53SMasayuki Ohtak ret = pci_enable_device(pdev); 823cf4ece53SMasayuki Ohtak if (ret) { 824cf4ece53SMasayuki Ohtak dev_err(&pdev->dev, 825cf4ece53SMasayuki Ohtak "%s-pci_enable_device failed(ret=%d) ", __func__, ret); 826cf4ece53SMasayuki Ohtak return ret; 827cf4ece53SMasayuki Ohtak } 828cf4ece53SMasayuki Ohtak 829cf4ece53SMasayuki Ohtak pci_enable_wake(pdev, PCI_D3hot, 0); 830cf4ece53SMasayuki Ohtak pch_phub_restore_reg_conf(pdev); 831cf4ece53SMasayuki Ohtak 832cf4ece53SMasayuki Ohtak return 0; 833cf4ece53SMasayuki Ohtak } 834cf4ece53SMasayuki Ohtak #else 835cf4ece53SMasayuki Ohtak #define pch_phub_suspend NULL 836cf4ece53SMasayuki Ohtak #define pch_phub_resume NULL 837cf4ece53SMasayuki Ohtak #endif /* CONFIG_PM */ 838cf4ece53SMasayuki Ohtak 839cf4ece53SMasayuki Ohtak static struct pci_device_id pch_phub_pcidev_id[] = { 840c47dda7dSTomoya MORINAGA { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_PCH1_PHUB), 1, }, 841c47dda7dSTomoya MORINAGA { PCI_VDEVICE(ROHM, PCI_DEVICE_ID_ROHM_ML7213_PHUB), 2, }, 842275640b0STomoya MORINAGA { PCI_VDEVICE(ROHM, PCI_DEVICE_ID_ROHM_ML7223_mPHUB), 3, }, 843275640b0STomoya MORINAGA { PCI_VDEVICE(ROHM, PCI_DEVICE_ID_ROHM_ML7223_nPHUB), 4, }, 844c47dda7dSTomoya MORINAGA { } 845cf4ece53SMasayuki Ohtak }; 846b2595142SAxel Lin MODULE_DEVICE_TABLE(pci, pch_phub_pcidev_id); 847cf4ece53SMasayuki Ohtak 848cf4ece53SMasayuki Ohtak static struct pci_driver pch_phub_driver = { 849cf4ece53SMasayuki Ohtak .name = "pch_phub", 850cf4ece53SMasayuki Ohtak .id_table = pch_phub_pcidev_id, 851cf4ece53SMasayuki Ohtak .probe = pch_phub_probe, 852cf4ece53SMasayuki Ohtak .remove = __devexit_p(pch_phub_remove), 853cf4ece53SMasayuki Ohtak .suspend = pch_phub_suspend, 854cf4ece53SMasayuki Ohtak .resume = pch_phub_resume 855cf4ece53SMasayuki Ohtak }; 856cf4ece53SMasayuki Ohtak 857cf4ece53SMasayuki Ohtak static int __init pch_phub_pci_init(void) 858cf4ece53SMasayuki Ohtak { 859cf4ece53SMasayuki Ohtak return pci_register_driver(&pch_phub_driver); 860cf4ece53SMasayuki Ohtak } 861cf4ece53SMasayuki Ohtak 862cf4ece53SMasayuki Ohtak static void __exit pch_phub_pci_exit(void) 863cf4ece53SMasayuki Ohtak { 864cf4ece53SMasayuki Ohtak pci_unregister_driver(&pch_phub_driver); 865cf4ece53SMasayuki Ohtak } 866cf4ece53SMasayuki Ohtak 867cf4ece53SMasayuki Ohtak module_init(pch_phub_pci_init); 868cf4ece53SMasayuki Ohtak module_exit(pch_phub_pci_exit); 869cf4ece53SMasayuki Ohtak 870275640b0STomoya MORINAGA MODULE_DESCRIPTION("Intel EG20T PCH/OKI SEMICONDUCTOR IOH(ML7213/ML7223) PHUB"); 871cf4ece53SMasayuki Ohtak MODULE_LICENSE("GPL"); 872