···185185 Say yes here to access the GPIO signals of WM831x power management186186 chips from Wolfson Microelectronics.187187188188+config GPIO_WM8350189189+ tristate "WM8350 GPIOs"190190+ depends on MFD_WM8350191191+ help192192+ Say yes here to access the GPIO signals of WM8350 power management193193+ chips from Wolfson Microelectronics.194194+188195config GPIO_ADP5520189196 tristate "GPIO Support for ADP5520 PMIC"190197 depends on PMIC_ADP5520
···11+/*22+ * wm835x-gpiolib.c -- gpiolib support for Wolfson WM835x PMICs33+ *44+ * Copyright 2009 Wolfson Microelectronics PLC.55+ *66+ * Author: Mark Brown <broonie@opensource.wolfsonmicro.com>77+ *88+ * This program is free software; you can redistribute it and/or modify it99+ * under the terms of the GNU General Public License as published by the1010+ * Free Software Foundation; either version 2 of the License, or (at your1111+ * option) any later version.1212+ *1313+ */1414+1515+#include <linux/kernel.h>1616+#include <linux/module.h>1717+#include <linux/gpio.h>1818+#include <linux/mfd/core.h>1919+#include <linux/platform_device.h>2020+#include <linux/seq_file.h>2121+2222+#include <linux/mfd/wm8350/core.h>2323+#include <linux/mfd/wm8350/gpio.h>2424+2525+struct wm8350_gpio_data {2626+ struct wm8350 *wm8350;2727+ struct gpio_chip gpio_chip;2828+};2929+3030+static inline struct wm8350_gpio_data *to_wm8350_gpio(struct gpio_chip *chip)3131+{3232+ return container_of(chip, struct wm8350_gpio_data, gpio_chip);3333+}3434+3535+static int wm8350_gpio_direction_in(struct gpio_chip *chip, unsigned offset)3636+{3737+ struct wm8350_gpio_data *wm8350_gpio = to_wm8350_gpio(chip);3838+ struct wm8350 *wm8350 = wm8350_gpio->wm8350;3939+4040+ return wm8350_set_bits(wm8350, WM8350_GPIO_CONFIGURATION_I_O,4141+ 1 << offset);4242+}4343+4444+static int wm8350_gpio_get(struct gpio_chip *chip, unsigned offset)4545+{4646+ struct wm8350_gpio_data *wm8350_gpio = to_wm8350_gpio(chip);4747+ struct wm8350 *wm8350 = wm8350_gpio->wm8350;4848+ int ret;4949+5050+ ret = wm8350_reg_read(wm8350, WM8350_GPIO_LEVEL);5151+ if (ret < 0)5252+ return ret;5353+5454+ if (ret & (1 << offset))5555+ return 1;5656+ else5757+ return 0;5858+}5959+6060+static void wm8350_gpio_set(struct gpio_chip *chip, unsigned offset, int value)6161+{6262+ struct wm8350_gpio_data *wm8350_gpio = to_wm8350_gpio(chip);6363+ struct wm8350 *wm8350 = wm8350_gpio->wm8350;6464+6565+ if (value)6666+ wm8350_set_bits(wm8350, WM8350_GPIO_LEVEL, 1 << offset);6767+ else6868+ wm8350_clear_bits(wm8350, WM8350_GPIO_LEVEL, 1 << offset);6969+}7070+7171+static int wm8350_gpio_direction_out(struct gpio_chip *chip,7272+ unsigned offset, int value)7373+{7474+ struct wm8350_gpio_data *wm8350_gpio = to_wm8350_gpio(chip);7575+ struct wm8350 *wm8350 = wm8350_gpio->wm8350;7676+ int ret;7777+7878+ ret = wm8350_clear_bits(wm8350, WM8350_GPIO_CONFIGURATION_I_O,7979+ 1 << offset);8080+ if (ret < 0)8181+ return ret;8282+8383+ /* Don't have an atomic direction/value setup */8484+ wm8350_gpio_set(chip, offset, value);8585+8686+ return 0;8787+}8888+8989+static int wm8350_gpio_to_irq(struct gpio_chip *chip, unsigned offset)9090+{9191+ struct wm8350_gpio_data *wm8350_gpio = to_wm8350_gpio(chip);9292+ struct wm8350 *wm8350 = wm8350_gpio->wm8350;9393+9494+ if (!wm8350->irq_base)9595+ return -EINVAL;9696+9797+ return wm8350->irq_base + WM8350_IRQ_GPIO(offset);9898+}9999+100100+static struct gpio_chip template_chip = {101101+ .label = "wm8350",102102+ .owner = THIS_MODULE,103103+ .direction_input = wm8350_gpio_direction_in,104104+ .get = wm8350_gpio_get,105105+ .direction_output = wm8350_gpio_direction_out,106106+ .set = wm8350_gpio_set,107107+ .to_irq = wm8350_gpio_to_irq,108108+ .can_sleep = 1,109109+};110110+111111+static int __devinit wm8350_gpio_probe(struct platform_device *pdev)112112+{113113+ struct wm8350 *wm8350 = dev_get_drvdata(pdev->dev.parent);114114+ struct wm8350_platform_data *pdata = wm8350->dev->platform_data;115115+ struct wm8350_gpio_data *wm8350_gpio;116116+ int ret;117117+118118+ wm8350_gpio = kzalloc(sizeof(*wm8350_gpio), GFP_KERNEL);119119+ if (wm8350_gpio == NULL)120120+ return -ENOMEM;121121+122122+ wm8350_gpio->wm8350 = wm8350;123123+ wm8350_gpio->gpio_chip = template_chip;124124+ wm8350_gpio->gpio_chip.ngpio = 13;125125+ wm8350_gpio->gpio_chip.dev = &pdev->dev;126126+ if (pdata && pdata->gpio_base)127127+ wm8350_gpio->gpio_chip.base = pdata->gpio_base;128128+ else129129+ wm8350_gpio->gpio_chip.base = -1;130130+131131+ ret = gpiochip_add(&wm8350_gpio->gpio_chip);132132+ if (ret < 0) {133133+ dev_err(&pdev->dev, "Could not register gpiochip, %d\n",134134+ ret);135135+ goto err;136136+ }137137+138138+ platform_set_drvdata(pdev, wm8350_gpio);139139+140140+ return ret;141141+142142+err:143143+ kfree(wm8350_gpio);144144+ return ret;145145+}146146+147147+static int __devexit wm8350_gpio_remove(struct platform_device *pdev)148148+{149149+ struct wm8350_gpio_data *wm8350_gpio = platform_get_drvdata(pdev);150150+ int ret;151151+152152+ ret = gpiochip_remove(&wm8350_gpio->gpio_chip);153153+ if (ret == 0)154154+ kfree(wm8350_gpio);155155+156156+ return ret;157157+}158158+159159+static struct platform_driver wm8350_gpio_driver = {160160+ .driver.name = "wm8350-gpio",161161+ .driver.owner = THIS_MODULE,162162+ .probe = wm8350_gpio_probe,163163+ .remove = __devexit_p(wm8350_gpio_remove),164164+};165165+166166+static int __init wm8350_gpio_init(void)167167+{168168+ return platform_driver_register(&wm8350_gpio_driver);169169+}170170+subsys_initcall(wm8350_gpio_init);171171+172172+static void __exit wm8350_gpio_exit(void)173173+{174174+ platform_driver_unregister(&wm8350_gpio_driver);175175+}176176+module_exit(wm8350_gpio_exit);177177+178178+MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>");179179+MODULE_DESCRIPTION("GPIO interface for WM8350 PMICs");180180+MODULE_LICENSE("GPL");181181+MODULE_ALIAS("platform:wm8350-gpio");
+2
include/linux/mfd/wm8350/core.h
···645645 * used by the platform to configure GPIO functions and similar.646646 * @irq_high: Set if WM8350 IRQ is active high.647647 * @irq_base: Base IRQ for genirq (not currently used).648648+ * @gpio_base: Base for gpiolib.648649 */649650struct wm8350_platform_data {650651 int (*init)(struct wm8350 *wm8350);651652 int irq_high;652653 int irq_base;654654+ int gpio_base;653655};654656655657