2008-10-31 00:37:50 +01:00
|
|
|
/****************************************************************************
|
2019-08-14 16:43:29 +02:00
|
|
|
* boards/arm/str71x/olimex-strp711/src/str71_spi.c
|
2008-10-31 00:37:50 +01:00
|
|
|
*
|
2021-03-17 18:14:12 +01:00
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed with
|
|
|
|
* this work for additional information regarding copyright ownership. The
|
|
|
|
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
|
|
|
* "License"); you may not use this file except in compliance with the
|
|
|
|
* License. You may obtain a copy of the License at
|
2008-10-31 00:37:50 +01:00
|
|
|
*
|
2021-03-17 18:14:12 +01:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2008-10-31 00:37:50 +01:00
|
|
|
*
|
2021-03-17 18:14:12 +01:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
* License for the specific language governing permissions and limitations
|
|
|
|
* under the License.
|
2008-10-31 00:37:50 +01:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
2009-12-15 21:56:22 +01:00
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdbool.h>
|
2016-01-24 16:15:01 +01:00
|
|
|
#include <assert.h>
|
2015-07-01 22:34:33 +02:00
|
|
|
#include <errno.h>
|
2010-05-04 03:28:47 +02:00
|
|
|
#include <debug.h>
|
2009-12-15 21:56:22 +01:00
|
|
|
|
2016-02-13 19:37:46 +01:00
|
|
|
#include <nuttx/irq.h>
|
2013-07-01 16:11:54 +02:00
|
|
|
#include <nuttx/arch.h>
|
2020-02-01 08:17:32 +01:00
|
|
|
#include <nuttx/semaphore.h>
|
2013-07-01 16:11:54 +02:00
|
|
|
#include <nuttx/spi/spi.h>
|
2008-10-31 00:37:50 +01:00
|
|
|
|
|
|
|
#include <arch/board/board.h>
|
|
|
|
|
2020-05-01 03:20:29 +02:00
|
|
|
#include "arm_internal.h"
|
|
|
|
#include "arm_arch.h"
|
2008-10-31 00:37:50 +01:00
|
|
|
|
|
|
|
#include "chip.h"
|
2015-12-30 01:07:27 +01:00
|
|
|
#include "str71x.h"
|
2008-10-31 00:37:50 +01:00
|
|
|
|
2008-11-02 23:24:58 +01:00
|
|
|
#if defined(CONFIG_STR71X_BSPI0) || defined(CONFIG_STR71X_BSPI1)
|
|
|
|
|
2008-10-31 00:37:50 +01:00
|
|
|
/****************************************************************************
|
2015-03-21 21:42:30 +01:00
|
|
|
* Pre-processor Definitions
|
2008-10-31 00:37:50 +01:00
|
|
|
****************************************************************************/
|
|
|
|
|
2008-11-02 23:24:58 +01:00
|
|
|
/* Configuration ************************************************************/
|
|
|
|
|
|
|
|
#ifndef CONFIG_STR714X_BSPI0_TXFIFO_DEPTH
|
|
|
|
# define CONFIG_STR714X_BSPI0_TXFIFO_DEPTH 8
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef CONFIG_STR714X_BSPI0_RXFIFO_DEPTH
|
|
|
|
# define CONFIG_STR714X_BSPI0_RXFIFO_DEPTH 8
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef CONFIG_STR714X_BSPI1_TXFIFO_DEPTH
|
|
|
|
# define CONFIG_STR714X_BSPI1_TXFIFO_DEPTH 8
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef CONFIG_STR714X_BSPI1_RXFIFO_DEPTH
|
|
|
|
# define CONFIG_STR714X_BSPI1_RXFIFO_DEPTH 8
|
|
|
|
#endif
|
|
|
|
|
2010-05-06 02:08:02 +02:00
|
|
|
#if defined(CONFIG_STR71X_UART3) && defined (CONFIG_STR71X_BSPI0)
|
|
|
|
# warning "BSPI0 GPIO usage conflicts with UART3"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(CONFIG_STR71X_IC21) && defined (CONFIG_STR71X_BSPI0)
|
|
|
|
# warning "BSPI0 GPIO usage conflicts with IC21"
|
|
|
|
#endif
|
|
|
|
|
2008-11-04 17:40:54 +01:00
|
|
|
#if defined(CONFIG_STR71X_HDLC) && defined (CONFIG_STR71X_BSPI1)
|
|
|
|
# warning "BSPI1 GPIO usage conflicts with HDLC"
|
|
|
|
#endif
|
|
|
|
|
2008-11-02 23:24:58 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* On the Olimex-STR-STR-P711, BSPI0 is not connected on board, but is
|
|
|
|
* available on a header for use in the prototyping area. BSPI connects
|
|
|
|
* to the MMC/SD card slot.
|
|
|
|
*
|
|
|
|
* GPIO pin configurations (STR710/STR711,2,5).
|
|
|
|
* BSP0:
|
|
|
|
* PIN NORMAL ALTERNATE Olimex-STR-STR-P711 Connection
|
|
|
|
* 123/52 P0.0 S0.MISO * UEXT-3 (Not connected on board)
|
|
|
|
* 124/53 P0.1 S0.MOSI * UEXT-4 " " " " "" " "
|
2008-11-04 17:40:54 +01:00
|
|
|
* 125/54 P0.2 S0.SCLK ** UEXT-5 " " " " "" " "
|
2008-11-02 23:24:58 +01:00
|
|
|
* 126/55 P0.3 ~SO.SS ** UEXT-6 " " " " "" " "
|
|
|
|
*
|
|
|
|
* * Programming the AF function selects UART3 by default. BSPI must be
|
|
|
|
* enabled with the SPI_EN bit in the BOOTCR register
|
2008-11-04 17:40:54 +01:00
|
|
|
* ** Programming the AF function selects I2C1 by default. BSPI must be
|
2008-11-02 23:24:58 +01:00
|
|
|
* enabled with the SPI_EN bit in the BOOTCR register
|
|
|
|
*
|
|
|
|
* BSP1
|
|
|
|
* PIN NORMAL ALTERNATE Olimex-STR-STR-P711 Connection
|
|
|
|
* 127/56 P0.4 S1.MISO SD_CARDBOT DAT0/D0
|
|
|
|
* 140/60 P0.5 S1.MOSI SD_CARDBOT CMD/DI
|
|
|
|
* 141/61 P0.6 S1.SCLK SD_CARDBOT CLK/SCLK
|
|
|
|
* 142/62 P0.7 ~S1.SS SD_CARDBOT CD/DAT/CS
|
|
|
|
*
|
2008-11-04 17:40:54 +01:00
|
|
|
* Two GPIO pins also connect to the MMC/SD slot:
|
|
|
|
*
|
|
|
|
* PIN NORMAL ALTERNATE Olimex-STR-STR-P711 Connection
|
|
|
|
* 106/46 P1.10 USB clock MMC/SD write protect (WP)
|
|
|
|
* 111/49 P1.15 HDLC xmit MMC/SD card present (CP)
|
|
|
|
*
|
2008-11-02 23:24:58 +01:00
|
|
|
****************************************************************************/
|
|
|
|
|
2010-05-02 19:29:37 +02:00
|
|
|
/* SPI0 *********************************************************************/
|
2008-11-04 17:40:54 +01:00
|
|
|
|
2010-05-02 19:29:37 +02:00
|
|
|
#define BSPI0_GPIO0_MISO (1 << 0)
|
|
|
|
#define BSPI0_GPIO0_MOSI (1 << 1)
|
|
|
|
#define BSPI0_GPIO0_SCLK (1 << 2)
|
|
|
|
#define BSPI0_GPIO0_SS (1 << 3) /* Not used */
|
2008-11-02 23:24:58 +01:00
|
|
|
|
2010-05-02 19:29:37 +02:00
|
|
|
#define BSPI0_GPIO0_ALT (BSPI0_GPIO0_MISO|BSPI0_GPIO0_MOSI|BSPI0_GPIO0_SCLK)
|
|
|
|
|
|
|
|
/* ENC28J60 Module
|
|
|
|
*
|
2019-08-14 16:43:29 +02:00
|
|
|
* The ENC28J60 module does not come on the Olimex-STR-P711, but this
|
|
|
|
* describes how I have connected it.
|
|
|
|
* NOTE that the ENC28J60 requires an external interrupt (XTI) pin.
|
|
|
|
* The only easily accessible XTI pins are on SPI0/1 so you can't have
|
2010-05-06 02:08:02 +02:00
|
|
|
* both SPI0 and 1 together with this configuration.
|
2010-05-02 19:29:37 +02:00
|
|
|
*
|
2014-04-14 00:22:22 +02:00
|
|
|
* STR-P711 PIN PIN CONFIGURATION ENC28J60 CONNECTION
|
2010-05-02 19:29:37 +02:00
|
|
|
* ----------------------- ----------------- -----------------------
|
2014-04-14 00:22:22 +02:00
|
|
|
* P0.3/S0.SS/I1.SDA P0.3 output CON5 1 J8-1 NET CS
|
2010-05-02 19:29:37 +02:00
|
|
|
* P0.2/S0.SCLK/I1.SCL SCLK0 2 2 SCK
|
|
|
|
* P0.0/S0.MOSI/U3.RX MOSI0 3 3 MOSI
|
|
|
|
* P0.1/S0.MISO/U3.TX MISO0 4 4 MISO
|
2014-04-14 00:22:22 +02:00
|
|
|
* GND GND 5 5 GND
|
2010-05-02 19:29:37 +02:00
|
|
|
* 3.3V 3.3V 10 J9-1 3V3
|
|
|
|
* NC NC 9 2 WOL
|
2010-05-06 02:08:02 +02:00
|
|
|
* P0.6/S1.SCLK P0.6 input 8 3 NET INT
|
2010-05-02 19:29:37 +02:00
|
|
|
* NC NC 7 4 CLKOUT
|
2010-05-06 02:08:02 +02:00
|
|
|
* P0.4/S1.MISO P0.4 output 6 5 NET RST
|
2010-05-02 19:29:37 +02:00
|
|
|
*/
|
|
|
|
|
2012-09-11 18:50:16 +02:00
|
|
|
#ifdef CONFIG_ENC28J60
|
2010-05-02 19:29:37 +02:00
|
|
|
|
|
|
|
/* UART3, I2C cannot be used with SPI0. The GPIOs selected for the ENC28J60
|
2010-05-06 02:08:02 +02:00
|
|
|
* interrupt conflict with BSPI1
|
2010-05-02 19:29:37 +02:00
|
|
|
*/
|
|
|
|
|
2010-05-06 02:08:02 +02:00
|
|
|
# ifdef CONFIG_STR71X_BSPI1
|
|
|
|
# warning "CONFIG_STR71X_BSPI1 cannot be used in this configuration"
|
2010-05-02 19:29:37 +02:00
|
|
|
# endif
|
|
|
|
|
|
|
|
/* ENC28J60 additional pins
|
|
|
|
*
|
|
|
|
* NOTE: The ENC28J60 is a 3.3V part; however, it was designed to be
|
|
|
|
* easily integrated into 5V systems. The SPI CS, SCK and SI inputs,
|
|
|
|
* as well as the RESET pin, are all 5V tolerant. On the other hand,
|
|
|
|
* if the host controller is operated at 5V, it quite likely will
|
|
|
|
* not be within specifications when its SPI and interrupt inputs
|
|
|
|
* are driven by the 3.3V CMOS outputs on the ENC28J60. A
|
|
|
|
* unidirectional level translator would be necessary.
|
|
|
|
*/
|
|
|
|
|
|
|
|
# define ENC_GPIO0_CS (1 << 3)
|
2010-05-06 02:08:02 +02:00
|
|
|
# define ENC_GPIO0_NETRST (1 << 4)
|
|
|
|
# define ENC_GPIO0_NETINT (1 << 6)
|
2010-05-02 19:29:37 +02:00
|
|
|
|
2010-05-06 02:08:02 +02:00
|
|
|
# define ENC_GPIO0_INTTL (0)
|
|
|
|
# define ENC_GPIO0_INCMOS ENC_GPIO0_NETINT
|
|
|
|
# define ENC_GPIO0_OUTPP (ENC_GPIO0_CS|ENC_GPIO0_NETRST)
|
|
|
|
# define ENC_GPIO0_ALL (ENC_GPIO0_CS|ENC_GPIO0_NETINT|ENC_GPIO0_NETRST)
|
2010-05-02 19:29:37 +02:00
|
|
|
|
|
|
|
# define BSPI0_GPIO0_INTTL ENC_GPIO0_INTTL
|
|
|
|
# define BSPI0_GPIO0_INCMOS ENC_GPIO0_INCMOS
|
|
|
|
# define BSPI0_GPIO0_OUTPP ENC_GPIO0_OUTPP
|
|
|
|
# define BSPI0_GPIO0_ALL (BSPI0_GPIO0_ALT|ENC_GPIO0_ALL)
|
|
|
|
|
|
|
|
#else
|
2015-07-02 03:18:51 +02:00
|
|
|
# ifdef CONFIG_STR71X_BSPI0
|
|
|
|
# warning "CONFIG_STR71X_BSPI0 has no function in this configuration"
|
|
|
|
# undef CONFIG_STR71X_BSPI0
|
|
|
|
# endif
|
|
|
|
|
2010-05-02 19:29:37 +02:00
|
|
|
# define BSPI0_GPIO0_INTTL (0)
|
|
|
|
# define BSPI0_GPIO0_INCMOS (0)
|
|
|
|
# define BSPI0_GPIO0_OUTPP (0)
|
|
|
|
# define BSPI0_GPIO0_ALL BSPI0_GPIO0_ALT
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* SPI1 *********************************************************************/
|
|
|
|
|
|
|
|
#define BSPI1_GPIO0_MISO (1 << 4)
|
|
|
|
#define BSPI1_GPIO0_MOSI (1 << 5)
|
|
|
|
#define BSPI1_GPIO0_SCLK (1 << 6)
|
|
|
|
#define BSPI1_GPIO0_SS (1 << 7) /* Not used */
|
2008-11-04 17:40:54 +01:00
|
|
|
|
2009-06-08 15:24:26 +02:00
|
|
|
#define BSPI1_GPIO0_ALT (BSPI1_GPIO0_MISO|BSPI1_GPIO0_MOSI|BSPI1_GPIO0_SCLK)
|
2008-11-02 23:24:58 +01:00
|
|
|
|
2010-05-02 19:29:37 +02:00
|
|
|
/* MMC/SD Pin Usage:
|
|
|
|
*
|
|
|
|
* STR-P711 PIN MMC/SD USAGE PIN CONFIGURATION
|
|
|
|
* ------------ ---------------- -----------------------
|
|
|
|
* P0.7/S1.SS 1 CD/DAT3/CS P0.7 output
|
|
|
|
* P0.5/S1.MOSI 2 CMD/DI MOSI1
|
|
|
|
* --- 3 VSS1 ---
|
|
|
|
* --- 4 VDD ---
|
|
|
|
* P0.6/S1.SCLK 5 CLK/SCLK SLCK1
|
|
|
|
* --- 6 VSS2 ---
|
|
|
|
* P0.4/S1.MISO 7 DAT0/D0 MISO1
|
|
|
|
* --- 8 DAT1/RES (Pulled up)
|
|
|
|
* --- 9 DAT2/RES (Pulled up)
|
2014-04-14 00:22:22 +02:00
|
|
|
*
|
2010-05-02 19:29:37 +02:00
|
|
|
* P1.10/USBCLK 10/14 WP P1.10 input
|
|
|
|
* P1.15/HTXD 13/15 CP P1.15 input
|
|
|
|
*
|
2020-04-13 10:08:03 +02:00
|
|
|
* Use of SPI1 doesn't conflict with anything. WP conflicts USB;
|
|
|
|
* CP conflicts with HTXD.
|
2010-05-02 19:29:37 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
/* MMC/SD additional pins */
|
|
|
|
|
|
|
|
#define MMCSD_GPIO0_CS (1 << 7)
|
|
|
|
#define MMCSD_GPIO0_INTTL (0)
|
|
|
|
#define MMCSD_GPIO0_INCMOS (0)
|
|
|
|
#define MMCSD_GPIO0_OUTPP MMCSD_GPIO0_CS
|
|
|
|
#define MMCSD_GPIO0_ALL MMCSD_GPIO0_CS
|
|
|
|
|
|
|
|
#define MMCSD_GPIO1_WPIN (1 << 10)
|
|
|
|
#define MMCSD_GPIO1_CPIN (1 << 15)
|
|
|
|
#define MMCSD_GPIO1_INTTL (MMCSD_GPIO1_WPIN|MMCSD_GPIO1_CPIN)
|
|
|
|
#define MMCSD_GPIO1_INCMOS (0)
|
|
|
|
#define MMCSD_GPIO1_OUTPP (0)
|
|
|
|
#define MMCSD_GPIO1_ALL (MMCSD_GPIO1_WPIN|MMCSD_GPIO1_CPIN)
|
|
|
|
|
|
|
|
#define BSPI1_GPIO0_INTTL MMCSD_GPIO0_INTTL
|
|
|
|
#define BSPI1_GPIO0_INCMOS MMCSD_GPIO0_INCMOS
|
|
|
|
#define BSPI1_GPIO0_OUTPP MMCSD_GPIO0_OUTPP
|
|
|
|
#define BSPI1_GPIO0_ALL (BSPI1_GPIO0_ALT|MMCSD_GPIO0_ALL)
|
|
|
|
|
|
|
|
#define BSPI1_GPIO1_INTTL MMCSD_GPIO1_INTTL
|
|
|
|
#define BSPI1_GPIO1_INCMOS MMCSD_GPIO1_INCMOS
|
|
|
|
#define BSPI1_GPIO1_OUTPP MMCSD_GPIO1_OUTPP
|
|
|
|
#define BSPI1_GPIO1_ALL MMCSD_GPIO1_ALL
|
2008-11-04 17:40:54 +01:00
|
|
|
|
2008-11-02 23:24:58 +01:00
|
|
|
/* Configuration register settings ******************************************/
|
|
|
|
|
|
|
|
#if CONFIG_STR714X_BSPI0_RXFIFO_DEPTH == 1
|
|
|
|
# define STR71X_BSPI0_CSR1RXFIFODEPTH STR71X_BSPICSR1_RFE1
|
|
|
|
#elif CONFIG_STR714X_BSPI0_RXFIFO_DEPTH == 2
|
|
|
|
# define STR71X_BSPI0_CSR1RXFIFODEPTH STR71X_BSPICSR1_RFE12
|
|
|
|
#elif CONFIG_STR714X_BSPI0_RXFIFO_DEPTH == 3
|
|
|
|
# define STR71X_BSPI0_CSR1RXFIFODEPTH STR71X_BSPICSR1_RFE13
|
|
|
|
#elif CONFIG_STR714X_BSPI0_RXFIFO_DEPTH == 4
|
|
|
|
# define STR71X_BSPI0_CSR1RXFIFODEPTH STR71X_BSPICSR1_RFE14
|
|
|
|
#elif CONFIG_STR714X_BSPI0_RXFIFO_DEPTH == 5
|
|
|
|
# define STR71X_BSPI0_CSR1RXFIFODEPTH STR71X_BSPICSR1_RFE15
|
|
|
|
#elif CONFIG_STR714X_BSPI0_RXFIFO_DEPTH == 6
|
|
|
|
# define STR71X_BSPI0_CSR1RXFIFODEPTH STR71X_BSPICSR1_RFE16
|
|
|
|
#elif CONFIG_STR714X_BSPI0_RXFIFO_DEPTH == 7
|
|
|
|
# define STR71X_BSPI0_CSR1RXFIFODEPTH STR71X_BSPICSR1_RFE17
|
|
|
|
#elif CONFIG_STR714X_BSPI0_RXFIFO_DEPTH == 8
|
|
|
|
# define STR71X_BSPI0_CSR1RXFIFODEPTH STR71X_BSPICSR1_RFE18
|
|
|
|
#elif CONFIG_STR714X_BSPI0_RXFIFO_DEPTH == 9
|
|
|
|
# define STR71X_BSPI0_CSR1RXFIFODEPTH STR71X_BSPICSR1_RFE19
|
|
|
|
#elif CONFIG_STR714X_BSPI0_RXFIFO_DEPTH == 10
|
|
|
|
# define STR71X_BSPI0_CSR1RXFIFODEPTH STR71X_BSPICSR1_RFE110
|
|
|
|
#else
|
2020-02-23 09:50:23 +01:00
|
|
|
# error "Invalid RX FIFO depth setting"
|
2008-11-02 23:24:58 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#define STR71X_BSPI0_CSR1DISABLE STR71X_BSPI0_CSR1RXFIFODEPTH
|
|
|
|
#define STR71X_BSPI0_CSR1ENABLE (STR71X_BSPICSR1_BSPE|STR71X_BSPICSR1_MSTR|STR71X_BSPI0_CSR1RXFIFODEPTH)
|
|
|
|
|
|
|
|
#if CONFIG_STR714X_BSPI0_TXFIFO_DEPTH == 1
|
|
|
|
# define STR71X_BSPI0_CSR1TXFIFODEPTH STR71X_BSPICSR2_TFE1
|
|
|
|
#elif CONFIG_STR714X_BSPI0_TXFIFO_DEPTH == 2
|
|
|
|
# define STR71X_BSPI0_CSR1TXFIFODEPTH STR71X_BSPICSR2_TFE12
|
|
|
|
#elif CONFIG_STR714X_BSPI0_TXFIFO_DEPTH == 3
|
|
|
|
# define STR71X_BSPI0_CSR1TXFIFODEPTH STR71X_BSPICSR2_TFE13
|
|
|
|
#elif CONFIG_STR714X_BSPI0_TXFIFO_DEPTH == 4
|
|
|
|
# define STR71X_BSPI0_CSR1TXFIFODEPTH STR71X_BSPICSR2_TFE14
|
|
|
|
#elif CONFIG_STR714X_BSPI0_TXFIFO_DEPTH == 5
|
|
|
|
# define STR71X_BSPI0_CSR1TXFIFODEPTH STR71X_BSPICSR2_TFE15
|
|
|
|
#elif CONFIG_STR714X_BSPI0_TXFIFO_DEPTH == 6
|
|
|
|
# define STR71X_BSPI0_CSR1TXFIFODEPTH STR71X_BSPICSR2_TFE16
|
|
|
|
#elif CONFIG_STR714X_BSPI0_TXFIFO_DEPTH == 7
|
|
|
|
# define STR71X_BSPI0_CSR1TXFIFODEPTH STR71X_BSPICSR2_TFE17
|
|
|
|
#elif CONFIG_STR714X_BSPI0_TXFIFO_DEPTH == 8
|
|
|
|
# define STR71X_BSPI0_CSR1TXFIFODEPTH STR71X_BSPICSR2_TFE18
|
|
|
|
#elif CONFIG_STR714X_BSPI0_TXFIFO_DEPTH == 9
|
|
|
|
# define STR71X_BSPI0_CSR1TXFIFODEPTH STR71X_BSPICSR2_TFE19
|
|
|
|
#elif CONFIG_STR714X_BSPI0_TXFIFO_DEPTH == 10
|
|
|
|
# define STR71X_BSPI0_CSR1TXFIFODEPTH STR71X_BSPICSR2_TFE110
|
|
|
|
#else
|
2020-02-23 09:50:23 +01:00
|
|
|
# error "Invalid TX FIFO depth setting"
|
2008-11-02 23:24:58 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#define STR71X_BSPI0_CSR2VALUE STR71X_BSPI0_CSR1TXFIFODEPTH
|
|
|
|
|
|
|
|
#if CONFIG_STR714X_BSPI1_RXFIFO_DEPTH == 1
|
|
|
|
# define STR71X_BSPI1_CSR1RXFIFODEPTH STR71X_BSPICSR1_RFE1
|
|
|
|
#elif CONFIG_STR714X_BSPI1_RXFIFO_DEPTH == 2
|
|
|
|
# define STR71X_BSPI1_CSR1RXFIFODEPTH STR71X_BSPICSR1_RFE12
|
|
|
|
#elif CONFIG_STR714X_BSPI1_RXFIFO_DEPTH == 3
|
|
|
|
# define STR71X_BSPI1_CSR1RXFIFODEPTH STR71X_BSPICSR1_RFE13
|
|
|
|
#elif CONFIG_STR714X_BSPI1_RXFIFO_DEPTH == 4
|
|
|
|
# define STR71X_BSPI1_CSR1RXFIFODEPTH STR71X_BSPICSR1_RFE14
|
|
|
|
#elif CONFIG_STR714X_BSPI1_RXFIFO_DEPTH == 5
|
|
|
|
# define STR71X_BSPI1_CSR1RXFIFODEPTH STR71X_BSPICSR1_RFE15
|
|
|
|
#elif CONFIG_STR714X_BSPI1_RXFIFO_DEPTH == 6
|
|
|
|
# define STR71X_BSPI1_CSR1RXFIFODEPTH STR71X_BSPICSR1_RFE16
|
|
|
|
#elif CONFIG_STR714X_BSPI1_RXFIFO_DEPTH == 7
|
|
|
|
# define STR71X_BSPI1_CSR1RXFIFODEPTH STR71X_BSPICSR1_RFE17
|
|
|
|
#elif CONFIG_STR714X_BSPI1_RXFIFO_DEPTH == 8
|
|
|
|
# define STR71X_BSPI1_CSR1RXFIFODEPTH STR71X_BSPICSR1_RFE18
|
|
|
|
#elif CONFIG_STR714X_BSPI1_RXFIFO_DEPTH == 9
|
|
|
|
# define STR71X_BSPI1_CSR1RXFIFODEPTH STR71X_BSPICSR1_RFE19
|
|
|
|
#elif CONFIG_STR714X_BSPI1_RXFIFO_DEPTH == 10
|
|
|
|
# define STR71X_BSPI1_CSR1RXFIFODEPTH STR71X_BSPICSR1_RFE110
|
|
|
|
#else
|
2020-02-23 09:50:23 +01:00
|
|
|
# error "Invalid RX FIFO depth setting"
|
2008-11-02 23:24:58 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#define STR71X_BSPI1_CSR1DISABLE STR71X_BSPI1_CSR1RXFIFODEPTH
|
|
|
|
#define STR71X_BSPI1_CSR1ENABLE (STR71X_BSPICSR1_BSPE|STR71X_BSPICSR1_MSTR|STR71X_BSPI1_CSR1RXFIFODEPTH)
|
|
|
|
|
|
|
|
#if CONFIG_STR714X_BSPI1_TXFIFO_DEPTH == 1
|
|
|
|
# define STR71X_BSPI1_CSR1TXFIFODEPTH STR71X_BSPICSR2_TFE1
|
|
|
|
#elif CONFIG_STR714X_BSPI1_TXFIFO_DEPTH == 2
|
|
|
|
# define STR71X_BSPI1_CSR1TXFIFODEPTH STR71X_BSPICSR2_TFE12
|
|
|
|
#elif CONFIG_STR714X_BSPI1_TXFIFO_DEPTH == 3
|
|
|
|
# define STR71X_BSPI1_CSR1TXFIFODEPTH STR71X_BSPICSR2_TFE13
|
|
|
|
#elif CONFIG_STR714X_BSPI1_TXFIFO_DEPTH == 4
|
|
|
|
# define STR71X_BSPI1_CSR1TXFIFODEPTH STR71X_BSPICSR2_TFE14
|
|
|
|
#elif CONFIG_STR714X_BSPI1_TXFIFO_DEPTH == 5
|
|
|
|
# define STR71X_BSPI1_CSR1TXFIFODEPTH STR71X_BSPICSR2_TFE15
|
|
|
|
#elif CONFIG_STR714X_BSPI1_TXFIFO_DEPTH == 6
|
|
|
|
# define STR71X_BSPI1_CSR1TXFIFODEPTH STR71X_BSPICSR2_TFE16
|
|
|
|
#elif CONFIG_STR714X_BSPI1_TXFIFO_DEPTH == 7
|
|
|
|
# define STR71X_BSPI1_CSR1TXFIFODEPTH STR71X_BSPICSR2_TFE17
|
|
|
|
#elif CONFIG_STR714X_BSPI1_TXFIFO_DEPTH == 8
|
|
|
|
# define STR71X_BSPI1_CSR1TXFIFODEPTH STR71X_BSPICSR2_TFE18
|
|
|
|
#elif CONFIG_STR714X_BSPI1_TXFIFO_DEPTH == 9
|
|
|
|
# define STR71X_BSPI1_CSR1TXFIFODEPTH STR71X_BSPICSR2_TFE19
|
|
|
|
#elif CONFIG_STR714X_BSPI1_TXFIFO_DEPTH == 10
|
|
|
|
# define STR71X_BSPI1_CSR1TXFIFODEPTH STR71X_BSPICSR2_TFE110
|
|
|
|
#else
|
2020-02-23 09:50:23 +01:00
|
|
|
# error "Invalid TX FIFO depth setting"
|
2008-11-02 23:24:58 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#define STR71X_BSPI1_CSR2VALUE STR71X_BSPI1_CSR1TXFIFODEPTH
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Types
|
|
|
|
****************************************************************************/
|
|
|
|
|
2010-05-02 19:29:37 +02:00
|
|
|
/* NOTE: As implemented here, this driver will support only one device per
|
|
|
|
* SPI bus: Only one chip select, csbit, per bus; no locking, not mode or
|
|
|
|
* bits-per-word settings. To support multiple devices per but, spi_select
|
|
|
|
* would also require some logic changes.
|
|
|
|
*/
|
|
|
|
|
2008-11-02 23:24:58 +01:00
|
|
|
struct str71x_spidev_s
|
|
|
|
{
|
2010-05-02 19:29:37 +02:00
|
|
|
struct spi_dev_s spidev; /* Externally visible part of the SPI interface */
|
|
|
|
bool initialized; /* Initialize port only once! */
|
|
|
|
uint32_t spibase; /* BSPIn base address */
|
|
|
|
uint16_t csbit; /* BSPIn SS bit int GPIO0 */
|
2016-01-24 16:15:01 +01:00
|
|
|
sem_t exclsem; /* Supports mutually exclusive access */
|
2008-11-02 23:24:58 +01:00
|
|
|
};
|
|
|
|
|
2008-10-31 00:37:50 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Private Function Prototypes
|
|
|
|
****************************************************************************/
|
|
|
|
|
2008-11-02 23:24:58 +01:00
|
|
|
/* Helpers */
|
|
|
|
|
2019-08-14 16:43:29 +02:00
|
|
|
static inline uint16_t spi_getreg(FAR struct str71x_spidev_s *priv,
|
|
|
|
uint8_t offset);
|
|
|
|
static inline void spi_putreg(FAR struct str71x_spidev_s *priv,
|
|
|
|
uint8_t offset, uint16_t value);
|
2010-05-02 19:29:37 +02:00
|
|
|
static inline void spi_drain(FAR struct str71x_spidev_s *priv);
|
2008-11-02 23:24:58 +01:00
|
|
|
|
|
|
|
/* SPI methods */
|
|
|
|
|
2010-05-15 03:15:52 +02:00
|
|
|
static int spi_lock(FAR struct spi_dev_s *dev, bool lock);
|
2019-08-14 16:43:29 +02:00
|
|
|
static void spi_select(FAR struct spi_dev_s *dev, uint32_t devid,
|
|
|
|
bool selected);
|
|
|
|
static uint32_t spi_setfrequency(FAR struct spi_dev_s *dev,
|
|
|
|
uint32_t frequency);
|
2017-04-28 18:31:44 +02:00
|
|
|
static uint8_t spi_status(FAR struct spi_dev_s *dev, uint32_t devid);
|
2010-12-03 02:37:56 +01:00
|
|
|
#ifdef CONFIG_SPI_CMDDATA
|
2019-08-14 16:43:29 +02:00
|
|
|
static int spi_cmddata(FAR struct spi_dev_s *dev, uint32_t devid,
|
|
|
|
bool cmd);
|
2010-12-03 02:37:56 +01:00
|
|
|
#endif
|
nuttx: Fix the nightly build warning
lpc2148_spi1.c:142:24: warning: initialization of 'uint32_t (*)(struct spi_dev_s *, uint32_t)' {aka 'unsigned int (*)(struct spi_dev_s *, unsigned int)'} from incompatible pointer type 'uint16_t (*)(struct spi_dev_s *, uint16_t)' {aka 'short unsigned int (*)(struct spi_dev_s *, short unsigned int)'} [-Wincompatible-pointer-types]
142 | .send = spi_send,
| ^~~~~~~~
lpc2148_spi1.c:142:24: note: (near initialization for 'g_spiops.send')
In file included from ieee802154/mac802154_bind.c:49:
ieee802154/mac802154_internal.h: In function 'mac802154_setdevmode':
ieee802154/mac802154_internal.h:788:42: warning: converting a packed 'enum ieee802154_devmode_e' pointer (alignment 1) to a 'const union ieee802154_attr_u' pointer (alignment 4) may result in an unaligned pointer value [-Waddress-of-packed-member]
788 | (FAR const union ieee802154_attr_u *)&mode);
| ^~~~~~~~~~~~~~~~~
chip/stm32_hciuart.c: In function 'hciuart_read':
chip/stm32_hciuart.c:2104:30: warning: statement with no effect [-Wunused-value]
2104 | ntotal == (ssize_t)ret;
| ~~~~~~~^~~~~~~~~~~~~~~
wireless/ieee80211/bcm43xxx/bcmf_driver.c: In function 'bcmf_wl_auth_event_handler':
wireless/ieee80211/bcm43xxx/bcmf_driver.c:579:23: warning: taking address of packed member of 'struct bcmf_event_s' may result in an unaligned pointer value [-Waddress-of-packed-member]
579 | type = bcmf_getle32(&event->type);
| ^~~~~~~~~~~~
wireless/ieee80211/bcm43xxx/bcmf_driver.c:580:25: warning: taking address of packed member of 'struct bcmf_event_s' may result in an unaligned pointer value [-Waddress-of-packed-member]
580 | status = bcmf_getle32(&event->status);
| ^~~~~~~~~~~~~~
wireless/ieee80211/bcm43xxx/bcmf_driver.c: In function 'bcmf_wl_scan_event_handler':
wireless/ieee80211/bcm43xxx/bcmf_driver.c:619:25: warning: taking address of packed member of 'struct bcmf_event_s' may result in an unaligned pointer value [-Waddress-of-packed-member]
619 | status = bcmf_getle32(&event->status);
| ^~~~~~~~~~~~~~
wireless/ieee80211/bcm43xxx/bcmf_driver.c:620:35: warning: taking address of packed member of 'struct bcmf_event_s' may result in an unaligned pointer value [-Waddress-of-packed-member]
620 | escan_result_len = bcmf_getle32(&event->len);
| ^~~~~~~~~~~
wireless/ieee80211/bcm43xxx/bcmf_bdc.c: In function 'bcmf_bdc_process_event_frame':
wireless/ieee80211/bcm43xxx/bcmf_bdc.c:166:27: warning: taking address of packed member of 'struct bcmf_event_s' may result in an unaligned pointer value [-Waddress-of-packed-member]
166 | event_id = bcmf_getle32(&event_msg->event.type);
| ^~~~~~~~~~~~~~~~~~~~~~
wireless/ieee80211/bcm43xxx/mmc_sdio.c: In function 'sdio_io_rw_direct':
wireless/ieee80211/bcm43xxx/mmc_sdio.c:157:3: warning: converting a packed 'struct sdio_resp_R5' pointer (alignment 1) to a 'uint32_t' {aka 'unsigned int'} pointer (alignment 4) may result in an unaligned pointer value [-Waddress-of-packed-member]
157 | ret = SDIO_RECVR5(dev, SD_ACMD52, (uint32_t *)&resp);
| ^~~
wireless/ieee80211/bcm43xxx/mmc_sdio.c:79:28: note: defined here
79 | begin_packed_struct struct sdio_resp_R5
| ^~~~~~~~~~~~
wireless/ieee80211/bcm43xxx/mmc_sdio.c: In function 'sdio_io_rw_extended':
wireless/ieee80211/bcm43xxx/mmc_sdio.c:239:11: warning: converting a packed 'struct sdio_resp_R5' pointer (alignment 1) to a 'uint32_t' {aka 'unsigned int'} pointer (alignment 4) may result in an unaligned pointer value [-Waddress-of-packed-member]
239 | ret = SDIO_RECVR5(dev, SD_ACMD53, (uint32_t *)&resp);
| ^~~
wireless/ieee80211/bcm43xxx/mmc_sdio.c:79:28: note: defined here
79 | begin_packed_struct struct sdio_resp_R5
| ^~~~~~~~~~~~
wireless/ieee80211/bcm43xxx/mmc_sdio.c:244:11: warning: converting a packed 'struct sdio_resp_R5' pointer (alignment 1) to a 'uint32_t' {aka 'unsigned int'} pointer (alignment 4) may result in an unaligned pointer value [-Waddress-of-packed-member]
244 | ret = SDIO_RECVR5(dev, SD_ACMD53, (uint32_t *)&resp);
| ^~~
wireless/ieee80211/bcm43xxx/mmc_sdio.c:79:28: note: defined here
79 | begin_packed_struct struct sdio_resp_R5
| ^~~~~~~~~~~~
wireless/ieee80211/bcm43xxx/mmc_sdio.c:257:7: warning: converting a packed 'struct sdio_resp_R5' pointer (alignment 1) to a 'uint32_t' {aka 'unsigned int'} pointer (alignment 4) may result in an unaligned pointer value [-Waddress-of-packed-member]
257 | ret = SDIO_RECVR5(dev, SD_ACMD53, (uint32_t *)&resp);
| ^~~
wireless/ieee80211/bcm43xxx/mmc_sdio.c:79:28: note: defined here
79 | begin_packed_struct struct sdio_resp_R5
| ^~~~~~~~~~~~
wireless/ieee80211/bcm43xxx/mmc_sdio.c:265:3: warning: converting a packed 'struct sdio_resp_R5' pointer (alignment 1) to a 'uint32_t' {aka 'unsigned int'} pointer (alignment 4) may result in an unaligned pointer value [-Waddress-of-packed-member]
265 | SDIO_RECVR1(dev, SD_ACMD52ABRT, (uint32_t *)&resp);
| ^~~~~~~~~~~
wireless/ieee80211/bcm43xxx/mmc_sdio.c:79:28: note: defined here
79 | begin_packed_struct struct sdio_resp_R5
| ^~~~~~~~~~~~
chip/stm32_adc.c: In function 'adc_reset':
chip/stm32_adc.c:2860:7: warning: unused variable 'ret' [-Wunused-variable]
2860 | int ret;
| ^~~
chip/stm32_adc.c: In function 'adc_shutdown':
chip/stm32_adc.c:3044:7: warning: unused variable 'ret' [-Wunused-variable]
3044 | int ret;
| ^~~
chip/stm32_i2c.c:722:12: warning: 'stm32_i2c_sem_wait_noncancelable' defined but not used [-Wunused-function]
722 | static int stm32_i2c_sem_wait_noncancelable(FAR struct i2c_master_s *dev)
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
wireless/gs2200m.c: In function 'gs2200m_read':
wireless/gs2200m.c:727:20: warning: passing argument 1 of 'nxsem_wait' from incompatible pointer type [-Wincompatible-pointer-types]
727 | ret = nxsem_wait(dev);
| ^~~
| |
| struct gs2200m_dev_s *
.config:1207:warning: symbol value '' invalid for TESTING_OSTEST_FPUSIZE
platform/audio/cxd56_audio_analog.c:69:13: warning: inline function 'cxd56_audio_clock_is_enabled' declared but never defined
69 | inline bool cxd56_audio_clock_is_enabled(void);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
platform/audio/cxd56_audio_analog.c:68:13: warning: inline function 'cxd56_audio_clock_disable' declared but never defined
68 | inline void cxd56_audio_clock_disable(void);
| ^~~~~~~~~~~~~~~~~~~~~~~~~
platform/audio/cxd56_audio_analog.c:67:13: warning: inline function 'cxd56_audio_clock_enable' declared but never defined
67 | inline void cxd56_audio_clock_enable(uint32_t clk, uint32_t div);
| ^~~~~~~~~~~~~~~~~~~~~~~~
chip/stm32_adc.c: In function 'adc_reset':
chip/stm32_adc.c:1348:7: warning: unused variable 'ret' [-Wunused-variable]
1348 | int ret;
| ^~~
chip/stm32_adc.c: In function 'adc_shutdown':
chip/stm32_adc.c:1496:7: warning: unused variable 'ret' [-Wunused-variable]
1496 | int ret;
| ^~~
chip/stm32_i2c.c:729:12: warning: 'stm32_i2c_sem_wait_uninterruptble' defined but not used [-Wunused-function]
729 | static int stm32_i2c_sem_wait_uninterruptble(FAR struct i2c_master_s *dev)
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
wireless/lpwan/sx127x/sx127x.c:147:52: warning: missing terminating ' character
147 | # warning OOK support is not complete, RX+TX doesn't work yet!
| ^
str71_spi.c:435:24: warning: initialization of 'uint32_t (*)(struct spi_dev_s *, uint32_t)' {aka 'unsigned int (*)(struct spi_dev_s *, unsigned int)'} from incompatible pointer type
'uint16_t (*)(struct spi_dev_s *, uint16_t)' {aka 'short unsigned int (*)(struct spi_dev_s *, short unsigned int)'} [-Wincompatible-pointer-types]
435 | .send = spi_send,
| ^~~~~~~~
str71_spi.c:435:24: note: (near initialization for 'g_spiops.send')
chip/pic32mx-lowconsole.c:147:24: warning: 'pic32mx_getreg' defined but not used [-Wunused-function]
static inline uint32_t pic32mx_getreg(uintptr_t uart_base,
^
chip/pic32mx-gpio.c:113:20: warning: 'pic32mx_value' defined but not used [-Wunused-function]
static inline bool pic32mx_value(uint16_t pinset)
^
chip/pic32mz-gpio.c:124:20: warning: 'pic32mz_value' defined but not used [-Wunused-function]
static inline bool pic32mz_value(pinset_t pinset)
^
chip/pic32mx-usbdev.c:3065:1: warning: 'pic32mx_epreserved' defined but not used [-Wunused-function]
pic32mx_epreserved(struct pic32mx_usbdev_s *priv, int epno)
^
mmcsd/mmcsd_spi.c: In function 'mmcsd_mediachanged':
mmcsd/mmcsd_spi.c:1938:7: warning: 'return' with a value, in function returning void
return ret;
^
In file included from partition/fs_partition.c:42:0:
partition/partition.h:66:19: warning: 'read_partition_block' defined but not used [-Wunused-function]
static inline int read_partition_block(FAR struct partition_state_s *state,
^
local/local_netpoll.c: In function 'local_pollsetup':
local/local_netpoll.c:305:1: warning: label 'pollerr' defined but not used [-Wunused-label]
pollerr:
^~~~~~~
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
Change-Id: If3ea8f32b878aa218072130f7c3018f0d3c1aca5
2020-04-12 15:52:28 +02:00
|
|
|
static uint32_t spi_send(FAR struct spi_dev_s *dev, uint32_t wd);
|
2019-08-14 16:43:29 +02:00
|
|
|
static void spi_sndblock(FAR struct spi_dev_s *dev,
|
|
|
|
FAR const void *buffer, size_t buflen);
|
|
|
|
static void spi_recvblock(FAR struct spi_dev_s *dev,
|
|
|
|
FAR void *buffer, size_t buflen);
|
2008-10-31 00:37:50 +01:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Data
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static const struct spi_ops_s g_spiops =
|
|
|
|
{
|
2010-05-15 03:15:52 +02:00
|
|
|
.lock = spi_lock,
|
2008-10-31 00:37:50 +01:00
|
|
|
.select = spi_select,
|
|
|
|
.setfrequency = spi_setfrequency,
|
|
|
|
.status = spi_status,
|
2010-12-03 02:37:56 +01:00
|
|
|
#ifdef CONFIG_SPI_CMDDATA
|
|
|
|
.cmddata = spi_cmddata,
|
|
|
|
#endif
|
2009-04-26 18:06:29 +02:00
|
|
|
.send = spi_send,
|
2008-10-31 00:37:50 +01:00
|
|
|
.sndblock = spi_sndblock,
|
|
|
|
.recvblock = spi_recvblock,
|
2009-10-20 16:05:56 +02:00
|
|
|
.registercallback = 0, /* Not implemented */
|
2008-10-31 00:37:50 +01:00
|
|
|
};
|
|
|
|
|
2008-11-02 23:24:58 +01:00
|
|
|
#ifdef CONFIG_STR71X_BSPI0
|
2008-11-03 00:32:26 +01:00
|
|
|
static struct str71x_spidev_s g_spidev0 =
|
2008-11-02 23:24:58 +01:00
|
|
|
{
|
2020-04-13 10:08:03 +02:00
|
|
|
.spidev =
|
|
|
|
{
|
|
|
|
&g_spiops
|
|
|
|
},
|
2008-11-02 23:24:58 +01:00
|
|
|
.spibase = STR71X_BSPI0_BASE,
|
2016-01-24 16:15:01 +01:00
|
|
|
.csbit = ENC_GPIO0_CS,
|
|
|
|
.exclsem = SEM_INITIALIZER(1)
|
2008-11-02 23:24:58 +01:00
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
2015-07-02 03:18:51 +02:00
|
|
|
#ifdef CONFIG_STR71X_BSPI1
|
2008-11-03 00:32:26 +01:00
|
|
|
static struct str71x_spidev_s g_spidev1 =
|
2008-11-02 23:24:58 +01:00
|
|
|
{
|
2020-04-13 10:08:03 +02:00
|
|
|
.spidev =
|
|
|
|
{
|
|
|
|
&g_spiops
|
|
|
|
},
|
2008-11-02 23:24:58 +01:00
|
|
|
.spibase = STR71X_BSPI1_BASE,
|
2016-01-24 16:15:01 +01:00
|
|
|
.csbit = MMCSD_GPIO0_CS,
|
|
|
|
.exclsem = SEM_INITIALIZER(1)
|
2008-11-02 23:24:58 +01:00
|
|
|
};
|
|
|
|
#endif
|
2008-10-31 00:37:50 +01:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Data
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
2008-11-02 23:24:58 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: spi_getreg
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Get the contents of the SPI register at offset
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* priv - private SPI device structure
|
|
|
|
* offset - offset to the register of interest
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* The contents of the 16-bit register
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2019-08-14 16:43:29 +02:00
|
|
|
static inline uint16_t spi_getreg(FAR struct str71x_spidev_s *priv,
|
|
|
|
uint8_t offset)
|
2008-11-02 23:24:58 +01:00
|
|
|
{
|
|
|
|
return getreg16(priv->spibase + offset);
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: spi_putreg
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Write a 16-bit value to the SPI register at offset
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* priv - private SPI device structure
|
|
|
|
* offset - offset to the register of interest
|
|
|
|
* value - the 16-bit value to be written
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* The contents of the 16-bit register
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2019-08-14 16:43:29 +02:00
|
|
|
static inline void spi_putreg(FAR struct str71x_spidev_s *priv,
|
|
|
|
uint8_t offset, uint16_t value)
|
2008-11-02 23:24:58 +01:00
|
|
|
{
|
2008-11-03 00:32:26 +01:00
|
|
|
putreg16(value, priv->spibase + offset);
|
2008-11-02 23:24:58 +01:00
|
|
|
}
|
|
|
|
|
2010-05-02 19:29:37 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: spi_drain
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Drain any bytes left in the fifos.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* dev - Device-specific state data
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static inline void spi_drain(FAR struct str71x_spidev_s *priv)
|
|
|
|
{
|
|
|
|
#if CONFIG_STR714X_BSPI0_TXFIFO_DEPTH > 1
|
|
|
|
/* Wait while the TX FIFO is full */
|
|
|
|
|
2020-04-13 10:08:03 +02:00
|
|
|
while (spi_getreg(priv, STR71X_BSPI_CSR2_OFFSET) & STR71X_BSPICSR2_TFF)
|
|
|
|
{
|
|
|
|
}
|
2010-05-02 19:29:37 +02:00
|
|
|
#else
|
|
|
|
/* Wait until the TX FIFO is empty */
|
|
|
|
|
2020-04-13 10:08:03 +02:00
|
|
|
while (!(spi_getreg(priv, STR71X_BSPI_CSR2_OFFSET) & STR71X_BSPICSR2_TFE))
|
|
|
|
{
|
|
|
|
}
|
2010-05-02 19:29:37 +02:00
|
|
|
#endif
|
2020-04-13 10:08:03 +02:00
|
|
|
|
2010-05-02 19:29:37 +02:00
|
|
|
/* Write 0xff to the TX FIFO */
|
|
|
|
|
|
|
|
spi_putreg(priv, STR71X_BSPI_TXR_OFFSET, 0xff00);
|
|
|
|
|
|
|
|
/* Wait for the TX FIFO empty */
|
|
|
|
|
2020-04-13 10:08:03 +02:00
|
|
|
while (spi_getreg(priv, STR71X_BSPI_CSR2_OFFSET) & STR71X_BSPICSR2_TFNE)
|
|
|
|
{
|
|
|
|
}
|
2010-05-02 19:29:37 +02:00
|
|
|
|
|
|
|
/* Wait for the RX FIFO not empty */
|
|
|
|
|
2020-04-13 10:08:03 +02:00
|
|
|
while (!(spi_getreg(priv, STR71X_BSPI_CSR2_OFFSET) & STR71X_BSPICSR2_RFNE))
|
|
|
|
{
|
|
|
|
}
|
2010-05-02 19:29:37 +02:00
|
|
|
|
|
|
|
/* Then read and discard bytes until the RX FIFO is empty */
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
2020-01-02 17:49:34 +01:00
|
|
|
spi_getreg(priv, STR71X_BSPI_RXR_OFFSET);
|
2010-05-02 19:29:37 +02:00
|
|
|
}
|
2020-04-13 10:08:03 +02:00
|
|
|
while (spi_getreg(priv, STR71X_BSPI_CSR2_OFFSET) & STR71X_BSPICSR2_RFNE);
|
2010-05-02 19:29:37 +02:00
|
|
|
}
|
|
|
|
|
2010-05-15 03:15:52 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: spi_lock
|
|
|
|
*
|
|
|
|
* Description:
|
2020-02-23 09:50:23 +01:00
|
|
|
* On SPI buses where there are multiple devices, it will be necessary to
|
|
|
|
* lock SPI to have exclusive access to the buses for a sequence of
|
2010-05-15 03:15:52 +02:00
|
|
|
* transfers. The bus should be locked before the chip is selected. After
|
|
|
|
* locking the SPI bus, the caller should then also call the setfrequency,
|
|
|
|
* setbits, and setmode methods to make sure that the SPI is properly
|
2020-02-23 09:50:23 +01:00
|
|
|
* configured for the device. If the SPI bus is being shared, then it
|
2010-05-15 03:15:52 +02:00
|
|
|
* may have been left in an incompatible state.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* dev - Device-specific state data
|
|
|
|
* lock - true: Lock spi bus, false: unlock SPI bus
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static int spi_lock(FAR struct spi_dev_s *dev, bool lock)
|
|
|
|
{
|
2016-01-24 16:15:01 +01:00
|
|
|
FAR struct str71x_spidev_s *priv = (FAR struct str71x_spidev_s *)dev;
|
2017-10-04 23:22:27 +02:00
|
|
|
int ret;
|
2010-05-15 03:15:52 +02:00
|
|
|
|
2016-01-24 16:15:01 +01:00
|
|
|
if (lock)
|
|
|
|
{
|
2020-01-02 17:49:34 +01:00
|
|
|
ret = nxsem_wait_uninterruptible(&priv->exclsem);
|
2016-01-24 16:15:01 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-01-02 17:49:34 +01:00
|
|
|
ret = nxsem_post(&priv->exclsem);
|
2016-01-24 16:15:01 +01:00
|
|
|
}
|
|
|
|
|
2017-10-04 23:22:27 +02:00
|
|
|
return ret;
|
2010-05-15 03:15:52 +02:00
|
|
|
}
|
|
|
|
|
2008-10-31 00:37:50 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: spi_select
|
|
|
|
*
|
|
|
|
* Description:
|
2009-03-29 20:02:35 +02:00
|
|
|
* Enable/disable the SPI slave select. The implementation of this method
|
|
|
|
* must include handshaking: If a device is selected, it must hold off
|
|
|
|
* all other attempts to select the device until the device is deselected.
|
2008-10-31 00:37:50 +01:00
|
|
|
*
|
|
|
|
* Input Parameters:
|
2009-03-29 20:02:35 +02:00
|
|
|
* dev - Device-specific state data
|
|
|
|
* devid - Identifies the device to select
|
2009-12-15 21:56:22 +01:00
|
|
|
* selected - true: slave selected, false: slave de-selected
|
2008-10-31 00:37:50 +01:00
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2019-08-14 16:43:29 +02:00
|
|
|
static void spi_select(FAR struct spi_dev_s *dev, uint32_t devid,
|
|
|
|
bool selected)
|
2008-10-31 00:37:50 +01:00
|
|
|
{
|
2008-11-02 23:24:58 +01:00
|
|
|
FAR struct str71x_spidev_s *priv = (FAR struct str71x_spidev_s *)dev;
|
2009-12-15 21:56:22 +01:00
|
|
|
uint16_t reg16;
|
2008-11-02 23:24:58 +01:00
|
|
|
|
|
|
|
DEBUGASSERT(priv && priv->spibase);
|
|
|
|
|
2008-11-03 00:32:26 +01:00
|
|
|
reg16 = spi_getreg(priv, STR71X_GPIO_PD_OFFSET);
|
2008-11-02 23:24:58 +01:00
|
|
|
if (selected)
|
|
|
|
{
|
2010-05-04 03:28:47 +02:00
|
|
|
/* Enable slave select (low enables) */
|
2008-11-02 23:24:58 +01:00
|
|
|
|
2008-11-03 00:32:26 +01:00
|
|
|
reg16 &= ~priv->csbit;
|
|
|
|
spi_putreg(priv, STR71X_GPIO_PD_OFFSET, reg16);
|
2008-11-02 23:24:58 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Disable slave select (low enables) */
|
|
|
|
|
2010-05-04 03:28:47 +02:00
|
|
|
reg16 |= priv->csbit;
|
|
|
|
spi_putreg(priv, STR71X_GPIO_PD_OFFSET, reg16);
|
2008-11-02 23:24:58 +01:00
|
|
|
|
2010-05-04 03:28:47 +02:00
|
|
|
/* And drain the FIFOs */
|
2008-11-02 23:24:58 +01:00
|
|
|
|
2010-05-04 03:28:47 +02:00
|
|
|
spi_drain(priv);
|
2008-11-02 23:24:58 +01:00
|
|
|
}
|
2008-10-31 00:37:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: spi_setfrequency
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Set the SPI frequency.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
2009-03-29 20:53:20 +02:00
|
|
|
* dev - Device-specific state data
|
|
|
|
* frequency - The SPI frequency requested
|
2008-10-31 00:37:50 +01:00
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* Returns the actual frequency selected
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2019-08-14 16:43:29 +02:00
|
|
|
static uint32_t spi_setfrequency(FAR struct spi_dev_s *dev,
|
|
|
|
uint32_t frequency)
|
2008-10-31 00:37:50 +01:00
|
|
|
{
|
2008-11-02 23:24:58 +01:00
|
|
|
FAR struct str71x_spidev_s *priv = (FAR struct str71x_spidev_s *)dev;
|
2009-12-15 21:56:22 +01:00
|
|
|
uint32_t divisor;
|
|
|
|
uint32_t cr1;
|
2008-11-02 23:24:58 +01:00
|
|
|
|
|
|
|
DEBUGASSERT(priv && priv->spibase);
|
|
|
|
|
|
|
|
/* The BSPI clock is determined by divider the APB1 clock (PCLK1).
|
|
|
|
*
|
|
|
|
* Eg. PCLK1 = 32MHz, frequency = 20000000:
|
|
|
|
* correct divisor is 2.1, calculated value is 2.
|
|
|
|
*/
|
|
|
|
|
2008-11-03 00:32:26 +01:00
|
|
|
divisor = (STR71X_PCLK1 + (frequency >> 1)) / frequency;
|
2008-11-02 23:24:58 +01:00
|
|
|
|
2020-02-23 09:50:23 +01:00
|
|
|
/* The divisor must be an even number and constrained to the range of
|
2008-11-02 23:24:58 +01:00
|
|
|
* 5 (master mode, or 7 for slave mode) and 255. These bits must
|
|
|
|
* be configured BEFORE the BSPE or MSTR bits.. i.e., before the SPI
|
|
|
|
* is put into master mode.
|
|
|
|
*/
|
|
|
|
|
|
|
|
divisor <<= 1; /* The full, even divisor */
|
|
|
|
if (divisor < 6)
|
|
|
|
{
|
|
|
|
divisor = 6;
|
|
|
|
}
|
|
|
|
else if (divisor > 254)
|
|
|
|
{
|
|
|
|
divisor = 254;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* The BSPI must be disable when the following setting is made. */
|
|
|
|
|
|
|
|
cr1 = spi_getreg(priv, STR71X_BSPI_CSR1_OFFSET);
|
2019-08-14 16:43:29 +02:00
|
|
|
cr1 &= ~(STR71X_BSPICSR1_BSPE | STR71X_BSPICSR1_MSTR);
|
2008-11-02 23:24:58 +01:00
|
|
|
spi_putreg(priv, STR71X_BSPI_CSR1_OFFSET, cr1);
|
2009-12-15 21:56:22 +01:00
|
|
|
spi_putreg(priv, STR71X_BSPI_CLK_OFFSET, (uint16_t)divisor);
|
2008-11-02 23:24:58 +01:00
|
|
|
|
|
|
|
/* Now we can enable the BSP in master mode */
|
|
|
|
|
2019-08-14 16:43:29 +02:00
|
|
|
cr1 |= (STR71X_BSPICSR1_BSPE | STR71X_BSPICSR1_MSTR);
|
2008-11-02 23:24:58 +01:00
|
|
|
spi_putreg(priv, STR71X_BSPI_CSR1_OFFSET, cr1);
|
|
|
|
|
2008-11-03 00:32:26 +01:00
|
|
|
return STR71X_PCLK1 / divisor;
|
2008-10-31 00:37:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: spi_status
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Get SPI/MMC status
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
2009-03-29 20:53:20 +02:00
|
|
|
* dev - Device-specific state data
|
|
|
|
* devid - Identifies the device to report status on
|
2008-10-31 00:37:50 +01:00
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* Returns a bitset of status values (see SPI_STATUS_* defines
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2017-04-28 18:31:44 +02:00
|
|
|
static uint8_t spi_status(FAR struct spi_dev_s *dev, uint32_t devid)
|
2008-10-31 00:37:50 +01:00
|
|
|
{
|
2009-12-15 21:56:22 +01:00
|
|
|
uint8_t ret = 0;
|
|
|
|
uint16_t reg16 = getreg16(STR71X_GPIO1_PD);
|
2008-11-04 17:40:54 +01:00
|
|
|
|
2009-06-08 15:24:26 +02:00
|
|
|
if ((reg16 & MMCSD_GPIO1_WPIN) != 0)
|
2008-11-04 17:40:54 +01:00
|
|
|
{
|
|
|
|
ret |= SPI_STATUS_WRPROTECTED;
|
|
|
|
}
|
2008-11-02 23:24:58 +01:00
|
|
|
|
2009-06-08 15:24:26 +02:00
|
|
|
if ((reg16 & MMCSD_GPIO1_CPIN) != 0)
|
2008-11-04 17:40:54 +01:00
|
|
|
{
|
|
|
|
ret |= SPI_STATUS_PRESENT;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
2008-10-31 00:37:50 +01:00
|
|
|
}
|
|
|
|
|
2010-12-03 02:37:56 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: spi_cmddata
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Some devices require and additional out-of-band bit to specify if the
|
|
|
|
* next word sent to the device is a command or data. This is typical, for
|
|
|
|
* example, in "9-bit" displays where the 9th bit is the CMD/DATA bit.
|
|
|
|
* This function provides selection of command or data.
|
|
|
|
*
|
|
|
|
* This "latches" the CMD/DATA state. It does not have to be called before
|
|
|
|
* every word is transferred; only when the CMD/DATA state changes. This
|
|
|
|
* method is required if CONFIG_SPI_CMDDATA is selected in the NuttX
|
|
|
|
* configuration
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* dev - Device-specific state data
|
|
|
|
* cmd - TRUE: The following word is a command; FALSE: the following words
|
|
|
|
* are data.
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* OK unless an error occurs. Then a negated errno value is returned
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2015-09-05 17:07:59 +02:00
|
|
|
#ifdef CONFIG_SPI_CMDDATA
|
2017-04-28 18:31:44 +02:00
|
|
|
static int spi_cmddata(FAR struct spi_dev_s *dev, uint32_t devid, bool cmd)
|
2010-12-03 02:37:56 +01:00
|
|
|
{
|
|
|
|
# error "spi_cmddata not implemented"
|
|
|
|
return -ENOSYS;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2008-10-31 00:37:50 +01:00
|
|
|
/****************************************************************************
|
2009-04-26 18:06:29 +02:00
|
|
|
* Name: spi_send
|
2008-10-31 00:37:50 +01:00
|
|
|
*
|
|
|
|
* Description:
|
2009-04-26 18:06:29 +02:00
|
|
|
* Exchange one word on SPI
|
2008-10-31 00:37:50 +01:00
|
|
|
*
|
|
|
|
* Input Parameters:
|
2009-03-29 20:53:20 +02:00
|
|
|
* dev - Device-specific state data
|
2009-04-26 18:06:29 +02:00
|
|
|
* wd - The word to send. the size of the data is determined by the
|
|
|
|
* number of bits selected for the SPI interface.
|
2008-10-31 00:37:50 +01:00
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* response
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
nuttx: Fix the nightly build warning
lpc2148_spi1.c:142:24: warning: initialization of 'uint32_t (*)(struct spi_dev_s *, uint32_t)' {aka 'unsigned int (*)(struct spi_dev_s *, unsigned int)'} from incompatible pointer type 'uint16_t (*)(struct spi_dev_s *, uint16_t)' {aka 'short unsigned int (*)(struct spi_dev_s *, short unsigned int)'} [-Wincompatible-pointer-types]
142 | .send = spi_send,
| ^~~~~~~~
lpc2148_spi1.c:142:24: note: (near initialization for 'g_spiops.send')
In file included from ieee802154/mac802154_bind.c:49:
ieee802154/mac802154_internal.h: In function 'mac802154_setdevmode':
ieee802154/mac802154_internal.h:788:42: warning: converting a packed 'enum ieee802154_devmode_e' pointer (alignment 1) to a 'const union ieee802154_attr_u' pointer (alignment 4) may result in an unaligned pointer value [-Waddress-of-packed-member]
788 | (FAR const union ieee802154_attr_u *)&mode);
| ^~~~~~~~~~~~~~~~~
chip/stm32_hciuart.c: In function 'hciuart_read':
chip/stm32_hciuart.c:2104:30: warning: statement with no effect [-Wunused-value]
2104 | ntotal == (ssize_t)ret;
| ~~~~~~~^~~~~~~~~~~~~~~
wireless/ieee80211/bcm43xxx/bcmf_driver.c: In function 'bcmf_wl_auth_event_handler':
wireless/ieee80211/bcm43xxx/bcmf_driver.c:579:23: warning: taking address of packed member of 'struct bcmf_event_s' may result in an unaligned pointer value [-Waddress-of-packed-member]
579 | type = bcmf_getle32(&event->type);
| ^~~~~~~~~~~~
wireless/ieee80211/bcm43xxx/bcmf_driver.c:580:25: warning: taking address of packed member of 'struct bcmf_event_s' may result in an unaligned pointer value [-Waddress-of-packed-member]
580 | status = bcmf_getle32(&event->status);
| ^~~~~~~~~~~~~~
wireless/ieee80211/bcm43xxx/bcmf_driver.c: In function 'bcmf_wl_scan_event_handler':
wireless/ieee80211/bcm43xxx/bcmf_driver.c:619:25: warning: taking address of packed member of 'struct bcmf_event_s' may result in an unaligned pointer value [-Waddress-of-packed-member]
619 | status = bcmf_getle32(&event->status);
| ^~~~~~~~~~~~~~
wireless/ieee80211/bcm43xxx/bcmf_driver.c:620:35: warning: taking address of packed member of 'struct bcmf_event_s' may result in an unaligned pointer value [-Waddress-of-packed-member]
620 | escan_result_len = bcmf_getle32(&event->len);
| ^~~~~~~~~~~
wireless/ieee80211/bcm43xxx/bcmf_bdc.c: In function 'bcmf_bdc_process_event_frame':
wireless/ieee80211/bcm43xxx/bcmf_bdc.c:166:27: warning: taking address of packed member of 'struct bcmf_event_s' may result in an unaligned pointer value [-Waddress-of-packed-member]
166 | event_id = bcmf_getle32(&event_msg->event.type);
| ^~~~~~~~~~~~~~~~~~~~~~
wireless/ieee80211/bcm43xxx/mmc_sdio.c: In function 'sdio_io_rw_direct':
wireless/ieee80211/bcm43xxx/mmc_sdio.c:157:3: warning: converting a packed 'struct sdio_resp_R5' pointer (alignment 1) to a 'uint32_t' {aka 'unsigned int'} pointer (alignment 4) may result in an unaligned pointer value [-Waddress-of-packed-member]
157 | ret = SDIO_RECVR5(dev, SD_ACMD52, (uint32_t *)&resp);
| ^~~
wireless/ieee80211/bcm43xxx/mmc_sdio.c:79:28: note: defined here
79 | begin_packed_struct struct sdio_resp_R5
| ^~~~~~~~~~~~
wireless/ieee80211/bcm43xxx/mmc_sdio.c: In function 'sdio_io_rw_extended':
wireless/ieee80211/bcm43xxx/mmc_sdio.c:239:11: warning: converting a packed 'struct sdio_resp_R5' pointer (alignment 1) to a 'uint32_t' {aka 'unsigned int'} pointer (alignment 4) may result in an unaligned pointer value [-Waddress-of-packed-member]
239 | ret = SDIO_RECVR5(dev, SD_ACMD53, (uint32_t *)&resp);
| ^~~
wireless/ieee80211/bcm43xxx/mmc_sdio.c:79:28: note: defined here
79 | begin_packed_struct struct sdio_resp_R5
| ^~~~~~~~~~~~
wireless/ieee80211/bcm43xxx/mmc_sdio.c:244:11: warning: converting a packed 'struct sdio_resp_R5' pointer (alignment 1) to a 'uint32_t' {aka 'unsigned int'} pointer (alignment 4) may result in an unaligned pointer value [-Waddress-of-packed-member]
244 | ret = SDIO_RECVR5(dev, SD_ACMD53, (uint32_t *)&resp);
| ^~~
wireless/ieee80211/bcm43xxx/mmc_sdio.c:79:28: note: defined here
79 | begin_packed_struct struct sdio_resp_R5
| ^~~~~~~~~~~~
wireless/ieee80211/bcm43xxx/mmc_sdio.c:257:7: warning: converting a packed 'struct sdio_resp_R5' pointer (alignment 1) to a 'uint32_t' {aka 'unsigned int'} pointer (alignment 4) may result in an unaligned pointer value [-Waddress-of-packed-member]
257 | ret = SDIO_RECVR5(dev, SD_ACMD53, (uint32_t *)&resp);
| ^~~
wireless/ieee80211/bcm43xxx/mmc_sdio.c:79:28: note: defined here
79 | begin_packed_struct struct sdio_resp_R5
| ^~~~~~~~~~~~
wireless/ieee80211/bcm43xxx/mmc_sdio.c:265:3: warning: converting a packed 'struct sdio_resp_R5' pointer (alignment 1) to a 'uint32_t' {aka 'unsigned int'} pointer (alignment 4) may result in an unaligned pointer value [-Waddress-of-packed-member]
265 | SDIO_RECVR1(dev, SD_ACMD52ABRT, (uint32_t *)&resp);
| ^~~~~~~~~~~
wireless/ieee80211/bcm43xxx/mmc_sdio.c:79:28: note: defined here
79 | begin_packed_struct struct sdio_resp_R5
| ^~~~~~~~~~~~
chip/stm32_adc.c: In function 'adc_reset':
chip/stm32_adc.c:2860:7: warning: unused variable 'ret' [-Wunused-variable]
2860 | int ret;
| ^~~
chip/stm32_adc.c: In function 'adc_shutdown':
chip/stm32_adc.c:3044:7: warning: unused variable 'ret' [-Wunused-variable]
3044 | int ret;
| ^~~
chip/stm32_i2c.c:722:12: warning: 'stm32_i2c_sem_wait_noncancelable' defined but not used [-Wunused-function]
722 | static int stm32_i2c_sem_wait_noncancelable(FAR struct i2c_master_s *dev)
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
wireless/gs2200m.c: In function 'gs2200m_read':
wireless/gs2200m.c:727:20: warning: passing argument 1 of 'nxsem_wait' from incompatible pointer type [-Wincompatible-pointer-types]
727 | ret = nxsem_wait(dev);
| ^~~
| |
| struct gs2200m_dev_s *
.config:1207:warning: symbol value '' invalid for TESTING_OSTEST_FPUSIZE
platform/audio/cxd56_audio_analog.c:69:13: warning: inline function 'cxd56_audio_clock_is_enabled' declared but never defined
69 | inline bool cxd56_audio_clock_is_enabled(void);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
platform/audio/cxd56_audio_analog.c:68:13: warning: inline function 'cxd56_audio_clock_disable' declared but never defined
68 | inline void cxd56_audio_clock_disable(void);
| ^~~~~~~~~~~~~~~~~~~~~~~~~
platform/audio/cxd56_audio_analog.c:67:13: warning: inline function 'cxd56_audio_clock_enable' declared but never defined
67 | inline void cxd56_audio_clock_enable(uint32_t clk, uint32_t div);
| ^~~~~~~~~~~~~~~~~~~~~~~~
chip/stm32_adc.c: In function 'adc_reset':
chip/stm32_adc.c:1348:7: warning: unused variable 'ret' [-Wunused-variable]
1348 | int ret;
| ^~~
chip/stm32_adc.c: In function 'adc_shutdown':
chip/stm32_adc.c:1496:7: warning: unused variable 'ret' [-Wunused-variable]
1496 | int ret;
| ^~~
chip/stm32_i2c.c:729:12: warning: 'stm32_i2c_sem_wait_uninterruptble' defined but not used [-Wunused-function]
729 | static int stm32_i2c_sem_wait_uninterruptble(FAR struct i2c_master_s *dev)
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
wireless/lpwan/sx127x/sx127x.c:147:52: warning: missing terminating ' character
147 | # warning OOK support is not complete, RX+TX doesn't work yet!
| ^
str71_spi.c:435:24: warning: initialization of 'uint32_t (*)(struct spi_dev_s *, uint32_t)' {aka 'unsigned int (*)(struct spi_dev_s *, unsigned int)'} from incompatible pointer type
'uint16_t (*)(struct spi_dev_s *, uint16_t)' {aka 'short unsigned int (*)(struct spi_dev_s *, short unsigned int)'} [-Wincompatible-pointer-types]
435 | .send = spi_send,
| ^~~~~~~~
str71_spi.c:435:24: note: (near initialization for 'g_spiops.send')
chip/pic32mx-lowconsole.c:147:24: warning: 'pic32mx_getreg' defined but not used [-Wunused-function]
static inline uint32_t pic32mx_getreg(uintptr_t uart_base,
^
chip/pic32mx-gpio.c:113:20: warning: 'pic32mx_value' defined but not used [-Wunused-function]
static inline bool pic32mx_value(uint16_t pinset)
^
chip/pic32mz-gpio.c:124:20: warning: 'pic32mz_value' defined but not used [-Wunused-function]
static inline bool pic32mz_value(pinset_t pinset)
^
chip/pic32mx-usbdev.c:3065:1: warning: 'pic32mx_epreserved' defined but not used [-Wunused-function]
pic32mx_epreserved(struct pic32mx_usbdev_s *priv, int epno)
^
mmcsd/mmcsd_spi.c: In function 'mmcsd_mediachanged':
mmcsd/mmcsd_spi.c:1938:7: warning: 'return' with a value, in function returning void
return ret;
^
In file included from partition/fs_partition.c:42:0:
partition/partition.h:66:19: warning: 'read_partition_block' defined but not used [-Wunused-function]
static inline int read_partition_block(FAR struct partition_state_s *state,
^
local/local_netpoll.c: In function 'local_pollsetup':
local/local_netpoll.c:305:1: warning: label 'pollerr' defined but not used [-Wunused-label]
pollerr:
^~~~~~~
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
Change-Id: If3ea8f32b878aa218072130f7c3018f0d3c1aca5
2020-04-12 15:52:28 +02:00
|
|
|
static uint32_t spi_send(FAR struct spi_dev_s *dev, uint32_t wd)
|
2008-10-31 00:37:50 +01:00
|
|
|
{
|
2008-11-02 23:24:58 +01:00
|
|
|
FAR struct str71x_spidev_s *priv = (FAR struct str71x_spidev_s *)dev;
|
|
|
|
|
|
|
|
DEBUGASSERT(priv && priv->spibase);
|
|
|
|
|
2008-11-03 00:32:26 +01:00
|
|
|
#if CONFIG_STR714X_BSPI0_TXFIFO_DEPTH > 1
|
2008-11-02 23:24:58 +01:00
|
|
|
/* Wait while the TX FIFO is full */
|
|
|
|
|
2020-04-13 10:08:03 +02:00
|
|
|
while (spi_getreg(priv, STR71X_BSPI_CSR2_OFFSET) & STR71X_BSPICSR2_TFF)
|
|
|
|
{
|
|
|
|
}
|
2008-11-02 23:24:58 +01:00
|
|
|
#else
|
|
|
|
/* Wait until the TX FIFO is empty */
|
|
|
|
|
2020-04-13 10:08:03 +02:00
|
|
|
while (!(spi_getreg(priv, STR71X_BSPI_CSR2_OFFSET) & STR71X_BSPICSR2_TFE))
|
|
|
|
{
|
|
|
|
}
|
2008-11-02 23:24:58 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Write the byte to the TX FIFO */
|
|
|
|
|
2009-04-26 18:06:29 +02:00
|
|
|
spi_putreg(priv, STR71X_BSPI_TXR_OFFSET, wd << 8);
|
2008-11-02 23:24:58 +01:00
|
|
|
|
|
|
|
/* Wait for the RX FIFO not empty */
|
|
|
|
|
2020-04-13 10:08:03 +02:00
|
|
|
while (!(spi_getreg(priv, STR71X_BSPI_CSR2_OFFSET) & STR71X_BSPICSR2_RFNE))
|
|
|
|
{
|
|
|
|
}
|
2008-11-02 23:24:58 +01:00
|
|
|
|
|
|
|
/* Get the received value from the RX FIFO and return it */
|
|
|
|
|
2009-12-15 21:56:22 +01:00
|
|
|
return (uint8_t)(spi_getreg(priv, STR71X_BSPI_RXR_OFFSET) >> 8);
|
2008-10-31 00:37:50 +01:00
|
|
|
}
|
|
|
|
|
2015-10-03 01:43:08 +02:00
|
|
|
/****************************************************************************
|
2008-10-31 00:37:50 +01:00
|
|
|
* Name: spi_sndblock
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Send a block of data on SPI
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
2009-03-29 20:53:20 +02:00
|
|
|
* dev - Device-specific state data
|
2008-10-31 00:37:50 +01:00
|
|
|
* buffer - A pointer to the buffer of data to be sent
|
2009-04-26 18:06:29 +02:00
|
|
|
* buflen - the length of data to send from the buffer in number of words.
|
|
|
|
* The wordsize is determined by the number of bits-per-word
|
|
|
|
* selected for the SPI interface. If nbits <= 8, the data is
|
2020-04-13 10:08:03 +02:00
|
|
|
* packed into uint8_t's; if nbits >8, the data is packed into
|
|
|
|
* uint16_t's
|
2008-10-31 00:37:50 +01:00
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2020-04-13 10:08:03 +02:00
|
|
|
static void spi_sndblock(FAR struct spi_dev_s *dev,
|
|
|
|
FAR const void *buffer, size_t buflen)
|
2008-10-31 00:37:50 +01:00
|
|
|
{
|
2008-11-02 23:24:58 +01:00
|
|
|
FAR struct str71x_spidev_s *priv = (FAR struct str71x_spidev_s *)dev;
|
2009-12-15 21:56:22 +01:00
|
|
|
FAR const uint8_t *ptr = (FAR const uint8_t *)buffer;
|
|
|
|
uint16_t csr2;
|
2008-11-02 23:24:58 +01:00
|
|
|
|
|
|
|
DEBUGASSERT(priv && priv->spibase);
|
|
|
|
|
2020-02-23 09:50:23 +01:00
|
|
|
/* Loop while there are bytes remaining to be sent */
|
2008-11-02 23:24:58 +01:00
|
|
|
|
|
|
|
while (buflen > 0)
|
|
|
|
{
|
|
|
|
/* While the TX FIFO is not full and there are bytes left to send */
|
|
|
|
|
2020-04-13 10:08:03 +02:00
|
|
|
while ((spi_getreg(priv, STR71X_BSPI_CSR2_OFFSET) &
|
|
|
|
STR71X_BSPICSR2_TFF) == 0 && buflen > 0)
|
2008-11-02 23:24:58 +01:00
|
|
|
{
|
|
|
|
/* Send the data */
|
|
|
|
|
2009-12-15 21:56:22 +01:00
|
|
|
spi_putreg(priv, STR71X_BSPI_TXR_OFFSET, ((uint16_t)*ptr) << 8);
|
2009-04-26 18:06:29 +02:00
|
|
|
ptr++;
|
2008-11-02 23:24:58 +01:00
|
|
|
buflen--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Then discard all card responses until the RX & TX FIFOs are emptied. */
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
/* Is there anything in the RX fifo? */
|
|
|
|
|
2008-11-03 00:32:26 +01:00
|
|
|
csr2 = spi_getreg(priv, STR71X_BSPI_CSR2_OFFSET);
|
2008-11-02 23:24:58 +01:00
|
|
|
if ((csr2 & STR71X_BSPICSR2_RFNE) != 0)
|
|
|
|
{
|
|
|
|
/* Yes.. Read and discard */
|
|
|
|
|
2020-01-02 17:49:34 +01:00
|
|
|
spi_getreg(priv, STR71X_BSPI_RXR_OFFSET);
|
2008-11-02 23:24:58 +01:00
|
|
|
}
|
|
|
|
|
2009-12-15 21:56:22 +01:00
|
|
|
/* There is a race condition where TFNE may go false just before
|
2019-08-14 16:43:29 +02:00
|
|
|
* RFNE goes true and this loop terminates prematurely.
|
|
|
|
* The nasty little delay in the following solves that
|
|
|
|
* (it could probably be tuned to improve performance).
|
2008-11-02 23:24:58 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
else if ((csr2 & STR71X_BSPICSR2_TFNE) != 0)
|
|
|
|
{
|
|
|
|
up_udelay(100);
|
2008-11-03 00:32:26 +01:00
|
|
|
csr2 = spi_getreg(priv, STR71X_BSPI_CSR2_OFFSET);
|
2008-11-02 23:24:58 +01:00
|
|
|
}
|
|
|
|
}
|
2020-04-13 10:08:03 +02:00
|
|
|
while ((csr2 & STR71X_BSPICSR2_RFNE) || !(csr2 & STR71X_BSPICSR2_TFNE));
|
2008-10-31 00:37:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: spi_recvblock
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Revice a block of data from SPI
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
2009-03-29 20:53:20 +02:00
|
|
|
* dev - Device-specific state data
|
2019-09-11 16:56:56 +02:00
|
|
|
* buffer - A pointer to the buffer in which to receive data
|
2019-08-14 16:43:29 +02:00
|
|
|
* buflen - the length of data that can be received in the buffer in
|
|
|
|
* number of words.
|
|
|
|
* The wordsize is determined by the number of bits-per-word
|
2009-04-26 18:06:29 +02:00
|
|
|
* selected for the SPI interface. If nbits <= 8, the data is
|
2019-08-14 16:43:29 +02:00
|
|
|
* packed into uint8_t; if nbits >8, the data is packed into
|
|
|
|
* uint16_t's
|
2008-10-31 00:37:50 +01:00
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2019-08-14 16:43:29 +02:00
|
|
|
static void spi_recvblock(FAR struct spi_dev_s *dev, FAR void *buffer,
|
|
|
|
size_t buflen)
|
2008-10-31 00:37:50 +01:00
|
|
|
{
|
2008-11-02 23:24:58 +01:00
|
|
|
FAR struct str71x_spidev_s *priv = (FAR struct str71x_spidev_s *)dev;
|
2020-04-13 10:08:03 +02:00
|
|
|
FAR uint8_t *ptr = (FAR uint8_t *)buffer;
|
2009-12-15 21:56:22 +01:00
|
|
|
uint32_t fifobytes = 0;
|
2008-11-02 23:24:58 +01:00
|
|
|
|
|
|
|
DEBUGASSERT(priv && priv->spibase);
|
|
|
|
|
2019-08-14 16:43:29 +02:00
|
|
|
/* While there is remaining to be sent
|
|
|
|
* (and no synchronization error has occurred)
|
|
|
|
*/
|
2008-11-02 23:24:58 +01:00
|
|
|
|
|
|
|
while (buflen || fifobytes)
|
|
|
|
{
|
|
|
|
/* Fill the transmit FIFO with 0xff...
|
|
|
|
* Write 0xff to the data register while (1) the TX FIFO is
|
|
|
|
* not full, (2) we have not exceeded the depth of the TX FIFO,
|
|
|
|
* and (3) there are more bytes to be sent.
|
|
|
|
*/
|
|
|
|
|
2020-04-13 10:08:03 +02:00
|
|
|
while (spi_getreg(priv, STR71X_BSPI_CSR2_OFFSET) & STR71X_BSPICSR2_TFF
|
|
|
|
&& fifobytes < CONFIG_STR714X_BSPI0_TXFIFO_DEPTH && buflen > 0)
|
2008-11-02 23:24:58 +01:00
|
|
|
{
|
|
|
|
spi_putreg(priv, STR71X_BSPI_TXR_OFFSET, 0xff00);
|
|
|
|
buflen--;
|
|
|
|
fifobytes++;
|
|
|
|
}
|
|
|
|
|
2020-04-13 10:08:03 +02:00
|
|
|
/* Now, read RX data from RX FIFO while RX FIFO is not empty */
|
2008-11-02 23:24:58 +01:00
|
|
|
|
2020-04-13 10:08:03 +02:00
|
|
|
while (spi_getreg(priv, STR71X_BSPI_CSR2_OFFSET)
|
|
|
|
& STR71X_BSPICSR2_RFNE)
|
2008-11-02 23:24:58 +01:00
|
|
|
{
|
2009-12-15 21:56:22 +01:00
|
|
|
*ptr++ = (uint8_t)(spi_getreg(priv, STR71X_BSPI_RXR_OFFSET) >> 8);
|
2008-11-02 23:24:58 +01:00
|
|
|
fifobytes--;
|
|
|
|
}
|
|
|
|
}
|
2008-10-31 00:37:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
2016-01-27 15:49:49 +01:00
|
|
|
* Name: str71_spibus_initialize
|
2008-10-31 00:37:50 +01:00
|
|
|
*
|
|
|
|
* Description:
|
2010-05-02 19:29:37 +02:00
|
|
|
* Initialize the selected SPI port. This function could get called
|
|
|
|
* multiple times for each STR7 devices that needs an SPI reference.
|
2008-10-31 00:37:50 +01:00
|
|
|
*
|
2018-02-01 17:00:02 +01:00
|
|
|
* Input Parameters:
|
2019-09-17 18:46:23 +02:00
|
|
|
* Port number (for hardware that has multiple SPI interfaces)
|
2008-10-31 00:37:50 +01:00
|
|
|
*
|
|
|
|
* Returned Value:
|
2019-09-17 18:46:23 +02:00
|
|
|
* Valid SPI device structure reference on success; a NULL on failure
|
2008-10-31 00:37:50 +01:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2016-01-27 15:49:49 +01:00
|
|
|
FAR struct spi_dev_s *str71_spibus_initialize(int port)
|
2008-10-31 00:37:50 +01:00
|
|
|
{
|
2008-11-02 23:24:58 +01:00
|
|
|
FAR struct spi_dev_s *ret;
|
2015-07-02 03:18:51 +02:00
|
|
|
#if defined(CONFIG_STR71X_BSPI0) || defined(CONFIG_STR71X_BSPI1)
|
2009-12-15 21:56:22 +01:00
|
|
|
uint16_t reg16;
|
2015-07-02 03:18:51 +02:00
|
|
|
#endif
|
|
|
|
irqstate_t flags;
|
2008-11-02 23:24:58 +01:00
|
|
|
|
2016-02-13 19:37:46 +01:00
|
|
|
flags = enter_critical_section();
|
2008-11-02 23:24:58 +01:00
|
|
|
#ifdef CONFIG_STR71X_BSPI0
|
|
|
|
if (port == 0)
|
|
|
|
{
|
2010-05-02 19:29:37 +02:00
|
|
|
/* Check if this port has already been initialized */
|
2008-11-02 23:24:58 +01:00
|
|
|
|
2010-05-02 19:29:37 +02:00
|
|
|
if (!g_spidev0.initialized)
|
|
|
|
{
|
2019-08-14 16:43:29 +02:00
|
|
|
/* The default, alternate functionality of the GPIO0 pin
|
|
|
|
* selections is UART3/I2C1.
|
|
|
|
* In order to have BSP0 functionality, we also have to set the
|
|
|
|
* BSPI0 enable bit in the PCU BOOTCR register.
|
2010-05-02 19:29:37 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
reg16 = getreg16(STR71X_PCU_BOOTCR);
|
|
|
|
reg16 |= STR71X_PCUBOOTCR_BSPIOEN;
|
|
|
|
putreg16(reg16, STR71X_PCU_BOOTCR);
|
|
|
|
|
|
|
|
/* Configure all GPIO pins to their appropriate function:
|
|
|
|
*
|
|
|
|
* PC0=1 PC1=1 PC2=1: Alternate function, push-pull
|
|
|
|
* PC0=1 PC1=0 PC2=0: In, TTL
|
|
|
|
* PC0=0 PC1=1 PC2=0: In, CMOS
|
2014-04-14 00:22:22 +02:00
|
|
|
* PC0=1 PC1=0 PC2=1: Output, push pull
|
2010-05-02 19:29:37 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
reg16 = getreg16(STR71X_GPIO0_PC0);
|
|
|
|
reg16 &= ~BSPI0_GPIO0_ALL;
|
2019-08-14 16:43:29 +02:00
|
|
|
reg16 |= (BSPI0_GPIO0_ALT | BSPI0_GPIO0_INTTL |
|
|
|
|
BSPI0_GPIO0_OUTPP);
|
2010-05-02 19:29:37 +02:00
|
|
|
putreg16(reg16, STR71X_GPIO0_PC0);
|
|
|
|
|
|
|
|
reg16 = getreg16(STR71X_GPIO0_PC1);
|
|
|
|
reg16 &= ~BSPI0_GPIO0_ALL;
|
2019-08-14 16:43:29 +02:00
|
|
|
reg16 |= (BSPI0_GPIO0_ALT | BSPI0_GPIO0_INCMOS);
|
2010-05-02 19:29:37 +02:00
|
|
|
putreg16(reg16, STR71X_GPIO0_PC1);
|
|
|
|
|
|
|
|
reg16 = getreg16(STR71X_GPIO0_PC2);
|
|
|
|
reg16 &= ~BSPI0_GPIO0_ALL;
|
2019-08-14 16:43:29 +02:00
|
|
|
reg16 |= (BSPI0_GPIO0_ALT | BSPI0_GPIO0_OUTPP);
|
2010-05-02 19:29:37 +02:00
|
|
|
putreg16(reg16, STR71X_GPIO0_PC2);
|
|
|
|
|
2010-05-06 02:08:02 +02:00
|
|
|
/* Start with enc28j60 de-selected (active low) and in
|
|
|
|
* reset (also active low)
|
|
|
|
*/
|
2010-05-02 19:29:37 +02:00
|
|
|
|
2012-09-11 18:50:16 +02:00
|
|
|
#ifdef CONFIG_ENC28J60
|
2010-05-02 19:29:37 +02:00
|
|
|
reg16 = getreg16(STR71X_GPIO0_PD);
|
2010-05-06 02:08:02 +02:00
|
|
|
reg16 |= (ENC_GPIO0_CS | ENC_GPIO0_NETRST);
|
2010-05-02 19:29:37 +02:00
|
|
|
putreg16(reg16, STR71X_GPIO0_PD);
|
|
|
|
#endif
|
2008-11-02 23:24:58 +01:00
|
|
|
|
2010-05-02 19:29:37 +02:00
|
|
|
/* Set the clock divider to the maximum */
|
2008-11-02 23:24:58 +01:00
|
|
|
|
2010-05-02 19:29:37 +02:00
|
|
|
putreg16(255, STR71X_BSPI0_CLK);
|
2008-11-02 23:24:58 +01:00
|
|
|
|
2010-05-02 19:29:37 +02:00
|
|
|
/* Set FIFO sizes and disable the BSP1. It won't be enabled
|
|
|
|
* until the frequency is set.
|
|
|
|
*/
|
2008-11-02 23:24:58 +01:00
|
|
|
|
2010-05-02 19:29:37 +02:00
|
|
|
putreg16(STR71X_BSPI0_CSR1DISABLE, STR71X_BSPI0_CSR1);
|
|
|
|
putreg16(STR71X_BSPI0_CSR2VALUE, STR71X_BSPI0_CSR2);
|
2008-11-02 23:24:58 +01:00
|
|
|
|
2010-05-02 19:29:37 +02:00
|
|
|
/* Configure GPIO1 pins for ENC28J60 inputs and outputs.
|
|
|
|
*
|
|
|
|
* PC0=1 PC1=0 PC2=0: In, TTL
|
|
|
|
* PC0=0 PC1=1 PC2=0: In, CMOS
|
2014-04-14 00:22:22 +02:00
|
|
|
* PC0=1 PC1=0 PC2=1: Output, push pull
|
2010-05-02 19:29:37 +02:00
|
|
|
*/
|
2008-11-02 23:24:58 +01:00
|
|
|
|
2010-05-06 02:08:02 +02:00
|
|
|
#ifdef BSPI0_GPIO1_ALL
|
2010-05-02 19:29:37 +02:00
|
|
|
reg16 = getreg16(STR71X_GPIO1_PC0);
|
|
|
|
reg16 &= ~BSPI0_GPIO1_ALL;
|
2019-08-14 16:43:29 +02:00
|
|
|
reg16 |= (BSPI0_GPIO1_INTTL | BSPI0_GPIO1_OUTPP);
|
2010-05-02 19:29:37 +02:00
|
|
|
putreg16(reg16, STR71X_GPIO1_PC0);
|
2008-11-02 23:24:58 +01:00
|
|
|
|
2010-05-02 19:29:37 +02:00
|
|
|
reg16 = getreg16(STR71X_GPIO1_PC1);
|
|
|
|
reg16 &= ~BSPI0_GPIO1_ALL;
|
|
|
|
reg16 |= BSPI0_GPIO0_INCMOS;
|
|
|
|
putreg16(reg16, STR71X_GPIO1_PC1);
|
2008-11-02 23:24:58 +01:00
|
|
|
|
2010-05-02 19:29:37 +02:00
|
|
|
reg16 = getreg16(STR71X_GPIO1_PC2);
|
|
|
|
reg16 &= ~BSPI0_GPIO1_ALL;
|
|
|
|
reg16 |= BSPI0_GPIO0_OUTPP;
|
|
|
|
putreg16(reg16, STR71X_GPIO1_PC2);
|
2010-05-06 02:08:02 +02:00
|
|
|
#endif
|
2010-05-02 19:29:37 +02:00
|
|
|
g_spidev0.initialized = true;
|
|
|
|
}
|
2008-11-02 23:24:58 +01:00
|
|
|
|
2010-05-02 19:29:37 +02:00
|
|
|
/* Return the SPI device reference */
|
2008-11-02 23:24:58 +01:00
|
|
|
|
|
|
|
ret = &g_spidev0.spidev;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
#endif
|
2008-11-03 00:32:26 +01:00
|
|
|
#ifdef CONFIG_STR71X_BSPI1
|
2008-11-02 23:24:58 +01:00
|
|
|
if (port == 1)
|
|
|
|
{
|
2010-05-02 19:29:37 +02:00
|
|
|
/* Check if this port has already been initialized */
|
2008-11-02 23:24:58 +01:00
|
|
|
|
2010-05-02 19:29:37 +02:00
|
|
|
if (!g_spidev1.initialized)
|
|
|
|
{
|
|
|
|
/* Configure all GPIO pins to their alternate function EXCEPT for
|
|
|
|
* the CS pin .. we will configure that as an push-pull output
|
|
|
|
* and control the chip select as a normal GPIO.
|
|
|
|
*
|
|
|
|
* PC0=1 PC1=1 PC2=1: Alternate function, push-pull
|
|
|
|
* PC0=1 PC1=0 PC2=0: In, TTL
|
|
|
|
* PC0=0 PC1=1 PC2=0: In, CMOS
|
2014-04-14 00:22:22 +02:00
|
|
|
* PC0=1 PC1=0 PC2=1: Output, push pull
|
2010-05-02 19:29:37 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
reg16 = getreg16(STR71X_GPIO0_PC0);
|
|
|
|
reg16 &= ~BSPI1_GPIO0_ALL;
|
2019-08-14 16:43:29 +02:00
|
|
|
reg16 |= (BSPI1_GPIO0_ALT | BSPI1_GPIO0_INTTL |
|
|
|
|
BSPI1_GPIO0_OUTPP);
|
2010-05-02 19:29:37 +02:00
|
|
|
putreg16(reg16, STR71X_GPIO0_PC0);
|
|
|
|
|
|
|
|
reg16 = getreg16(STR71X_GPIO0_PC1);
|
|
|
|
reg16 &= ~BSPI1_GPIO0_ALL;
|
2019-08-14 16:43:29 +02:00
|
|
|
reg16 |= (BSPI1_GPIO0_ALT | BSPI1_GPIO0_INCMOS);
|
2010-05-02 19:29:37 +02:00
|
|
|
putreg16(reg16, STR71X_GPIO0_PC1);
|
|
|
|
|
|
|
|
reg16 = getreg16(STR71X_GPIO0_PC2);
|
|
|
|
reg16 &= ~BSPI1_GPIO0_ALL;
|
2019-08-14 16:43:29 +02:00
|
|
|
reg16 |= (BSPI1_GPIO0_ALT | BSPI1_GPIO0_OUTPP);
|
2010-05-02 19:29:37 +02:00
|
|
|
putreg16(reg16, STR71X_GPIO0_PC2);
|
|
|
|
|
|
|
|
/* Start with MMC/SD disabled */
|
|
|
|
|
|
|
|
reg16 = getreg16(STR71X_GPIO0_PD);
|
|
|
|
reg16 |= MMCSD_GPIO0_CS;
|
|
|
|
putreg16(reg16, STR71X_GPIO0_PD);
|
|
|
|
|
|
|
|
/* Set the clock divider to the maximum */
|
|
|
|
|
|
|
|
putreg16(255, STR71X_BSPI1_CLK);
|
|
|
|
|
|
|
|
/* Set FIFO sizes and disable the BSP1. It won't be enabled
|
|
|
|
* until the frequency is set.
|
|
|
|
*/
|
|
|
|
|
|
|
|
putreg16(STR71X_BSPI1_CSR1DISABLE, STR71X_BSPI1_CSR1);
|
|
|
|
putreg16(STR71X_BSPI1_CSR2VALUE, STR71X_BSPI1_CSR2);
|
|
|
|
|
|
|
|
/* Configure GPIO1 pins for WP/CP input
|
|
|
|
*
|
|
|
|
* PC0=1 PC1=0 PC2=0: In, TTL
|
|
|
|
* PC0=0 PC1=1 PC2=0: In, CMOS
|
2014-04-14 00:22:22 +02:00
|
|
|
* PC0=1 PC1=0 PC2=1: Output, push pull
|
2010-05-02 19:29:37 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef BSPI1_GPIO1_ALL
|
|
|
|
reg16 = getreg16(STR71X_GPIO1_PC0);
|
|
|
|
reg16 &= ~BSPI1_GPIO1_ALL;
|
2019-08-14 16:43:29 +02:00
|
|
|
reg16 |= (BSPI1_GPIO1_INTTL | BSPI1_GPIO1_OUTPP);
|
2010-05-02 19:29:37 +02:00
|
|
|
putreg16(reg16, STR71X_GPIO1_PC0);
|
|
|
|
|
|
|
|
reg16 = getreg16(STR71X_GPIO1_PC1);
|
|
|
|
reg16 &= ~BSPI1_GPIO1_ALL;
|
|
|
|
reg16 |= BSPI1_GPIO0_INCMOS;
|
|
|
|
putreg16(reg16, STR71X_GPIO1_PC1);
|
|
|
|
|
|
|
|
reg16 = getreg16(STR71X_GPIO1_PC2);
|
|
|
|
reg16 &= ~BSPI1_GPIO1_ALL;
|
|
|
|
reg16 |= BSPI1_GPIO0_OUTPP;
|
|
|
|
putreg16(reg16, STR71X_GPIO1_PC2);
|
|
|
|
#endif
|
|
|
|
g_spidev1.initialized = true;
|
|
|
|
}
|
2008-11-04 17:40:54 +01:00
|
|
|
|
2010-05-02 19:29:37 +02:00
|
|
|
/* Return the SPI device reference */
|
2008-11-04 17:40:54 +01:00
|
|
|
|
2008-11-02 23:24:58 +01:00
|
|
|
ret = &g_spidev1.spidev;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
ret = NULL;
|
|
|
|
}
|
2015-07-02 03:18:51 +02:00
|
|
|
|
2016-02-13 19:37:46 +01:00
|
|
|
leave_critical_section(flags);
|
2008-11-02 23:24:58 +01:00
|
|
|
return ret;
|
2008-10-31 00:37:50 +01:00
|
|
|
}
|
2008-11-02 23:24:58 +01:00
|
|
|
|
|
|
|
#endif /* CONFIG_STR71X_BSPI0 || CONFIG_STR71X_BSPI1 */
|