1 /*
2 * Copyright (c) 2023 Cypress Semiconductor Corporation (an Infineon company) or
3 * an affiliate of Cypress Semiconductor Corporation
4 *
5 * SPDX-License-Identifier: Apache-2.0
6 */
7
8 #include "airoc_whd_hal_common.h"
9 #include "airoc_wifi.h"
10
11 #include <zephyr/kernel.h>
12 #include <zephyr/drivers/gpio.h>
13
14 LOG_MODULE_DECLARE(infineon_airoc_wifi, CONFIG_WIFI_LOG_LEVEL);
15
16 #ifdef __cplusplus
17 extern "C" {
18 #endif
19
20 /******************************************************
21 * Function
22 ******************************************************/
23
airoc_wifi_power_on(const struct device * dev)24 int airoc_wifi_power_on(const struct device *dev)
25 {
26 #if DT_INST_NODE_HAS_PROP(0, wifi_reg_on_gpios)
27 int ret;
28 const struct airoc_wifi_config *config = dev->config;
29
30 /* Check WIFI REG_ON gpio instance */
31 if (!device_is_ready(config->wifi_reg_on_gpio.port)) {
32 LOG_ERR("Error: failed to configure wifi_reg_on %s pin %d",
33 config->wifi_reg_on_gpio.port->name, config->wifi_reg_on_gpio.pin);
34 return -EIO;
35 }
36
37 /* Configure wifi_reg_on as output */
38 ret = gpio_pin_configure_dt(&config->wifi_reg_on_gpio, GPIO_OUTPUT);
39 if (ret) {
40 LOG_ERR("Error %d: failed to configure wifi_reg_on %s pin %d", ret,
41 config->wifi_reg_on_gpio.port->name, config->wifi_reg_on_gpio.pin);
42 return ret;
43 }
44 ret = gpio_pin_set_dt(&config->wifi_reg_on_gpio, 0);
45 if (ret) {
46 return ret;
47 }
48
49 /* Allow CBUCK regulator to discharge */
50 k_msleep(WLAN_CBUCK_DISCHARGE_MS);
51
52 /* WIFI power on */
53 ret = gpio_pin_set_dt(&config->wifi_reg_on_gpio, 1);
54 if (ret) {
55 return ret;
56 }
57 k_msleep(WLAN_POWER_UP_DELAY_MS);
58 #endif /* DT_INST_NODE_HAS_PROP(0, reg_on_gpios) */
59
60 return 0;
61 }
62
63 /*
64 * Implement WHD memory wrappers
65 */
66
whd_mem_malloc(size_t size)67 void *whd_mem_malloc(size_t size)
68 {
69 return k_malloc(size);
70 }
71
whd_mem_calloc(size_t nitems,size_t size)72 void *whd_mem_calloc(size_t nitems, size_t size)
73 {
74 return k_calloc(nitems, size);
75 }
76
whd_mem_free(void * ptr)77 void whd_mem_free(void *ptr)
78 {
79 k_free(ptr);
80 }
81
82 #ifdef __cplusplus
83 } /* extern "C" */
84 #endif
85