| .. | .. |
|---|
| 1 | | -/* |
|---|
| 2 | | - * Device driver for regulators in Hi655x IC |
|---|
| 3 | | - * |
|---|
| 4 | | - * Copyright (c) 2016 Hisilicon. |
|---|
| 5 | | - * |
|---|
| 6 | | - * Authors: |
|---|
| 7 | | - * Chen Feng <puck.chen@hisilicon.com> |
|---|
| 8 | | - * Fei Wang <w.f@huawei.com> |
|---|
| 9 | | - * |
|---|
| 10 | | - * This program is free software; you can redistribute it and/or modify |
|---|
| 11 | | - * it under the terms of the GNU General Public License version 2 as |
|---|
| 12 | | - * published by the Free Software Foundation. |
|---|
| 13 | | - */ |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0 |
|---|
| 2 | +// |
|---|
| 3 | +// Device driver for regulators in Hi655x IC |
|---|
| 4 | +// |
|---|
| 5 | +// Copyright (c) 2016 Hisilicon. |
|---|
| 6 | +// |
|---|
| 7 | +// Authors: |
|---|
| 8 | +// Chen Feng <puck.chen@hisilicon.com> |
|---|
| 9 | +// Fei Wang <w.f@huawei.com> |
|---|
| 14 | 10 | |
|---|
| 15 | 11 | #include <linux/bitops.h> |
|---|
| 16 | 12 | #include <linux/device.h> |
|---|
| .. | .. |
|---|
| 28 | 24 | struct hi655x_regulator { |
|---|
| 29 | 25 | unsigned int disable_reg; |
|---|
| 30 | 26 | unsigned int status_reg; |
|---|
| 31 | | - unsigned int ctrl_regs; |
|---|
| 32 | | - unsigned int ctrl_mask; |
|---|
| 33 | 27 | struct regulator_desc rdesc; |
|---|
| 34 | 28 | }; |
|---|
| 35 | 29 | |
|---|
| .. | .. |
|---|
| 78 | 72 | static int hi655x_is_enabled(struct regulator_dev *rdev) |
|---|
| 79 | 73 | { |
|---|
| 80 | 74 | unsigned int value = 0; |
|---|
| 81 | | - |
|---|
| 82 | | - struct hi655x_regulator *regulator = rdev_get_drvdata(rdev); |
|---|
| 75 | + const struct hi655x_regulator *regulator = rdev_get_drvdata(rdev); |
|---|
| 83 | 76 | |
|---|
| 84 | 77 | regmap_read(rdev->regmap, regulator->status_reg, &value); |
|---|
| 85 | | - return (value & BIT(regulator->ctrl_mask)); |
|---|
| 78 | + return (value & rdev->desc->enable_mask); |
|---|
| 86 | 79 | } |
|---|
| 87 | 80 | |
|---|
| 88 | 81 | static int hi655x_disable(struct regulator_dev *rdev) |
|---|
| 89 | 82 | { |
|---|
| 90 | | - int ret = 0; |
|---|
| 83 | + const struct hi655x_regulator *regulator = rdev_get_drvdata(rdev); |
|---|
| 91 | 84 | |
|---|
| 92 | | - struct hi655x_regulator *regulator = rdev_get_drvdata(rdev); |
|---|
| 93 | | - |
|---|
| 94 | | - ret = regmap_write(rdev->regmap, regulator->disable_reg, |
|---|
| 95 | | - BIT(regulator->ctrl_mask)); |
|---|
| 96 | | - return ret; |
|---|
| 85 | + return regmap_write(rdev->regmap, regulator->disable_reg, |
|---|
| 86 | + rdev->desc->enable_mask); |
|---|
| 97 | 87 | } |
|---|
| 98 | 88 | |
|---|
| 99 | 89 | static const struct regulator_ops hi655x_regulator_ops = { |
|---|
| .. | .. |
|---|
| 133 | 123 | }, \ |
|---|
| 134 | 124 | .disable_reg = HI655X_BUS_ADDR(dreg), \ |
|---|
| 135 | 125 | .status_reg = HI655X_BUS_ADDR(sreg), \ |
|---|
| 136 | | - .ctrl_mask = cmask, \ |
|---|
| 137 | 126 | } |
|---|
| 138 | 127 | |
|---|
| 139 | 128 | #define HI655X_LDO_LINEAR(_ID, vreg, vmask, ereg, dreg, \ |
|---|
| .. | .. |
|---|
| 156 | 145 | }, \ |
|---|
| 157 | 146 | .disable_reg = HI655X_BUS_ADDR(dreg), \ |
|---|
| 158 | 147 | .status_reg = HI655X_BUS_ADDR(sreg), \ |
|---|
| 159 | | - .ctrl_mask = cmask, \ |
|---|
| 160 | 148 | } |
|---|
| 161 | 149 | |
|---|
| 162 | | -static struct hi655x_regulator regulators[] = { |
|---|
| 150 | +static const struct hi655x_regulator regulators[] = { |
|---|
| 163 | 151 | HI655X_LDO_LINEAR(LDO2, 0x72, 0x07, 0x29, 0x2a, 0x2b, 0x01, |
|---|
| 164 | 152 | 2500000, 8, 100000), |
|---|
| 165 | 153 | HI655X_LDO(LDO7, 0x78, 0x07, 0x29, 0x2a, 0x2b, 0x06, ldo7_voltages), |
|---|
| .. | .. |
|---|
| 181 | 169 | static int hi655x_regulator_probe(struct platform_device *pdev) |
|---|
| 182 | 170 | { |
|---|
| 183 | 171 | unsigned int i; |
|---|
| 184 | | - struct hi655x_regulator *regulator; |
|---|
| 185 | 172 | struct hi655x_pmic *pmic; |
|---|
| 186 | 173 | struct regulator_config config = { }; |
|---|
| 187 | 174 | struct regulator_dev *rdev; |
|---|
| .. | .. |
|---|
| 192 | 179 | return -ENODEV; |
|---|
| 193 | 180 | } |
|---|
| 194 | 181 | |
|---|
| 195 | | - regulator = devm_kzalloc(&pdev->dev, sizeof(*regulator), GFP_KERNEL); |
|---|
| 196 | | - if (!regulator) |
|---|
| 197 | | - return -ENOMEM; |
|---|
| 198 | | - |
|---|
| 199 | | - platform_set_drvdata(pdev, regulator); |
|---|
| 200 | | - |
|---|
| 201 | 182 | config.dev = pdev->dev.parent; |
|---|
| 202 | 183 | config.regmap = pmic->regmap; |
|---|
| 203 | | - config.driver_data = regulator; |
|---|
| 204 | 184 | for (i = 0; i < ARRAY_SIZE(regulators); i++) { |
|---|
| 185 | + config.driver_data = (void *) ®ulators[i]; |
|---|
| 186 | + |
|---|
| 205 | 187 | rdev = devm_regulator_register(&pdev->dev, |
|---|
| 206 | 188 | ®ulators[i].rdesc, |
|---|
| 207 | 189 | &config); |
|---|
| 208 | 190 | if (IS_ERR(rdev)) { |
|---|
| 209 | 191 | dev_err(&pdev->dev, "failed to register regulator %s\n", |
|---|
| 210 | | - regulator->rdesc.name); |
|---|
| 192 | + regulators[i].rdesc.name); |
|---|
| 211 | 193 | return PTR_ERR(rdev); |
|---|
| 212 | 194 | } |
|---|
| 213 | 195 | } |
|---|