1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3 * pata_parport.h (c) 1997-8 Grant R. Guenther <grant@torque.net>
4 * Under the terms of the GPL.
5 *
6 * This file defines the interface for parallel port IDE adapter chip drivers.
7 */
8
9 #ifndef LINUX_PATA_PARPORT_H
10 #define LINUX_PATA_PARPORT_H
11
12 #include <linux/libata.h>
13
14 #define PI_PCD 1 /* dummy for paride protocol modules */
15
16 struct pi_adapter {
17 struct device dev;
18 struct pi_protocol *proto; /* adapter protocol */
19 int port; /* base address of parallel port */
20 int mode; /* transfer mode in use */
21 int delay; /* adapter delay setting */
22 int devtype; /* dummy for paride protocol modules */
23 char *device; /* dummy for paride protocol modules */
24 int unit; /* unit number for chained adapters */
25 int saved_r0; /* saved port state */
26 int saved_r2; /* saved port state */
27 unsigned long private; /* for protocol module */
28 struct pardevice *pardev; /* pointer to pardevice */
29 };
30
31 typedef struct pi_adapter PIA; /* for paride protocol modules */
32
33 /* registers are addressed as (cont,regr)
34 * cont: 0 for command register file, 1 for control register(s)
35 * regr: 0-7 for register number.
36 */
37
38 /* macros and functions exported to the protocol modules */
39 #define delay_p (pi->delay ? udelay(pi->delay) : (void)0)
40 #define out_p(offs, byte) do { outb(byte, pi->port + offs); delay_p; } while (0)
41 #define in_p(offs) (delay_p, inb(pi->port + offs))
42
43 #define w0(byte) out_p(0, byte)
44 #define r0() in_p(0)
45 #define w1(byte) out_p(1, byte)
46 #define r1() in_p(1)
47 #define w2(byte) out_p(2, byte)
48 #define r2() in_p(2)
49 #define w3(byte) out_p(3, byte)
50 #define w4(byte) out_p(4, byte)
51 #define r4() in_p(4)
52 #define w4w(data) do { outw(data, pi->port + 4); delay_p; } while (0)
53 #define w4l(data) do { outl(data, pi->port + 4); delay_p; } while (0)
54 #define r4w() (delay_p, inw(pi->port + 4))
55 #define r4l() (delay_p, inl(pi->port + 4))
56
pi_swab16(char * b,int k)57 static inline u16 pi_swab16(char *b, int k)
58 {
59 union { u16 u; char t[2]; } r;
60
61 r.t[0] = b[2 * k + 1]; r.t[1] = b[2 * k];
62 return r.u;
63 }
64
pi_swab32(char * b,int k)65 static inline u32 pi_swab32(char *b, int k)
66 {
67 union { u32 u; char f[4]; } r;
68
69 r.f[0] = b[4 * k + 1]; r.f[1] = b[4 * k];
70 r.f[2] = b[4 * k + 3]; r.f[3] = b[4 * k + 2];
71 return r.u;
72 }
73
74 struct pi_protocol {
75 char name[8];
76
77 int max_mode;
78 int epp_first; /* modes >= this use 8 ports */
79
80 int default_delay;
81 int max_units; /* max chained units probed for */
82
83 void (*write_regr)(struct pi_adapter *pi, int cont, int regr, int val);
84 int (*read_regr)(struct pi_adapter *pi, int cont, int regr);
85 void (*write_block)(struct pi_adapter *pi, char *buf, int count);
86 void (*read_block)(struct pi_adapter *pi, char *buf, int count);
87
88 void (*connect)(struct pi_adapter *pi);
89 void (*disconnect)(struct pi_adapter *pi);
90
91 int (*test_port)(struct pi_adapter *pi);
92 int (*probe_unit)(struct pi_adapter *pi);
93 int (*test_proto)(struct pi_adapter *pi, char *scratch, int verbose);
94 void (*log_adapter)(struct pi_adapter *pi, char *scratch, int verbose);
95
96 int (*init_proto)(struct pi_adapter *pi);
97 void (*release_proto)(struct pi_adapter *pi);
98 struct module *owner;
99 struct device_driver driver;
100 struct scsi_host_template sht;
101 };
102
103 #define PATA_PARPORT_SHT ATA_PIO_SHT
104
105 int pata_parport_register_driver(struct pi_protocol *pr);
106 void pata_parport_unregister_driver(struct pi_protocol *pr);
107 /* defines for old paride protocol modules */
108 #define paride_register pata_parport_register_driver
109 #define paride_unregister pata_parport_unregister_driver
110
111 #endif /* LINUX_PATA_PARPORT_H */
112