Skip to content

Commit d8ace32

Browse files
committed
Merge pull request #186 from mkj/rpi-3.6.y
Add bitbanging pullups, use them for w1-gpio
2 parents 5d9516c + 6e41bfa commit d8ace32

File tree

4 files changed

+206
-155
lines changed

4 files changed

+206
-155
lines changed

drivers/w1/masters/w1-gpio.c

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
#include "../w1.h"
1919
#include "../w1_int.h"
2020

21+
static int w1_gpio_pullup = 0;
22+
module_param_named(pullup, w1_gpio_pullup, int, 0);
23+
2124
static void w1_gpio_write_bit_dir(void *data, u8 bit)
2225
{
2326
struct w1_gpio_platform_data *pdata = data;
@@ -42,6 +45,16 @@ static u8 w1_gpio_read_bit(void *data)
4245
return gpio_get_value(pdata->pin) ? 1 : 0;
4346
}
4447

48+
static void w1_gpio_bitbang_pullup(void *data, u8 on)
49+
{
50+
struct w1_gpio_platform_data *pdata = data;
51+
52+
if (on)
53+
gpio_direction_output(pdata->pin, 1);
54+
else
55+
gpio_direction_input(pdata->pin);
56+
}
57+
4558
static int __init w1_gpio_probe(struct platform_device *pdev)
4659
{
4760
struct w1_bus_master *master;
@@ -70,6 +83,13 @@ static int __init w1_gpio_probe(struct platform_device *pdev)
7083
master->write_bit = w1_gpio_write_bit_dir;
7184
}
7285

86+
if (w1_gpio_pullup)
87+
if (pdata->is_open_drain)
88+
printk(KERN_ERR "w1-gpio 'pullup' option "
89+
"doesn't work with open drain GPIO\n");
90+
else
91+
master->bitbang_pullup = w1_gpio_bitbang_pullup;
92+
7393
err = w1_add_master_device(master);
7494
if (err)
7595
goto free_gpio;
@@ -81,9 +101,9 @@ static int __init w1_gpio_probe(struct platform_device *pdev)
81101

82102
return 0;
83103

84-
free_gpio:
104+
free_gpio:
85105
gpio_free(pdata->pin);
86-
free_master:
106+
free_master:
87107
kfree(master);
88108

89109
return err;
@@ -133,10 +153,10 @@ static int w1_gpio_resume(struct platform_device *pdev)
133153

134154
static struct platform_driver w1_gpio_driver = {
135155
.driver = {
136-
.name = "w1-gpio",
137-
.owner = THIS_MODULE,
138-
},
139-
.remove = __exit_p(w1_gpio_remove),
156+
.name = "w1-gpio",
157+
.owner = THIS_MODULE,
158+
},
159+
.remove = __exit_p(w1_gpio_remove),
140160
.suspend = w1_gpio_suspend,
141161
.resume = w1_gpio_resume,
142162
};

drivers/w1/w1.h

Lines changed: 72 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,11 @@
2222
#ifndef __W1_H
2323
#define __W1_H
2424

