hci_intel.c 32 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319
  1. /*
  2. *
  3. * Bluetooth HCI UART driver for Intel devices
  4. *
  5. * Copyright (C) 2015 Intel Corporation
  6. *
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  21. *
  22. */
  23. #include <linux/kernel.h>
  24. #include <linux/errno.h>
  25. #include <linux/skbuff.h>
  26. #include <linux/firmware.h>
  27. #include <linux/module.h>
  28. #include <linux/wait.h>
  29. #include <linux/tty.h>
  30. #include <linux/platform_device.h>
  31. #include <linux/gpio/consumer.h>
  32. #include <linux/acpi.h>
  33. #include <linux/interrupt.h>
  34. #include <linux/pm_runtime.h>
  35. #include <net/bluetooth/bluetooth.h>
  36. #include <net/bluetooth/hci_core.h>
  37. #include "hci_uart.h"
  38. #include "btintel.h"
  39. #define STATE_BOOTLOADER 0
  40. #define STATE_DOWNLOADING 1
  41. #define STATE_FIRMWARE_LOADED 2
  42. #define STATE_FIRMWARE_FAILED 3
  43. #define STATE_BOOTING 4
  44. #define STATE_LPM_ENABLED 5
  45. #define STATE_TX_ACTIVE 6
  46. #define STATE_SUSPENDED 7
  47. #define STATE_LPM_TRANSACTION 8
  48. #define HCI_LPM_WAKE_PKT 0xf0
  49. #define HCI_LPM_PKT 0xf1
  50. #define HCI_LPM_MAX_SIZE 10
  51. #define HCI_LPM_HDR_SIZE HCI_EVENT_HDR_SIZE
  52. #define LPM_OP_TX_NOTIFY 0x00
  53. #define LPM_OP_SUSPEND_ACK 0x02
  54. #define LPM_OP_RESUME_ACK 0x03
  55. #define LPM_SUSPEND_DELAY_MS 1000
  56. struct hci_lpm_pkt {
  57. __u8 opcode;
  58. __u8 dlen;
  59. __u8 data[0];
  60. } __packed;
  61. struct intel_device {
  62. struct list_head list;
  63. struct platform_device *pdev;
  64. struct gpio_desc *reset;
  65. struct hci_uart *hu;
  66. struct mutex hu_lock;
  67. int irq;
  68. };
  69. static LIST_HEAD(intel_device_list);
  70. static DEFINE_MUTEX(intel_device_list_lock);
  71. struct intel_data {
  72. struct sk_buff *rx_skb;
  73. struct sk_buff_head txq;
  74. struct work_struct busy_work;
  75. struct hci_uart *hu;
  76. unsigned long flags;
  77. };
  78. static u8 intel_convert_speed(unsigned int speed)
  79. {
  80. switch (speed) {
  81. case 9600:
  82. return 0x00;
  83. case 19200:
  84. return 0x01;
  85. case 38400:
  86. return 0x02;
  87. case 57600:
  88. return 0x03;
  89. case 115200:
  90. return 0x04;
  91. case 230400:
  92. return 0x05;
  93. case 460800:
  94. return 0x06;
  95. case 921600:
  96. return 0x07;
  97. case 1843200:
  98. return 0x08;
  99. case 3250000:
  100. return 0x09;
  101. case 2000000:
  102. return 0x0a;
  103. case 3000000:
  104. return 0x0b;
  105. default:
  106. return 0xff;
  107. }
  108. }
  109. static int intel_wait_booting(struct hci_uart *hu)
  110. {
  111. struct intel_data *intel = hu->priv;
  112. int err;
  113. err = wait_on_bit_timeout(&intel->flags, STATE_BOOTING,
  114. TASK_INTERRUPTIBLE,
  115. msecs_to_jiffies(1000));
  116. if (err == 1) {
  117. bt_dev_err(hu->hdev, "Device boot interrupted");
  118. return -EINTR;
  119. }
  120. if (err) {
  121. bt_dev_err(hu->hdev, "Device boot timeout");
  122. return -ETIMEDOUT;
  123. }
  124. return err;
  125. }
  126. #ifdef CONFIG_PM
  127. static int intel_wait_lpm_transaction(struct hci_uart *hu)
  128. {
  129. struct intel_data *intel = hu->priv;
  130. int err;
  131. err = wait_on_bit_timeout(&intel->flags, STATE_LPM_TRANSACTION,
  132. TASK_INTERRUPTIBLE,
  133. msecs_to_jiffies(1000));
  134. if (err == 1) {
  135. bt_dev_err(hu->hdev, "LPM transaction interrupted");
  136. return -EINTR;
  137. }
  138. if (err) {
  139. bt_dev_err(hu->hdev, "LPM transaction timeout");
  140. return -ETIMEDOUT;
  141. }
  142. return err;
  143. }
  144. static int intel_lpm_suspend(struct hci_uart *hu)
  145. {
  146. static const u8 suspend[] = { 0x01, 0x01, 0x01 };
  147. struct intel_data *intel = hu->priv;
  148. struct sk_buff *skb;
  149. if (!test_bit(STATE_LPM_ENABLED, &intel->flags) ||
  150. test_bit(STATE_SUSPENDED, &intel->flags))
  151. return 0;
  152. if (test_bit(STATE_TX_ACTIVE, &intel->flags))
  153. return -EAGAIN;
  154. bt_dev_dbg(hu->hdev, "Suspending");
  155. skb = bt_skb_alloc(sizeof(suspend), GFP_KERNEL);
  156. if (!skb) {
  157. bt_dev_err(hu->hdev, "Failed to alloc memory for LPM packet");
  158. return -ENOMEM;
  159. }
  160. memcpy(skb_put(skb, sizeof(suspend)), suspend, sizeof(suspend));
  161. hci_skb_pkt_type(skb) = HCI_LPM_PKT;
  162. set_bit(STATE_LPM_TRANSACTION, &intel->flags);
  163. /* LPM flow is a priority, enqueue packet at list head */
  164. skb_queue_head(&intel->txq, skb);
  165. hci_uart_tx_wakeup(hu);
  166. intel_wait_lpm_transaction(hu);
  167. /* Even in case of failure, continue and test the suspended flag */
  168. clear_bit(STATE_LPM_TRANSACTION, &intel->flags);
  169. if (!test_bit(STATE_SUSPENDED, &intel->flags)) {
  170. bt_dev_err(hu->hdev, "Device suspend error");
  171. return -EINVAL;
  172. }
  173. bt_dev_dbg(hu->hdev, "Suspended");
  174. hci_uart_set_flow_control(hu, true);
  175. return 0;
  176. }
  177. static int intel_lpm_resume(struct hci_uart *hu)
  178. {
  179. struct intel_data *intel = hu->priv;
  180. struct sk_buff *skb;
  181. if (!test_bit(STATE_LPM_ENABLED, &intel->flags) ||
  182. !test_bit(STATE_SUSPENDED, &intel->flags))
  183. return 0;
  184. bt_dev_dbg(hu->hdev, "Resuming");
  185. hci_uart_set_flow_control(hu, false);
  186. skb = bt_skb_alloc(0, GFP_KERNEL);
  187. if (!skb) {
  188. bt_dev_err(hu->hdev, "Failed to alloc memory for LPM packet");
  189. return -ENOMEM;
  190. }
  191. hci_skb_pkt_type(skb) = HCI_LPM_WAKE_PKT;
  192. set_bit(STATE_LPM_TRANSACTION, &intel->flags);
  193. /* LPM flow is a priority, enqueue packet at list head */
  194. skb_queue_head(&intel->txq, skb);
  195. hci_uart_tx_wakeup(hu);
  196. intel_wait_lpm_transaction(hu);
  197. /* Even in case of failure, continue and test the suspended flag */
  198. clear_bit(STATE_LPM_TRANSACTION, &intel->flags);
  199. if (test_bit(STATE_SUSPENDED, &intel->flags)) {
  200. bt_dev_err(hu->hdev, "Device resume error");
  201. return -EINVAL;
  202. }
  203. bt_dev_dbg(hu->hdev, "Resumed");
  204. return 0;
  205. }
  206. #endif /* CONFIG_PM */
  207. static int intel_lpm_host_wake(struct hci_uart *hu)
  208. {
  209. static const u8 lpm_resume_ack[] = { LPM_OP_RESUME_ACK, 0x00 };
  210. struct intel_data *intel = hu->priv;
  211. struct sk_buff *skb;
  212. hci_uart_set_flow_control(hu, false);
  213. clear_bit(STATE_SUSPENDED, &intel->flags);
  214. skb = bt_skb_alloc(sizeof(lpm_resume_ack), GFP_KERNEL);
  215. if (!skb) {
  216. bt_dev_err(hu->hdev, "Failed to alloc memory for LPM packet");
  217. return -ENOMEM;
  218. }
  219. memcpy(skb_put(skb, sizeof(lpm_resume_ack)), lpm_resume_ack,
  220. sizeof(lpm_resume_ack));
  221. hci_skb_pkt_type(skb) = HCI_LPM_PKT;
  222. /* LPM flow is a priority, enqueue packet at list head */
  223. skb_queue_head(&intel->txq, skb);
  224. hci_uart_tx_wakeup(hu);
  225. bt_dev_dbg(hu->hdev, "Resumed by controller");
  226. return 0;
  227. }
  228. static irqreturn_t intel_irq(int irq, void *dev_id)
  229. {
  230. struct intel_device *idev = dev_id;
  231. dev_info(&idev->pdev->dev, "hci_intel irq\n");
  232. mutex_lock(&idev->hu_lock);
  233. if (idev->hu)
  234. intel_lpm_host_wake(idev->hu);
  235. mutex_unlock(&idev->hu_lock);
  236. /* Host/Controller are now LPM resumed, trigger a new delayed suspend */
  237. pm_runtime_get(&idev->pdev->dev);
  238. pm_runtime_mark_last_busy(&idev->pdev->dev);
  239. pm_runtime_put_autosuspend(&idev->pdev->dev);
  240. return IRQ_HANDLED;
  241. }
  242. static int intel_set_power(struct hci_uart *hu, bool powered)
  243. {
  244. struct list_head *p;
  245. int err = -ENODEV;
  246. mutex_lock(&intel_device_list_lock);
  247. list_for_each(p, &intel_device_list) {
  248. struct intel_device *idev = list_entry(p, struct intel_device,
  249. list);
  250. /* tty device and pdev device should share the same parent
  251. * which is the UART port.
  252. */
  253. if (hu->tty->dev->parent != idev->pdev->dev.parent)
  254. continue;
  255. if (!idev->reset) {
  256. err = -ENOTSUPP;
  257. break;
  258. }
  259. BT_INFO("hu %p, Switching compatible pm device (%s) to %u",
  260. hu, dev_name(&idev->pdev->dev), powered);
  261. gpiod_set_value(idev->reset, powered);
  262. /* Provide to idev a hu reference which is used to run LPM
  263. * transactions (lpm suspend/resume) from PM callbacks.
  264. * hu needs to be protected against concurrent removing during
  265. * these PM ops.
  266. */
  267. mutex_lock(&idev->hu_lock);
  268. idev->hu = powered ? hu : NULL;
  269. mutex_unlock(&idev->hu_lock);
  270. if (idev->irq < 0)
  271. break;
  272. if (powered && device_can_wakeup(&idev->pdev->dev)) {
  273. err = devm_request_threaded_irq(&idev->pdev->dev,
  274. idev->irq, NULL,
  275. intel_irq,
  276. IRQF_ONESHOT,
  277. "bt-host-wake", idev);
  278. if (err) {
  279. BT_ERR("hu %p, unable to allocate irq-%d",
  280. hu, idev->irq);
  281. break;
  282. }
  283. device_wakeup_enable(&idev->pdev->dev);
  284. pm_runtime_set_active(&idev->pdev->dev);
  285. pm_runtime_use_autosuspend(&idev->pdev->dev);
  286. pm_runtime_set_autosuspend_delay(&idev->pdev->dev,
  287. LPM_SUSPEND_DELAY_MS);
  288. pm_runtime_enable(&idev->pdev->dev);
  289. } else if (!powered && device_may_wakeup(&idev->pdev->dev)) {
  290. devm_free_irq(&idev->pdev->dev, idev->irq, idev);
  291. device_wakeup_disable(&idev->pdev->dev);
  292. pm_runtime_disable(&idev->pdev->dev);
  293. }
  294. }
  295. mutex_unlock(&intel_device_list_lock);
  296. return err;
  297. }
  298. static void intel_busy_work(struct work_struct *work)
  299. {
  300. struct list_head *p;
  301. struct intel_data *intel = container_of(work, struct intel_data,
  302. busy_work);
  303. /* Link is busy, delay the suspend */
  304. mutex_lock(&intel_device_list_lock);
  305. list_for_each(p, &intel_device_list) {
  306. struct intel_device *idev = list_entry(p, struct intel_device,
  307. list);
  308. if (intel->hu->tty->dev->parent == idev->pdev->dev.parent) {
  309. pm_runtime_get(&idev->pdev->dev);
  310. pm_runtime_mark_last_busy(&idev->pdev->dev);
  311. pm_runtime_put_autosuspend(&idev->pdev->dev);
  312. break;
  313. }
  314. }
  315. mutex_unlock(&intel_device_list_lock);
  316. }
  317. static int intel_open(struct hci_uart *hu)
  318. {
  319. struct intel_data *intel;
  320. BT_DBG("hu %p", hu);
  321. intel = kzalloc(sizeof(*intel), GFP_KERNEL);
  322. if (!intel)
  323. return -ENOMEM;
  324. skb_queue_head_init(&intel->txq);
  325. INIT_WORK(&intel->busy_work, intel_busy_work);
  326. intel->hu = hu;
  327. hu->priv = intel;
  328. if (!intel_set_power(hu, true))
  329. set_bit(STATE_BOOTING, &intel->flags);
  330. return 0;
  331. }
  332. static int intel_close(struct hci_uart *hu)
  333. {
  334. struct intel_data *intel = hu->priv;
  335. BT_DBG("hu %p", hu);
  336. cancel_work_sync(&intel->busy_work);
  337. intel_set_power(hu, false);
  338. skb_queue_purge(&intel->txq);
  339. kfree_skb(intel->rx_skb);
  340. kfree(intel);
  341. hu->priv = NULL;
  342. return 0;
  343. }
  344. static int intel_flush(struct hci_uart *hu)
  345. {
  346. struct intel_data *intel = hu->priv;
  347. BT_DBG("hu %p", hu);
  348. skb_queue_purge(&intel->txq);
  349. return 0;
  350. }
  351. static int inject_cmd_complete(struct hci_dev *hdev, __u16 opcode)
  352. {
  353. struct sk_buff *skb;
  354. struct hci_event_hdr *hdr;
  355. struct hci_ev_cmd_complete *evt;
  356. skb = bt_skb_alloc(sizeof(*hdr) + sizeof(*evt) + 1, GFP_ATOMIC);
  357. if (!skb)
  358. return -ENOMEM;
  359. hdr = (struct hci_event_hdr *)skb_put(skb, sizeof(*hdr));
  360. hdr->evt = HCI_EV_CMD_COMPLETE;
  361. hdr->plen = sizeof(*evt) + 1;
  362. evt = (struct hci_ev_cmd_complete *)skb_put(skb, sizeof(*evt));
  363. evt->ncmd = 0x01;
  364. evt->opcode = cpu_to_le16(opcode);
  365. *skb_put(skb, 1) = 0x00;
  366. hci_skb_pkt_type(skb) = HCI_EVENT_PKT;
  367. return hci_recv_frame(hdev, skb);
  368. }
  369. static int intel_set_baudrate(struct hci_uart *hu, unsigned int speed)
  370. {
  371. struct intel_data *intel = hu->priv;
  372. struct hci_dev *hdev = hu->hdev;
  373. u8 speed_cmd[] = { 0x06, 0xfc, 0x01, 0x00 };
  374. struct sk_buff *skb;
  375. int err;
  376. /* This can be the first command sent to the chip, check
  377. * that the controller is ready.
  378. */
  379. err = intel_wait_booting(hu);
  380. clear_bit(STATE_BOOTING, &intel->flags);
  381. /* In case of timeout, try to continue anyway */
  382. if (err && err != ETIMEDOUT)
  383. return err;
  384. bt_dev_info(hdev, "Change controller speed to %d", speed);
  385. speed_cmd[3] = intel_convert_speed(speed);
  386. if (speed_cmd[3] == 0xff) {
  387. bt_dev_err(hdev, "Unsupported speed");
  388. return -EINVAL;
  389. }
  390. /* Device will not accept speed change if Intel version has not been
  391. * previously requested.
  392. */
  393. skb = __hci_cmd_sync(hdev, 0xfc05, 0, NULL, HCI_INIT_TIMEOUT);
  394. if (IS_ERR(skb)) {
  395. bt_dev_err(hdev, "Reading Intel version information failed (%ld)",
  396. PTR_ERR(skb));
  397. return PTR_ERR(skb);
  398. }
  399. kfree_skb(skb);
  400. skb = bt_skb_alloc(sizeof(speed_cmd), GFP_KERNEL);
  401. if (!skb) {
  402. bt_dev_err(hdev, "Failed to alloc memory for baudrate packet");
  403. return -ENOMEM;
  404. }
  405. memcpy(skb_put(skb, sizeof(speed_cmd)), speed_cmd, sizeof(speed_cmd));
  406. hci_skb_pkt_type(skb) = HCI_COMMAND_PKT;
  407. hci_uart_set_flow_control(hu, true);
  408. skb_queue_tail(&intel->txq, skb);
  409. hci_uart_tx_wakeup(hu);
  410. /* wait 100ms to change baudrate on controller side */
  411. msleep(100);
  412. hci_uart_set_baudrate(hu, speed);
  413. hci_uart_set_flow_control(hu, false);
  414. return 0;
  415. }
  416. static int intel_setup(struct hci_uart *hu)
  417. {
  418. static const u8 reset_param[] = { 0x00, 0x01, 0x00, 0x01,
  419. 0x00, 0x08, 0x04, 0x00 };
  420. static const u8 lpm_param[] = { 0x03, 0x07, 0x01, 0x0b };
  421. struct intel_data *intel = hu->priv;
  422. struct intel_device *idev = NULL;
  423. struct hci_dev *hdev = hu->hdev;
  424. struct sk_buff *skb;
  425. struct intel_version *ver;
  426. struct intel_boot_params *params;
  427. struct list_head *p;
  428. const struct firmware *fw;
  429. const u8 *fw_ptr;
  430. char fwname[64];
  431. u32 frag_len;
  432. ktime_t calltime, delta, rettime;
  433. unsigned long long duration;
  434. unsigned int init_speed, oper_speed;
  435. int speed_change = 0;
  436. int err;
  437. bt_dev_dbg(hdev, "start intel_setup");
  438. hu->hdev->set_diag = btintel_set_diag;
  439. hu->hdev->set_bdaddr = btintel_set_bdaddr;
  440. calltime = ktime_get();
  441. if (hu->init_speed)
  442. init_speed = hu->init_speed;
  443. else
  444. init_speed = hu->proto->init_speed;
  445. if (hu->oper_speed)
  446. oper_speed = hu->oper_speed;
  447. else
  448. oper_speed = hu->proto->oper_speed;
  449. if (oper_speed && init_speed && oper_speed != init_speed)
  450. speed_change = 1;
  451. /* Check that the controller is ready */
  452. err = intel_wait_booting(hu);
  453. clear_bit(STATE_BOOTING, &intel->flags);
  454. /* In case of timeout, try to continue anyway */
  455. if (err && err != ETIMEDOUT)
  456. return err;
  457. set_bit(STATE_BOOTLOADER, &intel->flags);
  458. /* Read the Intel version information to determine if the device
  459. * is in bootloader mode or if it already has operational firmware
  460. * loaded.
  461. */
  462. skb = __hci_cmd_sync(hdev, 0xfc05, 0, NULL, HCI_INIT_TIMEOUT);
  463. if (IS_ERR(skb)) {
  464. bt_dev_err(hdev, "Reading Intel version information failed (%ld)",
  465. PTR_ERR(skb));
  466. return PTR_ERR(skb);
  467. }
  468. if (skb->len != sizeof(*ver)) {
  469. bt_dev_err(hdev, "Intel version event size mismatch");
  470. kfree_skb(skb);
  471. return -EILSEQ;
  472. }
  473. ver = (struct intel_version *)skb->data;
  474. if (ver->status) {
  475. bt_dev_err(hdev, "Intel version command failure (%02x)",
  476. ver->status);
  477. err = -bt_to_errno(ver->status);
  478. kfree_skb(skb);
  479. return err;
  480. }
  481. /* The hardware platform number has a fixed value of 0x37 and
  482. * for now only accept this single value.
  483. */
  484. if (ver->hw_platform != 0x37) {
  485. bt_dev_err(hdev, "Unsupported Intel hardware platform (%u)",
  486. ver->hw_platform);
  487. kfree_skb(skb);
  488. return -EINVAL;
  489. }
  490. /* At the moment only the hardware variant iBT 3.0 (LnP/SfP) is
  491. * supported by this firmware loading method. This check has been
  492. * put in place to ensure correct forward compatibility options
  493. * when newer hardware variants come along.
  494. */
  495. if (ver->hw_variant != 0x0b) {
  496. bt_dev_err(hdev, "Unsupported Intel hardware variant (%u)",
  497. ver->hw_variant);
  498. kfree_skb(skb);
  499. return -EINVAL;
  500. }
  501. btintel_version_info(hdev, ver);
  502. /* The firmware variant determines if the device is in bootloader
  503. * mode or is running operational firmware. The value 0x06 identifies
  504. * the bootloader and the value 0x23 identifies the operational
  505. * firmware.
  506. *
  507. * When the operational firmware is already present, then only
  508. * the check for valid Bluetooth device address is needed. This
  509. * determines if the device will be added as configured or
  510. * unconfigured controller.
  511. *
  512. * It is not possible to use the Secure Boot Parameters in this
  513. * case since that command is only available in bootloader mode.
  514. */
  515. if (ver->fw_variant == 0x23) {
  516. kfree_skb(skb);
  517. clear_bit(STATE_BOOTLOADER, &intel->flags);
  518. btintel_check_bdaddr(hdev);
  519. return 0;
  520. }
  521. /* If the device is not in bootloader mode, then the only possible
  522. * choice is to return an error and abort the device initialization.
  523. */
  524. if (ver->fw_variant != 0x06) {
  525. bt_dev_err(hdev, "Unsupported Intel firmware variant (%u)",
  526. ver->fw_variant);
  527. kfree_skb(skb);
  528. return -ENODEV;
  529. }
  530. kfree_skb(skb);
  531. /* Read the secure boot parameters to identify the operating
  532. * details of the bootloader.
  533. */
  534. skb = __hci_cmd_sync(hdev, 0xfc0d, 0, NULL, HCI_INIT_TIMEOUT);
  535. if (IS_ERR(skb)) {
  536. bt_dev_err(hdev, "Reading Intel boot parameters failed (%ld)",
  537. PTR_ERR(skb));
  538. return PTR_ERR(skb);
  539. }
  540. if (skb->len != sizeof(*params)) {
  541. bt_dev_err(hdev, "Intel boot parameters size mismatch");
  542. kfree_skb(skb);
  543. return -EILSEQ;
  544. }
  545. params = (struct intel_boot_params *)skb->data;
  546. if (params->status) {
  547. bt_dev_err(hdev, "Intel boot parameters command failure (%02x)",
  548. params->status);
  549. err = -bt_to_errno(params->status);
  550. kfree_skb(skb);
  551. return err;
  552. }
  553. bt_dev_info(hdev, "Device revision is %u",
  554. le16_to_cpu(params->dev_revid));
  555. bt_dev_info(hdev, "Secure boot is %s",
  556. params->secure_boot ? "enabled" : "disabled");
  557. bt_dev_info(hdev, "Minimum firmware build %u week %u %u",
  558. params->min_fw_build_nn, params->min_fw_build_cw,
  559. 2000 + params->min_fw_build_yy);
  560. /* It is required that every single firmware fragment is acknowledged
  561. * with a command complete event. If the boot parameters indicate
  562. * that this bootloader does not send them, then abort the setup.
  563. */
  564. if (params->limited_cce != 0x00) {
  565. bt_dev_err(hdev, "Unsupported Intel firmware loading method (%u)",
  566. params->limited_cce);
  567. kfree_skb(skb);
  568. return -EINVAL;
  569. }
  570. /* If the OTP has no valid Bluetooth device address, then there will
  571. * also be no valid address for the operational firmware.
  572. */
  573. if (!bacmp(&params->otp_bdaddr, BDADDR_ANY)) {
  574. bt_dev_info(hdev, "No device address configured");
  575. set_bit(HCI_QUIRK_INVALID_BDADDR, &hdev->quirks);
  576. }
  577. /* With this Intel bootloader only the hardware variant and device
  578. * revision information are used to select the right firmware.
  579. *
  580. * Currently this bootloader support is limited to hardware variant
  581. * iBT 3.0 (LnP/SfP) which is identified by the value 11 (0x0b).
  582. */
  583. snprintf(fwname, sizeof(fwname), "intel/ibt-11-%u.sfi",
  584. le16_to_cpu(params->dev_revid));
  585. err = request_firmware(&fw, fwname, &hdev->dev);
  586. if (err < 0) {
  587. bt_dev_err(hdev, "Failed to load Intel firmware file (%d)",
  588. err);
  589. kfree_skb(skb);
  590. return err;
  591. }
  592. bt_dev_info(hdev, "Found device firmware: %s", fwname);
  593. /* Save the DDC file name for later */
  594. snprintf(fwname, sizeof(fwname), "intel/ibt-11-%u.ddc",
  595. le16_to_cpu(params->dev_revid));
  596. kfree_skb(skb);
  597. if (fw->size < 644) {
  598. bt_dev_err(hdev, "Invalid size of firmware file (%zu)",
  599. fw->size);
  600. err = -EBADF;
  601. goto done;
  602. }
  603. set_bit(STATE_DOWNLOADING, &intel->flags);
  604. /* Start the firmware download transaction with the Init fragment
  605. * represented by the 128 bytes of CSS header.
  606. */
  607. err = btintel_secure_send(hdev, 0x00, 128, fw->data);
  608. if (err < 0) {
  609. bt_dev_err(hdev, "Failed to send firmware header (%d)", err);
  610. goto done;
  611. }
  612. /* Send the 256 bytes of public key information from the firmware
  613. * as the PKey fragment.
  614. */
  615. err = btintel_secure_send(hdev, 0x03, 256, fw->data + 128);
  616. if (err < 0) {
  617. bt_dev_err(hdev, "Failed to send firmware public key (%d)",
  618. err);
  619. goto done;
  620. }
  621. /* Send the 256 bytes of signature information from the firmware
  622. * as the Sign fragment.
  623. */
  624. err = btintel_secure_send(hdev, 0x02, 256, fw->data + 388);
  625. if (err < 0) {
  626. bt_dev_err(hdev, "Failed to send firmware signature (%d)",
  627. err);
  628. goto done;
  629. }
  630. fw_ptr = fw->data + 644;
  631. frag_len = 0;
  632. while (fw_ptr - fw->data < fw->size) {
  633. struct hci_command_hdr *cmd = (void *)(fw_ptr + frag_len);
  634. frag_len += sizeof(*cmd) + cmd->plen;
  635. bt_dev_dbg(hdev, "Patching %td/%zu", (fw_ptr - fw->data),
  636. fw->size);
  637. /* The parameter length of the secure send command requires
  638. * a 4 byte alignment. It happens so that the firmware file
  639. * contains proper Intel_NOP commands to align the fragments
  640. * as needed.
  641. *
  642. * Send set of commands with 4 byte alignment from the
  643. * firmware data buffer as a single Data fragement.
  644. */
  645. if (frag_len % 4)
  646. continue;
  647. /* Send each command from the firmware data buffer as
  648. * a single Data fragment.
  649. */
  650. err = btintel_secure_send(hdev, 0x01, frag_len, fw_ptr);
  651. if (err < 0) {
  652. bt_dev_err(hdev, "Failed to send firmware data (%d)",
  653. err);
  654. goto done;
  655. }
  656. fw_ptr += frag_len;
  657. frag_len = 0;
  658. }
  659. set_bit(STATE_FIRMWARE_LOADED, &intel->flags);
  660. bt_dev_info(hdev, "Waiting for firmware download to complete");
  661. /* Before switching the device into operational mode and with that
  662. * booting the loaded firmware, wait for the bootloader notification
  663. * that all fragments have been successfully received.
  664. *
  665. * When the event processing receives the notification, then the
  666. * STATE_DOWNLOADING flag will be cleared.
  667. *
  668. * The firmware loading should not take longer than 5 seconds
  669. * and thus just timeout if that happens and fail the setup
  670. * of this device.
  671. */
  672. err = wait_on_bit_timeout(&intel->flags, STATE_DOWNLOADING,
  673. TASK_INTERRUPTIBLE,
  674. msecs_to_jiffies(5000));
  675. if (err == 1) {
  676. bt_dev_err(hdev, "Firmware loading interrupted");
  677. err = -EINTR;
  678. goto done;
  679. }
  680. if (err) {
  681. bt_dev_err(hdev, "Firmware loading timeout");
  682. err = -ETIMEDOUT;
  683. goto done;
  684. }
  685. if (test_bit(STATE_FIRMWARE_FAILED, &intel->flags)) {
  686. bt_dev_err(hdev, "Firmware loading failed");
  687. err = -ENOEXEC;
  688. goto done;
  689. }
  690. rettime = ktime_get();
  691. delta = ktime_sub(rettime, calltime);
  692. duration = (unsigned long long) ktime_to_ns(delta) >> 10;
  693. bt_dev_info(hdev, "Firmware loaded in %llu usecs", duration);
  694. done:
  695. release_firmware(fw);
  696. if (err < 0)
  697. return err;
  698. /* We need to restore the default speed before Intel reset */
  699. if (speed_change) {
  700. err = intel_set_baudrate(hu, init_speed);
  701. if (err)
  702. return err;
  703. }
  704. calltime = ktime_get();
  705. set_bit(STATE_BOOTING, &intel->flags);
  706. skb = __hci_cmd_sync(hdev, 0xfc01, sizeof(reset_param), reset_param,
  707. HCI_INIT_TIMEOUT);
  708. if (IS_ERR(skb))
  709. return PTR_ERR(skb);
  710. kfree_skb(skb);
  711. /* The bootloader will not indicate when the device is ready. This
  712. * is done by the operational firmware sending bootup notification.
  713. *
  714. * Booting into operational firmware should not take longer than
  715. * 1 second. However if that happens, then just fail the setup
  716. * since something went wrong.
  717. */
  718. bt_dev_info(hdev, "Waiting for device to boot");
  719. err = intel_wait_booting(hu);
  720. if (err)
  721. return err;
  722. clear_bit(STATE_BOOTING, &intel->flags);
  723. rettime = ktime_get();
  724. delta = ktime_sub(rettime, calltime);
  725. duration = (unsigned long long) ktime_to_ns(delta) >> 10;
  726. bt_dev_info(hdev, "Device booted in %llu usecs", duration);
  727. /* Enable LPM if matching pdev with wakeup enabled */
  728. mutex_lock(&intel_device_list_lock);
  729. list_for_each(p, &intel_device_list) {
  730. struct intel_device *dev = list_entry(p, struct intel_device,
  731. list);
  732. if (hu->tty->dev->parent == dev->pdev->dev.parent) {
  733. if (device_may_wakeup(&dev->pdev->dev))
  734. idev = dev;
  735. break;
  736. }
  737. }
  738. mutex_unlock(&intel_device_list_lock);
  739. if (!idev)
  740. goto no_lpm;
  741. bt_dev_info(hdev, "Enabling LPM");
  742. skb = __hci_cmd_sync(hdev, 0xfc8b, sizeof(lpm_param), lpm_param,
  743. HCI_CMD_TIMEOUT);
  744. if (IS_ERR(skb)) {
  745. bt_dev_err(hdev, "Failed to enable LPM");
  746. goto no_lpm;
  747. }
  748. kfree_skb(skb);
  749. set_bit(STATE_LPM_ENABLED, &intel->flags);
  750. no_lpm:
  751. /* Ignore errors, device can work without DDC parameters */
  752. btintel_load_ddc_config(hdev, fwname);
  753. skb = __hci_cmd_sync(hdev, HCI_OP_RESET, 0, NULL, HCI_CMD_TIMEOUT);
  754. if (IS_ERR(skb))
  755. return PTR_ERR(skb);
  756. kfree_skb(skb);
  757. if (speed_change) {
  758. err = intel_set_baudrate(hu, oper_speed);
  759. if (err)
  760. return err;
  761. }
  762. bt_dev_info(hdev, "Setup complete");
  763. clear_bit(STATE_BOOTLOADER, &intel->flags);
  764. return 0;
  765. }
  766. static int intel_recv_event(struct hci_dev *hdev, struct sk_buff *skb)
  767. {
  768. struct hci_uart *hu = hci_get_drvdata(hdev);
  769. struct intel_data *intel = hu->priv;
  770. struct hci_event_hdr *hdr;
  771. if (!test_bit(STATE_BOOTLOADER, &intel->flags) &&
  772. !test_bit(STATE_BOOTING, &intel->flags))
  773. goto recv;
  774. hdr = (void *)skb->data;
  775. /* When the firmware loading completes the device sends
  776. * out a vendor specific event indicating the result of
  777. * the firmware loading.
  778. */
  779. if (skb->len == 7 && hdr->evt == 0xff && hdr->plen == 0x05 &&
  780. skb->data[2] == 0x06) {
  781. if (skb->data[3] != 0x00)
  782. set_bit(STATE_FIRMWARE_FAILED, &intel->flags);
  783. if (test_and_clear_bit(STATE_DOWNLOADING, &intel->flags) &&
  784. test_bit(STATE_FIRMWARE_LOADED, &intel->flags)) {
  785. smp_mb__after_atomic();
  786. wake_up_bit(&intel->flags, STATE_DOWNLOADING);
  787. }
  788. /* When switching to the operational firmware the device
  789. * sends a vendor specific event indicating that the bootup
  790. * completed.
  791. */
  792. } else if (skb->len == 9 && hdr->evt == 0xff && hdr->plen == 0x07 &&
  793. skb->data[2] == 0x02) {
  794. if (test_and_clear_bit(STATE_BOOTING, &intel->flags)) {
  795. smp_mb__after_atomic();
  796. wake_up_bit(&intel->flags, STATE_BOOTING);
  797. }
  798. }
  799. recv:
  800. return hci_recv_frame(hdev, skb);
  801. }
  802. static void intel_recv_lpm_notify(struct hci_dev *hdev, int value)
  803. {
  804. struct hci_uart *hu = hci_get_drvdata(hdev);
  805. struct intel_data *intel = hu->priv;
  806. bt_dev_dbg(hdev, "TX idle notification (%d)", value);
  807. if (value) {
  808. set_bit(STATE_TX_ACTIVE, &intel->flags);
  809. schedule_work(&intel->busy_work);
  810. } else {
  811. clear_bit(STATE_TX_ACTIVE, &intel->flags);
  812. }
  813. }
  814. static int intel_recv_lpm(struct hci_dev *hdev, struct sk_buff *skb)
  815. {
  816. struct hci_lpm_pkt *lpm = (void *)skb->data;
  817. struct hci_uart *hu = hci_get_drvdata(hdev);
  818. struct intel_data *intel = hu->priv;
  819. switch (lpm->opcode) {
  820. case LPM_OP_TX_NOTIFY:
  821. if (lpm->dlen < 1) {
  822. bt_dev_err(hu->hdev, "Invalid LPM notification packet");
  823. break;
  824. }
  825. intel_recv_lpm_notify(hdev, lpm->data[0]);
  826. break;
  827. case LPM_OP_SUSPEND_ACK:
  828. set_bit(STATE_SUSPENDED, &intel->flags);
  829. if (test_and_clear_bit(STATE_LPM_TRANSACTION, &intel->flags)) {
  830. smp_mb__after_atomic();
  831. wake_up_bit(&intel->flags, STATE_LPM_TRANSACTION);
  832. }
  833. break;
  834. case LPM_OP_RESUME_ACK:
  835. clear_bit(STATE_SUSPENDED, &intel->flags);
  836. if (test_and_clear_bit(STATE_LPM_TRANSACTION, &intel->flags)) {
  837. smp_mb__after_atomic();
  838. wake_up_bit(&intel->flags, STATE_LPM_TRANSACTION);
  839. }
  840. break;
  841. default:
  842. bt_dev_err(hdev, "Unknown LPM opcode (%02x)", lpm->opcode);
  843. break;
  844. }
  845. kfree_skb(skb);
  846. return 0;
  847. }
  848. #define INTEL_RECV_LPM \
  849. .type = HCI_LPM_PKT, \
  850. .hlen = HCI_LPM_HDR_SIZE, \
  851. .loff = 1, \
  852. .lsize = 1, \
  853. .maxlen = HCI_LPM_MAX_SIZE
  854. static const struct h4_recv_pkt intel_recv_pkts[] = {
  855. { H4_RECV_ACL, .recv = hci_recv_frame },
  856. { H4_RECV_SCO, .recv = hci_recv_frame },
  857. { H4_RECV_EVENT, .recv = intel_recv_event },
  858. { INTEL_RECV_LPM, .recv = intel_recv_lpm },
  859. };
  860. static int intel_recv(struct hci_uart *hu, const void *data, int count)
  861. {
  862. struct intel_data *intel = hu->priv;
  863. if (!test_bit(HCI_UART_REGISTERED, &hu->flags))
  864. return -EUNATCH;
  865. intel->rx_skb = h4_recv_buf(hu->hdev, intel->rx_skb, data, count,
  866. intel_recv_pkts,
  867. ARRAY_SIZE(intel_recv_pkts));
  868. if (IS_ERR(intel->rx_skb)) {
  869. int err = PTR_ERR(intel->rx_skb);
  870. bt_dev_err(hu->hdev, "Frame reassembly failed (%d)", err);
  871. intel->rx_skb = NULL;
  872. return err;
  873. }
  874. return count;
  875. }
  876. static int intel_enqueue(struct hci_uart *hu, struct sk_buff *skb)
  877. {
  878. struct intel_data *intel = hu->priv;
  879. struct list_head *p;
  880. BT_DBG("hu %p skb %p", hu, skb);
  881. /* Be sure our controller is resumed and potential LPM transaction
  882. * completed before enqueuing any packet.
  883. */
  884. mutex_lock(&intel_device_list_lock);
  885. list_for_each(p, &intel_device_list) {
  886. struct intel_device *idev = list_entry(p, struct intel_device,
  887. list);
  888. if (hu->tty->dev->parent == idev->pdev->dev.parent) {
  889. pm_runtime_get_sync(&idev->pdev->dev);
  890. pm_runtime_mark_last_busy(&idev->pdev->dev);
  891. pm_runtime_put_autosuspend(&idev->pdev->dev);
  892. break;
  893. }
  894. }
  895. mutex_unlock(&intel_device_list_lock);
  896. skb_queue_tail(&intel->txq, skb);
  897. return 0;
  898. }
  899. static struct sk_buff *intel_dequeue(struct hci_uart *hu)
  900. {
  901. struct intel_data *intel = hu->priv;
  902. struct sk_buff *skb;
  903. skb = skb_dequeue(&intel->txq);
  904. if (!skb)
  905. return skb;
  906. if (test_bit(STATE_BOOTLOADER, &intel->flags) &&
  907. (hci_skb_pkt_type(skb) == HCI_COMMAND_PKT)) {
  908. struct hci_command_hdr *cmd = (void *)skb->data;
  909. __u16 opcode = le16_to_cpu(cmd->opcode);
  910. /* When the 0xfc01 command is issued to boot into
  911. * the operational firmware, it will actually not
  912. * send a command complete event. To keep the flow
  913. * control working inject that event here.
  914. */
  915. if (opcode == 0xfc01)
  916. inject_cmd_complete(hu->hdev, opcode);
  917. }
  918. /* Prepend skb with frame type */
  919. memcpy(skb_push(skb, 1), &hci_skb_pkt_type(skb), 1);
  920. return skb;
  921. }
  922. static const struct hci_uart_proto intel_proto = {
  923. .id = HCI_UART_INTEL,
  924. .name = "Intel",
  925. .manufacturer = 2,
  926. .init_speed = 115200,
  927. .oper_speed = 3000000,
  928. .open = intel_open,
  929. .close = intel_close,
  930. .flush = intel_flush,
  931. .setup = intel_setup,
  932. .set_baudrate = intel_set_baudrate,
  933. .recv = intel_recv,
  934. .enqueue = intel_enqueue,
  935. .dequeue = intel_dequeue,
  936. };
  937. #ifdef CONFIG_ACPI
  938. static const struct acpi_device_id intel_acpi_match[] = {
  939. { "INT33E1", 0 },
  940. { },
  941. };
  942. MODULE_DEVICE_TABLE(acpi, intel_acpi_match);
  943. #endif
  944. #ifdef CONFIG_PM
  945. static int intel_suspend_device(struct device *dev)
  946. {
  947. struct intel_device *idev = dev_get_drvdata(dev);
  948. mutex_lock(&idev->hu_lock);
  949. if (idev->hu)
  950. intel_lpm_suspend(idev->hu);
  951. mutex_unlock(&idev->hu_lock);
  952. return 0;
  953. }
  954. static int intel_resume_device(struct device *dev)
  955. {
  956. struct intel_device *idev = dev_get_drvdata(dev);
  957. mutex_lock(&idev->hu_lock);
  958. if (idev->hu)
  959. intel_lpm_resume(idev->hu);
  960. mutex_unlock(&idev->hu_lock);
  961. return 0;
  962. }
  963. #endif
  964. #ifdef CONFIG_PM_SLEEP
  965. static int intel_suspend(struct device *dev)
  966. {
  967. struct intel_device *idev = dev_get_drvdata(dev);
  968. if (device_may_wakeup(dev))
  969. enable_irq_wake(idev->irq);
  970. return intel_suspend_device(dev);
  971. }
  972. static int intel_resume(struct device *dev)
  973. {
  974. struct intel_device *idev = dev_get_drvdata(dev);
  975. if (device_may_wakeup(dev))
  976. disable_irq_wake(idev->irq);
  977. return intel_resume_device(dev);
  978. }
  979. #endif
  980. static const struct dev_pm_ops intel_pm_ops = {
  981. SET_SYSTEM_SLEEP_PM_OPS(intel_suspend, intel_resume)
  982. SET_RUNTIME_PM_OPS(intel_suspend_device, intel_resume_device, NULL)
  983. };
  984. static int intel_probe(struct platform_device *pdev)
  985. {
  986. struct intel_device *idev;
  987. idev = devm_kzalloc(&pdev->dev, sizeof(*idev), GFP_KERNEL);
  988. if (!idev)
  989. return -ENOMEM;
  990. mutex_init(&idev->hu_lock);
  991. idev->pdev = pdev;
  992. idev->reset = devm_gpiod_get_optional(&pdev->dev, "reset",
  993. GPIOD_OUT_LOW);
  994. if (IS_ERR(idev->reset)) {
  995. dev_err(&pdev->dev, "Unable to retrieve gpio\n");
  996. return PTR_ERR(idev->reset);
  997. }
  998. idev->irq = platform_get_irq(pdev, 0);
  999. if (idev->irq < 0) {
  1000. struct gpio_desc *host_wake;
  1001. dev_err(&pdev->dev, "No IRQ, falling back to gpio-irq\n");
  1002. host_wake = devm_gpiod_get_optional(&pdev->dev, "host-wake",
  1003. GPIOD_IN);
  1004. if (IS_ERR(host_wake)) {
  1005. dev_err(&pdev->dev, "Unable to retrieve IRQ\n");
  1006. goto no_irq;
  1007. }
  1008. idev->irq = gpiod_to_irq(host_wake);
  1009. if (idev->irq < 0) {
  1010. dev_err(&pdev->dev, "No corresponding irq for gpio\n");
  1011. goto no_irq;
  1012. }
  1013. }
  1014. /* Only enable wake-up/irq when controller is powered */
  1015. device_set_wakeup_capable(&pdev->dev, true);
  1016. device_wakeup_disable(&pdev->dev);
  1017. no_irq:
  1018. platform_set_drvdata(pdev, idev);
  1019. /* Place this instance on the device list */
  1020. mutex_lock(&intel_device_list_lock);
  1021. list_add_tail(&idev->list, &intel_device_list);
  1022. mutex_unlock(&intel_device_list_lock);
  1023. dev_info(&pdev->dev, "registered, gpio(%d)/irq(%d).\n",
  1024. desc_to_gpio(idev->reset), idev->irq);
  1025. return 0;
  1026. }
  1027. static int intel_remove(struct platform_device *pdev)
  1028. {
  1029. struct intel_device *idev = platform_get_drvdata(pdev);
  1030. device_wakeup_disable(&pdev->dev);
  1031. mutex_lock(&intel_device_list_lock);
  1032. list_del(&idev->list);
  1033. mutex_unlock(&intel_device_list_lock);
  1034. dev_info(&pdev->dev, "unregistered.\n");
  1035. return 0;
  1036. }
  1037. static struct platform_driver intel_driver = {
  1038. .probe = intel_probe,
  1039. .remove = intel_remove,
  1040. .driver = {
  1041. .name = "hci_intel",
  1042. .acpi_match_table = ACPI_PTR(intel_acpi_match),
  1043. .pm = &intel_pm_ops,
  1044. },
  1045. };
  1046. int __init intel_init(void)
  1047. {
  1048. platform_driver_register(&intel_driver);
  1049. return hci_uart_register_proto(&intel_proto);
  1050. }
  1051. int __exit intel_deinit(void)
  1052. {
  1053. platform_driver_unregister(&intel_driver);
  1054. return hci_uart_unregister_proto(&intel_proto);
  1055. }