xref: /OK3568_Linux_fs/kernel/Documentation/spi/butterfly.rst (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun===================================================
2*4882a593Smuzhiyunspi_butterfly - parport-to-butterfly adapter driver
3*4882a593Smuzhiyun===================================================
4*4882a593Smuzhiyun
5*4882a593SmuzhiyunThis is a hardware and software project that includes building and using
6*4882a593Smuzhiyuna parallel port adapter cable, together with an "AVR Butterfly" to run
7*4882a593Smuzhiyunfirmware for user interfacing and/or sensors.  A Butterfly is a $US20
8*4882a593Smuzhiyunbattery powered card with an AVR microcontroller and lots of goodies:
9*4882a593Smuzhiyunsensors, LCD, flash, toggle stick, and more.  You can use AVR-GCC to
10*4882a593Smuzhiyundevelop firmware for this, and flash it using this adapter cable.
11*4882a593Smuzhiyun
12*4882a593SmuzhiyunYou can make this adapter from an old printer cable and solder things
13*4882a593Smuzhiyundirectly to the Butterfly.  Or (if you have the parts and skills) you
14*4882a593Smuzhiyuncan come up with something fancier, providing ciruit protection to the
15*4882a593SmuzhiyunButterfly and the printer port, or with a better power supply than two
16*4882a593Smuzhiyunsignal pins from the printer port.  Or for that matter, you can use
17*4882a593Smuzhiyunsimilar cables to talk to many AVR boards, even a breadboard.
18*4882a593Smuzhiyun
19*4882a593SmuzhiyunThis is more powerful than "ISP programming" cables since it lets kernel
20*4882a593SmuzhiyunSPI protocol drivers interact with the AVR, and could even let the AVR
21*4882a593Smuzhiyunissue interrupts to them.  Later, your protocol driver should work
22*4882a593Smuzhiyuneasily with a "real SPI controller", instead of this bitbanger.
23*4882a593Smuzhiyun
24*4882a593Smuzhiyun
25*4882a593SmuzhiyunThe first cable connections will hook Linux up to one SPI bus, with the
26*4882a593SmuzhiyunAVR and a DataFlash chip; and to the AVR reset line.  This is all you
27*4882a593Smuzhiyunneed to reflash the firmware, and the pins are the standard Atmel "ISP"
28*4882a593Smuzhiyunconnector pins (used also on non-Butterfly AVR boards).  On the parport
29*4882a593Smuzhiyunside this is like "sp12" programming cables.
30*4882a593Smuzhiyun
31*4882a593Smuzhiyun	======	  =============	  ===================
32*4882a593Smuzhiyun	Signal	  Butterfly	  Parport (DB-25)
33*4882a593Smuzhiyun	======	  =============	  ===================
34*4882a593Smuzhiyun	SCK	  J403.PB1/SCK	  pin 2/D0
35*4882a593Smuzhiyun	RESET	  J403.nRST	  pin 3/D1
36*4882a593Smuzhiyun	VCC	  J403.VCC_EXT	  pin 8/D6
37*4882a593Smuzhiyun	MOSI	  J403.PB2/MOSI	  pin 9/D7
38*4882a593Smuzhiyun	MISO	  J403.PB3/MISO	  pin 11/S7,nBUSY
39*4882a593Smuzhiyun	GND	  J403.GND	  pin 23/GND
40*4882a593Smuzhiyun	======	  =============	  ===================
41*4882a593Smuzhiyun
42*4882a593SmuzhiyunThen to let Linux master that bus to talk to the DataFlash chip, you must
43*4882a593Smuzhiyun(a) flash new firmware that disables SPI (set PRR.2, and disable pullups
44*4882a593Smuzhiyunby clearing PORTB.[0-3]); (b) configure the mtd_dataflash driver; and
45*4882a593Smuzhiyun(c) cable in the chipselect.
46*4882a593Smuzhiyun
47*4882a593Smuzhiyun	======	  ============	  ===================
48*4882a593Smuzhiyun	Signal	  Butterfly	  Parport (DB-25)
49*4882a593Smuzhiyun	======	  ============	  ===================
50*4882a593Smuzhiyun	VCC	  J400.VCC_EXT	  pin 7/D5
51*4882a593Smuzhiyun	SELECT	  J400.PB0/nSS	  pin 17/C3,nSELECT
52*4882a593Smuzhiyun	GND	  J400.GND	  pin 24/GND
53*4882a593Smuzhiyun	======	  ============	  ===================
54*4882a593Smuzhiyun
55*4882a593SmuzhiyunOr you could flash firmware making the AVR into an SPI slave (keeping the
56*4882a593SmuzhiyunDataFlash in reset) and tweak the spi_butterfly driver to make it bind to
57*4882a593Smuzhiyunthe driver for your custom SPI-based protocol.
58*4882a593Smuzhiyun
59*4882a593SmuzhiyunThe "USI" controller, using J405, can also be used for a second SPI bus.
60*4882a593SmuzhiyunThat would let you talk to the AVR using custom SPI-with-USI firmware,
61*4882a593Smuzhiyunwhile letting either Linux or the AVR use the DataFlash.  There are plenty
62*4882a593Smuzhiyunof spare parport pins to wire this one up, such as:
63*4882a593Smuzhiyun
64*4882a593Smuzhiyun	======	  =============	  ===================
65*4882a593Smuzhiyun	Signal	  Butterfly	  Parport (DB-25)
66*4882a593Smuzhiyun	======	  =============	  ===================
67*4882a593Smuzhiyun	SCK	  J403.PE4/USCK	  pin 5/D3
68*4882a593Smuzhiyun	MOSI	  J403.PE5/DI	  pin 6/D4
69*4882a593Smuzhiyun	MISO	  J403.PE6/DO	  pin 12/S5,nPAPEROUT
70*4882a593Smuzhiyun	GND	  J403.GND	  pin 22/GND
71*4882a593Smuzhiyun
72*4882a593Smuzhiyun	IRQ	  J402.PF4	  pin 10/S6,ACK
73*4882a593Smuzhiyun	GND	  J402.GND(P2)	  pin 25/GND
74*4882a593Smuzhiyun	======	  =============	  ===================
75