@@ -9,7 +9,7 @@ What is SPI?
9
9
The "Serial Peripheral Interface" (SPI) is a synchronous four wire serial
10
10
link used to connect microcontrollers to sensors, memory, and peripherals.
11
11
It's a simple "de facto" standard, not complicated enough to acquire a
12
- standardization body. SPI uses a master/slave configuration.
12
+ standardization body. SPI uses a host/target configuration.
13
13
14
14
The three signal wires hold a clock (SCK, often on the order of 10 MHz),
15
15
and parallel data lines with "Master Out, Slave In" (MOSI) or "Master In,
@@ -19,14 +19,14 @@ commonly used. Each clock cycle shifts data out and data in; the clock
19
19
doesn't cycle except when there is a data bit to shift. Not all data bits
20
20
are used though; not every protocol uses those full duplex capabilities.
21
21
22
- SPI masters use a fourth "chip select" line to activate a given SPI slave
22
+ SPI hosts use a fourth "chip select" line to activate a given SPI target
23
23
device, so those three signal wires may be connected to several chips
24
- in parallel. All SPI slaves support chipselects; they are usually active
25
- low signals, labeled nCSx for slave 'x' (e.g. nCS0). Some devices have
26
- other signals, often including an interrupt to the master .
24
+ in parallel. All SPI targets support chipselects; they are usually active
25
+ low signals, labeled nCSx for target 'x' (e.g. nCS0). Some devices have
26
+ other signals, often including an interrupt to the host .
27
27
28
28
Unlike serial busses like USB or SMBus, even low level protocols for
29
- SPI slave functions are usually not interoperable between vendors
29
+ SPI target functions are usually not interoperable between vendors
30
30
(except for commodities like SPI memory chips).
31
31
32
32
- SPI may be used for request/response style device protocols, as with
@@ -43,10 +43,10 @@ SPI slave functions are usually not interoperable between vendors
43
43
44
44
- Sometimes SPI is used to daisy-chain devices, like shift registers.
45
45
46
- In the same way, SPI slaves will only rarely support any kind of automatic
47
- discovery/enumeration protocol. The tree of slave devices accessible from
48
- a given SPI master will normally be set up manually, with configuration
49
- tables.
46
+ In the same way, SPI targets will only rarely support any kind of automatic
47
+ discovery/enumeration protocol. The tree of target devices accessible from
48
+ a given SPI host controller will normally be set up manually, with
49
+ configuration tables.
50
50
51
51
SPI is only one of the names used by such four-wire protocols, and
52
52
most controllers have no problem handling "MicroWire" (think of it as
@@ -62,8 +62,8 @@ course they won't handle full duplex transfers. You may find such
62
62
chips described as using "three wire" signaling: SCK, data, nCSx.
63
63
(That data line is sometimes called MOMI or SISO.)
64
64
65
- Microcontrollers often support both master and slave sides of the SPI
66
- protocol. This document (and Linux) supports both the master and slave
65
+ Microcontrollers often support both host and target sides of the SPI
66
+ protocol. This document (and Linux) supports both the host and target
67
67
sides of SPI interactions.
68
68
69
69
@@ -75,7 +75,7 @@ protocol supported by every MMC or SD memory card. (The older "DataFlash"
75
75
cards, predating MMC cards but using the same connectors and card shape,
76
76
support only SPI.) Some PC hardware uses SPI flash for BIOS code.
77
77
78
- SPI slave chips range from digital/analog converters used for analog
78
+ SPI target chips range from digital/analog converters used for analog
79
79
sensors and codecs, to memory, to peripherals like USB controllers
80
80
or Ethernet adapters; and more.
81
81
@@ -118,8 +118,8 @@ starting low (CPOL=0) and data stabilized for sampling during the
118
118
trailing clock edge (CPHA=1), that's SPI mode 1.
119
119
120
120
Note that the clock mode is relevant as soon as the chipselect goes
121
- active. So the master must set the clock to inactive before selecting
122
- a slave , and the slave can tell the chosen polarity by sampling the
121
+ active. So the host must set the clock to inactive before selecting
122
+ a target , and the target can tell the chosen polarity by sampling the
123
123
clock level when its select line goes active. That's why many devices
124
124
support for example both modes 0 and 3: they don't care about polarity,
125
125
and always clock data in/out on rising clock edges.
@@ -142,13 +142,13 @@ There are two types of SPI driver, here called:
142
142
143
143
Controller drivers ...
144
144
controllers may be built into System-On-Chip
145
- processors, and often support both Master and Slave roles.
145
+ processors, and often support both Controller and target roles.
146
146
These drivers touch hardware registers and may use DMA.
147
147
Or they can be PIO bitbangers, needing just GPIO pins.
148
148
149
149
Protocol drivers ...
150
150
these pass messages through the controller
151
- driver to communicate with a Slave or Master device on the
151
+ driver to communicate with a target or Controller device on the
152
152
other side of an SPI link.
153
153
154
154
So for example one protocol driver might talk to the MTD layer to export
@@ -179,22 +179,22 @@ shows up in sysfs in several locations::
179
179
/sys/bus/spi/drivers/D ... driver for one or more spi*.* devices
180
180
181
181
/sys/class/spi_master/spiB ... symlink to a logical node which could hold
182
- class related state for the SPI master controller managing bus "B".
182
+ class related state for the SPI host controller managing bus "B".
183
183
All spiB.* devices share one physical SPI bus segment, with SCLK,
184
184
MOSI, and MISO.
185
185
186
186
/sys/devices/.../CTLR/slave ... virtual file for (un)registering the
187
- slave device for an SPI slave controller.
188
- Writing the driver name of an SPI slave handler to this file
189
- registers the slave device; writing "(null)" unregisters the slave
187
+ target device for an SPI target controller.
188
+ Writing the driver name of an SPI target handler to this file
189
+ registers the target device; writing "(null)" unregisters the target
190
190
device.
191
- Reading from this file shows the name of the slave device ("(null)"
191
+ Reading from this file shows the name of the target device ("(null)"
192
192
if not registered).
193
193
194
194
/sys/class/spi_slave/spiB ... symlink to a logical node which could hold
195
- class related state for the SPI slave controller on bus "B". When
195
+ class related state for the SPI target controller on bus "B". When
196
196
registered, a single spiB.* device is present here, possible sharing
197
- the physical SPI bus segment with other SPI slave devices.
197
+ the physical SPI bus segment with other SPI target devices.
198
198
199
199
At this time, the only class-specific state is the bus number ("B" in "spiB"),
200
200
so those /sys/class entries are only useful to quickly identify busses.
@@ -270,10 +270,10 @@ same SOC controller is used. For example, on one board SPI might use
270
270
an external clock, where another derives the SPI clock from current
271
271
settings of some master clock.
272
272
273
- Declare Slave Devices
274
- ^^^^^^^^^^^^^^^^^^^^^
273
+ Declare target Devices
274
+ ^^^^^^^^^^^^^^^^^^^^^^
275
275
276
- The second kind of information is a list of what SPI slave devices exist
276
+ The second kind of information is a list of what SPI target devices exist
277
277
on the target board, often with some board-specific data needed for the
278
278
driver to work correctly.
279
279
@@ -316,7 +316,7 @@ sharing a bus with a device that interprets chipselect "backwards" is
316
316
not possible until the infrastructure knows how to deselect it.
317
317
318
318
Then your board initialization code would register that table with the SPI
319
- infrastructure, so that it's available later when the SPI master controller
319
+ infrastructure, so that it's available later when the SPI host controller
320
320
driver is registered::
321
321
322
322
spi_register_board_info(spi_board_info, ARRAY_SIZE(spi_board_info));
@@ -469,39 +469,39 @@ routines are available to allocate and zero-initialize an spi_message
469
469
with several transfers.
470
470
471
471
472
- How do I write an "SPI Master Controller Driver"?
472
+ How do I write an "SPI Controller Driver"?
473
473
-------------------------------------------------
474
474
An SPI controller will probably be registered on the platform_bus; write
475
475
a driver to bind to the device, whichever bus is involved.
476
476
477
- The main task of this type of driver is to provide an "spi_master".
478
- Use spi_alloc_master() to allocate the master, and spi_master_get_devdata()
479
- to get the driver-private data allocated for that device.
477
+ The main task of this type of driver is to provide an "spi_controller".
478
+ Use spi_alloc_host() to allocate the host controller, and
479
+ spi_controller_get_devdata() to get the driver-private data allocated for that
480
+ device.
480
481
481
482
::
482
483
483
- struct spi_master *master ;
484
+ struct spi_controller *ctlr ;
484
485
struct CONTROLLER *c;
485
486
486
- master = spi_alloc_master (dev, sizeof *c);
487
- if (!master )
487
+ ctlr = spi_alloc_host (dev, sizeof *c);
488
+ if (!ctlr )
488
489
return -ENODEV;
489
490
490
- c = spi_master_get_devdata(master );
491
+ c = spi_controller_get_devdata(ctlr );
491
492
492
- The driver will initialize the fields of that spi_master, including the
493
- bus number (maybe the same as the platform device ID) and three methods
494
- used to interact with the SPI core and SPI protocol drivers. It will
495
- also initialize its own internal state. (See below about bus numbering
496
- and those methods.)
493
+ The driver will initialize the fields of that spi_controller, including the bus
494
+ number (maybe the same as the platform device ID) and three methods used to
495
+ interact with the SPI core and SPI protocol drivers. It will also initialize
496
+ its own internal state. (See below about bus numbering and those methods.)
497
497
498
- After you initialize the spi_master , then use spi_register_master () to
498
+ After you initialize the spi_controller , then use spi_register_controller () to
499
499
publish it to the rest of the system. At that time, device nodes for the
500
500
controller and any predeclared spi devices will be made available, and
501
501
the driver model core will take care of binding them to drivers.
502
502
503
- If you need to remove your SPI controller driver, spi_unregister_master ()
504
- will reverse the effect of spi_register_master ().
503
+ If you need to remove your SPI controller driver, spi_unregister_controller ()
504
+ will reverse the effect of spi_register_controller ().
505
505
506
506
507
507
Bus Numbering
@@ -519,49 +519,49 @@ then be replaced by a dynamically assigned number. You'd then need to treat
519
519
this as a non-static configuration (see above).
520
520
521
521
522
- SPI Master Methods
523
- ^^^^^^^^^^^^^^^^^^
522
+ SPI Host Controller Methods
523
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^
524
524
525
- ``master ->setup(struct spi_device *spi) ``
525
+ ``ctlr ->setup(struct spi_device *spi) ``
526
526
This sets up the device clock rate, SPI mode, and word sizes.
527
527
Drivers may change the defaults provided by board_info, and then
528
528
call spi_setup(spi) to invoke this routine. It may sleep.
529
529
530
- Unless each SPI slave has its own configuration registers, don't
530
+ Unless each SPI target has its own configuration registers, don't
531
531
change them right away ... otherwise drivers could corrupt I/O
532
532
that's in progress for other SPI devices.
533
533
534
534
.. note ::
535
535
536
536
BUG ALERT: for some reason the first version of
537
- many spi_master drivers seems to get this wrong.
537
+ many spi_controller drivers seems to get this wrong.
538
538
When you code setup(), ASSUME that the controller
539
539
is actively processing transfers for another device.
540
540
541
- ``master ->cleanup(struct spi_device *spi) ``
541
+ ``ctlr ->cleanup(struct spi_device *spi) ``
542
542
Your controller driver may use spi_device.controller_state to hold
543
543
state it dynamically associates with that device. If you do that,
544
544
be sure to provide the cleanup() method to free that state.
545
545
546
- ``master ->prepare_transfer_hardware(struct spi_master *master ) ``
546
+ ``ctlr ->prepare_transfer_hardware(struct spi_controller *ctlr ) ``
547
547
This will be called by the queue mechanism to signal to the driver
548
548
that a message is coming in soon, so the subsystem requests the
549
549
driver to prepare the transfer hardware by issuing this call.
550
550
This may sleep.
551
551
552
- ``master ->unprepare_transfer_hardware(struct spi_master *master ) ``
552
+ ``ctlr ->unprepare_transfer_hardware(struct spi_controller *ctlr ) ``
553
553
This will be called by the queue mechanism to signal to the driver
554
554
that there are no more messages pending in the queue and it may
555
555
relax the hardware (e.g. by power management calls). This may sleep.
556
556
557
- ``master ->transfer_one_message(struct spi_master *master , struct spi_message *mesg) ``
557
+ ``ctlr ->transfer_one_message(struct spi_controller *ctlr , struct spi_message *mesg) ``
558
558
The subsystem calls the driver to transfer a single message while
559
559
queuing transfers that arrive in the meantime. When the driver is
560
560
finished with this message, it must call
561
561
spi_finalize_current_message() so the subsystem can issue the next
562
562
message. This may sleep.
563
563
564
- ``master ->transfer_one(struct spi_master *master , struct spi_device *spi, struct spi_transfer *transfer) ``
564
+ ``ctrl ->transfer_one(struct spi_controller *ctlr , struct spi_device *spi, struct spi_transfer *transfer) ``
565
565
The subsystem calls the driver to transfer a single transfer while
566
566
queuing transfers that arrive in the meantime. When the driver is
567
567
finished with this transfer, it must call
@@ -576,15 +576,15 @@ SPI Master Methods
576
576
* 0: transfer is finished
577
577
* 1: transfer is still in progress
578
578
579
- ``master ->set_cs_timing(struct spi_device *spi, u8 setup_clk_cycles, u8 hold_clk_cycles, u8 inactive_clk_cycles) ``
580
- This method allows SPI client drivers to request SPI master controller
579
+ ``ctrl ->set_cs_timing(struct spi_device *spi, u8 setup_clk_cycles, u8 hold_clk_cycles, u8 inactive_clk_cycles) ``
580
+ This method allows SPI client drivers to request SPI host controller
581
581
for configuring device specific CS setup, hold and inactive timing
582
582
requirements.
583
583
584
584
Deprecated Methods
585
585
^^^^^^^^^^^^^^^^^^
586
586
587
- ``master ->transfer(struct spi_device *spi, struct spi_message *message) ``
587
+ ``ctrl ->transfer(struct spi_device *spi, struct spi_message *message) ``
588
588
This must not sleep. Its responsibility is to arrange that the
589
589
transfer happens and its complete() callback is issued. The two
590
590
will normally happen later, after other transfers complete, and
0 commit comments