Commodore's Gayle pcmcia driver
Subsystems (2)
cover Commodore's Gayle pcmcia driver
Here is a second attempt to get the PCMCIA side of Gayle's to work: it merges my previous attempt[1], some historical (e.g. v2.6.10 era) work from Kars de Jong[2](the set_io_map() and set_mem_map() are a blatant cut&paste), and it follows the NetBSD code[3] (when it made sense) - credit goes where credit is due.
The good news first:
if you have a pcnet_cs or fmvj18x_cs PCMCIA eth card, chances are it will work (i've 3 of them working here).
And now the bad one:
1) 3c589_cs (3COM Etherlink III): card is detected, it receives incoming packets (eth0 counter increases) but TX fails
2) axnet_cs: card is detected, but as soon as i try to up it, it errors out ("axnet_cs 0.0 eth0: Hw. address read/write mismap X")
3) pata_pcmcia (no name CF to PCMCIA adapter): it's recognized, but fails to attach ("pata_pcmcia 0.0: probe with driver pata_pcmcia failed with error -12") - looking a bit closer, it fails in pcmcia_init_one() when:
io_addr = devm_ioport_map(&pdev->dev, io_base, 8);
just notice that devm_ioport_unmap() is not implemented if CONFIG_HAS_IOPORT_MAP is not set (and M68K doesn't implement it).
And, finally, the extremly sad part:
1) i've forced the word and long I/O helpers to be little endian, and this is clearly a big no (see io_mm.h).
2) for the love of me, i couldn't figure out the proper way of acking an incoming interrupt on IRQ_AMIGA_PORTS at Gayle's level (and subsequenlty call all PCMCIA's card handlers registered), so i resorted to an ugly hack: i registered a dummy hanlder on IRQ_AMIGA_PORTS, checked for GAYLE_IRQ_IRQ, cleared the interrupt at Gayle's level, and then returned IRQ_NONE so the remaining handlers registered on IRQ_AMIGA_PORTS could be invoked - see gayle_irq_dummy().
3) the get_status() and set_socket() are pretty barebone, but that is intentional since, so far, i couldn't find a case where implementing all SS states made any difference.
If you want to see what's going on under the hood, stick a:
ccflags-y += -DDEBUG
in drivers/pcmcia/Makefile and rebuild your kernel.
Let me know what you think.
1: https://www.spinics.net/lists/linux-m68k/msg25982.html
2: https://dpaste.com//GYSLEKLLM and https://dpaste.com//EQE56PPSU
3: https://github.com/NetBSD/src/blob/trunk/sys/arch/amiga/dev/gayle_pcmcia.c
Paolo Pisati (1):
pcmcia: socket driver for Commodore's Gayle
arch/m68k/amiga/pcmcia.c | 59 ++++++ arch/m68k/amiga/platform.c | 29 +++ arch/m68k/include/asm/amipcmcia.h | 20 ++ arch/m68k/include/asm/io_mm.h | 20 +- drivers/pcmcia/Kconfig | 9 + drivers/pcmcia/Makefile | 1 + drivers/pcmcia/gayle.c | 303 ++++++++++++++++++++++++++++++ 7 files changed, 437 insertions(+), 4 deletions(-) create mode 100644 drivers/pcmcia/gayle.c
Signature · 1 line
2.34.1
PATCH 1/1 pcmcia: socket driver for Commodore's Gayle
--- arch/m68k/amiga/pcmcia.c | 59 ++++++ arch/m68k/amiga/platform.c | 29 +++ arch/m68k/include/asm/amipcmcia.h | 20 ++ arch/m68k/include/asm/io_mm.h | 20 +- drivers/pcmcia/Kconfig | 9 + drivers/pcmcia/Makefile | 1 + drivers/pcmcia/gayle.c | 306 ++++++++++++++++++++++++++++++ 7 files changed, 440 insertions(+), 4 deletions(-) create mode 100644 drivers/pcmcia/gayle.c
arch/m68k/amiga/pcmcia.c +59 -0
@@ -13,20 +13,37 @@*/ #include <linux/types.h> +#include <linux/delay.h> #include <linux/jiffies.h> #include <linux/timer.h> #include <linux/module.h> +#include <pcmcia/ss.h> #include <asm/amigayle.h> #include <asm/amipcmcia.h> /* gayle config byte for program voltage and access speed */ static unsigned char cfg_byte =GAYLE_CFG_0V |GAYLE_CFG_150NS ; +/* PCMCIA I/O maps */ +static struct pccard_io_map gayle_io_maps[MAX_IO_WIN ]; + +/* +* according to NetBSD (commit e26e7a8a2278 and 100db321d09e in [1]) +* and depending on Gayle's revision, there are two methods for a PCMCIA +* soft-reset +* +* 1: https://github.com/NetBSD/src.git +*/ void pcmcia_reset (void ) {unsigned long reset_start_time = jiffies; + gayle.intreq =0xff ; +udelay (10 ); + gayle.intreq =0xfc ; +udelay (20 ); + gayle_reset =0x00 ;while (time_before (jiffies, reset_start_time +1 *HZ /100 ));READ_ONCE (gayle_reset);
@@ -65,6 +82,11 @@ int pcmcia_copy_tuple(unsigned char tuple_id, void *tuple, int max_len) }EXPORT_SYMBOL (pcmcia_copy_tuple); +unsigned char pcmcia_get_voltage (void ) { +return gayle.config &0x03 ; +} +EXPORT_SYMBOL (pcmcia_get_voltage); +void pcmcia_program_voltage (int voltage) {unsigned char v;
@@ -119,3 +141,40 @@ void pcmcia_write_disable(void) }EXPORT_SYMBOL (pcmcia_write_disable); +void gayle_set_io_win (int win,unsigned char flags,unsigned int start,unsigned int stop) +{ +struct pccard_io_map *map = &gayle_io_maps[win]; + + map->flags = flags; + map->start = start; + map->stop = stop; +} + +unsigned long gayle_get_byte_base (unsigned long port) +{ +struct pccard_io_map *map; +int i; + +/* Simple case first */ +if (!(port &1 )) { +return (GAYLE_IO + port); + } + +for (i =0 , map = gayle_io_maps; i <MAX_IO_WIN ; i++, map++) { +if ((map->flags &MAP_ACTIVE ) && + (port >= map->start) && (port <= map->stop)) { +if (map->flags &MAP_16BIT ) { +return (GAYLE_IO + port); + }else { +/* Assume MAP_AUTOSZ works this way */ +return (GAYLE_IO + port + ((port &1 ) *GAYLE_ODD )); + } + } + } + +/* Sometimes an I/O access is done after a card has been removed. */ +return (GAYLE_IO + port); +} + +EXPORT_SYMBOL (gayle_set_io_win); +EXPORT_SYMBOL (gayle_get_byte_base);
arch/m68k/amiga/platform.c +29 -0
@@ -110,6 +110,26 @@ static const struct gayle_ide_platform_data a1200_ide_pdata __initconst = { .explicit_ack = 1, }; +static const struct resource a1200_pcmcia_resource[]__initconst = { + [0 ] = { + .name ="Gayle memory" , + .start =GAYLE_RAM , + .end =GAYLE_RAM +GAYLE_RAMSIZE -1 , + .flags =IORESOURCE_MEM , + }, + [1 ] = { + .name ="Gayle attribute" , + .start =GAYLE_ATTRIBUTE , + .end =GAYLE_ATTRIBUTE +GAYLE_ATTRIBUTESIZE -1 , + .flags =IORESOURCE_MEM , + }, + [2 ] = { + .name ="Gayle I/O" , + .start =GAYLE_IO , + .end =GAYLE_IO +GAYLE_IOSIZE -1 , + .flags =IORESOURCE_MEM , + } +};static const struct resource a4000_ide_resource__initconst = { .start =0xdd2000 ,
@@ -190,6 +210,15 @@ static int __init amiga_init_devices(void) sizeof(a1200_ide_pdata));if (error)return error; + + } + +if (AMIGAHW_PRESENT (PCMCIA )) { + pdev =platform_device_register_simple ("amiga-gayle-pcmcia" ,-1 , + a1200_pcmcia_resource, +ARRAY_SIZE (a1200_pcmcia_resource)); +if (IS_ERR (pdev)) +return PTR_ERR (pdev); }if (AMIGAHW_PRESENT (A4000_IDE )) {
arch/m68k/include/asm/amipcmcia.h +20 -0
@@ -19,10 +19,14 @@void pcmcia_reset (void );int pcmcia_copy_tuple (unsigned char tuple_id,void *tuple,int max_len); +unsigned char pcmcia_get_voltage (void );void pcmcia_program_voltage (int voltage);void pcmcia_access_speed (int speed);void pcmcia_write_enable (void );void pcmcia_write_disable (void ); +void gayle_set_io_win (int win,unsigned char flags,unsigned int start,unsigned +int stop); +unsigned long gayle_get_byte_base (unsigned long port);static inline u_char pcmcia_read_status (void ) {
@@ -39,6 +43,12 @@ static inline void pcmcia_ack_int(u_char intreq) gayle.intreq =0xf8 ; } +static inline void pcmcia_ack_ccdet (void ) +{ +/* reset GAYLE_IRQ_CCDET */ + gayle.intreq =0xbb ; +} +static inline void pcmcia_enable_irq (void ) { gayle.inten |=GAYLE_IRQ_IRQ ;
@@ -51,6 +61,16 @@ static inline void pcmcia_disable_irq(void)#define PCMCIA_INSERTED (gayle.cardstatus & GAYLE_CS_CCDET) +static inline void pcmcia_disable_ccdet_irq (void ) +{ + gayle.inten &= ~GAYLE_IRQ_CCDET ; +} + +static inline u_char pcmcia_wena (void ) +{ +return (gayle.cardstatus &GAYLE_CS_WR ); +} +/* valid voltages for pcmcia_ProgramVoltage */ #define PCMCIA_0V 0
arch/m68k/include/asm/io_mm.h +16 -4
@@ -56,7 +56,9 @@#ifdef CONFIG_AMIGA_PCMCIA #include <asm/amigayle.h> -#define AG_ISA_IO_B (ioaddr) ( GAYLE_IO+(ioaddr)+(((ioaddr)&1)*GAYLE_ODD) ) +extern unsigned long gayle_get_byte_base (unsigned long ); + +#define AG_ISA_IO_B (ioaddr) ( gayle_get_byte_base(ioaddr) )#define AG_ISA_IO_W (ioaddr) ( GAYLE_IO+(ioaddr) )#ifndef MULTI_ISA
@@ -199,20 +201,30 @@ static inline u16 __iomem *isa_mtw(unsigned long addr)#define isa_inb (port) in_8(isa_itb(port)) +#define isa_outb (val,port) out_8(isa_itb(port),(val)) +#define isa_readb (p) in_8(isa_mtb((unsigned long)(p))) +#define isa_writeb (val,p) out_8(isa_mtb((unsigned long)(p)),(val)) + +#ifdef CONFIG_PCMCIA_GAYLE +#define isa_inw (port) in_le16(isa_itw(port)) +#define isa_inl (port) in_le32(isa_itl(port)) +#define isa_outw (val,port) out_le16(isa_itw(port),(val)) +#define isa_outl (val,port) out_le32(isa_itl(port),(val)) +#define isa_readw (p) in_le16(isa_mtw((unsigned long)(p))) +#define isa_writew (val,p) out_le16(isa_mtw((unsigned long)(p)),(val)) +#else #define isa_inw (port) (ISA_SEX ? in_be16(isa_itw(port)) : in_le16(isa_itw(port)))#define isa_inl (port) (ISA_SEX ? in_be32(isa_itl(port)) : in_le32(isa_itl(port))) -#define isa_outb (val,port) out_8(isa_itb(port),(val))#define isa_outw (val,port) (ISA_SEX ? out_be16(isa_itw(port),(val)) : out_le16(isa_itw(port),(val)))#define isa_outl (val,port) (ISA_SEX ? out_be32(isa_itl(port),(val)) : out_le32(isa_itl(port),(val))) -#define isa_readb (p) in_8(isa_mtb((unsigned long)(p)))#define isa_readw (p) \ (ISA_SEX ? in_be16(isa_mtw((unsigned long)(p))) \ : in_le16(isa_mtw((unsigned long)(p)))) -#define isa_writeb (val,p) out_8(isa_mtb((unsigned long)(p)),(val))#define isa_writew (val,p) \ (ISA_SEX ? out_be16(isa_mtw((unsigned long)(p)),(val)) \ : out_le16(isa_mtw((unsigned long)(p)),(val))) +#endif #ifdef CONFIG_ATARI_ROM_ISA #define isa_rom_inb (port) rom_in_8(isa_itb(port))
drivers/pcmcia/Kconfig +9 -0
@@ -253,4 +253,13 @@ config PCCARD_NONSTATIC config PCCARD_IODYN bool +config PCMCIA_GAYLE + tristate "Amiga Gayle bridge support" + depends on PCMCIA && AMIGA && AMIGA_PCMCIA && !APNE + select PCCARD_IODYN + help + Say Y here to include support for PCMCIA host bridges that + are register compatible with Commodore's Gayle. This is found on + Amiga systems. If unsure, say N. + endif # PCCARD
drivers/pcmcia/Makefile +1 -0
@@ -33,6 +33,7 @@ obj-$(CONFIG_OMAP_CF) += omap_cf.o obj-$(CONFIG_ELECTRA_CF) += electra_cf.o obj-$(CONFIG_PCMCIA_ALCHEMY_DEVBOARD) += db1xxx_ss.o obj-$(CONFIG_PCMCIA_MAX1600) += max1600.o +obj-$(CONFIG_PCMCIA_GAYLE) += gayle.o sa1111_cs-y += sa1111_generic.o sa1111_cs-$(CONFIG_ASSABET_NEPONSET) += sa1111_neponset.o
drivers/pcmcia/gayle.c new file +306 -0
306 lines not on this page · raw message
Signature · 1 line
2.34.1
Geert Uytterhoeven
maintainerHi Paolo,
Quoted 4 lines · Paolo Pisati
Here is a second attempt to get the PCMCIA side of Gayle's to work: it merges my previous attempt[1], some historical (e.g. v2.6.10 era) work from Kars de Jong[2](the
set_io_map()andset_mem_map()are a blatant cut&paste), and it follows the NetBSD code[3] (when it made sense) - credit goes where credit is due.
Thanks for your series!
Quoted 4 lines
And, finally, the extremly sad part:
1) i've forced the word and long I/O helpers to be little endian, and this is clearly a big no (see
io_mm.h).
Can't that be avoided by setting ISA_SEX/isa_sex appropriately?
Gr{oetje,eeting}s,
Geert
Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected] In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds
Quoted 5 lines · Geert Uytterhoeven
Quoted 3 lines
1) i've forced the word and long I/O helpers to be little endian, and this is clearly a big no (see
io_mm.h).Can't that be avoided by setting ISA_SEX/isa_sex appropriately?
Hi Geert,
i tried ISA_SEX to do the be->le flipping but it broke all drivers: it seems like isa_insw()/isa_outsw()/isa_insl()/isa_outsl() must retain the host endianess.
Looking into it.
Signature · 2 lines
bye, p.
Geert Uytterhoeven
maintainerHi Paolo,
Quoted 9 lines · Paolo Pisati
Quoted 4 lines · Geert Uytterhoeven
Quoted 2 lines
1) i've forced the word and long I/O helpers to be little endian, and this is clearly a big no (see
io_mm.h).Can't that be avoided by setting ISA_SEX/isa_sex appropriately?
i tried
ISA_SEXto do thebe->leflipping but it broke all drivers: it seems like isa_insw()/isa_outsw()/isa_insl()/isa_outsl() must retain the host endianess.
Oh, I missed you're only overriding the non-repeating variants.
So ISA I/O registers are little endian, while ISA FIFO registers are native endian, as they operate on the raw data stored somewhere else (network, disk, ...)?
Gr{oetje,eeting}s,
Geert
Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected] In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds
Quoted 10 lines · Geert Uytterhoeven
Quoted 4 lines
i tried
ISA_SEXto do thebe->leflipping but it broke all drivers: it seems like isa_insw()/isa_outsw()/isa_insl()/isa_outsl() must retain the host endianess.Oh, I missed you're only overriding the non-repeating variants.
So ISA I/O registers are little endian, while ISA FIFO registers are native endian, as they operate on the raw data stored somewhere else (network, disk, ...)?
According to NetBSD[1], word access to the PCMCIA bus should be le but Kars didn't modify isa_insw()/isa_outsw()/isa_insl()/isa_outsl(), so that was my original assumption, but i'm not 100% sure here.
1: https://github.com/NetBSD/src/commit/07364bf8b04818675b3a1a1a23424be8c90ddfa2
Signature · 2 lines
bye, p.