Changes in 4.9.337 mm/khugepaged: fix GUP-fast interaction by sending IPI mm/khugepaged: invoke MMU notifiers in shmem/file collapse paths block: unhash blkdev part inode when the part is deleted ASoC: ops: Check bounds for second channel in snd_soc_put_volsw_sx() can: sja1000: fix size of OCR_MODE_MASK define ASoC: ops: Correct bounds check for second channel on SX controls udf: Discard preallocation before extending file with a hole udf: Drop unused arguments of udf_delete_aext() udf: Fix preallocation discarding at indirect extent boundary udf: Do not bother looking for prealloc extents if i_lenExtents matches i_size udf: Fix extending file within last block usb: gadget: uvc: Prevent buffer overflow in setup handler USB: serial: cp210x: add Kamstrup RF sniffer PIDs Bluetooth: L2CAP: Fix u8 overflow net: loopback: use NET_NAME_PREDICTABLE for name_assign_type drivers: soc: ti: knav_qmss_queue: Mark knav_acc_firmwares as static arm: dts: spear600: Fix clcd interrupt soc: ti: smartreflex: Fix PM disable depth imbalance in omap_sr_probe ARM: dts: dove: Fix assigned-addresses for every PCIe Root Port ARM: dts: armada-370: Fix assigned-addresses for every PCIe Root Port ARM: dts: armada-xp: Fix assigned-addresses for every PCIe Root Port ARM: dts: armada-375: Fix assigned-addresses for every PCIe Root Port ARM: dts: armada-38x: Fix assigned-addresses for every PCIe Root Port ARM: dts: armada-39x: Fix assigned-addresses for every PCIe Root Port ARM: mmp: fix timer_read delay pstore: Avoid kcore oops by vmap()ing with VM_IOREMAP cpuidle: dt: Return the correct numbers of parsed idle states alpha: fix syscall entry in !AUDUT_SYSCALL case PM: hibernate: Fix mistake in kerneldoc comment fs: don't audit the capability check in simple_xattr_list() perf: Fix possible memleak in pmu_dev_alloc() timerqueue: Use rb_entry_safe() in timerqueue_getnext() ocfs2: fix memory leak in ocfs2_stack_glue_init() MIPS: vpe-mt: fix possible memory leak while module exiting MIPS: vpe-cmp: fix possible memory leak while module exiting PNP: fix name memory leak in pnp_alloc_dev() irqchip: gic-pm: Use pm_runtime_resume_and_get() in gic_probe() libfs: add DEFINE_SIMPLE_ATTRIBUTE_SIGNED for signed value lib/notifier-error-inject: fix error when writing -errno to debugfs file rapidio: fix possible name leaks when rio_add_device() fails rapidio: rio: fix possible name leak in rio_register_mport() ACPICA: Fix use-after-free in acpi_ut_copy_ipackage_to_ipackage() uprobes/x86: Allow to probe a NOP instruction with 0x66 prefix x86/xen: Fix memory leak in xen_init_lock_cpu() MIPS: BCM63xx: Add check for NULL for clk in clk_enable fs: sysv: Fix sysv_nblocks() returns wrong value rapidio: fix possible UAF when kfifo_alloc() fails eventfd: change int to __u64 in eventfd_signal() ifndef CONFIG_EVENTFD hfs: Fix OOB Write in hfs_asc2mac rapidio: devices: fix missing put_device in mport_cdev_open wifi: ath9k: hif_usb: fix memory leak of urbs in ath9k_hif_usb_dealloc_tx_urbs() wifi: ath9k: hif_usb: Fix use-after-free in ath9k_hif_usb_reg_in_cb() media: i2c: ad5820: Fix error path media: vivid: fix compose size exceed boundary mtd: Fix device name leak when register device failed in add_mtd_device() ASoC: pxa: fix null-pointer dereference in filter() regulator: core: fix unbalanced of node refcount in regulator_dev_lookup() ima: Fix misuse of dereference of pointer in template_desc_init_fields() wifi: ath10k: Fix return value in ath10k_pci_init() mtd: lpddr2_nvm: Fix possible null-ptr-deref Input: elants_i2c - properly handle the reset GPIO when power is off media: solo6x10: fix possible memory leak in solo_sysfs_init() media: platform: exynos4-is: Fix error handling in fimc_md_init() HID: hid-sensor-custom: set fixed size for custom attributes ALSA: seq: fix undefined behavior in bit shift for SNDRV_SEQ_FILTER_USE_EVENT clk: rockchip: Fix memory leak in rockchip_clk_register_pll() mtd: maps: pxa2xx-flash: fix memory leak in probe media: imon: fix a race condition in send_packet() pinctrl: pinconf-generic: add missing of_node_put() media: dvb-usb: az6027: fix null-ptr-deref in az6027_i2c_xfer() NFSv4.2: Fix a memory stomp in decode_attr_security_label NFSv4: Fix a deadlock between nfs4_open_recover_helper() and delegreturn ALSA: asihpi: fix missing pci_disable_device() drm/radeon: Fix PCI device refcount leak in radeon_atrm_get_bios() drm/amdgpu: Fix PCI device refcount leak in amdgpu_atrm_get_bios() ASoC: pcm512x: Fix PM disable depth imbalance in pcm512x_probe bonding: uninitialized variable in bond_miimon_inspect() regulator: core: fix module refcount leak in set_supply() media: saa7164: fix missing pci_disable_device() ALSA: mts64: fix possible null-ptr-defer in snd_mts64_interrupt SUNRPC: Fix missing release socket in rpc_sockname() mmc: moxart: fix return value check of mmc_add_host() mmc: mxcmmc: fix return value check of mmc_add_host() mmc: rtsx_usb_sdmmc: fix return value check of mmc_add_host() mmc: toshsd: fix return value check of mmc_add_host() mmc: vub300: fix return value check of mmc_add_host() mmc: via-sdmmc: fix return value check of mmc_add_host() mmc: wbsd: fix return value check of mmc_add_host() mmc: mmci: fix return value check of mmc_add_host() media: c8sectpfe: Add of_node_put() when breaking out of loop media: coda: Add check for dcoda_iram_alloc media: coda: Add check for kmalloc wifi: rtl8xxxu: Add __packed to struct rtl8723bu_c2h wifi: brcmfmac: Fix error return code in brcmf_sdio_download_firmware() blktrace: Fix output non-blktrace event when blk_classic option enabled net: vmw_vsock: vmci: Check memcpy_from_msg() net: defxx: Fix missing err handling in dfx_init() drivers: net: qlcnic: Fix potential memory leak in qlcnic_sriov_init() ethernet: s2io: don't call dev_kfree_skb() under spin_lock_irqsave() net: farsync: Fix kmemleak when rmmods farsync net/tunnel: wait until all sk_user_data reader finish before releasing the sock net: apple: mace: don't call dev_kfree_skb() under spin_lock_irqsave() net: apple: bmac: don't call dev_kfree_skb() under spin_lock_irqsave() net: emaclite: don't call dev_kfree_skb() under spin_lock_irqsave() net: ethernet: dnet: don't call dev_kfree_skb() under spin_lock_irqsave() hamradio: don't call dev_kfree_skb() under spin_lock_irqsave() net: amd: lance: don't call dev_kfree_skb() under spin_lock_irqsave() ntb_netdev: Use dev_kfree_skb_any() in interrupt context Bluetooth: btusb: don't call kfree_skb() under spin_lock_irqsave() Bluetooth: hci_qca: don't call kfree_skb() under spin_lock_irqsave() Bluetooth: hci_h5: don't call kfree_skb() under spin_lock_irqsave() Bluetooth: hci_bcsp: don't call kfree_skb() under spin_lock_irqsave() Bluetooth: hci_core: don't call kfree_skb() under spin_lock_irqsave() stmmac: fix potential division by 0 scsi: hpsa: Fix error handling in hpsa_add_sas_host() scsi: hpsa: Fix possible memory leak in hpsa_add_sas_device() scsi: fcoe: Fix possible name leak when device_register() fails scsi: ipr: Fix WARNING in ipr_init() scsi: fcoe: Fix transport not deattached when fcoe_if_init() fails scsi: snic: Fix possible UAF in snic_tgt_create() orangefs: Fix sysfs not cleanup when dev init failed crypto: img-hash - Fix variable dereferenced before check 'hdev->req' hwrng: amd - Fix PCI device refcount leak hwrng: geode - Fix PCI device refcount leak IB/IPoIB: Fix queue count inconsistency for PKEY child interfaces drivers: dio: fix possible memory leak in dio_init() vfio: platform: Do not pass return buffer to ACPI _RST method uio: uio_dmem_genirq: Fix missing unlock in irq configuration uio: uio_dmem_genirq: Fix deadlock between irq config and handling usb: fotg210-udc: Fix ages old endianness issues staging: vme_user: Fix possible UAF in tsi148_dma_list_add serial: amba-pl011: avoid SBSA UART accessing DMACR register serial: pch: Fix PCI device refcount leak in pch_request_dma() serial: sunsab: Fix error handling in sunsab_init() misc: tifm: fix possible memory leak in tifm_7xx1_switch_media() misc: sgi-gru: fix use-after-free error in gru_set_context_option, gru_fault and gru_handle_user_call_os cxl: fix possible null-ptr-deref in cxl_guest_init_afu|adapter() cxl: fix possible null-ptr-deref in cxl_pci_init_afu|adapter() drivers: mcb: fix resource leak in mcb_probe() mcb: mcb-parse: fix error handing in chameleon_parse_gdd() chardev: fix error handling in cdev_device_add() i2c: pxa-pci: fix missing pci_disable_device() on error in ce4100_i2c_probe staging: rtl8192u: Fix use after free in ieee80211_rx() staging: rtl8192e: Fix potential use-after-free in rtllib_rx_Monitor() vme: Fix error not catched in fake_init() i2c: ismt: Fix an out-of-bounds bug in ismt_access() usb: storage: Add check for kcalloc fbdev: ssd1307fb: Drop optional dependency fbdev: pm2fb: fix missing pci_disable_device() fbdev: via: Fix error in via_core_init() fbdev: vermilion: decrease reference count in error path fbdev: uvesafb: Fixes an error handling path in uvesafb_probe() HSI: omap_ssi_core: fix unbalanced pm_runtime_disable() HSI: omap_ssi_core: fix possible memory leak in ssi_probe() power: supply: fix residue sysfs file in error handle route of __power_supply_register() HSI: omap_ssi_core: Fix error handling in ssi_init() include/uapi/linux/swab: Fix potentially missing __always_inline rtc: snvs: Allow a time difference on clock register read iommu/fsl_pamu: Fix resource leak in fsl_pamu_probe() macintosh: fix possible memory leak in macio_add_one_device() macintosh/macio-adb: check the return value of ioremap() powerpc/52xx: Fix a resource leak in an error handling path powerpc/perf: callchain validate kernel stack pointer bounds powerpc/83xx/mpc832x_rdb: call platform_device_put() in error case in of_fsl_spi_probe() powerpc/hv-gpci: Fix hv_gpci event list selftests/powerpc: Fix resource leaks rtc: st-lpc: Add missing clk_disable_unprepare in st_rtc_probe() nfsd: under NFSv4.1, fix double svc_xprt_put on rpc_create failure mISDN: hfcsusb: don't call dev_kfree_skb/kfree_skb() under spin_lock_irqsave() mISDN: hfcpci: don't call dev_kfree_skb/kfree_skb() under spin_lock_irqsave() mISDN: hfcmulti: don't call dev_kfree_skb/kfree_skb() under spin_lock_irqsave() nfc: pn533: Clear nfc_target before being used r6040: Fix kmemleak in probe and remove openvswitch: Fix flow lookup to use unmasked key skbuff: Account for tail adjustment during pull operations net_sched: reject TCF_EM_SIMPLE case for complex ematch module myri10ge: Fix an error handling path in myri10ge_probe() net: stream: purge sk_error_queue in sk_stream_kill_queues() binfmt_misc: fix shift-out-of-bounds in check_special_flags fs: jfs: fix shift-out-of-bounds in dbAllocAG udf: Avoid double brelse() in udf_rename() fs: jfs: fix shift-out-of-bounds in dbDiscardAG ACPICA: Fix error code path in acpi_ds_call_control_method() nilfs2: fix shift-out-of-bounds/overflow in nilfs_sb2_bad_offset() acct: fix potential integer overflow in encode_comp_t() hfs: fix OOB Read in __hfs_brec_find wifi: ath9k: verify the expected usb_endpoints are present wifi: ar5523: Fix use-after-free on ar5523_cmd() timed out ipmi: fix memleak when unload ipmi driver net: ethernet: ti: Fix return type of netcp_ndo_start_xmit() hamradio: baycom_epp: Fix return type of baycom_send_packet() wifi: brcmfmac: Fix potential shift-out-of-bounds in brcmf_fw_alloc_request() igb: Do not free q_vector unless new one was allocated s390/ctcm: Fix return type of ctc{mp,}m_tx() s390/netiucv: Fix return type of netiucv_tx() s390/lcs: Fix return type of lcs_start_xmit() drm/sti: Use drm_mode_copy() md/raid1: stop mdx_raid1 thread when raid1 array run failed mrp: introduce active flags to prevent UAF when applicant uninit ppp: associate skb with a device at tx media: dvb-frontends: fix leak of memory fw media: dvb-usb: fix memory leak in dvb_usb_adapter_init() blk-mq: fix possible memleak when register 'hctx' failed mmc: f-sdh30: Add quirks for broken timeout clock capability media: si470x: Fix use-after-free in si470x_int_in_callback() clk: st: Fix memory leak in st_of_quadfs_setup() drm/fsl-dcu: Fix return type of fsl_dcu_drm_connector_mode_valid() drm/sti: Fix return type of sti_{dvo,hda,hdmi}_connector_mode_valid() orangefs: Fix kmemleak in orangefs_prepare_debugfs_help_string() ASoC: mediatek: mt8173-rt5650-rt5514: fix refcount leak in mt8173_rt5650_rt5514_dev_probe() ASoC: wm8994: Fix potential deadlock ASoC: rockchip: spdif: Add missing clk_disable_unprepare() in rk_spdif_runtime_resume() ASoC: rt5670: Remove unbalanced pm_runtime_put() HID: wacom: Ensure bootloader PID is usable in hidraw mode reiserfs: Add missing calls to reiserfs_security_free() iio: adc: ad_sigma_delta: do not use internal iio_dev lock gcov: add support for checksum field powerpc/rtas: avoid scheduling in rtas_os_term() HID: plantronics: Additional PIDs for double volume key presses quirk hfsplus: fix bug causing custom uid and gid being unable to be assigned with mount ALSA: line6: correct midi status byte when receiving data from podxt ALSA: line6: fix stack overflow in line6_midi_transmit pnode: terminate at peers of source md: fix a crash in mempool_free mmc: vub300: fix warning - do not call blocking ops when !TASK_RUNNING media: stv0288: use explicitly signed char ktest.pl minconfig: Unset configs instead of just removing them ARM: ux500: do not directly dereference __iomem dm cache: Fix ABBA deadlock between shrink_slab and dm_cache_metadata_abort dm thin: Use last transaction's pmd->root when commit failed dm thin: Fix UAF in run_timer_softirq() dm cache: Fix UAF in destroy() dm cache: set needs_check flag after aborting metadata tracing: Fix infinite loop in tracing_read_pipe on overflowed print_trace_line ARM: 9256/1: NWFPE: avoid compiler-generated __aeabi_uldivmod media: dvb-core: Fix double free in dvb_register_device() cifs: fix confusing debug message PCI/sysfs: Fix double free in error path crypto: n2 - add missing hash statesize iommu/amd: Fix ivrs_acpihid cmdline parsing code parisc: led: Fix potential null-ptr-deref in start_task() device_cgroup: Roll back to original exceptions after copy failure drm/connector: send hotplug uevent on connector cleanup drm/vmwgfx: Validate the box size for the snooped cursor ext4: add inode table check in __ext4_get_inode_loc to aovid possible infinite loop ext4: fix undefined behavior in bit shift for ext4_check_flag_values ext4: fix bug_on in __es_tree_search caused by bad boot loader inode ext4: init quota for 'old.inode' in 'ext4_rename' ext4: fix error code return to user-space in ext4_get_branch() ext4: avoid BUG_ON when creating xattrs ext4: initialize quota before expanding inode in setproject ioctl Linux 4.9.337 Change-Id: I923e3fef499ae1688b25c70a1a805b55a9f4f027 Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
714 lines
18 KiB
C
714 lines
18 KiB
C
/*
|
|
* Toshiba PCI Secure Digital Host Controller Interface driver
|
|
*
|
|
* Copyright (C) 2014 Ondrej Zary
|
|
* Copyright (C) 2007 Richard Betts, All Rights Reserved.
|
|
*
|
|
* Based on asic3_mmc.c, copyright (c) 2005 SDG Systems, LLC and,
|
|
* sdhci.c, copyright (C) 2005-2006 Pierre Ossman
|
|
*
|
|
* This program is free software; you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation; either version 2 of the License, or (at
|
|
* your option) any later version.
|
|
*/
|
|
|
|
#include <linux/delay.h>
|
|
#include <linux/device.h>
|
|
#include <linux/module.h>
|
|
#include <linux/pci.h>
|
|
#include <linux/scatterlist.h>
|
|
#include <linux/interrupt.h>
|
|
#include <linux/io.h>
|
|
#include <linux/pm.h>
|
|
#include <linux/pm_runtime.h>
|
|
#include <linux/mmc/host.h>
|
|
#include <linux/mmc/mmc.h>
|
|
|
|
#include "toshsd.h"
|
|
|
|
#define DRIVER_NAME "toshsd"
|
|
|
|
static const struct pci_device_id pci_ids[] = {
|
|
{ PCI_DEVICE(PCI_VENDOR_ID_TOSHIBA, 0x0805) },
|
|
{ /* end: all zeroes */ },
|
|
};
|
|
|
|
MODULE_DEVICE_TABLE(pci, pci_ids);
|
|
|
|
static void toshsd_init(struct toshsd_host *host)
|
|
{
|
|
/* enable clock */
|
|
pci_write_config_byte(host->pdev, SD_PCICFG_CLKSTOP,
|
|
SD_PCICFG_CLKSTOP_ENABLE_ALL);
|
|
pci_write_config_byte(host->pdev, SD_PCICFG_CARDDETECT, 2);
|
|
|
|
/* reset */
|
|
iowrite16(0, host->ioaddr + SD_SOFTWARERESET); /* assert */
|
|
mdelay(2);
|
|
iowrite16(1, host->ioaddr + SD_SOFTWARERESET); /* deassert */
|
|
mdelay(2);
|
|
|
|
/* Clear card registers */
|
|
iowrite16(0, host->ioaddr + SD_CARDCLOCKCTRL);
|
|
iowrite32(0, host->ioaddr + SD_CARDSTATUS);
|
|
iowrite32(0, host->ioaddr + SD_ERRORSTATUS0);
|
|
iowrite16(0, host->ioaddr + SD_STOPINTERNAL);
|
|
|
|
/* SDIO clock? */
|
|
iowrite16(0x100, host->ioaddr + SDIO_BASE + SDIO_CLOCKNWAITCTRL);
|
|
|
|
/* enable LED */
|
|
pci_write_config_byte(host->pdev, SD_PCICFG_SDLED_ENABLE1,
|
|
SD_PCICFG_LED_ENABLE1_START);
|
|
pci_write_config_byte(host->pdev, SD_PCICFG_SDLED_ENABLE2,
|
|
SD_PCICFG_LED_ENABLE2_START);
|
|
|
|
/* set interrupt masks */
|
|
iowrite32(~(u32)(SD_CARD_RESP_END | SD_CARD_RW_END
|
|
| SD_CARD_CARD_REMOVED_0 | SD_CARD_CARD_INSERTED_0
|
|
| SD_BUF_READ_ENABLE | SD_BUF_WRITE_ENABLE
|
|
| SD_BUF_CMD_TIMEOUT),
|
|
host->ioaddr + SD_INTMASKCARD);
|
|
|
|
iowrite16(0x1000, host->ioaddr + SD_TRANSACTIONCTRL);
|
|
}
|
|
|
|
/* Set MMC clock / power.
|
|
* Note: This controller uses a simple divider scheme therefore it cannot run
|
|
* SD/MMC cards at full speed (24/20MHz). HCLK (=33MHz PCI clock?) is too high
|
|
* and the next slowest is 16MHz (div=2).
|
|
*/
|
|
static void __toshsd_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
|
|
{
|
|
struct toshsd_host *host = mmc_priv(mmc);
|
|
|
|
if (ios->clock) {
|
|
u16 clk;
|
|
int div = 1;
|
|
|
|
while (ios->clock < HCLK / div)
|
|
div *= 2;
|
|
|
|
clk = div >> 2;
|
|
|
|
if (div == 1) { /* disable the divider */
|
|
pci_write_config_byte(host->pdev, SD_PCICFG_CLKMODE,
|
|
SD_PCICFG_CLKMODE_DIV_DISABLE);
|
|
clk |= SD_CARDCLK_DIV_DISABLE;
|
|
} else
|
|
pci_write_config_byte(host->pdev, SD_PCICFG_CLKMODE, 0);
|
|
|
|
clk |= SD_CARDCLK_ENABLE_CLOCK;
|
|
iowrite16(clk, host->ioaddr + SD_CARDCLOCKCTRL);
|
|
|
|
mdelay(10);
|
|
} else
|
|
iowrite16(0, host->ioaddr + SD_CARDCLOCKCTRL);
|
|
|
|
switch (ios->power_mode) {
|
|
case MMC_POWER_OFF:
|
|
pci_write_config_byte(host->pdev, SD_PCICFG_POWER1,
|
|
SD_PCICFG_PWR1_OFF);
|
|
mdelay(1);
|
|
break;
|
|
case MMC_POWER_UP:
|
|
break;
|
|
case MMC_POWER_ON:
|
|
pci_write_config_byte(host->pdev, SD_PCICFG_POWER1,
|
|
SD_PCICFG_PWR1_33V);
|
|
pci_write_config_byte(host->pdev, SD_PCICFG_POWER2,
|
|
SD_PCICFG_PWR2_AUTO);
|
|
mdelay(20);
|
|
break;
|
|
}
|
|
|
|
switch (ios->bus_width) {
|
|
case MMC_BUS_WIDTH_1:
|
|
iowrite16(SD_CARDOPT_REQUIRED | SD_CARDOPT_DATA_RESP_TIMEOUT(14)
|
|
| SD_CARDOPT_C2_MODULE_ABSENT
|
|
| SD_CARDOPT_DATA_XFR_WIDTH_1,
|
|
host->ioaddr + SD_CARDOPTIONSETUP);
|
|
break;
|
|
case MMC_BUS_WIDTH_4:
|
|
iowrite16(SD_CARDOPT_REQUIRED | SD_CARDOPT_DATA_RESP_TIMEOUT(14)
|
|
| SD_CARDOPT_C2_MODULE_ABSENT
|
|
| SD_CARDOPT_DATA_XFR_WIDTH_4,
|
|
host->ioaddr + SD_CARDOPTIONSETUP);
|
|
break;
|
|
}
|
|
}
|
|
|
|
static void toshsd_set_led(struct toshsd_host *host, unsigned char state)
|
|
{
|
|
iowrite16(state, host->ioaddr + SDIO_BASE + SDIO_LEDCTRL);
|
|
}
|
|
|
|
static void toshsd_finish_request(struct toshsd_host *host)
|
|
{
|
|
struct mmc_request *mrq = host->mrq;
|
|
|
|
/* Write something to end the command */
|
|
host->mrq = NULL;
|
|
host->cmd = NULL;
|
|
host->data = NULL;
|
|
|
|
toshsd_set_led(host, 0);
|
|
mmc_request_done(host->mmc, mrq);
|
|
}
|
|
|
|
static irqreturn_t toshsd_thread_irq(int irq, void *dev_id)
|
|
{
|
|
struct toshsd_host *host = dev_id;
|
|
struct mmc_data *data = host->data;
|
|
struct sg_mapping_iter *sg_miter = &host->sg_miter;
|
|
unsigned short *buf;
|
|
int count;
|
|
unsigned long flags;
|
|
|
|
if (!data) {
|
|
dev_warn(&host->pdev->dev, "Spurious Data IRQ\n");
|
|
if (host->cmd) {
|
|
host->cmd->error = -EIO;
|
|
toshsd_finish_request(host);
|
|
}
|
|
return IRQ_NONE;
|
|
}
|
|
spin_lock_irqsave(&host->lock, flags);
|
|
|
|
if (!sg_miter_next(sg_miter))
|
|
goto done;
|
|
|
|
buf = sg_miter->addr;
|
|
|
|
/* Ensure we dont read more than one block. The chip will interrupt us
|
|
* When the next block is available.
|
|
*/
|
|
count = sg_miter->length;
|
|
if (count > data->blksz)
|
|
count = data->blksz;
|
|
|
|
dev_dbg(&host->pdev->dev, "count: %08x, flags %08x\n", count,
|
|
data->flags);
|
|
|
|
/* Transfer the data */
|
|
if (data->flags & MMC_DATA_READ)
|
|
ioread32_rep(host->ioaddr + SD_DATAPORT, buf, count >> 2);
|
|
else
|
|
iowrite32_rep(host->ioaddr + SD_DATAPORT, buf, count >> 2);
|
|
|
|
sg_miter->consumed = count;
|
|
sg_miter_stop(sg_miter);
|
|
|
|
done:
|
|
spin_unlock_irqrestore(&host->lock, flags);
|
|
|
|
return IRQ_HANDLED;
|
|
}
|
|
|
|
static void toshsd_cmd_irq(struct toshsd_host *host)
|
|
{
|
|
struct mmc_command *cmd = host->cmd;
|
|
u8 *buf;
|
|
u16 data;
|
|
|
|
if (!host->cmd) {
|
|
dev_warn(&host->pdev->dev, "Spurious CMD irq\n");
|
|
return;
|
|
}
|
|
buf = (u8 *)cmd->resp;
|
|
host->cmd = NULL;
|
|
|
|
if (cmd->flags & MMC_RSP_PRESENT && cmd->flags & MMC_RSP_136) {
|
|
/* R2 */
|
|
buf[12] = 0xff;
|
|
data = ioread16(host->ioaddr + SD_RESPONSE0);
|
|
buf[13] = data & 0xff;
|
|
buf[14] = data >> 8;
|
|
data = ioread16(host->ioaddr + SD_RESPONSE1);
|
|
buf[15] = data & 0xff;
|
|
buf[8] = data >> 8;
|
|
data = ioread16(host->ioaddr + SD_RESPONSE2);
|
|
buf[9] = data & 0xff;
|
|
buf[10] = data >> 8;
|
|
data = ioread16(host->ioaddr + SD_RESPONSE3);
|
|
buf[11] = data & 0xff;
|
|
buf[4] = data >> 8;
|
|
data = ioread16(host->ioaddr + SD_RESPONSE4);
|
|
buf[5] = data & 0xff;
|
|
buf[6] = data >> 8;
|
|
data = ioread16(host->ioaddr + SD_RESPONSE5);
|
|
buf[7] = data & 0xff;
|
|
buf[0] = data >> 8;
|
|
data = ioread16(host->ioaddr + SD_RESPONSE6);
|
|
buf[1] = data & 0xff;
|
|
buf[2] = data >> 8;
|
|
data = ioread16(host->ioaddr + SD_RESPONSE7);
|
|
buf[3] = data & 0xff;
|
|
} else if (cmd->flags & MMC_RSP_PRESENT) {
|
|
/* R1, R1B, R3, R6, R7 */
|
|
data = ioread16(host->ioaddr + SD_RESPONSE0);
|
|
buf[0] = data & 0xff;
|
|
buf[1] = data >> 8;
|
|
data = ioread16(host->ioaddr + SD_RESPONSE1);
|
|
buf[2] = data & 0xff;
|
|
buf[3] = data >> 8;
|
|
}
|
|
|
|
dev_dbg(&host->pdev->dev, "Command IRQ complete %d %d %x\n",
|
|
cmd->opcode, cmd->error, cmd->flags);
|
|
|
|
/* If there is data to handle we will
|
|
* finish the request in the mmc_data_end_irq handler.*/
|
|
if (host->data)
|
|
return;
|
|
|
|
toshsd_finish_request(host);
|
|
}
|
|
|
|
static void toshsd_data_end_irq(struct toshsd_host *host)
|
|
{
|
|
struct mmc_data *data = host->data;
|
|
|
|
host->data = NULL;
|
|
|
|
if (!data) {
|
|
dev_warn(&host->pdev->dev, "Spurious data end IRQ\n");
|
|
return;
|
|
}
|
|
|
|
if (data->error == 0)
|
|
data->bytes_xfered = data->blocks * data->blksz;
|
|
else
|
|
data->bytes_xfered = 0;
|
|
|
|
dev_dbg(&host->pdev->dev, "Completed data request xfr=%d\n",
|
|
data->bytes_xfered);
|
|
|
|
iowrite16(0, host->ioaddr + SD_STOPINTERNAL);
|
|
|
|
toshsd_finish_request(host);
|
|
}
|
|
|
|
static irqreturn_t toshsd_irq(int irq, void *dev_id)
|
|
{
|
|
struct toshsd_host *host = dev_id;
|
|
u32 int_reg, int_mask, int_status, detail;
|
|
int error = 0, ret = IRQ_HANDLED;
|
|
|
|
spin_lock(&host->lock);
|
|
int_status = ioread32(host->ioaddr + SD_CARDSTATUS);
|
|
int_mask = ioread32(host->ioaddr + SD_INTMASKCARD);
|
|
int_reg = int_status & ~int_mask & ~IRQ_DONT_CARE_BITS;
|
|
|
|
dev_dbg(&host->pdev->dev, "IRQ status:%x mask:%x\n",
|
|
int_status, int_mask);
|
|
|
|
/* nothing to do: it's not our IRQ */
|
|
if (!int_reg) {
|
|
ret = IRQ_NONE;
|
|
goto irq_end;
|
|
}
|
|
|
|
if (int_reg & SD_BUF_CMD_TIMEOUT) {
|
|
error = -ETIMEDOUT;
|
|
dev_dbg(&host->pdev->dev, "Timeout\n");
|
|
} else if (int_reg & SD_BUF_CRC_ERR) {
|
|
error = -EILSEQ;
|
|
dev_err(&host->pdev->dev, "BadCRC\n");
|
|
} else if (int_reg & (SD_BUF_ILLEGAL_ACCESS
|
|
| SD_BUF_CMD_INDEX_ERR
|
|
| SD_BUF_STOP_BIT_END_ERR
|
|
| SD_BUF_OVERFLOW
|
|
| SD_BUF_UNDERFLOW
|
|
| SD_BUF_DATA_TIMEOUT)) {
|
|
dev_err(&host->pdev->dev, "Buffer status error: { %s%s%s%s%s%s}\n",
|
|
int_reg & SD_BUF_ILLEGAL_ACCESS ? "ILLEGAL_ACC " : "",
|
|
int_reg & SD_BUF_CMD_INDEX_ERR ? "CMD_INDEX " : "",
|
|
int_reg & SD_BUF_STOP_BIT_END_ERR ? "STOPBIT_END " : "",
|
|
int_reg & SD_BUF_OVERFLOW ? "OVERFLOW " : "",
|
|
int_reg & SD_BUF_UNDERFLOW ? "UNDERFLOW " : "",
|
|
int_reg & SD_BUF_DATA_TIMEOUT ? "DATA_TIMEOUT " : "");
|
|
|
|
detail = ioread32(host->ioaddr + SD_ERRORSTATUS0);
|
|
dev_err(&host->pdev->dev, "detail error status { %s%s%s%s%s%s%s%s%s%s%s%s%s}\n",
|
|
detail & SD_ERR0_RESP_CMD_ERR ? "RESP_CMD " : "",
|
|
detail & SD_ERR0_RESP_NON_CMD12_END_BIT_ERR ? "RESP_END_BIT " : "",
|
|
detail & SD_ERR0_RESP_CMD12_END_BIT_ERR ? "RESP_END_BIT " : "",
|
|
detail & SD_ERR0_READ_DATA_END_BIT_ERR ? "READ_DATA_END_BIT " : "",
|
|
detail & SD_ERR0_WRITE_CRC_STATUS_END_BIT_ERR ? "WRITE_CMD_END_BIT " : "",
|
|
detail & SD_ERR0_RESP_NON_CMD12_CRC_ERR ? "RESP_CRC " : "",
|
|
detail & SD_ERR0_RESP_CMD12_CRC_ERR ? "RESP_CRC " : "",
|
|
detail & SD_ERR0_READ_DATA_CRC_ERR ? "READ_DATA_CRC " : "",
|
|
detail & SD_ERR0_WRITE_CMD_CRC_ERR ? "WRITE_CMD_CRC " : "",
|
|
detail & SD_ERR1_NO_CMD_RESP ? "NO_CMD_RESP " : "",
|
|
detail & SD_ERR1_TIMEOUT_READ_DATA ? "READ_DATA_TIMEOUT " : "",
|
|
detail & SD_ERR1_TIMEOUT_CRS_STATUS ? "CRS_STATUS_TIMEOUT " : "",
|
|
detail & SD_ERR1_TIMEOUT_CRC_BUSY ? "CRC_BUSY_TIMEOUT " : "");
|
|
error = -EIO;
|
|
}
|
|
|
|
if (error) {
|
|
if (host->cmd)
|
|
host->cmd->error = error;
|
|
|
|
if (error == -ETIMEDOUT) {
|
|
iowrite32(int_status &
|
|
~(SD_BUF_CMD_TIMEOUT | SD_CARD_RESP_END),
|
|
host->ioaddr + SD_CARDSTATUS);
|
|
} else {
|
|
toshsd_init(host);
|
|
__toshsd_set_ios(host->mmc, &host->mmc->ios);
|
|
goto irq_end;
|
|
}
|
|
}
|
|
|
|
/* Card insert/remove. The mmc controlling code is stateless. */
|
|
if (int_reg & (SD_CARD_CARD_INSERTED_0 | SD_CARD_CARD_REMOVED_0)) {
|
|
iowrite32(int_status &
|
|
~(SD_CARD_CARD_REMOVED_0 | SD_CARD_CARD_INSERTED_0),
|
|
host->ioaddr + SD_CARDSTATUS);
|
|
|
|
if (int_reg & SD_CARD_CARD_INSERTED_0)
|
|
toshsd_init(host);
|
|
|
|
mmc_detect_change(host->mmc, 1);
|
|
}
|
|
|
|
/* Data transfer */
|
|
if (int_reg & (SD_BUF_READ_ENABLE | SD_BUF_WRITE_ENABLE)) {
|
|
iowrite32(int_status &
|
|
~(SD_BUF_WRITE_ENABLE | SD_BUF_READ_ENABLE),
|
|
host->ioaddr + SD_CARDSTATUS);
|
|
|
|
ret = IRQ_WAKE_THREAD;
|
|
goto irq_end;
|
|
}
|
|
|
|
/* Command completion */
|
|
if (int_reg & SD_CARD_RESP_END) {
|
|
iowrite32(int_status & ~(SD_CARD_RESP_END),
|
|
host->ioaddr + SD_CARDSTATUS);
|
|
toshsd_cmd_irq(host);
|
|
}
|
|
|
|
/* Data transfer completion */
|
|
if (int_reg & SD_CARD_RW_END) {
|
|
iowrite32(int_status & ~(SD_CARD_RW_END),
|
|
host->ioaddr + SD_CARDSTATUS);
|
|
toshsd_data_end_irq(host);
|
|
}
|
|
irq_end:
|
|
spin_unlock(&host->lock);
|
|
return ret;
|
|
}
|
|
|
|
static void toshsd_start_cmd(struct toshsd_host *host, struct mmc_command *cmd)
|
|
{
|
|
struct mmc_data *data = host->data;
|
|
int c = cmd->opcode;
|
|
|
|
dev_dbg(&host->pdev->dev, "Command opcode: %d\n", cmd->opcode);
|
|
|
|
if (cmd->opcode == MMC_STOP_TRANSMISSION) {
|
|
iowrite16(SD_STOPINT_ISSUE_CMD12,
|
|
host->ioaddr + SD_STOPINTERNAL);
|
|
|
|
cmd->resp[0] = cmd->opcode;
|
|
cmd->resp[1] = 0;
|
|
cmd->resp[2] = 0;
|
|
cmd->resp[3] = 0;
|
|
|
|
toshsd_finish_request(host);
|
|
return;
|
|
}
|
|
|
|
switch (mmc_resp_type(cmd)) {
|
|
case MMC_RSP_NONE:
|
|
c |= SD_CMD_RESP_TYPE_NONE;
|
|
break;
|
|
|
|
case MMC_RSP_R1:
|
|
c |= SD_CMD_RESP_TYPE_EXT_R1;
|
|
break;
|
|
case MMC_RSP_R1B:
|
|
c |= SD_CMD_RESP_TYPE_EXT_R1B;
|
|
break;
|
|
case MMC_RSP_R2:
|
|
c |= SD_CMD_RESP_TYPE_EXT_R2;
|
|
break;
|
|
case MMC_RSP_R3:
|
|
c |= SD_CMD_RESP_TYPE_EXT_R3;
|
|
break;
|
|
|
|
default:
|
|
dev_err(&host->pdev->dev, "Unknown response type %d\n",
|
|
mmc_resp_type(cmd));
|
|
break;
|
|
}
|
|
|
|
host->cmd = cmd;
|
|
|
|
if (cmd->opcode == MMC_APP_CMD)
|
|
c |= SD_CMD_TYPE_ACMD;
|
|
|
|
if (cmd->opcode == MMC_GO_IDLE_STATE)
|
|
c |= (3 << 8); /* removed from ipaq-asic3.h for some reason */
|
|
|
|
if (data) {
|
|
c |= SD_CMD_DATA_PRESENT;
|
|
|
|
if (data->blocks > 1) {
|
|
iowrite16(SD_STOPINT_AUTO_ISSUE_CMD12,
|
|
host->ioaddr + SD_STOPINTERNAL);
|
|
c |= SD_CMD_MULTI_BLOCK;
|
|
}
|
|
|
|
if (data->flags & MMC_DATA_READ)
|
|
c |= SD_CMD_TRANSFER_READ;
|
|
|
|
/* MMC_DATA_WRITE does not require a bit to be set */
|
|
}
|
|
|
|
/* Send the command */
|
|
iowrite32(cmd->arg, host->ioaddr + SD_ARG0);
|
|
iowrite16(c, host->ioaddr + SD_CMD);
|
|
}
|
|
|
|
static void toshsd_start_data(struct toshsd_host *host, struct mmc_data *data)
|
|
{
|
|
unsigned int flags = SG_MITER_ATOMIC;
|
|
|
|
dev_dbg(&host->pdev->dev, "setup data transfer: blocksize %08x nr_blocks %d, offset: %08x\n",
|
|
data->blksz, data->blocks, data->sg->offset);
|
|
|
|
host->data = data;
|
|
|
|
if (data->flags & MMC_DATA_READ)
|
|
flags |= SG_MITER_TO_SG;
|
|
else
|
|
flags |= SG_MITER_FROM_SG;
|
|
|
|
sg_miter_start(&host->sg_miter, data->sg, data->sg_len, flags);
|
|
|
|
/* Set transfer length and blocksize */
|
|
iowrite16(data->blocks, host->ioaddr + SD_BLOCKCOUNT);
|
|
iowrite16(data->blksz, host->ioaddr + SD_CARDXFERDATALEN);
|
|
}
|
|
|
|
/* Process requests from the MMC layer */
|
|
static void toshsd_request(struct mmc_host *mmc, struct mmc_request *mrq)
|
|
{
|
|
struct toshsd_host *host = mmc_priv(mmc);
|
|
unsigned long flags;
|
|
|
|
/* abort if card not present */
|
|
if (!(ioread16(host->ioaddr + SD_CARDSTATUS) & SD_CARD_PRESENT_0)) {
|
|
mrq->cmd->error = -ENOMEDIUM;
|
|
mmc_request_done(mmc, mrq);
|
|
return;
|
|
}
|
|
|
|
spin_lock_irqsave(&host->lock, flags);
|
|
|
|
WARN_ON(host->mrq != NULL);
|
|
|
|
host->mrq = mrq;
|
|
|
|
if (mrq->data)
|
|
toshsd_start_data(host, mrq->data);
|
|
|
|
toshsd_set_led(host, 1);
|
|
|
|
toshsd_start_cmd(host, mrq->cmd);
|
|
|
|
spin_unlock_irqrestore(&host->lock, flags);
|
|
}
|
|
|
|
static void toshsd_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
|
|
{
|
|
struct toshsd_host *host = mmc_priv(mmc);
|
|
unsigned long flags;
|
|
|
|
spin_lock_irqsave(&host->lock, flags);
|
|
__toshsd_set_ios(mmc, ios);
|
|
spin_unlock_irqrestore(&host->lock, flags);
|
|
}
|
|
|
|
static int toshsd_get_ro(struct mmc_host *mmc)
|
|
{
|
|
struct toshsd_host *host = mmc_priv(mmc);
|
|
|
|
/* active low */
|
|
return !(ioread16(host->ioaddr + SD_CARDSTATUS) & SD_CARD_WRITE_PROTECT);
|
|
}
|
|
|
|
static int toshsd_get_cd(struct mmc_host *mmc)
|
|
{
|
|
struct toshsd_host *host = mmc_priv(mmc);
|
|
|
|
return !!(ioread16(host->ioaddr + SD_CARDSTATUS) & SD_CARD_PRESENT_0);
|
|
}
|
|
|
|
static struct mmc_host_ops toshsd_ops = {
|
|
.request = toshsd_request,
|
|
.set_ios = toshsd_set_ios,
|
|
.get_ro = toshsd_get_ro,
|
|
.get_cd = toshsd_get_cd,
|
|
};
|
|
|
|
|
|
static void toshsd_powerdown(struct toshsd_host *host)
|
|
{
|
|
/* mask all interrupts */
|
|
iowrite32(0xffffffff, host->ioaddr + SD_INTMASKCARD);
|
|
/* disable card clock */
|
|
iowrite16(0x000, host->ioaddr + SDIO_BASE + SDIO_CLOCKNWAITCTRL);
|
|
iowrite16(0, host->ioaddr + SD_CARDCLOCKCTRL);
|
|
/* power down card */
|
|
pci_write_config_byte(host->pdev, SD_PCICFG_POWER1, SD_PCICFG_PWR1_OFF);
|
|
/* disable clock */
|
|
pci_write_config_byte(host->pdev, SD_PCICFG_CLKSTOP, 0);
|
|
}
|
|
|
|
#ifdef CONFIG_PM_SLEEP
|
|
static int toshsd_pm_suspend(struct device *dev)
|
|
{
|
|
struct pci_dev *pdev = to_pci_dev(dev);
|
|
struct toshsd_host *host = pci_get_drvdata(pdev);
|
|
|
|
toshsd_powerdown(host);
|
|
|
|
pci_save_state(pdev);
|
|
pci_enable_wake(pdev, PCI_D3hot, 0);
|
|
pci_disable_device(pdev);
|
|
pci_set_power_state(pdev, PCI_D3hot);
|
|
|
|
return 0;
|
|
}
|
|
|
|
static int toshsd_pm_resume(struct device *dev)
|
|
{
|
|
struct pci_dev *pdev = to_pci_dev(dev);
|
|
struct toshsd_host *host = pci_get_drvdata(pdev);
|
|
int ret;
|
|
|
|
pci_set_power_state(pdev, PCI_D0);
|
|
pci_restore_state(pdev);
|
|
ret = pci_enable_device(pdev);
|
|
if (ret)
|
|
return ret;
|
|
|
|
toshsd_init(host);
|
|
|
|
return 0;
|
|
}
|
|
#endif /* CONFIG_PM_SLEEP */
|
|
|
|
static int toshsd_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
|
|
{
|
|
int ret;
|
|
struct toshsd_host *host;
|
|
struct mmc_host *mmc;
|
|
resource_size_t base;
|
|
|
|
ret = pci_enable_device(pdev);
|
|
if (ret)
|
|
return ret;
|
|
|
|
mmc = mmc_alloc_host(sizeof(struct toshsd_host), &pdev->dev);
|
|
if (!mmc) {
|
|
ret = -ENOMEM;
|
|
goto err;
|
|
}
|
|
|
|
host = mmc_priv(mmc);
|
|
host->mmc = mmc;
|
|
|
|
host->pdev = pdev;
|
|
pci_set_drvdata(pdev, host);
|
|
|
|
ret = pci_request_regions(pdev, DRIVER_NAME);
|
|
if (ret)
|
|
goto free;
|
|
|
|
host->ioaddr = pci_iomap(pdev, 0, 0);
|
|
if (!host->ioaddr) {
|
|
ret = -ENOMEM;
|
|
goto release;
|
|
}
|
|
|
|
/* Set MMC host parameters */
|
|
mmc->ops = &toshsd_ops;
|
|
mmc->caps = MMC_CAP_4_BIT_DATA;
|
|
mmc->ocr_avail = MMC_VDD_32_33;
|
|
|
|
mmc->f_min = HCLK / 512;
|
|
mmc->f_max = HCLK;
|
|
|
|
spin_lock_init(&host->lock);
|
|
|
|
toshsd_init(host);
|
|
|
|
ret = request_threaded_irq(pdev->irq, toshsd_irq, toshsd_thread_irq,
|
|
IRQF_SHARED, DRIVER_NAME, host);
|
|
if (ret)
|
|
goto unmap;
|
|
|
|
ret = mmc_add_host(mmc);
|
|
if (ret)
|
|
goto free_irq;
|
|
|
|
base = pci_resource_start(pdev, 0);
|
|
dev_dbg(&pdev->dev, "MMIO %pa, IRQ %d\n", &base, pdev->irq);
|
|
|
|
pm_suspend_ignore_children(&pdev->dev, 1);
|
|
|
|
return 0;
|
|
|
|
free_irq:
|
|
free_irq(pdev->irq, host);
|
|
unmap:
|
|
pci_iounmap(pdev, host->ioaddr);
|
|
release:
|
|
pci_release_regions(pdev);
|
|
free:
|
|
mmc_free_host(mmc);
|
|
pci_set_drvdata(pdev, NULL);
|
|
err:
|
|
pci_disable_device(pdev);
|
|
return ret;
|
|
}
|
|
|
|
static void toshsd_remove(struct pci_dev *pdev)
|
|
{
|
|
struct toshsd_host *host = pci_get_drvdata(pdev);
|
|
|
|
mmc_remove_host(host->mmc);
|
|
toshsd_powerdown(host);
|
|
free_irq(pdev->irq, host);
|
|
pci_iounmap(pdev, host->ioaddr);
|
|
pci_release_regions(pdev);
|
|
mmc_free_host(host->mmc);
|
|
pci_set_drvdata(pdev, NULL);
|
|
pci_disable_device(pdev);
|
|
}
|
|
|
|
static const struct dev_pm_ops toshsd_pm_ops = {
|
|
SET_SYSTEM_SLEEP_PM_OPS(toshsd_pm_suspend, toshsd_pm_resume)
|
|
};
|
|
|
|
static struct pci_driver toshsd_driver = {
|
|
.name = DRIVER_NAME,
|
|
.id_table = pci_ids,
|
|
.probe = toshsd_probe,
|
|
.remove = toshsd_remove,
|
|
.driver.pm = &toshsd_pm_ops,
|
|
};
|
|
|
|
module_pci_driver(toshsd_driver);
|
|
|
|
MODULE_AUTHOR("Ondrej Zary, Richard Betts");
|
|
MODULE_DESCRIPTION("Toshiba PCI Secure Digital Host Controller Interface driver");
|
|
MODULE_LICENSE("GPL");
|