Return-Path: MIME-Version: 1.0 Date: Fri, 13 May 2016 14:57:59 +1000 Message-ID: Subject: How to enable hci0 for bcm4356 chip on htc m9? From: Qingtao Cao To: linux-bluetooth@vger.kernel.org Content-Type: multipart/mixed; boundary=001a113abda0696e0a0532b21eaa Sender: linux-bluetooth-owner@vger.kernel.org List-ID: --001a113abda0696e0a0532b21eaa Content-Type: text/plain; charset=UTF-8 Dear community, I am trying to enable hci0 on the htc m9 phone. Of course, the bluetooth functionality on that phone with the original CyanogenMod Android works well. To my surprise, after I mounted a yocto rootfs(with bluez built in), setup needed pseudo filesystems such as proc and chroot into it, the hciconfig finds no hci0 device at all. So how could I enable the hci0 interface for the bcm4356 chipset? Also doesn't bluedroid manipulate it at all? BTW, the /dev/ttyHS0 is available on CyanogenMod Android, I also found how bluedroid and broadcom's libbt repo (implements the libbt-vendor.so library) setup its baud rate and writes into it the content of a firmware patchfile, so I tried to abstract relevant logic into the attached c file and run it on my own Linux (derived from 3.10 mainline kernel) with bluetooth and /dev/ttyHS0 drivers all enabled, however, again, I failed to run hciattach to attach /dev/ttyHS0 to further bring about hci0, despite that this simple c file can achieve similar result. The results of bluetooth related commands on my tailored linux on htc m9 are as followed. Many thanks for any advice or comment! Cheers, Harry / # hciconfig hci0 Can't get device info: No such device / # / # ls -l /dev/ttyHS0 crw-rw---- 1 root dialout 236, 0 May 13 04:50 /dev/ttyHS0 / # grep 236 /proc/devices 236 ttyHS / # / # rfkill list 0: bt_power: bluetooth Soft blocked: no Hard blocked: no 1: bcm4356: bluetooth Soft blocked: no Hard blocked: no 2: phy0: wlan Soft blocked: no Hard blocked: no 3: brcmfmac-wifi: wlan Soft blocked: no Hard blocked: no / # / # ./bcm4356_init userial vendor open: opening /dev/ttyHS0 device fd = 3 open bt vendor lib: set UART baud 4000000 HCI_VSC_LAUNCH_RAM received! bt vendor lib: set UART baud 115200 bt vendor lib: set UART baud 4000000 Setting local bd addr to 90:E7:C4:F3:F7:09 vendor lib fwcfg completed / # / # hciattach -n /dev/ttyHS0 any 4000000 90:E7:C4:F3:F7:09 Device setup complete (blocked, pressed ctrl + c to terminate) --001a113abda0696e0a0532b21eaa Content-Type: text/x-csrc; charset=US-ASCII; name="bcm4356_init.c" Content-Disposition: attachment; filename="bcm4356_init.c" Content-Transfer-Encoding: base64 X-Attachment-Id: f_io59159e0 I2luY2x1ZGUgPHN0ZGludC5oPgojaW5jbHVkZSA8c3RkYm9vbC5oPgojaW5jbHVkZSA8dGVybWlv cy5oPgojaW5jbHVkZSA8ZmNudGwuaD4KI2luY2x1ZGUgPGVycm5vLmg+CiNpbmNsdWRlIDxzdGRp by5oPgojaW5jbHVkZSA8c3RkbGliLmg+CiNpbmNsdWRlIDxzdHJpbmcuaD4KI2luY2x1ZGUgPHRp bWUuaD4KCi8qKioqIGJhdWQgcmF0ZXMgKioqKi8KI2RlZmluZSBVU0VSSUFMX0JBVURfMzAwICAg ICAgICAwCiNkZWZpbmUgVVNFUklBTF9CQVVEXzYwMCAgICAgICAgMQojZGVmaW5lIFVTRVJJQUxf QkFVRF8xMjAwICAgICAgIDIKI2RlZmluZSBVU0VSSUFMX0JBVURfMjQwMCAgICAgICAzCiNkZWZp bmUgVVNFUklBTF9CQVVEXzk2MDAgICAgICAgNAojZGVmaW5lIFVTRVJJQUxfQkFVRF8xOTIwMCAg ICAgIDUKI2RlZmluZSBVU0VSSUFMX0JBVURfNTc2MDAgICAgICA2CiNkZWZpbmUgVVNFUklBTF9C QVVEXzExNTIwMCAgICAgNwojZGVmaW5lIFVTRVJJQUxfQkFVRF8yMzA0MDAgICAgIDgKI2RlZmlu ZSBVU0VSSUFMX0JBVURfNDYwODAwICAgICA5CiNkZWZpbmUgVVNFUklBTF9CQVVEXzkyMTYwMCAg ICAgMTAKI2RlZmluZSBVU0VSSUFMX0JBVURfMU0gICAgICAgICAxMQojZGVmaW5lIFVTRVJJQUxf QkFVRF8xXzVNICAgICAgIDEyCiNkZWZpbmUgVVNFUklBTF9CQVVEXzJNICAgICAgICAgM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9MRU4gICAgICAgICAgICAgMjU4CgovKiBDb21tb24gSENJIGNvbW1hbmRzICovCiNkZWZpbmUg SENJX1JFU0VUICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIDB4MEMwMwojZGVmaW5lIEhD SV9SRUFEX0xPQ0FMX05BTUUgICAgICAgICAgICAgICAgICAgICAweDBDMTQKI2RlZmluZSBIQ0lf UkVBRF9MT0NBTF9CREFERFIgICAgICAgICAgICAgICAgICAgMHgxMDA5CgovKiBWZW5kb3IgU3Bl Y2lmaWMgSENJIGNvbW1hbmRzICovCiNkZWZpbmUgSENJX1ZTQ19XUklURV9VQVJUX0NMT0NLX1NF VFRJTkcgICAgICAgIDB4RkM0NQojZGVmaW5lIEhDSV9WU0NfVVBEQVRFX0JBVURSQVRFICAgICAg ICAgICAgICAgICAweEZDMTgKI2RlZmluZSBIQ0lfVlNDX0RPV05MT0FEX01JTklEUlYgICAgICAg ICAgICAgICAgMHhGQzJFCiNkZWZpbmUgSENJX1ZTQ19XUklURV9CRF9BRERSICAgICAgICAgICAg ICAgICAgIDB4RkMwMQojZGVmaW5lIEhDSV9WU0NfV1JJVEVfU0xFRVBfTU9ERSAgICAgICAgICAg ICAgICAweEZDMjcKI2RlZmluZSBIQ0lfVlNDX1dSSVRFX1NDT19QQ01fSU5UX1BBUkFNICAgICAg ICAgMHhGQzFDCiNkZWZpbmUgSENJX1ZTQ19XUklURV9QQ01fREFUQV9GT1JNQVRfUEFSQU0gICAg IDB4RkMxRQojZGVmaW5lIEhDSV9WU0NfV1JJVEVfSTJTUENNX0lOVEVSRkFDRV9QQVJBTSAgICAw eEZDNkQKI2RlZmluZSBIQ0lfVlNDX0VOQUJMRV9XQlMgICAgICAgICAgICAgICAgICAgICAgMHhG QzdFCiNkZWZpbmUgSENJX1ZTQ19MQVVOQ0hfUkFNICAgICAgICAgICAgICAgICAgICAgIDB4RkM0 RQoKI2RlZmluZSBIQ0lfRVZUX0NNRF9DTVBMX1NUQVRVU19SRVRfQllURSAgICAgICAgNQojZGVm aW5lIEhDSV9FVlRfQ01EX0NNUExfTE9DQUxfTkFNRV9TVFJJTkcgICAgICA2CiNkZWZpbmUgSENJ X0VWVF9DTURfQ01QTF9MT0NBTF9CREFERFJfQVJSQVkgICAgIDYKI2RlZmluZSBIQ0lfRVZUX0NN RF9DTVBMX09QQ09ERSAgICAgICAgICAgICAgICAgMwojZGVmaW5lIExQTV9DTURfUEFSQU1fU0la RSAgICAgICAgICAgICAgICAgICAgICAxMgojZGVmaW5lIFVQREFURV9CQVVEUkFURV9DTURfUEFS QU1fU0laRSAgICAgICAgICA2CiNkZWZpbmUgSENJX0NNRF9QUkVBTUJMRV9TSVpFICAgICAgICAg ICAgICAgICAgIDMKI2RlZmluZSBIQ0RfUkVDX1BBWUxPQURfTEVOX0JZVEUgICAgICAgICAgICAg ICAgMgojZGVmaW5lIEJEX0FERFJfTEVOICAgICAgICAgICAgICAgICAgICAgICAgICAgICA2CiNk ZWZpbmUgTE9DQUxfTkFNRV9CVUZGRVJfTEVOICAgICAgICAgICAgICAgICAgIDMyCiNkZWZpbmUg TE9DQUxfQkRBRERSX1BBVEhfQlVGRkVSX0xFTiAgICAgICAgICAgIDI1NgoKI2RlZmluZSBTVFJF QU1fVE9fVUlOVDE2KHUxNiwgcCkge3UxNiA9ICgodWludDE2X3QpKCoocCkpICsgKCgodWludDE2 X3QpKCooKHApICsgMSkpKSA8PCA4KSk7IFwKCQkocCkgKz0gMjt9CiNkZWZpbmUgVUlOVDhfVE9f U1RSRUFNKHAsIHU4KSAgIHsqKHApKysgPSAodWludDhfdCkodTgpO30KI2RlZmluZSBVSU5UMTZf VE9fU1RSRUFNKHAsIHUxNikgeyoocCkrKyA9ICh1aW50OF90KSh1MTYpOyAqKHApKysgPSAodWlu dDhfdCkoKHUxNikgPj4gOCk7fQojZGVmaW5lIFVJTlQzMl9UT19TVFJFQU0ocCwgdTMyKSB7Kihw KSsrID0gKHVpbnQ4X3QpKHUzMik7ICoocCkrKyA9ICh1a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hdWQocF9jZmctPmJhdWQsICZiYXVkKTsKCiAgICBpZihw X2NmZy0+Zm10ICYgVVNFUklBTF9EQVRBQklUU184KQogICAgICAgIGRhdGFfYml0cyA9IENTODsK ICAgIGVsc2UgaWYocF9jZmctPmZtdCAmIFVTRVJJQUxfREFUQUJJVFNfNykKICAgICAgICBkYXRh X2JpdHMgPSBDUzc7CiAgICBlbHNlIGlmKHBfY2ZnLT5mbXQgJiBVU0VSSUFMX0RBVEFCSVRTXzYp CiAgICAgICAgZGF0YV9iaXRzID0gQ1M2OwogICAgZWxzZSBpZihwX2NmZy0+Zm10ICYgVVNFUklB TF9EQVRBQklUU181KQogICAgICAgIGRhdGFfYml0cyA9IENTNTsKICAgIGVsc2UKICAgICAgICBy ZXR1cm4gLTE7CgogICAgaWYocF9jZmctPmZtdCAmIFVTRVJJQUxfUEFSSVRZX05PTkUpCiAgICAg ICAgcGFyaXR5ID0gMDsKICAgIGVsc2UgaWYocF9jZmctPmZtdCAmIFVTRVJJQUxfUEFSSVRZX0VW RU4pCiAgICAgICAgcGFyaXR5ID0gUEFSRU5COwogICAgZWxzZSBpZihwX2NmZy0+Zm10ICYgVVNF UklBTF9QQVJJVFlfT0REKQogICAgICAgIHBhcml0eSA9IChQQVJFTkIgfCBQQVJPREQpOwogICAg ZWxzZQogICAgICAgIHJldHVybiAtMTsKCiAgICBpZihwX2NmZy0+Zm10ICYgVVNFUklBTF9TVE9Q QklUU18xKQogICAgICAgIHN0b3BfYml0cyA9IDA7CiAgICBlbHNlIGlmKHBfY2ZnLT5mbXQgJiBV U0VSSUFMX1NUT1BCSVRTXzIpCiAgICAgICAgc3RvcF9iaXRzID0gQ1NUT1BCOwogICAgZWxzZQog ICAgICAgIHJldHVybiAtMTsKCiAgICBwcmludGYoInVzZXJpYWwgdmVuZG9yIG9wZW46IG9wZW5p bmcgJXNcbiIsIHZuZF91c2VyaWFsLnBvcnRfbmFtZSk7CgogICAgaWYgKCh2bmRfdXNlcmlhbC5m ZCA9IG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