1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /* NXP PCF50633 GPIO Driver
4 * (C) 2006-2008 by Openmoko, Inc.
5 * Author: Balaji Rao <balajirrao@openmoko.org>
8 * Broken down from monstrous PCF50633 driver mainly by
9 * Harald Welte, Andy Green and Werner Almesberger
12 #include <linux/kernel.h>
13 #include <linux/module.h>
15 #include <linux/mfd/pcf50633/core.h>
16 #include <linux/mfd/pcf50633/gpio.h>
17 #include <linux/mfd/pcf50633/pmic.h>
19 static const u8 pcf50633_regulator_registers
[PCF50633_NUM_REGULATORS
] = {
20 [PCF50633_REGULATOR_AUTO
] = PCF50633_REG_AUTOOUT
,
21 [PCF50633_REGULATOR_DOWN1
] = PCF50633_REG_DOWN1OUT
,
22 [PCF50633_REGULATOR_DOWN2
] = PCF50633_REG_DOWN2OUT
,
23 [PCF50633_REGULATOR_MEMLDO
] = PCF50633_REG_MEMLDOOUT
,
24 [PCF50633_REGULATOR_LDO1
] = PCF50633_REG_LDO1OUT
,
25 [PCF50633_REGULATOR_LDO2
] = PCF50633_REG_LDO2OUT
,
26 [PCF50633_REGULATOR_LDO3
] = PCF50633_REG_LDO3OUT
,
27 [PCF50633_REGULATOR_LDO4
] = PCF50633_REG_LDO4OUT
,
28 [PCF50633_REGULATOR_LDO5
] = PCF50633_REG_LDO5OUT
,
29 [PCF50633_REGULATOR_LDO6
] = PCF50633_REG_LDO6OUT
,
30 [PCF50633_REGULATOR_HCLDO
] = PCF50633_REG_HCLDOOUT
,
33 int pcf50633_gpio_set(struct pcf50633
*pcf
, int gpio
, u8 val
)
37 reg
= gpio
- PCF50633_GPIO1
+ PCF50633_REG_GPIO1CFG
;
39 return pcf50633_reg_set_bit_mask(pcf
, reg
, 0x07, val
);
41 EXPORT_SYMBOL_GPL(pcf50633_gpio_set
);
43 u8
pcf50633_gpio_get(struct pcf50633
*pcf
, int gpio
)
47 reg
= gpio
- PCF50633_GPIO1
+ PCF50633_REG_GPIO1CFG
;
48 val
= pcf50633_reg_read(pcf
, reg
) & 0x07;
52 EXPORT_SYMBOL_GPL(pcf50633_gpio_get
);
54 int pcf50633_gpio_invert_set(struct pcf50633
*pcf
, int gpio
, int invert
)
58 reg
= gpio
- PCF50633_GPIO1
+ PCF50633_REG_GPIO1CFG
;
61 return pcf50633_reg_set_bit_mask(pcf
, reg
, 1 << 3, val
);
63 EXPORT_SYMBOL_GPL(pcf50633_gpio_invert_set
);
65 int pcf50633_gpio_invert_get(struct pcf50633
*pcf
, int gpio
)
69 reg
= gpio
- PCF50633_GPIO1
+ PCF50633_REG_GPIO1CFG
;
70 val
= pcf50633_reg_read(pcf
, reg
);
72 return val
& (1 << 3);
74 EXPORT_SYMBOL_GPL(pcf50633_gpio_invert_get
);
76 int pcf50633_gpio_power_supply_set(struct pcf50633
*pcf
,
77 int gpio
, int regulator
, int on
)
81 /* the *ENA register is always one after the *OUT register */
82 reg
= pcf50633_regulator_registers
[regulator
] + 1;
84 val
= !!on
<< (gpio
- PCF50633_GPIO1
);
85 mask
= 1 << (gpio
- PCF50633_GPIO1
);
87 return pcf50633_reg_set_bit_mask(pcf
, reg
, mask
, val
);
89 EXPORT_SYMBOL_GPL(pcf50633_gpio_power_supply_set
);
91 MODULE_LICENSE("GPL");