Lines Matching +full:convert +full:- +full:channels
1 // SPDX-License-Identifier: GPL-2.0-only
5 * Copyright (c) 2012 Savoir-faire Linux Inc.
21 #include <linux/hwmon-sysfs.h>
28 #define MAX197_NUM_CH 8 /* 8 Analog Input Channels */
40 * struct max197_data - device instance specific data
46 * @ctrl_bytes: Channels control byte.
59 data->ctrl_bytes[channel] &= ~MAX197_BIP; in max197_set_unipolarity()
64 data->ctrl_bytes[channel] |= MAX197_BIP; in max197_set_bipolarity()
69 data->ctrl_bytes[channel] &= ~MAX197_RNG; in max197_set_half_range()
74 data->ctrl_bytes[channel] |= MAX197_RNG; in max197_set_full_range()
79 return data->ctrl_bytes[channel] & MAX197_BIP; in max197_is_bipolar()
84 return data->ctrl_bytes[channel] & MAX197_RNG; in max197_is_full_range()
93 int channel = attr->index; in max197_show_range()
94 bool is_min = attr->nr; in max197_show_range()
97 if (mutex_lock_interruptible(&data->lock)) in max197_show_range()
98 return -ERESTARTSYS; in max197_show_range()
101 data->limit : data->limit / 2; in max197_show_range()
104 range = -range; in max197_show_range()
109 mutex_unlock(&data->lock); in max197_show_range()
121 int channel = attr->index; in max197_store_range()
122 bool is_min = attr->nr; in max197_store_range()
124 int half = data->limit / 2; in max197_store_range()
125 int full = data->limit; in max197_store_range()
128 return -EINVAL; in max197_store_range()
131 if (value <= -full) in max197_store_range()
132 value = -full; in max197_store_range()
134 value = -half; in max197_store_range()
144 if (mutex_lock_interruptible(&data->lock)) in max197_store_range()
145 return -ERESTARTSYS; in max197_store_range()
150 } else if (value == -half) { in max197_store_range()
153 } else if (value == -full) { in max197_store_range()
164 mutex_unlock(&data->lock); in max197_store_range()
176 int channel = attr->index; in max197_show_input()
180 if (mutex_lock_interruptible(&data->lock)) in max197_show_input()
181 return -ERESTARTSYS; in max197_show_input()
183 ret = data->pdata->convert(data->ctrl_bytes[channel]); in max197_show_input()
194 if (data->scale) { in max197_show_input()
204 mutex_unlock(&data->lock); in max197_show_input()
212 return sprintf(buf, "%s\n", pdev->name); in name_show()
262 struct max197_platform_data *pdata = dev_get_platdata(&pdev->dev); in max197_probe()
263 enum max197_chips chip = platform_get_device_id(pdev)->driver_data; in max197_probe()
266 dev_err(&pdev->dev, "no platform data supplied\n"); in max197_probe()
267 return -EINVAL; in max197_probe()
270 if (pdata->convert == NULL) { in max197_probe()
271 dev_err(&pdev->dev, "no convert function supplied\n"); in max197_probe()
272 return -EINVAL; in max197_probe()
275 data = devm_kzalloc(&pdev->dev, sizeof(struct max197_data), GFP_KERNEL); in max197_probe()
277 return -ENOMEM; in max197_probe()
279 data->pdata = pdata; in max197_probe()
280 mutex_init(&data->lock); in max197_probe()
283 data->limit = MAX197_LIMIT; in max197_probe()
284 data->scale = true; in max197_probe()
286 data->limit = MAX199_LIMIT; in max197_probe()
287 data->scale = false; in max197_probe()
291 data->ctrl_bytes[ch] = (u8) ch; in max197_probe()
295 ret = sysfs_create_group(&pdev->dev.kobj, &max197_sysfs_group); in max197_probe()
297 dev_err(&pdev->dev, "sysfs create group failed\n"); in max197_probe()
301 data->hwmon_dev = hwmon_device_register(&pdev->dev); in max197_probe()
302 if (IS_ERR(data->hwmon_dev)) { in max197_probe()
303 ret = PTR_ERR(data->hwmon_dev); in max197_probe()
304 dev_err(&pdev->dev, "hwmon device register failed\n"); in max197_probe()
311 sysfs_remove_group(&pdev->dev.kobj, &max197_sysfs_group); in max197_probe()
319 hwmon_device_unregister(data->hwmon_dev); in max197_remove()
320 sysfs_remove_group(&pdev->dev.kobj, &max197_sysfs_group); in max197_remove()
341 MODULE_AUTHOR("Savoir-faire Linux Inc. <kernel@savoirfairelinux.com>");