Skip to content

Commit 91eef3e

Browse files
pavelmachekgregkh
authored andcommitted
staging/bluetooth: Add hci_h4p driver
Add hci_h4p bluetooth driver to staging tree. This device is used for example on Nokia N900 cell phone. Signed-off-by: Pali Rohár <pali.rohar@gmail.com> Signed-off-by: Pavel Machek <pavel@ucw.cz> Thanks-to: Sebastian Reichel <sre@debian.org> Thanks-to: Joe Perches <joe@perches.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent be973fc commit 91eef3e

13 files changed

Lines changed: 2430 additions & 0 deletions

File tree

‎drivers/staging/Kconfig‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,4 +148,6 @@ source "drivers/staging/dgap/Kconfig"
148148

149149
source "drivers/staging/gs_fpgaboot/Kconfig"
150150

151+
source "drivers/staging/nokia_h4p/Kconfig"
152+
151153
endif # STAGING

‎drivers/staging/Makefile‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,4 @@ obj-$(CONFIG_DGNC) += dgnc/
6666
obj-$(CONFIG_DGAP) += dgap/
6767
obj-$(CONFIG_MTD_SPINAND_MT29F) += mt29f_spinand/
6868
obj-$(CONFIG_GS_FPGABOOT) += gs_fpgaboot/
69+
obj-$(CONFIG_BT_NOKIA_H4P) += nokia_h4p/

‎drivers/staging/nokia_h4p/Kconfig‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
config BT_NOKIA_H4P
2+
tristate "HCI driver with H4 Nokia extensions"
3+
depends on BT && ARCH_OMAP
4+
help
5+
Bluetooth HCI driver with H4 extensions. This driver provides
6+
support for H4+ Bluetooth chip with vendor-specific H4 extensions.
7+
8+
Say Y here to compile support for h4 extended devices into the kernel
9+
or say M to compile it as module (btnokia_h4p).

‎drivers/staging/nokia_h4p/Makefile‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2+
obj-$(CONFIG_BT_NOKIA_H4P) += btnokia_h4p.o
3+
btnokia_h4p-objs := nokia_core.o nokia_fw.o nokia_uart.o nokia_fw-csr.o \
4+
nokia_fw-bcm.o nokia_fw-ti1273.o
5+
6+
ccflags-y += -D__CHECK_ENDIAN__

