|
11 | 11 | #include <lib/ddk/driver.h>
|
12 | 12 | #include <lib/ddk/io-buffer.h>
|
13 | 13 | #include <lib/ddk/metadata.h>
|
14 |
| -#include <lib/device-protocol/pdev-fidl.h> |
| 14 | +#include <lib/driver/platform-device/cpp/pdev.h> |
15 | 15 | #include <lib/mmio/mmio-buffer.h>
|
16 | 16 | #include <lib/zx/bti.h>
|
17 | 17 | #include <lib/zx/time.h>
|
@@ -1040,36 +1040,39 @@ zx_status_t AmlRawNand::Bind() {
|
1040 | 1040 | }
|
1041 | 1041 |
|
1042 | 1042 | zx_status_t AmlRawNand::Create(void* ctx, zx_device_t* parent) {
|
1043 |
| - ddk::PDevFidl pdev(parent); |
1044 |
| - if (!pdev.is_valid()) { |
1045 |
| - zxlogf(ERROR, "%s: ZX_PROTOCOL_PDEV not available", __FILE__); |
1046 |
| - return ZX_ERR_NO_RESOURCES; |
| 1043 | + zx::result pdev_client_end = |
| 1044 | + DdkConnectFragmentFidlProtocol<fuchsia_hardware_platform_device::Service::Device>(parent, |
| 1045 | + "pdev"); |
| 1046 | + if (pdev_client_end.is_error()) { |
| 1047 | + zxlogf(ERROR, "Failed to connect to platform device: %s", pdev_client_end.status_string()); |
| 1048 | + return pdev_client_end.status_value(); |
1047 | 1049 | }
|
| 1050 | + fdf::PDev pdev{std::move(pdev_client_end.value())}; |
1048 | 1051 |
|
1049 |
| - zx::bti bti; |
1050 |
| - if (zx_status_t status = pdev.GetBti(0, &bti); status != ZX_OK) { |
1051 |
| - zxlogf(ERROR, "%s: pdev_get_bti failed", __FILE__); |
1052 |
| - return status; |
| 1052 | + zx::result bti = pdev.GetBti(0); |
| 1053 | + if (bti.is_error()) { |
| 1054 | + zxlogf(ERROR, "Failed to get bti: %s", bti.status_string()); |
| 1055 | + return bti.status_value(); |
1053 | 1056 | }
|
1054 | 1057 |
|
1055 |
| - static constexpr uint32_t NandRegWindow = 0; |
1056 |
| - static constexpr uint32_t ClockRegWindow = 1; |
1057 |
| - std::optional<fdf::MmioBuffer> mmio_nandreg; |
1058 |
| - if (zx_status_t status = pdev.MapMmio(NandRegWindow, &mmio_nandreg); status != ZX_OK) { |
1059 |
| - zxlogf(ERROR, "%s: pdev.MapMmio nandreg failed", __FILE__); |
1060 |
| - return status; |
| 1058 | + static constexpr uint32_t kNandRegWindow = 0; |
| 1059 | + zx::result mmio_nandreg = pdev.MapMmio(kNandRegWindow); |
| 1060 | + if (mmio_nandreg.is_error()) { |
| 1061 | + zxlogf(ERROR, "Failed to map nand reg window mmio: %s", mmio_nandreg.status_string()); |
| 1062 | + return mmio_nandreg.status_value(); |
1061 | 1063 | }
|
1062 | 1064 |
|
1063 |
| - std::optional<fdf::MmioBuffer> mmio_clockreg; |
1064 |
| - if (zx_status_t status = pdev.MapMmio(ClockRegWindow, &mmio_clockreg); status != ZX_OK) { |
1065 |
| - zxlogf(ERROR, "%s: pdev.MapMmio clockreg failed", __FILE__); |
1066 |
| - return status; |
| 1065 | + static constexpr uint32_t kClockRegWindow = 1; |
| 1066 | + zx::result mmio_clockreg = pdev.MapMmio(kClockRegWindow); |
| 1067 | + if (mmio_clockreg.is_error()) { |
| 1068 | + zxlogf(ERROR, "Failed to map clock reg window mmio: %s", mmio_clockreg.status_string()); |
| 1069 | + return mmio_clockreg.status_value(); |
1067 | 1070 | }
|
1068 | 1071 |
|
1069 | 1072 | fbl::AllocChecker ac;
|
1070 |
| - std::unique_ptr<AmlRawNand> device(new (&ac) AmlRawNand(parent, *std::move(mmio_nandreg), |
1071 |
| - *std::move(mmio_clockreg), std::move(bti), |
1072 |
| - std::make_unique<Onfi>())); |
| 1073 | + std::unique_ptr<AmlRawNand> device(new (&ac) AmlRawNand( |
| 1074 | + parent, std::move(mmio_nandreg.value()), std::move(mmio_clockreg.value()), |
| 1075 | + std::move(bti.value()), std::make_unique<Onfi>())); |
1073 | 1076 |
|
1074 | 1077 | if (!ac.check()) {
|
1075 | 1078 | zxlogf(ERROR, "%s: AmlRawNand alloc failed", __FILE__);
|
|
0 commit comments