drivers/misc/ti_fpc202.c
Source file repositories/reference/linux-study-clean/drivers/misc/ti_fpc202.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/misc/ti_fpc202.c- Extension
.c- Size
- 19285 bytes
- Lines
- 740
- 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.
- 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/cleanup.hlinux/device/devres.hlinux/err.hlinux/i2c.hlinux/i2c-atr.hlinux/gpio/consumer.hlinux/gpio/driver.hlinux/gpio/machine.hlinux/leds.hlinux/module.hlinux/math.hlinux/types.h
Detected Declarations
struct fpc202_ledstruct fpc202_privenum fpc202_led_modefunction fpc202_fill_alias_tablefunction fpc202_gpio_get_dirfunction fpc202_gpio_has_led_capsfunction fpc202_readfunction fpc202_writefunction fpc202_set_enablefunction fpc202_led_mode_writefunction fpc202_led_mode_setfunction fpc202_gpio_setfunction fpc202_gpio_getfunction fpc202_gpio_direction_inputfunction fpc202_gpio_direction_outputfunction fpc202_write_dev_addrfunction fpc202_attach_addrfunction fpc202_detach_addrfunction fpc202_led_blink_setfunction fpc202_led_brightness_getfunction fpc202_led_brightness_setfunction fpc202_register_ledfunction fpc202_register_ledsfunction for_each_child_of_node_scopedfunction fpc202_probe_portfunction fpc202_remove_portfunction fpc202_probefunction for_each_child_of_node_scopedfunction fpc202_remove
Annotated Snippet
struct fpc202_led {
int offset;
struct led_classdev led_cdev;
struct fpc202_priv *priv;
struct gpio_desc *gpio;
enum fpc202_led_mode mode;
};
struct fpc202_priv {
struct i2c_client *client;
struct i2c_atr *atr;
struct gpio_desc *en_gpio;
struct gpio_chip gpio;
struct fpc202_led leds[FPC202_LED_COUNT];
/* Lock REG_MOD/AUX_DEV and addr_caches during attach/detach */
struct mutex reg_dev_lock;
/* Lock LED mode select register during accesses */
struct mutex led_mode_lock;
/* Cached device addresses for both ports and their devices */
u8 addr_caches[2][2];
/* Keep track of which ports were probed */
DECLARE_BITMAP(probed_ports, FPC202_NUM_PORTS);
};
static void fpc202_fill_alias_table(struct i2c_client *client, u16 *aliases, int port_id)
{
u16 first_alias;
int i;
/*
* There is a predefined list of aliases for each FPC202 I2C
* self-address. This allows daisy-chained FPC202 units to
* automatically take on different sets of aliases.
* Each port of an FPC202 unit is assigned two aliases from this list.
*/
first_alias = 0x10 + 4 * port_id + 8 * ((u16)client->addr - 2);
for (i = 0; i < FPC202_ALIASES_PER_PORT; i++)
aliases[i] = first_alias + i;
}
static int fpc202_gpio_get_dir(int offset)
{
return offset < FPC202_GPIO_P0_S0_OUT_A ? GPIO_LINE_DIRECTION_IN : GPIO_LINE_DIRECTION_OUT;
}
static int fpc202_gpio_has_led_caps(int offset)
{
return offset >= FPC202_GPIO_P0_S0_OUT_C;
}
static int fpc202_read(struct fpc202_priv *priv, u8 reg)
{
int val;
val = i2c_smbus_read_byte_data(priv->client, reg);
return val;
}
static int fpc202_write(struct fpc202_priv *priv, u8 reg, u8 value)
{
return i2c_smbus_write_byte_data(priv->client, reg, value);
}
static void fpc202_set_enable(struct fpc202_priv *priv, int enable)
{
if (!priv->en_gpio)
return;
gpiod_set_value(priv->en_gpio, enable);
}
static int fpc202_led_mode_write(struct fpc202_priv *priv,
int offset,
enum fpc202_led_mode mode)
{
u8 val, reg = FPC202_REG_LED_MODE(offset);
int ret;
guard(mutex)(&priv->led_mode_lock);
ret = fpc202_read(priv, reg);
if (ret < 0) {
dev_err(&priv->client->dev, "failed to read LED mode %d! err %d\n",
offset, ret);
return ret;
Annotation
- Immediate include surface: `linux/cleanup.h`, `linux/device/devres.h`, `linux/err.h`, `linux/i2c.h`, `linux/i2c-atr.h`, `linux/gpio/consumer.h`, `linux/gpio/driver.h`, `linux/gpio/machine.h`.
- Detected declarations: `struct fpc202_led`, `struct fpc202_priv`, `enum fpc202_led_mode`, `function fpc202_fill_alias_table`, `function fpc202_gpio_get_dir`, `function fpc202_gpio_has_led_caps`, `function fpc202_read`, `function fpc202_write`, `function fpc202_set_enable`, `function fpc202_led_mode_write`.
- 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.