Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

power: supply: bq24190_charger: Export 5V boost converter as regulator

Register the 5V boost converter as a regulator named "usb_otg_vbus".

This commit also adds support for bq24190_platform_data, through which
non device-tree platforms can pass the regulator_init_data (containing
mappings for the consumer amongst other things).

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Acked-by: Tony Lindgren <tony@atomide.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.co.uk>

authored by

Hans de Goede and committed by
Sebastian Reichel
66b6bef2 14e1a131

+130
+112
drivers/power/supply/bq24190_charger.c
··· 16 16 #include <linux/of_device.h> 17 17 #include <linux/pm_runtime.h> 18 18 #include <linux/power_supply.h> 19 + #include <linux/power/bq24190_charger.h> 20 + #include <linux/regulator/driver.h> 21 + #include <linux/regulator/machine.h> 19 22 #include <linux/workqueue.h> 20 23 #include <linux/gpio.h> 21 24 #include <linux/i2c.h> ··· 514 511 } 515 512 516 513 static inline void bq24190_sysfs_remove_group(struct bq24190_dev_info *bdi) {} 514 + #endif 515 + 516 + #ifdef CONFIG_REGULATOR 517 + static int bq24190_set_charge_mode(struct regulator_dev *dev, u8 val) 518 + { 519 + struct bq24190_dev_info *bdi = rdev_get_drvdata(dev); 520 + int ret; 521 + 522 + ret = pm_runtime_get_sync(bdi->dev); 523 + if (ret < 0) { 524 + dev_warn(bdi->dev, "pm_runtime_get failed: %i\n", ret); 525 + pm_runtime_put_noidle(bdi->dev); 526 + return ret; 527 + } 528 + 529 + ret = bq24190_write_mask(bdi, BQ24190_REG_POC, 530 + BQ24190_REG_POC_CHG_CONFIG_MASK, 531 + BQ24190_REG_POC_CHG_CONFIG_SHIFT, val); 532 + 533 + pm_runtime_mark_last_busy(bdi->dev); 534 + pm_runtime_put_autosuspend(bdi->dev); 535 + 536 + return ret; 537 + } 538 + 539 + static int bq24190_vbus_enable(struct regulator_dev *dev) 540 + { 541 + return bq24190_set_charge_mode(dev, BQ24190_REG_POC_CHG_CONFIG_OTG); 542 + } 543 + 544 + static int bq24190_vbus_disable(struct regulator_dev *dev) 545 + { 546 + return bq24190_set_charge_mode(dev, BQ24190_REG_POC_CHG_CONFIG_CHARGE); 547 + } 548 + 549 + static int bq24190_vbus_is_enabled(struct regulator_dev *dev) 550 + { 551 + struct bq24190_dev_info *bdi = rdev_get_drvdata(dev); 552 + int ret; 553 + u8 val; 554 + 555 + ret = pm_runtime_get_sync(bdi->dev); 556 + if (ret < 0) { 557 + dev_warn(bdi->dev, "pm_runtime_get failed: %i\n", ret); 558 + pm_runtime_put_noidle(bdi->dev); 559 + return ret; 560 + } 561 + 562 + ret = bq24190_read_mask(bdi, BQ24190_REG_POC, 563 + BQ24190_REG_POC_CHG_CONFIG_MASK, 564 + BQ24190_REG_POC_CHG_CONFIG_SHIFT, &val); 565 + 566 + pm_runtime_mark_last_busy(bdi->dev); 567 + pm_runtime_put_autosuspend(bdi->dev); 568 + 569 + return ret ? ret : val == BQ24190_REG_POC_CHG_CONFIG_OTG; 570 + } 571 + 572 + static const struct regulator_ops bq24190_vbus_ops = { 573 + .enable = bq24190_vbus_enable, 574 + .disable = bq24190_vbus_disable, 575 + .is_enabled = bq24190_vbus_is_enabled, 576 + }; 577 + 578 + static const struct regulator_desc bq24190_vbus_desc = { 579 + .name = "usb_otg_vbus", 580 + .type = REGULATOR_VOLTAGE, 581 + .owner = THIS_MODULE, 582 + .ops = &bq24190_vbus_ops, 583 + .fixed_uV = 5000000, 584 + .n_voltages = 1, 585 + }; 586 + 587 + static const struct regulator_init_data bq24190_vbus_init_data = { 588 + .constraints = { 589 + .valid_ops_mask = REGULATOR_CHANGE_STATUS, 590 + }, 591 + }; 592 + 593 + static int bq24190_register_vbus_regulator(struct bq24190_dev_info *bdi) 594 + { 595 + struct bq24190_platform_data *pdata = bdi->dev->platform_data; 596 + struct regulator_config cfg = { }; 597 + struct regulator_dev *reg; 598 + int ret = 0; 599 + 600 + cfg.dev = bdi->dev; 601 + if (pdata && pdata->regulator_init_data) 602 + cfg.init_data = pdata->regulator_init_data; 603 + else 604 + cfg.init_data = &bq24190_vbus_init_data; 605 + cfg.driver_data = bdi; 606 + reg = devm_regulator_register(bdi->dev, &bq24190_vbus_desc, &cfg); 607 + if (IS_ERR(reg)) { 608 + ret = PTR_ERR(reg); 609 + dev_err(bdi->dev, "Can't register regulator: %d\n", ret); 610 + } 611 + 612 + return ret; 613 + } 614 + #else 615 + static int bq24190_register_vbus_regulator(struct bq24190_dev_info *bdi) 616 + { 617 + return 0; 618 + } 517 619 #endif 518 620 519 621 static int bq24190_set_config(struct bq24190_dev_info *bdi) ··· 1847 1739 dev_err(dev, "Can't set up irq handler\n"); 1848 1740 goto out_sysfs; 1849 1741 } 1742 + 1743 + ret = bq24190_register_vbus_regulator(bdi); 1744 + if (ret < 0) 1745 + goto out_sysfs; 1850 1746 1851 1747 if (bdi->extcon) { 1852 1748 INIT_DELAYED_WORK(&bdi->extcon_work, bq24190_extcon_work);
+18
include/linux/power/bq24190_charger.h
··· 1 + /* 2 + * Platform data for the TI bq24190 battery charger driver. 3 + * 4 + * This program is free software; you can redistribute it and/or modify 5 + * it under the terms of the GNU General Public License version 2 as 6 + * published by the Free Software Foundation. 7 + */ 8 + 9 + #ifndef _BQ24190_CHARGER_H_ 10 + #define _BQ24190_CHARGER_H_ 11 + 12 + #include <linux/regulator/machine.h> 13 + 14 + struct bq24190_platform_data { 15 + const struct regulator_init_data *regulator_init_data; 16 + }; 17 + 18 + #endif