2 * Copyright (C) 2011 LAPIS Semiconductor Co., Ltd.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 2 of the License.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
18 #include <linux/module.h>
19 #include <linux/kernel.h>
20 #include <linux/types.h>
22 #include <linux/uaccess.h>
23 #include <linux/string.h>
24 #include <linux/pci.h>
26 #include <linux/delay.h>
27 #include <linux/mutex.h>
28 #include <linux/if_ether.h>
29 #include <linux/ctype.h>
30 #include <linux/dmi.h>
32 #define PHUB_STATUS 0x00 /* Status Register offset */
33 #define PHUB_CONTROL 0x04 /* Control Register offset */
34 #define PHUB_TIMEOUT 0x05 /* Time out value for Status Register */
35 #define PCH_PHUB_ROM_WRITE_ENABLE 0x01 /* Enabling for writing ROM */
36 #define PCH_PHUB_ROM_WRITE_DISABLE 0x00 /* Disabling for writing ROM */
37 #define PCH_PHUB_MAC_START_ADDR_EG20T 0x14 /* MAC data area start address
39 #define PCH_PHUB_MAC_START_ADDR_ML7223 0x20C /* MAC data area start address
41 #define PCH_PHUB_ROM_START_ADDR_EG20T 0x80 /* ROM data area start address offset
43 #define PCH_PHUB_ROM_START_ADDR_ML7213 0x400 /* ROM data area start address
44 offset(LAPIS Semicon ML7213)
46 #define PCH_PHUB_ROM_START_ADDR_ML7223 0x400 /* ROM data area start address
47 offset(LAPIS Semicon ML7223)
50 /* MAX number of INT_REDUCE_CONTROL registers */
51 #define MAX_NUM_INT_REDUCE_CONTROL_REG 128
52 #define PCI_DEVICE_ID_PCH1_PHUB 0x8801
53 #define PCH_MINOR_NOS 1
54 #define CLKCFG_CAN_50MHZ 0x12000000
55 #define CLKCFG_CANCLK_MASK 0xFF000000
56 #define CLKCFG_UART_MASK 0xFFFFFF
59 #define CLKCFG_UART_48MHZ (1 << 16)
60 #define CLKCFG_BAUDDIV (2 << 20)
61 #define CLKCFG_PLL2VCO (8 << 9)
62 #define CLKCFG_UARTCLKSEL (1 << 18)
64 /* Macros for ML7213 */
65 #define PCI_VENDOR_ID_ROHM 0x10db
66 #define PCI_DEVICE_ID_ROHM_ML7213_PHUB 0x801A
68 /* Macros for ML7223 */
69 #define PCI_DEVICE_ID_ROHM_ML7223_mPHUB 0x8012 /* for Bus-m */
70 #define PCI_DEVICE_ID_ROHM_ML7223_nPHUB 0x8002 /* for Bus-n */
72 /* Macros for ML7831 */
73 #define PCI_DEVICE_ID_ROHM_ML7831_PHUB 0x8801
75 /* SROM ACCESS Macro */
76 #define PCH_WORD_ADDR_MASK (~((1 << 2) - 1))
78 /* Registers address offset */
79 #define PCH_PHUB_ID_REG 0x0000
80 #define PCH_PHUB_QUEUE_PRI_VAL_REG 0x0004
81 #define PCH_PHUB_RC_QUEUE_MAXSIZE_REG 0x0008
82 #define PCH_PHUB_BRI_QUEUE_MAXSIZE_REG 0x000C
83 #define PCH_PHUB_COMP_RESP_TIMEOUT_REG 0x0010
84 #define PCH_PHUB_BUS_SLAVE_CONTROL_REG 0x0014
85 #define PCH_PHUB_DEADLOCK_AVOID_TYPE_REG 0x0018
86 #define PCH_PHUB_INTPIN_REG_WPERMIT_REG0 0x0020
87 #define PCH_PHUB_INTPIN_REG_WPERMIT_REG1 0x0024
88 #define PCH_PHUB_INTPIN_REG_WPERMIT_REG2 0x0028
89 #define PCH_PHUB_INTPIN_REG_WPERMIT_REG3 0x002C
90 #define PCH_PHUB_INT_REDUCE_CONTROL_REG_BASE 0x0040
91 #define CLKCFG_REG_OFFSET 0x500
92 #define FUNCSEL_REG_OFFSET 0x508
94 #define PCH_PHUB_OROM_SIZE 15360
97 * struct pch_phub_reg - PHUB register structure
98 * @phub_id_reg: PHUB_ID register val
99 * @q_pri_val_reg: QUEUE_PRI_VAL register val
100 * @rc_q_maxsize_reg: RC_QUEUE_MAXSIZE register val
101 * @bri_q_maxsize_reg: BRI_QUEUE_MAXSIZE register val
102 * @comp_resp_timeout_reg: COMP_RESP_TIMEOUT register val
103 * @bus_slave_control_reg: BUS_SLAVE_CONTROL_REG register val
104 * @deadlock_avoid_type_reg: DEADLOCK_AVOID_TYPE register val
105 * @intpin_reg_wpermit_reg0: INTPIN_REG_WPERMIT register 0 val
106 * @intpin_reg_wpermit_reg1: INTPIN_REG_WPERMIT register 1 val
107 * @intpin_reg_wpermit_reg2: INTPIN_REG_WPERMIT register 2 val
108 * @intpin_reg_wpermit_reg3: INTPIN_REG_WPERMIT register 3 val
109 * @int_reduce_control_reg: INT_REDUCE_CONTROL registers val
110 * @clkcfg_reg: CLK CFG register val
111 * @funcsel_reg: Function select register value
112 * @pch_phub_base_address: Register base address
113 * @pch_phub_extrom_base_address: external rom base address
114 * @pch_mac_start_address: MAC address area start address
115 * @pch_opt_rom_start_address: Option ROM start address
116 * @ioh_type: Save IOH type
117 * @pdev: pointer to pci device struct
119 struct pch_phub_reg
{
122 u32 rc_q_maxsize_reg
;
123 u32 bri_q_maxsize_reg
;
124 u32 comp_resp_timeout_reg
;
125 u32 bus_slave_control_reg
;
126 u32 deadlock_avoid_type_reg
;
127 u32 intpin_reg_wpermit_reg0
;
128 u32 intpin_reg_wpermit_reg1
;
129 u32 intpin_reg_wpermit_reg2
;
130 u32 intpin_reg_wpermit_reg3
;
131 u32 int_reduce_control_reg
[MAX_NUM_INT_REDUCE_CONTROL_REG
];
134 void __iomem
*pch_phub_base_address
;
135 void __iomem
*pch_phub_extrom_base_address
;
136 u32 pch_mac_start_address
;
137 u32 pch_opt_rom_start_address
;
139 struct pci_dev
*pdev
;
142 /* SROM SPEC for MAC address assignment offset */
143 static const int pch_phub_mac_offset
[ETH_ALEN
] = {0x3, 0x2, 0x1, 0x0, 0xb, 0xa};
145 static DEFINE_MUTEX(pch_phub_mutex
);
148 * pch_phub_read_modify_write_reg() - Reading modifying and writing register
149 * @reg_addr_offset: Register offset address value.
150 * @data: Writing value.
153 static void pch_phub_read_modify_write_reg(struct pch_phub_reg
*chip
,
154 unsigned int reg_addr_offset
,
155 unsigned int data
, unsigned int mask
)
157 void __iomem
*reg_addr
= chip
->pch_phub_base_address
+ reg_addr_offset
;
158 iowrite32(((ioread32(reg_addr
) & ~mask
)) | data
, reg_addr
);
161 /* pch_phub_save_reg_conf - saves register configuration */
162 static void pch_phub_save_reg_conf(struct pci_dev
*pdev
)
165 struct pch_phub_reg
*chip
= pci_get_drvdata(pdev
);
167 void __iomem
*p
= chip
->pch_phub_base_address
;
169 chip
->phub_id_reg
= ioread32(p
+ PCH_PHUB_ID_REG
);
170 chip
->q_pri_val_reg
= ioread32(p
+ PCH_PHUB_QUEUE_PRI_VAL_REG
);
171 chip
->rc_q_maxsize_reg
= ioread32(p
+ PCH_PHUB_RC_QUEUE_MAXSIZE_REG
);
172 chip
->bri_q_maxsize_reg
= ioread32(p
+ PCH_PHUB_BRI_QUEUE_MAXSIZE_REG
);
173 chip
->comp_resp_timeout_reg
=
174 ioread32(p
+ PCH_PHUB_COMP_RESP_TIMEOUT_REG
);
175 chip
->bus_slave_control_reg
=
176 ioread32(p
+ PCH_PHUB_BUS_SLAVE_CONTROL_REG
);
177 chip
->deadlock_avoid_type_reg
=
178 ioread32(p
+ PCH_PHUB_DEADLOCK_AVOID_TYPE_REG
);
179 chip
->intpin_reg_wpermit_reg0
=
180 ioread32(p
+ PCH_PHUB_INTPIN_REG_WPERMIT_REG0
);
181 chip
->intpin_reg_wpermit_reg1
=
182 ioread32(p
+ PCH_PHUB_INTPIN_REG_WPERMIT_REG1
);
183 chip
->intpin_reg_wpermit_reg2
=
184 ioread32(p
+ PCH_PHUB_INTPIN_REG_WPERMIT_REG2
);
185 chip
->intpin_reg_wpermit_reg3
=
186 ioread32(p
+ PCH_PHUB_INTPIN_REG_WPERMIT_REG3
);
187 dev_dbg(&pdev
->dev
, "%s : "
188 "chip->phub_id_reg=%x, "
189 "chip->q_pri_val_reg=%x, "
190 "chip->rc_q_maxsize_reg=%x, "
191 "chip->bri_q_maxsize_reg=%x, "
192 "chip->comp_resp_timeout_reg=%x, "
193 "chip->bus_slave_control_reg=%x, "
194 "chip->deadlock_avoid_type_reg=%x, "
195 "chip->intpin_reg_wpermit_reg0=%x, "
196 "chip->intpin_reg_wpermit_reg1=%x, "
197 "chip->intpin_reg_wpermit_reg2=%x, "
198 "chip->intpin_reg_wpermit_reg3=%x\n", __func__
,
201 chip
->rc_q_maxsize_reg
,
202 chip
->bri_q_maxsize_reg
,
203 chip
->comp_resp_timeout_reg
,
204 chip
->bus_slave_control_reg
,
205 chip
->deadlock_avoid_type_reg
,
206 chip
->intpin_reg_wpermit_reg0
,
207 chip
->intpin_reg_wpermit_reg1
,
208 chip
->intpin_reg_wpermit_reg2
,
209 chip
->intpin_reg_wpermit_reg3
);
210 for (i
= 0; i
< MAX_NUM_INT_REDUCE_CONTROL_REG
; i
++) {
211 chip
->int_reduce_control_reg
[i
] =
212 ioread32(p
+ PCH_PHUB_INT_REDUCE_CONTROL_REG_BASE
+ 4 * i
);
213 dev_dbg(&pdev
->dev
, "%s : "
214 "chip->int_reduce_control_reg[%d]=%x\n",
215 __func__
, i
, chip
->int_reduce_control_reg
[i
]);
217 chip
->clkcfg_reg
= ioread32(p
+ CLKCFG_REG_OFFSET
);
218 if ((chip
->ioh_type
== 2) || (chip
->ioh_type
== 4))
219 chip
->funcsel_reg
= ioread32(p
+ FUNCSEL_REG_OFFSET
);
222 /* pch_phub_restore_reg_conf - restore register configuration */
223 static void pch_phub_restore_reg_conf(struct pci_dev
*pdev
)
226 struct pch_phub_reg
*chip
= pci_get_drvdata(pdev
);
228 p
= chip
->pch_phub_base_address
;
230 iowrite32(chip
->phub_id_reg
, p
+ PCH_PHUB_ID_REG
);
231 iowrite32(chip
->q_pri_val_reg
, p
+ PCH_PHUB_QUEUE_PRI_VAL_REG
);
232 iowrite32(chip
->rc_q_maxsize_reg
, p
+ PCH_PHUB_RC_QUEUE_MAXSIZE_REG
);
233 iowrite32(chip
->bri_q_maxsize_reg
, p
+ PCH_PHUB_BRI_QUEUE_MAXSIZE_REG
);
234 iowrite32(chip
->comp_resp_timeout_reg
,
235 p
+ PCH_PHUB_COMP_RESP_TIMEOUT_REG
);
236 iowrite32(chip
->bus_slave_control_reg
,
237 p
+ PCH_PHUB_BUS_SLAVE_CONTROL_REG
);
238 iowrite32(chip
->deadlock_avoid_type_reg
,
239 p
+ PCH_PHUB_DEADLOCK_AVOID_TYPE_REG
);
240 iowrite32(chip
->intpin_reg_wpermit_reg0
,
241 p
+ PCH_PHUB_INTPIN_REG_WPERMIT_REG0
);
242 iowrite32(chip
->intpin_reg_wpermit_reg1
,
243 p
+ PCH_PHUB_INTPIN_REG_WPERMIT_REG1
);
244 iowrite32(chip
->intpin_reg_wpermit_reg2
,
245 p
+ PCH_PHUB_INTPIN_REG_WPERMIT_REG2
);
246 iowrite32(chip
->intpin_reg_wpermit_reg3
,
247 p
+ PCH_PHUB_INTPIN_REG_WPERMIT_REG3
);
248 dev_dbg(&pdev
->dev
, "%s : "
249 "chip->phub_id_reg=%x, "
250 "chip->q_pri_val_reg=%x, "
251 "chip->rc_q_maxsize_reg=%x, "
252 "chip->bri_q_maxsize_reg=%x, "
253 "chip->comp_resp_timeout_reg=%x, "
254 "chip->bus_slave_control_reg=%x, "
255 "chip->deadlock_avoid_type_reg=%x, "
256 "chip->intpin_reg_wpermit_reg0=%x, "
257 "chip->intpin_reg_wpermit_reg1=%x, "
258 "chip->intpin_reg_wpermit_reg2=%x, "
259 "chip->intpin_reg_wpermit_reg3=%x\n", __func__
,
262 chip
->rc_q_maxsize_reg
,
263 chip
->bri_q_maxsize_reg
,
264 chip
->comp_resp_timeout_reg
,
265 chip
->bus_slave_control_reg
,
266 chip
->deadlock_avoid_type_reg
,
267 chip
->intpin_reg_wpermit_reg0
,
268 chip
->intpin_reg_wpermit_reg1
,
269 chip
->intpin_reg_wpermit_reg2
,
270 chip
->intpin_reg_wpermit_reg3
);
271 for (i
= 0; i
< MAX_NUM_INT_REDUCE_CONTROL_REG
; i
++) {
272 iowrite32(chip
->int_reduce_control_reg
[i
],
273 p
+ PCH_PHUB_INT_REDUCE_CONTROL_REG_BASE
+ 4 * i
);
274 dev_dbg(&pdev
->dev
, "%s : "
275 "chip->int_reduce_control_reg[%d]=%x\n",
276 __func__
, i
, chip
->int_reduce_control_reg
[i
]);
279 iowrite32(chip
->clkcfg_reg
, p
+ CLKCFG_REG_OFFSET
);
280 if ((chip
->ioh_type
== 2) || (chip
->ioh_type
== 4))
281 iowrite32(chip
->funcsel_reg
, p
+ FUNCSEL_REG_OFFSET
);
285 * pch_phub_read_serial_rom() - Reading Serial ROM
286 * @offset_address: Serial ROM offset address to read.
287 * @data: Read buffer for specified Serial ROM value.
289 static void pch_phub_read_serial_rom(struct pch_phub_reg
*chip
,
290 unsigned int offset_address
, u8
*data
)
292 void __iomem
*mem_addr
= chip
->pch_phub_extrom_base_address
+
295 *data
= ioread8(mem_addr
);
299 * pch_phub_write_serial_rom() - Writing Serial ROM
300 * @offset_address: Serial ROM offset address.
301 * @data: Serial ROM value to write.
303 static int pch_phub_write_serial_rom(struct pch_phub_reg
*chip
,
304 unsigned int offset_address
, u8 data
)
306 void __iomem
*mem_addr
= chip
->pch_phub_extrom_base_address
+
307 (offset_address
& PCH_WORD_ADDR_MASK
);
309 unsigned int word_data
;
312 pos
= (offset_address
% 4) * 8;
313 mask
= ~(0xFF << pos
);
315 iowrite32(PCH_PHUB_ROM_WRITE_ENABLE
,
316 chip
->pch_phub_extrom_base_address
+ PHUB_CONTROL
);
318 word_data
= ioread32(mem_addr
);
319 iowrite32((word_data
& mask
) | (u32
)data
<< pos
, mem_addr
);
322 while (ioread8(chip
->pch_phub_extrom_base_address
+
323 PHUB_STATUS
) != 0x00) {
325 if (i
== PHUB_TIMEOUT
)
330 iowrite32(PCH_PHUB_ROM_WRITE_DISABLE
,
331 chip
->pch_phub_extrom_base_address
+ PHUB_CONTROL
);
337 * pch_phub_read_serial_rom_val() - Read Serial ROM value
338 * @offset_address: Serial ROM address offset value.
339 * @data: Serial ROM value to read.
341 static void pch_phub_read_serial_rom_val(struct pch_phub_reg
*chip
,
342 unsigned int offset_address
, u8
*data
)
344 unsigned int mem_addr
;
346 mem_addr
= chip
->pch_mac_start_address
+
347 pch_phub_mac_offset
[offset_address
];
349 pch_phub_read_serial_rom(chip
, mem_addr
, data
);
353 * pch_phub_write_serial_rom_val() - writing Serial ROM value
354 * @offset_address: Serial ROM address offset value.
355 * @data: Serial ROM value.
357 static int pch_phub_write_serial_rom_val(struct pch_phub_reg
*chip
,
358 unsigned int offset_address
, u8 data
)
361 unsigned int mem_addr
;
363 mem_addr
= chip
->pch_mac_start_address
+
364 pch_phub_mac_offset
[offset_address
];
366 retval
= pch_phub_write_serial_rom(chip
, mem_addr
, data
);
371 /* pch_phub_gbe_serial_rom_conf - makes Serial ROM header format configuration
372 * for Gigabit Ethernet MAC address
374 static int pch_phub_gbe_serial_rom_conf(struct pch_phub_reg
*chip
)
378 retval
= pch_phub_write_serial_rom(chip
, 0x0b, 0xbc);
379 retval
|= pch_phub_write_serial_rom(chip
, 0x0a, 0x10);
380 retval
|= pch_phub_write_serial_rom(chip
, 0x09, 0x01);
381 retval
|= pch_phub_write_serial_rom(chip
, 0x08, 0x02);
383 retval
|= pch_phub_write_serial_rom(chip
, 0x0f, 0x00);
384 retval
|= pch_phub_write_serial_rom(chip
, 0x0e, 0x00);
385 retval
|= pch_phub_write_serial_rom(chip
, 0x0d, 0x00);
386 retval
|= pch_phub_write_serial_rom(chip
, 0x0c, 0x80);
388 retval
|= pch_phub_write_serial_rom(chip
, 0x13, 0xbc);
389 retval
|= pch_phub_write_serial_rom(chip
, 0x12, 0x10);
390 retval
|= pch_phub_write_serial_rom(chip
, 0x11, 0x01);
391 retval
|= pch_phub_write_serial_rom(chip
, 0x10, 0x18);
393 retval
|= pch_phub_write_serial_rom(chip
, 0x1b, 0xbc);
394 retval
|= pch_phub_write_serial_rom(chip
, 0x1a, 0x10);
395 retval
|= pch_phub_write_serial_rom(chip
, 0x19, 0x01);
396 retval
|= pch_phub_write_serial_rom(chip
, 0x18, 0x19);
398 retval
|= pch_phub_write_serial_rom(chip
, 0x23, 0xbc);
399 retval
|= pch_phub_write_serial_rom(chip
, 0x22, 0x10);
400 retval
|= pch_phub_write_serial_rom(chip
, 0x21, 0x01);
401 retval
|= pch_phub_write_serial_rom(chip
, 0x20, 0x3a);
403 retval
|= pch_phub_write_serial_rom(chip
, 0x27, 0x01);
404 retval
|= pch_phub_write_serial_rom(chip
, 0x26, 0x00);
405 retval
|= pch_phub_write_serial_rom(chip
, 0x25, 0x00);
406 retval
|= pch_phub_write_serial_rom(chip
, 0x24, 0x00);
411 /* pch_phub_gbe_serial_rom_conf_mp - makes SerialROM header format configuration
412 * for Gigabit Ethernet MAC address
414 static int pch_phub_gbe_serial_rom_conf_mp(struct pch_phub_reg
*chip
)
420 retval
= pch_phub_write_serial_rom(chip
, 0x03 + offset_addr
, 0xbc);
421 retval
|= pch_phub_write_serial_rom(chip
, 0x02 + offset_addr
, 0x00);
422 retval
|= pch_phub_write_serial_rom(chip
, 0x01 + offset_addr
, 0x40);
423 retval
|= pch_phub_write_serial_rom(chip
, 0x00 + offset_addr
, 0x02);
425 retval
|= pch_phub_write_serial_rom(chip
, 0x07 + offset_addr
, 0x00);
426 retval
|= pch_phub_write_serial_rom(chip
, 0x06 + offset_addr
, 0x00);
427 retval
|= pch_phub_write_serial_rom(chip
, 0x05 + offset_addr
, 0x00);
428 retval
|= pch_phub_write_serial_rom(chip
, 0x04 + offset_addr
, 0x80);
430 retval
|= pch_phub_write_serial_rom(chip
, 0x0b + offset_addr
, 0xbc);
431 retval
|= pch_phub_write_serial_rom(chip
, 0x0a + offset_addr
, 0x00);
432 retval
|= pch_phub_write_serial_rom(chip
, 0x09 + offset_addr
, 0x40);
433 retval
|= pch_phub_write_serial_rom(chip
, 0x08 + offset_addr
, 0x18);
435 retval
|= pch_phub_write_serial_rom(chip
, 0x13 + offset_addr
, 0xbc);
436 retval
|= pch_phub_write_serial_rom(chip
, 0x12 + offset_addr
, 0x00);
437 retval
|= pch_phub_write_serial_rom(chip
, 0x11 + offset_addr
, 0x40);
438 retval
|= pch_phub_write_serial_rom(chip
, 0x10 + offset_addr
, 0x19);
440 retval
|= pch_phub_write_serial_rom(chip
, 0x1b + offset_addr
, 0xbc);
441 retval
|= pch_phub_write_serial_rom(chip
, 0x1a + offset_addr
, 0x00);
442 retval
|= pch_phub_write_serial_rom(chip
, 0x19 + offset_addr
, 0x40);
443 retval
|= pch_phub_write_serial_rom(chip
, 0x18 + offset_addr
, 0x3a);
445 retval
|= pch_phub_write_serial_rom(chip
, 0x1f + offset_addr
, 0x01);
446 retval
|= pch_phub_write_serial_rom(chip
, 0x1e + offset_addr
, 0x00);
447 retval
|= pch_phub_write_serial_rom(chip
, 0x1d + offset_addr
, 0x00);
448 retval
|= pch_phub_write_serial_rom(chip
, 0x1c + offset_addr
, 0x00);
454 * pch_phub_read_gbe_mac_addr() - Read Gigabit Ethernet MAC address
455 * @offset_address: Gigabit Ethernet MAC address offset value.
456 * @data: Buffer of the Gigabit Ethernet MAC address value.
458 static void pch_phub_read_gbe_mac_addr(struct pch_phub_reg
*chip
, u8
*data
)
461 for (i
= 0; i
< ETH_ALEN
; i
++)
462 pch_phub_read_serial_rom_val(chip
, i
, &data
[i
]);
466 * pch_phub_write_gbe_mac_addr() - Write MAC address
467 * @offset_address: Gigabit Ethernet MAC address offset value.
468 * @data: Gigabit Ethernet MAC address value.
470 static int pch_phub_write_gbe_mac_addr(struct pch_phub_reg
*chip
, u8
*data
)
475 if ((chip
->ioh_type
== 1) || (chip
->ioh_type
== 5)) /* EG20T or ML7831*/
476 retval
= pch_phub_gbe_serial_rom_conf(chip
);
478 retval
= pch_phub_gbe_serial_rom_conf_mp(chip
);
482 for (i
= 0; i
< ETH_ALEN
; i
++) {
483 retval
= pch_phub_write_serial_rom_val(chip
, i
, data
[i
]);
491 static ssize_t
pch_phub_bin_read(struct file
*filp
, struct kobject
*kobj
,
492 struct bin_attribute
*attr
, char *buf
,
493 loff_t off
, size_t count
)
495 unsigned int rom_signature
;
496 unsigned char rom_length
;
498 unsigned int addr_offset
;
499 unsigned int orom_size
;
504 struct pch_phub_reg
*chip
=
505 dev_get_drvdata(container_of(kobj
, struct device
, kobj
));
507 ret
= mutex_lock_interruptible(&pch_phub_mutex
);
510 goto return_err_nomutex
;
513 /* Get Rom signature */
514 chip
->pch_phub_extrom_base_address
= pci_map_rom(chip
->pdev
, &rom_size
);
515 if (!chip
->pch_phub_extrom_base_address
)
518 pch_phub_read_serial_rom(chip
, chip
->pch_opt_rom_start_address
,
519 (unsigned char *)&rom_signature
);
520 rom_signature
&= 0xff;
521 pch_phub_read_serial_rom(chip
, chip
->pch_opt_rom_start_address
+ 1,
522 (unsigned char *)&tmp
);
523 rom_signature
|= (tmp
& 0xff) << 8;
524 if (rom_signature
== 0xAA55) {
525 pch_phub_read_serial_rom(chip
,
526 chip
->pch_opt_rom_start_address
+ 2,
528 orom_size
= rom_length
* 512;
529 if (orom_size
< off
) {
533 if (orom_size
< count
) {
538 for (addr_offset
= 0; addr_offset
< count
; addr_offset
++) {
539 pch_phub_read_serial_rom(chip
,
540 chip
->pch_opt_rom_start_address
+ addr_offset
+ off
,
548 pci_unmap_rom(chip
->pdev
, chip
->pch_phub_extrom_base_address
);
549 mutex_unlock(&pch_phub_mutex
);
553 pci_unmap_rom(chip
->pdev
, chip
->pch_phub_extrom_base_address
);
555 mutex_unlock(&pch_phub_mutex
);
560 static ssize_t
pch_phub_bin_write(struct file
*filp
, struct kobject
*kobj
,
561 struct bin_attribute
*attr
,
562 char *buf
, loff_t off
, size_t count
)
565 unsigned int addr_offset
;
568 struct pch_phub_reg
*chip
=
569 dev_get_drvdata(container_of(kobj
, struct device
, kobj
));
571 ret
= mutex_lock_interruptible(&pch_phub_mutex
);
575 if (off
> PCH_PHUB_OROM_SIZE
) {
579 if (count
> PCH_PHUB_OROM_SIZE
) {
584 chip
->pch_phub_extrom_base_address
= pci_map_rom(chip
->pdev
, &rom_size
);
585 if (!chip
->pch_phub_extrom_base_address
) {
590 for (addr_offset
= 0; addr_offset
< count
; addr_offset
++) {
591 if (PCH_PHUB_OROM_SIZE
< off
+ addr_offset
)
594 ret
= pch_phub_write_serial_rom(chip
,
595 chip
->pch_opt_rom_start_address
+ addr_offset
+ off
,
604 pci_unmap_rom(chip
->pdev
, chip
->pch_phub_extrom_base_address
);
605 mutex_unlock(&pch_phub_mutex
);
609 pci_unmap_rom(chip
->pdev
, chip
->pch_phub_extrom_base_address
);
612 mutex_unlock(&pch_phub_mutex
);
616 static ssize_t
show_pch_mac(struct device
*dev
, struct device_attribute
*attr
,
620 struct pch_phub_reg
*chip
= dev_get_drvdata(dev
);
623 chip
->pch_phub_extrom_base_address
= pci_map_rom(chip
->pdev
, &rom_size
);
624 if (!chip
->pch_phub_extrom_base_address
)
627 pch_phub_read_gbe_mac_addr(chip
, mac
);
628 pci_unmap_rom(chip
->pdev
, chip
->pch_phub_extrom_base_address
);
630 return sprintf(buf
, "%pM\n", mac
);
633 static ssize_t
store_pch_mac(struct device
*dev
, struct device_attribute
*attr
,
634 const char *buf
, size_t count
)
638 struct pch_phub_reg
*chip
= dev_get_drvdata(dev
);
641 if (!mac_pton(buf
, mac
))
644 chip
->pch_phub_extrom_base_address
= pci_map_rom(chip
->pdev
, &rom_size
);
645 if (!chip
->pch_phub_extrom_base_address
)
648 ret
= pch_phub_write_gbe_mac_addr(chip
, mac
);
649 pci_unmap_rom(chip
->pdev
, chip
->pch_phub_extrom_base_address
);
656 static DEVICE_ATTR(pch_mac
, S_IRUGO
| S_IWUSR
, show_pch_mac
, store_pch_mac
);
658 static struct bin_attribute pch_bin_attr
= {
660 .name
= "pch_firmware",
661 .mode
= S_IRUGO
| S_IWUSR
,
663 .size
= PCH_PHUB_OROM_SIZE
+ 1,
664 .read
= pch_phub_bin_read
,
665 .write
= pch_phub_bin_write
,
668 static int pch_phub_probe(struct pci_dev
*pdev
,
669 const struct pci_device_id
*id
)
672 struct pch_phub_reg
*chip
;
674 chip
= kzalloc(sizeof(struct pch_phub_reg
), GFP_KERNEL
);
678 ret
= pci_enable_device(pdev
);
681 "%s : pci_enable_device FAILED(ret=%d)", __func__
, ret
);
682 goto err_pci_enable_dev
;
684 dev_dbg(&pdev
->dev
, "%s : pci_enable_device returns %d\n", __func__
,
687 ret
= pci_request_regions(pdev
, KBUILD_MODNAME
);
690 "%s : pci_request_regions FAILED(ret=%d)", __func__
, ret
);
691 goto err_req_regions
;
693 dev_dbg(&pdev
->dev
, "%s : "
694 "pci_request_regions returns %d\n", __func__
, ret
);
696 chip
->pch_phub_base_address
= pci_iomap(pdev
, 1, 0);
699 if (chip
->pch_phub_base_address
== NULL
) {
700 dev_err(&pdev
->dev
, "%s : pci_iomap FAILED", __func__
);
704 dev_dbg(&pdev
->dev
, "%s : pci_iomap SUCCESS and value "
705 "in pch_phub_base_address variable is %p\n", __func__
,
706 chip
->pch_phub_base_address
);
708 chip
->pdev
= pdev
; /* Save pci device struct */
710 if (id
->driver_data
== 1) { /* EG20T PCH */
711 const char *board_name
;
713 ret
= sysfs_create_file(&pdev
->dev
.kobj
,
714 &dev_attr_pch_mac
.attr
);
716 goto err_sysfs_create
;
718 ret
= sysfs_create_bin_file(&pdev
->dev
.kobj
, &pch_bin_attr
);
722 pch_phub_read_modify_write_reg(chip
,
723 (unsigned int)CLKCFG_REG_OFFSET
,
727 /* quirk for CM-iTC board */
728 board_name
= dmi_get_system_info(DMI_BOARD_NAME
);
729 if (board_name
&& strstr(board_name
, "CM-iTC"))
730 pch_phub_read_modify_write_reg(chip
,
731 (unsigned int)CLKCFG_REG_OFFSET
,
732 CLKCFG_UART_48MHZ
| CLKCFG_BAUDDIV
|
733 CLKCFG_PLL2VCO
| CLKCFG_UARTCLKSEL
,
736 /* set the prefech value */
737 iowrite32(0x000affaa, chip
->pch_phub_base_address
+ 0x14);
738 /* set the interrupt delay value */
739 iowrite32(0x25, chip
->pch_phub_base_address
+ 0x44);
740 chip
->pch_opt_rom_start_address
= PCH_PHUB_ROM_START_ADDR_EG20T
;
741 chip
->pch_mac_start_address
= PCH_PHUB_MAC_START_ADDR_EG20T
;
742 } else if (id
->driver_data
== 2) { /* ML7213 IOH */
743 ret
= sysfs_create_bin_file(&pdev
->dev
.kobj
, &pch_bin_attr
);
745 goto err_sysfs_create
;
746 /* set the prefech value
747 * Device2(USB OHCI #1/ USB EHCI #1/ USB Device):a
748 * Device4(SDIO #0,1,2):f
750 * Device8(USB OHCI #0/ USB EHCI #0):a
752 iowrite32(0x000affa0, chip
->pch_phub_base_address
+ 0x14);
753 chip
->pch_opt_rom_start_address
=\
754 PCH_PHUB_ROM_START_ADDR_ML7213
;
755 } else if (id
->driver_data
== 3) { /* ML7223 IOH Bus-m*/
756 /* set the prefech value
759 iowrite32(0x000a0000, chip
->pch_phub_base_address
+ 0x14);
760 /* set the interrupt delay value */
761 iowrite32(0x25, chip
->pch_phub_base_address
+ 0x140);
762 chip
->pch_opt_rom_start_address
=\
763 PCH_PHUB_ROM_START_ADDR_ML7223
;
764 chip
->pch_mac_start_address
= PCH_PHUB_MAC_START_ADDR_ML7223
;
765 } else if (id
->driver_data
== 4) { /* ML7223 IOH Bus-n*/
766 ret
= sysfs_create_file(&pdev
->dev
.kobj
,
767 &dev_attr_pch_mac
.attr
);
769 goto err_sysfs_create
;
770 ret
= sysfs_create_bin_file(&pdev
->dev
.kobj
, &pch_bin_attr
);
773 /* set the prefech value
774 * Device2(USB OHCI #0,1,2,3/ USB EHCI #0):a
775 * Device4(SDIO #0,1):f
778 iowrite32(0x0000ffa0, chip
->pch_phub_base_address
+ 0x14);
779 chip
->pch_opt_rom_start_address
=\
780 PCH_PHUB_ROM_START_ADDR_ML7223
;
781 chip
->pch_mac_start_address
= PCH_PHUB_MAC_START_ADDR_ML7223
;
782 } else if (id
->driver_data
== 5) { /* ML7831 */
783 ret
= sysfs_create_file(&pdev
->dev
.kobj
,
784 &dev_attr_pch_mac
.attr
);
786 goto err_sysfs_create
;
788 ret
= sysfs_create_bin_file(&pdev
->dev
.kobj
, &pch_bin_attr
);
792 /* set the prefech value */
793 iowrite32(0x000affaa, chip
->pch_phub_base_address
+ 0x14);
794 /* set the interrupt delay value */
795 iowrite32(0x25, chip
->pch_phub_base_address
+ 0x44);
796 chip
->pch_opt_rom_start_address
= PCH_PHUB_ROM_START_ADDR_EG20T
;
797 chip
->pch_mac_start_address
= PCH_PHUB_MAC_START_ADDR_EG20T
;
800 chip
->ioh_type
= id
->driver_data
;
801 pci_set_drvdata(pdev
, chip
);
805 sysfs_remove_file(&pdev
->dev
.kobj
, &dev_attr_pch_mac
.attr
);
808 pci_iounmap(pdev
, chip
->pch_phub_base_address
);
810 pci_release_regions(pdev
);
812 pci_disable_device(pdev
);
815 dev_err(&pdev
->dev
, "%s returns %d\n", __func__
, ret
);
819 static void pch_phub_remove(struct pci_dev
*pdev
)
821 struct pch_phub_reg
*chip
= pci_get_drvdata(pdev
);
823 sysfs_remove_file(&pdev
->dev
.kobj
, &dev_attr_pch_mac
.attr
);
824 sysfs_remove_bin_file(&pdev
->dev
.kobj
, &pch_bin_attr
);
825 pci_iounmap(pdev
, chip
->pch_phub_base_address
);
826 pci_release_regions(pdev
);
827 pci_disable_device(pdev
);
833 static int pch_phub_suspend(struct pci_dev
*pdev
, pm_message_t state
)
837 pch_phub_save_reg_conf(pdev
);
838 ret
= pci_save_state(pdev
);
841 " %s -pci_save_state returns %d\n", __func__
, ret
);
844 pci_enable_wake(pdev
, PCI_D3hot
, 0);
845 pci_disable_device(pdev
);
846 pci_set_power_state(pdev
, pci_choose_state(pdev
, state
));
851 static int pch_phub_resume(struct pci_dev
*pdev
)
855 pci_set_power_state(pdev
, PCI_D0
);
856 pci_restore_state(pdev
);
857 ret
= pci_enable_device(pdev
);
860 "%s-pci_enable_device failed(ret=%d) ", __func__
, ret
);
864 pci_enable_wake(pdev
, PCI_D3hot
, 0);
865 pch_phub_restore_reg_conf(pdev
);
870 #define pch_phub_suspend NULL
871 #define pch_phub_resume NULL
872 #endif /* CONFIG_PM */
874 static struct pci_device_id pch_phub_pcidev_id
[] = {
875 { PCI_VDEVICE(INTEL
, PCI_DEVICE_ID_PCH1_PHUB
), 1, },
876 { PCI_VDEVICE(ROHM
, PCI_DEVICE_ID_ROHM_ML7213_PHUB
), 2, },
877 { PCI_VDEVICE(ROHM
, PCI_DEVICE_ID_ROHM_ML7223_mPHUB
), 3, },
878 { PCI_VDEVICE(ROHM
, PCI_DEVICE_ID_ROHM_ML7223_nPHUB
), 4, },
879 { PCI_VDEVICE(ROHM
, PCI_DEVICE_ID_ROHM_ML7831_PHUB
), 5, },
882 MODULE_DEVICE_TABLE(pci
, pch_phub_pcidev_id
);
884 static struct pci_driver pch_phub_driver
= {
886 .id_table
= pch_phub_pcidev_id
,
887 .probe
= pch_phub_probe
,
888 .remove
= pch_phub_remove
,
889 .suspend
= pch_phub_suspend
,
890 .resume
= pch_phub_resume
893 module_pci_driver(pch_phub_driver
);
895 MODULE_DESCRIPTION("Intel EG20T PCH/LAPIS Semiconductor IOH(ML7213/ML7223) PHUB");
896 MODULE_LICENSE("GPL");