Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

media: i2c: ov5670: Replace client->dev usage

The driver needs to access the struct device in many places, and
retrieves it from the i2c_client itself retrieved with
v4l2_get_subdevdata(). Store it as a pointer in struct ov5670 and access
it from there instead, to simplify the driver.

While at it, fix a mistake in the sort order of include statements.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Reviewed-by: Mehdi Djait <mehdi.djait@linux.intel.com>
Signed-off-by: Hans Verkuil <hverkuil+cisco@kernel.org>

authored by

Laurent Pinchart and committed by
Mauro Carvalho Chehab
be3971e2 f994b6e7

+47 -52
+47 -52
drivers/media/i2c/ov5670.c
··· 1 1 // SPDX-License-Identifier: GPL-2.0 2 2 // Copyright (c) 2017 Intel Corporation. 3 3 4 - #include <linux/unaligned.h> 5 4 #include <linux/acpi.h> 6 5 #include <linux/clk.h> 7 6 #include <linux/delay.h> ··· 11 12 #include <linux/of.h> 12 13 #include <linux/pm_runtime.h> 13 14 #include <linux/regulator/consumer.h> 15 + #include <linux/unaligned.h> 16 + 14 17 #include <media/v4l2-ctrls.h> 15 18 #include <media/v4l2-device.h> 16 19 #include <media/v4l2-event.h> ··· 1855 1854 }; 1856 1855 1857 1856 struct ov5670 { 1857 + struct device *dev; 1858 + 1858 1859 struct v4l2_subdev sd; 1859 1860 struct media_pad pad; 1860 1861 struct v4l2_fwnode_endpoint endpoint; ··· 1962 1959 static int ov5670_write_regs(struct ov5670 *ov5670, 1963 1960 const struct ov5670_reg *regs, unsigned int len) 1964 1961 { 1965 - struct i2c_client *client = v4l2_get_subdevdata(&ov5670->sd); 1966 1962 unsigned int i; 1967 1963 int ret; 1968 1964 ··· 1969 1967 ret = ov5670_write_reg(ov5670, regs[i].address, 1, regs[i].val); 1970 1968 if (ret) { 1971 1969 dev_err_ratelimited( 1972 - &client->dev, 1970 + ov5670->dev, 1973 1971 "Failed to write reg 0x%4.4x. error = %d\n", 1974 1972 regs[i].address, ret); 1975 1973 ··· 2034 2032 { 2035 2033 struct ov5670 *ov5670 = container_of(ctrl->handler, 2036 2034 struct ov5670, ctrl_handler); 2037 - struct i2c_client *client = v4l2_get_subdevdata(&ov5670->sd); 2038 2035 s64 max; 2039 2036 int ret; 2040 2037 ··· 2049 2048 } 2050 2049 2051 2050 /* V4L2 controls values will be applied only when power is already up */ 2052 - if (!pm_runtime_get_if_in_use(&client->dev)) 2051 + if (!pm_runtime_get_if_in_use(ov5670->dev)) 2053 2052 return 0; 2054 2053 2055 2054 switch (ctrl->id) { ··· 2081 2080 break; 2082 2081 default: 2083 2082 ret = -EINVAL; 2084 - dev_info(&client->dev, "%s Unhandled id:0x%x, val:0x%x\n", 2083 + dev_info(ov5670->dev, "%s Unhandled id:0x%x, val:0x%x\n", 2085 2084 __func__, ctrl->id, ctrl->val); 2086 2085 break; 2087 2086 } 2088 2087 2089 - pm_runtime_put(&client->dev); 2088 + pm_runtime_put(ov5670->dev); 2090 2089 2091 2090 return ret; 2092 2091 } ··· 2100 2099 { 2101 2100 struct v4l2_mbus_config_mipi_csi2 *bus_mipi_csi2 = 2102 2101 &ov5670->endpoint.bus.mipi_csi2; 2103 - struct i2c_client *client = v4l2_get_subdevdata(&ov5670->sd); 2104 2102 struct v4l2_fwnode_device_properties props; 2105 2103 struct v4l2_ctrl_handler *ctrl_hdlr; 2106 2104 unsigned int lanes_count; ··· 2177 2177 goto error; 2178 2178 } 2179 2179 2180 - ret = v4l2_fwnode_device_parse(&client->dev, &props); 2180 + ret = v4l2_fwnode_device_parse(ov5670->dev, &props); 2181 2181 if (ret) 2182 2182 goto error; 2183 2183 ··· 2350 2350 /* Verify chip ID */ 2351 2351 static int ov5670_identify_module(struct ov5670 *ov5670) 2352 2352 { 2353 - struct i2c_client *client = v4l2_get_subdevdata(&ov5670->sd); 2354 2353 int ret; 2355 2354 u32 val; 2356 2355 ··· 2362 2363 return ret; 2363 2364 2364 2365 if (val != OV5670_CHIP_ID) { 2365 - dev_err(&client->dev, "chip id mismatch: %x!=%x\n", 2366 + dev_err(ov5670->dev, "chip id mismatch: %x!=%x\n", 2366 2367 OV5670_CHIP_ID, val); 2367 2368 return -ENXIO; 2368 2369 } ··· 2388 2389 /* Prepare streaming by writing default values and customized values */ 2389 2390 static int ov5670_start_streaming(struct ov5670 *ov5670) 2390 2391 { 2391 - struct i2c_client *client = v4l2_get_subdevdata(&ov5670->sd); 2392 2392 const struct ov5670_reg_list *reg_list; 2393 2393 int link_freq_index; 2394 2394 int ret; ··· 2400 2402 ret = ov5670_write_reg(ov5670, OV5670_REG_SOFTWARE_RST, 2401 2403 OV5670_REG_VALUE_08BIT, OV5670_SOFTWARE_RST); 2402 2404 if (ret) { 2403 - dev_err(&client->dev, "%s failed to set powerup registers\n", 2405 + dev_err(ov5670->dev, "%s failed to set powerup registers\n", 2404 2406 __func__); 2405 2407 return ret; 2406 2408 } ··· 2410 2412 reg_list = &link_freq_configs[link_freq_index].reg_list; 2411 2413 ret = ov5670_write_reg_list(ov5670, reg_list); 2412 2414 if (ret) { 2413 - dev_err(&client->dev, "%s failed to set plls\n", __func__); 2415 + dev_err(ov5670->dev, "%s failed to set plls\n", __func__); 2414 2416 return ret; 2415 2417 } 2416 2418 ··· 2418 2420 reg_list = &ov5670->cur_mode->reg_list; 2419 2421 ret = ov5670_write_reg_list(ov5670, reg_list); 2420 2422 if (ret) { 2421 - dev_err(&client->dev, "%s failed to set mode\n", __func__); 2423 + dev_err(ov5670->dev, "%s failed to set mode\n", __func__); 2422 2424 return ret; 2423 2425 } 2424 2426 2425 2427 ret = ov5670_mipi_configure(ov5670); 2426 2428 if (ret) { 2427 - dev_err(&client->dev, "%s failed to configure MIPI\n", __func__); 2429 + dev_err(ov5670->dev, "%s failed to configure MIPI\n", __func__); 2428 2430 return ret; 2429 2431 } 2430 2432 ··· 2436 2438 ret = ov5670_write_reg(ov5670, OV5670_REG_MODE_SELECT, 2437 2439 OV5670_REG_VALUE_08BIT, OV5670_MODE_STREAMING); 2438 2440 if (ret) { 2439 - dev_err(&client->dev, "%s failed to set stream\n", __func__); 2441 + dev_err(ov5670->dev, "%s failed to set stream\n", __func__); 2440 2442 return ret; 2441 2443 } 2442 2444 ··· 2445 2447 2446 2448 static int ov5670_stop_streaming(struct ov5670 *ov5670) 2447 2449 { 2448 - struct i2c_client *client = v4l2_get_subdevdata(&ov5670->sd); 2449 2450 int ret; 2450 2451 2451 2452 ret = ov5670_write_reg(ov5670, OV5670_REG_MODE_SELECT, 2452 2453 OV5670_REG_VALUE_08BIT, OV5670_MODE_STANDBY); 2453 2454 if (ret) 2454 - dev_err(&client->dev, "%s failed to set stream\n", __func__); 2455 + dev_err(ov5670->dev, "%s failed to set stream\n", __func__); 2455 2456 2456 2457 /* Return success even if it was an error, as there is nothing the 2457 2458 * caller can do about it. ··· 2461 2464 static int ov5670_set_stream(struct v4l2_subdev *sd, int enable) 2462 2465 { 2463 2466 struct ov5670 *ov5670 = to_ov5670(sd); 2464 - struct i2c_client *client = v4l2_get_subdevdata(sd); 2465 2467 int ret = 0; 2466 2468 2467 2469 mutex_lock(&ov5670->mutex); 2468 2470 2469 2471 if (enable) { 2470 - ret = pm_runtime_resume_and_get(&client->dev); 2472 + ret = pm_runtime_resume_and_get(ov5670->dev); 2471 2473 if (ret < 0) 2472 2474 goto unlock_and_return; 2473 2475 ··· 2475 2479 goto error; 2476 2480 } else { 2477 2481 ret = ov5670_stop_streaming(ov5670); 2478 - pm_runtime_put(&client->dev); 2482 + pm_runtime_put(ov5670->dev); 2479 2483 } 2480 2484 goto unlock_and_return; 2481 2485 2482 2486 error: 2483 - pm_runtime_put(&client->dev); 2487 + pm_runtime_put(ov5670->dev); 2484 2488 2485 2489 unlock_and_return: 2486 2490 mutex_unlock(&ov5670->mutex); ··· 2617 2621 2618 2622 static int ov5670_regulators_probe(struct ov5670 *ov5670) 2619 2623 { 2620 - struct i2c_client *client = v4l2_get_subdevdata(&ov5670->sd); 2621 2624 unsigned int i; 2622 2625 2623 2626 for (i = 0; i < OV5670_NUM_SUPPLIES; i++) 2624 2627 ov5670->supplies[i].supply = ov5670_supply_names[i]; 2625 2628 2626 - return devm_regulator_bulk_get(&client->dev, OV5670_NUM_SUPPLIES, 2629 + return devm_regulator_bulk_get(ov5670->dev, OV5670_NUM_SUPPLIES, 2627 2630 ov5670->supplies); 2628 2631 } 2629 2632 2630 2633 static int ov5670_gpio_probe(struct ov5670 *ov5670) 2631 2634 { 2632 - struct i2c_client *client = v4l2_get_subdevdata(&ov5670->sd); 2633 - 2634 - ov5670->pwdn_gpio = devm_gpiod_get_optional(&client->dev, "powerdown", 2635 + ov5670->pwdn_gpio = devm_gpiod_get_optional(ov5670->dev, "powerdown", 2635 2636 GPIOD_OUT_LOW); 2636 2637 if (IS_ERR(ov5670->pwdn_gpio)) 2637 2638 return PTR_ERR(ov5670->pwdn_gpio); 2638 2639 2639 - ov5670->reset_gpio = devm_gpiod_get_optional(&client->dev, "reset", 2640 + ov5670->reset_gpio = devm_gpiod_get_optional(ov5670->dev, "reset", 2640 2641 GPIOD_OUT_LOW); 2641 2642 if (IS_ERR(ov5670->reset_gpio)) 2642 2643 return PTR_ERR(ov5670->reset_gpio); ··· 2653 2660 if (!ov5670) 2654 2661 return -ENOMEM; 2655 2662 2656 - ov5670->xvclk = devm_clk_get_optional(&client->dev, NULL); 2663 + ov5670->dev = &client->dev; 2664 + 2665 + ov5670->xvclk = devm_clk_get_optional(ov5670->dev, NULL); 2657 2666 if (!IS_ERR_OR_NULL(ov5670->xvclk)) 2658 2667 input_clk = clk_get_rate(ov5670->xvclk); 2659 2668 else if (!ov5670->xvclk || PTR_ERR(ov5670->xvclk) == -ENOENT) 2660 - device_property_read_u32(&client->dev, "clock-frequency", 2669 + device_property_read_u32(ov5670->dev, "clock-frequency", 2661 2670 &input_clk); 2662 2671 else 2663 - return dev_err_probe(&client->dev, PTR_ERR(ov5670->xvclk), 2672 + return dev_err_probe(ov5670->dev, PTR_ERR(ov5670->xvclk), 2664 2673 "error getting clock\n"); 2665 2674 2666 2675 if (input_clk != OV5670_XVCLK_FREQ) { 2667 - dev_err(&client->dev, 2676 + dev_err(ov5670->dev, 2668 2677 "Unsupported clock frequency %u\n", input_clk); 2669 2678 return -EINVAL; 2670 2679 } ··· 2677 2682 2678 2683 ret = ov5670_regulators_probe(ov5670); 2679 2684 if (ret) 2680 - return dev_err_probe(&client->dev, ret, "Regulators probe failed\n"); 2685 + return dev_err_probe(ov5670->dev, ret, "Regulators probe failed\n"); 2681 2686 2682 2687 ret = ov5670_gpio_probe(ov5670); 2683 2688 if (ret) 2684 - return dev_err_probe(&client->dev, ret, "GPIO probe failed\n"); 2689 + return dev_err_probe(ov5670->dev, ret, "GPIO probe failed\n"); 2685 2690 2686 2691 /* 2687 2692 * Graph Endpoint. If it's missing we defer rather than fail, as this 2688 2693 * sensor is known to co-exist on systems with the IPU3 and so it might 2689 2694 * be created by the ipu-bridge. 2690 2695 */ 2691 - handle = fwnode_graph_get_next_endpoint(dev_fwnode(&client->dev), NULL); 2696 + handle = fwnode_graph_get_next_endpoint(dev_fwnode(ov5670->dev), NULL); 2692 2697 if (!handle) 2693 - return dev_err_probe(&client->dev, -EPROBE_DEFER, 2698 + return dev_err_probe(ov5670->dev, -EPROBE_DEFER, 2694 2699 "Endpoint for node get failed\n"); 2695 2700 2696 2701 ov5670->endpoint.bus_type = V4L2_MBUS_CSI2_DPHY; ··· 2699 2704 ret = v4l2_fwnode_endpoint_alloc_parse(handle, &ov5670->endpoint); 2700 2705 fwnode_handle_put(handle); 2701 2706 if (ret) 2702 - return dev_err_probe(&client->dev, ret, "Endpoint parse failed\n"); 2707 + return dev_err_probe(ov5670->dev, ret, "Endpoint parse failed\n"); 2703 2708 2704 - full_power = acpi_dev_state_d0(&client->dev); 2709 + full_power = acpi_dev_state_d0(ov5670->dev); 2705 2710 if (full_power) { 2706 - ret = ov5670_runtime_resume(&client->dev); 2711 + ret = ov5670_runtime_resume(ov5670->dev); 2707 2712 if (ret) { 2708 - dev_err_probe(&client->dev, ret, "Power up failed\n"); 2713 + dev_err_probe(ov5670->dev, ret, "Power up failed\n"); 2709 2714 goto error_endpoint; 2710 2715 } 2711 2716 2712 2717 /* Check module identity */ 2713 2718 ret = ov5670_identify_module(ov5670); 2714 2719 if (ret) { 2715 - dev_err_probe(&client->dev, ret, "ov5670_identify_module() error\n"); 2720 + dev_err_probe(ov5670->dev, ret, "ov5670_identify_module() error\n"); 2716 2721 goto error_power_off; 2717 2722 } 2718 2723 } ··· 2724 2729 2725 2730 ret = ov5670_init_controls(ov5670); 2726 2731 if (ret) { 2727 - dev_err_probe(&client->dev, ret, "ov5670_init_controls() error\n"); 2732 + dev_err_probe(ov5670->dev, ret, "ov5670_init_controls() error\n"); 2728 2733 goto error_mutex_destroy; 2729 2734 } 2730 2735 ··· 2737 2742 ov5670->pad.flags = MEDIA_PAD_FL_SOURCE; 2738 2743 ret = media_entity_pads_init(&ov5670->sd.entity, 1, &ov5670->pad); 2739 2744 if (ret) { 2740 - dev_err_probe(&client->dev, ret, "media_entity_pads_init() error\n"); 2745 + dev_err_probe(ov5670->dev, ret, "media_entity_pads_init() error\n"); 2741 2746 goto error_handler_free; 2742 2747 } 2743 2748 2744 2749 /* Set the device's state to active if it's in D0 state. */ 2745 2750 if (full_power) 2746 - pm_runtime_set_active(&client->dev); 2747 - pm_runtime_enable(&client->dev); 2751 + pm_runtime_set_active(ov5670->dev); 2752 + pm_runtime_enable(ov5670->dev); 2748 2753 2749 2754 /* Async register for subdev */ 2750 2755 ret = v4l2_async_register_subdev_sensor(&ov5670->sd); 2751 2756 if (ret < 0) { 2752 - dev_err_probe(&client->dev, ret, "v4l2_async_register_subdev() error\n"); 2757 + dev_err_probe(ov5670->dev, ret, "v4l2_async_register_subdev() error\n"); 2753 2758 goto error_pm_disable; 2754 2759 } 2755 2760 2756 - pm_runtime_idle(&client->dev); 2761 + pm_runtime_idle(ov5670->dev); 2757 2762 2758 2763 return 0; 2759 2764 2760 2765 error_pm_disable: 2761 - pm_runtime_disable(&client->dev); 2766 + pm_runtime_disable(ov5670->dev); 2762 2767 2763 2768 media_entity_cleanup(&ov5670->sd.entity); 2764 2769 ··· 2770 2775 2771 2776 error_power_off: 2772 2777 if (full_power) 2773 - ov5670_runtime_suspend(&client->dev); 2778 + ov5670_runtime_suspend(ov5670->dev); 2774 2779 2775 2780 error_endpoint: 2776 2781 v4l2_fwnode_endpoint_free(&ov5670->endpoint); ··· 2788 2793 v4l2_ctrl_handler_free(sd->ctrl_handler); 2789 2794 mutex_destroy(&ov5670->mutex); 2790 2795 2791 - pm_runtime_disable(&client->dev); 2792 - ov5670_runtime_suspend(&client->dev); 2796 + pm_runtime_disable(ov5670->dev); 2797 + ov5670_runtime_suspend(ov5670->dev); 2793 2798 2794 2799 v4l2_fwnode_endpoint_free(&ov5670->endpoint); 2795 2800 }