aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/rtc/rtc-ds1307.c
diff options
context:
space:
mode:
authorRoland Dreier <rolandd@cisco.com>2008-02-07 00:07:54 -0500
committerRoland Dreier <rolandd@cisco.com>2008-02-07 00:07:54 -0500
commit1c69fc2a9012e160c8d459f63df74a6b01db8322 (patch)
treea32a2be6b2c8b9f5c4e006bacebc1eeb723e2ff5 /drivers/rtc/rtc-ds1307.c
parent21511abd0a248a3f225d3b611cfabb93124605a7 (diff)
IB/mlx4: Consolidate code to get an entry from a struct mlx4_buf
We use struct mlx4_buf for kernel QP, CQ and SRQ buffers, and the code to look up an entry is duplicated in get_cqe_from_buf() and the QP and SRQ versions of get_wqe(). Factor this out into mlx4_buf_offset(). This will also make it easier to switch over to using vmap() for buffers. Signed-off-by: Roland Dreier <rolandd@cisco.com>
Diffstat (limited to 'drivers/rtc/rtc-ds1307.c')
0 files changed, 0 insertions, 0 deletions
Cameron <jic23@cam.ac.uk> 2009-08-18 13:06:26 -0400 committer Greg Kroah-Hartman <gregkh@suse.de> 2009-09-15 15:02:25 -0400 Staging: IIO: Trigger support added to core.' href='/cgit/cgit.cgi/litmus-rt-ext-res.git/commit/drivers/staging/iio/industrialio-trigger.c?id=1637db44413e32a0f100dd4bd164644e641842f7'>1637db44413e
1637db44413e






1637db44413e
47c24fdd4253
1637db44413e






1637db44413e
582e54890872
1637db44413e

47c24fdd4253
1637db44413e
8bade4066492
1637db44413e


f6517f22d4f6

1637db44413e
f6517f22d4f6
7c3278570161
1637db44413e
f6517f22d4f6


1637db44413e

1637db44413e

f6517f22d4f6
5f87404dfce1
1637db44413e
7b2c33b11ef0
1637db44413e
d96d1337e339
a1a8e1dc111d





d96d1337e339
a1a8e1dc111d



1637db44413e

8384d9573e93






1637db44413e
1f785681a870


a1a8e1dc111d





1f785681a870
a1a8e1dc111d



1f785681a870


1637db44413e

a1a8e1dc111d

e69616b1e65c
860c9c54272d
7b2c33b11ef0
1637db44413e


1637db44413e
208b813c04ef



















1637db44413e






860c9c54272d
208b813c04ef

1637db44413e

51c060a06937


860c9c54272d
f60c4a02aa05
51c060a06937



5dd72ecb0166





d29f73db7910
5dd72ecb0166


d96d1337e339
1637db44413e

1637db44413e
034bd7b5d926
208b813c04ef
1637db44413e
51c060a06937




d29f73db7910

51c060a06937

1637db44413e
51c060a06937

f60c4a02aa05
1637db44413e



1637db44413e
d96d1337e339







21b185f8d595



e65bc6ac6fa5
21b185f8d595


















e65bc6ac6fa5
21b185f8d595











1637db44413e
860c9c54272d
1637db44413e







e53f5ac52ec1
cb6c89a094df
f8c6f4e9a40d

cb6c89a094df
1637db44413e


860c9c54272d
1637db44413e

17666ef3c765
1637db44413e






e53f5ac52ec1
f8c6f4e9a40d
43a4360ea8f0


f8c6f4e9a40d


1637db44413e

f8c6f4e9a40d
1637db44413e
43a4360ea8f0
5dd72ecb0166

43a4360ea8f0
f8c6f4e9a40d

43a4360ea8f0



d29f73db7910
f8c6f4e9a40d
43a4360ea8f0



f8c6f4e9a40d
43a4360ea8f0
a35e1fd26826
7cbb753701d1
f8c6f4e9a40d
7cbb753701d1
1637db44413e



74112d3f3a64


1637db44413e













d96d1337e339















59c85e82c2e7
1637db44413e
1637db44413e



f59c2576c12d
1637db44413e

