From patchwork Thu Jun 15 14:13:36 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: 13281315 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 6D9D6EB64DC for ; Thu, 15 Jun 2023 14:15:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344996AbjFOOP2 (ORCPT ); Thu, 15 Jun 2023 10:15:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43244 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344993AbjFOOPX (ORCPT ); Thu, 15 Jun 2023 10:15:23 -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 EF6DA273E for ; Thu, 15 Jun 2023 07:14:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1686838473; 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=ojB8W48nW4hg1D3hfUlGo9qqdSiklyUlr6Ve23HfkGw=; b=TUGtpenFNlxIecrVBtjF7U3QUlHJnWsRDpChf0PNV+oUWIZTIJ2xkaexz6OyEnWW+kK1Ar xgeGUvqXm+UQMAzZKI211YeId69Mqn+mfKwOK5BnNlczKV9ATHWph6iYaCEIfvTchSI1PD 6geVCa/QyRlv+PpLWszkU4yuoTbx26s= 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-473-O9o08K6YO5OoZwZFb6lJTg-1; Thu, 15 Jun 2023 10:14:28 -0400 X-MC-Unique: O9o08K6YO5OoZwZFb6lJTg-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 12D32831026; Thu, 15 Jun 2023 14:14:11 +0000 (UTC) Received: from shalem.redhat.com (unknown [10.39.192.154]) by smtp.corp.redhat.com (Postfix) with ESMTP id F1EF048FB01; Thu, 15 Jun 2023 14:14:09 +0000 (UTC) From: Hans de Goede To: Sakari Ailus , Daniel Scally Cc: Hans de Goede , Mauro Carvalho Chehab , Andy Shevchenko , Kate Hsuan , Tommaso Merciai , linux-media@vger.kernel.org Subject: [PATCH v2 15/28] media: ov2680: Add support for 19.2 MHz clock Date: Thu, 15 Jun 2023 16:13:36 +0200 Message-Id: <20230615141349.172363-16-hdegoede@redhat.com> In-Reply-To: <20230615141349.172363-1-hdegoede@redhat.com> References: <20230615141349.172363-1-hdegoede@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.9 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org Most x86/ACPI boards use the ov2680 with a 19.2 MHz xvclk, rather then the expected 24MHz, add support for this. Compensate for the lower clk by setting a higher PLL multiplier of 69 when using 19.2 MHz vs the default multiplier of 55 for a 24MHz xvclk. Signed-off-by: Hans de Goede --- drivers/media/i2c/ov2680.c | 41 +++++++++++++++++++++++++++++++------- 1 file changed, 34 insertions(+), 7 deletions(-) diff --git a/drivers/media/i2c/ov2680.c b/drivers/media/i2c/ov2680.c index a6a83f0e53f3..d4ef34859914 100644 --- a/drivers/media/i2c/ov2680.c +++ b/drivers/media/i2c/ov2680.c @@ -27,14 +27,13 @@ #include #include -#define OV2680_XVCLK_VALUE 24000000 - #define OV2680_CHIP_ID 0x2680 #define OV2680_REG_STREAM_CTRL CCI_REG8(0x0100) #define OV2680_REG_SOFT_RESET CCI_REG8(0x0103) #define OV2680_REG_CHIP_ID CCI_REG16(0x300a) +#define OV2680_REG_PLL_MULTIPLIER CCI_REG16(0x3081) #define OV2680_REG_EXPOSURE_PK CCI_REG24(0x3500) #define OV2680_REG_R_MANUAL CCI_REG8(0x3503) @@ -69,6 +68,21 @@ static const char * const ov2680_supply_name[] = { #define OV2680_NUM_SUPPLIES ARRAY_SIZE(ov2680_supply_name) +enum { + OV2680_19_2_MHZ, + OV2680_24_MHZ, +}; + +static const unsigned long ov2680_xvclk_freqs[] = { + [OV2680_19_2_MHZ] = 19200000, + [OV2680_24_MHZ] = 24000000, +}; + +static const u8 ov2680_pll_multipliers[] = { + [OV2680_19_2_MHZ] = 69, + [OV2680_24_MHZ] = 55, +}; + struct ov2680_mode_info { const char *name; enum ov2680_mode_id id; @@ -95,6 +109,7 @@ struct ov2680_dev { struct media_pad pad; struct clk *xvclk; u32 xvclk_freq; + u8 pll_mult; struct regulator_bulk_data supplies[OV2680_NUM_SUPPLIES]; struct gpio_desc *pwdn_gpio; @@ -284,6 +299,11 @@ static int ov2680_stream_enable(struct ov2680_dev *sensor) { int ret; + ret = cci_write(sensor->regmap, OV2680_REG_PLL_MULTIPLIER, + sensor->pll_mult, NULL); + if (ret < 0) + return ret; + ret = regmap_multi_reg_write(sensor->regmap, ov2680_mode_init_data.reg_data, ov2680_mode_init_data.reg_data_size); @@ -699,7 +719,7 @@ static int ov2680_parse_dt(struct ov2680_dev *sensor) struct device *dev = sensor->dev; struct gpio_desc *gpio; unsigned int rate = 0; - int ret; + int i, ret; /* * The pin we want is named XSHUTDN in the datasheet. Linux sensor @@ -747,12 +767,19 @@ static int ov2680_parse_dt(struct ov2680_dev *sensor) } sensor->xvclk_freq = rate ?: clk_get_rate(sensor->xvclk); - if (sensor->xvclk_freq != OV2680_XVCLK_VALUE) { - dev_err(dev, "wrong xvclk frequency %d HZ, expected: %d Hz\n", - sensor->xvclk_freq, OV2680_XVCLK_VALUE); - return -EINVAL; + + for (i = 0; i < ARRAY_SIZE(ov2680_xvclk_freqs); i++) { + if (sensor->xvclk_freq == ov2680_xvclk_freqs[i]) + break; } + if (i == ARRAY_SIZE(ov2680_xvclk_freqs)) + return dev_err_probe(dev, -EINVAL, + "unsupported xvclk frequency %d Hz\n", + sensor->xvclk_freq); + + sensor->pll_mult = ov2680_pll_multipliers[i]; + return 0; }