ata-jmicron.c (199322) | ata-jmicron.c (200171) |
---|---|
1/*- 2 * Copyright (c) 1998 - 2008 S�ren Schmidt <sos@FreeBSD.org> 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 11 unchanged lines hidden (view full) --- 20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 */ 26 27#include <sys/cdefs.h> | 1/*- 2 * Copyright (c) 1998 - 2008 S�ren Schmidt <sos@FreeBSD.org> 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 11 unchanged lines hidden (view full) --- 20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 */ 26 27#include <sys/cdefs.h> |
28__FBSDID("$FreeBSD: head/sys/dev/ata/chipsets/ata-jmicron.c 199322 2009-11-16 15:38:27Z mav $"); | 28__FBSDID("$FreeBSD: head/sys/dev/ata/chipsets/ata-jmicron.c 200171 2009-12-06 00:10:13Z mav $"); |
29 30#include "opt_ata.h" 31#include <sys/param.h> 32#include <sys/module.h> 33#include <sys/systm.h> 34#include <sys/kernel.h> 35#include <sys/ata.h> 36#include <sys/bus.h> --- 11 unchanged lines hidden (view full) --- 48#include <dev/pci/pcivar.h> 49#include <dev/pci/pcireg.h> 50#include <dev/ata/ata-all.h> 51#include <dev/ata/ata-pci.h> 52#include <ata_if.h> 53 54/* local prototypes */ 55static int ata_jmicron_chipinit(device_t dev); | 29 30#include "opt_ata.h" 31#include <sys/param.h> 32#include <sys/module.h> 33#include <sys/systm.h> 34#include <sys/kernel.h> 35#include <sys/ata.h> 36#include <sys/bus.h> --- 11 unchanged lines hidden (view full) --- 48#include <dev/pci/pcivar.h> 49#include <dev/pci/pcireg.h> 50#include <dev/ata/ata-all.h> 51#include <dev/ata/ata-pci.h> 52#include <ata_if.h> 53 54/* local prototypes */ 55static int ata_jmicron_chipinit(device_t dev); |
56static void ata_jmicron_setmode(device_t dev, int mode); | 56static int ata_jmicron_ch_attach(device_t dev); 57static int ata_jmicron_setmode(device_t dev, int target, int mode); |
57 58/* 59 * JMicron chipset support functions 60 */ 61static int 62ata_jmicron_probe(device_t dev) 63{ 64 struct ata_pci_controller *ctlr = device_get_softc(dev); --- 9 unchanged lines hidden (view full) --- 74 char buffer[64]; 75 76 if (pci_get_vendor(dev) != ATA_JMICRON_ID) 77 return ENXIO; 78 79 if (!(idx = ata_match_chip(dev, ids))) 80 return ENXIO; 81 | 58 59/* 60 * JMicron chipset support functions 61 */ 62static int 63ata_jmicron_probe(device_t dev) 64{ 65 struct ata_pci_controller *ctlr = device_get_softc(dev); --- 9 unchanged lines hidden (view full) --- 75 char buffer[64]; 76 77 if (pci_get_vendor(dev) != ATA_JMICRON_ID) 78 return ENXIO; 79 80 if (!(idx = ata_match_chip(dev, ids))) 81 return ENXIO; 82 |
82 if ((pci_read_config(dev, 0xdf, 1) & 0x40) && 83 (pci_get_function(dev) == (pci_read_config(dev, 0x40, 1) & 0x02 >> 1))) 84 sprintf(buffer, "JMicron %s %s controller", 85 idx->text, ata_mode2str(ATA_UDMA6)); 86 else 87 sprintf(buffer, "JMicron %s %s controller", 88 idx->text, ata_mode2str(idx->max_dma)); | 83 sprintf(buffer, "JMicron %s %s controller", 84 idx->text, ata_mode2str(idx->max_dma)); |
89 device_set_desc_copy(dev, buffer); 90 ctlr->chip = idx; 91 ctlr->chipinit = ata_jmicron_chipinit; 92 return (BUS_PROBE_DEFAULT); 93} 94 95static int 96ata_jmicron_chipinit(device_t dev) --- 6 unchanged lines hidden (view full) --- 103 104 /* do we have multiple PCI functions ? */ 105 if (pci_read_config(dev, 0xdf, 1) & 0x40) { 106 /* are we on the AHCI part ? */ 107 if (ata_ahci_chipinit(dev) != ENXIO) 108 return 0; 109 110 /* otherwise we are on the PATA part */ | 85 device_set_desc_copy(dev, buffer); 86 ctlr->chip = idx; 87 ctlr->chipinit = ata_jmicron_chipinit; 88 return (BUS_PROBE_DEFAULT); 89} 90 91static int 92ata_jmicron_chipinit(device_t dev) --- 6 unchanged lines hidden (view full) --- 99 100 /* do we have multiple PCI functions ? */ 101 if (pci_read_config(dev, 0xdf, 1) & 0x40) { 102 /* are we on the AHCI part ? */ 103 if (ata_ahci_chipinit(dev) != ENXIO) 104 return 0; 105 106 /* otherwise we are on the PATA part */ |
111 ctlr->ch_attach = ata_pci_ch_attach; | 107 ctlr->ch_attach = ata_jmicron_ch_attach; |
112 ctlr->ch_detach = ata_pci_ch_detach; 113 ctlr->reset = ata_generic_reset; 114 ctlr->setmode = ata_jmicron_setmode; 115 ctlr->channels = ctlr->chip->cfg2; 116 } 117 else { 118 /* set controller configuration to a combined setup we support */ 119 pci_write_config(dev, 0x40, 0x80c0a131, 4); 120 pci_write_config(dev, 0x80, 0x01200000, 4); 121 /* Create AHCI subdevice if AHCI part present. */ 122 if (ctlr->chip->cfg1) { 123 child = device_add_child(dev, NULL, -1); 124 if (child != NULL) { 125 device_set_ivars(child, (void *)(intptr_t)-1); 126 bus_generic_attach(dev); 127 } 128 } | 108 ctlr->ch_detach = ata_pci_ch_detach; 109 ctlr->reset = ata_generic_reset; 110 ctlr->setmode = ata_jmicron_setmode; 111 ctlr->channels = ctlr->chip->cfg2; 112 } 113 else { 114 /* set controller configuration to a combined setup we support */ 115 pci_write_config(dev, 0x40, 0x80c0a131, 4); 116 pci_write_config(dev, 0x80, 0x01200000, 4); 117 /* Create AHCI subdevice if AHCI part present. */ 118 if (ctlr->chip->cfg1) { 119 child = device_add_child(dev, NULL, -1); 120 if (child != NULL) { 121 device_set_ivars(child, (void *)(intptr_t)-1); 122 bus_generic_attach(dev); 123 } 124 } |
129 ctlr->ch_attach = ata_pci_ch_attach; | 125 ctlr->ch_attach = ata_jmicron_ch_attach; |
130 ctlr->ch_detach = ata_pci_ch_detach; 131 ctlr->reset = ata_generic_reset; 132 ctlr->setmode = ata_jmicron_setmode; 133 ctlr->channels = ctlr->chip->cfg2; 134 } 135 return 0; 136} 137 | 126 ctlr->ch_detach = ata_pci_ch_detach; 127 ctlr->reset = ata_generic_reset; 128 ctlr->setmode = ata_jmicron_setmode; 129 ctlr->channels = ctlr->chip->cfg2; 130 } 131 return 0; 132} 133 |
138static void 139ata_jmicron_setmode(device_t dev, int mode) | 134static int 135ata_jmicron_ch_attach(device_t dev) |
140{ | 136{ |
141 struct ata_device *atadev = device_get_softc(dev); | 137 struct ata_channel *ch = device_get_softc(dev); 138 int error; 139 140 error = ata_pci_ch_attach(dev); 141 ch->flags |= ATA_CHECKS_CABLE; 142 return (error); 143} |
142 | 144 |
145static int 146ata_jmicron_setmode(device_t dev, int target, int mode) 147{ 148 struct ata_pci_controller *ctlr = device_get_softc(device_get_parent(dev)); 149 150 mode = min(mode, ctlr->chip->max_dma); |
|
143 /* check for 80pin cable present */ | 151 /* check for 80pin cable present */ |
144 if (pci_read_config(dev, 0x40, 1) & 0x08) 145 mode = ata_limit_mode(dev, mode, ATA_UDMA2); 146 else 147 mode = ata_limit_mode(dev, mode, ATA_UDMA6); 148 if (!ata_controlcmd(dev, ATA_SETFEATURES, ATA_SF_SETXFER, 0, mode)) 149 atadev->mode = mode; | 152 if (mode > ATA_UDMA2 && pci_read_config(dev, 0x40, 1) & 0x08) { 153 ata_print_cable(dev, "controller"); 154 mode = ATA_UDMA2; 155 } 156 /* Nothing to do to setup mode, the controller snoop SET_FEATURE cmd. */ 157 return (mode); |
150} 151 152ATA_DECLARE_DRIVER(ata_jmicron); 153MODULE_DEPEND(ata_jmicron, ata_ahci, 1, 1, 1); | 158} 159 160ATA_DECLARE_DRIVER(ata_jmicron); 161MODULE_DEPEND(ata_jmicron, ata_ahci, 1, 1, 1); |