2015-01-18 02:15:14 +08:00
|
|
|
/*
|
|
|
|
* Pin controller and GPIO driver for Amlogic Meson SoCs
|
|
|
|
*
|
|
|
|
* Copyright (C) 2014 Beniamino Galvani <b.galvani@gmail.com>
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/gpio.h>
|
|
|
|
#include <linux/pinctrl/pinctrl.h>
|
|
|
|
#include <linux/regmap.h>
|
|
|
|
#include <linux/types.h>
|
|
|
|
|
|
|
|
/**
|
|
|
|
* struct meson_pmx_group - a pinmux group
|
|
|
|
*
|
|
|
|
* @name: group name
|
|
|
|
* @pins: pins in the group
|
|
|
|
* @num_pins: number of pins in the group
|
|
|
|
* @is_gpio: whether the group is a single GPIO group
|
|
|
|
* @reg: register offset for the group in the domain mux registers
|
|
|
|
* @bit bit index enabling the group
|
|
|
|
* @domain: index of the domain this group belongs to
|
|
|
|
*/
|
|
|
|
struct meson_pmx_group {
|
|
|
|
const char *name;
|
|
|
|
const unsigned int *pins;
|
|
|
|
unsigned int num_pins;
|
|
|
|
bool is_gpio;
|
|
|
|
unsigned int reg;
|
|
|
|
unsigned int bit;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* struct meson_pmx_func - a pinmux function
|
|
|
|
*
|
|
|
|
* @name: function name
|
|
|
|
* @groups: groups in the function
|
|
|
|
* @num_groups: number of groups in the function
|
|
|
|
*/
|
|
|
|
struct meson_pmx_func {
|
|
|
|
const char *name;
|
|
|
|
const char * const *groups;
|
|
|
|
unsigned int num_groups;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* struct meson_reg_desc - a register descriptor
|
|
|
|
*
|
|
|
|
* @reg: register offset in the regmap
|
|
|
|
* @bit: bit index in register
|
|
|
|
*
|
|
|
|
* The structure describes the information needed to control pull,
|
|
|
|
* pull-enable, direction, etc. for a single pin
|
|
|
|
*/
|
|
|
|
struct meson_reg_desc {
|
|
|
|
unsigned int reg;
|
|
|
|
unsigned int bit;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* enum meson_reg_type - type of registers encoded in @meson_reg_desc
|
|
|
|
*/
|
|
|
|
enum meson_reg_type {
|
|
|
|
REG_PULLEN,
|
|
|
|
REG_PULL,
|
|
|
|
REG_DIR,
|
|
|
|
REG_OUT,
|
|
|
|
REG_IN,
|
|
|
|
NUM_REG,
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* struct meson bank
|
|
|
|
*
|
|
|
|
* @name: bank name
|
|
|
|
* @first: first pin of the bank
|
|
|
|
* @last: last pin of the bank
|
2017-06-09 03:37:50 +08:00
|
|
|
* @irq: hwirq base number of the bank
|
2015-01-18 02:15:14 +08:00
|
|
|
* @regs: array of register descriptors
|
|
|
|
*
|
|
|
|
* A bank represents a set of pins controlled by a contiguous set of
|
|
|
|
* bits in the domain registers. The structure specifies which bits in
|
|
|
|
* the regmap control the different functionalities. Each member of
|
|
|
|
* the @regs array refers to the first pin of the bank.
|
|
|
|
*/
|
|
|
|
struct meson_bank {
|
|
|
|
const char *name;
|
|
|
|
unsigned int first;
|
|
|
|
unsigned int last;
|
2017-06-09 03:37:50 +08:00
|
|
|
int irq_first;
|
|
|
|
int irq_last;
|
2015-01-18 02:15:14 +08:00
|
|
|
struct meson_reg_desc regs[NUM_REG];
|
|
|
|
};
|
|
|
|
|
|
|
|
struct meson_pinctrl_data {
|
2016-08-14 01:41:18 +08:00
|
|
|
const char *name;
|
2015-01-18 02:15:14 +08:00
|
|
|
const struct pinctrl_pin_desc *pins;
|
|
|
|
struct meson_pmx_group *groups;
|
|
|
|
struct meson_pmx_func *funcs;
|
|
|
|
unsigned int num_pins;
|
|
|
|
unsigned int num_groups;
|
|
|
|
unsigned int num_funcs;
|
2016-08-14 01:41:18 +08:00
|
|
|
struct meson_bank *banks;
|
|
|
|
unsigned int num_banks;
|
2015-01-18 02:15:14 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
struct meson_pinctrl {
|
|
|
|
struct device *dev;
|
|
|
|
struct pinctrl_dev *pcdev;
|
|
|
|
struct pinctrl_desc desc;
|
|
|
|
struct meson_pinctrl_data *data;
|
2016-08-14 01:41:18 +08:00
|
|
|
struct regmap *reg_mux;
|
|
|
|
struct regmap *reg_pullen;
|
|
|
|
struct regmap *reg_pull;
|
|
|
|
struct regmap *reg_gpio;
|
|
|
|
struct gpio_chip chip;
|
|
|
|
struct device_node *of_node;
|
2015-01-18 02:15:14 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
#define GROUP(grp, r, b) \
|
|
|
|
{ \
|
|
|
|
.name = #grp, \
|
|
|
|
.pins = grp ## _pins, \
|
|
|
|
.num_pins = ARRAY_SIZE(grp ## _pins), \
|
|
|
|
.reg = r, \
|
|
|
|
.bit = b, \
|
|
|
|
}
|
|
|
|
|
2017-09-20 21:39:20 +08:00
|
|
|
#define GPIO_GROUP(gpio) \
|
2015-01-18 02:15:14 +08:00
|
|
|
{ \
|
|
|
|
.name = #gpio, \
|
2017-09-20 21:39:20 +08:00
|
|
|
.pins = (const unsigned int[]){ gpio }, \
|
2015-01-18 02:15:14 +08:00
|
|
|
.num_pins = 1, \
|
|
|
|
.is_gpio = true, \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define FUNCTION(fn) \
|
|
|
|
{ \
|
|
|
|
.name = #fn, \
|
|
|
|
.groups = fn ## _groups, \
|
|
|
|
.num_groups = ARRAY_SIZE(fn ## _groups), \
|
|
|
|
}
|
|
|
|
|
2017-06-09 03:37:50 +08:00
|
|
|
#define BANK(n, f, l, fi, li, per, peb, pr, pb, dr, db, or, ob, ir, ib) \
|
2015-01-18 02:15:14 +08:00
|
|
|
{ \
|
2017-06-09 03:37:50 +08:00
|
|
|
.name = n, \
|
|
|
|
.first = f, \
|
|
|
|
.last = l, \
|
|
|
|
.irq_first = fi, \
|
|
|
|
.irq_last = li, \
|
|
|
|
.regs = { \
|
2015-01-18 02:15:14 +08:00
|
|
|
[REG_PULLEN] = { per, peb }, \
|
|
|
|
[REG_PULL] = { pr, pb }, \
|
|
|
|
[REG_DIR] = { dr, db }, \
|
|
|
|
[REG_OUT] = { or, ob }, \
|
|
|
|
[REG_IN] = { ir, ib }, \
|
|
|
|
}, \
|
|
|
|
}
|
|
|
|
|
2017-09-20 21:39:20 +08:00
|
|
|
#define MESON_PIN(x) PINCTRL_PIN(x, #x)
|
2015-01-18 02:15:14 +08:00
|
|
|
|
2016-03-02 06:04:34 +08:00
|
|
|
extern struct meson_pinctrl_data meson8_cbus_pinctrl_data;
|
|
|
|
extern struct meson_pinctrl_data meson8_aobus_pinctrl_data;
|
|
|
|
extern struct meson_pinctrl_data meson8b_cbus_pinctrl_data;
|
|
|
|
extern struct meson_pinctrl_data meson8b_aobus_pinctrl_data;
|
2016-05-02 16:02:15 +08:00
|
|
|
extern struct meson_pinctrl_data meson_gxbb_periphs_pinctrl_data;
|
|
|
|
extern struct meson_pinctrl_data meson_gxbb_aobus_pinctrl_data;
|
2016-11-01 00:32:11 +08:00
|
|
|
extern struct meson_pinctrl_data meson_gxl_periphs_pinctrl_data;
|
|
|
|
extern struct meson_pinctrl_data meson_gxl_aobus_pinctrl_data;
|