1 From 2c4842d42cad823e3927c9a54d8a7c30158d27d2 Mon Sep 17 00:00:00 2001
2 From: Sasha Levin <sashal@kernel.org>
3 Date: Sat, 24 Feb 2024 18:42:27 +0100
4 Subject: sparc32: Fix parport build with sparc32
6 From: Sam Ravnborg <sam@ravnborg.org>
8 [ Upstream commit 91d3ff922c346d6d8cb8de5ff8d504fe0ca9e17e ]
10 include/asm/parport.h is sparc64 specific.
11 Rename it to parport_64.h and use the generic version for sparc32.
13 This fixed all{mod,yes}config build errors like:
15 parport_pc.c:(.text):undefined-reference-to-ebus_dma_enable
16 parport_pc.c:(.text):undefined-reference-to-ebus_dma_irq_enable
17 parport_pc.c:(.text):undefined-reference-to-ebus_dma_register
19 The errors occur as the sparc32 build references sparc64 symbols.
21 Signed-off-by: Sam Ravnborg <sam@ravnborg.org>
22 Cc: "David S. Miller" <davem@davemloft.net>
23 Cc: Andreas Larsson <andreas@gaisler.com>
24 Cc: Randy Dunlap <rdunlap@infradead.org>
25 Cc: Maciej W. Rozycki <macro@orcam.me.uk>
26 Closes: https://lore.kernel.org/r/20230406160548.25721-1-rdunlap@infradead.org/
27 Fixes: 66bcd06099bb ("parport_pc: Also enable driver for PCI systems")
28 Cc: stable@vger.kernel.org # v5.18+
29 Tested-by: Randy Dunlap <rdunlap@infradead.org> # build-tested
30 Reviewed-by: Andreas Larsson <andreas@gaisler.com>
31 Signed-off-by: Andreas Larsson <andreas@gaisler.com>
32 Link: https://lore.kernel.org/r/20240224-sam-fix-sparc32-all-builds-v2-6-1f186603c5c4@ravnborg.org
33 Signed-off-by: Sasha Levin <sashal@kernel.org>
35 arch/sparc/include/asm/parport.h | 259 +---------------------------
36 arch/sparc/include/asm/parport_64.h | 256 +++++++++++++++++++++++++++
37 2 files changed, 263 insertions(+), 252 deletions(-)
38 create mode 100644 arch/sparc/include/asm/parport_64.h
40 diff --git a/arch/sparc/include/asm/parport.h b/arch/sparc/include/asm/parport.h
41 index 0a7ffcfd59cda..e2eed8f97665f 100644
42 --- a/arch/sparc/include/asm/parport.h
43 +++ b/arch/sparc/include/asm/parport.h
45 /* SPDX-License-Identifier: GPL-2.0 */
46 -/* parport.h: sparc64 specific parport initialization and dma.
48 - * Copyright (C) 1999 Eddie C. Dost (ecd@skynet.be)
50 +#ifndef ___ASM_SPARC_PARPORT_H
51 +#define ___ASM_SPARC_PARPORT_H
53 -#ifndef _ASM_SPARC64_PARPORT_H
54 -#define _ASM_SPARC64_PARPORT_H 1
56 -#include <linux/of.h>
57 -#include <linux/platform_device.h>
59 -#include <asm/ebus_dma.h>
60 -#include <asm/ns87303.h>
61 -#include <asm/prom.h>
63 -#define PARPORT_PC_MAX_PORTS PARPORT_MAX
66 - * While sparc64 doesn't have an ISA DMA API, we provide something that looks
67 - * close enough to make parport_pc happy
71 -#ifdef CONFIG_PARPORT_PC_FIFO
72 -static DEFINE_SPINLOCK(dma_spin_lock);
74 -#define claim_dma_lock() \
75 -({ unsigned long flags; \
76 - spin_lock_irqsave(&dma_spin_lock, flags); \
80 -#define release_dma_lock(__flags) \
81 - spin_unlock_irqrestore(&dma_spin_lock, __flags);
82 +#if defined(__sparc__) && defined(__arch64__)
83 +#include <asm/parport_64.h>
85 +#include <asm-generic/parport.h>
89 -static struct sparc_ebus_info {
90 - struct ebus_dma_info info;
95 - struct parport *port;
96 -} sparc_ebus_dmas[PARPORT_PC_MAX_PORTS];
98 -static DECLARE_BITMAP(dma_slot_map, PARPORT_PC_MAX_PORTS);
100 -static inline int request_dma(unsigned int dmanr, const char *device_id)
102 - if (dmanr >= PARPORT_PC_MAX_PORTS)
104 - if (xchg(&sparc_ebus_dmas[dmanr].lock, 1) != 0)
109 -static inline void free_dma(unsigned int dmanr)
111 - if (dmanr >= PARPORT_PC_MAX_PORTS) {
112 - printk(KERN_WARNING "Trying to free DMA%d\n", dmanr);
115 - if (xchg(&sparc_ebus_dmas[dmanr].lock, 0) == 0) {
116 - printk(KERN_WARNING "Trying to free free DMA%d\n", dmanr);
121 -static inline void enable_dma(unsigned int dmanr)
123 - ebus_dma_enable(&sparc_ebus_dmas[dmanr].info, 1);
125 - if (ebus_dma_request(&sparc_ebus_dmas[dmanr].info,
126 - sparc_ebus_dmas[dmanr].addr,
127 - sparc_ebus_dmas[dmanr].count))
131 -static inline void disable_dma(unsigned int dmanr)
133 - ebus_dma_enable(&sparc_ebus_dmas[dmanr].info, 0);
136 -static inline void clear_dma_ff(unsigned int dmanr)
141 -static inline void set_dma_mode(unsigned int dmanr, char mode)
143 - ebus_dma_prepare(&sparc_ebus_dmas[dmanr].info, (mode != DMA_MODE_WRITE));
146 -static inline void set_dma_addr(unsigned int dmanr, unsigned int addr)
148 - sparc_ebus_dmas[dmanr].addr = addr;
151 -static inline void set_dma_count(unsigned int dmanr, unsigned int count)
153 - sparc_ebus_dmas[dmanr].count = count;
156 -static inline unsigned int get_dma_residue(unsigned int dmanr)
158 - return ebus_dma_residue(&sparc_ebus_dmas[dmanr].info);
161 -static int ecpp_probe(struct platform_device *op)
163 - unsigned long base = op->resource[0].start;
164 - unsigned long config = op->resource[1].start;
165 - unsigned long d_base = op->resource[2].start;
166 - unsigned long d_len;
167 - struct device_node *parent;
171 - parent = op->dev.of_node->parent;
172 - if (of_node_name_eq(parent, "dma")) {
173 - p = parport_pc_probe_port(base, base + 0x400,
174 - op->archdata.irqs[0], PARPORT_DMA_NOFIFO,
175 - op->dev.parent->parent, 0);
178 - dev_set_drvdata(&op->dev, p);
182 - for (slot = 0; slot < PARPORT_PC_MAX_PORTS; slot++) {
183 - if (!test_and_set_bit(slot, dma_slot_map))
187 - if (slot >= PARPORT_PC_MAX_PORTS)
190 - spin_lock_init(&sparc_ebus_dmas[slot].info.lock);
192 - d_len = (op->resource[2].end - d_base) + 1UL;
193 - sparc_ebus_dmas[slot].info.regs =
194 - of_ioremap(&op->resource[2], 0, d_len, "ECPP DMA");
196 - if (!sparc_ebus_dmas[slot].info.regs)
197 - goto out_clear_map;
199 - sparc_ebus_dmas[slot].info.flags = 0;
200 - sparc_ebus_dmas[slot].info.callback = NULL;
201 - sparc_ebus_dmas[slot].info.client_cookie = NULL;
202 - sparc_ebus_dmas[slot].info.irq = 0xdeadbeef;
203 - strcpy(sparc_ebus_dmas[slot].info.name, "parport");
204 - if (ebus_dma_register(&sparc_ebus_dmas[slot].info))
205 - goto out_unmap_regs;
207 - ebus_dma_irq_enable(&sparc_ebus_dmas[slot].info, 1);
209 - /* Configure IRQ to Push Pull, Level Low */
210 - /* Enable ECP, set bit 2 of the CTR first */
211 - outb(0x04, base + 0x02);
212 - ns87303_modify(config, PCR,
219 - /* CTR bit 5 controls direction of port */
220 - ns87303_modify(config, PTR,
221 - 0, PTR_LPT_REG_DIR);
223 - p = parport_pc_probe_port(base, base + 0x400,
224 - op->archdata.irqs[0],
230 - goto out_disable_irq;
232 - dev_set_drvdata(&op->dev, p);
237 - ebus_dma_irq_enable(&sparc_ebus_dmas[slot].info, 0);
238 - ebus_dma_unregister(&sparc_ebus_dmas[slot].info);
241 - of_iounmap(&op->resource[2], sparc_ebus_dmas[slot].info.regs, d_len);
244 - clear_bit(slot, dma_slot_map);
250 -static int ecpp_remove(struct platform_device *op)
252 - struct parport *p = dev_get_drvdata(&op->dev);
255 - parport_pc_unregister_port(p);
257 - if (slot != PARPORT_DMA_NOFIFO) {
258 - unsigned long d_base = op->resource[2].start;
259 - unsigned long d_len;
261 - d_len = (op->resource[2].end - d_base) + 1UL;
263 - ebus_dma_irq_enable(&sparc_ebus_dmas[slot].info, 0);
264 - ebus_dma_unregister(&sparc_ebus_dmas[slot].info);
265 - of_iounmap(&op->resource[2],
266 - sparc_ebus_dmas[slot].info.regs,
268 - clear_bit(slot, dma_slot_map);
274 -static const struct of_device_id ecpp_match[] = {
279 - .name = "parallel",
280 - .compatible = "ecpp",
283 - .name = "parallel",
284 - .compatible = "ns87317-ecpp",
287 - .name = "parallel",
288 - .compatible = "pnpALI,1533,3",
293 -static struct platform_driver ecpp_driver = {
296 - .of_match_table = ecpp_match,
298 - .probe = ecpp_probe,
299 - .remove = ecpp_remove,
302 -static int parport_pc_find_nonpci_ports(int autoirq, int autodma)
304 - return platform_driver_register(&ecpp_driver);
307 -#endif /* !(_ASM_SPARC64_PARPORT_H */
308 diff --git a/arch/sparc/include/asm/parport_64.h b/arch/sparc/include/asm/parport_64.h
310 index 0000000000000..0a7ffcfd59cda
312 +++ b/arch/sparc/include/asm/parport_64.h
314 +/* SPDX-License-Identifier: GPL-2.0 */
315 +/* parport.h: sparc64 specific parport initialization and dma.
317 + * Copyright (C) 1999 Eddie C. Dost (ecd@skynet.be)
320 +#ifndef _ASM_SPARC64_PARPORT_H
321 +#define _ASM_SPARC64_PARPORT_H 1
323 +#include <linux/of.h>
324 +#include <linux/platform_device.h>
326 +#include <asm/ebus_dma.h>
327 +#include <asm/ns87303.h>
328 +#include <asm/prom.h>
330 +#define PARPORT_PC_MAX_PORTS PARPORT_MAX
333 + * While sparc64 doesn't have an ISA DMA API, we provide something that looks
334 + * close enough to make parport_pc happy
338 +#ifdef CONFIG_PARPORT_PC_FIFO
339 +static DEFINE_SPINLOCK(dma_spin_lock);
341 +#define claim_dma_lock() \
342 +({ unsigned long flags; \
343 + spin_lock_irqsave(&dma_spin_lock, flags); \
347 +#define release_dma_lock(__flags) \
348 + spin_unlock_irqrestore(&dma_spin_lock, __flags);
351 +static struct sparc_ebus_info {
352 + struct ebus_dma_info info;
354 + unsigned int count;
357 + struct parport *port;
358 +} sparc_ebus_dmas[PARPORT_PC_MAX_PORTS];
360 +static DECLARE_BITMAP(dma_slot_map, PARPORT_PC_MAX_PORTS);
362 +static inline int request_dma(unsigned int dmanr, const char *device_id)
364 + if (dmanr >= PARPORT_PC_MAX_PORTS)
366 + if (xchg(&sparc_ebus_dmas[dmanr].lock, 1) != 0)
371 +static inline void free_dma(unsigned int dmanr)
373 + if (dmanr >= PARPORT_PC_MAX_PORTS) {
374 + printk(KERN_WARNING "Trying to free DMA%d\n", dmanr);
377 + if (xchg(&sparc_ebus_dmas[dmanr].lock, 0) == 0) {
378 + printk(KERN_WARNING "Trying to free free DMA%d\n", dmanr);
383 +static inline void enable_dma(unsigned int dmanr)
385 + ebus_dma_enable(&sparc_ebus_dmas[dmanr].info, 1);
387 + if (ebus_dma_request(&sparc_ebus_dmas[dmanr].info,
388 + sparc_ebus_dmas[dmanr].addr,
389 + sparc_ebus_dmas[dmanr].count))
393 +static inline void disable_dma(unsigned int dmanr)
395 + ebus_dma_enable(&sparc_ebus_dmas[dmanr].info, 0);
398 +static inline void clear_dma_ff(unsigned int dmanr)
403 +static inline void set_dma_mode(unsigned int dmanr, char mode)
405 + ebus_dma_prepare(&sparc_ebus_dmas[dmanr].info, (mode != DMA_MODE_WRITE));
408 +static inline void set_dma_addr(unsigned int dmanr, unsigned int addr)
410 + sparc_ebus_dmas[dmanr].addr = addr;
413 +static inline void set_dma_count(unsigned int dmanr, unsigned int count)
415 + sparc_ebus_dmas[dmanr].count = count;
418 +static inline unsigned int get_dma_residue(unsigned int dmanr)
420 + return ebus_dma_residue(&sparc_ebus_dmas[dmanr].info);
423 +static int ecpp_probe(struct platform_device *op)
425 + unsigned long base = op->resource[0].start;
426 + unsigned long config = op->resource[1].start;
427 + unsigned long d_base = op->resource[2].start;
428 + unsigned long d_len;
429 + struct device_node *parent;
433 + parent = op->dev.of_node->parent;
434 + if (of_node_name_eq(parent, "dma")) {
435 + p = parport_pc_probe_port(base, base + 0x400,
436 + op->archdata.irqs[0], PARPORT_DMA_NOFIFO,
437 + op->dev.parent->parent, 0);
440 + dev_set_drvdata(&op->dev, p);
444 + for (slot = 0; slot < PARPORT_PC_MAX_PORTS; slot++) {
445 + if (!test_and_set_bit(slot, dma_slot_map))
449 + if (slot >= PARPORT_PC_MAX_PORTS)
452 + spin_lock_init(&sparc_ebus_dmas[slot].info.lock);
454 + d_len = (op->resource[2].end - d_base) + 1UL;
455 + sparc_ebus_dmas[slot].info.regs =
456 + of_ioremap(&op->resource[2], 0, d_len, "ECPP DMA");
458 + if (!sparc_ebus_dmas[slot].info.regs)
459 + goto out_clear_map;
461 + sparc_ebus_dmas[slot].info.flags = 0;
462 + sparc_ebus_dmas[slot].info.callback = NULL;
463 + sparc_ebus_dmas[slot].info.client_cookie = NULL;
464 + sparc_ebus_dmas[slot].info.irq = 0xdeadbeef;
465 + strcpy(sparc_ebus_dmas[slot].info.name, "parport");
466 + if (ebus_dma_register(&sparc_ebus_dmas[slot].info))
467 + goto out_unmap_regs;
469 + ebus_dma_irq_enable(&sparc_ebus_dmas[slot].info, 1);
471 + /* Configure IRQ to Push Pull, Level Low */
472 + /* Enable ECP, set bit 2 of the CTR first */
473 + outb(0x04, base + 0x02);
474 + ns87303_modify(config, PCR,
481 + /* CTR bit 5 controls direction of port */
482 + ns87303_modify(config, PTR,
483 + 0, PTR_LPT_REG_DIR);
485 + p = parport_pc_probe_port(base, base + 0x400,
486 + op->archdata.irqs[0],
492 + goto out_disable_irq;
494 + dev_set_drvdata(&op->dev, p);
499 + ebus_dma_irq_enable(&sparc_ebus_dmas[slot].info, 0);
500 + ebus_dma_unregister(&sparc_ebus_dmas[slot].info);
503 + of_iounmap(&op->resource[2], sparc_ebus_dmas[slot].info.regs, d_len);
506 + clear_bit(slot, dma_slot_map);
512 +static int ecpp_remove(struct platform_device *op)
514 + struct parport *p = dev_get_drvdata(&op->dev);
517 + parport_pc_unregister_port(p);
519 + if (slot != PARPORT_DMA_NOFIFO) {
520 + unsigned long d_base = op->resource[2].start;
521 + unsigned long d_len;
523 + d_len = (op->resource[2].end - d_base) + 1UL;
525 + ebus_dma_irq_enable(&sparc_ebus_dmas[slot].info, 0);
526 + ebus_dma_unregister(&sparc_ebus_dmas[slot].info);
527 + of_iounmap(&op->resource[2],
528 + sparc_ebus_dmas[slot].info.regs,
530 + clear_bit(slot, dma_slot_map);
536 +static const struct of_device_id ecpp_match[] = {
541 + .name = "parallel",
542 + .compatible = "ecpp",
545 + .name = "parallel",
546 + .compatible = "ns87317-ecpp",
549 + .name = "parallel",
550 + .compatible = "pnpALI,1533,3",
555 +static struct platform_driver ecpp_driver = {
558 + .of_match_table = ecpp_match,
560 + .probe = ecpp_probe,
561 + .remove = ecpp_remove,
564 +static int parport_pc_find_nonpci_ports(int autoirq, int autodma)
566 + return platform_driver_register(&ecpp_driver);
569 +#endif /* !(_ASM_SPARC64_PARPORT_H */