^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0+
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * gpiolib support for Wolfson WM8994
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright 2009 Wolfson Microelectronics PLC.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * Author: Mark Brown <broonie@opensource.wolfsonmicro.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/gpio/driver.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/mfd/core.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/platform_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/seq_file.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <linux/regmap.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <linux/mfd/wm8994/core.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include <linux/mfd/wm8994/pdata.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include <linux/mfd/wm8994/gpio.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #include <linux/mfd/wm8994/registers.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) struct wm8994_gpio {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) struct wm8994 *wm8994;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) struct gpio_chip gpio_chip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) static int wm8994_gpio_request(struct gpio_chip *chip, unsigned offset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) struct wm8994_gpio *wm8994_gpio = gpiochip_get_data(chip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) struct wm8994 *wm8994 = wm8994_gpio->wm8994;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) switch (wm8994->type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) case WM8958:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) switch (offset) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) case 1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) case 2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) case 3:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) case 4:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) case 6:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) static int wm8994_gpio_direction_in(struct gpio_chip *chip, unsigned offset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) struct wm8994_gpio *wm8994_gpio = gpiochip_get_data(chip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) struct wm8994 *wm8994 = wm8994_gpio->wm8994;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) return wm8994_set_bits(wm8994, WM8994_GPIO_1 + offset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) WM8994_GPN_DIR, WM8994_GPN_DIR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) static int wm8994_gpio_get(struct gpio_chip *chip, unsigned offset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) struct wm8994_gpio *wm8994_gpio = gpiochip_get_data(chip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) struct wm8994 *wm8994 = wm8994_gpio->wm8994;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) ret = wm8994_reg_read(wm8994, WM8994_GPIO_1 + offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) if (ret & WM8994_GPN_LVL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) static int wm8994_gpio_direction_out(struct gpio_chip *chip,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) unsigned offset, int value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) struct wm8994_gpio *wm8994_gpio = gpiochip_get_data(chip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) struct wm8994 *wm8994 = wm8994_gpio->wm8994;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) if (value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) value = WM8994_GPN_LVL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) return wm8994_set_bits(wm8994, WM8994_GPIO_1 + offset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) WM8994_GPN_DIR | WM8994_GPN_LVL, value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) static void wm8994_gpio_set(struct gpio_chip *chip, unsigned offset, int value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) struct wm8994_gpio *wm8994_gpio = gpiochip_get_data(chip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) struct wm8994 *wm8994 = wm8994_gpio->wm8994;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) if (value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) value = WM8994_GPN_LVL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) wm8994_set_bits(wm8994, WM8994_GPIO_1 + offset, WM8994_GPN_LVL, value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) static int wm8994_gpio_set_config(struct gpio_chip *chip, unsigned int offset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) unsigned long config)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) struct wm8994_gpio *wm8994_gpio = gpiochip_get_data(chip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) struct wm8994 *wm8994 = wm8994_gpio->wm8994;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) switch (pinconf_to_config_param(config)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) case PIN_CONFIG_DRIVE_OPEN_DRAIN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) return wm8994_set_bits(wm8994, WM8994_GPIO_1 + offset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) WM8994_GPN_OP_CFG_MASK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) WM8994_GPN_OP_CFG);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) case PIN_CONFIG_DRIVE_PUSH_PULL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) return wm8994_set_bits(wm8994, WM8994_GPIO_1 + offset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) WM8994_GPN_OP_CFG_MASK, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) return -ENOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) static int wm8994_gpio_to_irq(struct gpio_chip *chip, unsigned offset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) struct wm8994_gpio *wm8994_gpio = gpiochip_get_data(chip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) struct wm8994 *wm8994 = wm8994_gpio->wm8994;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) return regmap_irq_get_virq(wm8994->irq_data, offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) #ifdef CONFIG_DEBUG_FS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) static const char *wm8994_gpio_fn(u16 fn)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) switch (fn) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) case WM8994_GP_FN_PIN_SPECIFIC:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) return "pin-specific";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) case WM8994_GP_FN_GPIO:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) return "GPIO";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) case WM8994_GP_FN_SDOUT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) return "SDOUT";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) case WM8994_GP_FN_IRQ:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) return "IRQ";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) case WM8994_GP_FN_TEMPERATURE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) return "Temperature";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) case WM8994_GP_FN_MICBIAS1_DET:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) return "MICBIAS1 detect";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) case WM8994_GP_FN_MICBIAS1_SHORT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) return "MICBIAS1 short";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) case WM8994_GP_FN_MICBIAS2_DET:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) return "MICBIAS2 detect";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) case WM8994_GP_FN_MICBIAS2_SHORT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) return "MICBIAS2 short";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) case WM8994_GP_FN_FLL1_LOCK:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) return "FLL1 lock";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) case WM8994_GP_FN_FLL2_LOCK:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) return "FLL2 lock";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) case WM8994_GP_FN_SRC1_LOCK:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) return "SRC1 lock";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) case WM8994_GP_FN_SRC2_LOCK:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) return "SRC2 lock";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) case WM8994_GP_FN_DRC1_ACT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) return "DRC1 activity";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) case WM8994_GP_FN_DRC2_ACT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) return "DRC2 activity";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) case WM8994_GP_FN_DRC3_ACT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) return "DRC3 activity";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) case WM8994_GP_FN_WSEQ_STATUS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) return "Write sequencer";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) case WM8994_GP_FN_FIFO_ERROR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) return "FIFO error";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) case WM8994_GP_FN_OPCLK:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) return "OPCLK";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) case WM8994_GP_FN_THW:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) return "Thermal warning";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) case WM8994_GP_FN_DCS_DONE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) return "DC servo";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) case WM8994_GP_FN_FLL1_OUT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) return "FLL1 output";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) case WM8994_GP_FN_FLL2_OUT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) return "FLL1 output";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) return "Unknown";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) static void wm8994_gpio_dbg_show(struct seq_file *s, struct gpio_chip *chip)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) struct wm8994_gpio *wm8994_gpio = gpiochip_get_data(chip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) struct wm8994 *wm8994 = wm8994_gpio->wm8994;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) for (i = 0; i < chip->ngpio; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) int gpio = i + chip->base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) int reg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) const char *label;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) /* We report the GPIO even if it's not requested since
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) * we're also reporting things like alternate
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) * functions which apply even when the GPIO is not in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) * use as a GPIO.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) label = gpiochip_is_requested(chip, i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) if (!label)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) label = "Unrequested";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) seq_printf(s, " gpio-%-3d (%-20.20s) ", gpio, label);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) reg = wm8994_reg_read(wm8994, WM8994_GPIO_1 + i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) if (reg < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) dev_err(wm8994->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) "GPIO control %d read failed: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) gpio, reg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) seq_printf(s, "\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) if (reg & WM8994_GPN_DIR)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) seq_printf(s, "in ");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) seq_printf(s, "out ");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) if (reg & WM8994_GPN_PU)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) seq_printf(s, "pull up ");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) if (reg & WM8994_GPN_PD)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) seq_printf(s, "pull down ");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) if (reg & WM8994_GPN_POL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) seq_printf(s, "inverted ");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) seq_printf(s, "noninverted ");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) if (reg & WM8994_GPN_OP_CFG)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) seq_printf(s, "open drain ");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) seq_printf(s, "push-pull ");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) seq_printf(s, "%s (%x)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) wm8994_gpio_fn(reg & WM8994_GPN_FN_MASK), reg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) #define wm8994_gpio_dbg_show NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) static const struct gpio_chip template_chip = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) .label = "wm8994",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) .owner = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) .request = wm8994_gpio_request,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) .direction_input = wm8994_gpio_direction_in,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) .get = wm8994_gpio_get,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) .direction_output = wm8994_gpio_direction_out,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) .set = wm8994_gpio_set,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) .set_config = wm8994_gpio_set_config,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) .to_irq = wm8994_gpio_to_irq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) .dbg_show = wm8994_gpio_dbg_show,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) .can_sleep = true,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) static int wm8994_gpio_probe(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) struct wm8994 *wm8994 = dev_get_drvdata(pdev->dev.parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) struct wm8994_pdata *pdata = dev_get_platdata(wm8994->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) struct wm8994_gpio *wm8994_gpio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) wm8994_gpio = devm_kzalloc(&pdev->dev, sizeof(*wm8994_gpio),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) if (wm8994_gpio == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) wm8994_gpio->wm8994 = wm8994;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) wm8994_gpio->gpio_chip = template_chip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) wm8994_gpio->gpio_chip.ngpio = WM8994_GPIO_MAX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) wm8994_gpio->gpio_chip.parent = &pdev->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) if (pdata && pdata->gpio_base)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) wm8994_gpio->gpio_chip.base = pdata->gpio_base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) wm8994_gpio->gpio_chip.base = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) ret = devm_gpiochip_add_data(&pdev->dev, &wm8994_gpio->gpio_chip,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) wm8994_gpio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) dev_err(&pdev->dev, "Could not register gpiochip, %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) platform_set_drvdata(pdev, wm8994_gpio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) static struct platform_driver wm8994_gpio_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) .driver.name = "wm8994-gpio",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) .probe = wm8994_gpio_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) static int __init wm8994_gpio_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) return platform_driver_register(&wm8994_gpio_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) subsys_initcall(wm8994_gpio_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) static void __exit wm8994_gpio_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) platform_driver_unregister(&wm8994_gpio_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) module_exit(wm8994_gpio_exit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) MODULE_DESCRIPTION("GPIO interface for WM8994");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) MODULE_ALIAS("platform:wm8994-gpio");