2 * This file is part of hci_h4p bluetooth driver
4 * Copyright (C) 2005, 2006 Nokia Corporation.
6 * Contact: Ville Tervo <ville.tervo@nokia.com>
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * version 2 as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
24 #include <linux/module.h>
25 #include <linux/skbuff.h>
26 #include <linux/firmware.h>
27 #include <linux/clk.h>
29 #include <net/bluetooth/bluetooth.h>
33 #define FW_NAME_TI1271_PRELE "ti1273_prele.bin"
34 #define FW_NAME_TI1271_LE "ti1273_le.bin"
35 #define FW_NAME_TI1271 "ti1273.bin"
36 #define FW_NAME_BCM2048 "bcmfw.bin"
37 #define FW_NAME_CSR "bc4fw.bin"
41 /* Firmware handling */
42 static int hci_h4p_open_firmware(struct hci_h4p_info
*info
,
43 const struct firmware
**fw_entry
)
48 BT_DBG("Opening firmware man_id 0x%.2x ver_id 0x%.2x",
49 info
->man_id
, info
->ver_id
);
50 switch (info
->man_id
) {
52 switch (info
->ver_id
) {
54 err
= request_firmware(fw_entry
, FW_NAME_TI1271_PRELE
,
59 err
= request_firmware(fw_entry
, FW_NAME_TI1271_LE
,
63 err
= request_firmware(fw_entry
, FW_NAME_TI1271
,
68 err
= request_firmware(fw_entry
, FW_NAME_CSR
, info
->dev
);
71 err
= request_firmware(fw_entry
, FW_NAME_BCM2048
, info
->dev
);
74 dev_err(info
->dev
, "Invalid chip type\n");
82 static void hci_h4p_close_firmware(const struct firmware
*fw_entry
)
84 release_firmware(fw_entry
);
87 /* Read fw. Return length of the command. If no more commands in
88 * fw 0 is returned. In error case return value is negative.
90 static int hci_h4p_read_fw_cmd(struct hci_h4p_info
*info
, struct sk_buff
**skb
,
91 const struct firmware
*fw_entry
, gfp_t how
)
95 if (fw_pos
>= fw_entry
->size
)
98 if (fw_pos
+ 2 > fw_entry
->size
) {
99 dev_err(info
->dev
, "Corrupted firmware image 1\n");
103 cmd_len
= fw_entry
->data
[fw_pos
++];
104 cmd_len
+= fw_entry
->data
[fw_pos
++] << 8;
108 if (fw_pos
+ cmd_len
> fw_entry
->size
) {
109 dev_err(info
->dev
, "Corrupted firmware image 2\n");
113 *skb
= bt_skb_alloc(cmd_len
, how
);
115 dev_err(info
->dev
, "Cannot reserve memory for buffer\n");
118 memcpy(skb_put(*skb
, cmd_len
), &fw_entry
->data
[fw_pos
], cmd_len
);
125 int hci_h4p_read_fw(struct hci_h4p_info
*info
, struct sk_buff_head
*fw_queue
)
127 const struct firmware
*fw_entry
= NULL
;
128 struct sk_buff
*skb
= NULL
;
131 err
= hci_h4p_open_firmware(info
, &fw_entry
);
132 if (err
< 0 || !fw_entry
)
135 while ((err
= hci_h4p_read_fw_cmd(info
, &skb
, fw_entry
, GFP_KERNEL
))) {
139 skb_queue_tail(fw_queue
, skb
);
142 /* Chip detection code does neg and alive stuff
143 * discard two first skbs */
144 skb
= skb_dequeue(fw_queue
);
150 skb
= skb_dequeue(fw_queue
);
158 hci_h4p_close_firmware(fw_entry
);
162 int hci_h4p_send_fw(struct hci_h4p_info
*info
, struct sk_buff_head
*fw_queue
)
166 switch (info
->man_id
) {
168 err
= hci_h4p_bc4_send_fw(info
, fw_queue
);
171 err
= hci_h4p_ti1273_send_fw(info
, fw_queue
);
174 err
= hci_h4p_bcm_send_fw(info
, fw_queue
);
177 dev_err(info
->dev
, "Don't know how to send firmware\n");
184 void hci_h4p_parse_fw_event(struct hci_h4p_info
*info
, struct sk_buff
*skb
)
186 switch (info
->man_id
) {
188 hci_h4p_bc4_parse_fw_event(info
, skb
);
191 hci_h4p_ti1273_parse_fw_event(info
, skb
);
194 hci_h4p_bcm_parse_fw_event(info
, skb
);
197 dev_err(info
->dev
, "Don't know how to parse fw event\n");
198 info
->fw_error
= -EINVAL
;
204 MODULE_FIRMWARE(FW_NAME_TI1271_PRELE
);
205 MODULE_FIRMWARE(FW_NAME_TI1271_LE
);
206 MODULE_FIRMWARE(FW_NAME_TI1271
);
207 MODULE_FIRMWARE(FW_NAME_BCM2048
);
208 MODULE_FIRMWARE(FW_NAME_CSR
);
This page took 0.039055 seconds and 6 git commands to generate.