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