1 /* 2 * Copyright (c) 2019-2020 The Linux Foundation. All rights reserved. 3 * 4 * Permission to use, copy, modify, and/or distribute this software for 5 * any purpose with or without fee is hereby granted, provided that the 6 * above copyright notice and this permission notice appear in all 7 * copies. 8 * 9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL 10 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED 11 * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE 12 * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL 13 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR 14 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER 15 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 16 * PERFORMANCE OF THIS SOFTWARE. 17 */ 18 19 /** 20 * DOC: qal_vbus_dev 21 * QCA abstraction layer (QAL) virtual bus management APIs 22 */ 23 24 #if !defined(__I_QAL_VBUS_DEV_H) 25 #define __I_QAL_VBUS_DEV_H 26 27 /* Include Files */ 28 #include <qdf_types.h> 29 #include "qdf_util.h" 30 #include "qdf_module.h" 31 #include <linux/of_gpio.h> 32 #include <linux/clk.h> 33 #include <linux/platform_device.h> 34 #if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 9, 0) 35 #include <linux/reset.h> 36 #endif 37 38 struct qdf_vbus_resource; 39 struct qdf_vbus_rstctl; 40 struct qdf_dev_clk; 41 struct qdf_pfm_hndl; 42 struct qdf_pfm_drv; 43 44 /** 45 * __qal_vbus_get_iorsc() - acquire io resource 46 * @devnum: Device Number 47 * @flag: Property bitmap for the io resource 48 * @devname: Device name string 49 * 50 * This function will allocate the io resource for a device 51 * 52 * Return: QDF_STATUS_SUCCESS on success 53 */ 54 static inline QDF_STATUS 55 __qal_vbus_get_iorsc(int devnum, uint32_t flag, char *devname) 56 { 57 int ret; 58 59 ret = gpio_request_one(devnum, flag, devname); 60 61 return qdf_status_from_os_return(ret); 62 } 63 64 /** 65 * __qal_vbus_release_iorsc() - release io resource 66 * @devnum: Device Number 67 * 68 * This function will release the io resource attached to a device 69 * 70 * Return: QDF_STATUS_SUCCESS on success 71 */ 72 static inline QDF_STATUS 73 __qal_vbus_release_iorsc(int devnum) 74 { 75 gpio_free(devnum); 76 return QDF_STATUS_SUCCESS; 77 } 78 79 /** 80 * __qal_vbus_enable_devclk() - enable device clock 81 * @clk: Device clock 82 * 83 * This function will enable the clock for a device 84 * 85 * Return: QDF_STATUS_SUCCESS on success 86 */ 87 static inline QDF_STATUS 88 __qal_vbus_enable_devclk(struct qdf_dev_clk *clk) 89 { 90 int ret; 91 92 ret = clk_prepare_enable((struct clk *)clk); 93 94 return qdf_status_from_os_return(ret); 95 } 96 97 /** 98 * __qal_vbus_disable_devclk() - disable device clock 99 * @clk: Device clock 100 * 101 * This function will disable the clock for a device 102 * 103 * Return: QDF_STATUS_SUCCESS on success 104 */ 105 static inline QDF_STATUS 106 __qal_vbus_disable_devclk(struct qdf_dev_clk *clk) 107 { 108 clk_disable_unprepare((struct clk *)clk); 109 110 return QDF_STATUS_SUCCESS; 111 } 112 113 /** 114 * __qal_vbus_get_dev_rstctl() - get device reset control 115 * @pfhndl: Device handle 116 * @state: Device state information 117 * @rstctl: Device reset control handle 118 * 119 * This function will acquire the control to reset the device 120 * 121 * Return: QDF_STATUS_SUCCESS on success 122 */ 123 static inline QDF_STATUS 124 __qal_vbus_get_dev_rstctl(struct qdf_pfm_hndl *pfhndl, const char *state, 125 struct qdf_vbus_rstctl **rstctl) 126 { 127 struct reset_control *rsctl; 128 #if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 16, 0) 129 rsctl = devm_reset_control_get_optional((struct device *)pfhndl, state); 130 #elif LINUX_VERSION_CODE >= KERNEL_VERSION(3, 9, 0) 131 rsctl = reset_control_get_optional((struct device *)pfhndl, state); 132 #else 133 rsctl = NULL; 134 #endif 135 *rstctl = (struct qdf_vbus_rstctl *)rsctl; 136 return QDF_STATUS_SUCCESS; 137 } 138 139 /** 140 * __qal_vbus_release_dev_rstctl() - release device reset control 141 * @pfhndl: Device handle 142 * @rstctl: Device reset control handle 143 * 144 * This function will release the control to reset the device 145 * 146 * Return: QDF_STATUS_SUCCESS on success 147 */ 148 static inline QDF_STATUS 149 __qal_vbus_release_dev_rstctl(struct qdf_pfm_hndl *pfhndl, 150 struct qdf_vbus_rstctl *rstctl) 151 { 152 reset_control_put((struct reset_control *)rstctl); 153 return QDF_STATUS_SUCCESS; 154 } 155 156 /** 157 * __qal_vbus_activate_dev_rstctl() - activate device reset control 158 * @pfhndl: Device handle 159 * @rstctl: Device reset control handle 160 * 161 * This function will activate the reset control for the device 162 * 163 * Return: QDF_STATUS_SUCCESS on success 164 */ 165 static inline QDF_STATUS 166 __qal_vbus_activate_dev_rstctl(struct qdf_pfm_hndl *pfhndl, 167 struct qdf_vbus_rstctl *rstctl) 168 { 169 reset_control_assert((struct reset_control *)rstctl); 170 return QDF_STATUS_SUCCESS; 171 } 172 173 /** 174 * __qal_vbus_deactivate_dev_rstctl() - deactivate device reset control 175 * @pfhndl: Device handle 176 * @rstctl: Device reset control handle 177 * 178 * This function will deactivate the reset control for the device 179 * 180 * Return: QDF_STATUS_SUCCESS on success 181 */ 182 static inline QDF_STATUS 183 __qal_vbus_deactivate_dev_rstctl(struct qdf_pfm_hndl *pfhndl, 184 struct qdf_vbus_rstctl *rstctl) 185 { 186 reset_control_deassert((struct reset_control *)rstctl); 187 return QDF_STATUS_SUCCESS; 188 } 189 190 /** 191 * __qal_vbus_get_resource() - get resource 192 * @pfhndl: Device handle 193 * @rsc: Resource handle 194 * @restype: Resource type 195 * @residx: Resource index 196 * 197 * This function will acquire a particular resource and attach it to the device 198 * 199 * Return: QDF_STATUS_SUCCESS on success 200 */ 201 static inline QDF_STATUS 202 __qal_vbus_get_resource(struct qdf_pfm_hndl *pfhndl, 203 struct qdf_vbus_resource **rsc, uint32_t restype, 204 uint32_t residx) 205 { 206 struct resource *rsrc; 207 208 rsrc = platform_get_resource((struct platform_device *)pfhndl, 209 restype, residx); 210 *rsc = (struct qdf_vbus_resource *)rsrc; 211 return QDF_STATUS_SUCCESS; 212 } 213 214 /** 215 * __qal_vbus_get_irq() - get irq 216 * @pfhndl: Device handle 217 * @str: Device identifier 218 * @irq: irq number 219 * 220 * This function will acquire an irq for the device 221 * 222 * Return: QDF_STATUS_SUCCESS on success 223 */ 224 static inline QDF_STATUS 225 __qal_vbus_get_irq(struct qdf_pfm_hndl *pfhndl, const char *str, int *irq) 226 { 227 *irq = platform_get_irq_byname((struct platform_device *)pfhndl, str); 228 229 if (*irq < 0) 230 return QDF_STATUS_E_FAULT; 231 232 return QDF_STATUS_SUCCESS; 233 } 234 235 /** 236 * __qal_vbus_register_driver() - register driver 237 * @pfdev: Device handle 238 * 239 * This function will initialize a device 240 * 241 * Return: QDF_STATUS_SUCCESS on success 242 */ 243 static inline QDF_STATUS 244 __qal_vbus_register_driver(struct qdf_pfm_drv *pfdev) 245 { 246 int ret; 247 248 ret = platform_driver_register((struct platform_driver *)pfdev); 249 250 return qdf_status_from_os_return(ret); 251 } 252 253 /** 254 * __qal_vbus_deregister_driver() - deregister driver 255 * @pfdev: Device handle 256 * 257 * This function will deregister the driver for a device 258 * 259 * Return: QDF_STATUS_SUCCESS on success 260 */ 261 static inline QDF_STATUS 262 __qal_vbus_deregister_driver(struct qdf_pfm_drv *pfdev) 263 { 264 platform_driver_unregister((struct platform_driver *)pfdev); 265 266 return QDF_STATUS_SUCCESS; 267 } 268 #endif /* __I_QAL_VBUS_DEV_H */ 269