drivers/gpio/gpio-cros-ec.c
Source file repositories/reference/linux-study-clean/drivers/gpio/gpio-cros-ec.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/gpio/gpio-cros-ec.c- Extension
.c- Size
- 5750 bytes
- Lines
- 215
- Domain
- Driver Families
- Bucket
- drivers/gpio
- 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/bitops.hlinux/device.hlinux/errno.hlinux/gpio/driver.hlinux/kernel.hlinux/mod_devicetable.hlinux/module.hlinux/platform_data/cros_ec_commands.hlinux/platform_data/cros_ec_proto.hlinux/platform_device.hlinux/property.hlinux/slab.h
Detected Declarations
function cros_ec_gpio_setfunction cros_ec_gpio_getfunction cros_ec_gpio_get_directionfunction cros_ec_gpio_init_namesfunction cros_ec_gpio_ngpiosfunction cros_ec_gpio_probe
Annotated Snippet
if (ret < 0) {
dev_err_probe(gc->parent, ret, "error getting gpio%d info\n", i);
return ret;
}
names[i] = str;
copied = scnprintf(str, name_len, "%s%s", cros_ec_gpio_prefix,
response.get_info.name);
if (copied < 0)
return copied;
str += copied + 1;
}
return 0;
}
/* Query EC for number of gpios */
static int cros_ec_gpio_ngpios(struct cros_ec_device *cros_ec)
{
struct ec_params_gpio_get_v1 params = {
.subcmd = EC_GPIO_GET_COUNT,
};
struct ec_response_gpio_get_v1 response;
int ret;
ret = cros_ec_cmd(cros_ec, 1, EC_CMD_GPIO_GET, ¶ms,
sizeof(params), &response, sizeof(response));
if (ret < 0)
return ret;
return response.get_count.val;
}
static int cros_ec_gpio_probe(struct platform_device *pdev)
{
struct device *dev = &pdev->dev;
struct device *parent = dev->parent;
struct cros_ec_dev *ec_dev = dev_get_drvdata(parent);
struct cros_ec_device *cros_ec = ec_dev->ec_dev;
struct gpio_chip *gc;
int ngpios;
int ret;
/* Use the fwnode from the protocol device, e.g. cros-ec-spi */
device_set_node(dev, dev_fwnode(cros_ec->dev));
ngpios = cros_ec_gpio_ngpios(cros_ec);
if (ngpios < 0) {
dev_err_probe(dev, ngpios, "error getting gpio count\n");
return ngpios;
}
gc = devm_kzalloc(dev, sizeof(*gc), GFP_KERNEL);
if (!gc)
return -ENOMEM;
gc->ngpio = ngpios;
gc->parent = dev;
ret = cros_ec_gpio_init_names(cros_ec, gc);
if (ret)
return ret;
gc->can_sleep = true;
gc->label = dev_name(dev);
gc->base = -1;
gc->set = cros_ec_gpio_set;
gc->get = cros_ec_gpio_get;
gc->get_direction = cros_ec_gpio_get_direction;
return devm_gpiochip_add_data(dev, gc, cros_ec);
}
static const struct platform_device_id cros_ec_gpio_id[] = {
{ .name = "cros-ec-gpio" },
{ }
};
MODULE_DEVICE_TABLE(platform, cros_ec_gpio_id);
static struct platform_driver cros_ec_gpio_driver = {
.probe = cros_ec_gpio_probe,
.driver = {
.name = "cros-ec-gpio",
},
.id_table = cros_ec_gpio_id,
};
module_platform_driver(cros_ec_gpio_driver);
MODULE_DESCRIPTION("ChromeOS EC GPIO Driver");
MODULE_LICENSE("GPL");
Annotation
- Immediate include surface: `linux/bitops.h`, `linux/device.h`, `linux/errno.h`, `linux/gpio/driver.h`, `linux/kernel.h`, `linux/mod_devicetable.h`, `linux/module.h`, `linux/platform_data/cros_ec_commands.h`.
- Detected declarations: `function cros_ec_gpio_set`, `function cros_ec_gpio_get`, `function cros_ec_gpio_get_direction`, `function cros_ec_gpio_init_names`, `function cros_ec_gpio_ngpios`, `function cros_ec_gpio_probe`.
- Atlas domain: Driver Families / drivers/gpio.
- 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.