2 * Firmware loading and handling functions.
5 #include <linux/sched.h>
6 #include <linux/firmware.h>
7 #include <linux/firmware.h>
8 #include <linux/module.h>
9 #include <linux/sched.h>
14 static void load_next_firmware_from_table(struct lbs_private
*private);
16 static void lbs_fw_loaded(struct lbs_private
*priv
, int ret
,
17 const struct firmware
*helper
, const struct firmware
*mainfw
)
21 lbs_deb_fw("firmware load complete, code %d\n", ret
);
23 /* User must free helper/mainfw */
24 priv
->fw_callback(priv
, ret
, helper
, mainfw
);
26 spin_lock_irqsave(&priv
->driver_lock
, flags
);
27 priv
->fw_callback
= NULL
;
28 wake_up(&priv
->fw_waitq
);
29 spin_unlock_irqrestore(&priv
->driver_lock
, flags
);
32 static void do_load_firmware(struct lbs_private
*priv
, const char *name
,
33 void (*cb
)(const struct firmware
*fw
, void *context
))
37 lbs_deb_fw("Requesting %s\n", name
);
38 ret
= request_firmware_nowait(THIS_MODULE
, true, name
,
39 priv
->fw_device
, GFP_KERNEL
, priv
, cb
);
41 lbs_deb_fw("request_firmware_nowait error %d\n", ret
);
42 lbs_fw_loaded(priv
, ret
, NULL
, NULL
);
46 static void main_firmware_cb(const struct firmware
*firmware
, void *context
)
48 struct lbs_private
*priv
= context
;
51 /* Failed to find firmware: try next table entry */
52 load_next_firmware_from_table(priv
);
57 lbs_fw_loaded(priv
, 0, priv
->helper_fw
, firmware
);
60 static void helper_firmware_cb(const struct firmware
*firmware
, void *context
)
62 struct lbs_private
*priv
= context
;
65 /* Failed to find firmware: try next table entry */
66 load_next_firmware_from_table(priv
);
71 if (priv
->fw_iter
->fwname
) {
72 priv
->helper_fw
= firmware
;
73 do_load_firmware(priv
, priv
->fw_iter
->fwname
, main_firmware_cb
);
75 /* No main firmware needed for this helper --> success! */
76 lbs_fw_loaded(priv
, 0, firmware
, NULL
);
80 static void load_next_firmware_from_table(struct lbs_private
*priv
)
82 const struct lbs_fw_table
*iter
;
85 iter
= priv
->fw_table
;
87 iter
= ++priv
->fw_iter
;
89 if (priv
->helper_fw
) {
90 release_firmware(priv
->helper_fw
);
91 priv
->helper_fw
= NULL
;
96 /* End of table hit. */
97 lbs_fw_loaded(priv
, -ENOENT
, NULL
, NULL
);
101 if (iter
->model
!= priv
->fw_model
) {
106 priv
->fw_iter
= iter
;
107 do_load_firmware(priv
, iter
->helper
, helper_firmware_cb
);
110 void lbs_wait_for_firmware_load(struct lbs_private
*priv
)
112 wait_event(priv
->fw_waitq
, priv
->fw_callback
== NULL
);
116 * lbs_get_firmware_async - Retrieves firmware asynchronously. Can load
117 * either a helper firmware and a main firmware (2-stage), or just the helper.
119 * @priv: Pointer to lbs_private instance
120 * @dev: A pointer to &device structure
121 * @card_model: Bus-specific card model ID used to filter firmware table
123 * @fw_table: Table of firmware file names and device model numbers
124 * terminated by an entry with a NULL helper name
125 * @callback: User callback to invoke when firmware load succeeds or fails.
127 int lbs_get_firmware_async(struct lbs_private
*priv
, struct device
*device
,
128 u32 card_model
, const struct lbs_fw_table
*fw_table
,
133 spin_lock_irqsave(&priv
->driver_lock
, flags
);
134 if (priv
->fw_callback
) {
135 lbs_deb_fw("firmware load already in progress\n");
136 spin_unlock_irqrestore(&priv
->driver_lock
, flags
);
140 priv
->fw_device
= device
;
141 priv
->fw_callback
= callback
;
142 priv
->fw_table
= fw_table
;
143 priv
->fw_iter
= NULL
;
144 priv
->fw_model
= card_model
;
145 spin_unlock_irqrestore(&priv
->driver_lock
, flags
);
147 lbs_deb_fw("Starting async firmware load\n");
148 load_next_firmware_from_table(priv
);
151 EXPORT_SYMBOL_GPL(lbs_get_firmware_async
);
154 * lbs_get_firmware - Retrieves two-stage firmware
156 * @dev: A pointer to &device structure
157 * @card_model: Bus-specific card model ID used to filter firmware table
159 * @fw_table: Table of firmware file names and device model numbers
160 * terminated by an entry with a NULL helper name
161 * @helper: On success, the helper firmware; caller must free
162 * @mainfw: On success, the main firmware; caller must free
164 * Deprecated: use lbs_get_firmware_async() instead.
166 * returns: 0 on success, non-zero on failure
168 int lbs_get_firmware(struct device
*dev
, u32 card_model
,
169 const struct lbs_fw_table
*fw_table
,
170 const struct firmware
**helper
,
171 const struct firmware
**mainfw
)
173 const struct lbs_fw_table
*iter
;
176 BUG_ON(helper
== NULL
);
177 BUG_ON(mainfw
== NULL
);
179 /* Search for firmware to use from the table. */
181 while (iter
&& iter
->helper
) {
182 if (iter
->model
!= card_model
)
185 if (*helper
== NULL
) {
186 ret
= request_firmware(helper
, iter
->helper
, dev
);
190 /* If the device has one-stage firmware (ie cf8305) and
191 * we've got it then we don't need to bother with the
194 if (iter
->fwname
== NULL
)
198 if (*mainfw
== NULL
) {
199 ret
= request_firmware(mainfw
, iter
->fwname
, dev
);
201 /* Clear the helper to ensure we don't have
202 * mismatched firmware pairs.
204 release_firmware(*helper
);
209 if (*helper
&& *mainfw
)
217 release_firmware(*helper
);
219 release_firmware(*mainfw
);
224 EXPORT_SYMBOL_GPL(lbs_get_firmware
);
This page took 0.035459 seconds and 6 git commands to generate.