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/skbuff.h>
25 #include <linux/firmware.h>
26 #include <linux/clk.h>
28 #include <net/bluetooth/bluetooth.h>
34 /* Firmware handling */
35 static int hci_h4p_open_firmware(struct hci_h4p_info *info,
36 const struct firmware **fw_entry)
41 BT_DBG("Opening firmware man_id 0x%.2x ver_id 0x%.2x",
42 info->man_id, info->ver_id);
43 switch (info->man_id) {
45 switch (info->ver_id) {
47 err = request_firmware(fw_entry, FW_NAME_TI1271_PRELE,
52 err = request_firmware(fw_entry, FW_NAME_TI1271_LE,
56 err = request_firmware(fw_entry, FW_NAME_TI1271,
61 err = request_firmware(fw_entry, FW_NAME_CSR, info->dev);
64 err = request_firmware(fw_entry, FW_NAME_BCM2048, info->dev);
67 dev_err(info->dev, "Invalid chip type\n");
75 static void hci_h4p_close_firmware(const struct firmware *fw_entry)
77 release_firmware(fw_entry);
80 /* Read fw. Return length of the command. If no more commands in
81 * fw 0 is returned. In error case return value is negative.
83 static int hci_h4p_read_fw_cmd(struct hci_h4p_info *info, struct sk_buff **skb,
84 const struct firmware *fw_entry, gfp_t how)
88 if (fw_pos >= fw_entry->size)
91 if (fw_pos + 2 > fw_entry->size) {
92 dev_err(info->dev, "Corrupted firmware image 1\n");
96 cmd_len = fw_entry->data[fw_pos++];
97 cmd_len += fw_entry->data[fw_pos++] << 8;
101 if (fw_pos + cmd_len > fw_entry->size) {
102 dev_err(info->dev, "Corrupted firmware image 2\n");
106 *skb = bt_skb_alloc(cmd_len, how);
108 dev_err(info->dev, "Cannot reserve memory for buffer\n");
111 memcpy(skb_put(*skb, cmd_len), &fw_entry->data[fw_pos], cmd_len);
118 int hci_h4p_read_fw(struct hci_h4p_info *info, struct sk_buff_head *fw_queue)
120 const struct firmware *fw_entry = NULL;
121 struct sk_buff *skb = NULL;
124 err = hci_h4p_open_firmware(info, &fw_entry);
125 if (err < 0 || !fw_entry)
128 while ((err = hci_h4p_read_fw_cmd(info, &skb, fw_entry, GFP_KERNEL))) {
132 skb_queue_tail(fw_queue, skb);
135 /* Chip detection code does neg and alive stuff
136 * discard two first skbs */
137 skb = skb_dequeue(fw_queue);
143 skb = skb_dequeue(fw_queue);
151 hci_h4p_close_firmware(fw_entry);
155 int hci_h4p_send_fw(struct hci_h4p_info *info, struct sk_buff_head *fw_queue)
159 switch (info->man_id) {
161 err = hci_h4p_bc4_send_fw(info, fw_queue);
164 err = hci_h4p_ti1273_send_fw(info, fw_queue);
167 err = hci_h4p_bcm_send_fw(info, fw_queue);
170 dev_err(info->dev, "Don't know how to send firmware\n");
177 void hci_h4p_parse_fw_event(struct hci_h4p_info *info, struct sk_buff *skb)
179 switch (info->man_id) {
181 hci_h4p_bc4_parse_fw_event(info, skb);
184 hci_h4p_ti1273_parse_fw_event(info, skb);
187 hci_h4p_bcm_parse_fw_event(info, skb);
190 dev_err(info->dev, "Don't know how to parse fw event\n");
191 info->fw_error = -EINVAL;