Merge branch 'integrity-check-patch-v2' of git://btrfs.giantdisaster.de/git/btrfs...
[firefly-linux-kernel-4.4.55.git] / drivers / staging / rtl8192e / rtl_pci.c
1 /******************************************************************************
2  * Copyright(c) 2008 - 2010 Realtek Corporation. All rights reserved.
3  *
4  * Based on the r8180 driver, which is:
5  * Copyright 2004-2005 Andrea Merello <andreamrl@tiscali.it>, et al.
6  * This program is free software; you can redistribute it and/or modify it
7  * under the terms of version 2 of the GNU General Public License as
8  * published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful, but WITHOUT
11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
13  * more details.
14  *
15  * You should have received a copy of the GNU General Public License along with
16  * this program; if not, write to the Free Software Foundation, Inc.,
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
18  *
19  * The full GNU General Public License is included in this distribution in the
20  * file called LICENSE.
21  *
22  * Contact Information:
23  * wlanfae <wlanfae@realtek.com>
24  *****************************************************************************/
25 #include "rtl_pci.h"
26 #include "rtl_core.h"
27
28 static void rtl8192_parse_pci_configuration(struct pci_dev *pdev,
29                                             struct net_device *dev)
30 {
31         struct r8192_priv *priv = (struct r8192_priv *)rtllib_priv(dev);
32
33         u8 tmp;
34         int pos;
35         u8 LinkCtrlReg;
36
37         pos = pci_find_capability(priv->pdev, PCI_CAP_ID_EXP);
38         pci_read_config_byte(priv->pdev, pos + PCI_EXP_LNKCTL, &LinkCtrlReg);
39         priv->NdisAdapter.LinkCtrlReg = LinkCtrlReg;
40
41         RT_TRACE(COMP_INIT, "Link Control Register =%x\n",
42                  priv->NdisAdapter.LinkCtrlReg);
43
44         pci_read_config_byte(pdev, 0x98, &tmp);
45         tmp |= BIT4;
46         pci_write_config_byte(pdev, 0x98, tmp);
47
48         tmp = 0x17;
49         pci_write_config_byte(pdev, 0x70f, tmp);
50 }
51
52 bool rtl8192_pci_findadapter(struct pci_dev *pdev, struct net_device *dev)
53 {
54         struct r8192_priv *priv = (struct r8192_priv *)rtllib_priv(dev);
55         u16 VenderID;
56         u16 DeviceID;
57         u8  RevisionID;
58         u16 IrqLine;
59
60         VenderID = pdev->vendor;
61         DeviceID = pdev->device;
62         RevisionID = pdev->revision;
63         pci_read_config_word(pdev, 0x3C, &IrqLine);
64
65         priv->card_8192 = priv->ops->nic_type;
66
67         if (DeviceID == 0x8172) {
68                 switch (RevisionID) {
69                 case HAL_HW_PCI_REVISION_ID_8192PCIE:
70                         printk(KERN_INFO "Adapter(8192 PCI-E) is found - "
71                                "DeviceID=%x\n", DeviceID);
72                         priv->card_8192 = NIC_8192E;
73                         break;
74                 case HAL_HW_PCI_REVISION_ID_8192SE:
75                         printk(KERN_INFO "Adapter(8192SE) is found - "
76                                "DeviceID=%x\n", DeviceID);
77                         priv->card_8192 = NIC_8192SE;
78                         break;
79                 default:
80                         printk(KERN_INFO "UNKNOWN nic type(%4x:%4x)\n",
81                                pdev->vendor, pdev->device);
82                         priv->card_8192 = NIC_UNKNOWN;
83                         return false;
84                 }
85         }
86
87         if (priv->ops->nic_type != priv->card_8192) {
88                 printk(KERN_INFO "Detect info(%x) and hardware info(%x) not match!\n",
89                                 priv->ops->nic_type, priv->card_8192);
90                 printk(KERN_INFO "Please select proper driver before install!!!!\n");
91                 return false;
92         }
93
94         rtl8192_parse_pci_configuration(pdev, dev);
95
96         return true;
97 }