From: <Conor.Dooley@microchip.com>
To: <hdanton@sina.com>
Cc: <wsa@kernel.org>, <linux-i2c@vger.kernel.org>,
<linux-kernel@vger.kernel.org>, <linux-riscv@lists.infradead.org>,
<Daire.McNamara@microchip.com>
Subject: Re: [PATCH v2] i2c: add support for microchip fpga i2c controllers
Date: Wed, 4 May 2022 12:54:36 +0000 [thread overview]
Message-ID: <c4ccffe9-9892-2e32-45fc-7028f9b92a7b@microchip.com> (raw)
In-Reply-To: <20220504091622.5024-1-hdanton@sina.com>
On 04/05/2022 10:16, Hillf Danton wrote:
> [You don't often get email from hdanton@sina.com. Learn why this is important at https://aka.ms/LearnAboutSenderIdentification.]
>
> EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe
>
> On Mon, 21 Mar 2022 12:58:56 +0000 Conor Dooley wrote:
>> +
>> +static irqreturn_t mchp_corei2c_handle_isr(struct mchp_corei2c_dev *idev)
>> +{
>> + u32 status = idev->isr_status;
>> + u8 ctrl;
>> +
>> + if (!idev->buf)
>> + return IRQ_NONE;
>> +
>> + switch (status) {
>> + case STATUS_M_START_SENT:
>> + case STATUS_M_REPEATED_START_SENT:
>> + ctrl = readb(idev->base + CORE_I2C_CTRL);
>> + ctrl &= ~CTRL_STA;
>> + writeb(idev->addr, idev->base + CORE_I2C_DATA);
>> + writeb(ctrl, idev->base + CORE_I2C_CTRL);
>> + if (idev->msg_len <= 0)
>> + goto finished;
>> + break;
>> + case STATUS_M_ARB_LOST:
>> + idev->msg_err = -EAGAIN;
>> + goto finished;
>> + case STATUS_M_SLAW_ACK:
>> + case STATUS_M_TX_DATA_ACK:
>> + if (idev->msg_len > 0)
>> + mchp_corei2c_fill_tx(idev);
>> + else
>> + goto last_byte;
>> + break;
>> + case STATUS_M_TX_DATA_NACK:
>> + case STATUS_M_SLAR_NACK:
>> + case STATUS_M_SLAW_NACK:
>> + idev->msg_err = -ENXIO;
>> + goto last_byte;
>> + case STATUS_M_SLAR_ACK:
>> + ctrl = readb(idev->base + CORE_I2C_CTRL);
>> + if (idev->msg_len == 1u) {
>> + ctrl &= ~CTRL_AA;
>> + writeb(ctrl, idev->base + CORE_I2C_CTRL);
>> + } else {
>> + ctrl |= CTRL_AA;
>> + writeb(ctrl, idev->base + CORE_I2C_CTRL);
>> + }
>> + if (idev->msg_len < 1u)
>> + goto last_byte;
>> + break;
>> + case STATUS_M_RX_DATA_ACKED:
>> + mchp_corei2c_empty_rx(idev);
>> + break;
>> + case STATUS_M_RX_DATA_NACKED:
>> + mchp_corei2c_empty_rx(idev);
>> + if (idev->msg_len == 0)
>> + goto last_byte;
>> + break;
>> + default:
>> + break;
>> + }
>> +
>> + return IRQ_HANDLED;
>> +
>> +last_byte:
>> + /* On the last byte to be transmitted, send STOP */
>> + mchp_corei2c_stop(idev);
>> +finished:
>> + complete(&idev->msg_complete);
>> + return IRQ_HANDLED;
>> +}
>> +
>> +static irqreturn_t mchp_corei2c_isr(int irq, void *_dev)
>> +{
>> + struct mchp_corei2c_dev *idev = _dev;
>> + irqreturn_t ret = IRQ_NONE;
>> + u8 ctrl;
>> +
>> + ctrl = readb(idev->base + CORE_I2C_CTRL);
>> + if (ctrl & CTRL_SI) {
>> + idev->isr_status = readb(idev->base + CORE_I2C_STATUS);
>> + ret = mchp_corei2c_handle_isr(idev);
>> + }
>> +
>> + /* Clear the si flag */
>> + ctrl = readb(idev->base + CORE_I2C_CTRL);
>> + ctrl &= ~CTRL_SI;
>> + writeb(ctrl, idev->base + CORE_I2C_CTRL);
>> +
>> + return ret;
>> +}
>> +
>> +static int mchp_corei2c_xfer_msg(struct mchp_corei2c_dev *idev,
>> + struct i2c_msg *msg)
>> +{
>> + u8 ctrl;
>> + unsigned long time_left;
>> +
>> + if (msg->len == 0)
>> + return -EINVAL;
>> +
>> + idev->addr = i2c_8bit_addr_from_msg(msg);
>> + idev->msg_len = msg->len;
>> + idev->buf = msg->buf;
>> + idev->msg_err = 0;
>> + idev->msg_read = (msg->flags & I2C_M_RD);
>> +
>> + reinit_completion(&idev->msg_complete);
>
> Would you specify why you need reinit completion? Is it likely to race
> with the complete() above in mchp_corei2c_handle_isr()?
Is it not fairly common in i2c drivers to use a reinit completion()/
wait_for_completion_timeout() in the xfer function with a complete()
in the isr?
I can certainly add a comment explaining why this is being done?
Thanks,
Conor.
next parent reply other threads:[~2022-05-04 12:54 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20220504091622.5024-1-hdanton@sina.com>
2022-05-04 12:54 ` Conor.Dooley [this message]
2022-03-21 12:58 [PATCH v2] i2c: add support for microchip fpga i2c controllers Conor Dooley
2022-05-04 8:40 ` Conor.Dooley
2022-05-04 16:17 ` Conor Dooley
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=c4ccffe9-9892-2e32-45fc-7028f9b92a7b@microchip.com \
--to=conor.dooley@microchip.com \
--cc=Daire.McNamara@microchip.com \
--cc=hdanton@sina.com \
--cc=linux-i2c@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-riscv@lists.infradead.org \
--cc=wsa@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox