1cf4ece53SMasayuki Ohtak /* 2*1a738dcfSTomoya 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> 30cf4ece53SMasayuki Ohtak 31cf4ece53SMasayuki Ohtak #define PHUB_STATUS 0x00 /* Status Register offset */ 32cf4ece53SMasayuki Ohtak #define PHUB_CONTROL 0x04 /* Control Register offset */ 33cf4ece53SMasayuki Ohtak #define PHUB_TIMEOUT 0x05 /* Time out value for Status Register */ 34cf4ece53SMasayuki Ohtak #define PCH_PHUB_ROM_WRITE_ENABLE 0x01 /* Enabling for writing ROM */ 35cf4ece53SMasayuki Ohtak #define PCH_PHUB_ROM_WRITE_DISABLE 0x00 /* Disabling for writing ROM */ 36*1a738dcfSTomoya MORINAGA #define PCH_PHUB_MAC_START_ADDR 0x20C /* MAC data area start address offset */ 37*1a738dcfSTomoya MORINAGA #define PCH_PHUB_ROM_START_ADDR_EG20T 0x14 /* ROM data area start address offset 38*1a738dcfSTomoya MORINAGA (Intel EG20T PCH)*/ 39*1a738dcfSTomoya MORINAGA #define PCH_PHUB_ROM_START_ADDR_ML7213 0x400 /* ROM data area start address 40*1a738dcfSTomoya MORINAGA offset(OKI SEMICONDUCTOR ML7213) 41*1a738dcfSTomoya MORINAGA */ 42cf4ece53SMasayuki Ohtak 43cf4ece53SMasayuki Ohtak /* MAX number of INT_REDUCE_CONTROL registers */ 44cf4ece53SMasayuki Ohtak #define MAX_NUM_INT_REDUCE_CONTROL_REG 128 45cf4ece53SMasayuki Ohtak #define PCI_DEVICE_ID_PCH1_PHUB 0x8801 46cf4ece53SMasayuki Ohtak #define PCH_MINOR_NOS 1 47cf4ece53SMasayuki Ohtak #define CLKCFG_CAN_50MHZ 0x12000000 48cf4ece53SMasayuki Ohtak #define CLKCFG_CANCLK_MASK 0xFF000000 49cf4ece53SMasayuki Ohtak 50*1a738dcfSTomoya MORINAGA /* Macros for ML7213 */ 51*1a738dcfSTomoya MORINAGA #define PCI_VENDOR_ID_ROHM 0x10db 52*1a738dcfSTomoya MORINAGA #define PCI_DEVICE_ID_ROHM_ML7213_PHUB 0x801A 53*1a738dcfSTomoya MORINAGA 54cf4ece53SMasayuki Ohtak /* SROM ACCESS Macro */ 55cf4ece53SMasayuki Ohtak #define PCH_WORD_ADDR_MASK (~((1 << 2) - 1)) 56cf4ece53SMasayuki Ohtak 57cf4ece53SMasayuki Ohtak /* Registers address offset */ 58cf4ece53SMasayuki Ohtak #define PCH_PHUB_ID_REG 0x0000 59cf4ece53SMasayuki Ohtak #define PCH_PHUB_QUEUE_PRI_VAL_REG 0x0004 60cf4ece53SMasayuki Ohtak #define PCH_PHUB_RC_QUEUE_MAXSIZE_REG 0x0008 61cf4ece53SMasayuki Ohtak #define PCH_PHUB_BRI_QUEUE_MAXSIZE_REG 0x000C 62cf4ece53SMasayuki Ohtak #define PCH_PHUB_COMP_RESP_TIMEOUT_REG 0x0010 63cf4ece53SMasayuki Ohtak #define PCH_PHUB_BUS_SLAVE_CONTROL_REG 0x0014 64cf4ece53SMasayuki Ohtak #define PCH_PHUB_DEADLOCK_AVOID_TYPE_REG 0x0018 65cf4ece53SMasayuki Ohtak #define PCH_PHUB_INTPIN_REG_WPERMIT_REG0 0x0020 66cf4ece53SMasayuki Ohtak #define PCH_PHUB_INTPIN_REG_WPERMIT_REG1 0x0024 67cf4ece53SMasayuki Ohtak #define PCH_PHUB_INTPIN_REG_WPERMIT_REG2 0x0028 68cf4ece53SMasayuki Ohtak #define PCH_PHUB_INTPIN_REG_WPERMIT_REG3 0x002C 69cf4ece53SMasayuki Ohtak #define PCH_PHUB_INT_REDUCE_CONTROL_REG_BASE 0x0040 70cf4ece53SMasayuki Ohtak #define CLKCFG_REG_OFFSET 0x500 71cf4ece53SMasayuki Ohtak 72cf4ece53SMasayuki Ohtak #define PCH_PHUB_OROM_SIZE 15360 73cf4ece53SMasayuki Ohtak 74cf4ece53SMasayuki Ohtak /** 75cf4ece53SMasayuki Ohtak * struct pch_phub_reg - PHUB register structure 76cf4ece53SMasayuki Ohtak * @phub_id_reg: PHUB_ID register val 77cf4ece53SMasayuki Ohtak * @q_pri_val_reg: QUEUE_PRI_VAL register val 78cf4ece53SMasayuki Ohtak * @rc_q_maxsize_reg: RC_QUEUE_MAXSIZE register val 79cf4ece53SMasayuki Ohtak * @bri_q_maxsize_reg: BRI_QUEUE_MAXSIZE register val 80cf4ece53SMasayuki Ohtak * @comp_resp_timeout_reg: COMP_RESP_TIMEOUT register val 81cf4ece53SMasayuki Ohtak * @bus_slave_control_reg: BUS_SLAVE_CONTROL_REG register val 82cf4ece53SMasayuki Ohtak * @deadlock_avoid_type_reg: DEADLOCK_AVOID_TYPE register val 83cf4ece53SMasayuki Ohtak * @intpin_reg_wpermit_reg0: INTPIN_REG_WPERMIT register 0 val 84cf4ece53SMasayuki Ohtak * @intpin_reg_wpermit_reg1: INTPIN_REG_WPERMIT register 1 val 85cf4ece53SMasayuki Ohtak * @intpin_reg_wpermit_reg2: INTPIN_REG_WPERMIT register 2 val 86cf4ece53SMasayuki Ohtak * @intpin_reg_wpermit_reg3: INTPIN_REG_WPERMIT register 3 val 87cf4ece53SMasayuki Ohtak * @int_reduce_control_reg: INT_REDUCE_CONTROL registers val 88cf4ece53SMasayuki Ohtak * @clkcfg_reg: CLK CFG register val 89cf4ece53SMasayuki Ohtak * @pch_phub_base_address: Register base address 90cf4ece53SMasayuki Ohtak * @pch_phub_extrom_base_address: external rom base address 91cf4ece53SMasayuki Ohtak */ 92cf4ece53SMasayuki Ohtak struct pch_phub_reg { 93cf4ece53SMasayuki Ohtak u32 phub_id_reg; 94cf4ece53SMasayuki Ohtak u32 q_pri_val_reg; 95cf4ece53SMasayuki Ohtak u32 rc_q_maxsize_reg; 96cf4ece53SMasayuki Ohtak u32 bri_q_maxsize_reg; 97cf4ece53SMasayuki Ohtak u32 comp_resp_timeout_reg; 98cf4ece53SMasayuki Ohtak u32 bus_slave_control_reg; 99cf4ece53SMasayuki Ohtak u32 deadlock_avoid_type_reg; 100cf4ece53SMasayuki Ohtak u32 intpin_reg_wpermit_reg0; 101cf4ece53SMasayuki Ohtak u32 intpin_reg_wpermit_reg1; 102cf4ece53SMasayuki Ohtak u32 intpin_reg_wpermit_reg2; 103cf4ece53SMasayuki Ohtak u32 intpin_reg_wpermit_reg3; 104cf4ece53SMasayuki Ohtak u32 int_reduce_control_reg[MAX_NUM_INT_REDUCE_CONTROL_REG]; 105cf4ece53SMasayuki Ohtak u32 clkcfg_reg; 106cf4ece53SMasayuki Ohtak void __iomem *pch_phub_base_address; 107cf4ece53SMasayuki Ohtak void __iomem *pch_phub_extrom_base_address; 108cf4ece53SMasayuki Ohtak }; 109cf4ece53SMasayuki Ohtak 110cf4ece53SMasayuki Ohtak /* SROM SPEC for MAC address assignment offset */ 111cf4ece53SMasayuki Ohtak static const int pch_phub_mac_offset[ETH_ALEN] = {0x3, 0x2, 0x1, 0x0, 0xb, 0xa}; 112cf4ece53SMasayuki Ohtak 113cf4ece53SMasayuki Ohtak static DEFINE_MUTEX(pch_phub_mutex); 114cf4ece53SMasayuki Ohtak 115cf4ece53SMasayuki Ohtak /** 116cf4ece53SMasayuki Ohtak * pch_phub_read_modify_write_reg() - Reading modifying and writing register 117cf4ece53SMasayuki Ohtak * @reg_addr_offset: Register offset address value. 118cf4ece53SMasayuki Ohtak * @data: Writing value. 119cf4ece53SMasayuki Ohtak * @mask: Mask value. 120cf4ece53SMasayuki Ohtak */ 121cf4ece53SMasayuki Ohtak static void pch_phub_read_modify_write_reg(struct pch_phub_reg *chip, 122cf4ece53SMasayuki Ohtak unsigned int reg_addr_offset, 123cf4ece53SMasayuki Ohtak unsigned int data, unsigned int mask) 124cf4ece53SMasayuki Ohtak { 125cf4ece53SMasayuki Ohtak void __iomem *reg_addr = chip->pch_phub_base_address + reg_addr_offset; 126cf4ece53SMasayuki Ohtak iowrite32(((ioread32(reg_addr) & ~mask)) | data, reg_addr); 127cf4ece53SMasayuki Ohtak } 128cf4ece53SMasayuki Ohtak 129cf4ece53SMasayuki Ohtak /* pch_phub_save_reg_conf - saves register configuration */ 130cf4ece53SMasayuki Ohtak static void pch_phub_save_reg_conf(struct pci_dev *pdev) 131cf4ece53SMasayuki Ohtak { 132cf4ece53SMasayuki Ohtak unsigned int i; 133cf4ece53SMasayuki Ohtak struct pch_phub_reg *chip = pci_get_drvdata(pdev); 134cf4ece53SMasayuki Ohtak 135cf4ece53SMasayuki Ohtak void __iomem *p = chip->pch_phub_base_address; 136cf4ece53SMasayuki Ohtak 137cf4ece53SMasayuki Ohtak chip->phub_id_reg = ioread32(p + PCH_PHUB_ID_REG); 138cf4ece53SMasayuki Ohtak chip->q_pri_val_reg = ioread32(p + PCH_PHUB_QUEUE_PRI_VAL_REG); 139cf4ece53SMasayuki Ohtak chip->rc_q_maxsize_reg = ioread32(p + PCH_PHUB_RC_QUEUE_MAXSIZE_REG); 140cf4ece53SMasayuki Ohtak chip->bri_q_maxsize_reg = ioread32(p + PCH_PHUB_BRI_QUEUE_MAXSIZE_REG); 141cf4ece53SMasayuki Ohtak chip->comp_resp_timeout_reg = 142cf4ece53SMasayuki Ohtak ioread32(p + PCH_PHUB_COMP_RESP_TIMEOUT_REG); 143cf4ece53SMasayuki Ohtak chip->bus_slave_control_reg = 144cf4ece53SMasayuki Ohtak ioread32(p + PCH_PHUB_BUS_SLAVE_CONTROL_REG); 145cf4ece53SMasayuki Ohtak chip->deadlock_avoid_type_reg = 146cf4ece53SMasayuki Ohtak ioread32(p + PCH_PHUB_DEADLOCK_AVOID_TYPE_REG); 147cf4ece53SMasayuki Ohtak chip->intpin_reg_wpermit_reg0 = 148cf4ece53SMasayuki Ohtak ioread32(p + PCH_PHUB_INTPIN_REG_WPERMIT_REG0); 149cf4ece53SMasayuki Ohtak chip->intpin_reg_wpermit_reg1 = 150cf4ece53SMasayuki Ohtak ioread32(p + PCH_PHUB_INTPIN_REG_WPERMIT_REG1); 151cf4ece53SMasayuki Ohtak chip->intpin_reg_wpermit_reg2 = 152cf4ece53SMasayuki Ohtak ioread32(p + PCH_PHUB_INTPIN_REG_WPERMIT_REG2); 153cf4ece53SMasayuki Ohtak chip->intpin_reg_wpermit_reg3 = 154cf4ece53SMasayuki Ohtak ioread32(p + PCH_PHUB_INTPIN_REG_WPERMIT_REG3); 155cf4ece53SMasayuki Ohtak dev_dbg(&pdev->dev, "%s : " 156cf4ece53SMasayuki Ohtak "chip->phub_id_reg=%x, " 157cf4ece53SMasayuki Ohtak "chip->q_pri_val_reg=%x, " 158cf4ece53SMasayuki Ohtak "chip->rc_q_maxsize_reg=%x, " 159cf4ece53SMasayuki Ohtak "chip->bri_q_maxsize_reg=%x, " 160cf4ece53SMasayuki Ohtak "chip->comp_resp_timeout_reg=%x, " 161cf4ece53SMasayuki Ohtak "chip->bus_slave_control_reg=%x, " 162cf4ece53SMasayuki Ohtak "chip->deadlock_avoid_type_reg=%x, " 163cf4ece53SMasayuki Ohtak "chip->intpin_reg_wpermit_reg0=%x, " 164cf4ece53SMasayuki Ohtak "chip->intpin_reg_wpermit_reg1=%x, " 165cf4ece53SMasayuki Ohtak "chip->intpin_reg_wpermit_reg2=%x, " 166cf4ece53SMasayuki Ohtak "chip->intpin_reg_wpermit_reg3=%x\n", __func__, 167cf4ece53SMasayuki Ohtak chip->phub_id_reg, 168cf4ece53SMasayuki Ohtak chip->q_pri_val_reg, 169cf4ece53SMasayuki Ohtak chip->rc_q_maxsize_reg, 170cf4ece53SMasayuki Ohtak chip->bri_q_maxsize_reg, 171cf4ece53SMasayuki Ohtak chip->comp_resp_timeout_reg, 172cf4ece53SMasayuki Ohtak chip->bus_slave_control_reg, 173cf4ece53SMasayuki Ohtak chip->deadlock_avoid_type_reg, 174cf4ece53SMasayuki Ohtak chip->intpin_reg_wpermit_reg0, 175cf4ece53SMasayuki Ohtak chip->intpin_reg_wpermit_reg1, 176cf4ece53SMasayuki Ohtak chip->intpin_reg_wpermit_reg2, 177cf4ece53SMasayuki Ohtak chip->intpin_reg_wpermit_reg3); 178cf4ece53SMasayuki Ohtak for (i = 0; i < MAX_NUM_INT_REDUCE_CONTROL_REG; i++) { 179cf4ece53SMasayuki Ohtak chip->int_reduce_control_reg[i] = 180cf4ece53SMasayuki Ohtak ioread32(p + PCH_PHUB_INT_REDUCE_CONTROL_REG_BASE + 4 * i); 181cf4ece53SMasayuki Ohtak dev_dbg(&pdev->dev, "%s : " 182cf4ece53SMasayuki Ohtak "chip->int_reduce_control_reg[%d]=%x\n", 183cf4ece53SMasayuki Ohtak __func__, i, chip->int_reduce_control_reg[i]); 184cf4ece53SMasayuki Ohtak } 185cf4ece53SMasayuki Ohtak chip->clkcfg_reg = ioread32(p + CLKCFG_REG_OFFSET); 186cf4ece53SMasayuki Ohtak } 187cf4ece53SMasayuki Ohtak 188cf4ece53SMasayuki Ohtak /* pch_phub_restore_reg_conf - restore register configuration */ 189cf4ece53SMasayuki Ohtak static void pch_phub_restore_reg_conf(struct pci_dev *pdev) 190cf4ece53SMasayuki Ohtak { 191cf4ece53SMasayuki Ohtak unsigned int i; 192cf4ece53SMasayuki Ohtak struct pch_phub_reg *chip = pci_get_drvdata(pdev); 193cf4ece53SMasayuki Ohtak void __iomem *p; 194cf4ece53SMasayuki Ohtak p = chip->pch_phub_base_address; 195cf4ece53SMasayuki Ohtak 196cf4ece53SMasayuki Ohtak iowrite32(chip->phub_id_reg, p + PCH_PHUB_ID_REG); 197cf4ece53SMasayuki Ohtak iowrite32(chip->q_pri_val_reg, p + PCH_PHUB_QUEUE_PRI_VAL_REG); 198cf4ece53SMasayuki Ohtak iowrite32(chip->rc_q_maxsize_reg, p + PCH_PHUB_RC_QUEUE_MAXSIZE_REG); 199cf4ece53SMasayuki Ohtak iowrite32(chip->bri_q_maxsize_reg, p + PCH_PHUB_BRI_QUEUE_MAXSIZE_REG); 200cf4ece53SMasayuki Ohtak iowrite32(chip->comp_resp_timeout_reg, 201cf4ece53SMasayuki Ohtak p + PCH_PHUB_COMP_RESP_TIMEOUT_REG); 202cf4ece53SMasayuki Ohtak iowrite32(chip->bus_slave_control_reg, 203cf4ece53SMasayuki Ohtak p + PCH_PHUB_BUS_SLAVE_CONTROL_REG); 204cf4ece53SMasayuki Ohtak iowrite32(chip->deadlock_avoid_type_reg, 205cf4ece53SMasayuki Ohtak p + PCH_PHUB_DEADLOCK_AVOID_TYPE_REG); 206cf4ece53SMasayuki Ohtak iowrite32(chip->intpin_reg_wpermit_reg0, 207cf4ece53SMasayuki Ohtak p + PCH_PHUB_INTPIN_REG_WPERMIT_REG0); 208cf4ece53SMasayuki Ohtak iowrite32(chip->intpin_reg_wpermit_reg1, 209cf4ece53SMasayuki Ohtak p + PCH_PHUB_INTPIN_REG_WPERMIT_REG1); 210cf4ece53SMasayuki Ohtak iowrite32(chip->intpin_reg_wpermit_reg2, 211cf4ece53SMasayuki Ohtak p + PCH_PHUB_INTPIN_REG_WPERMIT_REG2); 212cf4ece53SMasayuki Ohtak iowrite32(chip->intpin_reg_wpermit_reg3, 213cf4ece53SMasayuki Ohtak p + PCH_PHUB_INTPIN_REG_WPERMIT_REG3); 214cf4ece53SMasayuki Ohtak dev_dbg(&pdev->dev, "%s : " 215cf4ece53SMasayuki Ohtak "chip->phub_id_reg=%x, " 216cf4ece53SMasayuki Ohtak "chip->q_pri_val_reg=%x, " 217cf4ece53SMasayuki Ohtak "chip->rc_q_maxsize_reg=%x, " 218cf4ece53SMasayuki Ohtak "chip->bri_q_maxsize_reg=%x, " 219cf4ece53SMasayuki Ohtak "chip->comp_resp_timeout_reg=%x, " 220cf4ece53SMasayuki Ohtak "chip->bus_slave_control_reg=%x, " 221cf4ece53SMasayuki Ohtak "chip->deadlock_avoid_type_reg=%x, " 222cf4ece53SMasayuki Ohtak "chip->intpin_reg_wpermit_reg0=%x, " 223cf4ece53SMasayuki Ohtak "chip->intpin_reg_wpermit_reg1=%x, " 224cf4ece53SMasayuki Ohtak "chip->intpin_reg_wpermit_reg2=%x, " 225cf4ece53SMasayuki Ohtak "chip->intpin_reg_wpermit_reg3=%x\n", __func__, 226cf4ece53SMasayuki Ohtak chip->phub_id_reg, 227cf4ece53SMasayuki Ohtak chip->q_pri_val_reg, 228cf4ece53SMasayuki Ohtak chip->rc_q_maxsize_reg, 229cf4ece53SMasayuki Ohtak chip->bri_q_maxsize_reg, 230cf4ece53SMasayuki Ohtak chip->comp_resp_timeout_reg, 231cf4ece53SMasayuki Ohtak chip->bus_slave_control_reg, 232cf4ece53SMasayuki Ohtak chip->deadlock_avoid_type_reg, 233cf4ece53SMasayuki Ohtak chip->intpin_reg_wpermit_reg0, 234cf4ece53SMasayuki Ohtak chip->intpin_reg_wpermit_reg1, 235cf4ece53SMasayuki Ohtak chip->intpin_reg_wpermit_reg2, 236cf4ece53SMasayuki Ohtak chip->intpin_reg_wpermit_reg3); 237cf4ece53SMasayuki Ohtak for (i = 0; i < MAX_NUM_INT_REDUCE_CONTROL_REG; i++) { 238cf4ece53SMasayuki Ohtak iowrite32(chip->int_reduce_control_reg[i], 239cf4ece53SMasayuki Ohtak p + PCH_PHUB_INT_REDUCE_CONTROL_REG_BASE + 4 * i); 240cf4ece53SMasayuki Ohtak dev_dbg(&pdev->dev, "%s : " 241cf4ece53SMasayuki Ohtak "chip->int_reduce_control_reg[%d]=%x\n", 242cf4ece53SMasayuki Ohtak __func__, i, chip->int_reduce_control_reg[i]); 243cf4ece53SMasayuki Ohtak } 244cf4ece53SMasayuki Ohtak 245cf4ece53SMasayuki Ohtak iowrite32(chip->clkcfg_reg, p + CLKCFG_REG_OFFSET); 246cf4ece53SMasayuki Ohtak } 247cf4ece53SMasayuki Ohtak 248cf4ece53SMasayuki Ohtak /** 249cf4ece53SMasayuki Ohtak * pch_phub_read_serial_rom() - Reading Serial ROM 250cf4ece53SMasayuki Ohtak * @offset_address: Serial ROM offset address to read. 251cf4ece53SMasayuki Ohtak * @data: Read buffer for specified Serial ROM value. 252cf4ece53SMasayuki Ohtak */ 253cf4ece53SMasayuki Ohtak static void pch_phub_read_serial_rom(struct pch_phub_reg *chip, 254cf4ece53SMasayuki Ohtak unsigned int offset_address, u8 *data) 255cf4ece53SMasayuki Ohtak { 256cf4ece53SMasayuki Ohtak void __iomem *mem_addr = chip->pch_phub_extrom_base_address + 257cf4ece53SMasayuki Ohtak offset_address; 258cf4ece53SMasayuki Ohtak 259cf4ece53SMasayuki Ohtak *data = ioread8(mem_addr); 260cf4ece53SMasayuki Ohtak } 261cf4ece53SMasayuki Ohtak 262cf4ece53SMasayuki Ohtak /** 263cf4ece53SMasayuki Ohtak * pch_phub_write_serial_rom() - Writing Serial ROM 264cf4ece53SMasayuki Ohtak * @offset_address: Serial ROM offset address. 265cf4ece53SMasayuki Ohtak * @data: Serial ROM value to write. 266cf4ece53SMasayuki Ohtak */ 267cf4ece53SMasayuki Ohtak static int pch_phub_write_serial_rom(struct pch_phub_reg *chip, 268cf4ece53SMasayuki Ohtak unsigned int offset_address, u8 data) 269cf4ece53SMasayuki Ohtak { 270cf4ece53SMasayuki Ohtak void __iomem *mem_addr = chip->pch_phub_extrom_base_address + 271cf4ece53SMasayuki Ohtak (offset_address & PCH_WORD_ADDR_MASK); 272cf4ece53SMasayuki Ohtak int i; 273cf4ece53SMasayuki Ohtak unsigned int word_data; 274cf4ece53SMasayuki Ohtak unsigned int pos; 275cf4ece53SMasayuki Ohtak unsigned int mask; 276cf4ece53SMasayuki Ohtak pos = (offset_address % 4) * 8; 277cf4ece53SMasayuki Ohtak mask = ~(0xFF << pos); 278cf4ece53SMasayuki Ohtak 279cf4ece53SMasayuki Ohtak iowrite32(PCH_PHUB_ROM_WRITE_ENABLE, 280cf4ece53SMasayuki Ohtak chip->pch_phub_extrom_base_address + PHUB_CONTROL); 281cf4ece53SMasayuki Ohtak 282cf4ece53SMasayuki Ohtak word_data = ioread32(mem_addr); 283cf4ece53SMasayuki Ohtak iowrite32((word_data & mask) | (u32)data << pos, mem_addr); 284cf4ece53SMasayuki Ohtak 285cf4ece53SMasayuki Ohtak i = 0; 286cf4ece53SMasayuki Ohtak while (ioread8(chip->pch_phub_extrom_base_address + 287cf4ece53SMasayuki Ohtak PHUB_STATUS) != 0x00) { 288cf4ece53SMasayuki Ohtak msleep(1); 289cf4ece53SMasayuki Ohtak if (i == PHUB_TIMEOUT) 290cf4ece53SMasayuki Ohtak return -ETIMEDOUT; 291cf4ece53SMasayuki Ohtak i++; 292cf4ece53SMasayuki Ohtak } 293cf4ece53SMasayuki Ohtak 294cf4ece53SMasayuki Ohtak iowrite32(PCH_PHUB_ROM_WRITE_DISABLE, 295cf4ece53SMasayuki Ohtak chip->pch_phub_extrom_base_address + PHUB_CONTROL); 296cf4ece53SMasayuki Ohtak 297cf4ece53SMasayuki Ohtak return 0; 298cf4ece53SMasayuki Ohtak } 299cf4ece53SMasayuki Ohtak 300cf4ece53SMasayuki Ohtak /** 301cf4ece53SMasayuki Ohtak * pch_phub_read_serial_rom_val() - Read Serial ROM value 302cf4ece53SMasayuki Ohtak * @offset_address: Serial ROM address offset value. 303cf4ece53SMasayuki Ohtak * @data: Serial ROM value to read. 304cf4ece53SMasayuki Ohtak */ 305cf4ece53SMasayuki Ohtak static void pch_phub_read_serial_rom_val(struct pch_phub_reg *chip, 306cf4ece53SMasayuki Ohtak unsigned int offset_address, u8 *data) 307cf4ece53SMasayuki Ohtak { 308cf4ece53SMasayuki Ohtak unsigned int mem_addr; 309cf4ece53SMasayuki Ohtak 310*1a738dcfSTomoya MORINAGA mem_addr = PCH_PHUB_ROM_START_ADDR_EG20T + 311cf4ece53SMasayuki Ohtak pch_phub_mac_offset[offset_address]; 312cf4ece53SMasayuki Ohtak 313cf4ece53SMasayuki Ohtak pch_phub_read_serial_rom(chip, mem_addr, data); 314cf4ece53SMasayuki Ohtak } 315cf4ece53SMasayuki Ohtak 316cf4ece53SMasayuki Ohtak /** 317cf4ece53SMasayuki Ohtak * pch_phub_write_serial_rom_val() - writing Serial ROM value 318cf4ece53SMasayuki Ohtak * @offset_address: Serial ROM address offset value. 319cf4ece53SMasayuki Ohtak * @data: Serial ROM value. 320cf4ece53SMasayuki Ohtak */ 321cf4ece53SMasayuki Ohtak static int pch_phub_write_serial_rom_val(struct pch_phub_reg *chip, 322cf4ece53SMasayuki Ohtak unsigned int offset_address, u8 data) 323cf4ece53SMasayuki Ohtak { 324cf4ece53SMasayuki Ohtak int retval; 325cf4ece53SMasayuki Ohtak unsigned int mem_addr; 326cf4ece53SMasayuki Ohtak 327*1a738dcfSTomoya MORINAGA mem_addr = PCH_PHUB_ROM_START_ADDR_EG20T + 328cf4ece53SMasayuki Ohtak pch_phub_mac_offset[offset_address]; 329cf4ece53SMasayuki Ohtak 330cf4ece53SMasayuki Ohtak retval = pch_phub_write_serial_rom(chip, mem_addr, data); 331cf4ece53SMasayuki Ohtak 332cf4ece53SMasayuki Ohtak return retval; 333cf4ece53SMasayuki Ohtak } 334cf4ece53SMasayuki Ohtak 335cf4ece53SMasayuki Ohtak /* pch_phub_gbe_serial_rom_conf - makes Serial ROM header format configuration 336cf4ece53SMasayuki Ohtak * for Gigabit Ethernet MAC address 337cf4ece53SMasayuki Ohtak */ 338cf4ece53SMasayuki Ohtak static int pch_phub_gbe_serial_rom_conf(struct pch_phub_reg *chip) 339cf4ece53SMasayuki Ohtak { 340cf4ece53SMasayuki Ohtak int retval; 341cf4ece53SMasayuki Ohtak 342cf4ece53SMasayuki Ohtak retval = pch_phub_write_serial_rom(chip, 0x0b, 0xbc); 343cf4ece53SMasayuki Ohtak retval |= pch_phub_write_serial_rom(chip, 0x0a, 0x10); 344cf4ece53SMasayuki Ohtak retval |= pch_phub_write_serial_rom(chip, 0x09, 0x01); 345cf4ece53SMasayuki Ohtak retval |= pch_phub_write_serial_rom(chip, 0x08, 0x02); 346cf4ece53SMasayuki Ohtak 347cf4ece53SMasayuki Ohtak retval |= pch_phub_write_serial_rom(chip, 0x0f, 0x00); 348cf4ece53SMasayuki Ohtak retval |= pch_phub_write_serial_rom(chip, 0x0e, 0x00); 349cf4ece53SMasayuki Ohtak retval |= pch_phub_write_serial_rom(chip, 0x0d, 0x00); 350cf4ece53SMasayuki Ohtak retval |= pch_phub_write_serial_rom(chip, 0x0c, 0x80); 351cf4ece53SMasayuki Ohtak 352cf4ece53SMasayuki Ohtak retval |= pch_phub_write_serial_rom(chip, 0x13, 0xbc); 353cf4ece53SMasayuki Ohtak retval |= pch_phub_write_serial_rom(chip, 0x12, 0x10); 354cf4ece53SMasayuki Ohtak retval |= pch_phub_write_serial_rom(chip, 0x11, 0x01); 355cf4ece53SMasayuki Ohtak retval |= pch_phub_write_serial_rom(chip, 0x10, 0x18); 356cf4ece53SMasayuki Ohtak 357cf4ece53SMasayuki Ohtak retval |= pch_phub_write_serial_rom(chip, 0x1b, 0xbc); 358cf4ece53SMasayuki Ohtak retval |= pch_phub_write_serial_rom(chip, 0x1a, 0x10); 359cf4ece53SMasayuki Ohtak retval |= pch_phub_write_serial_rom(chip, 0x19, 0x01); 360cf4ece53SMasayuki Ohtak retval |= pch_phub_write_serial_rom(chip, 0x18, 0x19); 361cf4ece53SMasayuki Ohtak 362cf4ece53SMasayuki Ohtak retval |= pch_phub_write_serial_rom(chip, 0x23, 0xbc); 363cf4ece53SMasayuki Ohtak retval |= pch_phub_write_serial_rom(chip, 0x22, 0x10); 364cf4ece53SMasayuki Ohtak retval |= pch_phub_write_serial_rom(chip, 0x21, 0x01); 365cf4ece53SMasayuki Ohtak retval |= pch_phub_write_serial_rom(chip, 0x20, 0x3a); 366cf4ece53SMasayuki Ohtak 367cf4ece53SMasayuki Ohtak retval |= pch_phub_write_serial_rom(chip, 0x27, 0x01); 368cf4ece53SMasayuki Ohtak retval |= pch_phub_write_serial_rom(chip, 0x26, 0x00); 369cf4ece53SMasayuki Ohtak retval |= pch_phub_write_serial_rom(chip, 0x25, 0x00); 370cf4ece53SMasayuki Ohtak retval |= pch_phub_write_serial_rom(chip, 0x24, 0x00); 371cf4ece53SMasayuki Ohtak 372cf4ece53SMasayuki Ohtak return retval; 373cf4ece53SMasayuki Ohtak } 374cf4ece53SMasayuki Ohtak 375cf4ece53SMasayuki Ohtak /** 376cf4ece53SMasayuki Ohtak * pch_phub_read_gbe_mac_addr() - Read Gigabit Ethernet MAC address 377cf4ece53SMasayuki Ohtak * @offset_address: Gigabit Ethernet MAC address offset value. 378cf4ece53SMasayuki Ohtak * @data: Buffer of the Gigabit Ethernet MAC address value. 379cf4ece53SMasayuki Ohtak */ 380cf4ece53SMasayuki Ohtak static void pch_phub_read_gbe_mac_addr(struct pch_phub_reg *chip, u8 *data) 381cf4ece53SMasayuki Ohtak { 382cf4ece53SMasayuki Ohtak int i; 383cf4ece53SMasayuki Ohtak for (i = 0; i < ETH_ALEN; i++) 384cf4ece53SMasayuki Ohtak pch_phub_read_serial_rom_val(chip, i, &data[i]); 385cf4ece53SMasayuki Ohtak } 386cf4ece53SMasayuki Ohtak 387cf4ece53SMasayuki Ohtak /** 388cf4ece53SMasayuki Ohtak * pch_phub_write_gbe_mac_addr() - Write MAC address 389cf4ece53SMasayuki Ohtak * @offset_address: Gigabit Ethernet MAC address offset value. 390cf4ece53SMasayuki Ohtak * @data: Gigabit Ethernet MAC address value. 391cf4ece53SMasayuki Ohtak */ 392cf4ece53SMasayuki Ohtak static int pch_phub_write_gbe_mac_addr(struct pch_phub_reg *chip, u8 *data) 393cf4ece53SMasayuki Ohtak { 394cf4ece53SMasayuki Ohtak int retval; 395cf4ece53SMasayuki Ohtak int i; 396cf4ece53SMasayuki Ohtak 397cf4ece53SMasayuki Ohtak retval = pch_phub_gbe_serial_rom_conf(chip); 398cf4ece53SMasayuki Ohtak if (retval) 399cf4ece53SMasayuki Ohtak return retval; 400cf4ece53SMasayuki Ohtak 401cf4ece53SMasayuki Ohtak for (i = 0; i < ETH_ALEN; i++) { 402cf4ece53SMasayuki Ohtak retval = pch_phub_write_serial_rom_val(chip, i, data[i]); 403cf4ece53SMasayuki Ohtak if (retval) 404cf4ece53SMasayuki Ohtak return retval; 405cf4ece53SMasayuki Ohtak } 406cf4ece53SMasayuki Ohtak 407cf4ece53SMasayuki Ohtak return retval; 408cf4ece53SMasayuki Ohtak } 409cf4ece53SMasayuki Ohtak 410cf4ece53SMasayuki Ohtak static ssize_t pch_phub_bin_read(struct file *filp, struct kobject *kobj, 411cf4ece53SMasayuki Ohtak struct bin_attribute *attr, char *buf, 412cf4ece53SMasayuki Ohtak loff_t off, size_t count) 413cf4ece53SMasayuki Ohtak { 414cf4ece53SMasayuki Ohtak unsigned int rom_signature; 415cf4ece53SMasayuki Ohtak unsigned char rom_length; 416cf4ece53SMasayuki Ohtak unsigned int tmp; 417cf4ece53SMasayuki Ohtak unsigned int addr_offset; 418cf4ece53SMasayuki Ohtak unsigned int orom_size; 419cf4ece53SMasayuki Ohtak int ret; 420cf4ece53SMasayuki Ohtak int err; 421cf4ece53SMasayuki Ohtak 422cf4ece53SMasayuki Ohtak struct pch_phub_reg *chip = 423cf4ece53SMasayuki Ohtak dev_get_drvdata(container_of(kobj, struct device, kobj)); 424cf4ece53SMasayuki Ohtak 425cf4ece53SMasayuki Ohtak ret = mutex_lock_interruptible(&pch_phub_mutex); 426cf4ece53SMasayuki Ohtak if (ret) { 427cf4ece53SMasayuki Ohtak err = -ERESTARTSYS; 428cf4ece53SMasayuki Ohtak goto return_err_nomutex; 429cf4ece53SMasayuki Ohtak } 430cf4ece53SMasayuki Ohtak 431cf4ece53SMasayuki Ohtak /* Get Rom signature */ 432cf4ece53SMasayuki Ohtak pch_phub_read_serial_rom(chip, 0x80, (unsigned char *)&rom_signature); 433cf4ece53SMasayuki Ohtak rom_signature &= 0xff; 434cf4ece53SMasayuki Ohtak pch_phub_read_serial_rom(chip, 0x81, (unsigned char *)&tmp); 435cf4ece53SMasayuki Ohtak rom_signature |= (tmp & 0xff) << 8; 436cf4ece53SMasayuki Ohtak if (rom_signature == 0xAA55) { 437cf4ece53SMasayuki Ohtak pch_phub_read_serial_rom(chip, 0x82, &rom_length); 438cf4ece53SMasayuki Ohtak orom_size = rom_length * 512; 439cf4ece53SMasayuki Ohtak if (orom_size < off) { 440cf4ece53SMasayuki Ohtak addr_offset = 0; 441cf4ece53SMasayuki Ohtak goto return_ok; 442cf4ece53SMasayuki Ohtak } 443cf4ece53SMasayuki Ohtak if (orom_size < count) { 444cf4ece53SMasayuki Ohtak addr_offset = 0; 445cf4ece53SMasayuki Ohtak goto return_ok; 446cf4ece53SMasayuki Ohtak } 447cf4ece53SMasayuki Ohtak 448cf4ece53SMasayuki Ohtak for (addr_offset = 0; addr_offset < count; addr_offset++) { 449cf4ece53SMasayuki Ohtak pch_phub_read_serial_rom(chip, 0x80 + addr_offset + off, 450cf4ece53SMasayuki Ohtak &buf[addr_offset]); 451cf4ece53SMasayuki Ohtak } 452cf4ece53SMasayuki Ohtak } else { 453cf4ece53SMasayuki Ohtak err = -ENODATA; 454cf4ece53SMasayuki Ohtak goto return_err; 455cf4ece53SMasayuki Ohtak } 456cf4ece53SMasayuki Ohtak return_ok: 457cf4ece53SMasayuki Ohtak mutex_unlock(&pch_phub_mutex); 458cf4ece53SMasayuki Ohtak return addr_offset; 459cf4ece53SMasayuki Ohtak 460cf4ece53SMasayuki Ohtak return_err: 461cf4ece53SMasayuki Ohtak mutex_unlock(&pch_phub_mutex); 462cf4ece53SMasayuki Ohtak return_err_nomutex: 463cf4ece53SMasayuki Ohtak return err; 464cf4ece53SMasayuki Ohtak } 465cf4ece53SMasayuki Ohtak 466cf4ece53SMasayuki Ohtak static ssize_t pch_phub_bin_write(struct file *filp, struct kobject *kobj, 467cf4ece53SMasayuki Ohtak struct bin_attribute *attr, 468cf4ece53SMasayuki Ohtak char *buf, loff_t off, size_t count) 469cf4ece53SMasayuki Ohtak { 470cf4ece53SMasayuki Ohtak int err; 471cf4ece53SMasayuki Ohtak unsigned int addr_offset; 472cf4ece53SMasayuki Ohtak int ret; 473cf4ece53SMasayuki Ohtak struct pch_phub_reg *chip = 474cf4ece53SMasayuki Ohtak dev_get_drvdata(container_of(kobj, struct device, kobj)); 475cf4ece53SMasayuki Ohtak 476cf4ece53SMasayuki Ohtak ret = mutex_lock_interruptible(&pch_phub_mutex); 477cf4ece53SMasayuki Ohtak if (ret) 478cf4ece53SMasayuki Ohtak return -ERESTARTSYS; 479cf4ece53SMasayuki Ohtak 480cf4ece53SMasayuki Ohtak if (off > PCH_PHUB_OROM_SIZE) { 481cf4ece53SMasayuki Ohtak addr_offset = 0; 482cf4ece53SMasayuki Ohtak goto return_ok; 483cf4ece53SMasayuki Ohtak } 484cf4ece53SMasayuki Ohtak if (count > PCH_PHUB_OROM_SIZE) { 485cf4ece53SMasayuki Ohtak addr_offset = 0; 486cf4ece53SMasayuki Ohtak goto return_ok; 487cf4ece53SMasayuki Ohtak } 488cf4ece53SMasayuki Ohtak 489cf4ece53SMasayuki Ohtak for (addr_offset = 0; addr_offset < count; addr_offset++) { 490cf4ece53SMasayuki Ohtak if (PCH_PHUB_OROM_SIZE < off + addr_offset) 491cf4ece53SMasayuki Ohtak goto return_ok; 492cf4ece53SMasayuki Ohtak 493cf4ece53SMasayuki Ohtak ret = pch_phub_write_serial_rom(chip, 0x80 + addr_offset + off, 494cf4ece53SMasayuki Ohtak buf[addr_offset]); 495cf4ece53SMasayuki Ohtak if (ret) { 496cf4ece53SMasayuki Ohtak err = ret; 497cf4ece53SMasayuki Ohtak goto return_err; 498cf4ece53SMasayuki Ohtak } 499cf4ece53SMasayuki Ohtak } 500cf4ece53SMasayuki Ohtak 501cf4ece53SMasayuki Ohtak return_ok: 502cf4ece53SMasayuki Ohtak mutex_unlock(&pch_phub_mutex); 503cf4ece53SMasayuki Ohtak return addr_offset; 504cf4ece53SMasayuki Ohtak 505cf4ece53SMasayuki Ohtak return_err: 506cf4ece53SMasayuki Ohtak mutex_unlock(&pch_phub_mutex); 507cf4ece53SMasayuki Ohtak return err; 508cf4ece53SMasayuki Ohtak } 509cf4ece53SMasayuki Ohtak 510cf4ece53SMasayuki Ohtak static ssize_t show_pch_mac(struct device *dev, struct device_attribute *attr, 511cf4ece53SMasayuki Ohtak char *buf) 512cf4ece53SMasayuki Ohtak { 513cf4ece53SMasayuki Ohtak u8 mac[8]; 514cf4ece53SMasayuki Ohtak struct pch_phub_reg *chip = dev_get_drvdata(dev); 515cf4ece53SMasayuki Ohtak 516cf4ece53SMasayuki Ohtak pch_phub_read_gbe_mac_addr(chip, mac); 517cf4ece53SMasayuki Ohtak 518cf4ece53SMasayuki Ohtak return sprintf(buf, "%02x:%02x:%02x:%02x:%02x:%02x\n", 519cf4ece53SMasayuki Ohtak mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); 520cf4ece53SMasayuki Ohtak } 521cf4ece53SMasayuki Ohtak 522cf4ece53SMasayuki Ohtak static ssize_t store_pch_mac(struct device *dev, struct device_attribute *attr, 523cf4ece53SMasayuki Ohtak const char *buf, size_t count) 524cf4ece53SMasayuki Ohtak { 525cf4ece53SMasayuki Ohtak u8 mac[6]; 526cf4ece53SMasayuki Ohtak struct pch_phub_reg *chip = dev_get_drvdata(dev); 527cf4ece53SMasayuki Ohtak 528cf4ece53SMasayuki Ohtak if (count != 18) 529cf4ece53SMasayuki Ohtak return -EINVAL; 530cf4ece53SMasayuki Ohtak 531cf4ece53SMasayuki Ohtak sscanf(buf, "%02x:%02x:%02x:%02x:%02x:%02x", 532cf4ece53SMasayuki Ohtak (u32 *)&mac[0], (u32 *)&mac[1], (u32 *)&mac[2], (u32 *)&mac[3], 533cf4ece53SMasayuki Ohtak (u32 *)&mac[4], (u32 *)&mac[5]); 534cf4ece53SMasayuki Ohtak 535cf4ece53SMasayuki Ohtak pch_phub_write_gbe_mac_addr(chip, mac); 536cf4ece53SMasayuki Ohtak 537cf4ece53SMasayuki Ohtak return count; 538cf4ece53SMasayuki Ohtak } 539cf4ece53SMasayuki Ohtak 540cf4ece53SMasayuki Ohtak static DEVICE_ATTR(pch_mac, S_IRUGO | S_IWUSR, show_pch_mac, store_pch_mac); 541cf4ece53SMasayuki Ohtak 542cf4ece53SMasayuki Ohtak static struct bin_attribute pch_bin_attr = { 543cf4ece53SMasayuki Ohtak .attr = { 544cf4ece53SMasayuki Ohtak .name = "pch_firmware", 545cf4ece53SMasayuki Ohtak .mode = S_IRUGO | S_IWUSR, 546cf4ece53SMasayuki Ohtak }, 547cf4ece53SMasayuki Ohtak .size = PCH_PHUB_OROM_SIZE + 1, 548cf4ece53SMasayuki Ohtak .read = pch_phub_bin_read, 549cf4ece53SMasayuki Ohtak .write = pch_phub_bin_write, 550cf4ece53SMasayuki Ohtak }; 551cf4ece53SMasayuki Ohtak 552cf4ece53SMasayuki Ohtak static int __devinit pch_phub_probe(struct pci_dev *pdev, 553cf4ece53SMasayuki Ohtak const struct pci_device_id *id) 554cf4ece53SMasayuki Ohtak { 555cf4ece53SMasayuki Ohtak int retval; 556cf4ece53SMasayuki Ohtak 557cf4ece53SMasayuki Ohtak int ret; 558da0d7f98SGreg Kroah-Hartman ssize_t rom_size; 559cf4ece53SMasayuki Ohtak struct pch_phub_reg *chip; 560cf4ece53SMasayuki Ohtak 561cf4ece53SMasayuki Ohtak chip = kzalloc(sizeof(struct pch_phub_reg), GFP_KERNEL); 562cf4ece53SMasayuki Ohtak if (chip == NULL) 563cf4ece53SMasayuki Ohtak return -ENOMEM; 564cf4ece53SMasayuki Ohtak 565cf4ece53SMasayuki Ohtak ret = pci_enable_device(pdev); 566cf4ece53SMasayuki Ohtak if (ret) { 567cf4ece53SMasayuki Ohtak dev_err(&pdev->dev, 568cf4ece53SMasayuki Ohtak "%s : pci_enable_device FAILED(ret=%d)", __func__, ret); 569cf4ece53SMasayuki Ohtak goto err_pci_enable_dev; 570cf4ece53SMasayuki Ohtak } 571cf4ece53SMasayuki Ohtak dev_dbg(&pdev->dev, "%s : pci_enable_device returns %d\n", __func__, 572cf4ece53SMasayuki Ohtak ret); 573cf4ece53SMasayuki Ohtak 574cf4ece53SMasayuki Ohtak ret = pci_request_regions(pdev, KBUILD_MODNAME); 575cf4ece53SMasayuki Ohtak if (ret) { 576cf4ece53SMasayuki Ohtak dev_err(&pdev->dev, 577cf4ece53SMasayuki Ohtak "%s : pci_request_regions FAILED(ret=%d)", __func__, ret); 578cf4ece53SMasayuki Ohtak goto err_req_regions; 579cf4ece53SMasayuki Ohtak } 580cf4ece53SMasayuki Ohtak dev_dbg(&pdev->dev, "%s : " 581cf4ece53SMasayuki Ohtak "pci_request_regions returns %d\n", __func__, ret); 582cf4ece53SMasayuki Ohtak 583cf4ece53SMasayuki Ohtak chip->pch_phub_base_address = pci_iomap(pdev, 1, 0); 584cf4ece53SMasayuki Ohtak 585cf4ece53SMasayuki Ohtak 586cf4ece53SMasayuki Ohtak if (chip->pch_phub_base_address == 0) { 587cf4ece53SMasayuki Ohtak dev_err(&pdev->dev, "%s : pci_iomap FAILED", __func__); 588cf4ece53SMasayuki Ohtak ret = -ENOMEM; 589cf4ece53SMasayuki Ohtak goto err_pci_iomap; 590cf4ece53SMasayuki Ohtak } 591cf4ece53SMasayuki Ohtak dev_dbg(&pdev->dev, "%s : pci_iomap SUCCESS and value " 592da0d7f98SGreg Kroah-Hartman "in pch_phub_base_address variable is %p\n", __func__, 593da0d7f98SGreg Kroah-Hartman chip->pch_phub_base_address); 594cf4ece53SMasayuki Ohtak chip->pch_phub_extrom_base_address = pci_map_rom(pdev, &rom_size); 595cf4ece53SMasayuki Ohtak 596cf4ece53SMasayuki Ohtak if (chip->pch_phub_extrom_base_address == 0) { 597cf4ece53SMasayuki Ohtak dev_err(&pdev->dev, "%s : pci_map_rom FAILED", __func__); 598cf4ece53SMasayuki Ohtak ret = -ENOMEM; 599cf4ece53SMasayuki Ohtak goto err_pci_map; 600cf4ece53SMasayuki Ohtak } 601cf4ece53SMasayuki Ohtak dev_dbg(&pdev->dev, "%s : " 602cf4ece53SMasayuki Ohtak "pci_map_rom SUCCESS and value in " 603da0d7f98SGreg Kroah-Hartman "pch_phub_extrom_base_address variable is %p\n", __func__, 604da0d7f98SGreg Kroah-Hartman chip->pch_phub_extrom_base_address); 605cf4ece53SMasayuki Ohtak 606*1a738dcfSTomoya MORINAGA if (id->driver_data == 1) { 607*1a738dcfSTomoya MORINAGA retval = sysfs_create_file(&pdev->dev.kobj, 608*1a738dcfSTomoya MORINAGA &dev_attr_pch_mac.attr); 609cf4ece53SMasayuki Ohtak if (retval) 610cf4ece53SMasayuki Ohtak goto err_sysfs_create; 611cf4ece53SMasayuki Ohtak 612cf4ece53SMasayuki Ohtak retval = sysfs_create_bin_file(&pdev->dev.kobj, &pch_bin_attr); 613cf4ece53SMasayuki Ohtak if (retval) 614cf4ece53SMasayuki Ohtak goto exit_bin_attr; 615cf4ece53SMasayuki Ohtak 616*1a738dcfSTomoya MORINAGA pch_phub_read_modify_write_reg(chip, 617*1a738dcfSTomoya MORINAGA (unsigned int)CLKCFG_REG_OFFSET, 618*1a738dcfSTomoya MORINAGA CLKCFG_CAN_50MHZ, 619*1a738dcfSTomoya MORINAGA CLKCFG_CANCLK_MASK); 620cf4ece53SMasayuki Ohtak 621cf4ece53SMasayuki Ohtak /* set the prefech value */ 622cf4ece53SMasayuki Ohtak iowrite32(0x000affaa, chip->pch_phub_base_address + 0x14); 623cf4ece53SMasayuki Ohtak /* set the interrupt delay value */ 624cf4ece53SMasayuki Ohtak iowrite32(0x25, chip->pch_phub_base_address + 0x44); 625*1a738dcfSTomoya MORINAGA } else if (id->driver_data == 2) { 626*1a738dcfSTomoya MORINAGA retval = sysfs_create_bin_file(&pdev->dev.kobj, &pch_bin_attr); 627*1a738dcfSTomoya MORINAGA if (retval) 628*1a738dcfSTomoya MORINAGA goto err_sysfs_create; 629*1a738dcfSTomoya MORINAGA /* set the prefech value 630*1a738dcfSTomoya MORINAGA * Device2(USB OHCI #1/ USB EHCI #1/ USB Device):a 631*1a738dcfSTomoya MORINAGA * Device4(SDIO #0,1,2):f 632*1a738dcfSTomoya MORINAGA * Device6(SATA 2):f 633*1a738dcfSTomoya MORINAGA * Device8(USB OHCI #0/ USB EHCI #0):a 634*1a738dcfSTomoya MORINAGA */ 635*1a738dcfSTomoya MORINAGA iowrite32(0x000affa0, chip->pch_phub_base_address + 0x14); 636*1a738dcfSTomoya MORINAGA } 637*1a738dcfSTomoya MORINAGA pci_set_drvdata(pdev, chip); 638cf4ece53SMasayuki Ohtak 639cf4ece53SMasayuki Ohtak return 0; 640cf4ece53SMasayuki Ohtak exit_bin_attr: 641cf4ece53SMasayuki Ohtak sysfs_remove_file(&pdev->dev.kobj, &dev_attr_pch_mac.attr); 642cf4ece53SMasayuki Ohtak 643cf4ece53SMasayuki Ohtak err_sysfs_create: 644cf4ece53SMasayuki Ohtak pci_unmap_rom(pdev, chip->pch_phub_extrom_base_address); 645cf4ece53SMasayuki Ohtak err_pci_map: 646cf4ece53SMasayuki Ohtak pci_iounmap(pdev, chip->pch_phub_base_address); 647cf4ece53SMasayuki Ohtak err_pci_iomap: 648cf4ece53SMasayuki Ohtak pci_release_regions(pdev); 649cf4ece53SMasayuki Ohtak err_req_regions: 650cf4ece53SMasayuki Ohtak pci_disable_device(pdev); 651cf4ece53SMasayuki Ohtak err_pci_enable_dev: 652cf4ece53SMasayuki Ohtak kfree(chip); 653cf4ece53SMasayuki Ohtak dev_err(&pdev->dev, "%s returns %d\n", __func__, ret); 654cf4ece53SMasayuki Ohtak return ret; 655cf4ece53SMasayuki Ohtak } 656cf4ece53SMasayuki Ohtak 657cf4ece53SMasayuki Ohtak static void __devexit pch_phub_remove(struct pci_dev *pdev) 658cf4ece53SMasayuki Ohtak { 659cf4ece53SMasayuki Ohtak struct pch_phub_reg *chip = pci_get_drvdata(pdev); 660cf4ece53SMasayuki Ohtak 661cf4ece53SMasayuki Ohtak sysfs_remove_file(&pdev->dev.kobj, &dev_attr_pch_mac.attr); 662cf4ece53SMasayuki Ohtak sysfs_remove_bin_file(&pdev->dev.kobj, &pch_bin_attr); 663cf4ece53SMasayuki Ohtak pci_unmap_rom(pdev, chip->pch_phub_extrom_base_address); 664cf4ece53SMasayuki Ohtak pci_iounmap(pdev, chip->pch_phub_base_address); 665cf4ece53SMasayuki Ohtak pci_release_regions(pdev); 666cf4ece53SMasayuki Ohtak pci_disable_device(pdev); 667cf4ece53SMasayuki Ohtak kfree(chip); 668cf4ece53SMasayuki Ohtak } 669cf4ece53SMasayuki Ohtak 670cf4ece53SMasayuki Ohtak #ifdef CONFIG_PM 671cf4ece53SMasayuki Ohtak 672cf4ece53SMasayuki Ohtak static int pch_phub_suspend(struct pci_dev *pdev, pm_message_t state) 673cf4ece53SMasayuki Ohtak { 674cf4ece53SMasayuki Ohtak int ret; 675cf4ece53SMasayuki Ohtak 676cf4ece53SMasayuki Ohtak pch_phub_save_reg_conf(pdev); 677cf4ece53SMasayuki Ohtak ret = pci_save_state(pdev); 678cf4ece53SMasayuki Ohtak if (ret) { 679cf4ece53SMasayuki Ohtak dev_err(&pdev->dev, 680cf4ece53SMasayuki Ohtak " %s -pci_save_state returns %d\n", __func__, ret); 681cf4ece53SMasayuki Ohtak return ret; 682cf4ece53SMasayuki Ohtak } 683cf4ece53SMasayuki Ohtak pci_enable_wake(pdev, PCI_D3hot, 0); 684cf4ece53SMasayuki Ohtak pci_disable_device(pdev); 685cf4ece53SMasayuki Ohtak pci_set_power_state(pdev, pci_choose_state(pdev, state)); 686cf4ece53SMasayuki Ohtak 687cf4ece53SMasayuki Ohtak return 0; 688cf4ece53SMasayuki Ohtak } 689cf4ece53SMasayuki Ohtak 690cf4ece53SMasayuki Ohtak static int pch_phub_resume(struct pci_dev *pdev) 691cf4ece53SMasayuki Ohtak { 692cf4ece53SMasayuki Ohtak int ret; 693cf4ece53SMasayuki Ohtak 694cf4ece53SMasayuki Ohtak pci_set_power_state(pdev, PCI_D0); 695cf4ece53SMasayuki Ohtak pci_restore_state(pdev); 696cf4ece53SMasayuki Ohtak ret = pci_enable_device(pdev); 697cf4ece53SMasayuki Ohtak if (ret) { 698cf4ece53SMasayuki Ohtak dev_err(&pdev->dev, 699cf4ece53SMasayuki Ohtak "%s-pci_enable_device failed(ret=%d) ", __func__, ret); 700cf4ece53SMasayuki Ohtak return ret; 701cf4ece53SMasayuki Ohtak } 702cf4ece53SMasayuki Ohtak 703cf4ece53SMasayuki Ohtak pci_enable_wake(pdev, PCI_D3hot, 0); 704cf4ece53SMasayuki Ohtak pch_phub_restore_reg_conf(pdev); 705cf4ece53SMasayuki Ohtak 706cf4ece53SMasayuki Ohtak return 0; 707cf4ece53SMasayuki Ohtak } 708cf4ece53SMasayuki Ohtak #else 709cf4ece53SMasayuki Ohtak #define pch_phub_suspend NULL 710cf4ece53SMasayuki Ohtak #define pch_phub_resume NULL 711cf4ece53SMasayuki Ohtak #endif /* CONFIG_PM */ 712cf4ece53SMasayuki Ohtak 713cf4ece53SMasayuki Ohtak static struct pci_device_id pch_phub_pcidev_id[] = { 714*1a738dcfSTomoya MORINAGA { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_PCH1_PHUB), 1, }, 715*1a738dcfSTomoya MORINAGA { PCI_VDEVICE(ROHM, PCI_DEVICE_ID_ROHM_ML7213_PHUB), 2, }, 716*1a738dcfSTomoya MORINAGA { } 717cf4ece53SMasayuki Ohtak }; 718cf4ece53SMasayuki Ohtak 719cf4ece53SMasayuki Ohtak static struct pci_driver pch_phub_driver = { 720cf4ece53SMasayuki Ohtak .name = "pch_phub", 721cf4ece53SMasayuki Ohtak .id_table = pch_phub_pcidev_id, 722cf4ece53SMasayuki Ohtak .probe = pch_phub_probe, 723cf4ece53SMasayuki Ohtak .remove = __devexit_p(pch_phub_remove), 724cf4ece53SMasayuki Ohtak .suspend = pch_phub_suspend, 725cf4ece53SMasayuki Ohtak .resume = pch_phub_resume 726cf4ece53SMasayuki Ohtak }; 727cf4ece53SMasayuki Ohtak 728cf4ece53SMasayuki Ohtak static int __init pch_phub_pci_init(void) 729cf4ece53SMasayuki Ohtak { 730cf4ece53SMasayuki Ohtak return pci_register_driver(&pch_phub_driver); 731cf4ece53SMasayuki Ohtak } 732cf4ece53SMasayuki Ohtak 733cf4ece53SMasayuki Ohtak static void __exit pch_phub_pci_exit(void) 734cf4ece53SMasayuki Ohtak { 735cf4ece53SMasayuki Ohtak pci_unregister_driver(&pch_phub_driver); 736cf4ece53SMasayuki Ohtak } 737cf4ece53SMasayuki Ohtak 738cf4ece53SMasayuki Ohtak module_init(pch_phub_pci_init); 739cf4ece53SMasayuki Ohtak module_exit(pch_phub_pci_exit); 740cf4ece53SMasayuki Ohtak 741cf4ece53SMasayuki Ohtak MODULE_DESCRIPTION("PCH Packet Hub PCI Driver"); 742cf4ece53SMasayuki Ohtak MODULE_LICENSE("GPL"); 743