Patch Detail
Show a patch.
GET /api/1.1/patches/14414/?format=api
{ "id": 14414, "url": "https://patchwork.libcamera.org/api/1.1/patches/14414/?format=api", "web_url": "https://patchwork.libcamera.org/patch/14414/", "project": { "id": 1, "url": "https://patchwork.libcamera.org/api/1.1/projects/1/?format=api", "name": "libcamera", "link_name": "libcamera", "list_id": "libcamera_core", "list_email": "libcamera-devel@lists.libcamera.org", "web_url": "", "scm_url": "", "webscm_url": "" }, "msgid": "<3b61bb2d-1136-cf35-ba7a-724da9642855@gmail.com>", "date": "2021-10-29T11:50:31", "name": "[libcamera-devel] Fwd: Surface Go VCM type (was: Need to pass acpi_enforce_resources=lax on the Surface Go (version1))", "commit_ref": null, "pull_url": null, "state": "rfc", "archived": false, "hash": "9077bb11d39f7e65de64cea80997ea42479536d7", "submitter": { "id": 90, "url": "https://patchwork.libcamera.org/api/1.1/people/90/?format=api", "name": "Daniel Scally", "email": "djrscally@gmail.com" }, "delegate": null, "mbox": "https://patchwork.libcamera.org/patch/14414/mbox/", "series": [ { "id": 2679, "url": "https://patchwork.libcamera.org/api/1.1/series/2679/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=2679", "date": "2021-10-29T11:50:31", "name": "[libcamera-devel] Fwd: Surface Go VCM type (was: Need to pass acpi_enforce_resources=lax on the Surface Go (version1))", "version": 1, "mbox": "https://patchwork.libcamera.org/series/2679/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/14414/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/14414/checks/", "tags": {}, "headers": { "Return-Path": "<libcamera-devel-bounces@lists.libcamera.org>", "X-Original-To": "parsemail@patchwork.libcamera.org", "Delivered-To": "parsemail@patchwork.libcamera.org", "Received": [ "from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 75078BDB1C\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri, 29 Oct 2021 11:50:35 +0000 (UTC)", "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id AFFC0600BF;\n\tFri, 29 Oct 2021 13:50:34 +0200 (CEST)", "from mail-wr1-x431.google.com (mail-wr1-x431.google.com\n\t[IPv6:2a00:1450:4864:20::431])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 85D89600B8\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 29 Oct 2021 13:50:33 +0200 (CEST)", "by mail-wr1-x431.google.com with SMTP id d3so15751085wrh.8\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 29 Oct 2021 04:50:33 -0700 (PDT)", "from [192.168.0.14]\n\t(cpc141996-chfd3-2-0-cust928.12-3.cable.virginm.net. [86.13.91.161])\n\tby smtp.gmail.com with ESMTPSA id\n\t126sm8360786wmz.28.2021.10.29.04.50.32\n\t(version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128);\n\tFri, 29 Oct 2021 04:50:32 -0700 (PDT)" ], "Authentication-Results": "lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (2048-bit key;\n\tunprotected) header.d=gmail.com header.i=@gmail.com\n\theader.b=\"TJZKlful\"; dkim-atps=neutral", "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112;\n\th=subject:references:from:to:cc:message-id:date:user-agent\n\t:mime-version:in-reply-to:content-language;\n\tbh=nQxB7at3IpWv7uH7OreBIOApLAo8AGQz9NFGJWbRmkM=;\n\tb=TJZKlful/u3UwMXmDkloo+iWRWtD3J8cPw8M9yekuEEpQ0HK0HvQ7BZOc/qbylOoKs\n\t1wtEmPERnuasnZwPzMoPmY3WBejFsXC4+QHMWL4Ty69AcAgXhO2WG2SBKaPW9SzU2jNo\n\tIvdYEEuifmwVvsOElZFutTTgZGj+M8TN5se/QvxcA+ClZbgvzLblsfZVQc3WsNTaryMj\n\tiPFkgYXbL8E2PqPmg9E8ErpYCyJoBKa0jVJq8cdVFl4wDGb9fYZZMz4efsrsk/7op2Bs\n\tmm467Bxc/UlH1VaVOFeF9cJ+P1YIN/Xsgqo4tkyV6fA4X/SDsgZYGCC4BhQISYd8+3hV\n\t6pdw==", "X-Google-DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20210112;\n\th=x-gm-message-state:subject:references:from:to:cc:message-id:date\n\t:user-agent:mime-version:in-reply-to:content-language;\n\tbh=nQxB7at3IpWv7uH7OreBIOApLAo8AGQz9NFGJWbRmkM=;\n\tb=f6GoF/lpg20bckd58Rw4s5VDr+V0q0Z6noocAddead/uujfcMV6+AEHBxtt+wrEtc6\n\txQlFNg28LNyjPktlhSdl7w3hue7/2mwaHIE3MGGl0bxCMi1eTJ32EkADKwUSYDDbKxxW\n\tSBxZpmBCHLje3ltZZCcX0/7OlMMyOYlIqTHTg3WjgPFsFG7xphw5A/IE3SkK+EjnjJF+\n\tz/+eNGxq0iphD25e5VMdUie0/ZpE3Cs2Q19iqFHPOwSqYxLMVGqEB8AwVN7V11Sp7XBT\n\twbHjFtlEFk5JzwxVTGKsLfDshVg+Nghe9+iCFTDOkTc/4spPVPbBSi2vW+Ewqx+p9hcd\n\t3yDg==", "X-Gm-Message-State": "AOAM531rrhOtFe+VtJnWdqXx8Yh1smYF7WqYULDgJ1PIZMkprDOc3ytp\n\thE/MJ6KhowJJVsrDK7fMo4s=", "X-Google-Smtp-Source": "ABdhPJxLkhBJuX972t8FI484exrCFZgMZZjRUi166/juQO03EcJcL5/ZgsojMZwEBNDesST4uwKedw==", "X-Received": "by 2002:adf:f001:: with SMTP id j1mr8819024wro.351.1635508233089;\n\tFri, 29 Oct 2021 04:50:33 -0700 (PDT)", "References": "<e2312277-f967-7d3f-5ce9-fbb197d35fd6@gmail.com>", "From": "Daniel Scally <djrscally@gmail.com>", "To": "Hans de Goede <hdegoede@redhat.com>,\n\tLaurent Pinchart <laurent.pinchart@ideasonboard.com>", "X-Forwarded-Message-Id": "<e2312277-f967-7d3f-5ce9-fbb197d35fd6@gmail.com>", "Message-ID": "<3b61bb2d-1136-cf35-ba7a-724da9642855@gmail.com>", "Date": "Fri, 29 Oct 2021 12:50:31 +0100", "User-Agent": "Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101\n\tThunderbird/78.13.0", "MIME-Version": "1.0", "In-Reply-To": "<e2312277-f967-7d3f-5ce9-fbb197d35fd6@gmail.com>", "Content-Type": "multipart/mixed;\n\tboundary=\"------------330DDFD1B2FB7DA1D0319E03\"", "Content-Language": "en-US", "Subject": "[libcamera-devel] Fwd: Surface Go VCM type (was: Need to pass\n\tacpi_enforce_resources=lax on the Surface Go (version1))", "X-BeenThere": "libcamera-devel@lists.libcamera.org", "X-Mailman-Version": "2.1.29", "Precedence": "list", "List-Id": "<libcamera-devel.lists.libcamera.org>", "List-Unsubscribe": "<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>", "List-Archive": "<https://lists.libcamera.org/pipermail/libcamera-devel/>", "List-Post": "<mailto:libcamera-devel@lists.libcamera.org>", "List-Help": "<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>", "List-Subscribe": "<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>", "Cc": "libcamera-devel@lists.libcamera.org,\n\tAndy Shevchenko <andriy.shevchenko@linux.intel.com>,\n\tLinux Media Mailing List <linux-media@vger.kernel.org>", "Errors-To": "libcamera-devel-bounces@lists.libcamera.org", "Sender": "\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>" }, "content": "Hi all\n\n\n+CC linux-media and libcamera-devel, as it's probably a good time to\nbroaden this out. Also Andy because I'm hoping you can help :) The\nbackground of the discussion is about how we identify and enumerate\n(correctly, I.E. with a type matching the vcm driver's i2c_device_id,\nand there are a few different vcm's in scope which seem encoded in the\nSSDB buffer) which VCM module is linked to a sensor in Intel's IPU3\ncentric ACPI tables. The I2C address for the device is just a second\nI2cSerialBusV2 against the sensor's acpi device rather than a separate\none, which is no awkward. We also need to get firmware created for the\nVCM such that the sensor will link to it via the lens-focus property.\n\nOn 28/10/2021 09:57, Hans de Goede wrote:\n> Hi,\n>\n> On 10/28/21 10:49, Laurent Pinchart wrote:\n>> Hi Hans,\n>>\n>> On Thu, Oct 28, 2021 at 09:51:08AM +0200, Hans de Goede wrote:\n>>> On 10/28/21 09:10, Daniel Scally wrote:\n>>>> On 27/10/2021 15:16, Hans de Goede wrote:\n>>>>> On 10/27/21 12:07, Daniel Scally wrote:\n>>>>>> On 26/10/2021 11:14, Hans de Goede wrote:\n>>>>>>>>> So yesterday I already sorta guessed it would be the DW9714 because of\n>>>>>>>>> the 0x0c address and I tried:\n>>>>>>>>>\n>>>>>>>>> i2ctransfer -y 2 w2@0x0c 0x00 0x00\n>>>>>>>>>\n>>>>>>>>> And the transfer fails, while according to the driver that is a valid\n>>>>>>>>> value. So maybe we are missing a regulator enable? Or its not a DW9714.\n>>>>>>>>>\n>>>>>>>>> Also \"i2cdetect -y -r 2\" does not see anything at address 0x0c (but some of\n>>>>>>>>> these VCMs seem to be write only...) it does OTOH see an unknown device at\n>>>>>>>>> address 0x21.\n>>>>>>>> Well, when debugging the necessary TPS68470 settings I used a poor man's\n>>>>>>>> i2ctransfer on Windows whilst the camera was running to read the values\n>>>>>>>> that were set for both the PMIC and the camera sensor. Using the same\n>>>>>>>> program I can connect to and read values from a device at 0x0c,\n>>>>>> Just as further testing I dumped the contents of the device at 0x0c,\n>>>>>> which comes back as\n>>>>>>\n>>>>>> f1 1 2 1 61 0 40 60\n>>>>>>\n>>>>>> Byte 0 is given in the driver you linked as the ID field and expected to\n>>>>>> be f1. The driver controls focus by writing to the 3rd and 4th byte\n>>>>>> (with the 4th being the LSB); the only value that seemed to fluctuate\n>>>>>> when running windows and moving my hand in front of the sensor was byte\n>>>>>> 4 and testing it out I wrote values into that byte and the focus\n>>>>>> changes. So the device at 0x0c is definitely the vcm and it sure looks\n>>>>>> like it's the DW9719\n>>>>>>\n>>>>>> The device at 0x21 is only available on Windows when the camera is\n>>>>>> running, I thought it was quite likely that one of the \"spare\"\n>>>>>> regulators from the TPS68470. One line is called VCM, and sure enough\n>>>>>> it's enabled whilst the world-facing camera is running. I switched to\n>>>>>> linux and started streaming the back camera, then enabled that voltage\n>>>>>> regulator via i2ctransfer:\n>>>>>>\n>>>>>> sudo i2ctransfer 2 w2@0x4d 0x3c 0x6d\n>>>>>>\n>>>>>> sudo i2ctransfer 2 w2@0x4d 0x44 0x01\n>>>>>>\n>>>>>> And now i2cdetect shows the device at 0x0c on bus 2 - so we need more\n>>>>>> jiggery pokey to map that VCM regulator to this new device (once we've\n>>>>>> gotten it enumerated...) and the driver needs to have a tweak to call\n>>>>>> regulator get and do a power on at some point.\n>>>>> Awesome, great job on figuring this out!\n>>>>>\n>>>>> As you know I can spend $dayjob time on this, so I'll take on the job\n>>>>> of creating the i2c-client and hooking up the regulator in some\n>>>>> upstreamable manner.\n>>>> Okedokey cool. I'd probably start at the cio2-bridge, if only because we\n>>>> already have the adev there and the SSDB buffer loaded, so should be\n>>>> easy enough to add an enum for the vcm_type and a call to\n>>>> i2c_acpi_new_device()...bit of a weird place for that though I guess.\n>>> Ah, I was actually thinking about doing this int he int3472 code for\n>>> a number of reasons:\n>>>\n>>> 1. We already have the regulator_init_data there and we will need to\n>>> expand it for this.\n>>>\n>>> 2. It is sorta the central place where we deal with all this glue-stuff\n>> I'm not too sure about that. The INT3472 model the \"Intel camera PMIC\"\n>> (I don't remember the exact wording, but that's more or less how the\n>> device is described in Windows, and it matches the intent we see in the\n>> DSDT).\n> I agree that the INT3472 models the PMIC, or whatever discrete bits\n> which offer similar functionality.\n>\n>> Given that we already have cio2-bridge, and that it hooks up the\n>> sensor to the CIO2, it seems to me that it would be a better central\n>> place.\n> Ok, I was sorta expecting you to want to keep glue code like this\n> out of drivers/media. But I guess that only applies to putting ACPI\n> specific stuff in sensor drivers; and since the cio2-bridge code is\n> already x86/ACPI specific you are fine with adding ACPI code there?\n>\n> I'm fine with putting the VCM i2c-client instantiation in the\n> cio2-bridge code, that may also make it easier to tie the 2 together\n> at the media-controller level.\n\n\nHaving looked at this yesterday evening I'm more and more convinced it's\nnecessary. I hacked it into the ov8865 driver in the interim (just by\ncalling i2c_acpi_new_device() in probe) and then worked on that dw9719\ncode you found [1] to turn it into an i2c driver (attached, though still\nneeds a bit of work), which will successfully bind to the i2c client\nenumerated by that i2c_acpi_new_device() call. From there though it\nneeds a way for the v4l2 subdev to be matched to the sensor's subdev.\nThis can happen automatically by way of the lens-focus firmware property\nagainst the sensor - we currently build those in the cio2-bridge, so\nadding another software node for the VCM and creating a lens-focus\nproperty for the sensor's software_node with a pointer to the VCM's node\nseems like the best way to do that.\n\n\nTo throw a spanner in the works though; I noticed this delightful _CRS\nfor the OV9734 sensor of a Surface Laptop 1 earlier:\n\n\nMethod (_CRS, 0, Serialized) // _CRS: Current Resource Settings\n{\n Name (SBUF, ResourceTemplate ()\n {\n I2cSerialBusV2 (0x0036, ControllerInitiated, 0x00061A80,\n AddressingMode7Bit, \"\\\\_SB.PCI0.I2C2\",\n 0x00, ResourceConsumer, , Exclusive,\n )\n I2cSerialBusV2 (0x0050, ControllerInitiated, 0x00061A80,\n AddressingMode7Bit, \"\\\\_SB.PCI0.I2C2\",\n 0x00, ResourceConsumer, , Exclusive,\n )\n I2cSerialBusV2 (0x0051, ControllerInitiated, 0x00061A80,\n AddressingMode7Bit, \"\\\\_SB.PCI0.I2C2\",\n 0x00, ResourceConsumer, , Exclusive,\n )\n I2cSerialBusV2 (0x0052, ControllerInitiated, 0x00061A80,\n AddressingMode7Bit, \"\\\\_SB.PCI0.I2C2\",\n 0x00, ResourceConsumer, , Exclusive,\n )\n I2cSerialBusV2 (0x0053, ControllerInitiated, 0x00061A80,\n AddressingMode7Bit, \"\\\\_SB.PCI0.I2C2\",\n 0x00, ResourceConsumer, , Exclusive,\n )\n })\n Return (SBUF) /* \\_SB_.PCI0.I2C2.CAMF._CRS.SBUF */\n}\n\n\nHow do we know which one's the VCM when there's more than just two like\nthat? Andy: don't suppose you can shed any light there?\n\n[1]\nhttps://github.com/ZenfoneArea/android_kernel_asus_zenfone5/blob/master/linux/modules/camera/drivers/media/i2c/imx/dw9719.c", "diff": "From 0f0e2fa09b1bf8260f0d5f3753ebc27bd2c74ad1 Mon Sep 17 00:00:00 2001\nFrom: Daniel Scally <djrscally@gmail.com>\nDate: Thu, 28 Oct 2021 21:55:16 +0100\nSubject: [PATCH] media: i2c: Add driver for DW9719 VCM\n\nAdd a driver for the DW9719 VCM\n\nSigned-off-by: Daniel Scally <djrscally@gmail.com>\n---\n MAINTAINERS | 7 +\n drivers/media/i2c/Kconfig | 11 ++\n drivers/media/i2c/Makefile | 1 +\n drivers/media/i2c/dw9719.c | 376 +++++++++++++++++++++++++++++++++++++\n 4 files changed, 395 insertions(+)\n create mode 100644 drivers/media/i2c/dw9719.c\n\ndiff --git a/MAINTAINERS b/MAINTAINERS\nindex 891189cecd51..3db7124c24ee 100644\n--- a/MAINTAINERS\n+++ b/MAINTAINERS\n@@ -5647,6 +5647,13 @@ T:\tgit git://linuxtv.org/media_tree.git\n F:\tDocumentation/devicetree/bindings/media/i2c/dongwoon,dw9714.txt\n F:\tdrivers/media/i2c/dw9714.c\n \n+DONGWOON DW9714 LENS VOICE COIL DRIVER\n+M:\tDaniel Scally <djrscally@gmail.com>\n+L:\tlinux-media@vger.kernel.org\n+S:\tMaintained\n+T:\tgit git://linuxtv.org/media_tree.git\n+F:\tdrivers/media/i2c/dw9719.c\n+\n DONGWOON DW9768 LENS VOICE COIL DRIVER\n M:\tDongchun Zhu <dongchun.zhu@mediatek.com>\n L:\tlinux-media@vger.kernel.org\ndiff --git a/drivers/media/i2c/Kconfig b/drivers/media/i2c/Kconfig\nindex dee06f535f2c..505483e7b1df 100644\n--- a/drivers/media/i2c/Kconfig\n+++ b/drivers/media/i2c/Kconfig\n@@ -1396,6 +1396,17 @@ config VIDEO_DW9714\n \t capability. This is designed for linear control of\n \t voice coil motors, controlled via I2C serial interface.\n \n+config VIDEO_DW9719\n+\ttristate \"DW9719 lens voice coil support\"\n+\tdepends on I2C && VIDEO_V4L2\n+\tselect MEDIA_CONTROLLER\n+\tselect VIDEO_V4L2_SUBDEV_API\n+\tselect V4L2_ASYNC\n+\thelp\n+\t This is a driver for the DW9719 camera lens voice coil.\n+\t This is designed for linear control of voice coil motors,\n+\t controlled via I2C serial interface.\n+\n config VIDEO_DW9768\n \ttristate \"DW9768 lens voice coil support\"\n \tdepends on I2C && VIDEO_V4L2\ndiff --git a/drivers/media/i2c/Makefile b/drivers/media/i2c/Makefile\nindex 011e90c1a288..6a8f55b6c6b9 100644\n--- a/drivers/media/i2c/Makefile\n+++ b/drivers/media/i2c/Makefile\n@@ -24,6 +24,7 @@ obj-$(CONFIG_VIDEO_SAA6752HS) += saa6752hs.o\n obj-$(CONFIG_VIDEO_AD5820) += ad5820.o\n obj-$(CONFIG_VIDEO_AK7375) += ak7375.o\n obj-$(CONFIG_VIDEO_DW9714) += dw9714.o\n+obj-$(CONFIG_VIDEO_DW9719) += dw9719.o\n obj-$(CONFIG_VIDEO_DW9768) += dw9768.o\n obj-$(CONFIG_VIDEO_DW9807_VCM) += dw9807-vcm.o\n obj-$(CONFIG_VIDEO_ADV7170) += adv7170.o\ndiff --git a/drivers/media/i2c/dw9719.c b/drivers/media/i2c/dw9719.c\nnew file mode 100644\nindex 000000000000..9021caa915a3\n--- /dev/null\n+++ b/drivers/media/i2c/dw9719.c\n@@ -0,0 +1,376 @@\n+// SPDX-License-Identifier: GPL-2.0\n+// Copyright (c) 2012 Intel Corporation\n+\n+#include <linux/delay.h>\n+#include <linux/i2c.h>\n+#include <linux/pm_runtime.h>\n+#include <linux/regulator/consumer.h>\n+#include <linux/types.h>\n+\n+#include <media/v4l2-common.h>\n+#include <media/v4l2-ctrls.h>\n+#include <media/v4l2-subdev.h>\n+\n+#define DW9719_MAX_FOCUS_POS\t1023\n+#define DELAY_PER_STEP_NS\t1000000\n+#define DELAY_MAX_PER_STEP_NS\t(1000000 * 1023)\n+\n+#define DW9719_INFO\t\t\t0\n+#define DW9719_ID\t\t\t0xF1\n+#define DW9719_CONTROL\t\t\t2\n+#define DW9719_VCM_CURRENT\t\t3\n+\n+#define DW9719_MODE\t\t\t6\n+#define DW9719_VCM_FREQ\t\t\t7\n+\n+#define DW9719_MODE_SAC3\t\t0x40\n+#define DW9719_DEFAULT_VCM_FREQ\t\t0x60\n+#define DW9719_ENABLE_RINGING\t\t0x02\n+\n+#define to_dw9719_device(x) container_of(x, struct dw9719_device, sd)\n+\n+struct dw9719_device {\n+\tstruct device *dev;\n+\tstruct i2c_client *client;\n+\tstruct regulator *vdd;\n+\tstruct v4l2_subdev sd;\n+\n+\tstruct dw9719_v4l2_ctrls {\n+\t\tstruct v4l2_ctrl_handler handler;\n+\t\tstruct v4l2_ctrl *focus;\n+\t} ctrls;\n+};\n+\n+static int dw9719_i2c_rd8(struct i2c_client *client, u8 reg, u8 *val)\n+{\n+\tstruct i2c_msg msg[2];\n+\tu8 buf[2] = { reg };\n+\n+\tmsg[0].addr = client->addr;\n+\tmsg[0].flags = 0;\n+\tmsg[0].len = 1;\n+\tmsg[0].buf = buf;\n+\n+\tmsg[1].addr = client->addr;\n+\tmsg[1].flags = I2C_M_RD;\n+\tmsg[1].len = 1;\n+\tmsg[1].buf = &buf[1];\n+\t*val = 0;\n+\n+\tif (i2c_transfer(client->adapter, msg, 2) != 2)\n+\t\treturn -EIO;\n+\t*val = buf[1];\n+\n+\treturn 0;\n+}\n+\n+static int dw9719_i2c_wr8(struct i2c_client *client, u8 reg, u8 val)\n+{\n+\tstruct i2c_msg msg;\n+\tu8 buf[2] = { reg, val };\n+\n+\tmsg.addr = client->addr;\n+\tmsg.flags = 0;\n+\tmsg.len = sizeof(buf);\n+\tmsg.buf = buf;\n+\n+\tif (i2c_transfer(client->adapter, &msg, 1) != 1)\n+\t\treturn -EIO;\n+\n+\treturn 0;\n+}\n+\n+static int dw9719_i2c_wr16(struct i2c_client *client, u8 reg, u16 val)\n+{\n+\tstruct i2c_msg msg;\n+\tu8 buf[3] = { reg, (u8)(val >> 8), (u8)(val & 0xff)};\n+\n+\tmsg.addr = client->addr;\n+\tmsg.flags = 0;\n+\tmsg.len = sizeof(buf);\n+\tmsg.buf = buf;\n+\n+\tif (i2c_transfer(client->adapter, &msg, 1) != 1)\n+\t\treturn -EIO;\n+\n+\treturn 0;\n+}\n+\n+static int dw9719_detect(struct dw9719_device *dw9719)\n+{\n+\tint ret;\n+\tu8 val;\n+\n+\tret = dw9719_i2c_rd8(dw9719->client, DW9719_INFO, &val);\n+\tif (ret < 0)\n+\t\treturn ret;\n+\n+\tif (val != DW9719_ID) {\n+\t\tdev_err(dw9719->dev, \"Failed to detect correct id\\n\");\n+\t\tret = -ENXIO;\n+\t}\n+\n+\treturn 0;\n+}\n+\n+static int dw9719_power_down(struct dw9719_device *dw9719)\n+{\n+\treturn regulator_disable(dw9719->vdd);\n+}\n+\n+static int dw9719_power_up(struct dw9719_device *dw9719)\n+{\n+\tint ret;\n+\n+\tret = regulator_enable(dw9719->vdd);\n+\tif (ret)\n+\t\treturn ret;\n+\n+\t/* Jiggle SCL pin to wake up device */\n+\tret = dw9719_i2c_wr8(dw9719->client, DW9719_CONTROL, 1);\n+\n+\t/* Need 100us to transit from SHUTDOWN to STANDBY*/\n+\tusleep_range(100, 1000);\n+\n+\tret = dw9719_i2c_wr8(dw9719->client, DW9719_CONTROL,\n+\t\t\t DW9719_ENABLE_RINGING);\n+\tif (ret < 0)\n+\t\tgoto fail_powerdown;\n+\n+\tret = dw9719_i2c_wr8(dw9719->client, DW9719_MODE, DW9719_MODE_SAC3);\n+\tif (ret < 0)\n+\t\tgoto fail_powerdown;\n+\n+\tret = dw9719_i2c_wr8(dw9719->client, DW9719_VCM_FREQ,\n+\t\t\t DW9719_DEFAULT_VCM_FREQ);\n+\tif (ret < 0)\n+\t\tgoto fail_powerdown;\n+\n+\treturn 0;\n+\n+fail_powerdown:\n+\tdw9719_power_down(dw9719);\n+\treturn ret;\n+}\n+\n+static int __maybe_unused dw9719_suspend(struct device *dev)\n+{\n+\tstruct v4l2_subdev *sd = dev_get_drvdata(dev);\n+\tstruct dw9719_device *dw9719 = to_dw9719_device(sd);\n+\n+\treturn dw9719_power_up(dw9719);\n+}\n+\n+static int __maybe_unused dw9719_resume(struct device *dev)\n+{\n+\tstruct v4l2_subdev *sd = dev_get_drvdata(dev);\n+\tstruct dw9719_device *dw9719 = to_dw9719_device(sd);\n+\n+\treturn dw9719_power_down(dw9719);\n+}\n+\n+static int dw9719_t_focus_abs(struct dw9719_device *dw9719, s32 value)\n+{\n+\tint ret;\n+\n+\tvalue = clamp(value, 0, DW9719_MAX_FOCUS_POS);\n+\tret = dw9719_i2c_wr16(dw9719->client, DW9719_VCM_CURRENT, value);\n+\tif (ret < 0)\n+\t\treturn ret;\n+\n+\treturn 0;\n+}\n+\n+static int dw9719_t_focus_rel(struct dw9719_device *dw9719, s32 value)\n+{\n+\ts32 cur_val = dw9719->ctrls.focus->val;\n+\n+\treturn dw9719_t_focus_abs(dw9719, cur_val + value);\n+}\n+\n+static int dw9719_set_ctrl(struct v4l2_ctrl *ctrl)\n+{\n+\tstruct dw9719_device *dw9719 = container_of(ctrl->handler,\n+\t\t\t\t\t\t struct dw9719_device,\n+\t\t\t\t\t\t ctrls.handler);\n+\tint ret;\n+\n+\t/* Only apply changes to the controls if the device is powered up */\n+\tif (!pm_runtime_get_if_in_use(dw9719->dev))\n+\t\treturn 0;\n+\n+\tswitch (ctrl->id) {\n+\tcase V4L2_CID_FOCUS_ABSOLUTE:\n+\t\tret = dw9719_t_focus_abs(dw9719, ctrl->val);\n+\t\tbreak;\n+\tcase V4L2_CID_FOCUS_RELATIVE:\n+\t\tret = dw9719_t_focus_rel(dw9719, ctrl->val);\n+\t\tbreak;\n+\tdefault:\n+\t\tret = -EINVAL;\n+\t}\n+\n+\tpm_runtime_put(dw9719->dev);\n+\n+\treturn ret;\n+}\n+\n+static const struct v4l2_ctrl_ops dw9719_ctrl_ops = {\n+\t.s_ctrl = dw9719_set_ctrl,\n+};\n+\n+static int dw9719_open(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh)\n+{\n+\treturn pm_runtime_resume_and_get(sd->dev);\n+}\n+\n+static int dw9719_close(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh)\n+{\n+\tpm_runtime_put(sd->dev);\n+\n+\treturn 0;\n+}\n+\n+static const struct v4l2_subdev_internal_ops dw9719_internal_ops = {\n+\t.open = dw9719_open,\n+\t.close = dw9719_close,\n+};\n+\n+static int dw9719_init_controls(struct dw9719_device *dw9719)\n+{\n+\tconst struct v4l2_ctrl_ops *ops = &dw9719_ctrl_ops;\n+\tint ret;\n+\n+\tret = v4l2_ctrl_handler_init(&dw9719->ctrls.handler, 1);\n+\tif (ret)\n+\t\treturn ret;\n+\n+\tdw9719->ctrls.focus = v4l2_ctrl_new_std(&dw9719->ctrls.handler, ops,\n+\t\t\t\t\t\tV4L2_CID_FOCUS_ABSOLUTE, 0,\n+\t\t\t\t\t\tDW9719_MAX_FOCUS_POS, 1, 0);\n+\n+\tif (dw9719->ctrls.handler.error) {\n+\t\tdev_err(dw9719->dev, \"Error initialising v4l2 ctrls\\n\");\n+\t\tret = dw9719->ctrls.handler.error;\n+\t\tgoto err_free_handler;\n+\t}\n+\n+\treturn ret;\n+\n+err_free_handler:\n+\tv4l2_ctrl_handler_free(&dw9719->ctrls.handler);\n+\treturn ret;\n+}\n+\n+static const struct v4l2_subdev_ops dw9719_ops = { };\n+\n+static int dw9719_probe(struct i2c_client *client)\n+{\n+\tstruct dw9719_device *dw9719;\n+\tint ret;\n+\n+\tdw9719 = devm_kzalloc(&client->dev, sizeof(*dw9719), GFP_KERNEL);\n+\tif (!dw9719)\n+\t\treturn -ENOMEM;\n+\n+\tdw9719->client = client;\n+\tdw9719->dev = &client->dev;\n+\n+\tdw9719->vdd = devm_regulator_get(&client->dev, \"vdd\");\n+\tif (IS_ERR(dw9719->vdd)) {\n+\t\tdev_err(&client->dev, \"Error getting regulator\\n\");\n+\t\treturn PTR_ERR(dw9719->vdd);\n+\t}\n+\n+\tv4l2_i2c_subdev_init(&dw9719->sd, client, &dw9719_ops);\n+\tdw9719->sd.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE;\n+\tdw9719->sd.internal_ops = &dw9719_internal_ops;\n+\n+\tret = dw9719_init_controls(dw9719);\n+\tif (ret)\n+\t\treturn ret;\n+\n+\tret = media_entity_pads_init(&dw9719->sd.entity, 0, NULL);\n+\tif (ret < 0)\n+\t\tgoto err_free_ctrl_handler;\n+\n+\tdw9719->sd.entity.function = MEDIA_ENT_F_LENS;\n+\n+\t/*\n+\t * We need the driver to work in the event that pm runtime is disable in\n+\t * the kernel, so power up and verify the chip now. In the event that\n+\t * runtime pm is disabled this will leave the chip on, so that the lens\n+\t * will work.\n+\t */\n+\n+\tret = dw9719_power_up(dw9719);\n+\tif (ret)\n+\t\tgoto err_cleanup_media;\n+\n+\tret = dw9719_detect(dw9719);\n+\tif (ret)\n+\t\tgoto err_powerdown;\n+\n+\tpm_runtime_set_active(&client->dev);\n+\tpm_runtime_get_noresume(&client->dev);\n+\tpm_runtime_enable(&client->dev);\n+\n+\tret = v4l2_async_register_subdev(&dw9719->sd);\n+\tif (ret < 0)\n+\t\tgoto err_pm_runtime;\n+\n+\tpm_runtime_set_autosuspend_delay(&client->dev, 1000);\n+\tpm_runtime_use_autosuspend(&client->dev);\n+\tpm_runtime_put_autosuspend(&client->dev);\n+\n+\treturn ret;\n+\n+err_pm_runtime:\n+\tpm_runtime_disable(&client->dev);\n+\tpm_runtime_put_noidle(&client->dev);\n+err_powerdown:\n+\tdw9719_power_down(dw9719);\n+err_cleanup_media:\n+\tmedia_entity_cleanup(&dw9719->sd.entity);\n+err_free_ctrl_handler:\n+\tv4l2_ctrl_handler_free(&dw9719->ctrls.handler);\n+\n+\treturn ret;\n+}\n+\n+static int dw9719_remove(struct i2c_client *client)\n+{\n+\tstruct v4l2_subdev *sd = i2c_get_clientdata(client);\n+\tstruct dw9719_device *dw9719 = container_of(sd, struct dw9719_device,\n+\t\t\t\t\t\t sd);\n+\n+\tv4l2_async_unregister_subdev(sd);\n+\tv4l2_ctrl_handler_free(&dw9719->ctrls.handler);\n+\tmedia_entity_cleanup(&dw9719->sd.entity);\n+\n+\treturn 0;\n+}\n+\n+static const struct i2c_device_id dw9719_id_table[] = {\n+\t{ \"dw9719\" },\n+\t{ }\n+};\n+MODULE_DEVICE_TABLE(i2c, dw9719_id_table);\n+\n+static const struct dev_pm_ops dw9719_pm_ops = {\n+\tSET_RUNTIME_PM_OPS(dw9719_suspend, dw9719_resume, NULL)\n+};\n+\n+static struct i2c_driver dw9719_i2c_driver = {\n+\t.driver = {\n+\t\t.name = \"dw9719\",\n+\t\t.pm = &dw9719_pm_ops,\n+\t},\n+\t.probe_new = dw9719_probe,\n+\t.remove = dw9719_remove,\n+\t.id_table = dw9719_id_table,\n+};\n+module_i2c_driver(dw9719_i2c_driver);\n+\n+MODULE_DESCRIPTION(\"DW9719 VCM Driver\");\n+MODULE_LICENSE(\"GPL\");\n-- \n2.25.1\n\n\n", "prefixes": [ "libcamera-devel" ] }