blob: 2aa5c38022f3b7d663eaf2c8d565fc88c8ce1afb [file] [log] [blame]
Ivo van Doorn5d78d342009-10-15 21:38:19 +02001/*
Gertjan van Wingerde9c9a0d12009-11-08 16:39:55 +01002 Copyright (C) 2004 - 2009 Ivo van Doorn <IvDoorn@gmail.com>
3 Copyright (C) 2004 - 2009 Felix Fietkau <nbd@openwrt.org>
Ivo van Doorn5d78d342009-10-15 21:38:19 +02004 <http://rt2x00.serialmonkey.com>
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
18 Free Software Foundation, Inc.,
19 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 */
21
22/*
23 Module: rt2x00soc
24 Abstract: rt2x00 generic soc device routines.
25 */
26
27#include <linux/bug.h>
28#include <linux/kernel.h>
29#include <linux/module.h>
30#include <linux/platform_device.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090031#include <linux/slab.h>
Ivo van Doorn5d78d342009-10-15 21:38:19 +020032
33#include "rt2x00.h"
34#include "rt2x00soc.h"
35
36static void rt2x00soc_free_reg(struct rt2x00_dev *rt2x00dev)
37{
38 kfree(rt2x00dev->rf);
39 rt2x00dev->rf = NULL;
40
41 kfree(rt2x00dev->eeprom);
42 rt2x00dev->eeprom = NULL;
Gertjan van Wingerdeef8397c2010-11-13 19:11:22 +010043
44 iounmap(rt2x00dev->csr.base);
Ivo van Doorn5d78d342009-10-15 21:38:19 +020045}
46
47static int rt2x00soc_alloc_reg(struct rt2x00_dev *rt2x00dev)
48{
49 struct platform_device *pdev = to_platform_device(rt2x00dev->dev);
50 struct resource *res;
51
52 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
53 if (!res)
54 return -ENODEV;
55
Gertjan van Wingerdeef8397c2010-11-13 19:11:22 +010056 rt2x00dev->csr.base = ioremap(res->start, resource_size(res));
Ivo van Doorn5d78d342009-10-15 21:38:19 +020057 if (!rt2x00dev->csr.base)
Gertjan van Wingerdeef8397c2010-11-13 19:11:22 +010058 return -ENOMEM;
Ivo van Doorn5d78d342009-10-15 21:38:19 +020059
60 rt2x00dev->eeprom = kzalloc(rt2x00dev->ops->eeprom_size, GFP_KERNEL);
61 if (!rt2x00dev->eeprom)
62 goto exit;
63
64 rt2x00dev->rf = kzalloc(rt2x00dev->ops->rf_size, GFP_KERNEL);
65 if (!rt2x00dev->rf)
66 goto exit;
67
68 return 0;
69
70exit:
71 ERROR_PROBE("Failed to allocate registers.\n");
72 rt2x00soc_free_reg(rt2x00dev);
73
74 return -ENOMEM;
75}
76
Gertjan van Wingerde714fa6632010-02-13 20:55:48 +010077int rt2x00soc_probe(struct platform_device *pdev, const struct rt2x00_ops *ops)
Ivo van Doorn5d78d342009-10-15 21:38:19 +020078{
79 struct ieee80211_hw *hw;
80 struct rt2x00_dev *rt2x00dev;
81 int retval;
82
83 hw = ieee80211_alloc_hw(sizeof(struct rt2x00_dev), ops->hw);
84 if (!hw) {
85 ERROR_PROBE("Failed to allocate hardware.\n");
86 return -ENOMEM;
87 }
88
89 platform_set_drvdata(pdev, hw);
90
91 rt2x00dev = hw->priv;
92 rt2x00dev->dev = &pdev->dev;
93 rt2x00dev->ops = ops;
94 rt2x00dev->hw = hw;
95 rt2x00dev->irq = platform_get_irq(pdev, 0);
96 rt2x00dev->name = pdev->dev.driver->name;
97
Gertjan van Wingerdecea90e52010-02-13 20:55:47 +010098 rt2x00_set_chip_intf(rt2x00dev, RT2X00_CHIP_INTF_SOC);
Ivo van Doorn5d78d342009-10-15 21:38:19 +020099
100 retval = rt2x00soc_alloc_reg(rt2x00dev);
101 if (retval)
102 goto exit_free_device;
103
104 retval = rt2x00lib_probe_dev(rt2x00dev);
105 if (retval)
106 goto exit_free_reg;
107
108 return 0;
109
110exit_free_reg:
111 rt2x00soc_free_reg(rt2x00dev);
112
113exit_free_device:
114 ieee80211_free_hw(hw);
115
116 return retval;
117}
Helmut Schaa31f66be2010-03-03 17:42:55 +0100118EXPORT_SYMBOL_GPL(rt2x00soc_probe);
Ivo van Doorn5d78d342009-10-15 21:38:19 +0200119
120int rt2x00soc_remove(struct platform_device *pdev)
121{
122 struct ieee80211_hw *hw = platform_get_drvdata(pdev);
123 struct rt2x00_dev *rt2x00dev = hw->priv;
124
125 /*
126 * Free all allocated data.
127 */
128 rt2x00lib_remove_dev(rt2x00dev);
129 rt2x00soc_free_reg(rt2x00dev);
130 ieee80211_free_hw(hw);
131
132 return 0;
133}
134EXPORT_SYMBOL_GPL(rt2x00soc_remove);
135
136#ifdef CONFIG_PM
137int rt2x00soc_suspend(struct platform_device *pdev, pm_message_t state)
138{
139 struct ieee80211_hw *hw = platform_get_drvdata(pdev);
140 struct rt2x00_dev *rt2x00dev = hw->priv;
141
142 return rt2x00lib_suspend(rt2x00dev, state);
143}
144EXPORT_SYMBOL_GPL(rt2x00soc_suspend);
145
146int rt2x00soc_resume(struct platform_device *pdev)
147{
148 struct ieee80211_hw *hw = platform_get_drvdata(pdev);
149 struct rt2x00_dev *rt2x00dev = hw->priv;
150
151 return rt2x00lib_resume(rt2x00dev);
152}
153EXPORT_SYMBOL_GPL(rt2x00soc_resume);
154#endif /* CONFIG_PM */
155
156/*
157 * rt2x00soc module information.
158 */
159MODULE_AUTHOR(DRV_PROJECT);
160MODULE_VERSION(DRV_VERSION);
161MODULE_DESCRIPTION("rt2x00 soc library");
162MODULE_LICENSE("GPL");