Linux Audio

Check our new training course

Loading...
v6.2
  1// SPDX-License-Identifier: GPL-2.0-only
  2/*
  3 * ROHM BD9571MWV-M and BD9574MWF-M GPIO driver
  4 *
  5 * Copyright (C) 2017 Marek Vasut <marek.vasut+renesas@gmail.com>
  6 *
 
 
 
 
 
 
 
 
 
  7 * Based on the TPS65086 driver
  8 *
  9 * NOTE: Interrupts are not supported yet.
 10 */
 11
 12#include <linux/gpio/driver.h>
 13#include <linux/mfd/rohm-generic.h>
 14#include <linux/module.h>
 15#include <linux/platform_device.h>
 16
 17#include <linux/mfd/bd9571mwv.h>
 18
 19struct bd9571mwv_gpio {
 20	struct regmap *regmap;
 21	struct gpio_chip chip;
 
 22};
 23
 24static int bd9571mwv_gpio_get_direction(struct gpio_chip *chip,
 25				       unsigned int offset)
 26{
 27	struct bd9571mwv_gpio *gpio = gpiochip_get_data(chip);
 28	int ret, val;
 29
 30	ret = regmap_read(gpio->regmap, BD9571MWV_GPIO_DIR, &val);
 31	if (ret < 0)
 32		return ret;
 33	if (val & BIT(offset))
 34		return GPIO_LINE_DIRECTION_IN;
 35
 36	return GPIO_LINE_DIRECTION_OUT;
 37}
 38
 39static int bd9571mwv_gpio_direction_input(struct gpio_chip *chip,
 40					 unsigned int offset)
 41{
 42	struct bd9571mwv_gpio *gpio = gpiochip_get_data(chip);
 43
 44	regmap_update_bits(gpio->regmap, BD9571MWV_GPIO_DIR, BIT(offset), 0);
 
 45
 46	return 0;
 47}
 48
 49static int bd9571mwv_gpio_direction_output(struct gpio_chip *chip,
 50					  unsigned int offset, int value)
 51{
 52	struct bd9571mwv_gpio *gpio = gpiochip_get_data(chip);
 53
 54	/* Set the initial value */
 55	regmap_update_bits(gpio->regmap, BD9571MWV_GPIO_OUT,
 56			   BIT(offset), value ? BIT(offset) : 0);
 57	regmap_update_bits(gpio->regmap, BD9571MWV_GPIO_DIR,
 58			   BIT(offset), BIT(offset));
 59
 60	return 0;
 61}
 62
 63static int bd9571mwv_gpio_get(struct gpio_chip *chip, unsigned int offset)
 64{
 65	struct bd9571mwv_gpio *gpio = gpiochip_get_data(chip);
 66	int ret, val;
 67
 68	ret = regmap_read(gpio->regmap, BD9571MWV_GPIO_IN, &val);
 69	if (ret < 0)
 70		return ret;
 71
 72	return val & BIT(offset);
 73}
 74
 75static void bd9571mwv_gpio_set(struct gpio_chip *chip, unsigned int offset,
 76			      int value)
 77{
 78	struct bd9571mwv_gpio *gpio = gpiochip_get_data(chip);
 79
 80	regmap_update_bits(gpio->regmap, BD9571MWV_GPIO_OUT,
 81			   BIT(offset), value ? BIT(offset) : 0);
 82}
 83
 84static const struct gpio_chip template_chip = {
 85	.label			= "bd9571mwv-gpio",
 86	.owner			= THIS_MODULE,
 87	.get_direction		= bd9571mwv_gpio_get_direction,
 88	.direction_input	= bd9571mwv_gpio_direction_input,
 89	.direction_output	= bd9571mwv_gpio_direction_output,
 90	.get			= bd9571mwv_gpio_get,
 91	.set			= bd9571mwv_gpio_set,
 92	.base			= -1,
 93	.ngpio			= 2,
 94	.can_sleep		= true,
 95};
 96
 97static int bd9571mwv_gpio_probe(struct platform_device *pdev)
 98{
 99	struct bd9571mwv_gpio *gpio;
 
100
101	gpio = devm_kzalloc(&pdev->dev, sizeof(*gpio), GFP_KERNEL);
102	if (!gpio)
103		return -ENOMEM;
104
105	gpio->regmap = dev_get_regmap(pdev->dev.parent, NULL);
 
 
106	gpio->chip = template_chip;
107	gpio->chip.parent = pdev->dev.parent;
108
109	return devm_gpiochip_add_data(&pdev->dev, &gpio->chip, gpio);
 
 
 
 
 
 
110}
111
112static const struct platform_device_id bd9571mwv_gpio_id_table[] = {
113	{ "bd9571mwv-gpio", ROHM_CHIP_TYPE_BD9571 },
114	{ "bd9574mwf-gpio", ROHM_CHIP_TYPE_BD9574 },
115	{ /* sentinel */ }
116};
117MODULE_DEVICE_TABLE(platform, bd9571mwv_gpio_id_table);
118
119static struct platform_driver bd9571mwv_gpio_driver = {
120	.driver = {
121		.name = "bd9571mwv-gpio",
122	},
123	.probe = bd9571mwv_gpio_probe,
124	.id_table = bd9571mwv_gpio_id_table,
125};
126module_platform_driver(bd9571mwv_gpio_driver);
127
128MODULE_AUTHOR("Marek Vasut <marek.vasut+renesas@gmail.com>");
129MODULE_DESCRIPTION("BD9571MWV GPIO driver");
130MODULE_LICENSE("GPL v2");
v5.4
 
  1/*
  2 * ROHM BD9571MWV-M GPIO driver
  3 *
  4 * Copyright (C) 2017 Marek Vasut <marek.vasut+renesas@gmail.com>
  5 *
  6 * This program is free software; you can redistribute it and/or
  7 * modify it under the terms of the GNU General Public License version 2 as
  8 * published by the Free Software Foundation.
  9 *
 10 * This program is distributed "as is" WITHOUT ANY WARRANTY of any
 11 * kind, whether expressed or implied; without even the implied warranty
 12 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 13 * GNU General Public License version 2 for more details.
 14 *
 15 * Based on the TPS65086 driver
 16 *
 17 * NOTE: Interrupts are not supported yet.
 18 */
 19
 20#include <linux/gpio/driver.h>
 
 21#include <linux/module.h>
 22#include <linux/platform_device.h>
 23
 24#include <linux/mfd/bd9571mwv.h>
 25
 26struct bd9571mwv_gpio {
 
 27	struct gpio_chip chip;
 28	struct bd9571mwv *bd;
 29};
 30
 31static int bd9571mwv_gpio_get_direction(struct gpio_chip *chip,
 32				       unsigned int offset)
 33{
 34	struct bd9571mwv_gpio *gpio = gpiochip_get_data(chip);
 35	int ret, val;
 36
 37	ret = regmap_read(gpio->bd->regmap, BD9571MWV_GPIO_DIR, &val);
 38	if (ret < 0)
 39		return ret;
 
 
 40
 41	return val & BIT(offset);
 42}
 43
 44static int bd9571mwv_gpio_direction_input(struct gpio_chip *chip,
 45					 unsigned int offset)
 46{
 47	struct bd9571mwv_gpio *gpio = gpiochip_get_data(chip);
 48
 49	regmap_update_bits(gpio->bd->regmap, BD9571MWV_GPIO_DIR,
 50			   BIT(offset), 0);
 51
 52	return 0;
 53}
 54
 55static int bd9571mwv_gpio_direction_output(struct gpio_chip *chip,
 56					  unsigned int offset, int value)
 57{
 58	struct bd9571mwv_gpio *gpio = gpiochip_get_data(chip);
 59
 60	/* Set the initial value */
 61	regmap_update_bits(gpio->bd->regmap, BD9571MWV_GPIO_OUT,
 62			   BIT(offset), value ? BIT(offset) : 0);
 63	regmap_update_bits(gpio->bd->regmap, BD9571MWV_GPIO_DIR,
 64			   BIT(offset), BIT(offset));
 65
 66	return 0;
 67}
 68
 69static int bd9571mwv_gpio_get(struct gpio_chip *chip, unsigned int offset)
 70{
 71	struct bd9571mwv_gpio *gpio = gpiochip_get_data(chip);
 72	int ret, val;
 73
 74	ret = regmap_read(gpio->bd->regmap, BD9571MWV_GPIO_IN, &val);
 75	if (ret < 0)
 76		return ret;
 77
 78	return val & BIT(offset);
 79}
 80
 81static void bd9571mwv_gpio_set(struct gpio_chip *chip, unsigned int offset,
 82			      int value)
 83{
 84	struct bd9571mwv_gpio *gpio = gpiochip_get_data(chip);
 85
 86	regmap_update_bits(gpio->bd->regmap, BD9571MWV_GPIO_OUT,
 87			   BIT(offset), value ? BIT(offset) : 0);
 88}
 89
 90static const struct gpio_chip template_chip = {
 91	.label			= "bd9571mwv-gpio",
 92	.owner			= THIS_MODULE,
 93	.get_direction		= bd9571mwv_gpio_get_direction,
 94	.direction_input	= bd9571mwv_gpio_direction_input,
 95	.direction_output	= bd9571mwv_gpio_direction_output,
 96	.get			= bd9571mwv_gpio_get,
 97	.set			= bd9571mwv_gpio_set,
 98	.base			= -1,
 99	.ngpio			= 2,
100	.can_sleep		= true,
101};
102
103static int bd9571mwv_gpio_probe(struct platform_device *pdev)
104{
105	struct bd9571mwv_gpio *gpio;
106	int ret;
107
108	gpio = devm_kzalloc(&pdev->dev, sizeof(*gpio), GFP_KERNEL);
109	if (!gpio)
110		return -ENOMEM;
111
112	platform_set_drvdata(pdev, gpio);
113
114	gpio->bd = dev_get_drvdata(pdev->dev.parent);
115	gpio->chip = template_chip;
116	gpio->chip.parent = gpio->bd->dev;
117
118	ret = devm_gpiochip_add_data(&pdev->dev, &gpio->chip, gpio);
119	if (ret < 0) {
120		dev_err(&pdev->dev, "Could not register gpiochip, %d\n", ret);
121		return ret;
122	}
123
124	return 0;
125}
126
127static const struct platform_device_id bd9571mwv_gpio_id_table[] = {
128	{ "bd9571mwv-gpio", },
 
129	{ /* sentinel */ }
130};
131MODULE_DEVICE_TABLE(platform, bd9571mwv_gpio_id_table);
132
133static struct platform_driver bd9571mwv_gpio_driver = {
134	.driver = {
135		.name = "bd9571mwv-gpio",
136	},
137	.probe = bd9571mwv_gpio_probe,
138	.id_table = bd9571mwv_gpio_id_table,
139};
140module_platform_driver(bd9571mwv_gpio_driver);
141
142MODULE_AUTHOR("Marek Vasut <marek.vasut+renesas@gmail.com>");
143MODULE_DESCRIPTION("BD9571MWV GPIO driver");
144MODULE_LICENSE("GPL v2");