Linux Audio

Check our new training course

Loading...
v3.15
 
  1/*
  2 * Philips UCB1400 GPIO driver
  3 *
  4 * Author: Marek Vasut <marek.vasut@gmail.com>
  5 *
  6 * This program is free software; you can redistribute it and/or modify
  7 * it under the terms of the GNU General Public License version 2 as
  8 * published by the Free Software Foundation.
  9 *
 10 */
 11
 12#include <linux/module.h>
 13#include <linux/ucb1400.h>
 14
 15static int ucb1400_gpio_dir_in(struct gpio_chip *gc, unsigned off)
 16{
 17	struct ucb1400_gpio *gpio;
 18	gpio = container_of(gc, struct ucb1400_gpio, gc);
 19	ucb1400_gpio_set_direction(gpio->ac97, off, 0);
 20	return 0;
 21}
 22
 23static int ucb1400_gpio_dir_out(struct gpio_chip *gc, unsigned off, int val)
 24{
 25	struct ucb1400_gpio *gpio;
 26	gpio = container_of(gc, struct ucb1400_gpio, gc);
 27	ucb1400_gpio_set_direction(gpio->ac97, off, 1);
 28	ucb1400_gpio_set_value(gpio->ac97, off, val);
 29	return 0;
 30}
 31
 32static int ucb1400_gpio_get(struct gpio_chip *gc, unsigned off)
 33{
 34	struct ucb1400_gpio *gpio;
 35	gpio = container_of(gc, struct ucb1400_gpio, gc);
 36	return ucb1400_gpio_get_value(gpio->ac97, off);
 
 37}
 38
 39static void ucb1400_gpio_set(struct gpio_chip *gc, unsigned off, int val)
 40{
 41	struct ucb1400_gpio *gpio;
 42	gpio = container_of(gc, struct ucb1400_gpio, gc);
 43	ucb1400_gpio_set_value(gpio->ac97, off, val);
 44}
 45
 46static int ucb1400_gpio_probe(struct platform_device *dev)
 47{
 48	struct ucb1400_gpio *ucb = dev_get_platdata(&dev->dev);
 49	int err = 0;
 50
 51	if (!(ucb && ucb->gpio_offset)) {
 52		err = -EINVAL;
 53		goto err;
 54	}
 55
 56	platform_set_drvdata(dev, ucb);
 57
 58	ucb->gc.label = "ucb1400_gpio";
 59	ucb->gc.base = ucb->gpio_offset;
 60	ucb->gc.ngpio = 10;
 61	ucb->gc.owner = THIS_MODULE;
 62
 63	ucb->gc.direction_input = ucb1400_gpio_dir_in;
 64	ucb->gc.direction_output = ucb1400_gpio_dir_out;
 65	ucb->gc.get = ucb1400_gpio_get;
 66	ucb->gc.set = ucb1400_gpio_set;
 67	ucb->gc.can_sleep = true;
 68
 69	err = gpiochip_add(&ucb->gc);
 70	if (err)
 71		goto err;
 72
 73	if (ucb && ucb->gpio_setup)
 74		err = ucb->gpio_setup(&dev->dev, ucb->gc.ngpio);
 75
 76err:
 77	return err;
 78
 79}
 80
 81static int ucb1400_gpio_remove(struct platform_device *dev)
 82{
 83	int err = 0;
 84	struct ucb1400_gpio *ucb = platform_get_drvdata(dev);
 85
 86	if (ucb && ucb->gpio_teardown) {
 87		err = ucb->gpio_teardown(&dev->dev, ucb->gc.ngpio);
 88		if (err)
 89			return err;
 90	}
 91
 92	err = gpiochip_remove(&ucb->gc);
 93	return err;
 94}
 95
 96static struct platform_driver ucb1400_gpio_driver = {
 97	.probe	= ucb1400_gpio_probe,
 98	.remove	= ucb1400_gpio_remove,
 99	.driver	= {
100		.name	= "ucb1400_gpio"
101	},
102};
103
104module_platform_driver(ucb1400_gpio_driver);
105
106MODULE_DESCRIPTION("Philips UCB1400 GPIO driver");
107MODULE_LICENSE("GPL");
108MODULE_ALIAS("platform:ucb1400_gpio");
v5.14.15
  1// SPDX-License-Identifier: GPL-2.0-only
  2/*
  3 * Philips UCB1400 GPIO driver
  4 *
  5 * Author: Marek Vasut <marek.vasut@gmail.com>
 
 
 
 
 
  6 */
  7
  8#include <linux/module.h>
  9#include <linux/ucb1400.h>
 10
 11static int ucb1400_gpio_dir_in(struct gpio_chip *gc, unsigned off)
 12{
 13	struct ucb1400_gpio *gpio;
 14	gpio = gpiochip_get_data(gc);
 15	ucb1400_gpio_set_direction(gpio->ac97, off, 0);
 16	return 0;
 17}
 18
 19static int ucb1400_gpio_dir_out(struct gpio_chip *gc, unsigned off, int val)
 20{
 21	struct ucb1400_gpio *gpio;
 22	gpio = gpiochip_get_data(gc);
 23	ucb1400_gpio_set_direction(gpio->ac97, off, 1);
 24	ucb1400_gpio_set_value(gpio->ac97, off, val);
 25	return 0;
 26}
 27
 28static int ucb1400_gpio_get(struct gpio_chip *gc, unsigned off)
 29{
 30	struct ucb1400_gpio *gpio;
 31
 32	gpio = gpiochip_get_data(gc);
 33	return !!ucb1400_gpio_get_value(gpio->ac97, off);
 34}
 35
 36static void ucb1400_gpio_set(struct gpio_chip *gc, unsigned off, int val)
 37{
 38	struct ucb1400_gpio *gpio;
 39	gpio = gpiochip_get_data(gc);
 40	ucb1400_gpio_set_value(gpio->ac97, off, val);
 41}
 42
 43static int ucb1400_gpio_probe(struct platform_device *dev)
 44{
 45	struct ucb1400_gpio *ucb = dev_get_platdata(&dev->dev);
 46	int err = 0;
 47
 48	if (!(ucb && ucb->gpio_offset)) {
 49		err = -EINVAL;
 50		goto err;
 51	}
 52
 53	platform_set_drvdata(dev, ucb);
 54
 55	ucb->gc.label = "ucb1400_gpio";
 56	ucb->gc.base = ucb->gpio_offset;
 57	ucb->gc.ngpio = 10;
 58	ucb->gc.owner = THIS_MODULE;
 59
 60	ucb->gc.direction_input = ucb1400_gpio_dir_in;
 61	ucb->gc.direction_output = ucb1400_gpio_dir_out;
 62	ucb->gc.get = ucb1400_gpio_get;
 63	ucb->gc.set = ucb1400_gpio_set;
 64	ucb->gc.can_sleep = true;
 65
 66	err = devm_gpiochip_add_data(&dev->dev, &ucb->gc, ucb);
 67	if (err)
 68		goto err;
 69
 70	if (ucb->gpio_setup)
 71		err = ucb->gpio_setup(&dev->dev, ucb->gc.ngpio);
 72
 73err:
 74	return err;
 75
 76}
 77
 78static int ucb1400_gpio_remove(struct platform_device *dev)
 79{
 80	int err = 0;
 81	struct ucb1400_gpio *ucb = platform_get_drvdata(dev);
 82
 83	if (ucb && ucb->gpio_teardown) {
 84		err = ucb->gpio_teardown(&dev->dev, ucb->gc.ngpio);
 85		if (err)
 86			return err;
 87	}
 88
 
 89	return err;
 90}
 91
 92static struct platform_driver ucb1400_gpio_driver = {
 93	.probe	= ucb1400_gpio_probe,
 94	.remove	= ucb1400_gpio_remove,
 95	.driver	= {
 96		.name	= "ucb1400_gpio"
 97	},
 98};
 99
100module_platform_driver(ucb1400_gpio_driver);
101
102MODULE_DESCRIPTION("Philips UCB1400 GPIO driver");
103MODULE_LICENSE("GPL");
104MODULE_ALIAS("platform:ucb1400_gpio");