d96d1337e339

















d536321df392
1637db44413e



d96d1337e339
1637db44413e
5aaaeba82e00
1637db44413e
d96d1337e339
59c85e82c2e7








d536321df392
59c85e82c2e7
59c85e82c2e7
















d96d1337e339
5f9c035cae18
1637db44413e
d536321df392












1637db44413e

7cbb753701d1
1637db44413e
7cbb753701d1
1637db44413e



7cbb753701d1
1637db44413e
d536321df392
















a7e57dce02ce
















d536321df392

























a7e57dce02ce






d536321df392









67be8e32c9f9
1637db44413e
f8c6f4e9a40d
26d25ae3f0d8
1637db44413e
1637db44413e
f8c6f4e9a40d
1637db44413e
860c9c54272d
f8c6f4e9a40d
7cbb753701d1
1637db44413e
1637db44413e
3b99fb7656a7
c3db00cc80cf
67be8e32c9f9

c3db00cc80cf
3b99fb7656a7
c3db00cc80cf
3b99fb7656a7
c3db00cc80cf
034bd7b5d926
67be8e32c9f9
c3db00cc80cf
3b99fb7656a7
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586









                                                                              




                            
                       
 

                              
                     
                             
                                       











                                                                  
                                   





                                           





                                                                   
                                                       




                                                               



                                                 
                               
 



                                                       


                                                                           
                               
         







                                                           






                                                                    
                    
                                                           






                                                          
                                           
                                   

                                             
                                                           
                                    
                                    


                                      

                                                                     
 
                                               
 
                                           


                                                          

                              

                                             
                    
 
 
                                                         
 
              





                                                                               
                                                                          



                                                              

                                






                                                                     
 


                                                                 





                                                                               
                                                                         



                                                              


                                        

                                                      

                                                                 
                                                  
                                                                        
                                                  


                                       
                                        



















                                                                       






                                                                             
                                                

                                                                 

                    


                                                                             
                                                                                
                                                         



                                                              





                                                                    
                                                               


                                                                       
 

                   
 
                                                                 
                                                                  
 




                                                                  

                                                                          

                                       
         

                                           
                                                       



                   
 







                                                     



                                                            
                                              


















                                                      
                                  











                                                   
   
                                                                            







                                                                         
                                                        
 

                                                                   
                 


   
                                                                           

                                                                         
                                                                          






                                                                       
                                                        
                                                      


                                 


                                                               

                              
                                        
 
                                                  

                            
 

                                                                         



                                   
                                                              
                                                                  



                                   
                               
 
                    
                                         
                            
                                                 



                   


                                                      













                                                                       















                                                                        
                          
                    



                                           
                                      

  

















                                                                  
                                                                             



                                                 
                      
                                                
                                              
                                              
 








                                                                           
 
                                                                
















                                                                         
                 
                                       
         












                                                           

                    
                                 
 
                                               



                                       
                                
 
















                                                                            
















                                                                               

























                                                                     






                                                                  









                                                                            
                                                                    
 
                                                      
                                                 
 
 
                                                                      
 
                                                                       
                            
                                                 
 
 
                                                              
 

                                                                 
 
                                               
 
                                                              
 
                                                            
                                                                  
 
                                               
/* The industrial I/O core, trigger handling functions
 *
 * Copyright (c) 2008 Jonathan Cameron
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 2 as published by
 * the Free Software Foundation.
 */

#include <linux/kernel.h>
#include <linux/idr.h>
#include <linux/err.h>
#include <linux/device.h>
#include <linux/interrupt.h>
#include <linux/list.h>
#include <linux/slab.h>

#include <linux/iio/iio.h>
#include <linux/iio/trigger.h>
#include "iio_core.h"
#include "iio_core_trigger.h"
#include <linux/iio/trigger_consumer.h>

/* RFC - Question of approach
 * Make the common case (single sensor single trigger)
 * simple by starting trigger capture from when first sensors
 * is added.
 *
 * Complex simultaneous start requires use of 'hold' functionality
 * of the trigger. (not implemented)
 *
 * Any other suggestions?
 */

static DEFINE_IDA(iio_trigger_ida);

