staging/lustre/libcfs: remove cfs_pause
[deliverable/linux.git] / drivers / staging / nokia_h4p / nokia_fw-csr.c
CommitLineData
91eef3e2
PM
1/*
2 * This file is part of Nokia H4P bluetooth driver
3 *
4 * Copyright (C) 2005-2008 Nokia Corporation.
5 *
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.
9 *
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.
14 *
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
19 *
20 */
21
22#include <linux/skbuff.h>
23#include <linux/delay.h>
24#include <linux/serial_reg.h>
25
26#include "hci_h4p.h"
27
28void hci_h4p_bc4_parse_fw_event(struct hci_h4p_info *info, struct sk_buff *skb)
29{
30 /* Check if this is fw packet */
31 if (skb->data[0] != 0xff) {
32 hci_recv_frame(info->hdev, skb);
33 return;
34 }
35
36 if (skb->data[11] || skb->data[12]) {
37 dev_err(info->dev, "Firmware sending command failed\n");
38 info->fw_error = -EPROTO;
39 }
40
41 kfree_skb(skb);
42 complete(&info->fw_completion);
43}
44
45int hci_h4p_bc4_send_fw(struct hci_h4p_info *info,
46 struct sk_buff_head *fw_queue)
47{
48 static const u8 nokia_oui[3] = {0x00, 0x19, 0x4F};
49 struct sk_buff *skb;
50 unsigned int offset;
51 int retries, count, i, not_valid;
52 unsigned long flags;
53
54 info->fw_error = 0;
55
56 BT_DBG("Sending firmware");
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
68 not_valid = 1;
69 for (i = 0; i < 6; i++) {
70 if (info->bd_addr[i] != 0x00) {
71 not_valid = 0;
72 break;
73 }
74 }
75
76 if (not_valid) {
77 dev_info(info->dev, "Valid bluetooth address not found,"
78 " setting some random\n");
79 /* When address is not valid, use some random */
80 memcpy(info->bd_addr, nokia_oui, 3);
81 get_random_bytes(info->bd_addr + 3, 3);
82 }
83
84 skb->data[offset + 7] = info->bd_addr[0];
85 skb->data[offset + 6] = info->bd_addr[1];
86 skb->data[offset + 4] = info->bd_addr[2];
87 skb->data[offset + 0] = info->bd_addr[3];
88 skb->data[offset + 3] = info->bd_addr[4];
89 skb->data[offset + 2] = info->bd_addr[5];
90 }
91
92 for (count = 1; ; count++) {
93 BT_DBG("Sending firmware command %d", count);
94 init_completion(&info->fw_completion);
95 skb_queue_tail(&info->txq, skb);
96 spin_lock_irqsave(&info->lock, flags);
97 hci_h4p_outb(info, UART_IER, hci_h4p_inb(info, UART_IER) |
98 UART_IER_THRI);
99 spin_unlock_irqrestore(&info->lock, flags);
100
101 skb = skb_dequeue(fw_queue);
102 if (!skb)
103 break;
104
105 if (!wait_for_completion_timeout(&info->fw_completion,
106 msecs_to_jiffies(1000))) {
107 dev_err(info->dev, "No reply to fw command\n");
108 return -ETIMEDOUT;
109 }
110
111 if (info->fw_error) {
112 dev_err(info->dev, "FW error\n");
113 return -EPROTO;
114 }
115 };
116
117 /* Wait for chip warm reset */
118 retries = 100;
119 while ((!skb_queue_empty(&info->txq) ||
120 !(hci_h4p_inb(info, UART_LSR) & UART_LSR_TEMT)) &&
121 retries--) {
122 msleep(10);
123 }
124 if (!retries) {
125 dev_err(info->dev, "Transmitter not empty\n");
126 return -ETIMEDOUT;
127 }
128
129 hci_h4p_change_speed(info, BC4_MAX_BAUD_RATE);
130
131 if (hci_h4p_wait_for_cts(info, 1, 100)) {
132 dev_err(info->dev, "cts didn't deassert after final speed\n");
133 return -ETIMEDOUT;
134 }
135
136 retries = 100;
137 do {
138 init_completion(&info->init_completion);
139 hci_h4p_send_alive_packet(info);
140 retries--;
141 } while (!wait_for_completion_timeout(&info->init_completion, 100) &&
142 retries > 0);
143
144 if (!retries) {
145 dev_err(info->dev, "No alive reply after speed change\n");
146 return -ETIMEDOUT;
147 }
148
149 return 0;
150}
This page took 0.058256 seconds and 5 git commands to generate.