Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

net/libertas: make SPI interface big endian aware

The comment (which I remove) says that the translation is done SPI routines.
IMHO this can't work because the SPI driver does not know whether the incomming
bytes are part of the registers/bytes which need to be flipped or part of
packet data which has to remain untouched.
While adding le helpers I also removed spu_write_u32() which has no users.

Tested-by: Andrey Yurovsky <andrey@cozybit.com>
Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Acked-by: Dan Williams <dcbw@redhat.com>
Signed-off-by: John W. Linville <linville@tuxdriver.com>

authored by

Sebastian Andrzej Siewior and committed by
John W. Linville
f488b72d 55aa4e0f

+16 -18
+16 -18
drivers/net/wireless/libertas/if_spi.c
··· 119 119 * First we have to put a SPU register name on the bus. Then we can 120 120 * either read from or write to that register. 121 121 * 122 - * For 16-bit transactions, byte order on the bus is big-endian. 123 - * We don't have to worry about that here, though. 124 - * The translation takes place in the SPI routines. 125 122 */ 126 123 127 124 static void spu_transaction_init(struct if_spi_card *card) ··· 144 147 static int spu_write(struct if_spi_card *card, u16 reg, const u8 *buf, int len) 145 148 { 146 149 int err = 0; 147 - u16 reg_out = reg | IF_SPI_WRITE_OPERATION_MASK; 150 + u16 reg_out = cpu_to_le16(reg | IF_SPI_WRITE_OPERATION_MASK); 148 151 149 152 /* You must give an even number of bytes to the SPU, even if it 150 153 * doesn't care about the last one. */ ··· 166 169 167 170 static inline int spu_write_u16(struct if_spi_card *card, u16 reg, u16 val) 168 171 { 169 - return spu_write(card, reg, (u8 *)&val, sizeof(u16)); 170 - } 172 + u16 buff; 171 173 172 - static inline int spu_write_u32(struct if_spi_card *card, u16 reg, u32 val) 173 - { 174 - /* The lower 16 bits are written first. */ 175 - u16 out[2]; 176 - out[0] = val & 0xffff; 177 - out[1] = (val & 0xffff0000) >> 16; 178 - return spu_write(card, reg, (u8 *)&out, sizeof(u32)); 174 + buff = cpu_to_le16(val); 175 + return spu_write(card, reg, (u8 *)&buff, sizeof(u16)); 179 176 } 180 177 181 178 static inline int spu_reg_is_port_reg(u16 reg) ··· 189 198 unsigned int i, delay; 190 199 int err = 0; 191 200 u16 zero = 0; 192 - u16 reg_out = reg | IF_SPI_READ_OPERATION_MASK; 201 + u16 reg_out = cpu_to_le16(reg | IF_SPI_READ_OPERATION_MASK); 193 202 194 203 /* You must take an even number of bytes from the SPU, even if you 195 204 * don't care about the last one. */ ··· 227 236 /* Read 16 bits from an SPI register */ 228 237 static inline int spu_read_u16(struct if_spi_card *card, u16 reg, u16 *val) 229 238 { 230 - return spu_read(card, reg, (u8 *)val, sizeof(u16)); 239 + u16 buf; 240 + int ret; 241 + 242 + ret = spu_read(card, reg, (u8 *)&buf, sizeof(buf)); 243 + if (ret == 0) 244 + *val = le16_to_cpup(&buf); 245 + return ret; 231 246 } 232 247 233 248 /* Read 32 bits from an SPI register. 234 249 * The low 16 bits are read first. */ 235 250 static int spu_read_u32(struct if_spi_card *card, u16 reg, u32 *val) 236 251 { 237 - u16 buf[2]; 252 + u32 buf; 238 253 int err; 239 - err = spu_read(card, reg, (u8 *)buf, sizeof(u32)); 254 + 255 + err = spu_read(card, reg, (u8 *)&buf, sizeof(buf)); 240 256 if (!err) 241 - *val = buf[0] | (buf[1] << 16); 257 + *val = le32_to_cpup(&buf); 242 258 return err; 243 259 } 244 260