drivers/hwmon/w83793.c

Source file repositories/reference/linux-study-clean/drivers/hwmon/w83793.c

File Facts

System
Linux kernel
Corpus path
drivers/hwmon/w83793.c
Extension
.c
Size
60253 bytes
Lines
2144
Domain
Driver Families
Bucket
drivers/hwmon
Inferred role
Driver Families: operation-table or driver-model contract
Status
pattern implementation candidate

Why This File Exists

Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.

Dependency Surface

Detected Declarations

Annotated Snippet

static const struct file_operations watchdog_fops = {
	.owner = THIS_MODULE,
	.open = watchdog_open,
	.release = watchdog_close,
	.write = watchdog_write,
	.unlocked_ioctl = watchdog_ioctl,
	.compat_ioctl = compat_ptr_ioctl,
};

/*
 *	Notifier for system down
 */

static int watchdog_notify_sys(struct notifier_block *this, unsigned long code,
			       void *unused)
{
	struct w83793_data *data = NULL;

	if (code == SYS_DOWN || code == SYS_HALT) {

		/* Disable each registered watchdog */
		mutex_lock(&watchdog_data_mutex);
		list_for_each_entry(data, &watchdog_data_list, list) {
			if (data->watchdog_miscdev.minor)
				watchdog_disable(data);
		}
		mutex_unlock(&watchdog_data_mutex);
	}

	return NOTIFY_DONE;
}

/*
 *	The WDT needs to learn about soft shutdowns in order to
 *	turn the timebomb registers off.
 */

static struct notifier_block watchdog_notifier = {
	.notifier_call = watchdog_notify_sys,
};

/*
 * Init / remove routines
 */

static void w83793_remove(struct i2c_client *client)
{
	struct w83793_data *data = i2c_get_clientdata(client);
	struct device *dev = &client->dev;
	int i, tmp;

	/* Unregister the watchdog (if registered) */
	if (data->watchdog_miscdev.minor) {
		misc_deregister(&data->watchdog_miscdev);

		if (data->watchdog_is_open) {
			dev_warn(&client->dev,
				"i2c client detached with watchdog open! "
				"Stopping watchdog.\n");
			watchdog_disable(data);
		}

		mutex_lock(&watchdog_data_mutex);
		list_del(&data->list);
		mutex_unlock(&watchdog_data_mutex);

		/* Tell the watchdog code the client is gone */
		mutex_lock(&data->watchdog_lock);
		data->client = NULL;
		mutex_unlock(&data->watchdog_lock);
	}

	/* Reset Configuration Register to Disable Watch Dog Registers */
	tmp = w83793_read_value(client, W83793_REG_CONFIG);
	w83793_write_value(client, W83793_REG_CONFIG, tmp & ~0x04);

	unregister_reboot_notifier(&watchdog_notifier);

	hwmon_device_unregister(data->hwmon_dev);

	for (i = 0; i < ARRAY_SIZE(w83793_sensor_attr_2); i++)
		device_remove_file(dev,
				   &w83793_sensor_attr_2[i].dev_attr);

	for (i = 0; i < ARRAY_SIZE(sda_single_files); i++)
		device_remove_file(dev, &sda_single_files[i].dev_attr);

	for (i = 0; i < ARRAY_SIZE(w83793_vid); i++)
		device_remove_file(dev, &w83793_vid[i].dev_attr);
	device_remove_file(dev, &dev_attr_vrm);

Annotation

Implementation Notes