blob: 2b43be3bca0a1f5a4d1282ee9a73e1c25d097877 [file] [log] [blame]
Anton Vorontsov8cb1f562007-10-11 23:53:58 +02001/*
2 * Platform IDE driver
3 *
4 * Copyright (C) 2007 MontaVista Software
5 *
6 * Maintainer: Kumar Gala <galak@kernel.crashing.org>
7 *
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the
10 * Free Software Foundation; either version 2 of the License, or (at your
11 * option) any later version.
12 */
13
14#include <linux/types.h>
15#include <linux/init.h>
16#include <linux/kernel.h>
17#include <linux/ide.h>
18#include <linux/ioport.h>
19#include <linux/module.h>
Jeff Garzik0a87e3e2008-02-01 18:02:30 -050020#include <linux/ata_platform.h>
Anton Vorontsov8cb1f562007-10-11 23:53:58 +020021#include <linux/platform_device.h>
Thomas Gleixner89e9aad2011-08-04 01:29:51 -070022#include <linux/interrupt.h>
Anton Vorontsov8cb1f562007-10-11 23:53:58 +020023#include <linux/io.h>
24
Greg Kroah-Hartmanfe31edc2012-12-21 13:21:03 -080025static void plat_ide_setup_ports(struct ide_hw *hw, void __iomem *base,
26 void __iomem *ctrl,
27 struct pata_platform_info *pdata, int irq)
Anton Vorontsov8cb1f562007-10-11 23:53:58 +020028{
29 unsigned long port = (unsigned long)base;
Bartlomiej Zolnierkiewiczbaa8f3e2007-10-20 00:32:31 +020030 int i;
Anton Vorontsov8cb1f562007-10-11 23:53:58 +020031
Bartlomiej Zolnierkiewicz4c3032d2008-04-27 15:38:32 +020032 hw->io_ports.data_addr = port;
Anton Vorontsov8cb1f562007-10-11 23:53:58 +020033
34 port += (1 << pdata->ioport_shift);
Bartlomiej Zolnierkiewicz4c3032d2008-04-27 15:38:32 +020035 for (i = 1; i <= 7;
Anton Vorontsov8cb1f562007-10-11 23:53:58 +020036 i++, port += (1 << pdata->ioport_shift))
Bartlomiej Zolnierkiewicz4c3032d2008-04-27 15:38:32 +020037 hw->io_ports_array[i] = port;
Anton Vorontsov8cb1f562007-10-11 23:53:58 +020038
Bartlomiej Zolnierkiewicz4c3032d2008-04-27 15:38:32 +020039 hw->io_ports.ctl_addr = (unsigned long)ctrl;
Anton Vorontsov8cb1f562007-10-11 23:53:58 +020040
Bartlomiej Zolnierkiewicz57c802e2008-01-26 20:13:05 +010041 hw->irq = irq;
Anton Vorontsov8cb1f562007-10-11 23:53:58 +020042}
43
Bartlomiej Zolnierkiewicz7b60fa12008-07-16 20:33:42 +020044static const struct ide_port_info platform_ide_port_info = {
45 .host_flags = IDE_HFLAG_NO_DMA,
Bartlomiej Zolnierkiewicz29e52cf2009-05-17 19:12:22 +020046 .chipset = ide_generic,
Bartlomiej Zolnierkiewicz7b60fa12008-07-16 20:33:42 +020047};
48
Greg Kroah-Hartmanfe31edc2012-12-21 13:21:03 -080049static int plat_ide_probe(struct platform_device *pdev)
Anton Vorontsov8cb1f562007-10-11 23:53:58 +020050{
51 struct resource *res_base, *res_alt, *res_irq;
Bartlomiej Zolnierkiewicz04244932008-02-01 23:09:35 +010052 void __iomem *base, *alt_base;
Anton Vorontsov8cb1f562007-10-11 23:53:58 +020053 struct pata_platform_info *pdata;
Bartlomiej Zolnierkiewicz48c3c102008-07-23 19:55:57 +020054 struct ide_host *host;
Bartlomiej Zolnierkiewiczc97c6ac2008-07-23 19:55:50 +020055 int ret = 0, mmio = 0;
Bartlomiej Zolnierkiewicz9f36d312009-05-17 19:12:25 +020056 struct ide_hw hw, *hws[] = { &hw };
Bartlomiej Zolnierkiewicz7b60fa12008-07-16 20:33:42 +020057 struct ide_port_info d = platform_ide_port_info;
Anton Vorontsov8cb1f562007-10-11 23:53:58 +020058
Jingoo Han7b6b5612013-07-30 17:16:47 +090059 pdata = dev_get_platdata(&pdev->dev);
Anton Vorontsov8cb1f562007-10-11 23:53:58 +020060
61 /* get a pointer to the register memory */
62 res_base = platform_get_resource(pdev, IORESOURCE_IO, 0);
63 res_alt = platform_get_resource(pdev, IORESOURCE_IO, 1);
64
65 if (!res_base || !res_alt) {
66 res_base = platform_get_resource(pdev, IORESOURCE_MEM, 0);
67 res_alt = platform_get_resource(pdev, IORESOURCE_MEM, 1);
68 if (!res_base || !res_alt) {
69 ret = -ENOMEM;
70 goto out;
71 }
72 mmio = 1;
73 }
74
75 res_irq = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
76 if (!res_irq) {
77 ret = -EINVAL;
78 goto out;
79 }
80
81 if (mmio) {
Bartlomiej Zolnierkiewicz04244932008-02-01 23:09:35 +010082 base = devm_ioremap(&pdev->dev,
H Hartley Sweeten30433d82009-11-23 10:30:34 -080083 res_base->start, resource_size(res_base));
Bartlomiej Zolnierkiewicz04244932008-02-01 23:09:35 +010084 alt_base = devm_ioremap(&pdev->dev,
H Hartley Sweeten30433d82009-11-23 10:30:34 -080085 res_alt->start, resource_size(res_alt));
Anton Vorontsov8cb1f562007-10-11 23:53:58 +020086 } else {
Bartlomiej Zolnierkiewicz04244932008-02-01 23:09:35 +010087 base = devm_ioport_map(&pdev->dev,
H Hartley Sweeten30433d82009-11-23 10:30:34 -080088 res_base->start, resource_size(res_base));
Bartlomiej Zolnierkiewicz04244932008-02-01 23:09:35 +010089 alt_base = devm_ioport_map(&pdev->dev,
H Hartley Sweeten30433d82009-11-23 10:30:34 -080090 res_alt->start, resource_size(res_alt));
Anton Vorontsov8cb1f562007-10-11 23:53:58 +020091 }
92
Bartlomiej Zolnierkiewicz57c802e2008-01-26 20:13:05 +010093 memset(&hw, 0, sizeof(hw));
Bartlomiej Zolnierkiewicz04244932008-02-01 23:09:35 +010094 plat_ide_setup_ports(&hw, base, alt_base, pdata, res_irq->start);
Bartlomiej Zolnierkiewicz57c802e2008-01-26 20:13:05 +010095 hw.dev = &pdev->dev;
96
Thomas Gleixner89e9aad2011-08-04 01:29:51 -070097 d.irq_flags = res_irq->flags & IRQF_TRIGGER_MASK;
98 if (res_irq->flags & IORESOURCE_IRQ_SHAREABLE)
99 d.irq_flags |= IRQF_SHARED;
100
Bartlomiej Zolnierkiewicz761052e2008-07-23 19:55:54 +0200101 if (mmio)
Bartlomiej Zolnierkiewicz7b60fa12008-07-16 20:33:42 +0200102 d.host_flags |= IDE_HFLAG_MMIO;
Bartlomiej Zolnierkiewicz57c802e2008-01-26 20:13:05 +0100103
Bartlomiej Zolnierkiewiczdca39832009-05-17 19:12:24 +0200104 ret = ide_host_add(&d, hws, 1, &host);
Bartlomiej Zolnierkiewicz6f904d02008-07-23 19:55:57 +0200105 if (ret)
Bartlomiej Zolnierkiewicz48c3c102008-07-23 19:55:57 +0200106 goto out;
Anton Vorontsov8cb1f562007-10-11 23:53:58 +0200107
Bartlomiej Zolnierkiewicz48c3c102008-07-23 19:55:57 +0200108 platform_set_drvdata(pdev, host);
Anton Vorontsov8cb1f562007-10-11 23:53:58 +0200109
110 return 0;
111
112out:
113 return ret;
114}
115
Greg Kroah-Hartmanfe31edc2012-12-21 13:21:03 -0800116static int plat_ide_remove(struct platform_device *pdev)
Anton Vorontsov8cb1f562007-10-11 23:53:58 +0200117{
Greg Kroah-Hartmanfcb52072009-04-30 14:43:31 -0700118 struct ide_host *host = dev_get_drvdata(&pdev->dev);
Anton Vorontsov8cb1f562007-10-11 23:53:58 +0200119
Bartlomiej Zolnierkiewicz48c3c102008-07-23 19:55:57 +0200120 ide_host_remove(host);
Anton Vorontsov8cb1f562007-10-11 23:53:58 +0200121
122 return 0;
123}
124
125static struct platform_driver platform_ide_driver = {
126 .driver = {
127 .name = "pata_platform",
128 },
129 .probe = plat_ide_probe,
Greg Kroah-Hartmanfe31edc2012-12-21 13:21:03 -0800130 .remove = plat_ide_remove,
Anton Vorontsov8cb1f562007-10-11 23:53:58 +0200131};
132
Christoph Jaegera53dae42014-04-09 09:28:01 +0200133module_platform_driver(platform_ide_driver);
Anton Vorontsov8cb1f562007-10-11 23:53:58 +0200134
135MODULE_DESCRIPTION("Platform IDE driver");
136MODULE_LICENSE("GPL");
Kay Sievers458622f2008-04-18 13:41:57 -0700137MODULE_ALIAS("platform:pata_platform");