1 // SPDX-License-Identifier: GPL-2.0-or-later
3 Copyright (C) 2004 - 2009 Ivo van Doorn <IvDoorn@gmail.com>
4 Copyright (C) 2004 - 2009 Felix Fietkau <nbd@openwrt.org>
5 <http://rt2x00.serialmonkey.com>
11 Abstract: rt2x00 generic soc device routines.
14 #include <linux/bug.h>
15 #include <linux/kernel.h>
16 #include <linux/module.h>
17 #include <linux/platform_device.h>
18 #include <linux/slab.h>
21 #include "rt2x00soc.h"
23 static void rt2x00soc_free_reg(struct rt2x00_dev
*rt2x00dev
)
28 kfree(rt2x00dev
->eeprom
);
29 rt2x00dev
->eeprom
= NULL
;
31 iounmap(rt2x00dev
->csr
.base
);
34 static int rt2x00soc_alloc_reg(struct rt2x00_dev
*rt2x00dev
)
36 struct platform_device
*pdev
= to_platform_device(rt2x00dev
->dev
);
39 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
43 rt2x00dev
->csr
.base
= ioremap(res
->start
, resource_size(res
));
44 if (!rt2x00dev
->csr
.base
)
47 rt2x00dev
->eeprom
= kzalloc(rt2x00dev
->ops
->eeprom_size
, GFP_KERNEL
);
48 if (!rt2x00dev
->eeprom
)
51 rt2x00dev
->rf
= kzalloc(rt2x00dev
->ops
->rf_size
, GFP_KERNEL
);
58 rt2x00_probe_err("Failed to allocate registers\n");
59 rt2x00soc_free_reg(rt2x00dev
);
64 int rt2x00soc_probe(struct platform_device
*pdev
, const struct rt2x00_ops
*ops
)
66 struct ieee80211_hw
*hw
;
67 struct rt2x00_dev
*rt2x00dev
;
70 hw
= ieee80211_alloc_hw(sizeof(struct rt2x00_dev
), ops
->hw
);
72 rt2x00_probe_err("Failed to allocate hardware\n");
76 platform_set_drvdata(pdev
, hw
);
79 rt2x00dev
->dev
= &pdev
->dev
;
82 rt2x00dev
->irq
= platform_get_irq(pdev
, 0);
83 rt2x00dev
->name
= pdev
->dev
.driver
->name
;
85 rt2x00dev
->clk
= clk_get(&pdev
->dev
, NULL
);
86 if (IS_ERR(rt2x00dev
->clk
))
87 rt2x00dev
->clk
= NULL
;
89 rt2x00_set_chip_intf(rt2x00dev
, RT2X00_CHIP_INTF_SOC
);
91 retval
= rt2x00soc_alloc_reg(rt2x00dev
);
93 goto exit_free_device
;
95 retval
= rt2x00lib_probe_dev(rt2x00dev
);
102 rt2x00soc_free_reg(rt2x00dev
);
105 ieee80211_free_hw(hw
);
109 EXPORT_SYMBOL_GPL(rt2x00soc_probe
);
111 int rt2x00soc_remove(struct platform_device
*pdev
)
113 struct ieee80211_hw
*hw
= platform_get_drvdata(pdev
);
114 struct rt2x00_dev
*rt2x00dev
= hw
->priv
;
117 * Free all allocated data.
119 rt2x00lib_remove_dev(rt2x00dev
);
120 rt2x00soc_free_reg(rt2x00dev
);
121 ieee80211_free_hw(hw
);
125 EXPORT_SYMBOL_GPL(rt2x00soc_remove
);
128 int rt2x00soc_suspend(struct platform_device
*pdev
, pm_message_t state
)
130 struct ieee80211_hw
*hw
= platform_get_drvdata(pdev
);
131 struct rt2x00_dev
*rt2x00dev
= hw
->priv
;
133 return rt2x00lib_suspend(rt2x00dev
, state
);
135 EXPORT_SYMBOL_GPL(rt2x00soc_suspend
);
137 int rt2x00soc_resume(struct platform_device
*pdev
)
139 struct ieee80211_hw
*hw
= platform_get_drvdata(pdev
);
140 struct rt2x00_dev
*rt2x00dev
= hw
->priv
;
142 return rt2x00lib_resume(rt2x00dev
);
144 EXPORT_SYMBOL_GPL(rt2x00soc_resume
);
145 #endif /* CONFIG_PM */
148 * rt2x00soc module information.
150 MODULE_AUTHOR(DRV_PROJECT
);
151 MODULE_VERSION(DRV_VERSION
);
152 MODULE_DESCRIPTION("rt2x00 soc library");
153 MODULE_LICENSE("GPL");