mirror of
git://nv-tegra.nvidia.com/linux-nv-oot.git
synced 2025-12-22 09:11:26 +03:00
nvidia-oot: add nvpps and ptp driver
Using this patch we are adding support for ptp and nvpps driver in oot kernel. JIRA ESLC-6885 Signed-off-by: Manish Bhardwaj <mbhardwaj@nvidia.com> Change-Id: Id47ac5602d11ce417f9d421b4f672578922ca94f Reviewed-on: https://git-master.nvidia.com/r/c/linux-nv-oot/+/2785318 Reviewed-by: Bitan Biswas <bbiswas@nvidia.com> Reviewed-by: David Tao <tehyut@nvidia.com> GVS: Gerrit_Virtual_Submit <buildbot_gerritrpt@nvidia.com>
This commit is contained in:
committed by
mobile promotions
parent
77001d121e
commit
a2fdb986b0
@@ -14,6 +14,7 @@ obj-m += i2c/busses/
|
|||||||
obj-m += mfd/
|
obj-m += mfd/
|
||||||
obj-m += misc/
|
obj-m += misc/
|
||||||
obj-m += net/
|
obj-m += net/
|
||||||
|
obj-m += nvpps/
|
||||||
obj-m += pci/
|
obj-m += pci/
|
||||||
obj-m += pinctrl/
|
obj-m += pinctrl/
|
||||||
obj-m += platform/tegra/
|
obj-m += platform/tegra/
|
||||||
|
|||||||
10
drivers/nvpps/Makefile
Normal file
10
drivers/nvpps/Makefile
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
# SPDX-FileCopyrightText: Copyright (c) 2022 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
||||||
|
# SPDX-License-Identifier: GPL-2.0-only
|
||||||
|
|
||||||
|
#
|
||||||
|
# NVPPS driver and PTP Framework.
|
||||||
|
#
|
||||||
|
|
||||||
|
obj-m += nvpps.o
|
||||||
|
nvpps-y += ../platform/tegra/ptp-notifier.o
|
||||||
|
nvpps-y += nvpps_main.o
|
||||||
1214
drivers/nvpps/nvpps_main.c
Normal file
1214
drivers/nvpps/nvpps_main.c
Normal file
File diff suppressed because it is too large
Load Diff
137
drivers/platform/tegra/ptp-notifier.c
Normal file
137
drivers/platform/tegra/ptp-notifier.c
Normal file
@@ -0,0 +1,137 @@
|
|||||||
|
/* SPDX-License-Identifier: GPL-2.0-only */
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2022, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <linux/notifier.h>
|
||||||
|
#include <linux/module.h>
|
||||||
|
#include <linux/platform/tegra/ptp-notifier.h>
|
||||||
|
|
||||||
|
static int (*get_systime[MAX_MAC_INSTANCES])(struct net_device *, void *, int);
|
||||||
|
static struct net_device *registered_ndev[MAX_MAC_INSTANCES];
|
||||||
|
static DEFINE_RAW_SPINLOCK(ptp_notifier_lock);
|
||||||
|
static ATOMIC_NOTIFIER_HEAD(tegra_hwtime_chain_head);
|
||||||
|
|
||||||
|
/* Clients register for notification of hwtime change events */
|
||||||
|
int tegra_register_hwtime_notifier(struct notifier_block *nb)
|
||||||
|
{
|
||||||
|
return atomic_notifier_chain_register(&tegra_hwtime_chain_head, nb);
|
||||||
|
}
|
||||||
|
EXPORT_SYMBOL(tegra_register_hwtime_notifier);
|
||||||
|
|
||||||
|
/* Clients unregister for notification of hwtime change events */
|
||||||
|
int tegra_unregister_hwtime_notifier(struct notifier_block *nb)
|
||||||
|
{
|
||||||
|
return atomic_notifier_chain_unregister(&tegra_hwtime_chain_head, nb);
|
||||||
|
}
|
||||||
|
EXPORT_SYMBOL(tegra_unregister_hwtime_notifier);
|
||||||
|
|
||||||
|
/* Trigger notification of hwtime change to all registered clients */
|
||||||
|
int tegra_hwtime_notifier_call_chain(unsigned int val, void *v)
|
||||||
|
{
|
||||||
|
int ret = atomic_notifier_call_chain(&tegra_hwtime_chain_head, val, v);
|
||||||
|
|
||||||
|
return notifier_to_errno(ret);
|
||||||
|
}
|
||||||
|
|
||||||
|
void tegra_register_hwtime_source(int (*func)(struct net_device *, void *, int),
|
||||||
|
struct net_device *ndev)
|
||||||
|
{
|
||||||
|
unsigned long flags;
|
||||||
|
int index = 0;
|
||||||
|
|
||||||
|
for (index = 0; index < MAX_MAC_INSTANCES; index++) {
|
||||||
|
if (registered_ndev[index] == ndev) {
|
||||||
|
pr_debug("source is already registered for this intf\n");
|
||||||
|
/* Didn't call the notifier as we are not using
|
||||||
|
* tegra_register_hwtime_notifier anywhere
|
||||||
|
*/
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
raw_spin_lock_irqsave(&ptp_notifier_lock, flags);
|
||||||
|
for (index = 0; index < MAX_MAC_INSTANCES; index++) {
|
||||||
|
if (get_systime[index] == NULL) {
|
||||||
|
get_systime[index] = func;
|
||||||
|
registered_ndev[index] = ndev;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (index == MAX_MAC_INSTANCES)
|
||||||
|
pr_err("Maximum registrations reached\n");
|
||||||
|
|
||||||
|
raw_spin_unlock_irqrestore(&ptp_notifier_lock, flags);
|
||||||
|
|
||||||
|
/* Notify HW time stamp update to registered clients.
|
||||||
|
* NULL callback parameter. We use a separate timestamp
|
||||||
|
* function to peek MAC time.
|
||||||
|
*/
|
||||||
|
tegra_hwtime_notifier_call_chain(0, NULL);
|
||||||
|
}
|
||||||
|
EXPORT_SYMBOL(tegra_register_hwtime_source);
|
||||||
|
|
||||||
|
void tegra_unregister_hwtime_source(struct net_device *dev)
|
||||||
|
{
|
||||||
|
unsigned long flags;
|
||||||
|
int index = 0;
|
||||||
|
|
||||||
|
raw_spin_lock_irqsave(&ptp_notifier_lock, flags);
|
||||||
|
for (index = 0; index < MAX_MAC_INSTANCES; index++) {
|
||||||
|
if (dev == registered_ndev[index])
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (index == MAX_MAC_INSTANCES) {
|
||||||
|
pr_debug("Trying to unregister non-registered hwtime source");
|
||||||
|
raw_spin_unlock_irqrestore(&ptp_notifier_lock, flags);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
get_systime[index] = NULL;
|
||||||
|
registered_ndev[index] = NULL;
|
||||||
|
raw_spin_unlock_irqrestore(&ptp_notifier_lock, flags);
|
||||||
|
}
|
||||||
|
EXPORT_SYMBOL(tegra_unregister_hwtime_source);
|
||||||
|
|
||||||
|
int tegra_get_hwtime(const char *intf_name, void *ts, int ts_type)
|
||||||
|
{
|
||||||
|
unsigned long flags;
|
||||||
|
int ret = 0, index = 0;
|
||||||
|
struct net_device *dev;
|
||||||
|
|
||||||
|
raw_spin_lock_irqsave(&ptp_notifier_lock, flags);
|
||||||
|
if (!intf_name || !ts) {
|
||||||
|
pr_err("passed Interface_name or time-stamp ptr is NULL");
|
||||||
|
raw_spin_unlock_irqrestore(&ptp_notifier_lock, flags);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
dev = dev_get_by_name(&init_net, intf_name);
|
||||||
|
|
||||||
|
if (!dev || !(dev->flags & IFF_UP)) {
|
||||||
|
pr_debug("dev is NULL or intf is not up for %s\n", intf_name);
|
||||||
|
ret = -EINVAL;
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
for (index = 0; index < MAX_MAC_INSTANCES; index++) {
|
||||||
|
if (dev == registered_ndev[index])
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (index == MAX_MAC_INSTANCES) {
|
||||||
|
pr_debug("Interface: %s is not registered to get HW time", intf_name);
|
||||||
|
ret = -EINVAL;
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (get_systime[index])
|
||||||
|
ret = (get_systime[index])(dev, ts, ts_type);
|
||||||
|
else
|
||||||
|
ret = -EINVAL;
|
||||||
|
|
||||||
|
out:
|
||||||
|
if (dev)
|
||||||
|
dev_put(dev);
|
||||||
|
raw_spin_unlock_irqrestore(&ptp_notifier_lock, flags);
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
EXPORT_SYMBOL(tegra_get_hwtime);
|
||||||
|
|
||||||
|
MODULE_LICENSE("GPL");
|
||||||
20
include/linux/nvpps.h
Normal file
20
include/linux/nvpps.h
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
/* SPDX-License-Identifier: GPL-2.0-only */
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2022, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __NVPPS_H__
|
||||||
|
#define __NVPPS_H__
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Get PTP time
|
||||||
|
* Clients may call the API every and anytime PTP time is needed.
|
||||||
|
* If PTP time source is not registered, returns -EINVAL
|
||||||
|
*
|
||||||
|
* This API is available irrespective of nvpps dt availablity
|
||||||
|
* When nvpps dt node is not present, interface name will
|
||||||
|
* default to "eth0".
|
||||||
|
*/
|
||||||
|
int nvpps_get_ptp_ts(void *ts);
|
||||||
|
|
||||||
|
#endif /* __NVPPS_H__ */
|
||||||
50
include/linux/platform/tegra/ptp-notifier.h
Normal file
50
include/linux/platform/tegra/ptp-notifier.h
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
/* SPDX-License-Identifier: GPL-2.0-only */
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2022, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __PTP_NOTIFIER_H
|
||||||
|
#define __PTP_NOTIFIER_H
|
||||||
|
|
||||||
|
#include <linux/types.h>
|
||||||
|
#include <linux/notifier.h>
|
||||||
|
#include <linux/etherdevice.h>
|
||||||
|
|
||||||
|
#define PTP_HWTIME 1
|
||||||
|
#define PTP_TSC_HWTIME 2
|
||||||
|
#define TSC_HIGH_SHIFT 32U
|
||||||
|
|
||||||
|
/** Max of 5 interfaces created per IP multiply by number of IP */
|
||||||
|
#define MAX_MAC_INSTANCES 25
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief ptp_tsc_data - Struture used to store TSC and PTP time
|
||||||
|
* information.
|
||||||
|
*/
|
||||||
|
struct ptp_tsc_data {
|
||||||
|
/** PTP TimeStamp in nSec*/
|
||||||
|
u64 ptp_ts;
|
||||||
|
/** TSC TimeStamp in nSec*/
|
||||||
|
u64 tsc_ts;
|
||||||
|
};
|
||||||
|
|
||||||
|
/* register / unregister HW time source */
|
||||||
|
void tegra_register_hwtime_source(int (*func)(struct net_device *, void *, int),
|
||||||
|
struct net_device *dev);
|
||||||
|
void tegra_unregister_hwtime_source(struct net_device *dev);
|
||||||
|
|
||||||
|
/* clients registering / unregistering for time update events */
|
||||||
|
int tegra_register_hwtime_notifier(struct notifier_block *nb);
|
||||||
|
int tegra_unregister_hwtime_notifier(struct notifier_block *nb);
|
||||||
|
|
||||||
|
/* Notify time updates to registered clients */
|
||||||
|
int tegra_hwtime_notifier_call_chain(unsigned int val, void *v);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Get HW time counter.
|
||||||
|
* Clients may call the API every anytime PTP/TSC time is needed.
|
||||||
|
* If HW time source is not registered, returns -EINVAL
|
||||||
|
*/
|
||||||
|
int tegra_get_hwtime(const char *intf_name, void *ts, int ts_type);
|
||||||
|
|
||||||
|
#endif /* __PTP_NOTIFIER_H */
|
||||||
96
include/linux/tegra-gte.h
Normal file
96
include/linux/tegra-gte.h
Normal file
@@ -0,0 +1,96 @@
|
|||||||
|
/* SPDX-License-Identifier: GPL-2.0-only */
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2022, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _LINUX_TEGRA_GTE_ENGINE_H
|
||||||
|
#define _LINUX_TEGRA_GTE_ENGINE_H
|
||||||
|
|
||||||
|
#include <linux/device.h>
|
||||||
|
|
||||||
|
struct tegra_gte_ev_desc {
|
||||||
|
int id;
|
||||||
|
u32 ev_bit;
|
||||||
|
u32 slice;
|
||||||
|
};
|
||||||
|
|
||||||
|
/* GTE hardware timestamping event details */
|
||||||
|
struct tegra_gte_ev_detail {
|
||||||
|
u64 ts_raw; /* raw counter value */
|
||||||
|
u64 ts_ns; /* counter value converted into nano seconds */
|
||||||
|
int dir; /* direction of the event */
|
||||||
|
};
|
||||||
|
|
||||||
|
#ifdef CONFIG_TEGRA_HTS_GTE
|
||||||
|
/*
|
||||||
|
* GTE event registration function
|
||||||
|
*
|
||||||
|
* Parameters:
|
||||||
|
*
|
||||||
|
* Input:
|
||||||
|
* @np: device node of the interested GTE device
|
||||||
|
* @ev_id: event id
|
||||||
|
*
|
||||||
|
* Returns:
|
||||||
|
* Returns ERR_PTR in case of failure or valid
|
||||||
|
* struct tegra_gte_ev_desc for success.
|
||||||
|
*
|
||||||
|
* Note: API is not stable and subject to change.
|
||||||
|
*/
|
||||||
|
struct tegra_gte_ev_desc *tegra_gte_register_event(struct device_node *np,
|
||||||
|
u32 ev_id);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* GTE event un-registration function
|
||||||
|
*
|
||||||
|
* Parameters:
|
||||||
|
*
|
||||||
|
* Input:
|
||||||
|
* @desc: This parameter should be the same as returned from register
|
||||||
|
*
|
||||||
|
* Returns:
|
||||||
|
* Returns 0 for success and any other value for the failure
|
||||||
|
*
|
||||||
|
* Note: API is not stable and subject to change.
|
||||||
|
*/
|
||||||
|
int tegra_gte_unregister_event(struct tegra_gte_ev_desc *desc);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* GTE event retrieval function
|
||||||
|
*
|
||||||
|
* Parameters:
|
||||||
|
*
|
||||||
|
* Input:
|
||||||
|
* @desc: This parameter should be the same as returned from register
|
||||||
|
*
|
||||||
|
* Output:
|
||||||
|
* @hts: hts event details
|
||||||
|
*
|
||||||
|
* Returns:
|
||||||
|
* Returns 0 for success and any other value for the failure
|
||||||
|
*
|
||||||
|
* Note: API is not stable and subject to change.
|
||||||
|
*/
|
||||||
|
int tegra_gte_retrieve_event(const struct tegra_gte_ev_desc *desc,
|
||||||
|
struct tegra_gte_ev_detail *hts);
|
||||||
|
|
||||||
|
#else /* ! CONFIG_TEGRA_HTS_GTE */
|
||||||
|
static inline struct tegra_gte_ev_desc *tegra_gte_register_event(
|
||||||
|
struct device_node *np, u32 ev_id)
|
||||||
|
{
|
||||||
|
return ERR_PTR(-ENOSYS);
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline int tegra_gte_unregister_event(struct tegra_gte_ev_desc *desc)
|
||||||
|
{
|
||||||
|
return -ENOSYS;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline int tegra_gte_retrieve_event(const struct tegra_gte_ev_desc *desc,
|
||||||
|
struct tegra_gte_ev_detail *hts)
|
||||||
|
{
|
||||||
|
return -ENOSYS;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* ! CONFIG_TEGRA_HTS_GTE */
|
||||||
|
#endif
|
||||||
78
include/uapi/linux/nvpps_ioctl.h
Normal file
78
include/uapi/linux/nvpps_ioctl.h
Normal file
@@ -0,0 +1,78 @@
|
|||||||
|
/* SPDX-License-Identifier: GPL-2.0-only */
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2022, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __UAPI_NVPPS_IOCTL_H__
|
||||||
|
#define __UAPI_NVPPS_IOCTL_H__
|
||||||
|
|
||||||
|
#include <linux/types.h>
|
||||||
|
#include <linux/ioctl.h>
|
||||||
|
|
||||||
|
struct nvpps_version {
|
||||||
|
struct _version {
|
||||||
|
__u32 major;
|
||||||
|
__u32 minor;
|
||||||
|
} version;
|
||||||
|
struct _api {
|
||||||
|
__u32 major;
|
||||||
|
__u32 minor;
|
||||||
|
} api;
|
||||||
|
};
|
||||||
|
|
||||||
|
#define NVPPS_VERSION_MAJOR 0
|
||||||
|
#define NVPPS_VERSION_MINOR 2
|
||||||
|
#define NVPPS_API_MAJOR 0
|
||||||
|
#define NVPPS_API_MINOR 4
|
||||||
|
|
||||||
|
struct nvpps_params {
|
||||||
|
__u32 evt_mode;
|
||||||
|
__u32 tsc_mode;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/* evt_mode */
|
||||||
|
#define NVPPS_MODE_GPIO 0x01
|
||||||
|
#define NVPPS_MODE_TIMER 0x02
|
||||||
|
|
||||||
|
/* tsc_mode */
|
||||||
|
#define NVPPS_TSC_NSEC 0
|
||||||
|
#define NVPPS_TSC_COUNTER 1
|
||||||
|
|
||||||
|
|
||||||
|
struct nvpps_timeevent {
|
||||||
|
__u32 evt_nb;
|
||||||
|
__u64 tsc;
|
||||||
|
__u64 ptp;
|
||||||
|
__u64 secondary_ptp;
|
||||||
|
__u64 tsc_res_ns;
|
||||||
|
__u32 evt_mode;
|
||||||
|
__u32 tsc_mode;
|
||||||
|
__u64 irq_latency;
|
||||||
|
};
|
||||||
|
|
||||||
|
#ifndef _LINUX_TIME64_H
|
||||||
|
typedef __s64 time64_t;
|
||||||
|
typedef __u64 timeu64_t;
|
||||||
|
|
||||||
|
struct timespec64 {
|
||||||
|
time64_t tv_sec; /* seconds */
|
||||||
|
long tv_nsec; /* nanoseconds */
|
||||||
|
};
|
||||||
|
#endif
|
||||||
|
|
||||||
|
struct nvpps_timestamp_struct {
|
||||||
|
clockid_t clockid;
|
||||||
|
struct timespec64 kernel_ts;
|
||||||
|
struct timespec64 hw_ptp_ts;
|
||||||
|
__u64 extra[2];
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#define NVPPS_GETVERSION _IOR('p', 0x1, struct nvpps_version *)
|
||||||
|
#define NVPPS_GETPARAMS _IOR('p', 0x2, struct nvpps_params *)
|
||||||
|
#define NVPPS_SETPARAMS _IOW('p', 0x3, struct nvpps_params *)
|
||||||
|
#define NVPPS_GETEVENT _IOR('p', 0x4, struct nvpps_timeevent *)
|
||||||
|
#define NVPPS_GETTIMESTAMP _IOWR('p', 0x5, struct nvpps_timestamp_struct *)
|
||||||
|
|
||||||
|
#endif /* __UAPI_NVPPS_IOCTL_H__ */
|
||||||
Reference in New Issue
Block a user