aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/w1/w1_smem.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
committerLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
commit1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 (patch)
tree0bba044c4ce775e45a88a51686b5d9f90697ea9d /drivers/w1/w1_smem.c
Linux-2.6.12-rc2v2.6.12-rc2
Initial git repository build. I'm not bothering with the full history, even though we have it. We can create a separate "historical" git archive of that later if we want to, and in the meantime it's about 3.2GB when imported into git - space that would just make the early git days unnecessarily complicated, when we don't have a lot of good infrastructure for it. Let it rip!
Diffstat (limited to 'drivers/w1/w1_smem.c')
-rw-r--r--drivers/w1/w1_smem.c118
1 files changed, 118 insertions, 0 deletions
diff --git a/drivers/w1/w1_smem.c b/drivers/w1/w1_smem.c
new file mode 100644
index 000000000000..ab82eb7ed74f
--- /dev/null
+++ b/drivers/w1/w1_smem.c
@@ -0,0 +1,118 @@
1/*
2 * w1_smem.c
3 *
4 * Copyright (c) 2004 Evgeniy Polyakov <johnpol@2ka.mipt.ru>
5 *
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the smems of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 */
21
22#include <asm/types.h>
23
24#include <linux/kernel.h>
25#include <linux/module.h>
26#include <linux/moduleparam.h>
27#include <linux/device.h>
28#include <linux/types.h>
29
30#include "w1.h"
31#include "w1_io.h"
32#include "w1_int.h"
33#include "w1_family.h"
34
35MODULE_LICENSE("GPL");
36MODULE_AUTHOR("Evgeniy Polyakov <johnpol@2ka.mipt.ru>");
37MODULE_DESCRIPTION("Driver for 1-wire Dallas network protocol, 64bit memory family.");
38
39static ssize_t w1_smem_read_name(struct device *, char *);
40static ssize_t w1_smem_read_val(struct device *, char *);
41static ssize_t w1_smem_read_bin(struct kobject *, char *, loff_t, size_t);
42
43static struct w1_family_ops w1_smem_fops = {
44 .rname = &w1_smem_read_name,
45 .rbin = &w1_smem_read_bin,
46 .rval = &w1_smem_read_val,
47 .rvalname = "id",
48};
49
50static ssize_t w1_smem_read_name(struct device *dev, char *buf)
51{
52 struct w1_slave *sl = container_of(dev, struct w1_slave, dev);
53
54 return sprintf(buf, "%s\n", sl->name);
55}
56
57static ssize_t w1_smem_read_val(struct device *dev, char *buf)
58{
59 struct w1_slave *sl = container_of(dev, struct w1_slave, dev);
60 int i;
61 ssize_t count = 0;
62
63 for (i = 0; i < 9; ++i)
64 count += sprintf(buf + count, "%02x ", ((u8 *)&sl->reg_num)[i]);
65 count += sprintf(buf + count, "\n");
66
67 return count;
68}
69
70static ssize_t w1_smem_read_bin(struct kobject *kobj, char *buf, loff_t off, size_t count)
71{
72 struct w1_slave *sl = container_of(container_of(kobj, struct device, kobj),
73 struct w1_slave, dev);
74 int i;
75
76 atomic_inc(&sl->refcnt);
77 if (down_interruptible(&sl->master->mutex)) {
78 count = 0;
79 goto out_dec;
80 }
81
82 if (off > W1_SLAVE_DATA_SIZE) {
83 count = 0;
84 goto out;
85 }
86 if (off + count > W1_SLAVE_DATA_SIZE) {
87 count = 0;
88 goto out;
89 }
90 for (i = 0; i < 9; ++i)
91 count += sprintf(buf + count, "%02x ", ((u8 *)&sl->reg_num)[i]);
92 count += sprintf(buf + count, "\n");
93
94out:
95 up(&sl->master->mutex);
96out_dec:
97 atomic_dec(&sl->refcnt);
98
99 return count;
100}
101
102static struct w1_family w1_smem_family = {
103 .fid = W1_FAMILY_SMEM,
104 .fops = &w1_smem_fops,
105};
106
107static int __init w1_smem_init(void)
108{
109 return w1_register_family(&w1_smem_family);
110}
111
112static void __exit w1_smem_fini(void)
113{
114 w1_unregister_family(&w1_smem_family);
115}
116
117module_init(w1_smem_init);
118module_exit(w1_smem_fini);