drivers/misc/isl29020.c
Source file repositories/reference/linux-study-clean/drivers/misc/isl29020.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/misc/isl29020.c- Extension
.c- Size
- 5031 bytes
- Lines
- 227
- Domain
- Driver Families
- Bucket
- drivers/misc
- 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.
- 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/slab.hlinux/i2c.hlinux/err.hlinux/delay.hlinux/sysfs.hlinux/pm_runtime.h
Detected Declarations
function als_sensing_range_showfunction als_lux_input_data_showfunction als_sensing_range_storefunction als_set_power_statefunction als_set_default_configfunction isl29020_probefunction isl29020_removefunction isl29020_runtime_suspendfunction isl29020_runtime_resume
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0-only
/*
* isl29020.c - Intersil ALS Driver
*
* Copyright (C) 2008 Intel Corp
*
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*
* Data sheet at: http://www.intersil.com/data/fn/fn6505.pdf
*/
#include <linux/module.h>
#include <linux/slab.h>
#include <linux/i2c.h>
#include <linux/err.h>
#include <linux/delay.h>
#include <linux/sysfs.h>
#include <linux/pm_runtime.h>
static DEFINE_MUTEX(mutex);
static ssize_t als_sensing_range_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
struct i2c_client *client = to_i2c_client(dev);
int val;
val = i2c_smbus_read_byte_data(client, 0x00);
if (val < 0)
return val;
return sprintf(buf, "%d000\n", 1 << (2 * (val & 3)));
}
static ssize_t als_lux_input_data_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
struct i2c_client *client = to_i2c_client(dev);
int ret_val, val;
unsigned long int lux;
int temp;
pm_runtime_get_sync(dev);
msleep(100);
mutex_lock(&mutex);
temp = i2c_smbus_read_byte_data(client, 0x02); /* MSB data */
if (temp < 0) {
pm_runtime_put_sync(dev);
mutex_unlock(&mutex);
return temp;
}
ret_val = i2c_smbus_read_byte_data(client, 0x01); /* LSB data */
mutex_unlock(&mutex);
if (ret_val < 0) {
pm_runtime_put_sync(dev);
return ret_val;
}
ret_val |= temp << 8;
val = i2c_smbus_read_byte_data(client, 0x00);
pm_runtime_put_sync(dev);
if (val < 0)
return val;
lux = ((((1 << (2 * (val & 3))))*1000) * ret_val) / 65536;
return sprintf(buf, "%lu\n", lux);
}
static ssize_t als_sensing_range_store(struct device *dev,
struct device_attribute *attr, const char *buf, size_t count)
{
struct i2c_client *client = to_i2c_client(dev);
int ret_val;
unsigned long val;
ret_val = kstrtoul(buf, 10, &val);
if (ret_val)
return ret_val;
if (val < 1 || val > 64000)
return -EINVAL;
/* Pick the smallest sensor range that will meet our requirements */
if (val <= 1000)
val = 1;
Annotation
- Immediate include surface: `linux/module.h`, `linux/slab.h`, `linux/i2c.h`, `linux/err.h`, `linux/delay.h`, `linux/sysfs.h`, `linux/pm_runtime.h`.
- Detected declarations: `function als_sensing_range_show`, `function als_lux_input_data_show`, `function als_sensing_range_store`, `function als_set_power_state`, `function als_set_default_config`, `function isl29020_probe`, `function isl29020_remove`, `function isl29020_runtime_suspend`, `function isl29020_runtime_resume`.
- Atlas domain: Driver Families / drivers/misc.
- Implementation status: source implementation candidate.
- 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.