1*4882a593Smuzhiyun // SPDX-License-Identifier: GPL-2.0-only
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun * Copyright (C) 1996 Linus Torvalds & author (see below)
4*4882a593Smuzhiyun */
5*4882a593Smuzhiyun
6*4882a593Smuzhiyun #include <linux/module.h>
7*4882a593Smuzhiyun #include <linux/types.h>
8*4882a593Smuzhiyun #include <linux/kernel.h>
9*4882a593Smuzhiyun #include <linux/delay.h>
10*4882a593Smuzhiyun #include <linux/timer.h>
11*4882a593Smuzhiyun #include <linux/mm.h>
12*4882a593Smuzhiyun #include <linux/ioport.h>
13*4882a593Smuzhiyun #include <linux/blkdev.h>
14*4882a593Smuzhiyun #include <linux/ide.h>
15*4882a593Smuzhiyun #include <linux/init.h>
16*4882a593Smuzhiyun
17*4882a593Smuzhiyun #include <asm/io.h>
18*4882a593Smuzhiyun
19*4882a593Smuzhiyun #define DRV_NAME "dtc2278"
20*4882a593Smuzhiyun
21*4882a593Smuzhiyun /*
22*4882a593Smuzhiyun * Changing this #undef to #define may solve start up problems in some systems.
23*4882a593Smuzhiyun */
24*4882a593Smuzhiyun #undef ALWAYS_SET_DTC2278_PIO_MODE
25*4882a593Smuzhiyun
26*4882a593Smuzhiyun /*
27*4882a593Smuzhiyun * From: andy@cercle.cts.com (Dyan Wile)
28*4882a593Smuzhiyun *
29*4882a593Smuzhiyun * Below is a patch for DTC-2278 - alike software-programmable controllers
30*4882a593Smuzhiyun * The code enables the secondary IDE controller and the PIO4 (3?) timings on
31*4882a593Smuzhiyun * the primary (EIDE). You may probably have to enable the 32-bit support to
32*4882a593Smuzhiyun * get the full speed. You better get the disk interrupts disabled ( hdparm -u0
33*4882a593Smuzhiyun * /dev/hd.. ) for the drives connected to the EIDE interface. (I get my
34*4882a593Smuzhiyun * filesystem corrupted with -u1, but under heavy disk load only :-)
35*4882a593Smuzhiyun *
36*4882a593Smuzhiyun * This card is now forced to use the "serialize" feature,
37*4882a593Smuzhiyun * and irq-unmasking is disallowed. If io_32bit is enabled,
38*4882a593Smuzhiyun * it must be done for BOTH drives on each interface.
39*4882a593Smuzhiyun *
40*4882a593Smuzhiyun * This code was written for the DTC2278E, but might work with any of these:
41*4882a593Smuzhiyun *
42*4882a593Smuzhiyun * DTC2278S has only a single IDE interface.
43*4882a593Smuzhiyun * DTC2278D has two IDE interfaces and is otherwise identical to the S version.
44*4882a593Smuzhiyun * DTC2278E also has serial ports and a printer port
45*4882a593Smuzhiyun * DTC2278EB: has onboard BIOS, and "works like a charm" -- Kent Bradford <kent@theory.caltech.edu>
46*4882a593Smuzhiyun *
47*4882a593Smuzhiyun * There may be a fourth controller type. The S and D versions use the
48*4882a593Smuzhiyun * Winbond chip, and I think the E version does also.
49*4882a593Smuzhiyun *
50*4882a593Smuzhiyun */
51*4882a593Smuzhiyun
sub22(char b,char c)52*4882a593Smuzhiyun static void sub22 (char b, char c)
53*4882a593Smuzhiyun {
54*4882a593Smuzhiyun int i;
55*4882a593Smuzhiyun
56*4882a593Smuzhiyun for(i = 0; i < 3; ++i) {
57*4882a593Smuzhiyun inb(0x3f6);
58*4882a593Smuzhiyun outb_p(b,0xb0);
59*4882a593Smuzhiyun inb(0x3f6);
60*4882a593Smuzhiyun outb_p(c,0xb4);
61*4882a593Smuzhiyun inb(0x3f6);
62*4882a593Smuzhiyun if(inb(0xb4) == c) {
63*4882a593Smuzhiyun outb_p(7,0xb0);
64*4882a593Smuzhiyun inb(0x3f6);
65*4882a593Smuzhiyun return; /* success */
66*4882a593Smuzhiyun }
67*4882a593Smuzhiyun }
68*4882a593Smuzhiyun }
69*4882a593Smuzhiyun
70*4882a593Smuzhiyun static DEFINE_SPINLOCK(dtc2278_lock);
71*4882a593Smuzhiyun
dtc2278_set_pio_mode(ide_hwif_t * hwif,ide_drive_t * drive)72*4882a593Smuzhiyun static void dtc2278_set_pio_mode(ide_hwif_t *hwif, ide_drive_t *drive)
73*4882a593Smuzhiyun {
74*4882a593Smuzhiyun unsigned long flags;
75*4882a593Smuzhiyun
76*4882a593Smuzhiyun if (drive->pio_mode >= XFER_PIO_3) {
77*4882a593Smuzhiyun spin_lock_irqsave(&dtc2278_lock, flags);
78*4882a593Smuzhiyun /*
79*4882a593Smuzhiyun * This enables PIO mode4 (3?) on the first interface
80*4882a593Smuzhiyun */
81*4882a593Smuzhiyun sub22(1,0xc3);
82*4882a593Smuzhiyun sub22(0,0xa0);
83*4882a593Smuzhiyun spin_unlock_irqrestore(&dtc2278_lock, flags);
84*4882a593Smuzhiyun } else {
85*4882a593Smuzhiyun /* we don't know how to set it back again.. */
86*4882a593Smuzhiyun /* Actually we do - there is a data sheet available for the
87*4882a593Smuzhiyun Winbond but does anyone actually care */
88*4882a593Smuzhiyun }
89*4882a593Smuzhiyun }
90*4882a593Smuzhiyun
91*4882a593Smuzhiyun static const struct ide_port_ops dtc2278_port_ops = {
92*4882a593Smuzhiyun .set_pio_mode = dtc2278_set_pio_mode,
93*4882a593Smuzhiyun };
94*4882a593Smuzhiyun
95*4882a593Smuzhiyun static const struct ide_port_info dtc2278_port_info __initconst = {
96*4882a593Smuzhiyun .name = DRV_NAME,
97*4882a593Smuzhiyun .chipset = ide_dtc2278,
98*4882a593Smuzhiyun .port_ops = &dtc2278_port_ops,
99*4882a593Smuzhiyun .host_flags = IDE_HFLAG_SERIALIZE |
100*4882a593Smuzhiyun IDE_HFLAG_NO_UNMASK_IRQS |
101*4882a593Smuzhiyun IDE_HFLAG_IO_32BIT |
102*4882a593Smuzhiyun /* disallow ->io_32bit changes */
103*4882a593Smuzhiyun IDE_HFLAG_NO_IO_32BIT |
104*4882a593Smuzhiyun IDE_HFLAG_NO_DMA |
105*4882a593Smuzhiyun IDE_HFLAG_DTC2278,
106*4882a593Smuzhiyun .pio_mask = ATA_PIO4,
107*4882a593Smuzhiyun };
108*4882a593Smuzhiyun
dtc2278_probe(void)109*4882a593Smuzhiyun static int __init dtc2278_probe(void)
110*4882a593Smuzhiyun {
111*4882a593Smuzhiyun unsigned long flags;
112*4882a593Smuzhiyun
113*4882a593Smuzhiyun local_irq_save(flags);
114*4882a593Smuzhiyun /*
115*4882a593Smuzhiyun * This enables the second interface
116*4882a593Smuzhiyun */
117*4882a593Smuzhiyun outb_p(4,0xb0);
118*4882a593Smuzhiyun inb(0x3f6);
119*4882a593Smuzhiyun outb_p(0x20,0xb4);
120*4882a593Smuzhiyun inb(0x3f6);
121*4882a593Smuzhiyun #ifdef ALWAYS_SET_DTC2278_PIO_MODE
122*4882a593Smuzhiyun /*
123*4882a593Smuzhiyun * This enables PIO mode4 (3?) on the first interface
124*4882a593Smuzhiyun * and may solve start-up problems for some people.
125*4882a593Smuzhiyun */
126*4882a593Smuzhiyun sub22(1,0xc3);
127*4882a593Smuzhiyun sub22(0,0xa0);
128*4882a593Smuzhiyun #endif
129*4882a593Smuzhiyun local_irq_restore(flags);
130*4882a593Smuzhiyun
131*4882a593Smuzhiyun return ide_legacy_device_add(&dtc2278_port_info, 0);
132*4882a593Smuzhiyun }
133*4882a593Smuzhiyun
134*4882a593Smuzhiyun static bool probe_dtc2278;
135*4882a593Smuzhiyun
136*4882a593Smuzhiyun module_param_named(probe, probe_dtc2278, bool, 0);
137*4882a593Smuzhiyun MODULE_PARM_DESC(probe, "probe for DTC2278xx chipsets");
138*4882a593Smuzhiyun
dtc2278_init(void)139*4882a593Smuzhiyun static int __init dtc2278_init(void)
140*4882a593Smuzhiyun {
141*4882a593Smuzhiyun if (probe_dtc2278 == 0)
142*4882a593Smuzhiyun return -ENODEV;
143*4882a593Smuzhiyun
144*4882a593Smuzhiyun if (dtc2278_probe()) {
145*4882a593Smuzhiyun printk(KERN_ERR "dtc2278: ide interfaces already in use!\n");
146*4882a593Smuzhiyun return -EBUSY;
147*4882a593Smuzhiyun }
148*4882a593Smuzhiyun return 0;
149*4882a593Smuzhiyun }
150*4882a593Smuzhiyun
151*4882a593Smuzhiyun module_init(dtc2278_init);
152*4882a593Smuzhiyun
153*4882a593Smuzhiyun MODULE_AUTHOR("See Local File");
154*4882a593Smuzhiyun MODULE_DESCRIPTION("support of DTC-2278 VLB IDE chipsets");
155*4882a593Smuzhiyun MODULE_LICENSE("GPL");
156