blob: f555c08427a66eac0ce27f55014056445e3b2100 [file] [log] [blame]
stroese771e05b2004-12-16 18:21:17 +00001/*
2 * (C) Copyright 2000
3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
4 *
Wolfgang Denk1a459662013-07-08 09:37:19 +02005 * SPDX-License-Identifier: GPL-2.0+
stroese771e05b2004-12-16 18:21:17 +00006 */
7/* ide.c - ide support functions */
8
9
10#include <common.h>
Jon Loeliger77a31852007-07-10 10:39:10 -050011#if defined(CONFIG_CMD_IDE)
stroese771e05b2004-12-16 18:21:17 +000012#include <ata.h>
13#include <ide.h>
14#include <pci.h>
15
Reinhard Arlt2b224602011-11-10 08:51:57 +000016int cpci_hd_type;
17
18int ata_device(int dev)
19{
20 int retval;
21
22 retval = (dev & 1) << 4;
23 if (cpci_hd_type == 2)
24 retval ^= 1 << 4;
25 return retval;
26}
27
stroese771e05b2004-12-16 18:21:17 +000028
wdenkefe2a4d2004-12-16 21:44:03 +000029int ide_preinit (void)
30{
31 int status;
32 pci_dev_t devbusfn;
33 int l;
stroese771e05b2004-12-16 18:21:17 +000034
wdenkefe2a4d2004-12-16 21:44:03 +000035 status = 1;
Reinhard Arlt2b224602011-11-10 08:51:57 +000036 cpci_hd_type = 0;
Stefan Roese58f10462009-06-04 13:35:39 +020037 if (CPCI750_SLAVE_TEST != 0)
38 return status;
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020039 for (l = 0; l < CONFIG_SYS_IDE_MAXBUS; l++) {
wdenkefe2a4d2004-12-16 21:44:03 +000040 ide_bus_offset[l] = -ATA_STATUS;
41 }
42 devbusfn = pci_find_device (0x1103, 0x0004, 0);
Reinhard Arlt2b224602011-11-10 08:51:57 +000043 if (devbusfn != -1) {
44 cpci_hd_type = 1;
45 } else {
Wolfgang Denk93e14592013-10-04 17:43:24 +020046 devbusfn = pci_find_device (0x1095, 0x3114, 0);
Reinhard Arlt2b224602011-11-10 08:51:57 +000047 if (devbusfn != -1) {
48 cpci_hd_type = 2;
49 }
50 }
wdenkefe2a4d2004-12-16 21:44:03 +000051 if (devbusfn != -1) {
Wolfgang Denk97138fc2009-09-11 11:15:31 +020052 ulong *ide_bus_offset_ptr;
53
wdenkefe2a4d2004-12-16 21:44:03 +000054 status = 0;
stroese771e05b2004-12-16 18:21:17 +000055
Wolfgang Denk97138fc2009-09-11 11:15:31 +020056 ide_bus_offset_ptr = &ide_bus_offset[0];
wdenkefe2a4d2004-12-16 21:44:03 +000057 pci_read_config_dword (devbusfn, PCI_BASE_ADDRESS_0,
Wolfgang Denk97138fc2009-09-11 11:15:31 +020058 (u32 *)ide_bus_offset_ptr);
wdenkefe2a4d2004-12-16 21:44:03 +000059 ide_bus_offset[0] &= 0xfffffffe;
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020060 ide_bus_offset[0] += CONFIG_SYS_PCI0_IO_SPACE;
Wolfgang Denk97138fc2009-09-11 11:15:31 +020061 ide_bus_offset_ptr = &ide_bus_offset[1];
wdenkefe2a4d2004-12-16 21:44:03 +000062 pci_read_config_dword (devbusfn, PCI_BASE_ADDRESS_2,
Wolfgang Denk97138fc2009-09-11 11:15:31 +020063 (u32 *)ide_bus_offset_ptr);
wdenkefe2a4d2004-12-16 21:44:03 +000064 ide_bus_offset[1] &= 0xfffffffe;
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020065 ide_bus_offset[1] += CONFIG_SYS_PCI0_IO_SPACE;
wdenkefe2a4d2004-12-16 21:44:03 +000066 }
Stefan Roese58f10462009-06-04 13:35:39 +020067 return status;
wdenkefe2a4d2004-12-16 21:44:03 +000068}
stroese771e05b2004-12-16 18:21:17 +000069
wdenkefe2a4d2004-12-16 21:44:03 +000070void ide_set_reset (int flag) {
71 return;
72}
stroese771e05b2004-12-16 18:21:17 +000073
74#endif /* of CONFIG_CMDS_IDE */