Subject: Re: [PATCH 1/3] ptp: Added a brand new class driver for ptp clocks.

From: Wolfgang Grandegger <[email-masked]>
Date: Sun, 02 May 2010 12:50:56 +0200

Hi Richard,

Richard Cochran wrote:
> This patch adds an infrastructure for hardware clocks that implement
> IEEE 1588, the Precision Time Protocol (PTP). A class driver offers a
> registration method to particular hardware clock drivers. Each clock is
> exposed to user space as a character device with ioctls that allow tuning
> of the PTP clock.
> 
> Signed-off-by: Richard Cochran <[email-masked]>
> ---
...
> diff --git a/drivers/ptp/ptp_clock.c b/drivers/ptp/ptp_clock.c
> new file mode 100644
> index 0000000..a5acac4
> --- /dev/null
> +++ b/drivers/ptp/ptp_clock.c
...
> +static int ptp_open(struct inode *inode, struct file *fp)
> +{
> +	struct ptp_clock *ptp;
> +	ptp = container_of(inode->i_cdev, struct ptp_clock, cdev);
> +
> +	if (mutex_lock_interruptible(&ptp->mux))
> +		return -ERESTARTSYS;
> +
> +	fp->private_data = ptp;
> +
> +	return 0;
> +}
...
> +static int ptp_release(struct inode *inode, struct file *fp)
> +{
> +	struct ptp_clock *ptp = fp->private_data;
> +	mutex_unlock(&ptp->mux);
> +	return 0;
> +}

As long as the device is in use by an application, no other can access
it, because the mutex is locked. Other application may want to read the
PTP clock time while ptpd is running, though.

Wolfgang.