12874c5fdSThomas Gleixner // SPDX-License-Identifier: GPL-2.0-or-later
26a3d119bSBalaji Rao /* NXP PCF50633 GPIO Driver
36a3d119bSBalaji Rao *
46a3d119bSBalaji Rao * (C) 2006-2008 by Openmoko, Inc.
56a3d119bSBalaji Rao * Author: Balaji Rao <balajirrao@openmoko.org>
66a3d119bSBalaji Rao * All rights reserved.
76a3d119bSBalaji Rao *
86a3d119bSBalaji Rao * Broken down from monstrous PCF50633 driver mainly by
96a3d119bSBalaji Rao * Harald Welte, Andy Green and Werner Almesberger
106a3d119bSBalaji Rao */
116a3d119bSBalaji Rao
126a3d119bSBalaji Rao #include <linux/kernel.h>
131346a1c7SAdrian Bunk #include <linux/module.h>
146a3d119bSBalaji Rao
156a3d119bSBalaji Rao #include <linux/mfd/pcf50633/core.h>
166a3d119bSBalaji Rao #include <linux/mfd/pcf50633/gpio.h>
177f849a39SAxel Lin #include <linux/mfd/pcf50633/pmic.h>
186a3d119bSBalaji Rao
196a3d119bSBalaji Rao static const u8 pcf50633_regulator_registers[PCF50633_NUM_REGULATORS] = {
206a3d119bSBalaji Rao [PCF50633_REGULATOR_AUTO] = PCF50633_REG_AUTOOUT,
216a3d119bSBalaji Rao [PCF50633_REGULATOR_DOWN1] = PCF50633_REG_DOWN1OUT,
226a3d119bSBalaji Rao [PCF50633_REGULATOR_DOWN2] = PCF50633_REG_DOWN2OUT,
236a3d119bSBalaji Rao [PCF50633_REGULATOR_MEMLDO] = PCF50633_REG_MEMLDOOUT,
246a3d119bSBalaji Rao [PCF50633_REGULATOR_LDO1] = PCF50633_REG_LDO1OUT,
256a3d119bSBalaji Rao [PCF50633_REGULATOR_LDO2] = PCF50633_REG_LDO2OUT,
266a3d119bSBalaji Rao [PCF50633_REGULATOR_LDO3] = PCF50633_REG_LDO3OUT,
276a3d119bSBalaji Rao [PCF50633_REGULATOR_LDO4] = PCF50633_REG_LDO4OUT,
286a3d119bSBalaji Rao [PCF50633_REGULATOR_LDO5] = PCF50633_REG_LDO5OUT,
296a3d119bSBalaji Rao [PCF50633_REGULATOR_LDO6] = PCF50633_REG_LDO6OUT,
306a3d119bSBalaji Rao [PCF50633_REGULATOR_HCLDO] = PCF50633_REG_HCLDOOUT,
316a3d119bSBalaji Rao };
326a3d119bSBalaji Rao
pcf50633_gpio_set(struct pcf50633 * pcf,int gpio,u8 val)336a3d119bSBalaji Rao int pcf50633_gpio_set(struct pcf50633 *pcf, int gpio, u8 val)
346a3d119bSBalaji Rao {
356a3d119bSBalaji Rao u8 reg;
366a3d119bSBalaji Rao
376a3d119bSBalaji Rao reg = gpio - PCF50633_GPIO1 + PCF50633_REG_GPIO1CFG;
386a3d119bSBalaji Rao
396a3d119bSBalaji Rao return pcf50633_reg_set_bit_mask(pcf, reg, 0x07, val);
406a3d119bSBalaji Rao }
416a3d119bSBalaji Rao EXPORT_SYMBOL_GPL(pcf50633_gpio_set);
426a3d119bSBalaji Rao
pcf50633_gpio_get(struct pcf50633 * pcf,int gpio)436a3d119bSBalaji Rao u8 pcf50633_gpio_get(struct pcf50633 *pcf, int gpio)
446a3d119bSBalaji Rao {
456a3d119bSBalaji Rao u8 reg, val;
466a3d119bSBalaji Rao
476a3d119bSBalaji Rao reg = gpio - PCF50633_GPIO1 + PCF50633_REG_GPIO1CFG;
486a3d119bSBalaji Rao val = pcf50633_reg_read(pcf, reg) & 0x07;
496a3d119bSBalaji Rao
506a3d119bSBalaji Rao return val;
516a3d119bSBalaji Rao }
526a3d119bSBalaji Rao EXPORT_SYMBOL_GPL(pcf50633_gpio_get);
536a3d119bSBalaji Rao
pcf50633_gpio_invert_set(struct pcf50633 * pcf,int gpio,int invert)546a3d119bSBalaji Rao int pcf50633_gpio_invert_set(struct pcf50633 *pcf, int gpio, int invert)
556a3d119bSBalaji Rao {
566a3d119bSBalaji Rao u8 val, reg;
576a3d119bSBalaji Rao
586a3d119bSBalaji Rao reg = gpio - PCF50633_GPIO1 + PCF50633_REG_GPIO1CFG;
596a3d119bSBalaji Rao val = !!invert << 3;
606a3d119bSBalaji Rao
616a3d119bSBalaji Rao return pcf50633_reg_set_bit_mask(pcf, reg, 1 << 3, val);
626a3d119bSBalaji Rao }
636a3d119bSBalaji Rao EXPORT_SYMBOL_GPL(pcf50633_gpio_invert_set);
646a3d119bSBalaji Rao
pcf50633_gpio_invert_get(struct pcf50633 * pcf,int gpio)656a3d119bSBalaji Rao int pcf50633_gpio_invert_get(struct pcf50633 *pcf, int gpio)
666a3d119bSBalaji Rao {
676a3d119bSBalaji Rao u8 reg, val;
686a3d119bSBalaji Rao
696a3d119bSBalaji Rao reg = gpio - PCF50633_GPIO1 + PCF50633_REG_GPIO1CFG;
706a3d119bSBalaji Rao val = pcf50633_reg_read(pcf, reg);
716a3d119bSBalaji Rao
726a3d119bSBalaji Rao return val & (1 << 3);
736a3d119bSBalaji Rao }
746a3d119bSBalaji Rao EXPORT_SYMBOL_GPL(pcf50633_gpio_invert_get);
756a3d119bSBalaji Rao
pcf50633_gpio_power_supply_set(struct pcf50633 * pcf,int gpio,int regulator,int on)766a3d119bSBalaji Rao int pcf50633_gpio_power_supply_set(struct pcf50633 *pcf,
776a3d119bSBalaji Rao int gpio, int regulator, int on)
786a3d119bSBalaji Rao {
796a3d119bSBalaji Rao u8 reg, val, mask;
806a3d119bSBalaji Rao
816a3d119bSBalaji Rao /* the *ENA register is always one after the *OUT register */
826a3d119bSBalaji Rao reg = pcf50633_regulator_registers[regulator] + 1;
836a3d119bSBalaji Rao
846a3d119bSBalaji Rao val = !!on << (gpio - PCF50633_GPIO1);
856a3d119bSBalaji Rao mask = 1 << (gpio - PCF50633_GPIO1);
866a3d119bSBalaji Rao
876a3d119bSBalaji Rao return pcf50633_reg_set_bit_mask(pcf, reg, mask, val);
886a3d119bSBalaji Rao }
896a3d119bSBalaji Rao EXPORT_SYMBOL_GPL(pcf50633_gpio_power_supply_set);
901346a1c7SAdrian Bunk
91*5fed47abSJeff Johnson MODULE_DESCRIPTION("NXP PCF50633 GPIO Driver");
921346a1c7SAdrian Bunk MODULE_LICENSE("GPL");
93