Lines Matching +full:group +full:- +full:index +full:- +full:bits
1 // SPDX-License-Identifier: GPL-2.0+
12 #include <linux/hwmon-sysfs.h>
23 * struct mlxreg_io_priv_data - driver's private data:
30 * @group: sysfs attribute group;
31 * @groups: list of sysfs attribute group for hwmon registration;
41 struct attribute_group group; member
53 ret = regmap_read(regmap, data->reg, regval); in mlxreg_io_get_reg()
59 * bits, bit sequence, bits in few registers For the first kind field in mlxreg_io_get_reg()
60 * mask indicates which bits are not related and field bit is set zero. in mlxreg_io_get_reg()
62 * with all bits one. No special handling for such kind of attributes - in mlxreg_io_get_reg()
64 * bits are related and the field bit is set to the first bit number in mlxreg_io_get_reg()
65 * (from 1 to 32) is the bit sequence. For the fourth kind - the number in mlxreg_io_get_reg()
67 * specified through 'data->regnum' field. in mlxreg_io_get_reg()
69 if (!data->bit) { in mlxreg_io_get_reg()
73 *regval = !!(*regval & ~data->mask); in mlxreg_io_get_reg()
76 *regval &= data->mask; in mlxreg_io_get_reg()
78 *regval |= ~data->mask; in mlxreg_io_get_reg()
80 } else if (data->mask) { in mlxreg_io_get_reg()
84 *regval = ror32(*regval & data->mask, (data->bit - 1)); in mlxreg_io_get_reg()
87 in_val = rol32(in_val, data->bit - 1) & data->mask; in mlxreg_io_get_reg()
88 /* Clear relevant bits and set them to new value. */ in mlxreg_io_get_reg()
89 *regval = (*regval & ~data->mask) | in_val; in mlxreg_io_get_reg()
95 * registers. Such attributes contain read-only data. in mlxreg_io_get_reg()
97 for (i = 1; i < data->regnum; i++) { in mlxreg_io_get_reg()
98 ret = regmap_read(regmap, data->reg + i, &val); in mlxreg_io_get_reg()
115 int index = to_sensor_dev_attr(attr)->index; in mlxreg_io_attr_show() local
116 struct mlxreg_core_data *data = priv->pdata->data + index; in mlxreg_io_attr_show()
120 mutex_lock(&priv->io_lock); in mlxreg_io_attr_show()
122 ret = mlxreg_io_get_reg(priv->pdata->regmap, data, 0, true, in mlxreg_io_attr_show()
123 priv->regsize, ®val); in mlxreg_io_attr_show()
127 mutex_unlock(&priv->io_lock); in mlxreg_io_attr_show()
132 mutex_unlock(&priv->io_lock); in mlxreg_io_attr_show()
141 int index = to_sensor_dev_attr(attr)->index; in mlxreg_io_attr_store() local
142 struct mlxreg_core_data *data = priv->pdata->data + index; in mlxreg_io_attr_store()
147 return -EINVAL; in mlxreg_io_attr_store()
154 mutex_lock(&priv->io_lock); in mlxreg_io_attr_store()
156 ret = mlxreg_io_get_reg(priv->pdata->regmap, data, input_val, false, in mlxreg_io_attr_store()
157 priv->regsize, ®val); in mlxreg_io_attr_store()
161 ret = regmap_write(priv->pdata->regmap, data->reg, regval); in mlxreg_io_attr_store()
165 mutex_unlock(&priv->io_lock); in mlxreg_io_attr_store()
170 mutex_unlock(&priv->io_lock); in mlxreg_io_attr_store()
171 dev_err(&priv->pdev->dev, "Bus access error\n"); in mlxreg_io_attr_store()
184 priv->group.attrs = devm_kcalloc(&priv->pdev->dev, in mlxreg_io_attr_init()
185 priv->pdata->counter, in mlxreg_io_attr_init()
188 if (!priv->group.attrs) in mlxreg_io_attr_init()
189 return -ENOMEM; in mlxreg_io_attr_init()
191 for (i = 0; i < priv->pdata->counter; i++) { in mlxreg_io_attr_init()
192 priv->mlxreg_io_attr[i] = in mlxreg_io_attr_init()
193 &priv->mlxreg_io_dev_attr[i].dev_attr.attr; in mlxreg_io_attr_init()
194 memcpy(&priv->mlxreg_io_dev_attr[i].dev_attr, in mlxreg_io_attr_init()
198 priv->mlxreg_io_attr[i]->name = in mlxreg_io_attr_init()
199 devm_kasprintf(&priv->pdev->dev, GFP_KERNEL, in mlxreg_io_attr_init()
200 priv->pdata->data[i].label); in mlxreg_io_attr_init()
202 if (!priv->mlxreg_io_attr[i]->name) { in mlxreg_io_attr_init()
203 dev_err(&priv->pdev->dev, "Memory allocation failed for sysfs attribute %d.\n", in mlxreg_io_attr_init()
205 return -ENOMEM; in mlxreg_io_attr_init()
208 priv->mlxreg_io_dev_attr[i].dev_attr.attr.mode = in mlxreg_io_attr_init()
209 priv->pdata->data[i].mode; in mlxreg_io_attr_init()
210 priv->mlxreg_io_dev_attr[i].dev_attr.attr.name = in mlxreg_io_attr_init()
211 priv->mlxreg_io_attr[i]->name; in mlxreg_io_attr_init()
212 priv->mlxreg_io_dev_attr[i].index = i; in mlxreg_io_attr_init()
213 sysfs_attr_init(&priv->mlxreg_io_dev_attr[i].dev_attr.attr); in mlxreg_io_attr_init()
216 priv->group.attrs = priv->mlxreg_io_attr; in mlxreg_io_attr_init()
217 priv->groups[0] = &priv->group; in mlxreg_io_attr_init()
218 priv->groups[1] = NULL; in mlxreg_io_attr_init()
228 priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); in mlxreg_io_probe()
230 return -ENOMEM; in mlxreg_io_probe()
232 priv->pdata = dev_get_platdata(&pdev->dev); in mlxreg_io_probe()
233 if (!priv->pdata) { in mlxreg_io_probe()
234 dev_err(&pdev->dev, "Failed to get platform data.\n"); in mlxreg_io_probe()
235 return -EINVAL; in mlxreg_io_probe()
238 priv->pdev = pdev; in mlxreg_io_probe()
239 priv->regsize = regmap_get_val_bytes(priv->pdata->regmap); in mlxreg_io_probe()
240 if (priv->regsize < 0) in mlxreg_io_probe()
241 return priv->regsize; in mlxreg_io_probe()
245 dev_err(&priv->pdev->dev, "Failed to allocate attributes: %d\n", in mlxreg_io_probe()
250 priv->hwmon = devm_hwmon_device_register_with_groups(&pdev->dev, in mlxreg_io_probe()
253 priv->groups); in mlxreg_io_probe()
254 if (IS_ERR(priv->hwmon)) { in mlxreg_io_probe()
255 dev_err(&pdev->dev, "Failed to register hwmon device %ld\n", in mlxreg_io_probe()
256 PTR_ERR(priv->hwmon)); in mlxreg_io_probe()
257 return PTR_ERR(priv->hwmon); in mlxreg_io_probe()
260 mutex_init(&priv->io_lock); in mlxreg_io_probe()
261 dev_set_drvdata(&pdev->dev, priv); in mlxreg_io_probe()
268 struct mlxreg_io_priv_data *priv = dev_get_drvdata(&pdev->dev); in mlxreg_io_remove()
270 mutex_destroy(&priv->io_lock); in mlxreg_io_remove()
275 .name = "mlxreg-io",
286 MODULE_ALIAS("platform:mlxreg-io");