From patchwork Sat Apr 1 14:58:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 13197026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7830EC77B6F for ; Sat, 1 Apr 2023 15:00:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229970AbjDAPAo (ORCPT ); Sat, 1 Apr 2023 11:00:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37576 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229793AbjDAPAl (ORCPT ); Sat, 1 Apr 2023 11:00:41 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EDD791DFA3 for ; Sat, 1 Apr 2023 07:59:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1680361184; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ne+rR4XLZ0KzDHP0VAOI0+r/B4rC6EPlijbl0n/7W10=; b=ht4vwW6VRm2UabQY1cVRlC72TJPIYWGCgltdHCC8xGuTABvUYv0BH1Ae8JbK/2oFh9VIZx NYn7aJUYt77bSMjG/98OuuKB/xcgRwGdpCsqX4sCB30K6pQb+TsnsqN8k/xjwVcsXLmM1e OK6rhysz85fOCMaluhShqXbCjU8ArfA= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-618-8oX0FZ8ONfi_szHjHcg7aw-1; Sat, 01 Apr 2023 10:59:38 -0400 X-MC-Unique: 8oX0FZ8ONfi_szHjHcg7aw-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 5266C101A531; Sat, 1 Apr 2023 14:59:38 +0000 (UTC) Received: from localhost.localdomain (unknown [10.39.192.49]) by smtp.corp.redhat.com (Postfix) with ESMTP id C3FDB400F59; Sat, 1 Apr 2023 14:59:36 +0000 (UTC) From: Hans de Goede To: Mauro Carvalho Chehab , Sakari Ailus Cc: Hans de Goede , Kate Hsuan , Tsuchiya Yuto , Andy Shevchenko , Yury Luneff , Nable , andrey.i.trufanov@gmail.com, Fabio Aiuto , linux-media@vger.kernel.org, linux-staging@lists.linux.dev Subject: [PATCH 01/28] media: atomisp: Add v4l2_get_acpi_sensor_info() helper Date: Sat, 1 Apr 2023 16:58:59 +0200 Message-Id: <20230401145926.596216-2-hdegoede@redhat.com> In-Reply-To: <20230401145926.596216-1-hdegoede@redhat.com> References: <20230401145926.596216-1-hdegoede@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org ACPI nodes describing sensors on atomisp devices implement a "79234640-9e10-4fea-a5c1-b5aa8b19756f" Device Specific Method (DSM) to get info about the GPIOs. Using this method is necessary to figure out which ACPI GPIO resource is "reset" and which one is "powerdown" and this is also necessary to figure out the correct polarity of the pins. One example where this is necessary is the GC0310 sensor. The current GC0310 code hardcodes reset as being active-low and power-down as being active-high. This works on a number of devices such as the mpman converter 9. But it is wrong for the Chuwi Vi8 CWI501 where the powerdown pin is active-low. Rather then adding DMI quirks for this, add a helper for this, which can be shared between sensor-drivers. This new helper optionally also returns a string identifying the exact sensor-module used, which might be useful if any module specific behvior is necessary in the sensor driver. This uses the DSM directly on the sensor device's ACPI node. This is different from later Intel hardware (IPU3 / IPU6) which has a separate INT3472 node (with its own driver) with this info. Since there is no separate ACPI node to which we can bind to register GPIO lookups, this unfortunately means that all sensor drivers which may be used on BYT or CHT hw need to call this new helper. Note for now this function is being added to atomisp_gmin_platform.c, but once things are ready to move atomisp over to using generic sensor drivers this will need to become a generic v4l2 sensor helper. but this will require upstream discussion first. Signed-off-by: Hans de Goede --- .../atomisp/include/linux/atomisp_platform.h | 2 + .../media/atomisp/pci/atomisp_gmin_platform.c | 240 ++++++++++++++++++ 2 files changed, 242 insertions(+) diff --git a/drivers/staging/media/atomisp/include/linux/atomisp_platform.h b/drivers/staging/media/atomisp/include/linux/atomisp_platform.h index b77bf814a5a6..e8e965f73fc8 100644 --- a/drivers/staging/media/atomisp/include/linux/atomisp_platform.h +++ b/drivers/staging/media/atomisp/include/linux/atomisp_platform.h @@ -213,6 +213,8 @@ int atomisp_register_sensor_no_gmin(struct v4l2_subdev *subdev, u32 lanes, enum atomisp_bayer_order bayer_order); void atomisp_unregister_subdev(struct v4l2_subdev *subdev); +int v4l2_get_acpi_sensor_info(struct device *dev, char **module_id_str); + /* API from old platform_camera.h, new CPUID implementation */ #define __IS_SOC(x) (boot_cpu_data.x86_vendor == X86_VENDOR_INTEL && \ boot_cpu_data.x86 == 6 && \ diff --git a/drivers/staging/media/atomisp/pci/atomisp_gmin_platform.c b/drivers/staging/media/atomisp/pci/atomisp_gmin_platform.c index 7fc7dfa56172..f8d8a34d7e7f 100644 --- a/drivers/staging/media/atomisp/pci/atomisp_gmin_platform.c +++ b/drivers/staging/media/atomisp/pci/atomisp_gmin_platform.c @@ -1447,3 +1447,243 @@ DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x0f38, isp_pm_cap_fixup); MODULE_DESCRIPTION("Ancillary routines for binding ACPI devices"); MODULE_LICENSE("GPL"); + +/* + * The below helper functions don't really belong here and should eventually be + * moved to some place under sys/drivers/media/v4l2-core . + */ +#include + +/* + * 79234640-9e10-4fea-a5c1-b5aa8b19756f + * This _DSM GUID returns information about the GPIO lines mapped to a sensor. + * Function number 1 returns a count of the GPIO lines that are mapped. + * Subsequent functions return 32 bit ints encoding information about the GPIO. + */ +static const guid_t intel_sensor_gpio_info_guid = + GUID_INIT(0x79234640, 0x9e10, 0x4fea, + 0xa5, 0xc1, 0xb5, 0xaa, 0x8b, 0x19, 0x75, 0x6f); + +/* + * 822ace8f-2814-4174-a56b-5f029fe079ee + * This _DSM GUID returns a string from the sensor device, which acts as a + * module identifier. + */ +static const guid_t intel_sensor_module_guid = + GUID_INIT(0x822ace8f, 0x2814, 0x4174, + 0xa5, 0x6b, 0x5f, 0x02, 0x9f, 0xe0, 0x79, 0xee); + +#define INTEL_DSM_TYPE_SHIFT 0 +#define INTEL_DSM_TYPE_MASK GENMASK(7, 0) +#define INTEL_DSM_PIN_SHIFT 8 +#define INTEL_DSM_PIN_MASK GENMASK(15, 8) +#define INTEL_DSM_SENSOR_ON_VAL_SHIFT 24 +#define INTEL_DSM_SENSOR_ON_VAL_MASK GENMASK(31, 24) + +#define INTEL_DSM_TYPE(x) \ + (((x) & INTEL_DSM_TYPE_MASK) >> INTEL_DSM_TYPE_SHIFT) +#define INTEL_DSM_PIN(x) \ + (((x) & INTEL_DSM_PIN_MASK) >> INTEL_DSM_PIN_SHIFT) +#define INTEL_DSM_SENSOR_ON_VAL(x) \ + (((x) & INTEL_DSM_SENSOR_ON_VAL_MASK) >> INTEL_DSM_SENSOR_ON_VAL_SHIFT) + +#define V4L2_SENSOR_MAX_ACPI_GPIOS 2u + +struct v4l2_acpi_gpio_map { + struct acpi_gpio_params params[V4L2_SENSOR_MAX_ACPI_GPIOS]; + struct acpi_gpio_mapping mapping[V4L2_SENSOR_MAX_ACPI_GPIOS + 1]; +}; + +struct v4l2_acpi_gpio_parsing_data { + struct device *dev; + u32 settings[V4L2_SENSOR_MAX_ACPI_GPIOS]; + unsigned int settings_count; + unsigned int res_count; + unsigned int map_count; + struct v4l2_acpi_gpio_map *map; +}; + +/* Note this always returns 1 to continue looping so that res_count is accurate */ +static int v4l2_acpi_handle_gpio_res(struct acpi_resource *ares, void *_data) +{ + struct v4l2_acpi_gpio_parsing_data *data = _data; + struct acpi_resource_gpio *agpio; + const char *name; + bool active_low; + unsigned int i; + u32 settings; + u8 pin; + + if (!acpi_gpio_get_io_resource(ares, &agpio)) + return 1; /* Not a GPIO, continue the loop */ + + data->res_count++; + + pin = agpio->pin_table[0]; + for (i = 0; i < data->settings_count; i++) { + if (INTEL_DSM_PIN(data->settings[i]) == pin) { + settings = data->settings[i]; + break; + } + } + + if (i == data->settings_count) { + dev_warn(data->dev, "Could not find DSM GPIO settings for pin %d\n", pin); + return 1; + } + + switch (INTEL_DSM_TYPE(settings)) { + case 0: + name = "reset-gpios"; + break; + case 1: + name = "powerdown-gpios"; + break; + default: + dev_warn(data->dev, "Unknown GPIO type 0x%02lx for pin %d\n", + INTEL_DSM_TYPE(settings), pin); + return 1; + } + + /* + * Both reset and power-down need to be logical false when the sensor + * is on (sensor should not be in reset and not be powered-down) so + * when the sensor-on-value, which is the physical pin value is high, + * then the signal is active-low. + */ + active_low = INTEL_DSM_SENSOR_ON_VAL(settings) ? true : false; + + i = data->map_count; + if (i == V4L2_SENSOR_MAX_ACPI_GPIOS) + return 1; + + /* res_count is already incremented */ + data->map->params[i].crs_entry_index = data->res_count - 1; + data->map->params[i].active_low = active_low; + data->map->mapping[i].name = name; + data->map->mapping[i].data = &data->map->params[i]; + data->map->mapping[i].size = 1; + data->map_count++; + + dev_info(data->dev, "%s crs %d %s pin %d active-%s\n", name, + data->res_count - 1, agpio->resource_source.string_ptr, + pin, active_low ? "low" : "high"); + + return 1; +} + +/* + * Helper function to create an ACPI GPIO lookup table for sensor reset and + * powerdown signals on Intel Bay Trail (BYT) and Cherry Trail (CHT) devices, + * including setting the correct polarity for the GPIO. + * + * This uses the "79234640-9e10-4fea-a5c1-b5aa8b19756f" DSM method directly + * on the sensor device's ACPI node. This is different from later Intel + * hardware which has a separate INT3472 with this info. Since there is + * no separate firmware-node to which we can bind to register the GPIO lookups + * this unfortunately means that all sensor drivers which may be used on + * BYT or CHT hw need to call this function. This also means that this function + * may only fail when it is actually called on BYT/CHT hw. In all other cases + * it must always succeed. + * + * Note this code uses the same DSM GUID as the INT3472 discrete.c code + * and there is some overlap, but there are enough differences that it is + * difficult to share the code. + */ +int v4l2_get_acpi_sensor_info(struct device *dev, char **module_id_str) +{ + struct acpi_device *adev = ACPI_COMPANION(dev); + struct v4l2_acpi_gpio_parsing_data data = { }; + LIST_HEAD(resource_list); + union acpi_object *obj; + unsigned int i, j; + int ret; + + if (module_id_str) + *module_id_str = NULL; + + if (!adev) + return 0; + + obj = acpi_evaluate_dsm_typed(adev->handle, &intel_sensor_module_guid, + 0x00, 0x01, NULL, ACPI_TYPE_STRING); + if (obj) { + dev_info(dev, "Sensor module id: '%s'\n", obj->string.pointer); + if (module_id_str) + *module_id_str = kstrdup(obj->string.pointer, GFP_KERNEL); + + ACPI_FREE(obj); + } + + if (!soc_intel_is_byt() && !soc_intel_is_cht()) + return 0; + + /* + * First get the GPIO-settings count and then get count GPIO-settings + * values. Note the order of these may differ from the order in which + * the GPIOs are listed on the ACPI resources! So we first store them all + * and then enumerate the ACPI resources and match them up by pin number. + */ + obj = acpi_evaluate_dsm_typed(adev->handle, + &intel_sensor_gpio_info_guid, 0x00, 1, + NULL, ACPI_TYPE_INTEGER); + if (!obj) + return dev_err_probe(dev, -EIO, "No _DSM entry for GPIO pin count\n"); + + data.settings_count = obj->integer.value; + ACPI_FREE(obj); + + if (data.settings_count > V4L2_SENSOR_MAX_ACPI_GPIOS) + return dev_err_probe(dev, -EIO, "Too many GPIOs %u > %u\n", + data.settings_count, V4L2_SENSOR_MAX_ACPI_GPIOS); + + for (i = 0; i < data.settings_count; i++) { + /* + * i + 2 because the index of this _DSM function is 1-based + * and the first function is just a count. + */ + obj = acpi_evaluate_dsm_typed(adev->handle, + &intel_sensor_gpio_info_guid, + 0x00, i + 2, + NULL, ACPI_TYPE_INTEGER); + if (!obj) + return dev_err_probe(dev, -EIO, "No _DSM entry for GPIO pin %u\n", i); + + data.settings[i] = obj->integer.value; + ACPI_FREE(obj); + } + + /* Since we match up by pin-number the pin-numbers must be unique */ + for (i = 0; i < data.settings_count; i++) { + for (j = i + 1; j < data.settings_count; j++) { + if (INTEL_DSM_PIN(data.settings[i]) != + INTEL_DSM_PIN(data.settings[j])) + continue; + + return dev_err_probe(dev, -EIO, "Duplicate pin number %lu\n", + INTEL_DSM_PIN(data.settings[i])); + } + } + + /* Use devm_kzalloc() for the mappings + params to auto-free them */ + data.map = devm_kzalloc(dev, sizeof(*data.map), GFP_KERNEL); + if (!data.map) + return -ENOMEM; + + /* Now parse the ACPI resources and build the lookup table */ + data.dev = dev; + ret = acpi_dev_get_resources(adev, &resource_list, + v4l2_acpi_handle_gpio_res, &data); + if (ret < 0) + return ret; + + acpi_dev_free_resource_list(&resource_list); + + if (data.map_count != data.settings_count || + data.res_count != data.settings_count) + dev_warn(dev, "ACPI GPIO resources vs DSM GPIO-info count mismatch (dsm: %d res: %d map %d\n", + data.settings_count, data.res_count, data.map_count); + + return devm_acpi_dev_add_driver_gpios(dev, data.map->mapping); +} +EXPORT_SYMBOL_GPL(v4l2_get_acpi_sensor_info); From patchwork Sat Apr 1 14:59:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 13197022 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 48CA9C76196 for ; Sat, 1 Apr 2023 15:00:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229792AbjDAPAk (ORCPT ); Sat, 1 Apr 2023 11:00:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37600 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229667AbjDAPAj (ORCPT ); Sat, 1 Apr 2023 11:00:39 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DE4921D2DC for ; Sat, 1 Apr 2023 07:59:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1680361184; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=PCnCunX8zPLtEMo/fn00t95JhskXvfVoqtR5aYXZvnU=; b=Y+hBUWC5tuKm6bf1x3TrEQlS9rzp91g0hGT8US3dAyKI0Rs8Sg6Y5+lvJCHyiTLTZ+r/M4 o+Jf6ewGuWAHkAGY1qQZA14/TnywJUp9jLVMPOrNYB1uLHjxH2Bx6208mgTq8WLC+cmGGH Rk05Mp/ZRZqaPlGE1GH2uVxg14u+adE= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-225-I2IOVZdDN1mR37GiUn2E5w-1; Sat, 01 Apr 2023 10:59:40 -0400 X-MC-Unique: I2IOVZdDN1mR37GiUn2E5w-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 121ED1C04181; Sat, 1 Apr 2023 14:59:40 +0000 (UTC) Received: from localhost.localdomain (unknown [10.39.192.49]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8581C400F59; Sat, 1 Apr 2023 14:59:38 +0000 (UTC) From: Hans de Goede To: Mauro Carvalho Chehab , Sakari Ailus Cc: Hans de Goede , Kate Hsuan , Tsuchiya Yuto , Andy Shevchenko , Yury Luneff , Nable , andrey.i.trufanov@gmail.com, Fabio Aiuto , linux-media@vger.kernel.org, linux-staging@lists.linux.dev Subject: [PATCH 02/28] media: atomisp: ov2680: Use v4l2_get_acpi_sensor_info() for the GPIO lookups Date: Sat, 1 Apr 2023 16:59:00 +0200 Message-Id: <20230401145926.596216-3-hdegoede@redhat.com> In-Reply-To: <20230401145926.596216-1-hdegoede@redhat.com> References: <20230401145926.596216-1-hdegoede@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org Use the new v4l2_get_acpi_sensor_info() for the GPIO lookups, this uses the special Intel _DSM method to get more info about the GPIOs like their function and their polarity. Signed-off-by: Hans de Goede --- .../media/atomisp/i2c/atomisp-ov2680.c | 26 +++---------------- drivers/staging/media/atomisp/i2c/ov2680.h | 1 - 2 files changed, 3 insertions(+), 24 deletions(-) diff --git a/drivers/staging/media/atomisp/i2c/atomisp-ov2680.c b/drivers/staging/media/atomisp/i2c/atomisp-ov2680.c index aeb38599fe13..3181276ed027 100644 --- a/drivers/staging/media/atomisp/i2c/atomisp-ov2680.c +++ b/drivers/staging/media/atomisp/i2c/atomisp-ov2680.c @@ -3,6 +3,7 @@ * Support for OmniVision OV2680 1080p HD camera sensor. * * Copyright (c) 2013 Intel Corporation. All Rights Reserved. + * Copyright (c) 2023 Hans de Goede * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License version @@ -614,21 +615,6 @@ static void ov2680_remove(struct i2c_client *client) pm_runtime_disable(&client->dev); } -/* - * Unlike other sensors which have both a rest and powerdown input pins, - * the OV2680 only has a powerdown input. But some ACPI tables still list - * 2 GPIOs for the OV2680 and it is unclear which to use. So try to get - * up to 2 GPIOs (1 mandatory, 1 optional) and control them in sync. - */ -static const struct acpi_gpio_params ov2680_first_gpio = { 0, 0, true }; -static const struct acpi_gpio_params ov2680_second_gpio = { 1, 0, true }; - -static const struct acpi_gpio_mapping ov2680_gpio_mapping[] = { - { "powerdown-gpios", &ov2680_first_gpio, 1 }, - { "powerdown-alt-gpios", &ov2680_second_gpio, 1 }, - { }, -}; - static int ov2680_probe(struct i2c_client *client) { struct device *dev = &client->dev; @@ -644,18 +630,14 @@ static int ov2680_probe(struct i2c_client *client) sensor->client = client; v4l2_i2c_subdev_init(&sensor->sd, client, &ov2680_ops); - ret = devm_acpi_dev_add_driver_gpios(&client->dev, ov2680_gpio_mapping); + ret = v4l2_get_acpi_sensor_info(dev, NULL); if (ret) return ret; - sensor->powerdown = devm_gpiod_get(dev, "powerdown", GPIOD_OUT_HIGH); + sensor->powerdown = devm_gpiod_get_optional(dev, "powerdown", GPIOD_OUT_HIGH); if (IS_ERR(sensor->powerdown)) return dev_err_probe(dev, PTR_ERR(sensor->powerdown), "getting powerdown GPIO\n"); - sensor->powerdown_alt = devm_gpiod_get_optional(dev, "powerdown-alt", GPIOD_OUT_HIGH); - if (IS_ERR(sensor->powerdown_alt)) - return dev_err_probe(dev, PTR_ERR(sensor->powerdown_alt), "getting powerdown-alt GPIO\n"); - pm_runtime_set_suspended(dev); pm_runtime_enable(dev); pm_runtime_set_autosuspend_delay(dev, 1000); @@ -699,7 +681,6 @@ static int ov2680_suspend(struct device *dev) struct ov2680_device *sensor = to_ov2680_sensor(sd); gpiod_set_value_cansleep(sensor->powerdown, 1); - gpiod_set_value_cansleep(sensor->powerdown_alt, 1); return 0; } @@ -712,7 +693,6 @@ static int ov2680_resume(struct device *dev) usleep_range(5000, 6000); gpiod_set_value_cansleep(sensor->powerdown, 0); - gpiod_set_value_cansleep(sensor->powerdown_alt, 0); /* according to DS, 20ms is needed between PWDN and i2c access */ msleep(20); diff --git a/drivers/staging/media/atomisp/i2c/ov2680.h b/drivers/staging/media/atomisp/i2c/ov2680.h index a37af0a74a53..baf49eb0659e 100644 --- a/drivers/staging/media/atomisp/i2c/ov2680.h +++ b/drivers/staging/media/atomisp/i2c/ov2680.h @@ -114,7 +114,6 @@ struct ov2680_device { struct mutex input_lock; struct i2c_client *client; struct gpio_desc *powerdown; - struct gpio_desc *powerdown_alt; bool is_streaming; struct ov2680_mode { From patchwork Sat Apr 1 14:59:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 13197025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 407D9C77B6D for ; Sat, 1 Apr 2023 15:00:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229906AbjDAPAn (ORCPT ); Sat, 1 Apr 2023 11:00:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37622 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229667AbjDAPAl (ORCPT ); Sat, 1 Apr 2023 11:00:41 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5C11B1DFB4 for ; Sat, 1 Apr 2023 07:59:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1680361185; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Og6uNSnQQlIDTobQmVAXOXrC2T4+vgbrAVfQOLRwNyA=; b=QDwJOOJMWk6baPSIXCEyRtN68EtmVDETQ/QcPTScfaw1wGRZOsnU6ewhZlLjvydpJPQ9co PQ2UNk5dA4l6XXtahmNMQ56rrhD2hdBZbeukKArzddA6gFPR9RRle8EpLdTNaD2+N2UWY+ WWmkGDN5nXLwVH9TtkZzBDW4ubrEzTE= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-630-_FxapGy3O7OCe6RlxyH9pA-1; Sat, 01 Apr 2023 10:59:42 -0400 X-MC-Unique: _FxapGy3O7OCe6RlxyH9pA-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id C5522185A78F; Sat, 1 Apr 2023 14:59:41 +0000 (UTC) Received: from localhost.localdomain (unknown [10.39.192.49]) by smtp.corp.redhat.com (Postfix) with ESMTP id 44E23400F59; Sat, 1 Apr 2023 14:59:40 +0000 (UTC) From: Hans de Goede To: Mauro Carvalho Chehab , Sakari Ailus Cc: Hans de Goede , Kate Hsuan , Tsuchiya Yuto , Andy Shevchenko , Yury Luneff , Nable , andrey.i.trufanov@gmail.com, Fabio Aiuto , linux-media@vger.kernel.org, linux-staging@lists.linux.dev Subject: [PATCH 03/28] media: atomisp: ov2680: Error handling fixes Date: Sat, 1 Apr 2023 16:59:01 +0200 Message-Id: <20230401145926.596216-4-hdegoede@redhat.com> In-Reply-To: <20230401145926.596216-1-hdegoede@redhat.com> References: <20230401145926.596216-1-hdegoede@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org Fix s_stream error handling Fix 3 error handling issues: 1. In ov2680_s_stream(), when pm_runtime_get_sync() fails it will still have incremented the pm-runtime reference count so we need to call pm_runtime_put() 2. In ov2680_s_stream() sensor->is_streaming should always be set to false when the sensor is powered-off even on i2c-communication errors. 3. In ov2680_probe(), call ov2680_remove() on ov2680_s_config() errors, so that pm_runtime_disable() is properly called to disable the runtime-pm which has been enabled before the ov2680_s_config() call. Signed-off-by: Hans de Goede --- drivers/staging/media/atomisp/i2c/atomisp-ov2680.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/drivers/staging/media/atomisp/i2c/atomisp-ov2680.c b/drivers/staging/media/atomisp/i2c/atomisp-ov2680.c index 3181276ed027..63de214916f5 100644 --- a/drivers/staging/media/atomisp/i2c/atomisp-ov2680.c +++ b/drivers/staging/media/atomisp/i2c/atomisp-ov2680.c @@ -419,7 +419,7 @@ static int ov2680_s_stream(struct v4l2_subdev *sd, int enable) if (enable) { ret = pm_runtime_get_sync(sensor->sd.dev); if (ret < 0) - goto error_unlock; + goto error_power_down; ret = ov2680_set_mode(sensor); if (ret) @@ -447,6 +447,7 @@ static int ov2680_s_stream(struct v4l2_subdev *sd, int enable) error_power_down: pm_runtime_put(sensor->sd.dev); + sensor->is_streaming = false; error_unlock: mutex_unlock(&sensor->input_lock); return ret; @@ -644,8 +645,10 @@ static int ov2680_probe(struct i2c_client *client) pm_runtime_use_autosuspend(dev); ret = ov2680_s_config(&sensor->sd); - if (ret) + if (ret) { + ov2680_remove(client); return ret; + } sensor->sd.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE; sensor->pad.flags = MEDIA_PAD_FL_SOURCE; From patchwork Sat Apr 1 14:59:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 13197024 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6B43EC761AF for ; Sat, 1 Apr 2023 15:00:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229899AbjDAPAm (ORCPT ); Sat, 1 Apr 2023 11:00:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37634 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229795AbjDAPAl (ORCPT ); Sat, 1 Apr 2023 11:00:41 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 69ACA1E710 for ; Sat, 1 Apr 2023 07:59:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1680361185; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=iesvLwv6X8XuCGw70Cmh6LGcbEs+u4LGH9OWDaM1z3k=; b=f9HhmT8Wxcno8x/QVK2L1nop+ZZRqmXrCMhbblAbhdXmWY6jlESbNycmLP1CT+vTeYtCMs +8yOV61xpJ2YRnt6oyhqqwrm1D6rFo3Nv+mimyTd8fP2W/t+WvGHWuavCiTFYL2hs0ne3r 3pkMd01t29eHTF2OiKSQihlNm4sSL4o= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-604-ovuNWvonNqusOP65giNUjQ-1; Sat, 01 Apr 2023 10:59:44 -0400 X-MC-Unique: ovuNWvonNqusOP65giNUjQ-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 8724A811E7C; Sat, 1 Apr 2023 14:59:43 +0000 (UTC) Received: from localhost.localdomain (unknown [10.39.192.49]) by smtp.corp.redhat.com (Postfix) with ESMTP id 048DA400F59; Sat, 1 Apr 2023 14:59:41 +0000 (UTC) From: Hans de Goede To: Mauro Carvalho Chehab , Sakari Ailus Cc: Hans de Goede , Kate Hsuan , Tsuchiya Yuto , Andy Shevchenko , Yury Luneff , Nable , andrey.i.trufanov@gmail.com, Fabio Aiuto , linux-media@vger.kernel.org, linux-staging@lists.linux.dev Subject: [PATCH 04/28] media: atomisp: gc0310: Remove some unused structure definitions Date: Sat, 1 Apr 2023 16:59:02 +0200 Message-Id: <20230401145926.596216-5-hdegoede@redhat.com> In-Reply-To: <20230401145926.596216-1-hdegoede@redhat.com> References: <20230401145926.596216-1-hdegoede@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org Drop the unused struct gc0310_format and struct regval_list definitions. Signed-off-by: Hans de Goede --- drivers/staging/media/atomisp/i2c/gc0310.h | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/drivers/staging/media/atomisp/i2c/gc0310.h b/drivers/staging/media/atomisp/i2c/gc0310.h index cae480ae6fba..6947bf53ff4f 100644 --- a/drivers/staging/media/atomisp/i2c/gc0310.h +++ b/drivers/staging/media/atomisp/i2c/gc0310.h @@ -107,11 +107,6 @@ #define GC0310_BIN_FACTOR_MAX 3 -struct regval_list { - u16 reg_num; - u8 value; -}; - struct gc0310_resolution { u8 *desc; const struct gc0310_reg *regs; @@ -126,12 +121,6 @@ struct gc0310_resolution { bool used; }; -struct gc0310_format { - u8 *desc; - u32 pixelformat; - struct gc0310_reg *regs; -}; - /* * gc0310 device structure. */ From patchwork Sat Apr 1 14:59:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 13197028 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9A354C761AF for ; Sat, 1 Apr 2023 15:00:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230005AbjDAPAr (ORCPT ); Sat, 1 Apr 2023 11:00:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37592 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229795AbjDAPAn (ORCPT ); Sat, 1 Apr 2023 11:00:43 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DA8D11D2C6 for ; Sat, 1 Apr 2023 07:59:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1680361189; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=6FuOeWEELOamaeerlnB3zyuCPRWdMphq+iPfxZumvpw=; b=C3Ss1supdQM427oCwzREYjWnpeJdMzyFRPzJ1HWARBahLeto2KOMHRVEMtloZc9acEuCdO 7q15SSc1txanBIIGLR5+04e3fvXCcp73/qLgqiZ9LGdEfafsivF7cZQSMv7AbkgXW3vdOm EYYSffSDdNVUTzbvoi0925t6sY8H7Wg= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-116-yMBJoRptP-ac6CMYwMETgw-1; Sat, 01 Apr 2023 10:59:46 -0400 X-MC-Unique: yMBJoRptP-ac6CMYwMETgw-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 4AAC51C04184; Sat, 1 Apr 2023 14:59:45 +0000 (UTC) Received: from localhost.localdomain (unknown [10.39.192.49]) by smtp.corp.redhat.com (Postfix) with ESMTP id BB739483EC1; Sat, 1 Apr 2023 14:59:43 +0000 (UTC) From: Hans de Goede To: Mauro Carvalho Chehab , Sakari Ailus Cc: Hans de Goede , Kate Hsuan , Tsuchiya Yuto , Andy Shevchenko , Yury Luneff , Nable , andrey.i.trufanov@gmail.com, Fabio Aiuto , linux-media@vger.kernel.org, linux-staging@lists.linux.dev Subject: [PATCH 05/28] media: atomisp: gc0310: Remove GC0310_TOK_* Date: Sat, 1 Apr 2023 16:59:03 +0200 Message-Id: <20230401145926.596216-6-hdegoede@redhat.com> In-Reply-To: <20230401145926.596216-1-hdegoede@redhat.com> References: <20230401145926.596216-1-hdegoede@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org Remove the ability to have special tokens in a reg-list, GC0310_TOK_DELAY is not used and GC0310_TOK_TERM can be replaced with ARRAY_SIZE, simplifying the code. Signed-off-by: Hans de Goede --- .../media/atomisp/i2c/atomisp-gc0310.c | 47 ++++++++----------- drivers/staging/media/atomisp/i2c/gc0310.h | 9 +--- 2 files changed, 21 insertions(+), 35 deletions(-) diff --git a/drivers/staging/media/atomisp/i2c/atomisp-gc0310.c b/drivers/staging/media/atomisp/i2c/atomisp-gc0310.c index 0d90683ed227..18aebeef6869 100644 --- a/drivers/staging/media/atomisp/i2c/atomisp-gc0310.c +++ b/drivers/staging/media/atomisp/i2c/atomisp-gc0310.c @@ -134,6 +134,7 @@ static int gc0310_write_reg(struct i2c_client *client, u16 data_length, * gc0310_write_reg_array - Initializes a list of GC0310 registers * @client: i2c driver client structure * @reglist: list of registers to be written + * @count: number of register, value pairs in the list * * This function initializes a list of registers. When consecutive addresses * are found in a row on the list, this function creates a buffer and sends @@ -202,39 +203,28 @@ static int __gc0310_write_reg_is_consecutive(struct i2c_client *client, } static int gc0310_write_reg_array(struct i2c_client *client, - const struct gc0310_reg *reglist) + const struct gc0310_reg *reglist, int count) { - const struct gc0310_reg *next = reglist; struct gc0310_write_ctrl ctrl; - int err; + int i, err; ctrl.index = 0; - for (; next->type != GC0310_TOK_TERM; next++) { - switch (next->type & GC0310_TOK_MASK) { - case GC0310_TOK_DELAY: + for (i = 0; i < count; i++) { + /* + * If next address is not consecutive, data needs to be + * flushed before proceed. + */ + if (!__gc0310_write_reg_is_consecutive(client, &ctrl, + ®list[i])) { err = __gc0310_flush_reg_array(client, &ctrl); if (err) return err; - msleep(next->val); - break; - default: - /* - * If next address is not consecutive, data needs to be - * flushed before proceed. - */ - if (!__gc0310_write_reg_is_consecutive(client, &ctrl, - next)) { - err = __gc0310_flush_reg_array(client, &ctrl); - if (err) - return err; - } - err = __gc0310_buf_reg_array(client, &ctrl, next); - if (err) { - dev_err(&client->dev, "%s: write error, aborted\n", - __func__); - return err; - } - break; + } + err = __gc0310_buf_reg_array(client, &ctrl, ®list[i]); + if (err) { + dev_err(&client->dev, "%s: write error, aborted\n", + __func__); + return err; } } @@ -478,7 +468,8 @@ static int gc0310_init(struct v4l2_subdev *sd) mutex_lock(&dev->input_lock); /* set initial registers */ - ret = gc0310_write_reg_array(client, gc0310_reset_register); + ret = gc0310_write_reg_array(client, gc0310_reset_register, + ARRAY_SIZE(gc0310_reset_register)); /* restore settings */ gc0310_res = gc0310_res_preview; @@ -648,7 +639,7 @@ static int startup(struct v4l2_subdev *sd) struct i2c_client *client = v4l2_get_subdevdata(sd); int ret = 0; - ret = gc0310_write_reg_array(client, dev->res->regs); + ret = gc0310_write_reg_array(client, dev->res->regs, dev->res->reg_count); if (ret) { dev_err(&client->dev, "gc0310 write register err.\n"); return ret; diff --git a/drivers/staging/media/atomisp/i2c/gc0310.h b/drivers/staging/media/atomisp/i2c/gc0310.h index 6947bf53ff4f..ecca3b5e42bf 100644 --- a/drivers/staging/media/atomisp/i2c/gc0310.h +++ b/drivers/staging/media/atomisp/i2c/gc0310.h @@ -110,6 +110,7 @@ struct gc0310_resolution { u8 *desc; const struct gc0310_reg *regs; + int reg_count; int res; int width; int height; @@ -139,9 +140,6 @@ struct gc0310_device { enum gc0310_tok_type { GC0310_8BIT = 0x0001, - GC0310_TOK_TERM = 0xf000, /* terminating token for reg list */ - GC0310_TOK_DELAY = 0xfe00, /* delay token for reg list */ - GC0310_TOK_MASK = 0xfff0 }; /** @@ -330,8 +328,6 @@ static const struct gc0310_reg gc0310_reset_register[] = { {GC0310_8BIT, 0x48, 0x03}, //sun mode {GC0310_8BIT, 0x4f, 0x60}, //sun_clamp {GC0310_8BIT, 0xfe, 0x00}, - - {GC0310_TOK_TERM, 0, 0}, }; static struct gc0310_reg const gc0310_VGA_30fps[] = { @@ -356,8 +352,6 @@ static struct gc0310_reg const gc0310_VGA_30fps[] = { {GC0310_8BIT, 0x13, 0x02},//05 //05 //LWC[15:8] {GC0310_8BIT, 0xfe, 0x00}, - - {GC0310_TOK_TERM, 0, 0}, }; static struct gc0310_resolution gc0310_res_preview[] = { @@ -374,6 +368,7 @@ static struct gc0310_resolution gc0310_res_preview[] = { #endif .skip_frames = 2, .regs = gc0310_VGA_30fps, + .reg_count = ARRAY_SIZE(gc0310_VGA_30fps), }, }; From patchwork Sat Apr 1 14:59:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 13197029 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A22CCC76196 for ; Sat, 1 Apr 2023 15:00:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230049AbjDAPAs (ORCPT ); Sat, 1 Apr 2023 11:00:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37670 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229972AbjDAPAo (ORCPT ); Sat, 1 Apr 2023 11:00:44 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6BCB11CBAE for ; Sat, 1 Apr 2023 07:59:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1680361190; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=US/2IeK285PZlUA2Tl98A9Oi89YZl6NRbds6ETiMeIg=; b=ZageukPlFnEPIoqba38FMN0eFoMGw3HbsV9lH0MyT73XvGZQlpKlx1s5YhYhG98lh7IQQX +ozrAT4/krE/ILqNCAo4qbkrcxETZZgDY4qFKVIfWZe9UM3GrhAAUZ6Gi05nsvB6ZjSiOR d8xhAWXIMmTZkXcenruoJeS7CvptkZM= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-606-0XVtv_RjM9ytluGJndfBjQ-1; Sat, 01 Apr 2023 10:59:47 -0400 X-MC-Unique: 0XVtv_RjM9ytluGJndfBjQ-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 0F65C3815F61; Sat, 1 Apr 2023 14:59:47 +0000 (UTC) Received: from localhost.localdomain (unknown [10.39.192.49]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7F45C400F59; Sat, 1 Apr 2023 14:59:45 +0000 (UTC) From: Hans de Goede To: Mauro Carvalho Chehab , Sakari Ailus Cc: Hans de Goede , Kate Hsuan , Tsuchiya Yuto , Andy Shevchenko , Yury Luneff , Nable , andrey.i.trufanov@gmail.com, Fabio Aiuto , linux-media@vger.kernel.org, linux-staging@lists.linux.dev Subject: [PATCH 06/28] media: atomisp: gc0310: Simplify gc0310_write_reg_array() Date: Sat, 1 Apr 2023 16:59:04 +0200 Message-Id: <20230401145926.596216-7-hdegoede@redhat.com> In-Reply-To: <20230401145926.596216-1-hdegoede@redhat.com> References: <20230401145926.596216-1-hdegoede@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org Remove the complex optimization to send multiple registers in one i2c-transfer. None of the other sensor drivers are doing this and the reg-lists are only used once at stream-start time, so this does not need to be highly optimized. Signed-off-by: Hans de Goede --- .../media/atomisp/i2c/atomisp-gc0310.c | 87 +------------------ drivers/staging/media/atomisp/i2c/gc0310.h | 12 --- 2 files changed, 3 insertions(+), 96 deletions(-) diff --git a/drivers/staging/media/atomisp/i2c/atomisp-gc0310.c b/drivers/staging/media/atomisp/i2c/atomisp-gc0310.c index 18aebeef6869..5974dd5bd95e 100644 --- a/drivers/staging/media/atomisp/i2c/atomisp-gc0310.c +++ b/drivers/staging/media/atomisp/i2c/atomisp-gc0310.c @@ -135,100 +135,19 @@ static int gc0310_write_reg(struct i2c_client *client, u16 data_length, * @client: i2c driver client structure * @reglist: list of registers to be written * @count: number of register, value pairs in the list - * - * This function initializes a list of registers. When consecutive addresses - * are found in a row on the list, this function creates a buffer and sends - * consecutive data in a single i2c_transfer(). - * - * __gc0310_flush_reg_array, __gc0310_buf_reg_array() and - * __gc0310_write_reg_is_consecutive() are internal functions to - * gc0310_write_reg_array_fast() and should be not used anywhere else. - * */ - -static int __gc0310_flush_reg_array(struct i2c_client *client, - struct gc0310_write_ctrl *ctrl) -{ - u16 size; - - if (ctrl->index == 0) - return 0; - - size = sizeof(u8) + ctrl->index; /* 8-bit address + data */ - ctrl->buffer.addr = (u8)(ctrl->buffer.addr); - ctrl->index = 0; - - return gc0310_i2c_write(client, size, (u8 *)&ctrl->buffer); -} - -static int __gc0310_buf_reg_array(struct i2c_client *client, - struct gc0310_write_ctrl *ctrl, - const struct gc0310_reg *next) -{ - int size; - - switch (next->type) { - case GC0310_8BIT: - size = 1; - ctrl->buffer.data[ctrl->index] = (u8)next->val; - break; - default: - return -EINVAL; - } - - /* When first item is added, we need to store its starting address */ - if (ctrl->index == 0) - ctrl->buffer.addr = next->reg; - - ctrl->index += size; - - /* - * Buffer cannot guarantee free space for u32? Better flush it to avoid - * possible lack of memory for next item. - */ - if (ctrl->index + sizeof(u8) >= GC0310_MAX_WRITE_BUF_SIZE) - return __gc0310_flush_reg_array(client, ctrl); - - return 0; -} - -static int __gc0310_write_reg_is_consecutive(struct i2c_client *client, - struct gc0310_write_ctrl *ctrl, - const struct gc0310_reg *next) -{ - if (ctrl->index == 0) - return 1; - - return ctrl->buffer.addr + ctrl->index == next->reg; -} - static int gc0310_write_reg_array(struct i2c_client *client, const struct gc0310_reg *reglist, int count) { - struct gc0310_write_ctrl ctrl; int i, err; - ctrl.index = 0; for (i = 0; i < count; i++) { - /* - * If next address is not consecutive, data needs to be - * flushed before proceed. - */ - if (!__gc0310_write_reg_is_consecutive(client, &ctrl, - ®list[i])) { - err = __gc0310_flush_reg_array(client, &ctrl); - if (err) - return err; - } - err = __gc0310_buf_reg_array(client, &ctrl, ®list[i]); - if (err) { - dev_err(&client->dev, "%s: write error, aborted\n", - __func__); + err = gc0310_write_reg(client, GC0310_8BIT, reglist[i].reg, reglist[i].val); + if (err) return err; - } } - return __gc0310_flush_reg_array(client, &ctrl); + return 0; } static int gc0310_set_gain(struct v4l2_subdev *sd, int gain) diff --git a/drivers/staging/media/atomisp/i2c/gc0310.h b/drivers/staging/media/atomisp/i2c/gc0310.h index ecca3b5e42bf..a2734934fc6a 100644 --- a/drivers/staging/media/atomisp/i2c/gc0310.h +++ b/drivers/staging/media/atomisp/i2c/gc0310.h @@ -158,18 +158,6 @@ struct gc0310_reg { #define to_gc0310_sensor(x) container_of(x, struct gc0310_device, sd) -#define GC0310_MAX_WRITE_BUF_SIZE 30 - -struct gc0310_write_buffer { - u8 addr; - u8 data[GC0310_MAX_WRITE_BUF_SIZE]; -}; - -struct gc0310_write_ctrl { - int index; - struct gc0310_write_buffer buffer; -}; - /* * Register settings for various resolution */ From patchwork Sat Apr 1 14:59:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 13197031 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id EF7A4C76196 for ; Sat, 1 Apr 2023 15:00:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230098AbjDAPAv (ORCPT ); Sat, 1 Apr 2023 11:00:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37686 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230025AbjDAPAs (ORCPT ); Sat, 1 Apr 2023 11:00:48 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 819431CB8F for ; Sat, 1 Apr 2023 07:59:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1680361193; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=nhH++bfezgpX1O8ytioGZoPaykLNLvHckhploTedUKk=; b=ZZEPcD8m4wiGaPvKbuaXIafEjNJDLXhdXkRtUHrw2azQTT+O2uRUu9duTYBQZhGbs1bbmZ +IkwvFDCclEOMESGziwglojgeAc9ADHRnN4FK/HqQhpyaEgCxWZi5QyDJewonUSCHpCl2s waL2zmJ/rlOvJLcjBy51pQ4tRVEg7iI= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-652-IvRs9Na4OtujrKH2LTJUdA-1; Sat, 01 Apr 2023 10:59:49 -0400 X-MC-Unique: IvRs9Na4OtujrKH2LTJUdA-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id E360D85A588; Sat, 1 Apr 2023 14:59:48 +0000 (UTC) Received: from localhost.localdomain (unknown [10.39.192.49]) by smtp.corp.redhat.com (Postfix) with ESMTP id 44B71400F59; Sat, 1 Apr 2023 14:59:47 +0000 (UTC) From: Hans de Goede To: Mauro Carvalho Chehab , Sakari Ailus Cc: Hans de Goede , Kate Hsuan , Tsuchiya Yuto , Andy Shevchenko , Yury Luneff , Nable , andrey.i.trufanov@gmail.com, Fabio Aiuto , linux-media@vger.kernel.org, linux-staging@lists.linux.dev Subject: [PATCH 07/28] media: atomisp: gc0310: Remove enum gc0310_tok_type Date: Sat, 1 Apr 2023 16:59:05 +0200 Message-Id: <20230401145926.596216-8-hdegoede@redhat.com> In-Reply-To: <20230401145926.596216-1-hdegoede@redhat.com> References: <20230401145926.596216-1-hdegoede@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org enum gc0310_tok_type / the data_length read/write parameter is always GC0310_8BIT, drop this. Note for the register-lists the indentation is also fixed and c++ style comments are converted to regular C-style /* */ comments. Signed-off-by: Hans de Goede --- .../media/atomisp/i2c/atomisp-gc0310.c | 72 ++--- drivers/staging/media/atomisp/i2c/gc0310.h | 302 +++++++++--------- 2 files changed, 167 insertions(+), 207 deletions(-) diff --git a/drivers/staging/media/atomisp/i2c/atomisp-gc0310.c b/drivers/staging/media/atomisp/i2c/atomisp-gc0310.c index 5974dd5bd95e..4e92268da32a 100644 --- a/drivers/staging/media/atomisp/i2c/atomisp-gc0310.c +++ b/drivers/staging/media/atomisp/i2c/atomisp-gc0310.c @@ -35,8 +35,7 @@ #include "gc0310.h" /* i2c read/write stuff */ -static int gc0310_read_reg(struct i2c_client *client, - u16 data_length, u8 reg, u8 *val) +static int gc0310_read_reg(struct i2c_client *client, u8 reg, u8 *val) { int err; struct i2c_msg msg[2]; @@ -48,12 +47,6 @@ static int gc0310_read_reg(struct i2c_client *client, return -ENODEV; } - if (data_length != GC0310_8BIT) { - dev_err(&client->dev, "%s error, invalid data length\n", - __func__); - return -EINVAL; - } - memset(msg, 0, sizeof(msg)); msg[0].addr = client->addr; @@ -65,7 +58,7 @@ static int gc0310_read_reg(struct i2c_client *client, data[0] = (u8)(reg & 0xff); msg[1].addr = client->addr; - msg[1].len = data_length; + msg[1].len = 1; msg[1].flags = I2C_M_RD; msg[1].buf = data; @@ -78,11 +71,7 @@ static int gc0310_read_reg(struct i2c_client *client, return err; } - *val = 0; - /* high byte comes first */ - if (data_length == GC0310_8BIT) - *val = (u8)data[0]; - + *val = (u8)data[0]; return 0; } @@ -101,25 +90,17 @@ static int gc0310_i2c_write(struct i2c_client *client, u16 len, u8 *data) return ret == num_msg ? 0 : -EIO; } -static int gc0310_write_reg(struct i2c_client *client, u16 data_length, - u8 reg, u8 val) +static int gc0310_write_reg(struct i2c_client *client, u8 reg, u8 val) { int ret; unsigned char data[2] = {0}; u8 *wreg = (u8 *)data; - const u16 len = data_length + sizeof(u8); /* 8-bit address + data */ - - if (data_length != GC0310_8BIT) { - dev_err(&client->dev, - "%s error, invalid data_length\n", __func__); - return -EINVAL; - } + const u16 len = 1 + sizeof(u8); /* 8-bit address + data */ /* high byte goes out first */ *wreg = (u8)(reg & 0xff); - if (data_length == GC0310_8BIT) - data[1] = (u8)(val); + data[1] = (u8)(val); ret = gc0310_i2c_write(client, len, data); if (ret) @@ -142,7 +123,7 @@ static int gc0310_write_reg_array(struct i2c_client *client, int i, err; for (i = 0; i < count; i++) { - err = gc0310_write_reg(client, GC0310_8BIT, reglist[i].reg, reglist[i].val); + err = gc0310_write_reg(client, reglist[i].reg, reglist[i].val); if (err) return err; } @@ -173,14 +154,12 @@ static int gc0310_set_gain(struct v4l2_subdev *sd, int gain) dev_dbg(&client->dev, "gain=0x%x again=0x%x dgain=0x%x\n", gain, again, dgain); /* set analog gain */ - ret = gc0310_write_reg(client, GC0310_8BIT, - GC0310_AGC_ADJ, again); + ret = gc0310_write_reg(client, GC0310_AGC_ADJ, again); if (ret) return ret; /* set digital gain */ - ret = gc0310_write_reg(client, GC0310_8BIT, - GC0310_DGC_ADJ, dgain); + ret = gc0310_write_reg(client, GC0310_DGC_ADJ, dgain); if (ret) return ret; @@ -197,15 +176,11 @@ static int __gc0310_set_exposure(struct v4l2_subdev *sd, int coarse_itg, dev_dbg(&client->dev, "coarse_itg=%d gain=%d digitgain=%d\n", coarse_itg, gain, digitgain); /* set exposure */ - ret = gc0310_write_reg(client, GC0310_8BIT, - GC0310_AEC_PK_EXPO_L, - coarse_itg & 0xff); + ret = gc0310_write_reg(client, GC0310_AEC_PK_EXPO_L, coarse_itg & 0xff); if (ret) return ret; - ret = gc0310_write_reg(client, GC0310_8BIT, - GC0310_AEC_PK_EXPO_H, - (coarse_itg >> 8) & 0x0f); + ret = gc0310_write_reg(client, GC0310_AEC_PK_EXPO_H, (coarse_itg >> 8) & 0x0f); if (ret) return ret; @@ -280,16 +255,12 @@ static int gc0310_q_exposure(struct v4l2_subdev *sd, s32 *value) int ret; /* get exposure */ - ret = gc0310_read_reg(client, GC0310_8BIT, - GC0310_AEC_PK_EXPO_L, - ®_v); + ret = gc0310_read_reg(client, GC0310_AEC_PK_EXPO_L, ®_v); if (ret) goto err; *value = reg_v; - ret = gc0310_read_reg(client, GC0310_8BIT, - GC0310_AEC_PK_EXPO_H, - ®_v); + ret = gc0310_read_reg(client, GC0310_AEC_PK_EXPO_H, ®_v); if (ret) goto err; @@ -654,14 +625,12 @@ static int gc0310_detect(struct i2c_client *client) if (!i2c_check_functionality(adapter, I2C_FUNC_I2C)) return -ENODEV; - ret = gc0310_read_reg(client, GC0310_8BIT, - GC0310_SC_CMMN_CHIP_ID_H, &high); + ret = gc0310_read_reg(client, GC0310_SC_CMMN_CHIP_ID_H, &high); if (ret) { dev_err(&client->dev, "read sensor_id_high failed\n"); return -ENODEV; } - ret = gc0310_read_reg(client, GC0310_8BIT, - GC0310_SC_CMMN_CHIP_ID_L, &low); + ret = gc0310_read_reg(client, GC0310_SC_CMMN_CHIP_ID_L, &low); if (ret) { dev_err(&client->dev, "read sensor_id_low failed\n"); return -ENODEV; @@ -691,22 +660,20 @@ static int gc0310_s_stream(struct v4l2_subdev *sd, int enable) if (enable) { /* enable per frame MIPI and sensor ctrl reset */ - ret = gc0310_write_reg(client, GC0310_8BIT, - 0xFE, 0x30); + ret = gc0310_write_reg(client, 0xFE, 0x30); if (ret) { mutex_unlock(&dev->input_lock); return ret; } } - ret = gc0310_write_reg(client, GC0310_8BIT, - GC0310_RESET_RELATED, GC0310_REGISTER_PAGE_3); + ret = gc0310_write_reg(client, GC0310_RESET_RELATED, GC0310_REGISTER_PAGE_3); if (ret) { mutex_unlock(&dev->input_lock); return ret; } - ret = gc0310_write_reg(client, GC0310_8BIT, GC0310_SW_STREAM, + ret = gc0310_write_reg(client, GC0310_SW_STREAM, enable ? GC0310_START_STREAMING : GC0310_STOP_STREAMING); if (ret) { @@ -714,8 +681,7 @@ static int gc0310_s_stream(struct v4l2_subdev *sd, int enable) return ret; } - ret = gc0310_write_reg(client, GC0310_8BIT, - GC0310_RESET_RELATED, GC0310_REGISTER_PAGE_0); + ret = gc0310_write_reg(client, GC0310_RESET_RELATED, GC0310_REGISTER_PAGE_0); if (ret) { mutex_unlock(&dev->input_lock); return ret; diff --git a/drivers/staging/media/atomisp/i2c/gc0310.h b/drivers/staging/media/atomisp/i2c/gc0310.h index a2734934fc6a..0ff2d93cbcbf 100644 --- a/drivers/staging/media/atomisp/i2c/gc0310.h +++ b/drivers/staging/media/atomisp/i2c/gc0310.h @@ -138,20 +138,14 @@ struct gc0310_device { bool power_on; }; -enum gc0310_tok_type { - GC0310_8BIT = 0x0001, -}; - /** * struct gc0310_reg - MI sensor register format - * @type: type of the register * @reg: 16-bit offset to register * @val: 8/16/32-bit register value * * Define a structure for sensor register initialization values */ struct gc0310_reg { - enum gc0310_tok_type type; u8 reg; u8 val; /* @set value for read/mod/write, @mask */ }; @@ -165,181 +159,181 @@ static const struct gc0310_reg gc0310_reset_register[] = { ///////////////////////////////////////////////// ///////////////// system reg ///////////////// ///////////////////////////////////////////////// - {GC0310_8BIT, 0xfe, 0xf0}, - {GC0310_8BIT, 0xfe, 0xf0}, - {GC0310_8BIT, 0xfe, 0x00}, - - {GC0310_8BIT, 0xfc, 0x0e}, //4e - {GC0310_8BIT, 0xfc, 0x0e}, //16//4e // [0]apwd [6]regf_clk_gate - {GC0310_8BIT, 0xf2, 0x80}, //sync output - {GC0310_8BIT, 0xf3, 0x00}, //1f//01 data output - {GC0310_8BIT, 0xf7, 0x33}, //f9 - {GC0310_8BIT, 0xf8, 0x05}, //00 - {GC0310_8BIT, 0xf9, 0x0e}, // 0x8e //0f - {GC0310_8BIT, 0xfa, 0x11}, + { 0xfe, 0xf0 }, + { 0xfe, 0xf0 }, + { 0xfe, 0x00 }, + + { 0xfc, 0x0e }, /* 4e */ + { 0xfc, 0x0e }, /* 16//4e // [0]apwd [6]regf_clk_gate */ + { 0xf2, 0x80 }, /* sync output */ + { 0xf3, 0x00 }, /* 1f//01 data output */ + { 0xf7, 0x33 }, /* f9 */ + { 0xf8, 0x05 }, /* 00 */ + { 0xf9, 0x0e }, /* 0x8e //0f */ + { 0xfa, 0x11 }, ///////////////////////////////////////////////// /////////////////// MIPI //////////////////// ///////////////////////////////////////////////// - {GC0310_8BIT, 0xfe, 0x03}, - {GC0310_8BIT, 0x01, 0x03}, ///mipi 1lane - {GC0310_8BIT, 0x02, 0x22}, // 0x33 - {GC0310_8BIT, 0x03, 0x94}, - {GC0310_8BIT, 0x04, 0x01}, // fifo_prog - {GC0310_8BIT, 0x05, 0x00}, //fifo_prog - {GC0310_8BIT, 0x06, 0x80}, //b0 //YUV ISP data - {GC0310_8BIT, 0x11, 0x2a},//1e //LDI set YUV422 - {GC0310_8BIT, 0x12, 0x90},//00 //04 //00 //04//00 //LWC[7:0] // - {GC0310_8BIT, 0x13, 0x02},//05 //05 //LWC[15:8] - {GC0310_8BIT, 0x15, 0x12}, // 0x10 //DPHYY_MODE read_ready - {GC0310_8BIT, 0x17, 0x01}, - {GC0310_8BIT, 0x40, 0x08}, - {GC0310_8BIT, 0x41, 0x00}, - {GC0310_8BIT, 0x42, 0x00}, - {GC0310_8BIT, 0x43, 0x00}, - {GC0310_8BIT, 0x21, 0x02}, // 0x01 - {GC0310_8BIT, 0x22, 0x02}, // 0x01 - {GC0310_8BIT, 0x23, 0x01}, // 0x05 //Nor:0x05 DOU:0x06 - {GC0310_8BIT, 0x29, 0x00}, - {GC0310_8BIT, 0x2A, 0x25}, // 0x05 //data zero 0x7a de - {GC0310_8BIT, 0x2B, 0x02}, - - {GC0310_8BIT, 0xfe, 0x00}, + { 0xfe, 0x03 }, + { 0x01, 0x03 }, /* mipi 1lane */ + { 0x02, 0x22 }, /* 0x33 */ + { 0x03, 0x94 }, + { 0x04, 0x01 }, /* fifo_prog */ + { 0x05, 0x00 }, /* fifo_prog */ + { 0x06, 0x80 }, /* b0 //YUV ISP data */ + { 0x11, 0x2a }, /* 1e //LDI set YUV422 */ + { 0x12, 0x90 }, /* 00 //04 //00 //04//00 //LWC[7:0] */ + { 0x13, 0x02 }, /* 05 //05 //LWC[15:8] */ + { 0x15, 0x12 }, /* 0x10 //DPHYY_MODE read_ready */ + { 0x17, 0x01 }, + { 0x40, 0x08 }, + { 0x41, 0x00 }, + { 0x42, 0x00 }, + { 0x43, 0x00 }, + { 0x21, 0x02 }, /* 0x01 */ + { 0x22, 0x02 }, /* 0x01 */ + { 0x23, 0x01 }, /* 0x05 //Nor:0x05 DOU:0x06 */ + { 0x29, 0x00 }, + { 0x2A, 0x25 }, /* 0x05 //data zero 0x7a de */ + { 0x2B, 0x02 }, + + { 0xfe, 0x00 }, ///////////////////////////////////////////////// ///////////////// CISCTL reg ///////////////// ///////////////////////////////////////////////// - {GC0310_8BIT, 0x00, 0x2f}, //2f//0f//02//01 - {GC0310_8BIT, 0x01, 0x0f}, //06 - {GC0310_8BIT, 0x02, 0x04}, - {GC0310_8BIT, 0x4f, 0x00}, //AEC 0FF - {GC0310_8BIT, 0x03, 0x01}, // 0x03 //04 - {GC0310_8BIT, 0x04, 0xc0}, // 0xe8 //58 - {GC0310_8BIT, 0x05, 0x00}, - {GC0310_8BIT, 0x06, 0xb2}, // 0x0a //HB - {GC0310_8BIT, 0x07, 0x00}, - {GC0310_8BIT, 0x08, 0x0c}, // 0x89 //VB - {GC0310_8BIT, 0x09, 0x00}, //row start - {GC0310_8BIT, 0x0a, 0x00}, // - {GC0310_8BIT, 0x0b, 0x00}, //col start - {GC0310_8BIT, 0x0c, 0x00}, - {GC0310_8BIT, 0x0d, 0x01}, //height - {GC0310_8BIT, 0x0e, 0xf2}, // 0xf7 //height - {GC0310_8BIT, 0x0f, 0x02}, //width - {GC0310_8BIT, 0x10, 0x94}, // 0xa0 //height - {GC0310_8BIT, 0x17, 0x14}, - {GC0310_8BIT, 0x18, 0x1a}, //0a//[4]double reset - {GC0310_8BIT, 0x19, 0x14}, //AD pipeline - {GC0310_8BIT, 0x1b, 0x48}, - {GC0310_8BIT, 0x1e, 0x6b}, //3b//col bias - {GC0310_8BIT, 0x1f, 0x28}, //20//00//08//txlow - {GC0310_8BIT, 0x20, 0x89}, //88//0c//[3:2]DA15 - {GC0310_8BIT, 0x21, 0x49}, //48//[3] txhigh - {GC0310_8BIT, 0x22, 0xb0}, - {GC0310_8BIT, 0x23, 0x04}, //[1:0]vcm_r - {GC0310_8BIT, 0x24, 0x16}, //15 - {GC0310_8BIT, 0x34, 0x20}, //[6:4] rsg high//range + { 0x00, 0x2f }, /* 2f//0f//02//01 */ + { 0x01, 0x0f }, /* 06 */ + { 0x02, 0x04 }, + { 0x4f, 0x00 }, /* AEC 0FF */ + { 0x03, 0x01 }, /* 0x03 //04 */ + { 0x04, 0xc0 }, /* 0xe8 //58 */ + { 0x05, 0x00 }, + { 0x06, 0xb2 }, /* 0x0a //HB */ + { 0x07, 0x00 }, + { 0x08, 0x0c }, /* 0x89 //VB */ + { 0x09, 0x00 }, /* row start */ + { 0x0a, 0x00 }, + { 0x0b, 0x00 }, /* col start */ + { 0x0c, 0x00 }, + { 0x0d, 0x01 }, /* height */ + { 0x0e, 0xf2 }, /* 0xf7 //height */ + { 0x0f, 0x02 }, /* width */ + { 0x10, 0x94 }, /* 0xa0 //height */ + { 0x17, 0x14 }, + { 0x18, 0x1a }, /* 0a//[4]double reset */ + { 0x19, 0x14 }, /* AD pipeline */ + { 0x1b, 0x48 }, + { 0x1e, 0x6b }, /* 3b//col bias */ + { 0x1f, 0x28 }, /* 20//00//08//txlow */ + { 0x20, 0x89 }, /* 88//0c//[3:2]DA15 */ + { 0x21, 0x49 }, /* 48//[3] txhigh */ + { 0x22, 0xb0 }, + { 0x23, 0x04 }, /* [1:0]vcm_r */ + { 0x24, 0x16 }, /* 15 */ + { 0x34, 0x20 }, /* [6:4] rsg high//range */ ///////////////////////////////////////////////// //////////////////// BLK //////////////////// ///////////////////////////////////////////////// - {GC0310_8BIT, 0x26, 0x23}, //[1]dark_current_en [0]offset_en - {GC0310_8BIT, 0x28, 0xff}, //BLK_limie_value - {GC0310_8BIT, 0x29, 0x00}, //global offset - {GC0310_8BIT, 0x33, 0x18}, //offset_ratio - {GC0310_8BIT, 0x37, 0x20}, //dark_current_ratio - {GC0310_8BIT, 0x2a, 0x00}, - {GC0310_8BIT, 0x2b, 0x00}, - {GC0310_8BIT, 0x2c, 0x00}, - {GC0310_8BIT, 0x2d, 0x00}, - {GC0310_8BIT, 0x2e, 0x00}, - {GC0310_8BIT, 0x2f, 0x00}, - {GC0310_8BIT, 0x30, 0x00}, - {GC0310_8BIT, 0x31, 0x00}, - {GC0310_8BIT, 0x47, 0x80}, //a7 - {GC0310_8BIT, 0x4e, 0x66}, //select_row - {GC0310_8BIT, 0xa8, 0x02}, //win_width_dark, same with crop_win_width - {GC0310_8BIT, 0xa9, 0x80}, + { 0x26, 0x23 }, /* [1]dark_current_en [0]offset_en */ + { 0x28, 0xff }, /* BLK_limie_value */ + { 0x29, 0x00 }, /* global offset */ + { 0x33, 0x18 }, /* offset_ratio */ + { 0x37, 0x20 }, /* dark_current_ratio */ + { 0x2a, 0x00 }, + { 0x2b, 0x00 }, + { 0x2c, 0x00 }, + { 0x2d, 0x00 }, + { 0x2e, 0x00 }, + { 0x2f, 0x00 }, + { 0x30, 0x00 }, + { 0x31, 0x00 }, + { 0x47, 0x80 }, /* a7 */ + { 0x4e, 0x66 }, /* select_row */ + { 0xa8, 0x02 }, /* win_width_dark, same with crop_win_width */ + { 0xa9, 0x80 }, ///////////////////////////////////////////////// ////////////////// ISP reg /////////////////// ///////////////////////////////////////////////// - {GC0310_8BIT, 0x40, 0x06}, // 0xff //ff //48 - {GC0310_8BIT, 0x41, 0x00}, // 0x21 //00//[0]curve_en - {GC0310_8BIT, 0x42, 0x04}, // 0xcf //0a//[1]awn_en - {GC0310_8BIT, 0x44, 0x18}, // 0x18 //02 - {GC0310_8BIT, 0x46, 0x02}, // 0x03 //sync - {GC0310_8BIT, 0x49, 0x03}, - {GC0310_8BIT, 0x4c, 0x20}, //00[5]pretect exp - {GC0310_8BIT, 0x50, 0x01}, //crop enable - {GC0310_8BIT, 0x51, 0x00}, - {GC0310_8BIT, 0x52, 0x00}, - {GC0310_8BIT, 0x53, 0x00}, - {GC0310_8BIT, 0x54, 0x01}, - {GC0310_8BIT, 0x55, 0x01}, //crop window height - {GC0310_8BIT, 0x56, 0xf0}, - {GC0310_8BIT, 0x57, 0x02}, //crop window width - {GC0310_8BIT, 0x58, 0x90}, + { 0x40, 0x06 }, /* 0xff //ff //48 */ + { 0x41, 0x00 }, /* 0x21 //00//[0]curve_en */ + { 0x42, 0x04 }, /* 0xcf //0a//[1]awn_en */ + { 0x44, 0x18 }, /* 0x18 //02 */ + { 0x46, 0x02 }, /* 0x03 //sync */ + { 0x49, 0x03 }, + { 0x4c, 0x20 }, /* 00[5]pretect exp */ + { 0x50, 0x01 }, /* crop enable */ + { 0x51, 0x00 }, + { 0x52, 0x00 }, + { 0x53, 0x00 }, + { 0x54, 0x01 }, + { 0x55, 0x01 }, /* crop window height */ + { 0x56, 0xf0 }, + { 0x57, 0x02 }, /* crop window width */ + { 0x58, 0x90 }, ///////////////////////////////////////////////// /////////////////// GAIN //////////////////// ///////////////////////////////////////////////// - {GC0310_8BIT, 0x70, 0x70}, //70 //80//global gain - {GC0310_8BIT, 0x71, 0x20}, // pregain gain - {GC0310_8BIT, 0x72, 0x40}, // post gain - {GC0310_8BIT, 0x5a, 0x84}, //84//analog gain 0 - {GC0310_8BIT, 0x5b, 0xc9}, //c9 - {GC0310_8BIT, 0x5c, 0xed}, //ed//not use pga gain highest level - {GC0310_8BIT, 0x77, 0x40}, // R gain 0x74 //awb gain - {GC0310_8BIT, 0x78, 0x40}, // G gain - {GC0310_8BIT, 0x79, 0x40}, // B gain 0x5f - - {GC0310_8BIT, 0x48, 0x00}, - {GC0310_8BIT, 0xfe, 0x01}, - {GC0310_8BIT, 0x0a, 0x45}, //[7]col gain mode - - {GC0310_8BIT, 0x3e, 0x40}, - {GC0310_8BIT, 0x3f, 0x5c}, - {GC0310_8BIT, 0x40, 0x7b}, - {GC0310_8BIT, 0x41, 0xbd}, - {GC0310_8BIT, 0x42, 0xf6}, - {GC0310_8BIT, 0x43, 0x63}, - {GC0310_8BIT, 0x03, 0x60}, - {GC0310_8BIT, 0x44, 0x03}, + { 0x70, 0x70 }, /* 70 //80//global gain */ + { 0x71, 0x20 }, /* pregain gain */ + { 0x72, 0x40 }, /* post gain */ + { 0x5a, 0x84 }, /* 84//analog gain 0 */ + { 0x5b, 0xc9 }, /* c9 */ + { 0x5c, 0xed }, /* ed//not use pga gain highest level */ + { 0x77, 0x40 }, /* R gain 0x74 //awb gain */ + { 0x78, 0x40 }, /* G gain */ + { 0x79, 0x40 }, /* B gain 0x5f */ + + { 0x48, 0x00 }, + { 0xfe, 0x01 }, + { 0x0a, 0x45 }, /* [7]col gain mode */ + + { 0x3e, 0x40 }, + { 0x3f, 0x5c }, + { 0x40, 0x7b }, + { 0x41, 0xbd }, + { 0x42, 0xf6 }, + { 0x43, 0x63 }, + { 0x03, 0x60 }, + { 0x44, 0x03 }, ///////////////////////////////////////////////// ///////////////// dark sun ////////////////// ///////////////////////////////////////////////// - {GC0310_8BIT, 0xfe, 0x01}, - {GC0310_8BIT, 0x45, 0xa4}, // 0xf7 - {GC0310_8BIT, 0x46, 0xf0}, // 0xff //f0//sun value th - {GC0310_8BIT, 0x48, 0x03}, //sun mode - {GC0310_8BIT, 0x4f, 0x60}, //sun_clamp - {GC0310_8BIT, 0xfe, 0x00}, + { 0xfe, 0x01 }, + { 0x45, 0xa4 }, /* 0xf7 */ + { 0x46, 0xf0 }, /* 0xff //f0//sun value th */ + { 0x48, 0x03 }, /* sun mode */ + { 0x4f, 0x60 }, /* sun_clamp */ + { 0xfe, 0x00 }, }; static struct gc0310_reg const gc0310_VGA_30fps[] = { - {GC0310_8BIT, 0xfe, 0x00}, - {GC0310_8BIT, 0x0d, 0x01}, //height - {GC0310_8BIT, 0x0e, 0xf2}, // 0xf7 //height - {GC0310_8BIT, 0x0f, 0x02}, //width - {GC0310_8BIT, 0x10, 0x94}, // 0xa0 //height - - {GC0310_8BIT, 0x50, 0x01}, //crop enable - {GC0310_8BIT, 0x51, 0x00}, - {GC0310_8BIT, 0x52, 0x00}, - {GC0310_8BIT, 0x53, 0x00}, - {GC0310_8BIT, 0x54, 0x01}, - {GC0310_8BIT, 0x55, 0x01}, //crop window height - {GC0310_8BIT, 0x56, 0xf0}, - {GC0310_8BIT, 0x57, 0x02}, //crop window width - {GC0310_8BIT, 0x58, 0x90}, - - {GC0310_8BIT, 0xfe, 0x03}, - {GC0310_8BIT, 0x12, 0x90},//00 //04 //00 //04//00 //LWC[7:0] // - {GC0310_8BIT, 0x13, 0x02},//05 //05 //LWC[15:8] - - {GC0310_8BIT, 0xfe, 0x00}, + { 0xfe, 0x00 }, + { 0x0d, 0x01 }, /* height */ + { 0x0e, 0xf2 }, /* 0xf7 //height */ + { 0x0f, 0x02 }, /* width */ + { 0x10, 0x94 }, /* 0xa0 //height */ + + { 0x50, 0x01 }, /* crop enable */ + { 0x51, 0x00 }, + { 0x52, 0x00 }, + { 0x53, 0x00 }, + { 0x54, 0x01 }, + { 0x55, 0x01 }, /* crop window height */ + { 0x56, 0xf0 }, + { 0x57, 0x02 }, /* crop window width */ + { 0x58, 0x90 }, + + { 0xfe, 0x03 }, + { 0x12, 0x90 }, /* 00 //04 //00 //04//00 //LWC[7:0] */ + { 0x13, 0x02 }, /* 05 //05 //LWC[15:8] */ + + { 0xfe, 0x00 }, }; static struct gc0310_resolution gc0310_res_preview[] = { From patchwork Sat Apr 1 14:59:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 13197027 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8D230C6FD1D for ; Sat, 1 Apr 2023 15:00:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229983AbjDAPAq (ORCPT ); Sat, 1 Apr 2023 11:00:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37652 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229833AbjDAPAm (ORCPT ); Sat, 1 Apr 2023 11:00:42 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 582BC1CB8E for ; Sat, 1 Apr 2023 07:59:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1680361196; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=6ylEeyfC08i2/PJAiEisT3yiVpoB6N1xOgUl3mSfYH0=; b=Sg8uCvFCIQCFzO1ca2Pys6mcDfUuBhfQ60myHlqczsN/sQEvQevGQoqHl4KfXv79b1n1CT 6p5o1nbKbP8AoaD0YkhACsBdDXD60oGaDiOvAZNBvQhkQlysztfMRnD/WkDhbTBxlygwWD jGy4UYOeNVusjr/ROUkNkK4ARe7mZYE= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-108-DImI9LH9MtiCzRP14KW1Bw-1; Sat, 01 Apr 2023 10:59:51 -0400 X-MC-Unique: DImI9LH9MtiCzRP14KW1Bw-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id A31EC1C04181; Sat, 1 Apr 2023 14:59:50 +0000 (UTC) Received: from localhost.localdomain (unknown [10.39.192.49]) by smtp.corp.redhat.com (Postfix) with ESMTP id 22843483EC1; Sat, 1 Apr 2023 14:59:49 +0000 (UTC) From: Hans de Goede To: Mauro Carvalho Chehab , Sakari Ailus Cc: Hans de Goede , Kate Hsuan , Tsuchiya Yuto , Andy Shevchenko , Yury Luneff , Nable , andrey.i.trufanov@gmail.com, Fabio Aiuto , linux-media@vger.kernel.org, linux-staging@lists.linux.dev Subject: [PATCH 08/28] media: atomisp: gc0310: Replace custom reg access functions with smbus helpers Date: Sat, 1 Apr 2023 16:59:06 +0200 Message-Id: <20230401145926.596216-9-hdegoede@redhat.com> In-Reply-To: <20230401145926.596216-1-hdegoede@redhat.com> References: <20230401145926.596216-1-hdegoede@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org The gc0310 uses 8 bit register addresses which makes it compatible with the standard smbus access functions. Drop the custom reg access helpers, replacing them with the smbus access functions. Signed-off-by: Hans de Goede --- .../media/atomisp/i2c/atomisp-gc0310.c | 145 ++++-------------- drivers/staging/media/atomisp/i2c/gc0310.h | 4 - 2 files changed, 26 insertions(+), 123 deletions(-) diff --git a/drivers/staging/media/atomisp/i2c/atomisp-gc0310.c b/drivers/staging/media/atomisp/i2c/atomisp-gc0310.c index 4e92268da32a..8f7eea39858b 100644 --- a/drivers/staging/media/atomisp/i2c/atomisp-gc0310.c +++ b/drivers/staging/media/atomisp/i2c/atomisp-gc0310.c @@ -34,83 +34,6 @@ #include "gc0310.h" -/* i2c read/write stuff */ -static int gc0310_read_reg(struct i2c_client *client, u8 reg, u8 *val) -{ - int err; - struct i2c_msg msg[2]; - unsigned char data[1]; - - if (!client->adapter) { - dev_err(&client->dev, "%s error, no client->adapter\n", - __func__); - return -ENODEV; - } - - memset(msg, 0, sizeof(msg)); - - msg[0].addr = client->addr; - msg[0].flags = 0; - msg[0].len = I2C_MSG_LENGTH; - msg[0].buf = data; - - /* high byte goes out first */ - data[0] = (u8)(reg & 0xff); - - msg[1].addr = client->addr; - msg[1].len = 1; - msg[1].flags = I2C_M_RD; - msg[1].buf = data; - - err = i2c_transfer(client->adapter, msg, 2); - if (err != 2) { - if (err >= 0) - err = -EIO; - dev_err(&client->dev, - "read from offset 0x%x error %d", reg, err); - return err; - } - - *val = (u8)data[0]; - return 0; -} - -static int gc0310_i2c_write(struct i2c_client *client, u16 len, u8 *data) -{ - struct i2c_msg msg; - const int num_msg = 1; - int ret; - - msg.addr = client->addr; - msg.flags = 0; - msg.len = len; - msg.buf = data; - ret = i2c_transfer(client->adapter, &msg, 1); - - return ret == num_msg ? 0 : -EIO; -} - -static int gc0310_write_reg(struct i2c_client *client, u8 reg, u8 val) -{ - int ret; - unsigned char data[2] = {0}; - u8 *wreg = (u8 *)data; - const u16 len = 1 + sizeof(u8); /* 8-bit address + data */ - - /* high byte goes out first */ - *wreg = (u8)(reg & 0xff); - - data[1] = (u8)(val); - - ret = gc0310_i2c_write(client, len, data); - if (ret) - dev_err(&client->dev, - "write error: wrote 0x%x to offset 0x%x error %d", - val, reg, ret); - - return ret; -} - /* * gc0310_write_reg_array - Initializes a list of GC0310 registers * @client: i2c driver client structure @@ -123,9 +46,12 @@ static int gc0310_write_reg_array(struct i2c_client *client, int i, err; for (i = 0; i < count; i++) { - err = gc0310_write_reg(client, reglist[i].reg, reglist[i].val); - if (err) + err = i2c_smbus_write_byte_data(client, reglist[i].reg, reglist[i].val); + if (err) { + dev_err(&client->dev, "write error: wrote 0x%x to offset 0x%x error %d", + reglist[i].val, reglist[i].reg, err); return err; + } } return 0; @@ -154,12 +80,12 @@ static int gc0310_set_gain(struct v4l2_subdev *sd, int gain) dev_dbg(&client->dev, "gain=0x%x again=0x%x dgain=0x%x\n", gain, again, dgain); /* set analog gain */ - ret = gc0310_write_reg(client, GC0310_AGC_ADJ, again); + ret = i2c_smbus_write_byte_data(client, GC0310_AGC_ADJ, again); if (ret) return ret; /* set digital gain */ - ret = gc0310_write_reg(client, GC0310_DGC_ADJ, dgain); + ret = i2c_smbus_write_byte_data(client, GC0310_DGC_ADJ, dgain); if (ret) return ret; @@ -176,11 +102,7 @@ static int __gc0310_set_exposure(struct v4l2_subdev *sd, int coarse_itg, dev_dbg(&client->dev, "coarse_itg=%d gain=%d digitgain=%d\n", coarse_itg, gain, digitgain); /* set exposure */ - ret = gc0310_write_reg(client, GC0310_AEC_PK_EXPO_L, coarse_itg & 0xff); - if (ret) - return ret; - - ret = gc0310_write_reg(client, GC0310_AEC_PK_EXPO_H, (coarse_itg >> 8) & 0x0f); + ret = i2c_smbus_write_word_swapped(client, GC0310_AEC_PK_EXPO_H, coarse_itg); if (ret) return ret; @@ -251,22 +173,15 @@ static long gc0310_ioctl(struct v4l2_subdev *sd, unsigned int cmd, void *arg) static int gc0310_q_exposure(struct v4l2_subdev *sd, s32 *value) { struct i2c_client *client = v4l2_get_subdevdata(sd); - u8 reg_v; int ret; /* get exposure */ - ret = gc0310_read_reg(client, GC0310_AEC_PK_EXPO_L, ®_v); - if (ret) - goto err; - - *value = reg_v; - ret = gc0310_read_reg(client, GC0310_AEC_PK_EXPO_H, ®_v); - if (ret) - goto err; + ret = i2c_smbus_read_word_swapped(client, GC0310_AEC_PK_EXPO_H); + if (ret < 0) + return ret; - *value = *value + (reg_v << 8); -err: - return ret; + *value = ret; + return 0; } static int gc0310_s_ctrl(struct v4l2_ctrl *ctrl) @@ -618,29 +533,22 @@ static int gc0310_get_fmt(struct v4l2_subdev *sd, static int gc0310_detect(struct i2c_client *client) { struct i2c_adapter *adapter = client->adapter; - u8 high, low; int ret; - u16 id; if (!i2c_check_functionality(adapter, I2C_FUNC_I2C)) return -ENODEV; - ret = gc0310_read_reg(client, GC0310_SC_CMMN_CHIP_ID_H, &high); - if (ret) { - dev_err(&client->dev, "read sensor_id_high failed\n"); - return -ENODEV; - } - ret = gc0310_read_reg(client, GC0310_SC_CMMN_CHIP_ID_L, &low); - if (ret) { - dev_err(&client->dev, "read sensor_id_low failed\n"); + ret = i2c_smbus_read_word_swapped(client, GC0310_SC_CMMN_CHIP_ID_H); + if (ret < 0) { + dev_err(&client->dev, "read sensor_id failed: %d\n", ret); return -ENODEV; } - id = ((((u16)high) << 8) | (u16)low); - dev_dbg(&client->dev, "sensor ID = 0x%x\n", id); - if (id != GC0310_ID) { - dev_err(&client->dev, "sensor ID error, read id = 0x%x, target id = 0x%x\n", id, - GC0310_ID); + dev_dbg(&client->dev, "sensor ID = 0x%x\n", ret); + + if (ret != GC0310_ID) { + dev_err(&client->dev, "sensor ID error, read id = 0x%x, target id = 0x%x\n", + ret, GC0310_ID); return -ENODEV; } @@ -660,28 +568,27 @@ static int gc0310_s_stream(struct v4l2_subdev *sd, int enable) if (enable) { /* enable per frame MIPI and sensor ctrl reset */ - ret = gc0310_write_reg(client, 0xFE, 0x30); + ret = i2c_smbus_write_byte_data(client, 0xFE, 0x30); if (ret) { mutex_unlock(&dev->input_lock); return ret; } } - ret = gc0310_write_reg(client, GC0310_RESET_RELATED, GC0310_REGISTER_PAGE_3); + ret = i2c_smbus_write_byte_data(client, GC0310_RESET_RELATED, GC0310_REGISTER_PAGE_3); if (ret) { mutex_unlock(&dev->input_lock); return ret; } - ret = gc0310_write_reg(client, GC0310_SW_STREAM, - enable ? GC0310_START_STREAMING : - GC0310_STOP_STREAMING); + ret = i2c_smbus_write_byte_data(client, GC0310_SW_STREAM, + enable ? GC0310_START_STREAMING : GC0310_STOP_STREAMING); if (ret) { mutex_unlock(&dev->input_lock); return ret; } - ret = gc0310_write_reg(client, GC0310_RESET_RELATED, GC0310_REGISTER_PAGE_0); + ret = i2c_smbus_write_byte_data(client, GC0310_RESET_RELATED, GC0310_REGISTER_PAGE_0); if (ret) { mutex_unlock(&dev->input_lock); return ret; diff --git a/drivers/staging/media/atomisp/i2c/gc0310.h b/drivers/staging/media/atomisp/i2c/gc0310.h index 0ff2d93cbcbf..540334bc7b0e 100644 --- a/drivers/staging/media/atomisp/i2c/gc0310.h +++ b/drivers/staging/media/atomisp/i2c/gc0310.h @@ -33,10 +33,6 @@ #include "../include/linux/atomisp_platform.h" -/* Defines for register writes and register array processing */ -#define I2C_MSG_LENGTH 1 -#define I2C_RETRY_COUNT 5 - #define GC0310_FOCAL_LENGTH_NUM 278 /*2.78mm*/ #define MAX_FMTS 1 From patchwork Sat Apr 1 14:59:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 13197030 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D2302C6FD1D for ; Sat, 1 Apr 2023 15:00:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230077AbjDAPAt (ORCPT ); Sat, 1 Apr 2023 11:00:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37672 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229985AbjDAPAq (ORCPT ); Sat, 1 Apr 2023 11:00:46 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5B4321CB9B for ; Sat, 1 Apr 2023 07:59:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1680361198; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=JP5qdqrHUFH6LRRriErWEru2yLbtNJt7pxXTeJIx3gs=; b=Z9AXOol+puCKTM2dNa+xRt5xJdhpsx7kJ0m201FEA8gyQR3/0eZ/mohNgiHRYN1fcByjLc /y3C0JpRAJECnrO8xscvAJk6iC1xnEJHTVNac+z/d9d6/32Ww1p8z3KVF5Z+x66m6DUCFv xyru//A4O+teOukuMVl9fRO7khP1pH0= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-655-hJwjZVlhOuWBq82cb94ovA-1; Sat, 01 Apr 2023 10:59:53 -0400 X-MC-Unique: hJwjZVlhOuWBq82cb94ovA-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 616EC85A588; Sat, 1 Apr 2023 14:59:52 +0000 (UTC) Received: from localhost.localdomain (unknown [10.39.192.49]) by smtp.corp.redhat.com (Postfix) with ESMTP id D65764021BC; Sat, 1 Apr 2023 14:59:50 +0000 (UTC) From: Hans de Goede To: Mauro Carvalho Chehab , Sakari Ailus Cc: Hans de Goede , Kate Hsuan , Tsuchiya Yuto , Andy Shevchenko , Yury Luneff , Nable , andrey.i.trufanov@gmail.com, Fabio Aiuto , linux-media@vger.kernel.org, linux-staging@lists.linux.dev Subject: [PATCH 09/28] media: atomisp: gc0310: Remove non working flip-controls Date: Sat, 1 Apr 2023 16:59:07 +0200 Message-Id: <20230401145926.596216-10-hdegoede@redhat.com> In-Reply-To: <20230401145926.596216-1-hdegoede@redhat.com> References: <20230401145926.596216-1-hdegoede@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org The gc0310_[v|h]_flip() functions are empty stubs, remove the non working controls. Signed-off-by: Hans de Goede --- .../media/atomisp/i2c/atomisp-gc0310.c | 45 ------------------- 1 file changed, 45 deletions(-) diff --git a/drivers/staging/media/atomisp/i2c/atomisp-gc0310.c b/drivers/staging/media/atomisp/i2c/atomisp-gc0310.c index 8f7eea39858b..93cde642ce44 100644 --- a/drivers/staging/media/atomisp/i2c/atomisp-gc0310.c +++ b/drivers/staging/media/atomisp/i2c/atomisp-gc0310.c @@ -144,18 +144,6 @@ static long gc0310_s_exposure(struct v4l2_subdev *sd, return gc0310_set_exposure(sd, exp, gain, digitgain); } -/* TO DO */ -static int gc0310_v_flip(struct v4l2_subdev *sd, s32 value) -{ - return 0; -} - -/* TO DO */ -static int gc0310_h_flip(struct v4l2_subdev *sd, s32 value) -{ - return 0; -} - static long gc0310_ioctl(struct v4l2_subdev *sd, unsigned int cmd, void *arg) { switch (cmd) { @@ -186,22 +174,9 @@ static int gc0310_q_exposure(struct v4l2_subdev *sd, s32 *value) static int gc0310_s_ctrl(struct v4l2_ctrl *ctrl) { - struct gc0310_device *dev = - container_of(ctrl->handler, struct gc0310_device, ctrl_handler); - struct i2c_client *client = v4l2_get_subdevdata(&dev->sd); int ret = 0; switch (ctrl->id) { - case V4L2_CID_VFLIP: - dev_dbg(&client->dev, "%s: CID_VFLIP:%d.\n", - __func__, ctrl->val); - ret = gc0310_v_flip(&dev->sd, ctrl->val); - break; - case V4L2_CID_HFLIP: - dev_dbg(&client->dev, "%s: CID_HFLIP:%d.\n", - __func__, ctrl->val); - ret = gc0310_h_flip(&dev->sd, ctrl->val); - break; default: ret = -EINVAL; } @@ -242,26 +217,6 @@ static const struct v4l2_ctrl_config gc0310_controls[] = { .def = 0x00, .flags = 0, }, - { - .ops = &ctrl_ops, - .id = V4L2_CID_VFLIP, - .type = V4L2_CTRL_TYPE_BOOLEAN, - .name = "Flip", - .min = 0, - .max = 1, - .step = 1, - .def = 0, - }, - { - .ops = &ctrl_ops, - .id = V4L2_CID_HFLIP, - .type = V4L2_CTRL_TYPE_BOOLEAN, - .name = "Mirror", - .min = 0, - .max = 1, - .step = 1, - .def = 0, - }, }; static int gc0310_init(struct v4l2_subdev *sd) From patchwork Sat Apr 1 14:59:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 13197034 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CB75CC77B6D for ; Sat, 1 Apr 2023 15:00:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229997AbjDAPAz (ORCPT ); Sat, 1 Apr 2023 11:00:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37726 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230095AbjDAPAv (ORCPT ); Sat, 1 Apr 2023 11:00:51 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E2E231D862 for ; Sat, 1 Apr 2023 08:00:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1680361200; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=S4GAIpJCftsr7cfhH7olfn6cbD9j4KKnAiVOmRdN5nc=; b=HyMnbsFi5tk8dDqtoy9N95kjYJOJg51uSXZuvEF/K8OOU9NAlRE+OU62S454kMHRheqmpD 1q0dXJoefouTR2XIxF2g4+H218BM5BH/akWoGivXw965oZBrOT4HYG8JLn972Qhs0zpf8n sbSjNmxwZcWu5LI2eqUrGP4jR3rZ/04= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-438-GG6NRFMbO1KQWG4K6pAVAw-1; Sat, 01 Apr 2023 10:59:54 -0400 X-MC-Unique: GG6NRFMbO1KQWG4K6pAVAw-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 200DF801779; Sat, 1 Apr 2023 14:59:54 +0000 (UTC) Received: from localhost.localdomain (unknown [10.39.192.49]) by smtp.corp.redhat.com (Postfix) with ESMTP id 945F74021C7; Sat, 1 Apr 2023 14:59:52 +0000 (UTC) From: Hans de Goede To: Mauro Carvalho Chehab , Sakari Ailus Cc: Hans de Goede , Kate Hsuan , Tsuchiya Yuto , Andy Shevchenko , Yury Luneff , Nable , andrey.i.trufanov@gmail.com, Fabio Aiuto , linux-media@vger.kernel.org, linux-staging@lists.linux.dev Subject: [PATCH 10/28] media: atomisp: gc0310: Remove read-only exposure control Date: Sat, 1 Apr 2023 16:59:08 +0200 Message-Id: <20230401145926.596216-11-hdegoede@redhat.com> In-Reply-To: <20230401145926.596216-1-hdegoede@redhat.com> References: <20230401145926.596216-1-hdegoede@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org The sensor does not have automatic exposure so the exposure cannot change underneath us. And the control is not marked volatile in it flags, so the .g_volatile_ctrl callback will never get called. Remove the current broken read-only (no s_ctrl implementation) exposure ctrl, this will be replaced with a proper r/w exposure control relying on the kernel caching the last set value (so non volatile). Signed-off-by: Hans de Goede --- .../media/atomisp/i2c/atomisp-gc0310.c | 58 +------------------ 1 file changed, 1 insertion(+), 57 deletions(-) diff --git a/drivers/staging/media/atomisp/i2c/atomisp-gc0310.c b/drivers/staging/media/atomisp/i2c/atomisp-gc0310.c index 93cde642ce44..ba36bd0a0b41 100644 --- a/drivers/staging/media/atomisp/i2c/atomisp-gc0310.c +++ b/drivers/staging/media/atomisp/i2c/atomisp-gc0310.c @@ -155,23 +155,6 @@ static long gc0310_ioctl(struct v4l2_subdev *sd, unsigned int cmd, void *arg) return 0; } -/* This returns the exposure time being used. This should only be used - * for filling in EXIF data, not for actual image processing. - */ -static int gc0310_q_exposure(struct v4l2_subdev *sd, s32 *value) -{ - struct i2c_client *client = v4l2_get_subdevdata(sd); - int ret; - - /* get exposure */ - ret = i2c_smbus_read_word_swapped(client, GC0310_AEC_PK_EXPO_H); - if (ret < 0) - return ret; - - *value = ret; - return 0; -} - static int gc0310_s_ctrl(struct v4l2_ctrl *ctrl) { int ret = 0; @@ -183,40 +166,8 @@ static int gc0310_s_ctrl(struct v4l2_ctrl *ctrl) return ret; } -static int gc0310_g_volatile_ctrl(struct v4l2_ctrl *ctrl) -{ - struct gc0310_device *dev = - container_of(ctrl->handler, struct gc0310_device, ctrl_handler); - int ret = 0; - - switch (ctrl->id) { - case V4L2_CID_EXPOSURE_ABSOLUTE: - ret = gc0310_q_exposure(&dev->sd, &ctrl->val); - break; - default: - ret = -EINVAL; - } - - return ret; -} - static const struct v4l2_ctrl_ops ctrl_ops = { .s_ctrl = gc0310_s_ctrl, - .g_volatile_ctrl = gc0310_g_volatile_ctrl -}; - -static const struct v4l2_ctrl_config gc0310_controls[] = { - { - .ops = &ctrl_ops, - .id = V4L2_CID_EXPOSURE_ABSOLUTE, - .type = V4L2_CTRL_TYPE_INTEGER, - .name = "exposure", - .min = 0x0, - .max = 0xffff, - .step = 0x01, - .def = 0x00, - .flags = 0, - }, }; static int gc0310_init(struct v4l2_subdev *sd) @@ -713,7 +664,6 @@ static int gc0310_probe(struct i2c_client *client) struct gc0310_device *dev; int ret; void *pdata; - unsigned int i; dev = kzalloc(sizeof(*dev), GFP_KERNEL); if (!dev) @@ -744,18 +694,12 @@ static int gc0310_probe(struct i2c_client *client) dev->pad.flags = MEDIA_PAD_FL_SOURCE; dev->format.code = MEDIA_BUS_FMT_SGRBG8_1X8; dev->sd.entity.function = MEDIA_ENT_F_CAM_SENSOR; - ret = - v4l2_ctrl_handler_init(&dev->ctrl_handler, - ARRAY_SIZE(gc0310_controls)); + ret = v4l2_ctrl_handler_init(&dev->ctrl_handler, 0); if (ret) { gc0310_remove(client); return ret; } - for (i = 0; i < ARRAY_SIZE(gc0310_controls); i++) - v4l2_ctrl_new_custom(&dev->ctrl_handler, &gc0310_controls[i], - NULL); - if (dev->ctrl_handler.error) { gc0310_remove(client); return dev->ctrl_handler.error; From patchwork Sat Apr 1 14:59:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 13197032 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 05DFDC761AF for ; Sat, 1 Apr 2023 15:00:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230061AbjDAPAw (ORCPT ); Sat, 1 Apr 2023 11:00:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37730 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230082AbjDAPAt (ORCPT ); Sat, 1 Apr 2023 11:00:49 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 54E301DFB1 for ; Sat, 1 Apr 2023 08:00:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1680361200; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Ykzzsi4vPVmnhdDu6qdf+OaX902dNbyBhmUCGQHQEy8=; b=F5E7SZVD0rTEah68UasgEc3zY+6HWxCPat515t6tpIz4bA8aMOEljq19pMnuqb70YxEm4e 3WxnAFdLWiK18yL4esl/mayJeG51j7YPSmjN6hf/pOHsXmsYnZRi+Sy9iMLNdDAP6Zr2eX soQ0RhAFjj0tH56lKgvZSBcfQ4lEF78= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-436-U2EDORFDO8SrvaCKl1Uj0w-1; Sat, 01 Apr 2023 10:59:56 -0400 X-MC-Unique: U2EDORFDO8SrvaCKl1Uj0w-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id D27338533DC; Sat, 1 Apr 2023 14:59:55 +0000 (UTC) Received: from localhost.localdomain (unknown [10.39.192.49]) by smtp.corp.redhat.com (Postfix) with ESMTP id 531FD400F59; Sat, 1 Apr 2023 14:59:54 +0000 (UTC) From: Hans de Goede To: Mauro Carvalho Chehab , Sakari Ailus Cc: Hans de Goede , Kate Hsuan , Tsuchiya Yuto , Andy Shevchenko , Yury Luneff , Nable , andrey.i.trufanov@gmail.com, Fabio Aiuto , linux-media@vger.kernel.org, linux-staging@lists.linux.dev Subject: [PATCH 11/28] media: atomisp: gc0310: Drop custom ATOMISP_IOC_S_EXPOSURE support Date: Sat, 1 Apr 2023 16:59:09 +0200 Message-Id: <20230401145926.596216-12-hdegoede@redhat.com> In-Reply-To: <20230401145926.596216-1-hdegoede@redhat.com> References: <20230401145926.596216-1-hdegoede@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org Exposure and gain control should use standard v4l2 controls, not a custom ioctl. The next patch in this series will re-add support as standard controls, this is split into 2 patches for easier reviewing. Signed-off-by: Hans de Goede --- .../media/atomisp/i2c/atomisp-gc0310.c | 99 ------------------- 1 file changed, 99 deletions(-) diff --git a/drivers/staging/media/atomisp/i2c/atomisp-gc0310.c b/drivers/staging/media/atomisp/i2c/atomisp-gc0310.c index ba36bd0a0b41..115493641010 100644 --- a/drivers/staging/media/atomisp/i2c/atomisp-gc0310.c +++ b/drivers/staging/media/atomisp/i2c/atomisp-gc0310.c @@ -57,104 +57,6 @@ static int gc0310_write_reg_array(struct i2c_client *client, return 0; } -static int gc0310_set_gain(struct v4l2_subdev *sd, int gain) - -{ - struct i2c_client *client = v4l2_get_subdevdata(sd); - int ret; - u8 again, dgain; - - if (gain < 0x20) - gain = 0x20; - if (gain > 0x80) - gain = 0x80; - - if (gain >= 0x20 && gain < 0x40) { - again = 0x0; /* sqrt(2) */ - dgain = gain; - } else { - again = 0x2; /* 2 * sqrt(2) */ - dgain = gain / 2; - } - - dev_dbg(&client->dev, "gain=0x%x again=0x%x dgain=0x%x\n", gain, again, dgain); - - /* set analog gain */ - ret = i2c_smbus_write_byte_data(client, GC0310_AGC_ADJ, again); - if (ret) - return ret; - - /* set digital gain */ - ret = i2c_smbus_write_byte_data(client, GC0310_DGC_ADJ, dgain); - if (ret) - return ret; - - return 0; -} - -static int __gc0310_set_exposure(struct v4l2_subdev *sd, int coarse_itg, - int gain, int digitgain) - -{ - struct i2c_client *client = v4l2_get_subdevdata(sd); - int ret; - - dev_dbg(&client->dev, "coarse_itg=%d gain=%d digitgain=%d\n", coarse_itg, gain, digitgain); - - /* set exposure */ - ret = i2c_smbus_write_word_swapped(client, GC0310_AEC_PK_EXPO_H, coarse_itg); - if (ret) - return ret; - - ret = gc0310_set_gain(sd, gain); - if (ret) - return ret; - - return ret; -} - -static int gc0310_set_exposure(struct v4l2_subdev *sd, int exposure, - int gain, int digitgain) -{ - struct gc0310_device *dev = to_gc0310_sensor(sd); - int ret; - - mutex_lock(&dev->input_lock); - ret = __gc0310_set_exposure(sd, exposure, gain, digitgain); - mutex_unlock(&dev->input_lock); - - return ret; -} - -static long gc0310_s_exposure(struct v4l2_subdev *sd, - struct atomisp_exposure *exposure) -{ - int exp = exposure->integration_time[0]; - int gain = exposure->gain[0]; - int digitgain = exposure->gain[1]; - - /* we should not accept the invalid value below. */ - if (gain == 0) { - struct i2c_client *client = v4l2_get_subdevdata(sd); - - v4l2_err(client, "%s: invalid value\n", __func__); - return -EINVAL; - } - - return gc0310_set_exposure(sd, exp, gain, digitgain); -} - -static long gc0310_ioctl(struct v4l2_subdev *sd, unsigned int cmd, void *arg) -{ - switch (cmd) { - case ATOMISP_IOC_S_EXPOSURE: - return gc0310_s_exposure(sd, arg); - default: - return -EINVAL; - } - return 0; -} - static int gc0310_s_ctrl(struct v4l2_ctrl *ctrl) { int ret = 0; @@ -627,7 +529,6 @@ static const struct v4l2_subdev_video_ops gc0310_video_ops = { static const struct v4l2_subdev_core_ops gc0310_core_ops = { .s_power = gc0310_s_power, - .ioctl = gc0310_ioctl, }; static const struct v4l2_subdev_pad_ops gc0310_pad_ops = { From patchwork Sat Apr 1 14:59:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 13197033 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 59E28C6FD1D for ; Sat, 1 Apr 2023 15:00:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230082AbjDAPAx (ORCPT ); Sat, 1 Apr 2023 11:00:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37716 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230015AbjDAPAu (ORCPT ); Sat, 1 Apr 2023 11:00:50 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9DAC81CBA4 for ; Sat, 1 Apr 2023 08:00:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1680361199; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=pkgaf5c4d1VhFzjzxgJCnOcCSZwf5jijmDkhU+8kZ8Y=; b=JjufkcWwtDhtYjhbKHH6KKZl/ZjetJWWVreCQ7jT2aLeKt+KBKcxAi3nvxhf9cDHnCfEQz jLMpIOL5hgycyooaB7Ho1XD8wun6P4156soFS4HfQnepCYdO6F1s2THVf8MF1EPWCvSE+2 QfqsYmXhZlZ8mFHeeJd6dNFK0PANigo= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-481-BoVStUByNLq80bc9suS1LQ-1; Sat, 01 Apr 2023 10:59:58 -0400 X-MC-Unique: BoVStUByNLq80bc9suS1LQ-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 983DE3C0253E; Sat, 1 Apr 2023 14:59:57 +0000 (UTC) Received: from localhost.localdomain (unknown [10.39.192.49]) by smtp.corp.redhat.com (Postfix) with ESMTP id 135C3400F59; Sat, 1 Apr 2023 14:59:55 +0000 (UTC) From: Hans de Goede To: Mauro Carvalho Chehab , Sakari Ailus Cc: Hans de Goede , Kate Hsuan , Tsuchiya Yuto , Andy Shevchenko , Yury Luneff , Nable , andrey.i.trufanov@gmail.com, Fabio Aiuto , linux-media@vger.kernel.org, linux-staging@lists.linux.dev Subject: [PATCH 12/28] media: atomisp: gc0310: Add exposure and gain controls Date: Sat, 1 Apr 2023 16:59:10 +0200 Message-Id: <20230401145926.596216-13-hdegoede@redhat.com> In-Reply-To: <20230401145926.596216-1-hdegoede@redhat.com> References: <20230401145926.596216-1-hdegoede@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org Add exposure and gain controls. This allows controlling the exposure and gain through standard v4l2 IOCTLs. Signed-off-by: Hans de Goede --- .../media/atomisp/i2c/atomisp-gc0310.c | 93 ++++++++++++++++--- drivers/staging/media/atomisp/i2c/gc0310.h | 7 +- 2 files changed, 86 insertions(+), 14 deletions(-) diff --git a/drivers/staging/media/atomisp/i2c/atomisp-gc0310.c b/drivers/staging/media/atomisp/i2c/atomisp-gc0310.c index 115493641010..6c0877ab96e3 100644 --- a/drivers/staging/media/atomisp/i2c/atomisp-gc0310.c +++ b/drivers/staging/media/atomisp/i2c/atomisp-gc0310.c @@ -57,14 +57,64 @@ static int gc0310_write_reg_array(struct i2c_client *client, return 0; } +static int gc0310_exposure_set(struct gc0310_device *dev, u32 exp) +{ + struct i2c_client *client = v4l2_get_subdevdata(&dev->sd); + + return i2c_smbus_write_word_swapped(client, GC0310_AEC_PK_EXPO_H, exp); +} + +static int gc0310_gain_set(struct gc0310_device *dev, u32 gain) +{ + struct i2c_client *client = v4l2_get_subdevdata(&dev->sd); + u8 again, dgain; + int ret; + + /* Taken from original driver, this never sets dgain lower then 32? */ + + /* Change 0 - 95 to 32 - 127 */ + gain += 32; + + if (gain < 64) { + again = 0x0; /* sqrt(2) */ + dgain = gain; + } else { + again = 0x2; /* 2 * sqrt(2) */ + dgain = gain / 2; + } + + ret = i2c_smbus_write_byte_data(client, GC0310_AGC_ADJ, again); + if (ret) + return ret; + + ret = i2c_smbus_write_byte_data(client, GC0310_DGC_ADJ, dgain); + if (ret) + return ret; + + return 0; +} + static int gc0310_s_ctrl(struct v4l2_ctrl *ctrl) { - int ret = 0; + struct gc0310_device *dev = + container_of(ctrl->handler, struct gc0310_device, ctrls.handler); + int ret; + + if (!dev->power_on) + return 0; switch (ctrl->id) { + case V4L2_CID_EXPOSURE: + ret = gc0310_exposure_set(dev, ctrl->val); + break; + case V4L2_CID_GAIN: + ret = gc0310_gain_set(dev, ctrl->val); + break; default: ret = -EINVAL; + break; } + return ret; } @@ -83,13 +133,18 @@ static int gc0310_init(struct v4l2_subdev *sd) /* set initial registers */ ret = gc0310_write_reg_array(client, gc0310_reset_register, ARRAY_SIZE(gc0310_reset_register)); + if (ret) + goto out_unlock; /* restore settings */ gc0310_res = gc0310_res_preview; N_RES = N_RES_PREVIEW; - mutex_unlock(&dev->input_lock); + /* restore value of all ctrls */ + ret = __v4l2_ctrl_handler_setup(&dev->ctrls.handler); +out_unlock: + mutex_unlock(&dev->input_lock); return ret; } @@ -545,6 +600,26 @@ static const struct v4l2_subdev_ops gc0310_ops = { .sensor = &gc0310_sensor_ops, }; +static int gc0310_init_controls(struct gc0310_device *dev) +{ + struct v4l2_ctrl_handler *hdl = &dev->ctrls.handler; + + v4l2_ctrl_handler_init(hdl, 2); + + /* Use same lock for controls as for everything else. */ + hdl->lock = &dev->input_lock; + dev->sd.ctrl_handler = hdl; + + dev->ctrls.exposure = + v4l2_ctrl_new_std(hdl, &ctrl_ops, V4L2_CID_EXPOSURE, 0, 4095, 1, 1023); + + /* 32 steps at base gain 1 + 64 half steps at base gain 2 */ + dev->ctrls.gain = + v4l2_ctrl_new_std(hdl, &ctrl_ops, V4L2_CID_GAIN, 0, 95, 1, 31); + + return hdl->error; +} + static void gc0310_remove(struct i2c_client *client) { struct v4l2_subdev *sd = i2c_get_clientdata(client); @@ -556,7 +631,7 @@ static void gc0310_remove(struct i2c_client *client) v4l2_device_unregister_subdev(sd); media_entity_cleanup(&dev->sd.entity); - v4l2_ctrl_handler_free(&dev->ctrl_handler); + v4l2_ctrl_handler_free(&dev->ctrls.handler); kfree(dev); } @@ -595,21 +670,13 @@ static int gc0310_probe(struct i2c_client *client) dev->pad.flags = MEDIA_PAD_FL_SOURCE; dev->format.code = MEDIA_BUS_FMT_SGRBG8_1X8; dev->sd.entity.function = MEDIA_ENT_F_CAM_SENSOR; - ret = v4l2_ctrl_handler_init(&dev->ctrl_handler, 0); + + ret = gc0310_init_controls(dev); if (ret) { gc0310_remove(client); return ret; } - if (dev->ctrl_handler.error) { - gc0310_remove(client); - return dev->ctrl_handler.error; - } - - /* Use same lock for controls as for everything else. */ - dev->ctrl_handler.lock = &dev->input_lock; - dev->sd.ctrl_handler = &dev->ctrl_handler; - ret = media_entity_pads_init(&dev->sd.entity, 1, &dev->pad); if (ret) gc0310_remove(client); diff --git a/drivers/staging/media/atomisp/i2c/gc0310.h b/drivers/staging/media/atomisp/i2c/gc0310.h index 540334bc7b0e..c15ca2b807f9 100644 --- a/drivers/staging/media/atomisp/i2c/gc0310.h +++ b/drivers/staging/media/atomisp/i2c/gc0310.h @@ -126,12 +126,17 @@ struct gc0310_device { struct media_pad pad; struct v4l2_mbus_framefmt format; struct mutex input_lock; - struct v4l2_ctrl_handler ctrl_handler; struct camera_sensor_platform_data *platform_data; struct gc0310_resolution *res; u8 type; bool power_on; + + struct gc0310_ctrls { + struct v4l2_ctrl_handler handler; + struct v4l2_ctrl *exposure; + struct v4l2_ctrl *gain; + } ctrls; }; /** From patchwork Sat Apr 1 14:59:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 13197035 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B5C0CC77B62 for ; Sat, 1 Apr 2023 15:00:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230052AbjDAPAz (ORCPT ); Sat, 1 Apr 2023 11:00:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37752 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230037AbjDAPAy (ORCPT ); Sat, 1 Apr 2023 11:00:54 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 901A01E728 for ; Sat, 1 Apr 2023 08:00:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1680361201; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=t4kfFE6KYMiQFTFIfMGebaiWP7ApdcSgc6W/HcJ9JMk=; b=TqKWSQJfQ4FA7mpZe6MK0SbeFuAF4VucJF1+der0m+kgnQTK3Z+G3zEHPM8WCOzsSLyGbJ UF7Bmqzoe2oYVC82lJ4WHRCdCTWFDOdULMI/9CQdI02bP8h16KIhFiqFUK03g5vGVqw7uo cZcEoBrTJUpRCkYfXtPXMy/Ilo7W7BQ= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-211-SjAC1yPnM6yLP0jkgWwOEA-1; Sat, 01 Apr 2023 11:00:00 -0400 X-MC-Unique: SjAC1yPnM6yLP0jkgWwOEA-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 5777C8533DC; Sat, 1 Apr 2023 14:59:59 +0000 (UTC) Received: from localhost.localdomain (unknown [10.39.192.49]) by smtp.corp.redhat.com (Postfix) with ESMTP id CB9124021BC; Sat, 1 Apr 2023 14:59:57 +0000 (UTC) From: Hans de Goede To: Mauro Carvalho Chehab , Sakari Ailus Cc: Hans de Goede , Kate Hsuan , Tsuchiya Yuto , Andy Shevchenko , Yury Luneff , Nable , andrey.i.trufanov@gmail.com, Fabio Aiuto , linux-media@vger.kernel.org, linux-staging@lists.linux.dev Subject: [PATCH 13/28] media: atomisp: gc0310: Add error_unlock label to s_stream() Date: Sat, 1 Apr 2023 16:59:11 +0200 Message-Id: <20230401145926.596216-14-hdegoede@redhat.com> In-Reply-To: <20230401145926.596216-1-hdegoede@redhat.com> References: <20230401145926.596216-1-hdegoede@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org Add error_unlock label + goto error_unlock on error to remove separate unlock-s in all the error-exit paths. Signed-off-by: Hans de Goede --- .../media/atomisp/i2c/atomisp-gc0310.c | 28 ++++++++----------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/drivers/staging/media/atomisp/i2c/atomisp-gc0310.c b/drivers/staging/media/atomisp/i2c/atomisp-gc0310.c index 6c0877ab96e3..239fc9012910 100644 --- a/drivers/staging/media/atomisp/i2c/atomisp-gc0310.c +++ b/drivers/staging/media/atomisp/i2c/atomisp-gc0310.c @@ -432,31 +432,27 @@ static int gc0310_s_stream(struct v4l2_subdev *sd, int enable) if (enable) { /* enable per frame MIPI and sensor ctrl reset */ ret = i2c_smbus_write_byte_data(client, 0xFE, 0x30); - if (ret) { - mutex_unlock(&dev->input_lock); - return ret; - } + if (ret) + goto error_unlock; } ret = i2c_smbus_write_byte_data(client, GC0310_RESET_RELATED, GC0310_REGISTER_PAGE_3); - if (ret) { - mutex_unlock(&dev->input_lock); - return ret; - } + if (ret) + goto error_unlock; ret = i2c_smbus_write_byte_data(client, GC0310_SW_STREAM, enable ? GC0310_START_STREAMING : GC0310_STOP_STREAMING); - if (ret) { - mutex_unlock(&dev->input_lock); - return ret; - } + if (ret) + goto error_unlock; ret = i2c_smbus_write_byte_data(client, GC0310_RESET_RELATED, GC0310_REGISTER_PAGE_0); - if (ret) { - mutex_unlock(&dev->input_lock); - return ret; - } + if (ret) + goto error_unlock; + + mutex_unlock(&dev->input_lock); + return 0; +error_unlock: mutex_unlock(&dev->input_lock); return ret; } From patchwork Sat Apr 1 14:59:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 13197036 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CE97AC76196 for ; Sat, 1 Apr 2023 15:00:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230037AbjDAPA5 (ORCPT ); Sat, 1 Apr 2023 11:00:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37768 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229845AbjDAPA4 (ORCPT ); Sat, 1 Apr 2023 11:00:56 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BEA751DFB6 for ; Sat, 1 Apr 2023 08:00:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1680361204; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=7ReSuU32dFMkQH+TDGRhJotj/ixwxLO0kvOtAU6uj0o=; b=KE7WWfs0qx476ADlgzIFArwzOCSpUqgory02nih3jfaUXhqJ54smW4/6OtEY9HcdCg1xFY Rt2j6koGyQ1Z8luSM5lG8SnOJTr2Q8Si6GF7/YfhtANwzjArUlciysO9U50pdPMiZT0awO kjQuIJC4QDXoOAC2lYaGy1Umo01v//o= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-629-CdYfV9J3MXCzLL-ezmaMiw-1; Sat, 01 Apr 2023 11:00:01 -0400 X-MC-Unique: CdYfV9J3MXCzLL-ezmaMiw-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 20A602A5955E; Sat, 1 Apr 2023 15:00:01 +0000 (UTC) Received: from localhost.localdomain (unknown [10.39.192.49]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8B23B400F59; Sat, 1 Apr 2023 14:59:59 +0000 (UTC) From: Hans de Goede To: Mauro Carvalho Chehab , Sakari Ailus Cc: Hans de Goede , Kate Hsuan , Tsuchiya Yuto , Andy Shevchenko , Yury Luneff , Nable , andrey.i.trufanov@gmail.com, Fabio Aiuto , linux-media@vger.kernel.org, linux-staging@lists.linux.dev Subject: [PATCH 14/28] media: atomisp: gc0310: Modernize and simply set_fmt(), get_fmt(), etc. Date: Sat, 1 Apr 2023 16:59:12 +0200 Message-Id: <20230401145926.596216-15-hdegoede@redhat.com> In-Reply-To: <20230401145926.596216-1-hdegoede@redhat.com> References: <20230401145926.596216-1-hdegoede@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org There only is 1 supported resolution allowing significant simplification of the code; and also bring the code up2date with current subdev fmt handling practices. Signed-off-by: Hans de Goede --- .../media/atomisp/i2c/atomisp-gc0310.c | 127 ++++++------------ drivers/staging/media/atomisp/i2c/gc0310.h | 72 ++-------- 2 files changed, 49 insertions(+), 150 deletions(-) diff --git a/drivers/staging/media/atomisp/i2c/atomisp-gc0310.c b/drivers/staging/media/atomisp/i2c/atomisp-gc0310.c index 239fc9012910..015795f32c3a 100644 --- a/drivers/staging/media/atomisp/i2c/atomisp-gc0310.c +++ b/drivers/staging/media/atomisp/i2c/atomisp-gc0310.c @@ -136,10 +136,6 @@ static int gc0310_init(struct v4l2_subdev *sd) if (ret) goto out_unlock; - /* restore settings */ - gc0310_res = gc0310_res_preview; - N_RES = N_RES_PREVIEW; - /* restore value of all ctrls */ ret = __v4l2_ctrl_handler_setup(&dev->ctrls.handler); @@ -300,76 +296,50 @@ static int gc0310_s_power(struct v4l2_subdev *sd, int on) return gc0310_init(sd); } -/* TODO: remove it. */ -static int startup(struct v4l2_subdev *sd) +static struct v4l2_mbus_framefmt * +gc0310_get_pad_format(struct gc0310_device *dev, + struct v4l2_subdev_state *state, + unsigned int pad, enum v4l2_subdev_format_whence which) { - struct gc0310_device *dev = to_gc0310_sensor(sd); - struct i2c_client *client = v4l2_get_subdevdata(sd); - int ret = 0; + if (which == V4L2_SUBDEV_FORMAT_TRY) + return v4l2_subdev_get_try_format(&dev->sd, state, pad); - ret = gc0310_write_reg_array(client, dev->res->regs, dev->res->reg_count); - if (ret) { - dev_err(&client->dev, "gc0310 write register err.\n"); - return ret; - } + return &dev->mode.fmt; +} - return ret; +/* The GC0310 currently only supports 1 fixed fmt */ +static void gc0310_fill_format(struct v4l2_mbus_framefmt *fmt) +{ + memset(fmt, 0, sizeof(*fmt)); + fmt->width = GC0310_NATIVE_WIDTH; + fmt->height = GC0310_NATIVE_HEIGHT; + fmt->field = V4L2_FIELD_NONE; + fmt->code = MEDIA_BUS_FMT_SGRBG8_1X8; } static int gc0310_set_fmt(struct v4l2_subdev *sd, struct v4l2_subdev_state *sd_state, struct v4l2_subdev_format *format) { - struct v4l2_mbus_framefmt *fmt = &format->format; - struct gc0310_device *dev = to_gc0310_sensor(sd); struct i2c_client *client = v4l2_get_subdevdata(sd); - struct camera_mipi_info *gc0310_info = NULL; - struct gc0310_resolution *res; - int ret = 0; - - if (format->pad) - return -EINVAL; - - if (!fmt) - return -EINVAL; - - gc0310_info = v4l2_get_subdev_hostdata(sd); - if (!gc0310_info) - return -EINVAL; - - mutex_lock(&dev->input_lock); + struct gc0310_device *dev = to_gc0310_sensor(sd); + struct v4l2_mbus_framefmt *fmt; + int ret; - res = v4l2_find_nearest_size(gc0310_res_preview, - ARRAY_SIZE(gc0310_res_preview), width, - height, fmt->width, fmt->height); - if (!res) - res = &gc0310_res_preview[N_RES - 1]; + fmt = gc0310_get_pad_format(dev, sd_state, format->pad, format->which); + gc0310_fill_format(fmt); - fmt->width = res->width; - fmt->height = res->height; - dev->res = res; + format->format = *fmt; - fmt->code = MEDIA_BUS_FMT_SGRBG8_1X8; - - if (format->which == V4L2_SUBDEV_FORMAT_TRY) { - sd_state->pads->try_fmt = *fmt; - mutex_unlock(&dev->input_lock); + if (format->which == V4L2_SUBDEV_FORMAT_TRY) return 0; - } + mutex_lock(&dev->input_lock); /* s_power has not been called yet for std v4l2 clients (camorama) */ power_up(sd); - - dev_dbg(&client->dev, "%s: before gc0310_write_reg_array %s\n", - __func__, dev->res->desc); - ret = startup(sd); - if (ret) { - dev_err(&client->dev, "gc0310 startup err\n"); - goto err; - } - -err: + ret = gc0310_write_reg_array(client, gc0310_VGA_30fps, ARRAY_SIZE(gc0310_VGA_30fps)); mutex_unlock(&dev->input_lock); + return ret; } @@ -377,19 +347,11 @@ static int gc0310_get_fmt(struct v4l2_subdev *sd, struct v4l2_subdev_state *sd_state, struct v4l2_subdev_format *format) { - struct v4l2_mbus_framefmt *fmt = &format->format; struct gc0310_device *dev = to_gc0310_sensor(sd); + struct v4l2_mbus_framefmt *fmt; - if (format->pad) - return -EINVAL; - - if (!fmt) - return -EINVAL; - - fmt->width = dev->res->width; - fmt->height = dev->res->height; - fmt->code = MEDIA_BUS_FMT_SGRBG8_1X8; - + fmt = gc0310_get_pad_format(dev, sd_state, format->pad, format->which); + format->format = *fmt; return 0; } @@ -522,10 +484,8 @@ static int gc0310_s_config(struct v4l2_subdev *sd, static int gc0310_g_frame_interval(struct v4l2_subdev *sd, struct v4l2_subdev_frame_interval *interval) { - struct gc0310_device *dev = to_gc0310_sensor(sd); - interval->interval.numerator = 1; - interval->interval.denominator = dev->res->fps; + interval->interval.denominator = GC0310_FPS; return 0; } @@ -534,7 +494,8 @@ static int gc0310_enum_mbus_code(struct v4l2_subdev *sd, struct v4l2_subdev_state *sd_state, struct v4l2_subdev_mbus_code_enum *code) { - if (code->index >= MAX_FMTS) + /* We support only a single format */ + if (code->index) return -EINVAL; code->code = MEDIA_BUS_FMT_SGRBG8_1X8; @@ -545,27 +506,21 @@ static int gc0310_enum_frame_size(struct v4l2_subdev *sd, struct v4l2_subdev_state *sd_state, struct v4l2_subdev_frame_size_enum *fse) { - int index = fse->index; - - if (index >= N_RES) + /* We support only a single resolution */ + if (fse->index) return -EINVAL; - fse->min_width = gc0310_res[index].width; - fse->min_height = gc0310_res[index].height; - fse->max_width = gc0310_res[index].width; - fse->max_height = gc0310_res[index].height; + fse->min_width = GC0310_NATIVE_WIDTH; + fse->max_width = GC0310_NATIVE_WIDTH; + fse->min_height = GC0310_NATIVE_HEIGHT; + fse->max_height = GC0310_NATIVE_HEIGHT; return 0; } static int gc0310_g_skip_frames(struct v4l2_subdev *sd, u32 *frames) { - struct gc0310_device *dev = to_gc0310_sensor(sd); - - mutex_lock(&dev->input_lock); - *frames = dev->res->skip_frames; - mutex_unlock(&dev->input_lock); - + *frames = GC0310_SKIP_FRAMES; return 0; } @@ -642,9 +597,8 @@ static int gc0310_probe(struct i2c_client *client) return -ENOMEM; mutex_init(&dev->input_lock); - - dev->res = &gc0310_res_preview[0]; v4l2_i2c_subdev_init(&dev->sd, client, &gc0310_ops); + gc0310_fill_format(&dev->mode.fmt); pdata = gmin_camera_platform_data(&dev->sd, ATOMISP_INPUT_FORMAT_RAW_8, @@ -664,7 +618,6 @@ static int gc0310_probe(struct i2c_client *client) dev->sd.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE; dev->pad.flags = MEDIA_PAD_FL_SOURCE; - dev->format.code = MEDIA_BUS_FMT_SGRBG8_1X8; dev->sd.entity.function = MEDIA_ENT_F_CAM_SENSOR; ret = gc0310_init_controls(dev); diff --git a/drivers/staging/media/atomisp/i2c/gc0310.h b/drivers/staging/media/atomisp/i2c/gc0310.h index c15ca2b807f9..1d22fd25e165 100644 --- a/drivers/staging/media/atomisp/i2c/gc0310.h +++ b/drivers/staging/media/atomisp/i2c/gc0310.h @@ -33,30 +33,14 @@ #include "../include/linux/atomisp_platform.h" -#define GC0310_FOCAL_LENGTH_NUM 278 /*2.78mm*/ +#define GC0310_NATIVE_WIDTH 656 +#define GC0310_NATIVE_HEIGHT 496 -#define MAX_FMTS 1 +#define GC0310_FPS 30 +#define GC0310_SKIP_FRAMES 3 -/* - * focal length bits definition: - * bits 31-16: numerator, bits 15-0: denominator - */ -#define GC0310_FOCAL_LENGTH_DEFAULT 0x1160064 - -/* - * current f-number bits definition: - * bits 31-16: numerator, bits 15-0: denominator - */ -#define GC0310_F_NUMBER_DEFAULT 0x1a000a +#define GC0310_FOCAL_LENGTH_NUM 278 /* 2.78mm */ -/* - * f-number range bits definition: - * bits 31-24: max f-number numerator - * bits 23-16: max f-number denominator - * bits 15-8: min f-number numerator - * bits 7-0: min f-number denominator - */ -#define GC0310_F_NUMBER_RANGE 0x1a0a1a0a #define GC0310_ID 0xa310 #define GC0310_RESET_RELATED 0xFE @@ -101,37 +85,21 @@ #define GC0310_START_STREAMING 0x94 /* 8-bit enable */ #define GC0310_STOP_STREAMING 0x0 /* 8-bit disable */ -#define GC0310_BIN_FACTOR_MAX 3 - -struct gc0310_resolution { - u8 *desc; - const struct gc0310_reg *regs; - int reg_count; - int res; - int width; - int height; - int fps; - int pix_clk_freq; - u32 skip_frames; - u16 pixels_per_line; - u16 lines_per_frame; - bool used; -}; - /* * gc0310 device structure. */ struct gc0310_device { struct v4l2_subdev sd; struct media_pad pad; - struct v4l2_mbus_framefmt format; struct mutex input_lock; struct camera_sensor_platform_data *platform_data; - struct gc0310_resolution *res; - u8 type; bool power_on; + struct gc0310_mode { + struct v4l2_mbus_framefmt fmt; + } mode; + struct gc0310_ctrls { struct v4l2_ctrl_handler handler; struct v4l2_ctrl *exposure; @@ -337,26 +305,4 @@ static struct gc0310_reg const gc0310_VGA_30fps[] = { { 0xfe, 0x00 }, }; -static struct gc0310_resolution gc0310_res_preview[] = { - { - .desc = "gc0310_VGA_30fps", - .width = 656, // 648, - .height = 496, // 488, - .fps = 30, - //.pix_clk_freq = 73, - .used = 0, -#if 0 - .pixels_per_line = 0x0314, - .lines_per_frame = 0x0213, -#endif - .skip_frames = 2, - .regs = gc0310_VGA_30fps, - .reg_count = ARRAY_SIZE(gc0310_VGA_30fps), - }, -}; - -#define N_RES_PREVIEW (ARRAY_SIZE(gc0310_res_preview)) - -static struct gc0310_resolution *gc0310_res = gc0310_res_preview; -static unsigned long N_RES = N_RES_PREVIEW; #endif From patchwork Sat Apr 1 14:59:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 13197039 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 50041C6FD1D for ; Sat, 1 Apr 2023 15:01:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230015AbjDAPBV (ORCPT ); Sat, 1 Apr 2023 11:01:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37922 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229845AbjDAPBU (ORCPT ); Sat, 1 Apr 2023 11:01:20 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8AFAC1EA19 for ; Sat, 1 Apr 2023 08:00:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1680361208; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=EWbPv+gRI/bXJ+PXZMYDiUh13YuVVwH3uscxjgyXbFY=; b=fTy64mwgCbdnspCQepYDHZ5jjj349KRGVAXZr0FnhPJxGDT+4HhdKw5QvBo7Uwpex/hPXK 4y1rMTY48hq7x77MOux78jzzt7VPrm/nudBEnFAlUFVj5TuESXqq3OSWn/egrfkRMX92Di w5lDJmRdlCY4Ifb6jAQi/dR7fmIrtuk= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-312-dT3750KEM5y4Zt1YxzGKBA-1; Sat, 01 Apr 2023 11:00:03 -0400 X-MC-Unique: dT3750KEM5y4Zt1YxzGKBA-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id D59893C0253E; Sat, 1 Apr 2023 15:00:02 +0000 (UTC) Received: from localhost.localdomain (unknown [10.39.192.49]) by smtp.corp.redhat.com (Postfix) with ESMTP id 54BE9400F59; Sat, 1 Apr 2023 15:00:01 +0000 (UTC) From: Hans de Goede To: Mauro Carvalho Chehab , Sakari Ailus Cc: Hans de Goede , Kate Hsuan , Tsuchiya Yuto , Andy Shevchenko , Yury Luneff , Nable , andrey.i.trufanov@gmail.com, Fabio Aiuto , linux-media@vger.kernel.org, linux-staging@lists.linux.dev Subject: [PATCH 15/28] media: atomisp: gc0310: Delay power-on till streaming is started Date: Sat, 1 Apr 2023 16:59:13 +0200 Message-Id: <20230401145926.596216-16-hdegoede@redhat.com> In-Reply-To: <20230401145926.596216-1-hdegoede@redhat.com> References: <20230401145926.596216-1-hdegoede@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org Move the setting of the mode to stream on, this also allows delaying power-on till streaming is started. And drop the deprecated s_power callback since this now no long is necessary. Signed-off-by: Hans de Goede --- .../media/atomisp/i2c/atomisp-gc0310.c | 87 +++++++------------ 1 file changed, 29 insertions(+), 58 deletions(-) diff --git a/drivers/staging/media/atomisp/i2c/atomisp-gc0310.c b/drivers/staging/media/atomisp/i2c/atomisp-gc0310.c index 015795f32c3a..305d43b9815b 100644 --- a/drivers/staging/media/atomisp/i2c/atomisp-gc0310.c +++ b/drivers/staging/media/atomisp/i2c/atomisp-gc0310.c @@ -122,28 +122,6 @@ static const struct v4l2_ctrl_ops ctrl_ops = { .s_ctrl = gc0310_s_ctrl, }; -static int gc0310_init(struct v4l2_subdev *sd) -{ - int ret; - struct i2c_client *client = v4l2_get_subdevdata(sd); - struct gc0310_device *dev = to_gc0310_sensor(sd); - - mutex_lock(&dev->input_lock); - - /* set initial registers */ - ret = gc0310_write_reg_array(client, gc0310_reset_register, - ARRAY_SIZE(gc0310_reset_register)); - if (ret) - goto out_unlock; - - /* restore value of all ctrls */ - ret = __v4l2_ctrl_handler_setup(&dev->ctrls.handler); - -out_unlock: - mutex_unlock(&dev->input_lock); - return ret; -} - static int power_ctrl(struct v4l2_subdev *sd, bool flag) { int ret = 0; @@ -282,20 +260,6 @@ static int power_down(struct v4l2_subdev *sd) return ret; } -static int gc0310_s_power(struct v4l2_subdev *sd, int on) -{ - int ret; - - if (on == 0) - return power_down(sd); - - ret = power_up(sd); - if (ret) - return ret; - - return gc0310_init(sd); -} - static struct v4l2_mbus_framefmt * gc0310_get_pad_format(struct gc0310_device *dev, struct v4l2_subdev_state *state, @@ -321,26 +285,14 @@ static int gc0310_set_fmt(struct v4l2_subdev *sd, struct v4l2_subdev_state *sd_state, struct v4l2_subdev_format *format) { - struct i2c_client *client = v4l2_get_subdevdata(sd); struct gc0310_device *dev = to_gc0310_sensor(sd); struct v4l2_mbus_framefmt *fmt; - int ret; fmt = gc0310_get_pad_format(dev, sd_state, format->pad, format->which); gc0310_fill_format(fmt); format->format = *fmt; - - if (format->which == V4L2_SUBDEV_FORMAT_TRY) - return 0; - - mutex_lock(&dev->input_lock); - /* s_power has not been called yet for std v4l2 clients (camorama) */ - power_up(sd); - ret = gc0310_write_reg_array(client, gc0310_VGA_30fps, ARRAY_SIZE(gc0310_VGA_30fps)); - mutex_unlock(&dev->input_lock); - - return ret; + return 0; } static int gc0310_get_fmt(struct v4l2_subdev *sd, @@ -392,28 +344,52 @@ static int gc0310_s_stream(struct v4l2_subdev *sd, int enable) mutex_lock(&dev->input_lock); if (enable) { + ret = power_up(sd); + if (ret) + goto error_unlock; + + ret = gc0310_write_reg_array(client, gc0310_reset_register, + ARRAY_SIZE(gc0310_reset_register)); + if (ret) + goto error_power_down; + + ret = gc0310_write_reg_array(client, gc0310_VGA_30fps, + ARRAY_SIZE(gc0310_VGA_30fps)); + if (ret) + goto error_power_down; + + /* restore value of all ctrls */ + ret = __v4l2_ctrl_handler_setup(&dev->ctrls.handler); + if (ret) + goto error_power_down; + /* enable per frame MIPI and sensor ctrl reset */ ret = i2c_smbus_write_byte_data(client, 0xFE, 0x30); if (ret) - goto error_unlock; + goto error_power_down; } ret = i2c_smbus_write_byte_data(client, GC0310_RESET_RELATED, GC0310_REGISTER_PAGE_3); if (ret) - goto error_unlock; + goto error_power_down; ret = i2c_smbus_write_byte_data(client, GC0310_SW_STREAM, enable ? GC0310_START_STREAMING : GC0310_STOP_STREAMING); if (ret) - goto error_unlock; + goto error_power_down; ret = i2c_smbus_write_byte_data(client, GC0310_RESET_RELATED, GC0310_REGISTER_PAGE_0); if (ret) - goto error_unlock; + goto error_power_down; + + if (!enable) + power_down(sd); mutex_unlock(&dev->input_lock); return 0; +error_power_down: + power_down(sd); error_unlock: mutex_unlock(&dev->input_lock); return ret; @@ -533,10 +509,6 @@ static const struct v4l2_subdev_video_ops gc0310_video_ops = { .g_frame_interval = gc0310_g_frame_interval, }; -static const struct v4l2_subdev_core_ops gc0310_core_ops = { - .s_power = gc0310_s_power, -}; - static const struct v4l2_subdev_pad_ops gc0310_pad_ops = { .enum_mbus_code = gc0310_enum_mbus_code, .enum_frame_size = gc0310_enum_frame_size, @@ -545,7 +517,6 @@ static const struct v4l2_subdev_pad_ops gc0310_pad_ops = { }; static const struct v4l2_subdev_ops gc0310_ops = { - .core = &gc0310_core_ops, .video = &gc0310_video_ops, .pad = &gc0310_pad_ops, .sensor = &gc0310_sensor_ops, From patchwork Sat Apr 1 14:59:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 13197038 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 435A1C761AF for ; Sat, 1 Apr 2023 15:01:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230054AbjDAPBA (ORCPT ); Sat, 1 Apr 2023 11:01:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37794 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229845AbjDAPA6 (ORCPT ); Sat, 1 Apr 2023 11:00:58 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 309EE1E73D for ; Sat, 1 Apr 2023 08:00:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1680361208; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=TKKh7czIRUQddklBJSPQE3QDh4P3NeHxHDOsxHwxqrY=; b=VzhQDefuCirwUzr9lDiQBG4P+07o/I+x5h1SEDvrQ/eulcLb2nBm1LRMLPAYKcKPnQqOtb ohWB42U02W6VUw6KBwI5bQO5QCQC+VOsPA0oKDGvtu0XjY6bnNO9NxBK5e13tUW3GkIsEb n8wFUE7in3vJ49cHz0nOsQX4t+2wbxE= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-187-Hk4ZOGNMOuyvZikwOw_FcA-1; Sat, 01 Apr 2023 11:00:05 -0400 X-MC-Unique: Hk4ZOGNMOuyvZikwOw_FcA-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 9A73A85A5A3; Sat, 1 Apr 2023 15:00:04 +0000 (UTC) Received: from localhost.localdomain (unknown [10.39.192.49]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1592C400F59; Sat, 1 Apr 2023 15:00:02 +0000 (UTC) From: Hans de Goede To: Mauro Carvalho Chehab , Sakari Ailus Cc: Hans de Goede , Kate Hsuan , Tsuchiya Yuto , Andy Shevchenko , Yury Luneff , Nable , andrey.i.trufanov@gmail.com, Fabio Aiuto , linux-media@vger.kernel.org, linux-staging@lists.linux.dev Subject: [PATCH 16/28] media: atomisp: gc0310: Add runtime-pm support Date: Sat, 1 Apr 2023 16:59:14 +0200 Message-Id: <20230401145926.596216-17-hdegoede@redhat.com> In-Reply-To: <20230401145926.596216-1-hdegoede@redhat.com> References: <20230401145926.596216-1-hdegoede@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org Add runtime-pm support. This is a preparation patch for letting ACPI deal with the regulators and clocks instead of the DIY code in atomisp_gmin_platform.c. Signed-off-by: Hans de Goede --- .../media/atomisp/i2c/atomisp-gc0310.c | 91 +++++++++++-------- drivers/staging/media/atomisp/i2c/gc0310.h | 2 +- 2 files changed, 53 insertions(+), 40 deletions(-) diff --git a/drivers/staging/media/atomisp/i2c/atomisp-gc0310.c b/drivers/staging/media/atomisp/i2c/atomisp-gc0310.c index 305d43b9815b..1224213d4195 100644 --- a/drivers/staging/media/atomisp/i2c/atomisp-gc0310.c +++ b/drivers/staging/media/atomisp/i2c/atomisp-gc0310.c @@ -28,6 +28,7 @@ #include #include #include +#include #include #include #include "../include/linux/atomisp_gmin_platform.h" @@ -100,7 +101,8 @@ static int gc0310_s_ctrl(struct v4l2_ctrl *ctrl) container_of(ctrl->handler, struct gc0310_device, ctrls.handler); int ret; - if (!dev->power_on) + /* Only apply changes to the controls if the device is powered up */ + if (!pm_runtime_get_if_in_use(dev->sd.dev)) return 0; switch (ctrl->id) { @@ -115,6 +117,7 @@ static int gc0310_s_ctrl(struct v4l2_ctrl *ctrl) break; } + pm_runtime_put(dev->sd.dev); return ret; } @@ -188,9 +191,6 @@ static int power_up(struct v4l2_subdev *sd) return -ENODEV; } - if (dev->power_on) - return 0; /* Already on */ - /* power control */ ret = power_ctrl(sd, 1); if (ret) @@ -211,7 +211,6 @@ static int power_up(struct v4l2_subdev *sd) msleep(100); - dev->power_on = true; return 0; fail_gpio: @@ -236,9 +235,6 @@ static int power_down(struct v4l2_subdev *sd) return -ENODEV; } - if (!dev->power_on) - return 0; /* Already off */ - /* gpio ctrl */ ret = gpio_ctrl(sd, 0); if (ret) { @@ -256,7 +252,6 @@ static int power_down(struct v4l2_subdev *sd) if (ret) dev_err(&client->dev, "vprog failed.\n"); - dev->power_on = false; return ret; } @@ -338,15 +333,20 @@ static int gc0310_s_stream(struct v4l2_subdev *sd, int enable) { struct gc0310_device *dev = to_gc0310_sensor(sd); struct i2c_client *client = v4l2_get_subdevdata(sd); - int ret; + int ret = 0; dev_dbg(&client->dev, "%s S enable=%d\n", __func__, enable); mutex_lock(&dev->input_lock); + if (dev->is_streaming == enable) { + dev_warn(&client->dev, "stream already %s\n", enable ? "started" : "stopped"); + goto error_unlock; + } + if (enable) { - ret = power_up(sd); - if (ret) - goto error_unlock; + ret = pm_runtime_get_sync(&client->dev); + if (ret < 0) + goto error_power_down; ret = gc0310_write_reg_array(client, gc0310_reset_register, ARRAY_SIZE(gc0310_reset_register)); @@ -383,13 +383,15 @@ static int gc0310_s_stream(struct v4l2_subdev *sd, int enable) goto error_power_down; if (!enable) - power_down(sd); + pm_runtime_put(&client->dev); + dev->is_streaming = enable; mutex_unlock(&dev->input_lock); return 0; error_power_down: - power_down(sd); + pm_runtime_put(&client->dev); + dev->is_streaming = false; error_unlock: mutex_unlock(&dev->input_lock); return ret; @@ -409,19 +411,9 @@ static int gc0310_s_config(struct v4l2_subdev *sd, (struct camera_sensor_platform_data *)platform_data; mutex_lock(&dev->input_lock); - /* power off the module, then power on it in future - * as first power on by board may not fulfill the - * power on sequqence needed by the module - */ - dev->power_on = true; /* force power_down() to run */ - ret = power_down(sd); - if (ret) { - dev_err(&client->dev, "gc0310 power-off err.\n"); - goto fail_power_off; - } - ret = power_up(sd); - if (ret) { + ret = pm_runtime_get_sync(&client->dev); + if (ret < 0) { dev_err(&client->dev, "gc0310 power-up err.\n"); goto fail_power_on; } @@ -438,11 +430,7 @@ static int gc0310_s_config(struct v4l2_subdev *sd, } /* turn off sensor, after probed */ - ret = power_down(sd); - if (ret) { - dev_err(&client->dev, "gc0310 power-off err.\n"); - goto fail_csi_cfg; - } + pm_runtime_put(&client->dev); mutex_unlock(&dev->input_lock); return 0; @@ -450,9 +438,7 @@ static int gc0310_s_config(struct v4l2_subdev *sd, fail_csi_cfg: dev->platform_data->csi_cfg(sd, 0); fail_power_on: - power_down(sd); - dev_err(&client->dev, "sensor power-gating failed\n"); -fail_power_off: + pm_runtime_put(&client->dev); mutex_unlock(&dev->input_lock); return ret; } @@ -554,6 +540,7 @@ static void gc0310_remove(struct i2c_client *client) v4l2_device_unregister_subdev(sd); media_entity_cleanup(&dev->sd.entity); v4l2_ctrl_handler_free(&dev->ctrls.handler); + pm_runtime_disable(&client->dev); kfree(dev); } @@ -579,13 +566,22 @@ static int gc0310_probe(struct i2c_client *client) goto out_free; } + pm_runtime_set_suspended(&client->dev); + pm_runtime_enable(&client->dev); + pm_runtime_set_autosuspend_delay(&client->dev, 1000); + pm_runtime_use_autosuspend(&client->dev); + ret = gc0310_s_config(&dev->sd, client->irq, pdata); - if (ret) - goto out_free; + if (ret) { + gc0310_remove(client); + return ret; + } ret = atomisp_register_i2c_module(&dev->sd, pdata, RAW_CAMERA); - if (ret) - goto out_free; + if (ret) { + gc0310_remove(client); + return ret; + } dev->sd.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE; dev->pad.flags = MEDIA_PAD_FL_SOURCE; @@ -608,6 +604,22 @@ static int gc0310_probe(struct i2c_client *client) return ret; } +static int gc0310_suspend(struct device *dev) +{ + struct v4l2_subdev *sd = dev_get_drvdata(dev); + + return power_down(sd); +} + +static int gc0310_resume(struct device *dev) +{ + struct v4l2_subdev *sd = dev_get_drvdata(dev); + + return power_up(sd); +} + +static DEFINE_RUNTIME_DEV_PM_OPS(gc0310_pm_ops, gc0310_suspend, gc0310_resume, NULL); + static const struct acpi_device_id gc0310_acpi_match[] = { {"XXGC0310"}, {"INT0310"}, @@ -618,6 +630,7 @@ MODULE_DEVICE_TABLE(acpi, gc0310_acpi_match); static struct i2c_driver gc0310_driver = { .driver = { .name = "gc0310", + .pm = pm_sleep_ptr(&gc0310_pm_ops), .acpi_match_table = gc0310_acpi_match, }, .probe_new = gc0310_probe, diff --git a/drivers/staging/media/atomisp/i2c/gc0310.h b/drivers/staging/media/atomisp/i2c/gc0310.h index 1d22fd25e165..485a060b40ff 100644 --- a/drivers/staging/media/atomisp/i2c/gc0310.h +++ b/drivers/staging/media/atomisp/i2c/gc0310.h @@ -94,7 +94,7 @@ struct gc0310_device { struct mutex input_lock; struct camera_sensor_platform_data *platform_data; - bool power_on; + bool is_streaming; struct gc0310_mode { struct v4l2_mbus_framefmt fmt; From patchwork Sat Apr 1 14:59:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 13197037 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2512FC6FD1D for ; Sat, 1 Apr 2023 15:01:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230090AbjDAPA7 (ORCPT ); Sat, 1 Apr 2023 11:00:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37784 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229944AbjDAPA6 (ORCPT ); Sat, 1 Apr 2023 11:00:58 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F0BA41E716 for ; Sat, 1 Apr 2023 08:00:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1680361208; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=d9bxYclTLgvm2p4T7WEwjxdU7TdJiJQDYi5GQDLCCYE=; b=Z7K1xsspeu10iSLuIfuH+rlFlSJWx2hmqX9fli9SDGsw1FwfijfhRKQq7/lvxc4SgNfBAJ Ncn5bTcgqreU5KYulQTjK3DXf8+bw1RmFQTrHvS76fDsutoG5a9G+tXc2FXj1R5woZpfT/ vRHBqxXDFT6lut+3MIgzwQysM2F0X9g= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-63-HpVyV5CePs6sIoRraTba6w-1; Sat, 01 Apr 2023 11:00:07 -0400 X-MC-Unique: HpVyV5CePs6sIoRraTba6w-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 664418533DD; Sat, 1 Apr 2023 15:00:06 +0000 (UTC) Received: from localhost.localdomain (unknown [10.39.192.49]) by smtp.corp.redhat.com (Postfix) with ESMTP id CE9D8400F59; Sat, 1 Apr 2023 15:00:04 +0000 (UTC) From: Hans de Goede To: Mauro Carvalho Chehab , Sakari Ailus Cc: Hans de Goede , Kate Hsuan , Tsuchiya Yuto , Andy Shevchenko , Yury Luneff , Nable , andrey.i.trufanov@gmail.com, Fabio Aiuto , linux-media@vger.kernel.org, linux-staging@lists.linux.dev Subject: [PATCH 17/28] media: atomisp: gc0310: Use devm_kzalloc() for data struct Date: Sat, 1 Apr 2023 16:59:15 +0200 Message-Id: <20230401145926.596216-18-hdegoede@redhat.com> In-Reply-To: <20230401145926.596216-1-hdegoede@redhat.com> References: <20230401145926.596216-1-hdegoede@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org Use devm_kzalloc() to allocate the data struct. It is always free-ed as the last step of probe-error-exit or remove, so it can be devm-managed. This will make unwinding things easier when support is added to the gc0310 code to use standard GPIO APIs instead of the custom atomisp_gmin code. This also allows dropping the out_free label and use direct return on errors. This may seem like a functional change since the out_free label also did a v4l2_device_unregister_subdev() but at the 1 changed return the device is not registered yet, so that always is a no-op and can be dropped. Signed-off-by: Hans de Goede --- drivers/staging/media/atomisp/i2c/atomisp-gc0310.c | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/drivers/staging/media/atomisp/i2c/atomisp-gc0310.c b/drivers/staging/media/atomisp/i2c/atomisp-gc0310.c index 1224213d4195..5016e0b65af1 100644 --- a/drivers/staging/media/atomisp/i2c/atomisp-gc0310.c +++ b/drivers/staging/media/atomisp/i2c/atomisp-gc0310.c @@ -550,7 +550,7 @@ static int gc0310_probe(struct i2c_client *client) int ret; void *pdata; - dev = kzalloc(sizeof(*dev), GFP_KERNEL); + dev = devm_kzalloc(&client->dev, sizeof(*dev), GFP_KERNEL); if (!dev) return -ENOMEM; @@ -561,10 +561,8 @@ static int gc0310_probe(struct i2c_client *client) pdata = gmin_camera_platform_data(&dev->sd, ATOMISP_INPUT_FORMAT_RAW_8, atomisp_bayer_order_grbg); - if (!pdata) { - ret = -EINVAL; - goto out_free; - } + if (!pdata) + return -EINVAL; pm_runtime_set_suspended(&client->dev); pm_runtime_enable(&client->dev); @@ -598,10 +596,6 @@ static int gc0310_probe(struct i2c_client *client) gc0310_remove(client); return ret; -out_free: - v4l2_device_unregister_subdev(&dev->sd); - kfree(dev); - return ret; } static int gc0310_suspend(struct device *dev) From patchwork Sat Apr 1 14:59:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 13197040 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CD2F1C76196 for ; Sat, 1 Apr 2023 15:01:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230095AbjDAPBW (ORCPT ); Sat, 1 Apr 2023 11:01:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37924 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229626AbjDAPBU (ORCPT ); Sat, 1 Apr 2023 11:01:20 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C39241EA20 for ; Sat, 1 Apr 2023 08:00:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1680361213; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=BqJKkLsXsmCFZRxGHR6LcIOaTsfjdyIt7f7GnhSFl+c=; b=PgngNECUyfStkZBLicpikpH8ub4hK2QbVba6J9yrs6fAnuSBE1/BJJ4hx0UzepX7FMIrLU AmZd2Jfyopgqd6NlM9FinIPUPS16MLOYrk95DLhBdEj0nifKJcgkaiennT2/JMtdl3jAer 4gWb2PbW9bcgW3R8CPwJJIIVBhir8co= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-62-phDG4cvGMUKg5_T6Tl2CLg-1; Sat, 01 Apr 2023 11:00:08 -0400 X-MC-Unique: phDG4cvGMUKg5_T6Tl2CLg-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 2942D101A550; Sat, 1 Apr 2023 15:00:08 +0000 (UTC) Received: from localhost.localdomain (unknown [10.39.192.49]) by smtp.corp.redhat.com (Postfix) with ESMTP id 99E26400F59; Sat, 1 Apr 2023 15:00:06 +0000 (UTC) From: Hans de Goede To: Mauro Carvalho Chehab , Sakari Ailus Cc: Hans de Goede , Kate Hsuan , Tsuchiya Yuto , Andy Shevchenko , Yury Luneff , Nable , andrey.i.trufanov@gmail.com, Fabio Aiuto , linux-media@vger.kernel.org, linux-staging@lists.linux.dev Subject: [PATCH 18/28] media: atomisp: gc0310: Switch over to ACPI powermanagement Date: Sat, 1 Apr 2023 16:59:16 +0200 Message-Id: <20230401145926.596216-19-hdegoede@redhat.com> In-Reply-To: <20230401145926.596216-1-hdegoede@redhat.com> References: <20230401145926.596216-1-hdegoede@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org The DSDT of all Windows BYT / CHT devices which I have seen has proper ACPI powermagement for the clk and regulators used by the sensors. So there is no need for the whole custom atomisp_gmin custom code to disable the ACPI pm and directly poke at the PMIC for this. Replace all the atomisp_gmin usage with using the new atomisp_register_sensor_no_gmin() / atomisp_unregister_subdev() helpers which allow registering a sensor with the atomisp code without using any of the atomisp_gmin power-management code. Note eventually these calls should be replaced by the standard v4l2_async_register_subdev_sensor() mechanism. But this first requires a bunch of work to the atomisp main code to make it set the necessary fwnodes up, similar to how drivers/media/pci/intel/ipu3/cio2-bridge.c does this. Signed-off-by: Hans de Goede --- .../media/atomisp/i2c/atomisp-gc0310.c | 234 ++++-------------- drivers/staging/media/atomisp/i2c/gc0310.h | 5 +- 2 files changed, 50 insertions(+), 189 deletions(-) diff --git a/drivers/staging/media/atomisp/i2c/atomisp-gc0310.c b/drivers/staging/media/atomisp/i2c/atomisp-gc0310.c index 5016e0b65af1..a134ef24ba8b 100644 --- a/drivers/staging/media/atomisp/i2c/atomisp-gc0310.c +++ b/drivers/staging/media/atomisp/i2c/atomisp-gc0310.c @@ -3,6 +3,7 @@ * Support for GalaxyCore GC0310 VGA camera sensor. * * Copyright (c) 2013 Intel Corporation. All Rights Reserved. + * Copyright (c) 2023 Hans de Goede * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License version @@ -26,6 +27,8 @@ #include #include #include +#include +#include #include #include #include @@ -125,136 +128,6 @@ static const struct v4l2_ctrl_ops ctrl_ops = { .s_ctrl = gc0310_s_ctrl, }; -static int power_ctrl(struct v4l2_subdev *sd, bool flag) -{ - int ret = 0; - struct gc0310_device *dev = to_gc0310_sensor(sd); - - if (!dev || !dev->platform_data) - return -ENODEV; - - if (flag) { - /* The upstream module driver (written to Crystal - * Cove) had this logic to pulse the rails low first. - * This appears to break things on the MRD7 with the - * X-Powers PMIC... - * - * ret = dev->platform_data->v1p8_ctrl(sd, 0); - * ret |= dev->platform_data->v2p8_ctrl(sd, 0); - * mdelay(50); - */ - ret |= dev->platform_data->v1p8_ctrl(sd, 1); - ret |= dev->platform_data->v2p8_ctrl(sd, 1); - usleep_range(10000, 15000); - } - - if (!flag || ret) { - ret |= dev->platform_data->v1p8_ctrl(sd, 0); - ret |= dev->platform_data->v2p8_ctrl(sd, 0); - } - return ret; -} - -static int gpio_ctrl(struct v4l2_subdev *sd, bool flag) -{ - int ret; - struct gc0310_device *dev = to_gc0310_sensor(sd); - - if (!dev || !dev->platform_data) - return -ENODEV; - - /* GPIO0 == "reset" (active low), GPIO1 == "power down" */ - if (flag) { - /* Pulse reset, then release power down */ - ret = dev->platform_data->gpio0_ctrl(sd, 0); - usleep_range(5000, 10000); - ret |= dev->platform_data->gpio0_ctrl(sd, 1); - usleep_range(10000, 15000); - ret |= dev->platform_data->gpio1_ctrl(sd, 0); - usleep_range(10000, 15000); - } else { - ret = dev->platform_data->gpio1_ctrl(sd, 1); - ret |= dev->platform_data->gpio0_ctrl(sd, 0); - } - return ret; -} - -static int power_up(struct v4l2_subdev *sd) -{ - struct gc0310_device *dev = to_gc0310_sensor(sd); - struct i2c_client *client = v4l2_get_subdevdata(sd); - int ret; - - if (!dev->platform_data) { - dev_err(&client->dev, - "no camera_sensor_platform_data"); - return -ENODEV; - } - - /* power control */ - ret = power_ctrl(sd, 1); - if (ret) - goto fail_power; - - /* flis clock control */ - ret = dev->platform_data->flisclk_ctrl(sd, 1); - if (ret) - goto fail_clk; - - /* gpio ctrl */ - ret = gpio_ctrl(sd, 1); - if (ret) { - ret = gpio_ctrl(sd, 1); - if (ret) - goto fail_gpio; - } - - msleep(100); - - return 0; - -fail_gpio: - dev->platform_data->flisclk_ctrl(sd, 0); -fail_clk: - power_ctrl(sd, 0); -fail_power: - dev_err(&client->dev, "sensor power-up failed\n"); - - return ret; -} - -static int power_down(struct v4l2_subdev *sd) -{ - struct gc0310_device *dev = to_gc0310_sensor(sd); - struct i2c_client *client = v4l2_get_subdevdata(sd); - int ret = 0; - - if (!dev->platform_data) { - dev_err(&client->dev, - "no camera_sensor_platform_data"); - return -ENODEV; - } - - /* gpio ctrl */ - ret = gpio_ctrl(sd, 0); - if (ret) { - ret = gpio_ctrl(sd, 0); - if (ret) - dev_err(&client->dev, "gpio failed 2\n"); - } - - ret = dev->platform_data->flisclk_ctrl(sd, 0); - if (ret) - dev_err(&client->dev, "flisclk failed\n"); - - /* power control */ - ret = power_ctrl(sd, 0); - if (ret) - dev_err(&client->dev, "vprog failed.\n"); - - return ret; -} - static struct v4l2_mbus_framefmt * gc0310_get_pad_format(struct gc0310_device *dev, struct v4l2_subdev_state *state, @@ -348,6 +221,8 @@ static int gc0310_s_stream(struct v4l2_subdev *sd, int enable) if (ret < 0) goto error_power_down; + msleep(100); + ret = gc0310_write_reg_array(client, gc0310_reset_register, ARRAY_SIZE(gc0310_reset_register)); if (ret) @@ -397,49 +272,16 @@ static int gc0310_s_stream(struct v4l2_subdev *sd, int enable) return ret; } -static int gc0310_s_config(struct v4l2_subdev *sd, - int irq, void *platform_data) +static int gc0310_s_config(struct v4l2_subdev *sd) { - struct gc0310_device *dev = to_gc0310_sensor(sd); struct i2c_client *client = v4l2_get_subdevdata(sd); - int ret = 0; - - if (!platform_data) - return -ENODEV; - - dev->platform_data = - (struct camera_sensor_platform_data *)platform_data; - - mutex_lock(&dev->input_lock); + int ret; ret = pm_runtime_get_sync(&client->dev); - if (ret < 0) { - dev_err(&client->dev, "gc0310 power-up err.\n"); - goto fail_power_on; - } - - ret = dev->platform_data->csi_cfg(sd, 1); - if (ret) - goto fail_csi_cfg; - - /* config & detect sensor */ - ret = gc0310_detect(client); - if (ret) { - dev_err(&client->dev, "gc0310_detect err s_config.\n"); - goto fail_csi_cfg; - } - - /* turn off sensor, after probed */ - pm_runtime_put(&client->dev); - mutex_unlock(&dev->input_lock); - - return 0; + if (ret >= 0) + ret = gc0310_detect(client); -fail_csi_cfg: - dev->platform_data->csi_cfg(sd, 0); -fail_power_on: pm_runtime_put(&client->dev); - mutex_unlock(&dev->input_lock); return ret; } @@ -535,8 +377,7 @@ static void gc0310_remove(struct i2c_client *client) dev_dbg(&client->dev, "gc0310_remove...\n"); - dev->platform_data->csi_cfg(sd, 0); - + atomisp_unregister_subdev(sd); v4l2_device_unregister_subdev(sd); media_entity_cleanup(&dev->sd.entity); v4l2_ctrl_handler_free(&dev->ctrls.handler); @@ -548,34 +389,35 @@ static int gc0310_probe(struct i2c_client *client) { struct gc0310_device *dev; int ret; - void *pdata; dev = devm_kzalloc(&client->dev, sizeof(*dev), GFP_KERNEL); if (!dev) return -ENOMEM; + ret = v4l2_get_acpi_sensor_info(&client->dev, NULL); + if (ret) + return ret; + + dev->reset = devm_gpiod_get(&client->dev, "reset", GPIOD_OUT_HIGH); + if (IS_ERR(dev->reset)) + return dev_err_probe(&client->dev, PTR_ERR(dev->reset), + "getting reset GPIO\n"); + + dev->powerdown = devm_gpiod_get(&client->dev, "powerdown", GPIOD_OUT_HIGH); + if (IS_ERR(dev->powerdown)) + return dev_err_probe(&client->dev, PTR_ERR(dev->powerdown), + "getting powerdown GPIO\n"); + mutex_init(&dev->input_lock); v4l2_i2c_subdev_init(&dev->sd, client, &gc0310_ops); gc0310_fill_format(&dev->mode.fmt); - pdata = gmin_camera_platform_data(&dev->sd, - ATOMISP_INPUT_FORMAT_RAW_8, - atomisp_bayer_order_grbg); - if (!pdata) - return -EINVAL; - pm_runtime_set_suspended(&client->dev); pm_runtime_enable(&client->dev); pm_runtime_set_autosuspend_delay(&client->dev, 1000); pm_runtime_use_autosuspend(&client->dev); - ret = gc0310_s_config(&dev->sd, client->irq, pdata); - if (ret) { - gc0310_remove(client); - return ret; - } - - ret = atomisp_register_i2c_module(&dev->sd, pdata, RAW_CAMERA); + ret = gc0310_s_config(&dev->sd); if (ret) { gc0310_remove(client); return ret; @@ -592,24 +434,42 @@ static int gc0310_probe(struct i2c_client *client) } ret = media_entity_pads_init(&dev->sd.entity, 1, &dev->pad); - if (ret) + if (ret) { gc0310_remove(client); + return ret; + } - return ret; + ret = atomisp_register_sensor_no_gmin(&dev->sd, 1, ATOMISP_INPUT_FORMAT_RAW_8, + atomisp_bayer_order_grbg); + if (ret) { + gc0310_remove(client); + return ret; + } + + return 0; } static int gc0310_suspend(struct device *dev) { struct v4l2_subdev *sd = dev_get_drvdata(dev); + struct gc0310_device *gc0310_dev = to_gc0310_sensor(sd); - return power_down(sd); + gpiod_set_value_cansleep(gc0310_dev->powerdown, 1); + gpiod_set_value_cansleep(gc0310_dev->reset, 1); + return 0; } static int gc0310_resume(struct device *dev) { struct v4l2_subdev *sd = dev_get_drvdata(dev); + struct gc0310_device *gc0310_dev = to_gc0310_sensor(sd); + + usleep_range(10000, 15000); + gpiod_set_value_cansleep(gc0310_dev->reset, 0); + usleep_range(10000, 15000); + gpiod_set_value_cansleep(gc0310_dev->powerdown, 0); - return power_up(sd); + return 0; } static DEFINE_RUNTIME_DEV_PM_OPS(gc0310_pm_ops, gc0310_suspend, gc0310_resume, NULL); diff --git a/drivers/staging/media/atomisp/i2c/gc0310.h b/drivers/staging/media/atomisp/i2c/gc0310.h index 485a060b40ff..d40406289598 100644 --- a/drivers/staging/media/atomisp/i2c/gc0310.h +++ b/drivers/staging/media/atomisp/i2c/gc0310.h @@ -92,10 +92,11 @@ struct gc0310_device { struct v4l2_subdev sd; struct media_pad pad; struct mutex input_lock; - - struct camera_sensor_platform_data *platform_data; bool is_streaming; + struct gpio_desc *reset; + struct gpio_desc *powerdown; + struct gc0310_mode { struct v4l2_mbus_framefmt fmt; } mode; From patchwork Sat Apr 1 14:59:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 13197043 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CE9C7C76196 for ; Sat, 1 Apr 2023 15:01:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230123AbjDAPBb (ORCPT ); Sat, 1 Apr 2023 11:01:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37600 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230122AbjDAPB3 (ORCPT ); Sat, 1 Apr 2023 11:01:29 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B54401EA23 for ; Sat, 1 Apr 2023 08:00:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1680361213; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=p4MzD35r/RrS1TyR4VnXqVtk+MtgwA7BTD4xECWDmHs=; b=agbl7zSDs71k/cOE6tbD9heR3m1+/ZwoXsrsgF0s6BnCY2E6pd25D2tUebJyzThq4Pst9q /oBI1aRWdlVoIcycTjob7JHTSaigI1pNIz+rLpCL/SqcFo9SMMhQFJfWIMQlmrn0dwfCc4 vBHO09nDUc+hsE/S2dvbDv0WaUWSRPo= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-76-Onn9KD1PMPet-rgbVSP1UA-1; Sat, 01 Apr 2023 11:00:10 -0400 X-MC-Unique: Onn9KD1PMPet-rgbVSP1UA-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id DE3D53815F61; Sat, 1 Apr 2023 15:00:09 +0000 (UTC) Received: from localhost.localdomain (unknown [10.39.192.49]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5E055400F59; Sat, 1 Apr 2023 15:00:08 +0000 (UTC) From: Hans de Goede To: Mauro Carvalho Chehab , Sakari Ailus Cc: Hans de Goede , Kate Hsuan , Tsuchiya Yuto , Andy Shevchenko , Yury Luneff , Nable , andrey.i.trufanov@gmail.com, Fabio Aiuto , linux-media@vger.kernel.org, linux-staging@lists.linux.dev Subject: [PATCH 19/28] media: atomisp: Remove duplicate atomisp_[start|stop]_streaming prototypes Date: Sat, 1 Apr 2023 16:59:17 +0200 Message-Id: <20230401145926.596216-20-hdegoede@redhat.com> In-Reply-To: <20230401145926.596216-1-hdegoede@redhat.com> References: <20230401145926.596216-1-hdegoede@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org atomisp_ioctl.h contains the atomisp_[start|stop]_streaming function prototypes 2 times. Drop one of the copies of the prototypes. Signed-off-by: Hans de Goede --- drivers/staging/media/atomisp/pci/atomisp_ioctl.h | 3 --- 1 file changed, 3 deletions(-) diff --git a/drivers/staging/media/atomisp/pci/atomisp_ioctl.h b/drivers/staging/media/atomisp/pci/atomisp_ioctl.h index 93139decf1d0..db6da77df06b 100644 --- a/drivers/staging/media/atomisp/pci/atomisp_ioctl.h +++ b/drivers/staging/media/atomisp/pci/atomisp_ioctl.h @@ -53,7 +53,4 @@ unsigned int atomisp_streaming_count(struct atomisp_device *isp); long atomisp_compat_ioctl32(struct file *file, unsigned int cmd, unsigned long arg); -int atomisp_start_streaming(struct vb2_queue *vq, unsigned int count); -void atomisp_stop_streaming(struct vb2_queue *vq); - #endif /* __ATOMISP_IOCTL_H__ */ From patchwork Sat Apr 1 14:59:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 13197041 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3263AC6FD1D for ; Sat, 1 Apr 2023 15:01:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230121AbjDAPB3 (ORCPT ); Sat, 1 Apr 2023 11:01:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37926 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229626AbjDAPB2 (ORCPT ); Sat, 1 Apr 2023 11:01:28 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 24F861E700 for ; Sat, 1 Apr 2023 08:00:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1680361219; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=mXSlI2J0Wu8gEb1g90iCOsfdjTIyDYzLT+DsHVPH8aE=; b=GwD5p6rbnU5OapZzwv6jYnt/+wI3DT9wsF8OJtTtmZbG4OR9Af5O8NlgTM1pjUp/d3rLW4 BJfxxUS7Y8xkY/sAmllnp8nFW6Tre3vHjttjMtkE/02G5NhNglPs1SZlIpsaSQ1LsL/mgC dSE826ekWctwXQh7iwuUKFGmaQEvQgc= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-258-_-l13NJvPgKgkN3EQLdb-Q-1; Sat, 01 Apr 2023 11:00:14 -0400 X-MC-Unique: _-l13NJvPgKgkN3EQLdb-Q-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id B7B72801779; Sat, 1 Apr 2023 15:00:13 +0000 (UTC) Received: from localhost.localdomain (unknown [10.39.192.49]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1D672400F59; Sat, 1 Apr 2023 15:00:10 +0000 (UTC) From: Hans de Goede To: Mauro Carvalho Chehab , Sakari Ailus Cc: Hans de Goede , Kate Hsuan , Tsuchiya Yuto , Andy Shevchenko , Yury Luneff , Nable , andrey.i.trufanov@gmail.com, Fabio Aiuto , linux-media@vger.kernel.org, linux-staging@lists.linux.dev Subject: [PATCH 20/28] media: atomisp: Remove continuous mode related code from atomisp_set_fmt() Date: Sat, 1 Apr 2023 16:59:18 +0200 Message-Id: <20230401145926.596216-21-hdegoede@redhat.com> In-Reply-To: <20230401145926.596216-1-hdegoede@redhat.com> References: <20230401145926.596216-1-hdegoede@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org Remove code to check / adjust code between video and preview / capture and view-finder nodes now that we no longer support continuous mode and this no longer support streaming from 2 /dev/video# nodes at the same time. Signed-off-by: Hans de Goede --- .../staging/media/atomisp/pci/atomisp_cmd.c | 84 +------------------ 1 file changed, 1 insertion(+), 83 deletions(-) diff --git a/drivers/staging/media/atomisp/pci/atomisp_cmd.c b/drivers/staging/media/atomisp/pci/atomisp_cmd.c index 65d46bae8ee8..9cf5ac55b867 100644 --- a/drivers/staging/media/atomisp/pci/atomisp_cmd.c +++ b/drivers/staging/media/atomisp/pci/atomisp_cmd.c @@ -4633,88 +4633,6 @@ int atomisp_set_fmt(struct video_device *vdev, struct v4l2_format *f) snr_fmt = f->fmt.pix; backup_fmt = snr_fmt; - /**********************************************************************/ - - if (source_pad == ATOMISP_SUBDEV_PAD_SOURCE_VF || - (source_pad == ATOMISP_SUBDEV_PAD_SOURCE_PREVIEW - && asd->run_mode->val == ATOMISP_RUN_MODE_VIDEO)) { - if (asd->fmt_auto->val) { - struct v4l2_rect *capture_comp; - struct v4l2_rect r = {0}; - - r.width = f->fmt.pix.width; - r.height = f->fmt.pix.height; - - if (source_pad == ATOMISP_SUBDEV_PAD_SOURCE_PREVIEW) - capture_comp = atomisp_subdev_get_rect( - &asd->subdev, NULL, - V4L2_SUBDEV_FORMAT_ACTIVE, - ATOMISP_SUBDEV_PAD_SOURCE_VIDEO, - V4L2_SEL_TGT_COMPOSE); - else - capture_comp = atomisp_subdev_get_rect( - &asd->subdev, NULL, - V4L2_SUBDEV_FORMAT_ACTIVE, - ATOMISP_SUBDEV_PAD_SOURCE_CAPTURE, - V4L2_SEL_TGT_COMPOSE); - - if (capture_comp->width < r.width - || capture_comp->height < r.height) { - r.width = capture_comp->width; - r.height = capture_comp->height; - } - - atomisp_subdev_set_selection( - &asd->subdev, fh.state, - V4L2_SUBDEV_FORMAT_ACTIVE, source_pad, - V4L2_SEL_TGT_COMPOSE, 0, &r); - - f->fmt.pix.width = r.width; - f->fmt.pix.height = r.height; - } - - if (source_pad == ATOMISP_SUBDEV_PAD_SOURCE_PREVIEW) { - atomisp_css_video_configure_viewfinder(asd, - f->fmt.pix.width, f->fmt.pix.height, - format_bridge->planar ? f->fmt.pix.bytesperline - : f->fmt.pix.bytesperline * 8 - / format_bridge->depth, format_bridge->sh_fmt); - atomisp_css_video_get_viewfinder_frame_info(asd, - &output_info); - asd->copy_mode = false; - } else { - atomisp_css_capture_configure_viewfinder(asd, - f->fmt.pix.width, f->fmt.pix.height, - format_bridge->planar ? f->fmt.pix.bytesperline - : f->fmt.pix.bytesperline * 8 - / format_bridge->depth, format_bridge->sh_fmt); - atomisp_css_capture_get_viewfinder_frame_info(asd, - &output_info); - asd->copy_mode = false; - } - - goto done; - } - /* - * Check whether main resolution configured smaller - * than snapshot resolution. If so, force main resolution - * to be the same as snapshot resolution - */ - if (source_pad == ATOMISP_SUBDEV_PAD_SOURCE_CAPTURE) { - struct v4l2_rect *r; - - r = atomisp_subdev_get_rect( - &asd->subdev, NULL, - V4L2_SUBDEV_FORMAT_ACTIVE, - ATOMISP_SUBDEV_PAD_SOURCE_VF, V4L2_SEL_TGT_COMPOSE); - - if (r->width && r->height - && (r->width > f->fmt.pix.width - || r->height > f->fmt.pix.height)) - dev_warn(isp->dev, - "Main Resolution config smaller then Vf Resolution. Force to be equal with Vf Resolution."); - } - /* Pipeline configuration done through subdevs. Bail out now. */ if (!asd->fmt_auto->val) goto set_fmt_to_isp; @@ -4885,7 +4803,7 @@ int atomisp_set_fmt(struct video_device *vdev, struct v4l2_format *f) dev_warn(isp->dev, "Can't set format on ISP. Error %d\n", ret); return -EINVAL; } -done: + pipe->pix.width = f->fmt.pix.width; pipe->pix.height = f->fmt.pix.height; pipe->pix.pixelformat = f->fmt.pix.pixelformat; From patchwork Sat Apr 1 14:59:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 13197044 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6AD8CC6FD1D for ; Sat, 1 Apr 2023 15:01:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230142AbjDAPBd (ORCPT ); Sat, 1 Apr 2023 11:01:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37576 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230122AbjDAPBb (ORCPT ); Sat, 1 Apr 2023 11:01:31 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 20B551EA2A for ; Sat, 1 Apr 2023 08:00:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1680361220; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=C+k2Efp8d+jIakXKRtUBgc1U//gkR8koQpCncuHXyvE=; b=VHA9ggKt5azhyVS9yOoicnhITMUM2h0NPYHnsbPR+j1o5Zg2Pa0VNl1PZmQ55/NjzGZr+7 Qnrr2n4wp3CIyGBI259a0gTs5ffogpJVZ1aUdOdCfLOxRcFjNH+YRytHy3FdGqEkTkxmQF abkeChiOXMjP7fioXrUQRGcM+OreugU= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-616--EH5SOEWP6WtXhSVCiwQ7w-1; Sat, 01 Apr 2023 11:00:17 -0400 X-MC-Unique: -EH5SOEWP6WtXhSVCiwQ7w-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 9386F1C051AA; Sat, 1 Apr 2023 15:00:16 +0000 (UTC) Received: from localhost.localdomain (unknown [10.39.192.49]) by smtp.corp.redhat.com (Postfix) with ESMTP id EB570400F59; Sat, 1 Apr 2023 15:00:13 +0000 (UTC) From: Hans de Goede To: Mauro Carvalho Chehab , Sakari Ailus Cc: Hans de Goede , Kate Hsuan , Tsuchiya Yuto , Andy Shevchenko , Yury Luneff , Nable , andrey.i.trufanov@gmail.com, Fabio Aiuto , linux-media@vger.kernel.org, linux-staging@lists.linux.dev Subject: [PATCH 21/28] media: atomisp: Remove custom V4L2_CID_FMT_AUTO control Date: Sat, 1 Apr 2023 16:59:19 +0200 Message-Id: <20230401145926.596216-22-hdegoede@redhat.com> In-Reply-To: <20230401145926.596216-1-hdegoede@redhat.com> References: <20230401145926.596216-1-hdegoede@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org The custom V4L2_CID_FMT_AUTO control, which defaults to true controls whether the atomisp driver will automatically configure the sensor and ISP settings to match. This is necessary to make normal v4l2 apps to work. We do eventually want to add libcamera support, but even then moving this to userspace does not give any added value, while breaking classic v4l2 apps. Moreover we really don't know all the exact pipeline constraints, so moving this to userspace/libcamera will be tricky thus it is best to keep the current in kernel code for this and make the kernel unconditionally do this. Signed-off-by: Hans de Goede --- .../staging/media/atomisp/include/linux/atomisp.h | 2 -- drivers/staging/media/atomisp/pci/atomisp_cmd.c | 8 +------- drivers/staging/media/atomisp/pci/atomisp_fops.c | 2 +- drivers/staging/media/atomisp/pci/atomisp_subdev.c | 13 ------------- drivers/staging/media/atomisp/pci/atomisp_subdev.h | 1 - 5 files changed, 2 insertions(+), 24 deletions(-) diff --git a/drivers/staging/media/atomisp/include/linux/atomisp.h b/drivers/staging/media/atomisp/include/linux/atomisp.h index b3cceea570ca..c7ec56a1c064 100644 --- a/drivers/staging/media/atomisp/include/linux/atomisp.h +++ b/drivers/staging/media/atomisp/include/linux/atomisp.h @@ -1056,8 +1056,6 @@ struct atomisp_sensor_ae_bracketing_lut { #define V4L2_2A_STATUS_AE_READY BIT(0) #define V4L2_2A_STATUS_AWB_READY BIT(1) -#define V4L2_CID_FMT_AUTO (V4L2_CID_CAMERA_LASTP1 + 19) - #define V4L2_CID_RUN_MODE (V4L2_CID_CAMERA_LASTP1 + 20) #define ATOMISP_RUN_MODE_VIDEO 1 #define ATOMISP_RUN_MODE_STILL_CAPTURE 2 diff --git a/drivers/staging/media/atomisp/pci/atomisp_cmd.c b/drivers/staging/media/atomisp/pci/atomisp_cmd.c index 9cf5ac55b867..c73931c77695 100644 --- a/drivers/staging/media/atomisp/pci/atomisp_cmd.c +++ b/drivers/staging/media/atomisp/pci/atomisp_cmd.c @@ -4283,8 +4283,7 @@ static int atomisp_set_fmt_to_isp(struct video_device *vdev, * Configure viewfinder also when vfpp is disabled: the * CSS still requires viewfinder configuration. */ - if (asd->fmt_auto->val || - asd->vfpp->val != ATOMISP_VFPP_ENABLE) { + { struct v4l2_rect vf_size = {0}; struct v4l2_mbus_framefmt vf_ffmt = {0}; @@ -4633,10 +4632,6 @@ int atomisp_set_fmt(struct video_device *vdev, struct v4l2_format *f) snr_fmt = f->fmt.pix; backup_fmt = snr_fmt; - /* Pipeline configuration done through subdevs. Bail out now. */ - if (!asd->fmt_auto->val) - goto set_fmt_to_isp; - /* get sensor resolution and format */ ret = atomisp_try_fmt(vdev, &snr_fmt, &res_overflow); if (ret) { @@ -4797,7 +4792,6 @@ int atomisp_set_fmt(struct video_device *vdev, struct v4l2_format *f) &main_compose); } -set_fmt_to_isp: ret = atomisp_set_fmt_to_isp(vdev, &output_info, &f->fmt.pix, source_pad); if (ret) { dev_warn(isp->dev, "Can't set format on ISP. Error %d\n", ret); diff --git a/drivers/staging/media/atomisp/pci/atomisp_fops.c b/drivers/staging/media/atomisp/pci/atomisp_fops.c index 7f757f510190..e220f500aff4 100644 --- a/drivers/staging/media/atomisp/pci/atomisp_fops.c +++ b/drivers/staging/media/atomisp/pci/atomisp_fops.c @@ -711,7 +711,7 @@ static int atomisp_release(struct file *file) * The sink pad setting can only be cleared when all device nodes * get released. */ - if (asd->fmt_auto->val) { + { struct v4l2_mbus_framefmt isp_sink_fmt = { 0 }; atomisp_subdev_set_ffmt(&asd->subdev, fh.state, diff --git a/drivers/staging/media/atomisp/pci/atomisp_subdev.c b/drivers/staging/media/atomisp/pci/atomisp_subdev.c index 371991883076..011e67ccdbba 100644 --- a/drivers/staging/media/atomisp/pci/atomisp_subdev.c +++ b/drivers/staging/media/atomisp/pci/atomisp_subdev.c @@ -754,17 +754,6 @@ static const struct v4l2_ctrl_ops ctrl_ops = { .s_ctrl = &s_ctrl, }; -static const struct v4l2_ctrl_config ctrl_fmt_auto = { - .ops = &ctrl_ops, - .id = V4L2_CID_FMT_AUTO, - .name = "Automatic format guessing", - .type = V4L2_CTRL_TYPE_BOOLEAN, - .min = 0, - .max = 1, - .step = 1, - .def = 1, -}; - static const char *const ctrl_run_mode_menu[] = { NULL, "Video", @@ -1000,8 +989,6 @@ static int isp_subdev_init_entities(struct atomisp_sub_device *asd) if (ret) return ret; - asd->fmt_auto = v4l2_ctrl_new_custom(&asd->ctrl_handler, - &ctrl_fmt_auto, NULL); asd->run_mode = v4l2_ctrl_new_custom(&asd->ctrl_handler, &ctrl_run_mode, NULL); asd->vfpp = v4l2_ctrl_new_custom(&asd->ctrl_handler, diff --git a/drivers/staging/media/atomisp/pci/atomisp_subdev.h b/drivers/staging/media/atomisp/pci/atomisp_subdev.h index bcb0fe8d0538..117803f3cbd1 100644 --- a/drivers/staging/media/atomisp/pci/atomisp_subdev.h +++ b/drivers/staging/media/atomisp/pci/atomisp_subdev.h @@ -259,7 +259,6 @@ struct atomisp_sub_device { /* struct isp_subdev_params params; */ struct atomisp_device *isp; struct v4l2_ctrl_handler ctrl_handler; - struct v4l2_ctrl *fmt_auto; struct v4l2_ctrl *run_mode; struct v4l2_ctrl *vfpp; struct v4l2_ctrl *continuous_raw_buffer_size; From patchwork Sat Apr 1 14:59:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 13197042 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 40E54C761AF for ; Sat, 1 Apr 2023 15:01:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230129AbjDAPBa (ORCPT ); Sat, 1 Apr 2023 11:01:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37634 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230119AbjDAPB2 (ORCPT ); Sat, 1 Apr 2023 11:01:28 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B0DDD1EA39 for ; Sat, 1 Apr 2023 08:00:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1680361222; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=NqV9490Mg4OeN8EDJ/97R+nPQu2ujG6puyFSMc5iU4Y=; b=bDhRveSoyNScmkOGMmSDTPtYwlF//9/t71nLU3xSEQkeph8HWfN5Qhe/SuFbspMatCLzd5 98sJNo3Q14hiO/UDinhgV0o13deC7yh8KPNFnZ3FWDlrhdXDSUP9XGnxt4I8sfljrCvPdk 9OQedkwkXBAX1OjT+uHRshLjzkmXAL4= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-675-qD4g6UROOSKE8ZRlbXlKPw-1; Sat, 01 Apr 2023 11:00:19 -0400 X-MC-Unique: qD4g6UROOSKE8ZRlbXlKPw-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 55DBD2A59560; Sat, 1 Apr 2023 15:00:18 +0000 (UTC) Received: from localhost.localdomain (unknown [10.39.192.49]) by smtp.corp.redhat.com (Postfix) with ESMTP id C6CA64021C7; Sat, 1 Apr 2023 15:00:16 +0000 (UTC) From: Hans de Goede To: Mauro Carvalho Chehab , Sakari Ailus Cc: Hans de Goede , Kate Hsuan , Tsuchiya Yuto , Andy Shevchenko , Yury Luneff , Nable , andrey.i.trufanov@gmail.com, Fabio Aiuto , linux-media@vger.kernel.org, linux-staging@lists.linux.dev Subject: [PATCH 22/28] media: atomisp: Remove snr_mbus_fmt local var from atomisp_try_fmt() Date: Sat, 1 Apr 2023 16:59:20 +0200 Message-Id: <20230401145926.596216-23-hdegoede@redhat.com> In-Reply-To: <20230401145926.596216-1-hdegoede@redhat.com> References: <20230401145926.596216-1-hdegoede@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org snr_mbus_fmt is a local variable pointing to a substruct of another local variable which really just makes the code harder to read / follow, so drop it. And likewise also drop the stream_info local variable. Signed-off-by: Hans de Goede --- .../staging/media/atomisp/pci/atomisp_cmd.c | 33 +++++++++---------- 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/drivers/staging/media/atomisp/pci/atomisp_cmd.c b/drivers/staging/media/atomisp/pci/atomisp_cmd.c index c73931c77695..0fca4bc605ec 100644 --- a/drivers/staging/media/atomisp/pci/atomisp_cmd.c +++ b/drivers/staging/media/atomisp/pci/atomisp_cmd.c @@ -3970,11 +3970,7 @@ int atomisp_try_fmt(struct video_device *vdev, struct v4l2_pix_format *f, struct v4l2_subdev_format format = { .which = V4L2_SUBDEV_FORMAT_TRY, }; - - struct v4l2_mbus_framefmt *snr_mbus_fmt = &format.format; const struct atomisp_format_bridge *fmt; - struct atomisp_input_stream_info *stream_info = - (struct atomisp_input_stream_info *)snr_mbus_fmt->reserved; int ret; if (!asd) { @@ -3995,14 +3991,15 @@ int atomisp_try_fmt(struct video_device *vdev, struct v4l2_pix_format *f, if (f->width <= 0 || f->height <= 0) return -EINVAL; - snr_mbus_fmt->code = fmt->mbus_code; - snr_mbus_fmt->width = f->width; - snr_mbus_fmt->height = f->height; + format.format.code = fmt->mbus_code; + format.format.width = f->width; + format.format.height = f->height; - __atomisp_init_stream_info(ATOMISP_INPUT_STREAM_GENERAL, stream_info); + __atomisp_init_stream_info(ATOMISP_INPUT_STREAM_GENERAL, + (struct atomisp_input_stream_info *)format.format.reserved); dev_dbg(isp->dev, "try_mbus_fmt: asking for %ux%u\n", - snr_mbus_fmt->width, snr_mbus_fmt->height); + format.format.width, format.format.height); ret = v4l2_subdev_call(isp->inputs[asd->input_curr].camera, pad, set_fmt, &pad_state, &format); @@ -4010,12 +4007,12 @@ int atomisp_try_fmt(struct video_device *vdev, struct v4l2_pix_format *f, return ret; dev_dbg(isp->dev, "try_mbus_fmt: got %ux%u\n", - snr_mbus_fmt->width, snr_mbus_fmt->height); + format.format.width, format.format.height); - fmt = atomisp_get_format_bridge_from_mbus(snr_mbus_fmt->code); + fmt = atomisp_get_format_bridge_from_mbus(format.format.code); if (!fmt) { dev_err(isp->dev, "unknown sensor format 0x%8.8x\n", - snr_mbus_fmt->code); + format.format.code); return -EINVAL; } @@ -4029,15 +4026,15 @@ int atomisp_try_fmt(struct video_device *vdev, struct v4l2_pix_format *f, */ if (f->pixelformat == V4L2_PIX_FMT_JPEG || f->pixelformat == V4L2_PIX_FMT_CUSTOM_M10MO_RAW) { - f->width = snr_mbus_fmt->width; - f->height = snr_mbus_fmt->height; + f->width = format.format.width; + f->height = format.format.height; return 0; } - if (!res_overflow || (snr_mbus_fmt->width < f->width && - snr_mbus_fmt->height < f->height)) { - f->width = snr_mbus_fmt->width; - f->height = snr_mbus_fmt->height; + if (!res_overflow || (format.format.width < f->width && + format.format.height < f->height)) { + f->width = format.format.width; + f->height = format.format.height; /* Set the flag when resolution requested is * beyond the max value supported by sensor */ From patchwork Sat Apr 1 14:59:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 13197049 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2D625C761AF for ; Sat, 1 Apr 2023 15:01:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230146AbjDAPBn (ORCPT ); Sat, 1 Apr 2023 11:01:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37968 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230140AbjDAPBc (ORCPT ); Sat, 1 Apr 2023 11:01:32 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BB44C1F7B2 for ; Sat, 1 Apr 2023 08:00:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1680361228; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=TezODqGRq70gjY6nlZ1O4bq0QDVSc71v9rjbdJs2K48=; b=fMrAP7K3gTQoqr8mcng8S5OlHhSA3JjHPRedHUdGb1F3aNkf2WE1QJuTGM2+sMhGtN/Oon X/wV1QXUJsvZfBftTJSFXum4/naF3+8EpyF7O0l+xtwtQeemjvXI8/wVsHnEZTC14/EhlL j/fQSPfCtOun32MGOqhWmwvL8LEqafE= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-554-fzpIHlJ3P8q1GbVLavFRng-1; Sat, 01 Apr 2023 11:00:21 -0400 X-MC-Unique: fzpIHlJ3P8q1GbVLavFRng-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id A4A0F101A531; Sat, 1 Apr 2023 15:00:20 +0000 (UTC) Received: from localhost.localdomain (unknown [10.39.192.49]) by smtp.corp.redhat.com (Postfix) with ESMTP id 88C59400F59; Sat, 1 Apr 2023 15:00:18 +0000 (UTC) From: Hans de Goede To: Mauro Carvalho Chehab , Sakari Ailus Cc: Hans de Goede , Kate Hsuan , Tsuchiya Yuto , Andy Shevchenko , Yury Luneff , Nable , andrey.i.trufanov@gmail.com, Fabio Aiuto , linux-media@vger.kernel.org, linux-staging@lists.linux.dev Subject: [PATCH 23/28] media: atomisp: Remove unused ATOM_ISP_MAX_WIDTH_TMP and ATOM_ISP_MAX_HEIGHT_TMP Date: Sat, 1 Apr 2023 16:59:21 +0200 Message-Id: <20230401145926.596216-24-hdegoede@redhat.com> In-Reply-To: <20230401145926.596216-1-hdegoede@redhat.com> References: <20230401145926.596216-1-hdegoede@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org Remove the unused ATOM_ISP_MAX_WIDTH_TMP and ATOM_ISP_MAX_HEIGHT_TMP defines. Signed-off-by: Hans de Goede --- drivers/staging/media/atomisp/pci/atomisp_internal.h | 3 --- 1 file changed, 3 deletions(-) diff --git a/drivers/staging/media/atomisp/pci/atomisp_internal.h b/drivers/staging/media/atomisp/pci/atomisp_internal.h index 681a9258288d..35293f2c196a 100644 --- a/drivers/staging/media/atomisp/pci/atomisp_internal.h +++ b/drivers/staging/media/atomisp/pci/atomisp_internal.h @@ -76,9 +76,6 @@ #define ATOM_RESOLUTION_SUBQCIF_WIDTH 128 #define ATOM_RESOLUTION_SUBQCIF_HEIGHT 96 -#define ATOM_ISP_MAX_WIDTH_TMP 1280 -#define ATOM_ISP_MAX_HEIGHT_TMP 720 - #define ATOM_ISP_I2C_BUS_1 4 #define ATOM_ISP_I2C_BUS_2 5 From patchwork Sat Apr 1 14:59:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 13197045 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id EB499C6FD1D for ; Sat, 1 Apr 2023 15:01:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230151AbjDAPBg (ORCPT ); Sat, 1 Apr 2023 11:01:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37964 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230128AbjDAPBb (ORCPT ); Sat, 1 Apr 2023 11:01:31 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3E12D1EFC4 for ; Sat, 1 Apr 2023 08:00:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1680361226; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=9p7Od3sAYEk1CgnqH+EkvcH2i880ldmpe7bHStWUwTg=; b=EL+U5R3kR+rN1zOlsYuSSCkCafNmBCqqtoyc0geRAtI2gjZmc4me9qYjVF4AakMY/PiywC gBGlaTmv1P1mj/o2ImAD2aih0uPNj+MggKDXWKgIUcFdsH0l5Y0OcApDy6XNiqTV9//9Xc WcC55QgDTBylyZ1jQvpWgdJMIORQSAY= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-564-w71TyjDdMSGVTs_yv5P6NA-1; Sat, 01 Apr 2023 11:00:23 -0400 X-MC-Unique: w71TyjDdMSGVTs_yv5P6NA-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 6989F101A531; Sat, 1 Apr 2023 15:00:22 +0000 (UTC) Received: from localhost.localdomain (unknown [10.39.192.49]) by smtp.corp.redhat.com (Postfix) with ESMTP id D7A4E400F59; Sat, 1 Apr 2023 15:00:20 +0000 (UTC) From: Hans de Goede To: Mauro Carvalho Chehab , Sakari Ailus Cc: Hans de Goede , Kate Hsuan , Tsuchiya Yuto , Andy Shevchenko , Yury Luneff , Nable , andrey.i.trufanov@gmail.com, Fabio Aiuto , linux-media@vger.kernel.org, linux-staging@lists.linux.dev Subject: [PATCH 24/28] media: atomisp: Remove atomisp_try_fmt() call from atomisp_set_fmt() Date: Sat, 1 Apr 2023 16:59:22 +0200 Message-Id: <20230401145926.596216-25-hdegoede@redhat.com> In-Reply-To: <20230401145926.596216-1-hdegoede@redhat.com> References: <20230401145926.596216-1-hdegoede@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org atomisp_set_fmt() first calls: v4l2_subdev_call(isp->inputs[asd->input_curr].camera, pad, set_fmt, ...); with v4l2_subdev_format.which set to V4L2_SUBDEV_FORMAT_ACTIVE and then reduces width + height by padding_w / padding_h followed by calling atomisp_try_fmt() which then sets res_overflow if the requested resolution is larger then the sensor's max resolution, but that will never happen since we are requesting for the result of a set_fmt call minus padding, so res_overflow will always be false. And when called with a res_overflow parameter, combined with there being no overflow then atomisp_try_fmt() does not change the passed in width/height. Except when using JPEG or CUSTOM_M10MO_RAW as pixelformat, then atomisp_try_fmt() does change the width/height but in that case atomisp_set_fmt actually restores the old widht/height which it has saved before the atomisp_try_fmt() call. So this too is a no-op. TL;DR: The atomisp_try_fmt() call in atomisp_set_fmt() is a no-op, remove it. Signed-off-by: Hans de Goede --- .../staging/media/atomisp/pci/atomisp_cmd.c | 56 ++----------------- 1 file changed, 6 insertions(+), 50 deletions(-) diff --git a/drivers/staging/media/atomisp/pci/atomisp_cmd.c b/drivers/staging/media/atomisp/pci/atomisp_cmd.c index 0fca4bc605ec..b5d094417fc5 100644 --- a/drivers/staging/media/atomisp/pci/atomisp_cmd.c +++ b/drivers/staging/media/atomisp/pci/atomisp_cmd.c @@ -4434,7 +4434,7 @@ static void atomisp_get_dis_envelop(struct atomisp_sub_device *asd, } static void atomisp_check_copy_mode(struct atomisp_sub_device *asd, - int source_pad, struct v4l2_pix_format *f) + int source_pad, const struct v4l2_pix_format *f) { struct v4l2_mbus_framefmt *sink, *src; @@ -4457,8 +4457,7 @@ static void atomisp_check_copy_mode(struct atomisp_sub_device *asd, dev_dbg(asd->isp->dev, "copy_mode: %d\n", asd->copy_mode); } -static int atomisp_set_fmt_to_snr(struct video_device *vdev, - struct v4l2_pix_format *f, unsigned int pixelformat, +static int atomisp_set_fmt_to_snr(struct video_device *vdev, const struct v4l2_pix_format *f, unsigned int padding_w, unsigned int padding_h, unsigned int dvs_env_w, unsigned int dvs_env_h) { @@ -4491,7 +4490,7 @@ static int atomisp_set_fmt_to_snr(struct video_device *vdev, v4l2_fh_init(&fh.vfh, vdev); - format = atomisp_get_format_bridge(pixelformat); + format = atomisp_get_format_bridge(f->pixelformat); if (!format) return -EINVAL; @@ -4567,8 +4566,6 @@ int atomisp_set_fmt(struct video_device *vdev, struct v4l2_format *f) const struct atomisp_format_bridge *format_bridge; const struct atomisp_format_bridge *snr_format_bridge; struct ia_css_frame_info output_info; - struct v4l2_pix_format snr_fmt; - struct v4l2_pix_format backup_fmt, s_fmt; unsigned int dvs_env_w = 0, dvs_env_h = 0; unsigned int padding_w = pad_w, padding_h = pad_h; struct v4l2_mbus_framefmt isp_source_fmt = {0}; @@ -4577,7 +4574,6 @@ int atomisp_set_fmt(struct video_device *vdev, struct v4l2_format *f) }; struct v4l2_rect isp_sink_crop; u16 source_pad = atomisp_subdev_source_pad(vdev); - bool res_overflow = false; struct v4l2_subdev_fh fh; int ret; @@ -4626,19 +4622,7 @@ int atomisp_set_fmt(struct video_device *vdev, struct v4l2_format *f) f->fmt.pix.width = vformat.format.width - padding_w; f->fmt.pix.height = vformat.format.height - padding_h; - snr_fmt = f->fmt.pix; - backup_fmt = snr_fmt; - - /* get sensor resolution and format */ - ret = atomisp_try_fmt(vdev, &snr_fmt, &res_overflow); - if (ret) { - dev_warn(isp->dev, "Try format failed with error %d\n", ret); - return ret; - } - f->fmt.pix.width = snr_fmt.width; - f->fmt.pix.height = snr_fmt.height; - - snr_format_bridge = atomisp_get_format_bridge(snr_fmt.pixelformat); + snr_format_bridge = atomisp_get_format_bridge_from_mbus(vformat.format.code); if (!snr_format_bridge) { dev_warn(isp->dev, "Can't find bridge format\n"); return -EINVAL; @@ -4659,40 +4643,12 @@ int atomisp_set_fmt(struct video_device *vdev, struct v4l2_format *f) padding_h = 0; } - /* construct resolution supported by isp */ - if (res_overflow) { - f->fmt.pix.width = rounddown( - clamp_t(u32, f->fmt.pix.width - padding_w, - ATOM_ISP_MIN_WIDTH, - ATOM_ISP_MAX_WIDTH), ATOM_ISP_STEP_WIDTH); - f->fmt.pix.height = rounddown( - clamp_t(u32, f->fmt.pix.height - padding_h, - ATOM_ISP_MIN_HEIGHT, - ATOM_ISP_MAX_HEIGHT), ATOM_ISP_STEP_HEIGHT); - } - atomisp_get_dis_envelop(asd, f->fmt.pix.width, f->fmt.pix.height, &dvs_env_w, &dvs_env_h); asd->capture_pad = source_pad; - /* - * For jpeg or custom raw format the sensor will return constant - * width and height. Because we already had quried try_mbus_fmt, - * f->fmt.pix.width and f->fmt.pix.height has been changed to - * this fixed width and height. So we cannot select the correct - * resolution with that information. So use the original width - * and height while set_mbus_fmt() so actual resolutions are - * being used in while set media bus format. - */ - s_fmt = f->fmt.pix; - if (f->fmt.pix.pixelformat == V4L2_PIX_FMT_JPEG || - f->fmt.pix.pixelformat == V4L2_PIX_FMT_CUSTOM_M10MO_RAW) { - s_fmt.width = backup_fmt.width; - s_fmt.height = backup_fmt.height; - } - - ret = atomisp_set_fmt_to_snr(vdev, &s_fmt, f->fmt.pix.pixelformat, + ret = atomisp_set_fmt_to_snr(vdev, &f->fmt.pix, padding_w, padding_h, dvs_env_w, dvs_env_h); if (ret) { dev_warn(isp->dev, @@ -4702,7 +4658,7 @@ int atomisp_set_fmt(struct video_device *vdev, struct v4l2_format *f) atomisp_csi_lane_config(isp); - atomisp_check_copy_mode(asd, source_pad, &backup_fmt); + atomisp_check_copy_mode(asd, source_pad, &f->fmt.pix); isp_sink_crop = *atomisp_subdev_get_rect(&asd->subdev, NULL, V4L2_SUBDEV_FORMAT_ACTIVE, From patchwork Sat Apr 1 14:59:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 13197046 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 80E95C761AF for ; Sat, 1 Apr 2023 15:01:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230132AbjDAPBi (ORCPT ); Sat, 1 Apr 2023 11:01:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37970 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230131AbjDAPBb (ORCPT ); Sat, 1 Apr 2023 11:01:31 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 609901F7B3 for ; Sat, 1 Apr 2023 08:00:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1680361228; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Tnzq3ByZM8vpu/jU4oQkw1x+J20uCLPHFfVgqaU1Fsc=; b=V1n8X6CBogxHRFtsnhMAOk6Nf9jhHM3HnlZrnHN7JE1cljPzuK5ehOesNx8yzo4DljHe1p OAI62Hd3QpgROrRT7nkdQul9EpyrHJmDvprOTlx/TrLbjb5ukP/hkGGKNbGpVzltyWVgdt 5WSK8W6RihIrPz5s452CREAM2eqy3X0= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-377-nyPR3IUWOLSbuXzFKT2p_Q-1; Sat, 01 Apr 2023 11:00:25 -0400 X-MC-Unique: nyPR3IUWOLSbuXzFKT2p_Q-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 85FA785A5A3; Sat, 1 Apr 2023 15:00:24 +0000 (UTC) Received: from localhost.localdomain (unknown [10.39.192.49]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9CF3E400F59; Sat, 1 Apr 2023 15:00:22 +0000 (UTC) From: Hans de Goede To: Mauro Carvalho Chehab , Sakari Ailus Cc: Hans de Goede , Kate Hsuan , Tsuchiya Yuto , Andy Shevchenko , Yury Luneff , Nable , andrey.i.trufanov@gmail.com, Fabio Aiuto , linux-media@vger.kernel.org, linux-staging@lists.linux.dev Subject: [PATCH 25/28] media: atomisp: Drop support for streaming from 2 sensors at once Date: Sat, 1 Apr 2023 16:59:23 +0200 Message-Id: <20230401145926.596216-26-hdegoede@redhat.com> In-Reply-To: <20230401145926.596216-1-hdegoede@redhat.com> References: <20230401145926.596216-1-hdegoede@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org With support for depth mode gone there really is no need to support streaming from 2 sensors at once. As discussed and acked on the list (see Link tag) it is desirable to drop support for this since it involves quite a lot of special handling / hacks in the code. This initial commit limits itself to a minimum set of changes to switch to 1 struct atomisp_sub_device / 1 stream. Further commits will actually remove / cleanup much of the special handling. Likewise this initial commit also deliberately skips the opportunity to turn some multi-line statements into single-line statements, so as to keep the diff small / easier to review. Link: https://lore.kernel.org/linux-media/5309d845-063b-6dd9-529d-0f82654290f2@redhat.com/ Signed-off-by: Hans de Goede --- .../staging/media/atomisp/pci/atomisp_cmd.c | 162 +++++------------- .../media/atomisp/pci/atomisp_compat.h | 4 +- .../media/atomisp/pci/atomisp_compat_css20.c | 89 ++++------ .../staging/media/atomisp/pci/atomisp_fops.c | 7 +- .../media/atomisp/pci/atomisp_internal.h | 17 +- .../staging/media/atomisp/pci/atomisp_ioctl.c | 41 ++--- .../media/atomisp/pci/atomisp_subdev.c | 97 ++++------- .../staging/media/atomisp/pci/atomisp_v4l2.c | 36 ++-- 8 files changed, 148 insertions(+), 305 deletions(-) diff --git a/drivers/staging/media/atomisp/pci/atomisp_cmd.c b/drivers/staging/media/atomisp/pci/atomisp_cmd.c index b5d094417fc5..d0386dcb24ce 100644 --- a/drivers/staging/media/atomisp/pci/atomisp_cmd.c +++ b/drivers/staging/media/atomisp/pci/atomisp_cmd.c @@ -196,8 +196,6 @@ int atomisp_freq_scaling(struct atomisp_device *isp, enum atomisp_dfs_mode mode, bool force) { - /* FIXME! Only use subdev[0] status yet */ - struct atomisp_sub_device *asd = &isp->asd[0]; const struct atomisp_dfs_config *dfs; unsigned int new_freq; struct atomisp_freq_scaling_rule curr_rules; @@ -223,7 +221,7 @@ int atomisp_freq_scaling(struct atomisp_device *isp, goto done; } - fps = atomisp_get_sensor_fps(asd); + fps = atomisp_get_sensor_fps(&isp->asd); if (fps == 0) { dev_info(isp->dev, "Sensor didn't report FPS. Using DFS max mode.\n"); @@ -231,10 +229,10 @@ int atomisp_freq_scaling(struct atomisp_device *isp, goto done; } - curr_rules.width = asd->fmt[asd->capture_pad].fmt.width; - curr_rules.height = asd->fmt[asd->capture_pad].fmt.height; + curr_rules.width = isp->asd.fmt[isp->asd.capture_pad].fmt.width; + curr_rules.height = isp->asd.fmt[isp->asd.capture_pad].fmt.height; curr_rules.fps = fps; - curr_rules.run_mode = asd->run_mode->val; + curr_rules.run_mode = isp->asd.run_mode->val; /* search for the target frequency by looping freq rules*/ for (i = 0; i < dfs->dfs_table_size; i++) { @@ -451,37 +449,13 @@ static void clear_irq_reg(struct atomisp_device *isp) pci_write_config_dword(pdev, PCI_INTERRUPT_CTRL, msg_ret); } -static struct atomisp_sub_device * -__get_asd_from_port(struct atomisp_device *isp, enum mipi_port_id port) -{ - int i; - - /* Check which isp subdev to send eof */ - for (i = 0; i < isp->num_of_streams; i++) { - struct atomisp_sub_device *asd = &isp->asd[i]; - struct camera_mipi_info *mipi_info; - - mipi_info = atomisp_to_sensor_mipi_info( - isp->inputs[asd->input_curr].camera); - - if (asd->streaming == ATOMISP_DEVICE_STREAMING_ENABLED && - __get_mipi_port(isp, mipi_info->port) == port) { - return asd; - } - } - - return NULL; -} - /* interrupt handling function*/ irqreturn_t atomisp_isr(int irq, void *dev) { struct atomisp_device *isp = (struct atomisp_device *)dev; - struct atomisp_sub_device *asd; struct atomisp_css_event eof_event; unsigned int irq_infos = 0; unsigned long flags; - unsigned int i; int err; spin_lock_irqsave(&isp->lock, flags); @@ -501,18 +475,10 @@ irqreturn_t atomisp_isr(int irq, void *dev) if (!atomisp_streaming_count(isp)) goto out_nowake; - for (i = 0; i < isp->num_of_streams; i++) { - asd = &isp->asd[i]; - - if (asd->streaming != ATOMISP_DEVICE_STREAMING_ENABLED) - continue; - /* - * Current SOF only support one stream, so the SOF only valid - * either solely one stream is running - */ + if (isp->asd.streaming == ATOMISP_DEVICE_STREAMING_ENABLED) { if (irq_infos & IA_CSS_IRQ_INFO_CSS_RECEIVER_SOF) { - atomic_inc(&asd->sof_count); - atomisp_sof_event(asd); + atomic_inc(&isp->asd.sof_count); + atomisp_sof_event(&isp->asd); /* If sequence_temp and sequence are the same * there where no frames lost so we can increase @@ -522,14 +488,14 @@ irqreturn_t atomisp_isr(int irq, void *dev) * NOTE: There is assumption here that ISP will not * start processing next frame from sensor before old * one is completely done. */ - if (atomic_read(&asd->sequence) == atomic_read( - &asd->sequence_temp)) - atomic_set(&asd->sequence_temp, - atomic_read(&asd->sof_count)); + if (atomic_read(&isp->asd.sequence) == + atomic_read(&isp->asd.sequence_temp)) + atomic_set(&isp->asd.sequence_temp, + atomic_read(&isp->asd.sof_count)); } if (irq_infos & IA_CSS_IRQ_INFO_EVENTS_READY) - atomic_set(&asd->sequence, - atomic_read(&asd->sequence_temp)); + atomic_set(&isp->asd.sequence, + atomic_read(&isp->asd.sequence_temp)); } if (irq_infos & IA_CSS_IRQ_INFO_CSS_RECEIVER_SOF) { @@ -554,21 +520,12 @@ irqreturn_t atomisp_isr(int irq, void *dev) } if (irq_infos & IA_CSS_IRQ_INFO_ISYS_EVENTS_READY) { - while (ia_css_dequeue_isys_event(&eof_event.event) == - 0) { - /* EOF Event does not have the css_pipe returned */ - asd = __get_asd_from_port(isp, eof_event.event.port); - if (!asd) { - dev_err(isp->dev, "%s: ISYS event, but no subdev.event:%d", - __func__, eof_event.event.type); - continue; - } - - atomisp_eof_event(asd, eof_event.event.exp_id); + while (ia_css_dequeue_isys_event(&eof_event.event) == 0) { + atomisp_eof_event(&isp->asd, eof_event.event.exp_id); dev_dbg_ratelimited(isp->dev, "%s ISYS event: EOF exp_id %d, asd %d\n", __func__, eof_event.event.exp_id, - asd->index); + isp->asd.index); } irq_infos &= ~IA_CSS_IRQ_INFO_ISYS_EVENTS_READY; @@ -993,9 +950,9 @@ static void __atomisp_css_recover(struct atomisp_device *isp, bool isp_timeout) { struct pci_dev *pdev = to_pci_dev(isp->dev); enum ia_css_pipe_id css_pipe_id; - bool stream_restart[MAX_STREAM_NUM] = {0}; + bool stream_restart = false; unsigned long flags; - int i, ret; + int ret; lockdep_assert_held(&isp->mutex); @@ -1004,44 +961,37 @@ static void __atomisp_css_recover(struct atomisp_device *isp, bool isp_timeout) atomisp_css_irq_enable(isp, IA_CSS_IRQ_INFO_CSS_RECEIVER_SOF, false); - BUG_ON(isp->num_of_streams > MAX_STREAM_NUM); - - for (i = 0; i < isp->num_of_streams; i++) { - struct atomisp_sub_device *asd = &isp->asd[i]; - - if (asd->streaming != ATOMISP_DEVICE_STREAMING_ENABLED && - !asd->stream_prepared) - continue; - - stream_restart[asd->index] = true; + if (isp->asd.streaming == ATOMISP_DEVICE_STREAMING_ENABLED || + isp->asd.stream_prepared) { + stream_restart = true; spin_lock_irqsave(&isp->lock, flags); - asd->streaming = ATOMISP_DEVICE_STREAMING_STOPPING; + isp->asd.streaming = ATOMISP_DEVICE_STREAMING_STOPPING; spin_unlock_irqrestore(&isp->lock, flags); /* stream off sensor */ ret = v4l2_subdev_call( - isp->inputs[asd->input_curr]. + isp->inputs[isp->asd.input_curr]. camera, video, s_stream, 0); if (ret) dev_warn(isp->dev, "can't stop streaming on sensor!\n"); - atomisp_clear_css_buffer_counters(asd); + atomisp_clear_css_buffer_counters(&isp->asd); - css_pipe_id = atomisp_get_css_pipe_id(asd); - atomisp_css_stop(asd, css_pipe_id, true); + css_pipe_id = atomisp_get_css_pipe_id(&isp->asd); + atomisp_css_stop(&isp->asd, css_pipe_id, true); spin_lock_irqsave(&isp->lock, flags); - asd->streaming = ATOMISP_DEVICE_STREAMING_DISABLED; + isp->asd.streaming = ATOMISP_DEVICE_STREAMING_DISABLED; spin_unlock_irqrestore(&isp->lock, flags); - asd->preview_exp_id = 1; - asd->postview_exp_id = 1; + isp->asd.preview_exp_id = 1; + isp->asd.postview_exp_id = 1; /* notify HAL the CSS reset */ dev_dbg(isp->dev, - "send reset event to %s\n", asd->subdev.devnode->name); - atomisp_reset_event(asd); + "send reset event to %s\n", isp->asd.subdev.devnode->name); + atomisp_reset_event(&isp->asd); } /* clear irq */ @@ -1057,25 +1007,20 @@ static void __atomisp_css_recover(struct atomisp_device *isp, bool isp_timeout) atomisp_reset(isp); isp->isp_timeout = false; - for (i = 0; i < isp->num_of_streams; i++) { - struct atomisp_sub_device *asd = &isp->asd[i]; - - if (!stream_restart[i]) - continue; + if (stream_restart) { + atomisp_css_input_set_mode(&isp->asd, IA_CSS_INPUT_MODE_BUFFERED_SENSOR); - atomisp_css_input_set_mode(asd, IA_CSS_INPUT_MODE_BUFFERED_SENSOR); - - css_pipe_id = atomisp_get_css_pipe_id(asd); - if (atomisp_css_start(asd, css_pipe_id, true)) { + css_pipe_id = atomisp_get_css_pipe_id(&isp->asd); + if (atomisp_css_start(&isp->asd, css_pipe_id, true)) { dev_warn(isp->dev, "start SP failed, so do not set streaming to be enable!\n"); } else { spin_lock_irqsave(&isp->lock, flags); - asd->streaming = ATOMISP_DEVICE_STREAMING_ENABLED; + isp->asd.streaming = ATOMISP_DEVICE_STREAMING_ENABLED; spin_unlock_irqrestore(&isp->lock, flags); } - atomisp_csi2_configure(asd); + atomisp_csi2_configure(&isp->asd); } atomisp_css_irq_enable(isp, IA_CSS_IRQ_INFO_CSS_RECEIVER_SOF, @@ -1084,27 +1029,20 @@ static void __atomisp_css_recover(struct atomisp_device *isp, bool isp_timeout) if (atomisp_freq_scaling(isp, ATOMISP_DFS_MODE_AUTO, true) < 0) dev_dbg(isp->dev, "DFS auto failed while recovering!\n"); - for (i = 0; i < isp->num_of_streams; i++) { - struct atomisp_sub_device *asd; - - asd = &isp->asd[i]; - - if (!stream_restart[i]) - continue; - + if (stream_restart) { /* * dequeueing buffers is not needed. CSS will recycle * buffers that it has. */ - atomisp_flush_bufs_and_wakeup(asd); + atomisp_flush_bufs_and_wakeup(&isp->asd); /* Requeue unprocessed per-frame parameters. */ - atomisp_recover_params_queue(&asd->video_out_capture); - atomisp_recover_params_queue(&asd->video_out_preview); - atomisp_recover_params_queue(&asd->video_out_video_capture); + atomisp_recover_params_queue(&isp->asd.video_out_capture); + atomisp_recover_params_queue(&isp->asd.video_out_preview); + atomisp_recover_params_queue(&isp->asd.video_out_video_capture); ret = v4l2_subdev_call( - isp->inputs[asd->input_curr].camera, video, + isp->inputs[isp->asd.input_curr].camera, video, s_stream, 1); if (ret) dev_warn(isp->dev, @@ -1164,10 +1102,6 @@ irqreturn_t atomisp_isr_thread(int irq, void *isp_ptr) { struct atomisp_device *isp = isp_ptr; unsigned long flags; - bool frame_done_found[MAX_STREAM_NUM] = {0}; - bool css_pipe_done[MAX_STREAM_NUM] = {0}; - unsigned int i; - struct atomisp_sub_device *asd; dev_dbg(isp->dev, ">%s\n", __func__); @@ -1206,15 +1140,11 @@ irqreturn_t atomisp_isr_thread(int irq, void *isp_ptr) * time, instead, dequue one and process one, then another */ mutex_lock(&isp->mutex); - if (atomisp_css_isr_thread(isp, frame_done_found, css_pipe_done)) + if (atomisp_css_isr_thread(isp)) goto out; - for (i = 0; i < isp->num_of_streams; i++) { - asd = &isp->asd[i]; - if (asd->streaming != ATOMISP_DEVICE_STREAMING_ENABLED) - continue; - atomisp_setup_flash(asd); - } + if (isp->asd.streaming == ATOMISP_DEVICE_STREAMING_ENABLED) + atomisp_setup_flash(&isp->asd); out: mutex_unlock(&isp->mutex); dev_dbg(isp->dev, "<%s\n", __func__); diff --git a/drivers/staging/media/atomisp/pci/atomisp_compat.h b/drivers/staging/media/atomisp/pci/atomisp_compat.h index 707509922784..218e8ac276c8 100644 --- a/drivers/staging/media/atomisp/pci/atomisp_compat.h +++ b/drivers/staging/media/atomisp/pci/atomisp_compat.h @@ -416,9 +416,7 @@ int atomisp_css_get_dis_stat(struct atomisp_sub_device *asd, int atomisp_css_update_stream(struct atomisp_sub_device *asd); -int atomisp_css_isr_thread(struct atomisp_device *isp, - bool *frame_done_found, - bool *css_pipe_done); +int atomisp_css_isr_thread(struct atomisp_device *isp); bool atomisp_css_valid_sof(struct atomisp_device *isp); diff --git a/drivers/staging/media/atomisp/pci/atomisp_compat_css20.c b/drivers/staging/media/atomisp/pci/atomisp_compat_css20.c index a1c1c9b1e806..1dae2a7cfdd9 100644 --- a/drivers/staging/media/atomisp/pci/atomisp_compat_css20.c +++ b/drivers/staging/media/atomisp/pci/atomisp_compat_css20.c @@ -3393,41 +3393,33 @@ void atomisp_css_morph_table_free(struct ia_css_morph_table *table) ia_css_morph_table_free(table); } -static struct atomisp_sub_device *__get_atomisp_subdev( - struct ia_css_pipe *css_pipe, - struct atomisp_device *isp, - enum atomisp_input_stream_id *stream_id) +static bool atomisp_css_isr_get_stream_id(struct ia_css_pipe *css_pipe, + struct atomisp_device *isp, + enum atomisp_input_stream_id *stream_id) { - int i, j, k; - struct atomisp_sub_device *asd; struct atomisp_stream_env *stream_env; + int i, j; - for (i = 0; i < isp->num_of_streams; i++) { - asd = &isp->asd[i]; - if (asd->streaming == ATOMISP_DEVICE_STREAMING_DISABLED) - continue; - for (j = 0; j < ATOMISP_INPUT_STREAM_NUM; j++) { - stream_env = &asd->stream_env[j]; - for (k = 0; k < IA_CSS_PIPE_ID_NUM; k++) { - if (stream_env->pipes[k] && - stream_env->pipes[k] == css_pipe) { - *stream_id = j; - return asd; - } + if (isp->asd.streaming == ATOMISP_DEVICE_STREAMING_DISABLED) + return false; + + for (i = 0; i < ATOMISP_INPUT_STREAM_NUM; i++) { + stream_env = &isp->asd.stream_env[i]; + for (j = 0; j < IA_CSS_PIPE_ID_NUM; j++) { + if (stream_env->pipes[j] && stream_env->pipes[j] == css_pipe) { + *stream_id = i; + return true; } } } - return NULL; + return false; } -int atomisp_css_isr_thread(struct atomisp_device *isp, - bool *frame_done_found, - bool *css_pipe_done) +int atomisp_css_isr_thread(struct atomisp_device *isp) { enum atomisp_input_stream_id stream_id = 0; struct atomisp_css_event current_event; - struct atomisp_sub_device *asd; lockdep_assert_held(&isp->mutex); @@ -3453,9 +3445,7 @@ int atomisp_css_isr_thread(struct atomisp_device *isp, continue; } - asd = __get_atomisp_subdev(current_event.event.pipe, - isp, &stream_id); - if (!asd) { + if (!atomisp_css_isr_get_stream_id(current_event.event.pipe, isp, &stream_id)) { if (current_event.event.type == IA_CSS_EVENT_TYPE_TIMER) dev_dbg(isp->dev, "event: Timer event."); @@ -3466,56 +3456,53 @@ int atomisp_css_isr_thread(struct atomisp_device *isp, continue; } - atomisp_css_temp_pipe_to_pipe_id(asd, ¤t_event); + atomisp_css_temp_pipe_to_pipe_id(&isp->asd, ¤t_event); switch (current_event.event.type) { case IA_CSS_EVENT_TYPE_OUTPUT_FRAME_DONE: dev_dbg(isp->dev, "event: Output frame done"); - frame_done_found[asd->index] = true; - atomisp_buf_done(asd, 0, IA_CSS_BUFFER_TYPE_OUTPUT_FRAME, + atomisp_buf_done(&isp->asd, 0, IA_CSS_BUFFER_TYPE_OUTPUT_FRAME, current_event.pipe, true, stream_id); break; case IA_CSS_EVENT_TYPE_SECOND_OUTPUT_FRAME_DONE: dev_dbg(isp->dev, "event: Second output frame done"); - frame_done_found[asd->index] = true; - atomisp_buf_done(asd, 0, IA_CSS_BUFFER_TYPE_SEC_OUTPUT_FRAME, + atomisp_buf_done(&isp->asd, 0, IA_CSS_BUFFER_TYPE_SEC_OUTPUT_FRAME, current_event.pipe, true, stream_id); break; case IA_CSS_EVENT_TYPE_3A_STATISTICS_DONE: dev_dbg(isp->dev, "event: 3A stats frame done"); - atomisp_buf_done(asd, 0, + atomisp_buf_done(&isp->asd, 0, IA_CSS_BUFFER_TYPE_3A_STATISTICS, current_event.pipe, false, stream_id); break; case IA_CSS_EVENT_TYPE_METADATA_DONE: dev_dbg(isp->dev, "event: metadata frame done"); - atomisp_buf_done(asd, 0, + atomisp_buf_done(&isp->asd, 0, IA_CSS_BUFFER_TYPE_METADATA, current_event.pipe, false, stream_id); break; case IA_CSS_EVENT_TYPE_VF_OUTPUT_FRAME_DONE: dev_dbg(isp->dev, "event: VF output frame done"); - atomisp_buf_done(asd, 0, + atomisp_buf_done(&isp->asd, 0, IA_CSS_BUFFER_TYPE_VF_OUTPUT_FRAME, current_event.pipe, true, stream_id); break; case IA_CSS_EVENT_TYPE_SECOND_VF_OUTPUT_FRAME_DONE: dev_dbg(isp->dev, "event: second VF output frame done"); - atomisp_buf_done(asd, 0, + atomisp_buf_done(&isp->asd, 0, IA_CSS_BUFFER_TYPE_SEC_VF_OUTPUT_FRAME, current_event.pipe, true, stream_id); break; case IA_CSS_EVENT_TYPE_DIS_STATISTICS_DONE: dev_dbg(isp->dev, "event: dis stats frame done"); - atomisp_buf_done(asd, 0, + atomisp_buf_done(&isp->asd, 0, IA_CSS_BUFFER_TYPE_DIS_STATISTICS, current_event.pipe, false, stream_id); break; case IA_CSS_EVENT_TYPE_PIPELINE_DONE: dev_dbg(isp->dev, "event: pipeline done"); - css_pipe_done[asd->index] = true; break; case IA_CSS_EVENT_TYPE_ACC_STAGE_COMPLETE: dev_warn(isp->dev, "unexpected event: acc stage done"); @@ -3532,23 +3519,17 @@ int atomisp_css_isr_thread(struct atomisp_device *isp, bool atomisp_css_valid_sof(struct atomisp_device *isp) { - unsigned int i, j; - - /* Loop for each css stream */ - for (i = 0; i < isp->num_of_streams; i++) { - struct atomisp_sub_device *asd = &isp->asd[i]; - /* Loop for each css vc stream */ - for (j = 0; j < ATOMISP_INPUT_STREAM_NUM; j++) { - if (!asd->stream_env[j].stream) - continue; - - dev_dbg(isp->dev, - "stream #%d: mode: %d\n", j, - asd->stream_env[j].stream_config.mode); - if (asd->stream_env[j].stream_config.mode == - IA_CSS_INPUT_MODE_BUFFERED_SENSOR) - return false; - } + unsigned int i; + + /* Loop for each css vc stream */ + for (i = 0; i < ATOMISP_INPUT_STREAM_NUM; i++) { + if (!isp->asd.stream_env[i].stream) + continue; + + dev_dbg(isp->dev, "stream #%d: mode: %d\n", + i, isp->asd.stream_env[i].stream_config.mode); + if (isp->asd.stream_env[i].stream_config.mode == IA_CSS_INPUT_MODE_BUFFERED_SENSOR) + return false; } return true; diff --git a/drivers/staging/media/atomisp/pci/atomisp_fops.c b/drivers/staging/media/atomisp/pci/atomisp_fops.c index e220f500aff4..fa362c8a37e8 100644 --- a/drivers/staging/media/atomisp/pci/atomisp_fops.c +++ b/drivers/staging/media/atomisp/pci/atomisp_fops.c @@ -594,12 +594,7 @@ static unsigned int atomisp_subdev_users(struct atomisp_sub_device *asd) unsigned int atomisp_dev_users(struct atomisp_device *isp) { - unsigned int i, sum; - - for (i = 0, sum = 0; i < isp->num_of_streams; i++) - sum += atomisp_subdev_users(&isp->asd[i]); - - return sum; + return atomisp_subdev_users(&isp->asd); } static int atomisp_open(struct file *file) diff --git a/drivers/staging/media/atomisp/pci/atomisp_internal.h b/drivers/staging/media/atomisp/pci/atomisp_internal.h index 35293f2c196a..1fac99f4e2b0 100644 --- a/drivers/staging/media/atomisp/pci/atomisp_internal.h +++ b/drivers/staging/media/atomisp/pci/atomisp_internal.h @@ -48,8 +48,6 @@ (((isp)->media_dev.hw_revision & ATOMISP_HW_REVISION_MASK) == \ ((rev) << ATOMISP_HW_REVISION_SHIFT)) -#define MAX_STREAM_NUM 2 - #define ATOMISP_PCI_DEVICE_SOC_MASK 0xfff8 /* MRFLD with 0x1178: ISP freq can burst to 457MHz */ #define ATOMISP_PCI_DEVICE_SOC_MRFLD 0x1178 @@ -181,6 +179,7 @@ struct atomisp_device { struct device *dev; struct v4l2_device v4l2_dev; struct media_device media_dev; + struct atomisp_sub_device asd; struct atomisp_platform_data *pdata; void *mmu_l1_base; void __iomem *base; @@ -190,18 +189,6 @@ struct atomisp_device { struct pm_qos_request pm_qos; s32 max_isr_latency; - /* - * ISP modules - * Multiple streams are represents by multiple - * atomisp_sub_device instances - */ - struct atomisp_sub_device *asd; - /* - * this will be assigned dyanamically. - * For Merr/BTY(ISP2400), 2 streams are supported. - */ - unsigned int num_of_streams; - struct atomisp_mipi_csi2_device csi2_port[ATOMISP_CAMERA_NR_PORTS]; struct atomisp_tpg_device tpg; @@ -222,7 +209,7 @@ struct atomisp_device { bool isp_fatal_error; struct work_struct assert_recovery_work; - spinlock_t lock; /* Protects asd[i].streaming */ + spinlock_t lock; /* Protects asd.streaming */ bool need_gfx_throttle; diff --git a/drivers/staging/media/atomisp/pci/atomisp_ioctl.c b/drivers/staging/media/atomisp/pci/atomisp_ioctl.c index 99cfe8a80bb1..14700afd92c2 100644 --- a/drivers/staging/media/atomisp/pci/atomisp_ioctl.c +++ b/drivers/staging/media/atomisp/pci/atomisp_ioctl.c @@ -626,13 +626,7 @@ atomisp_subdev_streaming_count(struct atomisp_sub_device *asd) unsigned int atomisp_streaming_count(struct atomisp_device *isp) { - unsigned int i, sum; - - for (i = 0, sum = 0; i < isp->num_of_streams; i++) - sum += isp->asd[i].streaming == - ATOMISP_DEVICE_STREAMING_ENABLED; - - return sum; + return isp->asd.streaming == ATOMISP_DEVICE_STREAMING_ENABLED; } /* @@ -1318,11 +1312,11 @@ void atomisp_stop_streaming(struct vb2_queue *vq) struct video_device *vdev = &pipe->vdev; struct atomisp_device *isp = asd->isp; struct pci_dev *pdev = to_pci_dev(isp->dev); - bool recreate_streams[MAX_STREAM_NUM] = {0}; enum ia_css_pipe_id css_pipe_id; + bool recreate_stream = false; bool first_streamoff = false; unsigned long flags; - int i, ret; + int ret; mutex_lock(&isp->mutex); @@ -1409,11 +1403,9 @@ void atomisp_stop_streaming(struct vb2_queue *vq) * * So force stream destroy here. */ - for (i = 0; i < isp->num_of_streams; i++) { - if (isp->asd[i].stream_prepared) { - atomisp_destroy_pipes_stream_force(&isp->asd[i]); - recreate_streams[i] = true; - } + if (isp->asd.stream_prepared) { + atomisp_destroy_pipes_stream_force(&isp->asd); + recreate_stream = true; } /* disable PUNIT/ISP acknowlede/handshake - SRSE=3 */ @@ -1421,19 +1413,18 @@ void atomisp_stop_streaming(struct vb2_queue *vq) isp->saved_regs.i_control | MRFLD_PCI_I_CONTROL_SRSE_RESET_MASK); dev_err(isp->dev, "atomisp_reset"); atomisp_reset(isp); - for (i = 0; i < isp->num_of_streams; i++) { - if (recreate_streams[i]) { - int ret2; - - ret2 = atomisp_create_pipes_stream(&isp->asd[i]); - if (ret2) { - dev_err(isp->dev, "%s error re-creating streams: %d\n", - __func__, ret2); - if (!ret) - ret = ret2; - } + + if (recreate_stream) { + int ret2; + + ret2 = atomisp_create_pipes_stream(&isp->asd); + if (ret2) { + dev_err(isp->dev, "%s error re-creating streams: %d\n", __func__, ret2); + if (!ret) + ret = ret2; } } + isp->isp_timeout = false; out_unlock: mutex_unlock(&isp->mutex); diff --git a/drivers/staging/media/atomisp/pci/atomisp_subdev.c b/drivers/staging/media/atomisp/pci/atomisp_subdev.c index 011e67ccdbba..143176bc684a 100644 --- a/drivers/staging/media/atomisp/pci/atomisp_subdev.c +++ b/drivers/staging/media/atomisp/pci/atomisp_subdev.c @@ -1018,21 +1018,16 @@ static int isp_subdev_init_entities(struct atomisp_sub_device *asd) int atomisp_create_pads_links(struct atomisp_device *isp) { - struct atomisp_sub_device *asd; - int i, j, ret = 0; + int i, ret; - isp->num_of_streams = 2; for (i = 0; i < ATOMISP_CAMERA_NR_PORTS; i++) { - for (j = 0; j < isp->num_of_streams; j++) { - ret = - media_create_pad_link(&isp->csi2_port[i].subdev. - entity, CSI2_PAD_SOURCE, - &isp->asd[j].subdev.entity, - ATOMISP_SUBDEV_PAD_SINK, 0); - if (ret < 0) - return ret; - } + ret = media_create_pad_link(&isp->csi2_port[i].subdev.entity, + CSI2_PAD_SOURCE, &isp->asd.subdev.entity, + ATOMISP_SUBDEV_PAD_SINK, 0); + if (ret < 0) + return ret; } + for (i = 0; i < isp->input_cnt; i++) { /* Don't create links for the test-pattern-generator */ if (isp->inputs[i].type == TEST_PATTERN) @@ -1047,33 +1042,28 @@ int atomisp_create_pads_links(struct atomisp_device *isp) if (ret < 0) return ret; } - for (i = 0; i < isp->num_of_streams; i++) { - asd = &isp->asd[i]; - ret = media_create_pad_link(&asd->subdev.entity, - ATOMISP_SUBDEV_PAD_SOURCE_PREVIEW, - &asd->video_out_preview.vdev.entity, - 0, 0); - if (ret < 0) - return ret; - ret = media_create_pad_link(&asd->subdev.entity, - ATOMISP_SUBDEV_PAD_SOURCE_VF, - &asd->video_out_vf.vdev.entity, 0, - 0); - if (ret < 0) - return ret; - ret = media_create_pad_link(&asd->subdev.entity, - ATOMISP_SUBDEV_PAD_SOURCE_CAPTURE, - &asd->video_out_capture.vdev.entity, - 0, 0); - if (ret < 0) - return ret; - ret = media_create_pad_link(&asd->subdev.entity, - ATOMISP_SUBDEV_PAD_SOURCE_VIDEO, - &asd->video_out_video_capture.vdev. - entity, 0, 0); - if (ret < 0) - return ret; - } + + ret = media_create_pad_link(&isp->asd.subdev.entity, + ATOMISP_SUBDEV_PAD_SOURCE_PREVIEW, + &isp->asd.video_out_preview.vdev.entity, 0, 0); + if (ret < 0) + return ret; + ret = media_create_pad_link(&isp->asd.subdev.entity, + ATOMISP_SUBDEV_PAD_SOURCE_VF, + &isp->asd.video_out_vf.vdev.entity, 0, 0); + if (ret < 0) + return ret; + ret = media_create_pad_link(&isp->asd.subdev.entity, + ATOMISP_SUBDEV_PAD_SOURCE_CAPTURE, + &isp->asd.video_out_capture.vdev.entity, 0, 0); + if (ret < 0) + return ret; + ret = media_create_pad_link(&isp->asd.subdev.entity, + ATOMISP_SUBDEV_PAD_SOURCE_VIDEO, + &isp->asd.video_out_video_capture.vdev.entity, 0, 0); + if (ret < 0) + return ret; + return 0; } @@ -1169,29 +1159,14 @@ int atomisp_subdev_register_video_nodes(struct atomisp_sub_device *asd, */ int atomisp_subdev_init(struct atomisp_device *isp) { - struct atomisp_sub_device *asd; - int i, ret = 0; + int ret; - /* - * CSS2.0 running ISP2400 support - * multiple streams - */ - isp->num_of_streams = 2; - isp->asd = devm_kzalloc(isp->dev, sizeof(struct atomisp_sub_device) * - isp->num_of_streams, GFP_KERNEL); - if (!isp->asd) - return -ENOMEM; - for (i = 0; i < isp->num_of_streams; i++) { - asd = &isp->asd[i]; - asd->isp = isp; - isp_subdev_init_params(asd); - asd->index = i; - ret = isp_subdev_init_entities(asd); - if (ret < 0) { - atomisp_subdev_cleanup_entities(asd); - break; - } - } + isp->asd.index = 0; + isp->asd.isp = isp; + isp_subdev_init_params(&isp->asd); + ret = isp_subdev_init_entities(&isp->asd); + if (ret < 0) + atomisp_subdev_cleanup_entities(&isp->asd); return ret; } diff --git a/drivers/staging/media/atomisp/pci/atomisp_v4l2.c b/drivers/staging/media/atomisp/pci/atomisp_v4l2.c index 4f5698e54711..3f315dabbeeb 100644 --- a/drivers/staging/media/atomisp/pci/atomisp_v4l2.c +++ b/drivers/staging/media/atomisp/pci/atomisp_v4l2.c @@ -753,8 +753,6 @@ static int atomisp_suspend(struct device *dev) { struct atomisp_device *isp = (struct atomisp_device *) dev_get_drvdata(dev); - /* FIXME: only has one isp_subdev at present */ - struct atomisp_sub_device *asd = &isp->asd[0]; unsigned long flags; /* @@ -765,7 +763,7 @@ static int atomisp_suspend(struct device *dev) return -EBUSY; spin_lock_irqsave(&isp->lock, flags); - if (asd->streaming != ATOMISP_DEVICE_STREAMING_DISABLED) { + if (isp->asd.streaming != ATOMISP_DEVICE_STREAMING_DISABLED) { spin_unlock_irqrestore(&isp->lock, flags); dev_err(isp->dev, "atomisp cannot suspend at this time.\n"); return -EINVAL; @@ -1004,8 +1002,7 @@ static void atomisp_unregister_entities(struct atomisp_device *isp) unsigned int i; struct v4l2_subdev *sd, *next; - for (i = 0; i < isp->num_of_streams; i++) - atomisp_subdev_unregister_entities(&isp->asd[i]); + atomisp_subdev_unregister_entities(&isp->asd); atomisp_tpg_unregister_entities(&isp->tpg); for (i = 0; i < ATOMISP_CAMERA_NR_PORTS; i++) atomisp_mipi_csi2_unregister_entities(&isp->csi2_port[i]); @@ -1064,17 +1061,10 @@ static int atomisp_register_entities(struct atomisp_device *isp) goto tpg_register_failed; } - for (i = 0; i < isp->num_of_streams; i++) { - struct atomisp_sub_device *asd = &isp->asd[i]; - - ret = atomisp_subdev_register_subdev(asd, &isp->v4l2_dev); - if (ret < 0) { - dev_err(isp->dev, "atomisp_subdev_register_subdev fail\n"); - for (; i > 0; i--) - atomisp_subdev_unregister_entities( - &isp->asd[i - 1]); - goto subdev_register_failed; - } + ret = atomisp_subdev_register_subdev(&isp->asd, &isp->v4l2_dev); + if (ret < 0) { + dev_err(isp->dev, "atomisp_subdev_register_subdev fail\n"); + goto subdev_register_failed; } for (i = 0; i < isp->input_cnt; i++) { @@ -1099,9 +1089,7 @@ static int atomisp_register_entities(struct atomisp_device *isp) return 0; link_failed: - for (i = 0; i < isp->num_of_streams; i++) - atomisp_subdev_unregister_entities( - &isp->asd[i]); + atomisp_subdev_unregister_entities(&isp->asd); subdev_register_failed: atomisp_tpg_unregister_entities(&isp->tpg); tpg_register_failed: @@ -1117,13 +1105,11 @@ static int atomisp_register_entities(struct atomisp_device *isp) static int atomisp_register_device_nodes(struct atomisp_device *isp) { - int i, err; + int err; - for (i = 0; i < isp->num_of_streams; i++) { - err = atomisp_subdev_register_video_nodes(&isp->asd[i], &isp->v4l2_dev); - if (err) - return err; - } + err = atomisp_subdev_register_video_nodes(&isp->asd, &isp->v4l2_dev); + if (err) + return err; err = atomisp_create_pads_links(isp); if (err) From patchwork Sat Apr 1 14:59:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 13197047 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 595FAC6FD1D for ; Sat, 1 Apr 2023 15:01:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230152AbjDAPBl (ORCPT ); Sat, 1 Apr 2023 11:01:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37652 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230134AbjDAPBc (ORCPT ); Sat, 1 Apr 2023 11:01:32 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 17B0B20316 for ; Sat, 1 Apr 2023 08:00:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1680361230; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=vLLGFFZ5T4qOEbu+uYcxBCyPbyHarXfWcqcHhnOPA8M=; b=f5ZZA7ZmAfifBQkAqbwsFUHrwRwryRtn2TjQ+n2m3RA3xHQHDaa45JMkpIHo9WlDywbj73 JrtdBXn0UT1vJcIV2ywggAq7E08/i6vrOQmFmGlgGT+iYgXNh67M+Em0HhDzbwLIRdZ2TE G35Qs/WGOrj+AzkIwDKm2+7HbFfdvjw= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-533-4iuCk85fOu6nyzUS2CsV3g-1; Sat, 01 Apr 2023 11:00:27 -0400 X-MC-Unique: 4iuCk85fOu6nyzUS2CsV3g-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 47473185A78F; Sat, 1 Apr 2023 15:00:26 +0000 (UTC) Received: from localhost.localdomain (unknown [10.39.192.49]) by smtp.corp.redhat.com (Postfix) with ESMTP id B87784021BC; Sat, 1 Apr 2023 15:00:24 +0000 (UTC) From: Hans de Goede To: Mauro Carvalho Chehab , Sakari Ailus Cc: Hans de Goede , Kate Hsuan , Tsuchiya Yuto , Andy Shevchenko , Yury Luneff , Nable , andrey.i.trufanov@gmail.com, Fabio Aiuto , linux-media@vger.kernel.org, linux-staging@lists.linux.dev Subject: [PATCH 26/28] media: atomisp: Remove struct atomisp_sub_device index field Date: Sat, 1 Apr 2023 16:59:24 +0200 Message-Id: <20230401145926.596216-27-hdegoede@redhat.com> In-Reply-To: <20230401145926.596216-1-hdegoede@redhat.com> References: <20230401145926.596216-1-hdegoede@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org Remove the struct atomisp_sub_device. This was used for 2 things: 1. In dev_dbg() messages 2. To set the name of the v4l2_subdev for each struct atomisp_sub_device Now that only 1 subdev is used neither is useful anymore. Remove the _%d postfix from the v4l2_subdev name and remove the logging of the asd index from the dev_dbg() messages. In case of the atomisp_s_input() check to see if an input/sensor has already been assigned to another subdev the entire check no longer makes sense, so instead of changing the dev_err() message there just drop the entire check. Signed-off-by: Hans de Goede --- .../staging/media/atomisp/pci/atomisp_cmd.c | 15 +++++------- .../staging/media/atomisp/pci/atomisp_ioctl.c | 23 ++++--------------- .../media/atomisp/pci/atomisp_subdev.c | 3 +-- .../media/atomisp/pci/atomisp_subdev.h | 5 ---- 4 files changed, 11 insertions(+), 35 deletions(-) diff --git a/drivers/staging/media/atomisp/pci/atomisp_cmd.c b/drivers/staging/media/atomisp/pci/atomisp_cmd.c index d0386dcb24ce..28663d6fc4dd 100644 --- a/drivers/staging/media/atomisp/pci/atomisp_cmd.c +++ b/drivers/staging/media/atomisp/pci/atomisp_cmd.c @@ -523,9 +523,8 @@ irqreturn_t atomisp_isr(int irq, void *dev) while (ia_css_dequeue_isys_event(&eof_event.event) == 0) { atomisp_eof_event(&isp->asd, eof_event.event.exp_id); dev_dbg_ratelimited(isp->dev, - "%s ISYS event: EOF exp_id %d, asd %d\n", - __func__, eof_event.event.exp_id, - isp->asd.index); + "%s ISYS event: EOF exp_id %d\n", + __func__, eof_event.event.exp_id); } irq_infos &= ~IA_CSS_IRQ_INFO_ISYS_EVENTS_READY; @@ -3302,9 +3301,8 @@ int atomisp_set_parameters(struct video_device *vdev, } dev_dbg(asd->isp->dev, - "%s: set parameter(per_frame_setting %d) for asd%d with isp_config_id %d of %s\n", - __func__, arg->per_frame_setting, asd->index, - arg->isp_config_id, vdev->name); + "%s: set parameter(per_frame_setting %d) isp_config_id %d of %s\n", + __func__, arg->per_frame_setting, arg->isp_config_id, vdev->name); if (IS_ISP2401) { if (atomisp_is_vf_pipe(pipe) && arg->per_frame_setting) { @@ -4515,9 +4513,8 @@ int atomisp_set_fmt(struct video_device *vdev, struct v4l2_format *f) return -EINVAL; dev_dbg(isp->dev, - "setting resolution %ux%u on pad %u for asd%d, bytesperline %u\n", - f->fmt.pix.width, f->fmt.pix.height, source_pad, - asd->index, f->fmt.pix.bytesperline); + "setting resolution %ux%u on pad %u bytesperline %u\n", + f->fmt.pix.width, f->fmt.pix.height, source_pad, f->fmt.pix.bytesperline); v4l2_fh_init(&fh.vfh, vdev); diff --git a/drivers/staging/media/atomisp/pci/atomisp_ioctl.c b/drivers/staging/media/atomisp/pci/atomisp_ioctl.c index 14700afd92c2..384f31fc66c5 100644 --- a/drivers/staging/media/atomisp/pci/atomisp_ioctl.c +++ b/drivers/staging/media/atomisp/pci/atomisp_ioctl.c @@ -671,18 +671,6 @@ static int atomisp_s_input(struct file *file, void *fh, unsigned int input) return -EINVAL; } - /* - * check whether the request camera: - * 1: already in use - * 2: if in use, whether it is used by other streams - */ - if (isp->inputs[input].asd && isp->inputs[input].asd != asd) { - dev_err(isp->dev, - "%s, camera is already used by stream: %d\n", __func__, - isp->inputs[input].asd->index); - return -EBUSY; - } - camera = isp->inputs[input].camera; if (!camera) { dev_err(isp->dev, "%s, no camera\n", __func__); @@ -1106,9 +1094,8 @@ static int atomisp_dqbuf_wrapper(struct file *file, void *fh, struct v4l2_buffer buf->reserved2 = pipe->frame_config_id[buf->index]; dev_dbg(isp->dev, - "dqbuf buffer %d (%s) for asd%d with exp_id %d, isp_config_id %d\n", - buf->index, vdev->name, asd->index, buf->reserved >> 16, - buf->reserved2); + "dqbuf buffer %d (%s) with exp_id %d, isp_config_id %d\n", + buf->index, vdev->name, buf->reserved >> 16, buf->reserved2); return 0; } @@ -1186,8 +1173,7 @@ int atomisp_start_streaming(struct vb2_queue *vq, unsigned int count) mutex_lock(&isp->mutex); - dev_dbg(isp->dev, "Start stream on pad %d for asd%d\n", - atomisp_subdev_source_pad(vdev), asd->index); + dev_dbg(isp->dev, "Start stream on pad %d\n", atomisp_subdev_source_pad(vdev)); ret = atomisp_pipe_check(pipe, false); if (ret) @@ -1320,8 +1306,7 @@ void atomisp_stop_streaming(struct vb2_queue *vq) mutex_lock(&isp->mutex); - dev_dbg(isp->dev, "Stop stream on pad %d for asd%d\n", - atomisp_subdev_source_pad(vdev), asd->index); + dev_dbg(isp->dev, "Stop stream on pad %d\n", atomisp_subdev_source_pad(vdev)); /* * There is no guarantee that the buffers queued to / owned by the ISP diff --git a/drivers/staging/media/atomisp/pci/atomisp_subdev.c b/drivers/staging/media/atomisp/pci/atomisp_subdev.c index 143176bc684a..a0acfdb87177 100644 --- a/drivers/staging/media/atomisp/pci/atomisp_subdev.c +++ b/drivers/staging/media/atomisp/pci/atomisp_subdev.c @@ -918,7 +918,7 @@ static int isp_subdev_init_entities(struct atomisp_sub_device *asd) int ret; v4l2_subdev_init(sd, &isp_subdev_v4l2_ops); - sprintf(sd->name, "ATOMISP_SUBDEV_%d", asd->index); + sprintf(sd->name, "ATOMISP_SUBDEV"); v4l2_set_subdevdata(sd, asd); sd->flags |= V4L2_SUBDEV_FL_HAS_EVENTS | V4L2_SUBDEV_FL_HAS_DEVNODE; @@ -1161,7 +1161,6 @@ int atomisp_subdev_init(struct atomisp_device *isp) { int ret; - isp->asd.index = 0; isp->asd.isp = isp; isp_subdev_init_params(&isp->asd); ret = isp_subdev_init_entities(&isp->asd); diff --git a/drivers/staging/media/atomisp/pci/atomisp_subdev.h b/drivers/staging/media/atomisp/pci/atomisp_subdev.h index 117803f3cbd1..fee663bc415a 100644 --- a/drivers/staging/media/atomisp/pci/atomisp_subdev.h +++ b/drivers/staging/media/atomisp/pci/atomisp_subdev.h @@ -315,11 +315,6 @@ struct atomisp_sub_device { unsigned int streaming; bool stream_prepared; /* whether css stream is created */ - /* subdev index: will be used to show which subdev is holding the - * resource, like which camera is used by which subdev - */ - unsigned int index; - unsigned int latest_preview_exp_id; /* CSS ZSL/SDV raw buffer id */ unsigned int mipi_frame_size; From patchwork Sat Apr 1 14:59:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 13197048 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2650AC77B62 for ; Sat, 1 Apr 2023 15:01:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230145AbjDAPBm (ORCPT ); Sat, 1 Apr 2023 11:01:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37966 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230133AbjDAPBc (ORCPT ); Sat, 1 Apr 2023 11:01:32 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ACBB32031D for ; Sat, 1 Apr 2023 08:00:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1680361232; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=cb6G5JbVFv+EPtm+OowTpy5n4KazA/zY4dcxtvzMYS4=; b=ZeLlZhhJBQZNgQtih6HYM0uV0Cp45qfmCqwhk8WWa77dWFq/muQQ4AgYDLcR4UPUQbItep o/WIOHx5lA2gS7ueW9CL8nwbiuOoqGZuQBn166tBZRPeCrbgwdKXNCa4Z5FYd9Kb8a03t/ gngN/LUuhJa2wqfDepK3uKRYr6Rg3Iw= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-264-vSFLvIQPPuKahXq27mIAYw-1; Sat, 01 Apr 2023 11:00:28 -0400 X-MC-Unique: vSFLvIQPPuKahXq27mIAYw-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 07B662A5955F; Sat, 1 Apr 2023 15:00:28 +0000 (UTC) Received: from localhost.localdomain (unknown [10.39.192.49]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7C621400F59; Sat, 1 Apr 2023 15:00:26 +0000 (UTC) From: Hans de Goede To: Mauro Carvalho Chehab , Sakari Ailus Cc: Hans de Goede , Kate Hsuan , Tsuchiya Yuto , Andy Shevchenko , Yury Luneff , Nable , andrey.i.trufanov@gmail.com, Fabio Aiuto , linux-media@vger.kernel.org, linux-staging@lists.linux.dev Subject: [PATCH 27/28] media: atomisp: gmin_platform: Make DMI quirks take precedence over the _DSM table Date: Sat, 1 Apr 2023 16:59:25 +0200 Message-Id: <20230401145926.596216-28-hdegoede@redhat.com> In-Reply-To: <20230401145926.596216-1-hdegoede@redhat.com> References: <20230401145926.596216-1-hdegoede@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org On some devices the _DSM sensor-info table contains wrong info, move the DMI quirk handling up to above the _DSM table check to allow DMI quirks to override wrong info in the _DSM table. Signed-off-by: Hans de Goede --- .../media/atomisp/pci/atomisp_gmin_platform.c | 30 +++++++------------ 1 file changed, 11 insertions(+), 19 deletions(-) diff --git a/drivers/staging/media/atomisp/pci/atomisp_gmin_platform.c b/drivers/staging/media/atomisp/pci/atomisp_gmin_platform.c index f8d8a34d7e7f..f83de0ffaf16 100644 --- a/drivers/staging/media/atomisp/pci/atomisp_gmin_platform.c +++ b/drivers/staging/media/atomisp/pci/atomisp_gmin_platform.c @@ -1353,37 +1353,22 @@ static int gmin_get_config_var(struct device *maindev, const char *var, char *out, size_t *out_len) { + struct acpi_device *adev = ACPI_COMPANION(maindev); efi_char16_t var16[CFG_VAR_NAME_MAX]; const struct dmi_system_id *id; - struct device *dev = maindev; char var8[CFG_VAR_NAME_MAX]; efi_status_t status; int i, ret; - /* For sensors, try first to use the _DSM table */ - if (!is_gmin) { - ret = gmin_get_config_dsm_var(maindev, var, out, out_len); - if (!ret) - return 0; - } - - /* Fall-back to other approaches */ - - if (!is_gmin && ACPI_COMPANION(dev)) - dev = &ACPI_COMPANION(dev)->dev; - - if (!is_gmin) - ret = snprintf(var8, sizeof(var8), "%s_%s", dev_name(dev), var); + if (!is_gmin && adev) + ret = snprintf(var8, sizeof(var8), "%s_%s", acpi_dev_name(adev), var); else ret = snprintf(var8, sizeof(var8), "gmin_%s", var); if (ret < 0 || ret >= sizeof(var8) - 1) return -EINVAL; - /* First check a hard-coded list of board-specific variables. - * Some device firmwares lack the ability to set EFI variables at - * runtime. - */ + /* DMI based quirks override both the _DSM table and EFI variables */ id = dmi_first_match(gmin_vars); if (id) { ret = gmin_get_hardcoded_var(maindev, id->driver_data, var8, @@ -1392,6 +1377,13 @@ static int gmin_get_config_var(struct device *maindev, return 0; } + /* For sensors, try first to use the _DSM table */ + if (!is_gmin) { + ret = gmin_get_config_dsm_var(maindev, var, out, out_len); + if (!ret) + return 0; + } + /* Our variable names are ASCII by construction, but EFI names * are wide chars. Convert and zero-pad. */ From patchwork Sat Apr 1 14:59:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 13197050 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 05A0BC76196 for ; Sat, 1 Apr 2023 15:01:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230139AbjDAPBo (ORCPT ); Sat, 1 Apr 2023 11:01:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37980 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230141AbjDAPBd (ORCPT ); Sat, 1 Apr 2023 11:01:33 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6FCE820620 for ; Sat, 1 Apr 2023 08:00:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1680361234; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Fu7akkSrLzuIcCNp6h4mKqSfsMWoS6+H12wTLO1rBuc=; b=AwOU2EzRTP8uqHdfP6KvWG9qoFOBXexizeuC2YSKY9DluAZhk2LsdkDi7D4boEP1y46Qs7 jSEqvaGrZfeZpZhqGu42Na/BKn4kK8v3j1OiL20eryp72Y6LExUqwG6A4Sb6c4/bfdADvo izsGYqJq0KpUF0ZIU94SbSl8yvlnKEk= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-655-kMV-mPxANJiEzGhDF2hl3w-1; Sat, 01 Apr 2023 11:00:30 -0400 X-MC-Unique: kMV-mPxANJiEzGhDF2hl3w-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id BEDAF3815F66; Sat, 1 Apr 2023 15:00:29 +0000 (UTC) Received: from localhost.localdomain (unknown [10.39.192.49]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3B4E4483EC1; Sat, 1 Apr 2023 15:00:28 +0000 (UTC) From: Hans de Goede To: Mauro Carvalho Chehab , Sakari Ailus Cc: Hans de Goede , Kate Hsuan , Tsuchiya Yuto , Andy Shevchenko , Yury Luneff , Nable , andrey.i.trufanov@gmail.com, Fabio Aiuto , linux-media@vger.kernel.org, linux-staging@lists.linux.dev Subject: [PATCH 28/28] media: atomisp: gmin_platform: Add Lenovo Ideapad Miix 310 gmin_vars Date: Sat, 1 Apr 2023 16:59:26 +0200 Message-Id: <20230401145926.596216-29-hdegoede@redhat.com> In-Reply-To: <20230401145926.596216-1-hdegoede@redhat.com> References: <20230401145926.596216-1-hdegoede@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org The _DSM used to get sensor variables like CsiPort returns the wrong csi-port for the front OV2680 sensor on the Lenovo Ideapad Miix 310 add a gmin_vars DMI quirk / override setting the right CsiPort. Signed-off-by: Hans de Goede --- .../media/atomisp/pci/atomisp_gmin_platform.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/drivers/staging/media/atomisp/pci/atomisp_gmin_platform.c b/drivers/staging/media/atomisp/pci/atomisp_gmin_platform.c index f83de0ffaf16..efcfc133311f 100644 --- a/drivers/staging/media/atomisp/pci/atomisp_gmin_platform.c +++ b/drivers/staging/media/atomisp/pci/atomisp_gmin_platform.c @@ -304,7 +304,17 @@ static struct gmin_cfg_var surface3_vars[] = { {}, }; +static struct gmin_cfg_var lenovo_ideapad_miix_310_vars[] = { + /* _DSM contains the wrong CsiPort! */ + { "OVTI2680:01_CsiPort", "0" }, + {} +}; + static const struct dmi_system_id gmin_vars[] = { + /* + * These DMI ids where present when the atomisp driver was merged into + * drivers/staging and it is unclear if they are really necessary. + */ { .ident = "BYT-T FFD8", .matches = { @@ -341,6 +351,7 @@ static const struct dmi_system_id gmin_vars[] = { }, .driver_data = i8880_vars, }, + /* Later added DMI ids, these are confirmed to really be necessary! */ { .ident = "Surface 3", .matches = { @@ -348,6 +359,14 @@ static const struct dmi_system_id gmin_vars[] = { }, .driver_data = surface3_vars, }, + { + .ident = "Lenovo Ideapad Miix 310", + .matches = { + DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"), + DMI_MATCH(DMI_PRODUCT_VERSION, "MIIX 310-10"), + }, + .driver_data = lenovo_ideapad_miix_310_vars, + }, {} };