From patchwork Wed Jun 12 01:20:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?WmhpIE1hbyAo5q+b5pm6KQ==?= X-Patchwork-Id: 804443 Received: from mailgw01.mediatek.com (unknown [60.244.123.138]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id ACF001FA1; Wed, 12 Jun 2024 01:20:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=60.244.123.138 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718155256; cv=none; b=pEoyYzGq1uxK2JKYujZrggfL5gZopJCagWC4isA9erGr29W0qCd0M9nX76kbFMTNjaGi1VBZ4KiERFYCHTPzBagezgwsVjgqL2RxRaTXLzCl9nmFL3u91Q9h4F4/oug4XRWO1QStdDrul1xwCKATXYiiJpwD4E+XeQasY39lftk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718155256; c=relaxed/simple; bh=YH/5hS5eoOqn19rlvn3PVu1w9CXf7mwCHSq8CKHihPc=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=hU/Vw082XAtJyOi5cqdHOdaNGn0nTgcFgSYQSki6CKZN3PusuN1tz1EIPBsRC6Tq5KbouJTHBRVyvFPGI6F54BoMjQyU+WwNSMt/T2FwW6GQKVTL36O0nX/RPomAYcucO7fHjQwrFGNurO9Zebb6Uil0r8+OOM2gsUIU96JVcwU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=mediatek.com; spf=pass smtp.mailfrom=mediatek.com; dkim=pass (1024-bit key) header.d=mediatek.com header.i=@mediatek.com header.b=RaKc9rZW; arc=none smtp.client-ip=60.244.123.138 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=mediatek.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=mediatek.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=mediatek.com header.i=@mediatek.com header.b="RaKc9rZW" X-UUID: 00bc8b62285a11efa54bbfbb386b949c-20240612 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mediatek.com; s=dk; h=Content-Type:Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:CC:To:From; bh=csC8MkY3DsP6u4dCYvKlXOs1d6t+aJumI4zvk6wekyA=; b=RaKc9rZWqRQXx4kGXRSyHb6fXYooS8lIZ7N77vbb8dVXCMWYayDjAW+vJlEeDQUCvXAD5KMq2j+VCSQnV8HDuR9mBMrtBtycYraAVAQVDAk7Da91XhjInLChuNlfRmp2+pXVqrSuhx8prC8vDYKGa1YukDomHR4lMxYge9Mif9I=; X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.39, REQID:ac50ee48-4dbd-48aa-82ab-d7b8acd2358f, IP:0, U RL:25,TC:0,Content:0,EDM:0,RT:0,SF:0,FILE:0,BULK:0,RULE:Release_Ham,ACTION :release,TS:25 X-CID-META: VersionHash:393d96e, CLOUDID:2730f984-4f93-4875-95e7-8c66ea833d57, B ulkID:nil,BulkQuantity:0,Recheck:0,SF:102,TC:nil,Content:0,EDM:-3,IP:nil,U RL:11|1,File:nil,RT:nil,Bulk:nil,QS:nil,BEC:nil,COL:0,OSI:0,OSA:0,AV:0,LES :1,SPR:NO,DKR:0,DKP:0,BRR:0,BRE:0,ARC:0 X-CID-BVR: 0 X-CID-BAS: 0,_,0,_ X-CID-FACTOR: TF_CID_SPAM_ULN,TF_CID_SPAM_SNR X-UUID: 00bc8b62285a11efa54bbfbb386b949c-20240612 Received: from mtkmbs13n2.mediatek.inc [(172.21.101.108)] by mailgw01.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 256/256) with ESMTP id 561728880; Wed, 12 Jun 2024 09:20:49 +0800 Received: from mtkmbs11n2.mediatek.inc (172.21.101.187) by MTKMBS09N2.mediatek.inc (172.21.101.94) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.26; Tue, 11 Jun 2024 18:20:48 -0700 Received: from mhfsdcap04.gcn.mediatek.inc (10.17.3.154) by mtkmbs11n2.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.2.1118.26 via Frontend Transport; Wed, 12 Jun 2024 09:20:46 +0800 From: Zhi Mao To: Mauro Carvalho Chehab , Rob Herring , Krzysztof Kozlowski , Conor Dooley CC: Matthias Brugger , AngeloGioacchino Del Regno , Zhi Mao , Philipp Zabel , Laurent Pinchart , Heiko Stuebner , Sakari Ailus , Hans Verkuil , Hans de Goede , Tomi Valkeinen , Alain Volmat , Paul Elder , Mehdi Djait , Andy Shevchenko , Bingbu Cao , , , , , , , , , <10572168@qq.com>, Krzysztof Kozlowski Subject: [PATCH v3 1/3] media: dt-bindings: i2c: add Giantec GT97xx VCM Date: Wed, 12 Jun 2024 09:20:17 +0800 Message-ID: <20240612012019.19078-2-zhi.mao@mediatek.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240612012019.19078-1-zhi.mao@mediatek.com> References: <20240612012019.19078-1-zhi.mao@mediatek.com> Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MTK: N Add YAML device tree binding for GT9768 & GT9769 VCM, and the relevant MAINTAINERS entries. Reviewed-by: Krzysztof Kozlowski Signed-off-by: Zhi Mao --- .../bindings/media/i2c/giantec,gt9769.yaml | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 Documentation/devicetree/bindings/media/i2c/giantec,gt9769.yaml diff --git a/Documentation/devicetree/bindings/media/i2c/giantec,gt9769.yaml b/Documentation/devicetree/bindings/media/i2c/giantec,gt9769.yaml new file mode 100644 index 000000000000..92d603acc53c --- /dev/null +++ b/Documentation/devicetree/bindings/media/i2c/giantec,gt9769.yaml @@ -0,0 +1,55 @@ +# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) +# Copyright (c) 2020 MediaTek Inc. +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/media/i2c/giantec,gt9769.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Giantec Semiconductor, Crop. GT9768 & GT9769 Voice Coil Motor (VCM) + +maintainers: + - Zhi Mao + +description: + The Giantec GT9768 & GT9769 is a 10-bit DAC with current sink capability. + The DAC is controlled via I2C bus that operates at clock rates up to 1MHz. + This chip integrates Advanced Actuator Control (AAC) technology + and is intended for driving voice coil lens in camera modules. + +properties: + compatible: + enum: + - giantec,gt9768 + - giantec,gt9769 + + reg: + maxItems: 1 + + vin-supply: true + + vdd-supply: true + +required: + - compatible + - reg + - vin-supply + - vdd-supply + +additionalProperties: false + +examples: + - | + i2c { + #address-cells = <1>; + #size-cells = <0>; + + camera-lens@c { + compatible = "giantec,gt9769"; + reg = <0x0c>; + + vin-supply = <>97xx_vin>; + vdd-supply = <>97xx_vdd>; + }; + }; + +... From patchwork Wed Jun 12 01:20:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?WmhpIE1hbyAo5q+b5pm6KQ==?= X-Patchwork-Id: 803754 Received: from mailgw02.mediatek.com (unknown [210.61.82.184]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 003394696; Wed, 12 Jun 2024 01:21:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=210.61.82.184 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718155280; cv=none; b=IYXZvoXM4847eNJT4q8Kn4mGoK40OYKXZBzwweGXR929FI5j6c0nOK9EE7T9ve6tJ8OVNyLJ/nd+Joo+L9qoHJAbrLU9bWhe07Ie76knx+Ooe0pYbUE3M0DpZB+cpHMz5TMrJsv2itKKfTGxnPdlb8b4yk1VIXQ6tzwMpfTKLho= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718155280; c=relaxed/simple; bh=6ziPJhnVL0eAaDt37WYy4IHioawmjX1wjC/m7wI++Cg=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=HEfYfeTUUwDZ9ZqDSGdOtrpYuSl3oqu4XesJcIt25DCMafBbdgo9V7DyDmyraKgxGRX0Z7eYDqn/uNPE5cWCI+6z6a+mCV2IUCiNSHB4xuvrK6Y6TpTyOTGq/qmDf7iMKmlne+eTZsgqYJmq9bEL9YrUNWPRsgchZ7xbaVHxE4c= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=mediatek.com; spf=pass smtp.mailfrom=mediatek.com; dkim=pass (1024-bit key) header.d=mediatek.com header.i=@mediatek.com header.b=q5E3+nol; arc=none smtp.client-ip=210.61.82.184 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=mediatek.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=mediatek.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=mediatek.com header.i=@mediatek.com header.b="q5E3+nol" X-UUID: 0b2e3e06285a11efa22eafcdcd04c131-20240612 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mediatek.com; s=dk; h=Content-Type:Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:CC:To:From; bh=ffRulny4vgDi0nVyFzV6vjEQL14X2dtE96SJnoGAa24=; b=q5E3+noltPeRyaorsBQepSSmzmEaMozzYGgM5EowOQp41UoidlHDFPyx6SpRKCGXFEFPv3U8Oqtx2svH0w4DsXLQk+5ffwj+bneItAjOgpAfFo5J2EM9D1cgoeHBZ/Vu7Efq8kCmVJQPUu+Q2GIJA9RJTGCSA49CUz3/ZmHjHRQ=; X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.39, REQID:0147ea96-9a05-4e9c-9b55-af8852591fc8, IP:0, U RL:0,TC:0,Content:-25,EDM:0,RT:0,SF:0,FILE:0,BULK:0,RULE:Release_Ham,ACTIO N:release,TS:-25 X-CID-META: VersionHash:393d96e, CLOUDID:0731f984-4f93-4875-95e7-8c66ea833d57, B ulkID:nil,BulkQuantity:0,Recheck:0,SF:102,TC:nil,Content:0,EDM:-3,IP:nil,U RL:0,File:nil,RT:nil,Bulk:nil,QS:nil,BEC:nil,COL:0,OSI:0,OSA:0,AV:0,LES:1, SPR:NO,DKR:0,DKP:0,BRR:0,BRE:0,ARC:0 X-CID-BVR: 0 X-CID-BAS: 0,_,0,_ X-CID-FACTOR: TF_CID_SPAM_SNR X-UUID: 0b2e3e06285a11efa22eafcdcd04c131-20240612 Received: from mtkmbs11n2.mediatek.inc [(172.21.101.187)] by mailgw02.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 256/256) with ESMTP id 1080805115; Wed, 12 Jun 2024 09:21:07 +0800 Received: from mtkmbs11n2.mediatek.inc (172.21.101.187) by MTKMBS14N2.mediatek.inc (172.21.101.76) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.26; Wed, 12 Jun 2024 09:21:04 +0800 Received: from mhfsdcap04.gcn.mediatek.inc (10.17.3.154) by mtkmbs11n2.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.2.1118.26 via Frontend Transport; Wed, 12 Jun 2024 09:21:03 +0800 From: Zhi Mao To: Mauro Carvalho Chehab , Rob Herring , Krzysztof Kozlowski , Conor Dooley CC: Matthias Brugger , AngeloGioacchino Del Regno , Zhi Mao , Philipp Zabel , Laurent Pinchart , Heiko Stuebner , Sakari Ailus , Hans Verkuil , Hans de Goede , "Tomi Valkeinen" , Alain Volmat , Paul Elder , "Mehdi Djait" , Andy Shevchenko , Bingbu Cao , , , , , , , , , <10572168@qq.com> Subject: [PATCH v3 2/3] media: i2c: Add GT97xx VCM driver Date: Wed, 12 Jun 2024 09:20:18 +0800 Message-ID: <20240612012019.19078-3-zhi.mao@mediatek.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240612012019.19078-1-zhi.mao@mediatek.com> References: <20240612012019.19078-1-zhi.mao@mediatek.com> Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-TM-AS-Product-Ver: SMEX-14.0.0.3152-9.1.1006-23728.005 X-TM-AS-Result: No-10--12.187700-8.000000 X-TMASE-MatchedRID: AH+13/h3BteuhCBFl/b63m3NvezwBrVmK2i9pofGVSvvSbc8qoHu0V/2 zKXxjR59dilmHfdk4Tzvl3F3WAnK8EgYkh+Pnbt/uIwLnB3Aqp2WHGENdT+VP8SiwizsgluQEXF HklABLo4L/rn9cjOlgV7bEojljVTyWELDcKwGO25AwvZYEy8IBQeCHewokHM/vDa284z78ydw/+ ihHRzmFb15S5EvoJigtauPEYeMK/UWS/lqyBekk5A6S0SjvcYUO69hrW/YgWFFDR0AKGX+XLwpt VrHh+Adp7efYlhEjtp+WREjl9udEraFzPn1CONWbT3mGmWPpNe1X9aaML89nAAheUymmndfy8c6 MKvt/YFGwPwv8DvB4fmpHsnYKi0GMxtmVplmiEJ1e7Xbb6Im2rqGBW9J0YqjH1bhq4z+yfQHn+R aCrVBsxSfg36pk/y2AnalUMYc0As6khM4kbcJpWwbuvhCHs3cfS0Ip2eEHnz3IzXlXlpamPoLR4 +zsDTtyMdyHKes7lu2OGUOke/w9/4LRe2Jwj39kb0e1ezQRJz2KjbmbVY7bQ== X-TM-AS-User-Approved-Sender: No X-TM-AS-User-Blocked-Sender: No X-TMASE-Result: 10--12.187700-8.000000 X-TMASE-Version: SMEX-14.0.0.3152-9.1.1006-23728.005 X-TM-SNTS-SMTP: 5FF69B637B02E76214D4EC8258953E6ECB4BC3F86640935CC8A9F9B2E3674D952000:8 X-MTK: N Add a V4L2 sub-device driver for Giantec GT97xx VCM. Signed-off-by: Zhi Mao --- drivers/media/i2c/Kconfig | 13 ++ drivers/media/i2c/Makefile | 1 + drivers/media/i2c/gt97xx.c | 436 +++++++++++++++++++++++++++++++++++++ 3 files changed, 450 insertions(+) create mode 100644 drivers/media/i2c/gt97xx.c diff --git a/drivers/media/i2c/Kconfig b/drivers/media/i2c/Kconfig index 5498128773c7..9976f02575a3 100644 --- a/drivers/media/i2c/Kconfig +++ b/drivers/media/i2c/Kconfig @@ -772,6 +772,19 @@ config VIDEO_DW9807_VCM capability. This is designed for linear control of voice coil motors, controlled via I2C serial interface. +config VIDEO_GT97XX + tristate "GT97xx lens voice coil support" + depends on I2C && VIDEO_DEV + select MEDIA_CONTROLLER + select VIDEO_V4L2_SUBDEV_API + select V4L2_FWNODE + select V4L2_CCI_I2C + help + This is a driver for the GT97xx camera lens voice coil. + GT97xx is a 10 bit DAC with 100mA output current sink + capability. It is designed for linear control of + voice coil motors, controlled via I2C serial interface. + endmenu menu "Flash devices" diff --git a/drivers/media/i2c/Makefile b/drivers/media/i2c/Makefile index d1403e3273ca..0009d3d6d6af 100644 --- a/drivers/media/i2c/Makefile +++ b/drivers/media/i2c/Makefile @@ -39,6 +39,7 @@ obj-$(CONFIG_VIDEO_DW9807_VCM) += dw9807-vcm.o obj-$(CONFIG_VIDEO_ET8EK8) += et8ek8/ obj-$(CONFIG_VIDEO_GC0308) += gc0308.o obj-$(CONFIG_VIDEO_GC2145) += gc2145.o +obj-$(CONFIG_VIDEO_GT97XX) += gt97xx.o obj-$(CONFIG_VIDEO_HI556) += hi556.o obj-$(CONFIG_VIDEO_HI846) += hi846.o obj-$(CONFIG_VIDEO_HI847) += hi847.o diff --git a/drivers/media/i2c/gt97xx.c b/drivers/media/i2c/gt97xx.c new file mode 100644 index 000000000000..ccae190ffba6 --- /dev/null +++ b/drivers/media/i2c/gt97xx.c @@ -0,0 +1,436 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Driver for Giantec gt97xx VCM lens device + * + * Copyright 2024 MediaTek + * + * Zhi Mao + */ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +/* gt97xx chip info register and name */ +#define GT97XX_IC_INFO_REG CCI_REG8(0x00) +#define GT9768_ID 0xE9 +#define GT9769_ID 0xE1 +#define GT97XX_NAME "gt97xx" + +/* + * Ring control and Power control register + * Bit[1] RING_EN + * 0: Direct mode + * 1: AAC mode (ringing control mode) + * Bit[0] PD + * 0: Normal operation mode + * 1: Power down mode + * requires waiting time after PD reset takes place. + */ +#define GT97XX_RING_PD_CONTROL_REG CCI_REG8(0x02) +#define GT97XX_PD_MODE_OFF 0x00 +#define GT97XX_PD_MODE_EN BIT(0) +#define GT97XX_AAC_MODE_EN BIT(1) + +/* + * DAC is a 10bit address to control the VCM position. + * DAC_MSB: D[9:8] (ADD: 0x03) + * DAC_LSB: D[7:0] (ADD: 0x04) + */ +#define GT97XX_DAC_ADDR_REG CCI_REG16(0x03) + +#define GT97XX_MOVE_STEPS 16 +#define GT97XX_MAX_FOCUS_POS (BIT(10) - 1) + +#define GT97XX_SLEEP_US (1 * USEC_PER_MSEC) + +enum vcm_giantec_reg_desc { + GT_IC_INFO_REG, + GT_RING_PD_CONTROL_REG, + GT_DAC_ADDR_REG, + GT_MAX_REG +}; + +struct vcm_giantec_of_data { + unsigned int id; + unsigned int regs[GT_MAX_REG]; +}; + +static const char *const gt97xx_supply_names[] = { + "vin", + "vdd", +}; + +/* gt97xx device structure */ +struct gt97xx { + struct v4l2_subdev sd; + + struct regulator_bulk_data supplies[ARRAY_SIZE(gt97xx_supply_names)]; + + struct v4l2_ctrl_handler ctrls; + struct v4l2_ctrl *focus; + + struct regmap *regmap; + + const struct vcm_giantec_of_data *chip; +}; + +static inline struct gt97xx *sd_to_gt97xx(struct v4l2_subdev *subdev) +{ + return container_of(subdev, struct gt97xx, sd); +} + +struct regval_list { + u8 reg_num; + u8 value; +}; + +static int gt97xx_set_dac(struct gt97xx *gt97xx, u16 val) +{ + /* Write VCM position to registers */ + return cci_write(gt97xx->regmap, + gt97xx->chip->regs[GT_DAC_ADDR_REG], val, NULL); +} + +static int gt97xx_identify_module(struct gt97xx *gt97xx) +{ + int ret; + u64 ic_id; + struct i2c_client *client = v4l2_get_subdevdata(>97xx->sd); + + ret = cci_read(gt97xx->regmap, gt97xx->chip->regs[GT_IC_INFO_REG], + &ic_id, NULL); + if (ret < 0) + return ret; + + if (ic_id != gt97xx->chip->id) { + dev_err(&client->dev, "chip id mismatch: 0x%x!=0x%llx", + gt97xx->chip->id, ic_id); + return -1; + } + + return 0; +} + +static int gt97xx_init(struct gt97xx *gt97xx) +{ + int ret, val; + + ret = gt97xx_identify_module(gt97xx); + if (ret < 0) + return ret; + + /* Reset PD_CONTROL */ + ret = cci_write(gt97xx->regmap, + gt97xx->chip->regs[GT_RING_PD_CONTROL_REG], + GT97XX_PD_MODE_OFF, NULL); + if (ret < 0) + return ret; + + /* Need waiting delay time after PD reset */ + fsleep(GT97XX_SLEEP_US); + + /* Enable ACC mode */ + ret = cci_write(gt97xx->regmap, + gt97xx->chip->regs[GT_RING_PD_CONTROL_REG], + GT97XX_AAC_MODE_EN, NULL); + if (ret < 0) + return ret; + + for (val = gt97xx->focus->val % GT97XX_MOVE_STEPS; + val <= gt97xx->focus->val; val += GT97XX_MOVE_STEPS) { + ret = gt97xx_set_dac(gt97xx, val); + if (ret) + return ret; + + fsleep(GT97XX_SLEEP_US); + } + + return 0; +} + +static int gt97xx_release(struct gt97xx *gt97xx) +{ + int ret, val; + + val = round_down(gt97xx->focus->val, GT97XX_MOVE_STEPS); + for (; val >= 0; val -= GT97XX_MOVE_STEPS) { + ret = gt97xx_set_dac(gt97xx, val); + if (ret) + return ret; + + fsleep(GT97XX_SLEEP_US); + } + + return 0; +} + +static int gt97xx_power_on(struct device *dev) +{ + struct v4l2_subdev *sd = dev_get_drvdata(dev); + struct gt97xx *gt97xx = sd_to_gt97xx(sd); + int ret; + + ret = regulator_bulk_enable(ARRAY_SIZE(gt97xx_supply_names), + gt97xx->supplies); + if (ret < 0) + dev_err(dev, "failed to enable regulators\n"); + + return ret; +} + +static int gt97xx_power_off(struct device *dev) +{ + struct v4l2_subdev *sd = dev_get_drvdata(dev); + struct gt97xx *gt97xx = sd_to_gt97xx(sd); + int ret; + + ret = regulator_bulk_disable(ARRAY_SIZE(gt97xx_supply_names), + gt97xx->supplies); + if (ret < 0) + dev_err(dev, "failed to disable regulators\n"); + + return ret; +} + +static int gt97xx_runtime_suspend(struct device *dev) +{ + struct v4l2_subdev *sd = dev_get_drvdata(dev); + struct gt97xx *gt97xx = sd_to_gt97xx(sd); + + gt97xx_release(gt97xx); + gt97xx_power_off(dev); + + return 0; +} + +static int gt97xx_runtime_resume(struct device *dev) +{ + struct v4l2_subdev *sd = dev_get_drvdata(dev); + struct gt97xx *gt97xx = sd_to_gt97xx(sd); + int ret; + + ret = gt97xx_power_on(dev); + if (ret < 0) { + dev_err(dev, "failed to power_on\n"); + return ret; + } + + /* Need waited before sending I2C commands after power-up */ + fsleep(GT97XX_SLEEP_US); + + ret = gt97xx_init(gt97xx); + if (ret < 0) + goto disable_power; + + return 0; + +disable_power: + gt97xx_power_off(dev); + + return ret; +} + +static int gt97xx_set_ctrl(struct v4l2_ctrl *ctrl) +{ + struct gt97xx *gt97xx = + container_of(ctrl->handler, struct gt97xx, ctrls); + + if (ctrl->id == V4L2_CID_FOCUS_ABSOLUTE) + return gt97xx_set_dac(gt97xx, ctrl->val); + + return 0; +} + +static const struct v4l2_ctrl_ops gt97xx_ctrl_ops = { + .s_ctrl = gt97xx_set_ctrl, +}; + +static int gt97xx_open(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh) +{ + return pm_runtime_resume_and_get(sd->dev); +} + +static int gt97xx_close(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh) +{ + return pm_runtime_put(sd->dev); +} + +static const struct v4l2_subdev_internal_ops gt97xx_int_ops = { + .open = gt97xx_open, + .close = gt97xx_close, +}; + +static const struct v4l2_subdev_core_ops gt97xx_core_ops = { + .subscribe_event = v4l2_ctrl_subdev_subscribe_event, + .unsubscribe_event = v4l2_event_subdev_unsubscribe, +}; + +static const struct v4l2_subdev_ops gt97xx_ops = { + .core = >97xx_core_ops, +}; + +static int gt97xx_init_controls(struct gt97xx *gt97xx) +{ + struct v4l2_ctrl_handler *hdl = >97xx->ctrls; + const struct v4l2_ctrl_ops *ops = >97xx_ctrl_ops; + + v4l2_ctrl_handler_init(hdl, 1); + + gt97xx->focus = v4l2_ctrl_new_std(hdl, ops, V4L2_CID_FOCUS_ABSOLUTE, 0, + GT97XX_MAX_FOCUS_POS, + 1, 0); + + if (hdl->error) + return hdl->error; + + gt97xx->sd.ctrl_handler = hdl; + + return 0; +} + +static int gt97xx_probe(struct i2c_client *client) +{ + struct device *dev = &client->dev; + struct gt97xx *gt97xx; + unsigned int i; + int ret; + + gt97xx = devm_kzalloc(dev, sizeof(*gt97xx), GFP_KERNEL); + if (!gt97xx) + return -ENOMEM; + + gt97xx->regmap = devm_cci_regmap_init_i2c(client, 8); + if (IS_ERR(gt97xx->regmap)) + return dev_err_probe(dev, PTR_ERR(gt97xx->regmap), + "failed to init CCI\n"); + + /* Initialize subdev */ + v4l2_i2c_subdev_init(>97xx->sd, client, >97xx_ops); + + gt97xx->chip = device_get_match_data(dev); + + for (i = 0; i < ARRAY_SIZE(gt97xx_supply_names); i++) + gt97xx->supplies[i].supply = gt97xx_supply_names[i]; + + ret = devm_regulator_bulk_get(dev, ARRAY_SIZE(gt97xx_supply_names), + gt97xx->supplies); + if (ret < 0) + return dev_err_probe(dev, ret, + "failed to get regulators\n"); + + /* Initialize controls */ + ret = gt97xx_init_controls(gt97xx); + if (ret) + goto err_free_handler; + + /* Initialize subdev */ + gt97xx->sd.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE; + gt97xx->sd.internal_ops = >97xx_int_ops; + gt97xx->sd.entity.function = MEDIA_ENT_F_LENS; + + ret = media_entity_pads_init(>97xx->sd.entity, 0, NULL); + if (ret < 0) + goto err_free_handler; + + /* Power on and initialize hardware */ + ret = gt97xx_runtime_resume(dev); + if (ret < 0) { + dev_err_probe(dev, ret, "failed to power on\n"); + goto err_clean_entity; + } + + pm_runtime_set_active(dev); + pm_runtime_enable(dev); + pm_runtime_set_autosuspend_delay(dev, 1000); + pm_runtime_use_autosuspend(dev); + pm_runtime_idle(dev); + + ret = v4l2_async_register_subdev(>97xx->sd); + if (ret < 0) { + dev_err_probe(dev, ret, "failed to register V4L2 subdev\n"); + goto err_power_off; + } + + return 0; + +err_power_off: + pm_runtime_disable(dev); +err_clean_entity: + media_entity_cleanup(>97xx->sd.entity); +err_free_handler: + v4l2_ctrl_handler_free(>97xx->ctrls); + + return ret; +} + +static void gt97xx_remove(struct i2c_client *client) +{ + struct v4l2_subdev *sd = i2c_get_clientdata(client); + struct gt97xx *gt97xx = sd_to_gt97xx(sd); + + v4l2_async_unregister_subdev(>97xx->sd); + v4l2_ctrl_handler_free(>97xx->ctrls); + media_entity_cleanup(>97xx->sd.entity); + pm_runtime_disable(&client->dev); + if (!pm_runtime_status_suspended(&client->dev)) + gt97xx_runtime_suspend(&client->dev); + pm_runtime_set_suspended(&client->dev); +} + +static DEFINE_RUNTIME_DEV_PM_OPS(gt97xx_pm_ops, + gt97xx_runtime_suspend, + gt97xx_runtime_resume, + NULL); + +static const struct vcm_giantec_of_data gt9768_data = { + .id = GT9768_ID, + .regs[GT_IC_INFO_REG] = GT97XX_IC_INFO_REG, + .regs[GT_RING_PD_CONTROL_REG] = GT97XX_RING_PD_CONTROL_REG, + .regs[GT_DAC_ADDR_REG] = GT97XX_DAC_ADDR_REG, +}; + +static const struct vcm_giantec_of_data gt9769_data = { + .id = GT9769_ID, + .regs[GT_IC_INFO_REG] = GT97XX_IC_INFO_REG, + .regs[GT_RING_PD_CONTROL_REG] = GT97XX_RING_PD_CONTROL_REG, + .regs[GT_DAC_ADDR_REG] = GT97XX_DAC_ADDR_REG, +}; + +static const struct of_device_id gt97xx_of_table[] = { + { .compatible = "giantec,gt9768", .data = >9768_data }, + { .compatible = "giantec,gt9769", .data = >9769_data }, + {} +}; +MODULE_DEVICE_TABLE(of, gt97xx_of_table); + +static struct i2c_driver gt97xx_i2c_driver = { + .driver = { + .name = GT97XX_NAME, + .pm = pm_ptr(>97xx_pm_ops), + .of_match_table = gt97xx_of_table, + }, + .probe = gt97xx_probe, + .remove = gt97xx_remove, +}; +module_i2c_driver(gt97xx_i2c_driver); + +MODULE_AUTHOR("Zhi Mao "); +MODULE_DESCRIPTION("GT97xx VCM driver"); +MODULE_LICENSE("GPL"); From patchwork Wed Jun 12 01:20:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?WmhpIE1hbyAo5q+b5pm6KQ==?= X-Patchwork-Id: 804442 Received: from mailgw02.mediatek.com (unknown [210.61.82.184]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 93EA7391; Wed, 12 Jun 2024 01:21:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=210.61.82.184 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718155294; cv=none; b=jjEiYnVO5U9hMhl2jzIL4cRbIjuQju6ZNAKMA5l1O46jw0sNX4StYhti/cz2RL3uAg0dzqM/pHtLMjED/f0ug9EAXEf5CWESz/UqsR4YSOlhDxz/ge8dk2MB04z+g6Pt5hOL7l6mTJRPdNH400Kg539Zth7DlU18IMwybLI2d74= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718155294; c=relaxed/simple; bh=QGO5DNB1ktBaq18MrT3YSf2fdBgNWF96qt+lNFGXEjs=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=ZDiXeQONM0ombjl5oDh4TU9okRbPogBOUD+/OI46uxHki9yTWqwsIZ8DtildmTWP6dZNHlKnT7MN6RceXZVJFl7QwR194KKbe73qUQRwDWyuYA3Occ8eN62p+lUThtvNeLBH6tfGjtWeaO2S9y5hDhc/Cxi362KbQosCaG0jsJ0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=mediatek.com; spf=pass smtp.mailfrom=mediatek.com; dkim=pass (1024-bit key) header.d=mediatek.com header.i=@mediatek.com header.b=iSb0nmpb; arc=none smtp.client-ip=210.61.82.184 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=mediatek.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=mediatek.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=mediatek.com header.i=@mediatek.com header.b="iSb0nmpb" X-UUID: 16d67b2e285a11efa22eafcdcd04c131-20240612 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mediatek.com; s=dk; h=Content-Type:Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:CC:To:From; bh=GoDbejxUQ5CH3/w/X+WKXRuM50NCUjo+XMdENx3Q9sc=; b=iSb0nmpbzwz+qwAH2d9XJwIcH3JbYsdkwv77GMJft1Br5dpug4R4lKiZMAOSI8FB9LcrUnSAKvCNgZmA/lpyMBeXQJ6dCkff59JvsDX/hOg/+q/8pV9gogXMxMVCWOtWgmCjjsf8dYsf9KNtqtGUhtP8i2O1i7OS5tBHe1jU+Vw=; X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.39, REQID:ef24ff04-c1ce-4d88-b794-01e9fe46a064, IP:0, U RL:0,TC:0,Content:-5,EDM:0,RT:0,SF:0,FILE:0,BULK:0,RULE:Release_Ham,ACTION :release,TS:-5 X-CID-META: VersionHash:393d96e, CLOUDID:f6157988-8d4f-477b-89d2-1e3bdbef96d1, B ulkID:nil,BulkQuantity:0,Recheck:0,SF:102,TC:nil,Content:0,EDM:-3,IP:nil,U RL:0,File:nil,RT:nil,Bulk:nil,QS:nil,BEC:nil,COL:0,OSI:0,OSA:0,AV:0,LES:1, SPR:NO,DKR:0,DKP:0,BRR:0,BRE:0,ARC:0 X-CID-BVR: 0 X-CID-BAS: 0,_,0,_ X-CID-FACTOR: TF_CID_SPAM_SNR X-UUID: 16d67b2e285a11efa22eafcdcd04c131-20240612 Received: from mtkmbs13n2.mediatek.inc [(172.21.101.108)] by mailgw02.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 256/256) with ESMTP id 560014558; Wed, 12 Jun 2024 09:21:26 +0800 Received: from mtkmbs11n2.mediatek.inc (172.21.101.187) by MTKMBS14N1.mediatek.inc (172.21.101.75) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.26; Wed, 12 Jun 2024 09:21:24 +0800 Received: from mhfsdcap04.gcn.mediatek.inc (10.17.3.154) by mtkmbs11n2.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.2.1118.26 via Frontend Transport; Wed, 12 Jun 2024 09:21:22 +0800 From: Zhi Mao To: Mauro Carvalho Chehab , Rob Herring , Krzysztof Kozlowski , Conor Dooley CC: Matthias Brugger , AngeloGioacchino Del Regno , Zhi Mao , Philipp Zabel , Laurent Pinchart , Heiko Stuebner , Sakari Ailus , Hans Verkuil , Hans de Goede , "Tomi Valkeinen" , Alain Volmat , Paul Elder , "Mehdi Djait" , Andy Shevchenko , Bingbu Cao , , , , , , , , , <10572168@qq.com> Subject: [PATCH v3 3/3] MAINTAINERS: Add entry for GT97xx VCM driver Date: Wed, 12 Jun 2024 09:20:19 +0800 Message-ID: <20240612012019.19078-4-zhi.mao@mediatek.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240612012019.19078-1-zhi.mao@mediatek.com> References: <20240612012019.19078-1-zhi.mao@mediatek.com> Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-TM-AS-Product-Ver: SMEX-14.0.0.3152-9.1.1006-23728.005 X-TM-AS-Result: No-10--1.740300-8.000000 X-TMASE-MatchedRID: GIpmbigRs3Y9S3IiQd+eNQPZZctd3P4BFuNF4lJG6xtGL0g1nVmkYTcG i0cOVVasRcK0DrBkisuAMuqetGVetksDkkP3zIjqavP8b9lJtWr6C0ePs7A07fH8XRQwShO7Ayk Qe1sIa0XYNwoFzR6TfCnyQECDq3YS+cAQf7nhiHEBxwmF6nT2v0FNSQkI9yjefYyfbAjKfD6cXr SpsbyZea6edyNz+tV1oydMlEjRcid9fBQSbWi4PMsNjEULX/uufoZ02Tg1aYA= X-TM-AS-User-Approved-Sender: No X-TM-AS-User-Blocked-Sender: No X-TMASE-Result: 10--1.740300-8.000000 X-TMASE-Version: SMEX-14.0.0.3152-9.1.1006-23728.005 X-TM-SNTS-SMTP: BBF44A3C6038B97E8327B33B45543D43F4733C587BBDE6740BD7819DB45B6D542000:8 X-MTK: N Add maintainer entry for GT97xx VCM driver Signed-off-by: Zhi Mao --- MAINTAINERS | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/MAINTAINERS b/MAINTAINERS index 670b8201973b..d12694c743ab 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -9328,6 +9328,13 @@ F: Documentation/filesystems/gfs2* F: fs/gfs2/ F: include/uapi/linux/gfs2_ondisk.h +GIANTEC GT9769 LENS VOICE COIL DRIVER +M: Zhi Mao +L: linux-media@vger.kernel.org +S: Maintained +F: Documentation/devicetree/bindings/media/i2c/giantec,gt9769.yaml +F: drivers/media/i2c/gt97xx.c + GIGABYTE WATERFORCE SENSOR DRIVER M: Aleksa Savic L: linux-hwmon@vger.kernel.org @@ -23590,6 +23597,7 @@ L: linux-media@vger.kernel.org S: Maintained F: drivers/media/i2c/ak* F: drivers/media/i2c/dw* +F: drivers/media/i2c/gt* F: drivers/media/i2c/lm* V4L2 CAMERA SENSOR DRIVERS