ramips: Allow ethernet interface to be taken down and up again
[openwrt.git] / target / linux / omap24xx / patches-2.6.36 / 400-bluetooth-hci_h4p.patch
1 ---
2 drivers/bluetooth/Kconfig | 10
3 drivers/bluetooth/Makefile | 1
4 drivers/bluetooth/hci_h4p/Makefile | 7
5 drivers/bluetooth/hci_h4p/core.c | 1023 ++++++++++++++++++++++++++++++++++++
6 drivers/bluetooth/hci_h4p/fw-csr.c | 149 +++++
7 drivers/bluetooth/hci_h4p/fw-ti.c | 90 +++
8 drivers/bluetooth/hci_h4p/fw.c | 155 +++++
9 drivers/bluetooth/hci_h4p/hci_h4p.h | 183 ++++++
10 drivers/bluetooth/hci_h4p/sysfs.c | 84 ++
11 drivers/bluetooth/hci_h4p/uart.c | 169 +++++
12 10 files changed, 1871 insertions(+)
13
14 --- /dev/null
15 +++ linux-2.6.36-rc4/drivers/bluetooth/hci_h4p/core.c
16 @@ -0,0 +1,1023 @@
17 +/*
18 + * This file is part of hci_h4p bluetooth driver
19 + *
20 + * Copyright (C) 2005, 2006 Nokia Corporation.
21 + *
22 + * Contact: Ville Tervo <ville.tervo@nokia.com>
23 + *
24 + * This program is free software; you can redistribute it and/or
25 + * modify it under the terms of the GNU General Public License
26 + * version 2 as published by the Free Software Foundation.
27 + *
28 + * This program is distributed in the hope that it will be useful, but
29 + * WITHOUT ANY WARRANTY; without even the implied warranty of
30 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
31 + * General Public License for more details.
32 + *
33 + * You should have received a copy of the GNU General Public License
34 + * along with this program; if not, write to the Free Software
35 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
36 + * 02110-1301 USA
37 + *
38 + */
39 +
40 +#include <linux/module.h>
41 +
42 +#include <linux/kernel.h>
43 +#include <linux/init.h>
44 +#include <linux/errno.h>
45 +#include <linux/delay.h>
46 +#include <linux/spinlock.h>
47 +#include <linux/serial_reg.h>
48 +#include <linux/skbuff.h>
49 +#include <linux/timer.h>
50 +#include <linux/device.h>
51 +#include <linux/platform_device.h>
52 +#include <linux/clk.h>
53 +#include <linux/gpio.h>
54 +
55 +#include <mach/hardware.h>
56 +#include <mach/board.h>
57 +#include <mach/irqs.h>
58 +//#include <mach/pm.h>
59 +
60 +#include <net/bluetooth/bluetooth.h>
61 +#include <net/bluetooth/hci_core.h>
62 +#include <net/bluetooth/hci.h>
63 +
64 +#include "hci_h4p.h"
65 +
66 +#define PM_TIMEOUT 200
67 +
68 +struct omap_bluetooth_config {
69 + u8 chip_type;
70 + u8 bt_wakeup_gpio;
71 + u8 host_wakeup_gpio;
72 + u8 reset_gpio;
73 + u8 bt_uart;
74 + u8 bd_addr[6];
75 + u8 bt_sysclk;
76 +};
77 +
78 +/* This should be used in function that cannot release clocks */
79 +static void hci_h4p_set_clk(struct hci_h4p_info *info, int *clock, int enable)
80 +{
81 + unsigned long flags;
82 +
83 + spin_lock_irqsave(&info->clocks_lock, flags);
84 + if (enable && !*clock) {
85 + NBT_DBG_POWER("Enabling %p\n", clock);
86 + clk_enable(info->uart_fclk);
87 +#ifdef CONFIG_ARCH_OMAP2
88 + if (cpu_is_omap24xx()) {
89 + clk_enable(info->uart_iclk);
90 + //omap2_block_sleep();
91 + }
92 +#endif
93 + }
94 + if (!enable && *clock) {
95 + NBT_DBG_POWER("Disabling %p\n", clock);
96 + clk_disable(info->uart_fclk);
97 +#ifdef CONFIG_ARCH_OMAP2
98 + if (cpu_is_omap24xx()) {
99 + clk_disable(info->uart_iclk);
100 + //omap2_allow_sleep();
101 + }
102 +#endif
103 + }
104 +
105 + *clock = enable;
106 + spin_unlock_irqrestore(&info->clocks_lock, flags);
107 +}
108 +
109 +/* Power management functions */
110 +static void hci_h4p_disable_tx(struct hci_h4p_info *info)
111 +{
112 + NBT_DBG_POWER("\n");
113 +
114 + if (!info->pm_enabled)
115 + return;
116 +
117 + mod_timer(&info->tx_pm_timer, jiffies + msecs_to_jiffies(PM_TIMEOUT));
118 +}
119 +
120 +static void hci_h4p_enable_tx(struct hci_h4p_info *info)
121 +{
122 + NBT_DBG_POWER("\n");
123 +
124 + if (!info->pm_enabled)
125 + return;
126 +
127 + del_timer_sync(&info->tx_pm_timer);
128 + if (info->tx_pm_enabled) {
129 + info->tx_pm_enabled = 0;
130 + hci_h4p_set_clk(info, &info->tx_clocks_en, 1);
131 + gpio_set_value(info->bt_wakeup_gpio, 1);
132 + }
133 +}
134 +
135 +static void hci_h4p_tx_pm_timer(unsigned long data)
136 +{
137 + struct hci_h4p_info *info;
138 +
139 + NBT_DBG_POWER("\n");
140 +
141 + info = (struct hci_h4p_info *)data;
142 +
143 + if (hci_h4p_inb(info, UART_LSR) & UART_LSR_TEMT) {
144 + gpio_set_value(info->bt_wakeup_gpio, 0);
145 + hci_h4p_set_clk(info, &info->tx_clocks_en, 0);
146 + info->tx_pm_enabled = 1;
147 + }
148 + else {
149 + mod_timer(&info->tx_pm_timer, jiffies + msecs_to_jiffies(PM_TIMEOUT));
150 + }
151 +}
152 +
153 +static void hci_h4p_disable_rx(struct hci_h4p_info *info)
154 +{
155 + if (!info->pm_enabled)
156 + return;
157 +
158 + mod_timer(&info->rx_pm_timer, jiffies + msecs_to_jiffies(PM_TIMEOUT));
159 +}
160 +
161 +static void hci_h4p_enable_rx(struct hci_h4p_info *info)
162 +{
163 + unsigned long flags;
164 +
165 + if (!info->pm_enabled)
166 + return;
167 +
168 + del_timer_sync(&info->rx_pm_timer);
169 + spin_lock_irqsave(&info->lock, flags);
170 + if (info->rx_pm_enabled) {
171 + hci_h4p_set_clk(info, &info->rx_clocks_en, 1);
172 + hci_h4p_outb(info, UART_IER, hci_h4p_inb(info, UART_IER) | UART_IER_RDI);
173 + __hci_h4p_set_auto_ctsrts(info, 1, UART_EFR_RTS);
174 + info->rx_pm_enabled = 0;
175 + }
176 + spin_unlock_irqrestore(&info->lock, flags);
177 +}
178 +
179 +static void hci_h4p_rx_pm_timer(unsigned long data)
180 +{
181 + unsigned long flags;
182 + struct hci_h4p_info *info = (struct hci_h4p_info *)data;
183 +
184 + spin_lock_irqsave(&info->lock, flags);
185 + if (!(hci_h4p_inb(info, UART_LSR) & UART_LSR_DR)) {
186 + __hci_h4p_set_auto_ctsrts(info, 0, UART_EFR_RTS);
187 + hci_h4p_set_rts(info, 0);
188 + hci_h4p_outb(info, UART_IER, hci_h4p_inb(info, UART_IER) & ~UART_IER_RDI);
189 + hci_h4p_set_clk(info, &info->rx_clocks_en, 0);
190 + info->rx_pm_enabled = 1;
191 + }
192 + else {
193 + mod_timer(&info->rx_pm_timer, jiffies + msecs_to_jiffies(PM_TIMEOUT));
194 + }
195 + spin_unlock_irqrestore(&info->lock, flags);
196 +}
197 +
198 +/* Negotiation functions */
199 +int hci_h4p_send_alive_packet(struct hci_h4p_info *info)
200 +{
201 + NBT_DBG("Sending alive packet\n");
202 +
203 + if (!info->alive_cmd_skb)
204 + return -EINVAL;
205 +
206 + /* Keep reference to buffer so we can reuse it */
207 + info->alive_cmd_skb = skb_get(info->alive_cmd_skb);
208 +
209 + skb_queue_tail(&info->txq, info->alive_cmd_skb);
210 + tasklet_schedule(&info->tx_task);
211 +
212 + NBT_DBG("Alive packet sent\n");
213 +
214 + return 0;
215 +}
216 +
217 +static void hci_h4p_alive_packet(struct hci_h4p_info *info, struct sk_buff *skb)
218 +{
219 + NBT_DBG("Received alive packet\n");
220 + if (skb->data[1] == 0xCC) {
221 + complete(&info->init_completion);
222 + }
223 +
224 + kfree_skb(skb);
225 +}
226 +
227 +static int hci_h4p_send_negotiation(struct hci_h4p_info *info, struct sk_buff *skb)
228 +{
229 + NBT_DBG("Sending negotiation..\n");
230 +
231 + hci_h4p_change_speed(info, INIT_SPEED);
232 +
233 + info->init_error = 0;
234 + init_completion(&info->init_completion);
235 + skb_queue_tail(&info->txq, skb);
236 + tasklet_schedule(&info->tx_task);
237 +
238 + if (!wait_for_completion_interruptible_timeout(&info->init_completion,
239 + msecs_to_jiffies(1000)))
240 + return -ETIMEDOUT;
241 +
242 + NBT_DBG("Negotiation sent\n");
243 + return info->init_error;
244 +}
245 +
246 +static void hci_h4p_negotiation_packet(struct hci_h4p_info *info,
247 + struct sk_buff *skb)
248 +{
249 + int err = 0;
250 +
251 + if (skb->data[1] == 0x20) {
252 + /* Change to operational settings */
253 + hci_h4p_set_rts(info, 0);
254 +
255 + err = hci_h4p_wait_for_cts(info, 0, 100);
256 + if (err < 0)
257 + goto neg_ret;
258 +
259 + hci_h4p_change_speed(info, MAX_BAUD_RATE);
260 +
261 + err = hci_h4p_wait_for_cts(info, 1, 100);
262 + if (err < 0)
263 + goto neg_ret;
264 +
265 + hci_h4p_set_auto_ctsrts(info, 1, UART_EFR_CTS | UART_EFR_RTS);
266 +
267 + err = hci_h4p_send_alive_packet(info);
268 + if (err < 0)
269 + goto neg_ret;
270 + } else {
271 + dev_err(info->dev, "Could not negotiate hci_h4p settings\n");
272 + err = -EINVAL;
273 + goto neg_ret;
274 + }
275 +
276 + kfree_skb(skb);
277 + return;
278 +
279 +neg_ret:
280 + info->init_error = err;
281 + complete(&info->init_completion);
282 + kfree_skb(skb);
283 +}
284 +
285 +/* H4 packet handling functions */
286 +static int hci_h4p_get_hdr_len(struct hci_h4p_info *info, u8 pkt_type)
287 +{
288 + long retval;
289 +
290 + switch (pkt_type) {
291 + case H4_EVT_PKT:
292 + retval = HCI_EVENT_HDR_SIZE;
293 + break;
294 + case H4_ACL_PKT:
295 + retval = HCI_ACL_HDR_SIZE;
296 + break;
297 + case H4_SCO_PKT:
298 + retval = HCI_SCO_HDR_SIZE;
299 + break;
300 + case H4_NEG_PKT:
301 + retval = 11;
302 + break;
303 + case H4_ALIVE_PKT:
304 + retval = 3;
305 + break;
306 + default:
307 + dev_err(info->dev, "Unknown H4 packet type 0x%.2x\n", pkt_type);
308 + retval = -1;
309 + break;
310 + }
311 +
312 + return retval;
313 +}
314 +
315 +static unsigned int hci_h4p_get_data_len(struct hci_h4p_info *info,
316 + struct sk_buff *skb)
317 +{
318 + long retval = -1;
319 + struct hci_event_hdr *evt_hdr;
320 + struct hci_acl_hdr *acl_hdr;
321 + struct hci_sco_hdr *sco_hdr;
322 +
323 + switch (bt_cb(skb)->pkt_type) {
324 + case H4_EVT_PKT:
325 + evt_hdr = (struct hci_event_hdr *)skb->data;
326 + retval = evt_hdr->plen;
327 + break;
328 + case H4_ACL_PKT:
329 + acl_hdr = (struct hci_acl_hdr *)skb->data;
330 + retval = le16_to_cpu(acl_hdr->dlen);
331 + break;
332 + case H4_SCO_PKT:
333 + sco_hdr = (struct hci_sco_hdr *)skb->data;
334 + retval = sco_hdr->dlen;
335 + break;
336 + case H4_NEG_PKT:
337 + retval = 0;
338 + break;
339 + case H4_ALIVE_PKT:
340 + retval = 0;
341 + break;
342 + }
343 +
344 + return retval;
345 +}
346 +
347 +static inline void hci_h4p_recv_frame(struct hci_h4p_info *info,
348 + struct sk_buff *skb)
349 +{
350 +
351 + if (unlikely(!test_bit(HCI_RUNNING, &info->hdev->flags))) {
352 + NBT_DBG("fw_event\n");
353 + hci_h4p_parse_fw_event(info, skb);
354 + } else {
355 + hci_recv_frame(skb);
356 + NBT_DBG("Frame sent to upper layer\n");
357 + }
358 +}
359 +
360 +static void hci_h4p_rx_tasklet(unsigned long data)
361 +{
362 + u8 byte;
363 + unsigned long flags;
364 + struct hci_h4p_info *info = (struct hci_h4p_info *)data;
365 +
366 + NBT_DBG("tasklet woke up\n");
367 + NBT_DBG_TRANSFER("rx_tasklet woke up\ndata ");
368 +
369 + while (hci_h4p_inb(info, UART_LSR) & UART_LSR_DR) {
370 + byte = hci_h4p_inb(info, UART_RX);
371 + if (info->garbage_bytes) {
372 + info->garbage_bytes--;
373 + continue;
374 + }
375 + if (info->rx_skb == NULL) {
376 + info->rx_skb = bt_skb_alloc(HCI_MAX_FRAME_SIZE, GFP_ATOMIC | GFP_DMA);
377 + if (!info->rx_skb) {
378 + dev_err(info->dev, "Can't allocate memory for new packet\n");
379 + goto finish_task;
380 + }
381 + info->rx_state = WAIT_FOR_PKT_TYPE;
382 + info->rx_skb->dev = (void *)info->hdev;
383 + }
384 + info->hdev->stat.byte_rx++;
385 + NBT_DBG_TRANSFER_NF("0x%.2x ", byte);
386 + switch (info->rx_state) {
387 + case WAIT_FOR_PKT_TYPE:
388 + bt_cb(info->rx_skb)->pkt_type = byte;
389 + info->rx_count = hci_h4p_get_hdr_len(info, byte);
390 + if (info->rx_count < 0) {
391 + info->hdev->stat.err_rx++;
392 + kfree_skb(info->rx_skb);
393 + info->rx_skb = NULL;
394 + } else {
395 + info->rx_state = WAIT_FOR_HEADER;
396 + }
397 + break;
398 + case WAIT_FOR_HEADER:
399 + info->rx_count--;
400 + *skb_put(info->rx_skb, 1) = byte;
401 + if (info->rx_count == 0) {
402 + info->rx_count = hci_h4p_get_data_len(info, info->rx_skb);
403 + if (info->rx_count > skb_tailroom(info->rx_skb)) {
404 + dev_err(info->dev, "Frame is %ld bytes too long.\n",
405 + info->rx_count - skb_tailroom(info->rx_skb));
406 + kfree_skb(info->rx_skb);
407 + info->rx_skb = NULL;
408 + info->garbage_bytes = info->rx_count - skb_tailroom(info->rx_skb);
409 + break;
410 + }
411 + info->rx_state = WAIT_FOR_DATA;
412 +
413 + if (bt_cb(info->rx_skb)->pkt_type == H4_NEG_PKT) {
414 + hci_h4p_negotiation_packet(info, info->rx_skb);
415 + info->rx_skb = NULL;
416 + info->rx_state = WAIT_FOR_PKT_TYPE;
417 + goto finish_task;
418 + }
419 + if (bt_cb(info->rx_skb)->pkt_type == H4_ALIVE_PKT) {
420 + hci_h4p_alive_packet(info, info->rx_skb);
421 + info->rx_skb = NULL;
422 + info->rx_state = WAIT_FOR_PKT_TYPE;
423 + goto finish_task;
424 + }
425 + }
426 + break;
427 + case WAIT_FOR_DATA:
428 + info->rx_count--;
429 + *skb_put(info->rx_skb, 1) = byte;
430 + if (info->rx_count == 0) {
431 + /* H4+ devices should allways send word aligned packets */
432 + if (!(info->rx_skb->len % 2)) {
433 + info->garbage_bytes++;
434 + }
435 + hci_h4p_recv_frame(info, info->rx_skb);
436 + info->rx_skb = NULL;
437 + }
438 + break;
439 + default:
440 + WARN_ON(1);
441 + break;
442 + }
443 + }
444 +
445 +finish_task:
446 + spin_lock_irqsave(&info->lock, flags);
447 + hci_h4p_outb(info, UART_IER, hci_h4p_inb(info, UART_IER) | UART_IER_RDI);
448 + spin_unlock_irqrestore(&info->lock, flags);
449 +
450 + NBT_DBG_TRANSFER_NF("\n");
451 + NBT_DBG("rx_ended\n");
452 +}
453 +
454 +static void hci_h4p_tx_tasklet(unsigned long data)
455 +{
456 + unsigned int sent = 0;
457 + unsigned long flags;
458 + struct sk_buff *skb;
459 + struct hci_h4p_info *info = (struct hci_h4p_info *)data;
460 +
461 + NBT_DBG("tasklet woke up\n");
462 + NBT_DBG_TRANSFER("tx_tasklet woke up\n data ");
463 +
464 + skb = skb_dequeue(&info->txq);
465 + if (!skb) {
466 + /* No data in buffer */
467 + NBT_DBG("skb ready\n");
468 + hci_h4p_disable_tx(info);
469 + return;
470 + }
471 +
472 + /* Copy data to tx fifo */
473 + while (!(hci_h4p_inb(info, UART_OMAP_SSR) & UART_OMAP_SSR_TXFULL) &&
474 + (sent < skb->len)) {
475 + NBT_DBG_TRANSFER_NF("0x%.2x ", skb->data[sent]);
476 + hci_h4p_outb(info, UART_TX, skb->data[sent]);
477 + sent++;
478 + }
479 +
480 + info->hdev->stat.byte_tx += sent;
481 + NBT_DBG_TRANSFER_NF("\n");
482 + if (skb->len == sent) {
483 + kfree_skb(skb);
484 + } else {
485 + skb_pull(skb, sent);
486 + skb_queue_head(&info->txq, skb);
487 + }
488 +
489 + spin_lock_irqsave(&info->lock, flags);
490 + hci_h4p_outb(info, UART_IER, hci_h4p_inb(info, UART_IER) | UART_IER_THRI);
491 + spin_unlock_irqrestore(&info->lock, flags);
492 +}
493 +
494 +static irqreturn_t hci_h4p_interrupt(int irq, void *data)
495 +{
496 + struct hci_h4p_info *info = (struct hci_h4p_info *)data;
497 + u8 iir, msr;
498 + int ret;
499 + unsigned long flags;
500 +
501 + ret = IRQ_NONE;
502 +
503 + iir = hci_h4p_inb(info, UART_IIR);
504 + if (iir & UART_IIR_NO_INT) {
505 + dev_err(info->dev, "Interrupt but no reason irq 0x%.2x\n", iir);
506 + return IRQ_HANDLED;
507 + }
508 +
509 + NBT_DBG("In interrupt handler iir 0x%.2x\n", iir);
510 +
511 + iir &= UART_IIR_ID;
512 +
513 + if (iir == UART_IIR_MSI) {
514 + msr = hci_h4p_inb(info, UART_MSR);
515 + ret = IRQ_HANDLED;
516 + }
517 + if (iir == UART_IIR_RLSI) {
518 + hci_h4p_inb(info, UART_RX);
519 + hci_h4p_inb(info, UART_LSR);
520 + ret = IRQ_HANDLED;
521 + }
522 +
523 + if (iir == UART_IIR_RDI) {
524 + spin_lock_irqsave(&info->lock, flags);
525 + hci_h4p_outb(info, UART_IER, hci_h4p_inb(info, UART_IER) & ~UART_IER_RDI);
526 + spin_unlock_irqrestore(&info->lock, flags);
527 + tasklet_schedule(&info->rx_task);
528 + ret = IRQ_HANDLED;
529 + }
530 +
531 + if (iir == UART_IIR_THRI) {
532 + spin_lock_irqsave(&info->lock, flags);
533 + hci_h4p_outb(info, UART_IER, hci_h4p_inb(info, UART_IER) & ~UART_IER_THRI);
534 + spin_unlock_irqrestore(&info->lock, flags);
535 + tasklet_schedule(&info->tx_task);
536 + ret = IRQ_HANDLED;
537 + }
538 +
539 + return ret;
540 +}
541 +
542 +static irqreturn_t hci_h4p_wakeup_interrupt(int irq, void *dev_inst)
543 +{
544 + struct hci_h4p_info *info = dev_inst;
545 + int should_wakeup;
546 + struct hci_dev *hdev;
547 +
548 + if (!info->hdev)
549 + return IRQ_HANDLED;
550 +
551 + hdev = info->hdev;
552 +
553 + if (!test_bit(HCI_RUNNING, &hdev->flags))
554 + return IRQ_HANDLED;
555 +
556 + should_wakeup = gpio_get_value(info->host_wakeup_gpio);
557 + NBT_DBG_POWER("gpio interrupt %d\n", should_wakeup);
558 + if (should_wakeup) {
559 + hci_h4p_enable_rx(info);
560 + } else {
561 + hci_h4p_disable_rx(info);
562 + }
563 +
564 + return IRQ_HANDLED;
565 +}
566 +
567 +static int hci_h4p_reset(struct hci_h4p_info *info)
568 +{
569 + int err;
570 +
571 + hci_h4p_init_uart(info);
572 + hci_h4p_set_rts(info, 0);
573 +
574 + gpio_set_value(info->reset_gpio, 0);
575 + msleep(100);
576 + gpio_set_value(info->bt_wakeup_gpio, 1);
577 + gpio_set_value(info->reset_gpio, 1);
578 + msleep(100);
579 +
580 + err = hci_h4p_wait_for_cts(info, 1, 10);
581 + if (err < 0) {
582 + dev_err(info->dev, "No cts from bt chip\n");
583 + return err;
584 + }
585 +
586 + hci_h4p_set_rts(info, 1);
587 +
588 + return 0;
589 +}
590 +
591 +/* hci callback functions */
592 +static int hci_h4p_hci_flush(struct hci_dev *hdev)
593 +{
594 + struct hci_h4p_info *info;
595 + info = hdev->driver_data;
596 +
597 + skb_queue_purge(&info->txq);
598 +
599 + return 0;
600 +}
601 +
602 +static int hci_h4p_hci_open(struct hci_dev *hdev)
603 +{
604 + struct hci_h4p_info *info;
605 + int err;
606 + struct sk_buff *neg_cmd_skb;
607 + struct sk_buff_head fw_queue;
608 +
609 + info = hdev->driver_data;
610 +
611 + if (test_bit(HCI_RUNNING, &hdev->flags))
612 + return 0;
613 +
614 + skb_queue_head_init(&fw_queue);
615 + err = hci_h4p_read_fw(info, &fw_queue);
616 + if (err < 0) {
617 + dev_err(info->dev, "Cannot read firmware\n");
618 + return err;
619 + }
620 + neg_cmd_skb = skb_dequeue(&fw_queue);
621 + if (!neg_cmd_skb) {
622 + err = -EPROTO;
623 + goto err_clean;
624 + }
625 + info->alive_cmd_skb = skb_dequeue(&fw_queue);
626 + if (!info->alive_cmd_skb) {
627 + err = -EPROTO;
628 + goto err_clean;
629 + }
630 +
631 + hci_h4p_set_clk(info, &info->tx_clocks_en, 1);
632 + hci_h4p_set_clk(info, &info->rx_clocks_en, 1);
633 +
634 + tasklet_enable(&info->tx_task);
635 + tasklet_enable(&info->rx_task);
636 + info->rx_state = WAIT_FOR_PKT_TYPE;
637 + info->rx_count = 0;
638 + info->garbage_bytes = 0;
639 + info->rx_skb = NULL;
640 + info->pm_enabled = 0;
641 + init_completion(&info->fw_completion);
642 +
643 + err = hci_h4p_reset(info);
644 + if (err < 0)
645 + goto err_clean;
646 +
647 + err = hci_h4p_send_negotiation(info, neg_cmd_skb);
648 + neg_cmd_skb = NULL;
649 + if (err < 0)
650 + goto err_clean;
651 +
652 + err = hci_h4p_send_fw(info, &fw_queue);
653 + if (err < 0) {
654 + dev_err(info->dev, "Sending firmware failed.\n");
655 + goto err_clean;
656 + }
657 +
658 + kfree_skb(info->alive_cmd_skb);
659 + info->alive_cmd_skb = NULL;
660 + info->pm_enabled = 1;
661 + info->tx_pm_enabled = 1;
662 + info->rx_pm_enabled = 0;
663 + set_bit(HCI_RUNNING, &hdev->flags);
664 +
665 + NBT_DBG("hci up and running\n");
666 + return 0;
667 +
668 +err_clean:
669 + hci_h4p_hci_flush(hdev);
670 + tasklet_disable(&info->tx_task);
671 + tasklet_disable(&info->rx_task);
672 + hci_h4p_reset_uart(info);
673 + hci_h4p_set_clk(info, &info->tx_clocks_en, 0);
674 + hci_h4p_set_clk(info, &info->rx_clocks_en, 0);
675 + gpio_set_value(info->reset_gpio, 0);
676 + gpio_set_value(info->bt_wakeup_gpio, 0);
677 + skb_queue_purge(&fw_queue);
678 + kfree_skb(neg_cmd_skb);
679 + neg_cmd_skb = NULL;
680 + kfree_skb(info->alive_cmd_skb);
681 + info->alive_cmd_skb = NULL;
682 + kfree_skb(info->rx_skb);
683 +
684 + return err;
685 +}
686 +
687 +static int hci_h4p_hci_close(struct hci_dev *hdev)
688 +{
689 + struct hci_h4p_info *info = hdev->driver_data;
690 +
691 + if (!test_and_clear_bit(HCI_RUNNING, &hdev->flags))
692 + return 0;
693 +
694 + hci_h4p_hci_flush(hdev);
695 + del_timer_sync(&info->tx_pm_timer);
696 + del_timer_sync(&info->rx_pm_timer);
697 + tasklet_disable(&info->tx_task);
698 + tasklet_disable(&info->rx_task);
699 + hci_h4p_set_clk(info, &info->tx_clocks_en, 1);
700 + hci_h4p_set_clk(info, &info->rx_clocks_en, 1);
701 + hci_h4p_reset_uart(info);
702 + hci_h4p_set_clk(info, &info->tx_clocks_en, 0);
703 + hci_h4p_set_clk(info, &info->rx_clocks_en, 0);
704 + gpio_set_value(info->reset_gpio, 0);
705 + gpio_set_value(info->bt_wakeup_gpio, 0);
706 + kfree_skb(info->rx_skb);
707 +
708 + return 0;
709 +}
710 +
711 +static void hci_h4p_hci_destruct(struct hci_dev *hdev)
712 +{
713 +}
714 +
715 +static int hci_h4p_hci_send_frame(struct sk_buff *skb)
716 +{
717 + struct hci_h4p_info *info;
718 + struct hci_dev *hdev = (struct hci_dev *)skb->dev;
719 + int err = 0;
720 +
721 + if (!hdev) {
722 + printk(KERN_WARNING "hci_h4p: Frame for unknown device\n");
723 + return -ENODEV;
724 + }
725 +
726 + NBT_DBG("dev %p, skb %p\n", hdev, skb);
727 +
728 + info = hdev->driver_data;
729 +
730 + if (!test_bit(HCI_RUNNING, &hdev->flags)) {
731 + dev_warn(info->dev, "Frame for non-running device\n");
732 + return -EIO;
733 + }
734 +
735 + switch (bt_cb(skb)->pkt_type) {
736 + case HCI_COMMAND_PKT:
737 + hdev->stat.cmd_tx++;
738 + break;
739 + case HCI_ACLDATA_PKT:
740 + hdev->stat.acl_tx++;
741 + break;
742 + case HCI_SCODATA_PKT:
743 + hdev->stat.sco_tx++;
744 + break;
745 + }
746 +
747 + /* Push frame type to skb */
748 + *skb_push(skb, 1) = (bt_cb(skb)->pkt_type);
749 + /* We should allways send word aligned data to h4+ devices */
750 + if (skb->len % 2) {
751 + err = skb_pad(skb, 1);
752 + }
753 + if (err)
754 + return err;
755 +
756 + hci_h4p_enable_tx(info);
757 + skb_queue_tail(&info->txq, skb);
758 + tasklet_schedule(&info->tx_task);
759 +
760 + return 0;
761 +}
762 +
763 +static int hci_h4p_hci_ioctl(struct hci_dev *hdev, unsigned int cmd, unsigned long arg)
764 +{
765 + return -ENOIOCTLCMD;
766 +}
767 +
768 +static int hci_h4p_register_hdev(struct hci_h4p_info *info)
769 +{
770 + struct hci_dev *hdev;
771 +
772 + /* Initialize and register HCI device */
773 +
774 + hdev = hci_alloc_dev();
775 + if (!hdev) {
776 + dev_err(info->dev, "Can't allocate memory for device\n");
777 + return -ENOMEM;
778 + }
779 + info->hdev = hdev;
780 +
781 + hdev->type = HCI_UART;
782 + hdev->driver_data = info;
783 +
784 + hdev->open = hci_h4p_hci_open;
785 + hdev->close = hci_h4p_hci_close;
786 + hdev->flush = hci_h4p_hci_flush;
787 + hdev->send = hci_h4p_hci_send_frame;
788 + hdev->destruct = hci_h4p_hci_destruct;
789 + hdev->ioctl = hci_h4p_hci_ioctl;
790 +
791 + hdev->owner = THIS_MODULE;
792 +
793 + if (hci_register_dev(hdev) < 0) {
794 + dev_err(info->dev, "hci_h4p: Can't register HCI device %s.\n", hdev->name);
795 + return -ENODEV;
796 + }
797 +
798 + return 0;
799 +}
800 +
801 +static int hci_h4p_probe(struct platform_device *pdev)
802 +{
803 + struct omap_bluetooth_config *bt_config;
804 + struct hci_h4p_info *info;
805 + int irq, err;
806 +
807 + dev_info(&pdev->dev, "Registering HCI H4P device\n");
808 + info = kzalloc(sizeof(struct hci_h4p_info), GFP_KERNEL);
809 + if (!info)
810 + return -ENOMEM;
811 +
812 + info->dev = &pdev->dev;
813 + info->pm_enabled = 0;
814 + info->tx_pm_enabled = 0;
815 + info->rx_pm_enabled = 0;
816 + info->garbage_bytes = 0;
817 + info->tx_clocks_en = 0;
818 + info->rx_clocks_en = 0;
819 + tasklet_init(&info->tx_task, hci_h4p_tx_tasklet, (unsigned long)info);
820 + tasklet_init(&info->rx_task, hci_h4p_rx_tasklet, (unsigned long)info);
821 + /* hci_h4p_hci_open assumes that tasklet is disabled in startup */
822 + tasklet_disable(&info->tx_task);
823 + tasklet_disable(&info->rx_task);
824 + spin_lock_init(&info->lock);
825 + spin_lock_init(&info->clocks_lock);
826 + skb_queue_head_init(&info->txq);
827 + init_timer(&info->tx_pm_timer);
828 + info->tx_pm_timer.function = hci_h4p_tx_pm_timer;
829 + info->tx_pm_timer.data = (unsigned long)info;
830 + init_timer(&info->rx_pm_timer);
831 + info->rx_pm_timer.function = hci_h4p_rx_pm_timer;
832 + info->rx_pm_timer.data = (unsigned long)info;
833 +
834 + if (pdev->dev.platform_data == NULL) {
835 + dev_err(&pdev->dev, "Could not get Bluetooth config data\n");
836 + return -ENODATA;
837 + }
838 +
839 + bt_config = pdev->dev.platform_data;
840 + info->chip_type = bt_config->chip_type;
841 + info->bt_wakeup_gpio = bt_config->bt_wakeup_gpio;
842 + info->host_wakeup_gpio = bt_config->host_wakeup_gpio;
843 + info->reset_gpio = bt_config->reset_gpio;
844 + info->bt_sysclk = bt_config->bt_sysclk;
845 +
846 + NBT_DBG("RESET gpio: %d\n", info->reset_gpio);
847 + NBT_DBG("BTWU gpio: %d\n", info->bt_wakeup_gpio);
848 + NBT_DBG("HOSTWU gpio: %d\n", info->host_wakeup_gpio);
849 + NBT_DBG("Uart: %d\n", bt_config->bt_uart);
850 + NBT_DBG("sysclk: %d\n", info->bt_sysclk);
851 +
852 + err = gpio_request(info->reset_gpio, "BT reset");
853 + if (err < 0) {
854 + dev_err(&pdev->dev, "Cannot get GPIO line %d\n",
855 + info->reset_gpio);
856 + kfree(info);
857 + goto cleanup;
858 + }
859 +
860 + err = gpio_request(info->bt_wakeup_gpio, "BT wakeup");
861 + if (err < 0)
862 + {
863 + dev_err(info->dev, "Cannot get GPIO line 0x%d",
864 + info->bt_wakeup_gpio);
865 + gpio_free(info->reset_gpio);
866 + kfree(info);
867 + goto cleanup;
868 + }
869 +
870 + err = gpio_request(info->host_wakeup_gpio, "BT host wakeup");
871 + if (err < 0)
872 + {
873 + dev_err(info->dev, "Cannot get GPIO line %d",
874 + info->host_wakeup_gpio);
875 + gpio_free(info->reset_gpio);
876 + gpio_free(info->bt_wakeup_gpio);
877 + kfree(info);
878 + goto cleanup;
879 + }
880 +
881 + gpio_direction_output(info->reset_gpio, 0);
882 + gpio_direction_output(info->bt_wakeup_gpio, 0);
883 + gpio_direction_input(info->host_wakeup_gpio);
884 +
885 + switch (bt_config->bt_uart) {
886 + case 1:
887 + if (cpu_is_omap16xx()) {
888 + irq = INT_UART1;
889 + info->uart_fclk = clk_get(NULL, "uart1_ck");
890 + } else if (cpu_is_omap24xx()) {
891 + irq = INT_24XX_UART1_IRQ;
892 + info->uart_iclk = clk_get(NULL, "uart1_ick");
893 + info->uart_fclk = clk_get(NULL, "uart1_fck");
894 + }
895 + /* FIXME: Use platform_get_resource for the port */
896 + info->uart_base = ioremap(OMAP_UART1_BASE, 0x16);
897 + if (!info->uart_base)
898 + goto cleanup;
899 + break;
900 + case 2:
901 + if (cpu_is_omap16xx()) {
902 + irq = INT_UART2;
903 + info->uart_fclk = clk_get(NULL, "uart2_ck");
904 + } else {
905 + irq = INT_24XX_UART2_IRQ;
906 + info->uart_iclk = clk_get(NULL, "uart2_ick");
907 + info->uart_fclk = clk_get(NULL, "uart2_fck");
908 + }
909 + /* FIXME: Use platform_get_resource for the port */
910 + info->uart_base = ioremap(OMAP_UART2_BASE, 0x16);
911 + if (!info->uart_base)
912 + goto cleanup;
913 + break;
914 + case 3:
915 + if (cpu_is_omap16xx()) {
916 + irq = INT_UART3;
917 + info->uart_fclk = clk_get(NULL, "uart3_ck");
918 + } else {
919 + irq = INT_24XX_UART3_IRQ;
920 + info->uart_iclk = clk_get(NULL, "uart3_ick");
921 + info->uart_fclk = clk_get(NULL, "uart3_fck");
922 + }
923 + /* FIXME: Use platform_get_resource for the port */
924 + info->uart_base = ioremap(OMAP_UART3_BASE, 0x16);
925 + if (!info->uart_base)
926 + goto cleanup;
927 + break;
928 + default:
929 + dev_err(info->dev, "No uart defined\n");
930 + goto cleanup;
931 + }
932 +
933 + info->irq = irq;
934 + err = request_irq(irq, hci_h4p_interrupt, 0, "hci_h4p", (void *)info);
935 + if (err < 0) {
936 + dev_err(info->dev, "hci_h4p: unable to get IRQ %d\n", irq);
937 + goto cleanup;
938 + }
939 +
940 + err = request_irq(gpio_to_irq(info->host_wakeup_gpio),
941 + hci_h4p_wakeup_interrupt,
942 + IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING,
943 + "hci_h4p_wkup", (void *)info);
944 + if (err < 0) {
945 + dev_err(info->dev, "hci_h4p: unable to get wakeup IRQ %d\n",
946 + gpio_to_irq(info->host_wakeup_gpio));
947 + free_irq(irq, (void *)info);
948 + goto cleanup;
949 + }
950 +
951 + hci_h4p_set_clk(info, &info->tx_clocks_en, 1);
952 + hci_h4p_set_auto_ctsrts(info, 0, UART_EFR_CTS | UART_EFR_RTS);
953 + err = hci_h4p_init_uart(info);
954 + if (err < 0)
955 + goto cleanup_irq;
956 + err = hci_h4p_reset(info);
957 + if (err < 0)
958 + goto cleanup_irq;
959 + err = hci_h4p_wait_for_cts(info, 1, 10);
960 + if (err < 0)
961 + goto cleanup_irq;
962 + hci_h4p_set_clk(info, &info->tx_clocks_en, 0);
963 +
964 + platform_set_drvdata(pdev, info);
965 + err = hci_h4p_sysfs_create_files(info->dev);
966 + if (err < 0)
967 + goto cleanup_irq;
968 +
969 + if (hci_h4p_register_hdev(info) < 0) {
970 + dev_err(info->dev, "failed to register hci_h4p hci device\n");
971 + goto cleanup_irq;
972 + }
973 + gpio_set_value(info->reset_gpio, 0);
974 +
975 + return 0;
976 +
977 +cleanup_irq:
978 + free_irq(irq, (void *)info);
979 + free_irq(gpio_to_irq(info->host_wakeup_gpio), (void *)info);
980 +cleanup:
981 + gpio_set_value(info->reset_gpio, 0);
982 + gpio_free(info->reset_gpio);
983 + gpio_free(info->bt_wakeup_gpio);
984 + gpio_free(info->host_wakeup_gpio);
985 + kfree(info);
986 +
987 + return err;
988 +
989 +}
990 +
991 +static int hci_h4p_remove(struct platform_device *dev)
992 +{
993 + struct hci_h4p_info *info;
994 +
995 + info = platform_get_drvdata(dev);
996 +
997 + hci_h4p_hci_close(info->hdev);
998 + free_irq(gpio_to_irq(info->host_wakeup_gpio), (void *) info);
999 + hci_free_dev(info->hdev);
1000 + gpio_free(info->reset_gpio);
1001 + gpio_free(info->bt_wakeup_gpio);
1002 + gpio_free(info->host_wakeup_gpio);
1003 + free_irq(info->irq, (void *) info);
1004 + kfree(info);
1005 +
1006 + return 0;
1007 +}
1008 +
1009 +static struct platform_driver hci_h4p_driver = {
1010 + .probe = hci_h4p_probe,
1011 + .remove = hci_h4p_remove,
1012 + .driver = {
1013 + .name = "hci_h4p",
1014 + },
1015 +};
1016 +
1017 +static int __init hci_h4p_init(void)
1018 +{
1019 + int err = 0;
1020 +
1021 + /* Register the driver with LDM */
1022 + err = platform_driver_register(&hci_h4p_driver);
1023 + if (err < 0)
1024 + printk(KERN_WARNING "failed to register hci_h4p driver\n");
1025 +
1026 + return err;
1027 +}
1028 +
1029 +static void __exit hci_h4p_exit(void)
1030 +{
1031 + platform_driver_unregister(&hci_h4p_driver);
1032 +}
1033 +
1034 +module_init(hci_h4p_init);
1035 +module_exit(hci_h4p_exit);
1036 +
1037 +MODULE_DESCRIPTION("h4 driver with nokia extensions");
1038 +MODULE_LICENSE("GPL");
1039 +MODULE_AUTHOR("Ville Tervo");
1040 --- /dev/null
1041 +++ linux-2.6.36-rc4/drivers/bluetooth/hci_h4p/fw.c
1042 @@ -0,0 +1,155 @@
1043 +/*
1044 + * This file is part of hci_h4p bluetooth driver
1045 + *
1046 + * Copyright (C) 2005, 2006 Nokia Corporation.
1047 + *
1048 + * Contact: Ville Tervo <ville.tervo@nokia.com>
1049 + *
1050 + * This program is free software; you can redistribute it and/or
1051 + * modify it under the terms of the GNU General Public License
1052 + * version 2 as published by the Free Software Foundation.
1053 + *
1054 + * This program is distributed in the hope that it will be useful, but
1055 + * WITHOUT ANY WARRANTY; without even the implied warranty of
1056 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1057 + * General Public License for more details.
1058 + *
1059 + * You should have received a copy of the GNU General Public License
1060 + * along with this program; if not, write to the Free Software
1061 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
1062 + * 02110-1301 USA
1063 + *
1064 + */
1065 +
1066 +#include <linux/skbuff.h>
1067 +#include <linux/firmware.h>
1068 +#include <linux/clk.h>
1069 +
1070 +#include <net/bluetooth/bluetooth.h>
1071 +
1072 +#include "hci_h4p.h"
1073 +
1074 +#define BT_CHIP_TI 2
1075 +#define BT_CHIP_CSR 1
1076 +
1077 +static int fw_pos;
1078 +
1079 +/* Firmware handling */
1080 +static int hci_h4p_open_firmware(struct hci_h4p_info *info,
1081 + const struct firmware **fw_entry)
1082 +{
1083 + int err;
1084 +
1085 + fw_pos = 0;
1086 + NBT_DBG_FW("Opening %d firmware\n", info->chip_type);
1087 + switch (info->chip_type) {
1088 + case BT_CHIP_TI:
1089 + err = request_firmware(fw_entry, "brf6150fw.bin", info->dev);
1090 + break;
1091 + case BT_CHIP_CSR:
1092 + err = request_firmware(fw_entry, "bc4fw.bin", info->dev);
1093 + break;
1094 + default:
1095 + dev_err(info->dev, "Invalid chip type\n");
1096 + *fw_entry = NULL;
1097 + err = -EINVAL;
1098 + }
1099 +
1100 + return err;
1101 +}
1102 +
1103 +static void hci_h4p_close_firmware(const struct firmware *fw_entry)
1104 +{
1105 + release_firmware(fw_entry);
1106 +}
1107 +
1108 +/* Read fw. Return length of the command. If no more commands in
1109 + * fw 0 is returned. In error case return value is negative.
1110 + */
1111 +static int hci_h4p_read_fw_cmd(struct hci_h4p_info *info, struct sk_buff **skb,
1112 + const struct firmware *fw_entry, int how)
1113 +{
1114 + unsigned int cmd_len;
1115 +
1116 + if (fw_pos >= fw_entry->size) {
1117 + return 0;
1118 + }
1119 +
1120 + cmd_len = fw_entry->data[fw_pos++];
1121 + if (!cmd_len)
1122 + return 0;
1123 +
1124 + if (fw_pos + cmd_len > fw_entry->size) {
1125 + dev_err(info->dev, "Corrupted firmware image\n");
1126 + return -EMSGSIZE;
1127 + }
1128 +
1129 + *skb = bt_skb_alloc(cmd_len, how);
1130 + if (!*skb) {
1131 + dev_err(info->dev, "Cannot reserve memory for buffer\n");
1132 + return -ENOMEM;
1133 + }
1134 + memcpy(skb_put(*skb, cmd_len), &fw_entry->data[fw_pos], cmd_len);
1135 +
1136 + fw_pos += cmd_len;
1137 +
1138 + return (*skb)->len;
1139 +}
1140 +
1141 +int hci_h4p_read_fw(struct hci_h4p_info *info, struct sk_buff_head *fw_queue)
1142 +{
1143 + const struct firmware *fw_entry = NULL;
1144 + struct sk_buff *skb = NULL;
1145 + int err;
1146 +
1147 + err = hci_h4p_open_firmware(info, &fw_entry);
1148 + if (err < 0 || !fw_entry)
1149 + goto err_clean;
1150 +
1151 + while ((err = hci_h4p_read_fw_cmd(info, &skb, fw_entry, GFP_KERNEL))) {
1152 + if (err < 0 || !skb)
1153 + goto err_clean;
1154 +
1155 + skb_queue_tail(fw_queue, skb);
1156 + }
1157 +
1158 +err_clean:
1159 + hci_h4p_close_firmware(fw_entry);
1160 + return err;
1161 +}
1162 +
1163 +int hci_h4p_send_fw(struct hci_h4p_info *info, struct sk_buff_head *fw_queue)
1164 +{
1165 + int err;
1166 +
1167 + switch(info->chip_type) {
1168 + case BT_CHIP_CSR:
1169 + err = hci_h4p_bc4_send_fw(info, fw_queue);
1170 + break;
1171 + case BT_CHIP_TI:
1172 + err = hci_h4p_brf6150_send_fw(info, fw_queue);
1173 + break;
1174 + default:
1175 + dev_err(info->dev, "Don't know how to send firmware\n");
1176 + err = -EINVAL;
1177 + }
1178 +
1179 + return err;
1180 +}
1181 +
1182 +void hci_h4p_parse_fw_event(struct hci_h4p_info *info, struct sk_buff *skb)
1183 +{
1184 + switch (info->chip_type) {
1185 + case BT_CHIP_CSR:
1186 + hci_h4p_bc4_parse_fw_event(info, skb);
1187 + break;
1188 + case BT_CHIP_TI:
1189 + hci_h4p_brf6150_parse_fw_event(info, skb);
1190 + break;
1191 + default:
1192 + dev_err(info->dev, "Don't know how to parse fw event\n");
1193 + info->fw_error = -EINVAL;
1194 + }
1195 +
1196 + return;
1197 +}
1198 --- /dev/null
1199 +++ linux-2.6.36-rc4/drivers/bluetooth/hci_h4p/fw-csr.c
1200 @@ -0,0 +1,149 @@
1201 +/*
1202 + * This file is part of hci_h4p bluetooth driver
1203 + *
1204 + * Copyright (C) 2005, 2006 Nokia Corporation.
1205 + *
1206 + * Contact: Ville Tervo <ville.tervo@nokia.com>
1207 + *
1208 + * This program is free software; you can redistribute it and/or
1209 + * modify it under the terms of the GNU General Public License
1210 + * version 2 as published by the Free Software Foundation.
1211 + *
1212 + * This program is distributed in the hope that it will be useful, but
1213 + * WITHOUT ANY WARRANTY; without even the implied warranty of
1214 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1215 + * General Public License for more details.
1216 + *
1217 + * You should have received a copy of the GNU General Public License
1218 + * along with this program; if not, write to the Free Software
1219 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
1220 + * 02110-1301 USA
1221 + *
1222 + */
1223 +
1224 +#include <linux/skbuff.h>
1225 +#include <linux/delay.h>
1226 +#include <linux/serial_reg.h>
1227 +
1228 +#include "hci_h4p.h"
1229 +
1230 +void hci_h4p_bc4_parse_fw_event(struct hci_h4p_info *info, struct sk_buff *skb)
1231 +{
1232 + /* Check if this is fw packet */
1233 + if (skb->data[0] != 0xff) {
1234 + hci_recv_frame(skb);
1235 + return;
1236 + }
1237 +
1238 + if (skb->data[11] || skb->data[12]) {
1239 + dev_err(info->dev, "Firmware sending command failed\n");
1240 + info->fw_error = -EPROTO;
1241 + }
1242 +
1243 + kfree_skb(skb);
1244 + complete(&info->fw_completion);
1245 +}
1246 +
1247 +int hci_h4p_bc4_send_fw(struct hci_h4p_info *info,
1248 + struct sk_buff_head *fw_queue)
1249 +{
1250 + struct sk_buff *skb;
1251 + unsigned int offset;
1252 + int retries, count, i;
1253 +
1254 + info->fw_error = 0;
1255 +
1256 + NBT_DBG_FW("Sending firmware\n");
1257 + skb = skb_dequeue(fw_queue);
1258 +
1259 + if (!skb)
1260 + return -ENOMSG;
1261 +
1262 + info->bdaddr[0] = 0x00;
1263 + info->bdaddr[1] = 0x1D;
1264 + info->bdaddr[2] = 0x6E;
1265 + info->bdaddr[3] = 0xD4;
1266 + info->bdaddr[4] = 0xF0;
1267 + info->bdaddr[5] = 0x37;
1268 +
1269 + /* Check if this is bd_address packet */
1270 + if (skb->data[15] == 0x01 && skb->data[16] == 0x00) {
1271 + dev_info(info->dev, "bd_address packet found\n");
1272 + offset = 21;
1273 + skb->data[offset + 1] = 0x00;
1274 + skb->data[offset + 5] = 0x00;
1275 + skb->data[offset + 7] = info->bdaddr[0];
1276 + skb->data[offset + 6] = info->bdaddr[1];
1277 + skb->data[offset + 4] = info->bdaddr[2];
1278 + skb->data[offset + 0] = info->bdaddr[3];
1279 + skb->data[offset + 3] = info->bdaddr[4];
1280 + skb->data[offset + 2] = info->bdaddr[5];
1281 + }
1282 +
1283 + for (i = 0; i < 6; i++) {
1284 + if (info->bdaddr[i] != 0x00)
1285 + break;
1286 + }
1287 +
1288 + /* if (i > 5) {
1289 + dev_info(info->dev, "Valid bluetooth address not found.\n");
1290 + kfree_skb(skb);
1291 + return -ENODEV;
1292 + } */
1293 +
1294 + for (count = 1; ; count++) {
1295 + NBT_DBG_FW("Sending firmware command %d\n", count);
1296 + init_completion(&info->fw_completion);
1297 + skb_queue_tail(&info->txq, skb);
1298 + tasklet_schedule(&info->tx_task);
1299 +
1300 + skb = skb_dequeue(fw_queue);
1301 + if (!skb)
1302 + break;
1303 +
1304 + if (!wait_for_completion_timeout(&info->fw_completion,
1305 + msecs_to_jiffies(1000))) {
1306 + dev_err(info->dev, "No reply to fw command\n");
1307 + return -ETIMEDOUT;
1308 + }
1309 +
1310 + if (info->fw_error) {
1311 + dev_err(info->dev, "FW error\n");
1312 + return -EPROTO;
1313 + }
1314 + };
1315 +
1316 + /* Wait for chip warm reset */
1317 + retries = 100;
1318 + while ((!skb_queue_empty(&info->txq) ||
1319 + !(hci_h4p_inb(info, UART_LSR) & UART_LSR_TEMT)) &&
1320 + retries--) {
1321 + msleep(10);
1322 + }
1323 + if (!retries) {
1324 + dev_err(info->dev, "Transmitter not empty\n");
1325 + return -ETIMEDOUT;
1326 + }
1327 +
1328 + hci_h4p_change_speed(info, BC4_MAX_BAUD_RATE);
1329 +
1330 + if (hci_h4p_wait_for_cts(info, 1, 100)) {
1331 + dev_err(info->dev, "cts didn't go down after final speed change\n");
1332 + return -ETIMEDOUT;
1333 + }
1334 +
1335 + retries = 100;
1336 + do {
1337 + init_completion(&info->init_completion);
1338 + hci_h4p_send_alive_packet(info);
1339 + retries--;
1340 + } while (!wait_for_completion_timeout(&info->init_completion, 100) &&
1341 + retries > 0);
1342 +
1343 + if (!retries) {
1344 + dev_err(info->dev, "No alive reply after speed change\n");
1345 + return -ETIMEDOUT;
1346 + }
1347 +
1348 + return 0;
1349 +}
1350 --- /dev/null
1351 +++ linux-2.6.36-rc4/drivers/bluetooth/hci_h4p/fw-ti.c
1352 @@ -0,0 +1,90 @@
1353 +/*
1354 + * This file is part of hci_h4p bluetooth driver
1355 + *
1356 + * Copyright (C) 2005, 2006 Nokia Corporation.
1357 + *
1358 + * Contact: Ville Tervo <ville.tervo@nokia.com>
1359 + *
1360 + * This program is free software; you can redistribute it and/or
1361 + * modify it under the terms of the GNU General Public License
1362 + * version 2 as published by the Free Software Foundation.
1363 + *
1364 + * This program is distributed in the hope that it will be useful, but
1365 + * WITHOUT ANY WARRANTY; without even the implied warranty of
1366 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1367 + * General Public License for more details.
1368 + *
1369 + * You should have received a copy of the GNU General Public License
1370 + * along with this program; if not, write to the Free Software
1371 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
1372 + * 02110-1301 USA
1373 + *
1374 + */
1375 +
1376 +#include <linux/skbuff.h>
1377 +
1378 +#include "hci_h4p.h"
1379 +
1380 +void hci_h4p_brf6150_parse_fw_event(struct hci_h4p_info *info,
1381 + struct sk_buff *skb)
1382 +{
1383 + struct hci_fw_event *ev;
1384 + int err = 0;
1385 +
1386 + if (bt_cb(skb)->pkt_type != H4_EVT_PKT) {
1387 + dev_err(info->dev, "Got non event fw packet.\n");
1388 + err = -EPROTO;
1389 + goto ret;
1390 + }
1391 +
1392 + ev = (struct hci_fw_event *)skb->data;
1393 + if (ev->hev.evt != HCI_EV_CMD_COMPLETE) {
1394 + dev_err(info->dev, "Got non cmd complete fw event\n");
1395 + err = -EPROTO;
1396 + goto ret;
1397 + }
1398 +
1399 + if (ev->status != 0) {
1400 + dev_err(info->dev, "Got error status from fw command\n");
1401 + err = -EPROTO;
1402 + goto ret;
1403 + }
1404 +
1405 +ret:
1406 + info->fw_error = err;
1407 + complete(&info->fw_completion);
1408 +}
1409 +
1410 +int hci_h4p_brf6150_send_fw(struct hci_h4p_info *info, struct sk_buff_head *fw_queue)
1411 +{
1412 + struct sk_buff *skb;
1413 + int err = 0;
1414 +
1415 + info->fw_error = 0;
1416 +
1417 + while ((skb = skb_dequeue(fw_queue)) != NULL) {
1418 + /* We should allways send word aligned data to h4+ devices */
1419 + if (skb->len % 2) {
1420 + err = skb_pad(skb, 1);
1421 + }
1422 + if (err)
1423 + return err;
1424 +
1425 + init_completion(&info->fw_completion);
1426 + skb_queue_tail(&info->txq, skb);
1427 + tasklet_schedule(&info->tx_task);
1428 +
1429 + if (!wait_for_completion_timeout(&info->fw_completion, HZ)) {
1430 + dev_err(info->dev, "Timeout while sending brf6150 fw\n");
1431 + return -ETIMEDOUT;
1432 + }
1433 +
1434 + if (info->fw_error) {
1435 + dev_err(info->dev, "There was fw_error while sending bfr6150 fw\n");
1436 + return -EPROTO;
1437 + }
1438 + }
1439 + NBT_DBG_FW("Firmware sent\n");
1440 +
1441 + return 0;
1442 +}
1443 --- /dev/null
1444 +++ linux-2.6.36-rc4/drivers/bluetooth/hci_h4p/hci_h4p.h
1445 @@ -0,0 +1,183 @@
1446 +/*
1447 + * This file is part of hci_h4p bluetooth driver
1448 + *
1449 + * Copyright (C) 2005, 2006 Nokia Corporation.
1450 + *
1451 + * Contact: Ville Tervo <ville.tervo@nokia.com>
1452 + *
1453 + * This program is free software; you can redistribute it and/or
1454 + * modify it under the terms of the GNU General Public License
1455 + * version 2 as published by the Free Software Foundation.
1456 + *
1457 + * This program is distributed in the hope that it will be useful, but
1458 + * WITHOUT ANY WARRANTY; without even the implied warranty of
1459 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1460 + * General Public License for more details.
1461 + *
1462 + * You should have received a copy of the GNU General Public License
1463 + * along with this program; if not, write to the Free Software
1464 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
1465 + * 02110-1301 USA
1466 + *
1467 + */
1468 +
1469 +#include <mach/board.h>
1470 +
1471 +#include <net/bluetooth/bluetooth.h>
1472 +#include <net/bluetooth/hci_core.h>
1473 +#include <net/bluetooth/hci.h>
1474 +
1475 +#ifndef __DRIVERS_BLUETOOTH_HCI_H4P_H
1476 +#define __DRIVERS_BLUETOOTH_HCI_H4P_H
1477 +
1478 +#define UART_SYSC_OMAP_RESET 0x03
1479 +#define UART_SYSS_RESETDONE 0x01
1480 +#define UART_OMAP_SCR_EMPTY_THR 0x08
1481 +#define UART_OMAP_SCR_WAKEUP 0x10
1482 +#define UART_OMAP_SSR_WAKEUP 0x02
1483 +#define UART_OMAP_SSR_TXFULL 0x01
1484 +
1485 +#if 0
1486 +#define NBT_DBG(fmt, arg...) printk("%s: " fmt "" , __FUNCTION__ , ## arg)
1487 +#else
1488 +#define NBT_DBG(...)
1489 +#endif
1490 +
1491 +#if 0
1492 +#define NBT_DBG_FW(fmt, arg...) printk("%s: " fmt "" , __FUNCTION__ , ## arg)
1493 +#else
1494 +#define NBT_DBG_FW(...)
1495 +#endif
1496 +
1497 +#if 0
1498 +#define NBT_DBG_POWER(fmt, arg...) printk("%s: " fmt "" , __FUNCTION__ , ## arg)
1499 +#else
1500 +#define NBT_DBG_POWER(...)
1501 +#endif
1502 +
1503 +#if 0
1504 +#define NBT_DBG_TRANSFER(fmt, arg...) printk("%s: " fmt "" , __FUNCTION__ , ## arg)
1505 +#else
1506 +#define NBT_DBG_TRANSFER(...)
1507 +#endif
1508 +
1509 +#if 0
1510 +#define NBT_DBG_TRANSFER_NF(fmt, arg...) printk(fmt "" , ## arg)
1511 +#else
1512 +#define NBT_DBG_TRANSFER_NF(...)
1513 +#endif
1514 +
1515 +#if 0
1516 +#define NBT_DBG_DMA(fmt, arg...) printk("%s: " fmt "" , __FUNCTION__ , ## arg)
1517 +#else
1518 +#define NBT_DBG_DMA(...)
1519 +#endif
1520 +
1521 +struct hci_h4p_info {
1522 + struct hci_dev *hdev;
1523 + spinlock_t lock;
1524 +
1525 + void __iomem *uart_base;
1526 + unsigned long uart_phys_base;
1527 + int irq;
1528 + struct device *dev;
1529 + u8 bdaddr[6];
1530 + u8 chip_type;
1531 + u8 bt_wakeup_gpio;
1532 + u8 host_wakeup_gpio;
1533 + u8 reset_gpio;
1534 + u8 bt_sysclk;
1535 +
1536 +
1537 + struct sk_buff_head fw_queue;
1538 + struct sk_buff *alive_cmd_skb;
1539 + struct completion init_completion;
1540 + struct completion fw_completion;
1541 + int fw_error;
1542 + int init_error;
1543 +
1544 + struct sk_buff_head txq;
1545 + struct tasklet_struct tx_task;
1546 +
1547 + struct sk_buff *rx_skb;
1548 + long rx_count;
1549 + unsigned long rx_state;
1550 + unsigned long garbage_bytes;
1551 + struct tasklet_struct rx_task;
1552 +
1553 + int pm_enabled;
1554 + int tx_pm_enabled;
1555 + int rx_pm_enabled;
1556 + struct timer_list tx_pm_timer;
1557 + struct timer_list rx_pm_timer;
1558 +
1559 + int tx_clocks_en;
1560 + int rx_clocks_en;
1561 + spinlock_t clocks_lock;
1562 + struct clk *uart_iclk;
1563 + struct clk *uart_fclk;
1564 +};
1565 +
1566 +#define MAX_BAUD_RATE 921600
1567 +#define BC4_MAX_BAUD_RATE 3692300
1568 +#define UART_CLOCK 48000000
1569 +#define BT_INIT_DIVIDER 320
1570 +#define BT_BAUDRATE_DIVIDER 384000000
1571 +#define BT_SYSCLK_DIV 1000
1572 +#define INIT_SPEED 120000
1573 +
1574 +#define H4_TYPE_SIZE 1
1575 +
1576 +/* H4+ packet types */
1577 +#define H4_CMD_PKT 0x01
1578 +#define H4_ACL_PKT 0x02
1579 +#define H4_SCO_PKT 0x03
1580 +#define H4_EVT_PKT 0x04
1581 +#define H4_NEG_PKT 0x06
1582 +#define H4_ALIVE_PKT 0x07
1583 +
1584 +/* TX states */
1585 +#define WAIT_FOR_PKT_TYPE 1
1586 +#define WAIT_FOR_HEADER 2
1587 +#define WAIT_FOR_DATA 3
1588 +
1589 +struct hci_fw_event {
1590 + struct hci_event_hdr hev;
1591 + struct hci_ev_cmd_complete cmd;
1592 + u8 status;
1593 +} __attribute__ ((packed));
1594 +
1595 +struct hci_bc4_set_bdaddr {
1596 + u8 type;
1597 + struct hci_command_hdr cmd_hdr;
1598 +} __attribute__ ((packed));
1599 +
1600 +int hci_h4p_send_alive_packet(struct hci_h4p_info *info);
1601 +
1602 +void hci_h4p_bc4_parse_fw_event(struct hci_h4p_info *info,
1603 + struct sk_buff *skb);
1604 +int hci_h4p_bc4_send_fw(struct hci_h4p_info *info,
1605 + struct sk_buff_head *fw_queue);
1606 +
1607 +void hci_h4p_brf6150_parse_fw_event(struct hci_h4p_info *info,
1608 + struct sk_buff *skb);
1609 +int hci_h4p_brf6150_send_fw(struct hci_h4p_info *info,
1610 + struct sk_buff_head *fw_queue);
1611 +
1612 +int hci_h4p_read_fw(struct hci_h4p_info *info, struct sk_buff_head *fw_queue);
1613 +int hci_h4p_send_fw(struct hci_h4p_info *info, struct sk_buff_head *fw_queue);
1614 +void hci_h4p_parse_fw_event(struct hci_h4p_info *info, struct sk_buff *skb);
1615 +
1616 +int hci_h4p_sysfs_create_files(struct device *dev);
1617 +
1618 +void hci_h4p_outb(struct hci_h4p_info *info, unsigned int offset, u8 val);
1619 +u8 hci_h4p_inb(struct hci_h4p_info *info, unsigned int offset);
1620 +void hci_h4p_set_rts(struct hci_h4p_info *info, int active);
1621 +int hci_h4p_wait_for_cts(struct hci_h4p_info *info, int active, int timeout_ms);
1622 +void __hci_h4p_set_auto_ctsrts(struct hci_h4p_info *info, int on, u8 which);
1623 +void hci_h4p_set_auto_ctsrts(struct hci_h4p_info *info, int on, u8 which);
1624 +void hci_h4p_change_speed(struct hci_h4p_info *info, unsigned long speed);
1625 +int hci_h4p_reset_uart(struct hci_h4p_info *info);
1626 +int hci_h4p_init_uart(struct hci_h4p_info *info);
1627 +
1628 +#endif /* __DRIVERS_BLUETOOTH_HCI_H4P_H */
1629 --- /dev/null
1630 +++ linux-2.6.36-rc4/drivers/bluetooth/hci_h4p/Makefile
1631 @@ -0,0 +1,7 @@
1632 +#
1633 +# Makefile for the Linux Bluetooth HCI device drivers.
1634 +#
1635 +
1636 +obj-$(CONFIG_BT_HCIH4P) += hci_h4p.o
1637 +
1638 +hci_h4p-objs := core.o fw.o uart.o sysfs.o fw-ti.o fw-csr.o
1639 --- /dev/null
1640 +++ linux-2.6.36-rc4/drivers/bluetooth/hci_h4p/sysfs.c
1641 @@ -0,0 +1,84 @@
1642 +/*
1643 + * This file is part of hci_h4p bluetooth driver
1644 + *
1645 + * Copyright (C) 2005, 2006 Nokia Corporation.
1646 + *
1647 + * Contact: Ville Tervo <ville.tervo@nokia.com>
1648 + *
1649 + * This program is free software; you can redistribute it and/or
1650 + * modify it under the terms of the GNU General Public License
1651 + * version 2 as published by the Free Software Foundation.
1652 + *
1653 + * This program is distributed in the hope that it will be useful, but
1654 + * WITHOUT ANY WARRANTY; without even the implied warranty of
1655 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1656 + * General Public License for more details.
1657 + *
1658 + * You should have received a copy of the GNU General Public License
1659 + * along with this program; if not, write to the Free Software
1660 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
1661 + * 02110-1301 USA
1662 + *
1663 + */
1664 +
1665 +#include <linux/kernel.h>
1666 +#include <linux/init.h>
1667 +#include <linux/device.h>
1668 +#include <linux/platform_device.h>
1669 +
1670 +#include "hci_h4p.h"
1671 +
1672 +#ifdef CONFIG_SYSFS
1673 +
1674 +static ssize_t hci_h4p_store_bdaddr(struct device *dev, struct device_attribute *attr,
1675 + const char *buf, size_t count)
1676 +{
1677 + struct hci_h4p_info *info = (struct hci_h4p_info*)dev_get_drvdata(dev);
1678 + unsigned int bdaddr[6];
1679 + int ret, i;
1680 +
1681 + dev_info(info->dev, "HCI_H4P_STORE_BDADDR called\n");
1682 +
1683 + ret = sscanf(buf, "%2x:%2x:%2x:%2x:%2x:%2x\n",
1684 + &bdaddr[0], &bdaddr[1], &bdaddr[2],
1685 + &bdaddr[3], &bdaddr[4], &bdaddr[5]);
1686 +
1687 + if (ret != 6) {
1688 + dev_info(info->dev, "bdaddr isn't found\n");
1689 + return -EINVAL;
1690 + }
1691 +
1692 + //for (i = 0; i < 6; i++)
1693 + //info->bdaddr[i] = bdaddr[i] & 0xff;
1694 +
1695 + info->bdaddr[0] = 0x00;
1696 + info->bdaddr[1] = 0x1D;
1697 + info->bdaddr[2] = 0x6E;
1698 + info->bdaddr[3] = 0xD4;
1699 + info->bdaddr[4] = 0xF0;
1700 + info->bdaddr[5] = 0x37;
1701 +
1702 + return count;
1703 +}
1704 +
1705 +static ssize_t hci_h4p_show_bdaddr(struct device *dev, struct device_attribute *attr,
1706 + char *buf)
1707 +{
1708 + struct hci_h4p_info *info = (struct hci_h4p_info*)dev_get_drvdata(dev);
1709 +
1710 + return sprintf(buf, "%.2x:%.2x:%.2x:%.2x:%.2x:%.2x\n",
1711 + info->bdaddr[0],
1712 + info->bdaddr[1],
1713 + info->bdaddr[2],
1714 + info->bdaddr[3],
1715 + info->bdaddr[4],
1716 + info->bdaddr[5]);
1717 +}
1718 +
1719 +static DEVICE_ATTR(bdaddr, S_IRUGO | S_IWUSR, hci_h4p_show_bdaddr, hci_h4p_store_bdaddr);
1720 +int hci_h4p_sysfs_create_files(struct device *dev)
1721 +{
1722 + return device_create_file(dev, &dev_attr_bdaddr);
1723 +}
1724 +
1725 +#endif
1726 --- /dev/null
1727 +++ linux-2.6.36-rc4/drivers/bluetooth/hci_h4p/uart.c
1728 @@ -0,0 +1,169 @@
1729 +/*
1730 + * This file is part of hci_h4p bluetooth driver
1731 + *
1732 + * Copyright (C) 2005, 2006 Nokia Corporation.
1733 + *
1734 + * Contact: Ville Tervo <ville.tervo@nokia.com>
1735 + *
1736 + * This program is free software; you can redistribute it and/or
1737 + * modify it under the terms of the GNU General Public License
1738 + * version 2 as published by the Free Software Foundation.
1739 + *
1740 + * This program is distributed in the hope that it will be useful, but
1741 + * WITHOUT ANY WARRANTY; without even the implied warranty of
1742 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1743 + * General Public License for more details.
1744 + *
1745 + * You should have received a copy of the GNU General Public License
1746 + * along with this program; if not, write to the Free Software
1747 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
1748 + * 02110-1301 USA
1749 + *
1750 + */
1751 +
1752 +#include <linux/serial_reg.h>
1753 +#include <linux/delay.h>
1754 +#include <linux/clk.h>
1755 +
1756 +#include <asm/io.h>
1757 +
1758 +#include "hci_h4p.h"
1759 +
1760 +inline void hci_h4p_outb(struct hci_h4p_info *info, unsigned int offset, u8 val)
1761 +{
1762 + offset <<= 2;
1763 + __raw_writeb(val, info->uart_base + offset);
1764 + //outb(val, info->uart_base + (offset << 2));
1765 +}
1766 +
1767 +inline u8 hci_h4p_inb(struct hci_h4p_info *info, unsigned int offset)
1768 +{
1769 + offset <<= 2;
1770 + return (u8)__raw_readb(info->uart_base + offset);
1771 + //return (unsigned int)__raw_readb(up->membase + offset);
1772 + //return inb(info->uart_base + (offset << 2));
1773 +}
1774 +
1775 +void hci_h4p_set_rts(struct hci_h4p_info *info, int active)
1776 +{
1777 + u8 b;
1778 +
1779 + b = hci_h4p_inb(info, UART_MCR);
1780 + if (active)
1781 + b |= UART_MCR_RTS;
1782 + else
1783 + b &= ~UART_MCR_RTS;
1784 + hci_h4p_outb(info, UART_MCR, b);
1785 +}
1786 +
1787 +int hci_h4p_wait_for_cts(struct hci_h4p_info *info, int active,
1788 + int timeout_ms)
1789 +{
1790 + int okay;
1791 + unsigned long timeout;
1792 +
1793 + okay = 0;
1794 + timeout = jiffies + msecs_to_jiffies(timeout_ms);
1795 + for (;;) {
1796 + int state;
1797 +
1798 + state = hci_h4p_inb(info, UART_MSR) & UART_MSR_CTS;
1799 + if (active) {
1800 + if (state)
1801 + return 0;
1802 + } else {
1803 + if (!state)
1804 + return 0;
1805 + }
1806 + if (time_after(jiffies, timeout))
1807 + return -ETIMEDOUT;
1808 + }
1809 +}
1810 +
1811 +void __hci_h4p_set_auto_ctsrts(struct hci_h4p_info *info, int on, u8 which)
1812 +{
1813 + u8 lcr, b;
1814 +
1815 + lcr = hci_h4p_inb(info, UART_LCR);
1816 + hci_h4p_outb(info, UART_LCR, 0xbf);
1817 + b = hci_h4p_inb(info, UART_EFR);
1818 + if (on)
1819 + b |= which;
1820 + else
1821 + b &= ~which;
1822 + hci_h4p_outb(info, UART_EFR, b);
1823 + hci_h4p_outb(info, UART_LCR, lcr);
1824 +}
1825 +
1826 +void hci_h4p_set_auto_ctsrts(struct hci_h4p_info *info, int on, u8 which)
1827 +{
1828 + unsigned long flags;
1829 +
1830 + spin_lock_irqsave(&info->lock, flags);
1831 + __hci_h4p_set_auto_ctsrts(info, on, which);
1832 + spin_unlock_irqrestore(&info->lock, flags);
1833 +}
1834 +
1835 +void hci_h4p_change_speed(struct hci_h4p_info *info, unsigned long speed)
1836 +{
1837 + unsigned int divisor;
1838 + u8 lcr, mdr1;
1839 +
1840 + NBT_DBG("Setting speed %lu\n", speed);
1841 +
1842 + if (speed >= 460800) {
1843 + divisor = UART_CLOCK / 13 / speed;
1844 + mdr1 = 3;
1845 + } else {
1846 + divisor = UART_CLOCK / 16 / speed;
1847 + mdr1 = 0;
1848 + }
1849 +
1850 + hci_h4p_outb(info, UART_OMAP_MDR1, 7); /* Make sure UART mode is disabled */
1851 + lcr = hci_h4p_inb(info, UART_LCR);
1852 + hci_h4p_outb(info, UART_LCR, UART_LCR_DLAB); /* Set DLAB */
1853 + hci_h4p_outb(info, UART_DLL, divisor & 0xff); /* Set speed */
1854 + hci_h4p_outb(info, UART_DLM, divisor >> 8);
1855 + hci_h4p_outb(info, UART_LCR, lcr);
1856 + hci_h4p_outb(info, UART_OMAP_MDR1, mdr1); /* Make sure UART mode is enabled */
1857 +}
1858 +
1859 +int hci_h4p_reset_uart(struct hci_h4p_info *info)
1860 +{
1861 + int count = 0;
1862 +
1863 + /* Reset the UART */
1864 + hci_h4p_outb(info, UART_OMAP_SYSC, UART_SYSC_OMAP_RESET);
1865 + while (!(hci_h4p_inb(info, UART_OMAP_SYSS) & UART_SYSS_RESETDONE)) {
1866 + if (count++ > 20000) {
1867 + dev_err(info->dev, "hci_h4p: UART reset timeout\n");
1868 + return -ENODEV;
1869 + }
1870 + udelay(1);
1871 + }
1872 +
1873 + return 0;
1874 +}
1875 +
1876 +int hci_h4p_init_uart(struct hci_h4p_info *info)
1877 +{
1878 + int err;
1879 +
1880 + err = hci_h4p_reset_uart(info);
1881 + if (err < 0)
1882 + return err;
1883 +
1884 + /* Enable and setup FIFO */
1885 + hci_h4p_outb(info, UART_LCR, UART_LCR_WLEN8);
1886 + hci_h4p_outb(info, UART_OMAP_MDR1, 0x00); /* Make sure UART mode is enabled */
1887 + hci_h4p_outb(info, UART_OMAP_SCR, 0x80);
1888 + hci_h4p_outb(info, UART_EFR, UART_EFR_ECB);
1889 + hci_h4p_outb(info, UART_MCR, UART_MCR_TCRTLR);
1890 + hci_h4p_outb(info, UART_TI752_TLR, 0x1f);
1891 + hci_h4p_outb(info, UART_TI752_TCR, 0xef);
1892 + hci_h4p_outb(info, UART_FCR, UART_FCR_ENABLE_FIFO | UART_FCR_CLEAR_RCVR |
1893 + UART_FCR_CLEAR_XMIT | UART_FCR_R_TRIG_00);
1894 + hci_h4p_outb(info, UART_IER, UART_IER_RDI);
1895 +
1896 + return 0;
1897 +}
1898 --- linux-2.6.36-rc4.orig/drivers/bluetooth/Kconfig
1899 +++ linux-2.6.36-rc4/drivers/bluetooth/Kconfig
1900 @@ -173,6 +173,16 @@ config BT_HCIBTUART
1901 Say Y here to compile support for HCI UART devices into the
1902 kernel or say M to compile it as module (btuart_cs).
1903
1904 +config BT_HCIH4P
1905 + tristate "HCI driver with H4 Nokia extensions"
1906 + depends on BT && ARCH_OMAP
1907 + help
1908 + Bluetooth HCI driver with H4 extensions. This driver provides
1909 + support for H4+ Bluetooth chip with vendor-specific H4 extensions.
1910 +
1911 + Say Y here to compile support for h4 extended devices into the kernel
1912 + or say M to compile it as module (hci_h4p).
1913 +
1914 config BT_HCIVHCI
1915 tristate "HCI VHCI (Virtual HCI device) driver"
1916 help
1917 --- linux-2.6.36-rc4.orig/drivers/bluetooth/Makefile
1918 +++ linux-2.6.36-rc4/drivers/bluetooth/Makefile
1919 @@ -11,6 +11,7 @@ obj-$(CONFIG_BT_HCIDTL1) += dtl1_cs.o
1920 obj-$(CONFIG_BT_HCIBT3C) += bt3c_cs.o
1921 obj-$(CONFIG_BT_HCIBLUECARD) += bluecard_cs.o
1922 obj-$(CONFIG_BT_HCIBTUART) += btuart_cs.o
1923 +obj-$(CONFIG_BT_HCIH4P) += hci_h4p/
1924
1925 obj-$(CONFIG_BT_HCIBTUSB) += btusb.o
1926 obj-$(CONFIG_BT_HCIBTSDIO) += btsdio.o
This page took 0.1658 seconds and 5 git commands to generate.