Lines Matching +full:firmware +full:- +full:initialized

1 // SPDX-License-Identifier: GPL-2.0-or-later
6 * Copyright (C) 2015-2017 Sebastian Reichel <sre@kernel.org>
11 #include <linux/firmware.h>
144 bool initialized; member
165 struct device *dev = &btdev->serdev->dev; in wakeup_handler()
166 int wake_state = gpiod_get_value(btdev->wakeup_host); in wakeup_handler()
168 if (btdev->rx_enabled == wake_state) in wakeup_handler()
176 btdev->rx_enabled = wake_state; in wakeup_handler()
183 struct nokia_bt_dev *btdev = hu->priv; in nokia_reset()
184 struct device *dev = &btdev->serdev->dev; in nokia_reset()
188 gpiod_set_value_cansleep(btdev->reset, 1); in nokia_reset()
189 gpiod_set_value_cansleep(btdev->wakeup_bt, 1); in nokia_reset()
194 err = gpiod_get_value_cansleep(btdev->wakeup_host); in nokia_reset()
197 return -EPROTO; in nokia_reset()
201 serdev_device_write_flush(btdev->serdev); in nokia_reset()
204 nokia_flow_control(btdev->serdev, false); in nokia_reset()
205 serdev_device_set_baudrate(btdev->serdev, INIT_BAUD_RATE); in nokia_reset()
207 gpiod_set_value_cansleep(btdev->reset, 0); in nokia_reset()
210 err = serdev_device_wait_for_cts(btdev->serdev, true, 200); in nokia_reset()
216 nokia_flow_control(btdev->serdev, true); in nokia_reset()
223 struct nokia_bt_dev *btdev = hu->priv; in nokia_send_alive_packet()
224 struct device *dev = &btdev->serdev->dev; in nokia_send_alive_packet()
230 init_completion(&btdev->init_completion); in nokia_send_alive_packet()
235 return -ENOMEM; in nokia_send_alive_packet()
238 memset(skb->data, 0x00, len); in nokia_send_alive_packet()
241 hdr->dlen = sizeof(*pkt); in nokia_send_alive_packet()
243 pkt->mid = NOKIA_ALIVE_REQ; in nokia_send_alive_packet()
250 if (!wait_for_completion_interruptible_timeout(&btdev->init_completion, in nokia_send_alive_packet()
252 return -ETIMEDOUT; in nokia_send_alive_packet()
255 if (btdev->init_error < 0) in nokia_send_alive_packet()
256 return btdev->init_error; in nokia_send_alive_packet()
263 struct nokia_bt_dev *btdev = hu->priv; in nokia_send_negotiation()
264 struct device *dev = &btdev->serdev->dev; in nokia_send_negotiation()
269 u16 baud = DIV_ROUND_CLOSEST(btdev->sysclk_speed * 10, SETUP_BAUD_RATE); in nokia_send_negotiation()
270 int sysclk = btdev->sysclk_speed / 1000; in nokia_send_negotiation()
275 return -ENOMEM; in nokia_send_negotiation()
280 neg_hdr->dlen = sizeof(*neg_cmd); in nokia_send_negotiation()
283 neg_cmd->ack = NOKIA_NEG_REQ; in nokia_send_negotiation()
284 neg_cmd->baud = cpu_to_le16(baud); in nokia_send_negotiation()
285 neg_cmd->unused1 = 0x0000; in nokia_send_negotiation()
286 neg_cmd->proto = NOKIA_PROTO_BYTE; in nokia_send_negotiation()
287 neg_cmd->sys_clk = cpu_to_le16(sysclk); in nokia_send_negotiation()
288 neg_cmd->unused2 = 0x0000; in nokia_send_negotiation()
290 btdev->init_error = 0; in nokia_send_negotiation()
291 init_completion(&btdev->init_completion); in nokia_send_negotiation()
298 if (!wait_for_completion_interruptible_timeout(&btdev->init_completion, in nokia_send_negotiation()
300 return -ETIMEDOUT; in nokia_send_negotiation()
303 if (btdev->init_error < 0) in nokia_send_negotiation()
304 return btdev->init_error; in nokia_send_negotiation()
310 nokia_flow_control(btdev->serdev, false); in nokia_send_negotiation()
311 serdev_device_set_baudrate(btdev->serdev, SETUP_BAUD_RATE); in nokia_send_negotiation()
312 err = serdev_device_wait_for_cts(btdev->serdev, true, 200); in nokia_send_negotiation()
317 nokia_flow_control(btdev->serdev, true); in nokia_send_negotiation()
326 struct nokia_bt_dev *btdev = hu->priv; in nokia_setup_fw()
327 struct device *dev = &btdev->serdev->dev; in nokia_setup_fw()
329 const struct firmware *fw; in nokia_setup_fw()
334 dev_dbg(dev, "setup firmware"); in nokia_setup_fw()
336 if (btdev->man_id == NOKIA_ID_BCM2048) { in nokia_setup_fw()
338 } else if (btdev->man_id == NOKIA_ID_TI1271) { in nokia_setup_fw()
342 return -ENODEV; in nokia_setup_fw()
347 dev_err(dev, "%s: Failed to load Nokia firmware file (%d)", in nokia_setup_fw()
348 hu->hdev->name, err); in nokia_setup_fw()
352 fw_ptr = fw->data; in nokia_setup_fw()
353 fw_size = fw->size; in nokia_setup_fw()
365 opcode = le16_to_cpu(cmd->opcode); in nokia_setup_fw()
367 skb = __hci_cmd_sync(hu->hdev, opcode, cmd->plen, in nokia_setup_fw()
373 hu->hdev->name, opcode, err); in nokia_setup_fw()
385 fw_size -= pkt_size + 2; in nokia_setup_fw()
395 struct nokia_bt_dev *btdev = hu->priv; in nokia_setup()
396 struct device *dev = &btdev->serdev->dev; in nokia_setup()
399 btdev->initialized = false; in nokia_setup()
401 nokia_flow_control(btdev->serdev, false); in nokia_setup()
405 if (btdev->tx_enabled) { in nokia_setup()
406 gpiod_set_value_cansleep(btdev->wakeup_bt, 0); in nokia_setup()
407 pm_runtime_put(&btdev->serdev->dev); in nokia_setup()
408 btdev->tx_enabled = false; in nokia_setup()
434 /* 3. send firmware */ in nokia_setup()
441 nokia_flow_control(btdev->serdev, false); in nokia_setup()
442 serdev_device_set_baudrate(btdev->serdev, MAX_BAUD_RATE); in nokia_setup()
443 nokia_flow_control(btdev->serdev, true); in nokia_setup()
445 if (btdev->man_id == NOKIA_ID_BCM2048) { in nokia_setup()
446 hu->hdev->set_bdaddr = btbcm_set_bdaddr; in nokia_setup()
447 set_bit(HCI_QUIRK_INVALID_BDADDR, &hu->hdev->quirks); in nokia_setup()
453 gpiod_set_value_cansleep(btdev->wakeup_bt, 0); in nokia_setup()
455 btdev->tx_enabled = false; in nokia_setup()
456 btdev->initialized = true; in nokia_setup()
467 struct device *dev = &hu->serdev->dev; in nokia_open()
478 struct nokia_bt_dev *btdev = hu->priv; in nokia_flush()
480 dev_dbg(&btdev->serdev->dev, "flush device"); in nokia_flush()
482 skb_queue_purge(&btdev->txq); in nokia_flush()
489 struct nokia_bt_dev *btdev = hu->priv; in nokia_close()
490 struct device *dev = &btdev->serdev->dev; in nokia_close()
494 btdev->initialized = false; in nokia_close()
496 skb_queue_purge(&btdev->txq); in nokia_close()
498 kfree_skb(btdev->rx_skb); in nokia_close()
501 gpiod_set_value(btdev->reset, 1); in nokia_close()
502 gpiod_set_value(btdev->wakeup_bt, 0); in nokia_close()
504 pm_runtime_disable(&btdev->serdev->dev); in nokia_close()
512 struct nokia_bt_dev *btdev = hu->priv; in nokia_enqueue()
516 memcpy(skb_push(skb, 1), &bt_cb(skb)->pkt_type, 1); in nokia_enqueue()
519 if (skb->len % 2) { in nokia_enqueue()
526 skb_queue_tail(&btdev->txq, skb); in nokia_enqueue()
535 struct nokia_bt_dev *btdev = hu->priv; in nokia_recv_negotiation_packet()
536 struct device *dev = &btdev->serdev->dev; in nokia_recv_negotiation_packet()
541 hdr = (struct hci_nokia_neg_hdr *)skb->data; in nokia_recv_negotiation_packet()
542 if (hdr->dlen != sizeof(*evt)) { in nokia_recv_negotiation_packet()
543 btdev->init_error = -EIO; in nokia_recv_negotiation_packet()
544 ret = -EIO; in nokia_recv_negotiation_packet()
550 if (evt->ack != NOKIA_NEG_ACK) { in nokia_recv_negotiation_packet()
552 btdev->init_error = -EINVAL; in nokia_recv_negotiation_packet()
553 ret = -EINVAL; in nokia_recv_negotiation_packet()
557 btdev->man_id = evt->man_id; in nokia_recv_negotiation_packet()
558 btdev->ver_id = evt->ver_id; in nokia_recv_negotiation_packet()
561 evt->baud, evt->sys_clk, evt->man_id, evt->ver_id); in nokia_recv_negotiation_packet()
564 complete(&btdev->init_completion); in nokia_recv_negotiation_packet()
572 struct nokia_bt_dev *btdev = hu->priv; in nokia_recv_alive_packet()
573 struct device *dev = &btdev->serdev->dev; in nokia_recv_alive_packet()
578 hdr = (struct hci_nokia_alive_hdr *)skb->data; in nokia_recv_alive_packet()
579 if (hdr->dlen != sizeof(*pkt)) { in nokia_recv_alive_packet()
581 btdev->init_error = -EIO; in nokia_recv_alive_packet()
582 ret = -EIO; in nokia_recv_alive_packet()
588 if (pkt->mid != NOKIA_ALIVE_RESP) { in nokia_recv_alive_packet()
590 pkt->mid); in nokia_recv_alive_packet()
591 btdev->init_error = -EINVAL; in nokia_recv_alive_packet()
592 ret = -EINVAL; in nokia_recv_alive_packet()
599 complete(&btdev->init_completion); in nokia_recv_alive_packet()
625 struct nokia_bt_dev *btdev = hu->priv; in nokia_recv()
626 struct device *dev = &btdev->serdev->dev; in nokia_recv()
629 if (!test_bit(HCI_UART_REGISTERED, &hu->flags)) in nokia_recv()
630 return -EUNATCH; in nokia_recv()
632 btdev->rx_skb = h4_recv_buf(hu->hdev, btdev->rx_skb, data, count, in nokia_recv()
634 if (IS_ERR(btdev->rx_skb)) { in nokia_recv()
635 err = PTR_ERR(btdev->rx_skb); in nokia_recv()
637 btdev->rx_skb = NULL; in nokia_recv()
646 struct nokia_bt_dev *btdev = hu->priv; in nokia_dequeue()
647 struct device *dev = &btdev->serdev->dev; in nokia_dequeue()
648 struct sk_buff *result = skb_dequeue(&btdev->txq); in nokia_dequeue()
650 if (!btdev->initialized) in nokia_dequeue()
653 if (btdev->tx_enabled == !!result) in nokia_dequeue()
658 gpiod_set_value_cansleep(btdev->wakeup_bt, 1); in nokia_dequeue()
660 serdev_device_wait_until_sent(btdev->serdev, 0); in nokia_dequeue()
661 gpiod_set_value_cansleep(btdev->wakeup_bt, 0); in nokia_dequeue()
665 btdev->tx_enabled = !!result; in nokia_dequeue()
685 struct device *dev = &serdev->dev; in nokia_bluetooth_serdev_probe()
692 return -ENOMEM; in nokia_bluetooth_serdev_probe()
694 btdev->hu.serdev = btdev->serdev = serdev; in nokia_bluetooth_serdev_probe()
697 btdev->reset = devm_gpiod_get(dev, "reset", GPIOD_OUT_HIGH); in nokia_bluetooth_serdev_probe()
698 if (IS_ERR(btdev->reset)) { in nokia_bluetooth_serdev_probe()
699 err = PTR_ERR(btdev->reset); in nokia_bluetooth_serdev_probe()
704 btdev->wakeup_host = devm_gpiod_get(dev, "host-wakeup", GPIOD_IN); in nokia_bluetooth_serdev_probe()
705 if (IS_ERR(btdev->wakeup_host)) { in nokia_bluetooth_serdev_probe()
706 err = PTR_ERR(btdev->wakeup_host); in nokia_bluetooth_serdev_probe()
711 btdev->wake_irq = gpiod_to_irq(btdev->wakeup_host); in nokia_bluetooth_serdev_probe()
713 err = devm_request_threaded_irq(dev, btdev->wake_irq, NULL, in nokia_bluetooth_serdev_probe()
722 btdev->wakeup_bt = devm_gpiod_get(dev, "bluetooth-wakeup", in nokia_bluetooth_serdev_probe()
724 if (IS_ERR(btdev->wakeup_bt)) { in nokia_bluetooth_serdev_probe()
725 err = PTR_ERR(btdev->wakeup_bt); in nokia_bluetooth_serdev_probe()
742 btdev->sysclk_speed = clk_get_rate(sysclk); in nokia_bluetooth_serdev_probe()
745 skb_queue_head_init(&btdev->txq); in nokia_bluetooth_serdev_probe()
747 btdev->hu.priv = btdev; in nokia_bluetooth_serdev_probe()
748 btdev->hu.alignment = 2; /* Nokia H4+ is word aligned */ in nokia_bluetooth_serdev_probe()
750 err = hci_uart_register_device(&btdev->hu, &nokia_proto); in nokia_bluetooth_serdev_probe()
763 hci_uart_unregister_device(&btdev->hu); in nokia_bluetooth_serdev_remove()
790 { .compatible = "nokia,h4p-bluetooth", },
800 .name = "nokia-bluetooth",