Skip to content

Commit 8525205

Browse files
Hans HuAndi Shyti
authored andcommitted
i2c: wmt: create wmt_i2c_init for general init
Some common initialization actions are put in the function wmt_i2c_init(), which is convenient to share with zhaoxin. Reviewed-by: Andi Shyti <andi.shyti@kernel.org> Reviewed-by: Wolfram Sang <wsa+renesas@sang-engineering.com> Signed-off-by: Hans Hu <hanshu-oc@zhaoxin.com> Signed-off-by: Andi Shyti <andi.shyti@kernel.org>
1 parent 53e3d52 commit 8525205

1 file changed

Lines changed: 37 additions & 28 deletions

File tree

drivers/i2c/busses/i2c-wmt.c

Lines changed: 37 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ static int wmt_check_status(struct wmt_i2c_dev *i2c_dev)
109109
unsigned long wait_result;
110110

111111
wait_result = wait_for_completion_timeout(&i2c_dev->complete,
112-
msecs_to_jiffies(500));
112+
msecs_to_jiffies(500));
113113
if (!wait_result)
114114
return -ETIMEDOUT;
115115

@@ -286,6 +286,38 @@ static irqreturn_t wmt_i2c_isr(int irq, void *data)
286286
return IRQ_HANDLED;
287287
}
288288

289+
static int wmt_i2c_init(struct platform_device *pdev, struct wmt_i2c_dev **pi2c_dev)
290+
{
291+
int err;
292+
struct wmt_i2c_dev *i2c_dev;
293+
struct device_node *np = pdev->dev.of_node;
294+
295+
i2c_dev = devm_kzalloc(&pdev->dev, sizeof(*i2c_dev), GFP_KERNEL);
296+
if (!i2c_dev)
297+
return -ENOMEM;
298+
299+
i2c_dev->base = devm_platform_get_and_ioremap_resource(pdev, 0, NULL);
300+
if (IS_ERR(i2c_dev->base))
301+
return PTR_ERR(i2c_dev->base);
302+
303+
i2c_dev->irq = irq_of_parse_and_map(np, 0);
304+
if (!i2c_dev->irq)
305+
return -EINVAL;
306+
307+
err = devm_request_irq(&pdev->dev, i2c_dev->irq, wmt_i2c_isr,
308+
0, pdev->name, i2c_dev);
309+
if (err)
310+
return dev_err_probe(&pdev->dev, err,
311+
"failed to request irq %i\n", i2c_dev->irq);
312+
313+
i2c_dev->dev = &pdev->dev;
314+
init_completion(&i2c_dev->complete);
315+
platform_set_drvdata(pdev, i2c_dev);
316+
317+
*pi2c_dev = i2c_dev;
318+
return 0;
319+
}
320+
289321
static int wmt_i2c_reset_hardware(struct wmt_i2c_dev *i2c_dev)
290322
{
291323
int err;
@@ -327,19 +359,9 @@ static int wmt_i2c_probe(struct platform_device *pdev)
327359
int err;
328360
u32 clk_rate;
329361

330-
i2c_dev = devm_kzalloc(&pdev->dev, sizeof(*i2c_dev), GFP_KERNEL);
331-
if (!i2c_dev)
332-
return -ENOMEM;
333-
334-
i2c_dev->base = devm_platform_get_and_ioremap_resource(pdev, 0, NULL);
335-
if (IS_ERR(i2c_dev->base))
336-
return PTR_ERR(i2c_dev->base);
337-
338-
i2c_dev->irq = irq_of_parse_and_map(np, 0);
339-
if (!i2c_dev->irq) {
340-
dev_err(&pdev->dev, "irq missing or invalid\n");
341-
return -EINVAL;
342-
}
362+
err = wmt_i2c_init(pdev, &i2c_dev);
363+
if (err)
364+
return err;
343365

344366
i2c_dev->clk = of_clk_get(np, 0);
345367
if (IS_ERR(i2c_dev->clk)) {
@@ -348,18 +370,9 @@ static int wmt_i2c_probe(struct platform_device *pdev)
348370
}
349371

350372
err = of_property_read_u32(np, "clock-frequency", &clk_rate);
351-
if (!err && (clk_rate == I2C_MAX_FAST_MODE_FREQ))
373+
if (!err && clk_rate == I2C_MAX_FAST_MODE_FREQ)
352374
i2c_dev->tcr = TCR_FAST_MODE;
353375

354-
i2c_dev->dev = &pdev->dev;
355-
356-
err = devm_request_irq(&pdev->dev, i2c_dev->irq, wmt_i2c_isr, 0,
357-
"i2c", i2c_dev);
358-
if (err) {
359-
dev_err(&pdev->dev, "failed to request irq %i\n", i2c_dev->irq);
360-
return err;
361-
}
362-
363376
adap = &i2c_dev->adapter;
364377
i2c_set_adapdata(adap, i2c_dev);
365378
strscpy(adap->name, "WMT I2C adapter", sizeof(adap->name));
@@ -368,8 +381,6 @@ static int wmt_i2c_probe(struct platform_device *pdev)
368381
adap->dev.parent = &pdev->dev;
369382
adap->dev.of_node = pdev->dev.of_node;
370383

371-
init_completion(&i2c_dev->complete);
372-
373384
err = wmt_i2c_reset_hardware(i2c_dev);
374385
if (err) {
375386
dev_err(&pdev->dev, "error initializing hardware\n");
@@ -380,8 +391,6 @@ static int wmt_i2c_probe(struct platform_device *pdev)
380391
if (err)
381392
goto err_disable_clk;
382393

383-
platform_set_drvdata(pdev, i2c_dev);
384-
385394
return 0;
386395

387396
err_disable_clk:

0 commit comments

Comments
 (0)