Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
vme_pio2_cntr.c
Go to the documentation of this file.
1 /*
2  * GE PIO2 Counter Driver
3  *
4  * Author: Martyn Welch <[email protected]>
5  * Copyright 2009 GE Intelligent Platforms Embedded Systems, Inc.
6  *
7  * This program is free software; you can redistribute it and/or modify it
8  * under the terms of the GNU General Public License as published by the
9  * Free Software Foundation; either version 2 of the License, or (at your
10  * option) any later version.
11  *
12  * The PIO-2 has 6 counters, currently this code just disables the interrupts
13  * and leaves them alone.
14  *
15  */
16 
17 #include <linux/device.h>
18 #include <linux/types.h>
19 #include <linux/gpio.h>
20 #include <linux/vme.h>
21 
22 #include "vme_pio2.h"
23 
24 static int pio2_cntr_irq_set(struct pio2_card *card, int id)
25 {
26  int retval;
27  u8 data;
28 
29  data = PIO2_CNTR_SC_DEV[id] | PIO2_CNTR_RW_BOTH | card->cntr[id].mode;
30  retval = vme_master_write(card->window, &data, 1, PIO2_CNTR_CTRL[id]);
31  if (retval < 0)
32  return retval;
33 
34  data = card->cntr[id].count & 0xFF;
35  retval = vme_master_write(card->window, &data, 1, PIO2_CNTR_DATA[id]);
36  if (retval < 0)
37  return retval;
38 
39  data = (card->cntr[id].count >> 8) & 0xFF;
40  retval = vme_master_write(card->window, &data, 1, PIO2_CNTR_DATA[id]);
41  if (retval < 0)
42  return retval;
43 
44  return 0;
45 }
46 
47 int pio2_cntr_reset(struct pio2_card *card)
48 {
49  int i, retval = 0;
50  u8 reg;
51 
52  /* Clear down all timers */
53  for (i = 0; i < 6; i++) {
54  card->cntr[i].mode = PIO2_CNTR_MODE5;
55  card->cntr[i].count = 0;
56  retval = pio2_cntr_irq_set(card, i);
57  if (retval < 0)
58  return retval;
59  }
60 
61  /* Ensure all counter interrupts are cleared */
62  do {
63  retval = vme_master_read(card->window, &reg, 1,
65  if (retval < 0)
66  return retval;
67  } while (reg != 0);
68 
69  return retval;
70 }
71