hci_bcm.c 30 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351
  1. /*
  2. *
  3. * Bluetooth HCI UART driver for Broadcom 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/acpi.h>
  29. #include <linux/of.h>
  30. #include <linux/property.h>
  31. #include <linux/platform_data/x86/apple.h>
  32. #include <linux/platform_device.h>
  33. #include <linux/clk.h>
  34. #include <linux/gpio/consumer.h>
  35. #include <linux/tty.h>
  36. #include <linux/interrupt.h>
  37. #include <linux/dmi.h>
  38. #include <linux/pm_runtime.h>
  39. #include <linux/serdev.h>
  40. #include <net/bluetooth/bluetooth.h>
  41. #include <net/bluetooth/hci_core.h>
  42. #include "btbcm.h"
  43. #include "hci_uart.h"
  44. #define BCM_NULL_PKT 0x00
  45. #define BCM_NULL_SIZE 0
  46. #define BCM_LM_DIAG_PKT 0x07
  47. #define BCM_LM_DIAG_SIZE 63
  48. #define BCM_AUTOSUSPEND_DELAY 5000 /* default autosleep delay */
  49. /**
  50. * struct bcm_device - device driver resources
  51. * @serdev_hu: HCI UART controller struct
  52. * @list: bcm_device_list node
  53. * @dev: physical UART slave
  54. * @name: device name logged by bt_dev_*() functions
  55. * @device_wakeup: BT_WAKE pin,
  56. * assert = Bluetooth device must wake up or remain awake,
  57. * deassert = Bluetooth device may sleep when sleep criteria are met
  58. * @shutdown: BT_REG_ON pin,
  59. * power up or power down Bluetooth device internal regulators
  60. * @set_device_wakeup: callback to toggle BT_WAKE pin
  61. * either by accessing @device_wakeup or by calling @btlp
  62. * @set_shutdown: callback to toggle BT_REG_ON pin
  63. * either by accessing @shutdown or by calling @btpu/@btpd
  64. * @btlp: Apple ACPI method to toggle BT_WAKE pin ("Bluetooth Low Power")
  65. * @btpu: Apple ACPI method to drive BT_REG_ON pin high ("Bluetooth Power Up")
  66. * @btpd: Apple ACPI method to drive BT_REG_ON pin low ("Bluetooth Power Down")
  67. * @clk: clock used by Bluetooth device
  68. * @clk_enabled: whether @clk is prepared and enabled
  69. * @init_speed: default baudrate of Bluetooth device;
  70. * the host UART is initially set to this baudrate so that
  71. * it can configure the Bluetooth device for @oper_speed
  72. * @oper_speed: preferred baudrate of Bluetooth device;
  73. * set to 0 if @init_speed is already the preferred baudrate
  74. * @irq: interrupt triggered by HOST_WAKE_BT pin
  75. * @irq_active_low: whether @irq is active low
  76. * @hu: pointer to HCI UART controller struct,
  77. * used to disable flow control during runtime suspend and system sleep
  78. * @is_suspended: whether flow control is currently disabled
  79. */
  80. struct bcm_device {
  81. /* Must be the first member, hci_serdev.c expects this. */
  82. struct hci_uart serdev_hu;
  83. struct list_head list;
  84. struct device *dev;
  85. const char *name;
  86. struct gpio_desc *device_wakeup;
  87. struct gpio_desc *shutdown;
  88. int (*set_device_wakeup)(struct bcm_device *, bool);
  89. int (*set_shutdown)(struct bcm_device *, bool);
  90. #ifdef CONFIG_ACPI
  91. acpi_handle btlp, btpu, btpd;
  92. int gpio_count;
  93. int gpio_int_idx;
  94. #endif
  95. struct clk *clk;
  96. bool clk_enabled;
  97. u32 init_speed;
  98. u32 oper_speed;
  99. int irq;
  100. bool irq_active_low;
  101. #ifdef CONFIG_PM
  102. struct hci_uart *hu;
  103. bool is_suspended;
  104. #endif
  105. };
  106. /* generic bcm uart resources */
  107. struct bcm_data {
  108. struct sk_buff *rx_skb;
  109. struct sk_buff_head txq;
  110. struct bcm_device *dev;
  111. };
  112. /* List of BCM BT UART devices */
  113. static DEFINE_MUTEX(bcm_device_lock);
  114. static LIST_HEAD(bcm_device_list);
  115. static int irq_polarity = -1;
  116. module_param(irq_polarity, int, 0444);
  117. MODULE_PARM_DESC(irq_polarity, "IRQ polarity 0: active-high 1: active-low");
  118. static inline void host_set_baudrate(struct hci_uart *hu, unsigned int speed)
  119. {
  120. if (hu->serdev)
  121. serdev_device_set_baudrate(hu->serdev, speed);
  122. else
  123. hci_uart_set_baudrate(hu, speed);
  124. }
  125. static int bcm_set_baudrate(struct hci_uart *hu, unsigned int speed)
  126. {
  127. struct hci_dev *hdev = hu->hdev;
  128. struct sk_buff *skb;
  129. struct bcm_update_uart_baud_rate param;
  130. if (speed > 3000000) {
  131. struct bcm_write_uart_clock_setting clock;
  132. clock.type = BCM_UART_CLOCK_48MHZ;
  133. bt_dev_dbg(hdev, "Set Controller clock (%d)", clock.type);
  134. /* This Broadcom specific command changes the UART's controller
  135. * clock for baud rate > 3000000.
  136. */
  137. skb = __hci_cmd_sync(hdev, 0xfc45, 1, &clock, HCI_INIT_TIMEOUT);
  138. if (IS_ERR(skb)) {
  139. int err = PTR_ERR(skb);
  140. bt_dev_err(hdev, "BCM: failed to write clock (%d)",
  141. err);
  142. return err;
  143. }
  144. kfree_skb(skb);
  145. }
  146. bt_dev_dbg(hdev, "Set Controller UART speed to %d bit/s", speed);
  147. param.zero = cpu_to_le16(0);
  148. param.baud_rate = cpu_to_le32(speed);
  149. /* This Broadcom specific command changes the UART's controller baud
  150. * rate.
  151. */
  152. skb = __hci_cmd_sync(hdev, 0xfc18, sizeof(param), &param,
  153. HCI_INIT_TIMEOUT);
  154. if (IS_ERR(skb)) {
  155. int err = PTR_ERR(skb);
  156. bt_dev_err(hdev, "BCM: failed to write update baudrate (%d)",
  157. err);
  158. return err;
  159. }
  160. kfree_skb(skb);
  161. return 0;
  162. }
  163. /* bcm_device_exists should be protected by bcm_device_lock */
  164. static bool bcm_device_exists(struct bcm_device *device)
  165. {
  166. struct list_head *p;
  167. #ifdef CONFIG_PM
  168. /* Devices using serdev always exist */
  169. if (device && device->hu && device->hu->serdev)
  170. return true;
  171. #endif
  172. list_for_each(p, &bcm_device_list) {
  173. struct bcm_device *dev = list_entry(p, struct bcm_device, list);
  174. if (device == dev)
  175. return true;
  176. }
  177. return false;
  178. }
  179. static int bcm_gpio_set_power(struct bcm_device *dev, bool powered)
  180. {
  181. int err;
  182. if (powered && !IS_ERR(dev->clk) && !dev->clk_enabled) {
  183. err = clk_prepare_enable(dev->clk);
  184. if (err)
  185. return err;
  186. }
  187. err = dev->set_shutdown(dev, powered);
  188. if (err)
  189. goto err_clk_disable;
  190. err = dev->set_device_wakeup(dev, powered);
  191. if (err)
  192. goto err_revert_shutdown;
  193. if (!powered && !IS_ERR(dev->clk) && dev->clk_enabled)
  194. clk_disable_unprepare(dev->clk);
  195. dev->clk_enabled = powered;
  196. return 0;
  197. err_revert_shutdown:
  198. dev->set_shutdown(dev, !powered);
  199. err_clk_disable:
  200. if (powered && !IS_ERR(dev->clk) && !dev->clk_enabled)
  201. clk_disable_unprepare(dev->clk);
  202. return err;
  203. }
  204. #ifdef CONFIG_PM
  205. static irqreturn_t bcm_host_wake(int irq, void *data)
  206. {
  207. struct bcm_device *bdev = data;
  208. bt_dev_dbg(bdev, "Host wake IRQ");
  209. pm_runtime_get(bdev->dev);
  210. pm_runtime_mark_last_busy(bdev->dev);
  211. pm_runtime_put_autosuspend(bdev->dev);
  212. return IRQ_HANDLED;
  213. }
  214. static int bcm_request_irq(struct bcm_data *bcm)
  215. {
  216. struct bcm_device *bdev = bcm->dev;
  217. int err;
  218. mutex_lock(&bcm_device_lock);
  219. if (!bcm_device_exists(bdev)) {
  220. err = -ENODEV;
  221. goto unlock;
  222. }
  223. if (bdev->irq <= 0) {
  224. err = -EOPNOTSUPP;
  225. goto unlock;
  226. }
  227. err = devm_request_irq(bdev->dev, bdev->irq, bcm_host_wake,
  228. bdev->irq_active_low ? IRQF_TRIGGER_FALLING :
  229. IRQF_TRIGGER_RISING,
  230. "host_wake", bdev);
  231. if (err) {
  232. bdev->irq = err;
  233. goto unlock;
  234. }
  235. device_init_wakeup(bdev->dev, true);
  236. pm_runtime_set_autosuspend_delay(bdev->dev,
  237. BCM_AUTOSUSPEND_DELAY);
  238. pm_runtime_use_autosuspend(bdev->dev);
  239. pm_runtime_set_active(bdev->dev);
  240. pm_runtime_enable(bdev->dev);
  241. unlock:
  242. mutex_unlock(&bcm_device_lock);
  243. return err;
  244. }
  245. static const struct bcm_set_sleep_mode default_sleep_params = {
  246. .sleep_mode = 1, /* 0=Disabled, 1=UART, 2=Reserved, 3=USB */
  247. .idle_host = 2, /* idle threshold HOST, in 300ms */
  248. .idle_dev = 2, /* idle threshold device, in 300ms */
  249. .bt_wake_active = 1, /* BT_WAKE active mode: 1 = high, 0 = low */
  250. .host_wake_active = 0, /* HOST_WAKE active mode: 1 = high, 0 = low */
  251. .allow_host_sleep = 1, /* Allow host sleep in SCO flag */
  252. .combine_modes = 1, /* Combine sleep and LPM flag */
  253. .tristate_control = 0, /* Allow tri-state control of UART tx flag */
  254. /* Irrelevant USB flags */
  255. .usb_auto_sleep = 0,
  256. .usb_resume_timeout = 0,
  257. .break_to_host = 0,
  258. .pulsed_host_wake = 1,
  259. };
  260. static int bcm_setup_sleep(struct hci_uart *hu)
  261. {
  262. struct bcm_data *bcm = hu->priv;
  263. struct sk_buff *skb;
  264. struct bcm_set_sleep_mode sleep_params = default_sleep_params;
  265. sleep_params.host_wake_active = !bcm->dev->irq_active_low;
  266. skb = __hci_cmd_sync(hu->hdev, 0xfc27, sizeof(sleep_params),
  267. &sleep_params, HCI_INIT_TIMEOUT);
  268. if (IS_ERR(skb)) {
  269. int err = PTR_ERR(skb);
  270. bt_dev_err(hu->hdev, "Sleep VSC failed (%d)", err);
  271. return err;
  272. }
  273. kfree_skb(skb);
  274. bt_dev_dbg(hu->hdev, "Set Sleep Parameters VSC succeeded");
  275. return 0;
  276. }
  277. #else
  278. static inline int bcm_request_irq(struct bcm_data *bcm) { return 0; }
  279. static inline int bcm_setup_sleep(struct hci_uart *hu) { return 0; }
  280. #endif
  281. static int bcm_set_diag(struct hci_dev *hdev, bool enable)
  282. {
  283. struct hci_uart *hu = hci_get_drvdata(hdev);
  284. struct bcm_data *bcm = hu->priv;
  285. struct sk_buff *skb;
  286. if (!test_bit(HCI_RUNNING, &hdev->flags))
  287. return -ENETDOWN;
  288. skb = bt_skb_alloc(3, GFP_KERNEL);
  289. if (!skb)
  290. return -ENOMEM;
  291. skb_put_u8(skb, BCM_LM_DIAG_PKT);
  292. skb_put_u8(skb, 0xf0);
  293. skb_put_u8(skb, enable);
  294. skb_queue_tail(&bcm->txq, skb);
  295. hci_uart_tx_wakeup(hu);
  296. return 0;
  297. }
  298. static int bcm_open(struct hci_uart *hu)
  299. {
  300. struct bcm_data *bcm;
  301. struct list_head *p;
  302. int err;
  303. bt_dev_dbg(hu->hdev, "hu %p", hu);
  304. bcm = kzalloc(sizeof(*bcm), GFP_KERNEL);
  305. if (!bcm)
  306. return -ENOMEM;
  307. skb_queue_head_init(&bcm->txq);
  308. hu->priv = bcm;
  309. mutex_lock(&bcm_device_lock);
  310. if (hu->serdev) {
  311. bcm->dev = serdev_device_get_drvdata(hu->serdev);
  312. goto out;
  313. }
  314. if (!hu->tty->dev)
  315. goto out;
  316. list_for_each(p, &bcm_device_list) {
  317. struct bcm_device *dev = list_entry(p, struct bcm_device, list);
  318. /* Retrieve saved bcm_device based on parent of the
  319. * platform device (saved during device probe) and
  320. * parent of tty device used by hci_uart
  321. */
  322. if (hu->tty->dev->parent == dev->dev->parent) {
  323. bcm->dev = dev;
  324. #ifdef CONFIG_PM
  325. dev->hu = hu;
  326. #endif
  327. break;
  328. }
  329. }
  330. out:
  331. if (bcm->dev) {
  332. hu->init_speed = bcm->dev->init_speed;
  333. hu->oper_speed = bcm->dev->oper_speed;
  334. err = bcm_gpio_set_power(bcm->dev, true);
  335. if (err)
  336. goto err_unset_hu;
  337. }
  338. mutex_unlock(&bcm_device_lock);
  339. return 0;
  340. err_unset_hu:
  341. #ifdef CONFIG_PM
  342. if (!hu->serdev)
  343. bcm->dev->hu = NULL;
  344. #endif
  345. mutex_unlock(&bcm_device_lock);
  346. hu->priv = NULL;
  347. kfree(bcm);
  348. return err;
  349. }
  350. static int bcm_close(struct hci_uart *hu)
  351. {
  352. struct bcm_data *bcm = hu->priv;
  353. struct bcm_device *bdev = NULL;
  354. int err;
  355. bt_dev_dbg(hu->hdev, "hu %p", hu);
  356. /* Protect bcm->dev against removal of the device or driver */
  357. mutex_lock(&bcm_device_lock);
  358. if (hu->serdev) {
  359. bdev = serdev_device_get_drvdata(hu->serdev);
  360. } else if (bcm_device_exists(bcm->dev)) {
  361. bdev = bcm->dev;
  362. #ifdef CONFIG_PM
  363. bdev->hu = NULL;
  364. #endif
  365. }
  366. if (bdev) {
  367. if (IS_ENABLED(CONFIG_PM) && bdev->irq > 0) {
  368. devm_free_irq(bdev->dev, bdev->irq, bdev);
  369. device_init_wakeup(bdev->dev, false);
  370. pm_runtime_disable(bdev->dev);
  371. }
  372. err = bcm_gpio_set_power(bdev, false);
  373. if (err)
  374. bt_dev_err(hu->hdev, "Failed to power down");
  375. else
  376. pm_runtime_set_suspended(bdev->dev);
  377. }
  378. mutex_unlock(&bcm_device_lock);
  379. skb_queue_purge(&bcm->txq);
  380. kfree_skb(bcm->rx_skb);
  381. kfree(bcm);
  382. hu->priv = NULL;
  383. return 0;
  384. }
  385. static int bcm_flush(struct hci_uart *hu)
  386. {
  387. struct bcm_data *bcm = hu->priv;
  388. bt_dev_dbg(hu->hdev, "hu %p", hu);
  389. skb_queue_purge(&bcm->txq);
  390. return 0;
  391. }
  392. static int bcm_setup(struct hci_uart *hu)
  393. {
  394. struct bcm_data *bcm = hu->priv;
  395. char fw_name[64];
  396. const struct firmware *fw;
  397. unsigned int speed;
  398. int err;
  399. bt_dev_dbg(hu->hdev, "hu %p", hu);
  400. hu->hdev->set_diag = bcm_set_diag;
  401. hu->hdev->set_bdaddr = btbcm_set_bdaddr;
  402. err = btbcm_initialize(hu->hdev, fw_name, sizeof(fw_name), false);
  403. if (err)
  404. return err;
  405. err = request_firmware(&fw, fw_name, &hu->hdev->dev);
  406. if (err < 0) {
  407. bt_dev_info(hu->hdev, "BCM: Patch %s not found", fw_name);
  408. return 0;
  409. }
  410. err = btbcm_patchram(hu->hdev, fw);
  411. if (err) {
  412. bt_dev_info(hu->hdev, "BCM: Patch failed (%d)", err);
  413. goto finalize;
  414. }
  415. /* Init speed if any */
  416. if (hu->init_speed)
  417. speed = hu->init_speed;
  418. else if (hu->proto->init_speed)
  419. speed = hu->proto->init_speed;
  420. else
  421. speed = 0;
  422. if (speed)
  423. host_set_baudrate(hu, speed);
  424. /* Operational speed if any */
  425. if (hu->oper_speed)
  426. speed = hu->oper_speed;
  427. else if (hu->proto->oper_speed)
  428. speed = hu->proto->oper_speed;
  429. else
  430. speed = 0;
  431. if (speed) {
  432. err = bcm_set_baudrate(hu, speed);
  433. if (!err)
  434. host_set_baudrate(hu, speed);
  435. }
  436. finalize:
  437. release_firmware(fw);
  438. err = btbcm_finalize(hu->hdev);
  439. if (err)
  440. return err;
  441. if (!bcm_request_irq(bcm))
  442. err = bcm_setup_sleep(hu);
  443. return err;
  444. }
  445. #define BCM_RECV_LM_DIAG \
  446. .type = BCM_LM_DIAG_PKT, \
  447. .hlen = BCM_LM_DIAG_SIZE, \
  448. .loff = 0, \
  449. .lsize = 0, \
  450. .maxlen = BCM_LM_DIAG_SIZE
  451. #define BCM_RECV_NULL \
  452. .type = BCM_NULL_PKT, \
  453. .hlen = BCM_NULL_SIZE, \
  454. .loff = 0, \
  455. .lsize = 0, \
  456. .maxlen = BCM_NULL_SIZE
  457. static const struct h4_recv_pkt bcm_recv_pkts[] = {
  458. { H4_RECV_ACL, .recv = hci_recv_frame },
  459. { H4_RECV_SCO, .recv = hci_recv_frame },
  460. { H4_RECV_EVENT, .recv = hci_recv_frame },
  461. { BCM_RECV_LM_DIAG, .recv = hci_recv_diag },
  462. { BCM_RECV_NULL, .recv = hci_recv_diag },
  463. };
  464. static int bcm_recv(struct hci_uart *hu, const void *data, int count)
  465. {
  466. struct bcm_data *bcm = hu->priv;
  467. if (!test_bit(HCI_UART_REGISTERED, &hu->flags))
  468. return -EUNATCH;
  469. bcm->rx_skb = h4_recv_buf(hu->hdev, bcm->rx_skb, data, count,
  470. bcm_recv_pkts, ARRAY_SIZE(bcm_recv_pkts));
  471. if (IS_ERR(bcm->rx_skb)) {
  472. int err = PTR_ERR(bcm->rx_skb);
  473. bt_dev_err(hu->hdev, "Frame reassembly failed (%d)", err);
  474. bcm->rx_skb = NULL;
  475. return err;
  476. } else if (!bcm->rx_skb) {
  477. /* Delay auto-suspend when receiving completed packet */
  478. mutex_lock(&bcm_device_lock);
  479. if (bcm->dev && bcm_device_exists(bcm->dev)) {
  480. pm_runtime_get(bcm->dev->dev);
  481. pm_runtime_mark_last_busy(bcm->dev->dev);
  482. pm_runtime_put_autosuspend(bcm->dev->dev);
  483. }
  484. mutex_unlock(&bcm_device_lock);
  485. }
  486. return count;
  487. }
  488. static int bcm_enqueue(struct hci_uart *hu, struct sk_buff *skb)
  489. {
  490. struct bcm_data *bcm = hu->priv;
  491. bt_dev_dbg(hu->hdev, "hu %p skb %p", hu, skb);
  492. /* Prepend skb with frame type */
  493. memcpy(skb_push(skb, 1), &hci_skb_pkt_type(skb), 1);
  494. skb_queue_tail(&bcm->txq, skb);
  495. return 0;
  496. }
  497. static struct sk_buff *bcm_dequeue(struct hci_uart *hu)
  498. {
  499. struct bcm_data *bcm = hu->priv;
  500. struct sk_buff *skb = NULL;
  501. struct bcm_device *bdev = NULL;
  502. mutex_lock(&bcm_device_lock);
  503. if (bcm_device_exists(bcm->dev)) {
  504. bdev = bcm->dev;
  505. pm_runtime_get_sync(bdev->dev);
  506. /* Shall be resumed here */
  507. }
  508. skb = skb_dequeue(&bcm->txq);
  509. if (bdev) {
  510. pm_runtime_mark_last_busy(bdev->dev);
  511. pm_runtime_put_autosuspend(bdev->dev);
  512. }
  513. mutex_unlock(&bcm_device_lock);
  514. return skb;
  515. }
  516. #ifdef CONFIG_PM
  517. static int bcm_suspend_device(struct device *dev)
  518. {
  519. struct bcm_device *bdev = dev_get_drvdata(dev);
  520. int err;
  521. bt_dev_dbg(bdev, "");
  522. if (!bdev->is_suspended && bdev->hu) {
  523. hci_uart_set_flow_control(bdev->hu, true);
  524. /* Once this returns, driver suspends BT via GPIO */
  525. bdev->is_suspended = true;
  526. }
  527. /* Suspend the device */
  528. err = bdev->set_device_wakeup(bdev, false);
  529. if (err) {
  530. if (bdev->is_suspended && bdev->hu) {
  531. bdev->is_suspended = false;
  532. hci_uart_set_flow_control(bdev->hu, false);
  533. }
  534. return -EBUSY;
  535. }
  536. bt_dev_dbg(bdev, "suspend, delaying 15 ms");
  537. msleep(15);
  538. return 0;
  539. }
  540. static int bcm_resume_device(struct device *dev)
  541. {
  542. struct bcm_device *bdev = dev_get_drvdata(dev);
  543. int err;
  544. bt_dev_dbg(bdev, "");
  545. err = bdev->set_device_wakeup(bdev, true);
  546. if (err) {
  547. dev_err(dev, "Failed to power up\n");
  548. return err;
  549. }
  550. bt_dev_dbg(bdev, "resume, delaying 15 ms");
  551. msleep(15);
  552. /* When this executes, the device has woken up already */
  553. if (bdev->is_suspended && bdev->hu) {
  554. bdev->is_suspended = false;
  555. hci_uart_set_flow_control(bdev->hu, false);
  556. }
  557. return 0;
  558. }
  559. #endif
  560. #ifdef CONFIG_PM_SLEEP
  561. /* suspend callback */
  562. static int bcm_suspend(struct device *dev)
  563. {
  564. struct bcm_device *bdev = dev_get_drvdata(dev);
  565. int error;
  566. bt_dev_dbg(bdev, "suspend: is_suspended %d", bdev->is_suspended);
  567. /*
  568. * When used with a device instantiated as platform_device, bcm_suspend
  569. * can be called at any time as long as the platform device is bound,
  570. * so it should use bcm_device_lock to protect access to hci_uart
  571. * and device_wake-up GPIO.
  572. */
  573. mutex_lock(&bcm_device_lock);
  574. if (!bdev->hu)
  575. goto unlock;
  576. if (pm_runtime_active(dev))
  577. bcm_suspend_device(dev);
  578. if (device_may_wakeup(dev) && bdev->irq > 0) {
  579. error = enable_irq_wake(bdev->irq);
  580. if (!error)
  581. bt_dev_dbg(bdev, "BCM irq: enabled");
  582. }
  583. unlock:
  584. mutex_unlock(&bcm_device_lock);
  585. return 0;
  586. }
  587. /* resume callback */
  588. static int bcm_resume(struct device *dev)
  589. {
  590. struct bcm_device *bdev = dev_get_drvdata(dev);
  591. int err = 0;
  592. bt_dev_dbg(bdev, "resume: is_suspended %d", bdev->is_suspended);
  593. /*
  594. * When used with a device instantiated as platform_device, bcm_resume
  595. * can be called at any time as long as platform device is bound,
  596. * so it should use bcm_device_lock to protect access to hci_uart
  597. * and device_wake-up GPIO.
  598. */
  599. mutex_lock(&bcm_device_lock);
  600. if (!bdev->hu)
  601. goto unlock;
  602. if (device_may_wakeup(dev) && bdev->irq > 0) {
  603. disable_irq_wake(bdev->irq);
  604. bt_dev_dbg(bdev, "BCM irq: disabled");
  605. }
  606. err = bcm_resume_device(dev);
  607. unlock:
  608. mutex_unlock(&bcm_device_lock);
  609. if (!err) {
  610. pm_runtime_disable(dev);
  611. pm_runtime_set_active(dev);
  612. pm_runtime_enable(dev);
  613. }
  614. return 0;
  615. }
  616. #endif
  617. static const struct acpi_gpio_params first_gpio = { 0, 0, false };
  618. static const struct acpi_gpio_params second_gpio = { 1, 0, false };
  619. static const struct acpi_gpio_params third_gpio = { 2, 0, false };
  620. static const struct acpi_gpio_mapping acpi_bcm_int_last_gpios[] = {
  621. { "device-wakeup-gpios", &first_gpio, 1 },
  622. { "shutdown-gpios", &second_gpio, 1 },
  623. { "host-wakeup-gpios", &third_gpio, 1 },
  624. { },
  625. };
  626. static const struct acpi_gpio_mapping acpi_bcm_int_first_gpios[] = {
  627. { "host-wakeup-gpios", &first_gpio, 1 },
  628. { "device-wakeup-gpios", &second_gpio, 1 },
  629. { "shutdown-gpios", &third_gpio, 1 },
  630. { },
  631. };
  632. /* Some firmware reports an IRQ which does not work (wrong pin in fw table?) */
  633. static const struct dmi_system_id bcm_broken_irq_dmi_table[] = {
  634. {
  635. .ident = "Meegopad T08",
  636. .matches = {
  637. DMI_EXACT_MATCH(DMI_BOARD_VENDOR,
  638. "To be filled by OEM."),
  639. DMI_EXACT_MATCH(DMI_BOARD_NAME, "T3 MRD"),
  640. DMI_EXACT_MATCH(DMI_BOARD_VERSION, "V1.1"),
  641. },
  642. },
  643. { }
  644. };
  645. #ifdef CONFIG_ACPI
  646. static int bcm_resource(struct acpi_resource *ares, void *data)
  647. {
  648. struct bcm_device *dev = data;
  649. struct acpi_resource_extended_irq *irq;
  650. struct acpi_resource_gpio *gpio;
  651. struct acpi_resource_uart_serialbus *sb;
  652. switch (ares->type) {
  653. case ACPI_RESOURCE_TYPE_EXTENDED_IRQ:
  654. irq = &ares->data.extended_irq;
  655. if (irq->polarity != ACPI_ACTIVE_LOW)
  656. dev_info(dev->dev, "ACPI Interrupt resource is active-high, this is usually wrong, treating the IRQ as active-low\n");
  657. dev->irq_active_low = true;
  658. break;
  659. case ACPI_RESOURCE_TYPE_GPIO:
  660. gpio = &ares->data.gpio;
  661. if (gpio->connection_type == ACPI_RESOURCE_GPIO_TYPE_INT) {
  662. dev->gpio_int_idx = dev->gpio_count;
  663. dev->irq_active_low = gpio->polarity == ACPI_ACTIVE_LOW;
  664. }
  665. dev->gpio_count++;
  666. break;
  667. case ACPI_RESOURCE_TYPE_SERIAL_BUS:
  668. sb = &ares->data.uart_serial_bus;
  669. if (sb->type == ACPI_RESOURCE_SERIAL_TYPE_UART) {
  670. dev->init_speed = sb->default_baud_rate;
  671. dev->oper_speed = 4000000;
  672. }
  673. break;
  674. default:
  675. break;
  676. }
  677. return 0;
  678. }
  679. static int bcm_apple_set_device_wakeup(struct bcm_device *dev, bool awake)
  680. {
  681. if (ACPI_FAILURE(acpi_execute_simple_method(dev->btlp, NULL, !awake)))
  682. return -EIO;
  683. return 0;
  684. }
  685. static int bcm_apple_set_shutdown(struct bcm_device *dev, bool powered)
  686. {
  687. if (ACPI_FAILURE(acpi_evaluate_object(powered ? dev->btpu : dev->btpd,
  688. NULL, NULL, NULL)))
  689. return -EIO;
  690. return 0;
  691. }
  692. static int bcm_apple_get_resources(struct bcm_device *dev)
  693. {
  694. struct acpi_device *adev = ACPI_COMPANION(dev->dev);
  695. const union acpi_object *obj;
  696. if (!adev ||
  697. ACPI_FAILURE(acpi_get_handle(adev->handle, "BTLP", &dev->btlp)) ||
  698. ACPI_FAILURE(acpi_get_handle(adev->handle, "BTPU", &dev->btpu)) ||
  699. ACPI_FAILURE(acpi_get_handle(adev->handle, "BTPD", &dev->btpd)))
  700. return -ENODEV;
  701. if (!acpi_dev_get_property(adev, "baud", ACPI_TYPE_BUFFER, &obj) &&
  702. obj->buffer.length == 8)
  703. dev->init_speed = *(u64 *)obj->buffer.pointer;
  704. dev->set_device_wakeup = bcm_apple_set_device_wakeup;
  705. dev->set_shutdown = bcm_apple_set_shutdown;
  706. return 0;
  707. }
  708. #else
  709. static inline int bcm_apple_get_resources(struct bcm_device *dev)
  710. {
  711. return -EOPNOTSUPP;
  712. }
  713. #endif /* CONFIG_ACPI */
  714. static int bcm_gpio_set_device_wakeup(struct bcm_device *dev, bool awake)
  715. {
  716. gpiod_set_value_cansleep(dev->device_wakeup, awake);
  717. return 0;
  718. }
  719. static int bcm_gpio_set_shutdown(struct bcm_device *dev, bool powered)
  720. {
  721. gpiod_set_value_cansleep(dev->shutdown, powered);
  722. return 0;
  723. }
  724. static int bcm_get_resources(struct bcm_device *dev)
  725. {
  726. const struct dmi_system_id *dmi_id;
  727. dev->name = dev_name(dev->dev);
  728. if (x86_apple_machine && !bcm_apple_get_resources(dev))
  729. return 0;
  730. dev->clk = devm_clk_get(dev->dev, NULL);
  731. dev->device_wakeup = devm_gpiod_get_optional(dev->dev, "device-wakeup",
  732. GPIOD_OUT_LOW);
  733. if (IS_ERR(dev->device_wakeup))
  734. return PTR_ERR(dev->device_wakeup);
  735. dev->shutdown = devm_gpiod_get_optional(dev->dev, "shutdown",
  736. GPIOD_OUT_LOW);
  737. if (IS_ERR(dev->shutdown))
  738. return PTR_ERR(dev->shutdown);
  739. dev->set_device_wakeup = bcm_gpio_set_device_wakeup;
  740. dev->set_shutdown = bcm_gpio_set_shutdown;
  741. /* IRQ can be declared in ACPI table as Interrupt or GpioInt */
  742. if (dev->irq <= 0) {
  743. struct gpio_desc *gpio;
  744. gpio = devm_gpiod_get_optional(dev->dev, "host-wakeup",
  745. GPIOD_IN);
  746. if (IS_ERR(gpio))
  747. return PTR_ERR(gpio);
  748. dev->irq = gpiod_to_irq(gpio);
  749. }
  750. dmi_id = dmi_first_match(bcm_broken_irq_dmi_table);
  751. if (dmi_id) {
  752. dev_info(dev->dev, "%s: Has a broken IRQ config, disabling IRQ support / runtime-pm\n",
  753. dmi_id->ident);
  754. dev->irq = 0;
  755. }
  756. dev_dbg(dev->dev, "BCM irq: %d\n", dev->irq);
  757. return 0;
  758. }
  759. #ifdef CONFIG_ACPI
  760. static int bcm_acpi_probe(struct bcm_device *dev)
  761. {
  762. LIST_HEAD(resources);
  763. const struct acpi_gpio_mapping *gpio_mapping = acpi_bcm_int_last_gpios;
  764. struct resource_entry *entry;
  765. int ret;
  766. /* Retrieve UART ACPI info */
  767. dev->gpio_int_idx = -1;
  768. ret = acpi_dev_get_resources(ACPI_COMPANION(dev->dev),
  769. &resources, bcm_resource, dev);
  770. if (ret < 0)
  771. return ret;
  772. resource_list_for_each_entry(entry, &resources) {
  773. if (resource_type(entry->res) == IORESOURCE_IRQ) {
  774. dev->irq = entry->res->start;
  775. break;
  776. }
  777. }
  778. acpi_dev_free_resource_list(&resources);
  779. /* If the DSDT uses an Interrupt resource for the IRQ, then there are
  780. * only 2 GPIO resources, we use the irq-last mapping for this, since
  781. * we already have an irq the 3th / last mapping will not be used.
  782. */
  783. if (dev->irq)
  784. gpio_mapping = acpi_bcm_int_last_gpios;
  785. else if (dev->gpio_int_idx == 0)
  786. gpio_mapping = acpi_bcm_int_first_gpios;
  787. else if (dev->gpio_int_idx == 2)
  788. gpio_mapping = acpi_bcm_int_last_gpios;
  789. else
  790. dev_warn(dev->dev, "Unexpected ACPI gpio_int_idx: %d\n",
  791. dev->gpio_int_idx);
  792. /* Warn if our expectations are not met. */
  793. if (dev->gpio_count != (dev->irq ? 2 : 3))
  794. dev_warn(dev->dev, "Unexpected number of ACPI GPIOs: %d\n",
  795. dev->gpio_count);
  796. ret = devm_acpi_dev_add_driver_gpios(dev->dev, gpio_mapping);
  797. if (ret)
  798. return ret;
  799. if (irq_polarity != -1) {
  800. dev->irq_active_low = irq_polarity;
  801. dev_warn(dev->dev, "Overwriting IRQ polarity to active %s by module-param\n",
  802. dev->irq_active_low ? "low" : "high");
  803. }
  804. return 0;
  805. }
  806. #else
  807. static int bcm_acpi_probe(struct bcm_device *dev)
  808. {
  809. return -EINVAL;
  810. }
  811. #endif /* CONFIG_ACPI */
  812. static int bcm_of_probe(struct bcm_device *bdev)
  813. {
  814. device_property_read_u32(bdev->dev, "max-speed", &bdev->oper_speed);
  815. return 0;
  816. }
  817. static int bcm_probe(struct platform_device *pdev)
  818. {
  819. struct bcm_device *dev;
  820. int ret;
  821. dev = devm_kzalloc(&pdev->dev, sizeof(*dev), GFP_KERNEL);
  822. if (!dev)
  823. return -ENOMEM;
  824. dev->dev = &pdev->dev;
  825. dev->irq = platform_get_irq(pdev, 0);
  826. if (has_acpi_companion(&pdev->dev)) {
  827. ret = bcm_acpi_probe(dev);
  828. if (ret)
  829. return ret;
  830. }
  831. ret = bcm_get_resources(dev);
  832. if (ret)
  833. return ret;
  834. platform_set_drvdata(pdev, dev);
  835. dev_info(&pdev->dev, "%s device registered.\n", dev->name);
  836. /* Place this instance on the device list */
  837. mutex_lock(&bcm_device_lock);
  838. list_add_tail(&dev->list, &bcm_device_list);
  839. mutex_unlock(&bcm_device_lock);
  840. ret = bcm_gpio_set_power(dev, false);
  841. if (ret)
  842. dev_err(&pdev->dev, "Failed to power down\n");
  843. return 0;
  844. }
  845. static int bcm_remove(struct platform_device *pdev)
  846. {
  847. struct bcm_device *dev = platform_get_drvdata(pdev);
  848. mutex_lock(&bcm_device_lock);
  849. list_del(&dev->list);
  850. mutex_unlock(&bcm_device_lock);
  851. dev_info(&pdev->dev, "%s device unregistered.\n", dev->name);
  852. return 0;
  853. }
  854. static const struct hci_uart_proto bcm_proto = {
  855. .id = HCI_UART_BCM,
  856. .name = "Broadcom",
  857. .manufacturer = 15,
  858. .init_speed = 115200,
  859. .open = bcm_open,
  860. .close = bcm_close,
  861. .flush = bcm_flush,
  862. .setup = bcm_setup,
  863. .set_baudrate = bcm_set_baudrate,
  864. .recv = bcm_recv,
  865. .enqueue = bcm_enqueue,
  866. .dequeue = bcm_dequeue,
  867. };
  868. #ifdef CONFIG_ACPI
  869. static const struct acpi_device_id bcm_acpi_match[] = {
  870. { "BCM2E00" },
  871. { "BCM2E01" },
  872. { "BCM2E02" },
  873. { "BCM2E03" },
  874. { "BCM2E04" },
  875. { "BCM2E05" },
  876. { "BCM2E06" },
  877. { "BCM2E07" },
  878. { "BCM2E08" },
  879. { "BCM2E09" },
  880. { "BCM2E0A" },
  881. { "BCM2E0B" },
  882. { "BCM2E0C" },
  883. { "BCM2E0D" },
  884. { "BCM2E0E" },
  885. { "BCM2E0F" },
  886. { "BCM2E10" },
  887. { "BCM2E11" },
  888. { "BCM2E12" },
  889. { "BCM2E13" },
  890. { "BCM2E14" },
  891. { "BCM2E15" },
  892. { "BCM2E16" },
  893. { "BCM2E17" },
  894. { "BCM2E18" },
  895. { "BCM2E19" },
  896. { "BCM2E1A" },
  897. { "BCM2E1B" },
  898. { "BCM2E1C" },
  899. { "BCM2E1D" },
  900. { "BCM2E1F" },
  901. { "BCM2E20" },
  902. { "BCM2E21" },
  903. { "BCM2E22" },
  904. { "BCM2E23" },
  905. { "BCM2E24" },
  906. { "BCM2E25" },
  907. { "BCM2E26" },
  908. { "BCM2E27" },
  909. { "BCM2E28" },
  910. { "BCM2E29" },
  911. { "BCM2E2A" },
  912. { "BCM2E2B" },
  913. { "BCM2E2C" },
  914. { "BCM2E2D" },
  915. { "BCM2E2E" },
  916. { "BCM2E2F" },
  917. { "BCM2E30" },
  918. { "BCM2E31" },
  919. { "BCM2E32" },
  920. { "BCM2E33" },
  921. { "BCM2E34" },
  922. { "BCM2E35" },
  923. { "BCM2E36" },
  924. { "BCM2E37" },
  925. { "BCM2E38" },
  926. { "BCM2E39" },
  927. { "BCM2E3A" },
  928. { "BCM2E3B" },
  929. { "BCM2E3C" },
  930. { "BCM2E3D" },
  931. { "BCM2E3E" },
  932. { "BCM2E3F" },
  933. { "BCM2E40" },
  934. { "BCM2E41" },
  935. { "BCM2E42" },
  936. { "BCM2E43" },
  937. { "BCM2E44" },
  938. { "BCM2E45" },
  939. { "BCM2E46" },
  940. { "BCM2E47" },
  941. { "BCM2E48" },
  942. { "BCM2E49" },
  943. { "BCM2E4A" },
  944. { "BCM2E4B" },
  945. { "BCM2E4C" },
  946. { "BCM2E4D" },
  947. { "BCM2E4E" },
  948. { "BCM2E4F" },
  949. { "BCM2E50" },
  950. { "BCM2E51" },
  951. { "BCM2E52" },
  952. { "BCM2E53" },
  953. { "BCM2E54" },
  954. { "BCM2E55" },
  955. { "BCM2E56" },
  956. { "BCM2E57" },
  957. { "BCM2E58" },
  958. { "BCM2E59" },
  959. { "BCM2E5A" },
  960. { "BCM2E5B" },
  961. { "BCM2E5C" },
  962. { "BCM2E5D" },
  963. { "BCM2E5E" },
  964. { "BCM2E5F" },
  965. { "BCM2E60" },
  966. { "BCM2E61" },
  967. { "BCM2E62" },
  968. { "BCM2E63" },
  969. { "BCM2E64" },
  970. { "BCM2E65" },
  971. { "BCM2E66" },
  972. { "BCM2E67" },
  973. { "BCM2E68" },
  974. { "BCM2E69" },
  975. { "BCM2E6B" },
  976. { "BCM2E6D" },
  977. { "BCM2E6E" },
  978. { "BCM2E6F" },
  979. { "BCM2E70" },
  980. { "BCM2E71" },
  981. { "BCM2E72" },
  982. { "BCM2E73" },
  983. { "BCM2E74" },
  984. { "BCM2E75" },
  985. { "BCM2E76" },
  986. { "BCM2E77" },
  987. { "BCM2E78" },
  988. { "BCM2E79" },
  989. { "BCM2E7A" },
  990. { "BCM2E7B" },
  991. { "BCM2E7C" },
  992. { "BCM2E7D" },
  993. { "BCM2E7E" },
  994. { "BCM2E7F" },
  995. { "BCM2E80" },
  996. { "BCM2E81" },
  997. { "BCM2E82" },
  998. { "BCM2E83" },
  999. { "BCM2E84" },
  1000. { "BCM2E85" },
  1001. { "BCM2E86" },
  1002. { "BCM2E87" },
  1003. { "BCM2E88" },
  1004. { "BCM2E89" },
  1005. { "BCM2E8A" },
  1006. { "BCM2E8B" },
  1007. { "BCM2E8C" },
  1008. { "BCM2E8D" },
  1009. { "BCM2E8E" },
  1010. { "BCM2E90" },
  1011. { "BCM2E92" },
  1012. { "BCM2E93" },
  1013. { "BCM2E94" },
  1014. { "BCM2E95" },
  1015. { "BCM2E96" },
  1016. { "BCM2E97" },
  1017. { "BCM2E98" },
  1018. { "BCM2E99" },
  1019. { "BCM2E9A" },
  1020. { "BCM2E9B" },
  1021. { "BCM2E9C" },
  1022. { "BCM2E9D" },
  1023. { "BCM2EA0" },
  1024. { "BCM2EA1" },
  1025. { "BCM2EA2" },
  1026. { "BCM2EA3" },
  1027. { "BCM2EA4" },
  1028. { "BCM2EA5" },
  1029. { "BCM2EA6" },
  1030. { "BCM2EA7" },
  1031. { "BCM2EA8" },
  1032. { "BCM2EA9" },
  1033. { "BCM2EAA" },
  1034. { "BCM2EAB" },
  1035. { "BCM2EAC" },
  1036. { },
  1037. };
  1038. MODULE_DEVICE_TABLE(acpi, bcm_acpi_match);
  1039. #endif
  1040. /* suspend and resume callbacks */
  1041. static const struct dev_pm_ops bcm_pm_ops = {
  1042. SET_SYSTEM_SLEEP_PM_OPS(bcm_suspend, bcm_resume)
  1043. SET_RUNTIME_PM_OPS(bcm_suspend_device, bcm_resume_device, NULL)
  1044. };
  1045. static struct platform_driver bcm_driver = {
  1046. .probe = bcm_probe,
  1047. .remove = bcm_remove,
  1048. .driver = {
  1049. .name = "hci_bcm",
  1050. .acpi_match_table = ACPI_PTR(bcm_acpi_match),
  1051. .pm = &bcm_pm_ops,
  1052. },
  1053. };
  1054. static int bcm_serdev_probe(struct serdev_device *serdev)
  1055. {
  1056. struct bcm_device *bcmdev;
  1057. int err;
  1058. bcmdev = devm_kzalloc(&serdev->dev, sizeof(*bcmdev), GFP_KERNEL);
  1059. if (!bcmdev)
  1060. return -ENOMEM;
  1061. bcmdev->dev = &serdev->dev;
  1062. #ifdef CONFIG_PM
  1063. bcmdev->hu = &bcmdev->serdev_hu;
  1064. #endif
  1065. bcmdev->serdev_hu.serdev = serdev;
  1066. serdev_device_set_drvdata(serdev, bcmdev);
  1067. if (has_acpi_companion(&serdev->dev))
  1068. err = bcm_acpi_probe(bcmdev);
  1069. else
  1070. err = bcm_of_probe(bcmdev);
  1071. if (err)
  1072. return err;
  1073. err = bcm_get_resources(bcmdev);
  1074. if (err)
  1075. return err;
  1076. if (!bcmdev->shutdown) {
  1077. dev_warn(&serdev->dev,
  1078. "No reset resource, using default baud rate\n");
  1079. bcmdev->oper_speed = bcmdev->init_speed;
  1080. }
  1081. err = bcm_gpio_set_power(bcmdev, false);
  1082. if (err)
  1083. dev_err(&serdev->dev, "Failed to power down\n");
  1084. return hci_uart_register_device(&bcmdev->serdev_hu, &bcm_proto);
  1085. }
  1086. static void bcm_serdev_remove(struct serdev_device *serdev)
  1087. {
  1088. struct bcm_device *bcmdev = serdev_device_get_drvdata(serdev);
  1089. hci_uart_unregister_device(&bcmdev->serdev_hu);
  1090. }
  1091. #ifdef CONFIG_OF
  1092. static const struct of_device_id bcm_bluetooth_of_match[] = {
  1093. { .compatible = "brcm,bcm43438-bt" },
  1094. { },
  1095. };
  1096. MODULE_DEVICE_TABLE(of, bcm_bluetooth_of_match);
  1097. #endif
  1098. static struct serdev_device_driver bcm_serdev_driver = {
  1099. .probe = bcm_serdev_probe,
  1100. .remove = bcm_serdev_remove,
  1101. .driver = {
  1102. .name = "hci_uart_bcm",
  1103. .of_match_table = of_match_ptr(bcm_bluetooth_of_match),
  1104. .acpi_match_table = ACPI_PTR(bcm_acpi_match),
  1105. .pm = &bcm_pm_ops,
  1106. },
  1107. };
  1108. int __init bcm_init(void)
  1109. {
  1110. /* For now, we need to keep both platform device
  1111. * driver (ACPI generated) and serdev driver (DT).
  1112. */
  1113. platform_driver_register(&bcm_driver);
  1114. serdev_device_driver_register(&bcm_serdev_driver);
  1115. return hci_uart_register_proto(&bcm_proto);
  1116. }
  1117. int __exit bcm_deinit(void)
  1118. {
  1119. platform_driver_unregister(&bcm_driver);
  1120. serdev_device_driver_unregister(&bcm_serdev_driver);
  1121. return hci_uart_unregister_proto(&bcm_proto);
  1122. }