/* Single list of all available triggers */
static LIST_HEAD(iio_trigger_list);
static DEFINE_MUTEX(iio_trigger_list_lock);

/**
 * iio_trigger_read_name() - retrieve useful identifying name
 **/
static ssize_t iio_trigger_read_name(struct device *dev,
				     struct device_attribute *attr,
				     char *buf)
{
	struct iio_trigger *trig = to_iio_trigger(dev);
	return sprintf(buf, "%s\n", trig->name);
}

static DEVICE_ATTR(name, S_IRUGO, iio_trigger_read_name, NULL);

static struct attribute *iio_trig_dev_attrs[] = {
	&dev_attr_name.attr,
	NULL,
};
ATTRIBUTE_GROUPS(iio_trig_dev);

int iio_trigger_register(struct iio_trigger *trig_info)
{
	int ret;

	trig_info->id = ida_simple_get(&iio_trigger_ida, 0, 0, GFP_KERNEL);
	if (trig_info->id < 0) {
		ret = trig_info->id;
		goto error_ret;
	}
	/* Set the name used for the sysfs directory etc */
	dev_set_name(&trig_info->dev, "trigger%ld",
		     (unsigned long) trig_info->id);

	ret = device_add(&trig_info->dev);
	if (ret)
		goto error_unregister_id;

	/* Add to list of available triggers held by the IIO core */
	mutex_lock(&iio_trigger_list_lock);
	list_add_tail(&trig_info->list, &iio_trigger_list);
	mutex_unlock(&iio_trigger_list_lock);

	return 0;

error_unregister_id:
	ida_simple_remove(&iio_trigger_ida, trig_info->id);
error_ret:
	return ret;
}
EXPORT_SYMBOL(iio_trigger_register);

void iio_trigger_unregister(struct iio_trigger *trig_info)
{
	mutex_lock(&iio_trigger_list_lock);
	list_del(&trig_info->list);
	mutex_unlock(&iio_trigger_list_lock);

	ida_simple_remove(&iio_trigger_ida, trig_info->id);
	/* Possible issue in here */
	device_del(&trig_info->dev);
}
EXPORT_SYMBOL(iio_trigger_unregister);

static struct iio_trigger *iio_trigger_find_by_name(const char *name,
						    size_t len)
{
	struct iio_trigger *trig = NULL, *iter;

	mutex_lock(&iio_trigger_list_lock);
	list_for_each_entry(iter, &iio_trigger_list, list)
		if (sysfs_streq(iter->name, name)) {
			trig = iter;
			break;
		}
	mutex_unlock(&iio_trigger_list_lock);

	return trig;
}

void iio_trigger_poll(struct iio_trigger *trig, s64 time)
{
	int i;

	if (!atomic_read(&trig->use_count)) {
		atomic_set(&trig->use_count, CONFIG_IIO_CONSUMERS_PER_TRIGGER);

		for (i = 0; i < CONFIG_IIO_CONSUMERS_PER_TRIGGER; i++) {
			if (trig->subirqs[i].enabled)
				generic_handle_irq(trig->subirq_base + i);
			else
				iio_trigger_notify_done(trig);
		}
	}
}
EXPORT_SYMBOL(iio_trigger_poll);

irqreturn_t iio_trigger_generic_data_rdy_poll(int irq, void *private)
{
	iio_trigger_poll(private, iio_get_time_ns());
	return IRQ_HANDLED;
}
EXPORT_SYMBOL(iio_trigger_generic_data_rdy_poll);

void iio_trigger_poll_chained(struct iio_trigger *trig, s64 time)
{
	int i;

	if (!atomic_read(&trig->use_count)) {
		atomic_set(&trig->use_count, CONFIG_IIO_CONSUMERS_PER_TRIGGER);

		for (i = 0; i < CONFIG_IIO_CONSUMERS_PER_TRIGGER; i++) {
			if (trig->subirqs[i].enabled)
				handle_nested_irq(trig->subirq_base + i);
			else
				iio_trigger_notify_done(trig);
		}
	}
}
EXPORT_SYMBOL(iio_trigger_poll_chained);

