ARM: at91: sama5d3: add usart dma configurations
[linux-2.6/btrfs-unstable.git] / drivers / staging / nokia_h4p / nokia_fw-bcm.c
blobb55f5ba1134efbd80d9574e8a184832cf985807e
1 /*
2 * This file is part of Nokia H4P bluetooth driver
4 * Copyright (C) 2005-2008 Nokia Corporation.
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * version 2 as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18 * 02110-1301 USA
22 #include <linux/skbuff.h>
23 #include <linux/delay.h>
24 #include <linux/serial_reg.h>
26 #include "hci_h4p.h"
28 static int hci_h4p_bcm_set_bdaddr(struct hci_h4p_info *info,
29 struct sk_buff *skb)
31 int i;
32 static const u8 nokia_oui[3] = {0x00, 0x1f, 0xdf};
33 int not_valid;
35 not_valid = 1;
36 for (i = 0; i < 6; i++) {
37 if (info->bd_addr[i] != 0x00) {
38 not_valid = 0;
39 break;
43 if (not_valid) {
44 dev_info(info->dev, "Valid bluetooth address not found, setting some random\n");
45 /* When address is not valid, use some random but Nokia MAC */
46 memcpy(info->bd_addr, nokia_oui, 3);
47 get_random_bytes(info->bd_addr + 3, 3);
50 for (i = 0; i < 6; i++)
51 skb->data[9 - i] = info->bd_addr[i];
53 return 0;
56 void hci_h4p_bcm_parse_fw_event(struct hci_h4p_info *info, struct sk_buff *skb)
58 struct sk_buff *fw_skb;
59 int err;
60 unsigned long flags;
62 if (skb->data[5] != 0x00) {
63 dev_err(info->dev, "Firmware sending command failed 0x%.2x\n",
64 skb->data[5]);
65 info->fw_error = -EPROTO;
68 kfree_skb(skb);
70 fw_skb = skb_dequeue(info->fw_q);
71 if (fw_skb == NULL || info->fw_error) {
72 complete(&info->fw_completion);
73 return;
76 if (fw_skb->data[1] == 0x01 && fw_skb->data[2] == 0xfc &&
77 fw_skb->len >= 10) {
78 BT_DBG("Setting bluetooth address");
79 err = hci_h4p_bcm_set_bdaddr(info, fw_skb);
80 if (err < 0) {
81 kfree_skb(fw_skb);
82 info->fw_error = err;
83 complete(&info->fw_completion);
84 return;
88 skb_queue_tail(&info->txq, fw_skb);
89 spin_lock_irqsave(&info->lock, flags);
90 hci_h4p_outb(info, UART_IER, hci_h4p_inb(info, UART_IER) |
91 UART_IER_THRI);
92 spin_unlock_irqrestore(&info->lock, flags);
96 int hci_h4p_bcm_send_fw(struct hci_h4p_info *info,
97 struct sk_buff_head *fw_queue)
99 struct sk_buff *skb;
100 unsigned long flags, time;
102 info->fw_error = 0;
104 BT_DBG("Sending firmware");
106 time = jiffies;
108 info->fw_q = fw_queue;
109 skb = skb_dequeue(fw_queue);
110 if (!skb)
111 return -ENODATA;
113 BT_DBG("Sending commands");
116 * Disable smart-idle as UART TX interrupts
117 * are not wake-up capable
119 hci_h4p_smart_idle(info, 0);
121 /* Check if this is bd_address packet */
122 init_completion(&info->fw_completion);
123 skb_queue_tail(&info->txq, skb);
124 spin_lock_irqsave(&info->lock, flags);
125 hci_h4p_outb(info, UART_IER, hci_h4p_inb(info, UART_IER) |
126 UART_IER_THRI);
127 spin_unlock_irqrestore(&info->lock, flags);
129 if (!wait_for_completion_timeout(&info->fw_completion,
130 msecs_to_jiffies(2000))) {
131 dev_err(info->dev, "No reply to fw command\n");
132 return -ETIMEDOUT;
135 if (info->fw_error) {
136 dev_err(info->dev, "FW error\n");
137 return -EPROTO;
140 BT_DBG("Firmware sent in %d msecs",
141 jiffies_to_msecs(jiffies-time));
143 hci_h4p_set_auto_ctsrts(info, 0, UART_EFR_RTS);
144 hci_h4p_set_rts(info, 0);
145 hci_h4p_change_speed(info, BC4_MAX_BAUD_RATE);
146 hci_h4p_set_auto_ctsrts(info, 1, UART_EFR_RTS);
148 return 0;