From: dsneddon@codeaurora.org
To: "Ivan T. Ivanov" <iivanov@mm-sol.com>
Cc: dsneddon@codeaurora.org, broonie@kernel.org,
grant.likely@linaro.org, robh+dt@kernel.org,
linux-spi@vger.kernel.org, linux-arm-msm@vger.kernel.org,
inux-kernel@vger.kernel.org, devicetree@vger.kernel.org,
alokc@codeaurora.org, gavidov@codeaurora.org,
kgunda@codeaurora.org, sdharia@codeaurora.org
Subject: Re: Fwd: [PATCH 2/2] spi: Add Qualcomm QUP SPI controller support
Date: Mon, 10 Feb 2014 17:41:31 -0000 [thread overview]
Message-ID: <9444e7f42975231b50bc6564192ba416.squirrel@www.codeaurora.org> (raw)
In-Reply-To: <1392052316.2853.67.camel@iivanov-dev>
Hi Ivan,
>> >> > +static int spi_qup_set_state(struct spi_qup *controller, u32
>> state)
>> >> > +{
>> >> > + unsigned long loop = 0;
>> >> > + u32 cur_state;
>> >> > +
>> >> > + cur_state = readl_relaxed(controller->base + QUP_STATE);
>> >> Make sure the state is valid before you read the current state.
>> >
>> > Why? Controller is always left in valid state (after probe and every
>> > transaction)? I know that CAF code contain this check, but now driver
>> > is little bit different. I have made some tests and controller is
>> > always in valid state in this point.
>>
>> The hardware programming guide we recommends doing this. I'd have to
>> talk
>> to the hardware designers to know exactly the reason why. I can follow
>> up
>> on this if you'd like.
>>
>
> Ok, thanks. I could add it back. Please, could you point me to place
> in driver where this could happen.
>
>
>> >
>> >> > + /*
>> >> > + * Per spec: for PAUSE_STATE to RESET_STATE, two writes
>> >> > + * of (b10) are required
>> >> > + */
>> >> > + if (((cur_state & QUP_STATE_MASK) == QUP_STATE_PAUSE) &&
>> >> > + (state == QUP_STATE_RESET)) {
>> >> > + writel_relaxed(QUP_STATE_CLEAR, controller->base +
>> >> > QUP_STATE);
>> >> > + writel_relaxed(QUP_STATE_CLEAR, controller->base +
>> >> > QUP_STATE);
>> >> > + } else {
>> >> Make sure you don't transition from RESET to PAUSE.
>> >
>> > I don't see this to be handled in CAF code. Could you give me
>> > more details, please?
>> >
>> > Right now possible state transactions are:
>> >
>> > * if everything is fine:
>> > RESET -> RUN -> PAUSE -> RUN -> RESET
>> > * in case of error:
>> > RESET -> RUN -> RESET
>> > RESET -> RUN -> PAUSE -> RESET
>> >
>> > Please correct me if I am wrong.
>>
>> According to the hardware documentation if the hardware is in the RESET
>> state and we try to transition to the PAUSE state the hardware behavior
>> is
>> "undefined", which usually means bad things will happen. Admittedly, if
>> the driver always follows the "valid" rules (the ones you've listed
>> above)
>> it _should_ never happen. However, it is _possible_ the hardware is in
>> the RESET state while the driver thinks it's in the RUN state and the
>> driver tries to put is in the PAUSE state. In other words, I'd like to
>> err on the side of caution since the check doesn't really cost us
>> anything.
>
> Ok that is fine, but did you see where/how this could happen in
> the current implementation. If this could happen I will like to fix it.
I don't see a problem in the current implementation that would cause you
to get in the RESET state without knowing it. It's just my paranoia
kicking in.
>
>>
>> >
>> >> > +
>> >> > +static void spi_qup_fifo_read(struct spi_qup *controller,
>> >> > + struct spi_transfer *xfer)
>> >> > +{
>> >> > + u8 *rx_buf = xfer->rx_buf;
>> >> > + u32 word, state;
>> >> > + int idx, shift;
>> >> > +
>> >> > + while (controller->rx_bytes < xfer->len) {
>> >> > +
>> >> > + state = readl_relaxed(controller->base +
>> >> QUP_OPERATIONAL);
>> >> > + if (0 == (state & QUP_OP_IN_FIFO_NOT_EMPTY))
>> >> > + break;
>> >> > +
>> >> > + word = readl_relaxed(controller->base +
>> >> QUP_INPUT_FIFO);
>> >> > +
>> >> > + for (idx = 0; idx < controller->bytes_per_word &&
>> >> > + controller->rx_bytes < xfer->len; idx++,
>> >> > + controller->rx_bytes++) {
>> >> > +
>> >> > + if (!rx_buf)
>> >> > + continue;
>> >> If there is no rx_buf just set rx_bytes to xfer->len and skip the
>> loop
>> >> entirely.
>> >
>> > Well, FIFO buffer still should be drained, right?
>> > Anyway. I am looking for better way to handle this.
>> > Same applies for filling FIFO buffer.
>> >
>>
>> Yes. Still read from the FIFO but skip the for loop since we're just
>> adding bytes_per_word to the total rx_byte count one iteration at a time
>> and not doing anything with the data.
>>
>
> My point was: If I made rx_bytes equal xfer->len, outer while loop will
> be terminated before FIFO was drained :-). I will see how to handle
> this better.
You're right! Had to read that snippet again. Though, I think we can
skip draining the FIFO by setting the NO_INPUT bit in the QUP_CONFIG
register (and the NO_OUTPUT for writes).
next prev parent reply other threads:[~2014-02-10 17:41 UTC|newest]
Thread overview: 37+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-02-06 16:57 [PATCH 0/2] spi: Add Qualcomm QUP SPI controller support Ivan T. Ivanov
2014-02-06 16:57 ` [PATCH 1/2] spi: qup: Add device tree bindings information Ivan T. Ivanov
[not found] ` <1391705868-20091-2-git-send-email-iivanov-NEYub+7Iv8PQT0dZR+AlfA@public.gmane.org>
2014-02-07 7:43 ` Andy Gross
2014-02-06 16:57 ` [PATCH 2/2] spi: Add Qualcomm QUP SPI controller support Ivan T. Ivanov
2014-02-07 7:39 ` Andy Gross
[not found] ` <20140207073952.GA2610-zC7DfRvBq/JWk0Htik3J/w@public.gmane.org>
2014-02-07 9:52 ` Ivan T. Ivanov
2014-02-07 17:32 ` Andy Gross
2014-02-07 17:52 ` Mark Brown
[not found] ` <20140207175234.GJ1757-GFdadSzt00ze9xe1eoZjHA@public.gmane.org>
2014-02-07 19:12 ` Andy Gross
2014-02-10 16:55 ` Ivan T. Ivanov
2014-02-10 17:47 ` Andy Gross
[not found] ` <20140210174738.GA31596-zC7DfRvBq/JWk0Htik3J/w@public.gmane.org>
2014-02-10 19:41 ` Ivan T. Ivanov
2014-02-10 20:29 ` Courtney Cavin
2014-02-10 20:59 ` Ivan T. Ivanov
2014-02-10 21:40 ` Mark Brown
[not found] ` <20140210202926.GV1706-/MT0OVThwyLZJqsBc5GL+g@public.gmane.org>
2014-02-11 15:46 ` Ivan T. Ivanov
2014-02-07 16:51 ` Josh Cartwright
[not found] ` <20140207165127.GV20228-OP5zVEFNDbfdOxZ39nK119BPR1lH4CV8@public.gmane.org>
2014-02-07 17:18 ` Mark Brown
2014-02-07 17:20 ` Josh Cartwright
[not found] ` <20140207172051.GW20228-OP5zVEFNDbfdOxZ39nK119BPR1lH4CV8@public.gmane.org>
2014-02-07 17:31 ` Mark Brown
[not found] ` <20140207173108.GH1757-GFdadSzt00ze9xe1eoZjHA@public.gmane.org>
2014-02-07 17:46 ` Josh Cartwright
2014-02-07 17:57 ` Mark Brown
[not found] ` <CACceFXdUobQvN2hcv5kh+QL=o8bWM_PVkAtrOx+euZSeVDm8hQ@mail.gmail.com>
2014-02-07 16:34 ` Fwd: " dsneddon
2014-02-07 17:16 ` Mark Brown
[not found] ` <214fe9fc7e62ab30bdfbb4ac5d1ee250.squirrel-mMfbam+mt9083fI46fginR2eb7JE58TQ@public.gmane.org>
2014-02-10 15:54 ` Ivan T. Ivanov
2014-02-10 16:21 ` dsneddon
[not found] ` <3388d68dc907e9190d997fad95830d74.squirrel-mMfbam+mt9083fI46fginR2eb7JE58TQ@public.gmane.org>
2014-02-10 17:11 ` Ivan T. Ivanov
2014-02-10 17:41 ` dsneddon [this message]
[not found] ` <1391705868-20091-3-git-send-email-iivanov-NEYub+7Iv8PQT0dZR+AlfA@public.gmane.org>
2014-02-07 17:12 ` Mark Brown
[not found] ` <20140207171202.GD1757-GFdadSzt00ze9xe1eoZjHA@public.gmane.org>
2014-02-10 16:29 ` Ivan T. Ivanov
2014-02-10 17:09 ` Mark Brown
2014-02-06 17:50 ` [PATCH 0/2] " Mark Brown
2014-02-07 7:43 ` [PATCH RESEND 1/2] spi: qup: Add device tree bindings information Ivan T. Ivanov
2014-02-07 12:27 ` Mark Brown
2014-02-07 13:00 ` Ivan T. Ivanov
2014-02-07 13:13 ` Mark Brown
2014-02-07 13:35 ` Ivan T. Ivanov
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=9444e7f42975231b50bc6564192ba416.squirrel@www.codeaurora.org \
--to=dsneddon@codeaurora.org \
--cc=alokc@codeaurora.org \
--cc=broonie@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=gavidov@codeaurora.org \
--cc=grant.likely@linaro.org \
--cc=iivanov@mm-sol.com \
--cc=inux-kernel@vger.kernel.org \
--cc=kgunda@codeaurora.org \
--cc=linux-arm-msm@vger.kernel.org \
--cc=linux-spi@vger.kernel.org \
--cc=robh+dt@kernel.org \
--cc=sdharia@codeaurora.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;
as well as URLs for NNTP newsgroup(s).