Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
pcf50633-gpio.c
Go to the documentation of this file.
1 /* NXP PCF50633 GPIO Driver
2  *
3  * (C) 2006-2008 by Openmoko, Inc.
4  * Author: Balaji Rao <[email protected]>
5  * All rights reserved.
6  *
7  * Broken down from monstrous PCF50633 driver mainly by
8  * Harald Welte, Andy Green and Werner Almesberger
9  *
10  * This program is free software; you can redistribute it and/or modify it
11  * under the terms of the GNU General Public License as published by the
12  * Free Software Foundation; either version 2 of the License, or (at your
13  * option) any later version.
14  *
15  */
16 
17 #include <linux/kernel.h>
18 #include <linux/module.h>
19 
23 
24 static const u8 pcf50633_regulator_registers[PCF50633_NUM_REGULATORS] = {
36 };
37 
38 int pcf50633_gpio_set(struct pcf50633 *pcf, int gpio, u8 val)
39 {
40  u8 reg;
41 
43 
44  return pcf50633_reg_set_bit_mask(pcf, reg, 0x07, val);
45 }
47 
48 u8 pcf50633_gpio_get(struct pcf50633 *pcf, int gpio)
49 {
50  u8 reg, val;
51 
53  val = pcf50633_reg_read(pcf, reg) & 0x07;
54 
55  return val;
56 }
58 
59 int pcf50633_gpio_invert_set(struct pcf50633 *pcf, int gpio, int invert)
60 {
61  u8 val, reg;
62 
64  val = !!invert << 3;
65 
66  return pcf50633_reg_set_bit_mask(pcf, reg, 1 << 3, val);
67 }
69 
70 int pcf50633_gpio_invert_get(struct pcf50633 *pcf, int gpio)
71 {
72  u8 reg, val;
73 
75  val = pcf50633_reg_read(pcf, reg);
76 
77  return val & (1 << 3);
78 }
80 
82  int gpio, int regulator, int on)
83 {
84  u8 reg, val, mask;
85 
86  /* the *ENA register is always one after the *OUT register */
87  reg = pcf50633_regulator_registers[regulator] + 1;
88 
89  val = !!on << (gpio - PCF50633_GPIO1);
90  mask = 1 << (gpio - PCF50633_GPIO1);
91 
92  return pcf50633_reg_set_bit_mask(pcf, reg, mask, val);
93 }
95 
96 MODULE_LICENSE("GPL");