blob: c6341ed702d92b5543fada1184dc4996e6f23c94 [file] [log] [blame]
Uwe Hermannb4dcb712009-05-13 11:36:06 +00001/*
2 * This file is part of the flashrom project.
3 *
4 * Copyright (C) 2009 Uwe Hermann <uwe@hermann-uwe.de>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21#include <stdlib.h>
22#include <string.h>
Uwe Hermann92c53ee2009-05-13 12:01:57 +000023#include <fcntl.h>
24#include <sys/types.h>
25#include <sys/stat.h>
Uwe Hermannb4dcb712009-05-13 11:36:06 +000026#include <errno.h>
Uwe Hermannb4dcb712009-05-13 11:36:06 +000027#include "flash.h"
28
29#define BIOS_ROM_ADDR 0x04
30#define BIOS_ROM_DATA 0x08
31#define INT_STATUS 0x0e
Uwe Hermann8403ccb2009-05-16 21:39:19 +000032#define INTERNAL_CONFIG 0x00
Uwe Hermannb4dcb712009-05-13 11:36:06 +000033#define SELECT_REG_WINDOW 0x800
34
Uwe Hermannb4dcb712009-05-13 11:36:06 +000035#define PCI_VENDOR_ID_3COM 0x10b7
36
Uwe Hermann8403ccb2009-05-16 21:39:19 +000037uint32_t internal_conf;
38uint16_t id;
39
Uwe Hermann515ab3d2009-05-15 17:02:34 +000040struct pcidev_status nics_3com[] = {
Uwe Hermannb4dcb712009-05-13 11:36:06 +000041 /* 3C90xB */
Uwe Hermann8403ccb2009-05-16 21:39:19 +000042 {0x10b7, 0x9055, PCI_OK, "3COM", "3C90xB: PCI 10/100 Mbps; shared 10BASE-T/100BASE-TX"},
Uwe Hermann515ab3d2009-05-15 17:02:34 +000043 {0x10b7, 0x9001, PCI_NT, "3COM", "3C90xB: PCI 10/100 Mbps; shared 10BASE-T/100BASE-T4" },
44 {0x10b7, 0x9004, PCI_NT, "3COM", "3C90xB: PCI 10BASE-T (TPO)" },
45 {0x10b7, 0x9005, PCI_NT, "3COM", "3C90xB: PCI 10BASE-T/10BASE2/AUI (COMBO)" },
46 {0x10b7, 0x9006, PCI_NT, "3COM", "3C90xB: PCI 10BASE-T/10BASE2 (TPC)" },
47 {0x10b7, 0x900a, PCI_NT, "3COM", "3C90xB: PCI 10BASE-FL" },
48 {0x10b7, 0x905a, PCI_NT, "3COM", "3C90xB: PCI 10BASE-FX" },
Uwe Hermannb4dcb712009-05-13 11:36:06 +000049
50 /* 3C905C */
Uwe Hermann515ab3d2009-05-15 17:02:34 +000051 {0x10b7, 0x9200, PCI_OK, "3COM", "3C905C: EtherLink 10/100 PCI (TX)" },
Uwe Hermannb4dcb712009-05-13 11:36:06 +000052
53 /* 3C980C */
Uwe Hermann515ab3d2009-05-15 17:02:34 +000054 {0x10b7, 0x9805, PCI_NT, "3COM", "3C980C: EtherLink Server 10/100 PCI (TX)" },
Uwe Hermannb4dcb712009-05-13 11:36:06 +000055
56 {},
57};
58
59int nic3com_init(void)
60{
Uwe Hermanna0869322009-05-14 20:41:57 +000061 get_io_perms();
Uwe Hermannb4dcb712009-05-13 11:36:06 +000062
Uwe Hermann515ab3d2009-05-15 17:02:34 +000063 io_base_addr = pcidev_init(PCI_VENDOR_ID_3COM, nics_3com);
Uwe Hermann8403ccb2009-05-16 21:39:19 +000064 id = pcidev_dev->device_id;
65
66 /* 3COM 3C90xB cards need a special fixup. */
67 if (id == 0x9055 || id == 0x9001 || id == 0x9004 || id == 0x9005
68 || id == 0x9006 || id == 0x900a || id == 0x905a) {
69 /* Select register window 3 and save the receiver status. */
70 OUTW(SELECT_REG_WINDOW + 3, io_base_addr + INT_STATUS);
71 internal_conf = INL(io_base_addr + INTERNAL_CONFIG);
72
73 /* Set receiver type to MII for full BIOS ROM access. */
74 OUTL((internal_conf & 0xf00fffff) | 0x00600000, io_base_addr);
75 }
Uwe Hermannb4dcb712009-05-13 11:36:06 +000076
77 /*
78 * The lowest 16 bytes of the I/O mapped register space of (most) 3COM
79 * cards form a 'register window' into one of multiple (usually 8)
80 * register banks. For 3C90xB/3C90xC we need register window/bank 0.
81 */
82 OUTW(SELECT_REG_WINDOW + 0, io_base_addr + INT_STATUS);
83
84 return 0;
85}
86
87int nic3com_shutdown(void)
88{
Uwe Hermann8403ccb2009-05-16 21:39:19 +000089 /* 3COM 3C90xB cards need a special fixup. */
90 if (id == 0x9055 || id == 0x9001 || id == 0x9004 || id == 0x9005
91 || id == 0x9006 || id == 0x900a || id == 0x905a) {
92 /* Select register window 3 and restore the receiver status. */
93 OUTW(SELECT_REG_WINDOW + 3, io_base_addr + INT_STATUS);
94 OUTL(internal_conf, io_base_addr + INTERNAL_CONFIG);
95 }
96
Uwe Hermann515ab3d2009-05-15 17:02:34 +000097 free(pcidev_bdf);
Christian Ruppert0cdb0312009-05-14 18:57:26 +000098 pci_cleanup(pacc);
Uwe Hermanna0869322009-05-14 20:41:57 +000099#if defined(__FreeBSD__) || defined(__DragonFly__)
100 close(io_fd);
101#endif
Uwe Hermannb4dcb712009-05-13 11:36:06 +0000102 return 0;
103}
104
Carl-Daniel Hailfinger5820f422009-05-16 21:22:56 +0000105void nic3com_chip_writeb(uint8_t val, chipaddr addr)
Uwe Hermannb4dcb712009-05-13 11:36:06 +0000106{
Carl-Daniel Hailfinger5820f422009-05-16 21:22:56 +0000107 OUTL((uint32_t)addr, io_base_addr + BIOS_ROM_ADDR);
Uwe Hermannb4dcb712009-05-13 11:36:06 +0000108 OUTB(val, io_base_addr + BIOS_ROM_DATA);
109}
110
Carl-Daniel Hailfinger5820f422009-05-16 21:22:56 +0000111uint8_t nic3com_chip_readb(const chipaddr addr)
Uwe Hermannb4dcb712009-05-13 11:36:06 +0000112{
Carl-Daniel Hailfinger5820f422009-05-16 21:22:56 +0000113 OUTL((uint32_t)addr, io_base_addr + BIOS_ROM_ADDR);
Uwe Hermannc7e8a0c2009-05-19 14:14:21 +0000114 return INB(io_base_addr + BIOS_ROM_DATA);
Uwe Hermannb4dcb712009-05-13 11:36:06 +0000115}