tps6507x-regulator.c (69c57b97db9c4886b1f338613fccb0b8408b324b) tps6507x-regulator.c (f979c08f762441188abb9be42689a72953efbbf7)
1/*
2 * tps6507x-regulator.c
3 *
4 * Regulator driver for TPS65073 PMIC
5 *
6 * Copyright (C) 2009 Texas Instrument Incorporated - http://www.ti.com/
7 *
8 * This program is free software; you can redistribute it and/or

--- 344 unchanged lines hidden (view full) ---

353 .enable = tps6507x_pmic_enable,
354 .disable = tps6507x_pmic_disable,
355 .get_voltage_sel = tps6507x_pmic_get_voltage_sel,
356 .set_voltage_sel = tps6507x_pmic_set_voltage_sel,
357 .list_voltage = regulator_list_voltage_table,
358 .map_voltage = regulator_map_voltage_ascend,
359};
360
1/*
2 * tps6507x-regulator.c
3 *
4 * Regulator driver for TPS65073 PMIC
5 *
6 * Copyright (C) 2009 Texas Instrument Incorporated - http://www.ti.com/
7 *
8 * This program is free software; you can redistribute it and/or

--- 344 unchanged lines hidden (view full) ---

353 .enable = tps6507x_pmic_enable,
354 .disable = tps6507x_pmic_disable,
355 .get_voltage_sel = tps6507x_pmic_get_voltage_sel,
356 .set_voltage_sel = tps6507x_pmic_set_voltage_sel,
357 .list_voltage = regulator_list_voltage_table,
358 .map_voltage = regulator_map_voltage_ascend,
359};
360
361static struct of_regulator_match tps6507x_matches[] = {
362 { .name = "VDCDC1"},
363 { .name = "VDCDC2"},
364 { .name = "VDCDC3"},
365 { .name = "LDO1"},
366 { .name = "LDO2"},
367};
368
369static struct tps6507x_board *tps6507x_parse_dt_reg_data(
370 struct platform_device *pdev,
371 struct of_regulator_match **tps6507x_reg_matches)
361static int tps6507x_pmic_of_parse_cb(struct device_node *np,
362 const struct regulator_desc *desc,
363 struct regulator_config *config)
372{
364{
373 struct tps6507x_board *tps_board;
374 struct device_node *np = pdev->dev.parent->of_node;
375 struct device_node *regulators;
376 struct of_regulator_match *matches;
377 struct regulator_init_data *reg_data;
378 int idx = 0, count, ret;
365 struct tps6507x_pmic *tps = config->driver_data;
366 struct tps_info *info = tps->info[desc->id];
367 u32 prop;
368 int ret;
379
369
380 tps_board = devm_kzalloc(&pdev->dev, sizeof(*tps_board),
381 GFP_KERNEL);
382 if (!tps_board)
383 return NULL;
370 ret = of_property_read_u32(np, "ti,defdcdc_default", &prop);
371 if (!ret)
372 info->defdcdc_default = prop;
384
373
385 regulators = of_get_child_by_name(np, "regulators");
386 if (!regulators) {
387 dev_err(&pdev->dev, "regulator node not found\n");
388 return NULL;
389 }
390
391 count = ARRAY_SIZE(tps6507x_matches);
392 matches = tps6507x_matches;
393
394 ret = of_regulator_match(&pdev->dev, regulators, matches, count);
395 of_node_put(regulators);
396 if (ret < 0) {
397 dev_err(&pdev->dev, "Error parsing regulator init data: %d\n",
398 ret);
399 return NULL;
400 }
401
402 *tps6507x_reg_matches = matches;
403
404 reg_data = devm_kzalloc(&pdev->dev, (sizeof(struct regulator_init_data)
405 * TPS6507X_NUM_REGULATOR), GFP_KERNEL);
406 if (!reg_data)
407 return NULL;
408
409 tps_board->tps6507x_pmic_init_data = reg_data;
410
411 for (idx = 0; idx < count; idx++) {
412 if (!matches[idx].init_data || !matches[idx].of_node)
413 continue;
414
415 memcpy(&reg_data[idx], matches[idx].init_data,
416 sizeof(struct regulator_init_data));
417
418 }
419
420 return tps_board;
374 return 0;
421}
422
423static int tps6507x_pmic_probe(struct platform_device *pdev)
424{
425 struct tps6507x_dev *tps6507x_dev = dev_get_drvdata(pdev->dev.parent);
426 struct tps_info *info = &tps6507x_pmic_regs[0];
427 struct regulator_config config = { };
375}
376
377static int tps6507x_pmic_probe(struct platform_device *pdev)
378{
379 struct tps6507x_dev *tps6507x_dev = dev_get_drvdata(pdev->dev.parent);
380 struct tps_info *info = &tps6507x_pmic_regs[0];
381 struct regulator_config config = { };
428 struct regulator_init_data *init_data;
382 struct regulator_init_data *init_data = NULL;
429 struct regulator_dev *rdev;
430 struct tps6507x_pmic *tps;
431 struct tps6507x_board *tps_board;
383 struct regulator_dev *rdev;
384 struct tps6507x_pmic *tps;
385 struct tps6507x_board *tps_board;
432 struct of_regulator_match *tps6507x_reg_matches = NULL;
433 int i;
386 int i;
434 int error;
435 unsigned int prop;
436
437 /**
438 * tps_board points to pmic related constants
439 * coming from the board-evm file.
440 */
441
442 tps_board = dev_get_platdata(tps6507x_dev->dev);
387
388 /**
389 * tps_board points to pmic related constants
390 * coming from the board-evm file.
391 */
392
393 tps_board = dev_get_platdata(tps6507x_dev->dev);
443 if (IS_ENABLED(CONFIG_OF) && !tps_board &&
444 tps6507x_dev->dev->of_node)
445 tps_board = tps6507x_parse_dt_reg_data(pdev,
446 &tps6507x_reg_matches);
447 if (!tps_board)
448 return -EINVAL;
394 if (tps_board)
395 init_data = tps_board->tps6507x_pmic_init_data;
449
396
450 /**
451 * init_data points to array of regulator_init structures
452 * coming from the board-evm file.
453 */
454 init_data = tps_board->tps6507x_pmic_init_data;
455 if (!init_data)
456 return -EINVAL;
457
458 tps = devm_kzalloc(&pdev->dev, sizeof(*tps), GFP_KERNEL);
459 if (!tps)
460 return -ENOMEM;
461
462 mutex_init(&tps->io_lock);
463
464 /* common for all regulators */
465 tps->mfd = tps6507x_dev;
466
467 for (i = 0; i < TPS6507X_NUM_REGULATOR; i++, info++, init_data++) {
468 /* Register the regulators */
469 tps->info[i] = info;
397 tps = devm_kzalloc(&pdev->dev, sizeof(*tps), GFP_KERNEL);
398 if (!tps)
399 return -ENOMEM;
400
401 mutex_init(&tps->io_lock);
402
403 /* common for all regulators */
404 tps->mfd = tps6507x_dev;
405
406 for (i = 0; i < TPS6507X_NUM_REGULATOR; i++, info++, init_data++) {
407 /* Register the regulators */
408 tps->info[i] = info;
470 if (init_data->driver_data) {
409 if (init_data && init_data->driver_data) {
471 struct tps6507x_reg_platform_data *data =
472 init_data->driver_data;
410 struct tps6507x_reg_platform_data *data =
411 init_data->driver_data;
473 tps->info[i]->defdcdc_default = data->defdcdc_default;
412 info->defdcdc_default = data->defdcdc_default;
474 }
475
476 tps->desc[i].name = info->name;
413 }
414
415 tps->desc[i].name = info->name;
416 tps->desc[i].of_match = of_match_ptr(info->name);
417 tps->desc[i].regulators_node = of_match_ptr("regulators");
418 tps->desc[i].of_parse_cb = tps6507x_pmic_of_parse_cb;
477 tps->desc[i].id = i;
478 tps->desc[i].n_voltages = info->table_len;
479 tps->desc[i].volt_table = info->table;
480 tps->desc[i].ops = &tps6507x_pmic_ops;
481 tps->desc[i].type = REGULATOR_VOLTAGE;
482 tps->desc[i].owner = THIS_MODULE;
483
484 config.dev = tps6507x_dev->dev;
485 config.init_data = init_data;
486 config.driver_data = tps;
487
419 tps->desc[i].id = i;
420 tps->desc[i].n_voltages = info->table_len;
421 tps->desc[i].volt_table = info->table;
422 tps->desc[i].ops = &tps6507x_pmic_ops;
423 tps->desc[i].type = REGULATOR_VOLTAGE;
424 tps->desc[i].owner = THIS_MODULE;
425
426 config.dev = tps6507x_dev->dev;
427 config.init_data = init_data;
428 config.driver_data = tps;
429
488 if (tps6507x_reg_matches) {
489 error = of_property_read_u32(
490 tps6507x_reg_matches[i].of_node,
491 "ti,defdcdc_default", &prop);
492
493 if (!error)
494 tps->info[i]->defdcdc_default = prop;
495
496 config.of_node = tps6507x_reg_matches[i].of_node;
497 }
498
499 rdev = devm_regulator_register(&pdev->dev, &tps->desc[i],
500 &config);
501 if (IS_ERR(rdev)) {
502 dev_err(tps6507x_dev->dev,
503 "failed to register %s regulator\n",
504 pdev->name);
505 return PTR_ERR(rdev);
506 }

--- 31 unchanged lines hidden ---
430 rdev = devm_regulator_register(&pdev->dev, &tps->desc[i],
431 &config);
432 if (IS_ERR(rdev)) {
433 dev_err(tps6507x_dev->dev,
434 "failed to register %s regulator\n",
435 pdev->name);
436 return PTR_ERR(rdev);
437 }

--- 31 unchanged lines hidden ---