Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pl022 spi v2 #905

Merged
merged 1 commit into from
Jul 22, 2016
Merged

pl022 spi v2 #905

merged 1 commit into from
Jul 22, 2016

Conversation

vchong
Copy link
Contributor

@vchong vchong commented Jul 7, 2016

Signed-off-by: Victor Chong [email protected]

@vchong
Copy link
Contributor Author

vchong commented Jul 7, 2016

+ @daniel-thompson fyi only

@vchong vchong mentioned this pull request Jul 7, 2016

static void pl022_sanity_check(struct pl022_data *pd)
{
DMSG("SSPB2BTRANS: Expected: 0x2. Read: 0x%x\n",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could check here that fields expected by pl022_configure() are initialized: non null, assuming pl022_init() resets the pl022_data structure. i.e base, and cs_gpio_pin

Copy link
Contributor Author

@vchong vchong Jul 8, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something like this?

edited

    assert(pd);
    assert(pd->chip.ops);
    assert(pd->base);
    assert(pd->cs_gpio_base);
    assert(pd->clk_hz);
    assert(pd->speed_hz && pd->speed_hz <= pd->clk_hz/2);
    assert(pd->mode <= SPI_MODE3);
    assert(pd->data_size_bits == 8 || pd->data_size_bits == 16);

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mode and data_size_bitsdo not need to be asserted. their value are checked in pl022_configure().

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't it easier to check/assert them here as you suggested than to wait till we get to pl022_configure()? If so, I can remove the value checkings in pl022_configure(), but should be no harm leaving them there?

@etienne-lms
Copy link
Contributor

thanks for the instantiation of the spi devices.

as a general minor comment: most of the uint32_t are simply unsigned values. I think you should better declare them as unsigned int, not caring about being 32b or 64b:

  • i and j counter in loops
  • num_txpkts and num_rxpkts arguments of send/recv handlers.
  • clk_hz and speed_hz fields of pl022_data structure, and related freqX local variables.

also the pl022_configuration() should fail somehow in case of bad configuration. panic or return with some non-null value ?


/* rx 1 packet */
if (read32(pd->base + SSPSR) & SSPSR_RNE)
rdat[j++] = read8(pd->base + SSPDR);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How can we know that the buffer is large enough?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The transfer by itself is always one packet/word in and one out, but since SPI doesn't specify rules for number of packets transmitted and/or received (does it?), the code was written with the assumption that there's a possibility to receive more packets than sent, and decisions regarding buffer size left to the caller assumed to have that knowledge, but yes, this does lead to a possibility of overflow.

What about

  1. Read only as many packets as transmitted, or
  2. Add a parameter to specify the length of the buffer, and only read up to its size, or
  3. Other better suggestions?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Normally one would expect *num_rxpkts hold the number of max packets to receive.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, will use num_rxpkts as inout.

@vchong
Copy link
Contributor Author

vchong commented Jul 8, 2016

thanks for the instantiation of the spi devices.

np, thanks for the review! :)

i and j counter in loops
num_txpkts and num_rxpkts arguments of send/recv handlers.

Changed these to size_t per Jens.

clk_hz and speed_hz fields of pl022_data structure, and related freqX local variables.

Changed these to unsigned int as suggested.

also the pl022_configuration() should fail somehow in case of bad configuration. panic or return with some non-null value ?

Is the assert suggested in the sanity check function above sufficient?

tee_time_wait(1);

DMSG("TX FIFO available.. resuming..\n");
i--; /* retry current packet in next loop */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a bit complicated. Why not just test this stuff at the beginning of the loop instead of decreasing i to make another round.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok. Will try to simplify this.

@vchong vchong force-pushed the spi2 branch 7 times, most recently from 4c1bfb2 to 45352cc Compare July 9, 2016 10:04
@vchong
Copy link
Contributor Author

vchong commented Jul 9, 2016

Comments addressed. Please continue review.

Thanks!

@vchong vchong force-pushed the spi2 branch 2 times, most recently from 5be9077 to 8d58f7c Compare July 9, 2016 10:25
size_t i = 0, j = 0;
struct pl022_data *pd = container_of(chip, struct pl022_data, chip);

gpio_set_value(pd->cs_gpio_pin, GPIO_LEVEL_LOW);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in case no data to read/write, it could be better to not trig the chip-select low/high.
maybe it's not an issue with SPI.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not an issue to toggle cs on no data as long as clk stays still. I can add a check to return if num_txpkts == 0, but that does seem to unnecessarily complicate the code for a use case that's probably close to 0%? I.e. why call read/write when there's nothing to read/write?

@etienne-lms
Copy link
Contributor

Reviewed-by: etienne carriere <[email protected]>

@vchong
Copy link
Contributor Author

vchong commented Jul 19, 2016

@jenswi-linaro Are you ok with the new changes as well?

@jenswi-linaro
Copy link
Contributor

Reviewed-by: Jens Wiklander <[email protected]>

@vchong
Copy link
Contributor Author

vchong commented Jul 19, 2016

Rebased, squashed, tags added and ready for merge. Thanks!

@jforissier
Copy link
Contributor

I'd like to see the outcome of the Travis build. For some reason it has not triggered; I will investigate.
I found a compile error when CFG_TEE_CORE_LOG_LEVEL=2:

core/drivers/pl022_spi.c: In function ‘pl022_flush_fifo’:
core/drivers/pl022_spi.c:402:11: error: variable ‘rdat’ set but not used [-Werror=unused-but-set-variable]
  uint32_t rdat;
           ^
cc1: all warnings being treated as errors
mk/compile.mk:146: recipe for target 'out/arm-plat-hikey/core/drivers/pl022_spi.o' failed

(you need to add a __maybe_unused qualifier).

#include <trace.h>
#include <util.h>

/* spi register offsets */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SPI

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

@jforissier
Copy link
Contributor

Please add $make CFG_PL022=y to .travis.yml so that this code gets compiled by the CI loop.

@vchong
Copy link
Contributor Author

vchong commented Jul 20, 2016

__maybe_unused added to rdat

@vchong
Copy link
Contributor Author

vchong commented Jul 21, 2016

Added $make PLATFORM=hikey CFG_ARM64_core=y CFG_TEE_TA_LOG_LEVEL=4 DEBUG=1 CFG_PL061=y CFG_PL022=y to .travis.yml.

@vchong vchong force-pushed the spi2 branch 3 times, most recently from 715fc3b to 60ad160 Compare July 21, 2016 12:59
@vchong
Copy link
Contributor Author

vchong commented Jul 21, 2016

Comments addressed. Please continue review.

@vchong
Copy link
Contributor Author

vchong commented Jul 21, 2016

Update: Added CFG_PL061=y CFG_PL022=y to some other platforms in .travis.yml.

@@ -94,9 +94,11 @@ script:

# FVP
- $make PLATFORM=vexpress-fvp CFG_ARM32_core=y
- $make PLATFORM=vexpress-fvp CFG_ARM32_core=y CFG_PL061=y CFG_PL022=y
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering if we should enable PL061 and PL022 by default on HiKey instead. Then, no need to add anything to .travis.yml to have the code build-tested by Travis. Enabling them on other platforms would not check more things it seems. What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good to me. Will change.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK thanks, sorry for my bad suggestion in the first place ;)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No problem. Updated and waiting for travis results.

@jforissier
Copy link
Contributor

Reviewed-by: Jerome Forissier <[email protected]>

@vchong
Copy link
Contributor Author

vchong commented Jul 22, 2016

Rebased, squashed and additional tag added. Ok for merge? Thanks!

Signed-off-by: Victor Chong <[email protected]>
Reviewed-by: etienne carriere <[email protected]>
Reviewed-by: Jens Wiklander <[email protected]>
Reviewed-by: Jerome Forissier <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants