Date: Sun, 2 Sep 2012 08:47:14 -0600 From: Warner Losh <imp@bsdimp.com> To: Luiz Otavio O Souza <loos.br@gmail.com> Cc: freebsd-arch@freebsd.org Subject: Re: spibus access serialization Message-ID: <A0F87D2D-B916-4FB5-9FDF-62807DED9A7E@bsdimp.com> In-Reply-To: <B54C4C9A-76F4-45CC-94C3-628DDF901051@gmail.com> References: <B54C4C9A-76F4-45CC-94C3-628DDF901051@gmail.com>
next in thread | previous in thread | raw e-mail | index | archive | help
On Sep 2, 2012, at 6:37 AM, Luiz Otavio O Souza wrote: > Hi, >=20 > I've some embedded systems with spi devices that share the same spibus = and because of that i'm working to get some kind of access serialization = on spibus and also protection to devices which need a series of spi = transfers to achieve some goal. >=20 > The SPI usage (with all the patches applied) goes like this: >=20 > /* Wait until the spibus is free. When free, acquire the bus and = select the device */ > SPIBUS_ACQUIRE_BUS(spibus, device); Does it do this with a sleep? > /* Program the CPLD to read data from NAND */ > SPIBUS_TRANSFER(spibus, device, &cmd); >=20 > /* Read 'n' bytes from CPLD */ > SPIBUS_TRANSFER(spibus, device, &cmd); >=20 > /* Release the spibus and deselect the device */ > SPIBUS_RELEASE_BUS(spibus, device); >=20 > While today everything is done inside SPIBUS_TRANSFER(). >=20 > The patch spibus-01.diff adds the bus methods and the default methods. >=20 > The spibus-02-devices.diff adds the needed glue to all spi devices = (dev/flash/at45d.c, dev/flash/mx25l.c, arm/lpc/ssd1289.c, = mips/atheros/pcf2123_rtc.c). As the default methods are just nops, there = are no functional changes. >=20 > On spibus-03-controllers.diff we finally add the serialization methods = to spi controllers (mips/atheros/ar71xx_spi.c and arm/lpc/lpc_spi.c) and = change the device CS to happen on bus acquire and release and not on = start and end of each transfer. >=20 > The spi controller on arm/at91/at91_spi.c wasn't changed because looks = like it will be need to move the device CS control from the controller = and use it as a GPIO pin. I need to read more of at91 code before i can = suggest some change there. Until there it will work just as now (no = serialization and selecting/deselecting the device within each = transfer). The at91_spi controller controls which CS line is asserted. So long as = you don't change the bits in the registers, it will stay asserted. I = think it can fit with this scheme. I'll have to take a closer look. = All my AT91 devices have only one chip on the spi bus. > Comments ? I like the idea.... I'll review the code in more detail to see if I see = any gotchas in it. Not sure why we need so many different flash modules, but that's a = different issue. > Thanks, > Luiz >=20 >=20 >=20 > = <spibus-01.diff><spibus-02-devices.diff><spibus-03-controllers.diff>______= _________________________________________ > freebsd-arch@freebsd.org mailing list > http://lists.freebsd.org/mailman/listinfo/freebsd-arch > To unsubscribe, send any mail to = "freebsd-arch-unsubscribe@freebsd.org"
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?A0F87D2D-B916-4FB5-9FDF-62807DED9A7E>