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
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
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>
28 #include <asm/amigaints.h>
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 */
40 static unsigned char amiga_read_data(struct parport *p)
42 /* Triggers also /STROBE. This behavior cannot be changed */
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)
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);
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 */
91 static unsigned char amiga_read_status(struct parport *p)
95 status = status_amiga_to_pc(ciab.pra & 7);
96 pr_debug("read_status %02x\n", 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 */
117 static void amiga_data_reverse(struct parport *p)
119 pr_debug("reverse\n");
120 ciaa.ddrb = 0; /* all pins input */
124 static void amiga_init_state(struct pardevice *dev, struct parport_state *s)
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)
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;
142 static void amiga_restore_state(struct parport *p, struct parport_state *s)
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;
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)
199 p = parport_register_port((unsigned long)&ciaa.prb, IRQ_AMIGA_CIAA_FLG,
200 PARPORT_DMA_NONE, &pp_amiga_ops);
204 err = request_irq(IRQ_AMIGA_CIAA_FLG, parport_irq_handler, 0, p->name,
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);
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);
233 static struct platform_driver amiga_parallel_driver = {
234 .remove = __exit_p(amiga_parallel_remove),
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_LICENSE("GPL");
245 MODULE_ALIAS("platform:amiga-parallel");