Merge branch 'for-3.16' of git://linux-nfs.org/~bfields/linux
[deliverable/linux.git] / drivers / staging / nokia_h4p / nokia_fw-ti1273.c
1 /*
2 * This file is part of Nokia H4P bluetooth driver
3 *
4 * Copyright (C) 2009 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
28 static struct sk_buff_head *fw_q;
29
30 void hci_h4p_ti1273_parse_fw_event(struct hci_h4p_info *info,
31 struct sk_buff *skb)
32 {
33 struct sk_buff *fw_skb;
34 unsigned long flags;
35
36 if (skb->data[5] != 0x00) {
37 dev_err(info->dev, "Firmware sending command failed 0x%.2x\n",
38 skb->data[5]);
39 info->fw_error = -EPROTO;
40 }
41
42 kfree_skb(skb);
43
44 fw_skb = skb_dequeue(fw_q);
45 if (fw_skb == NULL || info->fw_error) {
46 complete(&info->fw_completion);
47 return;
48 }
49
50 skb_queue_tail(&info->txq, fw_skb);
51 spin_lock_irqsave(&info->lock, flags);
52 hci_h4p_outb(info, UART_IER, hci_h4p_inb(info, UART_IER) |
53 UART_IER_THRI);
54 spin_unlock_irqrestore(&info->lock, flags);
55 }
56
57
58 int hci_h4p_ti1273_send_fw(struct hci_h4p_info *info,
59 struct sk_buff_head *fw_queue)
60 {
61 struct sk_buff *skb;
62 unsigned long flags, time;
63
64 info->fw_error = 0;
65
66 BT_DBG("Sending firmware");
67
68 time = jiffies;
69
70 fw_q = fw_queue;
71 skb = skb_dequeue(fw_queue);
72 if (!skb)
73 return -ENODATA;
74
75 BT_DBG("Sending commands");
76 /* Check if this is bd_address packet */
77 init_completion(&info->fw_completion);
78 hci_h4p_smart_idle(info, 0);
79 skb_queue_tail(&info->txq, skb);
80 spin_lock_irqsave(&info->lock, flags);
81 hci_h4p_outb(info, UART_IER, hci_h4p_inb(info, UART_IER) |
82 UART_IER_THRI);
83 spin_unlock_irqrestore(&info->lock, flags);
84
85 if (!wait_for_completion_timeout(&info->fw_completion,
86 msecs_to_jiffies(2000))) {
87 dev_err(info->dev, "No reply to fw command\n");
88 return -ETIMEDOUT;
89 }
90
91 if (info->fw_error) {
92 dev_err(info->dev, "FW error\n");
93 return -EPROTO;
94 }
95
96 BT_DBG("Firmware sent in %d msecs",
97 jiffies_to_msecs(jiffies-time));
98
99 hci_h4p_set_auto_ctsrts(info, 0, UART_EFR_RTS);
100 hci_h4p_set_rts(info, 0);
101 hci_h4p_change_speed(info, BC4_MAX_BAUD_RATE);
102 if (hci_h4p_wait_for_cts(info, 1, 100)) {
103 dev_err(info->dev,
104 "cts didn't go down after final speed change\n");
105 return -ETIMEDOUT;
106 }
107 hci_h4p_set_auto_ctsrts(info, 1, UART_EFR_RTS);
108
109 return 0;
110 }
This page took 0.033207 seconds and 5 git commands to generate.