drivers/gpio/gpio-cs5535.c
Source file repositories/reference/linux-study-clean/drivers/gpio/gpio-cs5535.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/gpio/gpio-cs5535.c- Extension
.c- Size
- 9159 bytes
- Lines
- 361
- Domain
- Driver Families
- Bucket
- drivers/gpio
- Inferred role
- Driver Families: exported/initcall integration point
- Status
- integration 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.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- 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/kernel.hlinux/spinlock.hlinux/module.hlinux/platform_device.hlinux/gpio/driver.hlinux/io.hlinux/cs5535.hasm/msr.h
Detected Declarations
function errata_outlfunction __cs5535_gpio_setfunction cs5535_gpio_setfunction __cs5535_gpio_clearfunction cs5535_gpio_clearfunction cs5535_gpio_issetfunction cs5535_gpio_set_irqfunction cs5535_gpio_setup_eventfunction chip_gpio_requestfunction chip_gpio_getfunction chip_gpio_setfunction chip_direction_inputfunction chip_direction_outputfunction cs5535_gpio_probeexport cs5535_gpio_setexport cs5535_gpio_clearexport cs5535_gpio_issetexport cs5535_gpio_set_irqexport cs5535_gpio_setup_event
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0-only
/*
* AMD CS5535/CS5536 GPIO driver
* Copyright (C) 2006 Advanced Micro Devices, Inc.
* Copyright (C) 2007-2009 Andres Salomon <dilinger@collabora.co.uk>
*/
#include <linux/kernel.h>
#include <linux/spinlock.h>
#include <linux/module.h>
#include <linux/platform_device.h>
#include <linux/gpio/driver.h>
#include <linux/io.h>
#include <linux/cs5535.h>
#include <asm/msr.h>
#define DRV_NAME "cs5535-gpio"
/*
* Some GPIO pins
* 31-29,23 : reserved (always mask out)
* 28 : Power Button
* 26 : PME#
* 22-16 : LPC
* 14,15 : SMBus
* 9,8 : UART1
* 7 : PCI INTB
* 3,4 : UART2/DDC
* 2 : IDE_IRQ0
* 1 : AC_BEEP
* 0 : PCI INTA
*
* If a mask was not specified, allow all except
* reserved and Power Button
*/
#define GPIO_DEFAULT_MASK 0x0F7FFFFF
static ulong mask = GPIO_DEFAULT_MASK;
module_param_named(mask, mask, ulong, 0444);
MODULE_PARM_DESC(mask, "GPIO channel mask.");
static struct cs5535_gpio_chip {
struct gpio_chip chip;
resource_size_t base;
struct platform_device *pdev;
spinlock_t lock;
} cs5535_gpio_chip;
/*
* The CS5535/CS5536 GPIOs support a number of extra features not defined
* by the gpio_chip API, so these are exported. For a full list of the
* registers, see include/linux/cs5535.h.
*/
static void errata_outl(struct cs5535_gpio_chip *chip, u32 val,
unsigned int reg)
{
unsigned long addr = chip->base + 0x80 + reg;
/*
* According to the CS5536 errata (#36), after suspend
* a write to the high bank GPIO register will clear all
* non-selected bits; the recommended workaround is a
* read-modify-write operation.
*
* Don't apply this errata to the edge status GPIOs, as writing
* to their lower bits will clear them.
*/
if (reg != GPIO_POSITIVE_EDGE_STS && reg != GPIO_NEGATIVE_EDGE_STS) {
if (val & 0xffff)
val |= (inl(addr) & 0xffff); /* ignore the high bits */
else
val |= (inl(addr) ^ (val >> 16));
}
outl(val, addr);
}
static void __cs5535_gpio_set(struct cs5535_gpio_chip *chip, unsigned offset,
unsigned int reg)
{
if (offset < 16)
/* low bank register */
outl(1 << offset, chip->base + reg);
else
/* high bank register */
errata_outl(chip, 1 << (offset - 16), reg);
}
void cs5535_gpio_set(unsigned offset, unsigned int reg)
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/spinlock.h`, `linux/module.h`, `linux/platform_device.h`, `linux/gpio/driver.h`, `linux/io.h`, `linux/cs5535.h`, `asm/msr.h`.
- Detected declarations: `function errata_outl`, `function __cs5535_gpio_set`, `function cs5535_gpio_set`, `function __cs5535_gpio_clear`, `function cs5535_gpio_clear`, `function cs5535_gpio_isset`, `function cs5535_gpio_set_irq`, `function cs5535_gpio_setup_event`, `function chip_gpio_request`, `function chip_gpio_get`.
- Atlas domain: Driver Families / drivers/gpio.
- Implementation status: integration 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.