Linux Audio

Check our new training course

Loading...
v6.13.7
  1// SPDX-License-Identifier: GPL-2.0+
  2/*
  3 * gpiolib support for Wolfson WM835x PMICs
  4 *
  5 * Copyright 2009 Wolfson Microelectronics PLC.
  6 *
  7 * Author: Mark Brown <broonie@opensource.wolfsonmicro.com>
  8 *
  9 */
 10
 11#include <linux/gpio/driver.h>
 12#include <linux/kernel.h>
 13#include <linux/mfd/core.h>
 14#include <linux/module.h>
 
 
 15#include <linux/platform_device.h>
 16#include <linux/slab.h>
 17
 18#include <linux/mfd/wm8350/core.h>
 19#include <linux/mfd/wm8350/gpio.h>
 20
 21struct wm8350_gpio_data {
 22	struct wm8350 *wm8350;
 23	struct gpio_chip gpio_chip;
 24};
 25
 26static int wm8350_gpio_direction_in(struct gpio_chip *chip, unsigned offset)
 27{
 28	struct wm8350_gpio_data *wm8350_gpio = gpiochip_get_data(chip);
 29	struct wm8350 *wm8350 = wm8350_gpio->wm8350;
 30
 31	return wm8350_set_bits(wm8350, WM8350_GPIO_CONFIGURATION_I_O,
 32			       1 << offset);
 33}
 34
 35static int wm8350_gpio_get(struct gpio_chip *chip, unsigned offset)
 36{
 37	struct wm8350_gpio_data *wm8350_gpio = gpiochip_get_data(chip);
 38	struct wm8350 *wm8350 = wm8350_gpio->wm8350;
 39	int ret;
 40
 41	ret = wm8350_reg_read(wm8350, WM8350_GPIO_LEVEL);
 42	if (ret < 0)
 43		return ret;
 44
 45	if (ret & (1 << offset))
 46		return 1;
 47	else
 48		return 0;
 49}
 50
 51static void wm8350_gpio_set(struct gpio_chip *chip, unsigned offset, int value)
 52{
 53	struct wm8350_gpio_data *wm8350_gpio = gpiochip_get_data(chip);
 54	struct wm8350 *wm8350 = wm8350_gpio->wm8350;
 55
 56	if (value)
 57		wm8350_set_bits(wm8350, WM8350_GPIO_LEVEL, 1 << offset);
 58	else
 59		wm8350_clear_bits(wm8350, WM8350_GPIO_LEVEL, 1 << offset);
 60}
 61
 62static int wm8350_gpio_direction_out(struct gpio_chip *chip,
 63				     unsigned offset, int value)
 64{
 65	struct wm8350_gpio_data *wm8350_gpio = gpiochip_get_data(chip);
 66	struct wm8350 *wm8350 = wm8350_gpio->wm8350;
 67	int ret;
 68
 69	ret = wm8350_clear_bits(wm8350, WM8350_GPIO_CONFIGURATION_I_O,
 70				1 << offset);
 71	if (ret < 0)
 72		return ret;
 73
 74	/* Don't have an atomic direction/value setup */
 75	wm8350_gpio_set(chip, offset, value);
 76
 77	return 0;
 78}
 79
 80static int wm8350_gpio_to_irq(struct gpio_chip *chip, unsigned offset)
 81{
 82	struct wm8350_gpio_data *wm8350_gpio = gpiochip_get_data(chip);
 83	struct wm8350 *wm8350 = wm8350_gpio->wm8350;
 84
 85	if (!wm8350->irq_base)
 86		return -EINVAL;
 87
 88	return wm8350->irq_base + WM8350_IRQ_GPIO(offset);
 89}
 90
 91static const struct gpio_chip template_chip = {
 92	.label			= "wm8350",
 93	.owner			= THIS_MODULE,
 94	.direction_input	= wm8350_gpio_direction_in,
 95	.get			= wm8350_gpio_get,
 96	.direction_output	= wm8350_gpio_direction_out,
 97	.set			= wm8350_gpio_set,
 98	.to_irq			= wm8350_gpio_to_irq,
 99	.can_sleep		= true,
100};
101
102static int wm8350_gpio_probe(struct platform_device *pdev)
103{
104	struct wm8350 *wm8350 = dev_get_drvdata(pdev->dev.parent);
105	struct wm8350_platform_data *pdata = dev_get_platdata(wm8350->dev);
106	struct wm8350_gpio_data *wm8350_gpio;
 
107
108	wm8350_gpio = devm_kzalloc(&pdev->dev, sizeof(*wm8350_gpio),
109				   GFP_KERNEL);
110	if (wm8350_gpio == NULL)
111		return -ENOMEM;
112
113	wm8350_gpio->wm8350 = wm8350;
114	wm8350_gpio->gpio_chip = template_chip;
115	wm8350_gpio->gpio_chip.ngpio = 13;
116	wm8350_gpio->gpio_chip.parent = &pdev->dev;
117	if (pdata && pdata->gpio_base)
118		wm8350_gpio->gpio_chip.base = pdata->gpio_base;
119	else
120		wm8350_gpio->gpio_chip.base = -1;
121
122	return devm_gpiochip_add_data(&pdev->dev, &wm8350_gpio->gpio_chip, wm8350_gpio);
 
 
 
 
 
 
 
 
 
123}
124
125static struct platform_driver wm8350_gpio_driver = {
126	.driver.name	= "wm8350-gpio",
127	.probe		= wm8350_gpio_probe,
128};
129
130static int __init wm8350_gpio_init(void)
131{
132	return platform_driver_register(&wm8350_gpio_driver);
133}
134subsys_initcall(wm8350_gpio_init);
135
136static void __exit wm8350_gpio_exit(void)
137{
138	platform_driver_unregister(&wm8350_gpio_driver);
139}
140module_exit(wm8350_gpio_exit);
141
142MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>");
143MODULE_DESCRIPTION("GPIO interface for WM8350 PMICs");
144MODULE_LICENSE("GPL");
145MODULE_ALIAS("platform:wm8350-gpio");
v5.4
  1// SPDX-License-Identifier: GPL-2.0+
  2/*
  3 * gpiolib support for Wolfson WM835x PMICs
  4 *
  5 * Copyright 2009 Wolfson Microelectronics PLC.
  6 *
  7 * Author: Mark Brown <broonie@opensource.wolfsonmicro.com>
  8 *
  9 */
 10
 
 11#include <linux/kernel.h>
 12#include <linux/slab.h>
 13#include <linux/module.h>
 14#include <linux/gpio/driver.h>
 15#include <linux/mfd/core.h>
 16#include <linux/platform_device.h>
 17#include <linux/seq_file.h>
 18
 19#include <linux/mfd/wm8350/core.h>
 20#include <linux/mfd/wm8350/gpio.h>
 21
 22struct wm8350_gpio_data {
 23	struct wm8350 *wm8350;
 24	struct gpio_chip gpio_chip;
 25};
 26
 27static int wm8350_gpio_direction_in(struct gpio_chip *chip, unsigned offset)
 28{
 29	struct wm8350_gpio_data *wm8350_gpio = gpiochip_get_data(chip);
 30	struct wm8350 *wm8350 = wm8350_gpio->wm8350;
 31
 32	return wm8350_set_bits(wm8350, WM8350_GPIO_CONFIGURATION_I_O,
 33			       1 << offset);
 34}
 35
 36static int wm8350_gpio_get(struct gpio_chip *chip, unsigned offset)
 37{
 38	struct wm8350_gpio_data *wm8350_gpio = gpiochip_get_data(chip);
 39	struct wm8350 *wm8350 = wm8350_gpio->wm8350;
 40	int ret;
 41
 42	ret = wm8350_reg_read(wm8350, WM8350_GPIO_LEVEL);
 43	if (ret < 0)
 44		return ret;
 45
 46	if (ret & (1 << offset))
 47		return 1;
 48	else
 49		return 0;
 50}
 51
 52static void wm8350_gpio_set(struct gpio_chip *chip, unsigned offset, int value)
 53{
 54	struct wm8350_gpio_data *wm8350_gpio = gpiochip_get_data(chip);
 55	struct wm8350 *wm8350 = wm8350_gpio->wm8350;
 56
 57	if (value)
 58		wm8350_set_bits(wm8350, WM8350_GPIO_LEVEL, 1 << offset);
 59	else
 60		wm8350_clear_bits(wm8350, WM8350_GPIO_LEVEL, 1 << offset);
 61}
 62
 63static int wm8350_gpio_direction_out(struct gpio_chip *chip,
 64				     unsigned offset, int value)
 65{
 66	struct wm8350_gpio_data *wm8350_gpio = gpiochip_get_data(chip);
 67	struct wm8350 *wm8350 = wm8350_gpio->wm8350;
 68	int ret;
 69
 70	ret = wm8350_clear_bits(wm8350, WM8350_GPIO_CONFIGURATION_I_O,
 71				1 << offset);
 72	if (ret < 0)
 73		return ret;
 74
 75	/* Don't have an atomic direction/value setup */
 76	wm8350_gpio_set(chip, offset, value);
 77
 78	return 0;
 79}
 80
 81static int wm8350_gpio_to_irq(struct gpio_chip *chip, unsigned offset)
 82{
 83	struct wm8350_gpio_data *wm8350_gpio = gpiochip_get_data(chip);
 84	struct wm8350 *wm8350 = wm8350_gpio->wm8350;
 85
 86	if (!wm8350->irq_base)
 87		return -EINVAL;
 88
 89	return wm8350->irq_base + WM8350_IRQ_GPIO(offset);
 90}
 91
 92static const struct gpio_chip template_chip = {
 93	.label			= "wm8350",
 94	.owner			= THIS_MODULE,
 95	.direction_input	= wm8350_gpio_direction_in,
 96	.get			= wm8350_gpio_get,
 97	.direction_output	= wm8350_gpio_direction_out,
 98	.set			= wm8350_gpio_set,
 99	.to_irq			= wm8350_gpio_to_irq,
100	.can_sleep		= true,
101};
102
103static int wm8350_gpio_probe(struct platform_device *pdev)
104{
105	struct wm8350 *wm8350 = dev_get_drvdata(pdev->dev.parent);
106	struct wm8350_platform_data *pdata = dev_get_platdata(wm8350->dev);
107	struct wm8350_gpio_data *wm8350_gpio;
108	int ret;
109
110	wm8350_gpio = devm_kzalloc(&pdev->dev, sizeof(*wm8350_gpio),
111				   GFP_KERNEL);
112	if (wm8350_gpio == NULL)
113		return -ENOMEM;
114
115	wm8350_gpio->wm8350 = wm8350;
116	wm8350_gpio->gpio_chip = template_chip;
117	wm8350_gpio->gpio_chip.ngpio = 13;
118	wm8350_gpio->gpio_chip.parent = &pdev->dev;
119	if (pdata && pdata->gpio_base)
120		wm8350_gpio->gpio_chip.base = pdata->gpio_base;
121	else
122		wm8350_gpio->gpio_chip.base = -1;
123
124	ret = devm_gpiochip_add_data(&pdev->dev, &wm8350_gpio->gpio_chip,
125				     wm8350_gpio);
126	if (ret < 0) {
127		dev_err(&pdev->dev, "Could not register gpiochip, %d\n", ret);
128		return ret;
129	}
130
131	platform_set_drvdata(pdev, wm8350_gpio);
132
133	return ret;
134}
135
136static struct platform_driver wm8350_gpio_driver = {
137	.driver.name	= "wm8350-gpio",
138	.probe		= wm8350_gpio_probe,
139};
140
141static int __init wm8350_gpio_init(void)
142{
143	return platform_driver_register(&wm8350_gpio_driver);
144}
145subsys_initcall(wm8350_gpio_init);
146
147static void __exit wm8350_gpio_exit(void)
148{
149	platform_driver_unregister(&wm8350_gpio_driver);
150}
151module_exit(wm8350_gpio_exit);
152
153MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>");
154MODULE_DESCRIPTION("GPIO interface for WM8350 PMICs");
155MODULE_LICENSE("GPL");
156MODULE_ALIAS("platform:wm8350-gpio");