| 543 | } |
| 544 | |
| 545 | struct rt_regulator *rt_regulator_get(struct rt_device *dev, const char *id) |
| 546 | { |
| 547 | struct rt_regulator *reg = RT_NULL; |
| 548 | struct rt_regulator_node *reg_np = RT_NULL; |
| 549 | |
| 550 | if (!dev || !id) |
| 551 | { |
| 552 | reg = rt_err_ptr(-RT_EINVAL); |
| 553 | goto _end; |
| 554 | } |
| 555 | |
| 556 | #ifdef RT_USING_OFW |
| 557 | if (dev->ofw_node) |
| 558 | { |
| 559 | rt_phandle supply_phandle; |
| 560 | struct rt_ofw_node *np = dev->ofw_node; |
| 561 | char supply_name[64]; |
| 562 | |
| 563 | rt_snprintf(supply_name, sizeof(supply_name), "%s-supply", id); |
| 564 | |
| 565 | if (rt_ofw_prop_read_u32(np, supply_name, &supply_phandle)) |
| 566 | { |
| 567 | goto _end; |
| 568 | } |
| 569 | |
| 570 | if (!(np = rt_ofw_find_node_by_phandle(supply_phandle))) |
| 571 | { |
| 572 | reg = rt_err_ptr(-RT_EIO); |
| 573 | goto _end; |
| 574 | } |
| 575 | |
| 576 | if (!rt_ofw_data(np)) |
| 577 | { |
| 578 | rt_platform_ofw_request(np); |
| 579 | } |
| 580 | |
| 581 | reg_np = rt_ofw_data(np); |
| 582 | rt_ofw_node_put(np); |
| 583 | } |
| 584 | #endif |
| 585 | |
| 586 | if (!reg_np) |
| 587 | { |
| 588 | reg = rt_err_ptr(-RT_ENOSYS); |
| 589 | goto _end; |
| 590 | } |
| 591 | |
| 592 | rt_hw_spin_lock(&_regulator_lock.lock); |
| 593 | |
| 594 | regulator_check_parent(reg_np); |
| 595 | |
| 596 | rt_hw_spin_unlock(&_regulator_lock.lock); |
| 597 | |
| 598 | reg = rt_calloc(1, sizeof(*reg)); |
| 599 | |
| 600 | if (!reg) |
| 601 | { |
| 602 | reg = rt_err_ptr(-RT_ENOMEM); |
no test coverage detected