drivers/char/ds1620.c
Source file repositories/reference/linux-study-clean/drivers/char/ds1620.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/char/ds1620.c- Extension
.c- Size
- 8649 bytes
- Lines
- 425
- Domain
- Driver Families
- Bucket
- drivers/char
- 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.
- 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.
- Defines an operation table; this is where Linux turns generic core objects into subsystem-specific behavior.
- Touches user memory; correctness depends on fault-safe copying and privilege boundary handling.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/module.hlinux/miscdevice.hlinux/delay.hlinux/proc_fs.hlinux/seq_file.hlinux/capability.hlinux/init.hlinux/mutex.hmach/hardware.hasm/mach-types.hlinux/uaccess.hasm/therm.h
Detected Declarations
function netwinder_ds1620_set_clkfunction netwinder_ds1620_set_datafunction netwinder_ds1620_get_datafunction netwinder_ds1620_set_data_dirfunction netwinder_ds1620_resetfunction netwinder_lockfunction netwinder_unlockfunction netwinder_set_fanfunction netwinder_get_fanfunction ds1620_send_bitsfunction ds1620_recv_bitsfunction ds1620_outfunction ds1620_infunction cvt_9_to_intfunction ds1620_write_statefunction ds1620_read_statefunction ds1620_openfunction ds1620_readfunction ds1620_ioctlfunction ds1620_unlocked_ioctlfunction ds1620_proc_therm_showfunction ds1620_initfunction ds1620_exitmodule init ds1620_init
Annotated Snippet
static const struct file_operations ds1620_fops = {
.owner = THIS_MODULE,
.open = ds1620_open,
.read = ds1620_read,
.unlocked_ioctl = ds1620_unlocked_ioctl,
};
static struct miscdevice ds1620_miscdev = {
TEMP_MINOR,
"temp",
&ds1620_fops
};
static int __init ds1620_init(void)
{
int ret;
struct therm th, th_start;
if (!machine_is_netwinder())
return -ENODEV;
ds1620_out(THERM_RESET, 0, 0);
ds1620_out(THERM_WRITE_CONFIG, 8, CFG_CPU);
ds1620_out(THERM_START_CONVERT, 0, 0);
/*
* Trigger the fan to start by setting
* temperature high point low. This kicks
* the fan into action.
*/
ds1620_read_state(&th);
th_start.lo = 0;
th_start.hi = 1;
ds1620_write_state(&th_start);
msleep(2000);
ds1620_write_state(&th);
ret = misc_register(&ds1620_miscdev);
if (ret < 0)
return ret;
#ifdef THERM_USE_PROC
if (!proc_create_single("therm", 0, NULL, ds1620_proc_therm_show))
printk(KERN_ERR "therm: unable to register /proc/therm\n");
#endif
ds1620_read_state(&th);
ret = cvt_9_to_int(ds1620_in(THERM_READ_TEMP, 9));
printk(KERN_INFO "Thermostat: high %i.%i, low %i.%i, "
"current %i.%i C, fan %s.\n",
th.hi >> 1, th.hi & 1 ? 5 : 0,
th.lo >> 1, th.lo & 1 ? 5 : 0,
ret >> 1, ret & 1 ? 5 : 0,
fan_state[netwinder_get_fan()]);
return 0;
}
static void __exit ds1620_exit(void)
{
#ifdef THERM_USE_PROC
remove_proc_entry("therm", NULL);
#endif
misc_deregister(&ds1620_miscdev);
}
module_init(ds1620_init);
module_exit(ds1620_exit);
MODULE_DESCRIPTION("Dallas Semiconductor DS1620 thermometer driver");
MODULE_LICENSE("GPL");
Annotation
- Immediate include surface: `linux/module.h`, `linux/miscdevice.h`, `linux/delay.h`, `linux/proc_fs.h`, `linux/seq_file.h`, `linux/capability.h`, `linux/init.h`, `linux/mutex.h`.
- Detected declarations: `function netwinder_ds1620_set_clk`, `function netwinder_ds1620_set_data`, `function netwinder_ds1620_get_data`, `function netwinder_ds1620_set_data_dir`, `function netwinder_ds1620_reset`, `function netwinder_lock`, `function netwinder_unlock`, `function netwinder_set_fan`, `function netwinder_get_fan`, `function ds1620_send_bits`.
- Atlas domain: Driver Families / drivers/char.
- Implementation status: pattern implementation candidate.
- This snippet crosses the user/kernel memory boundary; validate fault handling and access checks before translating the pattern.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
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.