vserver 1.9.5.x5
[linux-2.6.git] / drivers / w1 / w1.h
1 /*
2  *      w1.h
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 terms 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 #ifndef __W1_H
23 #define __W1_H
24
25 struct w1_reg_num
26 {
27         __u64   family:8,
28                 id:48,
29                 crc:8;
30 };
31
32 #ifdef __KERNEL__
33
34 #include <linux/completion.h>
35 #include <linux/device.h>
36
37 #include <net/sock.h>
38
39 #include <asm/semaphore.h>
40
41 #include "w1_family.h"
42
43 #define W1_MAXNAMELEN           32
44 #define W1_SLAVE_DATA_SIZE      128
45
46 #define W1_SEARCH               0xF0
47 #define W1_CONDITIONAL_SEARCH   0xEC
48 #define W1_CONVERT_TEMP         0x44
49 #define W1_SKIP_ROM             0xCC
50 #define W1_READ_SCRATCHPAD      0xBE
51 #define W1_READ_ROM             0x33
52 #define W1_READ_PSUPPLY         0xB4
53 #define W1_MATCH_ROM            0x55
54
55 #define W1_SLAVE_ACTIVE         (1<<0)
56
57 struct w1_slave
58 {
59         struct module           *owner;
60         unsigned char           name[W1_MAXNAMELEN];
61         struct list_head        w1_slave_entry;
62         struct w1_reg_num       reg_num;
63         atomic_t                refcnt;
64         u8                      rom[9];
65         u32                     flags;
66         int                     ttl;
67
68         struct w1_master        *master;
69         struct w1_family        *family;
70         struct device           dev;
71         struct completion       dev_released;
72
73         struct bin_attribute    attr_bin;
74         struct device_attribute attr_name, attr_val;
75 };
76
77 typedef void (* w1_slave_found_callback)(unsigned long, u64);
78
79 struct w1_bus_master
80 {
81         unsigned long           data;
82
83         u8                      (*read_bit)(unsigned long);
84         void                    (*write_bit)(unsigned long, u8);
85         
86         u8                      (*read_byte)(unsigned long);
87         void                    (*write_byte)(unsigned long, u8);
88         
89         u8                      (*read_block)(unsigned long, u8 *, int);
90         void                    (*write_block)(unsigned long, u8 *, int);
91         
92         u8                      (*touch_bit)(unsigned long, u8);
93   
94         u8                      (*reset_bus)(unsigned long);
95
96         void                    (*search)(unsigned long, w1_slave_found_callback);
97 };
98
99 struct w1_master
100 {
101         struct list_head        w1_master_entry;
102         struct module           *owner;
103         unsigned char           name[W1_MAXNAMELEN];
104         struct list_head        slist;
105         int                     max_slave_count, slave_count;
106         unsigned long           attempts;
107         int                     slave_ttl;
108         int                     initialized;
109         u32                     id;
110
111         atomic_t                refcnt;
112
113         void                    *priv;
114         int                     priv_size;
115
116         int                     need_exit;
117         pid_t                   kpid;
118         wait_queue_head_t       kwait;
119         struct semaphore        mutex;
120
121         struct device_driver    *driver;
122         struct device           dev;
123         struct completion       dev_released;
124         struct completion       dev_exited;
125
126         struct w1_bus_master    *bus_master;
127
128         u32                     seq, groups;
129         struct sock             *nls;
130 };
131
132 int w1_create_master_attributes(struct w1_master *);
133 void w1_destroy_master_attributes(struct w1_master *);
134 void w1_search(struct w1_master *dev);
135
136 #endif /* __KERNEL__ */
137
138 #endif /* __W1_H */