int max17135_register_regulator(struct max17135 *max17135, int reg, struct regulator_init_data *initdata) { struct platform_device *pdev; int ret; struct i2c_client *client = max17135->i2c_client; /* If we can't find PMIC via I2C, we should not register regulators */ if (i2c_smbus_read_byte_data(client, REG_MAX17135_PRODUCT_REV) != 0) { dev_err(max17135->dev, "Max17135 PMIC not found!\n"); return -ENXIO; } if (max17135->pdev[reg]) return -EBUSY; pdev = platform_device_alloc("max17135-reg", reg); if (!pdev) return -ENOMEM; max17135->pdev[reg] = pdev; initdata->driver_data = max17135; pdev->dev.platform_data = initdata; pdev->dev.parent = max17135->dev; platform_set_drvdata(pdev, max17135); ret = platform_device_add(pdev); if (ret != 0) { dev_err(max17135->dev, "Failed to register regulator %d: %d\n", reg, ret); platform_device_del(pdev); max17135->pdev[reg] = NULL; } if (!max17135->init_done) { max17135->pass_num = max17135_pass_num; max17135->vcom_uV = max17135_vcom; /* * Set up PMIC timing values. * Should only be done one time! Timing values may only be * changed a limited number of times according to spec. */ max17135_setup_timings(max17135); max17135->pwrgood_polarity = gpio_get_value(max17135->gpio_pmic_pwrgood); max17135->init_done = true; } return ret; }
/* * Regulator init/probing/exit functions */ static int max17135_regulator_probe(struct platform_device *pdev) { struct max17135 *max17135 = dev_get_drvdata(pdev->dev.parent); struct max17135_platform_data *pdata = max17135->pdata; struct max17135_data *priv; struct regulator_dev **rdev; struct regulator_config config = { }; int size, i, ret = 0; if (max17135->dev->of_node) { ret = max17135_pmic_dt_parse_pdata(pdev, pdata); if (ret) return ret; } priv = devm_kzalloc(&pdev->dev, sizeof(struct max17135_data), GFP_KERNEL); if (!priv) return -ENOMEM; size = sizeof(struct regulator_dev *) * pdata->num_regulators; priv->rdev = devm_kzalloc(&pdev->dev, size, GFP_KERNEL); if (!priv->rdev) return -ENOMEM; rdev = priv->rdev; priv->num_regulators = pdata->num_regulators; platform_set_drvdata(pdev, priv); max17135->vcom_setup = false; max17135->pass_num = max17135_pass_num; max17135->vcom_uV = max17135_vcom; for (i = 0; i < pdata->num_regulators; i++) { int id = pdata->regulators[i].id; config.dev = max17135->dev; config.init_data = pdata->regulators[i].initdata; config.driver_data = max17135; config.of_node = pdata->regulators[i].reg_node; rdev[i] = regulator_register(&max17135_reg[id], &config); if (IS_ERR(rdev[i])) { ret = PTR_ERR(rdev[i]); dev_err(&pdev->dev, "regulator init failed for %d\n", id); rdev[i] = NULL; goto err; } } /* * Set up PMIC timing values. * Should only be done one time! Timing values may only be * changed a limited number of times according to spec. */ max17135_setup_timings(max17135); return 0; err: while (--i >= 0) regulator_unregister(rdev[i]); return ret; }