void iio_trigger_notify_done(struct iio_trigger *trig)
{
	if (atomic_dec_and_test(&trig->use_count) && trig->ops &&
		trig->ops->try_reenable)
		if (trig->ops->try_reenable(trig))
			/* Missed an interrupt so launch new poll now */
			iio_trigger_poll(trig, 0);
}
EXPORT_SYMBOL(iio_trigger_notify_done);

/* Trigger Consumer related functions */
static int iio_trigger_get_irq(struct iio_trigger *trig)
{
	int ret;
	mutex_lock(&trig->pool_lock);
	ret = bitmap_find_free_region(trig->pool,
				      CONFIG_IIO_CONSUMERS_PER_TRIGGER,
				      ilog2(1));
	mutex_unlock(&trig->pool_lock);
	if (ret >= 0)
		ret += trig->subirq_base;

	return ret;
}

static void iio_trigger_put_irq(struct iio_trigger *trig, int irq)
{
	mutex_lock(&trig->pool_lock);
	clear_bit(irq - trig->subirq_base, trig->pool);
	mutex_unlock(&trig->pool_lock);
}

/* Complexity in here.  With certain triggers (datardy) an acknowledgement
 * may be needed if the pollfuncs do not include the data read for the
 * triggering device.
 * This is not currently handled.  Alternative of not enabling trigger unless
 * the relevant function is in there may be the best option.
 */
/* Worth protecting against double additions? */
static int iio_trigger_attach_poll_func(struct iio_trigger *trig,
					struct iio_poll_func *pf)
{
	int ret = 0;
	bool notinuse
		= bitmap_empty(trig->pool, CONFIG_IIO_CONSUMERS_PER_TRIGGER);

	/* Prevent the module from being removed whilst attached to a trigger */
	__module_get(pf->indio_dev->info->driver_module);
	pf->irq = iio_trigger_get_irq(trig);
	ret = request_threaded_irq(pf->irq, pf->h, pf->thread,
				   pf->type, pf->name,
				   pf);
	if (ret < 0) {
		module_put(pf->indio_dev->info->driver_module);
		return ret;
	}

	if (trig->ops && trig->ops->set_trigger_state && notinuse) {
		ret = trig->ops->set_trigger_state(trig, true);
		if (ret < 0)
			module_put(pf->indio_dev->info->driver_module);
	}

	return ret;
}

static int iio_trigger_detach_poll_func(struct iio_trigger *trig,
					 struct iio_poll_func *pf)
{
	int ret = 0;
	bool no_other_users
		= (bitmap_weight(trig->pool,
				 CONFIG_IIO_CONSUMERS_PER_TRIGGER)
		   == 1);
	if (trig->ops && trig->ops->set_trigger_state && no_other_users) {
		ret = trig->ops->set_trigger_state(trig, false);
		if (ret)
			goto error_ret;
	}
	iio_trigger_put_irq(trig, pf->irq);
	free_irq(pf->irq, pf);
	module_put(pf->indio_dev->info->driver_module);

error_ret:
	return ret;
}

irqreturn_t iio_pollfunc_store_time(int irq, void *p)
{
	struct iio_poll_func *pf = p;
	pf->timestamp = iio_get_time_ns();
	return IRQ_WAKE_THREAD;
}
EXPORT_SYMBOL(iio_pollfunc_store_time);

struct iio_poll_func
*iio_alloc_pollfunc(irqreturn_t (*h)(int irq, void *p),
		    irqreturn_t (*thread)(int irq, void *p),
		    int type,
		    struct iio_dev *indio_dev,
		    const char *fmt,
		    ...)
{
	va_list vargs;
	struct iio_poll_func *pf;

	pf = kmalloc(sizeof *pf, GFP_KERNEL);
	if (pf == NULL)
		return NULL;
	va_start(vargs, fmt);
	pf->name = kvasprintf(GFP_KERNEL, fmt, vargs);
	va_end(vargs);
	if (pf->name == NULL) {
		kfree(pf);
		return NULL;
	}
	pf->h = h;
	pf->thread = thread;
	pf->type = type;
	pf->indio_dev = indio_dev;

	return pf;
}
EXPORT_SYMBOL_GPL(iio_alloc_pollfunc);

