static void i2c_gpio_sda_set(struct gpio_desc *sda, int bit) { if (bit) { dm_gpio_set_dir_flags(sda, GPIOD_IS_IN); } else { dm_gpio_set_dir_flags(sda, GPIOD_IS_OUT); dm_gpio_set_value(sda, 0); } }
static void i2c_gpio_set_pin(struct gpio_desc *pin, int bit) { if (bit) dm_gpio_set_dir_flags(pin, GPIOD_IS_IN); else dm_gpio_set_dir_flags(pin, GPIOD_IS_OUT | GPIOD_ACTIVE_LOW | GPIOD_IS_OUT_ACTIVE); }
static int atmel_spi_probe(struct udevice *bus) { struct atmel_spi_platdata *bus_plat = dev_get_platdata(bus); struct atmel_spi_priv *priv = dev_get_priv(bus); int i, ret; ret = atmel_spi_enable_clk(bus); if (ret) return ret; bus_plat->regs = (struct at91_spi *)dev_get_addr(bus); ret = gpio_request_list_by_name(bus, "cs-gpios", priv->cs_gpios, ARRAY_SIZE(priv->cs_gpios), 0); if (ret < 0) { error("Can't get %s gpios! Error: %d", bus->name, ret); return ret; } for(i = 0; i < ARRAY_SIZE(priv->cs_gpios); i++) { dm_gpio_set_dir_flags(&priv->cs_gpios[i], GPIOD_IS_OUT | GPIOD_IS_OUT_ACTIVE); } writel(ATMEL_SPI_CR_SWRST, &bus_plat->regs->cr); return 0; }
void board_pex_config(void) { #ifdef CONFIG_SPL_BUILD uint k; struct gpio_desc gpio = {}; if (!request_gpio_by_name(&gpio, "pca9698@22", 31, "fpga-program-gpio")) { /* prepare FPGA reconfiguration */ dm_gpio_set_dir_flags(&gpio, GPIOD_IS_OUT); dm_gpio_set_value(&gpio, 0); /* give lunatic PCIe clock some time to stabilize */ mdelay(500); /* start FPGA reconfiguration */ dm_gpio_set_dir_flags(&gpio, GPIOD_IS_IN); } /* wait for FPGA done */ if (!request_gpio_by_name(&gpio, "pca9698@22", 19, "fpga-done-gpio")) { for (k = 0; k < 20; ++k) { if (dm_gpio_get_value(&gpio)) { printf("FPGA done after %u rounds\n", k); break; } mdelay(100); } } /* disable FPGA reset */ if (!request_gpio_by_name(&gpio, "gpio@18100", 6, "cpu-to-fpga-reset")) { dm_gpio_set_dir_flags(&gpio, GPIOD_IS_OUT); dm_gpio_set_value(&gpio, 1); } /* wait for FPGA ready */ if (!request_gpio_by_name(&gpio, "pca9698@22", 27, "fpga-ready-gpio")) { for (k = 0; k < 2; ++k) { if (!dm_gpio_get_value(&gpio)) break; mdelay(100); } } #endif }
static int _gpio_request_by_name_nodev(const void *blob, int node, const char *list_name, int index, struct gpio_desc *desc, int flags, bool add_index) { struct fdtdec_phandle_args args; int ret; desc->dev = NULL; desc->offset = 0; desc->flags = 0; ret = fdtdec_parse_phandle_with_args(blob, node, list_name, "#gpio-cells", 0, index, &args); if (ret) { debug("%s: fdtdec_parse_phandle_with_args failed\n", __func__); goto err; } ret = uclass_get_device_by_of_offset(UCLASS_GPIO, args.node, &desc->dev); if (ret) { debug("%s: uclass_get_device_by_of_offset failed\n", __func__); goto err; } ret = gpio_find_and_xlate(desc, &args); if (ret) { debug("%s: gpio_find_and_xlate failed\n", __func__); goto err; } ret = dm_gpio_requestf(desc, add_index ? "%s.%s%d" : "%s.%s", fdt_get_name(blob, node, NULL), list_name, index); if (ret) { debug("%s: dm_gpio_requestf failed\n", __func__); goto err; } ret = dm_gpio_set_dir_flags(desc, flags | desc->flags); if (ret) { debug("%s: dm_gpio_set_dir failed\n", __func__); goto err; } return 0; err: debug("%s: Node '%s', property '%s', failed to request GPIO index %d: %d\n", __func__, fdt_get_name(blob, node, NULL), list_name, index, ret); return ret; }
static int gpio_request_tail(int ret, ofnode node, struct ofnode_phandle_args *args, const char *list_name, int index, struct gpio_desc *desc, int flags, bool add_index) { desc->dev = NULL; desc->offset = 0; desc->flags = 0; if (ret) goto err; ret = uclass_get_device_by_ofnode(UCLASS_GPIO, args->node, &desc->dev); if (ret) { debug("%s: uclass_get_device_by_of_offset failed\n", __func__); goto err; } ret = gpio_find_and_xlate(desc, args); if (ret) { debug("%s: gpio_find_and_xlate failed\n", __func__); goto err; } ret = dm_gpio_requestf(desc, add_index ? "%s.%s%d" : "%s.%s", ofnode_get_name(node), list_name, index); if (ret) { debug("%s: dm_gpio_requestf failed\n", __func__); goto err; } ret = dm_gpio_set_dir_flags(desc, flags | desc->flags); if (ret) { debug("%s: dm_gpio_set_dir failed\n", __func__); goto err; } return 0; err: debug("%s: Node '%s', property '%s', failed to request GPIO index %d: %d\n", __func__, ofnode_get_name(node), list_name, index, ret); return ret; }
static int configure_emmc(struct udevice *pinctrl) { #if defined(CONFIG_TARGET_CHROMEBOOK_JERRY) struct gpio_desc desc; int ret; pinctrl_request_noflags(pinctrl, PERIPH_ID_EMMC); /* * TODO([email protected]): Pick this up from device tree or perhaps * use the EMMC_PWREN setting. */ ret = dm_gpio_lookup_name("D9", &desc); if (ret) { debug("gpio ret=%d\n", ret); return ret; } ret = dm_gpio_request(&desc, "emmc_pwren"); if (ret) { debug("gpio_request ret=%d\n", ret); return ret; } ret = dm_gpio_set_dir_flags(&desc, GPIOD_IS_OUT); if (ret) { debug("gpio dir ret=%d\n", ret); return ret; } ret = dm_gpio_set_value(&desc, 1); if (ret) { debug("gpio value ret=%d\n", ret); return ret; } #endif return 0; }
int dm_gpio_set_dir(struct gpio_desc *desc) { return dm_gpio_set_dir_flags(desc, desc->flags); }
int board_prepare_usb(enum usb_init_type type) { static struct udevice *pmic_gpio; static struct gpio_desc hub_reset, usb_sel; int ret = 0, node; if (!pmic_gpio) { ret = uclass_get_device_by_name(UCLASS_GPIO, "pm8916_gpios@c000", &pmic_gpio); if (ret < 0) { printf("Failed to find pm8916_gpios@c000 node.\n"); return ret; } } /* Try to request gpios needed to start usb host on dragonboard */ if (!dm_gpio_is_valid(&hub_reset)) { node = fdt_subnode_offset(gd->fdt_blob, dev_of_offset(pmic_gpio), "usb_hub_reset_pm"); if (node < 0) { printf("Failed to find usb_hub_reset_pm dt node.\n"); return node; } ret = gpio_request_by_name_nodev(offset_to_ofnode(node), "gpios", 0, &hub_reset, 0); if (ret < 0) { printf("Failed to request usb_hub_reset_pm gpio.\n"); return ret; } } if (!dm_gpio_is_valid(&usb_sel)) { node = fdt_subnode_offset(gd->fdt_blob, dev_of_offset(pmic_gpio), "usb_sw_sel_pm"); if (node < 0) { printf("Failed to find usb_sw_sel_pm dt node.\n"); return 0; } ret = gpio_request_by_name_nodev(offset_to_ofnode(node), "gpios", 0, &usb_sel, 0); if (ret < 0) { printf("Failed to request usb_sw_sel_pm gpio.\n"); return ret; } } if (type == USB_INIT_HOST) { /* Start USB Hub */ dm_gpio_set_dir_flags(&hub_reset, GPIOD_IS_OUT | GPIOD_IS_OUT_ACTIVE); mdelay(100); /* Switch usb to host connectors */ dm_gpio_set_dir_flags(&usb_sel, GPIOD_IS_OUT | GPIOD_IS_OUT_ACTIVE); mdelay(100); } else { /* Device */ /* Disable hub */ dm_gpio_set_dir_flags(&hub_reset, GPIOD_IS_OUT); /* Switch back to device connector */ dm_gpio_set_dir_flags(&usb_sel, GPIOD_IS_OUT); } return 0; }
static void i2c_gpio_scl_set(struct gpio_desc *scl, int bit) { dm_gpio_set_dir_flags(scl, GPIOD_IS_OUT); dm_gpio_set_value(scl, bit); }