Lines Matching +full:isa +full:- +full:base

1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * lm78.c - Part of lm_sensors, Linux kernel modules for hardware
17 #include <linux/hwmon-vid.h>
18 #include <linux/hwmon-sysfs.h>
35 /* Length of ISA address segment */
38 /* Where are the ISA address/data registers relative to the base address */
90 return val == 0 ? -1 : val == 255 ? 0 : 1350000 / (val * div); in FAN_FROM_REG()
94 * TEMP: mC (-128C to +127C)
99 int nval = clamp_val(val, -128000, 127000) ; in TEMP_TO_REG()
100 return nval < 0 ? (nval - 500) / 1000 : (nval + 500) / 1000; in TEMP_TO_REG()
115 /* For ISA device only */
147 return sprintf(buf, "%d\n", IN_FROM_REG(data->in[attr->index])); in in_show()
155 return sprintf(buf, "%d\n", IN_FROM_REG(data->in_min[attr->index])); in in_min_show()
163 return sprintf(buf, "%d\n", IN_FROM_REG(data->in_max[attr->index])); in in_max_show()
171 int nr = attr->index; in in_min_store()
179 mutex_lock(&data->update_lock); in in_min_store()
180 data->in_min[nr] = IN_TO_REG(val); in in_min_store()
181 lm78_write_value(data, LM78_REG_IN_MIN(nr), data->in_min[nr]); in in_min_store()
182 mutex_unlock(&data->update_lock); in in_min_store()
191 int nr = attr->index; in in_max_store()
199 mutex_lock(&data->update_lock); in in_max_store()
200 data->in_max[nr] = IN_TO_REG(val); in in_max_store()
201 lm78_write_value(data, LM78_REG_IN_MAX(nr), data->in_max[nr]); in in_max_store()
202 mutex_unlock(&data->update_lock); in in_max_store()
233 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp)); in temp1_input_show()
240 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_over)); in temp1_max_show()
255 mutex_lock(&data->update_lock); in temp1_max_store()
256 data->temp_over = TEMP_TO_REG(val); in temp1_max_store()
257 lm78_write_value(data, LM78_REG_TEMP_OVER, data->temp_over); in temp1_max_store()
258 mutex_unlock(&data->update_lock); in temp1_max_store()
266 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_hyst)); in temp1_max_hyst_show()
281 mutex_lock(&data->update_lock); in temp1_max_hyst_store()
282 data->temp_hyst = TEMP_TO_REG(val); in temp1_max_hyst_store()
283 lm78_write_value(data, LM78_REG_TEMP_HYST, data->temp_hyst); in temp1_max_hyst_store()
284 mutex_unlock(&data->update_lock); in temp1_max_hyst_store()
298 int nr = attr->index; in fan_show()
299 return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan[nr], in fan_show()
300 DIV_FROM_REG(data->fan_div[nr]))); in fan_show()
308 int nr = attr->index; in fan_min_show()
309 return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan_min[nr], in fan_min_show()
310 DIV_FROM_REG(data->fan_div[nr]))); in fan_min_show()
318 int nr = attr->index; in fan_min_store()
326 mutex_lock(&data->update_lock); in fan_min_store()
327 data->fan_min[nr] = FAN_TO_REG(val, DIV_FROM_REG(data->fan_div[nr])); in fan_min_store()
328 lm78_write_value(data, LM78_REG_FAN_MIN(nr), data->fan_min[nr]); in fan_min_store()
329 mutex_unlock(&data->update_lock); in fan_min_store()
338 return sprintf(buf, "%d\n", DIV_FROM_REG(data->fan_div[attr->index])); in fan_div_show()
352 int nr = attr->index; in fan_div_store()
362 mutex_lock(&data->update_lock); in fan_div_store()
363 min = FAN_FROM_REG(data->fan_min[nr], in fan_div_store()
364 DIV_FROM_REG(data->fan_div[nr])); in fan_div_store()
368 data->fan_div[nr] = 0; in fan_div_store()
371 data->fan_div[nr] = 1; in fan_div_store()
374 data->fan_div[nr] = 2; in fan_div_store()
377 data->fan_div[nr] = 3; in fan_div_store()
383 mutex_unlock(&data->update_lock); in fan_div_store()
384 return -EINVAL; in fan_div_store()
390 reg = (reg & 0xcf) | (data->fan_div[nr] << 4); in fan_div_store()
393 reg = (reg & 0x3f) | (data->fan_div[nr] << 6); in fan_div_store()
398 data->fan_min[nr] = in fan_div_store()
399 FAN_TO_REG(min, DIV_FROM_REG(data->fan_div[nr])); in fan_div_store()
400 lm78_write_value(data, LM78_REG_FAN_MIN(nr), data->fan_min[nr]); in fan_div_store()
401 mutex_unlock(&data->update_lock); in fan_div_store()
423 return sprintf(buf, "%d\n", vid_from_reg(data->vid, 82)); in cpu0_vid_show()
432 return sprintf(buf, "%u\n", data->alarms); in alarms_show()
440 int nr = to_sensor_dev_attr(da)->index; in alarm_show()
441 return sprintf(buf, "%u\n", (data->alarms >> nr) & 1); in alarm_show()
509 * ISA related code
513 /* ISA device, if found */
523 /* Returns 1 if the I2C chip appears to be an alias of the ISA chip */
526 struct lm78_data *isa; in lm78_alias_detect() local
529 if (!pdev) /* No ISA chip */ in lm78_alias_detect()
531 isa = platform_get_drvdata(pdev); in lm78_alias_detect()
533 if (lm78_read_value(isa, LM78_REG_I2C_ADDR) != client->addr) in lm78_alias_detect()
535 if ((lm78_read_value(isa, LM78_REG_CHIPID) & 0xfe) != (chipid & 0xfe)) in lm78_alias_detect()
543 if (lm78_read_value(isa, i) != in lm78_alias_detect()
547 if (lm78_read_value(isa, LM78_REG_CONFIG) != in lm78_alias_detect()
551 if (lm78_read_value(isa, i) != in lm78_alias_detect()
575 struct lm78_data *isa = lm78_data_if_isa(); in lm78_i2c_detect() local
577 struct i2c_adapter *adapter = client->adapter; in lm78_i2c_detect()
578 int address = client->addr; in lm78_i2c_detect()
581 return -ENODEV; in lm78_i2c_detect()
584 * We block updates of the ISA device to minimize the risk of in lm78_i2c_detect()
588 if (isa) in lm78_i2c_detect()
589 mutex_lock(&isa->update_lock); in lm78_i2c_detect()
603 || i == 0x40) /* LM78-J */ in lm78_i2c_detect()
611 dev_dbg(&adapter->dev, in lm78_i2c_detect()
612 "Device at 0x%02x appears to be the same as ISA device\n", in lm78_i2c_detect()
617 if (isa) in lm78_i2c_detect()
618 mutex_unlock(&isa->update_lock); in lm78_i2c_detect()
620 strscpy(info->type, client_name, I2C_NAME_SIZE); in lm78_i2c_detect()
625 if (isa) in lm78_i2c_detect()
626 mutex_unlock(&isa->update_lock); in lm78_i2c_detect()
627 return -ENODEV; in lm78_i2c_detect()
634 struct device *dev = &client->dev; in lm78_i2c_probe()
640 return -ENOMEM; in lm78_i2c_probe()
642 data->client = client; in lm78_i2c_probe()
643 data->type = i2c_match_id(lm78_i2c_id, client)->driver_data; in lm78_i2c_probe()
648 hwmon_dev = devm_hwmon_device_register_with_groups(dev, client->name, in lm78_i2c_probe()
672 * The SMBus locks itself, but ISA access must be locked explicitly!
673 * We don't want to lock the whole ISA bus, so we lock each client
675 * We ignore the LM78 BUSY flag at this moment - it could lead to deadlocks,
680 struct i2c_client *client = data->client; in lm78_read_value()
683 if (!client) { /* ISA device */ in lm78_read_value()
685 mutex_lock(&data->lock); in lm78_read_value()
686 outb_p(reg, data->isa_addr + LM78_ADDR_REG_OFFSET); in lm78_read_value()
687 res = inb_p(data->isa_addr + LM78_DATA_REG_OFFSET); in lm78_read_value()
688 mutex_unlock(&data->lock); in lm78_read_value()
697 struct i2c_client *client = data->client; in lm78_write_value()
700 if (!client) { /* ISA device */ in lm78_write_value()
701 mutex_lock(&data->lock); in lm78_write_value()
702 outb_p(reg, data->isa_addr + LM78_ADDR_REG_OFFSET); in lm78_write_value()
703 outb_p(value, data->isa_addr + LM78_DATA_REG_OFFSET); in lm78_write_value()
704 mutex_unlock(&data->lock); in lm78_write_value()
724 data->fan_min[i] = lm78_read_value(data, in lm78_init_device()
728 mutex_init(&data->update_lock); in lm78_init_device()
736 mutex_lock(&data->update_lock); in lm78_update_device()
738 if (time_after(jiffies, data->last_updated + HZ + HZ / 2) in lm78_update_device()
739 || !data->valid) { in lm78_update_device()
744 data->in[i] = in lm78_update_device()
746 data->in_min[i] = in lm78_update_device()
748 data->in_max[i] = in lm78_update_device()
752 data->fan[i] = in lm78_update_device()
754 data->fan_min[i] = in lm78_update_device()
757 data->temp = lm78_read_value(data, LM78_REG_TEMP); in lm78_update_device()
758 data->temp_over = in lm78_update_device()
760 data->temp_hyst = in lm78_update_device()
763 data->vid = i & 0x0f; in lm78_update_device()
764 if (data->type == lm79) in lm78_update_device()
765 data->vid |= in lm78_update_device()
769 data->vid |= 0x10; in lm78_update_device()
770 data->fan_div[0] = (i >> 4) & 0x03; in lm78_update_device()
771 data->fan_div[1] = i >> 6; in lm78_update_device()
772 data->alarms = lm78_read_value(data, LM78_REG_ALARM1) + in lm78_update_device()
774 data->last_updated = jiffies; in lm78_update_device()
775 data->valid = true; in lm78_update_device()
777 data->fan_div[2] = 1; in lm78_update_device()
780 mutex_unlock(&data->update_lock); in lm78_update_device()
788 struct device *dev = &pdev->dev; in lm78_isa_probe()
793 /* Reserve the ISA region */ in lm78_isa_probe()
795 if (!devm_request_region(dev, res->start + LM78_ADDR_REG_OFFSET, in lm78_isa_probe()
797 return -EBUSY; in lm78_isa_probe()
801 return -ENOMEM; in lm78_isa_probe()
803 mutex_init(&data->lock); in lm78_isa_probe()
804 data->isa_addr = res->start; in lm78_isa_probe()
808 data->type = lm79; in lm78_isa_probe()
809 data->name = "lm79"; in lm78_isa_probe()
811 data->type = lm78; in lm78_isa_probe()
812 data->name = "lm78"; in lm78_isa_probe()
818 hwmon_dev = devm_hwmon_device_register_with_groups(dev, data->name, in lm78_isa_probe()
837 * Some boards declare base+0 to base+7 as a PNP device, some base+4 in lm78_isa_found()
838 * to base+7 and some base+5 to base+6. So we better request each port in lm78_isa_found()
850 * We need the timeouts for at least some LM78-like in lm78_isa_found()
904 || val == 0x40 /* LM78-J */ in lm78_isa_found()
913 for (port--; port >= address; port--) in lm78_isa_found()
922 .end = address + LM78_EXTENT - 1, in lm78_isa_device_add()
930 err = -ENOMEM; in lm78_isa_device_add()
1003 * We register the ISA device first, so that we can skip the in sm_lm78_init()