]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blob - drivers/bluetooth/hci_h4p/fw-csr.c
Merge branch 'omap-fixes'
[linux-2.6-omap-h63xx.git] / drivers / bluetooth / hci_h4p / fw-csr.c
1 /*
2  * This file is part of hci_h4p bluetooth driver
3  *
4  * Copyright (C) 2005, 2006 Nokia Corporation.
5  *
6  * Contact: Ville Tervo <ville.tervo@nokia.com>
7  *
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.
11  *
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.
16  *
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
20  * 02110-1301 USA
21  *
22  */
23
24 #include <linux/skbuff.h>
25 #include <linux/delay.h>
26 #include <linux/serial_reg.h>
27
28 #include "hci_h4p.h"
29
30 void hci_h4p_bc4_parse_fw_event(struct hci_h4p_info *info, struct sk_buff *skb)
31 {
32         /* Check if this is fw packet */
33         if (skb->data[0] != 0xff) {
34                 hci_recv_frame(skb);
35                 return;
36         }
37
38         if (skb->data[11] || skb->data[12]) {
39                 dev_err(info->dev, "Firmware sending command failed\n");
40                 info->fw_error = -EPROTO;
41         }
42
43         kfree_skb(skb);
44         complete(&info->fw_completion);
45 }
46
47 int hci_h4p_bc4_send_fw(struct hci_h4p_info *info,
48                         struct sk_buff_head *fw_queue)
49 {
50         struct sk_buff *skb;
51         unsigned int offset;
52         int retries, count, i;
53
54         info->fw_error = 0;
55
56         NBT_DBG_FW("Sending firmware\n");
57         skb = skb_dequeue(fw_queue);
58
59         if (!skb)
60                 return -ENOMSG;
61
62         /* Check if this is bd_address packet */
63         if (skb->data[15] == 0x01 && skb->data[16] == 0x00) {
64                 offset = 21;
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];
73         }
74
75         for (i = 0; i < 6; i++) {
76                 if (info->bdaddr[i] != 0x00)
77                         break;
78         }
79
80         if (i > 5) {
81                 dev_info(info->dev, "Valid bluetooth address not found.\n");
82                 kfree_skb(skb);
83                 return -ENODEV;
84         }
85
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);
91
92                 skb = skb_dequeue(fw_queue);
93                 if (!skb)
94                         break;
95
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");
99                         return -ETIMEDOUT;
100                 }
101
102                 if (info->fw_error) {
103                         dev_err(info->dev, "FW error\n");
104                         return -EPROTO;
105                 }
106         };
107
108         /* Wait for chip warm reset */
109         retries = 100;
110         while ((!skb_queue_empty(&info->txq) ||
111                !(hci_h4p_inb(info, UART_LSR) & UART_LSR_TEMT)) &&
112                retries--) {
113                 msleep(10);
114         }
115         if (!retries) {
116                 dev_err(info->dev, "Transmitter not empty\n");
117                 return -ETIMEDOUT;
118         }
119
120         hci_h4p_change_speed(info, BC4_MAX_BAUD_RATE);
121
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");
124                 return -ETIMEDOUT;
125         }
126
127         retries = 100;
128         do {
129                 init_completion(&info->init_completion);
130                 hci_h4p_send_alive_packet(info);
131                 retries--;
132         } while (!wait_for_completion_timeout(&info->init_completion, 100) &&
133                  retries > 0);
134
135         if (!retries) {
136                 dev_err(info->dev, "No alive reply after speed change\n");
137                 return -ETIMEDOUT;
138         }
139
140         return 0;
141 }