summaryrefslogtreecommitdiff
path: root/drivers/staging/wilc1000/linux_wlan_spi.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/staging/wilc1000/linux_wlan_spi.c')
-rw-r--r--drivers/staging/wilc1000/linux_wlan_spi.c116
1 files changed, 23 insertions, 93 deletions
diff --git a/drivers/staging/wilc1000/linux_wlan_spi.c b/drivers/staging/wilc1000/linux_wlan_spi.c
index 236669cfcd3a..039d06192d6b 100644
--- a/drivers/staging/wilc1000/linux_wlan_spi.c
+++ b/drivers/staging/wilc1000/linux_wlan_spi.c
@@ -5,11 +5,12 @@
#include <linux/slab.h>
#include <linux/types.h>
#include <linux/cdev.h>
-#include <asm/uaccess.h>
+#include <linux/uaccess.h>
#include <linux/device.h>
#include <linux/spi/spi.h>
#include "linux_wlan_common.h"
+#include "linux_wlan_spi.h"
#define USE_SPI_DMA 0 /* johnny add */
@@ -38,7 +39,7 @@
#define MAX_SPEED 6000000
#endif /* WILC_ASIC_A0 */
-static uint32_t SPEED = MIN_SPEED;
+static u32 SPEED = MIN_SPEED;
struct spi_device *wilc_spi_dev;
void linux_spi_deinit(void *vp);
@@ -113,57 +114,20 @@ int linux_spi_init(void *vp)
#define TXRX_PHASE_SIZE (4096)
#endif
-#if defined (NM73131_0_BOARD)
+#if defined(TXRX_PHASE_SIZE)
-int linux_spi_write(uint8_t *b, uint32_t len)
+int linux_spi_write(u8 *b, u32 len)
{
-
int ret;
if (len > 0 && b != NULL) {
- struct spi_message msg;
- PRINT_D(BUS_DBG, "Request writing %d bytes\n", len);
- struct spi_transfer tr = {
- .tx_buf = b,
- .len = len,
- .speed_hz = SPEED,
- .delay_usecs = 0,
- };
-
- spi_message_init(&msg);
- spi_message_add_tail(&tr, &msg);
- ret = spi_sync(wilc_spi_dev, &msg);
- if (ret < 0) {
- PRINT_ER("SPI transaction failed\n");
- }
-
- } else {
- PRINT_ER("can't write data with the following length: %d\n", len);
- PRINT_ER("FAILED due to NULL buffer or ZERO length check the following length: %d\n", len);
- ret = -1;
- }
-
- /* change return value to match WILC interface */
- (ret < 0) ? (ret = 0) : (ret = 1);
-
-
- return ret;
-}
-
-#elif defined(TXRX_PHASE_SIZE)
-
-int linux_spi_write(uint8_t *b, uint32_t len)
-{
- int ret;
- if (len > 0 && b != NULL) {
int i = 0;
int blk = len / TXRX_PHASE_SIZE;
int remainder = len % TXRX_PHASE_SIZE;
char *r_buffer = kzalloc(TXRX_PHASE_SIZE, GFP_KERNEL);
- if (!r_buffer) {
- PRINT_ER("Failed to allocate memory for r_buffer\n");
- }
+ if (!r_buffer)
+ return -ENOMEM;
if (blk) {
while (i < blk) {
@@ -229,7 +193,7 @@ int linux_spi_write(uint8_t *b, uint32_t len)
}
#else
-int linux_spi_write(uint8_t *b, uint32_t len)
+int linux_spi_write(u8 *b, u32 len)
{
int ret;
@@ -243,9 +207,9 @@ int linux_spi_write(uint8_t *b, uint32_t len)
.delay_usecs = 0,
};
char *r_buffer = kzalloc(len, GFP_KERNEL);
- if (!r_buffer) {
- PRINT_ER("Failed to allocate memory for r_buffer\n");
- }
+ if (!r_buffer)
+ return -ENOMEM;
+
tr.rx_buf = r_buffer;
PRINT_D(BUS_DBG, "Request writing %d bytes\n", len);
@@ -278,42 +242,9 @@ int linux_spi_write(uint8_t *b, uint32_t len)
#endif
-#if defined (NM73131_0_BOARD)
+#if defined(TXRX_PHASE_SIZE)
-int linux_spi_read(unsigned char *rb, unsigned long rlen)
-{
-
- int ret;
-
- if (rlen > 0) {
- struct spi_message msg;
- struct spi_transfer tr = {
- .rx_buf = rb,
- .len = rlen,
- .speed_hz = SPEED,
- .delay_usecs = 0,
-
- };
-
- spi_message_init(&msg);
- spi_message_add_tail(&tr, &msg);
- ret = spi_sync(wilc_spi_dev, &msg);
- if (ret < 0) {
- PRINT_ER("SPI transaction failed\n");
- }
- } else {
- PRINT_ER("can't read data with the following length: %ld\n", rlen);
- ret = -1;
- }
- /* change return value to match WILC interface */
- (ret < 0) ? (ret = 0) : (ret = 1);
-
- return ret;
-}
-
-#elif defined(TXRX_PHASE_SIZE)
-
-int linux_spi_read(unsigned char *rb, unsigned long rlen)
+int linux_spi_read(u8 *rb, u32 rlen)
{
int ret;
@@ -324,9 +255,8 @@ int linux_spi_read(unsigned char *rb, unsigned long rlen)
int remainder = rlen % TXRX_PHASE_SIZE;
char *t_buffer = kzalloc(TXRX_PHASE_SIZE, GFP_KERNEL);
- if (!t_buffer) {
- PRINT_ER("Failed to allocate memory for t_buffer\n");
- }
+ if (!t_buffer)
+ return -ENOMEM;
if (blk) {
while (i < blk) {
@@ -378,7 +308,7 @@ int linux_spi_read(unsigned char *rb, unsigned long rlen)
kfree(t_buffer);
} else {
- PRINT_ER("can't read data with the following length: %ld\n", rlen);
+ PRINT_ER("can't read data with the following length: %u\n", rlen);
ret = -1;
}
/* change return value to match WILC interface */
@@ -388,7 +318,7 @@ int linux_spi_read(unsigned char *rb, unsigned long rlen)
}
#else
-int linux_spi_read(unsigned char *rb, unsigned long rlen)
+int linux_spi_read(u8 *rb, u32 rlen)
{
int ret;
@@ -403,9 +333,9 @@ int linux_spi_read(unsigned char *rb, unsigned long rlen)
};
char *t_buffer = kzalloc(rlen, GFP_KERNEL);
- if (!t_buffer) {
- PRINT_ER("Failed to allocate memory for t_buffer\n");
- }
+ if (!t_buffer)
+ return -ENOMEM;
+
tr.tx_buf = t_buffer;
memset(&msg, 0, sizeof(msg));
@@ -422,7 +352,7 @@ int linux_spi_read(unsigned char *rb, unsigned long rlen)
}
kfree(t_buffer);
} else {
- PRINT_ER("can't read data with the following length: %ld\n", rlen);
+ PRINT_ER("can't read data with the following length: %u\n", rlen);
ret = -1;
}
/* change return value to match WILC interface */
@@ -433,7 +363,7 @@ int linux_spi_read(unsigned char *rb, unsigned long rlen)
#endif
-int linux_spi_write_read(unsigned char *wb, unsigned char *rb, unsigned int rlen)
+int linux_spi_write_read(u8 *wb, u8 *rb, u32 rlen)
{
int ret;
@@ -461,7 +391,7 @@ int linux_spi_write_read(unsigned char *wb, unsigned char *rb, unsigned int rlen
PRINT_ER("SPI transaction failed\n");
}
} else {
- PRINT_ER("can't read data with the following length: %d\n", rlen);
+ PRINT_ER("can't read data with the following length: %u\n", rlen);
ret = -1;
}
/* change return value to match WILC interface */