drivers/mmc/core/sd_uhs2.c

Source file repositories/reference/linux-study-clean/drivers/mmc/core/sd_uhs2.c

File Facts

System
Linux kernel
Corpus path
drivers/mmc/core/sd_uhs2.c
Extension
.c
Size
35297 bytes
Lines
1305
Domain
Driver Families
Bucket
drivers/mmc
Inferred role
Driver Families: implementation source
Status
source implementation candidate

Why This File Exists

Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.

Dependency Surface

Detected Declarations

Annotated Snippet

struct sd_uhs2_wait_active_state_data {
	struct mmc_host *host;
	struct mmc_command *cmd;
};

static int sd_uhs2_power_up(struct mmc_host *host)
{
	if (host->ios.power_mode == MMC_POWER_ON)
		return 0;

	host->ios.vdd = fls(host->ocr_avail) - 1;
	host->ios.clock = host->f_init;
	host->ios.timing = MMC_TIMING_UHS2_SPEED_A;
	host->ios.power_mode = MMC_POWER_ON;

	return host->ops->uhs2_control(host, UHS2_SET_IOS);
}

static int sd_uhs2_power_off(struct mmc_host *host)
{
	int err;

	if (host->ios.power_mode == MMC_POWER_OFF)
		return 0;

	host->ios.vdd = 0;
	host->ios.clock = 0;
	host->ios.power_mode = MMC_POWER_OFF;
	host->uhs2_sd_tran = false;

	err = host->ops->uhs2_control(host, UHS2_SET_IOS);
	if (err)
		return err;

	/* For consistency, let's restore the initial timing. */
	host->ios.timing = MMC_TIMING_LEGACY;
	return 0;
}

/*
 * Run the phy initialization sequence, which mainly relies on the UHS-II host
 * to check that we reach the expected electrical state, between the host and
 * the card.
 */
static int sd_uhs2_phy_init(struct mmc_host *host)
{
	int err;

	err = host->ops->uhs2_control(host, UHS2_PHY_INIT);
	if (err) {
		pr_debug("%s: failed to initial phy for UHS-II!\n",
			 mmc_hostname(host));
	}

	return err;
}

/*
 * sd_uhs2_cmd_assemble() - build up UHS-II command packet which is embedded in
 *                          mmc_command structure
 * @cmd:	MMC command to executed
 * @uhs2_cmd:	UHS2 command corresponded to MMC command
 * @header:	Header field of UHS-II command cxpacket
 * @arg:	Argument field of UHS-II command packet
 * @payload:	Payload field of UHS-II command packet
 * @plen:	Payload length
 * @resp:	Response buffer is allocated by caller and it is used to keep
 *              the response of CM-TRAN command. For SD-TRAN command, uhs2_resp
 *              should be null and SD-TRAN command response should be stored in
 *              resp of mmc_command.
 * @resp_len:	Response buffer length
 *
 * The uhs2_command structure contains message packets which are transmited/
 * received on UHS-II bus. This function fills in the contents of uhs2_command
 * structure and embededs UHS2 command into mmc_command structure, which is used
 * in legacy SD operation functions.
 *
 */
static void sd_uhs2_cmd_assemble(struct mmc_command *cmd,
				 struct uhs2_command *uhs2_cmd,
				 u8 plen, u8 resp_len)
{
	uhs2_cmd->payload_len = plen * sizeof(u32);
	uhs2_cmd->packet_len = uhs2_cmd->payload_len + 4;

	cmd->uhs2_cmd = uhs2_cmd;
	cmd->uhs2_cmd->uhs2_resp_len = resp_len;
}

/*

Annotation

Implementation Notes