Merge branch 'dev' of git://git.kernel.org/pub/scm/linux/kernel/git/tytso/ext4
[pandora-kernel.git] / arch / mips / vr41xx / common / giu.c
1 /*
2  *  NEC VR4100 series GIU platform device.
3  *
4  *  Copyright (C) 2007  Yoichi Yuasa <yuasa@linux-mips.org>
5  *
6  *  This program is free software; you can redistribute it and/or modify
7  *  it under the terms of the GNU General Public License as published by
8  *  the Free Software Foundation; either version 2 of the License, or
9  *  (at your option) any later version.
10  *
11  *  This program is distributed in the hope that it will be useful,
12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  *  GNU General Public License for more details.
15  *
16  *  You should have received a copy of the GNU General Public License
17  *  along with this program; if not, write to the Free Software
18  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
19  */
20 #include <linux/errno.h>
21 #include <linux/init.h>
22 #include <linux/smp.h>
23 #include <linux/ioport.h>
24 #include <linux/platform_device.h>
25
26 #include <asm/cpu.h>
27 #include <asm/vr41xx/giu.h>
28 #include <asm/vr41xx/irq.h>
29
30 static struct resource giu_50pins_pullupdown_resource[] __initdata = {
31         {
32                 .start  = 0x0b000100,
33                 .end    = 0x0b00011f,
34                 .flags  = IORESOURCE_MEM,
35         },
36         {
37                 .start  = 0x0b0002e0,
38                 .end    = 0x0b0002e3,
39                 .flags  = IORESOURCE_MEM,
40         },
41         {
42                 .start  = GIUINT_IRQ,
43                 .end    = GIUINT_IRQ,
44                 .flags  = IORESOURCE_IRQ,
45         },
46 };
47
48 static struct resource giu_36pins_resource[] __initdata = {
49         {
50                 .start  = 0x0f000140,
51                 .end    = 0x0f00015f,
52                 .flags  = IORESOURCE_MEM,
53         },
54         {
55                 .start  = GIUINT_IRQ,
56                 .end    = GIUINT_IRQ,
57                 .flags  = IORESOURCE_IRQ,
58         },
59 };
60
61 static struct resource giu_48pins_resource[] __initdata = {
62         {
63                 .start  = 0x0f000140,
64                 .end    = 0x0f000167,
65                 .flags  = IORESOURCE_MEM,
66         },
67         {
68                 .start  = GIUINT_IRQ,
69                 .end    = GIUINT_IRQ,
70                 .flags  = IORESOURCE_IRQ,
71         },
72 };
73
74 static int __init vr41xx_giu_add(void)
75 {
76         struct platform_device *pdev;
77         struct resource *res;
78         unsigned int num;
79         int retval;
80
81         pdev = platform_device_alloc("GIU", -1);
82         if (!pdev)
83                 return -ENOMEM;
84
85         switch (current_cpu_type()) {
86         case CPU_VR4111:
87         case CPU_VR4121:
88                 pdev->id = GPIO_50PINS_PULLUPDOWN;
89                 res = giu_50pins_pullupdown_resource;
90                 num = ARRAY_SIZE(giu_50pins_pullupdown_resource);
91                 break;
92         case CPU_VR4122:
93         case CPU_VR4131:
94                 pdev->id = GPIO_36PINS;
95                 res = giu_36pins_resource;
96                 num = ARRAY_SIZE(giu_36pins_resource);
97                 break;
98         case CPU_VR4133:
99                 pdev->id = GPIO_48PINS_EDGE_SELECT;
100                 res = giu_48pins_resource;
101                 num = ARRAY_SIZE(giu_48pins_resource);
102                 break;
103         default:
104                 retval = -ENODEV;
105                 goto err_free_device;
106         }
107
108         retval = platform_device_add_resources(pdev, res, num);
109         if (retval)
110                 goto err_free_device;
111
112         retval = platform_device_add(pdev);
113         if (retval)
114                 goto err_free_device;
115
116         return 0;
117
118 err_free_device:
119         platform_device_put(pdev);
120
121         return retval;
122 }
123 device_initcall(vr41xx_giu_add);