| .. | .. |
|---|
| 1 | 1 | /* |
|---|
| 2 | 2 | * pbias-regulator.c |
|---|
| 3 | 3 | * |
|---|
| 4 | | - * Copyright (C) 2014 Texas Instruments Incorporated - http://www.ti.com/ |
|---|
| 4 | + * Copyright (C) 2014 Texas Instruments Incorporated - https://www.ti.com/ |
|---|
| 5 | 5 | * Author: Balaji T K <balajitk@ti.com> |
|---|
| 6 | 6 | * |
|---|
| 7 | 7 | * This program is free software; you can redistribute it and/or |
|---|
| .. | .. |
|---|
| 36 | 36 | char *name; |
|---|
| 37 | 37 | const unsigned int *pbias_volt_table; |
|---|
| 38 | 38 | int n_voltages; |
|---|
| 39 | | -}; |
|---|
| 40 | | - |
|---|
| 41 | | -struct pbias_regulator_data { |
|---|
| 42 | | - struct regulator_desc desc; |
|---|
| 43 | | - void __iomem *pbias_addr; |
|---|
| 44 | | - struct regulator_dev *dev; |
|---|
| 45 | | - struct regmap *syscon; |
|---|
| 46 | | - const struct pbias_reg_info *info; |
|---|
| 47 | | - int voltage; |
|---|
| 48 | 39 | }; |
|---|
| 49 | 40 | |
|---|
| 50 | 41 | struct pbias_of_data { |
|---|
| .. | .. |
|---|
| 157 | 148 | static int pbias_regulator_probe(struct platform_device *pdev) |
|---|
| 158 | 149 | { |
|---|
| 159 | 150 | struct device_node *np = pdev->dev.of_node; |
|---|
| 160 | | - struct pbias_regulator_data *drvdata; |
|---|
| 161 | 151 | struct resource *res; |
|---|
| 162 | 152 | struct regulator_config cfg = { }; |
|---|
| 153 | + struct regulator_desc *desc; |
|---|
| 154 | + struct regulator_dev *rdev; |
|---|
| 163 | 155 | struct regmap *syscon; |
|---|
| 164 | 156 | const struct pbias_reg_info *info; |
|---|
| 165 | | - int ret = 0; |
|---|
| 166 | | - int count, idx, data_idx = 0; |
|---|
| 167 | | - const struct of_device_id *match; |
|---|
| 157 | + int ret, count, idx; |
|---|
| 168 | 158 | const struct pbias_of_data *data; |
|---|
| 169 | 159 | unsigned int offset; |
|---|
| 170 | 160 | |
|---|
| .. | .. |
|---|
| 173 | 163 | if (count < 0) |
|---|
| 174 | 164 | return count; |
|---|
| 175 | 165 | |
|---|
| 176 | | - drvdata = devm_kcalloc(&pdev->dev, |
|---|
| 177 | | - count, sizeof(struct pbias_regulator_data), |
|---|
| 178 | | - GFP_KERNEL); |
|---|
| 179 | | - if (!drvdata) |
|---|
| 166 | + desc = devm_kcalloc(&pdev->dev, count, sizeof(*desc), GFP_KERNEL); |
|---|
| 167 | + if (!desc) |
|---|
| 180 | 168 | return -ENOMEM; |
|---|
| 181 | 169 | |
|---|
| 182 | 170 | syscon = syscon_regmap_lookup_by_phandle(np, "syscon"); |
|---|
| 183 | 171 | if (IS_ERR(syscon)) |
|---|
| 184 | 172 | return PTR_ERR(syscon); |
|---|
| 185 | 173 | |
|---|
| 186 | | - match = of_match_device(of_match_ptr(pbias_of_match), &pdev->dev); |
|---|
| 187 | | - if (match && match->data) { |
|---|
| 188 | | - data = match->data; |
|---|
| 174 | + data = of_device_get_match_data(&pdev->dev); |
|---|
| 175 | + if (data) { |
|---|
| 189 | 176 | offset = data->offset; |
|---|
| 190 | 177 | } else { |
|---|
| 191 | 178 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
|---|
| .. | .. |
|---|
| 200 | 187 | cfg.regmap = syscon; |
|---|
| 201 | 188 | cfg.dev = &pdev->dev; |
|---|
| 202 | 189 | |
|---|
| 203 | | - for (idx = 0; idx < PBIAS_NUM_REGS && data_idx < count; idx++) { |
|---|
| 190 | + for (idx = 0; idx < PBIAS_NUM_REGS && count; idx++) { |
|---|
| 204 | 191 | if (!pbias_matches[idx].init_data || |
|---|
| 205 | 192 | !pbias_matches[idx].of_node) |
|---|
| 206 | 193 | continue; |
|---|
| .. | .. |
|---|
| 209 | 196 | if (!info) |
|---|
| 210 | 197 | return -ENODEV; |
|---|
| 211 | 198 | |
|---|
| 212 | | - drvdata[data_idx].syscon = syscon; |
|---|
| 213 | | - drvdata[data_idx].info = info; |
|---|
| 214 | | - drvdata[data_idx].desc.name = info->name; |
|---|
| 215 | | - drvdata[data_idx].desc.owner = THIS_MODULE; |
|---|
| 216 | | - drvdata[data_idx].desc.type = REGULATOR_VOLTAGE; |
|---|
| 217 | | - drvdata[data_idx].desc.ops = &pbias_regulator_voltage_ops; |
|---|
| 218 | | - drvdata[data_idx].desc.volt_table = info->pbias_volt_table; |
|---|
| 219 | | - drvdata[data_idx].desc.n_voltages = info->n_voltages; |
|---|
| 220 | | - drvdata[data_idx].desc.enable_time = info->enable_time; |
|---|
| 221 | | - drvdata[data_idx].desc.vsel_reg = offset; |
|---|
| 222 | | - drvdata[data_idx].desc.vsel_mask = info->vmode; |
|---|
| 223 | | - drvdata[data_idx].desc.enable_reg = offset; |
|---|
| 224 | | - drvdata[data_idx].desc.enable_mask = info->enable_mask; |
|---|
| 225 | | - drvdata[data_idx].desc.enable_val = info->enable; |
|---|
| 226 | | - drvdata[data_idx].desc.disable_val = info->disable_val; |
|---|
| 199 | + desc->name = info->name; |
|---|
| 200 | + desc->owner = THIS_MODULE; |
|---|
| 201 | + desc->type = REGULATOR_VOLTAGE; |
|---|
| 202 | + desc->ops = &pbias_regulator_voltage_ops; |
|---|
| 203 | + desc->volt_table = info->pbias_volt_table; |
|---|
| 204 | + desc->n_voltages = info->n_voltages; |
|---|
| 205 | + desc->enable_time = info->enable_time; |
|---|
| 206 | + desc->vsel_reg = offset; |
|---|
| 207 | + desc->vsel_mask = info->vmode; |
|---|
| 208 | + desc->enable_reg = offset; |
|---|
| 209 | + desc->enable_mask = info->enable_mask; |
|---|
| 210 | + desc->enable_val = info->enable; |
|---|
| 211 | + desc->disable_val = info->disable_val; |
|---|
| 227 | 212 | |
|---|
| 228 | 213 | cfg.init_data = pbias_matches[idx].init_data; |
|---|
| 229 | | - cfg.driver_data = &drvdata[data_idx]; |
|---|
| 230 | 214 | cfg.of_node = pbias_matches[idx].of_node; |
|---|
| 231 | 215 | |
|---|
| 232 | | - drvdata[data_idx].dev = devm_regulator_register(&pdev->dev, |
|---|
| 233 | | - &drvdata[data_idx].desc, &cfg); |
|---|
| 234 | | - if (IS_ERR(drvdata[data_idx].dev)) { |
|---|
| 235 | | - ret = PTR_ERR(drvdata[data_idx].dev); |
|---|
| 216 | + rdev = devm_regulator_register(&pdev->dev, desc, &cfg); |
|---|
| 217 | + if (IS_ERR(rdev)) { |
|---|
| 218 | + ret = PTR_ERR(rdev); |
|---|
| 236 | 219 | dev_err(&pdev->dev, |
|---|
| 237 | 220 | "Failed to register regulator: %d\n", ret); |
|---|
| 238 | | - goto err_regulator; |
|---|
| 221 | + return ret; |
|---|
| 239 | 222 | } |
|---|
| 240 | | - data_idx++; |
|---|
| 223 | + desc++; |
|---|
| 224 | + count--; |
|---|
| 241 | 225 | } |
|---|
| 242 | 226 | |
|---|
| 243 | | - platform_set_drvdata(pdev, drvdata); |
|---|
| 244 | | - |
|---|
| 245 | | -err_regulator: |
|---|
| 246 | | - return ret; |
|---|
| 227 | + return 0; |
|---|
| 247 | 228 | } |
|---|
| 248 | 229 | |
|---|
| 249 | 230 | static struct platform_driver pbias_regulator_driver = { |
|---|