18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-only 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * Mac80211 SDIO driver for ST-Ericsson CW1200 device 48c2ecf20Sopenharmony_ci * 58c2ecf20Sopenharmony_ci * Copyright (c) 2010, ST-Ericsson 68c2ecf20Sopenharmony_ci * Author: Dmitry Tarnyagin <dmitry.tarnyagin@lockless.no> 78c2ecf20Sopenharmony_ci */ 88c2ecf20Sopenharmony_ci 98c2ecf20Sopenharmony_ci#include <linux/module.h> 108c2ecf20Sopenharmony_ci#include <linux/interrupt.h> 118c2ecf20Sopenharmony_ci#include <linux/gpio.h> 128c2ecf20Sopenharmony_ci#include <linux/delay.h> 138c2ecf20Sopenharmony_ci#include <linux/mmc/host.h> 148c2ecf20Sopenharmony_ci#include <linux/mmc/sdio_func.h> 158c2ecf20Sopenharmony_ci#include <linux/mmc/card.h> 168c2ecf20Sopenharmony_ci#include <linux/mmc/sdio.h> 178c2ecf20Sopenharmony_ci#include <linux/mmc/sdio_ids.h> 188c2ecf20Sopenharmony_ci#include <net/mac80211.h> 198c2ecf20Sopenharmony_ci 208c2ecf20Sopenharmony_ci#include "cw1200.h" 218c2ecf20Sopenharmony_ci#include "hwbus.h" 228c2ecf20Sopenharmony_ci#include <linux/platform_data/net-cw1200.h> 238c2ecf20Sopenharmony_ci#include "hwio.h" 248c2ecf20Sopenharmony_ci 258c2ecf20Sopenharmony_ciMODULE_AUTHOR("Dmitry Tarnyagin <dmitry.tarnyagin@lockless.no>"); 268c2ecf20Sopenharmony_ciMODULE_DESCRIPTION("mac80211 ST-Ericsson CW1200 SDIO driver"); 278c2ecf20Sopenharmony_ciMODULE_LICENSE("GPL"); 288c2ecf20Sopenharmony_ci 298c2ecf20Sopenharmony_ci#define SDIO_BLOCK_SIZE (512) 308c2ecf20Sopenharmony_ci 318c2ecf20Sopenharmony_ci/* Default platform data for Sagrad modules */ 328c2ecf20Sopenharmony_cistatic struct cw1200_platform_data_sdio sagrad_109x_evk_platform_data = { 338c2ecf20Sopenharmony_ci .ref_clk = 38400, 348c2ecf20Sopenharmony_ci .have_5ghz = false, 358c2ecf20Sopenharmony_ci .sdd_file = "sdd_sagrad_1091_1098.bin", 368c2ecf20Sopenharmony_ci}; 378c2ecf20Sopenharmony_ci 388c2ecf20Sopenharmony_ci/* Allow platform data to be overridden */ 398c2ecf20Sopenharmony_cistatic struct cw1200_platform_data_sdio *global_plat_data = &sagrad_109x_evk_platform_data; 408c2ecf20Sopenharmony_ci 418c2ecf20Sopenharmony_civoid __init cw1200_sdio_set_platform_data(struct cw1200_platform_data_sdio *pdata) 428c2ecf20Sopenharmony_ci{ 438c2ecf20Sopenharmony_ci global_plat_data = pdata; 448c2ecf20Sopenharmony_ci} 458c2ecf20Sopenharmony_ci 468c2ecf20Sopenharmony_cistruct hwbus_priv { 478c2ecf20Sopenharmony_ci struct sdio_func *func; 488c2ecf20Sopenharmony_ci struct cw1200_common *core; 498c2ecf20Sopenharmony_ci const struct cw1200_platform_data_sdio *pdata; 508c2ecf20Sopenharmony_ci}; 518c2ecf20Sopenharmony_ci 528c2ecf20Sopenharmony_cistatic const struct sdio_device_id cw1200_sdio_ids[] = { 538c2ecf20Sopenharmony_ci { SDIO_DEVICE(SDIO_VENDOR_ID_STE, SDIO_DEVICE_ID_STE_CW1200) }, 548c2ecf20Sopenharmony_ci { /* end: all zeroes */ }, 558c2ecf20Sopenharmony_ci}; 568c2ecf20Sopenharmony_ciMODULE_DEVICE_TABLE(sdio, cw1200_sdio_ids); 578c2ecf20Sopenharmony_ci 588c2ecf20Sopenharmony_ci/* hwbus_ops implemetation */ 598c2ecf20Sopenharmony_ci 608c2ecf20Sopenharmony_cistatic int cw1200_sdio_memcpy_fromio(struct hwbus_priv *self, 618c2ecf20Sopenharmony_ci unsigned int addr, 628c2ecf20Sopenharmony_ci void *dst, int count) 638c2ecf20Sopenharmony_ci{ 648c2ecf20Sopenharmony_ci return sdio_memcpy_fromio(self->func, dst, addr, count); 658c2ecf20Sopenharmony_ci} 668c2ecf20Sopenharmony_ci 678c2ecf20Sopenharmony_cistatic int cw1200_sdio_memcpy_toio(struct hwbus_priv *self, 688c2ecf20Sopenharmony_ci unsigned int addr, 698c2ecf20Sopenharmony_ci const void *src, int count) 708c2ecf20Sopenharmony_ci{ 718c2ecf20Sopenharmony_ci return sdio_memcpy_toio(self->func, addr, (void *)src, count); 728c2ecf20Sopenharmony_ci} 738c2ecf20Sopenharmony_ci 748c2ecf20Sopenharmony_cistatic void cw1200_sdio_lock(struct hwbus_priv *self) 758c2ecf20Sopenharmony_ci{ 768c2ecf20Sopenharmony_ci sdio_claim_host(self->func); 778c2ecf20Sopenharmony_ci} 788c2ecf20Sopenharmony_ci 798c2ecf20Sopenharmony_cistatic void cw1200_sdio_unlock(struct hwbus_priv *self) 808c2ecf20Sopenharmony_ci{ 818c2ecf20Sopenharmony_ci sdio_release_host(self->func); 828c2ecf20Sopenharmony_ci} 838c2ecf20Sopenharmony_ci 848c2ecf20Sopenharmony_cistatic void cw1200_sdio_irq_handler(struct sdio_func *func) 858c2ecf20Sopenharmony_ci{ 868c2ecf20Sopenharmony_ci struct hwbus_priv *self = sdio_get_drvdata(func); 878c2ecf20Sopenharmony_ci 888c2ecf20Sopenharmony_ci /* note: sdio_host already claimed here. */ 898c2ecf20Sopenharmony_ci if (self->core) 908c2ecf20Sopenharmony_ci cw1200_irq_handler(self->core); 918c2ecf20Sopenharmony_ci} 928c2ecf20Sopenharmony_ci 938c2ecf20Sopenharmony_cistatic irqreturn_t cw1200_gpio_hardirq(int irq, void *dev_id) 948c2ecf20Sopenharmony_ci{ 958c2ecf20Sopenharmony_ci return IRQ_WAKE_THREAD; 968c2ecf20Sopenharmony_ci} 978c2ecf20Sopenharmony_ci 988c2ecf20Sopenharmony_cistatic irqreturn_t cw1200_gpio_irq(int irq, void *dev_id) 998c2ecf20Sopenharmony_ci{ 1008c2ecf20Sopenharmony_ci struct hwbus_priv *self = dev_id; 1018c2ecf20Sopenharmony_ci 1028c2ecf20Sopenharmony_ci if (self->core) { 1038c2ecf20Sopenharmony_ci cw1200_sdio_lock(self); 1048c2ecf20Sopenharmony_ci cw1200_irq_handler(self->core); 1058c2ecf20Sopenharmony_ci cw1200_sdio_unlock(self); 1068c2ecf20Sopenharmony_ci return IRQ_HANDLED; 1078c2ecf20Sopenharmony_ci } else { 1088c2ecf20Sopenharmony_ci return IRQ_NONE; 1098c2ecf20Sopenharmony_ci } 1108c2ecf20Sopenharmony_ci} 1118c2ecf20Sopenharmony_ci 1128c2ecf20Sopenharmony_cistatic int cw1200_request_irq(struct hwbus_priv *self) 1138c2ecf20Sopenharmony_ci{ 1148c2ecf20Sopenharmony_ci int ret; 1158c2ecf20Sopenharmony_ci u8 cccr; 1168c2ecf20Sopenharmony_ci 1178c2ecf20Sopenharmony_ci cccr = sdio_f0_readb(self->func, SDIO_CCCR_IENx, &ret); 1188c2ecf20Sopenharmony_ci if (WARN_ON(ret)) 1198c2ecf20Sopenharmony_ci goto err; 1208c2ecf20Sopenharmony_ci 1218c2ecf20Sopenharmony_ci /* Master interrupt enable ... */ 1228c2ecf20Sopenharmony_ci cccr |= BIT(0); 1238c2ecf20Sopenharmony_ci 1248c2ecf20Sopenharmony_ci /* ... for our function */ 1258c2ecf20Sopenharmony_ci cccr |= BIT(self->func->num); 1268c2ecf20Sopenharmony_ci 1278c2ecf20Sopenharmony_ci sdio_f0_writeb(self->func, cccr, SDIO_CCCR_IENx, &ret); 1288c2ecf20Sopenharmony_ci if (WARN_ON(ret)) 1298c2ecf20Sopenharmony_ci goto err; 1308c2ecf20Sopenharmony_ci 1318c2ecf20Sopenharmony_ci ret = enable_irq_wake(self->pdata->irq); 1328c2ecf20Sopenharmony_ci if (WARN_ON(ret)) 1338c2ecf20Sopenharmony_ci goto err; 1348c2ecf20Sopenharmony_ci 1358c2ecf20Sopenharmony_ci /* Request the IRQ */ 1368c2ecf20Sopenharmony_ci ret = request_threaded_irq(self->pdata->irq, cw1200_gpio_hardirq, 1378c2ecf20Sopenharmony_ci cw1200_gpio_irq, 1388c2ecf20Sopenharmony_ci IRQF_TRIGGER_HIGH | IRQF_ONESHOT, 1398c2ecf20Sopenharmony_ci "cw1200_wlan_irq", self); 1408c2ecf20Sopenharmony_ci if (WARN_ON(ret)) 1418c2ecf20Sopenharmony_ci goto err; 1428c2ecf20Sopenharmony_ci 1438c2ecf20Sopenharmony_ci return 0; 1448c2ecf20Sopenharmony_ci 1458c2ecf20Sopenharmony_cierr: 1468c2ecf20Sopenharmony_ci return ret; 1478c2ecf20Sopenharmony_ci} 1488c2ecf20Sopenharmony_ci 1498c2ecf20Sopenharmony_cistatic int cw1200_sdio_irq_subscribe(struct hwbus_priv *self) 1508c2ecf20Sopenharmony_ci{ 1518c2ecf20Sopenharmony_ci int ret = 0; 1528c2ecf20Sopenharmony_ci 1538c2ecf20Sopenharmony_ci pr_debug("SW IRQ subscribe\n"); 1548c2ecf20Sopenharmony_ci sdio_claim_host(self->func); 1558c2ecf20Sopenharmony_ci if (self->pdata->irq) 1568c2ecf20Sopenharmony_ci ret = cw1200_request_irq(self); 1578c2ecf20Sopenharmony_ci else 1588c2ecf20Sopenharmony_ci ret = sdio_claim_irq(self->func, cw1200_sdio_irq_handler); 1598c2ecf20Sopenharmony_ci 1608c2ecf20Sopenharmony_ci sdio_release_host(self->func); 1618c2ecf20Sopenharmony_ci return ret; 1628c2ecf20Sopenharmony_ci} 1638c2ecf20Sopenharmony_ci 1648c2ecf20Sopenharmony_cistatic int cw1200_sdio_irq_unsubscribe(struct hwbus_priv *self) 1658c2ecf20Sopenharmony_ci{ 1668c2ecf20Sopenharmony_ci int ret = 0; 1678c2ecf20Sopenharmony_ci 1688c2ecf20Sopenharmony_ci pr_debug("SW IRQ unsubscribe\n"); 1698c2ecf20Sopenharmony_ci 1708c2ecf20Sopenharmony_ci if (self->pdata->irq) { 1718c2ecf20Sopenharmony_ci disable_irq_wake(self->pdata->irq); 1728c2ecf20Sopenharmony_ci free_irq(self->pdata->irq, self); 1738c2ecf20Sopenharmony_ci } else { 1748c2ecf20Sopenharmony_ci sdio_claim_host(self->func); 1758c2ecf20Sopenharmony_ci ret = sdio_release_irq(self->func); 1768c2ecf20Sopenharmony_ci sdio_release_host(self->func); 1778c2ecf20Sopenharmony_ci } 1788c2ecf20Sopenharmony_ci return ret; 1798c2ecf20Sopenharmony_ci} 1808c2ecf20Sopenharmony_ci 1818c2ecf20Sopenharmony_cistatic int cw1200_sdio_off(const struct cw1200_platform_data_sdio *pdata) 1828c2ecf20Sopenharmony_ci{ 1838c2ecf20Sopenharmony_ci if (pdata->reset) { 1848c2ecf20Sopenharmony_ci gpio_set_value(pdata->reset, 0); 1858c2ecf20Sopenharmony_ci msleep(30); /* Min is 2 * CLK32K cycles */ 1868c2ecf20Sopenharmony_ci gpio_free(pdata->reset); 1878c2ecf20Sopenharmony_ci } 1888c2ecf20Sopenharmony_ci 1898c2ecf20Sopenharmony_ci if (pdata->power_ctrl) 1908c2ecf20Sopenharmony_ci pdata->power_ctrl(pdata, false); 1918c2ecf20Sopenharmony_ci if (pdata->clk_ctrl) 1928c2ecf20Sopenharmony_ci pdata->clk_ctrl(pdata, false); 1938c2ecf20Sopenharmony_ci 1948c2ecf20Sopenharmony_ci return 0; 1958c2ecf20Sopenharmony_ci} 1968c2ecf20Sopenharmony_ci 1978c2ecf20Sopenharmony_cistatic int cw1200_sdio_on(const struct cw1200_platform_data_sdio *pdata) 1988c2ecf20Sopenharmony_ci{ 1998c2ecf20Sopenharmony_ci /* Ensure I/Os are pulled low */ 2008c2ecf20Sopenharmony_ci if (pdata->reset) { 2018c2ecf20Sopenharmony_ci gpio_request(pdata->reset, "cw1200_wlan_reset"); 2028c2ecf20Sopenharmony_ci gpio_direction_output(pdata->reset, 0); 2038c2ecf20Sopenharmony_ci } 2048c2ecf20Sopenharmony_ci if (pdata->powerup) { 2058c2ecf20Sopenharmony_ci gpio_request(pdata->powerup, "cw1200_wlan_powerup"); 2068c2ecf20Sopenharmony_ci gpio_direction_output(pdata->powerup, 0); 2078c2ecf20Sopenharmony_ci } 2088c2ecf20Sopenharmony_ci if (pdata->reset || pdata->powerup) 2098c2ecf20Sopenharmony_ci msleep(10); /* Settle time? */ 2108c2ecf20Sopenharmony_ci 2118c2ecf20Sopenharmony_ci /* Enable 3v3 and 1v8 to hardware */ 2128c2ecf20Sopenharmony_ci if (pdata->power_ctrl) { 2138c2ecf20Sopenharmony_ci if (pdata->power_ctrl(pdata, true)) { 2148c2ecf20Sopenharmony_ci pr_err("power_ctrl() failed!\n"); 2158c2ecf20Sopenharmony_ci return -1; 2168c2ecf20Sopenharmony_ci } 2178c2ecf20Sopenharmony_ci } 2188c2ecf20Sopenharmony_ci 2198c2ecf20Sopenharmony_ci /* Enable CLK32K */ 2208c2ecf20Sopenharmony_ci if (pdata->clk_ctrl) { 2218c2ecf20Sopenharmony_ci if (pdata->clk_ctrl(pdata, true)) { 2228c2ecf20Sopenharmony_ci pr_err("clk_ctrl() failed!\n"); 2238c2ecf20Sopenharmony_ci return -1; 2248c2ecf20Sopenharmony_ci } 2258c2ecf20Sopenharmony_ci msleep(10); /* Delay until clock is stable for 2 cycles */ 2268c2ecf20Sopenharmony_ci } 2278c2ecf20Sopenharmony_ci 2288c2ecf20Sopenharmony_ci /* Enable POWERUP signal */ 2298c2ecf20Sopenharmony_ci if (pdata->powerup) { 2308c2ecf20Sopenharmony_ci gpio_set_value(pdata->powerup, 1); 2318c2ecf20Sopenharmony_ci msleep(250); /* or more..? */ 2328c2ecf20Sopenharmony_ci } 2338c2ecf20Sopenharmony_ci /* Enable RSTn signal */ 2348c2ecf20Sopenharmony_ci if (pdata->reset) { 2358c2ecf20Sopenharmony_ci gpio_set_value(pdata->reset, 1); 2368c2ecf20Sopenharmony_ci msleep(50); /* Or more..? */ 2378c2ecf20Sopenharmony_ci } 2388c2ecf20Sopenharmony_ci return 0; 2398c2ecf20Sopenharmony_ci} 2408c2ecf20Sopenharmony_ci 2418c2ecf20Sopenharmony_cistatic size_t cw1200_sdio_align_size(struct hwbus_priv *self, size_t size) 2428c2ecf20Sopenharmony_ci{ 2438c2ecf20Sopenharmony_ci if (self->pdata->no_nptb) 2448c2ecf20Sopenharmony_ci size = round_up(size, SDIO_BLOCK_SIZE); 2458c2ecf20Sopenharmony_ci else 2468c2ecf20Sopenharmony_ci size = sdio_align_size(self->func, size); 2478c2ecf20Sopenharmony_ci 2488c2ecf20Sopenharmony_ci return size; 2498c2ecf20Sopenharmony_ci} 2508c2ecf20Sopenharmony_ci 2518c2ecf20Sopenharmony_cistatic int cw1200_sdio_pm(struct hwbus_priv *self, bool suspend) 2528c2ecf20Sopenharmony_ci{ 2538c2ecf20Sopenharmony_ci int ret = 0; 2548c2ecf20Sopenharmony_ci 2558c2ecf20Sopenharmony_ci if (self->pdata->irq) 2568c2ecf20Sopenharmony_ci ret = irq_set_irq_wake(self->pdata->irq, suspend); 2578c2ecf20Sopenharmony_ci return ret; 2588c2ecf20Sopenharmony_ci} 2598c2ecf20Sopenharmony_ci 2608c2ecf20Sopenharmony_cistatic const struct hwbus_ops cw1200_sdio_hwbus_ops = { 2618c2ecf20Sopenharmony_ci .hwbus_memcpy_fromio = cw1200_sdio_memcpy_fromio, 2628c2ecf20Sopenharmony_ci .hwbus_memcpy_toio = cw1200_sdio_memcpy_toio, 2638c2ecf20Sopenharmony_ci .lock = cw1200_sdio_lock, 2648c2ecf20Sopenharmony_ci .unlock = cw1200_sdio_unlock, 2658c2ecf20Sopenharmony_ci .align_size = cw1200_sdio_align_size, 2668c2ecf20Sopenharmony_ci .power_mgmt = cw1200_sdio_pm, 2678c2ecf20Sopenharmony_ci}; 2688c2ecf20Sopenharmony_ci 2698c2ecf20Sopenharmony_ci/* Probe Function to be called by SDIO stack when device is discovered */ 2708c2ecf20Sopenharmony_cistatic int cw1200_sdio_probe(struct sdio_func *func, 2718c2ecf20Sopenharmony_ci const struct sdio_device_id *id) 2728c2ecf20Sopenharmony_ci{ 2738c2ecf20Sopenharmony_ci struct hwbus_priv *self; 2748c2ecf20Sopenharmony_ci int status; 2758c2ecf20Sopenharmony_ci 2768c2ecf20Sopenharmony_ci pr_info("cw1200_wlan_sdio: Probe called\n"); 2778c2ecf20Sopenharmony_ci 2788c2ecf20Sopenharmony_ci /* We are only able to handle the wlan function */ 2798c2ecf20Sopenharmony_ci if (func->num != 0x01) 2808c2ecf20Sopenharmony_ci return -ENODEV; 2818c2ecf20Sopenharmony_ci 2828c2ecf20Sopenharmony_ci self = kzalloc(sizeof(*self), GFP_KERNEL); 2838c2ecf20Sopenharmony_ci if (!self) { 2848c2ecf20Sopenharmony_ci pr_err("Can't allocate SDIO hwbus_priv.\n"); 2858c2ecf20Sopenharmony_ci return -ENOMEM; 2868c2ecf20Sopenharmony_ci } 2878c2ecf20Sopenharmony_ci 2888c2ecf20Sopenharmony_ci func->card->quirks |= MMC_QUIRK_LENIENT_FN0; 2898c2ecf20Sopenharmony_ci 2908c2ecf20Sopenharmony_ci self->pdata = global_plat_data; /* FIXME */ 2918c2ecf20Sopenharmony_ci self->func = func; 2928c2ecf20Sopenharmony_ci sdio_set_drvdata(func, self); 2938c2ecf20Sopenharmony_ci sdio_claim_host(func); 2948c2ecf20Sopenharmony_ci sdio_enable_func(func); 2958c2ecf20Sopenharmony_ci sdio_release_host(func); 2968c2ecf20Sopenharmony_ci 2978c2ecf20Sopenharmony_ci status = cw1200_sdio_irq_subscribe(self); 2988c2ecf20Sopenharmony_ci 2998c2ecf20Sopenharmony_ci status = cw1200_core_probe(&cw1200_sdio_hwbus_ops, 3008c2ecf20Sopenharmony_ci self, &func->dev, &self->core, 3018c2ecf20Sopenharmony_ci self->pdata->ref_clk, 3028c2ecf20Sopenharmony_ci self->pdata->macaddr, 3038c2ecf20Sopenharmony_ci self->pdata->sdd_file, 3048c2ecf20Sopenharmony_ci self->pdata->have_5ghz); 3058c2ecf20Sopenharmony_ci if (status) { 3068c2ecf20Sopenharmony_ci cw1200_sdio_irq_unsubscribe(self); 3078c2ecf20Sopenharmony_ci sdio_claim_host(func); 3088c2ecf20Sopenharmony_ci sdio_disable_func(func); 3098c2ecf20Sopenharmony_ci sdio_release_host(func); 3108c2ecf20Sopenharmony_ci sdio_set_drvdata(func, NULL); 3118c2ecf20Sopenharmony_ci kfree(self); 3128c2ecf20Sopenharmony_ci } 3138c2ecf20Sopenharmony_ci 3148c2ecf20Sopenharmony_ci return status; 3158c2ecf20Sopenharmony_ci} 3168c2ecf20Sopenharmony_ci 3178c2ecf20Sopenharmony_ci/* Disconnect Function to be called by SDIO stack when 3188c2ecf20Sopenharmony_ci * device is disconnected 3198c2ecf20Sopenharmony_ci */ 3208c2ecf20Sopenharmony_cistatic void cw1200_sdio_disconnect(struct sdio_func *func) 3218c2ecf20Sopenharmony_ci{ 3228c2ecf20Sopenharmony_ci struct hwbus_priv *self = sdio_get_drvdata(func); 3238c2ecf20Sopenharmony_ci 3248c2ecf20Sopenharmony_ci if (self) { 3258c2ecf20Sopenharmony_ci cw1200_sdio_irq_unsubscribe(self); 3268c2ecf20Sopenharmony_ci if (self->core) { 3278c2ecf20Sopenharmony_ci cw1200_core_release(self->core); 3288c2ecf20Sopenharmony_ci self->core = NULL; 3298c2ecf20Sopenharmony_ci } 3308c2ecf20Sopenharmony_ci sdio_claim_host(func); 3318c2ecf20Sopenharmony_ci sdio_disable_func(func); 3328c2ecf20Sopenharmony_ci sdio_release_host(func); 3338c2ecf20Sopenharmony_ci sdio_set_drvdata(func, NULL); 3348c2ecf20Sopenharmony_ci kfree(self); 3358c2ecf20Sopenharmony_ci } 3368c2ecf20Sopenharmony_ci} 3378c2ecf20Sopenharmony_ci 3388c2ecf20Sopenharmony_ci#ifdef CONFIG_PM 3398c2ecf20Sopenharmony_cistatic int cw1200_sdio_suspend(struct device *dev) 3408c2ecf20Sopenharmony_ci{ 3418c2ecf20Sopenharmony_ci int ret; 3428c2ecf20Sopenharmony_ci struct sdio_func *func = dev_to_sdio_func(dev); 3438c2ecf20Sopenharmony_ci struct hwbus_priv *self = sdio_get_drvdata(func); 3448c2ecf20Sopenharmony_ci 3458c2ecf20Sopenharmony_ci if (!cw1200_can_suspend(self->core)) 3468c2ecf20Sopenharmony_ci return -EAGAIN; 3478c2ecf20Sopenharmony_ci 3488c2ecf20Sopenharmony_ci /* Notify SDIO that CW1200 will remain powered during suspend */ 3498c2ecf20Sopenharmony_ci ret = sdio_set_host_pm_flags(func, MMC_PM_KEEP_POWER); 3508c2ecf20Sopenharmony_ci if (ret) 3518c2ecf20Sopenharmony_ci pr_err("Error setting SDIO pm flags: %i\n", ret); 3528c2ecf20Sopenharmony_ci 3538c2ecf20Sopenharmony_ci return ret; 3548c2ecf20Sopenharmony_ci} 3558c2ecf20Sopenharmony_ci 3568c2ecf20Sopenharmony_cistatic int cw1200_sdio_resume(struct device *dev) 3578c2ecf20Sopenharmony_ci{ 3588c2ecf20Sopenharmony_ci return 0; 3598c2ecf20Sopenharmony_ci} 3608c2ecf20Sopenharmony_ci 3618c2ecf20Sopenharmony_cistatic const struct dev_pm_ops cw1200_pm_ops = { 3628c2ecf20Sopenharmony_ci .suspend = cw1200_sdio_suspend, 3638c2ecf20Sopenharmony_ci .resume = cw1200_sdio_resume, 3648c2ecf20Sopenharmony_ci}; 3658c2ecf20Sopenharmony_ci#endif 3668c2ecf20Sopenharmony_ci 3678c2ecf20Sopenharmony_cistatic struct sdio_driver sdio_driver = { 3688c2ecf20Sopenharmony_ci .name = "cw1200_wlan_sdio", 3698c2ecf20Sopenharmony_ci .id_table = cw1200_sdio_ids, 3708c2ecf20Sopenharmony_ci .probe = cw1200_sdio_probe, 3718c2ecf20Sopenharmony_ci .remove = cw1200_sdio_disconnect, 3728c2ecf20Sopenharmony_ci#ifdef CONFIG_PM 3738c2ecf20Sopenharmony_ci .drv = { 3748c2ecf20Sopenharmony_ci .pm = &cw1200_pm_ops, 3758c2ecf20Sopenharmony_ci } 3768c2ecf20Sopenharmony_ci#endif 3778c2ecf20Sopenharmony_ci}; 3788c2ecf20Sopenharmony_ci 3798c2ecf20Sopenharmony_ci/* Init Module function -> Called by insmod */ 3808c2ecf20Sopenharmony_cistatic int __init cw1200_sdio_init(void) 3818c2ecf20Sopenharmony_ci{ 3828c2ecf20Sopenharmony_ci const struct cw1200_platform_data_sdio *pdata; 3838c2ecf20Sopenharmony_ci int ret; 3848c2ecf20Sopenharmony_ci 3858c2ecf20Sopenharmony_ci /* FIXME -- this won't support multiple devices */ 3868c2ecf20Sopenharmony_ci pdata = global_plat_data; 3878c2ecf20Sopenharmony_ci 3888c2ecf20Sopenharmony_ci if (cw1200_sdio_on(pdata)) { 3898c2ecf20Sopenharmony_ci ret = -1; 3908c2ecf20Sopenharmony_ci goto err; 3918c2ecf20Sopenharmony_ci } 3928c2ecf20Sopenharmony_ci 3938c2ecf20Sopenharmony_ci ret = sdio_register_driver(&sdio_driver); 3948c2ecf20Sopenharmony_ci if (ret) 3958c2ecf20Sopenharmony_ci goto err; 3968c2ecf20Sopenharmony_ci 3978c2ecf20Sopenharmony_ci return 0; 3988c2ecf20Sopenharmony_ci 3998c2ecf20Sopenharmony_cierr: 4008c2ecf20Sopenharmony_ci cw1200_sdio_off(pdata); 4018c2ecf20Sopenharmony_ci return ret; 4028c2ecf20Sopenharmony_ci} 4038c2ecf20Sopenharmony_ci 4048c2ecf20Sopenharmony_ci/* Called at Driver Unloading */ 4058c2ecf20Sopenharmony_cistatic void __exit cw1200_sdio_exit(void) 4068c2ecf20Sopenharmony_ci{ 4078c2ecf20Sopenharmony_ci const struct cw1200_platform_data_sdio *pdata; 4088c2ecf20Sopenharmony_ci 4098c2ecf20Sopenharmony_ci /* FIXME -- this won't support multiple devices */ 4108c2ecf20Sopenharmony_ci pdata = global_plat_data; 4118c2ecf20Sopenharmony_ci sdio_unregister_driver(&sdio_driver); 4128c2ecf20Sopenharmony_ci cw1200_sdio_off(pdata); 4138c2ecf20Sopenharmony_ci} 4148c2ecf20Sopenharmony_ci 4158c2ecf20Sopenharmony_ci 4168c2ecf20Sopenharmony_cimodule_init(cw1200_sdio_init); 4178c2ecf20Sopenharmony_cimodule_exit(cw1200_sdio_exit); 418