ata-cyrix.c (10b3b54548f2290bbe8d8f88c59c28d12b7a635d) ata-cyrix.c (066f913a94b134b6d5e32b6af88f297c7da9c031)
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

--- 39 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_cyrix_chipinit(device_t dev);
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

--- 39 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_cyrix_chipinit(device_t dev);
56static void ata_cyrix_setmode(device_t dev, int mode);
56static int ata_cyrix_ch_attach(device_t dev);
57static int ata_cyrix_setmode(device_t dev, int target, int mode);
57
58
59/*
60 * Cyrix chipset support functions
61 */
62static int
63ata_cyrix_probe(device_t dev)
64{

--- 9 unchanged lines hidden (view full) ---

74
75static int
76ata_cyrix_chipinit(device_t dev)
77{
78 struct ata_pci_controller *ctlr = device_get_softc(dev);
79
80 if (ata_setup_interrupt(dev, ata_generic_intr))
81 return ENXIO;
58
59
60/*
61 * Cyrix chipset support functions
62 */
63static int
64ata_cyrix_probe(device_t dev)
65{

--- 9 unchanged lines hidden (view full) ---

75
76static int
77ata_cyrix_chipinit(device_t dev)
78{
79 struct ata_pci_controller *ctlr = device_get_softc(dev);
80
81 if (ata_setup_interrupt(dev, ata_generic_intr))
82 return ENXIO;
82
83 ctlr->ch_attach = ata_cyrix_ch_attach;
83 ctlr->setmode = ata_cyrix_setmode;
84 return 0;
85}
86
84 ctlr->setmode = ata_cyrix_setmode;
85 return 0;
86}
87
87static void
88ata_cyrix_setmode(device_t dev, int mode)
88static int
89ata_cyrix_ch_attach(device_t dev)
89{
90{
90 struct ata_pci_controller *ctlr = device_get_softc(GRANDPARENT(dev));
91 struct ata_channel *ch = device_get_softc(device_get_parent(dev));
92 struct ata_device *atadev = device_get_softc(dev);
93 int devno = (ch->unit << 1) + atadev->unit;
94 u_int32_t piotiming[] =
95 { 0x00009172, 0x00012171, 0x00020080, 0x00032010, 0x00040010 };
96 u_int32_t dmatiming[] = { 0x00077771, 0x00012121, 0x00002020 };
97 u_int32_t udmatiming[] = { 0x00921250, 0x00911140, 0x00911030 };
98 int error;
91 struct ata_channel *ch = device_get_softc(dev);
92 int error;
93
94 error = ata_pci_ch_attach(dev);
95 ch->dma.alignment = 16;
96 ch->dma.max_iosize = 64 * DEV_BSIZE;
97 return (error);
98}
99
99
100 mode = ata_limit_mode(dev, mode, ATA_UDMA2);
101
100
102 error = ata_controlcmd(dev, ATA_SETFEATURES, ATA_SF_SETXFER, 0, mode);
101static int
102ata_cyrix_setmode(device_t dev, int target, int mode)
103{
104 struct ata_pci_controller *ctlr = device_get_softc(device_get_parent(dev));
105 struct ata_channel *ch = device_get_softc(dev);
106 int devno = (ch->unit << 1) + target;
107 int piomode;
108 u_int32_t piotiming[] =
109 { 0x00009172, 0x00012171, 0x00020080, 0x00032010, 0x00040010 };
110 u_int32_t dmatiming[] = { 0x00077771, 0x00012121, 0x00002020 };
111 u_int32_t udmatiming[] = { 0x00921250, 0x00911140, 0x00911030 };
103
112
104 if (bootverbose)
105 device_printf(dev, "%ssetting %s on Cyrix chip\n",
106 (error) ? "FAILURE " : "", ata_mode2str(mode));
107
108 if (!error) {
113 mode = min(mode, ATA_UDMA2);
109 /* dont try to set the mode if we dont have the resource */
110 if (ctlr->r_res1) {
114 /* dont try to set the mode if we dont have the resource */
115 if (ctlr->r_res1) {
111 ch->dma.alignment = 16;
112 ch->dma.max_iosize = 64 * DEV_BSIZE;
113
114 if (mode >= ATA_UDMA0) {
116 if (mode >= ATA_UDMA0) {
117 /* Set UDMA timings, and PIO4. */
118 ATA_OUTL(ch->r_io[ATA_BMCMD_PORT].res,
119 0x24 + (devno << 3), udmatiming[mode & ATA_MODE_MASK]);
120 piomode = ATA_PIO4;
121 } else if (mode >= ATA_WDMA0) {
122 /* Set WDMA timings, and respective PIO mode. */
123 ATA_OUTL(ch->r_io[ATA_BMCMD_PORT].res,
124 0x24 + (devno << 3), dmatiming[mode & ATA_MODE_MASK]);
125 piomode = (mode == ATA_WDMA0) ? ATA_PIO0 :
126 (mode == ATA_WDMA1) ? ATA_PIO3 : ATA_PIO4;
127 } else
128 piomode = mode;
129 /* Set PIO mode calculated above. */
115 ATA_OUTL(ch->r_io[ATA_BMCMD_PORT].res,
130 ATA_OUTL(ch->r_io[ATA_BMCMD_PORT].res,
116 0x24 + (devno << 3), udmatiming[mode & ATA_MODE_MASK]);
117 }
118 else if (mode >= ATA_WDMA0) {
119 ATA_OUTL(ch->r_io[ATA_BMCMD_PORT].res,
120 0x24 + (devno << 3), dmatiming[mode & ATA_MODE_MASK]);
121 }
122 else {
123 ATA_OUTL(ch->r_io[ATA_BMCMD_PORT].res,
124 0x20 + (devno << 3), piotiming[mode & ATA_MODE_MASK]);
125 }
131 0x20 + (devno << 3), piotiming[ata_mode2idx(piomode)]);
126 }
132 }
127 atadev->mode = mode;
128 }
133 return (mode);
129}
130
131ATA_DECLARE_DRIVER(ata_cyrix);
134}
135
136ATA_DECLARE_DRIVER(ata_cyrix);