From nobody Sat Feb 7 05:15:29 2026 Received: from mg.richtek.com (mg.richtek.com [220.130.44.152]) by smtp.subspace.kernel.org (Postfix) with ESMTP id ED254127B52 for ; Tue, 30 Apr 2024 09:58:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=220.130.44.152 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714471131; cv=none; b=XYyPUZ5z2kV+v+XrrpiBZkz6MY+tTay0uzK2Af3IcdvRluSI5+fMvQD2YdD3ewuCgSl9JbKpoqL2ks/An4JC1CKy60GiN4HjVuN5uXg4SbTVlhkrTX2QYPF4JMpv65NxrpnhgikhEZUIkh32Ry2vb/suG3NAA73Ae+Q3CZFggiI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714471131; c=relaxed/simple; bh=WzSLblxs7n5kOPkFyGc4PsooUIWAas7udMZaq7lB7+c=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=eOelARk89vhvz8t/BDfrfXvLGeT/pWMa9SUhMbvNPSsVAqdXWjPVx9m9kwvXyYyQ9VjHB27Dr+TfJLtWBf3hLvOfjIbPOBYMPXVXg0TZqG2Wdst59FA37mwtdlNSKPZnuVH1ZbbPMnY8Q4BIILnncqzRW15NYc/D5In7uce9hAI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=richtek.com; spf=pass smtp.mailfrom=richtek.com; arc=none smtp.client-ip=220.130.44.152 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=richtek.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=richtek.com X-MailGates: (SIP:2,PASS,NONE)(compute_score:DELIVER,40,3) Received: from 192.168.10.46 by mg.richtek.com with MailGates ESMTPS Server V6.0(3367349:0:AUTH_RELAY) (envelope-from ) (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256/256); Tue, 30 Apr 2024 17:58:29 +0800 (CST) Received: from ex4.rt.l (192.168.10.47) by ex3.rt.l (192.168.10.46) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Tue, 30 Apr 2024 17:58:29 +0800 Received: from linuxcarl2.richtek.com (192.168.10.154) by ex4.rt.l (192.168.10.45) with Microsoft SMTP Server id 15.2.1544.4 via Frontend Transport; Tue, 30 Apr 2024 17:58:29 +0800 From: Alina Yu To: , CC: , , , Subject: [PATCH v2 1/4] regulator: rtq2208: Fix LDO discharge register and add vsel setting Date: Tue, 30 Apr 2024 17:58:24 +0800 Message-ID: <5d56b79c94de63fc86b5a70b7e374da4240fee8b.1714467553.git.alina_yu@richtek.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The LDO's Vout is adjustable if the hardware setting allows it, and it can be set either 1800mv or 3300mv. Additionally, the discharge register has been moved to another position. Signed-off-by: Alina Yu --- drivers/regulator/rtq2208-regulator.c | 100 +++++++++++++++++++++---------= ---- 1 file changed, 61 insertions(+), 39 deletions(-) diff --git a/drivers/regulator/rtq2208-regulator.c b/drivers/regulator/rtq2= 208-regulator.c index 2d54844..63d4037 100644 --- a/drivers/regulator/rtq2208-regulator.c +++ b/drivers/regulator/rtq2208-regulator.c @@ -26,6 +26,7 @@ #define RTQ2208_REG_BUCK_H_CFG0 0xA2 #define RTQ2208_REG_LDO1_CFG 0xB1 #define RTQ2208_REG_LDO2_CFG 0xC1 +#define RTQ2208_REG_LDO_DVS_CTRL 0xD0 =20 /* Mask */ #define RTQ2208_BUCK_NR_MTP_SEL_MASK GENMASK(7, 0) @@ -40,6 +41,10 @@ #define RTQ2208_EN_DIS_MASK BIT(0) #define RTQ2208_BUCK_RAMP_SEL_MASK GENMASK(2, 0) #define RTQ2208_HD_INT_MASK BIT(0) +#define RTQ2208_LDO1_DISCHG_EN_MASK BIT(4) +#define RTQ2208_LDO1_VOSEL_SD_MASK BIT(5) +#define RTQ2208_LDO2_DISCHG_EN_MASK BIT(6) +#define RTQ2208_LDO2_VOSEL_SD_MASK BIT(7) =20 /* Size */ #define RTQ2208_VOUT_MAXNUM 256 @@ -318,23 +323,6 @@ static irqreturn_t rtq2208_irq_handler(int irqno, void= *devid) return IRQ_HANDLED; } =20 -#define RTQ2208_REGULATOR_INFO(_name, _base) \ -{ \ - .name =3D #_name, \ - .base =3D _base, \ -} -#define BUCK_RG_BASE(_id) RTQ2208_REG_BUCK_##_id##_CFG0 -#define BUCK_RG_SHIFT(_base, _shift) (_base + _shift) -#define LDO_RG_BASE(_id) RTQ2208_REG_LDO##_id##_CFG -#define LDO_RG_SHIFT(_base, _shift) (_base + _shift) -#define VSEL_SHIFT(_sel) (_sel ? 3 : 1) -#define MTP_SEL_MASK(_sel) RTQ2208_BUCK_EN_NR_MTP_SEL##_sel##_MASK - -static const struct linear_range rtq2208_vout_range[] =3D { - REGULATOR_LINEAR_RANGE(400000, 0, 180, 5000), - REGULATOR_LINEAR_RANGE(1310000, 181, 255, 10000), -}; - static int rtq2208_of_get_fixed_voltage(struct device *dev, struct of_regulator_match *rtq2208_ldo_match, int n_fixed) { @@ -373,6 +361,34 @@ static int rtq2208_of_get_fixed_voltage(struct device = *dev, return 0; } =20 + +#define BUCK_INFO(_name, _id) \ +{ \ + .name =3D _name, \ + .base =3D RTQ2208_REG_BUCK_##_id##_CFG0, \ + .enable_reg =3D BUCK_RG_SHIFT(RTQ2208_REG_BUCK_##_id##_CFG0, 2), \ + .dis_reg =3D RTQ2208_REG_BUCK_##_id##_CFG0, \ +} + +#define LDO_INFO(_name, _id) \ +{ \ + .name =3D _name, \ + .base =3D RTQ2208_REG_LDO##_id##_CFG, \ + .enable_reg =3D RTQ2208_REG_LDO##_id##_CFG, \ + .dis_mask =3D RTQ2208_LDO##_id##_DISCHG_EN_MASK, \ + .dis_on =3D RTQ2208_LDO##_id##_DISCHG_EN_MASK, \ + .vsel_mask =3D RTQ2208_LDO##_id##_VOSEL_SD_MASK, \ +} + +#define BUCK_RG_SHIFT(_base, _shift) (_base + _shift) +#define VSEL_SHIFT(_sel) (_sel ? 3 : 1) +#define MTP_SEL_MASK(_sel) RTQ2208_BUCK_EN_NR_MTP_SEL##_sel##_MASK + +static const struct linear_range rtq2208_vout_range[] =3D { + REGULATOR_LINEAR_RANGE(400000, 0, 180, 5000), + REGULATOR_LINEAR_RANGE(1310000, 181, 255, 10000), +}; + static void rtq2208_init_regulator_desc(struct rtq2208_regulator_desc *rde= sc, int mtp_sel, int idx, struct of_regulator_match *rtq2208_ldo_match, int *ldo_idx) { @@ -380,17 +396,22 @@ static void rtq2208_init_regulator_desc(struct rtq220= 8_regulator_desc *rdesc, in static const struct { char *name; int base; + int enable_reg; + int dis_reg; + int dis_mask; + int dis_on; + int vsel_mask; } regulator_info[] =3D { - RTQ2208_REGULATOR_INFO(buck-b, BUCK_RG_BASE(B)), - RTQ2208_REGULATOR_INFO(buck-c, BUCK_RG_BASE(C)), - RTQ2208_REGULATOR_INFO(buck-d, BUCK_RG_BASE(D)), - RTQ2208_REGULATOR_INFO(buck-a, BUCK_RG_BASE(A)), - RTQ2208_REGULATOR_INFO(buck-f, BUCK_RG_BASE(F)), - RTQ2208_REGULATOR_INFO(buck-g, BUCK_RG_BASE(G)), - RTQ2208_REGULATOR_INFO(buck-h, BUCK_RG_BASE(H)), - RTQ2208_REGULATOR_INFO(buck-e, BUCK_RG_BASE(E)), - RTQ2208_REGULATOR_INFO(ldo2, LDO_RG_BASE(2)), - RTQ2208_REGULATOR_INFO(ldo1, LDO_RG_BASE(1)), + BUCK_INFO("buck-b", B), + BUCK_INFO("buck-c", C), + BUCK_INFO("buck-d", D), + BUCK_INFO("buck-a", A), + BUCK_INFO("buck-f", F), + BUCK_INFO("buck-g", G), + BUCK_INFO("buck-h", H), + BUCK_INFO("buck-e", E), + LDO_INFO("ldo2", 2), + LDO_INFO("ldo1", 1), }, *curr_info; =20 curr_info =3D regulator_info + idx; @@ -402,15 +423,13 @@ static void rtq2208_init_regulator_desc(struct rtq220= 8_regulator_desc *rdesc, in desc->owner =3D THIS_MODULE; desc->type =3D REGULATOR_VOLTAGE; desc->enable_mask =3D mtp_sel ? MTP_SEL_MASK(1) : MTP_SEL_MASK(0); - desc->active_discharge_on =3D RTQ2208_EN_DIS_MASK; + desc->enable_reg =3D curr_info->enable_reg; desc->active_discharge_off =3D 0; - desc->active_discharge_mask =3D RTQ2208_EN_DIS_MASK; =20 rdesc->mode_mask =3D RTQ2208_BUCK_NRMODE_MASK; =20 if (idx >=3D RTQ2208_BUCK_B && idx <=3D RTQ2208_BUCK_E) { /* init buck desc */ - desc->enable_reg =3D BUCK_RG_SHIFT(curr_info->base, 2); desc->ops =3D &rtq2208_regulator_buck_ops; desc->vsel_reg =3D curr_info->base + VSEL_SHIFT(mtp_sel); desc->vsel_mask =3D RTQ2208_BUCK_NR_MTP_SEL_MASK; @@ -418,8 +437,10 @@ static void rtq2208_init_regulator_desc(struct rtq2208= _regulator_desc *rdesc, in desc->linear_ranges =3D rtq2208_vout_range; desc->n_linear_ranges =3D ARRAY_SIZE(rtq2208_vout_range); desc->ramp_reg =3D BUCK_RG_SHIFT(curr_info->base, 5); - desc->active_discharge_reg =3D curr_info->base; desc->of_map_mode =3D rtq2208_of_map_mode; + desc->active_discharge_reg =3D curr_info->dis_reg; + desc->active_discharge_on =3D RTQ2208_EN_DIS_MASK; + desc->active_discharge_mask =3D RTQ2208_EN_DIS_MASK; =20 rdesc->mode_reg =3D BUCK_RG_SHIFT(curr_info->base, 2); rdesc->suspend_config_reg =3D BUCK_RG_SHIFT(curr_info->base, 4); @@ -427,14 +448,11 @@ static void rtq2208_init_regulator_desc(struct rtq220= 8_regulator_desc *rdesc, in rdesc->suspend_mode_mask =3D RTQ2208_BUCK_STRMODE_MASK; } else { /* init ldo desc */ - desc->enable_reg =3D curr_info->base; - desc->ops =3D &rtq2208_regulator_ldo_ops; - desc->n_voltages =3D 1; - desc->active_discharge_reg =3D LDO_RG_SHIFT(curr_info->base, 2); - - rtq2208_ldo_match[*ldo_idx].name =3D desc->name; - rtq2208_ldo_match[*ldo_idx].driver_data =3D rdesc; - rtq2208_ldo_match[(*ldo_idx)++].desc =3D desc; + desc->active_discharge_reg =3D RTQ2208_REG_LDO_DVS_CTRL; + desc->active_discharge_on =3D curr_info->dis_on; + desc->active_discharge_mask =3D curr_info->dis_mask; + desc->vsel_reg =3D RTQ2208_REG_LDO_DVS_CTRL; + desc->vsel_mask =3D curr_info->vsel_mask; =20 rdesc->suspend_config_reg =3D curr_info->base; rdesc->suspend_enable_mask =3D RTQ2208_LDO_EN_STR_MASK; @@ -458,6 +476,10 @@ static int rtq2208_parse_regulator_dt_data(int n_regul= ator, const unsigned int * return -ENOMEM; =20 rtq2208_init_regulator_desc(rdesc[i], mtp_sel, idx, rtq2208_ldo_match, &= ldo_idx); + + /* init ldo dvs ability */ + if (idx >=3D RTQ2208_LDO2) + rtq2208_ldo_match[idx - RTQ2208_LDO2].desc =3D &rdesc[i]->desc; } =20 /* init ldo fixed_uV */ --=20 2.7.4 From nobody Sat Feb 7 05:15:29 2026 Received: from mg.richtek.com (mg.richtek.com [220.130.44.152]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D9717127B66 for ; Tue, 30 Apr 2024 09:58:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=220.130.44.152 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714471132; cv=none; b=umR29tjSxSbw4AXO6ZQJEigO6kYYREb4YHJG5VxsnXyXorUA/dXuEoKIqp+foIei3ufLWSOX5Gh7af3FvpEqIUXmZ6+tLrv0MyhxL6Yl2oOFoTteOPN8MjyKs3Zur/9K78hY9mmewWGvUgNTABaFDjK1r0IvZTMeK5wCx3QTOWU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714471132; c=relaxed/simple; bh=TAIbU6KIXHjSHkPESe/qiPcIp+0I21hFgkQKToxiK8w=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=knOLZsV/6LVb1NgcJnM7S2R8cbCAVFAQ/4LfEee2h/VwyHOA/NWyJdRjS8ywCKod+jGyW8FeLZarUhLM6IGyabfQV/Sj3W23b51O0e9q61Kwd+mHLnuQP0A/M4hq3wS8Hdq8YxcwoBXS8XB3uYXe2dzHfCGySx9FnBTl7ILHY/c= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=richtek.com; spf=pass smtp.mailfrom=richtek.com; arc=none smtp.client-ip=220.130.44.152 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=richtek.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=richtek.com X-MailGates: (SIP:2,PASS,NONE)(compute_score:DELIVER,40,3) Received: from 192.168.10.46 by mg.richtek.com with MailGates ESMTPS Server V6.0(3367349:0:AUTH_RELAY) (envelope-from ) (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256/256); Tue, 30 Apr 2024 17:58:30 +0800 (CST) Received: from ex4.rt.l (192.168.10.47) by ex3.rt.l (192.168.10.46) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Tue, 30 Apr 2024 17:58:30 +0800 Received: from linuxcarl2.richtek.com (192.168.10.154) by ex4.rt.l (192.168.10.45) with Microsoft SMTP Server id 15.2.1544.4 via Frontend Transport; Tue, 30 Apr 2024 17:58:30 +0800 From: Alina Yu To: , CC: , , , Subject: [PATCH v2 2/4] regulator: rtq2208: Fix LDO to be compatible with both fixed and adjustable vout Date: Tue, 30 Apr 2024 17:58:25 +0800 Message-ID: X-Mailer: git-send-email 1.8.3.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" In this patch, LDO's adjustable and fixed Vout settings are compatible. The LDO Vout ability depends on the init_data->constraints. If adjustable, the Vout can be set to either 1800mV or 3300mV. Signed-off-by: Alina Yu --- drivers/regulator/rtq2208-regulator.c | 41 +++++++++++++++++++++++++++----= ---- 1 file changed, 32 insertions(+), 9 deletions(-) diff --git a/drivers/regulator/rtq2208-regulator.c b/drivers/regulator/rtq2= 208-regulator.c index 63d4037..80a4d2f 100644 --- a/drivers/regulator/rtq2208-regulator.c +++ b/drivers/regulator/rtq2208-regulator.c @@ -220,7 +220,7 @@ static const struct regulator_ops rtq2208_regulator_buc= k_ops =3D { .set_suspend_mode =3D rtq2208_set_suspend_mode, }; =20 -static const struct regulator_ops rtq2208_regulator_ldo_ops =3D { +static const struct regulator_ops rtq2208_regulator_ldo_fix_ops =3D { .enable =3D regulator_enable_regmap, .disable =3D regulator_disable_regmap, .is_enabled =3D regulator_is_enabled_regmap, @@ -229,6 +229,23 @@ static const struct regulator_ops rtq2208_regulator_ld= o_ops =3D { .set_suspend_disable =3D rtq2208_set_suspend_disable, }; =20 +static const struct regulator_ops rtq2208_regulator_ldo_adj_ops =3D { + .enable =3D regulator_enable_regmap, + .disable =3D regulator_disable_regmap, + .is_enabled =3D regulator_is_enabled_regmap, + .list_voltage =3D regulator_list_voltage_table, + .set_voltage_sel =3D regulator_set_voltage_sel_regmap, + .get_voltage_sel =3D regulator_get_voltage_sel_regmap, + .set_active_discharge =3D regulator_set_active_discharge_regmap, + .set_suspend_enable =3D rtq2208_set_suspend_enable, + .set_suspend_disable =3D rtq2208_set_suspend_disable, +}; + +static const unsigned int rtq2208_ldo_volt_table[] =3D { + 1800000, + 3300000, +}; + static unsigned int rtq2208_of_map_mode(unsigned int mode) { switch (mode) { @@ -323,12 +340,12 @@ static irqreturn_t rtq2208_irq_handler(int irqno, voi= d *devid) return IRQ_HANDLED; } =20 -static int rtq2208_of_get_fixed_voltage(struct device *dev, +static int rtq2208_of_get_ldo_dvs_ability(struct device *dev, struct of_regulator_match *rtq2208_ldo_match, int n_fixed) { struct device_node *np; struct of_regulator_match *match; - struct rtq2208_regulator_desc *rdesc; + struct regulator_desc *desc; struct regulator_init_data *init_data; int ret, i; =20 @@ -349,13 +366,20 @@ static int rtq2208_of_get_fixed_voltage(struct device= *dev, for (i =3D 0; i < n_fixed; i++) { match =3D rtq2208_ldo_match + i; init_data =3D match->init_data; - rdesc =3D (struct rtq2208_regulator_desc *)match->driver_data; + desc =3D (struct regulator_desc *)match->desc; =20 - if (!init_data || !rdesc) + if (!init_data || !desc) continue; =20 - if (init_data->constraints.min_uV =3D=3D init_data->constraints.max_uV) - rdesc->desc.fixed_uV =3D init_data->constraints.min_uV; + if (init_data->constraints.min_uV =3D=3D init_data->constraints.max_uV) { + desc->n_voltages =3D 1; + desc->fixed_uV =3D init_data->constraints.min_uV; + desc->ops =3D &rtq2208_regulator_ldo_fix_ops; + } else { + desc->n_voltages =3D ARRAY_SIZE(rtq2208_ldo_volt_table); + desc->volt_table =3D rtq2208_ldo_volt_table; + desc->ops =3D &rtq2208_regulator_ldo_adj_ops; + } } =20 return 0; @@ -482,8 +506,7 @@ static int rtq2208_parse_regulator_dt_data(int n_regula= tor, const unsigned int * rtq2208_ldo_match[idx - RTQ2208_LDO2].desc =3D &rdesc[i]->desc; } =20 - /* init ldo fixed_uV */ - ret =3D rtq2208_of_get_fixed_voltage(dev, rtq2208_ldo_match, ldo_idx); + ret =3D rtq2208_of_get_ldo_dvs_ability(dev, rtq2208_ldo_match, ldo_idx); if (ret) return dev_err_probe(dev, ret, "Failed to get ldo fixed_uV\n"); =20 --=20 2.7.4 From nobody Sat Feb 7 05:15:29 2026 Received: from mg.richtek.com (mg.richtek.com [220.130.44.152]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E3FCC128833 for ; Tue, 30 Apr 2024 09:58:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=220.130.44.152 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714471133; cv=none; b=ZATor0FXauMj0ScIj7nhq60G8dntL4A8WzMAMMr9TLqGxiOwUhuI8F0vzD39I5xUbNkgzfW0YOGJKmSYEZS7hi1eBPj8kNArDNlIM0A9eYFbarnC4y8wmaUTdbd1fihDOhZPY+/UBLnwx+hw7kUEnuRpOBP1GamRsCxOgwr4rLU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714471133; c=relaxed/simple; bh=aLW+hLhtsKefh2Nh1SYqXbYSstdwqst9ixv2hu0e2fg=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=HzF6hVdVxTFwkYyZmUrTYaHXD29rFi/ky8rVjH4o3AQqxDBj3uCYijca/cUwBSrk6+Tl/X9yh15HXxGcWvCUP1XXc71oHYYHQqk9hwTXEMlnZP3rimhtxHFsy8t0v+023wDZ8eysfzB/7n40LpTSHYTFD4Vclet7U0eM9qOjWO8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=richtek.com; spf=pass smtp.mailfrom=richtek.com; arc=none smtp.client-ip=220.130.44.152 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=richtek.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=richtek.com X-MailGates: (SIP:2,PASS,NONE)(compute_score:DELIVER,40,3) Received: from 192.168.10.46 by mg.richtek.com with MailGates ESMTPS Server V6.0(3367343:0:AUTH_RELAY) (envelope-from ) (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256/256); Tue, 30 Apr 2024 17:58:31 +0800 (CST) Received: from ex4.rt.l (192.168.10.47) by ex3.rt.l (192.168.10.46) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Tue, 30 Apr 2024 17:58:30 +0800 Received: from linuxcarl2.richtek.com (192.168.10.154) by ex4.rt.l (192.168.10.45) with Microsoft SMTP Server id 15.2.1544.4 via Frontend Transport; Tue, 30 Apr 2024 17:58:30 +0800 From: Alina Yu To: , CC: , , , Subject: [PATCH v2 3/4] regulator: rtq2208: Fix invalid memory access when devm_of_regulator_put_matches is called Date: Tue, 30 Apr 2024 17:58:26 +0800 Message-ID: X-Mailer: git-send-email 1.8.3.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" In this patch, a software bug has been fixed. rtq2208_ldo_match is no longer a local variable. It prevents invalid memory access when devm_of_regulator_put_matches is called. Signed-off-by: Alina Yu --- drivers/regulator/rtq2208-regulator.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/drivers/regulator/rtq2208-regulator.c b/drivers/regulator/rtq2= 208-regulator.c index 80a4d2f..97a97a4 100644 --- a/drivers/regulator/rtq2208-regulator.c +++ b/drivers/regulator/rtq2208-regulator.c @@ -246,6 +246,11 @@ static const unsigned int rtq2208_ldo_volt_table[] =3D= { 3300000, }; =20 +static struct of_regulator_match rtq2208_ldo_match[] =3D { + {.name =3D "ldo2", }, + {.name =3D "ldo1", }, +}; + static unsigned int rtq2208_of_map_mode(unsigned int mode) { switch (mode) { @@ -340,8 +345,7 @@ static irqreturn_t rtq2208_irq_handler(int irqno, void = *devid) return IRQ_HANDLED; } =20 -static int rtq2208_of_get_ldo_dvs_ability(struct device *dev, - struct of_regulator_match *rtq2208_ldo_match, int n_fixed) +static int rtq2208_of_get_ldo_dvs_ability(struct device *dev) { struct device_node *np; struct of_regulator_match *match; @@ -356,14 +360,14 @@ static int rtq2208_of_get_ldo_dvs_ability(struct devi= ce *dev, if (!np) np =3D dev->of_node; =20 - ret =3D of_regulator_match(dev, np, rtq2208_ldo_match, n_fixed); + ret =3D of_regulator_match(dev, np, rtq2208_ldo_match, ARRAY_SIZE(rtq2208= _ldo_match)); =20 of_node_put(np); =20 if (ret < 0) return ret; =20 - for (i =3D 0; i < n_fixed; i++) { + for (i =3D 0; i < ARRAY_SIZE(rtq2208_ldo_match); i++) { match =3D rtq2208_ldo_match + i; init_data =3D match->init_data; desc =3D (struct regulator_desc *)match->desc; @@ -413,8 +417,7 @@ static const struct linear_range rtq2208_vout_range[] = =3D { REGULATOR_LINEAR_RANGE(1310000, 181, 255, 10000), }; =20 -static void rtq2208_init_regulator_desc(struct rtq2208_regulator_desc *rde= sc, int mtp_sel, - int idx, struct of_regulator_match *rtq2208_ldo_match, int *ldo_idx) +static void rtq2208_init_regulator_desc(struct rtq2208_regulator_desc *rde= sc, int mtp_sel, int idx) { struct regulator_desc *desc; static const struct { @@ -486,8 +489,7 @@ static void rtq2208_init_regulator_desc(struct rtq2208_= regulator_desc *rdesc, in static int rtq2208_parse_regulator_dt_data(int n_regulator, const unsigned= int *regulator_idx_table, struct rtq2208_regulator_desc *rdesc[RTQ2208_LDO_MAX], struct device *de= v) { - struct of_regulator_match rtq2208_ldo_match[2]; - int mtp_sel, ret, i, idx, ldo_idx =3D 0; + int mtp_sel, i, idx, ret; =20 /* get mtp_sel0 or mtp_sel1 */ mtp_sel =3D device_property_read_bool(dev, "richtek,mtp-sel-high"); @@ -499,14 +501,14 @@ static int rtq2208_parse_regulator_dt_data(int n_regu= lator, const unsigned int * if (!rdesc[i]) return -ENOMEM; =20 - rtq2208_init_regulator_desc(rdesc[i], mtp_sel, idx, rtq2208_ldo_match, &= ldo_idx); + rtq2208_init_regulator_desc(rdesc[i], mtp_sel, idx); =20 /* init ldo dvs ability */ if (idx >=3D RTQ2208_LDO2) rtq2208_ldo_match[idx - RTQ2208_LDO2].desc =3D &rdesc[i]->desc; } =20 - ret =3D rtq2208_of_get_ldo_dvs_ability(dev, rtq2208_ldo_match, ldo_idx); + ret =3D rtq2208_of_get_ldo_dvs_ability(dev); if (ret) return dev_err_probe(dev, ret, "Failed to get ldo fixed_uV\n"); =20 --=20 2.7.4 From nobody Sat Feb 7 05:15:29 2026 Received: from mg.richtek.com (mg.richtek.com [220.130.44.152]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D9BA5127B70 for ; Tue, 30 Apr 2024 09:58:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=220.130.44.152 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714471133; cv=none; b=SQGVkTWNYabFSs73ugFrBDeXcnlfW/Z8IfJDNPneZrEtkqkwGr9FFbRbAx8zvmUAWzVYggfNxJYHLPkDGFyhfVDnj37vRSt/RkHyMvxeU2SORIORka7vzJOxVtLTOiMA5Pu9Jj2Exg7bsGOLkERGCw35/qh/gxBfqKfOwO2+IF0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714471133; c=relaxed/simple; bh=wYJBsZ1Psy2XQjY+LZVkvy93Tzfa/JKnhg4Y7abcKlY=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=q8QhsL/2g3+qMmya0bXGSBDj8TnJI/oxI4K5Y0rptTY2Ot7C94kYjtHsiLmJHwge8u3+4ZrlJKqXQ4BddLQDkabrz0vWVQ5s0egVDLBKa1UH3NlfFKLRDVFmJFGp+Dn+E4bVgiWrxAPazvP+WAQG3ErGyrOKTMy/RD62nHyoB2s= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=richtek.com; spf=pass smtp.mailfrom=richtek.com; arc=none smtp.client-ip=220.130.44.152 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=richtek.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=richtek.com X-MailGates: (SIP:2,PASS,NONE)(compute_score:DELIVER,40,3) Received: from 192.168.10.46 by mg.richtek.com with MailGates ESMTPS Server V6.0(3367343:0:AUTH_RELAY) (envelope-from ) (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256/256); Tue, 30 Apr 2024 17:58:31 +0800 (CST) Received: from ex4.rt.l (192.168.10.47) by ex3.rt.l (192.168.10.46) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Tue, 30 Apr 2024 17:58:31 +0800 Received: from linuxcarl2.richtek.com (192.168.10.154) by ex4.rt.l (192.168.10.45) with Microsoft SMTP Server id 15.2.1544.4 via Frontend Transport; Tue, 30 Apr 2024 17:58:31 +0800 From: Alina Yu To: , CC: , , , Subject: [PATCH v2 4/4] regulator: rtq2208: Fix the BUCK ramp_delay range to maximum of 16mVstep/us Date: Tue, 30 Apr 2024 17:58:27 +0800 Message-ID: <1777b18c0faa1f6b7196630e679a03362686c301.1714467553.git.alina_yu@richtek.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The maximum ramp up and down range of BUCK are shorten from 64mVstep/us to 16mVstep/us. Therefore, the RTQ2208_RAMP_VALUE_MAX_uV is modified to 16000uV in this version. Signed-off-by: Alina Yu --- drivers/regulator/rtq2208-regulator.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/drivers/regulator/rtq2208-regulator.c b/drivers/regulator/rtq2= 208-regulator.c index 97a97a4..39dde4e 100644 --- a/drivers/regulator/rtq2208-regulator.c +++ b/drivers/regulator/rtq2208-regulator.c @@ -53,7 +53,7 @@ =20 /* Value */ #define RTQ2208_RAMP_VALUE_MIN_uV 500 -#define RTQ2208_RAMP_VALUE_MAX_uV 64000 +#define RTQ2208_RAMP_VALUE_MAX_uV 16000 =20 #define RTQ2208_BUCK_MASK(uv_irq, ov_irq) (1 << ((uv_irq) % 8) | 1 << ((ov= _irq) % 8)) =20 @@ -147,12 +147,11 @@ static int rtq2208_set_ramp_delay(struct regulator_de= v *rdev, int ramp_delay) * Because the relation of seleltion and value is like that * * seletion: value - * 000: 64mv - * 001: 32mv + * 010: 16mv * ... * 111: 0.5mv * - * For example, if I would like to select 64mv, the fls(ramp_delay) - 1 w= ill be 0b111, + * For example, if I would like to select 16mv, the fls(ramp_delay) - 1 w= ill be 0b010, * and I need to use 0b111 - sel to do the shifting */ =20 --=20 2.7.4