diff options
author | Jean-Michel Hautbois <jean-michel.hautbois@vodalys.com> | 2014-07-24 04:53:00 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2014-07-27 14:10:42 -0400 |
commit | ee5311420d03eccee02e447e698d2fda6c25583d (patch) | |
tree | 51d88a3dec6db3b6c0179bf6c6538721ad810e4b | |
parent | 4dcc2ab3f869c5ecdcf4edfe5308767121f8a136 (diff) |
Lattice ECP3 FPGA: Correct endianness
This code corrects endianness and avoids a sparse error.
Tested with Lattice ECP3-35 with Freescale i.MX6.
It also sends uevent in order to load it.
Signed-off-by: Jean-Michel Hautbois <jean-michel.hautbois@vodalys.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r-- | drivers/misc/lattice-ecp3-config.c | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/drivers/misc/lattice-ecp3-config.c b/drivers/misc/lattice-ecp3-config.c index 0a1565e63c71..7ffdb589841e 100644 --- a/drivers/misc/lattice-ecp3-config.c +++ b/drivers/misc/lattice-ecp3-config.c | |||
@@ -15,6 +15,7 @@ | |||
15 | #include <linux/spi/spi.h> | 15 | #include <linux/spi/spi.h> |
16 | #include <linux/platform_device.h> | 16 | #include <linux/platform_device.h> |
17 | #include <linux/delay.h> | 17 | #include <linux/delay.h> |
18 | #include <asm/unaligned.h> | ||
18 | 19 | ||
19 | #define FIRMWARE_NAME "lattice-ecp3.bit" | 20 | #define FIRMWARE_NAME "lattice-ecp3.bit" |
20 | 21 | ||
@@ -91,8 +92,8 @@ static void firmware_load(const struct firmware *fw, void *context) | |||
91 | /* Trying to speak with the FPGA via SPI... */ | 92 | /* Trying to speak with the FPGA via SPI... */ |
92 | txbuf[0] = FPGA_CMD_READ_ID; | 93 | txbuf[0] = FPGA_CMD_READ_ID; |
93 | ret = spi_write_then_read(spi, txbuf, 8, rxbuf, rx_len); | 94 | ret = spi_write_then_read(spi, txbuf, 8, rxbuf, rx_len); |
94 | dev_dbg(&spi->dev, "FPGA JTAG ID=%08x\n", *(u32 *)&rxbuf[4]); | 95 | jedec_id = get_unaligned_be32(&rxbuf[4]); |
95 | jedec_id = *(u32 *)&rxbuf[4]; | 96 | dev_dbg(&spi->dev, "FPGA JTAG ID=%08x\n", jedec_id); |
96 | 97 | ||
97 | for (i = 0; i < ARRAY_SIZE(ecp3_dev); i++) { | 98 | for (i = 0; i < ARRAY_SIZE(ecp3_dev); i++) { |
98 | if (jedec_id == ecp3_dev[i].jedec_id) | 99 | if (jedec_id == ecp3_dev[i].jedec_id) |
@@ -109,7 +110,8 @@ static void firmware_load(const struct firmware *fw, void *context) | |||
109 | 110 | ||
110 | txbuf[0] = FPGA_CMD_READ_STATUS; | 111 | txbuf[0] = FPGA_CMD_READ_STATUS; |
111 | ret = spi_write_then_read(spi, txbuf, 8, rxbuf, rx_len); | 112 | ret = spi_write_then_read(spi, txbuf, 8, rxbuf, rx_len); |
112 | dev_dbg(&spi->dev, "FPGA Status=%08x\n", *(u32 *)&rxbuf[4]); | 113 | status = get_unaligned_be32(&rxbuf[4]); |
114 | dev_dbg(&spi->dev, "FPGA Status=%08x\n", status); | ||
113 | 115 | ||
114 | buffer = kzalloc(fw->size + 8, GFP_KERNEL); | 116 | buffer = kzalloc(fw->size + 8, GFP_KERNEL); |
115 | if (!buffer) { | 117 | if (!buffer) { |
@@ -141,7 +143,7 @@ static void firmware_load(const struct firmware *fw, void *context) | |||
141 | for (i = 0; i < FPGA_CLEAR_LOOP_COUNT; i++) { | 143 | for (i = 0; i < FPGA_CLEAR_LOOP_COUNT; i++) { |
142 | txbuf[0] = FPGA_CMD_READ_STATUS; | 144 | txbuf[0] = FPGA_CMD_READ_STATUS; |
143 | ret = spi_write_then_read(spi, txbuf, 8, rxbuf, rx_len); | 145 | ret = spi_write_then_read(spi, txbuf, 8, rxbuf, rx_len); |
144 | status = *(u32 *)&rxbuf[4]; | 146 | status = get_unaligned_be32(&rxbuf[4]); |
145 | if (status == FPGA_STATUS_CLEARED) | 147 | if (status == FPGA_STATUS_CLEARED) |
146 | break; | 148 | break; |
147 | 149 | ||
@@ -164,8 +166,8 @@ static void firmware_load(const struct firmware *fw, void *context) | |||
164 | 166 | ||
165 | txbuf[0] = FPGA_CMD_READ_STATUS; | 167 | txbuf[0] = FPGA_CMD_READ_STATUS; |
166 | ret = spi_write_then_read(spi, txbuf, 8, rxbuf, rx_len); | 168 | ret = spi_write_then_read(spi, txbuf, 8, rxbuf, rx_len); |
167 | dev_dbg(&spi->dev, "FPGA Status=%08x\n", *(u32 *)&rxbuf[4]); | 169 | status = get_unaligned_be32(&rxbuf[4]); |
168 | status = *(u32 *)&rxbuf[4]; | 170 | dev_dbg(&spi->dev, "FPGA Status=%08x\n", status); |
169 | 171 | ||
170 | /* Check result */ | 172 | /* Check result */ |
171 | if (status & FPGA_STATUS_DONE) | 173 | if (status & FPGA_STATUS_DONE) |
@@ -196,7 +198,7 @@ static int lattice_ecp3_probe(struct spi_device *spi) | |||
196 | spi_set_drvdata(spi, data); | 198 | spi_set_drvdata(spi, data); |
197 | 199 | ||
198 | init_completion(&data->fw_loaded); | 200 | init_completion(&data->fw_loaded); |
199 | err = request_firmware_nowait(THIS_MODULE, FW_ACTION_NOHOTPLUG, | 201 | err = request_firmware_nowait(THIS_MODULE, FW_ACTION_HOTPLUG, |
200 | FIRMWARE_NAME, &spi->dev, | 202 | FIRMWARE_NAME, &spi->dev, |
201 | GFP_KERNEL, spi, firmware_load); | 203 | GFP_KERNEL, spi, firmware_load); |
202 | if (err) { | 204 | if (err) { |