Merge tag 'block-5.11-2021-01-10' of git://git.kernel.dk/linux-block
[linux/fpc-iii.git] / drivers / parport / parport_amiga.c
blob1e88bcfe0d7b18adb4e410b902c3c273ac2a263e
1 // SPDX-License-Identifier: GPL-2.0-only
2 /* Low-level parallel port routines for the Amiga built-in port
4 * Author: Joerg Dorchain <joerg@dorchain.net>
6 * This is a complete rewrite of the code, but based heaviy upon the old
7 * lp_intern. code.
9 * The built-in Amiga parallel port provides one port at a fixed address
10 * with 8 bidirectional data lines (D0 - D7) and 3 bidirectional status
11 * lines (BUSY, POUT, SEL), 1 output control line /STROBE (raised automatically
12 * in hardware when the data register is accessed), and 1 input control line
13 * /ACK, able to cause an interrupt, but both not directly settable by
14 * software.
17 #include <linux/module.h>
18 #include <linux/init.h>
19 #include <linux/parport.h>
20 #include <linux/ioport.h>
21 #include <linux/interrupt.h>
22 #include <linux/platform_device.h>
24 #include <asm/setup.h>
25 #include <asm/amigahw.h>
26 #include <asm/irq.h>
27 #include <asm/io.h>
28 #include <asm/amigaints.h>
30 #undef DEBUG
32 static void amiga_write_data(struct parport *p, unsigned char data)
34 pr_debug("write_data %c\n", data);
35 /* Triggers also /STROBE. This behavior cannot be changed */
36 ciaa.prb = data;
37 mb();
40 static unsigned char amiga_read_data(struct parport *p)
42 /* Triggers also /STROBE. This behavior cannot be changed */
43 return ciaa.prb;
46 static unsigned char control_amiga_to_pc(unsigned char control)
48 return PARPORT_CONTROL_SELECT |
49 PARPORT_CONTROL_AUTOFD | PARPORT_CONTROL_STROBE;
50 /* fake value: interrupt enable, select in, no reset,
51 no autolf, no strobe - seems to be closest the wiring diagram */
54 static void amiga_write_control(struct parport *p, unsigned char control)
56 pr_debug("write_control %02x\n", control);
57 /* No implementation possible */
60 static unsigned char amiga_read_control( struct parport *p)
62 pr_debug("read_control\n");
63 return control_amiga_to_pc(0);
66 static unsigned char amiga_frob_control( struct parport *p, unsigned char mask, unsigned char val)
68 unsigned char old;
70 pr_debug("frob_control mask %02x, value %02x\n", mask, val);
71 old = amiga_read_control(p);
72 amiga_write_control(p, (old & ~mask) ^ val);
73 return old;
76 static unsigned char status_amiga_to_pc(unsigned char status)
78 unsigned char ret = PARPORT_STATUS_BUSY | PARPORT_STATUS_ACK | PARPORT_STATUS_ERROR;
80 if (status & 1) /* Busy */
81 ret &= ~PARPORT_STATUS_BUSY;
82 if (status & 2) /* PaperOut */
83 ret |= PARPORT_STATUS_PAPEROUT;
84 if (status & 4) /* Selected */
85 ret |= PARPORT_STATUS_SELECT;
86 /* the rest is not connected or handled autonomously in hardware */
88 return ret;
91 static unsigned char amiga_read_status(struct parport *p)
93 unsigned char status;
95 status = status_amiga_to_pc(ciab.pra & 7);
96 pr_debug("read_status %02x\n", status);
97 return status;
100 static void amiga_enable_irq(struct parport *p)
102 enable_irq(IRQ_AMIGA_CIAA_FLG);
105 static void amiga_disable_irq(struct parport *p)
107 disable_irq(IRQ_AMIGA_CIAA_FLG);
110 static void amiga_data_forward(struct parport *p)
112 pr_debug("forward\n");
113 ciaa.ddrb = 0xff; /* all pins output */
114 mb();
117 static void amiga_data_reverse(struct parport *p)
119 pr_debug("reverse\n");
120 ciaa.ddrb = 0; /* all pins input */
121 mb();
124 static void amiga_init_state(struct pardevice *dev, struct parport_state *s)
126 s->u.amiga.data = 0;
127 s->u.amiga.datadir = 255;
128 s->u.amiga.status = 0;
129 s->u.amiga.statusdir = 0;
132 static void amiga_save_state(struct parport *p, struct parport_state *s)
134 mb();
135 s->u.amiga.data = ciaa.prb;
136 s->u.amiga.datadir = ciaa.ddrb;
137 s->u.amiga.status = ciab.pra & 7;
138 s->u.amiga.statusdir = ciab.ddra & 7;
139 mb();
142 static void amiga_restore_state(struct parport *p, struct parport_state *s)
144 mb();
145 ciaa.prb = s->u.amiga.data;
146 ciaa.ddrb = s->u.amiga.datadir;
147 ciab.pra |= (ciab.pra & 0xf8) | s->u.amiga.status;
148 ciab.ddra |= (ciab.ddra & 0xf8) | s->u.amiga.statusdir;
149 mb();
152 static struct parport_operations pp_amiga_ops = {
153 .write_data = amiga_write_data,
154 .read_data = amiga_read_data,
156 .write_control = amiga_write_control,
157 .read_control = amiga_read_control,
158 .frob_control = amiga_frob_control,
160 .read_status = amiga_read_status,
162 .enable_irq = amiga_enable_irq,
163 .disable_irq = amiga_disable_irq,
165 .data_forward = amiga_data_forward,
166 .data_reverse = amiga_data_reverse,
168 .init_state = amiga_init_state,
169 .save_state = amiga_save_state,
170 .restore_state = amiga_restore_state,
172 .epp_write_data = parport_ieee1284_epp_write_data,
173 .epp_read_data = parport_ieee1284_epp_read_data,
174 .epp_write_addr = parport_ieee1284_epp_write_addr,
175 .epp_read_addr = parport_ieee1284_epp_read_addr,
177 .ecp_write_data = parport_ieee1284_ecp_write_data,
178 .ecp_read_data = parport_ieee1284_ecp_read_data,
179 .ecp_write_addr = parport_ieee1284_ecp_write_addr,
181 .compat_write_data = parport_ieee1284_write_compat,
182 .nibble_read_data = parport_ieee1284_read_nibble,
183 .byte_read_data = parport_ieee1284_read_byte,
185 .owner = THIS_MODULE,
188 /* ----------- Initialisation code --------------------------------- */
190 static int __init amiga_parallel_probe(struct platform_device *pdev)
192 struct parport *p;
193 int err;
195 ciaa.ddrb = 0xff;
196 ciab.ddra &= 0xf8;
197 mb();
199 p = parport_register_port((unsigned long)&ciaa.prb, IRQ_AMIGA_CIAA_FLG,
200 PARPORT_DMA_NONE, &pp_amiga_ops);
201 if (!p)
202 return -EBUSY;
204 err = request_irq(IRQ_AMIGA_CIAA_FLG, parport_irq_handler, 0, p->name,
206 if (err)
207 goto out_irq;
209 pr_info("%s: Amiga built-in port using irq\n", p->name);
210 /* XXX: set operating mode */
211 parport_announce_port(p);
213 platform_set_drvdata(pdev, p);
215 return 0;
217 out_irq:
218 parport_put_port(p);
219 return err;
222 static int __exit amiga_parallel_remove(struct platform_device *pdev)
224 struct parport *port = platform_get_drvdata(pdev);
226 parport_remove_port(port);
227 if (port->irq != PARPORT_IRQ_NONE)
228 free_irq(IRQ_AMIGA_CIAA_FLG, port);
229 parport_put_port(port);
230 return 0;
233 static struct platform_driver amiga_parallel_driver = {
234 .remove = __exit_p(amiga_parallel_remove),
235 .driver = {
236 .name = "amiga-parallel",
240 module_platform_driver_probe(amiga_parallel_driver, amiga_parallel_probe);
242 MODULE_AUTHOR("Joerg Dorchain <joerg@dorchain.net>");
243 MODULE_DESCRIPTION("Parport Driver for Amiga builtin Port");
244 MODULE_SUPPORTED_DEVICE("Amiga builtin Parallel Port");
245 MODULE_LICENSE("GPL");
246 MODULE_ALIAS("platform:amiga-parallel");