* SPI chip select problem @ 2012-06-25 7:45 Antony Pavlov 2012-06-25 8:53 ` Johannes Stezenbach 0 siblings, 1 reply; 4+ messages in thread From: Antony Pavlov @ 2012-06-25 7:45 UTC (permalink / raw) To: barebox Hi! I have added spi controller driver for one of my MIPS boards and found, that there is a problem with chip select. During initialisation we call *_spi_setup() method. It switch chip select and frequency for every probing spi slave chip. But after initialisation __we never__ call this method. So if I have more than 1 spi slave chip, I can use only last of them. There is the 'cs_change' flag for *_spi_transfer() method, but this flag does not used at all! I have made quick-and-dirty patch: --- a/drivers/spi/spi.c +++ b/drivers/spi/spi.c @@ -196,6 +196,8 @@ EXPORT_SYMBOL(spi_register_master); int spi_sync(struct spi_device *spi, struct spi_message *message) { + spi->master->setup(spi); + return spi->master->transfer(spi, message); } -- Best regards, Antony Pavlov _______________________________________________ barebox mailing list barebox@lists.infradead.org http://lists.infradead.org/mailman/listinfo/barebox ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: SPI chip select problem 2012-06-25 7:45 SPI chip select problem Antony Pavlov @ 2012-06-25 8:53 ` Johannes Stezenbach 2012-06-25 10:07 ` Antony Pavlov 0 siblings, 1 reply; 4+ messages in thread From: Johannes Stezenbach @ 2012-06-25 8:53 UTC (permalink / raw) To: Antony Pavlov; +Cc: barebox Hi, On Mon, Jun 25, 2012 at 11:45:06AM +0400, Antony Pavlov wrote: > I have added spi controller driver for one of my MIPS boards and > found, that there is a problem with chip select. > > During initialisation we call *_spi_setup() method. It switch chip > select and frequency for every probing spi slave chip. > But after initialisation __we never__ call this method. So if I have > more than 1 spi slave chip, I can use only last of them. > > There is the 'cs_change' flag for *_spi_transfer() method, but this > flag does not used at all! altera_spi.c and mic_spi.c use it, but often this is not needed (e.g. for SPI flashes) so to keep the code simple and small it might be better to not implement cs_change handling. > I have made quick-and-dirty patch: > > --- a/drivers/spi/spi.c > +++ b/drivers/spi/spi.c > @@ -196,6 +196,8 @@ EXPORT_SYMBOL(spi_register_master); > > int spi_sync(struct spi_device *spi, struct spi_message *message) > { > + spi->master->setup(spi); > + > return spi->master->transfer(spi, message); > } I noticed this issue, too, but since barebox spi code is similar to linux code I'd like to point out linux drivers must not modify the chip select in ->setup(). Since bare box only does synchronous transfers it isn't an issue, but in linux ->setup() is called when a new message is queued, at this time the previous message might still be transferring. Thus the only purpose of ->setup() is to do error checking on the provided parameters. Chip select, frequency etc. must be set in ->transfer(). In the interest of portability/similarity barebox drivers should do the same as linux. That said, your proposed patch still looks OK. BTW, ->cleanup() is also never called, but so far no driver needs it... Johannes _______________________________________________ barebox mailing list barebox@lists.infradead.org http://lists.infradead.org/mailman/listinfo/barebox ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: SPI chip select problem 2012-06-25 8:53 ` Johannes Stezenbach @ 2012-06-25 10:07 ` Antony Pavlov 2012-06-25 10:48 ` Johannes Stezenbach 0 siblings, 1 reply; 4+ messages in thread From: Antony Pavlov @ 2012-06-25 10:07 UTC (permalink / raw) To: Johannes Stezenbach; +Cc: barebox On 25 June 2012 12:53, Johannes Stezenbach <js@sig21.net> wrote: > Hi, > > On Mon, Jun 25, 2012 at 11:45:06AM +0400, Antony Pavlov wrote: >> I have added spi controller driver for one of my MIPS boards and >> found, that there is a problem with chip select. >> >> During initialisation we call *_spi_setup() method. It switch chip >> select and frequency for every probing spi slave chip. >> But after initialisation __we never__ call this method. So if I have >> more than 1 spi slave chip, I can use only last of them. >> >> There is the 'cs_change' flag for *_spi_transfer() method, but this >> flag does not used at all! > > altera_spi.c and mic_spi.c use it, but often this is not needed (e.g. for > SPI flashes) so to keep the code simple and small it might be better > to not implement cs_change handling. But I have not found any common code where cs_change is managed. > >> I have made quick-and-dirty patch: >> >> --- a/drivers/spi/spi.c >> +++ b/drivers/spi/spi.c >> @@ -196,6 +196,8 @@ EXPORT_SYMBOL(spi_register_master); >> >> int spi_sync(struct spi_device *spi, struct spi_message *message) >> { >> + spi->master->setup(spi); >> + >> return spi->master->transfer(spi, message); >> } > > I noticed this issue, too, but since barebox spi code is similar > to linux code I'd like to point out linux drivers must not modify the > chip select in ->setup(). Since bare box only does synchronous transfers > it isn't an issue, but in linux ->setup() is called when > a new message is queued, at this time the previous message > might still be transferring. Thus the only purpose of ->setup() > is to do error checking on the provided parameters. > Chip select, frequency etc. must be set in ->transfer(). > In the interest of portability/similarity barebox drivers should > do the same as linux. > > That said, your proposed patch still looks OK. > BTW, ->cleanup() is also never called, but so far no driver needs it... > > > Johannes -- Best regards, Antony Pavlov _______________________________________________ barebox mailing list barebox@lists.infradead.org http://lists.infradead.org/mailman/listinfo/barebox ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: SPI chip select problem 2012-06-25 10:07 ` Antony Pavlov @ 2012-06-25 10:48 ` Johannes Stezenbach 0 siblings, 0 replies; 4+ messages in thread From: Johannes Stezenbach @ 2012-06-25 10:48 UTC (permalink / raw) To: Antony Pavlov; +Cc: barebox On Mon, Jun 25, 2012 at 02:07:34PM +0400, Antony Pavlov wrote: > On 25 June 2012 12:53, Johannes Stezenbach <js@sig21.net> wrote: > > On Mon, Jun 25, 2012 at 11:45:06AM +0400, Antony Pavlov wrote: > >> > >> There is the 'cs_change' flag for *_spi_transfer() method, but this > >> flag does not used at all! > > > > altera_spi.c and mic_spi.c use it, but often this is not needed (e.g. for > > SPI flashes) so to keep the code simple and small it might be better > > to not implement cs_change handling. > > But I have not found any common code where cs_change is managed. It doesn't need to be handled in common code, the spi_device driver requests a cs_change if it needs one, the spi_master driver programs the hardware to do it. Common code in drivers/spi/spi.c doesn't need to care. (To clarify: cs_change does not mean to switch from one CS to another, it means to pulse the CS line between spi_transfers of a spi_message. Some devices need that in some cases.) Johannes _______________________________________________ barebox mailing list barebox@lists.infradead.org http://lists.infradead.org/mailman/listinfo/barebox ^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2012-06-25 10:49 UTC | newest] Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2012-06-25 7:45 SPI chip select problem Antony Pavlov 2012-06-25 8:53 ` Johannes Stezenbach 2012-06-25 10:07 ` Antony Pavlov 2012-06-25 10:48 ` Johannes Stezenbach
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox