[rdc] fix panic on boot due to invalid IORESOURCE for MFD cells, fix gpio value setting
[openwrt/svn-archive/archive.git] / target / linux / rdc / patches-2.6.32 / 001-rdc321x_mfd_southbridge.patch
1 This patch adds a new MFD driver for the RDC321x southbridge. This southbridge
2 is always present in the RDC321x System-on-a-Chip and provides access to some
3 GPIOs as well as a watchdog. Access to these two functions is done using the
4 southbridge PCI device configuration space.
5
6 Signed-off-by: Florian Fainelli <florian@openwrt.org>
7 ---
8 Changes from v2:
9 - pass the pci_dev pointer to MFD cell drivers as platform_data
10 - remove the printk(KERN_ERR and use dev_err instead
11 - removed pci_dev accessors
12 - use DEFINE_PCI_DEVICE_TABLE
13
14 Index: linux-2.6.32.10/drivers/mfd/Kconfig
15 ===================================================================
16 --- linux-2.6.32.10.orig/drivers/mfd/Kconfig 2010-03-15 16:52:04.000000000 +0100
17 +++ linux-2.6.32.10/drivers/mfd/Kconfig 2010-05-15 21:48:27.000000000 +0200
18 @@ -305,6 +305,15 @@
19 This enables the PCAP ASIC present on EZX Phones. This is
20 needed for MMC, TouchScreen, Sound, USB, etc..
21
22 +config MFD_RDC321X
23 + tristate "Support for RDC-R321x southbridge"
24 + select MFD_CORE
25 + depends on PCI
26 + help
27 + Say yes here if you want to have support for the RDC R-321x SoC
28 + southbridge which provides access to GPIOs and Watchdog using the
29 + southbridge PCI device configuration space.
30 +
31 endmenu
32
33 menu "Multimedia Capabilities Port drivers"
34 Index: linux-2.6.32.10/drivers/mfd/Makefile
35 ===================================================================
36 --- linux-2.6.32.10.orig/drivers/mfd/Makefile 2010-03-15 16:52:04.000000000 +0100
37 +++ linux-2.6.32.10/drivers/mfd/Makefile 2010-05-15 21:48:27.000000000 +0200
38 @@ -50,3 +50,5 @@
39 obj-$(CONFIG_PCF50633_GPIO) += pcf50633-gpio.o
40 obj-$(CONFIG_AB3100_CORE) += ab3100-core.o
41 obj-$(CONFIG_AB3100_OTP) += ab3100-otp.o
42 +
43 +obj-$(CONFIG_MFD_RDC321X) += rdc321x-southbridge.o
44 Index: linux-2.6.32.10/drivers/mfd/rdc321x-southbridge.c
45 ===================================================================
46 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
47 +++ linux-2.6.32.10/drivers/mfd/rdc321x-southbridge.c 2010-05-15 22:53:39.000000000 +0200
48 @@ -0,0 +1,123 @@
49 +/*
50 + * RDC321x MFD southbrige driver
51 + *
52 + * Copyright (C) 2007-2010 Florian Fainelli <florian@openwrt.org>
53 + * Copyright (C) 2010 Bernhard Loos <bernhardloos@googlemail.com>
54 + *
55 + * This program is free software; you can redistribute it and/or modify
56 + * it under the terms of the GNU General Public License as published by
57 + * the Free Software Foundation; either version 2 of the License, or
58 + * (at your option) any later version.
59 + *
60 + * This program is distributed in the hope that it will be useful,
61 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
62 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
63 + * GNU General Public License for more details.
64 + *
65 + * You should have received a copy of the GNU General Public License
66 + * along with this program; if not, write to the Free Software
67 + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
68 + *
69 + */
70 +#include <linux/init.h>
71 +#include <linux/module.h>
72 +#include <linux/kernel.h>
73 +#include <linux/platform_device.h>
74 +#include <linux/pci.h>
75 +#include <linux/mfd/core.h>
76 +#include <linux/mfd/rdc321x.h>
77 +
78 +static struct rdc321x_wdt_pdata rdc321x_wdt_pdata;
79 +
80 +static struct resource rdc321x_wdt_resource[] = {
81 + {
82 + .name = "wdt-reg",
83 + .start = RDC321X_WDT_CTRL,
84 + .end = RDC321X_WDT_CTRL + 0x3,
85 + .flags = IORESOURCE_IO,
86 + }
87 +};
88 +
89 +static struct rdc321x_gpio_pdata rdc321x_gpio_pdata = {
90 + .max_gpios = RDC321X_MAX_GPIO,
91 +};
92 +
93 +static struct resource rdc321x_gpio_resources[] = {
94 + {
95 + .name = "gpio-reg1",
96 + .start = RDC321X_GPIO_CTRL_REG1,
97 + .end = RDC321X_GPIO_CTRL_REG1 + 0x7,
98 + .flags = IORESOURCE_IO,
99 + }, {
100 + .name = "gpio-reg2",
101 + .start = RDC321X_GPIO_CTRL_REG2,
102 + .end = RDC321X_GPIO_CTRL_REG2 + 0x7,
103 + .flags = IORESOURCE_IO,
104 + }
105 +};
106 +
107 +static struct mfd_cell rdc321x_sb_cells[] = {
108 + {
109 + .name = "rdc321x-wdt",
110 + .resources = rdc321x_wdt_resource,
111 + .num_resources = ARRAY_SIZE(rdc321x_wdt_resource),
112 + .driver_data = &rdc321x_wdt_pdata,
113 + }, {
114 + .name = "rdc321x-gpio",
115 + .resources = rdc321x_gpio_resources,
116 + .num_resources = ARRAY_SIZE(rdc321x_gpio_resources),
117 + .driver_data = &rdc321x_gpio_pdata,
118 + },
119 +};
120 +
121 +static int __devinit rdc321x_sb_probe(struct pci_dev *pdev,
122 + const struct pci_device_id *ent)
123 +{
124 + int err;
125 +
126 + err = pci_enable_device(pdev);
127 + if (err) {
128 + dev_err(&pdev->dev, "failed to enable device\n");
129 + return err;
130 + }
131 +
132 + rdc321x_gpio_pdata.sb_pdev = pdev;
133 + rdc321x_wdt_pdata.sb_pdev = pdev;
134 +
135 + return mfd_add_devices(&pdev->dev, -1,
136 + rdc321x_sb_cells, ARRAY_SIZE(rdc321x_sb_cells), NULL, 0);
137 +}
138 +
139 +static void __devexit rdc321x_sb_remove(struct pci_dev *pdev)
140 +{
141 + mfd_remove_devices(&pdev->dev);
142 +}
143 +
144 +static DEFINE_PCI_DEVICE_TABLE(rdc321x_sb_table) = {
145 + { PCI_DEVICE(PCI_VENDOR_ID_RDC, PCI_DEVICE_ID_RDC_R6030) },
146 + {}
147 +};
148 +
149 +static struct pci_driver rdc321x_sb_driver = {
150 + .name = "RDC321x Southbridge",
151 + .id_table = rdc321x_sb_table,
152 + .probe = rdc321x_sb_probe,
153 + .remove = __devexit_p(rdc321x_sb_remove),
154 +};
155 +
156 +static int __init rdc321x_sb_init(void)
157 +{
158 + return pci_register_driver(&rdc321x_sb_driver);
159 +}
160 +
161 +static void __exit rdc321x_sb_exit(void)
162 +{
163 + pci_unregister_driver(&rdc321x_sb_driver);
164 +}
165 +
166 +module_init(rdc321x_sb_init);
167 +module_exit(rdc321x_sb_exit);
168 +
169 +MODULE_AUTHOR("Florian Fainelli <florian@openwrt.org>");
170 +MODULE_LICENSE("GPL");
171 +MODULE_DESCRIPTION("RDC R-321x MFD southbridge driver");
172 Index: linux-2.6.32.10/include/linux/mfd/rdc321x.h
173 ===================================================================
174 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
175 +++ linux-2.6.32.10/include/linux/mfd/rdc321x.h 2010-05-15 21:48:27.000000000 +0200
176 @@ -0,0 +1,26 @@
177 +#ifndef __RDC321X_MFD_H
178 +#define __RDC321X_MFD_H
179 +
180 +#include <linux/types.h>
181 +#include <linux/pci.h>
182 +
183 +/* Offsets to be accessed in the southbridge PCI
184 + * device configuration register */
185 +#define RDC321X_WDT_CTRL 0x44
186 +#define RDC321X_GPIO_CTRL_REG1 0x48
187 +#define RDC321X_GPIO_DATA_REG1 0x4c
188 +#define RDC321X_GPIO_CTRL_REG2 0x84
189 +#define RDC321X_GPIO_DATA_REG2 0x88
190 +
191 +#define RDC321X_MAX_GPIO 58
192 +
193 +struct rdc321x_gpio_pdata {
194 + struct pci_dev *sb_pdev;
195 + unsigned max_gpios;
196 +};
197 +
198 +struct rdc321x_wdt_pdata {
199 + struct pci_dev *sb_pdev;
200 +};
201 +
202 +#endif /* __RDC321X_MFD_H */