4 * Copyright (c) 2004 Evgeniy Polyakov <johnpol@2ka.mipt.ru>
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.
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.
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
22 #include <asm/types.h>
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>
33 #include "w1_family.h"
35 MODULE_LICENSE("GPL");
36 MODULE_AUTHOR("Evgeniy Polyakov <johnpol@2ka.mipt.ru>");
37 MODULE_DESCRIPTION("Driver for 1-wire Dallas network protocol, 64bit memory family.");
39 static ssize_t
w1_smem_read_name(struct device
*, char *);
40 static ssize_t
w1_smem_read_val(struct device
*, char *);
41 static ssize_t
w1_smem_read_bin(struct kobject
*, char *, loff_t
, size_t);
43 static 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
,
50 static ssize_t
w1_smem_read_name(struct device
*dev
, char *buf
)
52 struct w1_slave
*sl
= container_of(dev
, struct w1_slave
, dev
);
54 return sprintf(buf
, "%s\n", sl
->name
);
57 static ssize_t
w1_smem_read_val(struct device
*dev
, char *buf
)
59 struct w1_slave
*sl
= container_of(dev
, struct w1_slave
, dev
);
63 for (i
= 0; i
< 8; ++i
)
64 count
+= sprintf(buf
+ count
, "%02x ", ((u8
*)&sl
->reg_num
)[i
]);
65 count
+= sprintf(buf
+ count
, "\n");
70 static ssize_t
w1_smem_read_bin(struct kobject
*kobj
, char *buf
, loff_t off
, size_t count
)
72 struct w1_slave
*sl
= container_of(container_of(kobj
, struct device
, kobj
),
73 struct w1_slave
, dev
);
76 atomic_inc(&sl
->refcnt
);
77 if (down_interruptible(&sl
->master
->mutex
)) {
82 if (off
> W1_SLAVE_DATA_SIZE
) {
86 if (off
+ count
> W1_SLAVE_DATA_SIZE
) {
90 for (i
= 0; i
< 8; ++i
)
91 count
+= sprintf(buf
+ count
, "%02x ", ((u8
*)&sl
->reg_num
)[i
]);
92 count
+= sprintf(buf
+ count
, "\n");
95 up(&sl
->master
->mutex
);
97 atomic_dec(&sl
->refcnt
);
102 static struct w1_family w1_smem_family
= {
103 .fid
= W1_FAMILY_SMEM
,
104 .fops
= &w1_smem_fops
,
107 static int __init
w1_smem_init(void)
109 return w1_register_family(&w1_smem_family
);
112 static void __exit
w1_smem_fini(void)
114 w1_unregister_family(&w1_smem_family
);
117 module_init(w1_smem_init
);
118 module_exit(w1_smem_fini
);