18 #include <linux/module.h>
19 #include <linux/kernel.h>
20 #include <linux/types.h>
23 #include <linux/string.h>
24 #include <linux/pci.h>
28 #include <linux/if_ether.h>
29 #include <linux/ctype.h>
32 #define PHUB_STATUS 0x00
33 #define PHUB_CONTROL 0x04
34 #define PHUB_TIMEOUT 0x05
35 #define PCH_PHUB_ROM_WRITE_ENABLE 0x01
36 #define PCH_PHUB_ROM_WRITE_DISABLE 0x00
37 #define PCH_PHUB_MAC_START_ADDR_EG20T 0x14
39 #define PCH_PHUB_MAC_START_ADDR_ML7223 0x20C
41 #define PCH_PHUB_ROM_START_ADDR_EG20T 0x80
43 #define PCH_PHUB_ROM_START_ADDR_ML7213 0x400
46 #define PCH_PHUB_ROM_START_ADDR_ML7223 0x400
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)
65 #define PCI_VENDOR_ID_ROHM 0x10db
66 #define PCI_DEVICE_ID_ROHM_ML7213_PHUB 0x801A
69 #define PCI_DEVICE_ID_ROHM_ML7223_mPHUB 0x8012
70 #define PCI_DEVICE_ID_ROHM_ML7223_nPHUB 0x8002
73 #define PCI_DEVICE_ID_ROHM_ML7831_PHUB 0x8801
76 #define PCH_WORD_ADDR_MASK (~((1 << 2) - 1))
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
143 static const int pch_phub_mac_offset[
ETH_ALEN] = {0x3, 0x2, 0x1, 0x0, 0xb, 0xa};
154 unsigned int reg_addr_offset,
155 unsigned int data,
unsigned int mask)
162 static void pch_phub_save_reg_conf(
struct pci_dev *pdev)
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__,
214 "chip->int_reduce_control_reg[%d]=%x\n",
223 static void pch_phub_restore_reg_conf(
struct pci_dev *pdev)
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__,
275 "chip->int_reduce_control_reg[%d]=%x\n",
289 static void pch_phub_read_serial_rom(
struct pch_phub_reg *chip,
290 unsigned int offset_address,
u8 *data)
303 static int pch_phub_write_serial_rom(
struct pch_phub_reg *chip,
304 unsigned int offset_address,
u8 data)
309 unsigned int word_data;
312 pos = (offset_address % 4) * 8;
313 mask = ~(0xFF <<
pos);
319 iowrite32((word_data & mask) | (
u32)data << pos, mem_addr);
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;
347 pch_phub_mac_offset[offset_address];
349 pch_phub_read_serial_rom(chip, mem_addr, data);
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;
364 pch_phub_mac_offset[offset_address];
366 retval = pch_phub_write_serial_rom(chip, mem_addr, data);
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);
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);
458 static void pch_phub_read_gbe_mac_addr(
struct pch_phub_reg *chip,
u8 *data)
462 pch_phub_read_serial_rom_val(chip, i, &data[i]);
470 static int pch_phub_write_gbe_mac_addr(
struct pch_phub_reg *chip,
u8 *data)
476 retval = pch_phub_gbe_serial_rom_conf(chip);
478 retval = pch_phub_gbe_serial_rom_conf_mp(chip);
483 retval = pch_phub_write_serial_rom_val(chip, i, data[i]);
493 loff_t off,
size_t count)
495 unsigned int rom_signature;
498 unsigned int addr_offset;
499 unsigned int orom_size;
510 goto return_err_nomutex;
519 (
unsigned char *)&rom_signature);
520 rom_signature &= 0xff;
522 (
unsigned char *)&tmp);
523 rom_signature |= (tmp & 0xff) << 8;
524 if (rom_signature == 0xAA55) {
525 pch_phub_read_serial_rom(chip,
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,
562 char *buf, loff_t off,
size_t count)
565 unsigned int addr_offset;
590 for (addr_offset = 0; addr_offset <
count; addr_offset++) {
594 ret = pch_phub_write_serial_rom(chip,
627 pch_phub_read_gbe_mac_addr(chip, mac);
630 return sprintf(buf,
"%pM\n", mac);
634 const char *buf,
size_t count)
643 sscanf(buf,
"%02x:%02x:%02x:%02x:%02x:%02x",
644 (
u32 *)&mac[0], (
u32 *)&mac[1], (
u32 *)&mac[2], (
u32 *)&mac[3],
645 (
u32 *)&mac[4], (
u32 *)&mac[5]);
651 pch_phub_write_gbe_mac_addr(chip, mac);
661 .name =
"pch_firmware",
665 .read = pch_phub_bin_read,
666 .write = pch_phub_bin_write,
684 "%s : pci_enable_device FAILED(ret=%d)", __func__, ret);
685 goto err_pci_enable_dev;
687 dev_dbg(&pdev->
dev,
"%s : pci_enable_device returns %d\n", __func__,
693 "%s : pci_request_regions FAILED(ret=%d)", __func__, ret);
694 goto err_req_regions;
697 "pci_request_regions returns %d\n", __func__, ret);
703 dev_err(&pdev->
dev,
"%s : pci_iomap FAILED", __func__);
707 dev_dbg(&pdev->
dev,
"%s : pci_iomap SUCCESS and value "
708 "in pch_phub_base_address variable is %p\n", __func__,
714 const char *board_name;
717 &dev_attr_pch_mac.attr);
719 goto err_sysfs_create;
725 pch_phub_read_modify_write_reg(chip,
732 if (board_name &&
strstr(board_name,
"CM-iTC"))
733 pch_phub_read_modify_write_reg(chip,
748 goto err_sysfs_create;
757 PCH_PHUB_ROM_START_ADDR_ML7213;
766 PCH_PHUB_ROM_START_ADDR_ML7223;
770 &dev_attr_pch_mac.attr);
772 goto err_sysfs_create;
783 PCH_PHUB_ROM_START_ADDR_ML7223;
787 &dev_attr_pch_mac.attr);
789 goto err_sysfs_create;
804 pci_set_drvdata(pdev, chip);
818 dev_err(&pdev->
dev,
"%s returns %d\n", __func__, ret);
840 pch_phub_save_reg_conf(pdev);
844 " %s -pci_save_state returns %d\n", __func__, ret);
863 "%s-pci_enable_device failed(ret=%d) ", __func__, ret);
868 pch_phub_restore_reg_conf(pdev);
873 #define pch_phub_suspend NULL
874 #define pch_phub_resume NULL
889 .id_table = pch_phub_pcidev_id,
890 .probe = pch_phub_probe,