libanyio: remove spilbp as only spi_boards use it and it's too simple to be standalone
Signed-off-by: Michael Geszkiewicz <micges@wp.pl>
This commit is contained in:
parent
c044b78dd6
commit
f0018a4d35
5 changed files with 95 additions and 190 deletions
7
Makefile
7
Makefile
|
|
@ -49,10 +49,10 @@ endif
|
|||
CFLAGS = $(OPT) $(DEBUG) $(INCLUDE)
|
||||
|
||||
objects = common.o lbp.o lbp16.o bitfile.o hostmot2.o eeprom.o anyio.o eth_boards.o epp_boards.o usb_boards.o pci_boards.o
|
||||
objects += sserial_module.o eeprom_local.o eeprom_remote.o spi_boards.o serial_boards.o spilbp.o
|
||||
objects += sserial_module.o eeprom_local.o eeprom_remote.o spi_boards.o serial_boards.o
|
||||
|
||||
headers = eth_boards.h pci_boards.h epp_boards.h usb_boards.h spi_boards.h serial_boards.h anyio.h hostmot2.h lbp16.h types.h
|
||||
headers += common.h eeprom.h lbp.h eeprom_local.h eeprom_remote.h spilbp.h bitfile.h sserial_module.h hostmot2_def.h boards.h
|
||||
headers += common.h eeprom.h lbp.h eeprom_local.h eeprom_remote.h bitfile.h sserial_module.h hostmot2_def.h boards.h
|
||||
|
||||
all: $(LIBANYIO) $(BIN)
|
||||
|
||||
|
|
@ -103,9 +103,6 @@ lbp.o : lbp.c $(headers)
|
|||
lbp16.o : lbp16.c $(headers)
|
||||
$(CC) $(CFLAGS) -c lbp16.c
|
||||
|
||||
spilbp.o : spilbp.c $(headers)
|
||||
$(CC) $(CFLAGS) -c spilbp.c
|
||||
|
||||
hostmot2.o : hostmot2.c $(headers)
|
||||
$(CC) $(CFLAGS) -c hostmot2.c
|
||||
|
||||
|
|
|
|||
106
spi_boards.c
106
spi_boards.c
|
|
@ -16,19 +16,53 @@
|
|||
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
//
|
||||
|
||||
#include "types.h"
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <linux/spi/spidev.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "types.h"
|
||||
#include "eeprom_local.h"
|
||||
#include "spi_boards.h"
|
||||
#include "common.h"
|
||||
#include "spilbp.h"
|
||||
|
||||
extern board_t boards[MAX_BOARDS];
|
||||
extern int boards_count;
|
||||
|
||||
int sd = -1;
|
||||
struct spi_ioc_transfer settings;
|
||||
|
||||
static int spidev_set_lsb_first(int fd, u8 lsb_first) {
|
||||
return ioctl(fd, SPI_IOC_WR_LSB_FIRST, &lsb_first);
|
||||
}
|
||||
|
||||
static int spidev_set_mode(int fd, u8 mode) {
|
||||
return ioctl(fd, SPI_IOC_WR_MODE, &mode);
|
||||
}
|
||||
|
||||
static int spidev_set_max_speed_hz(int fd, u32 speed_hz) {
|
||||
return ioctl(fd, SPI_IOC_WR_MAX_SPEED_HZ, &speed_hz);
|
||||
}
|
||||
|
||||
static int spidev_set_bits_per_word(int fd, u8 bits) {
|
||||
return ioctl(fd, SPI_IOC_WR_BITS_PER_WORD, &bits);
|
||||
}
|
||||
|
||||
static u32 read_command(u16 addr, unsigned nelem) {
|
||||
bool increment = true;
|
||||
return (addr << 16) | SPILBP_CMD_READ | (increment ? SPILBP_ADDR_AUTO_INC : 0) | (nelem << 4);
|
||||
}
|
||||
|
||||
static u32 write_command(u16 addr, unsigned nelem) {
|
||||
bool increment = true;
|
||||
return (addr << 16) | SPILBP_CMD_WRITE | (increment ? SPILBP_ADDR_AUTO_INC : 0) | (nelem << 4);
|
||||
}
|
||||
|
||||
static int spi_board_open(board_t *board) {
|
||||
eeprom_init(&(board->llio));
|
||||
board->flash_id = read_flash_id(&(board->llio));
|
||||
|
|
@ -46,35 +80,77 @@ static int spi_board_close(board_t *board) {
|
|||
}
|
||||
|
||||
int spi_boards_init(board_access_t *access) {
|
||||
spilbp_init(access);
|
||||
settings.speed_hz = 8 * 1000 * 1000;
|
||||
settings.bits_per_word = 32;
|
||||
|
||||
sd = open(access->dev_addr, O_RDWR);
|
||||
if(sd == -1) {
|
||||
perror("open");
|
||||
return;
|
||||
}
|
||||
spidev_set_lsb_first(sd, false);
|
||||
spidev_set_mode(sd, 0);
|
||||
spidev_set_bits_per_word(sd, 32);
|
||||
spidev_set_max_speed_hz(sd, settings.speed_hz);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void spi_boards_cleanup(board_access_t *access) {
|
||||
spilbp_release();
|
||||
if(sd != -1) close(sd);
|
||||
}
|
||||
|
||||
void spi_read(llio_t *self, u32 off, void *buf, int sz) {
|
||||
return spilbp_read(off, buf, sz);
|
||||
int spi_read(llio_t *self, u32 addr, void *buffer, int size) {
|
||||
if(size % 4 != 0) return -1;
|
||||
u32 trxbuf[1+size/4];
|
||||
trxbuf[0] = read_command(addr, size/4);
|
||||
memset(trxbuf+1, 0, size);
|
||||
|
||||
struct spi_ioc_transfer t;
|
||||
t = settings;
|
||||
t.tx_buf = t.rx_buf = (uint64_t)(intptr_t)trxbuf;
|
||||
t.len = sizeof(trxbuf);
|
||||
|
||||
int r = ioctl(sd, SPI_IOC_MESSAGE(1), &t);
|
||||
if(r < 0) return r;
|
||||
|
||||
memcpy(buffer, trxbuf+1, size);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void spi_write(llio_t *self, u32 off, void *buf, int sz) {
|
||||
return spilbp_write(off, buf, sz);
|
||||
int spi_write(llio_t *self, u32 addr, void *buffer, int size) {
|
||||
if(size % 4 != 0) return -1;
|
||||
u32 txbuf[1+size/4];
|
||||
txbuf[0] = write_command(addr, size/4);
|
||||
memcpy(txbuf + 1, buffer, size);
|
||||
|
||||
struct spi_ioc_transfer t;
|
||||
t = settings;
|
||||
t.tx_buf = (uint64_t)(intptr_t)txbuf;
|
||||
t.len = sizeof(txbuf);
|
||||
|
||||
int r = ioctl(sd, SPI_IOC_MESSAGE(1), &t);
|
||||
if(r <= 0) return r;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void spi_boards_scan(board_access_t *access) {
|
||||
u32 buf[4];
|
||||
u32 cookie[] = {0x55aacafe, 0x54534f48, 0x32544f4d};
|
||||
if(spilbp_read(0x100, &buf, sizeof(buf)) < 0) return;
|
||||
board_t *board = &boards[boards_count];
|
||||
|
||||
if (spi_read(&(board->llio), HM2_COOKIE_REG, &buf, sizeof(buf)) < 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
if(memcmp(buf, cookie, sizeof(cookie))) {
|
||||
fprintf(stderr, "Unexpected cookie at 0000..000c:\n%08x %08x %08x\n",
|
||||
buf[0], buf[1], buf[2]);
|
||||
return 0;
|
||||
return;
|
||||
}
|
||||
|
||||
char ident[8];
|
||||
if(spilbp_read(buf[3] + 0xc, &ident, sizeof(ident)) < 0) return;
|
||||
if(spi_read(&(board->llio), buf[3] + 0xc, &ident, sizeof(ident)) < 0) return;
|
||||
|
||||
if(!memcmp(ident, "MESA7I90", 8)) {
|
||||
board_t *board = &boards[boards_count];
|
||||
|
|
@ -108,10 +184,6 @@ void spi_boards_scan(board_access_t *access) {
|
|||
}
|
||||
}
|
||||
|
||||
void spi_boards_release(board_access_t *access) {
|
||||
spilbp_release();
|
||||
}
|
||||
|
||||
void spi_print_info(board_t *board) {
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -21,11 +21,13 @@
|
|||
|
||||
#include "boards.h"
|
||||
|
||||
#define SPILBP_ADDR_AUTO_INC 0b0000100000000000
|
||||
#define SPILBP_CMD_READ 0b1010000000000000
|
||||
#define SPILBP_CMD_WRITE 0b1011000000000000
|
||||
|
||||
int spi_boards_init(board_access_t *access);
|
||||
void spi_boards_cleanup(board_access_t *access);
|
||||
void spi_boards_scan(board_access_t *access);
|
||||
void spi_boards_release(board_access_t *access);
|
||||
void spi_print_info(board_t *board);
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
|||
118
spilbp.c
118
spilbp.c
|
|
@ -1,118 +0,0 @@
|
|||
//
|
||||
// Copyright (C) 2013-2014 Michael Geszkiewicz
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation; either version 2 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
//
|
||||
|
||||
#include "types.h"
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <linux/spi/spidev.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include "eeprom_local.h"
|
||||
#include "boards.h"
|
||||
|
||||
int sd = -1;
|
||||
struct spi_ioc_transfer settings;
|
||||
|
||||
static u32 read_command(u16 addr, unsigned nelem) {
|
||||
bool increment = true;
|
||||
return (addr << 16) | 0xA000 | (increment ? 0x800 : 0) | (nelem << 4);
|
||||
}
|
||||
|
||||
static u32 write_command(u16 addr, unsigned nelem) {
|
||||
bool increment = true;
|
||||
return (addr << 16) | 0xB000 | (increment ? 0x800 : 0) | (nelem << 4);
|
||||
}
|
||||
|
||||
|
||||
int spilbp_write(u16 addr, void *buffer, int size) {
|
||||
if(size % 4 != 0) return -1;
|
||||
u32 txbuf[1+size/4];
|
||||
txbuf[0] = write_command(addr, size/4);
|
||||
memcpy(txbuf + 1, buffer, size);
|
||||
|
||||
struct spi_ioc_transfer t;
|
||||
t = settings;
|
||||
t.tx_buf = (uint64_t)(intptr_t)txbuf;
|
||||
t.len = sizeof(txbuf);
|
||||
|
||||
int r = ioctl(sd, SPI_IOC_MESSAGE(1), &t);
|
||||
if(r <= 0) return r;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int spilbp_read(u16 addr, void *buffer, int size) {
|
||||
if(size % 4 != 0) return -1;
|
||||
u32 trxbuf[1+size/4];
|
||||
trxbuf[0] = read_command(addr, size/4);
|
||||
memset(trxbuf+1, 0, size);
|
||||
|
||||
struct spi_ioc_transfer t;
|
||||
t = settings;
|
||||
t.tx_buf = t.rx_buf = (uint64_t)(intptr_t)trxbuf;
|
||||
t.len = sizeof(trxbuf);
|
||||
|
||||
int r = ioctl(sd, SPI_IOC_MESSAGE(1), &t);
|
||||
if(r < 0) return r;
|
||||
|
||||
memcpy(buffer, trxbuf+1, size);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void spilbp_print_info() {
|
||||
}
|
||||
|
||||
static int spidev_set_lsb_first(int fd, u8 lsb_first) {
|
||||
return ioctl(fd, SPI_IOC_WR_LSB_FIRST, &lsb_first);
|
||||
}
|
||||
|
||||
static int spidev_set_mode(int fd, u8 mode) {
|
||||
return ioctl(fd, SPI_IOC_WR_MODE, &mode);
|
||||
}
|
||||
|
||||
static int spidev_set_max_speed_hz(int fd, u32 speed_hz) {
|
||||
return ioctl(fd, SPI_IOC_WR_MAX_SPEED_HZ, &speed_hz);
|
||||
}
|
||||
|
||||
static int spidev_set_bits_per_word(int fd, u8 bits) {
|
||||
return ioctl(fd, SPI_IOC_WR_BITS_PER_WORD, &bits);
|
||||
}
|
||||
|
||||
|
||||
void spilbp_init(board_access_t *access) {
|
||||
settings.speed_hz = 8 * 1000 * 1000;
|
||||
settings.bits_per_word = 32;
|
||||
|
||||
sd = open(access->dev_addr, O_RDWR);
|
||||
if(sd == -1) {
|
||||
perror("open");
|
||||
return;
|
||||
}
|
||||
spidev_set_lsb_first(sd, false);
|
||||
spidev_set_mode(sd, 0);
|
||||
spidev_set_bits_per_word(sd, 32);
|
||||
spidev_set_max_speed_hz(sd, settings.speed_hz);
|
||||
}
|
||||
|
||||
void spilbp_release() {
|
||||
if(sd != -1) close(sd);
|
||||
}
|
||||
48
spilbp.h
48
spilbp.h
|
|
@ -1,48 +0,0 @@
|
|||
//
|
||||
// Copyright (C) 2013-2014 Michael Geszkiewicz
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation; either version 2 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
//
|
||||
|
||||
#ifndef __SPILBP_H
|
||||
#define __SPILBP_H
|
||||
|
||||
#include "types.h"
|
||||
#include "common.h"
|
||||
|
||||
#define SPILBP_SENDRECV_DEBUG 0
|
||||
|
||||
#define SPILBP_MAX_PACKET_DATA_SIZE 0x7F
|
||||
|
||||
#define SPILBP_ADDR_AUTO_INC 0b0000100000000000
|
||||
#define SPILBP_READ 0b1010000000000000
|
||||
#define SPILBP_WRITE 0b1011000000000000
|
||||
|
||||
typedef struct {
|
||||
u8 addr_hi;
|
||||
u8 addr_lo;
|
||||
u8 cmd_hi;
|
||||
u8 cmd_lo;
|
||||
} spilbp_cmd_addr;
|
||||
|
||||
void spilbp_print_info();
|
||||
void spilbp_init(board_access_t *access);
|
||||
void spilbp_release();
|
||||
int spilbp_write(u32 addr, void *buffer, int size);
|
||||
int spilbp_read(u32 addr, void *buffer, int size);
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
Loading…
Reference in a new issue