blob: 91639fd6c276bb9a321410e636d3ed36833d37c0 [file] [log] [blame]
Thomas Gleixner2874c5f2019-05-27 08:55:01 +02001// SPDX-License-Identifier: GPL-2.0-or-later
Anton Vorontsov8cb1f562007-10-11 23:53:58 +02002/*
3 * Platform IDE driver
4 *
5 * Copyright (C) 2007 MontaVista Software
6 *
7 * Maintainer: Kumar Gala <galak@kernel.crashing.org>
Anton Vorontsov8cb1f562007-10-11 23:53:58 +02008 */
9
10#include <linux/types.h>
11#include <linux/init.h>
12#include <linux/kernel.h>
13#include <linux/ide.h>
14#include <linux/ioport.h>
15#include <linux/module.h>
Jeff Garzik0a87e3e2008-02-01 18:02:30 -050016#include <linux/ata_platform.h>
Anton Vorontsov8cb1f562007-10-11 23:53:58 +020017#include <linux/platform_device.h>
Thomas Gleixner89e9aad2011-08-04 01:29:51 -070018#include <linux/interrupt.h>
Anton Vorontsov8cb1f562007-10-11 23:53:58 +020019#include <linux/io.h>
20
Greg Kroah-Hartmanfe31edc2012-12-21 13:21:03 -080021static void plat_ide_setup_ports(struct ide_hw *hw, void __iomem *base,
22 void __iomem *ctrl,
23 struct pata_platform_info *pdata, int irq)
Anton Vorontsov8cb1f562007-10-11 23:53:58 +020024{
25 unsigned long port = (unsigned long)base;
Bartlomiej Zolnierkiewiczbaa8f3e2007-10-20 00:32:31 +020026 int i;
Anton Vorontsov8cb1f562007-10-11 23:53:58 +020027
Bartlomiej Zolnierkiewicz4c3032d2008-04-27 15:38:32 +020028 hw->io_ports.data_addr = port;
Anton Vorontsov8cb1f562007-10-11 23:53:58 +020029
30 port += (1 << pdata->ioport_shift);
Bartlomiej Zolnierkiewicz4c3032d2008-04-27 15:38:32 +020031 for (i = 1; i <= 7;
Anton Vorontsov8cb1f562007-10-11 23:53:58 +020032 i++, port += (1 << pdata->ioport_shift))
Bartlomiej Zolnierkiewicz4c3032d2008-04-27 15:38:32 +020033 hw->io_ports_array[i] = port;
Anton Vorontsov8cb1f562007-10-11 23:53:58 +020034
Bartlomiej Zolnierkiewicz4c3032d2008-04-27 15:38:32 +020035 hw->io_ports.ctl_addr = (unsigned long)ctrl;
Anton Vorontsov8cb1f562007-10-11 23:53:58 +020036
Bartlomiej Zolnierkiewicz57c802e2008-01-26 20:13:05 +010037 hw->irq = irq;
Anton Vorontsov8cb1f562007-10-11 23:53:58 +020038}
39
Bartlomiej Zolnierkiewicz7b60fa12008-07-16 20:33:42 +020040static const struct ide_port_info platform_ide_port_info = {
41 .host_flags = IDE_HFLAG_NO_DMA,
Bartlomiej Zolnierkiewicz29e52cf2009-05-17 19:12:22 +020042 .chipset = ide_generic,
Bartlomiej Zolnierkiewicz7b60fa12008-07-16 20:33:42 +020043};
44
Greg Kroah-Hartmanfe31edc2012-12-21 13:21:03 -080045static int plat_ide_probe(struct platform_device *pdev)
Anton Vorontsov8cb1f562007-10-11 23:53:58 +020046{
47 struct resource *res_base, *res_alt, *res_irq;
Bartlomiej Zolnierkiewicz04244932008-02-01 23:09:35 +010048 void __iomem *base, *alt_base;
Anton Vorontsov8cb1f562007-10-11 23:53:58 +020049 struct pata_platform_info *pdata;
Bartlomiej Zolnierkiewicz48c3c102008-07-23 19:55:57 +020050 struct ide_host *host;
Bartlomiej Zolnierkiewiczc97c6ac2008-07-23 19:55:50 +020051 int ret = 0, mmio = 0;
Bartlomiej Zolnierkiewicz9f36d312009-05-17 19:12:25 +020052 struct ide_hw hw, *hws[] = { &hw };
Bartlomiej Zolnierkiewicz7b60fa12008-07-16 20:33:42 +020053 struct ide_port_info d = platform_ide_port_info;
Anton Vorontsov8cb1f562007-10-11 23:53:58 +020054
Jingoo Han7b6b5612013-07-30 17:16:47 +090055 pdata = dev_get_platdata(&pdev->dev);
Anton Vorontsov8cb1f562007-10-11 23:53:58 +020056
57 /* get a pointer to the register memory */
58 res_base = platform_get_resource(pdev, IORESOURCE_IO, 0);
59 res_alt = platform_get_resource(pdev, IORESOURCE_IO, 1);
60
61 if (!res_base || !res_alt) {
62 res_base = platform_get_resource(pdev, IORESOURCE_MEM, 0);
63 res_alt = platform_get_resource(pdev, IORESOURCE_MEM, 1);
64 if (!res_base || !res_alt) {
65 ret = -ENOMEM;
66 goto out;
67 }
68 mmio = 1;
69 }
70
71 res_irq = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
72 if (!res_irq) {
73 ret = -EINVAL;
74 goto out;
75 }
76
77 if (mmio) {
Bartlomiej Zolnierkiewicz04244932008-02-01 23:09:35 +010078 base = devm_ioremap(&pdev->dev,
H Hartley Sweeten30433d82009-11-23 10:30:34 -080079 res_base->start, resource_size(res_base));
Bartlomiej Zolnierkiewicz04244932008-02-01 23:09:35 +010080 alt_base = devm_ioremap(&pdev->dev,
H Hartley Sweeten30433d82009-11-23 10:30:34 -080081 res_alt->start, resource_size(res_alt));
Anton Vorontsov8cb1f562007-10-11 23:53:58 +020082 } else {
Bartlomiej Zolnierkiewicz04244932008-02-01 23:09:35 +010083 base = devm_ioport_map(&pdev->dev,
H Hartley Sweeten30433d82009-11-23 10:30:34 -080084 res_base->start, resource_size(res_base));
Bartlomiej Zolnierkiewicz04244932008-02-01 23:09:35 +010085 alt_base = devm_ioport_map(&pdev->dev,
H Hartley Sweeten30433d82009-11-23 10:30:34 -080086 res_alt->start, resource_size(res_alt));
Anton Vorontsov8cb1f562007-10-11 23:53:58 +020087 }
88
Bartlomiej Zolnierkiewicz57c802e2008-01-26 20:13:05 +010089 memset(&hw, 0, sizeof(hw));
Bartlomiej Zolnierkiewicz04244932008-02-01 23:09:35 +010090 plat_ide_setup_ports(&hw, base, alt_base, pdata, res_irq->start);
Bartlomiej Zolnierkiewicz57c802e2008-01-26 20:13:05 +010091 hw.dev = &pdev->dev;
92
Thomas Gleixner89e9aad2011-08-04 01:29:51 -070093 d.irq_flags = res_irq->flags & IRQF_TRIGGER_MASK;
94 if (res_irq->flags & IORESOURCE_IRQ_SHAREABLE)
95 d.irq_flags |= IRQF_SHARED;
96
Bartlomiej Zolnierkiewicz761052e2008-07-23 19:55:54 +020097 if (mmio)
Bartlomiej Zolnierkiewicz7b60fa12008-07-16 20:33:42 +020098 d.host_flags |= IDE_HFLAG_MMIO;
Bartlomiej Zolnierkiewicz57c802e2008-01-26 20:13:05 +010099
Bartlomiej Zolnierkiewiczdca39832009-05-17 19:12:24 +0200100 ret = ide_host_add(&d, hws, 1, &host);
Bartlomiej Zolnierkiewicz6f904d02008-07-23 19:55:57 +0200101 if (ret)
Bartlomiej Zolnierkiewicz48c3c102008-07-23 19:55:57 +0200102 goto out;
Anton Vorontsov8cb1f562007-10-11 23:53:58 +0200103
Bartlomiej Zolnierkiewicz48c3c102008-07-23 19:55:57 +0200104 platform_set_drvdata(pdev, host);
Anton Vorontsov8cb1f562007-10-11 23:53:58 +0200105
106 return 0;
107
108out:
109 return ret;
110}
111
Greg Kroah-Hartmanfe31edc2012-12-21 13:21:03 -0800112static int plat_ide_remove(struct platform_device *pdev)
Anton Vorontsov8cb1f562007-10-11 23:53:58 +0200113{
Greg Kroah-Hartmanfcb52072009-04-30 14:43:31 -0700114 struct ide_host *host = dev_get_drvdata(&pdev->dev);
Anton Vorontsov8cb1f562007-10-11 23:53:58 +0200115
Bartlomiej Zolnierkiewicz48c3c102008-07-23 19:55:57 +0200116 ide_host_remove(host);
Anton Vorontsov8cb1f562007-10-11 23:53:58 +0200117
118 return 0;
119}
120
121static struct platform_driver platform_ide_driver = {
122 .driver = {
123 .name = "pata_platform",
124 },
125 .probe = plat_ide_probe,
Greg Kroah-Hartmanfe31edc2012-12-21 13:21:03 -0800126 .remove = plat_ide_remove,
Anton Vorontsov8cb1f562007-10-11 23:53:58 +0200127};
128
Christoph Jaegera53dae42014-04-09 09:28:01 +0200129module_platform_driver(platform_ide_driver);
Anton Vorontsov8cb1f562007-10-11 23:53:58 +0200130
131MODULE_DESCRIPTION("Platform IDE driver");
132MODULE_LICENSE("GPL");
Kay Sievers458622f2008-04-18 13:41:57 -0700133MODULE_ALIAS("platform:pata_platform");