123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176 |
- #include<linux/string.h>
- #include "defines.h"
- #include "kspi.h"
- #include "kfile.h"
- #include "ktiva.h"
- /////////////////////////////////////////////////////////////////////////////
- /////////////////////////////////////////////////////////////////////////////
- int kspi_write_mode(struct file *pf, unsigned char mode)
- {
- int ret;
- if((ret = kf_ioctl(pf, SPI_IOC_WR_MODE, (unsigned long)&mode)) < 0)
- {
- KALERT("%s: kf_ioctl failed: %d\n", __FUNCTION__, ret);
- }
- return ret;
- }
- /////////////////////////////////////////////////////////////////////////////
- int kspi_read_mode(struct file *pf, unsigned char *mode)
- {
- int ret;
- if((ret = kf_ioctl(pf, SPI_IOC_RD_MODE, (unsigned long)mode)) < 0)
- {
- KALERT("%s: kf_ioctl failed: %d\n", __FUNCTION__, ret);
- }
- return ret;
- }
- /////////////////////////////////////////////////////////////////////////////
- int kspi_write_bits_per_word(struct file *pf, unsigned char bits)
- {
- int ret;
- if((ret = kf_ioctl(pf, SPI_IOC_WR_BITS_PER_WORD, (unsigned long)&bits)) < 0)
- {
- KALERT("%s: kf_ioctl failed: %d\n", __FUNCTION__, ret);
- }
- return ret;
- }
- /////////////////////////////////////////////////////////////////////////////
- int kspi_read_bits_per_word(struct file *pf, unsigned char *bits)
- {
- int ret;
- if((ret = kf_ioctl(pf, SPI_IOC_RD_BITS_PER_WORD, (unsigned long)bits)) < 0)
- {
- KALERT("%s: kf_ioctl failed: %d\n", __FUNCTION__, ret);
- }
- return ret;
- }
- /////////////////////////////////////////////////////////////////////////////
- int kspi_write_max_speed_hz(struct file *pf, unsigned int speed)
- {
- int ret;
- if((ret = kf_ioctl(pf, SPI_IOC_WR_MAX_SPEED_HZ, (unsigned long)&speed)) < 0)
- {
- KALERT("%s: kf_ioctl failed: %d\n", __FUNCTION__, ret);
- }
- return ret;
- }
- /////////////////////////////////////////////////////////////////////////////
- int kspi_read_max_speed_hz(struct file *pf, unsigned int *speed)
- {
- int ret;
- if((ret = kf_ioctl(pf, SPI_IOC_RD_MAX_SPEED_HZ, (unsigned long)speed)) < 0)
- {
- KALERT("%s: kf_ioctl failed: %d\n", __FUNCTION__, ret);
- }
- return ret;
- }
- /////////////////////////////////////////////////////////////////////////////
- /////////////////////////////////////////////////////////////////////////////
- /////////////////////////////////////////////////////////////////////////////
- int kspi_tx(struct file *pf, const void *pData, size_t nCbData)
- {
- int ret;
- struct spi_ioc_transfer tr =
- {
- .tx_buf = (unsigned long)pData,
- .rx_buf = 0,
- .len = nCbData,
- .delay_usecs = 0,
- .speed_hz = _SPI_SPEED_HZ,
- .bits_per_word = _SPI_BITS_PER_WORD,
- };
- if((ret = kf_ioctl(pf, SPI_IOC_MESSAGE(1), (unsigned long)&tr)) < 0)
- KALERT("%s failed: %d\n", __FUNCTION__, ret);
- return ret;
- }
- /////////////////////////////////////////////////////////////////////////////
- int kspi_rx(struct file *pf, void *pData, size_t nCbData)
- {
- int ret;
- struct spi_ioc_transfer tr =
- {
- .tx_buf = 0,
- .rx_buf = (unsigned long)pData,
- .len = nCbData,
- .delay_usecs = 0,
- .speed_hz = _SPI_SPEED_HZ,
- .bits_per_word = _SPI_BITS_PER_WORD,
- };
- if((ret = kf_ioctl(pf, SPI_IOC_MESSAGE(1), (unsigned long)&tr)) < 0)
- KALERT("%s failed: %d\n", __FUNCTION__, ret);
- return ret;
- }
- /////////////////////////////////////////////////////////////////////////////
- int kspi_tx_rx(struct file *pf, const void *pTx, void *pRx, size_t nCb)
- {
- int ret;
- struct spi_ioc_transfer tr =
- {
- .tx_buf = (unsigned long)pTx,
- .rx_buf = (unsigned long)pRx,
- .len = nCb,
- .delay_usecs = 0,
- .speed_hz = _SPI_SPEED_HZ,
- .bits_per_word = _SPI_BITS_PER_WORD,
- };
- if((ret = kf_ioctl(pf, SPI_IOC_MESSAGE(1), (unsigned long)&tr)) < 0)
- KALERT("%s failed: %d\n", __FUNCTION__, ret);
- return ret;
- }
- /////////////////////////////////////////////////////////////////////////////
- int kspi_rx_byte(struct file *pf, unsigned char *rx)
- {
- return kspi_rx(pf, rx, 1);
- }
- /////////////////////////////////////////////////////////////////////////////
- int kspi_tx_byte(struct file *pf, unsigned char tx)
- {
- return kspi_tx(pf, &tx, 1);
- }
- /////////////////////////////////////////////////////////////////////////////
- int kspi_tx_rx_byte(struct file *pf, unsigned char tx, unsigned char *rx)
- {
- return kspi_tx_rx(pf, &tx, rx, 1);
- }
|