]> err.no Git - linux-2.6/blob - drivers/ata/pata_of_platform.c
libata: pata_of_platform: OF-Platform PATA device driver
[linux-2.6] / drivers / ata / pata_of_platform.c
1 /*
2  * OF-platform PATA driver
3  *
4  * Copyright (c) 2007  MontaVista Software, Inc.
5  *                     Anton Vorontsov <avorontsov@ru.mvista.com>
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License (Version 2) as
9  * published by the Free Software Foundation.
10  */
11
12 #include <linux/kernel.h>
13 #include <linux/module.h>
14 #include <linux/of_platform.h>
15 #include <linux/pata_platform.h>
16
17 static int __devinit pata_of_platform_probe(struct of_device *ofdev,
18                                             const struct of_device_id *match)
19 {
20         int ret;
21         struct device_node *dn = ofdev->node;
22         struct resource io_res;
23         struct resource ctl_res;
24         struct resource irq_res;
25         unsigned int reg_shift = 0;
26         int pio_mode = 0;
27         int pio_mask;
28         const u32 *prop;
29
30         ret = of_address_to_resource(dn, 0, &io_res);
31         if (ret) {
32                 dev_err(&ofdev->dev, "can't get IO address from "
33                         "device tree\n");
34                 return -EINVAL;
35         }
36
37         ret = of_address_to_resource(dn, 1, &ctl_res);
38         if (ret) {
39                 dev_err(&ofdev->dev, "can't get CTL address from "
40                         "device tree\n");
41                 return -EINVAL;
42         }
43
44         ret = of_irq_to_resource(dn, 0, &irq_res);
45         if (ret == NO_IRQ)
46                 irq_res.start = irq_res.end = -1;
47         else
48                 irq_res.flags = 0;
49
50         prop = of_get_property(dn, "reg-shift", NULL);
51         if (prop)
52                 reg_shift = *prop;
53
54         prop = of_get_property(dn, "pio-mode", NULL);
55         if (prop) {
56                 pio_mode = *prop;
57                 if (pio_mode > 6) {
58                         dev_err(&ofdev->dev, "invalid pio-mode\n");
59                         return -EINVAL;
60                 }
61         } else {
62                 dev_info(&ofdev->dev, "pio-mode unspecified, assuming PIO0\n");
63         }
64
65         pio_mask = 1 << pio_mode;
66         pio_mask |= (1 << pio_mode) - 1;
67
68         return __pata_platform_probe(&ofdev->dev, &io_res, &ctl_res, &irq_res,
69                                      reg_shift, pio_mask);
70 }
71
72 static int __devexit pata_of_platform_remove(struct of_device *ofdev)
73 {
74         return __pata_platform_remove(&ofdev->dev);
75 }
76
77 static struct of_device_id pata_of_platform_match[] = {
78         { .compatible = "ata-generic", },
79         {},
80 };
81 MODULE_DEVICE_TABLE(of, pata_of_platform_match);
82
83 static struct of_platform_driver pata_of_platform_driver = {
84         .name           = "pata_of_platform",
85         .match_table    = pata_of_platform_match,
86         .probe          = pata_of_platform_probe,
87         .remove         = __devexit_p(pata_of_platform_remove),
88 };
89
90 static int __init pata_of_platform_init(void)
91 {
92         return of_register_platform_driver(&pata_of_platform_driver);
93 }
94 module_init(pata_of_platform_init);
95
96 static void __exit pata_of_platform_exit(void)
97 {
98         of_unregister_platform_driver(&pata_of_platform_driver);
99 }
100 module_exit(pata_of_platform_exit);
101
102 MODULE_DESCRIPTION("OF-platform PATA driver");
103 MODULE_AUTHOR("Anton Vorontsov <avorontsov@ru.mvista.com>");
104 MODULE_LICENSE("GPL");