hci_intel.c 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341
  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. bt_cb(skb)->pkt_type = 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. bt_cb(skb)->pkt_type = 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. bt_cb(skb)->pkt_type = 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. bt_cb(skb)->pkt_type = 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. bt_cb(skb)->pkt_type = 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_bdaddr = btintel_set_bdaddr;
  439. calltime = ktime_get();
  440. if (hu->init_speed)
  441. init_speed = hu->init_speed;
  442. else
  443. init_speed = hu->proto->init_speed;
  444. if (hu->oper_speed)
  445. oper_speed = hu->oper_speed;
  446. else
  447. oper_speed = hu->proto->oper_speed;
  448. if (oper_speed && init_speed && oper_speed != init_speed)
  449. speed_change = 1;
  450. /* Check that the controller is ready */
  451. err = intel_wait_booting(hu);
  452. clear_bit(STATE_BOOTING, &intel->flags);
  453. /* In case of timeout, try to continue anyway */
  454. if (err && err != ETIMEDOUT)
  455. return err;
  456. set_bit(STATE_BOOTLOADER, &intel->flags);
  457. /* Read the Intel version information to determine if the device
  458. * is in bootloader mode or if it already has operational firmware
  459. * loaded.
  460. */
  461. skb = __hci_cmd_sync(hdev, 0xfc05, 0, NULL, HCI_INIT_TIMEOUT);
  462. if (IS_ERR(skb)) {
  463. bt_dev_err(hdev, "Reading Intel version information failed (%ld)",
  464. PTR_ERR(skb));
  465. return PTR_ERR(skb);
  466. }
  467. if (skb->len != sizeof(*ver)) {
  468. bt_dev_err(hdev, "Intel version event size mismatch");
  469. kfree_skb(skb);
  470. return -EILSEQ;
  471. }
  472. ver = (struct intel_version *)skb->data;
  473. if (ver->status) {
  474. bt_dev_err(hdev, "Intel version command failure (%02x)",
  475. ver->status);
  476. err = -bt_to_errno(ver->status);
  477. kfree_skb(skb);
  478. return err;
  479. }
  480. /* The hardware platform number has a fixed value of 0x37 and
  481. * for now only accept this single value.
  482. */
  483. if (ver->hw_platform != 0x37) {
  484. bt_dev_err(hdev, "Unsupported Intel hardware platform (%u)",
  485. ver->hw_platform);
  486. kfree_skb(skb);
  487. return -EINVAL;
  488. }
  489. /* At the moment only the hardware variant iBT 3.0 (LnP/SfP) is
  490. * supported by this firmware loading method. This check has been
  491. * put in place to ensure correct forward compatibility options
  492. * when newer hardware variants come along.
  493. */
  494. if (ver->hw_variant != 0x0b) {
  495. bt_dev_err(hdev, "Unsupported Intel hardware variant (%u)",
  496. ver->hw_variant);
  497. kfree_skb(skb);
  498. return -EINVAL;
  499. }
  500. btintel_version_info(hdev, ver);
  501. /* The firmware variant determines if the device is in bootloader
  502. * mode or is running operational firmware. The value 0x06 identifies
  503. * the bootloader and the value 0x23 identifies the operational
  504. * firmware.
  505. *
  506. * When the operational firmware is already present, then only
  507. * the check for valid Bluetooth device address is needed. This
  508. * determines if the device will be added as configured or
  509. * unconfigured controller.
  510. *
  511. * It is not possible to use the Secure Boot Parameters in this
  512. * case since that command is only available in bootloader mode.
  513. */
  514. if (ver->fw_variant == 0x23) {
  515. kfree_skb(skb);
  516. clear_bit(STATE_BOOTLOADER, &intel->flags);
  517. btintel_check_bdaddr(hdev);
  518. return 0;
  519. }
  520. /* If the device is not in bootloader mode, then the only possible
  521. * choice is to return an error and abort the device initialization.
  522. */
  523. if (ver->fw_variant != 0x06) {
  524. bt_dev_err(hdev, "Unsupported Intel firmware variant (%u)",
  525. ver->fw_variant);
  526. kfree_skb(skb);
  527. return -ENODEV;
  528. }
  529. kfree_skb(skb);
  530. /* Read the secure boot parameters to identify the operating
  531. * details of the bootloader.
  532. */
  533. skb = __hci_cmd_sync(hdev, 0xfc0d, 0, NULL, HCI_INIT_TIMEOUT);
  534. if (IS_ERR(skb)) {
  535. bt_dev_err(hdev, "Reading Intel boot parameters failed (%ld)",
  536. PTR_ERR(skb));
  537. return PTR_ERR(skb);
  538. }
  539. if (skb->len != sizeof(*params)) {
  540. bt_dev_err(hdev, "Intel boot parameters size mismatch");
  541. kfree_skb(skb);
  542. return -EILSEQ;
  543. }
  544. params = (struct intel_boot_params *)skb->data;
  545. if (params->status) {
  546. bt_dev_err(hdev, "Intel boot parameters command failure (%02x)",
  547. params->status);
  548. err = -bt_to_errno(params->status);
  549. kfree_skb(skb);
  550. return err;
  551. }
  552. bt_dev_info(hdev, "Device revision is %u",
  553. le16_to_cpu(params->dev_revid));
  554. bt_dev_info(hdev, "Secure boot is %s",
  555. params->secure_boot ? "enabled" : "disabled");
  556. bt_dev_info(hdev, "Minimum firmware build %u week %u %u",
  557. params->min_fw_build_nn, params->min_fw_build_cw,
  558. 2000 + params->min_fw_build_yy);
  559. /* It is required that every single firmware fragment is acknowledged
  560. * with a command complete event. If the boot parameters indicate
  561. * that this bootloader does not send them, then abort the setup.
  562. */
  563. if (params->limited_cce != 0x00) {
  564. bt_dev_err(hdev, "Unsupported Intel firmware loading method (%u)",
  565. params->limited_cce);
  566. kfree_skb(skb);
  567. return -EINVAL;
  568. }
  569. /* If the OTP has no valid Bluetooth device address, then there will
  570. * also be no valid address for the operational firmware.
  571. */
  572. if (!bacmp(&params->otp_bdaddr, BDADDR_ANY)) {
  573. bt_dev_info(hdev, "No device address configured");
  574. set_bit(HCI_QUIRK_INVALID_BDADDR, &hdev->quirks);
  575. }
  576. /* With this Intel bootloader only the hardware variant and device
  577. * revision information are used to select the right firmware.
  578. *
  579. * Currently this bootloader support is limited to hardware variant
  580. * iBT 3.0 (LnP/SfP) which is identified by the value 11 (0x0b).
  581. */
  582. snprintf(fwname, sizeof(fwname), "intel/ibt-11-%u.sfi",
  583. le16_to_cpu(params->dev_revid));
  584. err = request_firmware(&fw, fwname, &hdev->dev);
  585. if (err < 0) {
  586. bt_dev_err(hdev, "Failed to load Intel firmware file (%d)",
  587. err);
  588. kfree_skb(skb);
  589. return err;
  590. }
  591. bt_dev_info(hdev, "Found device firmware: %s", fwname);
  592. /* Save the DDC file name for later */
  593. snprintf(fwname, sizeof(fwname), "intel/ibt-11-%u.ddc",
  594. le16_to_cpu(params->dev_revid));
  595. kfree_skb(skb);
  596. if (fw->size < 644) {
  597. bt_dev_err(hdev, "Invalid size of firmware file (%zu)",
  598. fw->size);
  599. err = -EBADF;
  600. goto done;
  601. }
  602. set_bit(STATE_DOWNLOADING, &intel->flags);
  603. /* Start the firmware download transaction with the Init fragment
  604. * represented by the 128 bytes of CSS header.
  605. */
  606. err = btintel_secure_send(hdev, 0x00, 128, fw->data);
  607. if (err < 0) {
  608. bt_dev_err(hdev, "Failed to send firmware header (%d)", err);
  609. goto done;
  610. }
  611. /* Send the 256 bytes of public key information from the firmware
  612. * as the PKey fragment.
  613. */
  614. err = btintel_secure_send(hdev, 0x03, 256, fw->data + 128);
  615. if (err < 0) {
  616. bt_dev_err(hdev, "Failed to send firmware public key (%d)",
  617. err);
  618. goto done;
  619. }
  620. /* Send the 256 bytes of signature information from the firmware
  621. * as the Sign fragment.
  622. */
  623. err = btintel_secure_send(hdev, 0x02, 256, fw->data + 388);
  624. if (err < 0) {
  625. bt_dev_err(hdev, "Failed to send firmware signature (%d)",
  626. err);
  627. goto done;
  628. }
  629. fw_ptr = fw->data + 644;
  630. frag_len = 0;
  631. while (fw_ptr - fw->data < fw->size) {
  632. struct hci_command_hdr *cmd = (void *)(fw_ptr + frag_len);
  633. frag_len += sizeof(*cmd) + cmd->plen;
  634. bt_dev_dbg(hdev, "Patching %td/%zu", (fw_ptr - fw->data),
  635. fw->size);
  636. /* The parameter length of the secure send command requires
  637. * a 4 byte alignment. It happens so that the firmware file
  638. * contains proper Intel_NOP commands to align the fragments
  639. * as needed.
  640. *
  641. * Send set of commands with 4 byte alignment from the
  642. * firmware data buffer as a single Data fragement.
  643. */
  644. if (frag_len % 4)
  645. continue;
  646. /* Send each command from the firmware data buffer as
  647. * a single Data fragment.
  648. */
  649. err = btintel_secure_send(hdev, 0x01, frag_len, fw_ptr);
  650. if (err < 0) {
  651. bt_dev_err(hdev, "Failed to send firmware data (%d)",
  652. err);
  653. goto done;
  654. }
  655. fw_ptr += frag_len;
  656. frag_len = 0;
  657. }
  658. set_bit(STATE_FIRMWARE_LOADED, &intel->flags);
  659. bt_dev_info(hdev, "Waiting for firmware download to complete");
  660. /* Before switching the device into operational mode and with that
  661. * booting the loaded firmware, wait for the bootloader notification
  662. * that all fragments have been successfully received.
  663. *
  664. * When the event processing receives the notification, then the
  665. * STATE_DOWNLOADING flag will be cleared.
  666. *
  667. * The firmware loading should not take longer than 5 seconds
  668. * and thus just timeout if that happens and fail the setup
  669. * of this device.
  670. */
  671. err = wait_on_bit_timeout(&intel->flags, STATE_DOWNLOADING,
  672. TASK_INTERRUPTIBLE,
  673. msecs_to_jiffies(5000));
  674. if (err == 1) {
  675. bt_dev_err(hdev, "Firmware loading interrupted");
  676. err = -EINTR;
  677. goto done;
  678. }
  679. if (err) {
  680. bt_dev_err(hdev, "Firmware loading timeout");
  681. err = -ETIMEDOUT;
  682. goto done;
  683. }
  684. if (test_bit(STATE_FIRMWARE_FAILED, &intel->flags)) {
  685. bt_dev_err(hdev, "Firmware loading failed");
  686. err = -ENOEXEC;
  687. goto done;
  688. }
  689. rettime = ktime_get();
  690. delta = ktime_sub(rettime, calltime);
  691. duration = (unsigned long long) ktime_to_ns(delta) >> 10;
  692. bt_dev_info(hdev, "Firmware loaded in %llu usecs", duration);
  693. done:
  694. release_firmware(fw);
  695. if (err < 0)
  696. return err;
  697. /* We need to restore the default speed before Intel reset */
  698. if (speed_change) {
  699. err = intel_set_baudrate(hu, init_speed);
  700. if (err)
  701. return err;
  702. }
  703. calltime = ktime_get();
  704. set_bit(STATE_BOOTING, &intel->flags);
  705. skb = __hci_cmd_sync(hdev, 0xfc01, sizeof(reset_param), reset_param,
  706. HCI_INIT_TIMEOUT);
  707. if (IS_ERR(skb))
  708. return PTR_ERR(skb);
  709. kfree_skb(skb);
  710. /* The bootloader will not indicate when the device is ready. This
  711. * is done by the operational firmware sending bootup notification.
  712. *
  713. * Booting into operational firmware should not take longer than
  714. * 1 second. However if that happens, then just fail the setup
  715. * since something went wrong.
  716. */
  717. bt_dev_info(hdev, "Waiting for device to boot");
  718. err = intel_wait_booting(hu);
  719. if (err)
  720. return err;
  721. clear_bit(STATE_BOOTING, &intel->flags);
  722. rettime = ktime_get();
  723. delta = ktime_sub(rettime, calltime);
  724. duration = (unsigned long long) ktime_to_ns(delta) >> 10;
  725. bt_dev_info(hdev, "Device booted in %llu usecs", duration);
  726. /* Enable LPM if matching pdev with wakeup enabled */
  727. mutex_lock(&intel_device_list_lock);
  728. list_for_each(p, &intel_device_list) {
  729. struct intel_device *dev = list_entry(p, struct intel_device,
  730. list);
  731. if (hu->tty->dev->parent == dev->pdev->dev.parent) {
  732. if (device_may_wakeup(&dev->pdev->dev))
  733. idev = dev;
  734. break;
  735. }
  736. }
  737. mutex_unlock(&intel_device_list_lock);
  738. if (!idev)
  739. goto no_lpm;
  740. bt_dev_info(hdev, "Enabling LPM");
  741. skb = __hci_cmd_sync(hdev, 0xfc8b, sizeof(lpm_param), lpm_param,
  742. HCI_CMD_TIMEOUT);
  743. if (IS_ERR(skb)) {
  744. bt_dev_err(hdev, "Failed to enable LPM");
  745. goto no_lpm;
  746. }
  747. kfree_skb(skb);
  748. set_bit(STATE_LPM_ENABLED, &intel->flags);
  749. no_lpm:
  750. /* Ignore errors, device can work without DDC parameters */
  751. btintel_load_ddc_config(hdev, fwname);
  752. skb = __hci_cmd_sync(hdev, HCI_OP_RESET, 0, NULL, HCI_CMD_TIMEOUT);
  753. if (IS_ERR(skb))
  754. return PTR_ERR(skb);
  755. kfree_skb(skb);
  756. if (speed_change) {
  757. err = intel_set_baudrate(hu, oper_speed);
  758. if (err)
  759. return err;
  760. }
  761. bt_dev_info(hdev, "Setup complete");
  762. clear_bit(STATE_BOOTLOADER, &intel->flags);
  763. return 0;
  764. }
  765. static int intel_recv_event(struct hci_dev *hdev, struct sk_buff *skb)
  766. {
  767. struct hci_uart *hu = hci_get_drvdata(hdev);
  768. struct intel_data *intel = hu->priv;
  769. struct hci_event_hdr *hdr;
  770. if (!test_bit(STATE_BOOTLOADER, &intel->flags) &&
  771. !test_bit(STATE_BOOTING, &intel->flags))
  772. goto recv;
  773. hdr = (void *)skb->data;
  774. /* When the firmware loading completes the device sends
  775. * out a vendor specific event indicating the result of
  776. * the firmware loading.
  777. */
  778. if (skb->len == 7 && hdr->evt == 0xff && hdr->plen == 0x05 &&
  779. skb->data[2] == 0x06) {
  780. if (skb->data[3] != 0x00)
  781. set_bit(STATE_FIRMWARE_FAILED, &intel->flags);
  782. if (test_and_clear_bit(STATE_DOWNLOADING, &intel->flags) &&
  783. test_bit(STATE_FIRMWARE_LOADED, &intel->flags)) {
  784. smp_mb__after_atomic();
  785. wake_up_bit(&intel->flags, STATE_DOWNLOADING);
  786. }
  787. /* When switching to the operational firmware the device
  788. * sends a vendor specific event indicating that the bootup
  789. * completed.
  790. */
  791. } else if (skb->len == 9 && hdr->evt == 0xff && hdr->plen == 0x07 &&
  792. skb->data[2] == 0x02) {
  793. if (test_and_clear_bit(STATE_BOOTING, &intel->flags)) {
  794. smp_mb__after_atomic();
  795. wake_up_bit(&intel->flags, STATE_BOOTING);
  796. }
  797. }
  798. recv:
  799. return hci_recv_frame(hdev, skb);
  800. }
  801. static void intel_recv_lpm_notify(struct hci_dev *hdev, int value)
  802. {
  803. struct hci_uart *hu = hci_get_drvdata(hdev);
  804. struct intel_data *intel = hu->priv;
  805. bt_dev_dbg(hdev, "TX idle notification (%d)", value);
  806. if (value) {
  807. set_bit(STATE_TX_ACTIVE, &intel->flags);
  808. schedule_work(&intel->busy_work);
  809. } else {
  810. clear_bit(STATE_TX_ACTIVE, &intel->flags);
  811. }
  812. }
  813. static int intel_recv_lpm(struct hci_dev *hdev, struct sk_buff *skb)
  814. {
  815. struct hci_lpm_pkt *lpm = (void *)skb->data;
  816. struct hci_uart *hu = hci_get_drvdata(hdev);
  817. struct intel_data *intel = hu->priv;
  818. switch (lpm->opcode) {
  819. case LPM_OP_TX_NOTIFY:
  820. if (lpm->dlen < 1) {
  821. bt_dev_err(hu->hdev, "Invalid LPM notification packet");
  822. break;
  823. }
  824. intel_recv_lpm_notify(hdev, lpm->data[0]);
  825. break;
  826. case LPM_OP_SUSPEND_ACK:
  827. set_bit(STATE_SUSPENDED, &intel->flags);
  828. if (test_and_clear_bit(STATE_LPM_TRANSACTION, &intel->flags)) {
  829. smp_mb__after_atomic();
  830. wake_up_bit(&intel->flags, STATE_LPM_TRANSACTION);
  831. }
  832. break;
  833. case LPM_OP_RESUME_ACK:
  834. clear_bit(STATE_SUSPENDED, &intel->flags);
  835. if (test_and_clear_bit(STATE_LPM_TRANSACTION, &intel->flags)) {
  836. smp_mb__after_atomic();
  837. wake_up_bit(&intel->flags, STATE_LPM_TRANSACTION);
  838. }
  839. break;
  840. default:
  841. bt_dev_err(hdev, "Unknown LPM opcode (%02x)", lpm->opcode);
  842. break;
  843. }
  844. kfree_skb(skb);
  845. return 0;
  846. }
  847. #define INTEL_RECV_LPM \
  848. .type = HCI_LPM_PKT, \
  849. .hlen = HCI_LPM_HDR_SIZE, \
  850. .loff = 1, \
  851. .lsize = 1, \
  852. .maxlen = HCI_LPM_MAX_SIZE
  853. static const struct h4_recv_pkt intel_recv_pkts[] = {
  854. { H4_RECV_ACL, .recv = hci_recv_frame },
  855. { H4_RECV_SCO, .recv = hci_recv_frame },
  856. { H4_RECV_EVENT, .recv = intel_recv_event },
  857. { INTEL_RECV_LPM, .recv = intel_recv_lpm },
  858. };
  859. static int intel_recv(struct hci_uart *hu, const void *data, int count)
  860. {
  861. struct intel_data *intel = hu->priv;
  862. if (!test_bit(HCI_UART_REGISTERED, &hu->flags))
  863. return -EUNATCH;
  864. intel->rx_skb = h4_recv_buf(hu->hdev, intel->rx_skb, data, count,
  865. intel_recv_pkts,
  866. ARRAY_SIZE(intel_recv_pkts));
  867. if (IS_ERR(intel->rx_skb)) {
  868. int err = PTR_ERR(intel->rx_skb);
  869. bt_dev_err(hu->hdev, "Frame reassembly failed (%d)", err);
  870. intel->rx_skb = NULL;
  871. return err;
  872. }
  873. return count;
  874. }
  875. static int intel_enqueue(struct hci_uart *hu, struct sk_buff *skb)
  876. {
  877. struct intel_data *intel = hu->priv;
  878. struct list_head *p;
  879. BT_DBG("hu %p skb %p", hu, skb);
  880. /* Be sure our controller is resumed and potential LPM transaction
  881. * completed before enqueuing any packet.
  882. */
  883. mutex_lock(&intel_device_list_lock);
  884. list_for_each(p, &intel_device_list) {
  885. struct intel_device *idev = list_entry(p, struct intel_device,
  886. list);
  887. if (hu->tty->dev->parent == idev->pdev->dev.parent) {
  888. pm_runtime_get_sync(&idev->pdev->dev);
  889. pm_runtime_mark_last_busy(&idev->pdev->dev);
  890. pm_runtime_put_autosuspend(&idev->pdev->dev);
  891. break;
  892. }
  893. }
  894. mutex_unlock(&intel_device_list_lock);
  895. skb_queue_tail(&intel->txq, skb);
  896. return 0;
  897. }
  898. static struct sk_buff *intel_dequeue(struct hci_uart *hu)
  899. {
  900. struct intel_data *intel = hu->priv;
  901. struct sk_buff *skb;
  902. skb = skb_dequeue(&intel->txq);
  903. if (!skb)
  904. return skb;
  905. if (test_bit(STATE_BOOTLOADER, &intel->flags) &&
  906. (bt_cb(skb)->pkt_type == HCI_COMMAND_PKT)) {
  907. struct hci_command_hdr *cmd = (void *)skb->data;
  908. __u16 opcode = le16_to_cpu(cmd->opcode);
  909. /* When the 0xfc01 command is issued to boot into
  910. * the operational firmware, it will actually not
  911. * send a command complete event. To keep the flow
  912. * control working inject that event here.
  913. */
  914. if (opcode == 0xfc01)
  915. inject_cmd_complete(hu->hdev, opcode);
  916. }
  917. /* Prepend skb with frame type */
  918. memcpy(skb_push(skb, 1), &bt_cb(skb)->pkt_type, 1);
  919. return skb;
  920. }
  921. static const struct hci_uart_proto intel_proto = {
  922. .id = HCI_UART_INTEL,
  923. .name = "Intel",
  924. .init_speed = 115200,
  925. .oper_speed = 3000000,
  926. .open = intel_open,
  927. .close = intel_close,
  928. .flush = intel_flush,
  929. .setup = intel_setup,
  930. .set_baudrate = intel_set_baudrate,
  931. .recv = intel_recv,
  932. .enqueue = intel_enqueue,
  933. .dequeue = intel_dequeue,
  934. };
  935. #ifdef CONFIG_ACPI
  936. static const struct acpi_device_id intel_acpi_match[] = {
  937. { "INT33E1", 0 },
  938. { },
  939. };
  940. MODULE_DEVICE_TABLE(acpi, intel_acpi_match);
  941. static int intel_acpi_probe(struct intel_device *idev)
  942. {
  943. const struct acpi_device_id *id;
  944. id = acpi_match_device(intel_acpi_match, &idev->pdev->dev);
  945. if (!id)
  946. return -ENODEV;
  947. return 0;
  948. }
  949. #else
  950. static int intel_acpi_probe(struct intel_device *idev)
  951. {
  952. return -ENODEV;
  953. }
  954. #endif
  955. #ifdef CONFIG_PM
  956. static int intel_suspend_device(struct device *dev)
  957. {
  958. struct intel_device *idev = dev_get_drvdata(dev);
  959. mutex_lock(&idev->hu_lock);
  960. if (idev->hu)
  961. intel_lpm_suspend(idev->hu);
  962. mutex_unlock(&idev->hu_lock);
  963. return 0;
  964. }
  965. static int intel_resume_device(struct device *dev)
  966. {
  967. struct intel_device *idev = dev_get_drvdata(dev);
  968. mutex_lock(&idev->hu_lock);
  969. if (idev->hu)
  970. intel_lpm_resume(idev->hu);
  971. mutex_unlock(&idev->hu_lock);
  972. return 0;
  973. }
  974. #endif
  975. #ifdef CONFIG_PM_SLEEP
  976. static int intel_suspend(struct device *dev)
  977. {
  978. struct intel_device *idev = dev_get_drvdata(dev);
  979. if (device_may_wakeup(dev))
  980. enable_irq_wake(idev->irq);
  981. return intel_suspend_device(dev);
  982. }
  983. static int intel_resume(struct device *dev)
  984. {
  985. struct intel_device *idev = dev_get_drvdata(dev);
  986. if (device_may_wakeup(dev))
  987. disable_irq_wake(idev->irq);
  988. return intel_resume_device(dev);
  989. }
  990. #endif
  991. static const struct dev_pm_ops intel_pm_ops = {
  992. SET_SYSTEM_SLEEP_PM_OPS(intel_suspend, intel_resume)
  993. SET_RUNTIME_PM_OPS(intel_suspend_device, intel_resume_device, NULL)
  994. };
  995. static int intel_probe(struct platform_device *pdev)
  996. {
  997. struct intel_device *idev;
  998. idev = devm_kzalloc(&pdev->dev, sizeof(*idev), GFP_KERNEL);
  999. if (!idev)
  1000. return -ENOMEM;
  1001. mutex_init(&idev->hu_lock);
  1002. idev->pdev = pdev;
  1003. if (ACPI_HANDLE(&pdev->dev)) {
  1004. int err = intel_acpi_probe(idev);
  1005. if (err)
  1006. return err;
  1007. } else {
  1008. return -ENODEV;
  1009. }
  1010. idev->reset = devm_gpiod_get_optional(&pdev->dev, "reset",
  1011. GPIOD_OUT_LOW);
  1012. if (IS_ERR(idev->reset)) {
  1013. dev_err(&pdev->dev, "Unable to retrieve gpio\n");
  1014. return PTR_ERR(idev->reset);
  1015. }
  1016. idev->irq = platform_get_irq(pdev, 0);
  1017. if (idev->irq < 0) {
  1018. struct gpio_desc *host_wake;
  1019. dev_err(&pdev->dev, "No IRQ, falling back to gpio-irq\n");
  1020. host_wake = devm_gpiod_get_optional(&pdev->dev, "host-wake",
  1021. GPIOD_IN);
  1022. if (IS_ERR(host_wake)) {
  1023. dev_err(&pdev->dev, "Unable to retrieve IRQ\n");
  1024. goto no_irq;
  1025. }
  1026. idev->irq = gpiod_to_irq(host_wake);
  1027. if (idev->irq < 0) {
  1028. dev_err(&pdev->dev, "No corresponding irq for gpio\n");
  1029. goto no_irq;
  1030. }
  1031. }
  1032. /* Only enable wake-up/irq when controller is powered */
  1033. device_set_wakeup_capable(&pdev->dev, true);
  1034. device_wakeup_disable(&pdev->dev);
  1035. no_irq:
  1036. platform_set_drvdata(pdev, idev);
  1037. /* Place this instance on the device list */
  1038. mutex_lock(&intel_device_list_lock);
  1039. list_add_tail(&idev->list, &intel_device_list);
  1040. mutex_unlock(&intel_device_list_lock);
  1041. dev_info(&pdev->dev, "registered, gpio(%d)/irq(%d).\n",
  1042. desc_to_gpio(idev->reset), idev->irq);
  1043. return 0;
  1044. }
  1045. static int intel_remove(struct platform_device *pdev)
  1046. {
  1047. struct intel_device *idev = platform_get_drvdata(pdev);
  1048. device_wakeup_disable(&pdev->dev);
  1049. mutex_lock(&intel_device_list_lock);
  1050. list_del(&idev->list);
  1051. mutex_unlock(&intel_device_list_lock);
  1052. dev_info(&pdev->dev, "unregistered.\n");
  1053. return 0;
  1054. }
  1055. static struct platform_driver intel_driver = {
  1056. .probe = intel_probe,
  1057. .remove = intel_remove,
  1058. .driver = {
  1059. .name = "hci_intel",
  1060. .acpi_match_table = ACPI_PTR(intel_acpi_match),
  1061. .pm = &intel_pm_ops,
  1062. },
  1063. };
  1064. int __init intel_init(void)
  1065. {
  1066. platform_driver_register(&intel_driver);
  1067. return hci_uart_register_proto(&intel_proto);
  1068. }
  1069. int __exit intel_deinit(void)
  1070. {
  1071. platform_driver_unregister(&intel_driver);
  1072. return hci_uart_unregister_proto(&intel_proto);
  1073. }