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
22 #include <linux/skbuff.h>
23 #include <linux/delay.h>
24 #include <linux/serial_reg.h>
28 static int hci_h4p_bcm_set_bdaddr(struct hci_h4p_info
*info
,
32 static const u8 nokia_oui
[3] = {0x00, 0x1f, 0xdf};
36 for (i
= 0; i
< 6; i
++) {
37 if (info
->bd_addr
[i
] != 0x00) {
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
];
56 void hci_h4p_bcm_parse_fw_event(struct hci_h4p_info
*info
, struct sk_buff
*skb
)
58 struct sk_buff
*fw_skb
;
62 if (skb
->data
[5] != 0x00) {
63 dev_err(info
->dev
, "Firmware sending command failed 0x%.2x\n",
65 info
->fw_error
= -EPROTO
;
70 fw_skb
= skb_dequeue(info
->fw_q
);
71 if (fw_skb
== NULL
|| info
->fw_error
) {
72 complete(&info
->fw_completion
);
76 if (fw_skb
->data
[1] == 0x01 && fw_skb
->data
[2] == 0xfc &&
78 BT_DBG("Setting bluetooth address");
79 err
= hci_h4p_bcm_set_bdaddr(info
, fw_skb
);
83 complete(&info
->fw_completion
);
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
) |
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
)
100 unsigned long flags
, time
;
104 BT_DBG("Sending firmware");
108 info
->fw_q
= fw_queue
;
109 skb
= skb_dequeue(fw_queue
);
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
) |
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");
135 if (info
->fw_error
) {
136 dev_err(info
->dev
, "FW error\n");
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
);