aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/regulator/twl-regulator.c
diff options
context:
space:
mode:
authorArnd Bergmann <arnd@arndb.de>2012-08-14 08:41:50 -0400
committerMark Brown <broonie@opensource.wolfsonmicro.com>2012-08-28 14:00:28 -0400
commit0ffff5a60fdd7455c83855ee788a8aae9a79aab4 (patch)
tree5a75585df8ecc9bbdf916cae20b70bee4d3a377d /drivers/regulator/twl-regulator.c
parentf9cfbde723ba89b7bf7d1ec0b8adeea0c3c4a091 (diff)
regulator: twl: make twl_info tables const
I currently carry the series to make of_device_id->data const in the arm-soc tree, which fixes a number of issues, but leaves one new compiler warning about the twl-regulator driver: drivers/regulator/twl-regulator.c: In function 'twlreg_probe': drivers/regulator/twl-regulator.c:1130:8: warning: assignment discards 'const' qualifier from pointer target type [enabled by default] drivers/regulator/twl-regulator.c:1139:9: warning: assignment discards 'const' qualifier from pointer target type [enabled by default] The warning indicates that the driver takes a static table with initialization data for each regulator, modifies the data in place and passes a pointer to that structure to the regulator_register function. This is probably ok because a system contains only one instance of each regulator, but it's still bad style because any driver should be written to support multiple instances of the same hardware. This patch changes the code to dynamically allocate the memory we pass to the regulator core so the table can be constant. Signed-off-by: Arnd Bergmann <arnd@arndb.de> Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
Diffstat (limited to 'drivers/regulator/twl-regulator.c')
-rw-r--r--drivers/regulator/twl-regulator.c38
1 files changed, 24 insertions, 14 deletions
diff --git a/drivers/regulator/twl-regulator.c b/drivers/regulator/twl-regulator.c
index 5ce841087447..a8365229ea6d 100644
--- a/drivers/regulator/twl-regulator.c
+++ b/drivers/regulator/twl-regulator.c
@@ -863,7 +863,7 @@ static struct regulator_ops twlsmps_ops = {
863 0x0, TWL6030, twl6030fixed_ops) 863 0x0, TWL6030, twl6030fixed_ops)
864 864
865#define TWL4030_ADJUSTABLE_LDO(label, offset, num, turnon_delay, remap_conf) \ 865#define TWL4030_ADJUSTABLE_LDO(label, offset, num, turnon_delay, remap_conf) \
866static struct twlreg_info TWL4030_INFO_##label = { \ 866static const struct twlreg_info TWL4030_INFO_##label = { \
867 .base = offset, \ 867 .base = offset, \
868 .id = num, \ 868 .id = num, \
869 .table_len = ARRAY_SIZE(label##_VSEL_table), \ 869 .table_len = ARRAY_SIZE(label##_VSEL_table), \
@@ -881,7 +881,7 @@ static struct twlreg_info TWL4030_INFO_##label = { \
881 } 881 }
882 882
883#define TWL4030_ADJUSTABLE_SMPS(label, offset, num, turnon_delay, remap_conf) \ 883#define TWL4030_ADJUSTABLE_SMPS(label, offset, num, turnon_delay, remap_conf) \
884static struct twlreg_info TWL4030_INFO_##label = { \ 884static const struct twlreg_info TWL4030_INFO_##label = { \
885 .base = offset, \ 885 .base = offset, \
886 .id = num, \ 886 .id = num, \
887 .remap = remap_conf, \ 887 .remap = remap_conf, \
@@ -896,7 +896,7 @@ static struct twlreg_info TWL4030_INFO_##label = { \
896 } 896 }
897 897
898#define TWL6030_ADJUSTABLE_SMPS(label) \ 898#define TWL6030_ADJUSTABLE_SMPS(label) \
899static struct twlreg_info TWL6030_INFO_##label = { \ 899static const struct twlreg_info TWL6030_INFO_##label = { \
900 .desc = { \ 900 .desc = { \
901 .name = #label, \ 901 .name = #label, \
902 .id = TWL6030_REG_##label, \ 902 .id = TWL6030_REG_##label, \
@@ -907,7 +907,7 @@ static struct twlreg_info TWL6030_INFO_##label = { \
907 } 907 }
908 908
909#define TWL6030_ADJUSTABLE_LDO(label, offset, min_mVolts, max_mVolts) \ 909#define TWL6030_ADJUSTABLE_LDO(label, offset, min_mVolts, max_mVolts) \
910static struct twlreg_info TWL6030_INFO_##label = { \ 910static const struct twlreg_info TWL6030_INFO_##label = { \
911 .base = offset, \ 911 .base = offset, \
912 .min_mV = min_mVolts, \ 912 .min_mV = min_mVolts, \
913 .max_mV = max_mVolts, \ 913 .max_mV = max_mVolts, \
@@ -922,7 +922,7 @@ static struct twlreg_info TWL6030_INFO_##label = { \
922 } 922 }
923 923
924#define TWL6025_ADJUSTABLE_LDO(label, offset, min_mVolts, max_mVolts) \ 924#define TWL6025_ADJUSTABLE_LDO(label, offset, min_mVolts, max_mVolts) \
925static struct twlreg_info TWL6025_INFO_##label = { \ 925static const struct twlreg_info TWL6025_INFO_##label = { \
926 .base = offset, \ 926 .base = offset, \
927 .min_mV = min_mVolts, \ 927 .min_mV = min_mVolts, \
928 .max_mV = max_mVolts, \ 928 .max_mV = max_mVolts, \
@@ -938,7 +938,7 @@ static struct twlreg_info TWL6025_INFO_##label = { \
938 938
939#define TWL_FIXED_LDO(label, offset, mVolts, num, turnon_delay, remap_conf, \ 939#define TWL_FIXED_LDO(label, offset, mVolts, num, turnon_delay, remap_conf, \
940 family, operations) \ 940 family, operations) \
941static struct twlreg_info TWLFIXED_INFO_##label = { \ 941static const struct twlreg_info TWLFIXED_INFO_##label = { \
942 .base = offset, \ 942 .base = offset, \
943 .id = num, \ 943 .id = num, \
944 .min_mV = mVolts, \ 944 .min_mV = mVolts, \
@@ -968,7 +968,7 @@ static struct twlreg_info TWLRES_INFO_##label = { \
968 } 968 }
969 969
970#define TWL6025_ADJUSTABLE_SMPS(label, offset) \ 970#define TWL6025_ADJUSTABLE_SMPS(label, offset) \
971static struct twlreg_info TWLSMPS_INFO_##label = { \ 971static const struct twlreg_info TWLSMPS_INFO_##label = { \
972 .base = offset, \ 972 .base = offset, \
973 .min_mV = 600, \ 973 .min_mV = 600, \
974 .max_mV = 2100, \ 974 .max_mV = 2100, \
@@ -1125,6 +1125,7 @@ static int __devinit twlreg_probe(struct platform_device *pdev)
1125{ 1125{
1126 int i, id; 1126 int i, id;
1127 struct twlreg_info *info; 1127 struct twlreg_info *info;
1128 const struct twlreg_info *template;
1128 struct regulator_init_data *initdata; 1129 struct regulator_init_data *initdata;
1129 struct regulation_constraints *c; 1130 struct regulation_constraints *c;
1130 struct regulator_dev *rdev; 1131 struct regulator_dev *rdev;
@@ -1134,17 +1135,17 @@ static int __devinit twlreg_probe(struct platform_device *pdev)
1134 1135
1135 match = of_match_device(twl_of_match, &pdev->dev); 1136 match = of_match_device(twl_of_match, &pdev->dev);
1136 if (match) { 1137 if (match) {
1137 info = match->data; 1138 template = match->data;
1138 id = info->desc.id; 1139 id = template->desc.id;
1139 initdata = of_get_regulator_init_data(&pdev->dev, 1140 initdata = of_get_regulator_init_data(&pdev->dev,
1140 pdev->dev.of_node); 1141 pdev->dev.of_node);
1141 drvdata = NULL; 1142 drvdata = NULL;
1142 } else { 1143 } else {
1143 id = pdev->id; 1144 id = pdev->id;
1144 initdata = pdev->dev.platform_data; 1145 initdata = pdev->dev.platform_data;
1145 for (i = 0, info = NULL; i < ARRAY_SIZE(twl_of_match); i++) { 1146 for (i = 0, template = NULL; i < ARRAY_SIZE(twl_of_match); i++) {
1146 info = twl_of_match[i].data; 1147 template = twl_of_match[i].data;
1147 if (info && info->desc.id == id) 1148 if (template && template->desc.id == id)
1148 break; 1149 break;
1149 } 1150 }
1150 if (i == ARRAY_SIZE(twl_of_match)) 1151 if (i == ARRAY_SIZE(twl_of_match))
@@ -1155,12 +1156,16 @@ static int __devinit twlreg_probe(struct platform_device *pdev)
1155 return -EINVAL; 1156 return -EINVAL;
1156 } 1157 }
1157 1158
1158 if (!info) 1159 if (!template)
1159 return -ENODEV; 1160 return -ENODEV;
1160 1161
1161 if (!initdata) 1162 if (!initdata)
1162 return -EINVAL; 1163 return -EINVAL;
1163 1164
1165 info = kmemdup(template, sizeof (*info), GFP_KERNEL);
1166 if (!info)
1167 return -ENOMEM;
1168
1164 if (drvdata) { 1169 if (drvdata) {
1165 /* copy the driver data into regulator data */ 1170 /* copy the driver data into regulator data */
1166 info->features = drvdata->features; 1171 info->features = drvdata->features;
@@ -1221,6 +1226,7 @@ static int __devinit twlreg_probe(struct platform_device *pdev)
1221 if (IS_ERR(rdev)) { 1226 if (IS_ERR(rdev)) {
1222 dev_err(&pdev->dev, "can't register %s, %ld\n", 1227 dev_err(&pdev->dev, "can't register %s, %ld\n",
1223 info->desc.name, PTR_ERR(rdev)); 1228 info->desc.name, PTR_ERR(rdev));
1229 kfree(info);
1224 return PTR_ERR(rdev); 1230 return PTR_ERR(rdev);
1225 } 1231 }
1226 platform_set_drvdata(pdev, rdev); 1232 platform_set_drvdata(pdev, rdev);
@@ -1242,7 +1248,11 @@ static int __devinit twlreg_probe(struct platform_device *pdev)
1242 1248
1243static int __devexit twlreg_remove(struct platform_device *pdev) 1249static int __devexit twlreg_remove(struct platform_device *pdev)
1244{ 1250{
1245 regulator_unregister(platform_get_drvdata(pdev)); 1251 struct regulator_dev *rdev = platform_get_drvdata(pdev);
1252 struct twlreg_info *info = rdev->reg_data;
1253
1254 regulator_unregister(rdev);
1255 kfree(info);
1246 return 0; 1256 return 0;
1247} 1257}
1248 1258