‎drivers/staging/nokia_h4p/TODO‎

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
Few attempts to submission have been made, last review comments were received in
2+
3+
Date: Wed, 15 Jan 2014 19:01:51 -0800
4+
From: Marcel Holtmann <marcel@holtmann.org>
5+
Subject: Re: [PATCH v6] Bluetooth: Add hci_h4p driver
6+
7+
Some code refactoring is still needed.
8+
9+
TODO:
10+
11+
> +++ b/drivers/bluetooth/hci_h4p.h
12+
13+
can we please get the naming straight. File names do not start with
14+
hci_ anymore. We moved away from it since that term is too generic.
15+
16+
> +#define FW_NAME_TI1271_LE "ti1273_le.bin"
17+
> +#define FW_NAME_TI1271 "ti1273.bin"
18+
> +#define FW_NAME_BCM2048 "bcmfw.bin"
19+
> +#define FW_NAME_CSR "bc4fw.bin"
20+
21+
We do these have to be global in a header file. This should be
22+
confined to the specific firmware part.
23+
24+
> +struct hci_h4p_info {
25+
26+
Can we please get rid of the hci_ prefix for everything. Copying from
27+
drivers that are over 10 years old is not a good idea. Please look at
28+
recent ones.
29+
30+
> + struct timer_list lazy_release;
31+
32+
Timer? Not delayed work?
33+
34+
> +void hci_h4p_outb(struct hci_h4p_info *info, unsigned int offset, u8 val);
35+
> +u8 hci_h4p_inb(struct hci_h4p_info *info, unsigned int offset);
36+
> +void hci_h4p_set_rts(struct hci_h4p_info *info, int active);
37+
> +int hci_h4p_wait_for_cts(struct hci_h4p_info *info, int active, int timeout_ms);
38+
> +void __hci_h4p_set_auto_ctsrts(struct hci_h4p_info *info, int on, u8 which);
39+
> +void hci_h4p_set_auto_ctsrts(struct hci_h4p_info *info, int on, u8 which);
40+
> +void hci_h4p_change_speed(struct hci_h4p_info *info, unsigned long speed);
41+
> +int hci_h4p_reset_uart(struct hci_h4p_info *info);
42+
> +void hci_h4p_init_uart(struct hci_h4p_info *info);
43+
> +void hci_h4p_enable_tx(struct hci_h4p_info *info);
44+
> +void hci_h4p_store_regs(struct hci_h4p_info *info);
45+
> +void hci_h4p_restore_regs(struct hci_h4p_info *info);
46+
> +void hci_h4p_smart_idle(struct hci_h4p_info *info, bool enable);
47+
48+
These are a lot of public functions. Are they all really needed or can
49+
the code be done smart.
50+
51+
> +static ssize_t hci_h4p_store_bdaddr(struct device *dev,
52+
> + struct device_attribute *attr,
53+
> + const char *buf, size_t count)
54+
> +{
55+
> + struct hci_h4p_info *info = dev_get_drvdata(dev);
56+
57+
Since none of these devices can function without having a valid
58+
address, the way this should work is that we should not register the
59+
HCI device when probing the platform device.
60+
61+
The HCI device should be registered once a valid address has been
62+
written into the sysfs file. I do not want to play the tricks with
63+
bringing up the device without a valid address.
64+
65+
> + hdev->close = hci_h4p_hci_close;
66+
> + hdev->flush = hci_h4p_hci_flush;
67+
> + hdev->send = hci_h4p_hci_send_frame;
68+
69+
It needs to use hdev->setup to load the firmware. I assume the
70+
firmware only needs to be loaded once. That is exactly what
71+
hdev->setup does. It gets executed once.
72+
73+
> + set_bit(HCI_QUIRK_RESET_ON_CLOSE, &hdev->quirks);
74+
75+
Is this quirk really needed? Normally only Bluetooth 1.1 and early
76+
devices qualify for it.
77+
78+
> +static int hci_h4p_bcm_set_bdaddr(struct hci_h4p_info *info, struct sk_buff *skb)
79+
> +{
80+
> + int i;
81+
> + static const u8 nokia_oui[3] = {0x00, 0x1f, 0xdf};
82+
> + int not_valid;
83+
84+
Has this actually been confirmed that we can just randomly set an
85+
address out of the Nokia range. I do not think so. This is a pretty
86+
bad idea.
87+
88+
I have no interest in merging a driver with such a hack.
89+
90+
> + not_valid = 1;
91+
> + for (i = 0; i < 6; i++) {
92+
> + if (info->bd_addr[i] != 0x00) {
93+
> + not_valid = 0;
94+
> + break;
95+
> + }
96+
> + }
97+
98+
Anybody every heard of memcmp or bacmp and BDADDR_ANY?
99+
100+
> + if (not_valid) {
101+
> + dev_info(info->dev, "Valid bluetooth address not found,"
102+
> + " setting some random\n");
103+
> + /* When address is not valid, use some random */
104+
> + memcpy(info->bd_addr, nokia_oui, 3);
105+
> + get_random_bytes(info->bd_addr + 3, 3);
106+
> + }
107+
108+
109+
And why does every single chip firmware does this differently. Seriously, this is a mess.
110+
111+
> +void hci_h4p_parse_fw_event(struct hci_h4p_info *info, struct sk_buff *skb)
112+
> +{
113+
> + switch (info->man_id) {
114+
> + case H4P_ID_CSR:
115+
> + hci_h4p_bc4_parse_fw_event(info, skb);
116+
> + break;
117+
...
118+
> +}
119+
120+
We have proper HCI sync command handling in recent kernels. I really
121+
do not know why this is hand coded these days. Check how the Intel
122+
firmware loading inside btusb.c does it.
123+
124+
> +inline u8 hci_h4p_inb(struct hci_h4p_info *info, unsigned int offset)
125+
> +{
126+
> + return __raw_readb(info->uart_base + (offset << 2));
127+
> +}
128+
129+
Inline in a *.c file for a non-static function. Makes no sense to me.
130+
131+
> +/**
132+
> + * struct hci_h4p_platform data - hci_h4p Platform data structure
133+
> + */
134+
> +struct hci_h4p_platform_data {
135+
136+
please have a proper name here. For example
137+
btnokia_h4p_platform_data.
138+
139+
Please send patches to Greg Kroah-Hartman <greg@kroah.com> and Cc:
140+
Pavel Machek <pavel@ucw.cz>
Lines changed: 228 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,228 @@
1+
/*
2+
* This file is part of Nokia H4P bluetooth driver
3+
*
4+
* Copyright (C) 2005-2008 Nokia Corporation.
5+
*
6+
* This program is free software; you can redistribute it and/or
7+
* modify it under the terms of the GNU General Public License
8+
* version 2 as published by the Free Software Foundation.
9+
*
10+
* This program is distributed in the hope that it will be useful, but
11+
* WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13+
* General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU General Public License
16+
* along with this program; if not, write to the Free Software
17+
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18+
* 02110-1301 USA
19+
*
20+
*/
21+
22+
#ifndef __DRIVERS_BLUETOOTH_HCI_H4P_H
23+
#define __DRIVERS_BLUETOOTH_HCI_H4P_H
24+
25+
#include <net/bluetooth/bluetooth.h>
26+
#include <net/bluetooth/hci_core.h>
27+
#include <net/bluetooth/hci.h>
28+
29+
#define FW_NAME_TI1271_PRELE "ti1273_prele.bin"
30+
#define FW_NAME_TI1271_LE "ti1273_le.bin"
31+
#define FW_NAME_TI1271 "ti1273.bin"
32+
#define FW_NAME_BCM2048 "bcmfw.bin"
33+
#define FW_NAME_CSR "bc4fw.bin"
34+
35+
#define UART_SYSC_OMAP_RESET 0x03
36+
#define UART_SYSS_RESETDONE 0x01
37+
#define UART_OMAP_SCR_EMPTY_THR 0x08
38+
#define UART_OMAP_SCR_WAKEUP 0x10
39+
#define UART_OMAP_SSR_WAKEUP 0x02
40+
#define UART_OMAP_SSR_TXFULL 0x01
41+
42+
#define UART_OMAP_SYSC_IDLEMODE 0x03
43+
#define UART_OMAP_SYSC_IDLEMASK (3 << UART_OMAP_SYSC_IDLEMODE)
44+
45+
#define UART_OMAP_SYSC_FORCE_IDLE (0 << UART_OMAP_SYSC_IDLEMODE)
46+
#define UART_OMAP_SYSC_NO_IDLE (1 << UART_OMAP_SYSC_IDLEMODE)
47+
#define UART_OMAP_SYSC_SMART_IDLE (2 << UART_OMAP_SYSC_IDLEMODE)
48+
49+
#define H4P_TRANSFER_MODE 1
50+
#define H4P_SCHED_TRANSFER_MODE 2
51+
#define H4P_ACTIVE_MODE 3
52+
53+
struct hci_h4p_info {
54+
struct timer_list lazy_release;
55+
struct hci_dev *hdev;
56+
spinlock_t lock;
57+
58+
void __iomem *uart_base;
59+
unsigned long uart_phys_base;
60+
int irq;
61+
struct device *dev;
62+
u8 chip_type;
63+
u8 bt_wakeup_gpio;
64+
u8 host_wakeup_gpio;
65+
u8 reset_gpio;
66+
u8 reset_gpio_shared;
67+
u8 bt_sysclk;
68+
u8 man_id;
69+
u8 ver_id;
70+
71+
struct sk_buff_head fw_queue;
72+
struct sk_buff *alive_cmd_skb;
73+
struct completion init_completion;
74+
struct completion fw_completion;
75+
struct completion test_completion;
76+
int fw_error;
77+
int init_error;
78+
79+
struct sk_buff_head txq;
80+
81+
struct sk_buff *rx_skb;
82+
long rx_count;
83+
unsigned long rx_state;
84+
unsigned long garbage_bytes;
85+
86+
u8 bd_addr[6];
87+
struct sk_buff_head *fw_q;
88+
89+
int pm_enabled;
90+
int tx_enabled;
91+
int autorts;
92+
int rx_enabled;
93+
unsigned long pm_flags;
94+
95+
int tx_clocks_en;
96+
int rx_clocks_en;
97+
spinlock_t clocks_lock;
98+
struct clk *uart_iclk;
99+
struct clk *uart_fclk;
100+
atomic_t clk_users;
101+
u16 dll;
102+
u16 dlh;
103+
u16 ier;
104+
u16 mdr1;
105+
u16 efr;
106+
};
107+
108+
struct hci_h4p_radio_hdr {
109+
__u8 evt;
110+
__u8 dlen;
111+
} __attribute__ ((packed));
112+
113+
struct hci_h4p_neg_hdr {
114+
__u8 dlen;
115+
} __attribute__ ((packed));
116+
#define H4P_NEG_HDR_SIZE 1
117+
118+
#define H4P_NEG_REQ 0x00
119+
#define H4P_NEG_ACK 0x20
120+
#define H4P_NEG_NAK 0x40
121+
122+
#define H4P_PROTO_PKT 0x44
123+
#define H4P_PROTO_BYTE 0x4c
124+
125+
#define H4P_ID_CSR 0x02
126+
#define H4P_ID_BCM2048 0x04
127+
#define H4P_ID_TI1271 0x31
128+
129+
struct hci_h4p_neg_cmd {
130+
__u8 ack;
131+
__u16 baud;
132+
__u16 unused1;
133+
__u8 proto;
134+
__u16 sys_clk;
135+
__u16 unused2;
136+
} __attribute__ ((packed));
137+
138+
struct hci_h4p_neg_evt {
139+
__u8 ack;
140+
__u16 baud;
141+
__u16 unused1;
142+
__u8 proto;
143+
__u16 sys_clk;
144+
__u16 unused2;
145+
__u8 man_id;
146+
__u8 ver_id;
147+
} __attribute__ ((packed));
148+
149+
#define H4P_ALIVE_REQ 0x55
150+
#define H4P_ALIVE_RESP 0xcc
151+
152+
struct hci_h4p_alive_hdr {
153+
__u8 dlen;
154+
} __attribute__ ((packed));
155+
#define H4P_ALIVE_HDR_SIZE 1
156+
157+
struct hci_h4p_alive_pkt {
158+
__u8 mid;
159+
__u8 unused;
160+
} __attribute__ ((packed));
161+
162+
#define MAX_BAUD_RATE 921600
163+
#define BC4_MAX_BAUD_RATE 3692300
164+
#define UART_CLOCK 48000000
165+
#define BT_INIT_DIVIDER 320
166+
#define BT_BAUDRATE_DIVIDER 384000000
167+
#define BT_SYSCLK_DIV 1000
168+
#define INIT_SPEED 120000
169+
170+
#define H4_TYPE_SIZE 1
171+
#define H4_RADIO_HDR_SIZE 2
172+
173+
/* H4+ packet types */
174+
#define H4_CMD_PKT 0x01
175+
#define H4_ACL_PKT 0x02
176+
#define H4_SCO_PKT 0x03
177+
#define H4_EVT_PKT 0x04
178+
#define H4_NEG_PKT 0x06
179+
#define H4_ALIVE_PKT 0x07
180+
#define H4_RADIO_PKT 0x08
181+
182+
/* TX states */
183+
#define WAIT_FOR_PKT_TYPE 1
184+
#define WAIT_FOR_HEADER 2
185+
#define WAIT_FOR_DATA 3
186+
187+
struct hci_fw_event {
188+
struct hci_event_hdr hev;
189+
struct hci_ev_cmd_complete cmd;
190+
u8 status;
191+
} __attribute__ ((packed));
192+
193+
int hci_h4p_send_alive_packet(struct hci_h4p_info *info);
194+
195+
void hci_h4p_bcm_parse_fw_event(struct hci_h4p_info *info,
196+
struct sk_buff *skb);
197+
int hci_h4p_bcm_send_fw(struct hci_h4p_info *info,
198+
struct sk_buff_head *fw_queue);
199+
200+
void hci_h4p_bc4_parse_fw_event(struct hci_h4p_info *info,
201+
struct sk_buff *skb);
202+
int hci_h4p_bc4_send_fw(struct hci_h4p_info *info,
203+
struct sk_buff_head *fw_queue);
204+
205+
void hci_h4p_ti1273_parse_fw_event(struct hci_h4p_info *info,
206+
struct sk_buff *skb);
207+
int hci_h4p_ti1273_send_fw(struct hci_h4p_info *info,
208+
struct sk_buff_head *fw_queue);
209+
210+
int hci_h4p_read_fw(struct hci_h4p_info *info, struct sk_buff_head *fw_queue);
211+
int hci_h4p_send_fw(struct hci_h4p_info *info, struct sk_buff_head *fw_queue);
212+
void hci_h4p_parse_fw_event(struct hci_h4p_info *info, struct sk_buff *skb);
213+
214+
void hci_h4p_outb(struct hci_h4p_info *info, unsigned int offset, u8 val);
215+
u8 hci_h4p_inb(struct hci_h4p_info *info, unsigned int offset);
216+
void hci_h4p_set_rts(struct hci_h4p_info *info, int active);
217+
int hci_h4p_wait_for_cts(struct hci_h4p_info *info, int active, int timeout_ms);
218+
void __hci_h4p_set_auto_ctsrts(struct hci_h4p_info *info, int on, u8 which);
219+
void hci_h4p_set_auto_ctsrts(struct hci_h4p_info *info, int on, u8 which);
220+
void hci_h4p_change_speed(struct hci_h4p_info *info, unsigned long speed);
221+
int hci_h4p_reset_uart(struct hci_h4p_info *info);
222+
void hci_h4p_init_uart(struct hci_h4p_info *info);
223+
void hci_h4p_enable_tx(struct hci_h4p_info *info);
224+
void hci_h4p_store_regs(struct hci_h4p_info *info);
225+
void hci_h4p_restore_regs(struct hci_h4p_info *info);
226+
void hci_h4p_smart_idle(struct hci_h4p_info *info, bool enable);
227+
228+
#endif /* __DRIVERS_BLUETOOTH_HCI_H4P_H */

0 commit comments

Comments
 (0)