aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@g5.osdl.org>2005-09-08 18:55:53 -0400
committerLinus Torvalds <torvalds@g5.osdl.org>2005-09-08 18:55:53 -0400
commit6d8de3a26b5c20b04a9317b4446582167d5883da (patch)
treeaa71ab52059380fa2bbdcee4a0cf559a9dacdf01 /drivers
parent7bbedd521310547ca73cc77adcf61fb85723adc3 (diff)
parent0a25e4d5647003a32ba5496f9d0f40ba9c1e3863 (diff)
Merge master.kernel.org:/pub/scm/linux/kernel/git/gregkh/w1-2.6
Diffstat (limited to 'drivers')
-rw-r--r--drivers/w1/Kconfig16
-rw-r--r--drivers/w1/Makefile7
-rw-r--r--drivers/w1/ds_w1_bridge.c24
-rw-r--r--drivers/w1/dscore.c161
-rw-r--r--drivers/w1/dscore.h10
-rw-r--r--drivers/w1/w1.c302
-rw-r--r--drivers/w1/w1.h22
-rw-r--r--drivers/w1/w1_ds2433.c327
-rw-r--r--drivers/w1/w1_family.c11
-rw-r--r--drivers/w1/w1_family.h7
-rw-r--r--drivers/w1/w1_int.c26
-rw-r--r--drivers/w1/w1_io.c24
-rw-r--r--drivers/w1/w1_io.h1
-rw-r--r--drivers/w1/w1_netlink.c26
-rw-r--r--drivers/w1/w1_netlink.h2
-rw-r--r--drivers/w1/w1_smem.c49
-rw-r--r--drivers/w1/w1_therm.c47
17 files changed, 750 insertions, 312 deletions
diff --git a/drivers/w1/Kconfig b/drivers/w1/Kconfig
index 711b90903e7b..9a1e00dd3e02 100644
--- a/drivers/w1/Kconfig
+++ b/drivers/w1/Kconfig
@@ -54,4 +54,20 @@ config W1_SMEM
54 Say Y here if you want to connect 1-wire 54 Say Y here if you want to connect 1-wire
55 simple 64bit memory rom(ds2401/ds2411/ds1990*) to you wire. 55 simple 64bit memory rom(ds2401/ds2411/ds1990*) to you wire.
56 56
57config W1_DS2433
58 tristate "4kb EEPROM family support (DS2433)"
59 depends on W1
60 help
61 Say Y here if you want to use a 1-wire
62 4kb EEPROM family device (DS2433).
63
64config W1_DS2433_CRC
65 bool "Protect DS2433 data with a CRC16"
66 depends on W1_DS2433
67 select CRC16
68 help
69 Say Y here to protect DS2433 data with a CRC16.
70 Each block has 30 bytes of data and a two byte CRC16.
71 Full block writes are only allowed if the CRC is valid.
72
57endmenu 73endmenu
diff --git a/drivers/w1/Makefile b/drivers/w1/Makefile
index 80725c348e70..01fb54391470 100644
--- a/drivers/w1/Makefile
+++ b/drivers/w1/Makefile
@@ -6,6 +6,10 @@ ifneq ($(CONFIG_NET), y)
6EXTRA_CFLAGS += -DNETLINK_DISABLED 6EXTRA_CFLAGS += -DNETLINK_DISABLED
7endif 7endif
8 8
9ifeq ($(CONFIG_W1_DS2433_CRC), y)
10EXTRA_CFLAGS += -DCONFIG_W1_F23_CRC
11endif
12
9obj-$(CONFIG_W1) += wire.o 13obj-$(CONFIG_W1) += wire.o
10wire-objs := w1.o w1_int.o w1_family.o w1_netlink.o w1_io.o 14wire-objs := w1.o w1_int.o w1_family.o w1_netlink.o w1_io.o
11 15
@@ -13,8 +17,9 @@ obj-$(CONFIG_W1_MATROX) += matrox_w1.o
13obj-$(CONFIG_W1_THERM) += w1_therm.o 17obj-$(CONFIG_W1_THERM) += w1_therm.o
14obj-$(CONFIG_W1_SMEM) += w1_smem.o 18obj-$(CONFIG_W1_SMEM) += w1_smem.o
15 19
16obj-$(CONFIG_W1_DS9490) += ds9490r.o 20obj-$(CONFIG_W1_DS9490) += ds9490r.o
17ds9490r-objs := dscore.o 21ds9490r-objs := dscore.o
18 22
19obj-$(CONFIG_W1_DS9490_BRIDGE) += ds_w1_bridge.o 23obj-$(CONFIG_W1_DS9490_BRIDGE) += ds_w1_bridge.o
20 24
25obj-$(CONFIG_W1_DS2433) += w1_ds2433.o
diff --git a/drivers/w1/ds_w1_bridge.c b/drivers/w1/ds_w1_bridge.c
index 7bddd8ac7d7f..a79d16d5666f 100644
--- a/drivers/w1/ds_w1_bridge.c
+++ b/drivers/w1/ds_w1_bridge.c
@@ -1,8 +1,8 @@
1/* 1/*
2 * ds_w1_bridge.c 2 * ds_w1_bridge.c
3 * 3 *
4 * Copyright (c) 2004 Evgeniy Polyakov <johnpol@2ka.mipt.ru> 4 * Copyright (c) 2004 Evgeniy Polyakov <johnpol@2ka.mipt.ru>
5 * 5 *
6 * 6 *
7 * This program is free software; you can redistribute it and/or modify 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 8 * it under the terms of the GNU General Public License as published by
@@ -25,7 +25,7 @@
25#include "../w1/w1.h" 25#include "../w1/w1.h"
26#include "../w1/w1_int.h" 26#include "../w1/w1_int.h"
27#include "dscore.h" 27#include "dscore.h"
28 28
29static struct ds_device *ds_dev; 29static struct ds_device *ds_dev;
30static struct w1_bus_master *ds_bus_master; 30static struct w1_bus_master *ds_bus_master;
31 31
@@ -120,7 +120,7 @@ static u8 ds9490r_reset(unsigned long data)
120static int __devinit ds_w1_init(void) 120static int __devinit ds_w1_init(void)
121{ 121{
122 int err; 122 int err;
123 123
124 ds_bus_master = kmalloc(sizeof(*ds_bus_master), GFP_KERNEL); 124 ds_bus_master = kmalloc(sizeof(*ds_bus_master), GFP_KERNEL);
125 if (!ds_bus_master) { 125 if (!ds_bus_master) {
126 printk(KERN_ERR "Failed to allocate DS9490R USB<->W1 bus_master structure.\n"); 126 printk(KERN_ERR "Failed to allocate DS9490R USB<->W1 bus_master structure.\n");
@@ -136,14 +136,14 @@ static int __devinit ds_w1_init(void)
136 136
137 memset(ds_bus_master, 0, sizeof(*ds_bus_master)); 137 memset(ds_bus_master, 0, sizeof(*ds_bus_master));
138 138
139 ds_bus_master->data = (unsigned long)ds_dev; 139 ds_bus_master->data = (unsigned long)ds_dev;
140 ds_bus_master->touch_bit = &ds9490r_touch_bit; 140 ds_bus_master->touch_bit = &ds9490r_touch_bit;
141 ds_bus_master->read_bit = &ds9490r_read_bit; 141 ds_bus_master->read_bit = &ds9490r_read_bit;
142 ds_bus_master->write_bit = &ds9490r_write_bit; 142 ds_bus_master->write_bit = &ds9490r_write_bit;
143 ds_bus_master->read_byte = &ds9490r_read_byte; 143 ds_bus_master->read_byte = &ds9490r_read_byte;
144 ds_bus_master->write_byte = &ds9490r_write_byte; 144 ds_bus_master->write_byte = &ds9490r_write_byte;
145 ds_bus_master->read_block = &ds9490r_read_block; 145 ds_bus_master->read_block = &ds9490r_read_block;
146 ds_bus_master->write_block = &ds9490r_write_block; 146 ds_bus_master->write_block = &ds9490r_write_block;
147 ds_bus_master->reset_bus = &ds9490r_reset; 147 ds_bus_master->reset_bus = &ds9490r_reset;
148 148
149 err = w1_add_master_device(ds_bus_master); 149 err = w1_add_master_device(ds_bus_master);
diff --git a/drivers/w1/dscore.c b/drivers/w1/dscore.c
index eee6644d33d6..15fb250451e5 100644
--- a/drivers/w1/dscore.c
+++ b/drivers/w1/dscore.c
@@ -1,8 +1,8 @@
1/* 1/*
2 * dscore.c 2 * dscore.c
3 * 3 *
4 * Copyright (c) 2004 Evgeniy Polyakov <johnpol@2ka.mipt.ru> 4 * Copyright (c) 2004 Evgeniy Polyakov <johnpol@2ka.mipt.ru>
5 * 5 *
6 * 6 *
7 * This program is free software; you can redistribute it and/or modify 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 8 * it under the terms of the GNU General Public License as published by
@@ -32,19 +32,16 @@ static struct usb_device_id ds_id_table [] = {
32}; 32};
33MODULE_DEVICE_TABLE(usb, ds_id_table); 33MODULE_DEVICE_TABLE(usb, ds_id_table);
34 34
35int ds_probe(struct usb_interface *, const struct usb_device_id *); 35static int ds_probe(struct usb_interface *, const struct usb_device_id *);
36void ds_disconnect(struct usb_interface *); 36static void ds_disconnect(struct usb_interface *);
37 37
38int ds_touch_bit(struct ds_device *, u8, u8 *); 38int ds_touch_bit(struct ds_device *, u8, u8 *);
39int ds_read_byte(struct ds_device *, u8 *); 39int ds_read_byte(struct ds_device *, u8 *);
40int ds_read_bit(struct ds_device *, u8 *); 40int ds_read_bit(struct ds_device *, u8 *);
41int ds_write_byte(struct ds_device *, u8); 41int ds_write_byte(struct ds_device *, u8);
42int ds_write_bit(struct ds_device *, u8); 42int ds_write_bit(struct ds_device *, u8);
43int ds_start_pulse(struct ds_device *, int); 43static int ds_start_pulse(struct ds_device *, int);
44int ds_set_speed(struct ds_device *, int);
45int ds_reset(struct ds_device *, struct ds_status *); 44int ds_reset(struct ds_device *, struct ds_status *);
46int ds_detect(struct ds_device *, struct ds_status *);
47int ds_stop_pulse(struct ds_device *, int);
48struct ds_device * ds_get_device(void); 45struct ds_device * ds_get_device(void);
49void ds_put_device(struct ds_device *); 46void ds_put_device(struct ds_device *);
50 47
@@ -79,11 +76,11 @@ void ds_put_device(struct ds_device *dev)
79static int ds_send_control_cmd(struct ds_device *dev, u16 value, u16 index) 76static int ds_send_control_cmd(struct ds_device *dev, u16 value, u16 index)
80{ 77{
81 int err; 78 int err;
82 79
83 err = usb_control_msg(dev->udev, usb_sndctrlpipe(dev->udev, dev->ep[EP_CONTROL]), 80 err = usb_control_msg(dev->udev, usb_sndctrlpipe(dev->udev, dev->ep[EP_CONTROL]),
84 CONTROL_CMD, 0x40, value, index, NULL, 0, 1000); 81 CONTROL_CMD, 0x40, value, index, NULL, 0, 1000);
85 if (err < 0) { 82 if (err < 0) {
86 printk(KERN_ERR "Failed to send command control message %x.%x: err=%d.\n", 83 printk(KERN_ERR "Failed to send command control message %x.%x: err=%d.\n",
87 value, index, err); 84 value, index, err);
88 return err; 85 return err;
89 } 86 }
@@ -94,11 +91,11 @@ static int ds_send_control_cmd(struct ds_device *dev, u16 value, u16 index)
94static int ds_send_control_mode(struct ds_device *dev, u16 value, u16 index) 91static int ds_send_control_mode(struct ds_device *dev, u16 value, u16 index)
95{ 92{
96 int err; 93 int err;
97 94
98 err = usb_control_msg(dev->udev, usb_sndctrlpipe(dev->udev, dev->ep[EP_CONTROL]), 95 err = usb_control_msg(dev->udev, usb_sndctrlpipe(dev->udev, dev->ep[EP_CONTROL]),
99 MODE_CMD, 0x40, value, index, NULL, 0, 1000); 96 MODE_CMD, 0x40, value, index, NULL, 0, 1000);
100 if (err < 0) { 97 if (err < 0) {
101 printk(KERN_ERR "Failed to send mode control message %x.%x: err=%d.\n", 98 printk(KERN_ERR "Failed to send mode control message %x.%x: err=%d.\n",
102 value, index, err); 99 value, index, err);
103 return err; 100 return err;
104 } 101 }
@@ -109,11 +106,11 @@ static int ds_send_control_mode(struct ds_device *dev, u16 value, u16 index)
109static int ds_send_control(struct ds_device *dev, u16 value, u16 index) 106static int ds_send_control(struct ds_device *dev, u16 value, u16 index)
110{ 107{
111 int err; 108 int err;
112 109
113 err = usb_control_msg(dev->udev, usb_sndctrlpipe(dev->udev, dev->ep[EP_CONTROL]), 110 err = usb_control_msg(dev->udev, usb_sndctrlpipe(dev->udev, dev->ep[EP_CONTROL]),
114 COMM_CMD, 0x40, value, index, NULL, 0, 1000); 111 COMM_CMD, 0x40, value, index, NULL, 0, 1000);
115 if (err < 0) { 112 if (err < 0) {
116 printk(KERN_ERR "Failed to send control message %x.%x: err=%d.\n", 113 printk(KERN_ERR "Failed to send control message %x.%x: err=%d.\n",
117 value, index, err); 114 value, index, err);
118 return err; 115 return err;
119 } 116 }
@@ -126,19 +123,20 @@ static inline void ds_dump_status(unsigned char *buf, unsigned char *str, int of
126 printk("%45s: %8x\n", str, buf[off]); 123 printk("%45s: %8x\n", str, buf[off]);
127} 124}
128 125
129int ds_recv_status_nodump(struct ds_device *dev, struct ds_status *st, unsigned char *buf, int size) 126static int ds_recv_status_nodump(struct ds_device *dev, struct ds_status *st,
127 unsigned char *buf, int size)
130{ 128{
131 int count, err; 129 int count, err;
132 130
133 memset(st, 0, sizeof(st)); 131 memset(st, 0, sizeof(st));
134 132
135 count = 0; 133 count = 0;
136 err = usb_bulk_msg(dev->udev, usb_rcvbulkpipe(dev->udev, dev->ep[EP_STATUS]), buf, size, &count, 100); 134 err = usb_bulk_msg(dev->udev, usb_rcvbulkpipe(dev->udev, dev->ep[EP_STATUS]), buf, size, &count, 100);
137 if (err < 0) { 135 if (err < 0) {
138 printk(KERN_ERR "Failed to read 1-wire data from 0x%x: err=%d.\n", dev->ep[EP_STATUS], err); 136 printk(KERN_ERR "Failed to read 1-wire data from 0x%x: err=%d.\n", dev->ep[EP_STATUS], err);
139 return err; 137 return err;
140 } 138 }
141 139
142 if (count >= sizeof(*st)) 140 if (count >= sizeof(*st))
143 memcpy(st, buf, sizeof(*st)); 141 memcpy(st, buf, sizeof(*st));
144 142
@@ -149,13 +147,13 @@ static int ds_recv_status(struct ds_device *dev, struct ds_status *st)
149{ 147{
150 unsigned char buf[64]; 148 unsigned char buf[64];
151 int count, err = 0, i; 149 int count, err = 0, i;
152 150
153 memcpy(st, buf, sizeof(*st)); 151 memcpy(st, buf, sizeof(*st));
154 152
155 count = ds_recv_status_nodump(dev, st, buf, sizeof(buf)); 153 count = ds_recv_status_nodump(dev, st, buf, sizeof(buf));
156 if (count < 0) 154 if (count < 0)
157 return err; 155 return err;
158 156
159 printk("0x%x: count=%d, status: ", dev->ep[EP_STATUS], count); 157 printk("0x%x: count=%d, status: ", dev->ep[EP_STATUS], count);
160 for (i=0; i<count; ++i) 158 for (i=0; i<count; ++i)
161 printk("%02x ", buf[i]); 159 printk("%02x ", buf[i]);
@@ -199,7 +197,7 @@ static int ds_recv_status(struct ds_device *dev, struct ds_status *st)
199 return err; 197 return err;
200 } 198 }
201#endif 199#endif
202 200
203 return err; 201 return err;
204} 202}
205 203
@@ -207,9 +205,9 @@ static int ds_recv_data(struct ds_device *dev, unsigned char *buf, int size)
207{ 205{
208 int count, err; 206 int count, err;
209 struct ds_status st; 207 struct ds_status st;
210 208
211 count = 0; 209 count = 0;
212 err = usb_bulk_msg(dev->udev, usb_rcvbulkpipe(dev->udev, dev->ep[EP_DATA_IN]), 210 err = usb_bulk_msg(dev->udev, usb_rcvbulkpipe(dev->udev, dev->ep[EP_DATA_IN]),
213 buf, size, &count, 1000); 211 buf, size, &count, 1000);
214 if (err < 0) { 212 if (err < 0) {
215 printk(KERN_INFO "Clearing ep0x%x.\n", dev->ep[EP_DATA_IN]); 213 printk(KERN_INFO "Clearing ep0x%x.\n", dev->ep[EP_DATA_IN]);
@@ -234,7 +232,7 @@ static int ds_recv_data(struct ds_device *dev, unsigned char *buf, int size)
234static int ds_send_data(struct ds_device *dev, unsigned char *buf, int len) 232static int ds_send_data(struct ds_device *dev, unsigned char *buf, int len)
235{ 233{
236 int count, err; 234 int count, err;
237 235
238 count = 0; 236 count = 0;
239 err = usb_bulk_msg(dev->udev, usb_sndbulkpipe(dev->udev, dev->ep[EP_DATA_OUT]), buf, len, &count, 1000); 237 err = usb_bulk_msg(dev->udev, usb_sndbulkpipe(dev->udev, dev->ep[EP_DATA_OUT]), buf, len, &count, 1000);
240 if (err < 0) { 238 if (err < 0) {
@@ -245,12 +243,14 @@ static int ds_send_data(struct ds_device *dev, unsigned char *buf, int len)
245 return err; 243 return err;
246} 244}
247 245
246#if 0
247
248int ds_stop_pulse(struct ds_device *dev, int limit) 248int ds_stop_pulse(struct ds_device *dev, int limit)
249{ 249{
250 struct ds_status st; 250 struct ds_status st;
251 int count = 0, err = 0; 251 int count = 0, err = 0;
252 u8 buf[0x20]; 252 u8 buf[0x20];
253 253
254 do { 254 do {
255 err = ds_send_control(dev, CTL_HALT_EXE_IDLE, 0); 255 err = ds_send_control(dev, CTL_HALT_EXE_IDLE, 0);
256 if (err) 256 if (err)
@@ -275,7 +275,7 @@ int ds_stop_pulse(struct ds_device *dev, int limit)
275int ds_detect(struct ds_device *dev, struct ds_status *st) 275int ds_detect(struct ds_device *dev, struct ds_status *st)
276{ 276{
277 int err; 277 int err;
278 278
279 err = ds_send_control_cmd(dev, CTL_RESET_DEVICE, 0); 279 err = ds_send_control_cmd(dev, CTL_RESET_DEVICE, 0);
280 if (err) 280 if (err)
281 return err; 281 return err;
@@ -283,11 +283,11 @@ int ds_detect(struct ds_device *dev, struct ds_status *st)
283 err = ds_send_control(dev, COMM_SET_DURATION | COMM_IM, 0); 283 err = ds_send_control(dev, COMM_SET_DURATION | COMM_IM, 0);
284 if (err) 284 if (err)
285 return err; 285 return err;
286 286
287 err = ds_send_control(dev, COMM_SET_DURATION | COMM_IM | COMM_TYPE, 0x40); 287 err = ds_send_control(dev, COMM_SET_DURATION | COMM_IM | COMM_TYPE, 0x40);
288 if (err) 288 if (err)
289 return err; 289 return err;
290 290
291 err = ds_send_control_mode(dev, MOD_PULSE_EN, PULSE_PROG); 291 err = ds_send_control_mode(dev, MOD_PULSE_EN, PULSE_PROG);
292 if (err) 292 if (err)
293 return err; 293 return err;
@@ -297,7 +297,9 @@ int ds_detect(struct ds_device *dev, struct ds_status *st)
297 return err; 297 return err;
298} 298}
299 299
300int ds_wait_status(struct ds_device *dev, struct ds_status *st) 300#endif /* 0 */
301
302static int ds_wait_status(struct ds_device *dev, struct ds_status *st)
301{ 303{
302 u8 buf[0x20]; 304 u8 buf[0x20];
303 int err, count = 0; 305 int err, count = 0;
@@ -305,7 +307,7 @@ int ds_wait_status(struct ds_device *dev, struct ds_status *st)
305 do { 307 do {
306 err = ds_recv_status_nodump(dev, st, buf, sizeof(buf)); 308 err = ds_recv_status_nodump(dev, st, buf, sizeof(buf));
307#if 0 309#if 0
308 if (err >= 0) { 310 if (err >= 0) {
309 int i; 311 int i;
310 printk("0x%x: count=%d, status: ", dev->ep[EP_STATUS], err); 312 printk("0x%x: count=%d, status: ", dev->ep[EP_STATUS], err);
311 for (i=0; i<err; ++i) 313 for (i=0; i<err; ++i)
@@ -319,10 +321,8 @@ int ds_wait_status(struct ds_device *dev, struct ds_status *st)
319 if (((err > 16) && (buf[0x10] & 0x01)) || count >= 100 || err < 0) { 321 if (((err > 16) && (buf[0x10] & 0x01)) || count >= 100 || err < 0) {
320 ds_recv_status(dev, st); 322 ds_recv_status(dev, st);
321 return -1; 323 return -1;
322 } 324 } else
323 else {
324 return 0; 325 return 0;
325 }
326} 326}
327 327
328int ds_reset(struct ds_device *dev, struct ds_status *st) 328int ds_reset(struct ds_device *dev, struct ds_status *st)
@@ -345,6 +345,7 @@ int ds_reset(struct ds_device *dev, struct ds_status *st)
345 return 0; 345 return 0;
346} 346}
347 347
348#if 0
348int ds_set_speed(struct ds_device *dev, int speed) 349int ds_set_speed(struct ds_device *dev, int speed)
349{ 350{
350 int err; 351 int err;
@@ -356,20 +357,21 @@ int ds_set_speed(struct ds_device *dev, int speed)
356 speed = SPEED_FLEXIBLE; 357 speed = SPEED_FLEXIBLE;
357 358
358 speed &= 0xff; 359 speed &= 0xff;
359 360
360 err = ds_send_control_mode(dev, MOD_1WIRE_SPEED, speed); 361 err = ds_send_control_mode(dev, MOD_1WIRE_SPEED, speed);
361 if (err) 362 if (err)
362 return err; 363 return err;
363 364
364 return err; 365 return err;
365} 366}
367#endif /* 0 */
366 368
367int ds_start_pulse(struct ds_device *dev, int delay) 369static int ds_start_pulse(struct ds_device *dev, int delay)
368{ 370{
369 int err; 371 int err;
370 u8 del = 1 + (u8)(delay >> 4); 372 u8 del = 1 + (u8)(delay >> 4);
371 struct ds_status st; 373 struct ds_status st;
372 374
373#if 0 375#if 0
374 err = ds_stop_pulse(dev, 10); 376 err = ds_stop_pulse(dev, 10);
375 if (err) 377 if (err)
@@ -390,7 +392,7 @@ int ds_start_pulse(struct ds_device *dev, int delay)
390 mdelay(delay); 392 mdelay(delay);
391 393
392 ds_wait_status(dev, &st); 394 ds_wait_status(dev, &st);
393 395
394 return err; 396 return err;
395} 397}
396 398
@@ -400,7 +402,7 @@ int ds_touch_bit(struct ds_device *dev, u8 bit, u8 *tbit)
400 struct ds_status st; 402 struct ds_status st;
401 u16 value = (COMM_BIT_IO | COMM_IM) | ((bit) ? COMM_D : 0); 403 u16 value = (COMM_BIT_IO | COMM_IM) | ((bit) ? COMM_D : 0);
402 u16 cmd; 404 u16 cmd;
403 405
404 err = ds_send_control(dev, value, 0); 406 err = ds_send_control(dev, value, 0);
405 if (err) 407 if (err)
406 return err; 408 return err;
@@ -430,7 +432,7 @@ int ds_write_bit(struct ds_device *dev, u8 bit)
430{ 432{
431 int err; 433 int err;
432 struct ds_status st; 434 struct ds_status st;
433 435
434 err = ds_send_control(dev, COMM_BIT_IO | COMM_IM | (bit) ? COMM_D : 0, 0); 436 err = ds_send_control(dev, COMM_BIT_IO | COMM_IM | (bit) ? COMM_D : 0, 0);
435 if (err) 437 if (err)
436 return err; 438 return err;
@@ -445,7 +447,7 @@ int ds_write_byte(struct ds_device *dev, u8 byte)
445 int err; 447 int err;
446 struct ds_status st; 448 struct ds_status st;
447 u8 rbyte; 449 u8 rbyte;
448 450
449 err = ds_send_control(dev, COMM_BYTE_IO | COMM_IM | COMM_SPU, byte); 451 err = ds_send_control(dev, COMM_BYTE_IO | COMM_IM | COMM_SPU, byte);
450 if (err) 452 if (err)
451 return err; 453 return err;
@@ -453,11 +455,11 @@ int ds_write_byte(struct ds_device *dev, u8 byte)
453 err = ds_wait_status(dev, &st); 455 err = ds_wait_status(dev, &st);
454 if (err) 456 if (err)
455 return err; 457 return err;
456 458
457 err = ds_recv_data(dev, &rbyte, sizeof(rbyte)); 459 err = ds_recv_data(dev, &rbyte, sizeof(rbyte));
458 if (err < 0) 460 if (err < 0)
459 return err; 461 return err;
460 462
461 ds_start_pulse(dev, PULLUP_PULSE_DURATION); 463 ds_start_pulse(dev, PULLUP_PULSE_DURATION);
462 464
463 return !(byte == rbyte); 465 return !(byte == rbyte);
@@ -470,11 +472,11 @@ int ds_read_bit(struct ds_device *dev, u8 *bit)
470 err = ds_send_control_mode(dev, MOD_PULSE_EN, PULSE_SPUE); 472 err = ds_send_control_mode(dev, MOD_PULSE_EN, PULSE_SPUE);
471 if (err) 473 if (err)
472 return err; 474 return err;
473 475
474 err = ds_send_control(dev, COMM_BIT_IO | COMM_IM | COMM_SPU | COMM_D, 0); 476 err = ds_send_control(dev, COMM_BIT_IO | COMM_IM | COMM_SPU | COMM_D, 0);
475 if (err) 477 if (err)
476 return err; 478 return err;
477 479
478 err = ds_recv_data(dev, bit, sizeof(*bit)); 480 err = ds_recv_data(dev, bit, sizeof(*bit));
479 if (err < 0) 481 if (err < 0)
480 return err; 482 return err;
@@ -492,7 +494,7 @@ int ds_read_byte(struct ds_device *dev, u8 *byte)
492 return err; 494 return err;
493 495
494 ds_wait_status(dev, &st); 496 ds_wait_status(dev, &st);
495 497
496 err = ds_recv_data(dev, byte, sizeof(*byte)); 498 err = ds_recv_data(dev, byte, sizeof(*byte));
497 if (err < 0) 499 if (err < 0)
498 return err; 500 return err;
@@ -509,17 +511,17 @@ int ds_read_block(struct ds_device *dev, u8 *buf, int len)
509 return -E2BIG; 511 return -E2BIG;
510 512
511 memset(buf, 0xFF, len); 513 memset(buf, 0xFF, len);
512 514
513 err = ds_send_data(dev, buf, len); 515 err = ds_send_data(dev, buf, len);
514 if (err < 0) 516 if (err < 0)
515 return err; 517 return err;
516 518
517 err = ds_send_control(dev, COMM_BLOCK_IO | COMM_IM | COMM_SPU, len); 519 err = ds_send_control(dev, COMM_BLOCK_IO | COMM_IM | COMM_SPU, len);
518 if (err) 520 if (err)
519 return err; 521 return err;
520 522
521 ds_wait_status(dev, &st); 523 ds_wait_status(dev, &st);
522 524
523 memset(buf, 0x00, len); 525 memset(buf, 0x00, len);
524 err = ds_recv_data(dev, buf, len); 526 err = ds_recv_data(dev, buf, len);
525 527
@@ -530,11 +532,11 @@ int ds_write_block(struct ds_device *dev, u8 *buf, int len)
530{ 532{
531 int err; 533 int err;
532 struct ds_status st; 534 struct ds_status st;
533 535
534 err = ds_send_data(dev, buf, len); 536 err = ds_send_data(dev, buf, len);
535 if (err < 0) 537 if (err < 0)
536 return err; 538 return err;
537 539
538 ds_wait_status(dev, &st); 540 ds_wait_status(dev, &st);
539 541
540 err = ds_send_control(dev, COMM_BLOCK_IO | COMM_IM | COMM_SPU, len); 542 err = ds_send_control(dev, COMM_BLOCK_IO | COMM_IM | COMM_SPU, len);
@@ -548,10 +550,12 @@ int ds_write_block(struct ds_device *dev, u8 *buf, int len)
548 return err; 550 return err;
549 551
550 ds_start_pulse(dev, PULLUP_PULSE_DURATION); 552 ds_start_pulse(dev, PULLUP_PULSE_DURATION);
551 553
552 return !(err == len); 554 return !(err == len);
553} 555}
554 556
557#if 0
558
555int ds_search(struct ds_device *dev, u64 init, u64 *buf, u8 id_number, int conditional_search) 559int ds_search(struct ds_device *dev, u64 init, u64 *buf, u8 id_number, int conditional_search)
556{ 560{
557 int err; 561 int err;
@@ -559,11 +563,11 @@ int ds_search(struct ds_device *dev, u64 init, u64 *buf, u8 id_number, int condi
559 struct ds_status st; 563 struct ds_status st;
560 564
561 memset(buf, 0, sizeof(buf)); 565 memset(buf, 0, sizeof(buf));
562 566
563 err = ds_send_data(ds_dev, (unsigned char *)&init, 8); 567 err = ds_send_data(ds_dev, (unsigned char *)&init, 8);
564 if (err) 568 if (err)
565 return err; 569 return err;
566 570
567 ds_wait_status(ds_dev, &st); 571 ds_wait_status(ds_dev, &st);
568 572
569 value = COMM_SEARCH_ACCESS | COMM_IM | COMM_SM | COMM_F | COMM_RTS; 573 value = COMM_SEARCH_ACCESS | COMM_IM | COMM_SM | COMM_F | COMM_RTS;
@@ -589,7 +593,7 @@ int ds_match_access(struct ds_device *dev, u64 init)
589 err = ds_send_data(dev, (unsigned char *)&init, sizeof(init)); 593 err = ds_send_data(dev, (unsigned char *)&init, sizeof(init));
590 if (err) 594 if (err)
591 return err; 595 return err;
592 596
593 ds_wait_status(dev, &st); 597 ds_wait_status(dev, &st);
594 598
595 err = ds_send_control(dev, COMM_MATCH_ACCESS | COMM_IM | COMM_RST, 0x0055); 599 err = ds_send_control(dev, COMM_MATCH_ACCESS | COMM_IM | COMM_RST, 0x0055);
@@ -609,11 +613,11 @@ int ds_set_path(struct ds_device *dev, u64 init)
609 613
610 memcpy(buf, &init, 8); 614 memcpy(buf, &init, 8);
611 buf[8] = BRANCH_MAIN; 615 buf[8] = BRANCH_MAIN;
612 616
613 err = ds_send_data(dev, buf, sizeof(buf)); 617 err = ds_send_data(dev, buf, sizeof(buf));
614 if (err) 618 if (err)
615 return err; 619 return err;
616 620
617 ds_wait_status(dev, &st); 621 ds_wait_status(dev, &st);
618 622
619 err = ds_send_control(dev, COMM_SET_PATH | COMM_IM | COMM_RST, 0); 623 err = ds_send_control(dev, COMM_SET_PATH | COMM_IM | COMM_RST, 0);
@@ -625,7 +629,10 @@ int ds_set_path(struct ds_device *dev, u64 init)
625 return 0; 629 return 0;
626} 630}
627 631
628int ds_probe(struct usb_interface *intf, const struct usb_device_id *udev_id) 632#endif /* 0 */
633
634static int ds_probe(struct usb_interface *intf,
635 const struct usb_device_id *udev_id)
629{ 636{
630 struct usb_device *udev = interface_to_usbdev(intf); 637 struct usb_device *udev = interface_to_usbdev(intf);
631 struct usb_endpoint_descriptor *endpoint; 638 struct usb_endpoint_descriptor *endpoint;
@@ -653,7 +660,7 @@ int ds_probe(struct usb_interface *intf, const struct usb_device_id *udev_id)
653 printk(KERN_ERR "Failed to reset configuration: err=%d.\n", err); 660 printk(KERN_ERR "Failed to reset configuration: err=%d.\n", err);
654 return err; 661 return err;
655 } 662 }
656 663
657 iface_desc = &intf->altsetting[0]; 664 iface_desc = &intf->altsetting[0];
658 if (iface_desc->desc.bNumEndpoints != NUM_EP-1) { 665 if (iface_desc->desc.bNumEndpoints != NUM_EP-1) {
659 printk(KERN_INFO "Num endpoints=%d. It is not DS9490R.\n", iface_desc->desc.bNumEndpoints); 666 printk(KERN_INFO "Num endpoints=%d. It is not DS9490R.\n", iface_desc->desc.bNumEndpoints);
@@ -662,37 +669,37 @@ int ds_probe(struct usb_interface *intf, const struct usb_device_id *udev_id)
662 669
663 atomic_set(&ds_dev->refcnt, 0); 670 atomic_set(&ds_dev->refcnt, 0);
664 memset(ds_dev->ep, 0, sizeof(ds_dev->ep)); 671 memset(ds_dev->ep, 0, sizeof(ds_dev->ep));
665 672
666 /* 673 /*
667 * This loop doesn'd show control 0 endpoint, 674 * This loop doesn'd show control 0 endpoint,
668 * so we will fill only 1-3 endpoints entry. 675 * so we will fill only 1-3 endpoints entry.
669 */ 676 */
670 for (i = 0; i < iface_desc->desc.bNumEndpoints; ++i) { 677 for (i = 0; i < iface_desc->desc.bNumEndpoints; ++i) {
671 endpoint = &iface_desc->endpoint[i].desc; 678 endpoint = &iface_desc->endpoint[i].desc;
672 679
673 ds_dev->ep[i+1] = endpoint->bEndpointAddress; 680 ds_dev->ep[i+1] = endpoint->bEndpointAddress;
674 681
675 printk("%d: addr=%x, size=%d, dir=%s, type=%x\n", 682 printk("%d: addr=%x, size=%d, dir=%s, type=%x\n",
676 i, endpoint->bEndpointAddress, le16_to_cpu(endpoint->wMaxPacketSize), 683 i, endpoint->bEndpointAddress, le16_to_cpu(endpoint->wMaxPacketSize),
677 (endpoint->bEndpointAddress & USB_DIR_IN)?"IN":"OUT", 684 (endpoint->bEndpointAddress & USB_DIR_IN)?"IN":"OUT",
678 endpoint->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK); 685 endpoint->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK);
679 } 686 }
680 687
681#if 0 688#if 0
682 { 689 {
683 int err, i; 690 int err, i;
684 u64 buf[3]; 691 u64 buf[3];
685 u64 init=0xb30000002078ee81ull; 692 u64 init=0xb30000002078ee81ull;
686 struct ds_status st; 693 struct ds_status st;
687 694
688 ds_reset(ds_dev, &st); 695 ds_reset(ds_dev, &st);
689 err = ds_search(ds_dev, init, buf, 3, 0); 696 err = ds_search(ds_dev, init, buf, 3, 0);
690 if (err < 0) 697 if (err < 0)
691 return err; 698 return err;
692 for (i=0; i<err; ++i) 699 for (i=0; i<err; ++i)
693 printk("%d: %llx\n", i, buf[i]); 700 printk("%d: %llx\n", i, buf[i]);
694 701
695 printk("Resetting...\n"); 702 printk("Resetting...\n");
696 ds_reset(ds_dev, &st); 703 ds_reset(ds_dev, &st);
697 printk("Setting path for %llx.\n", init); 704 printk("Setting path for %llx.\n", init);
698 err = ds_set_path(ds_dev, init); 705 err = ds_set_path(ds_dev, init);
@@ -707,12 +714,12 @@ int ds_probe(struct usb_interface *intf, const struct usb_device_id *udev_id)
707 err = ds_search(ds_dev, init, buf, 3, 0); 714 err = ds_search(ds_dev, init, buf, 3, 0);
708 715
709 printk("ds_search() returned %d\n", err); 716 printk("ds_search() returned %d\n", err);
710 717
711 if (err < 0) 718 if (err < 0)
712 return err; 719 return err;
713 for (i=0; i<err; ++i) 720 for (i=0; i<err; ++i)
714 printk("%d: %llx\n", i, buf[i]); 721 printk("%d: %llx\n", i, buf[i]);
715 722
716 return 0; 723 return 0;
717 } 724 }
718#endif 725#endif
@@ -720,10 +727,10 @@ int ds_probe(struct usb_interface *intf, const struct usb_device_id *udev_id)
720 return 0; 727 return 0;
721} 728}
722 729
723void ds_disconnect(struct usb_interface *intf) 730static void ds_disconnect(struct usb_interface *intf)
724{ 731{
725 struct ds_device *dev; 732 struct ds_device *dev;
726 733
727 dev = usb_get_intfdata(intf); 734 dev = usb_get_intfdata(intf);
728 usb_set_intfdata(intf, NULL); 735 usb_set_intfdata(intf, NULL);
729 736
@@ -740,7 +747,7 @@ void ds_disconnect(struct usb_interface *intf)
740 ds_dev = NULL; 747 ds_dev = NULL;
741} 748}
742 749
743int ds_init(void) 750static int ds_init(void)
744{ 751{
745 int err; 752 int err;
746 753
@@ -753,7 +760,7 @@ int ds_init(void)
753 return 0; 760 return 0;
754} 761}
755 762
756void ds_fini(void) 763static void ds_fini(void)
757{ 764{
758 usb_deregister(&ds_driver); 765 usb_deregister(&ds_driver);
759} 766}
@@ -776,8 +783,8 @@ EXPORT_SYMBOL(ds_get_device);
776EXPORT_SYMBOL(ds_put_device); 783EXPORT_SYMBOL(ds_put_device);
777 784
778/* 785/*
779 * This functions can be used for EEPROM programming, 786 * This functions can be used for EEPROM programming,
780 * when driver will be included into mainline this will 787 * when driver will be included into mainline this will
781 * require uncommenting. 788 * require uncommenting.
782 */ 789 */
783#if 0 790#if 0
diff --git a/drivers/w1/dscore.h b/drivers/w1/dscore.h
index 9c767ef4ac24..6cf5671d6ebe 100644
--- a/drivers/w1/dscore.h
+++ b/drivers/w1/dscore.h
@@ -1,8 +1,8 @@
1/* 1/*
2 * dscore.h 2 * dscore.h
3 * 3 *
4 * Copyright (c) 2004 Evgeniy Polyakov <johnpol@2ka.mipt.ru> 4 * Copyright (c) 2004 Evgeniy Polyakov <johnpol@2ka.mipt.ru>
5 * 5 *
6 * 6 *
7 * This program is free software; you can redistribute it and/or modify 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 8 * it under the terms of the GNU General Public License as published by
@@ -122,7 +122,7 @@
122 122
123struct ds_device 123struct ds_device
124{ 124{
125 struct usb_device *udev; 125 struct usb_device *udev;
126 struct usb_interface *intf; 126 struct usb_interface *intf;
127 127
128 int ep[NUM_EP]; 128 int ep[NUM_EP];
@@ -156,11 +156,7 @@ int ds_read_byte(struct ds_device *, u8 *);
156int ds_read_bit(struct ds_device *, u8 *); 156int ds_read_bit(struct ds_device *, u8 *);
157int ds_write_byte(struct ds_device *, u8); 157int ds_write_byte(struct ds_device *, u8);
158int ds_write_bit(struct ds_device *, u8); 158int ds_write_bit(struct ds_device *, u8);
159int ds_start_pulse(struct ds_device *, int);
160int ds_set_speed(struct ds_device *, int);
161int ds_reset(struct ds_device *, struct ds_status *); 159int ds_reset(struct ds_device *, struct ds_status *);
162int ds_detect(struct ds_device *, struct ds_status *);
163int ds_stop_pulse(struct ds_device *, int);
164struct ds_device * ds_get_device(void); 160struct ds_device * ds_get_device(void);
165void ds_put_device(struct ds_device *); 161void ds_put_device(struct ds_device *);
166int ds_write_block(struct ds_device *, u8 *, int); 162int ds_write_block(struct ds_device *, u8 *, int);
diff --git a/drivers/w1/w1.c b/drivers/w1/w1.c
index 0bbf029b1ef1..1b6b74c116a9 100644
--- a/drivers/w1/w1.c
+++ b/drivers/w1/w1.c
@@ -45,10 +45,12 @@ MODULE_AUTHOR("Evgeniy Polyakov <johnpol@2ka.mipt.ru>");
45MODULE_DESCRIPTION("Driver for 1-wire Dallas network protocol."); 45MODULE_DESCRIPTION("Driver for 1-wire Dallas network protocol.");
46 46
47static int w1_timeout = 10; 47static int w1_timeout = 10;
48static int w1_control_timeout = 1;
48int w1_max_slave_count = 10; 49int w1_max_slave_count = 10;
49int w1_max_slave_ttl = 10; 50int w1_max_slave_ttl = 10;
50 51
51module_param_named(timeout, w1_timeout, int, 0); 52module_param_named(timeout, w1_timeout, int, 0);
53module_param_named(control_timeout, w1_control_timeout, int, 0);
52module_param_named(max_slave_count, w1_max_slave_count, int, 0); 54module_param_named(max_slave_count, w1_max_slave_count, int, 0);
53module_param_named(slave_ttl, w1_max_slave_ttl, int, 0); 55module_param_named(slave_ttl, w1_max_slave_ttl, int, 0);
54 56
@@ -59,19 +61,6 @@ static pid_t control_thread;
59static int control_needs_exit; 61static int control_needs_exit;
60static DECLARE_COMPLETION(w1_control_complete); 62static DECLARE_COMPLETION(w1_control_complete);
61 63
62/* stuff for the default family */
63static ssize_t w1_famdefault_read_name(struct device *dev, struct device_attribute *attr, char *buf)
64{
65 struct w1_slave *sl = container_of(dev, struct w1_slave, dev);
66 return(sprintf(buf, "%s\n", sl->name));
67}
68static struct w1_family_ops w1_default_fops = {
69 .rname = &w1_famdefault_read_name,
70};
71static struct w1_family w1_default_family = {
72 .fops = &w1_default_fops,
73};
74
75static int w1_master_match(struct device *dev, struct device_driver *drv) 64static int w1_master_match(struct device *dev, struct device_driver *drv)
76{ 65{
77 return 1; 66 return 1;
@@ -82,73 +71,116 @@ static int w1_master_probe(struct device *dev)
82 return -ENODEV; 71 return -ENODEV;
83} 72}
84 73
85static int w1_master_remove(struct device *dev)
86{
87 return 0;
88}
89
90static void w1_master_release(struct device *dev) 74static void w1_master_release(struct device *dev)
91{ 75{
92 struct w1_master *md = container_of(dev, struct w1_master, dev); 76 struct w1_master *md = dev_to_w1_master(dev);
93 77
94 complete(&md->dev_released); 78 dev_dbg(dev, "%s: Releasing %s.\n", __func__, md->name);
79
80 if (md->nls && md->nls->sk_socket)
81 sock_release(md->nls->sk_socket);
82 memset(md, 0, sizeof(struct w1_master) + sizeof(struct w1_bus_master));
83 kfree(md);
95} 84}
96 85
97static void w1_slave_release(struct device *dev) 86static void w1_slave_release(struct device *dev)
98{ 87{
99 struct w1_slave *sl = container_of(dev, struct w1_slave, dev); 88 struct w1_slave *sl = dev_to_w1_slave(dev);
89
90 dev_dbg(dev, "%s: Releasing %s.\n", __func__, sl->name);
91
92 while (atomic_read(&sl->refcnt)) {
93 dev_dbg(dev, "Waiting for %s to become free: refcnt=%d.\n",
94 sl->name, atomic_read(&sl->refcnt));
95 if (msleep_interruptible(1000))
96 flush_signals(current);
97 }
98
99 w1_family_put(sl->family);
100 sl->master->slave_count--;
100 101
101 complete(&sl->dev_released); 102 complete(&sl->released);
102} 103}
103 104
104static ssize_t w1_default_read_name(struct device *dev, struct device_attribute *attr, char *buf) 105static ssize_t w1_slave_read_name(struct device *dev, struct device_attribute *attr, char *buf)
105{ 106{
106 return sprintf(buf, "No family registered.\n"); 107 struct w1_slave *sl = dev_to_w1_slave(dev);
108
109 return sprintf(buf, "%s\n", sl->name);
107} 110}
108 111
109static ssize_t w1_default_read_bin(struct kobject *kobj, char *buf, loff_t off, 112static ssize_t w1_slave_read_id(struct kobject *kobj, char *buf, loff_t off, size_t count)
110 size_t count)
111{ 113{
112 return sprintf(buf, "No family registered.\n"); 114 struct w1_slave *sl = kobj_to_w1_slave(kobj);
115
116 atomic_inc(&sl->refcnt);
117 if (off > 8) {
118 count = 0;
119 } else {
120 if (off + count > 8)
121 count = 8 - off;
122
123 memcpy(buf, (u8 *)&sl->reg_num, count);
124 }
125 atomic_dec(&sl->refcnt);
126
127 return count;
113} 128}
114 129
115static struct device_attribute w1_slave_attribute = 130static struct device_attribute w1_slave_attr_name =
116 __ATTR(name, S_IRUGO, w1_default_read_name, NULL); 131 __ATTR(name, S_IRUGO, w1_slave_read_name, NULL);
117 132
118static struct bin_attribute w1_slave_bin_attribute = { 133static struct bin_attribute w1_slave_attr_bin_id = {
119 .attr = { 134 .attr = {
120 .name = "w1_slave", 135 .name = "id",
121 .mode = S_IRUGO, 136 .mode = S_IRUGO,
122 .owner = THIS_MODULE, 137 .owner = THIS_MODULE,
123 }, 138 },
124 .size = W1_SLAVE_DATA_SIZE, 139 .size = 8,
125 .read = &w1_default_read_bin, 140 .read = w1_slave_read_id,
126}; 141};
127 142
143/* Default family */
144static struct w1_family w1_default_family;
145
146static int w1_hotplug(struct device *dev, char **envp, int num_envp, char *buffer, int buffer_size);
128 147
129static struct bus_type w1_bus_type = { 148static struct bus_type w1_bus_type = {
130 .name = "w1", 149 .name = "w1",
131 .match = w1_master_match, 150 .match = w1_master_match,
151 .hotplug = w1_hotplug,
132}; 152};
133 153
134struct device_driver w1_driver = { 154struct device_driver w1_master_driver = {
135 .name = "w1_driver", 155 .name = "w1_master_driver",
136 .bus = &w1_bus_type, 156 .bus = &w1_bus_type,
137 .probe = w1_master_probe, 157 .probe = w1_master_probe,
138 .remove = w1_master_remove,
139}; 158};
140 159
141struct device w1_device = { 160struct device w1_master_device = {
142 .parent = NULL, 161 .parent = NULL,
143 .bus = &w1_bus_type, 162 .bus = &w1_bus_type,
144 .bus_id = "w1 bus master", 163 .bus_id = "w1 bus master",
145 .driver = &w1_driver, 164 .driver = &w1_master_driver,
146 .release = &w1_master_release 165 .release = &w1_master_release
147}; 166};
148 167
168struct device_driver w1_slave_driver = {
169 .name = "w1_slave_driver",
170 .bus = &w1_bus_type,
171};
172
173struct device w1_slave_device = {
174 .parent = NULL,
175 .bus = &w1_bus_type,
176 .bus_id = "w1 bus slave",
177 .driver = &w1_slave_driver,
178 .release = &w1_slave_release
179};
180
149static ssize_t w1_master_attribute_show_name(struct device *dev, struct device_attribute *attr, char *buf) 181static ssize_t w1_master_attribute_show_name(struct device *dev, struct device_attribute *attr, char *buf)
150{ 182{
151 struct w1_master *md = container_of(dev, struct w1_master, dev); 183 struct w1_master *md = dev_to_w1_master(dev);
152 ssize_t count; 184 ssize_t count;
153 185
154 if (down_interruptible (&md->mutex)) 186 if (down_interruptible (&md->mutex))
@@ -165,7 +197,7 @@ static ssize_t w1_master_attribute_store_search(struct device * dev,
165 struct device_attribute *attr, 197 struct device_attribute *attr,
166 const char * buf, size_t count) 198 const char * buf, size_t count)
167{ 199{
168 struct w1_master *md = container_of(dev, struct w1_master, dev); 200 struct w1_master *md = dev_to_w1_master(dev);
169 201
170 if (down_interruptible (&md->mutex)) 202 if (down_interruptible (&md->mutex))
171 return -EBUSY; 203 return -EBUSY;
@@ -181,7 +213,7 @@ static ssize_t w1_master_attribute_show_search(struct device *dev,
181 struct device_attribute *attr, 213 struct device_attribute *attr,
182 char *buf) 214 char *buf)
183{ 215{
184 struct w1_master *md = container_of(dev, struct w1_master, dev); 216 struct w1_master *md = dev_to_w1_master(dev);
185 ssize_t count; 217 ssize_t count;
186 218
187 if (down_interruptible (&md->mutex)) 219 if (down_interruptible (&md->mutex))
@@ -196,7 +228,7 @@ static ssize_t w1_master_attribute_show_search(struct device *dev,
196 228
197static ssize_t w1_master_attribute_show_pointer(struct device *dev, struct device_attribute *attr, char *buf) 229static ssize_t w1_master_attribute_show_pointer(struct device *dev, struct device_attribute *attr, char *buf)
198{ 230{
199 struct w1_master *md = container_of(dev, struct w1_master, dev); 231 struct w1_master *md = dev_to_w1_master(dev);
200 ssize_t count; 232 ssize_t count;
201 233
202 if (down_interruptible(&md->mutex)) 234 if (down_interruptible(&md->mutex))
@@ -217,7 +249,7 @@ static ssize_t w1_master_attribute_show_timeout(struct device *dev, struct devic
217 249
218static ssize_t w1_master_attribute_show_max_slave_count(struct device *dev, struct device_attribute *attr, char *buf) 250static ssize_t w1_master_attribute_show_max_slave_count(struct device *dev, struct device_attribute *attr, char *buf)
219{ 251{
220 struct w1_master *md = container_of(dev, struct w1_master, dev); 252 struct w1_master *md = dev_to_w1_master(dev);
221 ssize_t count; 253 ssize_t count;
222 254
223 if (down_interruptible(&md->mutex)) 255 if (down_interruptible(&md->mutex))
@@ -231,7 +263,7 @@ static ssize_t w1_master_attribute_show_max_slave_count(struct device *dev, stru
231 263
232static ssize_t w1_master_attribute_show_attempts(struct device *dev, struct device_attribute *attr, char *buf) 264static ssize_t w1_master_attribute_show_attempts(struct device *dev, struct device_attribute *attr, char *buf)
233{ 265{
234 struct w1_master *md = container_of(dev, struct w1_master, dev); 266 struct w1_master *md = dev_to_w1_master(dev);
235 ssize_t count; 267 ssize_t count;
236 268
237 if (down_interruptible(&md->mutex)) 269 if (down_interruptible(&md->mutex))
@@ -245,7 +277,7 @@ static ssize_t w1_master_attribute_show_attempts(struct device *dev, struct devi
245 277
246static ssize_t w1_master_attribute_show_slave_count(struct device *dev, struct device_attribute *attr, char *buf) 278static ssize_t w1_master_attribute_show_slave_count(struct device *dev, struct device_attribute *attr, char *buf)
247{ 279{
248 struct w1_master *md = container_of(dev, struct w1_master, dev); 280 struct w1_master *md = dev_to_w1_master(dev);
249 ssize_t count; 281 ssize_t count;
250 282
251 if (down_interruptible(&md->mutex)) 283 if (down_interruptible(&md->mutex))
@@ -259,7 +291,7 @@ static ssize_t w1_master_attribute_show_slave_count(struct device *dev, struct d
259 291
260static ssize_t w1_master_attribute_show_slaves(struct device *dev, struct device_attribute *attr, char *buf) 292static ssize_t w1_master_attribute_show_slaves(struct device *dev, struct device_attribute *attr, char *buf)
261{ 293{
262 struct w1_master *md = container_of(dev, struct w1_master, dev); 294 struct w1_master *md = dev_to_w1_master(dev);
263 int c = PAGE_SIZE; 295 int c = PAGE_SIZE;
264 296
265 if (down_interruptible(&md->mutex)) 297 if (down_interruptible(&md->mutex))
@@ -329,12 +361,55 @@ void w1_destroy_master_attributes(struct w1_master *master)
329 sysfs_remove_group(&master->dev.kobj, &w1_master_defattr_group); 361 sysfs_remove_group(&master->dev.kobj, &w1_master_defattr_group);
330} 362}
331 363
364#ifdef CONFIG_HOTPLUG
365static int w1_hotplug(struct device *dev, char **envp, int num_envp, char *buffer, int buffer_size)
366{
367 struct w1_master *md = NULL;
368 struct w1_slave *sl = NULL;
369 char *event_owner, *name;
370 int err, cur_index=0, cur_len=0;
371
372 if (dev->driver == &w1_master_driver) {
373 md = container_of(dev, struct w1_master, dev);
374 event_owner = "master";
375 name = md->name;
376 } else if (dev->driver == &w1_slave_driver) {
377 sl = container_of(dev, struct w1_slave, dev);
378 event_owner = "slave";
379 name = sl->name;
380 } else {
381 dev_dbg(dev, "Unknown hotplug event.\n");
382 return -EINVAL;
383 }
384
385 dev_dbg(dev, "Hotplug event for %s %s, bus_id=%s.\n", event_owner, name, dev->bus_id);
386
387 if (dev->driver != &w1_slave_driver || !sl)
388 return 0;
389
390 err = add_hotplug_env_var(envp, num_envp, &cur_index, buffer, buffer_size, &cur_len, "W1_FID=%02X", sl->reg_num.family);
391 if (err)
392 return err;
393
394 err = add_hotplug_env_var(envp, num_envp, &cur_index, buffer, buffer_size, &cur_len, "W1_SLAVE_ID=%024LX", (u64)sl->reg_num.id);
395 if (err)
396 return err;
397
398 return 0;
399};
400#else
401static int w1_hotplug(struct device *dev, char **envp, int num_envp, char *buffer, int buffer_size)
402{
403 return 0;
404}
405#endif
406
332static int __w1_attach_slave_device(struct w1_slave *sl) 407static int __w1_attach_slave_device(struct w1_slave *sl)
333{ 408{
334 int err; 409 int err;
335 410
336 sl->dev.parent = &sl->master->dev; 411 sl->dev.parent = &sl->master->dev;
337 sl->dev.driver = sl->master->driver; 412 sl->dev.driver = &w1_slave_driver;
338 sl->dev.bus = &w1_bus_type; 413 sl->dev.bus = &w1_bus_type;
339 sl->dev.release = &w1_slave_release; 414 sl->dev.release = &w1_slave_release;
340 415
@@ -347,8 +422,7 @@ static int __w1_attach_slave_device(struct w1_slave *sl)
347 (unsigned int) sl->reg_num.family, 422 (unsigned int) sl->reg_num.family,
348 (unsigned long long) sl->reg_num.id); 423 (unsigned long long) sl->reg_num.id);
349 424
350 dev_dbg(&sl->dev, "%s: registering %s.\n", __func__, 425 dev_dbg(&sl->dev, "%s: registering %s as %p.\n", __func__, &sl->dev.bus_id[0]);
351 &sl->dev.bus_id[0]);
352 426
353 err = device_register(&sl->dev); 427 err = device_register(&sl->dev);
354 if (err < 0) { 428 if (err < 0) {
@@ -358,36 +432,44 @@ static int __w1_attach_slave_device(struct w1_slave *sl)
358 return err; 432 return err;
359 } 433 }
360 434
361 memcpy(&sl->attr_bin, &w1_slave_bin_attribute, sizeof(sl->attr_bin)); 435 /* Create "name" entry */
362 memcpy(&sl->attr_name, &w1_slave_attribute, sizeof(sl->attr_name)); 436 err = device_create_file(&sl->dev, &w1_slave_attr_name);
363 437 if (err < 0) {
364 sl->attr_bin.read = sl->family->fops->rbin; 438 dev_err(&sl->dev,
365 sl->attr_name.show = sl->family->fops->rname; 439 "sysfs file creation for [%s] failed. err=%d\n",
440 sl->dev.bus_id, err);
441 goto out_unreg;
442 }
366 443
367 err = device_create_file(&sl->dev, &sl->attr_name); 444 /* Create "id" entry */
445 err = sysfs_create_bin_file(&sl->dev.kobj, &w1_slave_attr_bin_id);
368 if (err < 0) { 446 if (err < 0) {
369 dev_err(&sl->dev, 447 dev_err(&sl->dev,
370 "sysfs file creation for [%s] failed. err=%d\n", 448 "sysfs file creation for [%s] failed. err=%d\n",
371 sl->dev.bus_id, err); 449 sl->dev.bus_id, err);
372 device_unregister(&sl->dev); 450 goto out_rem1;
373 return err;
374 } 451 }
375 452
376 if ( sl->attr_bin.read ) { 453 /* if the family driver needs to initialize something... */
377 err = sysfs_create_bin_file(&sl->dev.kobj, &sl->attr_bin); 454 if (sl->family->fops && sl->family->fops->add_slave &&
378 if (err < 0) { 455 ((err = sl->family->fops->add_slave(sl)) < 0)) {
379 dev_err(&sl->dev, 456 dev_err(&sl->dev,
380 "sysfs file creation for [%s] failed. err=%d\n", 457 "sysfs file creation for [%s] failed. err=%d\n",
381 sl->dev.bus_id, err); 458 sl->dev.bus_id, err);
382 device_remove_file(&sl->dev, &sl->attr_name); 459 goto out_rem2;
383 device_unregister(&sl->dev);
384 return err;
385 }
386 } 460 }
387 461
388 list_add_tail(&sl->w1_slave_entry, &sl->master->slist); 462 list_add_tail(&sl->w1_slave_entry, &sl->master->slist);
389 463
390 return 0; 464 return 0;
465
466out_rem2:
467 sysfs_remove_bin_file(&sl->dev.kobj, &w1_slave_attr_bin_id);
468out_rem1:
469 device_remove_file(&sl->dev, &w1_slave_attr_name);
470out_unreg:
471 device_unregister(&sl->dev);
472 return err;
391} 473}
392 474
393static int w1_attach_slave_device(struct w1_master *dev, struct w1_reg_num *rn) 475static int w1_attach_slave_device(struct w1_master *dev, struct w1_reg_num *rn)
@@ -413,7 +495,7 @@ static int w1_attach_slave_device(struct w1_master *dev, struct w1_reg_num *rn)
413 495
414 memcpy(&sl->reg_num, rn, sizeof(sl->reg_num)); 496 memcpy(&sl->reg_num, rn, sizeof(sl->reg_num));
415 atomic_set(&sl->refcnt, 0); 497 atomic_set(&sl->refcnt, 0);
416 init_completion(&sl->dev_released); 498 init_completion(&sl->released);
417 499
418 spin_lock(&w1_flock); 500 spin_lock(&w1_flock);
419 f = w1_family_registered(rn->family); 501 f = w1_family_registered(rn->family);
@@ -452,28 +534,23 @@ static void w1_slave_detach(struct w1_slave *sl)
452{ 534{
453 struct w1_netlink_msg msg; 535 struct w1_netlink_msg msg;
454 536
455 dev_info(&sl->dev, "%s: detaching %s.\n", __func__, sl->name); 537 dev_dbg(&sl->dev, "%s: detaching %s [%p].\n", __func__, sl->name, sl);
456
457 while (atomic_read(&sl->refcnt)) {
458 printk(KERN_INFO "Waiting for %s to become free: refcnt=%d.\n",
459 sl->name, atomic_read(&sl->refcnt));
460 538
461 if (msleep_interruptible(1000)) 539 list_del(&sl->w1_slave_entry);
462 flush_signals(current);
463 }
464
465 if ( sl->attr_bin.read ) {
466 sysfs_remove_bin_file (&sl->dev.kobj, &sl->attr_bin);
467 }
468 device_remove_file(&sl->dev, &sl->attr_name);
469 device_unregister(&sl->dev);
470 w1_family_put(sl->family);
471 540
472 sl->master->slave_count--; 541 if (sl->family->fops && sl->family->fops->remove_slave)
542 sl->family->fops->remove_slave(sl);
473 543
474 memcpy(&msg.id.id, &sl->reg_num, sizeof(msg.id.id)); 544 memcpy(&msg.id.id, &sl->reg_num, sizeof(msg.id.id));
475 msg.type = W1_SLAVE_REMOVE; 545 msg.type = W1_SLAVE_REMOVE;
476 w1_netlink_send(sl->master, &msg); 546 w1_netlink_send(sl->master, &msg);
547
548 sysfs_remove_bin_file(&sl->dev.kobj, &w1_slave_attr_bin_id);
549 device_remove_file(&sl->dev, &w1_slave_attr_name);
550 device_unregister(&sl->dev);
551
552 wait_for_completion(&sl->released);
553 kfree(sl);
477} 554}
478 555
479static struct w1_master *w1_search_master(unsigned long data) 556static struct w1_master *w1_search_master(unsigned long data)
@@ -500,14 +577,13 @@ void w1_reconnect_slaves(struct w1_family *f)
500 577
501 spin_lock_bh(&w1_mlock); 578 spin_lock_bh(&w1_mlock);
502 list_for_each_entry(dev, &w1_masters, w1_master_entry) { 579 list_for_each_entry(dev, &w1_masters, w1_master_entry) {
503 dev_info(&dev->dev, "Reconnecting slaves in %s into new family %02x.\n", 580 dev_dbg(&dev->dev, "Reconnecting slaves in %s into new family %02x.\n",
504 dev->name, f->fid); 581 dev->name, f->fid);
505 set_bit(W1_MASTER_NEED_RECONNECT, &dev->flags); 582 set_bit(W1_MASTER_NEED_RECONNECT, &dev->flags);
506 } 583 }
507 spin_unlock_bh(&w1_mlock); 584 spin_unlock_bh(&w1_mlock);
508} 585}
509 586
510
511static void w1_slave_found(unsigned long data, u64 rn) 587static void w1_slave_found(unsigned long data, u64 rn)
512{ 588{
513 int slave_count; 589 int slave_count;
@@ -646,7 +722,7 @@ static int w1_control(void *data)
646 have_to_wait = 0; 722 have_to_wait = 0;
647 723
648 try_to_freeze(); 724 try_to_freeze();
649 msleep_interruptible(w1_timeout * 1000); 725 msleep_interruptible(w1_control_timeout * 1000);
650 726
651 if (signal_pending(current)) 727 if (signal_pending(current))
652 flush_signals(current); 728 flush_signals(current);
@@ -679,33 +755,30 @@ static int w1_control(void *data)
679 list_del(&dev->w1_master_entry); 755 list_del(&dev->w1_master_entry);
680 spin_unlock_bh(&w1_mlock); 756 spin_unlock_bh(&w1_mlock);
681 757
758 down(&dev->mutex);
682 list_for_each_entry_safe(sl, sln, &dev->slist, w1_slave_entry) { 759 list_for_each_entry_safe(sl, sln, &dev->slist, w1_slave_entry) {
683 list_del(&sl->w1_slave_entry);
684
685 w1_slave_detach(sl); 760 w1_slave_detach(sl);
686 kfree(sl);
687 } 761 }
688 w1_destroy_master_attributes(dev); 762 w1_destroy_master_attributes(dev);
763 up(&dev->mutex);
689 atomic_dec(&dev->refcnt); 764 atomic_dec(&dev->refcnt);
690 continue; 765 continue;
691 } 766 }
692 767
693 if (test_bit(W1_MASTER_NEED_RECONNECT, &dev->flags)) { 768 if (test_bit(W1_MASTER_NEED_RECONNECT, &dev->flags)) {
694 dev_info(&dev->dev, "Reconnecting slaves in device %s.\n", dev->name); 769 dev_dbg(&dev->dev, "Reconnecting slaves in device %s.\n", dev->name);
695 down(&dev->mutex); 770 down(&dev->mutex);
696 list_for_each_entry(sl, &dev->slist, w1_slave_entry) { 771 list_for_each_entry_safe(sl, sln, &dev->slist, w1_slave_entry) {
697 if (sl->family->fid == W1_FAMILY_DEFAULT) { 772 if (sl->family->fid == W1_FAMILY_DEFAULT) {
698 struct w1_reg_num rn; 773 struct w1_reg_num rn;
699 list_del(&sl->w1_slave_entry);
700 w1_slave_detach(sl);
701 774
702 memcpy(&rn, &sl->reg_num, sizeof(rn)); 775 memcpy(&rn, &sl->reg_num, sizeof(rn));
703 776 w1_slave_detach(sl);
704 kfree(sl);
705 777
706 w1_attach_slave_device(dev, &rn); 778 w1_attach_slave_device(dev, &rn);
707 } 779 }
708 } 780 }
781 dev_dbg(&dev->dev, "Reconnecting slaves in device %s has been finished.\n", dev->name);
709 clear_bit(W1_MASTER_NEED_RECONNECT, &dev->flags); 782 clear_bit(W1_MASTER_NEED_RECONNECT, &dev->flags);
710 up(&dev->mutex); 783 up(&dev->mutex);
711 } 784 }
@@ -749,10 +822,7 @@ int w1_process(void *data)
749 822
750 list_for_each_entry_safe(sl, sln, &dev->slist, w1_slave_entry) { 823 list_for_each_entry_safe(sl, sln, &dev->slist, w1_slave_entry) {
751 if (!test_bit(W1_SLAVE_ACTIVE, (unsigned long *)&sl->flags) && !--sl->ttl) { 824 if (!test_bit(W1_SLAVE_ACTIVE, (unsigned long *)&sl->flags) && !--sl->ttl) {
752 list_del (&sl->w1_slave_entry); 825 w1_slave_detach(sl);
753
754 w1_slave_detach (sl);
755 kfree (sl);
756 826
757 dev->slave_count--; 827 dev->slave_count--;
758 } else if (test_bit(W1_SLAVE_ACTIVE, (unsigned long *)&sl->flags)) 828 } else if (test_bit(W1_SLAVE_ACTIVE, (unsigned long *)&sl->flags))
@@ -783,7 +853,7 @@ static int w1_init(void)
783 goto err_out_exit_init; 853 goto err_out_exit_init;
784 } 854 }
785 855
786 retval = driver_register(&w1_driver); 856 retval = driver_register(&w1_master_driver);
787 if (retval) { 857 if (retval) {
788 printk(KERN_ERR 858 printk(KERN_ERR
789 "Failed to register master driver. err=%d.\n", 859 "Failed to register master driver. err=%d.\n",
@@ -791,18 +861,29 @@ static int w1_init(void)
791 goto err_out_bus_unregister; 861 goto err_out_bus_unregister;
792 } 862 }
793 863
864 retval = driver_register(&w1_slave_driver);
865 if (retval) {
866 printk(KERN_ERR
867 "Failed to register master driver. err=%d.\n",
868 retval);
869 goto err_out_master_unregister;
870 }
871
794 control_thread = kernel_thread(&w1_control, NULL, 0); 872 control_thread = kernel_thread(&w1_control, NULL, 0);
795 if (control_thread < 0) { 873 if (control_thread < 0) {
796 printk(KERN_ERR "Failed to create control thread. err=%d\n", 874 printk(KERN_ERR "Failed to create control thread. err=%d\n",
797 control_thread); 875 control_thread);
798 retval = control_thread; 876 retval = control_thread;
799 goto err_out_driver_unregister; 877 goto err_out_slave_unregister;
800 } 878 }
801 879
802 return 0; 880 return 0;
803 881
804err_out_driver_unregister: 882err_out_slave_unregister:
805 driver_unregister(&w1_driver); 883 driver_unregister(&w1_slave_driver);
884
885err_out_master_unregister:
886 driver_unregister(&w1_master_driver);
806 887
807err_out_bus_unregister: 888err_out_bus_unregister:
808 bus_unregister(&w1_bus_type); 889 bus_unregister(&w1_bus_type);
@@ -821,7 +902,8 @@ static void w1_fini(void)
821 control_needs_exit = 1; 902 control_needs_exit = 1;
822 wait_for_completion(&w1_control_complete); 903 wait_for_completion(&w1_control_complete);
823 904
824 driver_unregister(&w1_driver); 905 driver_unregister(&w1_slave_driver);
906 driver_unregister(&w1_master_driver);
825 bus_unregister(&w1_bus_type); 907 bus_unregister(&w1_bus_type);
826} 908}
827 909
diff --git a/drivers/w1/w1.h b/drivers/w1/w1.h
index 4f0a986e33e3..d8900780c3bf 100644
--- a/drivers/w1/w1.h
+++ b/drivers/w1/w1.h
@@ -75,11 +75,9 @@ struct w1_slave
75 75
76 struct w1_master *master; 76 struct w1_master *master;
77 struct w1_family *family; 77 struct w1_family *family;
78 void *family_data;
78 struct device dev; 79 struct device dev;
79 struct completion dev_released; 80 struct completion released;
80
81 struct bin_attribute attr_bin;
82 struct device_attribute attr_name;
83}; 81};
84 82
85typedef void (* w1_slave_found_callback)(unsigned long, u64); 83typedef void (* w1_slave_found_callback)(unsigned long, u64);
@@ -179,7 +177,6 @@ struct w1_master
179 177
180 struct device_driver *driver; 178 struct device_driver *driver;
181 struct device dev; 179 struct device dev;
182 struct completion dev_released;
183 struct completion dev_exited; 180 struct completion dev_exited;
184 181
185 struct w1_bus_master *bus_master; 182 struct w1_bus_master *bus_master;
@@ -191,6 +188,21 @@ struct w1_master
191int w1_create_master_attributes(struct w1_master *); 188int w1_create_master_attributes(struct w1_master *);
192void w1_search(struct w1_master *dev, w1_slave_found_callback cb); 189void w1_search(struct w1_master *dev, w1_slave_found_callback cb);
193 190
191static inline struct w1_slave* dev_to_w1_slave(struct device *dev)
192{
193 return container_of(dev, struct w1_slave, dev);
194}
195
196static inline struct w1_slave* kobj_to_w1_slave(struct kobject *kobj)
197{
198 return dev_to_w1_slave(container_of(kobj, struct device, kobj));
199}
200
201static inline struct w1_master* dev_to_w1_master(struct device *dev)
202{
203 return container_of(dev, struct w1_master, dev);
204}
205
194#endif /* __KERNEL__ */ 206#endif /* __KERNEL__ */
195 207
196#endif /* __W1_H */ 208#endif /* __W1_H */
diff --git a/drivers/w1/w1_ds2433.c b/drivers/w1/w1_ds2433.c
new file mode 100644
index 000000000000..b7c24b34d270
--- /dev/null
+++ b/drivers/w1/w1_ds2433.c
@@ -0,0 +1,327 @@
1/*
2 * w1_ds2433.c - w1 family 23 (DS2433) driver
3 *
4 * Copyright (c) 2005 Ben Gardner <bgardner@wabtec.com>
5 *
6 * This source code is licensed under the GNU General Public License,
7 * Version 2. See the file COPYING for more details.
8 */
9
10#include <linux/kernel.h>
11#include <linux/module.h>
12#include <linux/moduleparam.h>
13#include <linux/device.h>
14#include <linux/types.h>
15#include <linux/delay.h>
16#ifdef CONFIG_W1_F23_CRC
17#include <linux/crc16.h>
18#endif
19
20#include "w1.h"
21#include "w1_io.h"
22#include "w1_int.h"
23#include "w1_family.h"
24
25MODULE_LICENSE("GPL");
26MODULE_AUTHOR("Ben Gardner <bgardner@wabtec.com>");
27MODULE_DESCRIPTION("w1 family 23 driver for DS2433, 4kb EEPROM");
28
29#define W1_EEPROM_SIZE 512
30#define W1_PAGE_COUNT 16
31#define W1_PAGE_SIZE 32
32#define W1_PAGE_BITS 5
33#define W1_PAGE_MASK 0x1F
34
35#define W1_F23_TIME 300
36
37#define W1_F23_READ_EEPROM 0xF0
38#define W1_F23_WRITE_SCRATCH 0x0F
39#define W1_F23_READ_SCRATCH 0xAA
40#define W1_F23_COPY_SCRATCH 0x55
41
42struct w1_f23_data {
43 u8 memory[W1_EEPROM_SIZE];
44 u32 validcrc;
45};
46
47/**
48 * Check the file size bounds and adjusts count as needed.
49 * This would not be needed if the file size didn't reset to 0 after a write.
50 */
51static inline size_t w1_f23_fix_count(loff_t off, size_t count, size_t size)
52{
53 if (off > size)
54 return 0;
55
56 if ((off + count) > size)
57 return (size - off);
58
59 return count;
60}
61
62#ifdef CONFIG_W1_F23_CRC
63static int w1_f23_refresh_block(struct w1_slave *sl, struct w1_f23_data *data,
64 int block)
65{
66 u8 wrbuf[3];
67 int off = block * W1_PAGE_SIZE;
68
69 if (data->validcrc & (1 << block))
70 return 0;
71
72 if (w1_reset_select_slave(sl)) {
73 data->validcrc = 0;
74 return -EIO;
75 }
76
77 wrbuf[0] = W1_F23_READ_EEPROM;
78 wrbuf[1] = off & 0xff;
79 wrbuf[2] = off >> 8;
80 w1_write_block(sl->master, wrbuf, 3);
81 w1_read_block(sl->master, &data->memory[off], W1_PAGE_SIZE);
82
83 /* cache the block if the CRC is valid */
84 if (crc16(CRC16_INIT, &data->memory[off], W1_PAGE_SIZE) == CRC16_VALID)
85 data->validcrc |= (1 << block);
86
87 return 0;
88}
89#endif /* CONFIG_W1_F23_CRC */
90
91static ssize_t w1_f23_read_bin(struct kobject *kobj, char *buf, loff_t off,
92 size_t count)
93{
94 struct w1_slave *sl = kobj_to_w1_slave(kobj);
95#ifdef CONFIG_W1_F23_CRC
96 struct w1_f23_data *data = sl->family_data;
97 int i, min_page, max_page;
98#else
99 u8 wrbuf[3];
100#endif
101
102 if ((count = w1_f23_fix_count(off, count, W1_EEPROM_SIZE)) == 0)
103 return 0;
104
105 atomic_inc(&sl->refcnt);
106 if (down_interruptible(&sl->master->mutex)) {
107 count = 0;
108 goto out_dec;
109 }
110
111#ifdef CONFIG_W1_F23_CRC
112
113 min_page = (off >> W1_PAGE_BITS);
114 max_page = (off + count - 1) >> W1_PAGE_BITS;
115 for (i = min_page; i <= max_page; i++) {
116 if (w1_f23_refresh_block(sl, data, i)) {
117 count = -EIO;
118 goto out_up;
119 }
120 }
121 memcpy(buf, &data->memory[off], count);
122
123#else /* CONFIG_W1_F23_CRC */
124
125 /* read directly from the EEPROM */
126 if (w1_reset_select_slave(sl)) {
127 count = -EIO;
128 goto out_up;
129 }
130
131 wrbuf[0] = W1_F23_READ_EEPROM;
132 wrbuf[1] = off & 0xff;
133 wrbuf[2] = off >> 8;
134 w1_write_block(sl->master, wrbuf, 3);
135 w1_read_block(sl->master, buf, count);
136
137#endif /* CONFIG_W1_F23_CRC */
138
139out_up:
140 up(&sl->master->mutex);
141out_dec:
142 atomic_dec(&sl->refcnt);
143
144 return count;
145}
146
147/**
148 * Writes to the scratchpad and reads it back for verification.
149 * Then copies the scratchpad to EEPROM.
150 * The data must be on one page.
151 * The master must be locked.
152 *
153 * @param sl The slave structure
154 * @param addr Address for the write
155 * @param len length must be <= (W1_PAGE_SIZE - (addr & W1_PAGE_MASK))
156 * @param data The data to write
157 * @return 0=Success -1=failure
158 */
159static int w1_f23_write(struct w1_slave *sl, int addr, int len, const u8 *data)
160{
161 u8 wrbuf[4];
162 u8 rdbuf[W1_PAGE_SIZE + 3];
163 u8 es = (addr + len - 1) & 0x1f;
164
165 /* Write the data to the scratchpad */
166 if (w1_reset_select_slave(sl))
167 return -1;
168
169 wrbuf[0] = W1_F23_WRITE_SCRATCH;
170 wrbuf[1] = addr & 0xff;
171 wrbuf[2] = addr >> 8;
172
173 w1_write_block(sl->master, wrbuf, 3);
174 w1_write_block(sl->master, data, len);
175
176 /* Read the scratchpad and verify */
177 if (w1_reset_select_slave(sl))
178 return -1;
179
180 w1_write_8(sl->master, W1_F23_READ_SCRATCH);
181 w1_read_block(sl->master, rdbuf, len + 3);
182
183 /* Compare what was read against the data written */
184 if ((rdbuf[0] != wrbuf[1]) || (rdbuf[1] != wrbuf[2]) ||
185 (rdbuf[2] != es) || (memcmp(data, &rdbuf[3], len) != 0))
186 return -1;
187
188 /* Copy the scratchpad to EEPROM */
189 if (w1_reset_select_slave(sl))
190 return -1;
191
192 wrbuf[0] = W1_F23_COPY_SCRATCH;
193 wrbuf[3] = es;
194 w1_write_block(sl->master, wrbuf, 4);
195
196 /* Sleep for 5 ms to wait for the write to complete */
197 msleep(5);
198
199 /* Reset the bus to wake up the EEPROM (this may not be needed) */
200 w1_reset_bus(sl->master);
201
202 return 0;
203}
204
205static ssize_t w1_f23_write_bin(struct kobject *kobj, char *buf, loff_t off,
206 size_t count)
207{
208 struct w1_slave *sl = kobj_to_w1_slave(kobj);
209 int addr, len, idx;
210
211 if ((count = w1_f23_fix_count(off, count, W1_EEPROM_SIZE)) == 0)
212 return 0;
213
214#ifdef CONFIG_W1_F23_CRC
215 /* can only write full blocks in cached mode */
216 if ((off & W1_PAGE_MASK) || (count & W1_PAGE_MASK)) {
217 dev_err(&sl->dev, "invalid offset/count off=%d cnt=%d\n",
218 (int)off, count);
219 return -EINVAL;
220 }
221
222 /* make sure the block CRCs are valid */
223 for (idx = 0; idx < count; idx += W1_PAGE_SIZE) {
224 if (crc16(CRC16_INIT, &buf[idx], W1_PAGE_SIZE) != CRC16_VALID) {
225 dev_err(&sl->dev, "bad CRC at offset %d\n", (int)off);
226 return -EINVAL;
227 }
228 }
229#endif /* CONFIG_W1_F23_CRC */
230
231 atomic_inc(&sl->refcnt);
232 if (down_interruptible(&sl->master->mutex)) {
233 count = 0;
234 goto out_dec;
235 }
236
237 /* Can only write data to one page at a time */
238 idx = 0;
239 while (idx < count) {
240 addr = off + idx;
241 len = W1_PAGE_SIZE - (addr & W1_PAGE_MASK);
242 if (len > (count - idx))
243 len = count - idx;
244
245 if (w1_f23_write(sl, addr, len, &buf[idx]) < 0) {
246 count = -EIO;
247 goto out_up;
248 }
249 idx += len;
250 }
251
252out_up:
253 up(&sl->master->mutex);
254out_dec:
255 atomic_dec(&sl->refcnt);
256
257 return count;
258}
259
260static struct bin_attribute w1_f23_bin_attr = {
261 .attr = {
262 .name = "eeprom",
263 .mode = S_IRUGO | S_IWUSR,
264 .owner = THIS_MODULE,
265 },
266 .size = W1_EEPROM_SIZE,
267 .read = w1_f23_read_bin,
268 .write = w1_f23_write_bin,
269};
270
271static int w1_f23_add_slave(struct w1_slave *sl)
272{
273 int err;
274#ifdef CONFIG_W1_F23_CRC
275 struct w1_f23_data *data;
276
277 data = kmalloc(sizeof(struct w1_f23_data), GFP_KERNEL);
278 if (!data)
279 return -ENOMEM;
280 memset(data, 0, sizeof(struct w1_f23_data));
281 sl->family_data = data;
282
283#endif /* CONFIG_W1_F23_CRC */
284
285 err = sysfs_create_bin_file(&sl->dev.kobj, &w1_f23_bin_attr);
286
287#ifdef CONFIG_W1_F23_CRC
288 if (err)
289 kfree(data);
290#endif /* CONFIG_W1_F23_CRC */
291
292 return err;
293}
294
295static void w1_f23_remove_slave(struct w1_slave *sl)
296{
297#ifdef CONFIG_W1_F23_CRC
298 if (sl->family_data) {
299 kfree(sl->family_data);
300 sl->family_data = NULL;
301 }
302#endif /* CONFIG_W1_F23_CRC */
303 sysfs_remove_bin_file(&sl->dev.kobj, &w1_f23_bin_attr);
304}
305
306static struct w1_family_ops w1_f23_fops = {
307 .add_slave = w1_f23_add_slave,
308 .remove_slave = w1_f23_remove_slave,
309};
310
311static struct w1_family w1_family_23 = {
312 .fid = W1_EEPROM_DS2433,
313 .fops = &w1_f23_fops,
314};
315
316static int __init w1_f23_init(void)
317{
318 return w1_register_family(&w1_family_23);
319}
320
321static void __exit w1_f23_fini(void)
322{
323 w1_unregister_family(&w1_family_23);
324}
325
326module_init(w1_f23_init);
327module_exit(w1_f23_fini);
diff --git a/drivers/w1/w1_family.c b/drivers/w1/w1_family.c
index 02eee57d3c0c..88c517a4c178 100644
--- a/drivers/w1/w1_family.c
+++ b/drivers/w1/w1_family.c
@@ -29,23 +29,12 @@ DEFINE_SPINLOCK(w1_flock);
29static LIST_HEAD(w1_families); 29static LIST_HEAD(w1_families);
30extern void w1_reconnect_slaves(struct w1_family *f); 30extern void w1_reconnect_slaves(struct w1_family *f);
31 31
32static int w1_check_family(struct w1_family *f)
33{
34 if (!f->fops->rname || !f->fops->rbin)
35 return -EINVAL;
36
37 return 0;
38}
39
40int w1_register_family(struct w1_family *newf) 32int w1_register_family(struct w1_family *newf)
41{ 33{
42 struct list_head *ent, *n; 34 struct list_head *ent, *n;
43 struct w1_family *f; 35 struct w1_family *f;
44 int ret = 0; 36 int ret = 0;
45 37
46 if (w1_check_family(newf))
47 return -EINVAL;
48
49 spin_lock(&w1_flock); 38 spin_lock(&w1_flock);
50 list_for_each_safe(ent, n, &w1_families) { 39 list_for_each_safe(ent, n, &w1_families) {
51 f = list_entry(ent, struct w1_family, family_entry); 40 f = list_entry(ent, struct w1_family, family_entry);
diff --git a/drivers/w1/w1_family.h b/drivers/w1/w1_family.h
index b26da01bbc38..2ca0489c716a 100644
--- a/drivers/w1/w1_family.h
+++ b/drivers/w1/w1_family.h
@@ -31,14 +31,17 @@
31#define W1_FAMILY_SMEM_81 0x81 31#define W1_FAMILY_SMEM_81 0x81
32#define W1_THERM_DS18S20 0x10 32#define W1_THERM_DS18S20 0x10
33#define W1_THERM_DS1822 0x22 33#define W1_THERM_DS1822 0x22
34#define W1_EEPROM_DS2433 0x23
34#define W1_THERM_DS18B20 0x28 35#define W1_THERM_DS18B20 0x28
35 36
36#define MAXNAMELEN 32 37#define MAXNAMELEN 32
37 38
39struct w1_slave;
40
38struct w1_family_ops 41struct w1_family_ops
39{ 42{
40 ssize_t (* rname)(struct device *, struct device_attribute *, char *); 43 int (* add_slave)(struct w1_slave *);
41 ssize_t (* rbin)(struct kobject *, char *, loff_t, size_t); 44 void (* remove_slave)(struct w1_slave *);
42}; 45};
43 46
44struct w1_family 47struct w1_family
diff --git a/drivers/w1/w1_int.c b/drivers/w1/w1_int.c
index 498ad505fa5f..c3f67eafc7ec 100644
--- a/drivers/w1/w1_int.c
+++ b/drivers/w1/w1_int.c
@@ -29,9 +29,9 @@
29 29
30static u32 w1_ids = 1; 30static u32 w1_ids = 1;
31 31
32extern struct device_driver w1_driver; 32extern struct device_driver w1_master_driver;
33extern struct bus_type w1_bus_type; 33extern struct bus_type w1_bus_type;
34extern struct device w1_device; 34extern struct device w1_master_device;
35extern int w1_max_slave_count; 35extern int w1_max_slave_count;
36extern int w1_max_slave_ttl; 36extern int w1_max_slave_ttl;
37extern struct list_head w1_masters; 37extern struct list_head w1_masters;
@@ -76,7 +76,6 @@ static struct w1_master * w1_alloc_dev(u32 id, int slave_count, int slave_ttl,
76 INIT_LIST_HEAD(&dev->slist); 76 INIT_LIST_HEAD(&dev->slist);
77 init_MUTEX(&dev->mutex); 77 init_MUTEX(&dev->mutex);
78 78
79 init_completion(&dev->dev_released);
80 init_completion(&dev->dev_exited); 79 init_completion(&dev->dev_exited);
81 80
82 memcpy(&dev->dev, device, sizeof(struct device)); 81 memcpy(&dev->dev, device, sizeof(struct device));
@@ -88,17 +87,14 @@ static struct w1_master * w1_alloc_dev(u32 id, int slave_count, int slave_ttl,
88 87
89 dev->groups = 1; 88 dev->groups = 1;
90 dev->seq = 1; 89 dev->seq = 1;
91 dev->nls = netlink_kernel_create(NETLINK_W1, 1, NULL, THIS_MODULE); 90 dev_init_netlink(dev);
92 if (!dev->nls) {
93 printk(KERN_ERR "Failed to create new netlink socket(%u) for w1 master %s.\n",
94 NETLINK_NFLOG, dev->dev.bus_id);
95 }
96 91
97 err = device_register(&dev->dev); 92 err = device_register(&dev->dev);
98 if (err) { 93 if (err) {
99 printk(KERN_ERR "Failed to register master device. err=%d\n", err); 94 printk(KERN_ERR "Failed to register master device. err=%d\n", err);
100 if (dev->nls && dev->nls->sk_socket) 95
101 sock_release(dev->nls->sk_socket); 96 dev_fini_netlink(dev);
97
102 memset(dev, 0, sizeof(struct w1_master)); 98 memset(dev, 0, sizeof(struct w1_master));
103 kfree(dev); 99 kfree(dev);
104 dev = NULL; 100 dev = NULL;
@@ -107,13 +103,9 @@ static struct w1_master * w1_alloc_dev(u32 id, int slave_count, int slave_ttl,
107 return dev; 103 return dev;
108} 104}
109 105
110static void w1_free_dev(struct w1_master *dev) 106void w1_free_dev(struct w1_master *dev)
111{ 107{
112 device_unregister(&dev->dev); 108 device_unregister(&dev->dev);
113 if (dev->nls && dev->nls->sk_socket)
114 sock_release(dev->nls->sk_socket);
115 memset(dev, 0, sizeof(struct w1_master) + sizeof(struct w1_bus_master));
116 kfree(dev);
117} 109}
118 110
119int w1_add_master_device(struct w1_bus_master *master) 111int w1_add_master_device(struct w1_bus_master *master)
@@ -129,7 +121,7 @@ int w1_add_master_device(struct w1_bus_master *master)
129 return(-EINVAL); 121 return(-EINVAL);
130 } 122 }
131 123
132 dev = w1_alloc_dev(w1_ids++, w1_max_slave_count, w1_max_slave_ttl, &w1_driver, &w1_device); 124 dev = w1_alloc_dev(w1_ids++, w1_max_slave_count, w1_max_slave_ttl, &w1_master_driver, &w1_master_device);
133 if (!dev) 125 if (!dev)
134 return -ENOMEM; 126 return -ENOMEM;
135 127
@@ -188,7 +180,7 @@ void __w1_remove_master_device(struct w1_master *dev)
188 __func__, dev->kpid); 180 __func__, dev->kpid);
189 181
190 while (atomic_read(&dev->refcnt)) { 182 while (atomic_read(&dev->refcnt)) {
191 printk(KERN_INFO "Waiting for %s to become free: refcnt=%d.\n", 183 dev_dbg(&dev->dev, "Waiting for %s to become free: refcnt=%d.\n",
192 dev->name, atomic_read(&dev->refcnt)); 184 dev->name, atomic_read(&dev->refcnt));
193 185
194 if (msleep_interruptible(1000)) 186 if (msleep_interruptible(1000))
diff --git a/drivers/w1/w1_io.c b/drivers/w1/w1_io.c
index 00f032220173..e2a043354ddf 100644
--- a/drivers/w1/w1_io.c
+++ b/drivers/w1/w1_io.c
@@ -277,6 +277,29 @@ void w1_search_devices(struct w1_master *dev, w1_slave_found_callback cb)
277 w1_search(dev, cb); 277 w1_search(dev, cb);
278} 278}
279 279
280/**
281 * Resets the bus and then selects the slave by sending either a skip rom
282 * or a rom match.
283 * The w1 master lock must be held.
284 *
285 * @param sl the slave to select
286 * @return 0=success, anything else=error
287 */
288int w1_reset_select_slave(struct w1_slave *sl)
289{
290 if (w1_reset_bus(sl->master))
291 return -1;
292
293 if (sl->master->slave_count == 1)
294 w1_write_8(sl->master, W1_SKIP_ROM);
295 else {
296 u8 match[9] = {W1_MATCH_ROM, };
297 memcpy(&match[1], (u8 *)&sl->reg_num, 8);
298 w1_write_block(sl->master, match, 9);
299 }
300 return 0;
301}
302
280EXPORT_SYMBOL(w1_touch_bit); 303EXPORT_SYMBOL(w1_touch_bit);
281EXPORT_SYMBOL(w1_write_8); 304EXPORT_SYMBOL(w1_write_8);
282EXPORT_SYMBOL(w1_read_8); 305EXPORT_SYMBOL(w1_read_8);
@@ -286,3 +309,4 @@ EXPORT_SYMBOL(w1_delay);
286EXPORT_SYMBOL(w1_read_block); 309EXPORT_SYMBOL(w1_read_block);
287EXPORT_SYMBOL(w1_write_block); 310EXPORT_SYMBOL(w1_write_block);
288EXPORT_SYMBOL(w1_search_devices); 311EXPORT_SYMBOL(w1_search_devices);
312EXPORT_SYMBOL(w1_reset_select_slave);
diff --git a/drivers/w1/w1_io.h b/drivers/w1/w1_io.h
index af5829778aaa..232860184a29 100644
--- a/drivers/w1/w1_io.h
+++ b/drivers/w1/w1_io.h
@@ -34,5 +34,6 @@ u8 w1_calc_crc8(u8 *, int);
34void w1_write_block(struct w1_master *, const u8 *, int); 34void w1_write_block(struct w1_master *, const u8 *, int);
35u8 w1_read_block(struct w1_master *, u8 *, int); 35u8 w1_read_block(struct w1_master *, u8 *, int);
36void w1_search_devices(struct w1_master *dev, w1_slave_found_callback cb); 36void w1_search_devices(struct w1_master *dev, w1_slave_found_callback cb);
37int w1_reset_select_slave(struct w1_slave *sl);
37 38
38#endif /* __W1_IO_H */ 39#endif /* __W1_IO_H */
diff --git a/drivers/w1/w1_netlink.c b/drivers/w1/w1_netlink.c
index e7b774423dd6..328645da7972 100644
--- a/drivers/w1/w1_netlink.c
+++ b/drivers/w1/w1_netlink.c
@@ -57,10 +57,36 @@ void w1_netlink_send(struct w1_master *dev, struct w1_netlink_msg *msg)
57nlmsg_failure: 57nlmsg_failure:
58 return; 58 return;
59} 59}
60
61int dev_init_netlink(struct w1_master *dev)
62{
63 dev->nls = netlink_kernel_create(NETLINK_W1, 1, NULL, THIS_MODULE);
64 if (!dev->nls) {
65 printk(KERN_ERR "Failed to create new netlink socket(%u) for w1 master %s.\n",
66 NETLINK_W1, dev->dev.bus_id);
67 }
68
69 return 0;
70}
71
72void dev_fini_netlink(struct w1_master *dev)
73{
74 if (dev->nls && dev->nls->sk_socket)
75 sock_release(dev->nls->sk_socket);
76}
60#else 77#else
61#warning Netlink support is disabled. Please compile with NET support enabled. 78#warning Netlink support is disabled. Please compile with NET support enabled.
62 79
63void w1_netlink_send(struct w1_master *dev, struct w1_netlink_msg *msg) 80void w1_netlink_send(struct w1_master *dev, struct w1_netlink_msg *msg)
64{ 81{
65} 82}
83
84int dev_init_netlink(struct w1_master *dev)
85{
86 return 0;
87}
88
89void dev_fini_netlink(struct w1_master *dev)
90{
91}
66#endif 92#endif
diff --git a/drivers/w1/w1_netlink.h b/drivers/w1/w1_netlink.h
index 8615756946df..eb0c8b3152c8 100644
--- a/drivers/w1/w1_netlink.h
+++ b/drivers/w1/w1_netlink.h
@@ -52,6 +52,8 @@ struct w1_netlink_msg
52#ifdef __KERNEL__ 52#ifdef __KERNEL__
53 53
54void w1_netlink_send(struct w1_master *, struct w1_netlink_msg *); 54void w1_netlink_send(struct w1_master *, struct w1_netlink_msg *);
55int dev_init_netlink(struct w1_master *dev);
56void dev_fini_netlink(struct w1_master *dev);
55 57
56#endif /* __KERNEL__ */ 58#endif /* __KERNEL__ */
57#endif /* __W1_NETLINK_H */ 59#endif /* __W1_NETLINK_H */
diff --git a/drivers/w1/w1_smem.c b/drivers/w1/w1_smem.c
index 70d2d469963c..e3209d0aca9b 100644
--- a/drivers/w1/w1_smem.c
+++ b/drivers/w1/w1_smem.c
@@ -36,61 +36,12 @@ MODULE_LICENSE("GPL");
36MODULE_AUTHOR("Evgeniy Polyakov <johnpol@2ka.mipt.ru>"); 36MODULE_AUTHOR("Evgeniy Polyakov <johnpol@2ka.mipt.ru>");
37MODULE_DESCRIPTION("Driver for 1-wire Dallas network protocol, 64bit memory family."); 37MODULE_DESCRIPTION("Driver for 1-wire Dallas network protocol, 64bit memory family.");
38 38
39static ssize_t w1_smem_read_name(struct device *, struct device_attribute *attr, char *);
40static ssize_t w1_smem_read_bin(struct kobject *, char *, loff_t, size_t);
41
42static struct w1_family_ops w1_smem_fops = {
43 .rname = &w1_smem_read_name,
44 .rbin = &w1_smem_read_bin,
45};
46
47static ssize_t w1_smem_read_name(struct device *dev, struct device_attribute *attr, char *buf)
48{
49 struct w1_slave *sl = container_of(dev, struct w1_slave, dev);
50
51 return sprintf(buf, "%s\n", sl->name);
52}
53
54static ssize_t w1_smem_read_bin(struct kobject *kobj, char *buf, loff_t off, size_t count)
55{
56 struct w1_slave *sl = container_of(container_of(kobj, struct device, kobj),
57 struct w1_slave, dev);
58 int i;
59
60 atomic_inc(&sl->refcnt);
61 if (down_interruptible(&sl->master->mutex)) {
62 count = 0;
63 goto out_dec;
64 }
65
66 if (off > W1_SLAVE_DATA_SIZE) {
67 count = 0;
68 goto out;
69 }
70 if (off + count > W1_SLAVE_DATA_SIZE) {
71 count = 0;
72 goto out;
73 }
74 for (i = 0; i < 8; ++i)
75 count += sprintf(buf + count, "%02x ", ((u8 *)&sl->reg_num)[i]);
76 count += sprintf(buf + count, "\n");
77
78out:
79 up(&sl->master->mutex);
80out_dec:
81 atomic_dec(&sl->refcnt);
82
83 return count;
84}
85
86static struct w1_family w1_smem_family_01 = { 39static struct w1_family w1_smem_family_01 = {
87 .fid = W1_FAMILY_SMEM_01, 40 .fid = W1_FAMILY_SMEM_01,
88 .fops = &w1_smem_fops,
89}; 41};
90 42
91static struct w1_family w1_smem_family_81 = { 43static struct w1_family w1_smem_family_81 = {
92 .fid = W1_FAMILY_SMEM_81, 44 .fid = W1_FAMILY_SMEM_81,
93 .fops = &w1_smem_fops,
94}; 45};
95 46
96static int __init w1_smem_init(void) 47static int __init w1_smem_init(void)
diff --git a/drivers/w1/w1_therm.c b/drivers/w1/w1_therm.c
index 165526c9360a..4577df3cfc48 100644
--- a/drivers/w1/w1_therm.c
+++ b/drivers/w1/w1_therm.c
@@ -42,12 +42,31 @@ static u8 bad_roms[][9] = {
42 {} 42 {}
43 }; 43 };
44 44
45static ssize_t w1_therm_read_name(struct device *, struct device_attribute *attr, char *);
46static ssize_t w1_therm_read_bin(struct kobject *, char *, loff_t, size_t); 45static ssize_t w1_therm_read_bin(struct kobject *, char *, loff_t, size_t);
47 46
47static struct bin_attribute w1_therm_bin_attr = {
48 .attr = {
49 .name = "w1_slave",
50 .mode = S_IRUGO,
51 .owner = THIS_MODULE,
52 },
53 .size = W1_SLAVE_DATA_SIZE,
54 .read = w1_therm_read_bin,
55};
56
57static int w1_therm_add_slave(struct w1_slave *sl)
58{
59 return sysfs_create_bin_file(&sl->dev.kobj, &w1_therm_bin_attr);
60}
61
62static void w1_therm_remove_slave(struct w1_slave *sl)
63{
64 sysfs_remove_bin_file(&sl->dev.kobj, &w1_therm_bin_attr);
65}
66
48static struct w1_family_ops w1_therm_fops = { 67static struct w1_family_ops w1_therm_fops = {
49 .rname = &w1_therm_read_name, 68 .add_slave = w1_therm_add_slave,
50 .rbin = &w1_therm_read_bin, 69 .remove_slave = w1_therm_remove_slave,
51}; 70};
52 71
53static struct w1_family w1_therm_family_DS18S20 = { 72static struct w1_family w1_therm_family_DS18S20 = {
@@ -59,6 +78,7 @@ static struct w1_family w1_therm_family_DS18B20 = {
59 .fid = W1_THERM_DS18B20, 78 .fid = W1_THERM_DS18B20,
60 .fops = &w1_therm_fops, 79 .fops = &w1_therm_fops,
61}; 80};
81
62static struct w1_family w1_therm_family_DS1822 = { 82static struct w1_family w1_therm_family_DS1822 = {
63 .fid = W1_THERM_DS1822, 83 .fid = W1_THERM_DS1822,
64 .fops = &w1_therm_fops, 84 .fops = &w1_therm_fops,
@@ -90,13 +110,6 @@ static struct w1_therm_family_converter w1_therm_families[] = {
90 }, 110 },
91}; 111};
92 112
93static ssize_t w1_therm_read_name(struct device *dev, struct device_attribute *attr, char *buf)
94{
95 struct w1_slave *sl = container_of(dev, struct w1_slave, dev);
96
97 return sprintf(buf, "%s\n", sl->name);
98}
99
100static inline int w1_DS18B20_convert_temp(u8 rom[9]) 113static inline int w1_DS18B20_convert_temp(u8 rom[9])
101{ 114{
102 int t = (rom[1] << 8) | rom[0]; 115 int t = (rom[1] << 8) | rom[0];
@@ -148,8 +161,7 @@ static int w1_therm_check_rom(u8 rom[9])
148 161
149static ssize_t w1_therm_read_bin(struct kobject *kobj, char *buf, loff_t off, size_t count) 162static ssize_t w1_therm_read_bin(struct kobject *kobj, char *buf, loff_t off, size_t count)
150{ 163{
151 struct w1_slave *sl = container_of(container_of(kobj, struct device, kobj), 164 struct w1_slave *sl = kobj_to_w1_slave(kobj);
152 struct w1_slave, dev);
153 struct w1_master *dev = sl->master; 165 struct w1_master *dev = sl->master;
154 u8 rom[9], crc, verdict; 166 u8 rom[9], crc, verdict;
155 int i, max_trying = 10; 167 int i, max_trying = 10;
@@ -178,15 +190,10 @@ static ssize_t w1_therm_read_bin(struct kobject *kobj, char *buf, loff_t off, si
178 crc = 0; 190 crc = 0;
179 191
180 while (max_trying--) { 192 while (max_trying--) {
181 if (!w1_reset_bus (dev)) { 193 if (!w1_reset_select_slave(sl)) {
182 int count = 0; 194 int count = 0;
183 u8 match[9] = {W1_MATCH_ROM, };
184 unsigned int tm = 750; 195 unsigned int tm = 750;
185 196
186 memcpy(&match[1], (u64 *) & sl->reg_num, 8);
187
188 w1_write_block(dev, match, 9);
189
190 w1_write_8(dev, W1_CONVERT_TEMP); 197 w1_write_8(dev, W1_CONVERT_TEMP);
191 198
192 while (tm) { 199 while (tm) {
@@ -195,8 +202,7 @@ static ssize_t w1_therm_read_bin(struct kobject *kobj, char *buf, loff_t off, si
195 flush_signals(current); 202 flush_signals(current);
196 } 203 }
197 204
198 if (!w1_reset_bus (dev)) { 205 if (!w1_reset_select_slave(sl)) {
199 w1_write_block(dev, match, 9);
200 206
201 w1_write_8(dev, W1_READ_SCRATCHPAD); 207 w1_write_8(dev, W1_READ_SCRATCHPAD);
202 if ((count = w1_read_block(dev, rom, 9)) != 9) { 208 if ((count = w1_read_block(dev, rom, 9)) != 9) {
@@ -207,7 +213,6 @@ static ssize_t w1_therm_read_bin(struct kobject *kobj, char *buf, loff_t off, si
207 213
208 if (rom[8] == crc && rom[0]) 214 if (rom[8] == crc && rom[0])
209 verdict = 1; 215 verdict = 1;
210
211 } 216 }
212 } 217 }
213 218