blob: 56e51a5cacbcc57ebf21e30d556ba3f2505cd174 [file] [log] [blame]
Patrick Georgibe61a172010-12-18 07:48:43 +00001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2009-2010 iWave Systems
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 as
Uwe Hermann405721d2010-12-18 13:22:37 +00008 * published by the Free Software Foundation; version 2 of the License.
Patrick Georgibe61a172010-12-18 07:48:43 +00009 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
Patrick Georgibe61a172010-12-18 07:48:43 +000014 */
15
16#include <console/console.h>
17#include <device/device.h>
18#include <device/pci.h>
19#include <device/pci_ids.h>
20
21/* PCI Configuration Space (D31:F1): IDE */
Uwe Hermann405721d2010-12-18 13:22:37 +000022#define INTR_LN 0x3c
23#define IDE_TIM_PRI 0x80 /* IDE timings, primary */
Patrick Georgibe61a172010-12-18 07:48:43 +000024
Uwe Hermann405721d2010-12-18 13:22:37 +000025extern int sch_port_access_read(int port, int reg, int bytes);
26
Patrick Georgibe61a172010-12-18 07:48:43 +000027static void ide_init(struct device *dev)
28{
Uwe Hermann405721d2010-12-18 13:22:37 +000029 u32 ideTimingConfig, reg32;
30
Patrick Georgibe61a172010-12-18 07:48:43 +000031 printk(BIOS_DEBUG, "sch_ide: initializing... ");
32
33 reg32 = pci_read_config32(dev, PCI_COMMAND);
Uwe Hermann405721d2010-12-18 13:22:37 +000034 pci_write_config32(dev, PCI_COMMAND,
35 reg32 | PCI_COMMAND_IO | PCI_COMMAND_MASTER);
Patrick Georgibe61a172010-12-18 07:48:43 +000036
Uwe Hermann405721d2010-12-18 13:22:37 +000037 /* Program the clock. */
38 if (sch_port_access_read(5, 3, 4) & (1 << 3)) {
39 /* 533MHz, Read PCI MC register */
Patrick Georgibe61a172010-12-18 07:48:43 +000040 reg32 = pci_read_config32(dev, 0x60);
Uwe Hermann405721d2010-12-18 13:22:37 +000041 pci_write_config32(dev, 0x60, reg32 | 1);
42 } else {
43 /* 400MHz */
Patrick Georgibe61a172010-12-18 07:48:43 +000044 reg32 = pci_read_config32(dev, 0x60);
Uwe Hermann405721d2010-12-18 13:22:37 +000045 reg32 &= ~1;
46 pci_write_config32(dev, 0x60, reg32);
Patrick Georgibe61a172010-12-18 07:48:43 +000047 }
48
Uwe Hermann405721d2010-12-18 13:22:37 +000049 /* Enable primary IDE interface. 80=04 81=00 82=02 83=80 */
Patrick Georgibe61a172010-12-18 07:48:43 +000050 ideTimingConfig = 0x80020000;
51 printk(BIOS_DEBUG, "IDE0 ");
52 pci_write_config32(dev, IDE_TIM_PRI, ideTimingConfig);
53
Uwe Hermann405721d2010-12-18 13:22:37 +000054 /* Set Interrupt Line. */
Patrick Georgibe61a172010-12-18 07:48:43 +000055 /* Interrupt Pin is set by D31IP.PIP */
56 printk(BIOS_DEBUG, "\n");
57}
58
59static void ide_set_subsystem(device_t dev, unsigned vendor, unsigned device)
60{
61 if (!vendor || !device) {
62 pci_write_config32(dev, PCI_SUBSYSTEM_VENDOR_ID,
Uwe Hermann405721d2010-12-18 13:22:37 +000063 pci_read_config32(dev, PCI_VENDOR_ID));
Patrick Georgibe61a172010-12-18 07:48:43 +000064 } else {
65 pci_write_config32(dev, PCI_SUBSYSTEM_VENDOR_ID,
66 ((device & 0xffff) << 16) | (vendor & 0xffff));
67 }
68}
69
70static struct pci_operations ide_pci_ops = {
Uwe Hermann405721d2010-12-18 13:22:37 +000071 .set_subsystem = ide_set_subsystem,
Patrick Georgibe61a172010-12-18 07:48:43 +000072};
73
74static struct device_operations ide_ops = {
75 .read_resources = pci_dev_read_resources,
76 .set_resources = pci_dev_set_resources,
77 .enable_resources = pci_dev_enable_resources,
78 .init = ide_init,
79 .scan_bus = 0,
80 .ops_pci = &ide_pci_ops,
81};
82
83static const struct pci_driver sch_ide __pci_driver = {
84 .ops = &ide_ops,
85 .vendor = PCI_VENDOR_ID_INTEL,
86 .device = 0x811A,
87};