static int reg_fixed_voltage_probe(struct platform_device *pdev) { struct fixed_voltage_config *config; struct fixed_voltage_data *drvdata; struct regulator_config cfg = { }; int ret; if (pdev->dev.of_node) { config = of_get_fixed_voltage_config(&pdev->dev); if (IS_ERR(config)) return PTR_ERR(config); } else { config = dev_get_platdata(&pdev->dev); } if (!config) return -ENOMEM; drvdata = devm_kzalloc(&pdev->dev, sizeof(struct fixed_voltage_data), GFP_KERNEL); if (!drvdata) return -ENOMEM; drvdata->desc.name = devm_kstrdup(&pdev->dev, config->supply_name, GFP_KERNEL); if (drvdata->desc.name == NULL) { dev_err(&pdev->dev, "Failed to allocate supply name\n"); return -ENOMEM; } drvdata->desc.type = REGULATOR_VOLTAGE; drvdata->desc.owner = THIS_MODULE; drvdata->desc.ops = &fixed_voltage_ops; drvdata->desc.enable_time = config->startup_delay; if (config->input_supply) { drvdata->desc.supply_name = devm_kstrdup(&pdev->dev, config->input_supply, GFP_KERNEL); if (!drvdata->desc.supply_name) { dev_err(&pdev->dev, "Failed to allocate input supply\n"); return -ENOMEM; } } if (config->microvolts) drvdata->desc.n_voltages = 1; drvdata->desc.fixed_uV = config->microvolts; if (config->gpio >= 0) cfg.ena_gpio = config->gpio; cfg.ena_gpio_invert = !config->enable_high; if (config->enabled_at_boot) { if (config->enable_high) cfg.ena_gpio_flags |= GPIOF_OUT_INIT_HIGH; else cfg.ena_gpio_flags |= GPIOF_OUT_INIT_LOW; } else { if (config->enable_high) cfg.ena_gpio_flags |= GPIOF_OUT_INIT_LOW; else cfg.ena_gpio_flags |= GPIOF_OUT_INIT_HIGH; } if (config->gpio_is_open_drain) cfg.ena_gpio_flags |= GPIOF_OPEN_DRAIN; cfg.dev = &pdev->dev; cfg.init_data = config->init_data; cfg.driver_data = drvdata; cfg.of_node = pdev->dev.of_node; drvdata->dev = devm_regulator_register(&pdev->dev, &drvdata->desc, &cfg); if (IS_ERR(drvdata->dev)) { ret = PTR_ERR(drvdata->dev); dev_err(&pdev->dev, "Failed to register regulator: %d\n", ret); return ret; } platform_set_drvdata(pdev, drvdata); dev_dbg(&pdev->dev, "%s supplying %duV\n", drvdata->desc.name, drvdata->desc.fixed_uV); return 0; }
static int __devinit reg_fixed_voltage_probe(struct platform_device *pdev) { struct fixed_voltage_config *config; struct fixed_voltage_data *drvdata; int ret; if (pdev->dev.of_node) config = of_get_fixed_voltage_config(&pdev->dev); else config = pdev->dev.platform_data; if (!config) return -ENOMEM; drvdata = kzalloc(sizeof(struct fixed_voltage_data), GFP_KERNEL); if (drvdata == NULL) { dev_err(&pdev->dev, "Failed to allocate device data\n"); ret = -ENOMEM; goto err; } drvdata->desc.name = kstrdup(config->supply_name, GFP_KERNEL); if (drvdata->desc.name == NULL) { dev_err(&pdev->dev, "Failed to allocate supply name\n"); ret = -ENOMEM; goto err; } drvdata->desc.type = REGULATOR_VOLTAGE; drvdata->desc.owner = THIS_MODULE; drvdata->desc.ops = &fixed_voltage_ops; if (config->microvolts) drvdata->desc.n_voltages = 1; drvdata->microvolts = config->microvolts; drvdata->gpio = config->gpio; drvdata->startup_delay = config->startup_delay; if (gpio_is_valid(config->gpio)) { drvdata->enable_high = config->enable_high; /* FIXME: Remove below print warning * * config->gpio must be set to -EINVAL by platform code if * GPIO control is not required. However, early adopters * not requiring GPIO control may forget to initialize * config->gpio to -EINVAL. This will cause GPIO 0 to be used * for GPIO control. * * This warning will be removed once there are a couple of users * for this driver. */ if (!config->gpio) dev_warn(&pdev->dev, "using GPIO 0 for regulator enable control\n"); ret = gpio_request(config->gpio, config->supply_name); if (ret) { dev_err(&pdev->dev, "Could not obtain regulator enable GPIO %d: %d\n", config->gpio, ret); goto err_name; } /* set output direction without changing state * to prevent glitch */ drvdata->is_enabled = config->enabled_at_boot; ret = drvdata->is_enabled ? config->enable_high : !config->enable_high; ret = gpio_direction_output(config->gpio, ret); if (ret) { dev_err(&pdev->dev, "Could not configure regulator enable GPIO %d direction: %d\n", config->gpio, ret); goto err_gpio; } } else { /* Regulator without GPIO control is considered * always enabled */ drvdata->is_enabled = true; } drvdata->dev = regulator_register(&drvdata->desc, &pdev->dev, config->init_data, drvdata); if (IS_ERR(drvdata->dev)) { ret = PTR_ERR(drvdata->dev); dev_err(&pdev->dev, "Failed to register regulator: %d\n", ret); goto err_gpio; } platform_set_drvdata(pdev, drvdata); dev_dbg(&pdev->dev, "%s supplying %duV\n", drvdata->desc.name, drvdata->microvolts); return 0; err_gpio: if (gpio_is_valid(config->gpio)) gpio_free(config->gpio); err_name: kfree(drvdata->desc.name); err: kfree(drvdata); return ret; }