drivers: hci: spi: update to new GPIO API
Update bluetooth hcp spi driver to new GPIO API. Following changes have been done: - Use new gpio api functions - Get reset, irq and cs flags from dt defines - Define reset pin as active low and invert set/unset logic. Tested on disco_l475_iot1 and 96b_carbon. Signed-off-by: Erwan Gouriou <erwan.gouriou@linaro.org>
This commit is contained in:
parent
2a117748f6
commit
bfc1a50eb9
4 changed files with 23 additions and 24 deletions
|
@ -84,8 +84,8 @@
|
||||||
bt-hci@0 {
|
bt-hci@0 {
|
||||||
compatible = "zephyr,bt-hci-spi";
|
compatible = "zephyr,bt-hci-spi";
|
||||||
reg = <0>;
|
reg = <0>;
|
||||||
reset-gpios = <&gpiob 4 0>;
|
reset-gpios = <&gpiob 4 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)>;
|
||||||
irq-gpios = <&gpiob 1 0>;
|
irq-gpios = <&gpiob 1 GPIO_ACTIVE_HIGH>;
|
||||||
spi-max-frequency = <2000000>;
|
spi-max-frequency = <2000000>;
|
||||||
label = "BT_HCI";
|
label = "BT_HCI";
|
||||||
};
|
};
|
||||||
|
|
|
@ -117,13 +117,14 @@
|
||||||
&spi3 {
|
&spi3 {
|
||||||
status = "okay";
|
status = "okay";
|
||||||
|
|
||||||
cs-gpios = <&gpiod 13 0>, <&gpioe 0 GPIO_ACTIVE_HIGH>;
|
cs-gpios = <&gpiod 13 (GPIO_ACTIVE_HIGH | GPIO_PULL_UP)>,
|
||||||
|
<&gpioe 0 GPIO_ACTIVE_HIGH>;
|
||||||
|
|
||||||
spbtle-rf@0 {
|
spbtle-rf@0 {
|
||||||
compatible = "zephyr,bt-hci-spi";
|
compatible = "zephyr,bt-hci-spi";
|
||||||
reg = <0>;
|
reg = <0>;
|
||||||
reset-gpios = <&gpioa 8 0>;
|
reset-gpios = <&gpioa 8 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)>;
|
||||||
irq-gpios = <&gpioe 6 0>;
|
irq-gpios = <&gpioe 6 (GPIO_ACTIVE_HIGH | GPIO_PULL_DOWN)>;
|
||||||
spi-max-frequency = <2000000>;
|
spi-max-frequency = <2000000>;
|
||||||
label = "SPBTLE-RF";
|
label = "SPBTLE-RF";
|
||||||
};
|
};
|
||||||
|
|
|
@ -5,13 +5,13 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
&arduino_spi {
|
&arduino_spi {
|
||||||
cs-gpios = <&arduino_header 16 0>; /* D10 */
|
cs-gpios = <&arduino_header 16 (GPIO_ACTIVE_HIGH | GPIO_PULL_UP)>; /* D10 */
|
||||||
|
|
||||||
spbtle-rf@0 {
|
spbtle-rf@0 {
|
||||||
compatible = "zephyr,bt-hci-spi";
|
compatible = "zephyr,bt-hci-spi";
|
||||||
reg = <0>;
|
reg = <0>;
|
||||||
reset-gpios = <&arduino_header 13 0>; /* D7 */
|
reset-gpios = <&arduino_header 13 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)>; /* D7 */
|
||||||
irq-gpios = <&arduino_header 0 0>; /* A0 */
|
irq-gpios = <&arduino_header 0 (GPIO_ACTIVE_HIGH | GPIO_PULL_DOWN)>; /* A0 */
|
||||||
spi-max-frequency = <2000000>;
|
spi-max-frequency = <2000000>;
|
||||||
label = "SPBTLE-RF";
|
label = "SPBTLE-RF";
|
||||||
};
|
};
|
||||||
|
|
|
@ -46,9 +46,12 @@
|
||||||
#define CMD_OCF 2
|
#define CMD_OCF 2
|
||||||
|
|
||||||
#define GPIO_IRQ_PIN DT_INST_0_ZEPHYR_BT_HCI_SPI_IRQ_GPIOS_PIN
|
#define GPIO_IRQ_PIN DT_INST_0_ZEPHYR_BT_HCI_SPI_IRQ_GPIOS_PIN
|
||||||
|
#define GPIO_IRQ_FLAGS DT_INST_0_ZEPHYR_BT_HCI_SPI_IRQ_GPIOS_FLAGS
|
||||||
#define GPIO_RESET_PIN DT_INST_0_ZEPHYR_BT_HCI_SPI_RESET_GPIOS_PIN
|
#define GPIO_RESET_PIN DT_INST_0_ZEPHYR_BT_HCI_SPI_RESET_GPIOS_PIN
|
||||||
|
#define GPIO_RESET_FLAGS DT_INST_0_ZEPHYR_BT_HCI_SPI_RESET_GPIOS_FLAGS
|
||||||
#ifdef DT_INST_0_ZEPHYR_BT_HCI_SPI_CS_GPIOS_PIN
|
#ifdef DT_INST_0_ZEPHYR_BT_HCI_SPI_CS_GPIOS_PIN
|
||||||
#define GPIO_CS_PIN DT_INST_0_ZEPHYR_BT_HCI_SPI_CS_GPIOS_PIN
|
#define GPIO_CS_PIN DT_INST_0_ZEPHYR_BT_HCI_SPI_CS_GPIOS_PIN
|
||||||
|
#define GPIO_CS_FLAGS DT_INST_0_ZEPHYR_BT_HCI_SPI_CS_GPIOS_FLAGS
|
||||||
#endif /* DT_INST_0_ZEPHYR_BT_HCI_SPI_CS_GPIOS_PIN */
|
#endif /* DT_INST_0_ZEPHYR_BT_HCI_SPI_CS_GPIOS_PIN */
|
||||||
|
|
||||||
/* Max SPI buffer length for transceive operations.
|
/* Max SPI buffer length for transceive operations.
|
||||||
|
@ -201,22 +204,23 @@ static int configure_cs(void)
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Configure pin as output and set to active */
|
||||||
gpio_pin_configure(cs_dev, GPIO_CS_PIN,
|
gpio_pin_configure(cs_dev, GPIO_CS_PIN,
|
||||||
GPIO_DIR_OUT | GPIO_PUD_PULL_UP);
|
GPIO_OUTPUT_ACTIVE | GPIO_CS_FLAGS);
|
||||||
gpio_pin_write(cs_dev, GPIO_CS_PIN, 1);
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void kick_cs(void)
|
static void kick_cs(void)
|
||||||
{
|
{
|
||||||
gpio_pin_write(cs_dev, GPIO_CS_PIN, 1);
|
gpio_pin_set(cs_dev, GPIO_CS_PIN, 1);
|
||||||
gpio_pin_write(cs_dev, GPIO_CS_PIN, 0);
|
gpio_pin_set(cs_dev, GPIO_CS_PIN, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void release_cs(void)
|
static void release_cs(void)
|
||||||
{
|
{
|
||||||
gpio_pin_write(cs_dev, GPIO_CS_PIN, 1);
|
gpio_pin_set(cs_dev, GPIO_CS_PIN, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool irq_pin_high(void)
|
static bool irq_pin_high(void)
|
||||||
|
@ -480,16 +484,11 @@ static int bt_spi_open(void)
|
||||||
{
|
{
|
||||||
/* Configure RST pin and hold BLE in Reset */
|
/* Configure RST pin and hold BLE in Reset */
|
||||||
gpio_pin_configure(rst_dev, GPIO_RESET_PIN,
|
gpio_pin_configure(rst_dev, GPIO_RESET_PIN,
|
||||||
GPIO_DIR_OUT | GPIO_PUD_PULL_UP);
|
GPIO_OUTPUT_ACTIVE | GPIO_RESET_FLAGS);
|
||||||
gpio_pin_write(rst_dev, GPIO_RESET_PIN, 0);
|
|
||||||
|
|
||||||
/* Configure IRQ pin and the IRQ call-back/handler */
|
/* Configure IRQ pin and the IRQ call-back/handler */
|
||||||
gpio_pin_configure(irq_dev, GPIO_IRQ_PIN,
|
gpio_pin_configure(irq_dev, GPIO_IRQ_PIN,
|
||||||
#if defined(CONFIG_BT_SPI_BLUENRG)
|
GPIO_INPUT | GPIO_IRQ_FLAGS);
|
||||||
GPIO_PUD_PULL_DOWN |
|
|
||||||
#endif
|
|
||||||
GPIO_DIR_IN | GPIO_INT |
|
|
||||||
GPIO_INT_EDGE | GPIO_INT_ACTIVE_HIGH);
|
|
||||||
|
|
||||||
gpio_init_callback(&gpio_cb, bt_spi_isr, BIT(GPIO_IRQ_PIN));
|
gpio_init_callback(&gpio_cb, bt_spi_isr, BIT(GPIO_IRQ_PIN));
|
||||||
|
|
||||||
|
@ -497,9 +496,8 @@ static int bt_spi_open(void)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (gpio_pin_enable_callback(irq_dev, GPIO_IRQ_PIN)) {
|
gpio_pin_interrupt_configure(irq_dev, GPIO_IRQ_PIN,
|
||||||
return -EINVAL;
|
GPIO_INT_EDGE_TO_ACTIVE);
|
||||||
}
|
|
||||||
|
|
||||||
/* Start RX thread */
|
/* Start RX thread */
|
||||||
k_thread_create(&spi_rx_thread_data, spi_rx_stack,
|
k_thread_create(&spi_rx_thread_data, spi_rx_stack,
|
||||||
|
@ -509,7 +507,7 @@ static int bt_spi_open(void)
|
||||||
0, K_NO_WAIT);
|
0, K_NO_WAIT);
|
||||||
|
|
||||||
/* Take BLE out of reset */
|
/* Take BLE out of reset */
|
||||||
gpio_pin_write(rst_dev, GPIO_RESET_PIN, 1);
|
gpio_pin_set(rst_dev, GPIO_RESET_PIN, 0);
|
||||||
|
|
||||||
/* Device will let us know when it's ready */
|
/* Device will let us know when it's ready */
|
||||||
k_sem_take(&sem_initialised, K_FOREVER);
|
k_sem_take(&sem_initialised, K_FOREVER);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue