[PATCH] w1: fix build issues
[wandboard.git] / drivers / w1 / w1_smem.c
blob70d2d469963cfe8e57be5b242c31ae1bec525a69
1 /*
2 * w1_smem.c
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>
30 #include "w1.h"
31 #include "w1_io.h"
32 #include "w1_int.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 *, struct device_attribute *attr, char *);
40 static ssize_t w1_smem_read_bin(struct kobject *, char *, loff_t, size_t);
42 static struct w1_family_ops w1_smem_fops = {
43 .rname = &w1_smem_read_name,
44 .rbin = &w1_smem_read_bin,
47 static ssize_t w1_smem_read_name(struct device *dev, struct device_attribute *attr, char *buf)
49 struct w1_slave *sl = container_of(dev, struct w1_slave, dev);
51 return sprintf(buf, "%s\n", sl->name);
54 static ssize_t w1_smem_read_bin(struct kobject *kobj, char *buf, loff_t off, size_t count)
56 struct w1_slave *sl = container_of(container_of(kobj, struct device, kobj),
57 struct w1_slave, dev);
58 int i;
60 atomic_inc(&sl->refcnt);
61 if (down_interruptible(&sl->master->mutex)) {
62 count = 0;
63 goto out_dec;
66 if (off > W1_SLAVE_DATA_SIZE) {
67 count = 0;
68 goto out;
70 if (off + count > W1_SLAVE_DATA_SIZE) {
71 count = 0;
72 goto out;
74 for (i = 0; i < 8; ++i)
75 count += sprintf(buf + count, "%02x ", ((u8 *)&sl->reg_num)[i]);
76 count += sprintf(buf + count, "\n");
78 out:
79 up(&sl->master->mutex);
80 out_dec:
81 atomic_dec(&sl->refcnt);
83 return count;
86 static struct w1_family w1_smem_family_01 = {
87 .fid = W1_FAMILY_SMEM_01,
88 .fops = &w1_smem_fops,
91 static struct w1_family w1_smem_family_81 = {
92 .fid = W1_FAMILY_SMEM_81,
93 .fops = &w1_smem_fops,
96 static int __init w1_smem_init(void)
98 int err;
100 err = w1_register_family(&w1_smem_family_01);
101 if (err)
102 return err;
104 err = w1_register_family(&w1_smem_family_81);
105 if (err) {
106 w1_unregister_family(&w1_smem_family_01);
107 return err;
110 return 0;
113 static void __exit w1_smem_fini(void)
115 w1_unregister_family(&w1_smem_family_01);
116 w1_unregister_family(&w1_smem_family_81);
119 module_init(w1_smem_init);
120 module_exit(w1_smem_fini);