25-
struct w1_reg_num
26-
{
25+
struct w1_reg_num {
2726
#if defined(__LITTLE_ENDIAN_BITFIELD)
28-
__u64 family:8,
29-
id:48,
30-
crc:8;
27+
__u64 family:8, id:48, crc:8;
3128
#elif defined(__BIG_ENDIAN_BITFIELD)
32-
__u64 crc:8,
33-
id:48,
34-
family:8;
29+
__u64 crc:8, id:48, family:8;
3530
#else
3631
#error "Please fix <asm/byteorder.h>"
3732
#endif
@@ -59,26 +54,24 @@ struct w1_reg_num
5954

6055
#define W1_SLAVE_ACTIVE 0
6156

62-
struct w1_slave
63-
{
64-
struct module *owner;
65-
unsigned char name[W1_MAXNAMELEN];
66-
struct list_head w1_slave_entry;
67-
struct w1_reg_num reg_num;
68-
atomic_t refcnt;
69-
u8 rom[9];
70-
u32 flags;
71-
int ttl;
72-
73-
struct w1_master *master;
74-
struct w1_family *family;
75-
void *family_data;
76-
struct device dev;
77-
struct completion released;
57+
struct w1_slave {
58+
struct module *owner;
59+
unsigned char name[W1_MAXNAMELEN];
60+
struct list_head w1_slave_entry;
61+
struct w1_reg_num reg_num;
62+
atomic_t refcnt;
63+
u8 rom[9];
64+
u32 flags;
65+
int ttl;
66+
67+
struct w1_master *master;
68+
struct w1_family *family;
69+
void *family_data;
70+
struct device dev;
71+
struct completion released;
7872
};
7973

80-
typedef void (*w1_slave_found_callback)(struct w1_master *, u64);
81-
74+
typedef void (*w1_slave_found_callback) (struct w1_master *, u64);
8275

8376
/**
8477
* Note: read_bit and write_bit are very low level functions and should only
@@ -87,19 +80,18 @@ typedef void (*w1_slave_found_callback)(struct w1_master *, u64);
8780
* Either define read_bit and write_bit OR define, at minimum, touch_bit and
8881
* reset_bus.
8982
*/
90-
struct w1_bus_master
91-
{
83+
struct w1_bus_master {
9284
/** the first parameter in all the functions below */
93-
void *data;
85+
void *data;
9486

9587
/**
9688
* Sample the line level
9789
* @return the level read (0 or 1)
9890
*/
99-
u8 (*read_bit)(void *);
91+
u8(*read_bit) (void *);
10092

10193
/** Sets the line level */
102-
void (*write_bit)(void *, u8);
94+
void (*write_bit) (void *, u8);
10395

10496
/**
10597
* touch_bit is the lowest-level function for devices that really
@@ -108,96 +100,103 @@ struct w1_bus_master
108100
* touch_bit(1) = write-1 / read cycle
109101
* @return the bit read (0 or 1)
110102
*/
111-
u8 (*touch_bit)(void *, u8);
103+
u8(*touch_bit) (void *, u8);
112104

113105
/**
114106
* Reads a bytes. Same as 8 touch_bit(1) calls.
115107
* @return the byte read
116108
*/
117-
u8 (*read_byte)(void *);
109+
u8(*read_byte) (void *);
118110

119111
/**
120112
* Writes a byte. Same as 8 touch_bit(x) calls.
121113
*/
122-
void (*write_byte)(void *, u8);
114+
void (*write_byte) (void *, u8);
123115

124116
/**
125117
* Same as a series of read_byte() calls
126118
* @return the number of bytes read
127119
*/
128-
u8 (*read_block)(void *, u8 *, int);
120+
u8(*read_block) (void *, u8 *, int);
129121

130122
/** Same as a series of write_byte() calls */
131-
void (*write_block)(void *, const u8 *, int);
123+
void (*write_block) (void *, const u8 *, int);
132124

133125
/**
134126
* Combines two reads and a smart write for ROM searches
135127
* @return bit0=Id bit1=comp_id bit2=dir_taken
136128
*/
137-
u8 (*triplet)(void *, u8);
129+
u8(*triplet) (void *, u8);
138130

139131
/**
140132
* long write-0 with a read for the presence pulse detection
141133
* @return -1=Error, 0=Device present, 1=No device present
142134
*/
143-
u8 (*reset_bus)(void *);
135+
u8(*reset_bus) (void *);
144136

145137
/**
146138
* Put out a strong pull-up pulse of the specified duration.
147139
* @return -1=Error, 0=completed
148140
*/
149-
u8 (*set_pullup)(void *, int);
141+
u8(*set_pullup) (void *, int);
142+
143+
/**
144+
* Turns the pullup on/off in bitbanging mode, takes an on/off argument.
145+
* @return -1=Error, 0=completed
146+
*/
147+
void (*bitbang_pullup) (void *, u8);
150148

151149
/** Really nice hardware can handles the different types of ROM search
152150
* w1_master* is passed to the slave found callback.
153151
*/
154-
void (*search)(void *, struct w1_master *,
155-
u8, w1_slave_found_callback);
152+
void (*search) (void *, struct w1_master *,
153+
u8, w1_slave_found_callback);
156154
};
157155

158-
struct w1_master
159-
{
160-
struct list_head w1_master_entry;
161-
struct module *owner;
162-
unsigned char name[W1_MAXNAMELEN];
163-
struct list_head slist;
164-
int max_slave_count, slave_count;
165-
unsigned long attempts;
166-
int slave_ttl;
167-
int initialized;
168-
u32 id;
169-
int search_count;
170-
171-
atomic_t refcnt;
172-
173-
void *priv;
174-
int priv_size;
156+
struct w1_master {
157+
struct list_head w1_master_entry;
158+
struct module *owner;
159+
unsigned char name[W1_MAXNAMELEN];
160+
struct list_head slist;
161+
int max_slave_count, slave_count;
162+
unsigned long attempts;
163+
int slave_ttl;
164+
int initialized;
165+
u32 id;
166+
int search_count;
167+
168+
atomic_t refcnt;
169+
170+
void *priv;
171+
int priv_size;
175172

176173
/** 5V strong pullup enabled flag, 1 enabled, zero disabled. */
177-
int enable_pullup;
174+
int enable_pullup;
178175
/** 5V strong pullup duration in milliseconds, zero disabled. */
179-
int pullup_duration;
176+
int pullup_duration;
180177

181-
struct task_struct *thread;
182-
struct mutex mutex;
183-
struct mutex bus_mutex;
178+
struct task_struct *thread;
179+
struct mutex mutex;
180+
struct mutex bus_mutex;
184181

185-
struct device_driver *driver;
186-
struct device dev;
182+
struct device_driver *driver;
183+
struct device dev;
187184

188-
struct w1_bus_master *bus_master;
185+
struct w1_bus_master *bus_master;
189186

190-
u32 seq;
187+
u32 seq;
191188
};
192189

193190
int w1_create_master_attributes(struct w1_master *);
194191
void w1_destroy_master_attributes(struct w1_master *master);
195-
void w1_search(struct w1_master *dev, u8 search_type, w1_slave_found_callback cb);
196-
void w1_search_devices(struct w1_master *dev, u8 search_type, w1_slave_found_callback cb);
192+
void w1_search(struct w1_master *dev, u8 search_type,
193+
w1_slave_found_callback cb);
194+
void w1_search_devices(struct w1_master *dev, u8 search_type,
195+
w1_slave_found_callback cb);
197196
struct w1_slave *w1_search_slave(struct w1_reg_num *id);
198197
void w1_slave_found(struct w1_master *dev, u64 rn);
199198
void w1_search_process_cb(struct w1_master *dev, u8 search_type,
200-
w1_slave_found_callback cb);
199+
w1_slave_found_callback cb);
201200
struct w1_master *w1_search_master_id(u32 id);
202201

203202
/* Disconnect and reconnect devices in the given family. Used for finding
@@ -220,17 +219,17 @@ int w1_reset_select_slave(struct w1_slave *sl);
220219
int w1_reset_resume_command(struct w1_master *);
221220
void w1_next_pullup(struct w1_master *, int);
222221

223-
static inline struct w1_slave* dev_to_w1_slave(struct device *dev)
222+
static inline struct w1_slave *dev_to_w1_slave(struct device *dev)
224223
{
225224
return container_of(dev, struct w1_slave, dev);
226225
}
227226

228-
static inline struct w1_slave* kobj_to_w1_slave(struct kobject *kobj)
227+
static inline struct w1_slave *kobj_to_w1_slave(struct kobject *kobj)
229228
{
230229
return dev_to_w1_slave(container_of(kobj, struct device, kobj));
231230
}
232231

233-
static inline struct w1_master* dev_to_w1_master(struct device *dev)
232+
static inline struct w1_master *dev_to_w1_master(struct device *dev)
234233
{
235234
return container_of(dev, struct w1_master, dev);
236235
}

0 commit comments

Comments
 (0)