Skip to content

Commit 78821a7

Browse files
Artem ShimkoAndi Shyti
authored andcommitted
i2c: designware-platdrv: simplify reset control
The current implementation uses separate calls to acquire and deassert reset control, requiring manual error handling for the deassertion operation. This can be simplified using the dedicated devm function that combines both operations. Replace devm_reset_control_get_optional_exclusive() with devm_reset_control_get_optional_exclusive_deasserted(), which handles both reset acquisition and deassertion in a single call as well as reset_control_put() which is called automatically on driver detach. This eliminates the need for explicit deassertion and its associated error checking while maintaining the same functional behavior through automatic resource management. Signed-off-by: Artem Shimko <a.shimko.dev@gmail.com> Acked-by: Mika Westerberg <mika.westerberg@linux.intel.com> Signed-off-by: Andi Shyti <andi.shyti@kernel.org> Link: https://lore.kernel.org/r/20260130111039.874548-2-a.shimko.dev@gmail.com
1 parent eddfdab commit 78821a7

1 file changed

Lines changed: 9 additions & 21 deletions

File tree

drivers/i2c/busses/i2c-designware-platdrv.c

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -160,40 +160,32 @@ static int dw_i2c_plat_probe(struct platform_device *pdev)
160160
if (ret)
161161
return ret;
162162

163-
dev->rst = devm_reset_control_get_optional_exclusive(device, NULL);
163+
dev->rst = devm_reset_control_get_optional_exclusive_deasserted(device, NULL);
164164
if (IS_ERR(dev->rst))
165165
return dev_err_probe(device, PTR_ERR(dev->rst), "failed to acquire reset\n");
166166

167-
reset_control_deassert(dev->rst);
168-
169167
ret = i2c_dw_fw_parse_and_configure(dev);
170168
if (ret)
171-
goto exit_reset;
169+
return ret;
172170

173171
ret = i2c_dw_probe_lock_support(dev);
174-
if (ret) {
175-
dev_err_probe(device, ret, "failed to probe lock support\n");
176-
goto exit_reset;
177-
}
172+
if (ret)
173+
return dev_err_probe(device, ret, "failed to probe lock support\n");
178174

179175
i2c_dw_configure(dev);
180176

181177
/* Optional interface clock */
182178
dev->pclk = devm_clk_get_optional(device, "pclk");
183-
if (IS_ERR(dev->pclk)) {
184-
ret = dev_err_probe(device, PTR_ERR(dev->pclk), "failed to acquire pclk\n");
185-
goto exit_reset;
186-
}
179+
if (IS_ERR(dev->pclk))
180+
return dev_err_probe(device, PTR_ERR(dev->pclk), "failed to acquire pclk\n");
187181

188182
dev->clk = devm_clk_get_optional(device, NULL);
189-
if (IS_ERR(dev->clk)) {
190-
ret = dev_err_probe(device, PTR_ERR(dev->clk), "failed to acquire clock\n");
191-
goto exit_reset;
192-
}
183+
if (IS_ERR(dev->clk))
184+
return dev_err_probe(device, PTR_ERR(dev->clk), "failed to acquire clock\n");
193185

194186
ret = i2c_dw_prepare_clk(dev, true);
195187
if (ret)
196-
goto exit_reset;
188+
return ret;
197189

198190
if (dev->clk) {
199191
struct i2c_timings *t = &dev->timings;
@@ -241,8 +233,6 @@ static int dw_i2c_plat_probe(struct platform_device *pdev)
241233
exit_probe:
242234
dw_i2c_plat_pm_cleanup(dev);
243235
i2c_dw_prepare_clk(dev, false);
244-
exit_reset:
245-
reset_control_assert(dev->rst);
246236
return ret;
247237
}
248238

@@ -262,8 +252,6 @@ static void dw_i2c_plat_remove(struct platform_device *pdev)
262252
dw_i2c_plat_pm_cleanup(dev);
263253

264254
i2c_dw_prepare_clk(dev, false);
265-
266-
reset_control_assert(dev->rst);
267255
}
268256

269257
static const struct of_device_id dw_i2c_of_match[] = {

0 commit comments

Comments
 (0)