539568c48953c4f7a0ae05004afafa0ee31d52c4
[deliverable/linux.git] / drivers / net / wireless / rt2x00 / rt2x00soc.c
1 /*
2 Copyright (C) 2004 - 2009 rt2x00 SourceForge Project
3 <http://rt2x00.serialmonkey.com>
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the
17 Free Software Foundation, Inc.,
18 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 */
20
21 /*
22 Module: rt2x00soc
23 Abstract: rt2x00 generic soc device routines.
24 */
25
26 #include <linux/bug.h>
27 #include <linux/kernel.h>
28 #include <linux/module.h>
29 #include <linux/platform_device.h>
30
31 #include "rt2x00.h"
32 #include "rt2x00soc.h"
33
34 static void rt2x00soc_free_reg(struct rt2x00_dev *rt2x00dev)
35 {
36 kfree(rt2x00dev->rf);
37 rt2x00dev->rf = NULL;
38
39 kfree(rt2x00dev->eeprom);
40 rt2x00dev->eeprom = NULL;
41 }
42
43 static int rt2x00soc_alloc_reg(struct rt2x00_dev *rt2x00dev)
44 {
45 struct platform_device *pdev = to_platform_device(rt2x00dev->dev);
46 struct resource *res;
47
48 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
49 if (!res)
50 return -ENODEV;
51
52 rt2x00dev->csr.base = (void __iomem *)KSEG1ADDR(res->start);
53 if (!rt2x00dev->csr.base)
54 goto exit;
55
56 rt2x00dev->eeprom = kzalloc(rt2x00dev->ops->eeprom_size, GFP_KERNEL);
57 if (!rt2x00dev->eeprom)
58 goto exit;
59
60 rt2x00dev->rf = kzalloc(rt2x00dev->ops->rf_size, GFP_KERNEL);
61 if (!rt2x00dev->rf)
62 goto exit;
63
64 return 0;
65
66 exit:
67 ERROR_PROBE("Failed to allocate registers.\n");
68 rt2x00soc_free_reg(rt2x00dev);
69
70 return -ENOMEM;
71 }
72
73 int rt2x00soc_probe(struct platform_device *pdev,
74 const unsigned short chipset,
75 const struct rt2x00_ops *ops)
76 {
77 struct ieee80211_hw *hw;
78 struct rt2x00_dev *rt2x00dev;
79 int retval;
80
81 hw = ieee80211_alloc_hw(sizeof(struct rt2x00_dev), ops->hw);
82 if (!hw) {
83 ERROR_PROBE("Failed to allocate hardware.\n");
84 return -ENOMEM;
85 }
86
87 platform_set_drvdata(pdev, hw);
88
89 rt2x00dev = hw->priv;
90 rt2x00dev->dev = &pdev->dev;
91 rt2x00dev->ops = ops;
92 rt2x00dev->hw = hw;
93 rt2x00dev->irq = platform_get_irq(pdev, 0);
94 rt2x00dev->name = pdev->dev.driver->name;
95
96 rt2x00_set_chip_rt(rt2x00dev, chipset);
97
98 retval = rt2x00soc_alloc_reg(rt2x00dev);
99 if (retval)
100 goto exit_free_device;
101
102 retval = rt2x00lib_probe_dev(rt2x00dev);
103 if (retval)
104 goto exit_free_reg;
105
106 return 0;
107
108 exit_free_reg:
109 rt2x00soc_free_reg(rt2x00dev);
110
111 exit_free_device:
112 ieee80211_free_hw(hw);
113
114 return retval;
115 }
116
117 int rt2x00soc_remove(struct platform_device *pdev)
118 {
119 struct ieee80211_hw *hw = platform_get_drvdata(pdev);
120 struct rt2x00_dev *rt2x00dev = hw->priv;
121
122 /*
123 * Free all allocated data.
124 */
125 rt2x00lib_remove_dev(rt2x00dev);
126 rt2x00soc_free_reg(rt2x00dev);
127 ieee80211_free_hw(hw);
128
129 return 0;
130 }
131 EXPORT_SYMBOL_GPL(rt2x00soc_remove);
132
133 #ifdef CONFIG_PM
134 int rt2x00soc_suspend(struct platform_device *pdev, pm_message_t state)
135 {
136 struct ieee80211_hw *hw = platform_get_drvdata(pdev);
137 struct rt2x00_dev *rt2x00dev = hw->priv;
138
139 return rt2x00lib_suspend(rt2x00dev, state);
140 }
141 EXPORT_SYMBOL_GPL(rt2x00soc_suspend);
142
143 int rt2x00soc_resume(struct platform_device *pdev)
144 {
145 struct ieee80211_hw *hw = platform_get_drvdata(pdev);
146 struct rt2x00_dev *rt2x00dev = hw->priv;
147
148 return rt2x00lib_resume(rt2x00dev);
149 }
150 EXPORT_SYMBOL_GPL(rt2x00soc_resume);
151 #endif /* CONFIG_PM */
152
153 /*
154 * rt2x00soc module information.
155 */
156 MODULE_AUTHOR(DRV_PROJECT);
157 MODULE_VERSION(DRV_VERSION);
158 MODULE_DESCRIPTION("rt2x00 soc library");
159 MODULE_LICENSE("GPL");
This page took 0.032664 seconds and 4 git commands to generate.