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