Linux Audio

Check our new training course

Embedded Linux training

Mar 10-20, 2025, special US time zones
Register
Loading...
v3.15
 
  1/*
  2 * Access to GPOs on TWL6040 chip
  3 *
  4 * Copyright (C) 2012 Texas Instruments, Inc.
  5 *
  6 * Authors:
  7 *	Sergio Aguirre <saaguirre@ti.com>
  8 *	Peter Ujfalusi <peter.ujfalusi@ti.com>
  9 *
 10 * This program is free software; you can redistribute it and/or modify
 11 * it under the terms of the GNU General Public License as published by
 12 * the Free Software Foundation; either version 2 of the License, or
 13 * (at your option) any later version.
 14 *
 15 * This program is distributed in the hope that it will be useful,
 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 18 * GNU General Public License for more details.
 19 *
 20 * You should have received a copy of the GNU General Public License
 21 * along with this program; if not, write to the Free Software
 22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 23 */
 24
 25#include <linux/module.h>
 26#include <linux/init.h>
 27#include <linux/kthread.h>
 28#include <linux/irq.h>
 29#include <linux/gpio.h>
 30#include <linux/platform_device.h>
 
 31#include <linux/of.h>
 32
 33#include <linux/mfd/twl6040.h>
 34
 35static struct gpio_chip twl6040gpo_chip;
 36
 37static int twl6040gpo_get(struct gpio_chip *chip, unsigned offset)
 38{
 39	struct twl6040 *twl6040 = dev_get_drvdata(chip->dev->parent);
 40	int ret = 0;
 41
 42	ret = twl6040_reg_read(twl6040, TWL6040_REG_GPOCTL);
 43	if (ret < 0)
 44		return ret;
 45
 46	return (ret >> offset) & 1;
 
 
 
 
 
 
 47}
 48
 49static int twl6040gpo_direction_out(struct gpio_chip *chip, unsigned offset,
 50				    int value)
 51{
 52	/* This only drives GPOs, and can't change direction */
 53	return 0;
 54}
 55
 56static void twl6040gpo_set(struct gpio_chip *chip, unsigned offset, int value)
 57{
 58	struct twl6040 *twl6040 = dev_get_drvdata(chip->dev->parent);
 59	int ret;
 60	u8 gpoctl;
 61
 62	ret = twl6040_reg_read(twl6040, TWL6040_REG_GPOCTL);
 63	if (ret < 0)
 64		return;
 65
 66	if (value)
 67		gpoctl = ret | (1 << offset);
 68	else
 69		gpoctl = ret & ~(1 << offset);
 70
 71	twl6040_reg_write(twl6040, TWL6040_REG_GPOCTL, gpoctl);
 72}
 73
 74static struct gpio_chip twl6040gpo_chip = {
 75	.label			= "twl6040",
 76	.owner			= THIS_MODULE,
 77	.get			= twl6040gpo_get,
 78	.direction_output	= twl6040gpo_direction_out,
 
 79	.set			= twl6040gpo_set,
 80	.can_sleep		= true,
 81};
 82
 83/*----------------------------------------------------------------------*/
 84
 85static int gpo_twl6040_probe(struct platform_device *pdev)
 86{
 87	struct device *twl6040_core_dev = pdev->dev.parent;
 88	struct twl6040 *twl6040 = dev_get_drvdata(twl6040_core_dev);
 89	int ret;
 90
 91	twl6040gpo_chip.base = -1;
 92
 93	if (twl6040_get_revid(twl6040) < TWL6041_REV_ES2_0)
 94		twl6040gpo_chip.ngpio = 3; /* twl6040 have 3 GPO */
 95	else
 96		twl6040gpo_chip.ngpio = 1; /* twl6041 have 1 GPO */
 97
 98	twl6040gpo_chip.dev = &pdev->dev;
 99#ifdef CONFIG_OF_GPIO
100	twl6040gpo_chip.of_node = twl6040_core_dev->of_node;
101#endif
102
103	ret = gpiochip_add(&twl6040gpo_chip);
104	if (ret < 0) {
105		dev_err(&pdev->dev, "could not register gpiochip, %d\n", ret);
106		twl6040gpo_chip.ngpio = 0;
107	}
108
109	return ret;
110}
111
112static int gpo_twl6040_remove(struct platform_device *pdev)
113{
114	return gpiochip_remove(&twl6040gpo_chip);
115}
116
117/* Note:  this hardware lives inside an I2C-based multi-function device. */
118MODULE_ALIAS("platform:twl6040-gpo");
119
120static struct platform_driver gpo_twl6040_driver = {
121	.driver = {
122		.name	= "twl6040-gpo",
123		.owner	= THIS_MODULE,
124	},
125	.probe		= gpo_twl6040_probe,
126	.remove		= gpo_twl6040_remove,
127};
128
129module_platform_driver(gpo_twl6040_driver);
130
131MODULE_AUTHOR("Texas Instruments, Inc.");
132MODULE_DESCRIPTION("GPO interface for TWL6040");
133MODULE_LICENSE("GPL");
v5.4
  1// SPDX-License-Identifier: GPL-2.0+
  2/*
  3 * Access to GPOs on TWL6040 chip
  4 *
  5 * Copyright (C) 2012 Texas Instruments, Inc.
  6 *
  7 * Authors:
  8 *	Sergio Aguirre <saaguirre@ti.com>
  9 *	Peter Ujfalusi <peter.ujfalusi@ti.com>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 10 */
 11
 12#include <linux/module.h>
 13#include <linux/init.h>
 14#include <linux/kthread.h>
 15#include <linux/irq.h>
 16#include <linux/gpio/driver.h>
 17#include <linux/platform_device.h>
 18#include <linux/bitops.h>
 19#include <linux/of.h>
 20
 21#include <linux/mfd/twl6040.h>
 22
 
 
 23static int twl6040gpo_get(struct gpio_chip *chip, unsigned offset)
 24{
 25	struct twl6040 *twl6040 = dev_get_drvdata(chip->parent->parent);
 26	int ret = 0;
 27
 28	ret = twl6040_reg_read(twl6040, TWL6040_REG_GPOCTL);
 29	if (ret < 0)
 30		return ret;
 31
 32	return !!(ret & BIT(offset));
 33}
 34
 35static int twl6040gpo_get_direction(struct gpio_chip *chip, unsigned offset)
 36{
 37	/* This means "out" */
 38	return 0;
 39}
 40
 41static int twl6040gpo_direction_out(struct gpio_chip *chip, unsigned offset,
 42				    int value)
 43{
 44	/* This only drives GPOs, and can't change direction */
 45	return 0;
 46}
 47
 48static void twl6040gpo_set(struct gpio_chip *chip, unsigned offset, int value)
 49{
 50	struct twl6040 *twl6040 = dev_get_drvdata(chip->parent->parent);
 51	int ret;
 52	u8 gpoctl;
 53
 54	ret = twl6040_reg_read(twl6040, TWL6040_REG_GPOCTL);
 55	if (ret < 0)
 56		return;
 57
 58	if (value)
 59		gpoctl = ret | BIT(offset);
 60	else
 61		gpoctl = ret & ~BIT(offset);
 62
 63	twl6040_reg_write(twl6040, TWL6040_REG_GPOCTL, gpoctl);
 64}
 65
 66static struct gpio_chip twl6040gpo_chip = {
 67	.label			= "twl6040",
 68	.owner			= THIS_MODULE,
 69	.get			= twl6040gpo_get,
 70	.direction_output	= twl6040gpo_direction_out,
 71	.get_direction		= twl6040gpo_get_direction,
 72	.set			= twl6040gpo_set,
 73	.can_sleep		= true,
 74};
 75
 76/*----------------------------------------------------------------------*/
 77
 78static int gpo_twl6040_probe(struct platform_device *pdev)
 79{
 80	struct device *twl6040_core_dev = pdev->dev.parent;
 81	struct twl6040 *twl6040 = dev_get_drvdata(twl6040_core_dev);
 82	int ret;
 83
 84	twl6040gpo_chip.base = -1;
 85
 86	if (twl6040_get_revid(twl6040) < TWL6041_REV_ES2_0)
 87		twl6040gpo_chip.ngpio = 3; /* twl6040 have 3 GPO */
 88	else
 89		twl6040gpo_chip.ngpio = 1; /* twl6041 have 1 GPO */
 90
 91	twl6040gpo_chip.parent = &pdev->dev;
 92#ifdef CONFIG_OF_GPIO
 93	twl6040gpo_chip.of_node = twl6040_core_dev->of_node;
 94#endif
 95
 96	ret = devm_gpiochip_add_data(&pdev->dev, &twl6040gpo_chip, NULL);
 97	if (ret < 0) {
 98		dev_err(&pdev->dev, "could not register gpiochip, %d\n", ret);
 99		twl6040gpo_chip.ngpio = 0;
100	}
101
102	return ret;
103}
104
 
 
 
 
 
105/* Note:  this hardware lives inside an I2C-based multi-function device. */
106MODULE_ALIAS("platform:twl6040-gpo");
107
108static struct platform_driver gpo_twl6040_driver = {
109	.driver = {
110		.name	= "twl6040-gpo",
 
111	},
112	.probe		= gpo_twl6040_probe,
 
113};
114
115module_platform_driver(gpo_twl6040_driver);
116
117MODULE_AUTHOR("Texas Instruments, Inc.");
118MODULE_DESCRIPTION("GPO interface for TWL6040");
119MODULE_LICENSE("GPL");