1 /* 2 * arizona-ldo1.c -- LDO1 supply for Arizona devices 3 * 4 * Copyright 2012 Wolfson Microelectronics PLC. 5 * 6 * Author: Mark Brown <broonie@opensource.wolfsonmicro.com> 7 * 8 * This program is free software; you can redistribute it and/or modify it 9 * under the terms of the GNU General Public License as published by the 10 * Free Software Foundation; either version 2 of the License, or (at your 11 * option) any later version. 12 */ 13 14 #include <linux/module.h> 15 #include <linux/moduleparam.h> 16 #include <linux/init.h> 17 #include <linux/bitops.h> 18 #include <linux/err.h> 19 #include <linux/platform_device.h> 20 #include <linux/regulator/driver.h> 21 #include <linux/regulator/machine.h> 22 #include <linux/gpio.h> 23 #include <linux/slab.h> 24 25 #include <linux/mfd/arizona/core.h> 26 #include <linux/mfd/arizona/pdata.h> 27 #include <linux/mfd/arizona/registers.h> 28 29 struct arizona_ldo1 { 30 struct regulator_dev *regulator; 31 struct arizona *arizona; 32 33 struct regulator_consumer_supply supply; 34 struct regulator_init_data init_data; 35 }; 36 37 static struct regulator_ops arizona_ldo1_ops = { 38 .list_voltage = regulator_list_voltage_linear, 39 .map_voltage = regulator_map_voltage_linear, 40 .get_voltage_sel = regulator_get_voltage_sel_regmap, 41 .set_voltage_sel = regulator_set_voltage_sel_regmap, 42 .get_bypass = regulator_get_bypass_regmap, 43 .set_bypass = regulator_set_bypass_regmap, 44 }; 45 46 static const struct regulator_desc arizona_ldo1 = { 47 .name = "LDO1", 48 .supply_name = "LDOVDD", 49 .type = REGULATOR_VOLTAGE, 50 .ops = &arizona_ldo1_ops, 51 52 .vsel_reg = ARIZONA_LDO1_CONTROL_1, 53 .vsel_mask = ARIZONA_LDO1_VSEL_MASK, 54 .bypass_reg = ARIZONA_LDO1_CONTROL_1, 55 .bypass_mask = ARIZONA_LDO1_BYPASS, 56 .min_uV = 900000, 57 .uV_step = 50000, 58 .n_voltages = 6, 59 60 .owner = THIS_MODULE, 61 }; 62 63 static const struct regulator_init_data arizona_ldo1_default = { 64 .constraints = { 65 .valid_ops_mask = REGULATOR_CHANGE_STATUS, 66 }, 67 .num_consumer_supplies = 1, 68 }; 69 70 static __devinit int arizona_ldo1_probe(struct platform_device *pdev) 71 { 72 struct arizona *arizona = dev_get_drvdata(pdev->dev.parent); 73 struct regulator_config config = { }; 74 struct arizona_ldo1 *ldo1; 75 int ret; 76 77 ldo1 = devm_kzalloc(&pdev->dev, sizeof(*ldo1), GFP_KERNEL); 78 if (ldo1 == NULL) { 79 dev_err(&pdev->dev, "Unable to allocate private data\n"); 80 return -ENOMEM; 81 } 82 83 ldo1->arizona = arizona; 84 85 /* 86 * Since the chip usually supplies itself we provide some 87 * default init_data for it. This will be overridden with 88 * platform data if provided. 89 */ 90 ldo1->init_data = arizona_ldo1_default; 91 ldo1->init_data.consumer_supplies = &ldo1->supply; 92 ldo1->supply.supply = "DCVDD"; 93 ldo1->supply.dev_name = dev_name(arizona->dev); 94 95 config.dev = arizona->dev; 96 config.driver_data = ldo1; 97 config.regmap = arizona->regmap; 98 config.ena_gpio = arizona->pdata.ldoena; 99 100 if (arizona->pdata.ldo1) 101 config.init_data = arizona->pdata.ldo1; 102 else 103 config.init_data = &ldo1->init_data; 104 105 ldo1->regulator = regulator_register(&arizona_ldo1, &config); 106 if (IS_ERR(ldo1->regulator)) { 107 ret = PTR_ERR(ldo1->regulator); 108 dev_err(arizona->dev, "Failed to register LDO1 supply: %d\n", 109 ret); 110 return ret; 111 } 112 113 platform_set_drvdata(pdev, ldo1); 114 115 return 0; 116 } 117 118 static __devexit int arizona_ldo1_remove(struct platform_device *pdev) 119 { 120 struct arizona_ldo1 *ldo1 = platform_get_drvdata(pdev); 121 122 regulator_unregister(ldo1->regulator); 123 124 return 0; 125 } 126 127 static struct platform_driver arizona_ldo1_driver = { 128 .probe = arizona_ldo1_probe, 129 .remove = __devexit_p(arizona_ldo1_remove), 130 .driver = { 131 .name = "arizona-ldo1", 132 .owner = THIS_MODULE, 133 }, 134 }; 135 136 module_platform_driver(arizona_ldo1_driver); 137 138 /* Module information */ 139 MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>"); 140 MODULE_DESCRIPTION("Arizona LDO1 driver"); 141 MODULE_LICENSE("GPL"); 142 MODULE_ALIAS("platform:arizona-ldo1"); 143