| .. | .. | 
|---|
|  | 1 | +/* SPDX-License-Identifier: GPL-2.0-only */ | 
|---|
| 1 | 2 | /* | 
|---|
| 2 | 3 | *  linux/include/linux/mmc/host.h | 
|---|
| 3 |  | - * | 
|---|
| 4 |  | - * This program is free software; you can redistribute it and/or modify | 
|---|
| 5 |  | - * it under the terms of the GNU General Public License version 2 as | 
|---|
| 6 |  | - * published by the Free Software Foundation. | 
|---|
| 7 | 4 | * | 
|---|
| 8 | 5 | *  Host driver specific definitions. | 
|---|
| 9 | 6 | */ | 
|---|
| .. | .. | 
|---|
| 18 | 15 | #include <linux/mmc/card.h> | 
|---|
| 19 | 16 | #include <linux/mmc/pm.h> | 
|---|
| 20 | 17 | #include <linux/dma-direction.h> | 
|---|
|  | 18 | +#include <linux/keyslot-manager.h> | 
|---|
|  | 19 | +#include <linux/android_kabi.h> | 
|---|
|  | 20 | + | 
|---|
|  | 21 | +#include <linux/android_vendor.h> | 
|---|
| 21 | 22 |  | 
|---|
| 22 | 23 | struct mmc_ios { | 
|---|
| 23 | 24 | unsigned int	clock;			/* clock rate */ | 
|---|
| .. | .. | 
|---|
| 134 | 135 | int	(*get_cd)(struct mmc_host *host); | 
|---|
| 135 | 136 |  | 
|---|
| 136 | 137 | void	(*enable_sdio_irq)(struct mmc_host *host, int enable); | 
|---|
|  | 138 | +	/* Mandatory callback when using MMC_CAP2_SDIO_IRQ_NOTHREAD. */ | 
|---|
| 137 | 139 | void	(*ack_sdio_irq)(struct mmc_host *host); | 
|---|
| 138 | 140 |  | 
|---|
| 139 | 141 | /* optional callback for HC quirks */ | 
|---|
| .. | .. | 
|---|
| 143 | 145 |  | 
|---|
| 144 | 146 | /* Check if the card is pulling dat[0:3] low */ | 
|---|
| 145 | 147 | int	(*card_busy)(struct mmc_host *host); | 
|---|
| 146 |  | -	int     (*set_sdio_status)(struct mmc_host *host, int val); | 
|---|
| 147 | 148 |  | 
|---|
| 148 | 149 | /* The tuning command opcode value is different for SD and eMMC cards */ | 
|---|
| 149 | 150 | int	(*execute_tuning)(struct mmc_host *host, u32 opcode); | 
|---|
| 150 | 151 |  | 
|---|
| 151 | 152 | /* Prepare HS400 target operating frequency depending host driver */ | 
|---|
| 152 | 153 | int	(*prepare_hs400_tuning)(struct mmc_host *host, struct mmc_ios *ios); | 
|---|
|  | 154 | + | 
|---|
|  | 155 | +	/* Prepare switch to DDR during the HS400 init sequence */ | 
|---|
|  | 156 | +	int	(*hs400_prepare_ddr)(struct mmc_host *host); | 
|---|
| 153 | 157 |  | 
|---|
| 154 | 158 | /* Prepare for switching from HS400 to HS200 */ | 
|---|
| 155 | 159 | void	(*hs400_downgrade)(struct mmc_host *host); | 
|---|
| .. | .. | 
|---|
| 163 | 167 | int	(*select_drive_strength)(struct mmc_card *card, | 
|---|
| 164 | 168 | unsigned int max_dtr, int host_drv, | 
|---|
| 165 | 169 | int card_drv, int *drv_type); | 
|---|
|  | 170 | +	/* Reset the eMMC card via RST_n */ | 
|---|
| 166 | 171 | void	(*hw_reset)(struct mmc_host *host); | 
|---|
| 167 | 172 | void	(*card_event)(struct mmc_host *host); | 
|---|
| 168 | 173 |  | 
|---|
| .. | .. | 
|---|
| 172 | 177 | */ | 
|---|
| 173 | 178 | int	(*multi_io_quirk)(struct mmc_card *card, | 
|---|
| 174 | 179 | unsigned int direction, int blk_size); | 
|---|
|  | 180 | + | 
|---|
|  | 181 | +	ANDROID_KABI_RESERVE(1); | 
|---|
|  | 182 | +	ANDROID_KABI_RESERVE(2); | 
|---|
| 175 | 183 | }; | 
|---|
| 176 | 184 |  | 
|---|
| 177 | 185 | struct mmc_cqe_ops { | 
|---|
| .. | .. | 
|---|
| 216 | 224 | * will have zero data bytes transferred. | 
|---|
| 217 | 225 | */ | 
|---|
| 218 | 226 | void	(*cqe_recovery_finish)(struct mmc_host *host); | 
|---|
|  | 227 | + | 
|---|
|  | 228 | +	ANDROID_KABI_RESERVE(1); | 
|---|
|  | 229 | +	ANDROID_KABI_RESERVE(2); | 
|---|
| 219 | 230 | }; | 
|---|
| 220 | 231 |  | 
|---|
| 221 | 232 | struct mmc_async_req { | 
|---|
| .. | .. | 
|---|
| 242 | 253 | struct mmc_slot { | 
|---|
| 243 | 254 | int cd_irq; | 
|---|
| 244 | 255 | bool cd_wake_enabled; | 
|---|
|  | 256 | +	ANDROID_OEM_DATA_ARRAY(1, 2); | 
|---|
| 245 | 257 | void *handler_priv; | 
|---|
| 246 | 258 | }; | 
|---|
| 247 | 259 |  | 
|---|
| .. | .. | 
|---|
| 284 | 296 | u32			ocr_avail_sdio;	/* SDIO-specific OCR */ | 
|---|
| 285 | 297 | u32			ocr_avail_sd;	/* SD-specific OCR */ | 
|---|
| 286 | 298 | u32			ocr_avail_mmc;	/* MMC-specific OCR */ | 
|---|
| 287 |  | -#ifdef CONFIG_PM_SLEEP | 
|---|
| 288 |  | -	struct notifier_block	pm_notify; | 
|---|
| 289 |  | -#endif | 
|---|
|  | 299 | +	struct wakeup_source	*ws;		/* Enable consume of uevents */ | 
|---|
| 290 | 300 | u32			max_current_330; | 
|---|
| 291 | 301 | u32			max_current_300; | 
|---|
| 292 | 302 | u32			max_current_180; | 
|---|
| .. | .. | 
|---|
| 321 | 331 | #define MMC_CAP_AGGRESSIVE_PM	(1 << 7)	/* Suspend (e)MMC/SD at idle  */ | 
|---|
| 322 | 332 | #define MMC_CAP_NONREMOVABLE	(1 << 8)	/* Nonremovable e.g. eMMC */ | 
|---|
| 323 | 333 | #define MMC_CAP_WAIT_WHILE_BUSY	(1 << 9)	/* Waits while card is busy */ | 
|---|
| 324 |  | -#define MMC_CAP_ERASE		(1 << 10)	/* Allow erase/trim commands */ | 
|---|
| 325 | 334 | #define MMC_CAP_3_3V_DDR	(1 << 11)	/* Host supports eMMC DDR 3.3V */ | 
|---|
| 326 | 335 | #define MMC_CAP_1_8V_DDR	(1 << 12)	/* Host supports eMMC DDR 1.8V */ | 
|---|
| 327 | 336 | #define MMC_CAP_1_2V_DDR	(1 << 13)	/* Host supports eMMC DDR 1.2V */ | 
|---|
|  | 337 | +#define MMC_CAP_DDR		(MMC_CAP_3_3V_DDR | MMC_CAP_1_8V_DDR | \ | 
|---|
|  | 338 | +				 MMC_CAP_1_2V_DDR) | 
|---|
| 328 | 339 | #define MMC_CAP_POWER_OFF_CARD	(1 << 14)	/* Can power off after boot */ | 
|---|
| 329 | 340 | #define MMC_CAP_BUS_WIDTH_TEST	(1 << 15)	/* CMD14/CMD19 bus width ok */ | 
|---|
| 330 | 341 | #define MMC_CAP_UHS_SDR12	(1 << 16)	/* Host supports UHS SDR12 mode */ | 
|---|
| .. | .. | 
|---|
| 335 | 346 | #define MMC_CAP_UHS		(MMC_CAP_UHS_SDR12 | MMC_CAP_UHS_SDR25 | \ | 
|---|
| 336 | 347 | MMC_CAP_UHS_SDR50 | MMC_CAP_UHS_SDR104 | \ | 
|---|
| 337 | 348 | MMC_CAP_UHS_DDR50) | 
|---|
| 338 |  | -/* (1 << 21) is free for reuse */ | 
|---|
|  | 349 | +#define MMC_CAP_SYNC_RUNTIME_PM	(1 << 21)	/* Synced runtime PM suspends. */ | 
|---|
| 339 | 350 | #define MMC_CAP_NEED_RSP_BUSY	(1 << 22)	/* Commands with R1B can't use R1. */ | 
|---|
| 340 | 351 | #define MMC_CAP_DRIVER_TYPE_A	(1 << 23)	/* Host supports Driver Type A */ | 
|---|
| 341 | 352 | #define MMC_CAP_DRIVER_TYPE_C	(1 << 24)	/* Host supports Driver Type C */ | 
|---|
| .. | .. | 
|---|
| 344 | 355 | #define MMC_CAP_CD_WAKE		(1 << 28)	/* Enable card detect wake */ | 
|---|
| 345 | 356 | #define MMC_CAP_CMD_DURING_TFR	(1 << 29)	/* Commands during data transfer */ | 
|---|
| 346 | 357 | #define MMC_CAP_CMD23		(1 << 30)	/* CMD23 supported. */ | 
|---|
| 347 |  | -#define MMC_CAP_HW_RESET	(1 << 31)	/* Hardware reset */ | 
|---|
|  | 358 | +#define MMC_CAP_HW_RESET	(1 << 31)	/* Reset the eMMC card via RST_n */ | 
|---|
| 348 | 359 |  | 
|---|
| 349 | 360 | u32			caps2;		/* More host capabilities */ | 
|---|
| 350 | 361 |  | 
|---|
| 351 | 362 | #define MMC_CAP2_BOOTPART_NOACC	(1 << 0)	/* Boot partition no access */ | 
|---|
| 352 | 363 | #define MMC_CAP2_FULL_PWR_CYCLE	(1 << 2)	/* Can do full power cycle */ | 
|---|
|  | 364 | +#define MMC_CAP2_FULL_PWR_CYCLE_IN_SUSPEND (1 << 3) /* Can do full power cycle in suspend */ | 
|---|
| 353 | 365 | #define MMC_CAP2_HS200_1_8V_SDR	(1 << 5)        /* can support */ | 
|---|
| 354 | 366 | #define MMC_CAP2_HS200_1_2V_SDR	(1 << 6)        /* can support */ | 
|---|
| 355 | 367 | #define MMC_CAP2_HS200		(MMC_CAP2_HS200_1_8V_SDR | \ | 
|---|
| .. | .. | 
|---|
| 372 | 384 | #define MMC_CAP2_CQE		(1 << 23)	/* Has eMMC command queue engine */ | 
|---|
| 373 | 385 | #define MMC_CAP2_CQE_DCMD	(1 << 24)	/* CQE can issue a direct command */ | 
|---|
| 374 | 386 | #define MMC_CAP2_AVOID_3_3V	(1 << 25)	/* Host must negotiate down from 3.3V */ | 
|---|
|  | 387 | +#define MMC_CAP2_MERGE_CAPABLE	(1 << 26)	/* Host can merge a segment over the segment size */ | 
|---|
|  | 388 | +#ifdef CONFIG_MMC_CRYPTO | 
|---|
| 375 | 389 | #define MMC_CAP2_CRYPTO		(1 << 27)	/* Host supports inline encryption */ | 
|---|
|  | 390 | +#else | 
|---|
|  | 391 | +#define MMC_CAP2_CRYPTO		0 | 
|---|
|  | 392 | +#endif | 
|---|
| 376 | 393 |  | 
|---|
| 377 | 394 | int			fixed_drv_type;	/* fixed driver type for non-removable media */ | 
|---|
| 378 | 395 |  | 
|---|
| 379 | 396 | mmc_pm_flag_t		pm_caps;	/* supported pm features */ | 
|---|
| 380 |  | -	u32			restrict_caps;  /* Indicate slot specific card type */ | 
|---|
| 381 |  | -#define RESTRICT_CARD_TYPE_SD   (1 << 0)        /* Can support Secure-Digital Card */ | 
|---|
| 382 |  | -#define RESTRICT_CARD_TYPE_SDIO (1 << 1)        /* Can support Secure-Digital I/O Card or Combo-Mem */ | 
|---|
| 383 |  | -#define RESTRICT_CARD_TYPE_EMMC (1 << 2)        /* Can support embedded Multi-Media Card */ | 
|---|
| 384 |  | - | 
|---|
| 385 |  | -#ifdef CONFIG_SDIO_KEEPALIVE | 
|---|
| 386 |  | -	bool		support_chip_alive; | 
|---|
| 387 |  | -	bool		chip_alive; | 
|---|
| 388 |  | -	bool		logic_remove_card; | 
|---|
| 389 |  | -#endif | 
|---|
| 390 | 397 |  | 
|---|
| 391 | 398 | /* host specific block data */ | 
|---|
| 392 | 399 | unsigned int		max_seg_size;	/* see blk_queue_max_segment_size */ | 
|---|
| .. | .. | 
|---|
| 406 | 413 | unsigned int		use_spi_crc:1; | 
|---|
| 407 | 414 | unsigned int		claimed:1;	/* host exclusively claimed */ | 
|---|
| 408 | 415 | unsigned int		bus_dead:1;	/* bus has been released */ | 
|---|
|  | 416 | +	unsigned int		doing_init_tune:1; /* initial tuning in progress */ | 
|---|
| 409 | 417 | unsigned int		can_retune:1;	/* re-tuning can be used */ | 
|---|
| 410 | 418 | unsigned int		doing_retune:1;	/* re-tuning in progress */ | 
|---|
| 411 | 419 | unsigned int		retune_now:1;	/* do re-tuning at next req */ | 
|---|
| 412 | 420 | unsigned int		retune_paused:1; /* re-tuning is temporarily disabled */ | 
|---|
| 413 | 421 | unsigned int		use_blk_mq:1;	/* use blk-mq */ | 
|---|
| 414 | 422 | unsigned int		retune_crc_disable:1; /* don't trigger retune upon crc */ | 
|---|
|  | 423 | +	unsigned int		can_dma_map_merge:1; /* merging can be used */ | 
|---|
| 415 | 424 |  | 
|---|
| 416 | 425 | int			rescan_disable;	/* disable card detection */ | 
|---|
| 417 | 426 | int			rescan_entered;	/* used with nonremovable devices */ | 
|---|
| .. | .. | 
|---|
| 474 | 483 | int			cqe_qdepth; | 
|---|
| 475 | 484 | bool			cqe_enabled; | 
|---|
| 476 | 485 | bool			cqe_on; | 
|---|
|  | 486 | + | 
|---|
|  | 487 | +	/* Inline encryption support */ | 
|---|
| 477 | 488 | #ifdef CONFIG_MMC_CRYPTO | 
|---|
| 478 |  | -	struct keyslot_manager	*ksm; | 
|---|
| 479 |  | -#endif /* CONFIG_MMC_CRYPTO */ | 
|---|
|  | 489 | +	struct blk_keyslot_manager ksm; | 
|---|
|  | 490 | +#endif | 
|---|
| 480 | 491 |  | 
|---|
| 481 | 492 | /* Host Software Queue support */ | 
|---|
| 482 | 493 | bool			hsq_enabled; | 
|---|
| 483 | 494 |  | 
|---|
| 484 |  | -	unsigned long		private[0] ____cacheline_aligned; | 
|---|
|  | 495 | +	ANDROID_KABI_RESERVE(1); | 
|---|
|  | 496 | +	ANDROID_KABI_RESERVE(2); | 
|---|
|  | 497 | +	ANDROID_VENDOR_DATA(1); | 
|---|
|  | 498 | +	ANDROID_OEM_DATA(1); | 
|---|
|  | 499 | + | 
|---|
|  | 500 | +	unsigned long		private[] ____cacheline_aligned; | 
|---|
| 485 | 501 | }; | 
|---|
| 486 | 502 |  | 
|---|
| 487 | 503 | struct device_node; | 
|---|
| 488 | 504 |  | 
|---|
| 489 | 505 | struct mmc_host *mmc_alloc_host(int extra, struct device *); | 
|---|
|  | 506 | +struct mmc_host *devm_mmc_alloc_host(struct device *dev, int extra); | 
|---|
| 490 | 507 | int mmc_add_host(struct mmc_host *); | 
|---|
| 491 | 508 | void mmc_remove_host(struct mmc_host *); | 
|---|
| 492 | 509 | void mmc_free_host(struct mmc_host *); | 
|---|
| 493 | 510 | int mmc_of_parse(struct mmc_host *host); | 
|---|
| 494 | 511 | int mmc_of_parse_voltage(struct device_node *np, u32 *mask); | 
|---|
| 495 | 512 |  | 
|---|
| 496 |  | -extern struct mmc_host *primary_sdio_host; | 
|---|
| 497 |  | -int mmc_host_rescan(struct mmc_host *host, int val, int is_cap_sdio_irq); | 
|---|
| 498 |  | - | 
|---|
| 499 | 513 | static inline void *mmc_priv(struct mmc_host *host) | 
|---|
| 500 | 514 | { | 
|---|
| 501 | 515 | return (void *)host->private; | 
|---|
|  | 516 | +} | 
|---|
|  | 517 | + | 
|---|
|  | 518 | +static inline struct mmc_host *mmc_from_priv(void *priv) | 
|---|
|  | 519 | +{ | 
|---|
|  | 520 | +	return container_of(priv, struct mmc_host, private); | 
|---|
| 502 | 521 | } | 
|---|
| 503 | 522 |  | 
|---|
| 504 | 523 | #define mmc_host_is_spi(host)	((host)->caps & MMC_CAP_SPI) | 
|---|
| .. | .. | 
|---|
| 530 | 549 | wake_up_process(host->sdio_irq_thread); | 
|---|
| 531 | 550 | } | 
|---|
| 532 | 551 |  | 
|---|
| 533 |  | -void sdio_run_irqs(struct mmc_host *host); | 
|---|
| 534 | 552 | void sdio_signal_irq(struct mmc_host *host); | 
|---|
| 535 | 553 |  | 
|---|
| 536 | 554 | #ifdef CONFIG_REGULATOR | 
|---|
| 537 |  | -int mmc_regulator_get_ocrmask(struct regulator *supply); | 
|---|
| 538 | 555 | int mmc_regulator_set_ocr(struct mmc_host *mmc, | 
|---|
| 539 | 556 | struct regulator *supply, | 
|---|
| 540 | 557 | unsigned short vdd_bit); | 
|---|
| 541 | 558 | int mmc_regulator_set_vqmmc(struct mmc_host *mmc, struct mmc_ios *ios); | 
|---|
| 542 | 559 | #else | 
|---|
| 543 |  | -static inline int mmc_regulator_get_ocrmask(struct regulator *supply) | 
|---|
| 544 |  | -{ | 
|---|
| 545 |  | -	return 0; | 
|---|
| 546 |  | -} | 
|---|
| 547 |  | - | 
|---|
| 548 | 560 | static inline int mmc_regulator_set_ocr(struct mmc_host *mmc, | 
|---|
| 549 | 561 | struct regulator *supply, | 
|---|
| 550 | 562 | unsigned short vdd_bit) | 
|---|
| .. | .. | 
|---|
| 559 | 571 | } | 
|---|
| 560 | 572 | #endif | 
|---|
| 561 | 573 |  | 
|---|
| 562 |  | -u32 mmc_vddrange_to_ocrmask(int vdd_min, int vdd_max); | 
|---|
| 563 | 574 | int mmc_regulator_get_supply(struct mmc_host *mmc); | 
|---|
| 564 | 575 |  | 
|---|
| 565 | 576 | static inline int mmc_card_is_removable(struct mmc_host *host) | 
|---|
| .. | .. | 
|---|
| 604 | 615 | return host->can_retune == 1; | 
|---|
| 605 | 616 | } | 
|---|
| 606 | 617 |  | 
|---|
|  | 618 | +static inline bool mmc_doing_retune(struct mmc_host *host) | 
|---|
|  | 619 | +{ | 
|---|
|  | 620 | +	return host->doing_retune == 1; | 
|---|
|  | 621 | +} | 
|---|
|  | 622 | + | 
|---|
|  | 623 | +static inline bool mmc_doing_tune(struct mmc_host *host) | 
|---|
|  | 624 | +{ | 
|---|
|  | 625 | +	return host->doing_retune == 1 || host->doing_init_tune == 1; | 
|---|
|  | 626 | +} | 
|---|
|  | 627 | + | 
|---|
| 607 | 628 | static inline enum dma_data_direction mmc_get_dma_dir(struct mmc_data *data) | 
|---|
| 608 | 629 | { | 
|---|
| 609 | 630 | return data->flags & MMC_DATA_WRITE ? DMA_TO_DEVICE : DMA_FROM_DEVICE; | 
|---|
| .. | .. | 
|---|
| 611 | 632 |  | 
|---|
| 612 | 633 | int mmc_send_tuning(struct mmc_host *host, u32 opcode, int *cmd_error); | 
|---|
| 613 | 634 | int mmc_abort_tuning(struct mmc_host *host, u32 opcode); | 
|---|
| 614 |  | -void mmc_retune_enable(struct mmc_host *host); | 
|---|
| 615 |  | -void mmc_retune_disable(struct mmc_host *host); | 
|---|
| 616 | 635 |  | 
|---|
| 617 | 636 | #endif /* LINUX_MMC_HOST_H */ | 
|---|