drivers/gnss/serial.c
Source file repositories/reference/linux-study-clean/drivers/gnss/serial.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/gnss/serial.c- Extension
.c- Size
- 6339 bytes
- Lines
- 277
- Domain
- Driver Families
- Bucket
- drivers/gnss
- 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.
- 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/errno.hlinux/gnss.hlinux/init.hlinux/kernel.hlinux/module.hlinux/of.hlinux/pm.hlinux/pm_runtime.hlinux/sched.hlinux/serdev.hlinux/slab.hserial.h
Detected Declarations
function Copyrightfunction gnss_serial_closefunction gnss_serial_write_rawfunction gnss_serial_receive_buffunction gnss_serial_set_powerfunction gnss_serial_parse_dtfunction gnss_serial_freefunction gnss_serial_registerfunction gnss_serial_deregisterfunction gnss_serial_runtime_suspendfunction gnss_serial_runtime_resumefunction gnss_serial_preparefunction gnss_serial_suspendfunction gnss_serial_resumeexport gnss_serial_allocateexport gnss_serial_freeexport gnss_serial_registerexport gnss_serial_deregisterexport gnss_serial_pm_ops
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0
/*
* Generic serial GNSS receiver driver
*
* Copyright (C) 2018 Johan Hovold <johan@kernel.org>
*/
#include <linux/errno.h>
#include <linux/gnss.h>
#include <linux/init.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/of.h>
#include <linux/pm.h>
#include <linux/pm_runtime.h>
#include <linux/sched.h>
#include <linux/serdev.h>
#include <linux/slab.h>
#include "serial.h"
static int gnss_serial_open(struct gnss_device *gdev)
{
struct gnss_serial *gserial = gnss_get_drvdata(gdev);
struct serdev_device *serdev = gserial->serdev;
int ret;
ret = serdev_device_open(serdev);
if (ret)
return ret;
serdev_device_set_baudrate(serdev, gserial->speed);
serdev_device_set_flow_control(serdev, false);
ret = pm_runtime_get_sync(&serdev->dev);
if (ret < 0) {
pm_runtime_put_noidle(&serdev->dev);
goto err_close;
}
return 0;
err_close:
serdev_device_close(serdev);
return ret;
}
static void gnss_serial_close(struct gnss_device *gdev)
{
struct gnss_serial *gserial = gnss_get_drvdata(gdev);
struct serdev_device *serdev = gserial->serdev;
serdev_device_close(serdev);
pm_runtime_put(&serdev->dev);
}
static int gnss_serial_write_raw(struct gnss_device *gdev,
const unsigned char *buf, size_t count)
{
struct gnss_serial *gserial = gnss_get_drvdata(gdev);
struct serdev_device *serdev = gserial->serdev;
int ret;
/* write is only buffered synchronously */
ret = serdev_device_write(serdev, buf, count, MAX_SCHEDULE_TIMEOUT);
if (ret < 0 || ret < count)
return ret;
/* FIXME: determine if interrupted? */
serdev_device_wait_until_sent(serdev, 0);
return count;
}
static const struct gnss_operations gnss_serial_gnss_ops = {
.open = gnss_serial_open,
.close = gnss_serial_close,
.write_raw = gnss_serial_write_raw,
};
static size_t gnss_serial_receive_buf(struct serdev_device *serdev,
const u8 *buf, size_t count)
{
struct gnss_serial *gserial = serdev_device_get_drvdata(serdev);
struct gnss_device *gdev = gserial->gdev;
return gnss_insert_raw(gdev, buf, count);
}
Annotation
- Immediate include surface: `linux/errno.h`, `linux/gnss.h`, `linux/init.h`, `linux/kernel.h`, `linux/module.h`, `linux/of.h`, `linux/pm.h`, `linux/pm_runtime.h`.
- Detected declarations: `function Copyright`, `function gnss_serial_close`, `function gnss_serial_write_raw`, `function gnss_serial_receive_buf`, `function gnss_serial_set_power`, `function gnss_serial_parse_dt`, `function gnss_serial_free`, `function gnss_serial_register`, `function gnss_serial_deregister`, `function gnss_serial_runtime_suspend`.
- Atlas domain: Driver Families / drivers/gnss.
- Implementation status: integration 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.