1*8ee626c9Schristos /* $NetBSD: init_bcm2035.c,v 1.3 2015/06/16 23:04:14 christos Exp $ */
2486e4624Splunky
3486e4624Splunky /*-
4486e4624Splunky * Copyright (c) 2008 Iain Hibbert
5486e4624Splunky * All rights reserved.
6486e4624Splunky *
7486e4624Splunky * Redistribution and use in source and binary forms, with or without
8486e4624Splunky * modification, are permitted provided that the following conditions
9486e4624Splunky * are met:
10486e4624Splunky * 1. Redistributions of source code must retain the above copyright
11486e4624Splunky * notice, this list of conditions and the following disclaimer.
12486e4624Splunky * 2. Redistributions in binary form must reproduce the above copyright
13486e4624Splunky * notice, this list of conditions and the following disclaimer in the
14486e4624Splunky * documentation and/or other materials provided with the distribution.
15486e4624Splunky *
16486e4624Splunky * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17486e4624Splunky * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18486e4624Splunky * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19486e4624Splunky * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20486e4624Splunky * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21486e4624Splunky * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22486e4624Splunky * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23486e4624Splunky * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24486e4624Splunky * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25486e4624Splunky * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26486e4624Splunky */
27486e4624Splunky
28486e4624Splunky /*
29486e4624Splunky * init information in this file gleaned from hciattach(8)
30486e4624Splunky * command from BlueZ for Linux - see http://www.bluez.org/
31486e4624Splunky */
32486e4624Splunky
33486e4624Splunky #include <sys/cdefs.h>
34*8ee626c9Schristos __RCSID("$NetBSD: init_bcm2035.c,v 1.3 2015/06/16 23:04:14 christos Exp $");
35486e4624Splunky
36486e4624Splunky #include <bluetooth.h>
37486e4624Splunky #include <err.h>
38486e4624Splunky #include <errno.h>
39486e4624Splunky #include <stdlib.h>
40486e4624Splunky #include <termios.h>
41486e4624Splunky
42486e4624Splunky #include "btattach.h"
43486e4624Splunky
44486e4624Splunky #define HCI_CMD_BCM2035_SET_UART_BAUD_RATE \
45486e4624Splunky HCI_OPCODE(HCI_OGF_VENDOR, 0x018)
46486e4624Splunky
47486e4624Splunky #define HCI_CMD_BCM2035_SET_BDADDR \
48486e4624Splunky HCI_OPCODE(HCI_OGF_VENDOR, 0x001)
49486e4624Splunky
50486e4624Splunky void
init_bcm2035(int fd,unsigned int speed)51486e4624Splunky init_bcm2035(int fd, unsigned int speed)
52486e4624Splunky {
53486e4624Splunky uint16_t rate;
54486e4624Splunky
55486e4624Splunky uart_send_cmd(fd, HCI_CMD_RESET, NULL, 0);
56486e4624Splunky
57486e4624Splunky uart_recv_cc(fd, HCI_CMD_RESET, NULL, 0);
58486e4624Splunky /* assume it succeeded? */
59486e4624Splunky
60486e4624Splunky /* can also set the bdaddr */
61486e4624Splunky
62486e4624Splunky switch(speed) {
63486e4624Splunky case B57600: rate = 0xe600; break;
64486e4624Splunky case B115200: rate = 0xf300; break;
65486e4624Splunky case B230400: rate = 0xfa22; break;
66486e4624Splunky case B460800: rate = 0xfd22; break;
67486e4624Splunky case B921600: rate = 0xff55; break;
68486e4624Splunky default:
69*8ee626c9Schristos errx(EXIT_FAILURE, "invalid speed for bcm2035: %u", speed);
70486e4624Splunky };
71486e4624Splunky
72486e4624Splunky rate = htole16(rate);
73486e4624Splunky uart_send_cmd(fd, HCI_CMD_BCM2035_SET_UART_BAUD_RATE, &rate, sizeof(rate));
74486e4624Splunky uart_recv_cc(fd, HCI_CMD_BCM2035_SET_UART_BAUD_RATE, NULL, 0);
75486e4624Splunky /* assume it succeeded? */
76486e4624Splunky }
77