Skip to content

Commit bf3c3cc

Browse files
Zhiyi ChenRebase bot
authored andcommitted
[bluetooth] Migrate bt-transport-uart to new composite spec
Test: 1. Bluetooth basic functionalities are verified by bt-cli tool on astro, sherlock, nelson and vim3. 2. CQ. Change-Id: I8a57ee4028095fb47a43a0cb105e07980f0cd8cb Reviewed-on: https://fuchsia-review.googlesource.com/c/fuchsia/+/863296 Commit-Queue: Zhiyi Chen <[email protected]> Reviewed-by: Sarah Chan <[email protected]>
1 parent 610aefd commit bf3c3cc

File tree

22 files changed

+201
-286
lines changed

22 files changed

+201
-286
lines changed

src/devices/board/drivers/astro/BUILD.gn

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,6 @@ driver_bind_rules("astro-bind") {
2525
]
2626
}
2727

28-
driver_bind_rules("astro-bluetooth-bind") {
29-
rules = "bind/astro-bluetooth.bind"
30-
header_output = "astro-bluetooth-bind.h"
31-
bind_output = "astro-bluetooth.bindbc"
32-
tests = "bind-tests/astro-bluetooth-test.json"
33-
deps = [
34-
"//src/devices/bind/fuchsia.amlogic.platform",
35-
"//src/devices/bind/fuchsia.hardware.pwm",
36-
"//src/devices/bind/fuchsia.platform",
37-
]
38-
}
39-
4028
driver_bind_rules("astro-buttons-bind") {
4129
rules = "bind/astro-buttons.bind"
4230
header_output = "astro-buttons-bind.h"
@@ -240,7 +228,6 @@ fuchsia_driver("astro-driver") {
240228
":astro-aml-sdio-bind_header",
241229
":astro-aml-usb-phy-v2-bind_header",
242230
":astro-bind",
243-
":astro-bluetooth-bind_header",
244231
":astro-buttons-bind_header",
245232
":astro-cpu-bind_header",
246233
":astro-dwc2-phy-bind_header",
@@ -330,7 +317,6 @@ group("tests") {
330317
":astro-aml-sdio-bind_test",
331318
":astro-aml-usb-phy-v2-bind_test",
332319
":astro-bind_test",
333-
":astro-bluetooth-bind_test",
334320
":astro-buttons-bind_test",
335321
":astro-cpu-bind_test",
336322
":astro-dwc2-phy-bind_test",

src/devices/board/drivers/astro/astro-bluetooth.cc

Lines changed: 37 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,13 @@
1414
#include <lib/mmio/mmio.h>
1515
#include <unistd.h>
1616

17+
#include <bind/fuchsia/cpp/bind.h>
18+
#include <bind/fuchsia/hardware/pwm/cpp/bind.h>
19+
#include <sdk/lib/driver/component/cpp/composite_node_spec.h>
20+
#include <sdk/lib/driver/component/cpp/node_add_args.h>
1721
#include <soc/aml-s905d2/s905d2-hw.h>
1822

1923
#include "astro.h"
20-
#include "src/devices/board/drivers/astro/astro-bluetooth-bind.h"
2124
#include "src/devices/bus/lib/platform-bus-composites/platform-bus-composite.h"
2225

2326
namespace astro {
@@ -96,21 +99,45 @@ zx_status_t Astro::BluetoothInit() {
9699
return status;
97100
}
98101

99-
// Bind UART for Bluetooth HCI
100-
fidl::Arena<> fidl_arena;
101102
fdf::Arena arena('BLUE');
102-
auto result = pbus_.buffer(arena)->AddComposite(
103-
fidl::ToWire(fidl_arena, bt_uart_dev),
104-
platform_bus_composite::MakeFidlFragment(fidl_arena, bt_uart_fragments,
105-
std::size(bt_uart_fragments)),
106-
"pdev");
103+
104+
fuchsia_driver_framework::wire::BindRule kPwmBindRules[] = {
105+
// TODO(fxbug.dev/129042): Replace this with wire type function.
106+
fidl::ToWire(arena, fdf::MakeAcceptBindRule(bind_fuchsia::INIT_STEP,
107+
bind_fuchsia_hardware_pwm::BIND_INIT_STEP_PWM)),
108+
};
109+
110+
fuchsia_driver_framework::wire::NodeProperty kPwmProperties[] = {
111+
fdf::MakeProperty(arena, bind_fuchsia::INIT_STEP,
112+
bind_fuchsia_hardware_pwm::BIND_INIT_STEP_PWM),
113+
};
114+
115+
auto parents = std::vector{
116+
fuchsia_driver_framework::wire::ParentSpec{
117+
.bind_rules = fidl::VectorView<fuchsia_driver_framework::wire::BindRule>::FromExternal(
118+
kPwmBindRules, 1),
119+
.properties =
120+
fidl::VectorView<fuchsia_driver_framework::wire::NodeProperty>::FromExternal(
121+
kPwmProperties, 1),
122+
},
123+
};
124+
125+
auto builder =
126+
fuchsia_driver_framework::wire::CompositeNodeSpec::Builder(arena)
127+
.name("bluetooth-composite-spec")
128+
.parents(fidl::VectorView<fuchsia_driver_framework::wire::ParentSpec>(arena, parents));
129+
130+
// Create composite spec for aml-uart based on UART and PWM nodes. The parent spec of bt_uart_dev
131+
// will be generated by the handler of AddCompositeNodeSpec.
132+
auto result =
133+
pbus_.buffer(arena)->AddCompositeNodeSpec(fidl::ToWire(arena, bt_uart_dev), builder.Build());
107134
if (!result.ok()) {
108-
zxlogf(ERROR, "%s: AddComposite Bluetooth(bt_uart_dev) request failed: %s", __func__,
135+
zxlogf(ERROR, "AddCompositeNodeSpec Bluetooth(bt_uart_dev) request failed: %s",
109136
result.FormatDescription().data());
110137
return result.status();
111138
}
112139
if (result->is_error()) {
113-
zxlogf(ERROR, "%s: AddComposite Bluetooth(bt_uart_dev) failed: %s", __func__,
140+
zxlogf(ERROR, "AddCompositeNodeSpec Bluetooth(bt_uart_dev) failed: %s",
114141
zx_status_get_string(result->error_value()));
115142
return result->error_value();
116143
}

src/devices/board/drivers/astro/bind-tests/astro-bluetooth-test.json

Lines changed: 0 additions & 30 deletions
This file was deleted.

src/devices/board/drivers/astro/bind/astro-bluetooth.bind

Lines changed: 0 additions & 21 deletions
This file was deleted.

src/devices/board/drivers/nelson/BUILD.gn

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -37,18 +37,6 @@ driver_bind_rules("nelson-bind") {
3737
]
3838
}
3939

40-
driver_bind_rules("nelson_bt_uart_bind") {
41-
rules = "bind/nelson_bt_uart.bind"
42-
header_output = "nelson_bt_uart_bind.h"
43-
bind_output = "nelson_bt_uart_bind.bc"
44-
tests = "bind-tests/nelson_bt_uart-test.json"
45-
deps = [
46-
"//src/devices/bind/fuchsia.amlogic.platform",
47-
"//src/devices/bind/fuchsia.hardware.pwm",
48-
"//src/devices/bind/fuchsia.platform",
49-
]
50-
}
51-
5240
driver_bind_rules("nelson_buttons_bind") {
5341
rules = "bind/nelson_buttons.bind"
5442
header_output = "nelson_buttons_bind.h"
@@ -331,7 +319,6 @@ fuchsia_driver("nelson-module-driver") {
331319
":nelson-bind",
332320
":nelson_aml_sdio_bind_header",
333321
":nelson_aml_video_bind_header",
334-
":nelson_bt_uart_bind_header",
335322
":nelson_buttons_bind_header",
336323
":nelson_dwc2_bind_header",
337324
":nelson_emmc_bind_header",
@@ -432,7 +419,6 @@ group("tests") {
432419
":nelson_aml_sdio_bind_test",
433420
":nelson_aml_video_bind_test",
434421
":nelson_aml_video_bind_test",
435-
":nelson_bt_uart_bind_test",
436422
":nelson_dwc2_bind_test",
437423
":nelson_ot_radio_bind_test",
438424
":nelson_selina_bind_test",

src/devices/board/drivers/nelson/bind-tests/nelson_bt_uart-test.json

Lines changed: 0 additions & 30 deletions
This file was deleted.

src/devices/board/drivers/nelson/bind/nelson_bt_uart.bind

Lines changed: 0 additions & 21 deletions
This file was deleted.

src/devices/board/drivers/nelson/nelson-bluetooth.cc

Lines changed: 37 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,14 @@
1414
#include <lib/mmio/mmio.h>
1515
#include <unistd.h>
1616

17+
#include <bind/fuchsia/cpp/bind.h>
18+
#include <bind/fuchsia/hardware/pwm/cpp/bind.h>
19+
#include <sdk/lib/driver/component/cpp/composite_node_spec.h>
20+
#include <sdk/lib/driver/component/cpp/node_add_args.h>
1721
#include <soc/aml-s905d3/s905d3-gpio.h>
1822
#include <soc/aml-s905d3/s905d3-hw.h>
1923

2024
#include "nelson.h"
21-
#include "src/devices/board/drivers/nelson/nelson_bt_uart_bind.h"
2225
#include "src/devices/bus/lib/platform-bus-composites/platform-bus-composite.h"
2326

2427
namespace nelson {
@@ -98,20 +101,45 @@ zx_status_t Nelson::BluetoothInit() {
98101
}
99102

100103
// Bind UART for Bluetooth HCI
101-
fidl::Arena<> fidl_arena;
102104
fdf::Arena arena('BLUE');
103-
auto result = pbus_.buffer(arena)->AddComposite(
104-
fidl::ToWire(fidl_arena, bt_uart_dev),
105-
platform_bus_composite::MakeFidlFragment(fidl_arena, bt_uart_fragments,
106-
std::size(bt_uart_fragments)),
107-
"pdev");
105+
106+
fuchsia_driver_framework::wire::BindRule kPwmBindRules[] = {
107+
// TODO(fxbug.dev/129042): Replace this with wire type function.
108+
fidl::ToWire(arena, fdf::MakeAcceptBindRule(bind_fuchsia::INIT_STEP,
109+
bind_fuchsia_hardware_pwm::BIND_INIT_STEP_PWM)),
110+
};
111+
112+
fuchsia_driver_framework::wire::NodeProperty kPwmProperties[] = {
113+
fdf::MakeProperty(arena, bind_fuchsia::INIT_STEP,
114+
bind_fuchsia_hardware_pwm::BIND_INIT_STEP_PWM),
115+
};
116+
117+
auto parents = std::vector{
118+
fuchsia_driver_framework::wire::ParentSpec{
119+
.bind_rules = fidl::VectorView<fuchsia_driver_framework::wire::BindRule>::FromExternal(
120+
kPwmBindRules, 1),
121+
.properties =
122+
fidl::VectorView<fuchsia_driver_framework::wire::NodeProperty>::FromExternal(
123+
kPwmProperties, 1),
124+
},
125+
};
126+
127+
auto builder =
128+
fuchsia_driver_framework::wire::CompositeNodeSpec::Builder(arena)
129+
.name("bluetooth-composite-spec")
130+
.parents(fidl::VectorView<fuchsia_driver_framework::wire::ParentSpec>(arena, parents));
131+
132+
// Create composite spec for aml-uart based on UART and PWM nodes. The parent spec of bt_uart_dev
133+
// will be generated by the handler of AddCompositeNodeSpec.
134+
auto result =
135+
pbus_.buffer(arena)->AddCompositeNodeSpec(fidl::ToWire(arena, bt_uart_dev), builder.Build());
108136
if (!result.ok()) {
109-
zxlogf(ERROR, "%s: AddComposite Bluetooth(bt_uart_dev) request failed: %s", __func__,
137+
zxlogf(ERROR, "AddCompositeNodeSpec Bluetooth(bt_uart_dev) request failed: %s",
110138
result.FormatDescription().data());
111139
return result.status();
112140
}
113141
if (result->is_error()) {
114-
zxlogf(ERROR, "%s: AddComposite Bluetooth(bt_uart_dev) failed: %s", __func__,
142+
zxlogf(ERROR, "AddCompositeNodeSpec Bluetooth(bt_uart_dev) failed: %s",
115143
zx_status_get_string(result->error_value()));
116144
return result->error_value();
117145
}

src/devices/board/drivers/sherlock/BUILD.gn

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -69,18 +69,6 @@ driver_bind_rules("sherlock-tee-bind") {
6969
]
7070
}
7171

72-
driver_bind_rules("sherlock-bluetooth-bind") {
73-
rules = "bind/sherlock-bluetooth.bind"
74-
header_output = "sherlock-bluetooth-bind.h"
75-
bind_output = "sherlock-bluetooth-bind.bc"
76-
tests = "bind-tests/sherlock-bluetooth-test.json"
77-
deps = [
78-
"//src/devices/bind/fuchsia.amlogic.platform",
79-
"//src/devices/bind/fuchsia.hardware.pwm",
80-
"//src/devices/bind/fuchsia.platform",
81-
]
82-
}
83-
8472
driver_bind_rules("sherlock-video-bind") {
8573
rules = "bind/sherlock-video.bind"
8674
header_output = "sherlock-video-bind.h"
@@ -331,7 +319,6 @@ template("sherlock_driver") {
331319
deps = [
332320
":camera-isp-bind_header",
333321
":sherlock-aml-usb-phy-v2-bind_header",
334-
":sherlock-bluetooth-bind_header",
335322
":sherlock-buttons-bind_header",
336323
":sherlock-dwc2-phy-bind_header",
337324
":sherlock-emmc-bind_header",

src/devices/board/drivers/sherlock/bind-tests/sherlock-bluetooth-test.json

Lines changed: 0 additions & 30 deletions
This file was deleted.

0 commit comments

Comments
 (0)