lkml.org 
[lkml]   [2008]   [Feb]   [11]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH 1/8] LinuxPPS core support.
On Mon, Feb 11, 2008 at 07:31:53PM +0100, Rodolfo Giometti wrote:
> Do you think is better create these files anyway and in case report a
> NULL string?

Is that ok?

/*
* Attribute functions
*/

static ssize_t pps_show_assert(struct device *dev,
struct device_attribute *attr, char *buf)
{
struct pps_device *pps = dev_get_drvdata(dev);

if (!(pps->info.mode & PPS_CAPTUREASSERT))
return 0;

return sprintf(buf, "%lld.%09d#%d\n",
pps->assert_tu.sec, pps->assert_tu.nsec,
pps->assert_sequence);
}
DEVICE_ATTR(assert, S_IRUGO, pps_show_assert, NULL);

static ssize_t pps_show_clear(struct device *dev,
struct device_attribute *attr, char *buf)
{
struct pps_device *pps = dev_get_drvdata(dev);

if (!(pps->info.mode & PPS_CAPTURECLEAR))
return 0;

return sprintf(buf, "%lld.%09d#%d\n",
pps->clear_tu.sec, pps->clear_tu.nsec,
pps->clear_sequence);
}
DEVICE_ATTR(clear, S_IRUGO, pps_show_clear, NULL);

static ssize_t pps_show_mode(struct device *dev,
struct device_attribute *attr, char *buf)
{
struct pps_device *pps = dev_get_drvdata(dev);

return sprintf(buf, "%4x\n", pps->info.mode);
}
DEVICE_ATTR(mode, S_IRUGO, pps_show_mode, NULL);

...

static struct attribute *pps_attrs[] = {
&dev_attr_mode.attr,
&dev_attr_echo.attr,
&dev_attr_name.attr,
&dev_attr_path.attr,
&dev_attr_assert.attr,
&dev_attr_clear.attr,
NULL
};

static struct attribute_group pps_group = {
.attrs = pps_attrs,
};

/*
* Public functions
*/

void pps_sysfs_remove_source_entry(struct pps_device *pps)
{
/* Delete info files */
sysfs_remove_group(&pps->dev->kobj, &pps_group);
}

int pps_sysfs_create_source_entry(struct pps_device *pps)
{
int ret;

/* Create info files */
ret = sysfs_create_group(&pps->dev->kobj, &pps_group);
if (ret)
dev_err(pps->dev, "unable to create default sysfs entries");

return 0;
}

Ciao,

Rodolfo

--

GNU/Linux Solutions e-mail: giometti@enneenne.com
Linux Device Driver giometti@gnudd.com
Embedded Systems giometti@linux.it
UNIX programming phone: +39 349 2432127


\
 
 \ /
  Last update: 2008-02-11 19:43    [W:0.059 / U:0.996 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site