diff options
author | Linus Torvalds <torvalds@g5.osdl.org> | 2006-01-14 13:43:26 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@g5.osdl.org> | 2006-01-14 13:43:26 -0500 |
commit | 61b7efddc5256225099d13185659e9ad9d8abc8a (patch) | |
tree | 7cbfec9c0012b07c7a236a953f5e067304725415 /Documentation | |
parent | 3e2b32b69308e974cd1167beaf266d3c716e4734 (diff) | |
parent | 2e10c84b9cf0b2d269c5629048d8d6e35eaf6b2b (diff) |
Merge master.kernel.org:/pub/scm/linux/kernel/git/gregkh/spi-2.6
Diffstat (limited to 'Documentation')
-rw-r--r-- | Documentation/spi/butterfly | 57 | ||||
-rw-r--r-- | Documentation/spi/spi-summary | 457 |
2 files changed, 514 insertions, 0 deletions
diff --git a/Documentation/spi/butterfly b/Documentation/spi/butterfly new file mode 100644 index 000000000000..a2e8c8d90e35 --- /dev/null +++ b/Documentation/spi/butterfly | |||
@@ -0,0 +1,57 @@ | |||
1 | spi_butterfly - parport-to-butterfly adapter driver | ||
2 | =================================================== | ||
3 | |||
4 | This is a hardware and software project that includes building and using | ||
5 | a parallel port adapter cable, together with an "AVR Butterfly" to run | ||
6 | firmware for user interfacing and/or sensors. A Butterfly is a $US20 | ||
7 | battery powered card with an AVR microcontroller and lots of goodies: | ||
8 | sensors, LCD, flash, toggle stick, and more. You can use AVR-GCC to | ||
9 | develop firmware for this, and flash it using this adapter cable. | ||
10 | |||
11 | You can make this adapter from an old printer cable and solder things | ||
12 | directly to the Butterfly. Or (if you have the parts and skills) you | ||
13 | can come up with something fancier, providing ciruit protection to the | ||
14 | Butterfly and the printer port, or with a better power supply than two | ||
15 | signal pins from the printer port. | ||
16 | |||
17 | |||
18 | The first cable connections will hook Linux up to one SPI bus, with the | ||
19 | AVR and a DataFlash chip; and to the AVR reset line. This is all you | ||
20 | need to reflash the firmware, and the pins are the standard Atmel "ISP" | ||
21 | connector pins (used also on non-Butterfly AVR boards). | ||
22 | |||
23 | Signal Butterfly Parport (DB-25) | ||
24 | ------ --------- --------------- | ||
25 | SCK = J403.PB1/SCK = pin 2/D0 | ||
26 | RESET = J403.nRST = pin 3/D1 | ||
27 | VCC = J403.VCC_EXT = pin 8/D6 | ||
28 | MOSI = J403.PB2/MOSI = pin 9/D7 | ||
29 | MISO = J403.PB3/MISO = pin 11/S7,nBUSY | ||
30 | GND = J403.GND = pin 23/GND | ||
31 | |||
32 | Then to let Linux master that bus to talk to the DataFlash chip, you must | ||
33 | (a) flash new firmware that disables SPI (set PRR.2, and disable pullups | ||
34 | by clearing PORTB.[0-3]); (b) configure the mtd_dataflash driver; and | ||
35 | (c) cable in the chipselect. | ||
36 | |||
37 | Signal Butterfly Parport (DB-25) | ||
38 | ------ --------- --------------- | ||
39 | VCC = J400.VCC_EXT = pin 7/D5 | ||
40 | SELECT = J400.PB0/nSS = pin 17/C3,nSELECT | ||
41 | GND = J400.GND = pin 24/GND | ||
42 | |||
43 | The "USI" controller, using J405, can be used for a second SPI bus. That | ||
44 | would let you talk to the AVR over SPI, running firmware that makes it act | ||
45 | as an SPI slave, while letting either Linux or the AVR use the DataFlash. | ||
46 | There are plenty of spare parport pins to wire this one up, such as: | ||
47 | |||
48 | Signal Butterfly Parport (DB-25) | ||
49 | ------ --------- --------------- | ||
50 | SCK = J403.PE4/USCK = pin 5/D3 | ||
51 | MOSI = J403.PE5/DI = pin 6/D4 | ||
52 | MISO = J403.PE6/DO = pin 12/S5,nPAPEROUT | ||
53 | GND = J403.GND = pin 22/GND | ||
54 | |||
55 | IRQ = J402.PF4 = pin 10/S6,ACK | ||
56 | GND = J402.GND(P2) = pin 25/GND | ||
57 | |||
diff --git a/Documentation/spi/spi-summary b/Documentation/spi/spi-summary new file mode 100644 index 000000000000..a5ffba33a351 --- /dev/null +++ b/Documentation/spi/spi-summary | |||
@@ -0,0 +1,457 @@ | |||
1 | Overview of Linux kernel SPI support | ||
2 | ==================================== | ||
3 | |||
4 | 02-Dec-2005 | ||
5 | |||
6 | What is SPI? | ||
7 | ------------ | ||
8 | The "Serial Peripheral Interface" (SPI) is a synchronous four wire serial | ||
9 | link used to connect microcontrollers to sensors, memory, and peripherals. | ||
10 | |||
11 | The three signal wires hold a clock (SCLK, often on the order of 10 MHz), | ||
12 | and parallel data lines with "Master Out, Slave In" (MOSI) or "Master In, | ||
13 | Slave Out" (MISO) signals. (Other names are also used.) There are four | ||
14 | clocking modes through which data is exchanged; mode-0 and mode-3 are most | ||
15 | commonly used. Each clock cycle shifts data out and data in; the clock | ||
16 | doesn't cycle except when there is data to shift. | ||
17 | |||
18 | SPI masters may use a "chip select" line to activate a given SPI slave | ||
19 | device, so those three signal wires may be connected to several chips | ||
20 | in parallel. All SPI slaves support chipselects. Some devices have | ||
21 | other signals, often including an interrupt to the master. | ||
22 | |||
23 | Unlike serial busses like USB or SMBUS, even low level protocols for | ||
24 | SPI slave functions are usually not interoperable between vendors | ||
25 | (except for cases like SPI memory chips). | ||
26 | |||
27 | - SPI may be used for request/response style device protocols, as with | ||
28 | touchscreen sensors and memory chips. | ||
29 | |||
30 | - It may also be used to stream data in either direction (half duplex), | ||
31 | or both of them at the same time (full duplex). | ||
32 | |||
33 | - Some devices may use eight bit words. Others may different word | ||
34 | lengths, such as streams of 12-bit or 20-bit digital samples. | ||
35 | |||
36 | In the same way, SPI slaves will only rarely support any kind of automatic | ||
37 | discovery/enumeration protocol. The tree of slave devices accessible from | ||
38 | a given SPI master will normally be set up manually, with configuration | ||
39 | tables. | ||
40 | |||
41 | SPI is only one of the names used by such four-wire protocols, and | ||
42 | most controllers have no problem handling "MicroWire" (think of it as | ||
43 | half-duplex SPI, for request/response protocols), SSP ("Synchronous | ||
44 | Serial Protocol"), PSP ("Programmable Serial Protocol"), and other | ||
45 | related protocols. | ||
46 | |||
47 | Microcontrollers often support both master and slave sides of the SPI | ||
48 | protocol. This document (and Linux) currently only supports the master | ||
49 | side of SPI interactions. | ||
50 | |||
51 | |||
52 | Who uses it? On what kinds of systems? | ||
53 | --------------------------------------- | ||
54 | Linux developers using SPI are probably writing device drivers for embedded | ||
55 | systems boards. SPI is used to control external chips, and it is also a | ||
56 | protocol supported by every MMC or SD memory card. (The older "DataFlash" | ||
57 | cards, predating MMC cards but using the same connectors and card shape, | ||
58 | support only SPI.) Some PC hardware uses SPI flash for BIOS code. | ||
59 | |||
60 | SPI slave chips range from digital/analog converters used for analog | ||
61 | sensors and codecs, to memory, to peripherals like USB controllers | ||
62 | or Ethernet adapters; and more. | ||
63 | |||
64 | Most systems using SPI will integrate a few devices on a mainboard. | ||
65 | Some provide SPI links on expansion connectors; in cases where no | ||
66 | dedicated SPI controller exists, GPIO pins can be used to create a | ||
67 | low speed "bitbanging" adapter. Very few systems will "hotplug" an SPI | ||
68 | controller; the reasons to use SPI focus on low cost and simple operation, | ||
69 | and if dynamic reconfiguration is important, USB will often be a more | ||
70 | appropriate low-pincount peripheral bus. | ||
71 | |||
72 | Many microcontrollers that can run Linux integrate one or more I/O | ||
73 | interfaces with SPI modes. Given SPI support, they could use MMC or SD | ||
74 | cards without needing a special purpose MMC/SD/SDIO controller. | ||
75 | |||
76 | |||
77 | How do these driver programming interfaces work? | ||
78 | ------------------------------------------------ | ||
79 | The <linux/spi/spi.h> header file includes kerneldoc, as does the | ||
80 | main source code, and you should certainly read that. This is just | ||
81 | an overview, so you get the big picture before the details. | ||
82 | |||
83 | SPI requests always go into I/O queues. Requests for a given SPI device | ||
84 | are always executed in FIFO order, and complete asynchronously through | ||
85 | completion callbacks. There are also some simple synchronous wrappers | ||
86 | for those calls, including ones for common transaction types like writing | ||
87 | a command and then reading its response. | ||
88 | |||
89 | There are two types of SPI driver, here called: | ||
90 | |||
91 | Controller drivers ... these are often built in to System-On-Chip | ||
92 | processors, and often support both Master and Slave roles. | ||
93 | These drivers touch hardware registers and may use DMA. | ||
94 | Or they can be PIO bitbangers, needing just GPIO pins. | ||
95 | |||
96 | Protocol drivers ... these pass messages through the controller | ||
97 | driver to communicate with a Slave or Master device on the | ||
98 | other side of an SPI link. | ||
99 | |||
100 | So for example one protocol driver might talk to the MTD layer to export | ||
101 | data to filesystems stored on SPI flash like DataFlash; and others might | ||
102 | control audio interfaces, present touchscreen sensors as input interfaces, | ||
103 | or monitor temperature and voltage levels during industrial processing. | ||
104 | And those might all be sharing the same controller driver. | ||
105 | |||
106 | A "struct spi_device" encapsulates the master-side interface between | ||
107 | those two types of driver. At this writing, Linux has no slave side | ||
108 | programming interface. | ||
109 | |||
110 | There is a minimal core of SPI programming interfaces, focussing on | ||
111 | using driver model to connect controller and protocol drivers using | ||
112 | device tables provided by board specific initialization code. SPI | ||
113 | shows up in sysfs in several locations: | ||
114 | |||
115 | /sys/devices/.../CTLR/spiB.C ... spi_device for on bus "B", | ||
116 | chipselect C, accessed through CTLR. | ||
117 | |||
118 | /sys/devices/.../CTLR/spiB.C/modalias ... identifies the driver | ||
119 | that should be used with this device (for hotplug/coldplug) | ||
120 | |||
121 | /sys/bus/spi/devices/spiB.C ... symlink to the physical | ||
122 | spiB-C device | ||
123 | |||
124 | /sys/bus/spi/drivers/D ... driver for one or more spi*.* devices | ||
125 | |||
126 | /sys/class/spi_master/spiB ... class device for the controller | ||
127 | managing bus "B". All the spiB.* devices share the same | ||
128 | physical SPI bus segment, with SCLK, MOSI, and MISO. | ||
129 | |||
130 | |||
131 | How does board-specific init code declare SPI devices? | ||
132 | ------------------------------------------------------ | ||
133 | Linux needs several kinds of information to properly configure SPI devices. | ||
134 | That information is normally provided by board-specific code, even for | ||
135 | chips that do support some of automated discovery/enumeration. | ||
136 | |||
137 | DECLARE CONTROLLERS | ||
138 | |||
139 | The first kind of information is a list of what SPI controllers exist. | ||
140 | For System-on-Chip (SOC) based boards, these will usually be platform | ||
141 | devices, and the controller may need some platform_data in order to | ||
142 | operate properly. The "struct platform_device" will include resources | ||
143 | like the physical address of the controller's first register and its IRQ. | ||
144 | |||
145 | Platforms will often abstract the "register SPI controller" operation, | ||
146 | maybe coupling it with code to initialize pin configurations, so that | ||
147 | the arch/.../mach-*/board-*.c files for several boards can all share the | ||
148 | same basic controller setup code. This is because most SOCs have several | ||
149 | SPI-capable controllers, and only the ones actually usable on a given | ||
150 | board should normally be set up and registered. | ||
151 | |||
152 | So for example arch/.../mach-*/board-*.c files might have code like: | ||
153 | |||
154 | #include <asm/arch/spi.h> /* for mysoc_spi_data */ | ||
155 | |||
156 | /* if your mach-* infrastructure doesn't support kernels that can | ||
157 | * run on multiple boards, pdata wouldn't benefit from "__init". | ||
158 | */ | ||
159 | static struct mysoc_spi_data __init pdata = { ... }; | ||
160 | |||
161 | static __init board_init(void) | ||
162 | { | ||
163 | ... | ||
164 | /* this board only uses SPI controller #2 */ | ||
165 | mysoc_register_spi(2, &pdata); | ||
166 | ... | ||
167 | } | ||
168 | |||
169 | And SOC-specific utility code might look something like: | ||
170 | |||
171 | #include <asm/arch/spi.h> | ||
172 | |||
173 | static struct platform_device spi2 = { ... }; | ||
174 | |||
175 | void mysoc_register_spi(unsigned n, struct mysoc_spi_data *pdata) | ||
176 | { | ||
177 | struct mysoc_spi_data *pdata2; | ||
178 | |||
179 | pdata2 = kmalloc(sizeof *pdata2, GFP_KERNEL); | ||
180 | *pdata2 = pdata; | ||
181 | ... | ||
182 | if (n == 2) { | ||
183 | spi2->dev.platform_data = pdata2; | ||
184 | register_platform_device(&spi2); | ||
185 | |||
186 | /* also: set up pin modes so the spi2 signals are | ||
187 | * visible on the relevant pins ... bootloaders on | ||
188 | * production boards may already have done this, but | ||
189 | * developer boards will often need Linux to do it. | ||
190 | */ | ||
191 | } | ||
192 | ... | ||
193 | } | ||
194 | |||
195 | Notice how the platform_data for boards may be different, even if the | ||
196 | same SOC controller is used. For example, on one board SPI might use | ||
197 | an external clock, where another derives the SPI clock from current | ||
198 | settings of some master clock. | ||
199 | |||
200 | |||
201 | DECLARE SLAVE DEVICES | ||
202 | |||
203 | The second kind of information is a list of what SPI slave devices exist | ||
204 | on the target board, often with some board-specific data needed for the | ||
205 | driver to work correctly. | ||
206 | |||
207 | Normally your arch/.../mach-*/board-*.c files would provide a small table | ||
208 | listing the SPI devices on each board. (This would typically be only a | ||
209 | small handful.) That might look like: | ||
210 | |||
211 | static struct ads7846_platform_data ads_info = { | ||
212 | .vref_delay_usecs = 100, | ||
213 | .x_plate_ohms = 580, | ||
214 | .y_plate_ohms = 410, | ||
215 | }; | ||
216 | |||
217 | static struct spi_board_info spi_board_info[] __initdata = { | ||
218 | { | ||
219 | .modalias = "ads7846", | ||
220 | .platform_data = &ads_info, | ||
221 | .mode = SPI_MODE_0, | ||
222 | .irq = GPIO_IRQ(31), | ||
223 | .max_speed_hz = 120000 /* max sample rate at 3V */ * 16, | ||
224 | .bus_num = 1, | ||
225 | .chip_select = 0, | ||
226 | }, | ||
227 | }; | ||
228 | |||
229 | Again, notice how board-specific information is provided; each chip may need | ||
230 | several types. This example shows generic constraints like the fastest SPI | ||
231 | clock to allow (a function of board voltage in this case) or how an IRQ pin | ||
232 | is wired, plus chip-specific constraints like an important delay that's | ||
233 | changed by the capacitance at one pin. | ||
234 | |||
235 | (There's also "controller_data", information that may be useful to the | ||
236 | controller driver. An example would be peripheral-specific DMA tuning | ||
237 | data or chipselect callbacks. This is stored in spi_device later.) | ||
238 | |||
239 | The board_info should provide enough information to let the system work | ||
240 | without the chip's driver being loaded. The most troublesome aspect of | ||
241 | that is likely the SPI_CS_HIGH bit in the spi_device.mode field, since | ||
242 | sharing a bus with a device that interprets chipselect "backwards" is | ||
243 | not possible. | ||
244 | |||
245 | Then your board initialization code would register that table with the SPI | ||
246 | infrastructure, so that it's available later when the SPI master controller | ||
247 | driver is registered: | ||
248 | |||
249 | spi_register_board_info(spi_board_info, ARRAY_SIZE(spi_board_info)); | ||
250 | |||
251 | Like with other static board-specific setup, you won't unregister those. | ||
252 | |||
253 | The widely used "card" style computers bundle memory, cpu, and little else | ||
254 | onto a card that's maybe just thirty square centimeters. On such systems, | ||
255 | your arch/.../mach-.../board-*.c file would primarily provide information | ||
256 | about the devices on the mainboard into which such a card is plugged. That | ||
257 | certainly includes SPI devices hooked up through the card connectors! | ||
258 | |||
259 | |||
260 | NON-STATIC CONFIGURATIONS | ||
261 | |||
262 | Developer boards often play by different rules than product boards, and one | ||
263 | example is the potential need to hotplug SPI devices and/or controllers. | ||
264 | |||
265 | For those cases you might need to use use spi_busnum_to_master() to look | ||
266 | up the spi bus master, and will likely need spi_new_device() to provide the | ||
267 | board info based on the board that was hotplugged. Of course, you'd later | ||
268 | call at least spi_unregister_device() when that board is removed. | ||
269 | |||
270 | When Linux includes support for MMC/SD/SDIO/DataFlash cards through SPI, those | ||
271 | configurations will also be dynamic. Fortunately, those devices all support | ||
272 | basic device identification probes, so that support should hotplug normally. | ||
273 | |||
274 | |||
275 | How do I write an "SPI Protocol Driver"? | ||
276 | ---------------------------------------- | ||
277 | All SPI drivers are currently kernel drivers. A userspace driver API | ||
278 | would just be another kernel driver, probably offering some lowlevel | ||
279 | access through aio_read(), aio_write(), and ioctl() calls and using the | ||
280 | standard userspace sysfs mechanisms to bind to a given SPI device. | ||
281 | |||
282 | SPI protocol drivers somewhat resemble platform device drivers: | ||
283 | |||
284 | static struct spi_driver CHIP_driver = { | ||
285 | .driver = { | ||
286 | .name = "CHIP", | ||
287 | .bus = &spi_bus_type, | ||
288 | .owner = THIS_MODULE, | ||
289 | }, | ||
290 | |||
291 | .probe = CHIP_probe, | ||
292 | .remove = __devexit_p(CHIP_remove), | ||
293 | .suspend = CHIP_suspend, | ||
294 | .resume = CHIP_resume, | ||
295 | }; | ||
296 | |||
297 | The driver core will autmatically attempt to bind this driver to any SPI | ||
298 | device whose board_info gave a modalias of "CHIP". Your probe() code | ||
299 | might look like this unless you're creating a class_device: | ||
300 | |||
301 | static int __devinit CHIP_probe(struct spi_device *spi) | ||
302 | { | ||
303 | struct CHIP *chip; | ||
304 | struct CHIP_platform_data *pdata; | ||
305 | |||
306 | /* assuming the driver requires board-specific data: */ | ||
307 | pdata = &spi->dev.platform_data; | ||
308 | if (!pdata) | ||
309 | return -ENODEV; | ||
310 | |||
311 | /* get memory for driver's per-chip state */ | ||
312 | chip = kzalloc(sizeof *chip, GFP_KERNEL); | ||
313 | if (!chip) | ||
314 | return -ENOMEM; | ||
315 | dev_set_drvdata(&spi->dev, chip); | ||
316 | |||
317 | ... etc | ||
318 | return 0; | ||
319 | } | ||
320 | |||
321 | As soon as it enters probe(), the driver may issue I/O requests to | ||
322 | the SPI device using "struct spi_message". When remove() returns, | ||
323 | the driver guarantees that it won't submit any more such messages. | ||
324 | |||
325 | - An spi_message is a sequence of of protocol operations, executed | ||
326 | as one atomic sequence. SPI driver controls include: | ||
327 | |||
328 | + when bidirectional reads and writes start ... by how its | ||
329 | sequence of spi_transfer requests is arranged; | ||
330 | |||
331 | + optionally defining short delays after transfers ... using | ||
332 | the spi_transfer.delay_usecs setting; | ||
333 | |||
334 | + whether the chipselect becomes inactive after a transfer and | ||
335 | any delay ... by using the spi_transfer.cs_change flag; | ||
336 | |||
337 | + hinting whether the next message is likely to go to this same | ||
338 | device ... using the spi_transfer.cs_change flag on the last | ||
339 | transfer in that atomic group, and potentially saving costs | ||
340 | for chip deselect and select operations. | ||
341 | |||
342 | - Follow standard kernel rules, and provide DMA-safe buffers in | ||
343 | your messages. That way controller drivers using DMA aren't forced | ||
344 | to make extra copies unless the hardware requires it (e.g. working | ||
345 | around hardware errata that force the use of bounce buffering). | ||
346 | |||
347 | If standard dma_map_single() handling of these buffers is inappropriate, | ||
348 | you can use spi_message.is_dma_mapped to tell the controller driver | ||
349 | that you've already provided the relevant DMA addresses. | ||
350 | |||
351 | - The basic I/O primitive is spi_async(). Async requests may be | ||
352 | issued in any context (irq handler, task, etc) and completion | ||
353 | is reported using a callback provided with the message. | ||
354 | After any detected error, the chip is deselected and processing | ||
355 | of that spi_message is aborted. | ||
356 | |||
357 | - There are also synchronous wrappers like spi_sync(), and wrappers | ||
358 | like spi_read(), spi_write(), and spi_write_then_read(). These | ||
359 | may be issued only in contexts that may sleep, and they're all | ||
360 | clean (and small, and "optional") layers over spi_async(). | ||
361 | |||
362 | - The spi_write_then_read() call, and convenience wrappers around | ||
363 | it, should only be used with small amounts of data where the | ||
364 | cost of an extra copy may be ignored. It's designed to support | ||
365 | common RPC-style requests, such as writing an eight bit command | ||
366 | and reading a sixteen bit response -- spi_w8r16() being one its | ||
367 | wrappers, doing exactly that. | ||
368 | |||
369 | Some drivers may need to modify spi_device characteristics like the | ||
370 | transfer mode, wordsize, or clock rate. This is done with spi_setup(), | ||
371 | which would normally be called from probe() before the first I/O is | ||
372 | done to the device. | ||
373 | |||
374 | While "spi_device" would be the bottom boundary of the driver, the | ||
375 | upper boundaries might include sysfs (especially for sensor readings), | ||
376 | the input layer, ALSA, networking, MTD, the character device framework, | ||
377 | or other Linux subsystems. | ||
378 | |||
379 | Note that there are two types of memory your driver must manage as part | ||
380 | of interacting with SPI devices. | ||
381 | |||
382 | - I/O buffers use the usual Linux rules, and must be DMA-safe. | ||
383 | You'd normally allocate them from the heap or free page pool. | ||
384 | Don't use the stack, or anything that's declared "static". | ||
385 | |||
386 | - The spi_message and spi_transfer metadata used to glue those | ||
387 | I/O buffers into a group of protocol transactions. These can | ||
388 | be allocated anywhere it's convenient, including as part of | ||
389 | other allocate-once driver data structures. Zero-init these. | ||
390 | |||
391 | If you like, spi_message_alloc() and spi_message_free() convenience | ||
392 | routines are available to allocate and zero-initialize an spi_message | ||
393 | with several transfers. | ||
394 | |||
395 | |||
396 | How do I write an "SPI Master Controller Driver"? | ||
397 | ------------------------------------------------- | ||
398 | An SPI controller will probably be registered on the platform_bus; write | ||
399 | a driver to bind to the device, whichever bus is involved. | ||
400 | |||
401 | The main task of this type of driver is to provide an "spi_master". | ||
402 | Use spi_alloc_master() to allocate the master, and class_get_devdata() | ||
403 | to get the driver-private data allocated for that device. | ||
404 | |||
405 | struct spi_master *master; | ||
406 | struct CONTROLLER *c; | ||
407 | |||
408 | master = spi_alloc_master(dev, sizeof *c); | ||
409 | if (!master) | ||
410 | return -ENODEV; | ||
411 | |||
412 | c = class_get_devdata(&master->cdev); | ||
413 | |||
414 | The driver will initialize the fields of that spi_master, including the | ||
415 | bus number (maybe the same as the platform device ID) and three methods | ||
416 | used to interact with the SPI core and SPI protocol drivers. It will | ||
417 | also initialize its own internal state. | ||
418 | |||
419 | master->setup(struct spi_device *spi) | ||
420 | This sets up the device clock rate, SPI mode, and word sizes. | ||
421 | Drivers may change the defaults provided by board_info, and then | ||
422 | call spi_setup(spi) to invoke this routine. It may sleep. | ||
423 | |||
424 | master->transfer(struct spi_device *spi, struct spi_message *message) | ||
425 | This must not sleep. Its responsibility is arrange that the | ||
426 | transfer happens and its complete() callback is issued; the two | ||
427 | will normally happen later, after other transfers complete. | ||
428 | |||
429 | master->cleanup(struct spi_device *spi) | ||
430 | Your controller driver may use spi_device.controller_state to hold | ||
431 | state it dynamically associates with that device. If you do that, | ||
432 | be sure to provide the cleanup() method to free that state. | ||
433 | |||
434 | The bulk of the driver will be managing the I/O queue fed by transfer(). | ||
435 | |||
436 | That queue could be purely conceptual. For example, a driver used only | ||
437 | for low-frequency sensor acess might be fine using synchronous PIO. | ||
438 | |||
439 | But the queue will probably be very real, using message->queue, PIO, | ||
440 | often DMA (especially if the root filesystem is in SPI flash), and | ||
441 | execution contexts like IRQ handlers, tasklets, or workqueues (such | ||
442 | as keventd). Your driver can be as fancy, or as simple, as you need. | ||
443 | |||
444 | |||
445 | THANKS TO | ||
446 | --------- | ||
447 | Contributors to Linux-SPI discussions include (in alphabetical order, | ||
448 | by last name): | ||
449 | |||
450 | David Brownell | ||
451 | Russell King | ||
452 | Dmitry Pervushin | ||
453 | Stephen Street | ||
454 | Mark Underwood | ||
455 | Andrew Victor | ||
456 | Vitaly Wool | ||
457 | |||