Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 98e90de9 authored by Linus Walleij's avatar Linus Walleij Committed by Ulf Hansson
Browse files

mmc: host: switch OF parser to use gpio descriptors



This switches the central MMC OF parser to use gpio descriptors
instead of grabbing GPIOs explicitly from the device tree.
This strips out an unecessary use of the integer-based GPIO
API that we want to get rid of, cuts down on code as the
gpio descriptor code will handle active low flags.

Acked-by: default avatarAlexandre Courbot <acourbot@nvidia.com>
Signed-off-by: default avatarLinus Walleij <linus.walleij@linaro.org>
Signed-off-by: default avatarUlf Hansson <ulf.hansson@linaro.org>
parent 9d2fa242
Loading
Loading
Loading
Loading
+23 −45
Original line number Original line Diff line number Diff line
@@ -310,9 +310,7 @@ int mmc_of_parse(struct mmc_host *host)
{
{
	struct device_node *np;
	struct device_node *np;
	u32 bus_width;
	u32 bus_width;
	bool explicit_inv_wp, gpio_inv_wp = false;
	int len, ret;
	enum of_gpio_flags flags;
	int len, ret, gpio;


	if (!host->parent || !host->parent->of_node)
	if (!host->parent || !host->parent->of_node)
		return 0;
		return 0;
@@ -360,60 +358,40 @@ int mmc_of_parse(struct mmc_host *host)
	if (of_find_property(np, "non-removable", &len)) {
	if (of_find_property(np, "non-removable", &len)) {
		host->caps |= MMC_CAP_NONREMOVABLE;
		host->caps |= MMC_CAP_NONREMOVABLE;
	} else {
	} else {
		bool explicit_inv_cd, gpio_inv_cd = false;
		if (of_property_read_bool(np, "cd-inverted"))

			host->caps2 |= MMC_CAP2_CD_ACTIVE_HIGH;
		explicit_inv_cd = of_property_read_bool(np, "cd-inverted");


		if (of_find_property(np, "broken-cd", &len))
		if (of_find_property(np, "broken-cd", &len))
			host->caps |= MMC_CAP_NEEDS_POLL;
			host->caps |= MMC_CAP_NEEDS_POLL;


		gpio = of_get_named_gpio_flags(np, "cd-gpios", 0, &flags);
		ret = mmc_gpiod_request_cd(host, "cd", 0, false, 0);
		if (gpio == -EPROBE_DEFER)
		if (ret) {
			return gpio;
			if (ret == -EPROBE_DEFER)
		if (gpio_is_valid(gpio)) {
			if (!(flags & OF_GPIO_ACTIVE_LOW))
				gpio_inv_cd = true;

			ret = mmc_gpio_request_cd(host, gpio, 0);
			if (ret < 0) {
				dev_err(host->parent,
					"Failed to request CD GPIO #%d: %d!\n",
					gpio, ret);
				return ret;
				return ret;
			} else {
			if (ret != -ENOENT) {
				dev_info(host->parent, "Got CD GPIO #%d.\n",
				dev_err(host->parent,
					 gpio);
					"Failed to request CD GPIO: %d\n",
			}
					ret);
			}
			}

		} else
		if (explicit_inv_cd ^ gpio_inv_cd)
			dev_info(host->parent, "Got CD GPIO\n");
			host->caps2 |= MMC_CAP2_CD_ACTIVE_HIGH;
	}
	}


	/* Parse Write Protection */
	/* Parse Write Protection */
	explicit_inv_wp = of_property_read_bool(np, "wp-inverted");
	if (of_property_read_bool(np, "wp-inverted"))
		host->caps2 |= MMC_CAP2_RO_ACTIVE_HIGH;


	gpio = of_get_named_gpio_flags(np, "wp-gpios", 0, &flags);
	ret = mmc_gpiod_request_ro(host, "wp", 0, false, 0);
	if (gpio == -EPROBE_DEFER) {
	if (ret) {
		ret = -EPROBE_DEFER;
		if (ret == -EPROBE_DEFER)
			goto out;
			goto out;
	}
		if (ret != -ENOENT) {
	if (gpio_is_valid(gpio)) {
		if (!(flags & OF_GPIO_ACTIVE_LOW))
			gpio_inv_wp = true;

		ret = mmc_gpio_request_ro(host, gpio);
		if (ret < 0) {
			dev_err(host->parent,
			dev_err(host->parent,
				"Failed to request WP GPIO: %d!\n", ret);
				"Failed to request WP GPIO: %d\n",
			goto out;
				ret);
		} else {
				dev_info(host->parent, "Got WP GPIO #%d.\n",
					 gpio);
		}
		}
	}
	} else
	if (explicit_inv_wp ^ gpio_inv_wp)
		dev_info(host->parent, "Got WP GPIO\n");
		host->caps2 |= MMC_CAP2_RO_ACTIVE_HIGH;


	if (of_find_property(np, "cap-sd-highspeed", &len))
	if (of_find_property(np, "cap-sd-highspeed", &len))
		host->caps |= MMC_CAP_SD_HIGHSPEED;
		host->caps |= MMC_CAP_SD_HIGHSPEED;