blob: 9ab19a8f669dfa5a5b2fef8942aff5e90df3d073 [file] [log] [blame]
Balaji Rao6a3d1192009-01-09 01:49:37 +01001/* NXP PCF50633 GPIO Driver
2 *
3 * (C) 2006-2008 by Openmoko, Inc.
4 * Author: Balaji Rao <balajirrao@openmoko.org>
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>
Adrian Bunk1346a1c2009-05-12 13:45:14 -070018#include <linux/module.h>
Balaji Rao6a3d1192009-01-09 01:49:37 +010019
20#include <linux/mfd/pcf50633/core.h>
21#include <linux/mfd/pcf50633/gpio.h>
22
23enum pcf50633_regulator_id {
24 PCF50633_REGULATOR_AUTO,
25 PCF50633_REGULATOR_DOWN1,
26 PCF50633_REGULATOR_DOWN2,
27 PCF50633_REGULATOR_LDO1,
28 PCF50633_REGULATOR_LDO2,
29 PCF50633_REGULATOR_LDO3,
30 PCF50633_REGULATOR_LDO4,
31 PCF50633_REGULATOR_LDO5,
32 PCF50633_REGULATOR_LDO6,
33 PCF50633_REGULATOR_HCLDO,
34 PCF50633_REGULATOR_MEMLDO,
35};
36
37#define PCF50633_REG_AUTOOUT 0x1a
38#define PCF50633_REG_DOWN1OUT 0x1e
39#define PCF50633_REG_DOWN2OUT 0x22
40#define PCF50633_REG_MEMLDOOUT 0x26
41#define PCF50633_REG_LDO1OUT 0x2d
42#define PCF50633_REG_LDO2OUT 0x2f
43#define PCF50633_REG_LDO3OUT 0x31
44#define PCF50633_REG_LDO4OUT 0x33
45#define PCF50633_REG_LDO5OUT 0x35
46#define PCF50633_REG_LDO6OUT 0x37
47#define PCF50633_REG_HCLDOOUT 0x39
48
49static const u8 pcf50633_regulator_registers[PCF50633_NUM_REGULATORS] = {
50 [PCF50633_REGULATOR_AUTO] = PCF50633_REG_AUTOOUT,
51 [PCF50633_REGULATOR_DOWN1] = PCF50633_REG_DOWN1OUT,
52 [PCF50633_REGULATOR_DOWN2] = PCF50633_REG_DOWN2OUT,
53 [PCF50633_REGULATOR_MEMLDO] = PCF50633_REG_MEMLDOOUT,
54 [PCF50633_REGULATOR_LDO1] = PCF50633_REG_LDO1OUT,
55 [PCF50633_REGULATOR_LDO2] = PCF50633_REG_LDO2OUT,
56 [PCF50633_REGULATOR_LDO3] = PCF50633_REG_LDO3OUT,
57 [PCF50633_REGULATOR_LDO4] = PCF50633_REG_LDO4OUT,
58 [PCF50633_REGULATOR_LDO5] = PCF50633_REG_LDO5OUT,
59 [PCF50633_REGULATOR_LDO6] = PCF50633_REG_LDO6OUT,
60 [PCF50633_REGULATOR_HCLDO] = PCF50633_REG_HCLDOOUT,
61};
62
63int pcf50633_gpio_set(struct pcf50633 *pcf, int gpio, u8 val)
64{
65 u8 reg;
66
67 reg = gpio - PCF50633_GPIO1 + PCF50633_REG_GPIO1CFG;
68
69 return pcf50633_reg_set_bit_mask(pcf, reg, 0x07, val);
70}
71EXPORT_SYMBOL_GPL(pcf50633_gpio_set);
72
73u8 pcf50633_gpio_get(struct pcf50633 *pcf, int gpio)
74{
75 u8 reg, val;
76
77 reg = gpio - PCF50633_GPIO1 + PCF50633_REG_GPIO1CFG;
78 val = pcf50633_reg_read(pcf, reg) & 0x07;
79
80 return val;
81}
82EXPORT_SYMBOL_GPL(pcf50633_gpio_get);
83
84int pcf50633_gpio_invert_set(struct pcf50633 *pcf, int gpio, int invert)
85{
86 u8 val, reg;
87
88 reg = gpio - PCF50633_GPIO1 + PCF50633_REG_GPIO1CFG;
89 val = !!invert << 3;
90
91 return pcf50633_reg_set_bit_mask(pcf, reg, 1 << 3, val);
92}
93EXPORT_SYMBOL_GPL(pcf50633_gpio_invert_set);
94
95int pcf50633_gpio_invert_get(struct pcf50633 *pcf, int gpio)
96{
97 u8 reg, val;
98
99 reg = gpio - PCF50633_GPIO1 + PCF50633_REG_GPIO1CFG;
100 val = pcf50633_reg_read(pcf, reg);
101
102 return val & (1 << 3);
103}
104EXPORT_SYMBOL_GPL(pcf50633_gpio_invert_get);
105
106int pcf50633_gpio_power_supply_set(struct pcf50633 *pcf,
107 int gpio, int regulator, int on)
108{
109 u8 reg, val, mask;
110
111 /* the *ENA register is always one after the *OUT register */
112 reg = pcf50633_regulator_registers[regulator] + 1;
113
114 val = !!on << (gpio - PCF50633_GPIO1);
115 mask = 1 << (gpio - PCF50633_GPIO1);
116
117 return pcf50633_reg_set_bit_mask(pcf, reg, mask, val);
118}
119EXPORT_SYMBOL_GPL(pcf50633_gpio_power_supply_set);
Adrian Bunk1346a1c2009-05-12 13:45:14 -0700120
121MODULE_LICENSE("GPL");