drivers/hwmon/nct6775-i2c.c
Source file repositories/reference/linux-study-clean/drivers/hwmon/nct6775-i2c.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/hwmon/nct6775-i2c.c- Extension
.c- Size
- 6234 bytes
- Lines
- 188
- Domain
- Driver Families
- Bucket
- drivers/hwmon
- Inferred role
- Driver Families: implementation source
- Status
- source 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.
- 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.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/module.hlinux/init.hlinux/i2c.hlinux/hwmon.hlinux/hwmon-sysfs.hlinux/err.hlinux/of.hlinux/regmap.hnct6775.h
Detected Declarations
function Copyrightfunction nct6775_i2c_writefunction nct6775_i2c_probe_initfunction nct6775_i2c_probe
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0
/*
* nct6775-i2c - I2C driver for the hardware monitoring functionality of
* Nuvoton NCT677x Super-I/O chips
*
* Copyright (C) 2022 Zev Weiss <zev@bewilderbeest.net>
*
* This driver interacts with the chip via it's "back door" i2c interface, as
* is often exposed to a BMC. Because the host may still be operating the
* chip via the ("front door") LPC interface, this driver cannot assume that
* it actually has full control of the chip, and in particular must avoid
* making any changes that could confuse the host's LPC usage of it. It thus
* operates in a strictly read-only fashion, with the only exception being the
* bank-select register (which seems, thankfully, to be replicated for the i2c
* interface so it doesn't affect the LPC interface).
*/
#include <linux/module.h>
#include <linux/init.h>
#include <linux/i2c.h>
#include <linux/hwmon.h>
#include <linux/hwmon-sysfs.h>
#include <linux/err.h>
#include <linux/of.h>
#include <linux/regmap.h>
#include "nct6775.h"
static int nct6775_i2c_read(void *ctx, unsigned int reg, unsigned int *val)
{
int ret;
u32 tmp;
u8 bank = reg >> 8;
struct nct6775_data *data = ctx;
struct i2c_client *client = data->driver_data;
if (bank != data->bank) {
ret = i2c_smbus_write_byte_data(client, NCT6775_REG_BANK, bank);
if (ret)
return ret;
data->bank = bank;
}
ret = i2c_smbus_read_byte_data(client, reg & 0xff);
if (ret < 0)
return ret;
tmp = ret;
if (nct6775_reg_is_word_sized(data, reg)) {
ret = i2c_smbus_read_byte_data(client, (reg & 0xff) + 1);
if (ret < 0)
return ret;
tmp = (tmp << 8) | ret;
}
*val = tmp;
return 0;
}
/*
* The write operation is a dummy so as not to disturb anything being done
* with the chip via LPC.
*/
static int nct6775_i2c_write(void *ctx, unsigned int reg, unsigned int value)
{
struct nct6775_data *data = ctx;
struct i2c_client *client = data->driver_data;
dev_dbg(&client->dev, "skipping attempted write: %02x -> %03x\n", value, reg);
/*
* This is a lie, but writing anything but the bank-select register is
* something this driver shouldn't be doing.
*/
return 0;
}
static const struct of_device_id __maybe_unused nct6775_i2c_of_match[] = {
{ .compatible = "nuvoton,nct6106", .data = (void *)nct6106, },
{ .compatible = "nuvoton,nct6116", .data = (void *)nct6116, },
{ .compatible = "nuvoton,nct6775", .data = (void *)nct6775, },
{ .compatible = "nuvoton,nct6776", .data = (void *)nct6776, },
{ .compatible = "nuvoton,nct6779", .data = (void *)nct6779, },
{ .compatible = "nuvoton,nct6791", .data = (void *)nct6791, },
{ .compatible = "nuvoton,nct6792", .data = (void *)nct6792, },
{ .compatible = "nuvoton,nct6793", .data = (void *)nct6793, },
{ .compatible = "nuvoton,nct6795", .data = (void *)nct6795, },
{ .compatible = "nuvoton,nct6796", .data = (void *)nct6796, },
{ .compatible = "nuvoton,nct6797", .data = (void *)nct6797, },
{ .compatible = "nuvoton,nct6798", .data = (void *)nct6798, },
{ .compatible = "nuvoton,nct6799", .data = (void *)nct6799, },
Annotation
- Immediate include surface: `linux/module.h`, `linux/init.h`, `linux/i2c.h`, `linux/hwmon.h`, `linux/hwmon-sysfs.h`, `linux/err.h`, `linux/of.h`, `linux/regmap.h`.
- Detected declarations: `function Copyright`, `function nct6775_i2c_write`, `function nct6775_i2c_probe_init`, `function nct6775_i2c_probe`.
- Atlas domain: Driver Families / drivers/hwmon.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.