|
22 | 22 |
|
23 | 23 | #include "fsi-master.h" |
24 | 24 |
|
| 25 | +#define FSI_SLAVE_BASE 0x800 |
| 26 | + |
| 27 | +/* |
| 28 | + * FSI slave engine control register offsets |
| 29 | + */ |
| 30 | +#define FSI_SMODE 0x0 /* R/W: Mode register */ |
| 31 | + |
| 32 | +/* |
| 33 | + * SMODE fields |
| 34 | + */ |
| 35 | +#define FSI_SMODE_WSC 0x80000000 /* Warm start done */ |
| 36 | +#define FSI_SMODE_ECRC 0x20000000 /* Hw CRC check */ |
| 37 | +#define FSI_SMODE_SID_SHIFT 24 /* ID shift */ |
| 38 | +#define FSI_SMODE_SID_MASK 3 /* ID Mask */ |
| 39 | +#define FSI_SMODE_ED_SHIFT 20 /* Echo delay shift */ |
| 40 | +#define FSI_SMODE_ED_MASK 0xf /* Echo delay mask */ |
| 41 | +#define FSI_SMODE_SD_SHIFT 16 /* Send delay shift */ |
| 42 | +#define FSI_SMODE_SD_MASK 0xf /* Send delay mask */ |
| 43 | +#define FSI_SMODE_LBCRR_SHIFT 8 /* Clk ratio shift */ |
| 44 | +#define FSI_SMODE_LBCRR_MASK 0xf /* Clk ratio mask */ |
| 45 | + |
25 | 46 | #define FSI_SLAVE_SIZE_23b 0x800000 |
26 | 47 |
|
27 | 48 | static DEFINE_IDA(master_ida); |
@@ -94,6 +115,52 @@ static int fsi_slave_write(struct fsi_slave *slave, uint32_t addr, |
94 | 115 | addr, val, size); |
95 | 116 | } |
96 | 117 |
|
| 118 | +/* Encode slave local bus echo delay */ |
| 119 | +static inline uint32_t fsi_smode_echodly(int x) |
| 120 | +{ |
| 121 | + return (x & FSI_SMODE_ED_MASK) << FSI_SMODE_ED_SHIFT; |
| 122 | +} |
| 123 | + |
| 124 | +/* Encode slave local bus send delay */ |
| 125 | +static inline uint32_t fsi_smode_senddly(int x) |
| 126 | +{ |
| 127 | + return (x & FSI_SMODE_SD_MASK) << FSI_SMODE_SD_SHIFT; |
| 128 | +} |
| 129 | + |
| 130 | +/* Encode slave local bus clock rate ratio */ |
| 131 | +static inline uint32_t fsi_smode_lbcrr(int x) |
| 132 | +{ |
| 133 | + return (x & FSI_SMODE_LBCRR_MASK) << FSI_SMODE_LBCRR_SHIFT; |
| 134 | +} |
| 135 | + |
| 136 | +/* Encode slave ID */ |
| 137 | +static inline uint32_t fsi_smode_sid(int x) |
| 138 | +{ |
| 139 | + return (x & FSI_SMODE_SID_MASK) << FSI_SMODE_SID_SHIFT; |
| 140 | +} |
| 141 | + |
| 142 | +static const uint32_t fsi_slave_smode(int id) |
| 143 | +{ |
| 144 | + return FSI_SMODE_WSC | FSI_SMODE_ECRC |
| 145 | + | fsi_smode_sid(id) |
| 146 | + | fsi_smode_echodly(0xf) | fsi_smode_senddly(0xf) |
| 147 | + | fsi_smode_lbcrr(0x8); |
| 148 | +} |
| 149 | + |
| 150 | +static int fsi_slave_set_smode(struct fsi_master *master, int link, int id) |
| 151 | +{ |
| 152 | + uint32_t smode; |
| 153 | + |
| 154 | + /* set our smode register with the slave ID field to 0; this enables |
| 155 | + * extended slave addressing |
| 156 | + */ |
| 157 | + smode = fsi_slave_smode(id); |
| 158 | + smode = cpu_to_be32(smode); |
| 159 | + |
| 160 | + return fsi_master_write(master, link, id, FSI_SLAVE_BASE + FSI_SMODE, |
| 161 | + &smode, sizeof(smode)); |
| 162 | +} |
| 163 | + |
97 | 164 | static void fsi_slave_release(struct device *dev) |
98 | 165 | { |
99 | 166 | struct fsi_slave *slave = to_fsi_slave(dev); |
@@ -132,6 +199,14 @@ static int fsi_slave_init(struct fsi_master *master, int link, uint8_t id) |
132 | 199 | dev_info(&master->dev, "fsi: found chip %08x at %02x:%02x:%02x\n", |
133 | 200 | chip_id, master->idx, link, id); |
134 | 201 |
|
| 202 | + rc = fsi_slave_set_smode(master, link, id); |
| 203 | + if (rc) { |
| 204 | + dev_warn(&master->dev, |
| 205 | + "can't set smode on slave:%02x:%02x %d\n", |
| 206 | + link, id, rc); |
| 207 | + return -ENODEV; |
| 208 | + } |
| 209 | + |
135 | 210 | /* We can communicate with a slave; create the slave device and |
136 | 211 | * register. |
137 | 212 | */ |
|
0 commit comments