blob: 29250f79c4a4bffc0996222eb2c6381877f47c6f [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
Jeff Kirshera05b8c52013-12-06 03:32:11 -080017 along with this program; if not, see <http://www.gnu.org/licenses/>.
Ivo van Doorn5d78d342009-10-15 21:38:19 +020018 */
19
20/*
21 Module: rt2x00soc
22 Abstract: rt2x00 generic soc device routines.
23 */
24
25#include <linux/bug.h>
26#include <linux/kernel.h>
27#include <linux/module.h>
28#include <linux/platform_device.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090029#include <linux/slab.h>
Ivo van Doorn5d78d342009-10-15 21:38:19 +020030
31#include "rt2x00.h"
32#include "rt2x00soc.h"
33
34static 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;
Gertjan van Wingerdeef8397c2010-11-13 19:11:22 +010041
42 iounmap(rt2x00dev->csr.base);
Ivo van Doorn5d78d342009-10-15 21:38:19 +020043}
44
45static int rt2x00soc_alloc_reg(struct rt2x00_dev *rt2x00dev)
46{
47 struct platform_device *pdev = to_platform_device(rt2x00dev->dev);
48 struct resource *res;
49
50 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
51 if (!res)
52 return -ENODEV;
53
Gertjan van Wingerdeef8397c2010-11-13 19:11:22 +010054 rt2x00dev->csr.base = ioremap(res->start, resource_size(res));
Ivo van Doorn5d78d342009-10-15 21:38:19 +020055 if (!rt2x00dev->csr.base)
Gertjan van Wingerdeef8397c2010-11-13 19:11:22 +010056 return -ENOMEM;
Ivo van Doorn5d78d342009-10-15 21:38:19 +020057
58 rt2x00dev->eeprom = kzalloc(rt2x00dev->ops->eeprom_size, GFP_KERNEL);
59 if (!rt2x00dev->eeprom)
60 goto exit;
61
62 rt2x00dev->rf = kzalloc(rt2x00dev->ops->rf_size, GFP_KERNEL);
63 if (!rt2x00dev->rf)
64 goto exit;
65
66 return 0;
67
68exit:
Joe Perchesec9c4982013-04-19 08:33:40 -070069 rt2x00_probe_err("Failed to allocate registers\n");
Ivo van Doorn5d78d342009-10-15 21:38:19 +020070 rt2x00soc_free_reg(rt2x00dev);
71
72 return -ENOMEM;
73}
74
Gertjan van Wingerde714fa662010-02-13 20:55:48 +010075int rt2x00soc_probe(struct platform_device *pdev, const struct rt2x00_ops *ops)
Ivo van Doorn5d78d342009-10-15 21:38:19 +020076{
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) {
Joe Perchesec9c4982013-04-19 08:33:40 -070083 rt2x00_probe_err("Failed to allocate hardware\n");
Ivo van Doorn5d78d342009-10-15 21:38:19 +020084 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;
Stanislaw Gruszka33e962c2017-01-29 12:40:52 +010095
96 rt2x00dev->clk = clk_get(&pdev->dev, NULL);
97 if (IS_ERR(rt2x00dev->clk))
98 rt2x00dev->clk = NULL;
Ivo van Doorn5d78d342009-10-15 21:38:19 +020099
Gertjan van Wingerdecea90e52010-02-13 20:55:47 +0100100 rt2x00_set_chip_intf(rt2x00dev, RT2X00_CHIP_INTF_SOC);
Ivo van Doorn5d78d342009-10-15 21:38:19 +0200101
102 retval = rt2x00soc_alloc_reg(rt2x00dev);
103 if (retval)
104 goto exit_free_device;
105
106 retval = rt2x00lib_probe_dev(rt2x00dev);
107 if (retval)
108 goto exit_free_reg;
109
110 return 0;
111
112exit_free_reg:
113 rt2x00soc_free_reg(rt2x00dev);
114
115exit_free_device:
116 ieee80211_free_hw(hw);
117
118 return retval;
119}
Helmut Schaa31f66be2010-03-03 17:42:55 +0100120EXPORT_SYMBOL_GPL(rt2x00soc_probe);
Ivo van Doorn5d78d342009-10-15 21:38:19 +0200121
122int rt2x00soc_remove(struct platform_device *pdev)
123{
124 struct ieee80211_hw *hw = platform_get_drvdata(pdev);
125 struct rt2x00_dev *rt2x00dev = hw->priv;
126
127 /*
128 * Free all allocated data.
129 */
130 rt2x00lib_remove_dev(rt2x00dev);
131 rt2x00soc_free_reg(rt2x00dev);
132 ieee80211_free_hw(hw);
133
134 return 0;
135}
136EXPORT_SYMBOL_GPL(rt2x00soc_remove);
137
138#ifdef CONFIG_PM
139int rt2x00soc_suspend(struct platform_device *pdev, pm_message_t state)
140{
141 struct ieee80211_hw *hw = platform_get_drvdata(pdev);
142 struct rt2x00_dev *rt2x00dev = hw->priv;
143
144 return rt2x00lib_suspend(rt2x00dev, state);
145}
146EXPORT_SYMBOL_GPL(rt2x00soc_suspend);
147
148int rt2x00soc_resume(struct platform_device *pdev)
149{
150 struct ieee80211_hw *hw = platform_get_drvdata(pdev);
151 struct rt2x00_dev *rt2x00dev = hw->priv;
152
153 return rt2x00lib_resume(rt2x00dev);
154}
155EXPORT_SYMBOL_GPL(rt2x00soc_resume);
156#endif /* CONFIG_PM */
157
158/*
159 * rt2x00soc module information.
160 */
161MODULE_AUTHOR(DRV_PROJECT);
162MODULE_VERSION(DRV_VERSION);
163MODULE_DESCRIPTION("rt2x00 soc library");
164MODULE_LICENSE("GPL");