763
/********************************************************************/
764
/* Power management */
765
/********************************************************************/
767
static int if_sdio_power_on(struct if_sdio_card *card)
769
struct sdio_func *func = card->func;
770
struct lbs_private *priv = card->priv;
771
struct mmc_host *host = func->card->host;
774
sdio_claim_host(func);
776
ret = sdio_enable_func(func);
780
/* For 1-bit transfers to the 8686 model, we need to enable the
781
* interrupt flag in the CCCR register. Set the MMC_QUIRK_LENIENT_FN0
782
* bit to allow access to non-vendor registers. */
783
if ((card->model == MODEL_8686) &&
784
(host->caps & MMC_CAP_SDIO_IRQ) &&
785
(host->ios.bus_width == MMC_BUS_WIDTH_1)) {
788
func->card->quirks |= MMC_QUIRK_LENIENT_FN0;
789
reg = sdio_f0_readb(func, SDIO_CCCR_IF, &ret);
793
reg |= SDIO_BUS_ECSI;
794
sdio_f0_writeb(func, reg, SDIO_CCCR_IF, &ret);
799
card->ioport = sdio_readb(func, IF_SDIO_IOPORT, &ret);
803
card->ioport |= sdio_readb(func, IF_SDIO_IOPORT + 1, &ret) << 8;
807
card->ioport |= sdio_readb(func, IF_SDIO_IOPORT + 2, &ret) << 16;
811
sdio_release_host(func);
812
ret = if_sdio_prog_firmware(card);
813
sdio_claim_host(func);
818
* Get rx_unit if the chip is SD8688 or newer.
819
* SD8385 & SD8686 do not have rx_unit.
821
if ((card->model != MODEL_8385)
822
&& (card->model != MODEL_8686))
823
card->rx_unit = if_sdio_read_rx_unit(card);
828
* Set up the interrupt handler late.
830
* If we set it up earlier, the (buggy) hardware generates a spurious
831
* interrupt, even before the interrupt has been enabled, with
834
* We register the interrupt handler late so that we can handle any
835
* spurious interrupts, and also to avoid generation of that known
836
* spurious interrupt in the first place.
838
ret = sdio_claim_irq(func, if_sdio_interrupt);
843
* Enable interrupts now that everything is set up
845
sdio_writeb(func, 0x0f, IF_SDIO_H_INT_MASK, &ret);
849
sdio_release_host(func);
852
* FUNC_INIT is required for SD8688 WLAN/BT multiple functions
854
if (card->model == MODEL_8688) {
855
struct cmd_header cmd;
857
memset(&cmd, 0, sizeof(cmd));
859
lbs_deb_sdio("send function INIT command\n");
860
if (__lbs_cmd(priv, CMD_FUNC_INIT, &cmd, sizeof(cmd),
861
lbs_cmd_copyback, (unsigned long) &cmd))
862
netdev_alert(priv->dev, "CMD_FUNC_INIT cmd failed\n");
870
sdio_release_irq(func);
872
sdio_disable_func(func);
874
sdio_release_host(func);
878
static int if_sdio_power_off(struct if_sdio_card *card)
880
struct sdio_func *func = card->func;
881
struct lbs_private *priv = card->priv;
885
sdio_claim_host(func);
886
sdio_release_irq(func);
887
sdio_disable_func(func);
888
sdio_release_host(func);
760
893
/*******************************************************************/
761
894
/* Libertas callbacks */
762
895
/*******************************************************************/
1028
static struct mmc_host *reset_host;
1030
static void if_sdio_reset_card_worker(struct work_struct *work)
1033
* The actual reset operation must be run outside of lbs_thread. This
1034
* is because mmc_remove_host() will cause the device to be instantly
1035
* destroyed, and the libertas driver then needs to end lbs_thread,
1036
* leading to a deadlock.
1038
* We run it in a workqueue totally independent from the if_sdio_card
1039
* instance for that reason.
1042
pr_info("Resetting card...");
1043
mmc_remove_host(reset_host);
1044
mmc_add_host(reset_host);
1046
static DECLARE_WORK(card_reset_work, if_sdio_reset_card_worker);
1048
static void if_sdio_reset_card(struct lbs_private *priv)
1050
struct if_sdio_card *card = priv->card;
1052
if (work_pending(&card_reset_work))
1055
reset_host = card->func->card->host;
1056
schedule_work(&card_reset_work);
1059
static int if_sdio_power_save(struct lbs_private *priv)
1061
struct if_sdio_card *card = priv->card;
1064
flush_workqueue(card->workqueue);
1066
ret = if_sdio_power_off(card);
1068
/* Let runtime PM know the card is powered off */
1069
pm_runtime_put_sync(&card->func->dev);
1074
static int if_sdio_power_restore(struct lbs_private *priv)
1076
struct if_sdio_card *card = priv->card;
1078
/* Make sure the card will not be powered off by runtime PM */
1079
pm_runtime_get_sync(&card->func->dev);
1081
return if_sdio_power_on(card);
895
1085
/*******************************************************************/
896
1086
/* SDIO callbacks */
897
1087
/*******************************************************************/
1005
sdio_claim_host(func);
1007
ret = sdio_enable_func(func);
1011
/* For 1-bit transfers to the 8686 model, we need to enable the
1012
* interrupt flag in the CCCR register. Set the MMC_QUIRK_LENIENT_FN0
1013
* bit to allow access to non-vendor registers. */
1014
if ((card->model == MODEL_8686) &&
1015
(host->caps & MMC_CAP_SDIO_IRQ) &&
1016
(host->ios.bus_width == MMC_BUS_WIDTH_1)) {
1019
func->card->quirks |= MMC_QUIRK_LENIENT_FN0;
1020
reg = sdio_f0_readb(func, SDIO_CCCR_IF, &ret);
1024
reg |= SDIO_BUS_ECSI;
1025
sdio_f0_writeb(func, reg, SDIO_CCCR_IF, &ret);
1030
card->ioport = sdio_readb(func, IF_SDIO_IOPORT, &ret);
1034
card->ioport |= sdio_readb(func, IF_SDIO_IOPORT + 1, &ret) << 8;
1038
card->ioport |= sdio_readb(func, IF_SDIO_IOPORT + 2, &ret) << 16;
1042
sdio_release_host(func);
1044
1194
sdio_set_drvdata(func, card);
1046
1196
lbs_deb_sdio("class = 0x%X, vendor = 0x%X, "
1065
1212
priv->enter_deep_sleep = if_sdio_enter_deep_sleep;
1066
1213
priv->exit_deep_sleep = if_sdio_exit_deep_sleep;
1067
1214
priv->reset_deep_sleep_wakeup = if_sdio_reset_deep_sleep_wakeup;
1069
sdio_claim_host(func);
1072
* Get rx_unit if the chip is SD8688 or newer.
1073
* SD8385 & SD8686 do not have rx_unit.
1075
if ((card->model != MODEL_8385)
1076
&& (card->model != MODEL_8686))
1077
card->rx_unit = if_sdio_read_rx_unit(card);
1082
* Set up the interrupt handler late.
1084
* If we set it up earlier, the (buggy) hardware generates a spurious
1085
* interrupt, even before the interrupt has been enabled, with
1088
* We register the interrupt handler late so that we can handle any
1089
* spurious interrupts, and also to avoid generation of that known
1090
* spurious interrupt in the first place.
1092
ret = sdio_claim_irq(func, if_sdio_interrupt);
1097
* Enable interrupts now that everything is set up
1099
sdio_writeb(func, 0x0f, IF_SDIO_H_INT_MASK, &ret);
1100
sdio_release_host(func);
1107
* FUNC_INIT is required for SD8688 WLAN/BT multiple functions
1109
if (card->model == MODEL_8688) {
1110
struct cmd_header cmd;
1112
memset(&cmd, 0, sizeof(cmd));
1114
lbs_deb_sdio("send function INIT command\n");
1115
if (__lbs_cmd(priv, CMD_FUNC_INIT, &cmd, sizeof(cmd),
1116
lbs_cmd_copyback, (unsigned long) &cmd))
1117
netdev_alert(priv->dev, "CMD_FUNC_INIT cmd failed\n");
1215
priv->reset_card = if_sdio_reset_card;
1216
priv->power_save = if_sdio_power_save;
1217
priv->power_restore = if_sdio_power_restore;
1219
ret = if_sdio_power_on(card);
1221
goto err_activate_card;
1120
1223
ret = lbs_start_card(priv);
1224
if_sdio_power_off(card);
1122
1226
goto err_activate_card;
1228
/* Tell PM core that we don't need the card to be powered now */
1229
pm_runtime_put_noidle(&func->dev);
1125
1232
lbs_deb_leave_args(LBS_DEB_SDIO, "ret %d", ret);