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/delay.h>
26 #include <linux/serial_reg.h>
30 void hci_h4p_bc4_parse_fw_event(struct hci_h4p_info *info, struct sk_buff *skb)
32 /* Check if this is fw packet */
33 if (skb->data[0] != 0xff) {
38 if (skb->data[11] || skb->data[12]) {
39 dev_err(info->dev, "Firmware sending command failed\n");
40 info->fw_error = -EPROTO;
44 complete(&info->fw_completion);
47 int hci_h4p_bc4_send_fw(struct hci_h4p_info *info,
48 struct sk_buff_head *fw_queue)
52 int retries, count, i;
56 NBT_DBG_FW("Sending firmware\n");
57 skb = skb_dequeue(fw_queue);
62 /* Check if this is bd_address packet */
63 if (skb->data[15] == 0x01 && skb->data[16] == 0x00) {
65 skb->data[offset + 1] = 0x00;
66 skb->data[offset + 5] = 0x00;
67 skb->data[offset + 7] = info->bdaddr[0];
68 skb->data[offset + 6] = info->bdaddr[1];
69 skb->data[offset + 4] = info->bdaddr[2];
70 skb->data[offset + 0] = info->bdaddr[3];
71 skb->data[offset + 3] = info->bdaddr[4];
72 skb->data[offset + 2] = info->bdaddr[5];
75 for (i = 0; i < 6; i++) {
76 if (info->bdaddr[i] != 0x00)
81 dev_info(info->dev, "Valid bluetooth address not found.\n");
86 for (count = 1; ; count++) {
87 NBT_DBG_FW("Sending firmware command %d\n", count);
88 init_completion(&info->fw_completion);
89 skb_queue_tail(&info->txq, skb);
90 tasklet_schedule(&info->tx_task);
92 skb = skb_dequeue(fw_queue);
96 if (!wait_for_completion_timeout(&info->fw_completion,
97 msecs_to_jiffies(1000))) {
98 dev_err(info->dev, "No reply to fw command\n");
102 if (info->fw_error) {
103 dev_err(info->dev, "FW error\n");
108 /* Wait for chip warm reset */
110 while ((!skb_queue_empty(&info->txq) ||
111 !(hci_h4p_inb(info, UART_LSR) & UART_LSR_TEMT)) &&
116 dev_err(info->dev, "Transmitter not empty\n");
120 hci_h4p_change_speed(info, BC4_MAX_BAUD_RATE);
122 if (hci_h4p_wait_for_cts(info, 1, 100)) {
123 dev_err(info->dev, "cts didn't go down after final speed change\n");
129 init_completion(&info->init_completion);
130 hci_h4p_send_alive_packet(info);
132 } while (!wait_for_completion_timeout(&info->init_completion, 100) &&
136 dev_err(info->dev, "No alive reply after speed change\n");