2019-06-01 16:09:00 +08:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0-only */
|
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>
|
|
|
|
*/
|
|
|
|
|
2018-09-13 19:58:21 +08:00
|
|
|
#include <linux/gpio/driver.h>
|
2015-01-18 02:15:14 +08:00
|
|
|
#include <linux/pinctrl/pinctrl.h>
|
2017-10-12 20:40:25 +08:00
|
|
|
#include <linux/platform_device.h>
|
2015-01-18 02:15:14 +08:00
|
|
|
#include <linux/regmap.h>
|
|
|
|
#include <linux/types.h>
|
|
|
|
|
pinctrl: meson: add a new callback for SoCs fixup
In meson_pinctrl_parse_dt, it contains two parts: reg parsing and
SoC relative fixup for AO. Several fixups in the same code make it hard
to maintain, so move all fixups to each SoC's callback and make
meson_pinctrl_parse_dt just do the reg parsing, separate these two
parts.Overview of all current Meson SoCs fixup is as below:
+------+--------------------------------------+--------------------------+
| | | |
| SoC | EE domain | AO domain |
+------+--------------------------------------+--------------------------+
|m8 | parse regs: | parse regs: |
|m8b | gpio,mux,pull,pull-enable(skip ds) | gpio,mux,pull(skip ds)|
|gxl | fixup: | fixup: |
|gxbb | no | pull-enable = pull; |
|axg | | |
+------+--------------------------------------+--------------------------+
|g12a | parse regs: | parse regs: |
|sm1 | gpio,mux,pull,pull-enable,ds | gpio,mux,ds |
| | fixup: | fixup: |
| | no | pull = gpio; |
| | | pull-enable = gpio; |
+------+--------------------------------------+--------------------------+
|a1 or | parse regs: |
|later | gpio/mux (without ao domain) |
|SoCs | fixup: |
| | pull = gpio; pull-enable = gpio; ds = gpio; |
+------+-----------------------------------------------------------------+
Since m8-axg share the same ao fixup, make a common function
meson8_aobus_parse_dt_extra to do the job.
Signed-off-by: Qianggui Song <qianggui.song@amlogic.com>
Link: https://lore.kernel.org/r/1573819429-6937-2-git-send-email-qianggui.song@amlogic.com
Reviewed-by: Neil Armstrong <narmstrong@baylibre.com>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
2019-11-15 20:03:47 +08:00
|
|
|
struct meson_pinctrl;
|
|
|
|
|
2015-01-18 02:15:14 +08:00
|
|
|
/**
|
|
|
|
* 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;
|
2017-10-12 20:40:26 +08:00
|
|
|
const void *data;
|
2015-01-18 02:15:14 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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,
|
2019-05-14 16:26:51 +08:00
|
|
|
REG_DS,
|
2015-01-18 02:15:14 +08:00
|
|
|
NUM_REG,
|
|
|
|
};
|
|
|
|
|
2019-05-14 16:26:51 +08:00
|
|
|
/**
|
|
|
|
* enum meson_pinconf_drv - value of drive-strength supported
|
|
|
|
*/
|
|
|
|
enum meson_pinconf_drv {
|
|
|
|
MESON_PINCONF_DRV_500UA,
|
|
|
|
MESON_PINCONF_DRV_2500UA,
|
|
|
|
MESON_PINCONF_DRV_3000UA,
|
|
|
|
MESON_PINCONF_DRV_4000UA,
|
|
|
|
};
|
|
|
|
|
2015-01-18 02:15:14 +08:00
|
|
|
/**
|
|
|
|
* 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;
|
2017-10-12 20:40:26 +08:00
|
|
|
const struct pinmux_ops *pmx_ops;
|
2017-11-20 18:08:24 +08:00
|
|
|
void *pmx_data;
|
pinctrl: meson: add a new callback for SoCs fixup
In meson_pinctrl_parse_dt, it contains two parts: reg parsing and
SoC relative fixup for AO. Several fixups in the same code make it hard
to maintain, so move all fixups to each SoC's callback and make
meson_pinctrl_parse_dt just do the reg parsing, separate these two
parts.Overview of all current Meson SoCs fixup is as below:
+------+--------------------------------------+--------------------------+
| | | |
| SoC | EE domain | AO domain |
+------+--------------------------------------+--------------------------+
|m8 | parse regs: | parse regs: |
|m8b | gpio,mux,pull,pull-enable(skip ds) | gpio,mux,pull(skip ds)|
|gxl | fixup: | fixup: |
|gxbb | no | pull-enable = pull; |
|axg | | |
+------+--------------------------------------+--------------------------+
|g12a | parse regs: | parse regs: |
|sm1 | gpio,mux,pull,pull-enable,ds | gpio,mux,ds |
| | fixup: | fixup: |
| | no | pull = gpio; |
| | | pull-enable = gpio; |
+------+--------------------------------------+--------------------------+
|a1 or | parse regs: |
|later | gpio/mux (without ao domain) |
|SoCs | fixup: |
| | pull = gpio; pull-enable = gpio; ds = gpio; |
+------+-----------------------------------------------------------------+
Since m8-axg share the same ao fixup, make a common function
meson8_aobus_parse_dt_extra to do the job.
Signed-off-by: Qianggui Song <qianggui.song@amlogic.com>
Link: https://lore.kernel.org/r/1573819429-6937-2-git-send-email-qianggui.song@amlogic.com
Reviewed-by: Neil Armstrong <narmstrong@baylibre.com>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
2019-11-15 20:03:47 +08:00
|
|
|
int (*parse_dt)(struct meson_pinctrl *pc);
|
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;
|
2019-01-17 18:23:15 +08:00
|
|
|
struct regmap *reg_ds;
|
2016-08-14 01:41:18 +08:00
|
|
|
struct gpio_chip chip;
|
|
|
|
struct device_node *of_node;
|
2015-01-18 02:15:14 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
#define FUNCTION(fn) \
|
|
|
|
{ \
|
|
|
|
.name = #fn, \
|
|
|
|
.groups = fn ## _groups, \
|
|
|
|
.num_groups = ARRAY_SIZE(fn ## _groups), \
|
|
|
|
}
|
|
|
|
|
2019-05-14 16:26:51 +08:00
|
|
|
#define BANK_DS(n, f, l, fi, li, per, peb, pr, pb, dr, db, or, ob, ir, ib, \
|
|
|
|
dsr, dsb) \
|
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 }, \
|
2019-05-14 16:26:51 +08:00
|
|
|
[REG_DS] = { dsr, dsb }, \
|
2015-01-18 02:15:14 +08:00
|
|
|
}, \
|
|
|
|
}
|
|
|
|
|
2019-05-14 16:26:51 +08:00
|
|
|
#define BANK(n, f, l, fi, li, per, peb, pr, pb, dr, db, or, ob, ir, ib) \
|
|
|
|
BANK_DS(n, f, l, fi, li, per, peb, pr, pb, dr, db, or, ob, ir, ib, 0, 0)
|
|
|
|
|
2017-09-20 21:39:20 +08:00
|
|
|
#define MESON_PIN(x) PINCTRL_PIN(x, #x)
|
2015-01-18 02:15:14 +08:00
|
|
|
|
2017-10-12 20:40:26 +08:00
|
|
|
/* Common pmx functions */
|
|
|
|
int meson_pmx_get_funcs_count(struct pinctrl_dev *pcdev);
|
|
|
|
const char *meson_pmx_get_func_name(struct pinctrl_dev *pcdev,
|
|
|
|
unsigned selector);
|
|
|
|
int meson_pmx_get_groups(struct pinctrl_dev *pcdev,
|
|
|
|
unsigned selector,
|
|
|
|
const char * const **groups,
|
|
|
|
unsigned * const num_groups);
|
|
|
|
|
2017-10-12 20:40:25 +08:00
|
|
|
/* Common probe function */
|
|
|
|
int meson_pinctrl_probe(struct platform_device *pdev);
|
pinctrl: meson: add a new callback for SoCs fixup
In meson_pinctrl_parse_dt, it contains two parts: reg parsing and
SoC relative fixup for AO. Several fixups in the same code make it hard
to maintain, so move all fixups to each SoC's callback and make
meson_pinctrl_parse_dt just do the reg parsing, separate these two
parts.Overview of all current Meson SoCs fixup is as below:
+------+--------------------------------------+--------------------------+
| | | |
| SoC | EE domain | AO domain |
+------+--------------------------------------+--------------------------+
|m8 | parse regs: | parse regs: |
|m8b | gpio,mux,pull,pull-enable(skip ds) | gpio,mux,pull(skip ds)|
|gxl | fixup: | fixup: |
|gxbb | no | pull-enable = pull; |
|axg | | |
+------+--------------------------------------+--------------------------+
|g12a | parse regs: | parse regs: |
|sm1 | gpio,mux,pull,pull-enable,ds | gpio,mux,ds |
| | fixup: | fixup: |
| | no | pull = gpio; |
| | | pull-enable = gpio; |
+------+--------------------------------------+--------------------------+
|a1 or | parse regs: |
|later | gpio/mux (without ao domain) |
|SoCs | fixup: |
| | pull = gpio; pull-enable = gpio; ds = gpio; |
+------+-----------------------------------------------------------------+
Since m8-axg share the same ao fixup, make a common function
meson8_aobus_parse_dt_extra to do the job.
Signed-off-by: Qianggui Song <qianggui.song@amlogic.com>
Link: https://lore.kernel.org/r/1573819429-6937-2-git-send-email-qianggui.song@amlogic.com
Reviewed-by: Neil Armstrong <narmstrong@baylibre.com>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
2019-11-15 20:03:47 +08:00
|
|
|
/* Common ao groups extra dt parse function for SoCs before g12a */
|
|
|
|
int meson8_aobus_parse_dt_extra(struct meson_pinctrl *pc);
|
pinctrl: meson: add pinctrl driver support for Meson-A1 SoC
Meson A1 SoC share the same register layout of pinmux with previous
Meson-G12A, however there is difference for gpio and pin config register
in A1. The main difference is that registers before A1 are grouped by
function while those of A1 are by bank. The new register layout is as
below:
/* first bank */ /* addr */
- P_PADCTRL_GPIOP_I base + 0x00 << 2
- P_PADCTRL_GPIOP_O base + 0x01 << 2
- P_PADCTRL_GPIOP_OEN base + 0x02 << 2
- P_PADCTRL_GPIOP_PULL_EN base + 0x03 << 2
- P_PADCTRL_GPIOP_PULL_UP base + 0x04 << 2
- P_PADCTRL_GPIOP_DS base + 0x05 << 2
/* second bank */
- P_PADCTRL_GPIOB_I base + 0x10 << 2
- P_PADCTRL_GPIOB_O base + 0x11 << 2
- P_PADCTRL_GPIOB_OEN base + 0x12 << 2
- P_PADCTRL_GPIOB_PULL_EN base + 0x13 << 2
- P_PADCTRL_GPIOB_PULL_UP base + 0x14 << 2
- P_PADCTRL_GPIOB_DS base + 0x15 << 2
Each bank contains at least 6 registers to be configured, if one bank
has more than 16 gpios, an extra P_PADCTRL_GPIO[X]_DS_EXT is included.
Between two adjacent P_PADCTRL_GPIO[X]_I, there is an offset 0x10, that
is to say, for third bank, the offsets will be 0x20,0x21,0x22,0x23,0x24
,0x25 according to above register layout. For previous chips, registers
are grouped according to their functions while registers of A1 are
according to bank.Also note that there is no AO bank any more in A1.
Current Meson pinctrl driver can cover such change by using base address
of GPIO as that of drive-strength. While simply giving reg_ds = reg_pullen
make wrong value to reg_ds for Socs that do not support drive-strength
like AXG.To make things simple, add an extra dt parser function for
a1 and remain the old dt parser function for only reg parsing.
Signed-off-by: Qianggui Song <qianggui.song@amlogic.com>
Link: https://lore.kernel.org/r/1573819429-6937-3-git-send-email-qianggui.song@amlogic.com
Reviewed-by: Neil Armstrong <narmstrong@baylibre.com>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
2019-11-15 20:03:48 +08:00
|
|
|
/* Common extra dt parse function for SoCs like A1 */
|
|
|
|
int meson_a1_parse_dt_extra(struct meson_pinctrl *pc);
|