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 NBT_DBG_FW("Opening %d firmware\n", info->chip_type);
42 switch (info->chip_type) {
44 err = request_firmware(fw_entry, "brf6150fw.bin", info->dev);
47 err = request_firmware(fw_entry, "bc4fw.bin", info->dev);
50 dev_err(info->dev, "Invalid chip type\n");
58 static void hci_h4p_close_firmware(const struct firmware *fw_entry)
60 release_firmware(fw_entry);
63 /* Read fw. Return length of the command. If no more commands in
64 * fw 0 is returned. In error case return value is negative.
66 static int hci_h4p_read_fw_cmd(struct hci_h4p_info *info, struct sk_buff **skb,
67 const struct firmware *fw_entry, int how)
71 if (fw_pos >= fw_entry->size) {
75 cmd_len = fw_entry->data[fw_pos++];
79 if (fw_pos + cmd_len > fw_entry->size) {
80 dev_err(info->dev, "Corrupted firmware image\n");
84 *skb = bt_skb_alloc(cmd_len, how);
86 dev_err(info->dev, "Cannot reserve memory for buffer\n");
89 memcpy(skb_put(*skb, cmd_len), &fw_entry->data[fw_pos], cmd_len);
96 int hci_h4p_read_fw(struct hci_h4p_info *info, struct sk_buff_head *fw_queue)
98 const struct firmware *fw_entry = NULL;
99 struct sk_buff *skb = NULL;
102 err = hci_h4p_open_firmware(info, &fw_entry);
103 if (err < 0 || !fw_entry)
106 while ((err = hci_h4p_read_fw_cmd(info, &skb, fw_entry, GFP_KERNEL))) {
110 skb_queue_tail(fw_queue, skb);
114 hci_h4p_close_firmware(fw_entry);
118 int hci_h4p_send_fw(struct hci_h4p_info *info, struct sk_buff_head *fw_queue)
122 switch(info->chip_type) {
124 err = hci_h4p_bc4_send_fw(info, fw_queue);
127 err = hci_h4p_brf6150_send_fw(info, fw_queue);
130 dev_err(info->dev, "Don't know how to send firmware\n");
137 void hci_h4p_parse_fw_event(struct hci_h4p_info *info, struct sk_buff *skb)
139 switch (info->chip_type) {
141 hci_h4p_bc4_parse_fw_event(info, skb);
144 hci_h4p_brf6150_parse_fw_event(info, skb);
147 dev_err(info->dev, "Don't know how to parse fw event\n");
148 info->fw_error = -EINVAL;