1 /* 2 * Copyright (c) 2019 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(3, 9, 0) 129 rsctl = reset_control_get_optional((struct device *)pfhndl, state); 130 #else 131 rsctl = NULL; 132 #endif 133 *rstctl = (struct qdf_vbus_rstctl *)rsctl; 134 return QDF_STATUS_SUCCESS; 135 } 136 137 /** 138 * __qal_vbus_release_dev_rstctl() - release device reset control 139 * @pfhndl: Device handle 140 * @rstctl: Device reset control handle 141 * 142 * This function will release the control to reset the device 143 * 144 * Return: QDF_STATUS_SUCCESS on success 145 */ 146 static inline QDF_STATUS 147 __qal_vbus_release_dev_rstctl(struct qdf_pfm_hndl *pfhndl, 148 struct qdf_vbus_rstctl *rstctl) 149 { 150 reset_control_put((struct reset_control *)rstctl); 151 return QDF_STATUS_SUCCESS; 152 } 153 154 /** 155 * __qal_vbus_activate_dev_rstctl() - activate device reset control 156 * @pfhndl: Device handle 157 * @rstctl: Device reset control handle 158 * 159 * This function will activate the reset control for the device 160 * 161 * Return: QDF_STATUS_SUCCESS on success 162 */ 163 static inline QDF_STATUS 164 __qal_vbus_activate_dev_rstctl(struct qdf_pfm_hndl *pfhndl, 165 struct qdf_vbus_rstctl *rstctl) 166 { 167 reset_control_assert((struct reset_control *)rstctl); 168 return QDF_STATUS_SUCCESS; 169 } 170 171 /** 172 * __qal_vbus_deactivate_dev_rstctl() - deactivate device reset control 173 * @pfhndl: Device handle 174 * @rstctl: Device reset control handle 175 * 176 * This function will deactivate the reset control for the device 177 * 178 * Return: QDF_STATUS_SUCCESS on success 179 */ 180 static inline QDF_STATUS 181 __qal_vbus_deactivate_dev_rstctl(struct qdf_pfm_hndl *pfhndl, 182 struct qdf_vbus_rstctl *rstctl) 183 { 184 reset_control_deassert((struct reset_control *)rstctl); 185 return QDF_STATUS_SUCCESS; 186 } 187 188 /** 189 * __qal_vbus_get_resource() - get resource 190 * @pfhndl: Device handle 191 * @rsc: Resource handle 192 * @restype: Resource type 193 * @residx: Resource index 194 * 195 * This function will acquire a particular resource and attach it to the device 196 * 197 * Return: QDF_STATUS_SUCCESS on success 198 */ 199 static inline QDF_STATUS 200 __qal_vbus_get_resource(struct qdf_pfm_hndl *pfhndl, 201 struct qdf_vbus_resource **rsc, uint32_t restype, 202 uint32_t residx) 203 { 204 struct resource *rsrc; 205 206 rsrc = platform_get_resource((struct platform_device *)pfhndl, 207 restype, residx); 208 *rsc = (struct qdf_vbus_resource *)rsrc; 209 return QDF_STATUS_SUCCESS; 210 } 211 212 /** 213 * __qal_vbus_get_irq() - get irq 214 * @pfhndl: Device handle 215 * @str: Device identifier 216 * @irq: irq number 217 * 218 * This function will acquire an irq for the device 219 * 220 * Return: QDF_STATUS_SUCCESS on success 221 */ 222 static inline QDF_STATUS 223 __qal_vbus_get_irq(struct qdf_pfm_hndl *pfhndl, const char *str, int *irq) 224 { 225 *irq = platform_get_irq_byname((struct platform_device *)pfhndl, str); 226 227 if (*irq < 0) 228 return QDF_STATUS_E_FAULT; 229 230 return QDF_STATUS_SUCCESS; 231 } 232 233 /** 234 * __qal_vbus_register_driver() - register driver 235 * @pfdev: Device handle 236 * 237 * This function will initialize a device 238 * 239 * Return: QDF_STATUS_SUCCESS on success 240 */ 241 static inline QDF_STATUS 242 __qal_vbus_register_driver(struct qdf_pfm_drv *pfdev) 243 { 244 int ret; 245 246 ret = platform_driver_register((struct platform_driver *)pfdev); 247 248 return qdf_status_from_os_return(ret); 249 } 250 251 /** 252 * __qal_vbus_deregister_driver() - deregister driver 253 * @pfdev: Device handle 254 * 255 * This function will deregister the driver for a device 256 * 257 * Return: QDF_STATUS_SUCCESS on success 258 */ 259 static inline QDF_STATUS 260 __qal_vbus_deregister_driver(struct qdf_pfm_drv *pfdev) 261 { 262 platform_driver_unregister((struct platform_driver *)pfdev); 263 264 return QDF_STATUS_SUCCESS; 265 } 266 #endif /* __I_QAL_VBUS_DEV_H */ 267