blob: 16025f128dc4d24d3b1c0a2fbb902faa315f93f2 [file] [log] [blame]
Alexandru Gagniuc67f556c2012-08-10 03:55:42 -05001/*
2 * viatool - dump all registers on a VIA CPU + chipset based system.
3 *
4 * Copyright (C) 2013 Alexandru Gagniuc
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (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.
Alexandru Gagniuc67f556c2012-08-10 03:55:42 -050015 */
16
17#include "quirks.h"
18
19#include <stdio.h>
20
21typedef u8 sata_phy_config[64];
22
23static u32 sata_phy_read32(struct pci_dev *dev, u8 index)
24{
25 /* The SATA PHY control registers are accessed by a funny index/value
26 * scheme. Each byte (0,1,2,3) has its own 4-bit index */
27 index = (index >> 2) & 0xf;
28 u16 i16 = index | (index << 4) | (index << 8)| (index << 12);
29 /* The index */
30 pci_write_word(dev, 0x68, i16);
31 /* The value */
32 return pci_read_long(dev, 0x64);
33}
34
35static void vx900_sata_read_phy_config(struct pci_dev *dev, sata_phy_config cfg)
36{
37 size_t i;
38 u32* data = (u32*)cfg;
39 for (i = 0; i < ( sizeof(sata_phy_config) ) >> 2; i++) {
40 data[i] = sata_phy_read32(dev, i<<2);
41 }
42}
43
44static int quirk_vx900_sata(struct pci_dev *dev)
45{
46 sata_phy_config ephy;
47
48 /* Get all the info in one pass */
49 vx900_sata_read_phy_config(dev, ephy);
50
51 /* Put it on the terminal for the user to read and be done with it */
52 printf("SATA PHY config:\n");
53 unsigned int i;
54 for (i = 0; i < sizeof(sata_phy_config); i++) {
55 if ((i & 0x0f) == 0) {
56 printf("%.2x :", i);
57 }
58 if( (i & 0x0f) == 0x08 )
59 printf("| ");
60 printf("%.2x ", ephy[i]);
61 if ((i & 0x0f) == 0x0f) {
62 printf("\n");
63 }
64 }
65 return 0;
66}
67
68
69
70
71static struct quirk vx900_sb_quirks[] = {
72 {0, 0, 0x0f, 0, PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_VX900_SATA,
73 quirk_vx900_sata },
74 {0, 0, 0, 0, 0, 0, 0},
75};
76
77struct quirk_list vx900_sb_quirk_list = {
78 .pci_vendor_id = PCI_VENDOR_ID_VIA,
79 .pci_device_id = PCI_DEVICE_ID_VIA_VX900_LPC,
80 .dev_quirks = vx900_sb_quirks
81};