void iio_dealloc_pollfunc(struct iio_poll_func *pf)
{
	kfree(pf->name);
	kfree(pf);
}
EXPORT_SYMBOL_GPL(iio_dealloc_pollfunc);

/**
 * iio_trigger_read_current() - trigger consumer sysfs query current trigger
 *
 * For trigger consumers the current_trigger interface allows the trigger
 * used by the device to be queried.
 **/
static ssize_t iio_trigger_read_current(struct device *dev,
					struct device_attribute *attr,
					char *buf)
{
	struct iio_dev *indio_dev = dev_to_iio_dev(dev);

	if (indio_dev->trig)
		return sprintf(buf, "%s\n", indio_dev->trig->name);
	return 0;
}

/**
 * iio_trigger_write_current() - trigger consumer sysfs set current trigger
 *
 * For trigger consumers the current_trigger interface allows the trigger
 * used for this device to be specified at run time based on the trigger's
 * name.
 **/
static ssize_t iio_trigger_write_current(struct device *dev,
					 struct device_attribute *attr,
					 const char *buf,
					 size_t len)
{
	struct iio_dev *indio_dev = dev_to_iio_dev(dev);
	struct iio_trigger *oldtrig = indio_dev->trig;
	struct iio_trigger *trig;
	int ret;

	mutex_lock(&indio_dev->mlock);
	if (indio_dev->currentmode == INDIO_BUFFER_TRIGGERED) {
		mutex_unlock(&indio_dev->mlock);
		return -EBUSY;
	}
	mutex_unlock(&indio_dev->mlock);

	trig = iio_trigger_find_by_name(buf, len);
	if (oldtrig == trig)
		return len;

	if (trig && indio_dev->info->validate_trigger) {
		ret = indio_dev->info->validate_trigger(indio_dev, trig);
		if (ret)
			return ret;
	}

	if (trig && trig->ops && trig->ops->validate_device) {
		ret = trig->ops->validate_device(trig, indio_dev);
		if (ret)
			return ret;
	}

	indio_dev->trig = trig;

	if (oldtrig)
		iio_trigger_put(oldtrig);
	if (indio_dev->trig)
		iio_trigger_get(indio_dev->trig);

	return len;
}

static DEVICE_ATTR(current_trigger, S_IRUGO | S_IWUSR,
		   iio_trigger_read_current,
		   iio_trigger_write_current);

static struct attribute *iio_trigger_consumer_attrs[] = {
	&dev_attr_current_trigger.attr,
	NULL,
};

static const struct attribute_group iio_trigger_consumer_attr_group = {
	.name = "trigger",
	.attrs = iio_trigger_consumer_attrs,
};

static void iio_trig_release(struct device *device)
{
	struct iio_trigger *trig = to_iio_trigger(device);
	int i;

	if (trig->subirq_base) {
		for (i = 0; i < CONFIG_IIO_CONSUMERS_PER_TRIGGER; i++) {
			irq_modify_status(trig->subirq_base + i,
					  IRQ_NOAUTOEN,
					  IRQ_NOREQUEST | IRQ_NOPROBE);
			irq_set_chip(trig->subirq_base + i,
				     NULL);
			irq_set_handler(trig->subirq_base + i,
					NULL);
		}

		irq_free_descs(trig->subirq_base,
			       CONFIG_IIO_CONSUMERS_PER_TRIGGER);
	}
	kfree(trig->name);
	kfree(trig);
}

static struct device_type iio_trig_type = {
	.release = iio_trig_release,
	.groups = iio_trig_dev_groups,
};

static void iio_trig_subirqmask(struct irq_data *d)
{
	struct irq_chip *chip = irq_data_get_irq_chip(d);
	struct iio_trigger *trig
		= container_of(chip,
			       struct iio_trigger, subirq_chip);
	trig->subirqs[d->irq - trig->subirq_base].enabled = false;
}

static void iio_trig_subirqunmask(struct irq_data *d)
{
	struct irq_chip *chip = irq_data_get_irq_chip(d);
	struct iio_trigger *trig