diff options
| author | Bhanu Murthy V <bmurthyv@nvidia.com> | 2018-09-14 14:42:39 -0400 |
|---|---|---|
| committer | mobile promotions <svcmobile_promotions@nvidia.com> | 2019-02-01 02:27:54 -0500 |
| commit | 3ef8b6a33d67d6a7e2d10ed0eede148d88c01152 (patch) | |
| tree | 196e30ac07359e7f4573de2cd53f8ba3284bfd9d | |
| parent | 8eb6de8344f843d545eff7e41d22cd002a827c68 (diff) | |
driver: camera: Read sensor bus configuration
Add reading i2c bus driver configuration from
device tree.
Add reading SPI bus driver configuration from
device tree.
The bus configuration is required to register with
RCE driver for sensors.
Bug 2433156
Change-Id: I012c98ff417096669cfbf6cf20b83fd0299af150
Signed-off-by: Bhanu Murthy V <bmurthyv@nvidia.com>
Reviewed-on: https://git-master.nvidia.com/r/1851317
(cherry picked from commit 5bc239e0ccea141af75ad55a9f6acd1f1c620d45)
Reviewed-on: https://git-master.nvidia.com/r/2006761
Reviewed-by: svc-mobile-coverity <svc-mobile-coverity@nvidia.com>
Tested-by: Ian Kaszubski <ikaszubski@nvidia.com>
Reviewed-by: Vincent Chung <vincentc@nvidia.com>
GVS: Gerrit_Virtual_Submit
Reviewed-by: Frank Chen <frankc@nvidia.com>
Reviewed-by: mobile promotions <svcmobile_promotions@nvidia.com>
Tested-by: mobile promotions <svcmobile_promotions@nvidia.com>
| -rw-r--r-- | drivers/media/platform/tegra/camera/sensor_common.c | 164 | ||||
| -rw-r--r-- | drivers/media/platform/tegra/camera/tegracam_core.c | 2 |
2 files changed, 165 insertions, 1 deletions
diff --git a/drivers/media/platform/tegra/camera/sensor_common.c b/drivers/media/platform/tegra/camera/sensor_common.c index ff99682eb..42864af76 100644 --- a/drivers/media/platform/tegra/camera/sensor_common.c +++ b/drivers/media/platform/tegra/camera/sensor_common.c | |||
| @@ -537,6 +537,166 @@ int sensor_common_parse_num_modes(const struct device *dev) | |||
| 537 | } | 537 | } |
| 538 | EXPORT_SYMBOL(sensor_common_parse_num_modes); | 538 | EXPORT_SYMBOL(sensor_common_parse_num_modes); |
| 539 | 539 | ||
| 540 | static int sensor_common_init_i2c_device_config( | ||
| 541 | struct device *dev, struct device_node *np, | ||
| 542 | struct sensor_cfg *cfg) | ||
| 543 | { | ||
| 544 | struct i2c_sensor_cfg *i2c_sensor = &cfg->u.i2c_sensor; | ||
| 545 | struct device_node *node = NULL; | ||
| 546 | struct device_node *parent = NULL; | ||
| 547 | int err = 0; | ||
| 548 | u32 value = 0; | ||
| 549 | bool is_mux_valid = 0; | ||
| 550 | |||
| 551 | of_node_get(np); | ||
| 552 | cfg->type = CAMERA_DEVICE_I2C_SENSOR; | ||
| 553 | err = of_property_read_u32(np, "reg", &value); | ||
| 554 | if (err) { | ||
| 555 | dev_err(dev, "sensor address unavailable\n"); | ||
| 556 | return err; | ||
| 557 | } | ||
| 558 | |||
| 559 | /* Reading more devices has to be supported */ | ||
| 560 | i2c_sensor->num_devs = 1; | ||
| 561 | i2c_sensor->sd[0].addr = value; | ||
| 562 | |||
| 563 | parent = of_get_parent(np); | ||
| 564 | /* verify the parent is mux or i2c bus */ | ||
| 565 | is_mux_valid = | ||
| 566 | of_property_read_bool(parent, "i2c-mux,deselect-on-exit"); | ||
| 567 | i2c_sensor->mux.is_mux_valid = is_mux_valid; | ||
| 568 | of_node_put(np); | ||
| 569 | |||
| 570 | if (is_mux_valid) { | ||
| 571 | |||
| 572 | /* at mux port read the mux channel */ | ||
| 573 | err = of_property_read_u32(parent, "reg", &value); | ||
| 574 | if (err) { | ||
| 575 | dev_err(dev, "mux channel unavailable\n"); | ||
| 576 | return err; | ||
| 577 | } | ||
| 578 | i2c_sensor->mux.mux_channel = value; | ||
| 579 | |||
| 580 | /* move to mux node */ | ||
| 581 | node = of_get_parent(parent); | ||
| 582 | err = of_property_read_u32(node, "reg", &value); | ||
| 583 | if (err) { | ||
| 584 | dev_err(dev, "mux address unavailable\n"); | ||
| 585 | return err; | ||
| 586 | } | ||
| 587 | i2c_sensor->mux.mux_addr = value; | ||
| 588 | of_node_put(parent); | ||
| 589 | |||
| 590 | /* move to i2c bus node */ | ||
| 591 | parent = of_get_parent(node); | ||
| 592 | of_node_put(node); | ||
| 593 | } | ||
| 594 | |||
| 595 | /* read parent which is i2c bus */ | ||
| 596 | err = of_property_read_u32_index(parent, "reg", 1, &value); | ||
| 597 | if (err) { | ||
| 598 | dev_err(dev, "i2c bus regbase unavailable\n"); | ||
| 599 | return err; | ||
| 600 | } | ||
| 601 | i2c_sensor->bus.reg_base = value; | ||
| 602 | |||
| 603 | err = of_property_read_u32(parent, "clock-frequency", &value); | ||
| 604 | if (err) { | ||
| 605 | dev_err(dev, "bus clock frequency unavailable\n"); | ||
| 606 | return err; | ||
| 607 | } | ||
| 608 | i2c_sensor->bus.clk_rate = value; | ||
| 609 | |||
| 610 | of_node_put(parent); | ||
| 611 | /* | ||
| 612 | * Read any additional flags to configure I2C for any | ||
| 613 | * special properties of the device like-high-speed mode, | ||
| 614 | * 10bit addressing etc., | ||
| 615 | */ | ||
| 616 | |||
| 617 | return 0; | ||
| 618 | } | ||
| 619 | |||
| 620 | static int sensor_common_init_spi_device_config( | ||
| 621 | struct device *dev, struct device_node *np, | ||
| 622 | struct sensor_cfg *cfg) | ||
| 623 | { | ||
| 624 | struct spi_sensor_cfg *spi_sensor = &cfg->u.spi_sensor; | ||
| 625 | struct device_node *parent = NULL; | ||
| 626 | int err = 0; | ||
| 627 | u32 value = 0; | ||
| 628 | |||
| 629 | of_node_get(np); | ||
| 630 | cfg->type = CAMERA_DEVICE_SPI_SENSOR; | ||
| 631 | err = of_property_read_u32(np, "reg", &value); | ||
| 632 | if (err) { | ||
| 633 | dev_err(dev, "sensor address unavailable\n"); | ||
| 634 | return err; | ||
| 635 | } | ||
| 636 | |||
| 637 | /* Reading more devices has to be supported */ | ||
| 638 | spi_sensor->num_devs = 1; | ||
| 639 | spi_sensor->sd[0].addr = value; | ||
| 640 | |||
| 641 | parent = of_get_parent(np); | ||
| 642 | of_node_put(np); | ||
| 643 | /* TODO: Add logic for spi mux if available */ | ||
| 644 | |||
| 645 | /* read parent which is spi bus */ | ||
| 646 | err = of_property_read_u32_index(parent, "reg", 1, &value); | ||
| 647 | if (err) { | ||
| 648 | dev_err(dev, "spi bus regbase unavailable\n"); | ||
| 649 | return err; | ||
| 650 | } | ||
| 651 | spi_sensor->bus.reg_base = value; | ||
| 652 | |||
| 653 | err = of_property_read_u32(parent, "spi-max-frequency", &value); | ||
| 654 | if (err) { | ||
| 655 | dev_err(dev, "bus clock frequency unavailable\n"); | ||
| 656 | return err; | ||
| 657 | } | ||
| 658 | spi_sensor->bus.clk_rate = value; | ||
| 659 | |||
| 660 | of_node_put(parent); | ||
| 661 | /* Read any additional flags to configure SPI */ | ||
| 662 | |||
| 663 | return 0; | ||
| 664 | } | ||
| 665 | |||
| 666 | static int sensor_common_init_device_config( | ||
| 667 | struct device *dev, struct device_node *np, | ||
| 668 | struct sensor_cfg *cfg) | ||
| 669 | { | ||
| 670 | struct device_node *parent = NULL; | ||
| 671 | char *tmp; | ||
| 672 | int err = 0; | ||
| 673 | |||
| 674 | if (!np) | ||
| 675 | return -EINVAL; | ||
| 676 | |||
| 677 | parent = of_get_parent(np); | ||
| 678 | if (!parent) | ||
| 679 | return -EINVAL; | ||
| 680 | |||
| 681 | tmp = strnstr(parent->name, "i2c", 4); | ||
| 682 | if (tmp != NULL) { | ||
| 683 | err = sensor_common_init_i2c_device_config(dev, np, cfg); | ||
| 684 | if (err) | ||
| 685 | goto exit; | ||
| 686 | } | ||
| 687 | |||
| 688 | tmp = strnstr(parent->name, "spi", 4); | ||
| 689 | if (tmp != NULL) { | ||
| 690 | err = sensor_common_init_spi_device_config(dev, np, cfg); | ||
| 691 | if (err) | ||
| 692 | goto exit; | ||
| 693 | } | ||
| 694 | |||
| 695 | exit: | ||
| 696 | of_node_put(parent); | ||
| 697 | return err; | ||
| 698 | } | ||
| 699 | |||
| 540 | int sensor_common_init_sensor_properties( | 700 | int sensor_common_init_sensor_properties( |
| 541 | struct device *dev, struct device_node *np, | 701 | struct device *dev, struct device_node *np, |
| 542 | struct sensor_properties *sensor) | 702 | struct sensor_properties *sensor) |
| @@ -549,6 +709,10 @@ int sensor_common_init_sensor_properties( | |||
| 549 | if (sensor == NULL) | 709 | if (sensor == NULL) |
| 550 | return -EINVAL; | 710 | return -EINVAL; |
| 551 | 711 | ||
| 712 | err = sensor_common_init_device_config(dev, np, &sensor->cfg); | ||
| 713 | if (err) | ||
| 714 | return err; | ||
| 715 | |||
| 552 | /* get number of modes */ | 716 | /* get number of modes */ |
| 553 | for (i = 0; num_modes < MAX_NUM_SENSOR_MODES; i++) { | 717 | for (i = 0; num_modes < MAX_NUM_SENSOR_MODES; i++) { |
| 554 | snprintf(temp_str, sizeof(temp_str), "%s%d", | 718 | snprintf(temp_str, sizeof(temp_str), "%s%d", |
diff --git a/drivers/media/platform/tegra/camera/tegracam_core.c b/drivers/media/platform/tegra/camera/tegracam_core.c index 6e5249c1d..5a17322ff 100644 --- a/drivers/media/platform/tegra/camera/tegracam_core.c +++ b/drivers/media/platform/tegra/camera/tegracam_core.c | |||
| @@ -22,7 +22,7 @@ | |||
| 22 | /* use semantic versioning convention */ | 22 | /* use semantic versioning convention */ |
