Merge current mainline tree into linux-omap tree
[pandora-kernel.git] / drivers / bluetooth / hci_h4p / hci_h4p.h
1 /*
2  * This file is part of hci_h4p bluetooth driver
3  *
4  * Copyright (C) 2005, 2006 Nokia Corporation.
5  *
6  * Contact: Ville Tervo <ville.tervo@nokia.com>
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * version 2 as published by the Free Software Foundation.
11  *
12  * This program is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20  * 02110-1301 USA
21  *
22  */
23
24 #include <mach/board.h>
25
26 #include <net/bluetooth/bluetooth.h>
27 #include <net/bluetooth/hci_core.h>
28 #include <net/bluetooth/hci.h>
29
30 #ifndef __DRIVERS_BLUETOOTH_HCI_H4P_H
31 #define __DRIVERS_BLUETOOTH_HCI_H4P_H
32
33 #define UART_SYSC_OMAP_RESET    0x03
34 #define UART_SYSS_RESETDONE     0x01
35 #define UART_OMAP_SCR_EMPTY_THR 0x08
36 #define UART_OMAP_SCR_WAKEUP    0x10
37 #define UART_OMAP_SSR_WAKEUP    0x02
38 #define UART_OMAP_SSR_TXFULL    0x01
39
40 #if 0
41 #define NBT_DBG(fmt, arg...)  printk("%s: " fmt "" , __FUNCTION__ , ## arg)
42 #else
43 #define NBT_DBG(...)
44 #endif
45
46 #if 0
47 #define NBT_DBG_FW(fmt, arg...)  printk("%s: " fmt "" , __FUNCTION__ , ## arg)
48 #else
49 #define NBT_DBG_FW(...)
50 #endif
51
52 #if 0
53 #define NBT_DBG_POWER(fmt, arg...)  printk("%s: " fmt "" , __FUNCTION__ , ## arg)
54 #else
55 #define NBT_DBG_POWER(...)
56 #endif
57
58 #if 0
59 #define NBT_DBG_TRANSFER(fmt, arg...)  printk("%s: " fmt "" , __FUNCTION__ , ## arg)
60 #else
61 #define NBT_DBG_TRANSFER(...)
62 #endif
63
64 #if 0
65 #define NBT_DBG_TRANSFER_NF(fmt, arg...)  printk(fmt "" , ## arg)
66 #else
67 #define NBT_DBG_TRANSFER_NF(...)
68 #endif
69
70 #if 0
71 #define NBT_DBG_DMA(fmt, arg...)  printk("%s: " fmt "" , __FUNCTION__ , ## arg)
72 #else
73 #define NBT_DBG_DMA(...)
74 #endif
75
76 struct hci_h4p_info {
77         struct hci_dev *hdev;
78         spinlock_t lock;
79
80         void __iomem *uart_base;
81         unsigned long uart_phys_base;
82         int irq;
83         struct device *dev;
84         u8 bdaddr[6];
85         u8 chip_type;
86         u8 bt_wakeup_gpio;
87         u8 host_wakeup_gpio;
88         u8 reset_gpio;
89         u8 bt_sysclk;
90
91
92         struct sk_buff_head fw_queue;
93         struct sk_buff *alive_cmd_skb;
94         struct completion init_completion;
95         struct completion fw_completion;
96         int fw_error;
97         int init_error;
98
99         struct sk_buff_head txq;
100         struct tasklet_struct tx_task;
101
102         struct sk_buff *rx_skb;
103         long rx_count;
104         unsigned long rx_state;
105         unsigned long garbage_bytes;
106         struct tasklet_struct rx_task;
107
108         int pm_enabled;
109         int tx_pm_enabled;
110         int rx_pm_enabled;
111         struct timer_list tx_pm_timer;
112         struct timer_list rx_pm_timer;
113
114         int tx_clocks_en;
115         int rx_clocks_en;
116         spinlock_t clocks_lock;
117         struct clk *uart_iclk;
118         struct clk *uart_fclk;
119 };
120
121 #define MAX_BAUD_RATE           921600
122 #define BC4_MAX_BAUD_RATE       3692300
123 #define UART_CLOCK              48000000
124 #define BT_INIT_DIVIDER         320
125 #define BT_BAUDRATE_DIVIDER     384000000
126 #define BT_SYSCLK_DIV           1000
127 #define INIT_SPEED              120000
128
129 #define H4_TYPE_SIZE            1
130
131 /* H4+ packet types */
132 #define H4_CMD_PKT              0x01
133 #define H4_ACL_PKT              0x02
134 #define H4_SCO_PKT              0x03
135 #define H4_EVT_PKT              0x04
136 #define H4_NEG_PKT              0x06
137 #define H4_ALIVE_PKT            0x07
138
139 /* TX states */
140 #define WAIT_FOR_PKT_TYPE       1
141 #define WAIT_FOR_HEADER         2
142 #define WAIT_FOR_DATA           3
143
144 struct hci_fw_event {
145         struct hci_event_hdr hev;
146         struct hci_ev_cmd_complete cmd;
147         u8 status;
148 } __attribute__ ((packed));
149
150 struct hci_bc4_set_bdaddr {
151         u8 type;
152         struct hci_command_hdr cmd_hdr;
153 } __attribute__ ((packed));
154
155 int hci_h4p_send_alive_packet(struct hci_h4p_info *info);
156
157 void hci_h4p_bc4_parse_fw_event(struct hci_h4p_info *info,
158                                 struct sk_buff *skb);
159 int hci_h4p_bc4_send_fw(struct hci_h4p_info *info,
160                         struct sk_buff_head *fw_queue);
161
162 void hci_h4p_brf6150_parse_fw_event(struct hci_h4p_info *info,
163                                     struct sk_buff *skb);
164 int hci_h4p_brf6150_send_fw(struct hci_h4p_info *info,
165                             struct sk_buff_head *fw_queue);
166
167 int hci_h4p_read_fw(struct hci_h4p_info *info, struct sk_buff_head *fw_queue);
168 int hci_h4p_send_fw(struct hci_h4p_info *info, struct sk_buff_head *fw_queue);
169 void hci_h4p_parse_fw_event(struct hci_h4p_info *info, struct sk_buff *skb);
170
171 int hci_h4p_sysfs_create_files(struct device *dev);
172
173 void hci_h4p_outb(struct hci_h4p_info *info, unsigned int offset, u8 val);
174 u8 hci_h4p_inb(struct hci_h4p_info *info, unsigned int offset);
175 void hci_h4p_set_rts(struct hci_h4p_info *info, int active);
176 int hci_h4p_wait_for_cts(struct hci_h4p_info *info, int active, int timeout_ms);
177 void __hci_h4p_set_auto_ctsrts(struct hci_h4p_info *info, int on, u8 which);
178 void hci_h4p_set_auto_ctsrts(struct hci_h4p_info *info, int on, u8 which);
179 void hci_h4p_change_speed(struct hci_h4p_info *info, unsigned long speed);
180 int hci_h4p_reset_uart(struct hci_h4p_info *info);
181 int hci_h4p_init_uart(struct hci_h4p_info *info);
182
183 #endif /* __DRIVERS_BLUETOOTH_HCI_H4P_H */