2013-01-08 17:41:02 +08:00
|
|
|
/*
|
|
|
|
* Copyright (C) ST-Ericsson SA 2013
|
|
|
|
*
|
|
|
|
* Author: Patrice Chotard <patrice.chotard@st.com>
|
|
|
|
* License terms: GNU General Public License (GPL) version 2
|
|
|
|
*
|
2016-08-24 05:19:40 +08:00
|
|
|
* Driver allows to use AxB5xx unused pins to be used as GPIO
|
|
|
|
*
|
2013-01-08 17:41:02 +08:00
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License version 2 as
|
|
|
|
* published by the Free Software Foundation.
|
|
|
|
*/
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/types.h>
|
|
|
|
#include <linux/slab.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/err.h>
|
2013-01-31 19:07:40 +08:00
|
|
|
#include <linux/of.h>
|
|
|
|
#include <linux/of_device.h>
|
2013-01-08 17:41:02 +08:00
|
|
|
#include <linux/platform_device.h>
|
|
|
|
#include <linux/gpio.h>
|
|
|
|
#include <linux/irq.h>
|
2013-01-31 18:43:00 +08:00
|
|
|
#include <linux/irqdomain.h>
|
2013-01-08 17:41:02 +08:00
|
|
|
#include <linux/interrupt.h>
|
|
|
|
#include <linux/bitops.h>
|
|
|
|
#include <linux/mfd/abx500.h>
|
|
|
|
#include <linux/mfd/abx500/ab8500.h>
|
|
|
|
#include <linux/pinctrl/pinctrl.h>
|
|
|
|
#include <linux/pinctrl/consumer.h>
|
|
|
|
#include <linux/pinctrl/pinmux.h>
|
|
|
|
#include <linux/pinctrl/pinconf.h>
|
|
|
|
#include <linux/pinctrl/pinconf-generic.h>
|
2013-06-20 22:04:59 +08:00
|
|
|
#include <linux/pinctrl/machine.h>
|
2013-01-08 17:41:02 +08:00
|
|
|
|
|
|
|
#include "pinctrl-abx500.h"
|
2014-07-11 20:57:06 +08:00
|
|
|
#include "../core.h"
|
|
|
|
#include "../pinconf.h"
|
2014-09-30 17:11:50 +08:00
|
|
|
#include "../pinctrl-utils.h"
|
2013-01-08 17:41:02 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* GPIO registers offset
|
|
|
|
* Bank: 0x10
|
|
|
|
*/
|
|
|
|
#define AB8500_GPIO_SEL1_REG 0x00
|
|
|
|
#define AB8500_GPIO_SEL2_REG 0x01
|
|
|
|
#define AB8500_GPIO_SEL3_REG 0x02
|
|
|
|
#define AB8500_GPIO_SEL4_REG 0x03
|
|
|
|
#define AB8500_GPIO_SEL5_REG 0x04
|
|
|
|
#define AB8500_GPIO_SEL6_REG 0x05
|
|
|
|
|
|
|
|
#define AB8500_GPIO_DIR1_REG 0x10
|
|
|
|
#define AB8500_GPIO_DIR2_REG 0x11
|
|
|
|
#define AB8500_GPIO_DIR3_REG 0x12
|
|
|
|
#define AB8500_GPIO_DIR4_REG 0x13
|
|
|
|
#define AB8500_GPIO_DIR5_REG 0x14
|
|
|
|
#define AB8500_GPIO_DIR6_REG 0x15
|
|
|
|
|
|
|
|
#define AB8500_GPIO_OUT1_REG 0x20
|
|
|
|
#define AB8500_GPIO_OUT2_REG 0x21
|
|
|
|
#define AB8500_GPIO_OUT3_REG 0x22
|
|
|
|
#define AB8500_GPIO_OUT4_REG 0x23
|
|
|
|
#define AB8500_GPIO_OUT5_REG 0x24
|
|
|
|
#define AB8500_GPIO_OUT6_REG 0x25
|
|
|
|
|
|
|
|
#define AB8500_GPIO_PUD1_REG 0x30
|
|
|
|
#define AB8500_GPIO_PUD2_REG 0x31
|
|
|
|
#define AB8500_GPIO_PUD3_REG 0x32
|
|
|
|
#define AB8500_GPIO_PUD4_REG 0x33
|
|
|
|
#define AB8500_GPIO_PUD5_REG 0x34
|
|
|
|
#define AB8500_GPIO_PUD6_REG 0x35
|
|
|
|
|
|
|
|
#define AB8500_GPIO_IN1_REG 0x40
|
|
|
|
#define AB8500_GPIO_IN2_REG 0x41
|
|
|
|
#define AB8500_GPIO_IN3_REG 0x42
|
|
|
|
#define AB8500_GPIO_IN4_REG 0x43
|
|
|
|
#define AB8500_GPIO_IN5_REG 0x44
|
|
|
|
#define AB8500_GPIO_IN6_REG 0x45
|
|
|
|
#define AB8500_GPIO_ALTFUN_REG 0x50
|
|
|
|
|
2013-06-24 20:41:45 +08:00
|
|
|
#define ABX500_GPIO_INPUT 0
|
|
|
|
#define ABX500_GPIO_OUTPUT 1
|
|
|
|
|
2013-01-08 17:41:02 +08:00
|
|
|
struct abx500_pinctrl {
|
|
|
|
struct device *dev;
|
|
|
|
struct pinctrl_dev *pctldev;
|
|
|
|
struct abx500_pinctrl_soc_data *soc;
|
|
|
|
struct gpio_chip chip;
|
|
|
|
struct ab8500 *parent;
|
|
|
|
struct abx500_gpio_irq_cluster *irq_cluster;
|
|
|
|
int irq_cluster_size;
|
|
|
|
};
|
|
|
|
|
|
|
|
static int abx500_gpio_get_bit(struct gpio_chip *chip, u8 reg,
|
2013-01-23 21:24:08 +08:00
|
|
|
unsigned offset, bool *bit)
|
2013-01-08 17:41:02 +08:00
|
|
|
{
|
2015-12-08 15:29:43 +08:00
|
|
|
struct abx500_pinctrl *pct = gpiochip_get_data(chip);
|
2013-01-08 17:41:02 +08:00
|
|
|
u8 pos = offset % 8;
|
|
|
|
u8 val;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
reg += offset / 8;
|
|
|
|
ret = abx500_get_register_interruptible(pct->dev,
|
|
|
|
AB8500_MISC, reg, &val);
|
2018-08-08 20:04:49 +08:00
|
|
|
if (ret < 0) {
|
2013-01-08 17:41:02 +08:00
|
|
|
dev_err(pct->dev,
|
2013-06-24 20:41:46 +08:00
|
|
|
"%s read reg =%x, offset=%x failed (%d)\n",
|
|
|
|
__func__, reg, offset, ret);
|
2018-08-08 20:04:49 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
*bit = !!(val & BIT(pos));
|
2013-01-08 17:41:02 +08:00
|
|
|
|
2018-08-08 20:04:49 +08:00
|
|
|
return 0;
|
2013-01-08 17:41:02 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int abx500_gpio_set_bits(struct gpio_chip *chip, u8 reg,
|
2013-01-23 21:24:08 +08:00
|
|
|
unsigned offset, int val)
|
2013-01-08 17:41:02 +08:00
|
|
|
{
|
2015-12-08 15:29:43 +08:00
|
|
|
struct abx500_pinctrl *pct = gpiochip_get_data(chip);
|
2013-01-08 17:41:02 +08:00
|
|
|
u8 pos = offset % 8;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
reg += offset / 8;
|
|
|
|
ret = abx500_mask_and_set_register_interruptible(pct->dev,
|
2013-01-23 21:26:02 +08:00
|
|
|
AB8500_MISC, reg, BIT(pos), val << pos);
|
2013-01-08 17:41:02 +08:00
|
|
|
if (ret < 0)
|
2013-06-24 20:41:46 +08:00
|
|
|
dev_err(pct->dev, "%s write reg, %x offset %x failed (%d)\n",
|
|
|
|
__func__, reg, offset, ret);
|
2013-01-23 21:24:08 +08:00
|
|
|
|
2013-01-08 17:41:02 +08:00
|
|
|
return ret;
|
|
|
|
}
|
2013-01-23 21:24:08 +08:00
|
|
|
|
2013-01-08 17:41:02 +08:00
|
|
|
/**
|
|
|
|
* abx500_gpio_get() - Get the particular GPIO value
|
2013-01-23 21:24:08 +08:00
|
|
|
* @chip: Gpio device
|
|
|
|
* @offset: GPIO number to read
|
2013-01-08 17:41:02 +08:00
|
|
|
*/
|
|
|
|
static int abx500_gpio_get(struct gpio_chip *chip, unsigned offset)
|
|
|
|
{
|
2015-12-08 15:29:43 +08:00
|
|
|
struct abx500_pinctrl *pct = gpiochip_get_data(chip);
|
2013-01-08 17:41:02 +08:00
|
|
|
bool bit;
|
2013-06-20 22:05:43 +08:00
|
|
|
bool is_out;
|
|
|
|
u8 gpio_offset = offset - 1;
|
2013-01-08 17:41:02 +08:00
|
|
|
int ret;
|
|
|
|
|
2013-06-20 22:05:43 +08:00
|
|
|
ret = abx500_gpio_get_bit(chip, AB8500_GPIO_DIR1_REG,
|
|
|
|
gpio_offset, &is_out);
|
2013-06-24 20:41:46 +08:00
|
|
|
if (ret < 0)
|
|
|
|
goto out;
|
2013-06-20 22:05:43 +08:00
|
|
|
|
|
|
|
if (is_out)
|
|
|
|
ret = abx500_gpio_get_bit(chip, AB8500_GPIO_OUT1_REG,
|
|
|
|
gpio_offset, &bit);
|
|
|
|
else
|
|
|
|
ret = abx500_gpio_get_bit(chip, AB8500_GPIO_IN1_REG,
|
|
|
|
gpio_offset, &bit);
|
2013-06-24 20:41:46 +08:00
|
|
|
out:
|
2013-01-08 17:41:02 +08:00
|
|
|
if (ret < 0) {
|
2013-06-24 20:41:46 +08:00
|
|
|
dev_err(pct->dev, "%s failed (%d)\n", __func__, ret);
|
2013-01-08 17:41:02 +08:00
|
|
|
return ret;
|
|
|
|
}
|
2013-01-23 21:24:08 +08:00
|
|
|
|
2013-01-08 17:41:02 +08:00
|
|
|
return bit;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void abx500_gpio_set(struct gpio_chip *chip, unsigned offset, int val)
|
|
|
|
{
|
2015-12-08 15:29:43 +08:00
|
|
|
struct abx500_pinctrl *pct = gpiochip_get_data(chip);
|
2013-01-08 17:41:02 +08:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = abx500_gpio_set_bits(chip, AB8500_GPIO_OUT1_REG, offset, val);
|
|
|
|
if (ret < 0)
|
2013-06-24 20:41:46 +08:00
|
|
|
dev_err(pct->dev, "%s write failed (%d)\n", __func__, ret);
|
2013-01-08 17:41:02 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int abx500_gpio_direction_output(struct gpio_chip *chip,
|
|
|
|
unsigned offset,
|
|
|
|
int val)
|
|
|
|
{
|
2015-12-08 15:29:43 +08:00
|
|
|
struct abx500_pinctrl *pct = gpiochip_get_data(chip);
|
2013-01-08 17:41:02 +08:00
|
|
|
int ret;
|
2013-01-23 21:24:08 +08:00
|
|
|
|
2013-01-08 17:41:02 +08:00
|
|
|
/* set direction as output */
|
2013-06-24 20:41:45 +08:00
|
|
|
ret = abx500_gpio_set_bits(chip,
|
|
|
|
AB8500_GPIO_DIR1_REG,
|
|
|
|
offset,
|
|
|
|
ABX500_GPIO_OUTPUT);
|
2013-01-08 17:41:02 +08:00
|
|
|
if (ret < 0)
|
2013-06-24 20:41:46 +08:00
|
|
|
goto out;
|
2013-01-08 17:41:02 +08:00
|
|
|
|
|
|
|
/* disable pull down */
|
2013-06-24 20:41:45 +08:00
|
|
|
ret = abx500_gpio_set_bits(chip,
|
|
|
|
AB8500_GPIO_PUD1_REG,
|
|
|
|
offset,
|
|
|
|
ABX500_GPIO_PULL_NONE);
|
2013-01-08 17:41:02 +08:00
|
|
|
|
2013-06-24 20:41:46 +08:00
|
|
|
out:
|
|
|
|
if (ret < 0) {
|
|
|
|
dev_err(pct->dev, "%s failed (%d)\n", __func__, ret);
|
|
|
|
return ret;
|
2013-01-08 17:41:02 +08:00
|
|
|
}
|
2013-01-23 21:24:08 +08:00
|
|
|
|
2013-01-08 17:41:02 +08:00
|
|
|
/* set the output as 1 or 0 */
|
|
|
|
return abx500_gpio_set_bits(chip, AB8500_GPIO_OUT1_REG, offset, val);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int abx500_gpio_direction_input(struct gpio_chip *chip, unsigned offset)
|
|
|
|
{
|
|
|
|
/* set the register as input */
|
2013-06-24 20:41:45 +08:00
|
|
|
return abx500_gpio_set_bits(chip,
|
|
|
|
AB8500_GPIO_DIR1_REG,
|
|
|
|
offset,
|
|
|
|
ABX500_GPIO_INPUT);
|
2013-01-08 17:41:02 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int abx500_gpio_to_irq(struct gpio_chip *chip, unsigned offset)
|
|
|
|
{
|
2015-12-08 15:29:43 +08:00
|
|
|
struct abx500_pinctrl *pct = gpiochip_get_data(chip);
|
2013-01-31 17:45:17 +08:00
|
|
|
/* The AB8500 GPIO numbers are off by one */
|
|
|
|
int gpio = offset + 1;
|
2013-01-31 17:57:52 +08:00
|
|
|
int hwirq;
|
2013-01-08 17:41:02 +08:00
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < pct->irq_cluster_size; i++) {
|
|
|
|
struct abx500_gpio_irq_cluster *cluster =
|
|
|
|
&pct->irq_cluster[i];
|
|
|
|
|
2013-01-31 17:57:52 +08:00
|
|
|
if (gpio >= cluster->start && gpio <= cluster->end) {
|
|
|
|
/*
|
|
|
|
* The ABx500 GPIO's associated IRQs are clustered together
|
|
|
|
* throughout the interrupt numbers at irregular intervals.
|
|
|
|
* To solve this quandry, we have placed the read-in values
|
|
|
|
* into the cluster information table.
|
|
|
|
*/
|
2013-02-04 22:21:41 +08:00
|
|
|
hwirq = gpio - cluster->start + cluster->to_irq;
|
2013-01-31 17:57:52 +08:00
|
|
|
return irq_create_mapping(pct->parent->domain, hwirq);
|
|
|
|
}
|
2013-01-08 17:41:02 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int abx500_set_mode(struct pinctrl_dev *pctldev, struct gpio_chip *chip,
|
2013-01-23 21:24:08 +08:00
|
|
|
unsigned gpio, int alt_setting)
|
2013-01-08 17:41:02 +08:00
|
|
|
{
|
|
|
|
struct abx500_pinctrl *pct = pinctrl_dev_get_drvdata(pctldev);
|
|
|
|
struct alternate_functions af = pct->soc->alternate_functions[gpio];
|
|
|
|
int ret;
|
|
|
|
int val;
|
|
|
|
unsigned offset;
|
2013-01-23 21:24:08 +08:00
|
|
|
|
2013-01-08 17:41:02 +08:00
|
|
|
const char *modes[] = {
|
|
|
|
[ABX500_DEFAULT] = "default",
|
|
|
|
[ABX500_ALT_A] = "altA",
|
|
|
|
[ABX500_ALT_B] = "altB",
|
|
|
|
[ABX500_ALT_C] = "altC",
|
|
|
|
};
|
|
|
|
|
|
|
|
/* sanity check */
|
|
|
|
if (((alt_setting == ABX500_ALT_A) && (af.gpiosel_bit == UNUSED)) ||
|
|
|
|
((alt_setting == ABX500_ALT_B) && (af.alt_bit1 == UNUSED)) ||
|
|
|
|
((alt_setting == ABX500_ALT_C) && (af.alt_bit2 == UNUSED))) {
|
|
|
|
dev_dbg(pct->dev, "pin %d doesn't support %s mode\n", gpio,
|
|
|
|
modes[alt_setting]);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* on ABx5xx, there is no GPIO0, so adjust the offset */
|
|
|
|
offset = gpio - 1;
|
2013-01-23 21:24:08 +08:00
|
|
|
|
2013-01-08 17:41:02 +08:00
|
|
|
switch (alt_setting) {
|
|
|
|
case ABX500_DEFAULT:
|
|
|
|
/*
|
|
|
|
* for ABx5xx family, default mode is always selected by
|
|
|
|
* writing 0 to GPIOSELx register, except for pins which
|
|
|
|
* support at least ALT_B mode, default mode is selected
|
|
|
|
* by writing 1 to GPIOSELx register
|
|
|
|
*/
|
|
|
|
val = 0;
|
|
|
|
if (af.alt_bit1 != UNUSED)
|
|
|
|
val++;
|
|
|
|
|
|
|
|
ret = abx500_gpio_set_bits(chip, AB8500_GPIO_SEL1_REG,
|
|
|
|
offset, val);
|
|
|
|
break;
|
2013-01-23 21:24:08 +08:00
|
|
|
|
2013-01-08 17:41:02 +08:00
|
|
|
case ABX500_ALT_A:
|
|
|
|
/*
|
|
|
|
* for ABx5xx family, alt_a mode is always selected by
|
|
|
|
* writing 1 to GPIOSELx register, except for pins which
|
|
|
|
* support at least ALT_B mode, alt_a mode is selected
|
|
|
|
* by writing 0 to GPIOSELx register and 0 in ALTFUNC
|
|
|
|
* register
|
|
|
|
*/
|
|
|
|
if (af.alt_bit1 != UNUSED) {
|
|
|
|
ret = abx500_gpio_set_bits(chip, AB8500_GPIO_SEL1_REG,
|
|
|
|
offset, 0);
|
2013-06-24 20:41:46 +08:00
|
|
|
if (ret < 0)
|
|
|
|
goto out;
|
|
|
|
|
2013-01-08 17:41:02 +08:00
|
|
|
ret = abx500_gpio_set_bits(chip,
|
|
|
|
AB8500_GPIO_ALTFUN_REG,
|
|
|
|
af.alt_bit1,
|
2013-11-10 07:35:56 +08:00
|
|
|
!!(af.alta_val & BIT(0)));
|
2013-06-24 20:41:46 +08:00
|
|
|
if (ret < 0)
|
|
|
|
goto out;
|
|
|
|
|
2013-01-08 17:41:02 +08:00
|
|
|
if (af.alt_bit2 != UNUSED)
|
|
|
|
ret = abx500_gpio_set_bits(chip,
|
|
|
|
AB8500_GPIO_ALTFUN_REG,
|
|
|
|
af.alt_bit2,
|
2013-08-27 00:03:50 +08:00
|
|
|
!!(af.alta_val & BIT(1)));
|
2013-01-08 17:41:02 +08:00
|
|
|
} else
|
|
|
|
ret = abx500_gpio_set_bits(chip, AB8500_GPIO_SEL1_REG,
|
|
|
|
offset, 1);
|
|
|
|
break;
|
2013-01-23 21:24:08 +08:00
|
|
|
|
2013-01-08 17:41:02 +08:00
|
|
|
case ABX500_ALT_B:
|
|
|
|
ret = abx500_gpio_set_bits(chip, AB8500_GPIO_SEL1_REG,
|
|
|
|
offset, 0);
|
2013-06-24 20:41:46 +08:00
|
|
|
if (ret < 0)
|
|
|
|
goto out;
|
|
|
|
|
2013-01-08 17:41:02 +08:00
|
|
|
ret = abx500_gpio_set_bits(chip, AB8500_GPIO_ALTFUN_REG,
|
2013-11-10 07:35:56 +08:00
|
|
|
af.alt_bit1, !!(af.altb_val & BIT(0)));
|
2013-06-24 20:41:46 +08:00
|
|
|
if (ret < 0)
|
|
|
|
goto out;
|
|
|
|
|
2013-01-08 17:41:02 +08:00
|
|
|
if (af.alt_bit2 != UNUSED)
|
|
|
|
ret = abx500_gpio_set_bits(chip,
|
|
|
|
AB8500_GPIO_ALTFUN_REG,
|
|
|
|
af.alt_bit2,
|
2013-08-27 00:03:50 +08:00
|
|
|
!!(af.altb_val & BIT(1)));
|
2013-01-08 17:41:02 +08:00
|
|
|
break;
|
2013-01-23 21:24:08 +08:00
|
|
|
|
2013-01-08 17:41:02 +08:00
|
|
|
case ABX500_ALT_C:
|
|
|
|
ret = abx500_gpio_set_bits(chip, AB8500_GPIO_SEL1_REG,
|
|
|
|
offset, 0);
|
2013-06-24 20:41:46 +08:00
|
|
|
if (ret < 0)
|
|
|
|
goto out;
|
|
|
|
|
2013-01-08 17:41:02 +08:00
|
|
|
ret = abx500_gpio_set_bits(chip, AB8500_GPIO_ALTFUN_REG,
|
2013-08-27 00:03:50 +08:00
|
|
|
af.alt_bit2, !!(af.altc_val & BIT(0)));
|
2013-06-24 20:41:46 +08:00
|
|
|
if (ret < 0)
|
|
|
|
goto out;
|
|
|
|
|
2013-01-08 17:41:02 +08:00
|
|
|
ret = abx500_gpio_set_bits(chip, AB8500_GPIO_ALTFUN_REG,
|
2013-11-10 07:35:56 +08:00
|
|
|
af.alt_bit2, !!(af.altc_val & BIT(1)));
|
2013-01-08 17:41:02 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2015-02-24 22:11:26 +08:00
|
|
|
dev_dbg(pct->dev, "unknown alt_setting %d\n", alt_setting);
|
2013-01-23 21:24:08 +08:00
|
|
|
|
2013-01-08 17:41:02 +08:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
2013-06-24 20:41:46 +08:00
|
|
|
out:
|
|
|
|
if (ret < 0)
|
|
|
|
dev_err(pct->dev, "%s failed (%d)\n", __func__, ret);
|
2013-01-23 21:24:08 +08:00
|
|
|
|
2013-01-08 17:41:02 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2016-01-25 23:59:09 +08:00
|
|
|
#ifdef CONFIG_DEBUG_FS
|
2013-06-24 20:41:46 +08:00
|
|
|
static int abx500_get_mode(struct pinctrl_dev *pctldev, struct gpio_chip *chip,
|
2013-01-23 21:24:08 +08:00
|
|
|
unsigned gpio)
|
2013-01-08 17:41:02 +08:00
|
|
|
{
|
|
|
|
u8 mode;
|
|
|
|
bool bit_mode;
|
|
|
|
bool alt_bit1;
|
|
|
|
bool alt_bit2;
|
|
|
|
struct abx500_pinctrl *pct = pinctrl_dev_get_drvdata(pctldev);
|
|
|
|
struct alternate_functions af = pct->soc->alternate_functions[gpio];
|
2013-02-06 03:10:57 +08:00
|
|
|
/* on ABx5xx, there is no GPIO0, so adjust the offset */
|
|
|
|
unsigned offset = gpio - 1;
|
2013-06-24 20:41:46 +08:00
|
|
|
int ret;
|
2013-01-08 17:41:02 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* if gpiosel_bit is set to unused,
|
|
|
|
* it means no GPIO or special case
|
|
|
|
*/
|
|
|
|
if (af.gpiosel_bit == UNUSED)
|
|
|
|
return ABX500_DEFAULT;
|
|
|
|
|
|
|
|
/* read GpioSelx register */
|
2013-06-24 20:41:46 +08:00
|
|
|
ret = abx500_gpio_get_bit(chip, AB8500_GPIO_SEL1_REG + (offset / 8),
|
2013-01-08 17:41:02 +08:00
|
|
|
af.gpiosel_bit, &bit_mode);
|
2013-06-24 20:41:46 +08:00
|
|
|
if (ret < 0)
|
|
|
|
goto out;
|
|
|
|
|
2013-01-08 17:41:02 +08:00
|
|
|
mode = bit_mode;
|
|
|
|
|
|
|
|
/* sanity check */
|
|
|
|
if ((af.alt_bit1 < UNUSED) || (af.alt_bit1 > 7) ||
|
|
|
|
(af.alt_bit2 < UNUSED) || (af.alt_bit2 > 7)) {
|
|
|
|
dev_err(pct->dev,
|
|
|
|
"alt_bitX value not in correct range (-1 to 7)\n");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
2013-01-23 21:24:08 +08:00
|
|
|
|
2013-01-08 17:41:02 +08:00
|
|
|
/* if alt_bit2 is used, alt_bit1 must be used too */
|
|
|
|
if ((af.alt_bit2 != UNUSED) && (af.alt_bit1 == UNUSED)) {
|
|
|
|
dev_err(pct->dev,
|
|
|
|
"if alt_bit2 is used, alt_bit1 can't be unused\n");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* check if pin use AlternateFunction register */
|
2013-03-05 14:58:53 +08:00
|
|
|
if ((af.alt_bit1 == UNUSED) && (af.alt_bit2 == UNUSED))
|
2013-01-08 17:41:02 +08:00
|
|
|
return mode;
|
|
|
|
/*
|
|
|
|
* if pin GPIOSEL bit is set and pin supports alternate function,
|
|
|
|
* it means DEFAULT mode
|
|
|
|
*/
|
|
|
|
if (mode)
|
|
|
|
return ABX500_DEFAULT;
|
2013-01-23 21:24:08 +08:00
|
|
|
|
2013-01-08 17:41:02 +08:00
|
|
|
/*
|
|
|
|
* pin use the AlternatFunction register
|
|
|
|
* read alt_bit1 value
|
|
|
|
*/
|
2013-06-24 20:41:46 +08:00
|
|
|
ret = abx500_gpio_get_bit(chip, AB8500_GPIO_ALTFUN_REG,
|
2013-01-08 17:41:02 +08:00
|
|
|
af.alt_bit1, &alt_bit1);
|
2013-06-24 20:41:46 +08:00
|
|
|
if (ret < 0)
|
|
|
|
goto out;
|
2013-01-08 17:41:02 +08:00
|
|
|
|
2013-06-24 20:41:46 +08:00
|
|
|
if (af.alt_bit2 != UNUSED) {
|
2013-01-08 17:41:02 +08:00
|
|
|
/* read alt_bit2 value */
|
2013-06-24 20:41:46 +08:00
|
|
|
ret = abx500_gpio_get_bit(chip, AB8500_GPIO_ALTFUN_REG,
|
|
|
|
af.alt_bit2,
|
2013-01-08 17:41:02 +08:00
|
|
|
&alt_bit2);
|
2013-06-24 20:41:46 +08:00
|
|
|
if (ret < 0)
|
|
|
|
goto out;
|
|
|
|
} else
|
2013-01-08 17:41:02 +08:00
|
|
|
alt_bit2 = 0;
|
|
|
|
|
|
|
|
mode = (alt_bit2 << 1) + alt_bit1;
|
|
|
|
if (mode == af.alta_val)
|
|
|
|
return ABX500_ALT_A;
|
|
|
|
else if (mode == af.altb_val)
|
|
|
|
return ABX500_ALT_B;
|
|
|
|
else
|
|
|
|
return ABX500_ALT_C;
|
2013-06-24 20:41:46 +08:00
|
|
|
|
|
|
|
out:
|
|
|
|
dev_err(pct->dev, "%s failed (%d)\n", __func__, ret);
|
|
|
|
return ret;
|
2013-01-08 17:41:02 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#include <linux/seq_file.h>
|
|
|
|
|
|
|
|
static void abx500_gpio_dbg_show_one(struct seq_file *s,
|
2013-01-23 21:24:08 +08:00
|
|
|
struct pinctrl_dev *pctldev,
|
|
|
|
struct gpio_chip *chip,
|
|
|
|
unsigned offset, unsigned gpio)
|
2013-01-08 17:41:02 +08:00
|
|
|
{
|
2013-05-24 20:06:31 +08:00
|
|
|
struct abx500_pinctrl *pct = pinctrl_dev_get_drvdata(pctldev);
|
2013-01-08 17:41:02 +08:00
|
|
|
const char *label = gpiochip_is_requested(chip, offset - 1);
|
|
|
|
u8 gpio_offset = offset - 1;
|
|
|
|
int mode = -1;
|
|
|
|
bool is_out;
|
2013-05-24 20:06:31 +08:00
|
|
|
bool pd;
|
2013-06-24 20:41:46 +08:00
|
|
|
int ret;
|
2013-01-23 21:24:08 +08:00
|
|
|
|
2013-01-08 17:41:02 +08:00
|
|
|
const char *modes[] = {
|
|
|
|
[ABX500_DEFAULT] = "default",
|
|
|
|
[ABX500_ALT_A] = "altA",
|
|
|
|
[ABX500_ALT_B] = "altB",
|
|
|
|
[ABX500_ALT_C] = "altC",
|
|
|
|
};
|
|
|
|
|
2013-05-24 20:06:31 +08:00
|
|
|
const char *pull_up_down[] = {
|
|
|
|
[ABX500_GPIO_PULL_DOWN] = "pull down",
|
|
|
|
[ABX500_GPIO_PULL_NONE] = "pull none",
|
|
|
|
[ABX500_GPIO_PULL_NONE + 1] = "pull none",
|
|
|
|
[ABX500_GPIO_PULL_UP] = "pull up",
|
|
|
|
};
|
|
|
|
|
2013-06-24 20:41:46 +08:00
|
|
|
ret = abx500_gpio_get_bit(chip, AB8500_GPIO_DIR1_REG,
|
|
|
|
gpio_offset, &is_out);
|
|
|
|
if (ret < 0)
|
|
|
|
goto out;
|
2013-05-24 20:06:31 +08:00
|
|
|
|
|
|
|
seq_printf(s, " gpio-%-3d (%-20.20s) %-3s",
|
|
|
|
gpio, label ?: "(none)",
|
|
|
|
is_out ? "out" : "in ");
|
|
|
|
|
|
|
|
if (!is_out) {
|
2018-03-22 18:12:54 +08:00
|
|
|
ret = abx500_gpio_get_bit(chip, AB8500_GPIO_PUD1_REG,
|
|
|
|
gpio_offset, &pd);
|
|
|
|
if (ret < 0)
|
|
|
|
goto out;
|
2013-06-24 20:41:46 +08:00
|
|
|
|
2018-03-22 18:12:54 +08:00
|
|
|
seq_printf(s, " %-9s", pull_up_down[pd]);
|
2013-05-24 20:06:31 +08:00
|
|
|
} else
|
|
|
|
seq_printf(s, " %-9s", chip->get(chip, offset) ? "hi" : "lo");
|
2013-01-08 17:41:02 +08:00
|
|
|
|
2014-08-01 15:38:43 +08:00
|
|
|
mode = abx500_get_mode(pctldev, chip, offset);
|
2013-01-08 17:41:02 +08:00
|
|
|
|
2013-05-24 20:06:31 +08:00
|
|
|
seq_printf(s, " %s", (mode < 0) ? "unknown" : modes[mode]);
|
2013-06-24 20:41:46 +08:00
|
|
|
|
|
|
|
out:
|
|
|
|
if (ret < 0)
|
|
|
|
dev_err(pct->dev, "%s failed (%d)\n", __func__, ret);
|
2013-01-08 17:41:02 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void abx500_gpio_dbg_show(struct seq_file *s, struct gpio_chip *chip)
|
|
|
|
{
|
|
|
|
unsigned i;
|
|
|
|
unsigned gpio = chip->base;
|
2015-12-08 15:29:43 +08:00
|
|
|
struct abx500_pinctrl *pct = gpiochip_get_data(chip);
|
2013-01-08 17:41:02 +08:00
|
|
|
struct pinctrl_dev *pctldev = pct->pctldev;
|
|
|
|
|
|
|
|
for (i = 0; i < chip->ngpio; i++, gpio++) {
|
|
|
|
/* On AB8500, there is no GPIO0, the first is the GPIO 1 */
|
|
|
|
abx500_gpio_dbg_show_one(s, pctldev, chip, i + 1, gpio);
|
2018-01-13 18:04:29 +08:00
|
|
|
seq_putc(s, '\n');
|
2013-01-08 17:41:02 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#else
|
|
|
|
static inline void abx500_gpio_dbg_show_one(struct seq_file *s,
|
2013-01-23 21:24:08 +08:00
|
|
|
struct pinctrl_dev *pctldev,
|
|
|
|
struct gpio_chip *chip,
|
|
|
|
unsigned offset, unsigned gpio)
|
2013-01-08 17:41:02 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
#define abx500_gpio_dbg_show NULL
|
|
|
|
#endif
|
|
|
|
|
2017-07-12 05:29:29 +08:00
|
|
|
static const struct gpio_chip abx500gpio_chip = {
|
2013-01-08 17:41:02 +08:00
|
|
|
.label = "abx500-gpio",
|
|
|
|
.owner = THIS_MODULE,
|
2015-10-11 23:34:19 +08:00
|
|
|
.request = gpiochip_generic_request,
|
|
|
|
.free = gpiochip_generic_free,
|
2013-01-08 17:41:02 +08:00
|
|
|
.direction_input = abx500_gpio_direction_input,
|
|
|
|
.get = abx500_gpio_get,
|
|
|
|
.direction_output = abx500_gpio_direction_output,
|
|
|
|
.set = abx500_gpio_set,
|
|
|
|
.to_irq = abx500_gpio_to_irq,
|
|
|
|
.dbg_show = abx500_gpio_dbg_show,
|
|
|
|
};
|
|
|
|
|
|
|
|
static int abx500_pmx_get_funcs_cnt(struct pinctrl_dev *pctldev)
|
|
|
|
{
|
|
|
|
struct abx500_pinctrl *pct = pinctrl_dev_get_drvdata(pctldev);
|
|
|
|
|
|
|
|
return pct->soc->nfunctions;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char *abx500_pmx_get_func_name(struct pinctrl_dev *pctldev,
|
|
|
|
unsigned function)
|
|
|
|
{
|
|
|
|
struct abx500_pinctrl *pct = pinctrl_dev_get_drvdata(pctldev);
|
|
|
|
|
|
|
|
return pct->soc->functions[function].name;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int abx500_pmx_get_func_groups(struct pinctrl_dev *pctldev,
|
2013-01-23 21:24:08 +08:00
|
|
|
unsigned function,
|
|
|
|
const char * const **groups,
|
|
|
|
unsigned * const num_groups)
|
2013-01-08 17:41:02 +08:00
|
|
|
{
|
|
|
|
struct abx500_pinctrl *pct = pinctrl_dev_get_drvdata(pctldev);
|
|
|
|
|
|
|
|
*groups = pct->soc->functions[function].groups;
|
|
|
|
*num_groups = pct->soc->functions[function].ngroups;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-09-03 19:02:56 +08:00
|
|
|
static int abx500_pmx_set(struct pinctrl_dev *pctldev, unsigned function,
|
|
|
|
unsigned group)
|
2013-01-08 17:41:02 +08:00
|
|
|
{
|
|
|
|
struct abx500_pinctrl *pct = pinctrl_dev_get_drvdata(pctldev);
|
|
|
|
struct gpio_chip *chip = &pct->chip;
|
|
|
|
const struct abx500_pingroup *g;
|
|
|
|
int i;
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
g = &pct->soc->groups[group];
|
|
|
|
if (g->altsetting < 0)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
dev_dbg(pct->dev, "enable group %s, %u pins\n", g->name, g->npins);
|
|
|
|
|
|
|
|
for (i = 0; i < g->npins; i++) {
|
|
|
|
dev_dbg(pct->dev, "setting pin %d to altsetting %d\n",
|
|
|
|
g->pins[i], g->altsetting);
|
|
|
|
|
|
|
|
ret = abx500_set_mode(pctldev, chip, g->pins[i], g->altsetting);
|
|
|
|
}
|
2013-01-23 21:24:08 +08:00
|
|
|
|
2013-06-24 20:41:46 +08:00
|
|
|
if (ret < 0)
|
|
|
|
dev_err(pct->dev, "%s failed (%d)\n", __func__, ret);
|
|
|
|
|
2013-01-08 17:41:02 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2013-03-19 14:31:17 +08:00
|
|
|
static int abx500_gpio_request_enable(struct pinctrl_dev *pctldev,
|
2013-01-23 21:24:08 +08:00
|
|
|
struct pinctrl_gpio_range *range,
|
|
|
|
unsigned offset)
|
2013-01-08 17:41:02 +08:00
|
|
|
{
|
|
|
|
struct abx500_pinctrl *pct = pinctrl_dev_get_drvdata(pctldev);
|
|
|
|
const struct abx500_pinrange *p;
|
|
|
|
int ret;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Different ranges have different ways to enable GPIO function on a
|
|
|
|
* pin, so refer back to our local range type, where we handily define
|
|
|
|
* what altfunc enables GPIO for a certain pin.
|
|
|
|
*/
|
|
|
|
for (i = 0; i < pct->soc->gpio_num_ranges; i++) {
|
|
|
|
p = &pct->soc->gpio_ranges[i];
|
|
|
|
if ((offset >= p->offset) &&
|
|
|
|
(offset < (p->offset + p->npins)))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (i == pct->soc->gpio_num_ranges) {
|
|
|
|
dev_err(pct->dev, "%s failed to locate range\n", __func__);
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
|
|
|
dev_dbg(pct->dev, "enable GPIO by altfunc %d at gpio %d\n",
|
|
|
|
p->altfunc, offset);
|
|
|
|
|
|
|
|
ret = abx500_set_mode(pct->pctldev, &pct->chip,
|
|
|
|
offset, p->altfunc);
|
2013-06-24 20:41:46 +08:00
|
|
|
if (ret < 0)
|
2013-01-08 17:41:02 +08:00
|
|
|
dev_err(pct->dev, "%s setting altfunc failed\n", __func__);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void abx500_gpio_disable_free(struct pinctrl_dev *pctldev,
|
2013-01-23 21:24:08 +08:00
|
|
|
struct pinctrl_gpio_range *range,
|
|
|
|
unsigned offset)
|
2013-01-08 17:41:02 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-02-16 17:25:07 +08:00
|
|
|
static const struct pinmux_ops abx500_pinmux_ops = {
|
2013-01-08 17:41:02 +08:00
|
|
|
.get_functions_count = abx500_pmx_get_funcs_cnt,
|
|
|
|
.get_function_name = abx500_pmx_get_func_name,
|
|
|
|
.get_function_groups = abx500_pmx_get_func_groups,
|
2014-09-03 19:02:56 +08:00
|
|
|
.set_mux = abx500_pmx_set,
|
2013-01-08 17:41:02 +08:00
|
|
|
.gpio_request_enable = abx500_gpio_request_enable,
|
|
|
|
.gpio_disable_free = abx500_gpio_disable_free,
|
|
|
|
};
|
|
|
|
|
|
|
|
static int abx500_get_groups_cnt(struct pinctrl_dev *pctldev)
|
|
|
|
{
|
|
|
|
struct abx500_pinctrl *pct = pinctrl_dev_get_drvdata(pctldev);
|
|
|
|
|
|
|
|
return pct->soc->ngroups;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char *abx500_get_group_name(struct pinctrl_dev *pctldev,
|
2013-01-23 21:24:08 +08:00
|
|
|
unsigned selector)
|
2013-01-08 17:41:02 +08:00
|
|
|
{
|
|
|
|
struct abx500_pinctrl *pct = pinctrl_dev_get_drvdata(pctldev);
|
|
|
|
|
|
|
|
return pct->soc->groups[selector].name;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int abx500_get_group_pins(struct pinctrl_dev *pctldev,
|
2013-01-23 21:24:08 +08:00
|
|
|
unsigned selector,
|
|
|
|
const unsigned **pins,
|
|
|
|
unsigned *num_pins)
|
2013-01-08 17:41:02 +08:00
|
|
|
{
|
|
|
|
struct abx500_pinctrl *pct = pinctrl_dev_get_drvdata(pctldev);
|
|
|
|
|
|
|
|
*pins = pct->soc->groups[selector].pins;
|
|
|
|
*num_pins = pct->soc->groups[selector].npins;
|
2013-01-23 21:24:08 +08:00
|
|
|
|
2013-01-08 17:41:02 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void abx500_pin_dbg_show(struct pinctrl_dev *pctldev,
|
2013-01-23 21:24:08 +08:00
|
|
|
struct seq_file *s, unsigned offset)
|
2013-01-08 17:41:02 +08:00
|
|
|
{
|
|
|
|
struct abx500_pinctrl *pct = pinctrl_dev_get_drvdata(pctldev);
|
|
|
|
struct gpio_chip *chip = &pct->chip;
|
|
|
|
|
|
|
|
abx500_gpio_dbg_show_one(s, pctldev, chip, offset,
|
|
|
|
chip->base + offset - 1);
|
|
|
|
}
|
|
|
|
|
2013-06-20 22:04:59 +08:00
|
|
|
static int abx500_dt_add_map_mux(struct pinctrl_map **map,
|
|
|
|
unsigned *reserved_maps,
|
|
|
|
unsigned *num_maps, const char *group,
|
|
|
|
const char *function)
|
|
|
|
{
|
|
|
|
if (*num_maps == *reserved_maps)
|
|
|
|
return -ENOSPC;
|
|
|
|
|
|
|
|
(*map)[*num_maps].type = PIN_MAP_TYPE_MUX_GROUP;
|
|
|
|
(*map)[*num_maps].data.mux.group = group;
|
|
|
|
(*map)[*num_maps].data.mux.function = function;
|
|
|
|
(*num_maps)++;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int abx500_dt_add_map_configs(struct pinctrl_map **map,
|
|
|
|
unsigned *reserved_maps,
|
|
|
|
unsigned *num_maps, const char *group,
|
|
|
|
unsigned long *configs, unsigned num_configs)
|
|
|
|
{
|
|
|
|
unsigned long *dup_configs;
|
|
|
|
|
|
|
|
if (*num_maps == *reserved_maps)
|
|
|
|
return -ENOSPC;
|
|
|
|
|
|
|
|
dup_configs = kmemdup(configs, num_configs * sizeof(*dup_configs),
|
|
|
|
GFP_KERNEL);
|
|
|
|
if (!dup_configs)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
(*map)[*num_maps].type = PIN_MAP_TYPE_CONFIGS_PIN;
|
|
|
|
|
|
|
|
(*map)[*num_maps].data.configs.group_or_pin = group;
|
|
|
|
(*map)[*num_maps].data.configs.configs = dup_configs;
|
|
|
|
(*map)[*num_maps].data.configs.num_configs = num_configs;
|
|
|
|
(*num_maps)++;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char *abx500_find_pin_name(struct pinctrl_dev *pctldev,
|
|
|
|
const char *pin_name)
|
|
|
|
{
|
|
|
|
int i, pin_number;
|
|
|
|
struct abx500_pinctrl *npct = pinctrl_dev_get_drvdata(pctldev);
|
|
|
|
|
|
|
|
if (sscanf((char *)pin_name, "GPIO%d", &pin_number) == 1)
|
|
|
|
for (i = 0; i < npct->soc->npins; i++)
|
|
|
|
if (npct->soc->pins[i].number == pin_number)
|
|
|
|
return npct->soc->pins[i].name;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int abx500_dt_subnode_to_map(struct pinctrl_dev *pctldev,
|
|
|
|
struct device_node *np,
|
|
|
|
struct pinctrl_map **map,
|
|
|
|
unsigned *reserved_maps,
|
|
|
|
unsigned *num_maps)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
const char *function = NULL;
|
|
|
|
unsigned long *configs;
|
|
|
|
unsigned int nconfigs = 0;
|
|
|
|
struct property *prop;
|
|
|
|
|
2014-09-30 18:10:11 +08:00
|
|
|
ret = of_property_read_string(np, "function", &function);
|
2014-09-30 17:22:07 +08:00
|
|
|
if (ret >= 0) {
|
2014-09-30 18:10:11 +08:00
|
|
|
const char *group;
|
|
|
|
|
|
|
|
ret = of_property_count_strings(np, "groups");
|
2014-09-30 17:22:07 +08:00
|
|
|
if (ret < 0)
|
|
|
|
goto exit;
|
|
|
|
|
|
|
|
ret = pinctrl_utils_reserve_map(pctldev, map, reserved_maps,
|
|
|
|
num_maps, ret);
|
|
|
|
if (ret < 0)
|
|
|
|
goto exit;
|
|
|
|
|
2014-09-30 18:10:11 +08:00
|
|
|
of_property_for_each_string(np, "groups", prop, group) {
|
2014-09-30 17:22:07 +08:00
|
|
|
ret = abx500_dt_add_map_mux(map, reserved_maps,
|
|
|
|
num_maps, group, function);
|
|
|
|
if (ret < 0)
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
}
|
2013-06-20 22:04:59 +08:00
|
|
|
|
2015-01-09 23:43:46 +08:00
|
|
|
ret = pinconf_generic_parse_dt_config(np, pctldev, &configs, &nconfigs);
|
2014-09-30 18:23:15 +08:00
|
|
|
if (nconfigs) {
|
2014-09-30 18:10:11 +08:00
|
|
|
const char *gpio_name;
|
|
|
|
const char *pin;
|
|
|
|
|
2014-09-30 18:19:40 +08:00
|
|
|
ret = of_property_count_strings(np, "pins");
|
2014-09-30 17:22:07 +08:00
|
|
|
if (ret < 0)
|
|
|
|
goto exit;
|
2013-06-20 22:04:59 +08:00
|
|
|
|
2014-09-30 17:22:07 +08:00
|
|
|
ret = pinctrl_utils_reserve_map(pctldev, map,
|
|
|
|
reserved_maps,
|
|
|
|
num_maps, ret);
|
|
|
|
if (ret < 0)
|
|
|
|
goto exit;
|
2013-06-20 22:04:59 +08:00
|
|
|
|
2014-09-30 18:19:40 +08:00
|
|
|
of_property_for_each_string(np, "pins", prop, pin) {
|
2014-09-30 18:10:11 +08:00
|
|
|
gpio_name = abx500_find_pin_name(pctldev, pin);
|
2013-06-20 22:04:59 +08:00
|
|
|
|
|
|
|
ret = abx500_dt_add_map_configs(map, reserved_maps,
|
|
|
|
num_maps, gpio_name, configs, 1);
|
|
|
|
if (ret < 0)
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
}
|
2014-09-30 17:22:07 +08:00
|
|
|
|
2013-06-20 22:04:59 +08:00
|
|
|
exit:
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int abx500_dt_node_to_map(struct pinctrl_dev *pctldev,
|
|
|
|
struct device_node *np_config,
|
|
|
|
struct pinctrl_map **map, unsigned *num_maps)
|
|
|
|
{
|
|
|
|
unsigned reserved_maps;
|
|
|
|
struct device_node *np;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
reserved_maps = 0;
|
|
|
|
*map = NULL;
|
|
|
|
*num_maps = 0;
|
|
|
|
|
|
|
|
for_each_child_of_node(np_config, np) {
|
|
|
|
ret = abx500_dt_subnode_to_map(pctldev, np, map,
|
|
|
|
&reserved_maps, num_maps);
|
|
|
|
if (ret < 0) {
|
2016-03-31 19:44:42 +08:00
|
|
|
pinctrl_utils_free_map(pctldev, *map, *num_maps);
|
2013-06-20 22:04:59 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-02-16 17:25:07 +08:00
|
|
|
static const struct pinctrl_ops abx500_pinctrl_ops = {
|
2013-01-08 17:41:02 +08:00
|
|
|
.get_groups_count = abx500_get_groups_cnt,
|
|
|
|
.get_group_name = abx500_get_group_name,
|
|
|
|
.get_group_pins = abx500_get_group_pins,
|
|
|
|
.pin_dbg_show = abx500_pin_dbg_show,
|
2013-06-20 22:04:59 +08:00
|
|
|
.dt_node_to_map = abx500_dt_node_to_map,
|
2016-03-31 19:44:42 +08:00
|
|
|
.dt_free_map = pinctrl_utils_free_map,
|
2013-01-08 17:41:02 +08:00
|
|
|
};
|
|
|
|
|
2013-03-19 14:31:17 +08:00
|
|
|
static int abx500_pin_config_get(struct pinctrl_dev *pctldev,
|
2013-01-23 21:24:08 +08:00
|
|
|
unsigned pin,
|
|
|
|
unsigned long *config)
|
2013-01-08 17:41:02 +08:00
|
|
|
{
|
2012-12-20 19:11:19 +08:00
|
|
|
return -ENOSYS;
|
2013-01-08 17:41:02 +08:00
|
|
|
}
|
|
|
|
|
2013-03-19 14:31:17 +08:00
|
|
|
static int abx500_pin_config_set(struct pinctrl_dev *pctldev,
|
2013-01-23 21:24:08 +08:00
|
|
|
unsigned pin,
|
2013-08-28 02:32:12 +08:00
|
|
|
unsigned long *configs,
|
|
|
|
unsigned num_configs)
|
2013-01-08 17:41:02 +08:00
|
|
|
{
|
|
|
|
struct abx500_pinctrl *pct = pinctrl_dev_get_drvdata(pctldev);
|
|
|
|
struct gpio_chip *chip = &pct->chip;
|
|
|
|
unsigned offset;
|
2013-06-20 22:05:00 +08:00
|
|
|
int ret = -EINVAL;
|
2013-08-28 02:32:12 +08:00
|
|
|
int i;
|
|
|
|
enum pin_config_param param;
|
|
|
|
enum pin_config_param argument;
|
|
|
|
|
|
|
|
for (i = 0; i < num_configs; i++) {
|
|
|
|
param = pinconf_to_config_param(configs[i]);
|
|
|
|
argument = pinconf_to_config_argument(configs[i]);
|
|
|
|
|
2015-11-04 16:56:26 +08:00
|
|
|
dev_dbg(chip->parent, "pin %d [%#lx]: %s %s\n",
|
2013-08-28 02:32:12 +08:00
|
|
|
pin, configs[i],
|
|
|
|
(param == PIN_CONFIG_OUTPUT) ? "output " : "input",
|
|
|
|
(param == PIN_CONFIG_OUTPUT) ?
|
|
|
|
(argument ? "high" : "low") :
|
|
|
|
(argument ? "pull up" : "pull down"));
|
|
|
|
|
|
|
|
/* on ABx500, there is no GPIO0, so adjust the offset */
|
|
|
|
offset = pin - 1;
|
|
|
|
|
|
|
|
switch (param) {
|
|
|
|
case PIN_CONFIG_BIAS_DISABLE:
|
|
|
|
ret = abx500_gpio_direction_input(chip, offset);
|
|
|
|
if (ret < 0)
|
|
|
|
goto out;
|
2018-03-22 18:12:54 +08:00
|
|
|
|
|
|
|
/* Chip only supports pull down */
|
|
|
|
ret = abx500_gpio_set_bits(chip,
|
|
|
|
AB8500_GPIO_PUD1_REG, offset,
|
|
|
|
ABX500_GPIO_PULL_NONE);
|
2013-08-28 02:32:12 +08:00
|
|
|
break;
|
2013-05-24 20:06:30 +08:00
|
|
|
|
2013-08-28 02:32:12 +08:00
|
|
|
case PIN_CONFIG_BIAS_PULL_DOWN:
|
|
|
|
ret = abx500_gpio_direction_input(chip, offset);
|
|
|
|
if (ret < 0)
|
|
|
|
goto out;
|
|
|
|
/*
|
|
|
|
* if argument = 1 set the pull down
|
|
|
|
* else clear the pull down
|
2018-03-22 18:12:54 +08:00
|
|
|
* Chip only supports pull down
|
2013-08-28 02:32:12 +08:00
|
|
|
*/
|
2018-03-22 18:12:54 +08:00
|
|
|
ret = abx500_gpio_set_bits(chip,
|
|
|
|
AB8500_GPIO_PUD1_REG,
|
|
|
|
offset,
|
|
|
|
argument ? ABX500_GPIO_PULL_DOWN :
|
|
|
|
ABX500_GPIO_PULL_NONE);
|
2013-08-28 02:32:12 +08:00
|
|
|
break;
|
2013-01-23 21:24:08 +08:00
|
|
|
|
2013-08-28 02:32:12 +08:00
|
|
|
case PIN_CONFIG_BIAS_PULL_UP:
|
|
|
|
ret = abx500_gpio_direction_input(chip, offset);
|
|
|
|
if (ret < 0)
|
|
|
|
goto out;
|
|
|
|
/*
|
|
|
|
* if argument = 1 set the pull up
|
|
|
|
* else clear the pull up
|
|
|
|
*/
|
|
|
|
ret = abx500_gpio_direction_input(chip, offset);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PIN_CONFIG_OUTPUT:
|
|
|
|
ret = abx500_gpio_direction_output(chip, offset,
|
|
|
|
argument);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2015-11-04 16:56:26 +08:00
|
|
|
dev_err(chip->parent,
|
|
|
|
"illegal configuration requested\n");
|
2013-08-28 02:32:12 +08:00
|
|
|
}
|
|
|
|
} /* for each config */
|
2013-06-24 20:41:46 +08:00
|
|
|
out:
|
|
|
|
if (ret < 0)
|
|
|
|
dev_err(pct->dev, "%s failed (%d)\n", __func__, ret);
|
2013-01-23 21:24:08 +08:00
|
|
|
|
2013-01-08 17:41:02 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2013-02-16 17:25:07 +08:00
|
|
|
static const struct pinconf_ops abx500_pinconf_ops = {
|
2013-01-08 17:41:02 +08:00
|
|
|
.pin_config_get = abx500_pin_config_get,
|
|
|
|
.pin_config_set = abx500_pin_config_set,
|
2014-09-30 19:12:28 +08:00
|
|
|
.is_generic = true,
|
2013-01-08 17:41:02 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
static struct pinctrl_desc abx500_pinctrl_desc = {
|
|
|
|
.name = "pinctrl-abx500",
|
|
|
|
.pctlops = &abx500_pinctrl_ops,
|
|
|
|
.pmxops = &abx500_pinmux_ops,
|
|
|
|
.confops = &abx500_pinconf_ops,
|
|
|
|
.owner = THIS_MODULE,
|
|
|
|
};
|
|
|
|
|
|
|
|
static int abx500_get_gpio_num(struct abx500_pinctrl_soc_data *soc)
|
|
|
|
{
|
|
|
|
unsigned int lowest = 0;
|
|
|
|
unsigned int highest = 0;
|
|
|
|
unsigned int npins = 0;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Compute number of GPIOs from the last SoC gpio range descriptors
|
|
|
|
* These ranges may include "holes" but the GPIO number space shall
|
|
|
|
* still be homogeneous, so we need to detect and account for any
|
|
|
|
* such holes so that these are included in the number of GPIO pins.
|
|
|
|
*/
|
|
|
|
for (i = 0; i < soc->gpio_num_ranges; i++) {
|
|
|
|
unsigned gstart;
|
|
|
|
unsigned gend;
|
|
|
|
const struct abx500_pinrange *p;
|
|
|
|
|
|
|
|
p = &soc->gpio_ranges[i];
|
|
|
|
gstart = p->offset;
|
|
|
|
gend = p->offset + p->npins - 1;
|
|
|
|
|
|
|
|
if (i == 0) {
|
|
|
|
/* First iteration, set start values */
|
|
|
|
lowest = gstart;
|
|
|
|
highest = gend;
|
|
|
|
} else {
|
|
|
|
if (gstart < lowest)
|
|
|
|
lowest = gstart;
|
|
|
|
if (gend > highest)
|
|
|
|
highest = gend;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* this gives the absolute number of pins */
|
|
|
|
npins = highest - lowest + 1;
|
|
|
|
return npins;
|
|
|
|
}
|
|
|
|
|
2013-01-31 19:07:40 +08:00
|
|
|
static const struct of_device_id abx500_gpio_match[] = {
|
|
|
|
{ .compatible = "stericsson,ab8500-gpio", .data = (void *)PINCTRL_AB8500, },
|
|
|
|
{ .compatible = "stericsson,ab8505-gpio", .data = (void *)PINCTRL_AB8505, },
|
2013-02-17 21:58:47 +08:00
|
|
|
{ }
|
2013-01-31 19:07:40 +08:00
|
|
|
};
|
|
|
|
|
2013-01-08 17:41:02 +08:00
|
|
|
static int abx500_gpio_probe(struct platform_device *pdev)
|
|
|
|
{
|
2013-01-31 19:07:40 +08:00
|
|
|
struct device_node *np = pdev->dev.of_node;
|
2013-12-03 22:50:17 +08:00
|
|
|
const struct of_device_id *match;
|
2013-01-08 17:41:02 +08:00
|
|
|
struct abx500_pinctrl *pct;
|
2013-01-31 19:07:40 +08:00
|
|
|
unsigned int id = -1;
|
2014-10-02 15:30:43 +08:00
|
|
|
int ret;
|
2013-01-08 17:41:02 +08:00
|
|
|
int i;
|
|
|
|
|
2013-12-03 22:50:17 +08:00
|
|
|
if (!np) {
|
|
|
|
dev_err(&pdev->dev, "gpio dt node missing\n");
|
2013-05-08 21:29:08 +08:00
|
|
|
return -ENODEV;
|
2013-01-08 17:41:02 +08:00
|
|
|
}
|
|
|
|
|
2017-12-20 17:22:53 +08:00
|
|
|
pct = devm_kzalloc(&pdev->dev, sizeof(*pct), GFP_KERNEL);
|
2017-12-20 17:12:56 +08:00
|
|
|
if (!pct)
|
2013-01-08 17:41:02 +08:00
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
pct->dev = &pdev->dev;
|
|
|
|
pct->parent = dev_get_drvdata(pdev->dev.parent);
|
|
|
|
pct->chip = abx500gpio_chip;
|
2015-11-04 16:56:26 +08:00
|
|
|
pct->chip.parent = &pdev->dev;
|
2013-12-03 22:50:17 +08:00
|
|
|
pct->chip.base = -1; /* Dynamic allocation */
|
2013-05-08 21:29:08 +08:00
|
|
|
|
2013-12-03 22:50:17 +08:00
|
|
|
match = of_match_device(abx500_gpio_match, &pdev->dev);
|
|
|
|
if (!match) {
|
|
|
|
dev_err(&pdev->dev, "gpio dt not matching\n");
|
|
|
|
return -ENODEV;
|
2013-05-08 21:29:08 +08:00
|
|
|
}
|
2013-12-03 22:50:17 +08:00
|
|
|
id = (unsigned long)match->data;
|
2013-05-08 21:29:08 +08:00
|
|
|
|
2013-01-08 17:41:02 +08:00
|
|
|
/* Poke in other ASIC variants here */
|
2013-01-31 19:07:40 +08:00
|
|
|
switch (id) {
|
2013-01-08 17:59:53 +08:00
|
|
|
case PINCTRL_AB8500:
|
|
|
|
abx500_pinctrl_ab8500_init(&pct->soc);
|
|
|
|
break;
|
2013-01-28 21:23:45 +08:00
|
|
|
case PINCTRL_AB8505:
|
|
|
|
abx500_pinctrl_ab8505_init(&pct->soc);
|
|
|
|
break;
|
2013-01-08 17:41:02 +08:00
|
|
|
default:
|
2013-05-08 21:29:07 +08:00
|
|
|
dev_err(&pdev->dev, "Unsupported pinctrl sub driver (%d)\n", id);
|
2013-01-08 17:41:02 +08:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!pct->soc) {
|
|
|
|
dev_err(&pdev->dev, "Invalid SOC data\n");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
pct->chip.ngpio = abx500_get_gpio_num(pct->soc);
|
|
|
|
pct->irq_cluster = pct->soc->gpio_irq_cluster;
|
|
|
|
pct->irq_cluster_size = pct->soc->ngpio_irq_cluster;
|
|
|
|
|
2015-12-08 15:29:43 +08:00
|
|
|
ret = gpiochip_add_data(&pct->chip, pct);
|
2013-01-08 17:41:02 +08:00
|
|
|
if (ret) {
|
2013-01-23 21:24:08 +08:00
|
|
|
dev_err(&pdev->dev, "unable to add gpiochip: %d\n", ret);
|
2013-01-31 18:43:00 +08:00
|
|
|
return ret;
|
2013-01-08 17:41:02 +08:00
|
|
|
}
|
|
|
|
dev_info(&pdev->dev, "added gpiochip\n");
|
|
|
|
|
|
|
|
abx500_pinctrl_desc.pins = pct->soc->pins;
|
|
|
|
abx500_pinctrl_desc.npins = pct->soc->npins;
|
2016-02-24 17:14:07 +08:00
|
|
|
pct->pctldev = devm_pinctrl_register(&pdev->dev, &abx500_pinctrl_desc,
|
|
|
|
pct);
|
2015-06-09 12:01:16 +08:00
|
|
|
if (IS_ERR(pct->pctldev)) {
|
2013-01-08 17:41:02 +08:00
|
|
|
dev_err(&pdev->dev,
|
|
|
|
"could not register abx500 pinctrl driver\n");
|
2015-06-09 12:01:16 +08:00
|
|
|
ret = PTR_ERR(pct->pctldev);
|
2013-01-08 17:41:02 +08:00
|
|
|
goto out_rem_chip;
|
|
|
|
}
|
|
|
|
dev_info(&pdev->dev, "registered pin controller\n");
|
|
|
|
|
|
|
|
/* We will handle a range of GPIO pins */
|
|
|
|
for (i = 0; i < pct->soc->gpio_num_ranges; i++) {
|
|
|
|
const struct abx500_pinrange *p = &pct->soc->gpio_ranges[i];
|
|
|
|
|
|
|
|
ret = gpiochip_add_pin_range(&pct->chip,
|
|
|
|
dev_name(&pdev->dev),
|
|
|
|
p->offset - 1, p->offset, p->npins);
|
|
|
|
if (ret < 0)
|
2013-01-31 19:06:33 +08:00
|
|
|
goto out_rem_chip;
|
2013-01-08 17:41:02 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
platform_set_drvdata(pdev, pct);
|
|
|
|
dev_info(&pdev->dev, "initialized abx500 pinctrl driver\n");
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
out_rem_chip:
|
2014-09-17 06:05:41 +08:00
|
|
|
gpiochip_remove(&pct->chip);
|
2013-01-08 17:41:02 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2013-01-23 21:24:08 +08:00
|
|
|
/**
|
2013-01-08 17:41:02 +08:00
|
|
|
* abx500_gpio_remove() - remove Ab8500-gpio driver
|
2013-01-23 21:24:08 +08:00
|
|
|
* @pdev: Platform device registered
|
2013-01-08 17:41:02 +08:00
|
|
|
*/
|
|
|
|
static int abx500_gpio_remove(struct platform_device *pdev)
|
|
|
|
{
|
|
|
|
struct abx500_pinctrl *pct = platform_get_drvdata(pdev);
|
|
|
|
|
2014-09-17 06:05:41 +08:00
|
|
|
gpiochip_remove(&pct->chip);
|
2013-01-08 17:41:02 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct platform_driver abx500_gpio_driver = {
|
|
|
|
.driver = {
|
|
|
|
.name = "abx500-gpio",
|
2013-01-31 19:07:40 +08:00
|
|
|
.of_match_table = abx500_gpio_match,
|
2013-01-08 17:41:02 +08:00
|
|
|
},
|
|
|
|
.probe = abx500_gpio_probe,
|
|
|
|
.remove = abx500_gpio_remove,
|
|
|
|
};
|
|
|
|
|
|
|
|
static int __init abx500_gpio_init(void)
|
|
|
|
{
|
|
|
|
return platform_driver_register(&abx500_gpio_driver);
|
|
|
|
}
|
|
|
|
core_initcall(abx500_gpio_init);
|