xref: /linux/drivers/ata/pata_parport/pata_parport.h (revision 1ac731c529cd4d6adbce134754b51ff7d822b145)
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 struct pi_adapter {
15 	struct device dev;
16 	struct pi_protocol *proto;	/* adapter protocol */
17 	int port;			/* base address of parallel port */
18 	int mode;			/* transfer mode in use */
19 	int delay;			/* adapter delay setting */
20 	int unit;			/* unit number for chained adapters */
21 	int saved_r0;			/* saved port state */
22 	int saved_r2;			/* saved port state */
23 	unsigned long private;		/* for protocol module */
24 	struct pardevice *pardev;	/* pointer to pardevice */
25 };
26 
27 /* registers are addressed as (cont,regr)
28  *	cont: 0 for command register file, 1 for control register(s)
29  *	regr: 0-7 for register number.
30  */
31 
32 /* macros and functions exported to the protocol modules */
33 #define delay_p			(pi->delay ? udelay(pi->delay) : (void)0)
34 #define out_p(offs, byte)	do { outb(byte, pi->port + offs); delay_p; } while (0)
35 #define in_p(offs)		(delay_p, inb(pi->port + offs))
36 
37 #define w0(byte)		out_p(0, byte)
38 #define r0()			in_p(0)
39 #define w1(byte)		out_p(1, byte)
40 #define r1()			in_p(1)
41 #define w2(byte)		out_p(2, byte)
42 #define r2()			in_p(2)
43 #define w3(byte)		out_p(3, byte)
44 #define w4(byte)		out_p(4, byte)
45 #define r4()			in_p(4)
46 #define w4w(data)		do { outw(data, pi->port + 4); delay_p; } while (0)
47 #define w4l(data)		do { outl(data, pi->port + 4); delay_p; } while (0)
48 #define r4w()			(delay_p, inw(pi->port + 4))
49 #define r4l()			(delay_p, inl(pi->port + 4))
50 
51 struct pi_protocol {
52 	char name[8];
53 
54 	int max_mode;
55 	int epp_first;		/* modes >= this use 8 ports */
56 
57 	int default_delay;
58 	int max_units;		/* max chained units probed for */
59 
60 	void (*write_regr)(struct pi_adapter *pi, int cont, int regr, int val);
61 	int (*read_regr)(struct pi_adapter *pi, int cont, int regr);
62 	void (*write_block)(struct pi_adapter *pi, char *buf, int count);
63 	void (*read_block)(struct pi_adapter *pi, char *buf, int count);
64 
65 	void (*connect)(struct pi_adapter *pi);
66 	void (*disconnect)(struct pi_adapter *pi);
67 
68 	int (*test_port)(struct pi_adapter *pi);
69 	int (*probe_unit)(struct pi_adapter *pi);
70 	int (*test_proto)(struct pi_adapter *pi);
71 	void (*log_adapter)(struct pi_adapter *pi);
72 
73 	int (*init_proto)(struct pi_adapter *pi);
74 	void (*release_proto)(struct pi_adapter *pi);
75 	struct module *owner;
76 	struct device_driver driver;
77 	struct scsi_host_template sht;
78 };
79 
80 #define PATA_PARPORT_SHT ATA_PIO_SHT
81 
82 int pata_parport_register_driver(struct pi_protocol *pr);
83 void pata_parport_unregister_driver(struct pi_protocol *pr);
84 
85 /**
86  * module_pata_parport_driver() - Helper macro for registering a pata_parport driver
87  * @__pi_protocol: pi_protocol struct
88  *
89  * Helper macro for pata_parport drivers which do not do anything special in module
90  * init/exit. This eliminates a lot of boilerplate. Each module may only
91  * use this macro once, and calling it replaces module_init() and module_exit()
92  */
93 #define module_pata_parport_driver(__pi_protocol) \
94 	module_driver(__pi_protocol, pata_parport_register_driver, pata_parport_unregister_driver)
95 
96 #endif /* LINUX_PATA_PARPORT_H */
97