void ap6210_gpio_init(void) { struct ap6210_gpio_wifi_ops *ops = &ap6210_wifi_select_pm_ops; int ap6210_lpo = 0; /* CT expected ap6210_lpo as a GPIO */ ap6210_lpo = gpio_request_ex(wifi_para, "ap6xxx_lpo"); if (!ap6210_lpo) { AP6210_ERR("request lpo gpio failed.\n" ); return; } if(ap6210_lpo) { AP6210_DEBUG("config 32k clock.\n" ); ap6210_cfg_gpio_32k_clkout(ap6210_lpo); } ap6210_wl_regon = gpio_request_ex(wifi_para, "ap6xxx_wl_regon"); if (!ap6210_wl_regon) { AP6210_ERR("request wl_regon gpio failed.\n" ); return; } ap6210_bt_regon = gpio_request_ex(wifi_para, "ap6xxx_bt_regon"); if (!ap6210_bt_regon) { AP6210_ERR("request ap6210_bt_regon gpio failed.\n" ); return; } ops->gpio_ctrl = ap6210_gpio_ctrl; ops->power = ap6210_power; }
static int ap6210_gpio_wifi_probe(struct platform_device *pdev) { struct ap6210_gpio_wifi_ops *ops = &ap6210_wifi_select_pm_ops; switch (ops->module_sel) { case 1: /* BCM40181 */ case 2: /* BCM40183 */ case 3: /* RTL8723AS */ case 4: /* RTL8189ES */ case 5: /* RTL8192CU */ case 6: /* RTL8188EU */ AP6210_ERR("Unsupported device.\n"); break; case 7: /* AP6210 */ case 8: /* AP6330 */ case 9: /* AP6181 */ AP6210_ERR("Initializing %s.\n", ops->mod_name); ap6210_gpio_init(); break; case 10: /* RTL8723AU */ AP6210_ERR("Unsupported device.\n"); break; default: AP6210_ERR("Unsupported device.\n"); } awwifi_procfs_attach(); AP6210_DEBUG("wifi gpio attached.\n" ); return 0; }
static int ap6210_gpio_read(char* name) { int i = 0; int gpio = 0; int val = 0; char * gpio_name[2] = {"ap6210_wl_regon", "ap6210_bt_regon"}; for (i = 0; i < 2; i++) { if (strcmp(name, gpio_name[i]) == 0) { switch (i) { case 0: /*ap6210_wl_regon*/ gpio = ap6210_wl_regon; break; case 1: /*ap6210_bt_regon*/ gpio = ap6210_bt_regon; break; default: AP6210_ERR("no matched gpio.\n" ); } break; } } val = gpio_read_one_pin_value(gpio, name); return val; }
static int ap6210_gpio_ctrl(char* name, int level) { int i = 0; int ret = 0; int gpio = 0; char * gpio_name[2] = {"ap6210_wl_regon", "ap6210_bt_regon"}; for (i = 0; i < 2; i++) { if (strcmp(name, gpio_name[i]) == 0) { switch (i) { case 0: /*ap6210_wl_regon*/ gpio = ap6210_wl_regon; break; case 1: /*ap6210_bt_regon*/ gpio = ap6210_bt_regon; break; default: AP6210_ERR("no matched gpio.\n" ); } break; } } ret = gpio_write_one_pin_value(gpio, level, name); return 0; }
int ap6210_gpio_wifi_gpio_ctrl(char* name, int level) { struct ap6210_gpio_wifi_ops *ops = &ap6210_wifi_select_pm_ops; if (ops->wifi_used && ops->gpio_ctrl) return ops->gpio_ctrl(name, level); else { AP6210_ERR("No wifi type selected, please check your config.\n" ); return -1; } }
int ap6210_gpio_wifi_get_mod_type(void) { struct ap6210_gpio_wifi_ops *ops = &ap6210_wifi_select_pm_ops; if (ops->wifi_used) return ops->module_sel; else { AP6210_ERR("No wifi type selected, please check your config.\n" ); return 0; } }
int wldev_set_country( struct net_device *dev, char *country_code) { int error = -1; wl_country_t cspec = {{0}, 0, {0}}; scb_val_t scbval; char smbuf[WLC_IOCTL_SMLEN]; if (!country_code) return error; error = wldev_iovar_getbuf(dev, "country", &cspec, sizeof(cspec), smbuf, sizeof(smbuf), NULL); if (error < 0) AP6210_ERR("%s: get country failed = %d\n", __FUNCTION__, error); if ((error < 0) || (strncmp(country_code, smbuf, WLC_CNTRY_BUF_SZ) != 0)) { bzero(&scbval, sizeof(scb_val_t)); error = wldev_ioctl(dev, WLC_DISASSOC, &scbval, sizeof(scb_val_t), true); if (error < 0) { AP6210_ERR("%s: set country failed due to Disassoc error %d\n", __FUNCTION__, error); return error; } cspec.rev = -1; memcpy(cspec.country_abbrev, country_code, WLC_CNTRY_BUF_SZ); memcpy(cspec.ccode, country_code, WLC_CNTRY_BUF_SZ); get_customized_country_code((char *)&cspec.country_abbrev, &cspec); error = wldev_iovar_setbuf(dev, "country", &cspec, sizeof(cspec), smbuf, sizeof(smbuf), NULL); if (error < 0) { AP6210_ERR("%s: set country for %s as %s rev %d failed\n", __FUNCTION__, country_code, cspec.ccode, cspec.rev); return error; } dhd_bus_country_set(dev, &cspec); AP6210_ERR("%s: set country for %s as %s rev %d\n", __FUNCTION__, country_code, cspec.ccode, cspec.rev); } return 0; }
static int ap6210_gpio_wifi_power_ctrl(struct file *file, const char __user *buffer, unsigned long count, void *data) { struct ap6210_gpio_wifi_ops *ops = (struct ap6210_gpio_wifi_ops *)data; int power = simple_strtoul(buffer, NULL, 10); power = power ? 1 : 0; if (ops->power) ops->power(1, &power); else AP6210_ERR("No power control for %s\n", ops->mod_name); return sizeof(power); }
void ap6210_gpio_wifi_power(int on) { struct ap6210_gpio_wifi_ops *ops = &ap6210_wifi_select_pm_ops; int power = on; if (ops->wifi_used && ops->power) return ops->power(1, &power); else { AP6210_ERR("No wifi type selected, please check your config.\n" ); return; } }
static int ap6210_gpio_wifi_get_res(void) { struct ap6210_gpio_wifi_ops *ops = &ap6210_wifi_select_pm_ops; if (SCRIPT_PARSER_OK != script_parser_fetch(wifi_para, "wifi_used", &ops->wifi_used, 1)) { AP6210_ERR("parse wifi_used failed in script.fex.\n" ); return -1; } if (!ops->wifi_used) { AP6210_ERR("wifi pm disable in script.fex.\n" ); return -1; } if (SCRIPT_PARSER_OK != script_parser_fetch(wifi_para, "wifi_sdc_id", &ops->sdio_id, 1)) { AP6210_ERR("parse wifi_sdc_id in script.fex failed.\n" ); return -1; } if (SCRIPT_PARSER_OK != script_parser_fetch(wifi_para, "wifi_usbc_id", &ops->usb_id, 1)) { AP6210_ERR("parse wifi_sdc_id in script.fex failed.\n" ); return -1; } if (SCRIPT_PARSER_OK != script_parser_fetch(wifi_para, "wifi_mod_sel", &ops->module_sel, 1)) { AP6210_ERR("parse wifi_sdc_id in script.fex failed.\n" ); return -1; } ops->mod_name = ap6210_gpio_wifi_get_name(ops->module_sel); AP6210_ERR("select wifi %s\n", ops->mod_name); return 0; }
static inline void awwifi_procfs_attach(void) { char proc_rootname[] = "driver/ap6210_gpio_wifi"; char proc_powername[] = "power"; struct ap6210_gpio_wifi_ops *ops = &ap6210_wifi_select_pm_ops; ops->proc_root = proc_mkdir(proc_rootname, NULL); if (IS_ERR(ops->proc_root)) { AP6210_ERR("failed to create procfs \"%s\".\n", proc_rootname ); } ops->proc_power = proc_create(proc_powername, 0644, ops->proc_root, NULL); if (IS_ERR(ops->proc_power)) { AP6210_ERR("failed to create procfs \"%s\".\n", proc_powername); } ops->proc_power->data = ops; ops->proc_power->read_proc = ap6210_gpio_wifi_power_stat; ops->proc_power->write_proc = ap6210_gpio_wifi_power_ctrl; }
static void ap6210_cfg_gpio_32k_clkout(int gpio_index) { int ret; struct clk *clk_32k, *parent; parent = clk_get(NULL, CLK_SYS_LOSC); clk_32k = clk_get(NULL, CLK_MOD_OUTA); ret = clk_set_parent(clk_32k, parent); if(ret){ AP6210_ERR("32k clk_set_parent fail.\n" ); return; } ret = clk_set_rate(clk_32k, 32768); if(ret){ AP6210_ERR("32k clk_set_rate fail.\n" ); return; } clk_enable(clk_32k); }
/** Format a bsscfg indexed iovar buffer. The bsscfg index will be * taken care of in dhd_ioctl_entry. Internal use only, not exposed to * wl_iw, wl_cfg80211 and wl_cfgp2p */ s32 wldev_mkiovar_bsscfg( const s8 *iovar_name, s8 *param, s32 paramlen, s8 *iovar_buf, s32 buflen, s32 bssidx) { const s8 *prefix = "bsscfg:"; s8 *p; u32 prefixlen; u32 namelen; u32 iolen; if (bssidx == 0) { return wldev_mkiovar((s8*)iovar_name, (s8 *)param, paramlen, (s8 *) iovar_buf, buflen); } prefixlen = (u32) strlen(prefix); /* lengh of bsscfg prefix */ namelen = (u32) strlen(iovar_name) + 1; /* lengh of iovar name + null */ iolen = prefixlen + namelen + sizeof(u32) + paramlen; if (buflen < 0 || iolen > (u32)buflen) { AP6210_ERR("%s: buffer is too short\n", __FUNCTION__); return BCME_BUFTOOSHORT; } p = (s8 *)iovar_buf; /* copy prefix, no null */ memcpy(p, prefix, prefixlen); p += prefixlen; /* copy iovar name including null */ memcpy(p, iovar_name, namelen); p += namelen; /* bss config index as first param */ bssidx = htod32(bssidx); memcpy(p, &bssidx, sizeof(u32)); p += sizeof(u32); /* parameter buffer follows */ if (paramlen) memcpy(p, param, paramlen); return iolen; }