Root/target/linux/omap24xx/patches-3.1/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--- /dev/null
15+++ b/drivers/bluetooth/hci_h4p/core.c
16@@ -0,0 +1,1043 @@
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 <plat/serial.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->dev_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+//FIXME
886+#if defined(CONFIG_ARCH_OMAP1)
887+# define OMAP_UART1_BASE OMAP1_UART1_BASE
888+# define OMAP_UART2_BASE OMAP1_UART2_BASE
889+# define OMAP_UART3_BASE OMAP1_UART3_BASE
890+#elif defined(CONFIG_ARCH_OMAP2)
891+# define OMAP_UART1_BASE OMAP2_UART1_BASE
892+# define OMAP_UART2_BASE OMAP2_UART2_BASE
893+# define OMAP_UART3_BASE OMAP2_UART3_BASE
894+#elif defined(CONFIG_ARCH_OMAP3)
895+# define OMAP_UART1_BASE OMAP3_UART1_BASE
896+# define OMAP_UART2_BASE OMAP3_UART2_BASE
897+# define OMAP_UART3_BASE OMAP3_UART3_BASE
898+#elif defined(CONFIG_ARCH_OMAP4)
899+# define OMAP_UART1_BASE OMAP4_UART1_BASE
900+# define OMAP_UART2_BASE OMAP4_UART2_BASE
901+# define OMAP_UART3_BASE OMAP4_UART3_BASE
902+#else
903+# error
904+#endif
905+ switch (bt_config->bt_uart) {
906+ case 1:
907+ if (cpu_is_omap16xx()) {
908+ irq = INT_UART1;
909+ info->uart_fclk = clk_get(NULL, "uart1_ck");
910+ } else if (cpu_is_omap24xx()) {
911+ irq = INT_24XX_UART1_IRQ;
912+ info->uart_iclk = clk_get(NULL, "uart1_ick");
913+ info->uart_fclk = clk_get(NULL, "uart1_fck");
914+ }
915+ /* FIXME: Use platform_get_resource for the port */
916+ info->uart_base = ioremap(OMAP_UART1_BASE, 0x16);
917+ if (!info->uart_base)
918+ goto cleanup;
919+ break;
920+ case 2:
921+ if (cpu_is_omap16xx()) {
922+ irq = INT_UART2;
923+ info->uart_fclk = clk_get(NULL, "uart2_ck");
924+ } else {
925+ irq = INT_24XX_UART2_IRQ;
926+ info->uart_iclk = clk_get(NULL, "uart2_ick");
927+ info->uart_fclk = clk_get(NULL, "uart2_fck");
928+ }
929+ /* FIXME: Use platform_get_resource for the port */
930+ info->uart_base = ioremap(OMAP_UART2_BASE, 0x16);
931+ if (!info->uart_base)
932+ goto cleanup;
933+ break;
934+ case 3:
935+ if (cpu_is_omap16xx()) {
936+ irq = INT_UART3;
937+ info->uart_fclk = clk_get(NULL, "uart3_ck");
938+ } else {
939+ irq = INT_24XX_UART3_IRQ;
940+ info->uart_iclk = clk_get(NULL, "uart3_ick");
941+ info->uart_fclk = clk_get(NULL, "uart3_fck");
942+ }
943+ /* FIXME: Use platform_get_resource for the port */
944+ info->uart_base = ioremap(OMAP_UART3_BASE, 0x16);
945+ if (!info->uart_base)
946+ goto cleanup;
947+ break;
948+ default:
949+ dev_err(info->dev, "No uart defined\n");
950+ goto cleanup;
951+ }
952+
953+ info->irq = irq;
954+ err = request_irq(irq, hci_h4p_interrupt, 0, "hci_h4p", (void *)info);
955+ if (err < 0) {
956+ dev_err(info->dev, "hci_h4p: unable to get IRQ %d\n", irq);
957+ goto cleanup;
958+ }
959+
960+ err = request_irq(gpio_to_irq(info->host_wakeup_gpio),
961+ hci_h4p_wakeup_interrupt,
962+ IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING,
963+ "hci_h4p_wkup", (void *)info);
964+ if (err < 0) {
965+ dev_err(info->dev, "hci_h4p: unable to get wakeup IRQ %d\n",
966+ gpio_to_irq(info->host_wakeup_gpio));
967+ free_irq(irq, (void *)info);
968+ goto cleanup;
969+ }
970+
971+ hci_h4p_set_clk(info, &info->tx_clocks_en, 1);
972+ hci_h4p_set_auto_ctsrts(info, 0, UART_EFR_CTS | UART_EFR_RTS);
973+ err = hci_h4p_init_uart(info);
974+ if (err < 0)
975+ goto cleanup_irq;
976+ err = hci_h4p_reset(info);
977+ if (err < 0)
978+ goto cleanup_irq;
979+ err = hci_h4p_wait_for_cts(info, 1, 10);
980+ if (err < 0)
981+ goto cleanup_irq;
982+ hci_h4p_set_clk(info, &info->tx_clocks_en, 0);
983+
984+ platform_set_drvdata(pdev, info);
985+ err = hci_h4p_sysfs_create_files(info->dev);
986+ if (err < 0)
987+ goto cleanup_irq;
988+
989+ if (hci_h4p_register_hdev(info) < 0) {
990+ dev_err(info->dev, "failed to register hci_h4p hci device\n");
991+ goto cleanup_irq;
992+ }
993+ gpio_set_value(info->reset_gpio, 0);
994+
995+ return 0;
996+
997+cleanup_irq:
998+ free_irq(irq, (void *)info);
999+ free_irq(gpio_to_irq(info->host_wakeup_gpio), (void *)info);
1000+cleanup:
1001+ gpio_set_value(info->reset_gpio, 0);
1002+ gpio_free(info->reset_gpio);
1003+ gpio_free(info->bt_wakeup_gpio);
1004+ gpio_free(info->host_wakeup_gpio);
1005+ kfree(info);
1006+
1007+ return err;
1008+
1009+}
1010+
1011+static int hci_h4p_remove(struct platform_device *dev)
1012+{
1013+ struct hci_h4p_info *info;
1014+
1015+ info = platform_get_drvdata(dev);
1016+
1017+ hci_h4p_hci_close(info->hdev);
1018+ free_irq(gpio_to_irq(info->host_wakeup_gpio), (void *) info);
1019+ hci_free_dev(info->hdev);
1020+ gpio_free(info->reset_gpio);
1021+ gpio_free(info->bt_wakeup_gpio);
1022+ gpio_free(info->host_wakeup_gpio);
1023+ free_irq(info->irq, (void *) info);
1024+ kfree(info);
1025+
1026+ return 0;
1027+}
1028+
1029+static struct platform_driver hci_h4p_driver = {
1030+ .probe = hci_h4p_probe,
1031+ .remove = hci_h4p_remove,
1032+ .driver = {
1033+ .name = "hci_h4p",
1034+ },
1035+};
1036+
1037+static int __init hci_h4p_init(void)
1038+{
1039+ int err = 0;
1040+
1041+ /* Register the driver with LDM */
1042+ err = platform_driver_register(&hci_h4p_driver);
1043+ if (err < 0)
1044+ printk(KERN_WARNING "failed to register hci_h4p driver\n");
1045+
1046+ return err;
1047+}
1048+
1049+static void __exit hci_h4p_exit(void)
1050+{
1051+ platform_driver_unregister(&hci_h4p_driver);
1052+}
1053+
1054+module_init(hci_h4p_init);
1055+module_exit(hci_h4p_exit);
1056+
1057+MODULE_DESCRIPTION("h4 driver with nokia extensions");
1058+MODULE_LICENSE("GPL");
1059+MODULE_AUTHOR("Ville Tervo");
1060--- /dev/null
1061+++ b/drivers/bluetooth/hci_h4p/fw.c
1062@@ -0,0 +1,155 @@
1063+/*
1064+ * This file is part of hci_h4p bluetooth driver
1065+ *
1066+ * Copyright (C) 2005, 2006 Nokia Corporation.
1067+ *
1068+ * Contact: Ville Tervo <ville.tervo@nokia.com>
1069+ *
1070+ * This program is free software; you can redistribute it and/or
1071+ * modify it under the terms of the GNU General Public License
1072+ * version 2 as published by the Free Software Foundation.
1073+ *
1074+ * This program is distributed in the hope that it will be useful, but
1075+ * WITHOUT ANY WARRANTY; without even the implied warranty of
1076+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1077+ * General Public License for more details.
1078+ *
1079+ * You should have received a copy of the GNU General Public License
1080+ * along with this program; if not, write to the Free Software
1081+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
1082+ * 02110-1301 USA
1083+ *
1084+ */
1085+
1086+#include <linux/skbuff.h>
1087+#include <linux/firmware.h>
1088+#include <linux/clk.h>
1089+
1090+#include <net/bluetooth/bluetooth.h>
1091+
1092+#include "hci_h4p.h"
1093+
1094+#define BT_CHIP_TI 2
1095+#define BT_CHIP_CSR 1
1096+
1097+static int fw_pos;
1098+
1099+/* Firmware handling */
1100+static int hci_h4p_open_firmware(struct hci_h4p_info *info,
1101+ const struct firmware **fw_entry)
1102+{
1103+ int err;
1104+
1105+ fw_pos = 0;
1106+ NBT_DBG_FW("Opening %d firmware\n", info->chip_type);
1107+ switch (info->chip_type) {
1108+ case BT_CHIP_TI:
1109+ err = request_firmware(fw_entry, "brf6150fw.bin", info->dev);
1110+ break;
1111+ case BT_CHIP_CSR:
1112+ err = request_firmware(fw_entry, "bc4fw.bin", info->dev);
1113+ break;
1114+ default:
1115+ dev_err(info->dev, "Invalid chip type\n");
1116+ *fw_entry = NULL;
1117+ err = -EINVAL;
1118+ }
1119+
1120+ return err;
1121+}
1122+
1123+static void hci_h4p_close_firmware(const struct firmware *fw_entry)
1124+{
1125+ release_firmware(fw_entry);
1126+}
1127+
1128+/* Read fw. Return length of the command. If no more commands in
1129+ * fw 0 is returned. In error case return value is negative.
1130+ */
1131+static int hci_h4p_read_fw_cmd(struct hci_h4p_info *info, struct sk_buff **skb,
1132+ const struct firmware *fw_entry, int how)
1133+{
1134+ unsigned int cmd_len;
1135+
1136+ if (fw_pos >= fw_entry->size) {
1137+ return 0;
1138+ }
1139+
1140+ cmd_len = fw_entry->data[fw_pos++];
1141+ if (!cmd_len)
1142+ return 0;
1143+
1144+ if (fw_pos + cmd_len > fw_entry->size) {
1145+ dev_err(info->dev, "Corrupted firmware image\n");
1146+ return -EMSGSIZE;
1147+ }
1148+
1149+ *skb = bt_skb_alloc(cmd_len, how);
1150+ if (!*skb) {
1151+ dev_err(info->dev, "Cannot reserve memory for buffer\n");
1152+ return -ENOMEM;
1153+ }
1154+ memcpy(skb_put(*skb, cmd_len), &fw_entry->data[fw_pos], cmd_len);
1155+
1156+ fw_pos += cmd_len;
1157+
1158+ return (*skb)->len;
1159+}
1160+
1161+int hci_h4p_read_fw(struct hci_h4p_info *info, struct sk_buff_head *fw_queue)
1162+{
1163+ const struct firmware *fw_entry = NULL;
1164+ struct sk_buff *skb = NULL;
1165+ int err;
1166+
1167+ err = hci_h4p_open_firmware(info, &fw_entry);
1168+ if (err < 0 || !fw_entry)
1169+ goto err_clean;
1170+
1171+ while ((err = hci_h4p_read_fw_cmd(info, &skb, fw_entry, GFP_KERNEL))) {
1172+ if (err < 0 || !skb)
1173+ goto err_clean;
1174+
1175+ skb_queue_tail(fw_queue, skb);
1176+ }
1177+
1178+err_clean:
1179+ hci_h4p_close_firmware(fw_entry);
1180+ return err;
1181+}
1182+
1183+int hci_h4p_send_fw(struct hci_h4p_info *info, struct sk_buff_head *fw_queue)
1184+{
1185+ int err;
1186+
1187+ switch(info->chip_type) {
1188+ case BT_CHIP_CSR:
1189+ err = hci_h4p_bc4_send_fw(info, fw_queue);
1190+ break;
1191+ case BT_CHIP_TI:
1192+ err = hci_h4p_brf6150_send_fw(info, fw_queue);
1193+ break;
1194+ default:
1195+ dev_err(info->dev, "Don't know how to send firmware\n");
1196+ err = -EINVAL;
1197+ }
1198+
1199+ return err;
1200+}
1201+
1202+void hci_h4p_parse_fw_event(struct hci_h4p_info *info, struct sk_buff *skb)
1203+{
1204+ switch (info->chip_type) {
1205+ case BT_CHIP_CSR:
1206+ hci_h4p_bc4_parse_fw_event(info, skb);
1207+ break;
1208+ case BT_CHIP_TI:
1209+ hci_h4p_brf6150_parse_fw_event(info, skb);
1210+ break;
1211+ default:
1212+ dev_err(info->dev, "Don't know how to parse fw event\n");
1213+ info->fw_error = -EINVAL;
1214+ }
1215+
1216+ return;
1217+}
1218--- /dev/null
1219+++ b/drivers/bluetooth/hci_h4p/fw-csr.c
1220@@ -0,0 +1,149 @@
1221+/*
1222+ * This file is part of hci_h4p bluetooth driver
1223+ *
1224+ * Copyright (C) 2005, 2006 Nokia Corporation.
1225+ *
1226+ * Contact: Ville Tervo <ville.tervo@nokia.com>
1227+ *
1228+ * This program is free software; you can redistribute it and/or
1229+ * modify it under the terms of the GNU General Public License
1230+ * version 2 as published by the Free Software Foundation.
1231+ *
1232+ * This program is distributed in the hope that it will be useful, but
1233+ * WITHOUT ANY WARRANTY; without even the implied warranty of
1234+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1235+ * General Public License for more details.
1236+ *
1237+ * You should have received a copy of the GNU General Public License
1238+ * along with this program; if not, write to the Free Software
1239+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
1240+ * 02110-1301 USA
1241+ *
1242+ */
1243+
1244+#include <linux/skbuff.h>
1245+#include <linux/delay.h>
1246+#include <linux/serial_reg.h>
1247+
1248+#include "hci_h4p.h"
1249+
1250+void hci_h4p_bc4_parse_fw_event(struct hci_h4p_info *info, struct sk_buff *skb)
1251+{
1252+ /* Check if this is fw packet */
1253+ if (skb->data[0] != 0xff) {
1254+ hci_recv_frame(skb);
1255+ return;
1256+ }
1257+
1258+ if (skb->data[11] || skb->data[12]) {
1259+ dev_err(info->dev, "Firmware sending command failed\n");
1260+ info->fw_error = -EPROTO;
1261+ }
1262+
1263+ kfree_skb(skb);
1264+ complete(&info->fw_completion);
1265+}
1266+
1267+int hci_h4p_bc4_send_fw(struct hci_h4p_info *info,
1268+ struct sk_buff_head *fw_queue)
1269+{
1270+ struct sk_buff *skb;
1271+ unsigned int offset;
1272+ int retries, count, i;
1273+
1274+ info->fw_error = 0;
1275+
1276+ NBT_DBG_FW("Sending firmware\n");
1277+ skb = skb_dequeue(fw_queue);
1278+
1279+ if (!skb)
1280+ return -ENOMSG;
1281+
1282+ info->bdaddr[0] = 0x00;
1283+ info->bdaddr[1] = 0x1D;
1284+ info->bdaddr[2] = 0x6E;
1285+ info->bdaddr[3] = 0xD4;
1286+ info->bdaddr[4] = 0xF0;
1287+ info->bdaddr[5] = 0x37;
1288+
1289+ /* Check if this is bd_address packet */
1290+ if (skb->data[15] == 0x01 && skb->data[16] == 0x00) {
1291+ dev_info(info->dev, "bd_address packet found\n");
1292+ offset = 21;
1293+ skb->data[offset + 1] = 0x00;
1294+ skb->data[offset + 5] = 0x00;
1295+ skb->data[offset + 7] = info->bdaddr[0];
1296+ skb->data[offset + 6] = info->bdaddr[1];
1297+ skb->data[offset + 4] = info->bdaddr[2];
1298+ skb->data[offset + 0] = info->bdaddr[3];
1299+ skb->data[offset + 3] = info->bdaddr[4];
1300+ skb->data[offset + 2] = info->bdaddr[5];
1301+ }
1302+
1303+ for (i = 0; i < 6; i++) {
1304+ if (info->bdaddr[i] != 0x00)
1305+ break;
1306+ }
1307+
1308+ /* if (i > 5) {
1309+ dev_info(info->dev, "Valid bluetooth address not found.\n");
1310+ kfree_skb(skb);
1311+ return -ENODEV;
1312+ } */
1313+
1314+ for (count = 1; ; count++) {
1315+ NBT_DBG_FW("Sending firmware command %d\n", count);
1316+ init_completion(&info->fw_completion);
1317+ skb_queue_tail(&info->txq, skb);
1318+ tasklet_schedule(&info->tx_task);
1319+
1320+ skb = skb_dequeue(fw_queue);
1321+ if (!skb)
1322+ break;
1323+
1324+ if (!wait_for_completion_timeout(&info->fw_completion,
1325+ msecs_to_jiffies(1000))) {
1326+ dev_err(info->dev, "No reply to fw command\n");
1327+ return -ETIMEDOUT;
1328+ }
1329+
1330+ if (info->fw_error) {
1331+ dev_err(info->dev, "FW error\n");
1332+ return -EPROTO;
1333+ }
1334+ };
1335+
1336+ /* Wait for chip warm reset */
1337+ retries = 100;
1338+ while ((!skb_queue_empty(&info->txq) ||
1339+ !(hci_h4p_inb(info, UART_LSR) & UART_LSR_TEMT)) &&
1340+ retries--) {
1341+ msleep(10);
1342+ }
1343+ if (!retries) {
1344+ dev_err(info->dev, "Transmitter not empty\n");
1345+ return -ETIMEDOUT;
1346+ }
1347+
1348+ hci_h4p_change_speed(info, BC4_MAX_BAUD_RATE);
1349+
1350+ if (hci_h4p_wait_for_cts(info, 1, 100)) {
1351+ dev_err(info->dev, "cts didn't go down after final speed change\n");
1352+ return -ETIMEDOUT;
1353+ }
1354+
1355+ retries = 100;
1356+ do {
1357+ init_completion(&info->init_completion);
1358+ hci_h4p_send_alive_packet(info);
1359+ retries--;
1360+ } while (!wait_for_completion_timeout(&info->init_completion, 100) &&
1361+ retries > 0);
1362+
1363+ if (!retries) {
1364+ dev_err(info->dev, "No alive reply after speed change\n");
1365+ return -ETIMEDOUT;
1366+ }
1367+
1368+ return 0;
1369+}
1370--- /dev/null
1371+++ b/drivers/bluetooth/hci_h4p/fw-ti.c
1372@@ -0,0 +1,90 @@
1373+/*
1374+ * This file is part of hci_h4p bluetooth driver
1375+ *
1376+ * Copyright (C) 2005, 2006 Nokia Corporation.
1377+ *
1378+ * Contact: Ville Tervo <ville.tervo@nokia.com>
1379+ *
1380+ * This program is free software; you can redistribute it and/or
1381+ * modify it under the terms of the GNU General Public License
1382+ * version 2 as published by the Free Software Foundation.
1383+ *
1384+ * This program is distributed in the hope that it will be useful, but
1385+ * WITHOUT ANY WARRANTY; without even the implied warranty of
1386+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1387+ * General Public License for more details.
1388+ *
1389+ * You should have received a copy of the GNU General Public License
1390+ * along with this program; if not, write to the Free Software
1391+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
1392+ * 02110-1301 USA
1393+ *
1394+ */
1395+
1396+#include <linux/skbuff.h>
1397+
1398+#include "hci_h4p.h"
1399+
1400+void hci_h4p_brf6150_parse_fw_event(struct hci_h4p_info *info,
1401+ struct sk_buff *skb)
1402+{
1403+ struct hci_fw_event *ev;
1404+ int err = 0;
1405+
1406+ if (bt_cb(skb)->pkt_type != H4_EVT_PKT) {
1407+ dev_err(info->dev, "Got non event fw packet.\n");
1408+ err = -EPROTO;
1409+ goto ret;
1410+ }
1411+
1412+ ev = (struct hci_fw_event *)skb->data;
1413+ if (ev->hev.evt != HCI_EV_CMD_COMPLETE) {
1414+ dev_err(info->dev, "Got non cmd complete fw event\n");
1415+ err = -EPROTO;
1416+ goto ret;
1417+ }
1418+
1419+ if (ev->status != 0) {
1420+ dev_err(info->dev, "Got error status from fw command\n");
1421+ err = -EPROTO;
1422+ goto ret;
1423+ }
1424+
1425+ret:
1426+ info->fw_error = err;
1427+ complete(&info->fw_completion);
1428+}
1429+
1430+int hci_h4p_brf6150_send_fw(struct hci_h4p_info *info, struct sk_buff_head *fw_queue)
1431+{
1432+ struct sk_buff *skb;
1433+ int err = 0;
1434+
1435+ info->fw_error = 0;
1436+
1437+ while ((skb = skb_dequeue(fw_queue)) != NULL) {
1438+ /* We should allways send word aligned data to h4+ devices */
1439+ if (skb->len % 2) {
1440+ err = skb_pad(skb, 1);
1441+ }
1442+ if (err)
1443+ return err;
1444+
1445+ init_completion(&info->fw_completion);
1446+ skb_queue_tail(&info->txq, skb);
1447+ tasklet_schedule(&info->tx_task);
1448+
1449+ if (!wait_for_completion_timeout(&info->fw_completion, HZ)) {
1450+ dev_err(info->dev, "Timeout while sending brf6150 fw\n");
1451+ return -ETIMEDOUT;
1452+ }
1453+
1454+ if (info->fw_error) {
1455+ dev_err(info->dev, "There was fw_error while sending bfr6150 fw\n");
1456+ return -EPROTO;
1457+ }
1458+ }
1459+ NBT_DBG_FW("Firmware sent\n");
1460+
1461+ return 0;
1462+}
1463--- /dev/null
1464+++ b/drivers/bluetooth/hci_h4p/hci_h4p.h
1465@@ -0,0 +1,183 @@
1466+/*
1467+ * This file is part of hci_h4p bluetooth driver
1468+ *
1469+ * Copyright (C) 2005, 2006 Nokia Corporation.
1470+ *
1471+ * Contact: Ville Tervo <ville.tervo@nokia.com>
1472+ *
1473+ * This program is free software; you can redistribute it and/or
1474+ * modify it under the terms of the GNU General Public License
1475+ * version 2 as published by the Free Software Foundation.
1476+ *
1477+ * This program is distributed in the hope that it will be useful, but
1478+ * WITHOUT ANY WARRANTY; without even the implied warranty of
1479+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1480+ * General Public License for more details.
1481+ *
1482+ * You should have received a copy of the GNU General Public License
1483+ * along with this program; if not, write to the Free Software
1484+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
1485+ * 02110-1301 USA
1486+ *
1487+ */
1488+
1489+#include <mach/board.h>
1490+
1491+#include <net/bluetooth/bluetooth.h>
1492+#include <net/bluetooth/hci_core.h>
1493+#include <net/bluetooth/hci.h>
1494+
1495+#ifndef __DRIVERS_BLUETOOTH_HCI_H4P_H
1496+#define __DRIVERS_BLUETOOTH_HCI_H4P_H
1497+
1498+#define UART_SYSC_OMAP_RESET 0x03
1499+#define UART_SYSS_RESETDONE 0x01
1500+#define UART_OMAP_SCR_EMPTY_THR 0x08
1501+#define UART_OMAP_SCR_WAKEUP 0x10
1502+#define UART_OMAP_SSR_WAKEUP 0x02
1503+#define UART_OMAP_SSR_TXFULL 0x01
1504+
1505+#if 0
1506+#define NBT_DBG(fmt, arg...) printk("%s: " fmt "" , __FUNCTION__ , ## arg)
1507+#else
1508+#define NBT_DBG(...)
1509+#endif
1510+
1511+#if 0
1512+#define NBT_DBG_FW(fmt, arg...) printk("%s: " fmt "" , __FUNCTION__ , ## arg)
1513+#else
1514+#define NBT_DBG_FW(...)
1515+#endif
1516+
1517+#if 0
1518+#define NBT_DBG_POWER(fmt, arg...) printk("%s: " fmt "" , __FUNCTION__ , ## arg)
1519+#else
1520+#define NBT_DBG_POWER(...)
1521+#endif
1522+
1523+#if 0
1524+#define NBT_DBG_TRANSFER(fmt, arg...) printk("%s: " fmt "" , __FUNCTION__ , ## arg)
1525+#else
1526+#define NBT_DBG_TRANSFER(...)
1527+#endif
1528+
1529+#if 0
1530+#define NBT_DBG_TRANSFER_NF(fmt, arg...) printk(fmt "" , ## arg)
1531+#else
1532+#define NBT_DBG_TRANSFER_NF(...)
1533+#endif
1534+
1535+#if 0
1536+#define NBT_DBG_DMA(fmt, arg...) printk("%s: " fmt "" , __FUNCTION__ , ## arg)
1537+#else
1538+#define NBT_DBG_DMA(...)
1539+#endif
1540+
1541+struct hci_h4p_info {
1542+ struct hci_dev *hdev;
1543+ spinlock_t lock;
1544+
1545+ void __iomem *uart_base;
1546+ unsigned long uart_phys_base;
1547+ int irq;
1548+ struct device *dev;
1549+ u8 bdaddr[6];
1550+ u8 chip_type;
1551+ u8 bt_wakeup_gpio;
1552+ u8 host_wakeup_gpio;
1553+ u8 reset_gpio;
1554+ u8 bt_sysclk;
1555+
1556+
1557+ struct sk_buff_head fw_queue;
1558+ struct sk_buff *alive_cmd_skb;
1559+ struct completion init_completion;
1560+ struct completion fw_completion;
1561+ int fw_error;
1562+ int init_error;
1563+
1564+ struct sk_buff_head txq;
1565+ struct tasklet_struct tx_task;
1566+
1567+ struct sk_buff *rx_skb;
1568+ long rx_count;
1569+ unsigned long rx_state;
1570+ unsigned long garbage_bytes;
1571+ struct tasklet_struct rx_task;
1572+
1573+ int pm_enabled;
1574+ int tx_pm_enabled;
1575+ int rx_pm_enabled;
1576+ struct timer_list tx_pm_timer;
1577+ struct timer_list rx_pm_timer;
1578+
1579+ int tx_clocks_en;
1580+ int rx_clocks_en;
1581+ spinlock_t clocks_lock;
1582+ struct clk *uart_iclk;
1583+ struct clk *uart_fclk;
1584+};
1585+
1586+#define MAX_BAUD_RATE 921600
1587+#define BC4_MAX_BAUD_RATE 3692300
1588+#define UART_CLOCK 48000000
1589+#define BT_INIT_DIVIDER 320
1590+#define BT_BAUDRATE_DIVIDER 384000000
1591+#define BT_SYSCLK_DIV 1000
1592+#define INIT_SPEED 120000
1593+
1594+#define H4_TYPE_SIZE 1
1595+
1596+/* H4+ packet types */
1597+#define H4_CMD_PKT 0x01
1598+#define H4_ACL_PKT 0x02
1599+#define H4_SCO_PKT 0x03
1600+#define H4_EVT_PKT 0x04
1601+#define H4_NEG_PKT 0x06
1602+#define H4_ALIVE_PKT 0x07
1603+
1604+/* TX states */
1605+#define WAIT_FOR_PKT_TYPE 1
1606+#define WAIT_FOR_HEADER 2
1607+#define WAIT_FOR_DATA 3
1608+
1609+struct hci_fw_event {
1610+ struct hci_event_hdr hev;
1611+ struct hci_ev_cmd_complete cmd;
1612+ u8 status;
1613+} __attribute__ ((packed));
1614+
1615+struct hci_bc4_set_bdaddr {
1616+ u8 type;
1617+ struct hci_command_hdr cmd_hdr;
1618+} __attribute__ ((packed));
1619+
1620+int hci_h4p_send_alive_packet(struct hci_h4p_info *info);
1621+
1622+void hci_h4p_bc4_parse_fw_event(struct hci_h4p_info *info,
1623+ struct sk_buff *skb);
1624+int hci_h4p_bc4_send_fw(struct hci_h4p_info *info,
1625+ struct sk_buff_head *fw_queue);
1626+
1627+void hci_h4p_brf6150_parse_fw_event(struct hci_h4p_info *info,
1628+ struct sk_buff *skb);
1629+int hci_h4p_brf6150_send_fw(struct hci_h4p_info *info,
1630+ struct sk_buff_head *fw_queue);
1631+
1632+int hci_h4p_read_fw(struct hci_h4p_info *info, struct sk_buff_head *fw_queue);
1633+int hci_h4p_send_fw(struct hci_h4p_info *info, struct sk_buff_head *fw_queue);
1634+void hci_h4p_parse_fw_event(struct hci_h4p_info *info, struct sk_buff *skb);
1635+
1636+int hci_h4p_sysfs_create_files(struct device *dev);
1637+
1638+void hci_h4p_outb(struct hci_h4p_info *info, unsigned int offset, u8 val);
1639+u8 hci_h4p_inb(struct hci_h4p_info *info, unsigned int offset);
1640+void hci_h4p_set_rts(struct hci_h4p_info *info, int active);
1641+int hci_h4p_wait_for_cts(struct hci_h4p_info *info, int active, int timeout_ms);
1642+void __hci_h4p_set_auto_ctsrts(struct hci_h4p_info *info, int on, u8 which);
1643+void hci_h4p_set_auto_ctsrts(struct hci_h4p_info *info, int on, u8 which);
1644+void hci_h4p_change_speed(struct hci_h4p_info *info, unsigned long speed);
1645+int hci_h4p_reset_uart(struct hci_h4p_info *info);
1646+int hci_h4p_init_uart(struct hci_h4p_info *info);
1647+
1648+#endif /* __DRIVERS_BLUETOOTH_HCI_H4P_H */
1649--- /dev/null
1650+++ b/drivers/bluetooth/hci_h4p/Makefile
1651@@ -0,0 +1,7 @@
1652+#
1653+# Makefile for the Linux Bluetooth HCI device drivers.
1654+#
1655+
1656+obj-$(CONFIG_BT_HCIH4P) += hci_h4p.o
1657+
1658+hci_h4p-objs := core.o fw.o uart.o sysfs.o fw-ti.o fw-csr.o
1659--- /dev/null
1660+++ b/drivers/bluetooth/hci_h4p/sysfs.c
1661@@ -0,0 +1,84 @@
1662+/*
1663+ * This file is part of hci_h4p bluetooth driver
1664+ *
1665+ * Copyright (C) 2005, 2006 Nokia Corporation.
1666+ *
1667+ * Contact: Ville Tervo <ville.tervo@nokia.com>
1668+ *
1669+ * This program is free software; you can redistribute it and/or
1670+ * modify it under the terms of the GNU General Public License
1671+ * version 2 as published by the Free Software Foundation.
1672+ *
1673+ * This program is distributed in the hope that it will be useful, but
1674+ * WITHOUT ANY WARRANTY; without even the implied warranty of
1675+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1676+ * General Public License for more details.
1677+ *
1678+ * You should have received a copy of the GNU General Public License
1679+ * along with this program; if not, write to the Free Software
1680+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
1681+ * 02110-1301 USA
1682+ *
1683+ */
1684+
1685+#include <linux/kernel.h>
1686+#include <linux/init.h>
1687+#include <linux/device.h>
1688+#include <linux/platform_device.h>
1689+
1690+#include "hci_h4p.h"
1691+
1692+#ifdef CONFIG_SYSFS
1693+
1694+static ssize_t hci_h4p_store_bdaddr(struct device *dev, struct device_attribute *attr,
1695+ const char *buf, size_t count)
1696+{
1697+ struct hci_h4p_info *info = (struct hci_h4p_info*)dev_get_drvdata(dev);
1698+ unsigned int bdaddr[6];
1699+ int ret, i;
1700+
1701+ dev_info(info->dev, "HCI_H4P_STORE_BDADDR called\n");
1702+
1703+ ret = sscanf(buf, "%2x:%2x:%2x:%2x:%2x:%2x\n",
1704+ &bdaddr[0], &bdaddr[1], &bdaddr[2],
1705+ &bdaddr[3], &bdaddr[4], &bdaddr[5]);
1706+
1707+ if (ret != 6) {
1708+ dev_info(info->dev, "bdaddr isn't found\n");
1709+ return -EINVAL;
1710+ }
1711+
1712+ //for (i = 0; i < 6; i++)
1713+ //info->bdaddr[i] = bdaddr[i] & 0xff;
1714+
1715+ info->bdaddr[0] = 0x00;
1716+ info->bdaddr[1] = 0x1D;
1717+ info->bdaddr[2] = 0x6E;
1718+ info->bdaddr[3] = 0xD4;
1719+ info->bdaddr[4] = 0xF0;
1720+ info->bdaddr[5] = 0x37;
1721+
1722+ return count;
1723+}
1724+
1725+static ssize_t hci_h4p_show_bdaddr(struct device *dev, struct device_attribute *attr,
1726+ char *buf)
1727+{
1728+ struct hci_h4p_info *info = (struct hci_h4p_info*)dev_get_drvdata(dev);
1729+
1730+ return sprintf(buf, "%.2x:%.2x:%.2x:%.2x:%.2x:%.2x\n",
1731+ info->bdaddr[0],
1732+ info->bdaddr[1],
1733+ info->bdaddr[2],
1734+ info->bdaddr[3],
1735+ info->bdaddr[4],
1736+ info->bdaddr[5]);
1737+}
1738+
1739+static DEVICE_ATTR(bdaddr, S_IRUGO | S_IWUSR, hci_h4p_show_bdaddr, hci_h4p_store_bdaddr);
1740+int hci_h4p_sysfs_create_files(struct device *dev)
1741+{
1742+ return device_create_file(dev, &dev_attr_bdaddr);
1743+}
1744+
1745+#endif
1746--- /dev/null
1747+++ b/drivers/bluetooth/hci_h4p/uart.c
1748@@ -0,0 +1,169 @@
1749+/*
1750+ * This file is part of hci_h4p bluetooth driver
1751+ *
1752+ * Copyright (C) 2005, 2006 Nokia Corporation.
1753+ *
1754+ * Contact: Ville Tervo <ville.tervo@nokia.com>
1755+ *
1756+ * This program is free software; you can redistribute it and/or
1757+ * modify it under the terms of the GNU General Public License
1758+ * version 2 as published by the Free Software Foundation.
1759+ *
1760+ * This program is distributed in the hope that it will be useful, but
1761+ * WITHOUT ANY WARRANTY; without even the implied warranty of
1762+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1763+ * General Public License for more details.
1764+ *
1765+ * You should have received a copy of the GNU General Public License
1766+ * along with this program; if not, write to the Free Software
1767+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
1768+ * 02110-1301 USA
1769+ *
1770+ */
1771+
1772+#include <linux/serial_reg.h>
1773+#include <linux/delay.h>
1774+#include <linux/clk.h>
1775+
1776+#include <asm/io.h>
1777+
1778+#include "hci_h4p.h"
1779+
1780+inline void hci_h4p_outb(struct hci_h4p_info *info, unsigned int offset, u8 val)
1781+{
1782+ offset <<= 2;
1783+ __raw_writeb(val, info->uart_base + offset);
1784+ //outb(val, info->uart_base + (offset << 2));
1785+}
1786+
1787+inline u8 hci_h4p_inb(struct hci_h4p_info *info, unsigned int offset)
1788+{
1789+ offset <<= 2;
1790+ return (u8)__raw_readb(info->uart_base + offset);
1791+ //return (unsigned int)__raw_readb(up->membase + offset);
1792+ //return inb(info->uart_base + (offset << 2));
1793+}
1794+
1795+void hci_h4p_set_rts(struct hci_h4p_info *info, int active)
1796+{
1797+ u8 b;
1798+
1799+ b = hci_h4p_inb(info, UART_MCR);
1800+ if (active)
1801+ b |= UART_MCR_RTS;
1802+ else
1803+ b &= ~UART_MCR_RTS;
1804+ hci_h4p_outb(info, UART_MCR, b);
1805+}
1806+
1807+int hci_h4p_wait_for_cts(struct hci_h4p_info *info, int active,
1808+ int timeout_ms)
1809+{
1810+ int okay;
1811+ unsigned long timeout;
1812+
1813+ okay = 0;
1814+ timeout = jiffies + msecs_to_jiffies(timeout_ms);
1815+ for (;;) {
1816+ int state;
1817+
1818+ state = hci_h4p_inb(info, UART_MSR) & UART_MSR_CTS;
1819+ if (active) {
1820+ if (state)
1821+ return 0;
1822+ } else {
1823+ if (!state)
1824+ return 0;
1825+ }
1826+ if (time_after(jiffies, timeout))
1827+ return -ETIMEDOUT;
1828+ }
1829+}
1830+
1831+void __hci_h4p_set_auto_ctsrts(struct hci_h4p_info *info, int on, u8 which)
1832+{
1833+ u8 lcr, b;
1834+
1835+ lcr = hci_h4p_inb(info, UART_LCR);
1836+ hci_h4p_outb(info, UART_LCR, 0xbf);
1837+ b = hci_h4p_inb(info, UART_EFR);
1838+ if (on)
1839+ b |= which;
1840+ else
1841+ b &= ~which;
1842+ hci_h4p_outb(info, UART_EFR, b);
1843+ hci_h4p_outb(info, UART_LCR, lcr);
1844+}
1845+
1846+void hci_h4p_set_auto_ctsrts(struct hci_h4p_info *info, int on, u8 which)
1847+{
1848+ unsigned long flags;
1849+
1850+ spin_lock_irqsave(&info->lock, flags);
1851+ __hci_h4p_set_auto_ctsrts(info, on, which);
1852+ spin_unlock_irqrestore(&info->lock, flags);
1853+}
1854+
1855+void hci_h4p_change_speed(struct hci_h4p_info *info, unsigned long speed)
1856+{
1857+ unsigned int divisor;
1858+ u8 lcr, mdr1;
1859+
1860+ NBT_DBG("Setting speed %lu\n", speed);
1861+
1862+ if (speed >= 460800) {
1863+ divisor = UART_CLOCK / 13 / speed;
1864+ mdr1 = 3;
1865+ } else {
1866+ divisor = UART_CLOCK / 16 / speed;
1867+ mdr1 = 0;
1868+ }
1869+
1870+ hci_h4p_outb(info, UART_OMAP_MDR1, 7); /* Make sure UART mode is disabled */
1871+ lcr = hci_h4p_inb(info, UART_LCR);
1872+ hci_h4p_outb(info, UART_LCR, UART_LCR_DLAB); /* Set DLAB */
1873+ hci_h4p_outb(info, UART_DLL, divisor & 0xff); /* Set speed */
1874+ hci_h4p_outb(info, UART_DLM, divisor >> 8);
1875+ hci_h4p_outb(info, UART_LCR, lcr);
1876+ hci_h4p_outb(info, UART_OMAP_MDR1, mdr1); /* Make sure UART mode is enabled */
1877+}
1878+
1879+int hci_h4p_reset_uart(struct hci_h4p_info *info)
1880+{
1881+ int count = 0;
1882+
1883+ /* Reset the UART */
1884+ hci_h4p_outb(info, UART_OMAP_SYSC, UART_SYSC_OMAP_RESET);
1885+ while (!(hci_h4p_inb(info, UART_OMAP_SYSS) & UART_SYSS_RESETDONE)) {
1886+ if (count++ > 20000) {
1887+ dev_err(info->dev, "hci_h4p: UART reset timeout\n");
1888+ return -ENODEV;
1889+ }
1890+ udelay(1);
1891+ }
1892+
1893+ return 0;
1894+}
1895+
1896+int hci_h4p_init_uart(struct hci_h4p_info *info)
1897+{
1898+ int err;
1899+
1900+ err = hci_h4p_reset_uart(info);
1901+ if (err < 0)
1902+ return err;
1903+
1904+ /* Enable and setup FIFO */
1905+ hci_h4p_outb(info, UART_LCR, UART_LCR_WLEN8);
1906+ hci_h4p_outb(info, UART_OMAP_MDR1, 0x00); /* Make sure UART mode is enabled */
1907+ hci_h4p_outb(info, UART_OMAP_SCR, 0x80);
1908+ hci_h4p_outb(info, UART_EFR, UART_EFR_ECB);
1909+ hci_h4p_outb(info, UART_MCR, UART_MCR_TCRTLR);
1910+ hci_h4p_outb(info, UART_TI752_TLR, 0x1f);
1911+ hci_h4p_outb(info, UART_TI752_TCR, 0xef);
1912+ hci_h4p_outb(info, UART_FCR, UART_FCR_ENABLE_FIFO | UART_FCR_CLEAR_RCVR |
1913+ UART_FCR_CLEAR_XMIT | UART_FCR_R_TRIG_00);
1914+ hci_h4p_outb(info, UART_IER, UART_IER_RDI);
1915+
1916+ return 0;
1917+}
1918--- a/drivers/bluetooth/Kconfig
1919+++ b/drivers/bluetooth/Kconfig
1920@@ -173,6 +173,16 @@ config BT_HCIBTUART
1921       Say Y here to compile support for HCI UART devices into the
1922       kernel or say M to compile it as module (btuart_cs).
1923 
1924+config BT_HCIH4P
1925+ tristate "HCI driver with H4 Nokia extensions"
1926+ depends on BT && ARCH_OMAP
1927+ help
1928+ Bluetooth HCI driver with H4 extensions. This driver provides
1929+ support for H4+ Bluetooth chip with vendor-specific H4 extensions.
1930+
1931+ Say Y here to compile support for h4 extended devices into the kernel
1932+ or say M to compile it as module (hci_h4p).
1933+
1934 config BT_HCIVHCI
1935     tristate "HCI VHCI (Virtual HCI device) driver"
1936     help
1937--- a/drivers/bluetooth/Makefile
1938+++ b/drivers/bluetooth/Makefile
1939@@ -11,6 +11,7 @@ obj-$(CONFIG_BT_HCIDTL1) += dtl1_cs.o
1940 obj-$(CONFIG_BT_HCIBT3C) += bt3c_cs.o
1941 obj-$(CONFIG_BT_HCIBLUECARD) += bluecard_cs.o
1942 obj-$(CONFIG_BT_HCIBTUART) += btuart_cs.o
1943+obj-$(CONFIG_BT_HCIH4P) += hci_h4p/
1944 
1945 obj-$(CONFIG_BT_HCIBTUSB) += btusb.o
1946 obj-$(CONFIG_BT_HCIBTSDIO) += btsdio.o
1947

Archive Download this file



interactive