Skip to content

Commit 9c95bb6

Browse files
Michael Arndtgregkh
authored andcommitted
w1: ds2482: Added 1-Wire pull-up support to the driver
Signed-off-by: Michael Arndt <michael@scriptkiller.de> Acked-by: Evgeniy Polyakov <zbr@ioremap.net> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent def1820 commit 9c95bb6

1 file changed

Lines changed: 45 additions & 6 deletions

File tree

‎drivers/w1/masters/ds2482.c‎

Lines changed: 45 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,10 @@
5151
* The top 4 bits always read 0.
5252
* To write, the top nibble must be the 1's compl. of the low nibble.
5353
*/
54-
#define DS2482_REG_CFG_1WS 0x08
55-
#define DS2482_REG_CFG_SPU 0x04
56-
#define DS2482_REG_CFG_PPM 0x02
57-
#define DS2482_REG_CFG_APU 0x01
54+
#define DS2482_REG_CFG_1WS 0x08 /* 1-wire speed */
55+
#define DS2482_REG_CFG_SPU 0x04 /* strong pull-up */
56+
#define DS2482_REG_CFG_PPM 0x02 /* presence pulse masking */
57+
#define DS2482_REG_CFG_APU 0x01 /* active pull-up */
5858

5959

6060
/**
@@ -131,6 +131,17 @@ struct ds2482_data {
131131
};
132132

133133

134+
/**
135+
* Helper to calculate values for configuration register
136+
* @param conf the raw config value
137+
* @return the value w/ complements that can be written to register
138+
*/
139+
static inline u8 ds2482_calculate_config(u8 conf)
140+
{
141+
return conf | ((~conf & 0x0f) << 4);
142+
}
143+
144+
134145
/**
135146
* Sets the read pointer.
136147
* @param pdev The ds2482 client pointer
@@ -399,14 +410,40 @@ static u8 ds2482_w1_reset_bus(void *data)
399410
/* If the chip did reset since detect, re-config it */
400411
if (err & DS2482_REG_STS_RST)
401412
ds2482_send_cmd_data(pdev, DS2482_CMD_WRITE_CONFIG,
402-
0xF0);
413+
ds2482_calculate_config(0x00));
403414
}
404415

405416
mutex_unlock(&pdev->access_lock);
406417

407418
return retval;
408419
}
409420

421+
static u8 ds2482_w1_set_pullup(void *data, int delay)
422+
{
423+
struct ds2482_w1_chan *pchan = data;
424+
struct ds2482_data *pdev = pchan->pdev;
425+
u8 retval = 1;
426+
427+
/* if delay is non-zero activate the pullup,
428+
* the strong pullup will be automatically deactivated
429+
* by the master, so do not explicitly deactive it
430+
*/
431+
if (delay) {
432+
/* both waits are crucial, otherwise devices might not be
433+
* powered long enough, causing e.g. a w1_therm sensor to
434+
* provide wrong conversion results
435+
*/
436+
ds2482_wait_1wire_idle(pdev);
437+
/* note: it seems like both SPU and APU have to be set! */
438+
retval = ds2482_send_cmd_data(pdev, DS2482_CMD_WRITE_CONFIG,
439+
ds2482_calculate_config(DS2482_REG_CFG_SPU |
440+
DS2482_REG_CFG_APU));
441+
ds2482_wait_1wire_idle(pdev);
442+
}
443+
444+
return retval;
445+
}
446+
410447

411448
static int ds2482_probe(struct i2c_client *client,
412449
const struct i2c_device_id *id)
@@ -452,7 +489,8 @@ static int ds2482_probe(struct i2c_client *client,
452489
data->w1_count = 8;
453490

454491
/* Set all config items to 0 (off) */
455-
ds2482_send_cmd_data(data, DS2482_CMD_WRITE_CONFIG, 0xF0);
492+
ds2482_send_cmd_data(data, DS2482_CMD_WRITE_CONFIG,
493+
ds2482_calculate_config(0x00));
456494

457495
mutex_init(&data->access_lock);
458496

@@ -468,6 +506,7 @@ static int ds2482_probe(struct i2c_client *client,
468506
data->w1_ch[idx].w1_bm.touch_bit = ds2482_w1_touch_bit;
469507
data->w1_ch[idx].w1_bm.triplet = ds2482_w1_triplet;
470508
data->w1_ch[idx].w1_bm.reset_bus = ds2482_w1_reset_bus;
509+
data->w1_ch[idx].w1_bm.set_pullup = ds2482_w1_set_pullup;
471510

472511
err = w1_add_master_device(&data->w1_ch[idx].w1_bm);
473512
if (err) {

0 commit comments

Comments
 (0)