2 * Copyright (C) 2011-2014 MediaTek Inc.
4 * This program is free software: you can redistribute it and/or modify it under the terms of the
5 * GNU General Public License version 2 as published by the Free Software Foundation.
7 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
8 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
9 * See the GNU General Public License for more details.
11 * You should have received a copy of the GNU General Public License along with this program.
12 * If not, see <http://www.gnu.org/licenses/>.
15 #include <mach/mtk_wcn_cmb_stub.h>
22 #define DFT_TAG "[WMT-DETECT]"
24 #include "wmt_detect.h"
27 #include "conn_drv_init.h"
32 #define WMT_DETECT_MAJOR 154
33 #define WMT_DETECT_DEV_NUM 1
34 #define WMT_DETECT_DRVIER_NAME "mtk_wcn_detect"
35 #define WMT_DETECT_DEVICE_NAME "wmtdetect"
37 struct class *pDetectClass
= NULL
;
38 struct device
*pDetectDev
= NULL
;
39 static int gWmtDetectMajor
= WMT_DETECT_MAJOR
;
40 static struct cdev gWmtDetectCdev
;
41 unsigned int gWmtDetectDbgLvl
= WMT_DETECT_LOG_INFO
;
43 #ifdef MTK_WCN_SOC_CHIP_SUPPORT
44 extern unsigned int wmt_plat_get_soc_chipid(void);
46 extern unsigned int wmt_plat_get_soc_chipid(void)
48 WMT_DETECT_INFO_FUNC("no soc chip supported, due to MTK_WCN_SOC_CHIP_SUPPORT is not set.\n");
53 static int wmt_detect_open(struct inode
*inode
, struct file
*file
)
55 WMT_DETECT_INFO_FUNC("open major %d minor %d (pid %d)\n",
64 static int wmt_detect_close(struct inode
*inode
, struct file
*file
)
66 WMT_DETECT_INFO_FUNC("close major %d minor %d (pid %d)\n",
76 static ssize_t
wmt_detect_read(struct file
*filp
, char __user
*buf
, size_t count
, loff_t
*f_pos
)
79 WMT_DETECT_INFO_FUNC(" ++\n");
80 WMT_DETECT_INFO_FUNC(" --\n");
88 const char __user
*buf
,
93 WMT_DETECT_INFO_FUNC(" ++\n");
94 WMT_DETECT_INFO_FUNC(" --\n");
99 static long wmt_detect_unlocked_ioctl(struct file
*filp
, unsigned int cmd
, unsigned long arg
)
103 WMT_DETECT_INFO_FUNC("cmd (%d),arg(%ld)\n", cmd
,arg
);
106 case COMBO_IOCTL_GET_CHIP_ID
:
107 /*just get chipid from sdio-detect module*/
108 /*check if external combo chip exists or not*/
109 /*if yes, just return combo chip id*/
110 /*if no, get soc chipid*/
111 retval
= mtk_wcn_wmt_chipid_query();
114 case COMBO_IOCTL_SET_CHIP_ID
:
115 mtk_wcn_wmt_set_chipid(arg
);
119 case COMBO_IOCTL_EXT_CHIP_PWR_ON
:
120 retval
= wmt_detect_ext_chip_pwr_on();
123 case COMBO_IOCTL_EXT_CHIP_DETECT
:
124 retval
= wmt_detect_ext_chip_detect();
127 case COMBO_IOCTL_EXT_CHIP_PWR_OFF
:
128 retval
= wmt_detect_ext_chip_pwr_off();
131 case COMBO_IOCTL_DO_SDIO_AUDOK
:
132 retval
= sdio_detect_do_autok(arg
);
135 case COMBO_IOCTL_GET_SOC_CHIP_ID
:
136 retval
= wmt_plat_get_soc_chipid();
137 /*get soc chipid by HAL interface*/
140 case COMBO_IOCTL_MODULE_CLEANUP
:
141 #if (MTK_WCN_REMOVE_KO)
142 /*deinit SDIO-DETECT module*/
143 retval
= sdio_detect_exit();
145 WMT_DETECT_INFO_FUNC("no MTK_WCN_REMOVE_KO defined\n");
149 case COMBO_IOCTL_DO_MODULE_INIT
:
150 #if (MTK_WCN_REMOVE_KO)
151 /*deinit SDIO-DETECT module*/
152 retval
= do_connectivity_driver_init(arg
);
154 WMT_DETECT_INFO_FUNC("no MTK_WCN_REMOVE_KO defined\n");
159 WMT_DETECT_WARN_FUNC("unknown cmd (%d)\n", cmd
);
166 struct file_operations gWmtDetectFops
= {
167 .open
= wmt_detect_open
,
168 .release
= wmt_detect_close
,
169 .read
= wmt_detect_read
,
170 .write
= wmt_detect_write
,
171 .unlocked_ioctl
= wmt_detect_unlocked_ioctl
,
174 int wmt_detect_ext_chip_pwr_on(void)
176 /*pre power on external chip*/
177 //wmt_plat_pwr_ctrl(FUNC_ON);
178 WMT_DETECT_INFO_FUNC("++\n");
179 if (0 != wmt_detect_chip_pwr_ctrl(1))
183 if (0 != wmt_detect_sdio_pwr_ctrl(1))
190 int wmt_detect_ext_chip_pwr_off(void)
192 /*pre power off external chip*/
193 //wmt_plat_pwr_ctrl(FUNC_OFF);
194 WMT_DETECT_INFO_FUNC("--\n");
195 wmt_detect_sdio_pwr_ctrl(0);
196 return wmt_detect_chip_pwr_ctrl(0);
199 int wmt_detect_ext_chip_detect(void)
202 unsigned int chipId
= -1;
203 /*if there is no external combo chip, return -1*/
204 int bgfEintStatus
= -1;
205 WMT_DETECT_INFO_FUNC("++\n");
206 /*wait for a stable time*/
209 /*read BGF_EINT_PIN status*/
210 bgfEintStatus
= wmt_detect_read_ext_cmb_status();;
212 if (0 == bgfEintStatus
)
214 /*external chip does not exist*/
215 WMT_DETECT_INFO_FUNC("external combo chip not detected\n");
217 else if (1 == bgfEintStatus
)
219 /*combo chip exists*/
220 WMT_DETECT_INFO_FUNC("external combo chip detected\n");
222 /*detect chipid by sdio_detect module*/
223 chipId
= sdio_detect_query_chipid(1);
224 if (0 <= hif_sdio_is_chipid_valid(chipId
))
226 WMT_DETECT_INFO_FUNC("valid external combo chip id (0x%x)\n", chipId
);
230 WMT_DETECT_INFO_FUNC("invalid external combo chip id (0x%x)\n", chipId
);
237 WMT_DETECT_ERR_FUNC("error happens when detecting combo chip\n");
239 WMT_DETECT_INFO_FUNC("--\n");
243 /*todo: if there is external combo chip, power on chip return 0*/
245 static int wmt_detect_init(void)
247 dev_t devID
= MKDEV(gWmtDetectMajor
, 0);
251 ret
= register_chrdev_region(devID
, WMT_DETECT_DEV_NUM
, WMT_DETECT_DRVIER_NAME
);
253 WMT_DETECT_ERR_FUNC("fail to register chrdev\n");
257 cdev_init(&gWmtDetectCdev
, &gWmtDetectFops
);
258 gWmtDetectCdev
.owner
= THIS_MODULE
;
260 cdevErr
= cdev_add(&gWmtDetectCdev
, devID
, WMT_DETECT_DEV_NUM
);
262 WMT_DETECT_ERR_FUNC("cdev_add() fails (%d) \n", cdevErr
);
266 pDetectClass
= class_create(THIS_MODULE
, WMT_DETECT_DEVICE_NAME
);
267 if(IS_ERR(pDetectClass
))
269 WMT_DETECT_ERR_FUNC("class create fail, error code(%ld)\n",PTR_ERR(pDetectClass
));
273 pDetectDev
= device_create(pDetectClass
,NULL
,devID
,NULL
,WMT_DETECT_DEVICE_NAME
);
274 if(IS_ERR(pDetectDev
))
276 WMT_DETECT_ERR_FUNC("device create fail, error code(%ld)\n",PTR_ERR(pDetectDev
));
280 WMT_DETECT_INFO_FUNC("driver(major %d) installed success\n", gWmtDetectMajor
);
282 /*init SDIO-DETECT module*/
291 class_destroy(pDetectClass
);
298 cdev_del(&gWmtDetectCdev
);
302 unregister_chrdev_region(devID
, WMT_DETECT_DEV_NUM
);
303 gWmtDetectMajor
= -1;
306 WMT_DETECT_ERR_FUNC("fail \n");
311 static void wmt_detect_exit (void)
313 dev_t dev
= MKDEV(gWmtDetectMajor
, 0);
317 device_destroy(pDetectClass
, dev
);
323 class_destroy(pDetectClass
);
327 cdev_del(&gWmtDetectCdev
);
328 unregister_chrdev_region(dev
, WMT_DETECT_DEV_NUM
);
330 #if !(MTK_WCN_REMOVE_KO)
331 /*deinit SDIO-DETECT module*/
335 WMT_DETECT_INFO_FUNC("done\n");
338 module_init(wmt_detect_init
);
339 module_exit(wmt_detect_exit
);
341 MODULE_LICENSE("GPL");
342 MODULE_AUTHOR("Zhiguo.Niu & Chaozhong.Liang @ MBJ/WCNSE/SS1");
344 module_param(gWmtDetectMajor
, uint
, 0);