Re: [PATCH v7 2/3] i2c: ma35d1: Add Nuvoton MA35D1 I2C driver support

zychen <[email protected]>
Newsgroups gmane.linux.drivers.i2c,gmane.linux.drivers.devicetree,gmane.linux.ports.arm.kernel,gmane.linux.kernel
Message-ID <[email protected]>
Hi Andi,

Andi Shyti 於 2026/7/30 上午 05:06 寫道:
> Hi Zi-Yu,
> 
> ...
> 
>> +static void ma35d1_i2c_stop(struct ma35d1_i2c *i2c, int ret)
>> +{
>> +	ma35d1_i2c_write_ctl(i2c, MA35_CTL_STO_SI);
> 
> I think there is a valid review from sashiko here.
> 
Address sashiko's review, I will introduce a new helper to handle
bus errors and spurious interrupts based on the current state, while
keeping ma35d1_i2c_stop() unchanged and used exclusively during
active transfers.

>> +	if (ret)
>> +		i2c->err = ret;
>> +
>> +	ma35d1_i2c_controller_complete(i2c);
>> +}
> 
> ...
> 
>> +static irqreturn_t ma35d1_i2c_irq(int irqno, void *dev_id)
>> +{
>> +	struct ma35d1_i2c *i2c = dev_id;
>> +	unsigned long status;
>> +
>> +	status = readl(i2c->regs + MA35_STATUS0);
>> +
>> +	if (status == MA35_BUS_ERROR) {
>> +		dev_err(i2c->dev, "Bus error during transfer\n");
>> +		ma35d1_i2c_stop(i2c, -EIO);
>> +		goto out;
>> +	}
>> +
>> +	if (ma35d1_is_controller_status(status))
>> +		ma35d1_i2c_irq_controller_trx(i2c, status);
>> +	else
>> +		ma35d1_i2c_irq_target_trx(i2c, status);
> 
> Why are these functions void? We should at least print an error
> in case of failures.
> 
Agree.
Changed the return types of both TRX helper functions to irqreturn_t.
On unhandled/unknown status codes, will return IRQ_NONE.

>> +
>> +out:
>> +	return IRQ_HANDLED;
>> +}
> 
> ...
> 
>> +static int ma35d1_i2c_probe(struct platform_device *pdev)
>> +{
>> +	struct ma35d1_i2c *i2c;
>> +	struct resource *res;
>> +	int ret, clkdiv;
>> +	u32 val;
>> +	unsigned int busfreq;
> 
> you can immediately initialize busfreq here.
Sure.

> 
>> +	struct device *dev = &pdev->dev;
> 
> nit: can you please sort the declaration by line length, in a
> reverse christmast tree shape?
Sure.
> 
>> +	i2c = devm_kzalloc(dev, sizeof(*i2c), GFP_KERNEL);
>> +	if (!i2c)
>> +		return -ENOMEM;
> 
> ...
> 
>> +	ret = devm_add_action_or_reset(dev, ma35d1_i2c_pm_cleanup, dev);
>> +	if (ret)
>> +		goto rpm_put;
>> +
>> +	writel(MA35_CTL_I2CEN | MA35_CTL_INTEN, i2c->regs + MA35_CTL0);
>> +	writel(FIELD_PREP(MA35_CLKDIV_MSK, clkdiv), i2c->regs + MA35_CLKDIV);
>> +
>> +	ret = devm_request_irq(dev, i2c->irq, ma35d1_i2c_irq, 0, dev_name(dev),
>> +			       i2c);
>> +	if (ret) {
>> +		dev_err_probe(dev, ret, "cannot claim IRQ %d\n", i2c->irq);
>> +		goto rpm_put;
> 
> The actions in rpm_put are executed twice, considering
> devm_add_action_or_reset.
> 
Agree.
Removed the redundant rpm_put label and changed error paths to return
ret directly, leaving PM cleanup to devm_add_action_or_reset().

All these changes will be included in v8.

> Thanks,
> Andi
> 
>> +	}

Best regards,
Zi-Yu
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.