drivers/net/dsa/hirschmann/hellcreek_ptp.c
Source file repositories/reference/linux-study-clean/drivers/net/dsa/hirschmann/hellcreek_ptp.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/net/dsa/hirschmann/hellcreek_ptp.c- Extension
.c- Size
- 13522 bytes
- Lines
- 473
- Domain
- Driver Families
- Bucket
- drivers/net
- 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/of.hlinux/ptp_clock_kernel.hhellcreek.hhellcreek_ptp.hhellcreek_hwtstamp.h
Detected Declarations
function Copyrightfunction hellcreek_ptp_writefunction hellcreek_ptp_clock_readfunction __hellcreek_ptp_gettimefunction hellcreek_ptp_gettime_secondsfunction hellcreek_ptp_gettimexfunction hellcreek_ptp_settimefunction hellcreek_ptp_adjfinefunction hellcreek_ptp_adjtimefunction hellcreek_ptp_enablefunction hellcreek_ptp_overflow_checkfunction hellcreek_get_brightnessfunction hellcreek_set_brightnessfunction hellcreek_led_sync_good_setfunction hellcreek_led_sync_good_getfunction hellcreek_led_is_gm_setfunction hellcreek_led_is_gm_getfunction hellcreek_led_setupfunction hellcreek_ptp_setupfunction hellcreek_ptp_free
Annotated Snippet
// SPDX-License-Identifier: (GPL-2.0 OR MIT)
/*
* DSA driver for:
* Hirschmann Hellcreek TSN switch.
*
* Copyright (C) 2019,2020 Hochschule Offenburg
* Copyright (C) 2019,2020 Linutronix GmbH
* Authors: Kamil Alkhouri <kamil.alkhouri@hs-offenburg.de>
* Kurt Kanzenbach <kurt@linutronix.de>
*/
#include <linux/of.h>
#include <linux/ptp_clock_kernel.h>
#include "hellcreek.h"
#include "hellcreek_ptp.h"
#include "hellcreek_hwtstamp.h"
u16 hellcreek_ptp_read(struct hellcreek *hellcreek, unsigned int offset)
{
return readw(hellcreek->ptp_base + offset);
}
void hellcreek_ptp_write(struct hellcreek *hellcreek, u16 data,
unsigned int offset)
{
writew(data, hellcreek->ptp_base + offset);
}
/* Get nanoseconds from PTP clock */
static u64 hellcreek_ptp_clock_read(struct hellcreek *hellcreek,
struct ptp_system_timestamp *sts)
{
u16 nsl, nsh;
/* Take a snapshot */
hellcreek_ptp_write(hellcreek, PR_COMMAND_C_SS, PR_COMMAND_C);
/* The time of the day is saved as 96 bits. However, due to hardware
* limitations the seconds are not or only partly kept in the PTP
* core. Currently only three bits for the seconds are available. That's
* why only the nanoseconds are used and the seconds are tracked in
* software. Anyway due to internal locking all five registers should be
* read.
*/
nsh = hellcreek_ptp_read(hellcreek, PR_SS_SYNC_DATA_C);
nsh = hellcreek_ptp_read(hellcreek, PR_SS_SYNC_DATA_C);
nsh = hellcreek_ptp_read(hellcreek, PR_SS_SYNC_DATA_C);
nsh = hellcreek_ptp_read(hellcreek, PR_SS_SYNC_DATA_C);
ptp_read_system_prets(sts);
nsl = hellcreek_ptp_read(hellcreek, PR_SS_SYNC_DATA_C);
ptp_read_system_postts(sts);
return (u64)nsl | ((u64)nsh << 16);
}
static u64 __hellcreek_ptp_gettime(struct hellcreek *hellcreek,
struct ptp_system_timestamp *sts)
{
u64 ns;
ns = hellcreek_ptp_clock_read(hellcreek, sts);
if (ns < hellcreek->last_ts)
hellcreek->seconds++;
hellcreek->last_ts = ns;
ns += hellcreek->seconds * NSEC_PER_SEC;
return ns;
}
/* Retrieve the seconds parts in nanoseconds for a packet timestamped with @ns.
* There has to be a check whether an overflow occurred between the packet
* arrival and now. If so use the correct seconds (-1) for calculating the
* packet arrival time.
*/
u64 hellcreek_ptp_gettime_seconds(struct hellcreek *hellcreek, u64 ns)
{
u64 s;
__hellcreek_ptp_gettime(hellcreek, NULL);
if (hellcreek->last_ts > ns)
s = hellcreek->seconds * NSEC_PER_SEC;
else
s = (hellcreek->seconds - 1) * NSEC_PER_SEC;
return s;
}
static int hellcreek_ptp_gettimex(struct ptp_clock_info *ptp,
struct timespec64 *ts,
struct ptp_system_timestamp *sts)
Annotation
- Immediate include surface: `linux/of.h`, `linux/ptp_clock_kernel.h`, `hellcreek.h`, `hellcreek_ptp.h`, `hellcreek_hwtstamp.h`.
- Detected declarations: `function Copyright`, `function hellcreek_ptp_write`, `function hellcreek_ptp_clock_read`, `function __hellcreek_ptp_gettime`, `function hellcreek_ptp_gettime_seconds`, `function hellcreek_ptp_gettimex`, `function hellcreek_ptp_settime`, `function hellcreek_ptp_adjfine`, `function hellcreek_ptp_adjtime`, `function hellcreek_ptp_enable`.
- Atlas domain: Driver Families / drivers/net.
- 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.