Lines Matching +full:done +full:- +full:gpios

1 // SPDX-License-Identifier: GPL-2.0-only
21 #include <linux/hwmon-sysfs.h>
66 int gpios[3]; member
71 * sample all GPIO's as analog voltages, a round-robin sampling method is used.
74 * LOCKING: must hold data->update_lock
79 struct i2c_client *client = data->client; in ltc4245_update_gpios()
83 /* no extra gpio support, we're basically done */ in ltc4245_update_gpios()
84 if (!data->use_extra_gpios) { in ltc4245_update_gpios()
85 data->gpios[0] = data->vregs[LTC4245_GPIOADC - 0x10]; in ltc4245_update_gpios()
91 * readings as stale by setting them to -EAGAIN in ltc4245_update_gpios()
93 if (time_after(jiffies, data->last_updated + 5 * HZ)) { in ltc4245_update_gpios()
94 for (i = 0; i < ARRAY_SIZE(data->gpios); i++) in ltc4245_update_gpios()
95 data->gpios[i] = -EAGAIN; in ltc4245_update_gpios()
101 * The datasheet calls these GPIO[1-3], but we'll calculate the zero in ltc4245_update_gpios()
102 * based array index instead, and call them GPIO[0-2]. This is much in ltc4245_update_gpios()
105 gpio_curr = (data->cregs[LTC4245_GPIO] & 0xc0) >> 6; in ltc4245_update_gpios()
107 gpio_curr -= 1; in ltc4245_update_gpios()
110 data->gpios[gpio_curr] = data->vregs[LTC4245_GPIOADC - 0x10]; in ltc4245_update_gpios()
113 gpio_next = (gpio_curr + 1) % ARRAY_SIZE(data->gpios); in ltc4245_update_gpios()
119 gpio_reg = (data->cregs[LTC4245_GPIO] & 0x3f) | ((gpio_next + 1) << 6); in ltc4245_update_gpios()
125 data->cregs[LTC4245_GPIO] = gpio_reg; in ltc4245_update_gpios()
131 struct i2c_client *client = data->client; in ltc4245_update_device()
135 mutex_lock(&data->update_lock); in ltc4245_update_device()
137 if (time_after(jiffies, data->last_updated + HZ) || !data->valid) { in ltc4245_update_device()
139 /* Read control registers -- 0x00 to 0x07 */ in ltc4245_update_device()
140 for (i = 0; i < ARRAY_SIZE(data->cregs); i++) { in ltc4245_update_device()
143 data->cregs[i] = 0; in ltc4245_update_device()
145 data->cregs[i] = val; in ltc4245_update_device()
148 /* Read voltage registers -- 0x10 to 0x1c */ in ltc4245_update_device()
149 for (i = 0; i < ARRAY_SIZE(data->vregs); i++) { in ltc4245_update_device()
152 data->vregs[i] = 0; in ltc4245_update_device()
154 data->vregs[i] = val; in ltc4245_update_device()
160 data->last_updated = jiffies; in ltc4245_update_device()
161 data->valid = true; in ltc4245_update_device()
164 mutex_unlock(&data->update_lock); in ltc4245_update_device()
173 const u8 regval = data->vregs[reg - 0x10]; in ltc4245_get_voltage()
191 voltage = regval * -55; in ltc4245_get_voltage()
209 const u8 regval = data->vregs[reg - 0x10]; in ltc4245_get_current()
214 * The strange looking conversions that follow are fixed-point in ltc4245_get_current()
278 *val = !!(data->cregs[LTC4245_FAULT1] & BIT(channel + 4)); in ltc4245_read_curr()
281 return -EOPNOTSUPP; in ltc4245_read_curr()
295 int regval = data->gpios[channel - 8]; in ltc4245_read_in()
304 *val = !!(data->cregs[LTC4245_FAULT1] & BIT(channel)); in ltc4245_read_in()
306 *val = !!(data->cregs[LTC4245_FAULT2] & in ltc4245_read_in()
307 BIT(channel - 4)); in ltc4245_read_in()
310 return -EOPNOTSUPP; in ltc4245_read_in()
328 return -EOPNOTSUPP; in ltc4245_read_power()
342 return ltc4245_read_in(dev, attr, channel - 1, val); in ltc4245_read()
344 return -EOPNOTSUPP; in ltc4245_read()
360 if (channel > 9 && !data->use_extra_gpios) in ltc4245_is_visible()
429 struct ltc4245_platform_data *pdata = dev_get_platdata(&client->dev); in ltc4245_use_extra_gpios()
430 struct device_node *np = client->dev.of_node; in ltc4245_use_extra_gpios()
434 return pdata->use_extra_gpios; in ltc4245_use_extra_gpios()
437 if (of_property_read_bool(np, "ltc4245,use-extra-gpios")) in ltc4245_use_extra_gpios()
445 struct i2c_adapter *adapter = client->adapter; in ltc4245_probe()
450 return -ENODEV; in ltc4245_probe()
452 data = devm_kzalloc(&client->dev, sizeof(*data), GFP_KERNEL); in ltc4245_probe()
454 return -ENOMEM; in ltc4245_probe()
456 data->client = client; in ltc4245_probe()
457 mutex_init(&data->update_lock); in ltc4245_probe()
458 data->use_extra_gpios = ltc4245_use_extra_gpios(client); in ltc4245_probe()
464 hwmon_dev = devm_hwmon_device_register_with_info(&client->dev, in ltc4245_probe()
465 client->name, data, in ltc4245_probe()