https://source.android.com/docs/security/bulletin/2024-02-01 * tag 'ASB-2024-02-05_4.19-stable' of https://android.googlesource.com/kernel/common: Reapply "perf: Fix perf_event_validate_size()" UPSTREAM: usb: raw-gadget: properly handle interrupted requests UPSTREAM: mm/cma: use nth_page() in place of direct struct page manipulation UPSTREAM: wireguard: allowedips: expand maximum node depth UPSTREAM: coresight: tmc: Explicit type conversions to prevent integer overflow UPSTREAM: wireguard: netlink: send staged packets when setting initial private key UPSTREAM: wireguard: queueing: use saner cpu selection wrapping UPSTREAM: kheaders: Use array declaration instead of char UPSTREAM: arm64: efi: Make efi_rt_lock a raw_spinlock UPSTREAM: sched/psi: Fix use-after-free in ep_remove_wait_queue() UPSTREAM: usb: musb: mediatek: don't unregister something that wasn't registered UPSTREAM: xfrm/compat: prevent potential spectre v1 gadget in xfrm_xlate32_attr() UPSTREAM: xfrm: compat: change expression for switch in xfrm_xlate64 UPSTREAM: perf/core: Call LSM hook after copying perf_event_attr Linux 4.19.306 crypto: scompress - initialize per-CPU variables on each CPU Revert "NFSD: Fix possible sleep during nfsd4_release_lockowner()" i2c: s3c24xx: fix transferring more than one message in polling mode i2c: s3c24xx: fix read transfers in polling mode kdb: Fix a potential buffer overflow in kdb_local() kdb: Censor attempts to set PROMPT without ENABLE_MEM_READ ipvs: avoid stat macros calls from preemptible context net: dsa: vsc73xx: Add null pointer check to vsc73xx_gpio_probe net: ravb: Fix dma_addr_t truncation in error case net: qualcomm: rmnet: fix global oob in rmnet_policy serial: imx: Correct clock error message in function probe() apparmor: avoid crash when parsed profile name is empty perf genelf: Set ELF program header addresses properly acpi: property: Let args be NULL in __acpi_node_get_property_reference MIPS: Alchemy: Fix an out-of-bound access in db1550_dev_setup() MIPS: Alchemy: Fix an out-of-bound access in db1200_dev_setup() HID: wacom: Correct behavior when processing some confidence == false touches wifi: mwifiex: configure BSSID consistently when starting AP wifi: rtlwifi: Convert LNKCTL change to PCIe cap RMW accessors wifi: rtlwifi: Remove bogus and dangerous ASPM disable/enable code fbdev: flush deferred work in fb_deferred_io_fsync() ALSA: oxygen: Fix right channel of capture volume mixer usb: mon: Fix atomicity violation in mon_bin_vma_fault usb: typec: class: fix typec_altmode_put_partner to put plugs Revert "usb: typec: class: fix typec_altmode_put_partner to put plugs" usb: chipidea: wait controller resume finished for wakeup irq Revert "usb: dwc3: don't reset device side if dwc3 was configured as host-only" Revert "usb: dwc3: Soft reset phy on probe for host" usb: dwc: ep0: Update request status in dwc3_ep0_stall_restart usb: phy: mxs: remove CONFIG_USB_OTG condition for mxs_phy_is_otg_host() tick-sched: Fix idle and iowait sleeptime accounting vs CPU hotplug binder: fix unused alloc->free_async_space binder: fix race between mmput() and do_exit() xen-netback: don't produce zero-size SKB frags Revert "ASoC: atmel: Remove system clock tree configuration for at91sam9g20ek" Input: atkbd - use ab83 as id when skipping the getid command binder: fix async space check for 0-sized buffers of: unittest: Fix of_count_phandle_with_args() expected value message of: Fix double free in of_parse_phandle_with_args_map mmc: sdhci_omap: Fix TI SoC dependencies watchdog: bcm2835_wdt: Fix WDIOC_SETTIMEOUT handling watchdog/hpwdt: Only claim UNKNOWN NMI if from iLO watchdog: set cdev owner before adding gpu/drm/radeon: fix two memleaks in radeon_vm_init drivers/amd/pm: fix a use-after-free in kv_parse_power_table drm/amd/pm: fix a double-free in si_dpm_init drm/amdgpu/debugfs: fix error code when smc register accessors are NULL media: dvbdev: drop refcount on error path in dvb_device_open() media: cx231xx: fix a memleak in cx231xx_init_isoc drm/radeon/trinity_dpm: fix a memleak in trinity_parse_power_table drm/radeon/dpm: fix a memleak in sumo_parse_power_table drm/radeon: check the alloc_workqueue return value in radeon_crtc_init() drm/drv: propagate errors from drm_modeset_register_all() drm/msm/mdp4: flush vblank event on disable ASoC: cs35l34: Fix GPIO name and drop legacy include ASoC: cs35l33: Fix GPIO name and drop legacy include drm/radeon: check return value of radeon_ring_lock() drm/radeon/r100: Fix integer overflow issues in r100_cs_track_check() drm/radeon/r600_cs: Fix possible int overflows in r600_cs_check_reg() f2fs: fix to avoid dirent corruption drm/bridge: Fix typo in post_disable() description media: pvrusb2: fix use after free on context disconnection RDMA/usnic: Silence uninitialized symbol smatch warnings ip6_tunnel: fix NEXTHDR_FRAGMENT handling in ip6_tnl_parse_tlv_enc_lim() Bluetooth: btmtkuart: fix recv_buf() return value Bluetooth: Fix bogus check for re-auth no supported with non-ssp wifi: rtlwifi: rtl8192se: using calculate_bit_shift() wifi: rtlwifi: rtl8192ee: using calculate_bit_shift() wifi: rtlwifi: rtl8192de: using calculate_bit_shift() rtlwifi: rtl8192de: make arrays static const, makes object smaller wifi: rtlwifi: rtl8192ce: using calculate_bit_shift() wifi: rtlwifi: rtl8192cu: using calculate_bit_shift() wifi: rtlwifi: rtl8192c: using calculate_bit_shift() wifi: rtlwifi: rtl8188ee: phy: using calculate_bit_shift() wifi: rtlwifi: add calculate_bit_shift() dma-mapping: clear dev->dma_mem to NULL after freeing it scsi: hisi_sas: Replace with standard error code return value wifi: rtlwifi: rtl8821ae: phy: fix an undefined bitwise shift behavior rtlwifi: Use ffs in <foo>_phy_calculate_bit_shift firmware: ti_sci: Fix an off-by-one in ti_sci_debugfs_create() net/ncsi: Fix netlink major/minor version numbers ncsi: internal.h: Fix a spello ARM: dts: qcom: apq8064: correct XOADC register address wifi: libertas: stop selecting wext bpf, lpm: Fix check prefixlen before walking trie NFSv4.1/pnfs: Ensure we handle the error NFS4ERR_RETURNCONFLICT blocklayoutdriver: Fix reference leak of pnfs_device_node crypto: scomp - fix req->dst buffer overflow crypto: scompress - Use per-CPU struct instead multiple variables crypto: scompress - return proper error code for allocation failure crypto: sahara - do not resize req->src when doing hash operations crypto: sahara - fix processing hash requests with req->nbytes < sg->length crypto: sahara - improve error handling in sahara_sha_process() crypto: sahara - fix wait_for_completion_timeout() error handling crypto: sahara - fix ahash reqsize crypto: virtio - Wait for tasklet to complete on device remove pstore: ram_core: fix possible overflow in persistent_ram_init_ecc() crypto: sahara - fix error handling in sahara_hw_descriptor_create() crypto: sahara - fix processing requests with cryptlen < sg->length crypto: sahara - fix ahash selftest failure crypto: sahara - remove FLAGS_NEW_KEY logic crypto: af_alg - Disallow multiple in-flight AIO requests crypto: ccp - fix memleak in ccp_init_dm_workarea crypto: virtio - Handle dataq logic with tasklet selinux: Fix error priority for bind with AF_UNSPEC on PF_INET6 socket mtd: Fix gluebi NULL pointer dereference caused by ftl notifier calipso: fix memory leak in netlbl_calipso_add_pass() netlabel: remove unused parameter in netlbl_netlink_auditinfo() net: netlabel: Fix kerneldoc warnings ACPI: LPIT: Avoid u32 multiplication overflow ACPI: video: check for error while searching for backlight device parent mtd: rawnand: Increment IFC_TIMEOUT_MSECS for nand controller response powerpc/imc-pmu: Add a null pointer check in update_events_in_group() powerpc/powernv: Add a null pointer check in opal_event_init() selftests/powerpc: Fix error handling in FPU/VMX preemption tests powerpc/pseries/memhp: Fix access beyond end of drmem array powerpc/pseries/memhotplug: Quieten some DLPAR operations powerpc/44x: select I2C for CURRITUCK powerpc: remove redundant 'default n' from Kconfig-s powerpc: add crtsavres.o to always-y instead of extra-y EDAC/thunderx: Fix possible out-of-bounds string access x86/lib: Fix overflow when counting digits coresight: etm4x: Fix width of CCITMIN field uio: Fix use-after-free in uio_open binder: fix comment on binder_alloc_new_buf() return value binder: use EPOLLERR from eventpoll.h drm/crtc: fix uninitialized variable use ARM: sun9i: smp: fix return code check of of_property_match_string Input: xpad - add Razer Wolverine V2 support ARC: fix spare error s390/scm: fix virtual vs physical address confusion Input: i8042 - add nomux quirk for Acer P459-G2-M Input: atkbd - skip ATKBD_CMD_GETID in translated mode reset: hisilicon: hi6220: fix Wvoid-pointer-to-enum-cast warning ring-buffer: Do not record in NMI if the arch does not support cmpxchg in NMI tracing: Add size check when printing trace_marker output tracing: Have large events show up as '[LINE TOO BIG]' instead of nothing drm/crtc: Fix uninit-value bug in drm_mode_setcrtc jbd2: correct the printing of write_flags in jbd2_write_superblock() clk: rockchip: rk3128: Fix HCLK_OTG gate register drm/exynos: fix a potential error pointer dereference ASoC: da7219: Support low DC impedance headset net/tg3: fix race condition in tg3_reset_task() ASoC: rt5650: add mutex to avoid the jack detection failure ASoC: cs43130: Fix incorrect frame delay configuration ASoC: cs43130: Fix the position of const qualifier ASoC: Intel: Skylake: mem leak in skl register function f2fs: explicitly null-terminate the xattr list UPSTREAM: wifi: cfg80211: fix buffer overflow in elem comparison UPSTREAM: gcov: clang: fix the buffer overflow issue BACKPORT: selinux: enable use of both GFP_KERNEL and GFP_ATOMIC in convert_context() UPSTREAM: wifi: cfg80211: avoid nontransmitted BSS list corruption UPSTREAM: wifi: cfg80211: fix BSS refcounting bugs UPSTREAM: wifi: cfg80211: ensure length byte is present before access UPSTREAM: wifi: cfg80211: fix u8 overflow in cfg80211_update_notlisted_nontrans() UPSTREAM: wireguard: netlink: avoid variable-sized memcpy on sockaddr UPSTREAM: wireguard: ratelimiter: disable timings test by default UPSTREAM: crypto: lib - remove unneeded selection of XOR_BLOCKS UPSTREAM: wireguard: allowedips: don't corrupt stack when detecting overflow UPSTREAM: wireguard: ratelimiter: use hrtimer in selftest UPSTREAM: crypto: arm64/poly1305 - fix a read out-of-bound UPSTREAM: wifi: mac80211_hwsim: set virtio device ready in probe() UPSTREAM: crypto: memneq - move into lib/ UPSTREAM: dma-buf: fix use of DMA_BUF_SET_NAME_{A,B} in userspace BACKPORT: usb: typec: mux: Check dev_set_name() return value UPSTREAM: wireguard: device: check for metadata_dst with skb_valid_dst() UPSTREAM: sched/fair: Fix cfs_rq_clock_pelt() for throttled cfs_rq UPSTREAM: cfg80211: hold bss_lock while updating nontrans_list UPSTREAM: wireguard: socket: ignore v6 endpoints when ipv6 is disabled UPSTREAM: wireguard: socket: free skb in send6 when ipv6 is disabled UPSTREAM: wireguard: queueing: use CFI-safe ptr_ring cleanup function UPSTREAM: mm: don't try to NUMA-migrate COW pages that have other uses UPSTREAM: copy_process(): Move fd_install() out of sighand->siglock critical section UPSTREAM: usb: raw-gadget: fix handling of dual-direction-capable endpoints UPSTREAM: psi: Fix "no previous prototype" warnings when CONFIG_CGROUPS=n UPSTREAM: sched/uclamp: Fix rq->uclamp_max not set on first enqueue UPSTREAM: wireguard: selftests: increase default dmesg log size UPSTREAM: wireguard: allowedips: add missing __rcu annotation to satisfy sparse UPSTREAM: sched/uclamp: Fix uclamp_tg_restrict() UPSTREAM: coresight: etm4x: Fix etm4_count race by moving cpuhp callbacks to init UPSTREAM: sched/uclamp: Fix a deadlock when enabling uclamp static key UPSTREAM: mac80211_hwsim: use GFP_ATOMIC under spin lock UPSTREAM: usercopy: Avoid soft lockups in test_check_nonzero_user() UPSTREAM: lib: test_user_copy: style cleanup UPSTREAM: fork: return proper negative error code Revert "ipv6: make ip6_rt_gc_expire an atomic_t" Revert "ipv6: remove max_size check inline with ipv4" Linux 4.19.305 ipv6: remove max_size check inline with ipv4 ipv6: make ip6_rt_gc_expire an atomic_t net/dst: use a smaller percpu_counter batch for dst entries accounting net: add a route cache full diagnostic message PCI: Disable ATS for specific Intel IPU E2000 devices PCI: Extract ATS disabling to a helper function netfilter: nf_tables: Reject tables of unsupported family fuse: nlookup missing decrement in fuse_direntplus_link mmc: core: Cancel delayed work before releasing host mmc: rpmb: fixes pause retune on all RPMB partitions. mm: fix unmap_mapping_range high bits shift bug firewire: ohci: suppress unexpected system reboot in AMD Ryzen machines and ASM108x/VT630x PCIe cards mm/memory-failure: check the mapcount of the precise page bnxt_en: Remove mis-applied code from bnxt_cfg_ntp_filters() asix: Add check for usbnet_get_endpoints net/qla3xxx: fix potential memleak in ql_alloc_buffer_queues net/qla3xxx: switch from 'pci_' to 'dma_' API i40e: Restore VF MSI-X state during PCI reset i40e: fix use-after-free in i40e_aqc_add_filters() net: Save and restore msg_namelen in sock_sendmsg net: bcmgenet: Fix FCS generation for fragmented skbuffs ARM: sun9i: smp: Fix array-index-out-of-bounds read in sunxi_mc_smp_init net: sched: em_text: fix possible memory leak in em_text_destroy() i40e: Fix filter input checks to prevent config with invalid values nfc: llcp_core: Hold a ref to llcp_local->dev when holding a ref to llcp_local UPSTREAM: fsverity: skip PKCS#7 parser when keyring is empty Conflicts: drivers/hwtracing/coresight/coresight-etm4x.c drivers/net/ethernet/qualcomm/rmnet/rmnet_config.c include/linux/psi.h mm/memory-failure.c net/wireless/scan.c Change-Id: I49b769cb8387e5d5f28730d13cbdf4ffd335dc70
736 lines
19 KiB
C
736 lines
19 KiB
C
/*
|
|
* linux/drivers/mmc/core/host.c
|
|
*
|
|
* Copyright (C) 2003 Russell King, All Rights Reserved.
|
|
* Copyright (C) 2007-2008 Pierre Ossman
|
|
* Copyright (C) 2010 Linus Walleij
|
|
*
|
|
* This program is free software; you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License version 2 as
|
|
* published by the Free Software Foundation.
|
|
*
|
|
* MMC host class device management
|
|
*/
|
|
|
|
#include <linux/device.h>
|
|
#include <linux/err.h>
|
|
#include <linux/idr.h>
|
|
#include <linux/of.h>
|
|
#include <linux/of_gpio.h>
|
|
#include <linux/pagemap.h>
|
|
#include <linux/export.h>
|
|
#include <linux/leds.h>
|
|
#include <linux/slab.h>
|
|
|
|
#include <linux/mmc/host.h>
|
|
#include <linux/mmc/card.h>
|
|
#include <linux/mmc/slot-gpio.h>
|
|
|
|
#include "core.h"
|
|
#include "crypto.h"
|
|
#include "host.h"
|
|
#include "slot-gpio.h"
|
|
#include "pwrseq.h"
|
|
#include "sdio_ops.h"
|
|
|
|
#define cls_dev_to_mmc_host(d) container_of(d, struct mmc_host, class_dev)
|
|
|
|
#define MMC_DEVFRQ_DEFAULT_UP_THRESHOLD 35
|
|
#define MMC_DEVFRQ_DEFAULT_DOWN_THRESHOLD 5
|
|
#define MMC_DEVFRQ_DEFAULT_POLLING_MSEC 100
|
|
|
|
static DEFINE_IDA(mmc_host_ida);
|
|
|
|
static void mmc_host_classdev_release(struct device *dev)
|
|
{
|
|
struct mmc_host *host = cls_dev_to_mmc_host(dev);
|
|
ida_simple_remove(&mmc_host_ida, host->index);
|
|
kfree(host);
|
|
}
|
|
|
|
static int mmc_host_prepare(struct device *dev)
|
|
{
|
|
/*
|
|
* Since mmc_host is a virtual device, we don't have to do anything.
|
|
* If we return a positive value, the pm framework will consider that
|
|
* the runtime suspend and system suspend of this device is same and
|
|
* will set direct_complete flag as true. We don't want this as the
|
|
* mmc_host always has positive disable_depth and setting the flag
|
|
* will not speed up the suspend process.
|
|
* So return 0.
|
|
*/
|
|
return 0;
|
|
}
|
|
|
|
static const struct dev_pm_ops mmc_pm_ops = {
|
|
.prepare = mmc_host_prepare,
|
|
};
|
|
|
|
static struct class mmc_host_class = {
|
|
.name = "mmc_host",
|
|
.dev_release = mmc_host_classdev_release,
|
|
.pm = &mmc_pm_ops,
|
|
};
|
|
|
|
int mmc_register_host_class(void)
|
|
{
|
|
return class_register(&mmc_host_class);
|
|
}
|
|
|
|
void mmc_unregister_host_class(void)
|
|
{
|
|
class_unregister(&mmc_host_class);
|
|
}
|
|
|
|
void mmc_retune_enable(struct mmc_host *host)
|
|
{
|
|
host->can_retune = 1;
|
|
if (host->retune_period)
|
|
mod_timer(&host->retune_timer,
|
|
jiffies + host->retune_period * HZ);
|
|
}
|
|
|
|
/*
|
|
* Pause re-tuning for a small set of operations. The pause begins after the
|
|
* next command and after first doing re-tuning.
|
|
*/
|
|
void mmc_retune_pause(struct mmc_host *host)
|
|
{
|
|
if (!host->retune_paused) {
|
|
host->retune_paused = 1;
|
|
mmc_retune_needed(host);
|
|
mmc_retune_hold(host);
|
|
}
|
|
}
|
|
EXPORT_SYMBOL(mmc_retune_pause);
|
|
|
|
void mmc_retune_unpause(struct mmc_host *host)
|
|
{
|
|
if (host->retune_paused) {
|
|
host->retune_paused = 0;
|
|
mmc_retune_release(host);
|
|
}
|
|
}
|
|
EXPORT_SYMBOL(mmc_retune_unpause);
|
|
|
|
void mmc_retune_disable(struct mmc_host *host)
|
|
{
|
|
mmc_retune_unpause(host);
|
|
host->can_retune = 0;
|
|
del_timer_sync(&host->retune_timer);
|
|
host->retune_now = 0;
|
|
host->need_retune = 0;
|
|
}
|
|
|
|
void mmc_retune_timer_stop(struct mmc_host *host)
|
|
{
|
|
del_timer_sync(&host->retune_timer);
|
|
}
|
|
EXPORT_SYMBOL(mmc_retune_timer_stop);
|
|
|
|
void mmc_retune_hold(struct mmc_host *host)
|
|
{
|
|
if (!host->hold_retune)
|
|
host->retune_now = 1;
|
|
host->hold_retune += 1;
|
|
}
|
|
|
|
void mmc_retune_release(struct mmc_host *host)
|
|
{
|
|
if (host->hold_retune)
|
|
host->hold_retune -= 1;
|
|
else
|
|
WARN_ON(1);
|
|
}
|
|
EXPORT_SYMBOL(mmc_retune_release);
|
|
|
|
int mmc_retune(struct mmc_host *host)
|
|
{
|
|
bool return_to_hs400 = false;
|
|
int err;
|
|
|
|
if (host->retune_now)
|
|
host->retune_now = 0;
|
|
else
|
|
return 0;
|
|
|
|
if (!host->need_retune || host->doing_retune || !host->card
|
|
|| mmc_card_hs400es(host->card)
|
|
|| (host->ios.clock <= MMC_HIGH_DDR_MAX_DTR))
|
|
return 0;
|
|
|
|
host->need_retune = 0;
|
|
|
|
host->doing_retune = 1;
|
|
|
|
if (host->ios.timing == MMC_TIMING_MMC_HS400) {
|
|
err = mmc_hs400_to_hs200(host->card);
|
|
if (err)
|
|
goto out;
|
|
|
|
return_to_hs400 = true;
|
|
}
|
|
|
|
/*
|
|
* Timing should be adjusted to the HS400 target
|
|
* operation frequency for tuning process.
|
|
* Similar handling is also done in mmc_hs200_tuning()
|
|
* This is handled properly in sdhci-msm.c from msm-5.4 onwards.
|
|
*/
|
|
if (host->card->mmc_avail_type & EXT_CSD_CARD_TYPE_HS400 &&
|
|
host->ios.bus_width == MMC_BUS_WIDTH_8)
|
|
mmc_set_timing(host, MMC_TIMING_MMC_HS400);
|
|
|
|
err = mmc_execute_tuning(host->card);
|
|
if (err)
|
|
goto out;
|
|
|
|
if (return_to_hs400)
|
|
err = mmc_hs200_to_hs400(host->card);
|
|
out:
|
|
host->doing_retune = 0;
|
|
|
|
return err;
|
|
}
|
|
|
|
/**
|
|
* mmc_host_may_gate_card - check if this card may be gated
|
|
* @card: card to check.
|
|
*/
|
|
bool mmc_host_may_gate_card(struct mmc_card *card)
|
|
{
|
|
/* If there is no card we may gate it */
|
|
if (!card)
|
|
return true;
|
|
|
|
/*
|
|
* SDIO3.0 card allows the clock to be gated off so check if
|
|
* that is the case or not
|
|
*/
|
|
if (mmc_card_sdio(card) && card->cccr.async_intr_sup)
|
|
return true;
|
|
|
|
/*
|
|
* Don't gate SDIO cards! These need to be clocked at all times
|
|
* since they may be independent systems generating interrupts
|
|
* and other events. The clock requests counter from the core will
|
|
* go down to zero since the core does not need it, but we will not
|
|
* gate the clock, because there is somebody out there that may still
|
|
* be using it.
|
|
*/
|
|
return !(card->quirks & MMC_QUIRK_BROKEN_CLK_GATING);
|
|
}
|
|
|
|
static void mmc_retune_timer(struct timer_list *t)
|
|
{
|
|
struct mmc_host *host = from_timer(host, t, retune_timer);
|
|
|
|
mmc_retune_needed(host);
|
|
}
|
|
|
|
/**
|
|
* mmc_of_parse() - parse host's device-tree node
|
|
* @host: host whose node should be parsed.
|
|
*
|
|
* To keep the rest of the MMC subsystem unaware of whether DT has been
|
|
* used to to instantiate and configure this host instance or not, we
|
|
* parse the properties and set respective generic mmc-host flags and
|
|
* parameters.
|
|
*/
|
|
int mmc_of_parse(struct mmc_host *host)
|
|
{
|
|
struct device *dev = host->parent;
|
|
u32 bus_width, drv_type, cd_debounce_delay_ms;
|
|
int ret;
|
|
bool cd_cap_invert, cd_gpio_invert = false;
|
|
bool ro_cap_invert, ro_gpio_invert = false;
|
|
|
|
if (!dev || !dev_fwnode(dev))
|
|
return 0;
|
|
|
|
/* "bus-width" is translated to MMC_CAP_*_BIT_DATA flags */
|
|
if (device_property_read_u32(dev, "bus-width", &bus_width) < 0) {
|
|
dev_dbg(host->parent,
|
|
"\"bus-width\" property is missing, assuming 1 bit.\n");
|
|
bus_width = 1;
|
|
}
|
|
|
|
switch (bus_width) {
|
|
case 8:
|
|
host->caps |= MMC_CAP_8_BIT_DATA;
|
|
/* Hosts capable of 8-bit transfers can also do 4 bits */
|
|
case 4:
|
|
host->caps |= MMC_CAP_4_BIT_DATA;
|
|
break;
|
|
case 1:
|
|
break;
|
|
default:
|
|
dev_err(host->parent,
|
|
"Invalid \"bus-width\" value %u!\n", bus_width);
|
|
return -EINVAL;
|
|
}
|
|
|
|
/* f_max is obtained from the optional "max-frequency" property */
|
|
device_property_read_u32(dev, "max-frequency", &host->f_max);
|
|
|
|
/*
|
|
* Configure CD and WP pins. They are both by default active low to
|
|
* match the SDHCI spec. If GPIOs are provided for CD and / or WP, the
|
|
* mmc-gpio helpers are used to attach, configure and use them. If
|
|
* polarity inversion is specified in DT, one of MMC_CAP2_CD_ACTIVE_HIGH
|
|
* and MMC_CAP2_RO_ACTIVE_HIGH capability-2 flags is set. If the
|
|
* "broken-cd" property is provided, the MMC_CAP_NEEDS_POLL capability
|
|
* is set. If the "non-removable" property is found, the
|
|
* MMC_CAP_NONREMOVABLE capability is set and no card-detection
|
|
* configuration is performed.
|
|
*/
|
|
|
|
/* Parse Card Detection */
|
|
if (device_property_read_bool(dev, "non-removable")) {
|
|
host->caps |= MMC_CAP_NONREMOVABLE;
|
|
} else {
|
|
cd_cap_invert = device_property_read_bool(dev, "cd-inverted");
|
|
|
|
if (device_property_read_u32(dev, "cd-debounce-delay-ms",
|
|
&cd_debounce_delay_ms))
|
|
cd_debounce_delay_ms = 200;
|
|
|
|
if (device_property_read_bool(dev, "broken-cd"))
|
|
host->caps |= MMC_CAP_NEEDS_POLL;
|
|
|
|
ret = mmc_gpiod_request_cd(host, "cd", 0, true,
|
|
cd_debounce_delay_ms * 1000,
|
|
&cd_gpio_invert);
|
|
if (!ret)
|
|
dev_info(host->parent, "Got CD GPIO\n");
|
|
else if (ret != -ENOENT && ret != -ENOSYS)
|
|
return ret;
|
|
|
|
/*
|
|
* There are two ways to flag that the CD line is inverted:
|
|
* through the cd-inverted flag and by the GPIO line itself
|
|
* being inverted from the GPIO subsystem. This is a leftover
|
|
* from the times when the GPIO subsystem did not make it
|
|
* possible to flag a line as inverted.
|
|
*
|
|
* If the capability on the host AND the GPIO line are
|
|
* both inverted, the end result is that the CD line is
|
|
* not inverted.
|
|
*/
|
|
if (cd_cap_invert ^ cd_gpio_invert)
|
|
host->caps2 |= MMC_CAP2_CD_ACTIVE_HIGH;
|
|
}
|
|
|
|
/* Parse Write Protection */
|
|
ro_cap_invert = device_property_read_bool(dev, "wp-inverted");
|
|
|
|
ret = mmc_gpiod_request_ro(host, "wp", 0, false, 0, &ro_gpio_invert);
|
|
if (!ret)
|
|
dev_info(host->parent, "Got WP GPIO\n");
|
|
else if (ret != -ENOENT && ret != -ENOSYS)
|
|
return ret;
|
|
|
|
if (device_property_read_bool(dev, "disable-wp"))
|
|
host->caps2 |= MMC_CAP2_NO_WRITE_PROTECT;
|
|
|
|
/* See the comment on CD inversion above */
|
|
if (ro_cap_invert ^ ro_gpio_invert)
|
|
host->caps2 |= MMC_CAP2_RO_ACTIVE_HIGH;
|
|
|
|
if (device_property_read_bool(dev, "cap-sd-highspeed"))
|
|
host->caps |= MMC_CAP_SD_HIGHSPEED;
|
|
if (device_property_read_bool(dev, "cap-mmc-highspeed"))
|
|
host->caps |= MMC_CAP_MMC_HIGHSPEED;
|
|
if (device_property_read_bool(dev, "sd-uhs-sdr12"))
|
|
host->caps |= MMC_CAP_UHS_SDR12;
|
|
if (device_property_read_bool(dev, "sd-uhs-sdr25"))
|
|
host->caps |= MMC_CAP_UHS_SDR25;
|
|
if (device_property_read_bool(dev, "sd-uhs-sdr50"))
|
|
host->caps |= MMC_CAP_UHS_SDR50;
|
|
if (device_property_read_bool(dev, "sd-uhs-sdr104"))
|
|
host->caps |= MMC_CAP_UHS_SDR104;
|
|
if (device_property_read_bool(dev, "sd-uhs-ddr50"))
|
|
host->caps |= MMC_CAP_UHS_DDR50;
|
|
if (device_property_read_bool(dev, "cap-power-off-card"))
|
|
host->caps |= MMC_CAP_POWER_OFF_CARD;
|
|
if (device_property_read_bool(dev, "cap-mmc-hw-reset"))
|
|
host->caps |= MMC_CAP_HW_RESET;
|
|
if (device_property_read_bool(dev, "cap-sdio-irq"))
|
|
host->caps |= MMC_CAP_SDIO_IRQ;
|
|
if (device_property_read_bool(dev, "full-pwr-cycle"))
|
|
host->caps2 |= MMC_CAP2_FULL_PWR_CYCLE;
|
|
if (device_property_read_bool(dev, "keep-power-in-suspend"))
|
|
host->pm_caps |= MMC_PM_KEEP_POWER;
|
|
if (device_property_read_bool(dev, "wakeup-source") ||
|
|
device_property_read_bool(dev, "enable-sdio-wakeup")) /* legacy */
|
|
host->pm_caps |= MMC_PM_WAKE_SDIO_IRQ;
|
|
if (device_property_read_bool(dev, "mmc-ddr-3_3v"))
|
|
host->caps |= MMC_CAP_3_3V_DDR;
|
|
if (device_property_read_bool(dev, "mmc-ddr-1_8v"))
|
|
host->caps |= MMC_CAP_1_8V_DDR;
|
|
if (device_property_read_bool(dev, "mmc-ddr-1_2v"))
|
|
host->caps |= MMC_CAP_1_2V_DDR;
|
|
if (device_property_read_bool(dev, "mmc-hs200-1_8v"))
|
|
host->caps2 |= MMC_CAP2_HS200_1_8V_SDR;
|
|
if (device_property_read_bool(dev, "mmc-hs200-1_2v"))
|
|
host->caps2 |= MMC_CAP2_HS200_1_2V_SDR;
|
|
if (device_property_read_bool(dev, "mmc-hs400-1_8v"))
|
|
host->caps2 |= MMC_CAP2_HS400_1_8V | MMC_CAP2_HS200_1_8V_SDR;
|
|
if (device_property_read_bool(dev, "mmc-hs400-1_2v"))
|
|
host->caps2 |= MMC_CAP2_HS400_1_2V | MMC_CAP2_HS200_1_2V_SDR;
|
|
if (device_property_read_bool(dev, "mmc-hs400-enhanced-strobe"))
|
|
host->caps2 |= MMC_CAP2_HS400_ES;
|
|
if (device_property_read_bool(dev, "no-sdio"))
|
|
host->caps2 |= MMC_CAP2_NO_SDIO;
|
|
if (device_property_read_bool(dev, "no-sd"))
|
|
host->caps2 |= MMC_CAP2_NO_SD;
|
|
if (device_property_read_bool(dev, "no-mmc"))
|
|
host->caps2 |= MMC_CAP2_NO_MMC;
|
|
|
|
/* Must be after "non-removable" check */
|
|
if (device_property_read_u32(dev, "fixed-emmc-driver-type", &drv_type) == 0) {
|
|
if (host->caps & MMC_CAP_NONREMOVABLE)
|
|
host->fixed_drv_type = drv_type;
|
|
else
|
|
dev_err(host->parent,
|
|
"can't use fixed driver type, media is removable\n");
|
|
}
|
|
|
|
host->dsr_req = !device_property_read_u32(dev, "dsr", &host->dsr);
|
|
if (host->dsr_req && (host->dsr & ~0xffff)) {
|
|
dev_err(host->parent,
|
|
"device tree specified broken value for DSR: 0x%x, ignoring\n",
|
|
host->dsr);
|
|
host->dsr_req = 0;
|
|
}
|
|
|
|
device_property_read_u32(dev, "post-power-on-delay-ms",
|
|
&host->ios.power_delay_ms);
|
|
|
|
return mmc_pwrseq_alloc(host);
|
|
}
|
|
|
|
EXPORT_SYMBOL(mmc_of_parse);
|
|
|
|
/**
|
|
* mmc_alloc_host - initialise the per-host structure.
|
|
* @extra: sizeof private data structure
|
|
* @dev: pointer to host device model structure
|
|
*
|
|
* Initialise the per-host structure.
|
|
*/
|
|
struct mmc_host *mmc_alloc_host(int extra, struct device *dev)
|
|
{
|
|
int err;
|
|
struct mmc_host *host;
|
|
|
|
host = kzalloc(sizeof(struct mmc_host) + extra, GFP_KERNEL);
|
|
if (!host)
|
|
return NULL;
|
|
|
|
/* scanning will be enabled when we're ready */
|
|
host->rescan_disable = 1;
|
|
|
|
err = ida_simple_get(&mmc_host_ida, 0, 0, GFP_KERNEL);
|
|
if (err < 0) {
|
|
kfree(host);
|
|
return NULL;
|
|
}
|
|
|
|
host->index = err;
|
|
|
|
dev_set_name(&host->class_dev, "mmc%d", host->index);
|
|
|
|
host->parent = dev;
|
|
host->class_dev.parent = dev;
|
|
host->class_dev.class = &mmc_host_class;
|
|
device_initialize(&host->class_dev);
|
|
device_enable_async_suspend(&host->class_dev);
|
|
|
|
if (mmc_gpio_alloc(host)) {
|
|
put_device(&host->class_dev);
|
|
return NULL;
|
|
}
|
|
|
|
spin_lock_init(&host->lock);
|
|
atomic_set(&host->active_reqs, 0);
|
|
init_waitqueue_head(&host->wq);
|
|
INIT_DELAYED_WORK(&host->detect, mmc_rescan);
|
|
INIT_DELAYED_WORK(&host->sdio_irq_work, sdio_irq_work);
|
|
timer_setup(&host->retune_timer, mmc_retune_timer, 0);
|
|
|
|
/*
|
|
* By default, hosts do not support SGIO or large requests.
|
|
* They have to set these according to their abilities.
|
|
*/
|
|
host->max_segs = 1;
|
|
host->max_seg_size = PAGE_SIZE;
|
|
|
|
host->max_req_size = PAGE_SIZE;
|
|
host->max_blk_size = 512;
|
|
host->max_blk_count = PAGE_SIZE / 512;
|
|
|
|
host->fixed_drv_type = -EINVAL;
|
|
host->ios.power_delay_ms = 10;
|
|
|
|
return host;
|
|
}
|
|
EXPORT_SYMBOL(mmc_alloc_host);
|
|
|
|
static ssize_t enable_show(struct device *dev,
|
|
struct device_attribute *attr, char *buf)
|
|
{
|
|
struct mmc_host *host = cls_dev_to_mmc_host(dev);
|
|
|
|
if (!host)
|
|
return -EINVAL;
|
|
|
|
return snprintf(buf, PAGE_SIZE, "%d\n", mmc_can_scale_clk(host));
|
|
}
|
|
|
|
static ssize_t enable_store(struct device *dev,
|
|
struct device_attribute *attr, const char *buf, size_t count)
|
|
{
|
|
struct mmc_host *host = cls_dev_to_mmc_host(dev);
|
|
unsigned long value;
|
|
|
|
if (!host || !host->card || kstrtoul(buf, 0, &value))
|
|
return -EINVAL;
|
|
|
|
mmc_get_card(host->card, NULL);
|
|
|
|
if (!value) {
|
|
/* Suspend the clock scaling and mask host capability */
|
|
if (host->clk_scaling.enable)
|
|
mmc_suspend_clk_scaling(host);
|
|
host->clk_scaling.enable = false;
|
|
host->caps2 &= ~MMC_CAP2_CLK_SCALE;
|
|
host->clk_scaling.state = MMC_LOAD_HIGH;
|
|
/* Set to max. frequency when disabling */
|
|
mmc_clk_update_freq(host, host->card->clk_scaling_highest,
|
|
host->clk_scaling.state);
|
|
} else if (value) {
|
|
/* Unmask host capability and resume scaling */
|
|
host->caps2 |= MMC_CAP2_CLK_SCALE;
|
|
if (!host->clk_scaling.enable) {
|
|
host->clk_scaling.enable = true;
|
|
mmc_resume_clk_scaling(host);
|
|
}
|
|
}
|
|
|
|
mmc_put_card(host->card, NULL);
|
|
|
|
return count;
|
|
}
|
|
|
|
static ssize_t up_threshold_show(struct device *dev,
|
|
struct device_attribute *attr, char *buf)
|
|
{
|
|
struct mmc_host *host = cls_dev_to_mmc_host(dev);
|
|
|
|
if (!host)
|
|
return -EINVAL;
|
|
|
|
return snprintf(buf, PAGE_SIZE, "%d\n", host->clk_scaling.upthreshold);
|
|
}
|
|
|
|
#define MAX_PERCENTAGE 100
|
|
static ssize_t up_threshold_store(struct device *dev,
|
|
struct device_attribute *attr, const char *buf, size_t count)
|
|
{
|
|
struct mmc_host *host = cls_dev_to_mmc_host(dev);
|
|
unsigned long value;
|
|
|
|
if (!host || kstrtoul(buf, 0, &value) || (value > MAX_PERCENTAGE))
|
|
return -EINVAL;
|
|
|
|
host->clk_scaling.upthreshold = value;
|
|
|
|
pr_debug("%s: clkscale_up_thresh set to %lu\n",
|
|
mmc_hostname(host), value);
|
|
return count;
|
|
}
|
|
|
|
static ssize_t down_threshold_show(struct device *dev,
|
|
struct device_attribute *attr, char *buf)
|
|
{
|
|
struct mmc_host *host = cls_dev_to_mmc_host(dev);
|
|
|
|
if (!host)
|
|
return -EINVAL;
|
|
|
|
return snprintf(buf, PAGE_SIZE, "%d\n",
|
|
host->clk_scaling.downthreshold);
|
|
}
|
|
|
|
static ssize_t down_threshold_store(struct device *dev,
|
|
struct device_attribute *attr, const char *buf, size_t count)
|
|
{
|
|
struct mmc_host *host = cls_dev_to_mmc_host(dev);
|
|
unsigned long value;
|
|
|
|
if (!host || kstrtoul(buf, 0, &value) || (value > MAX_PERCENTAGE))
|
|
return -EINVAL;
|
|
|
|
host->clk_scaling.downthreshold = value;
|
|
|
|
pr_debug("%s: clkscale_down_thresh set to %lu\n",
|
|
mmc_hostname(host), value);
|
|
return count;
|
|
}
|
|
|
|
static ssize_t polling_interval_show(struct device *dev,
|
|
struct device_attribute *attr, char *buf)
|
|
{
|
|
struct mmc_host *host = cls_dev_to_mmc_host(dev);
|
|
|
|
if (!host)
|
|
return -EINVAL;
|
|
|
|
return snprintf(buf, PAGE_SIZE, "%lu milliseconds\n",
|
|
host->clk_scaling.polling_delay_ms);
|
|
}
|
|
|
|
static ssize_t polling_interval_store(struct device *dev,
|
|
struct device_attribute *attr, const char *buf, size_t count)
|
|
{
|
|
struct mmc_host *host = cls_dev_to_mmc_host(dev);
|
|
unsigned long value;
|
|
|
|
if (!host || kstrtoul(buf, 0, &value))
|
|
return -EINVAL;
|
|
|
|
host->clk_scaling.polling_delay_ms = value;
|
|
|
|
pr_debug("%s: clkscale_polling_delay_ms set to %lu\n",
|
|
mmc_hostname(host), value);
|
|
return count;
|
|
}
|
|
|
|
DEVICE_ATTR_RW(enable);
|
|
DEVICE_ATTR_RW(polling_interval);
|
|
DEVICE_ATTR_RW(up_threshold);
|
|
DEVICE_ATTR_RW(down_threshold);
|
|
|
|
static struct attribute *clk_scaling_attrs[] = {
|
|
&dev_attr_enable.attr,
|
|
&dev_attr_up_threshold.attr,
|
|
&dev_attr_down_threshold.attr,
|
|
&dev_attr_polling_interval.attr,
|
|
NULL,
|
|
};
|
|
|
|
static struct attribute_group clk_scaling_attr_grp = {
|
|
.name = "clk_scaling",
|
|
.attrs = clk_scaling_attrs,
|
|
};
|
|
|
|
static int mmc_validate_host_caps(struct mmc_host *host)
|
|
{
|
|
if (host->caps & MMC_CAP_SDIO_IRQ && !host->ops->enable_sdio_irq) {
|
|
dev_warn(host->parent, "missing ->enable_sdio_irq() ops\n");
|
|
return -EINVAL;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
/**
|
|
* mmc_add_host - initialise host hardware
|
|
* @host: mmc host
|
|
*
|
|
* Register the host with the driver model. The host must be
|
|
* prepared to start servicing requests before this function
|
|
* completes.
|
|
*/
|
|
int mmc_add_host(struct mmc_host *host)
|
|
{
|
|
int err;
|
|
|
|
err = mmc_validate_host_caps(host);
|
|
if (err)
|
|
return err;
|
|
|
|
err = device_add(&host->class_dev);
|
|
if (err)
|
|
return err;
|
|
|
|
led_trigger_register_simple(dev_name(&host->class_dev), &host->led);
|
|
|
|
host->clk_scaling.upthreshold = MMC_DEVFRQ_DEFAULT_UP_THRESHOLD;
|
|
host->clk_scaling.downthreshold = MMC_DEVFRQ_DEFAULT_DOWN_THRESHOLD;
|
|
host->clk_scaling.polling_delay_ms = MMC_DEVFRQ_DEFAULT_POLLING_MSEC;
|
|
host->clk_scaling.skip_clk_scale_freq_update = false;
|
|
|
|
#ifdef CONFIG_DEBUG_FS
|
|
mmc_add_host_debugfs(host);
|
|
#endif
|
|
|
|
#ifdef CONFIG_MMC_IPC_LOGGING
|
|
host->ipc_log_ctxt = ipc_log_context_create(NUM_LOG_PAGES,
|
|
dev_name(&host->class_dev), 0);
|
|
if (!host->ipc_log_ctxt)
|
|
pr_err("%s: Error getting ipc_log_ctxt\n", __func__);
|
|
#endif
|
|
|
|
err = sysfs_create_group(&host->class_dev.kobj, &clk_scaling_attr_grp);
|
|
if (err)
|
|
pr_err("%s: failed to create clk scale sysfs group with err %d\n",
|
|
__func__, err);
|
|
|
|
mmc_start_host(host);
|
|
if (!(host->pm_flags & MMC_PM_IGNORE_PM_NOTIFY))
|
|
mmc_register_pm_notifier(host);
|
|
|
|
return 0;
|
|
}
|
|
|
|
EXPORT_SYMBOL(mmc_add_host);
|
|
|
|
/**
|
|
* mmc_remove_host - remove host hardware
|
|
* @host: mmc host
|
|
*
|
|
* Unregister and remove all cards associated with this host,
|
|
* and power down the MMC bus. No new requests will be issued
|
|
* after this function has returned.
|
|
*/
|
|
void mmc_remove_host(struct mmc_host *host)
|
|
{
|
|
if (!(host->pm_flags & MMC_PM_IGNORE_PM_NOTIFY))
|
|
mmc_unregister_pm_notifier(host);
|
|
mmc_stop_host(host);
|
|
|
|
#ifdef CONFIG_DEBUG_FS
|
|
mmc_remove_host_debugfs(host);
|
|
#endif
|
|
|
|
#ifdef CONFIG_MMC_IPC_LOGGING
|
|
ipc_log_context_destroy(host->ipc_log_ctxt);
|
|
host->ipc_log_ctxt = NULL;
|
|
#endif
|
|
sysfs_remove_group(&host->class_dev.kobj, &clk_scaling_attr_grp);
|
|
|
|
device_del(&host->class_dev);
|
|
|
|
led_trigger_unregister_simple(host->led);
|
|
}
|
|
|
|
EXPORT_SYMBOL(mmc_remove_host);
|
|
|
|
/**
|
|
* mmc_free_host - free the host structure
|
|
* @host: mmc host
|
|
*
|
|
* Free the host once all references to it have been dropped.
|
|
*/
|
|
void mmc_free_host(struct mmc_host *host)
|
|
{
|
|
cancel_delayed_work_sync(&host->detect);
|
|
mmc_crypto_free_host(host);
|
|
mmc_pwrseq_free(host);
|
|
put_device(&host->class_dev);
|
|
}
|
|
|
|
EXPORT_SYMBOL(mmc_free_host);
|