1 .. SPDX-License-Identifier: GPL-2.0
3 ========================
4 Spear PCIe Gadget Driver
5 ========================
9 Pratyush Anand (pratyush.anand@gmail.com)
13 driver/misc/spear13xx_pcie_gadget.c
24 PCIe gadget support for SPEAr13XX platform
28 This driver has several nodes which can be read/written by configfs interface.
29 Its main purpose is to configure selected dual mode PCIe controller as device
30 and then program its various registers to configure it as a particular device
31 type. This driver can be used to show spear's PCIe device capability.
33 Description of different nodes:
34 ===============================
36 read behavior of nodes:
37 -----------------------
39 =============== ==============================================================
40 link gives ltssm status.
41 int_type type of supported interrupt
42 no_of_msi zero if MSI is not enabled by host. A positive value is the
43 number of MSI vector granted.
44 vendor_id returns programmed vendor id (hex)
45 device_id returns programmed device id(hex)
46 bar0_size: returns size of bar0 in hex.
47 bar0_address returns address of bar0 mapped area in hex.
48 bar0_rw_offset returns offset of bar0 for which bar0_data will return value.
49 bar0_data returns data at bar0_rw_offset.
50 =============== ==============================================================
52 write behavior of nodes:
53 ------------------------
55 =============== ================================================================
56 link write UP to enable ltsmm DOWN to disable
57 int_type write interrupt type to be configured and (int_type could be
58 INTA, MSI or NO_INT). Select MSI only when you have programmed
60 no_of_msi number of MSI vector needed.
61 inta write 1 to assert INTA and 0 to de-assert.
62 send_msi write MSI vector to be sent.
63 vendor_id write vendor id(hex) to be programmed.
64 device_id write device id(hex) to be programmed.
65 bar0_size write size of bar0 in hex. default bar0 size is 1000 (hex)
67 bar0_address write address of bar0 mapped area in hex. (default mapping of
68 bar0 is SYSRAM1(E0800000). Always program bar size before bar
69 address. Kernel might modify bar size and address for alignment,
70 so read back bar size and address after writing to cross check.
71 bar0_rw_offset write offset of bar0 for which bar0_data will write value.
72 bar0_data write data to be written at bar0_rw_offset.
73 =============== ================================================================
75 Node programming example
76 ========================
78 Program all PCIe registers in such a way that when this device is connected
79 to the PCIe host, then host sees this device as 1MB RAM.
83 #mount -t configfs none /Config
85 For nth PCIe Device Controller::
87 # cd /config/pcie_gadget.n/
89 Now you have all the nodes in this directory.
90 program vendor id as 0x104a::
92 # echo 104A >> vendor_id
94 program device id as 0xCD80::
96 # echo CD80 >> device_id
98 program BAR0 size as 1MB::
100 # echo 100000 >> bar0_size
102 check for programmed bar0 size::
106 Program BAR0 Address as DDR (0x2100000). This is the physical address of
107 memory, which is to be made visible to PCIe host. Similarly any other peripheral
108 can also be made visible to PCIe host. E.g., if you program base address of UART
109 as BAR0 address then when this device will be connected to a host, it will be
114 # echo 2100000 >> bar0_address
116 program interrupt type : INTA::
118 # echo INTA >> int_type
124 It will have to be insured that, once link up is done on gadget, then only host
125 is initialized and start to search PCIe devices on its port.
129 /*wait till link is up*/
132 Wait till it returns UP.
142 if MSI is to be used as interrupt, program no of msi vector needed (say4)::
144 # echo 4 >> no_of_msi
146 select MSI as interrupt type::
148 # echo MSI >> int_type
154 wait till link is up::
158 An application can repetitively read this node till link is found UP. It can
159 sleep between two read.
161 wait till msi is enabled::
165 Should return 4 (number of requested MSI vector)
167 to send msi vector 2::