Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

m68k/atari: Convert Falcon IDE drivers to platform drivers

Autoloading of Falcon IDE driver modules requires converting these
drivers to platform drivers.

Add platform device for Falcon IDE interface in Atari platform setup
code. Use this in the pata_falcon driver in place of the simple
platform device set up on the fly.

Convert falconide driver to use the same platform device that is used
by pata_falcon also. (With the introduction of a platform device for
the Atari Falcon IDE interface, the old Falcon IDE driver no longer
loads (resource already claimed by the platform device)).

Tested (as built-in driver) on my Atari Falcon.

Signed-off-by: Michael Schmitz <schmitzmic@gmail.com>
Acked-by: Bartlomiej Zolnierkiewicz <b.zolnierkie@samsung.com>
Link: https://lore.kernel.org/r/1573008449-8226-1-git-send-email-schmitzmic@gmail.com
Signed-off-by: Geert Uytterhoeven <geert@linux-m68k.org>

authored by

Michael Schmitz and committed by
Geert Uytterhoeven
5ed0794c 032f128d

+95 -34
+27
arch/m68k/atari/config.c
··· 869 869 }; 870 870 #endif 871 871 872 + /* 873 + * Falcon IDE interface 874 + */ 875 + 876 + #define FALCON_IDE_BASE 0xfff00000 877 + 878 + static const struct resource atari_falconide_rsrc[] __initconst = { 879 + { 880 + .flags = IORESOURCE_MEM, 881 + .start = FALCON_IDE_BASE, 882 + .end = FALCON_IDE_BASE + 0x39, 883 + }, 884 + { 885 + .flags = IORESOURCE_IRQ, 886 + .start = IRQ_MFP_FSCSI, 887 + .end = IRQ_MFP_FSCSI, 888 + }, 889 + }; 890 + 872 891 int __init atari_platform_init(void) 873 892 { 893 + struct platform_device *pdev; 874 894 int rv = 0; 875 895 876 896 if (!MACH_IS_ATARI) ··· 931 911 platform_device_register_simple("atari_scsi", -1, 932 912 atari_scsi_tt_rsrc, ARRAY_SIZE(atari_scsi_tt_rsrc)); 933 913 #endif 914 + 915 + if (ATARIHW_PRESENT(IDE)) { 916 + pdev = platform_device_register_simple("atari-falcon-ide", -1, 917 + atari_falconide_rsrc, ARRAY_SIZE(atari_falconide_rsrc)); 918 + if (IS_ERR(pdev)) 919 + rv = PTR_ERR(pdev); 920 + } 934 921 935 922 return rv; 936 923 }
+28 -14
drivers/ata/pata_falcon.c
··· 33 33 #define DRV_NAME "pata_falcon" 34 34 #define DRV_VERSION "0.1.0" 35 35 36 - #define ATA_HD_BASE 0xfff00000 37 36 #define ATA_HD_CONTROL 0x39 38 37 39 38 static struct scsi_host_template pata_falcon_sht = { ··· 119 120 .set_mode = pata_falcon_set_mode, 120 121 }; 121 122 122 - static int pata_falcon_init_one(void) 123 + static int __init pata_falcon_init_one(struct platform_device *pdev) 123 124 { 125 + struct resource *res; 124 126 struct ata_host *host; 125 127 struct ata_port *ap; 126 - struct platform_device *pdev; 127 128 void __iomem *base; 128 129 129 - if (!MACH_IS_ATARI || !ATARIHW_PRESENT(IDE)) 130 + dev_info(&pdev->dev, "Atari Falcon PATA controller\n"); 131 + 132 + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 133 + if (!res) 130 134 return -ENODEV; 131 135 132 - pr_info(DRV_NAME ": Atari Falcon PATA controller\n"); 133 - 134 - pdev = platform_device_register_simple(DRV_NAME, 0, NULL, 0); 135 - if (IS_ERR(pdev)) 136 - return PTR_ERR(pdev); 137 - 138 - if (!devm_request_mem_region(&pdev->dev, ATA_HD_BASE, 0x40, DRV_NAME)) { 139 - pr_err(DRV_NAME ": resources busy\n"); 136 + if (!devm_request_mem_region(&pdev->dev, res->start, 137 + resource_size(res), DRV_NAME)) { 138 + dev_err(&pdev->dev, "resources busy\n"); 140 139 return -EBUSY; 141 140 } 142 141 ··· 149 152 ap->flags |= ATA_FLAG_SLAVE_POSS | ATA_FLAG_NO_IORDY; 150 153 ap->flags |= ATA_FLAG_PIO_POLLING; 151 154 152 - base = (void __iomem *)ATA_HD_BASE; 155 + base = (void __iomem *)res->start; 153 156 ap->ioaddr.data_addr = base; 154 157 ap->ioaddr.error_addr = base + 1 + 1 * 4; 155 158 ap->ioaddr.feature_addr = base + 1 + 1 * 4; ··· 171 174 return ata_host_activate(host, 0, NULL, 0, &pata_falcon_sht); 172 175 } 173 176 174 - module_init(pata_falcon_init_one); 177 + static int __exit pata_falcon_remove_one(struct platform_device *pdev) 178 + { 179 + struct ata_host *host = platform_get_drvdata(pdev); 180 + 181 + ata_host_detach(host); 182 + 183 + return 0; 184 + } 185 + 186 + static struct platform_driver pata_falcon_driver = { 187 + .remove = __exit_p(pata_falcon_remove_one), 188 + .driver = { 189 + .name = "atari-falcon-ide", 190 + }, 191 + }; 192 + 193 + module_platform_driver_probe(pata_falcon_driver, pata_falcon_init_one); 175 194 176 195 MODULE_AUTHOR("Bartlomiej Zolnierkiewicz"); 177 196 MODULE_DESCRIPTION("low-level driver for Atari Falcon PATA"); 178 197 MODULE_LICENSE("GPL v2"); 198 + MODULE_ALIAS("platform:atari-falcon-ide"); 179 199 MODULE_VERSION(DRV_VERSION);
+40 -20
drivers/ide/falconide.c
··· 15 15 #include <linux/blkdev.h> 16 16 #include <linux/ide.h> 17 17 #include <linux/init.h> 18 + #include <linux/platform_device.h> 18 19 19 20 #include <asm/setup.h> 20 21 #include <asm/atarihw.h> ··· 26 25 #define DRV_NAME "falconide" 27 26 28 27 /* 29 - * Base of the IDE interface 30 - */ 31 - 32 - #define ATA_HD_BASE 0xfff00000 33 - 34 - /* 35 - * Offsets from the above base 28 + * Offsets from base address 36 29 */ 37 30 38 31 #define ATA_HD_CONTROL 0x39 ··· 109 114 .chipset = ide_generic, 110 115 }; 111 116 112 - static void __init falconide_setup_ports(struct ide_hw *hw) 117 + static void __init falconide_setup_ports(struct ide_hw *hw, unsigned long base) 113 118 { 114 119 int i; 115 120 116 121 memset(hw, 0, sizeof(*hw)); 117 122 118 - hw->io_ports.data_addr = ATA_HD_BASE; 123 + hw->io_ports.data_addr = base; 119 124 120 125 for (i = 1; i < 8; i++) 121 - hw->io_ports_array[i] = ATA_HD_BASE + 1 + i * 4; 126 + hw->io_ports_array[i] = base + 1 + i * 4; 122 127 123 - hw->io_ports.ctl_addr = ATA_HD_BASE + ATA_HD_CONTROL; 128 + hw->io_ports.ctl_addr = base + ATA_HD_CONTROL; 124 129 125 130 hw->irq = IRQ_MFP_IDE; 126 131 } ··· 129 134 * Probe for a Falcon IDE interface 130 135 */ 131 136 132 - static int __init falconide_init(void) 137 + static int __init falconide_init(struct platform_device *pdev) 133 138 { 139 + struct resource *res; 134 140 struct ide_host *host; 135 141 struct ide_hw hw, *hws[] = { &hw }; 142 + unsigned long base; 136 143 int rc; 137 144 138 - if (!MACH_IS_ATARI || !ATARIHW_PRESENT(IDE)) 145 + dev_info(&pdev->dev, "Atari Falcon IDE controller\n"); 146 + 147 + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 148 + if (!res) 139 149 return -ENODEV; 140 150 141 - printk(KERN_INFO "ide: Falcon IDE controller\n"); 142 - 143 - if (!request_mem_region(ATA_HD_BASE, 0x40, DRV_NAME)) { 144 - printk(KERN_ERR "%s: resources busy\n", DRV_NAME); 151 + if (!devm_request_mem_region(&pdev->dev, res->start, 152 + resource_size(res), DRV_NAME)) { 153 + dev_err(&pdev->dev, "resources busy\n"); 145 154 return -EBUSY; 146 155 } 147 156 148 - falconide_setup_ports(&hw); 157 + base = (unsigned long)res->start; 158 + 159 + falconide_setup_ports(&hw, base); 149 160 150 161 host = ide_host_alloc(&falconide_port_info, hws, 1); 151 162 if (host == NULL) { ··· 170 169 err_free: 171 170 ide_host_free(host); 172 171 err: 173 - release_mem_region(ATA_HD_BASE, 0x40); 172 + release_mem_region(res->start, resource_size(res)); 174 173 return rc; 175 174 } 176 175 177 - module_init(falconide_init); 176 + static int falconide_remove(struct platform_device *pdev) 177 + { 178 + struct ide_host *host = dev_get_drvdata(&pdev->dev); 178 179 180 + ide_host_remove(host); 181 + 182 + return 0; 183 + } 184 + 185 + static struct platform_driver ide_falcon_driver = { 186 + .remove = falconide_remove, 187 + .driver = { 188 + .name = "atari-falcon-ide", 189 + }, 190 + }; 191 + 192 + module_platform_driver_probe(ide_falcon_driver, falconide_init); 193 + 194 + MODULE_AUTHOR("Geert Uytterhoeven"); 195 + MODULE_DESCRIPTION("low-level driver for Atari Falcon IDE"); 179 196 MODULE_LICENSE("GPL"); 197 + MODULE_ALIAS("platform:atari-falcon-ide");