|
|
@ -1,7 +1,8 @@ |
|
|
|
#include <string.h> |
|
|
|
#include "csl/csl.h" |
|
|
|
#include "csl/csl_mcbsp.h" |
|
|
|
#include "platform_internal.h" |
|
|
|
#include "spi.h" |
|
|
|
|
|
|
|
typedef struct __spi_handle *spi_t; |
|
|
|
struct __spi_handle { |
|
|
|
MCBSP_Handle spi; |
|
|
|
int bits; |
|
|
@ -9,14 +10,12 @@ struct __spi_handle { |
|
|
|
|
|
|
|
static struct __spi_handle __spi_devs[_MCBSP_PORT_CNT]; |
|
|
|
|
|
|
|
unsigned long platform_cpu_freq(); |
|
|
|
|
|
|
|
void spi_lowlevel_init() |
|
|
|
{ |
|
|
|
memset(__spi_devs, 0, sizeof __spi_devs); |
|
|
|
} |
|
|
|
|
|
|
|
spi_t spi_open(int dev_id, int mode, int freq, int bits) |
|
|
|
int spi_open(int dev_id, int mode, int freq, int bits) |
|
|
|
{ |
|
|
|
MCBSP_Config mbconf; |
|
|
|
MCBSP_Handle handle = 0; |
|
|
@ -45,7 +44,7 @@ spi_t spi_open(int dev_id, int mode, int freq, int bits) |
|
|
|
dlen1 = MCBSP_XCR_XWDLEN1_32BIT; |
|
|
|
break; |
|
|
|
default: |
|
|
|
return NULL; |
|
|
|
return -1; |
|
|
|
} |
|
|
|
|
|
|
|
switch (mode) { |
|
|
@ -178,7 +177,7 @@ spi_t spi_open(int dev_id, int mode, int freq, int bits) |
|
|
|
MCBSP_SRGR_DEFAULT_DELAY); |
|
|
|
|
|
|
|
spi->spi = handle; |
|
|
|
return spi; |
|
|
|
return 0; |
|
|
|
} |
|
|
|
|
|
|
|
static int __write_u8(spi_t spi, const Uint8 *buf, int len) |
|
|
@ -214,11 +213,30 @@ static int __write_u32(spi_t spi, const Uint32 *buf, int len) |
|
|
|
return (len); |
|
|
|
} |
|
|
|
|
|
|
|
int spi_write(spi_t spi, const void *buf, int len) |
|
|
|
static spi_t __get_active_device(int dev_id) |
|
|
|
{ |
|
|
|
spi_t spi; |
|
|
|
|
|
|
|
if (dev_id < 0 || dev_id >= ARRAY_SIZE(__spi_devs)) |
|
|
|
return NULL; |
|
|
|
|
|
|
|
spi = &__spi_devs[dev_id]; |
|
|
|
|
|
|
|
return spi->spi ? spi : NULL; |
|
|
|
} |
|
|
|
|
|
|
|
int spi_write(int dev_id, const void *buf, int len) |
|
|
|
{ |
|
|
|
const Uint8 *u8; |
|
|
|
const Uint16 *u16; |
|
|
|
const Uint32 *u32; |
|
|
|
spi_t spi; |
|
|
|
|
|
|
|
if ((spi = __get_active_device(dev_id)) == NULL) { |
|
|
|
return -1; |
|
|
|
} |
|
|
|
|
|
|
|
spi = &__spi_devs[dev_id]; |
|
|
|
|
|
|
|
switch (spi->bits) { |
|
|
|
case 8: |
|
|
@ -275,11 +293,16 @@ static int __read_u32(spi_t spi, Uint32 *buf, int len) |
|
|
|
return (len); |
|
|
|
} |
|
|
|
|
|
|
|
int spi_read(spi_t spi, void *buf, int len) |
|
|
|
int spi_read(int dev_id, void *buf, int len) |
|
|
|
{ |
|
|
|
Uint8 *u8; |
|
|
|
Uint16 *u16; |
|
|
|
Uint32 *u32; |
|
|
|
spi_t spi; |
|
|
|
|
|
|
|
if ((spi = __get_active_device(dev_id)) == NULL) { |
|
|
|
return -1; |
|
|
|
} |
|
|
|
|
|
|
|
switch (spi->bits) { |
|
|
|
case 8: |
|
|
@ -303,9 +326,16 @@ int spi_read(spi_t spi, void *buf, int len) |
|
|
|
return (len); |
|
|
|
} |
|
|
|
|
|
|
|
void spi_close(spi_t spi) |
|
|
|
void spi_close(int dev_id) |
|
|
|
{ |
|
|
|
spi_t spi; |
|
|
|
|
|
|
|
if ((spi = __get_active_device(dev_id)) == NULL) { |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
MCBSP_close(spi->spi); |
|
|
|
spi->spi = NULL; |
|
|
|
spi->bits = 0; |
|
|
|
} |
|
|
|
|
|
|
|