spi.h
上传用户:beauty0755
上传日期:2022-02-24
资源大小:7k
文件大小:3k
- #include <linux/ioctl.h>
- /*------------------------------------------*/
- /* GPIO I/F */
- /*------------------------------------------*/
- //#define IXP4XX_DEBUG_UART_BASE_PHYS (0xC8000000)
- #define IXP4XX_GPIO_BASE_PHYS (IXP4XX_PERIPHERAL_BASE_PHYS + 0x4000)
- //#define IXP4XX_PERIPHERAL_BASE_VIRT (0xFF000000)
- #define IXP4XX_GPIO_BASE_VIRT (IXP4XX_PERIPHERAL_BASE_VIRT + 0x4000)
- /*
- * Constants to make it easy to access GPIO registers
- */
- #define IXP4XX_GPIO_GPOUTR_OFFSET 0x00
- #define IXP4XX_GPIO_GPOER_OFFSET 0x04
- #define IXP4XX_GPIO_GPINR_OFFSET 0x08
- #define IXP4XX_GPIO_GPISR_OFFSET 0x0C
- #define IXP4XX_GPIO_GPIT1R_OFFSET 0x10
- #define IXP4XX_GPIO_GPIT2R_OFFSET 0x14
- #define IXP4XX_GPIO_GPCLKR_OFFSET 0x18
- #define IXP4XX_GPIO_GPDBSELR_OFFSET 0x1C
- /*
- * GPIO Register Definitions.
- * [Only perform 32bit reads/writes]
- */
- #define IXP4XX_GPIO_REG(x) ((volatile u32 *)(IXP4XX_GPIO_BASE_VIRT+(x)))
- #define IXP4XX_GPIO_GPOUTR IXP4XX_GPIO_REG(IXP4XX_GPIO_GPOUTR_OFFSET)
- #define IXP4XX_GPIO_GPOER IXP4XX_GPIO_REG(IXP4XX_GPIO_GPOER_OFFSET)
- #define IXP4XX_GPIO_GPINR IXP4XX_GPIO_REG(IXP4XX_GPIO_GPINR_OFFSET)
- #define IXP4XX_GPIO_GPISR IXP4XX_GPIO_REG(IXP4XX_GPIO_GPISR_OFFSET)
- #define IXP4XX_GPIO_GPIT1R IXP4XX_GPIO_REG(IXP4XX_GPIO_GPIT1R_OFFSET)
- #define IXP4XX_GPIO_GPIT2R IXP4XX_GPIO_REG(IXP4XX_GPIO_GPIT2R_OFFSET)
- #define IXP4XX_GPIO_GPCLKR IXP4XX_GPIO_REG(IXP4XX_GPIO_GPCLKR_OFFSET)
- #define IXP4XX_GPIO_GPDBSELR IXP4XX_GPIO_REG(IXP4XX_GPIO_GPDBSELR_OFFSET)
- /* Global Robo registers */
- #define R_ROBOSPI_SPI_DATA 0xf0
- #define R_ROBOSPI_SPI_STATUS 0xfe
- #define R_ROBOSPI_PAGE 0xff
- #define GPIOOUTPUT 1
- #define GPIOINPUT 0
- #define SPI_SCK 1<<2
- #define SPI_SS 1<<3
- #define SPI_MISO 1<<4
- #define SPI_MOSI 1<<5
- #define _DD_MAKEMASK1(n) (1 << (n))
- /* Robo SPI Status registers */
- #define M_SPISTAT_TXRDY _DD_MAKEMASK1(0)
- #define M_SPISTAT_RXRDY _DD_MAKEMASK1(1)
- #define M_SPISTAT_MDIO_START _DD_MAKEMASK1(2)
- #define M_SPISTAT_RACK _DD_MAKEMASK1(5)
- #define M_SPISTAT_WCOL _DD_MAKEMASK1(6)
- #define M_SPISTAT_SPIF _DD_MAKEMASK1(7)
- /* Robo Fast SPI read response */
- #define M_SPISTAT_FAST_RACK _DD_MAKEMASK1(0)
- #define SPI_WRITE8(b) do { uint8_t _d8 = b; sb_spi_write(&_d8,1); } while (0)
- #define POLL_DELAY() udelay(1)
- #define SPIDEV_MAJOR 153
- #define DEVICE_NAME "spidev"
- #define IOCTL_SPI_READ _IOR(SPIDEV_MAJOR, 0, char *)
- #define IOCTL_SPI_WRITE _IOR(SPIDEV_MAJOR, 1, char *)
- static int sb_gpio_init(void);
- static int sb_gpio(int out, unsigned long gpio,int logic);
- static int sb_spi_read(uint8_t * buf, int len);
- static int sb_spi_write(uint8_t *buf, int len);
- static int robo_select_page(int page);
- static int robo_reset(void);
- static int robo_fast_rack_poll();
- static int robo_read_reg(int page, int reg, uint8_t * buffer, int length);
- static int robo_write_reg(int page, int reg, uint8_t * buffer, int length);
- void BCM5324_soft_init(void);