2018-09-08 19:07:17 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
|
|
|
/*
|
|
|
|
* Copyright (C) 2018 MediaTek Inc.
|
|
|
|
*
|
|
|
|
* Author: Sean Wang <sean.wang@mediatek.com>
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2020-01-22 14:53:13 +08:00
|
|
|
#include <dt-bindings/pinctrl/mt65xx.h>
|
2018-09-08 19:07:17 +08:00
|
|
|
#include <linux/device.h>
|
|
|
|
#include <linux/err.h>
|
2018-09-19 06:03:13 +08:00
|
|
|
#include <linux/gpio/driver.h>
|
2018-09-08 19:07:37 +08:00
|
|
|
#include <linux/platform_device.h>
|
2018-09-08 19:07:17 +08:00
|
|
|
#include <linux/io.h>
|
2020-04-08 04:08:16 +08:00
|
|
|
#include <linux/module.h>
|
2018-09-08 19:07:37 +08:00
|
|
|
#include <linux/of_irq.h>
|
2018-09-08 19:07:17 +08:00
|
|
|
|
2018-09-08 19:07:37 +08:00
|
|
|
#include "mtk-eint.h"
|
2018-09-08 19:07:17 +08:00
|
|
|
#include "pinctrl-mtk-common-v2.h"
|
|
|
|
|
2018-09-08 19:07:22 +08:00
|
|
|
/**
|
|
|
|
* struct mtk_drive_desc - the structure that holds the information
|
|
|
|
* of the driving current
|
|
|
|
* @min: the minimum current of this group
|
|
|
|
* @max: the maximum current of this group
|
|
|
|
* @step: the step current of this group
|
|
|
|
* @scal: the weight factor
|
|
|
|
*
|
|
|
|
* formula: output = ((input) / step - 1) * scal
|
|
|
|
*/
|
|
|
|
struct mtk_drive_desc {
|
|
|
|
u8 min;
|
|
|
|
u8 max;
|
|
|
|
u8 step;
|
|
|
|
u8 scal;
|
|
|
|
};
|
|
|
|
|
|
|
|
/* The groups of drive strength */
|
2018-09-20 14:21:42 +08:00
|
|
|
static const struct mtk_drive_desc mtk_drive[] = {
|
2018-09-08 19:07:22 +08:00
|
|
|
[DRV_GRP0] = { 4, 16, 4, 1 },
|
|
|
|
[DRV_GRP1] = { 4, 16, 4, 2 },
|
|
|
|
[DRV_GRP2] = { 2, 8, 2, 1 },
|
|
|
|
[DRV_GRP3] = { 2, 8, 2, 2 },
|
|
|
|
[DRV_GRP4] = { 2, 16, 2, 1 },
|
|
|
|
};
|
|
|
|
|
2018-09-08 19:07:30 +08:00
|
|
|
static void mtk_w32(struct mtk_pinctrl *pctl, u8 i, u32 reg, u32 val)
|
2018-09-08 19:07:17 +08:00
|
|
|
{
|
2018-09-08 19:07:30 +08:00
|
|
|
writel_relaxed(val, pctl->base[i] + reg);
|
2018-09-08 19:07:17 +08:00
|
|
|
}
|
|
|
|
|
2018-09-08 19:07:30 +08:00
|
|
|
static u32 mtk_r32(struct mtk_pinctrl *pctl, u8 i, u32 reg)
|
2018-09-08 19:07:17 +08:00
|
|
|
{
|
2018-09-08 19:07:30 +08:00
|
|
|
return readl_relaxed(pctl->base[i] + reg);
|
2018-09-08 19:07:17 +08:00
|
|
|
}
|
|
|
|
|
2018-09-08 19:07:30 +08:00
|
|
|
void mtk_rmw(struct mtk_pinctrl *pctl, u8 i, u32 reg, u32 mask, u32 set)
|
2018-09-08 19:07:17 +08:00
|
|
|
{
|
|
|
|
u32 val;
|
2021-04-19 17:34:49 +08:00
|
|
|
unsigned long flags;
|
2018-09-08 19:07:17 +08:00
|
|
|
|
2021-04-19 17:34:49 +08:00
|
|
|
spin_lock_irqsave(&pctl->lock, flags);
|
2021-03-21 11:31:50 +08:00
|
|
|
|
2018-09-08 19:07:30 +08:00
|
|
|
val = mtk_r32(pctl, i, reg);
|
2018-09-08 19:07:17 +08:00
|
|
|
val &= ~mask;
|
|
|
|
val |= set;
|
2018-09-08 19:07:30 +08:00
|
|
|
mtk_w32(pctl, i, reg, val);
|
2021-03-21 11:31:50 +08:00
|
|
|
|
2021-04-19 17:34:49 +08:00
|
|
|
spin_unlock_irqrestore(&pctl->lock, flags);
|
2018-09-08 19:07:17 +08:00
|
|
|
}
|
|
|
|
|
2018-09-08 19:07:29 +08:00
|
|
|
static int mtk_hw_pin_field_lookup(struct mtk_pinctrl *hw,
|
|
|
|
const struct mtk_pin_desc *desc,
|
2018-09-08 19:07:31 +08:00
|
|
|
int field, struct mtk_pin_field *pfd)
|
2018-09-08 19:07:17 +08:00
|
|
|
{
|
2020-02-18 10:36:25 +08:00
|
|
|
const struct mtk_pin_field_calc *c;
|
2018-09-08 19:07:31 +08:00
|
|
|
const struct mtk_pin_reg_calc *rc;
|
2020-01-22 14:53:09 +08:00
|
|
|
int start = 0, end, check;
|
|
|
|
bool found = false;
|
2018-09-08 19:07:17 +08:00
|
|
|
u32 bits;
|
|
|
|
|
2018-09-08 19:07:31 +08:00
|
|
|
if (hw->soc->reg_cal && hw->soc->reg_cal[field].range) {
|
|
|
|
rc = &hw->soc->reg_cal[field];
|
|
|
|
} else {
|
|
|
|
dev_dbg(hw->dev,
|
2020-01-22 14:53:09 +08:00
|
|
|
"Not support field %d for this soc\n", field);
|
2018-09-08 19:07:31 +08:00
|
|
|
return -ENOTSUPP;
|
|
|
|
}
|
|
|
|
|
2020-01-22 14:53:09 +08:00
|
|
|
end = rc->nranges - 1;
|
2018-09-08 19:07:17 +08:00
|
|
|
|
2020-01-22 14:53:09 +08:00
|
|
|
while (start <= end) {
|
|
|
|
check = (start + end) >> 1;
|
|
|
|
if (desc->number >= rc->range[check].s_pin
|
|
|
|
&& desc->number <= rc->range[check].e_pin) {
|
|
|
|
found = true;
|
|
|
|
break;
|
|
|
|
} else if (start == end)
|
2018-09-08 19:07:17 +08:00
|
|
|
break;
|
2020-01-22 14:53:09 +08:00
|
|
|
else if (desc->number < rc->range[check].s_pin)
|
|
|
|
end = check - 1;
|
|
|
|
else
|
|
|
|
start = check + 1;
|
2018-09-08 19:07:17 +08:00
|
|
|
}
|
|
|
|
|
2020-01-22 14:53:09 +08:00
|
|
|
if (!found) {
|
2018-09-08 19:07:31 +08:00
|
|
|
dev_dbg(hw->dev, "Not support field %d for pin = %d (%s)\n",
|
|
|
|
field, desc->number, desc->name);
|
|
|
|
return -ENOTSUPP;
|
2018-09-08 19:07:17 +08:00
|
|
|
}
|
|
|
|
|
2020-01-22 14:53:09 +08:00
|
|
|
c = rc->range + check;
|
|
|
|
|
2018-09-08 19:07:30 +08:00
|
|
|
if (c->i_base > hw->nbase - 1) {
|
2018-09-08 19:07:31 +08:00
|
|
|
dev_err(hw->dev,
|
|
|
|
"Invalid base for field %d for pin = %d (%s)\n",
|
|
|
|
field, desc->number, desc->name);
|
2018-09-08 19:07:30 +08:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2018-09-08 19:07:19 +08:00
|
|
|
/* Calculated bits as the overall offset the pin is located at,
|
|
|
|
* if c->fixed is held, that determines the all the pins in the
|
|
|
|
* range use the same field with the s_pin.
|
|
|
|
*/
|
2018-09-08 19:07:29 +08:00
|
|
|
bits = c->fixed ? c->s_bit : c->s_bit +
|
|
|
|
(desc->number - c->s_pin) * (c->x_bits);
|
2018-09-08 19:07:17 +08:00
|
|
|
|
2018-09-08 19:07:19 +08:00
|
|
|
/* Fill pfd from bits. For example 32-bit register applied is assumed
|
|
|
|
* when c->sz_reg is equal to 32.
|
|
|
|
*/
|
2018-09-08 19:07:30 +08:00
|
|
|
pfd->index = c->i_base;
|
2018-09-08 19:07:19 +08:00
|
|
|
pfd->offset = c->s_addr + c->x_addrs * (bits / c->sz_reg);
|
|
|
|
pfd->bitpos = bits % c->sz_reg;
|
2018-09-08 19:07:17 +08:00
|
|
|
pfd->mask = (1 << c->x_bits) - 1;
|
|
|
|
|
|
|
|
/* pfd->next is used for indicating that bit wrapping-around happens
|
|
|
|
* which requires the manipulation for bit 0 starting in the next
|
|
|
|
* register to form the complete field read/write.
|
|
|
|
*/
|
2018-09-08 19:07:19 +08:00
|
|
|
pfd->next = pfd->bitpos + c->x_bits > c->sz_reg ? c->x_addrs : 0;
|
2018-09-08 19:07:17 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-09-08 19:07:29 +08:00
|
|
|
static int mtk_hw_pin_field_get(struct mtk_pinctrl *hw,
|
|
|
|
const struct mtk_pin_desc *desc,
|
2018-09-08 19:07:17 +08:00
|
|
|
int field, struct mtk_pin_field *pfd)
|
|
|
|
{
|
|
|
|
if (field < 0 || field >= PINCTRL_PIN_REG_MAX) {
|
|
|
|
dev_err(hw->dev, "Invalid Field %d\n", field);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2018-09-08 19:07:31 +08:00
|
|
|
return mtk_hw_pin_field_lookup(hw, desc, field, pfd);
|
2018-09-08 19:07:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void mtk_hw_bits_part(struct mtk_pin_field *pf, int *h, int *l)
|
|
|
|
{
|
|
|
|
*l = 32 - pf->bitpos;
|
|
|
|
*h = get_count_order(pf->mask) - *l;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void mtk_hw_write_cross_field(struct mtk_pinctrl *hw,
|
|
|
|
struct mtk_pin_field *pf, int value)
|
|
|
|
{
|
|
|
|
int nbits_l, nbits_h;
|
|
|
|
|
|
|
|
mtk_hw_bits_part(pf, &nbits_h, &nbits_l);
|
|
|
|
|
2018-09-08 19:07:30 +08:00
|
|
|
mtk_rmw(hw, pf->index, pf->offset, pf->mask << pf->bitpos,
|
2018-09-08 19:07:17 +08:00
|
|
|
(value & pf->mask) << pf->bitpos);
|
|
|
|
|
2018-09-08 19:07:30 +08:00
|
|
|
mtk_rmw(hw, pf->index, pf->offset + pf->next, BIT(nbits_h) - 1,
|
2018-09-08 19:07:17 +08:00
|
|
|
(value & pf->mask) >> nbits_l);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void mtk_hw_read_cross_field(struct mtk_pinctrl *hw,
|
|
|
|
struct mtk_pin_field *pf, int *value)
|
|
|
|
{
|
|
|
|
int nbits_l, nbits_h, h, l;
|
|
|
|
|
|
|
|
mtk_hw_bits_part(pf, &nbits_h, &nbits_l);
|
|
|
|
|
2018-09-08 19:07:30 +08:00
|
|
|
l = (mtk_r32(hw, pf->index, pf->offset)
|
|
|
|
>> pf->bitpos) & (BIT(nbits_l) - 1);
|
|
|
|
h = (mtk_r32(hw, pf->index, pf->offset + pf->next))
|
|
|
|
& (BIT(nbits_h) - 1);
|
2018-09-08 19:07:17 +08:00
|
|
|
|
|
|
|
*value = (h << nbits_l) | l;
|
|
|
|
}
|
|
|
|
|
2018-09-08 19:07:29 +08:00
|
|
|
int mtk_hw_set_value(struct mtk_pinctrl *hw, const struct mtk_pin_desc *desc,
|
|
|
|
int field, int value)
|
2018-09-08 19:07:17 +08:00
|
|
|
{
|
|
|
|
struct mtk_pin_field pf;
|
|
|
|
int err;
|
|
|
|
|
2018-09-08 19:07:29 +08:00
|
|
|
err = mtk_hw_pin_field_get(hw, desc, field, &pf);
|
2018-09-08 19:07:17 +08:00
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
2020-01-22 14:53:09 +08:00
|
|
|
if (value < 0 || value > pf.mask)
|
|
|
|
return -EINVAL;
|
|
|
|
|
2018-09-08 19:07:17 +08:00
|
|
|
if (!pf.next)
|
2018-09-08 19:07:30 +08:00
|
|
|
mtk_rmw(hw, pf.index, pf.offset, pf.mask << pf.bitpos,
|
2018-09-08 19:07:17 +08:00
|
|
|
(value & pf.mask) << pf.bitpos);
|
|
|
|
else
|
|
|
|
mtk_hw_write_cross_field(hw, &pf, value);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2020-04-08 04:08:16 +08:00
|
|
|
EXPORT_SYMBOL_GPL(mtk_hw_set_value);
|
2018-09-08 19:07:17 +08:00
|
|
|
|
2018-09-08 19:07:29 +08:00
|
|
|
int mtk_hw_get_value(struct mtk_pinctrl *hw, const struct mtk_pin_desc *desc,
|
|
|
|
int field, int *value)
|
2018-09-08 19:07:17 +08:00
|
|
|
{
|
|
|
|
struct mtk_pin_field pf;
|
|
|
|
int err;
|
|
|
|
|
2018-09-08 19:07:29 +08:00
|
|
|
err = mtk_hw_pin_field_get(hw, desc, field, &pf);
|
2018-09-08 19:07:17 +08:00
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
if (!pf.next)
|
2018-09-08 19:07:30 +08:00
|
|
|
*value = (mtk_r32(hw, pf.index, pf.offset)
|
|
|
|
>> pf.bitpos) & pf.mask;
|
2018-09-08 19:07:17 +08:00
|
|
|
else
|
|
|
|
mtk_hw_read_cross_field(hw, &pf, value);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2020-04-08 04:08:16 +08:00
|
|
|
EXPORT_SYMBOL_GPL(mtk_hw_get_value);
|
2018-09-08 19:07:22 +08:00
|
|
|
|
2018-09-08 19:07:37 +08:00
|
|
|
static int mtk_xt_find_eint_num(struct mtk_pinctrl *hw, unsigned long eint_n)
|
|
|
|
{
|
|
|
|
const struct mtk_pin_desc *desc;
|
|
|
|
int i = 0;
|
|
|
|
|
|
|
|
desc = (const struct mtk_pin_desc *)hw->soc->pins;
|
|
|
|
|
|
|
|
while (i < hw->soc->npins) {
|
|
|
|
if (desc[i].eint.eint_n == eint_n)
|
|
|
|
return desc[i].number;
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return EINT_NA;
|
|
|
|
}
|
|
|
|
|
2020-07-23 19:19:53 +08:00
|
|
|
/*
|
|
|
|
* Virtual GPIO only used inside SOC and not being exported to outside SOC.
|
|
|
|
* Some modules use virtual GPIO as eint (e.g. pmif or usb).
|
|
|
|
* In MTK platform, external interrupt (EINT) and GPIO is 1-1 mapping
|
|
|
|
* and we can set GPIO as eint.
|
|
|
|
* But some modules use specific eint which doesn't have real GPIO pin.
|
|
|
|
* So we use virtual GPIO to map it.
|
|
|
|
*/
|
|
|
|
|
|
|
|
bool mtk_is_virt_gpio(struct mtk_pinctrl *hw, unsigned int gpio_n)
|
|
|
|
{
|
|
|
|
const struct mtk_pin_desc *desc;
|
|
|
|
bool virt_gpio = false;
|
|
|
|
|
|
|
|
desc = (const struct mtk_pin_desc *)&hw->soc->pins[gpio_n];
|
|
|
|
|
2020-08-20 19:22:25 +08:00
|
|
|
/* if the GPIO is not supported for eint mode */
|
|
|
|
if (desc->eint.eint_m == NO_EINT_SUPPORT)
|
|
|
|
return virt_gpio;
|
|
|
|
|
2020-07-23 19:19:53 +08:00
|
|
|
if (desc->funcs && !desc->funcs[desc->eint.eint_m].name)
|
|
|
|
virt_gpio = true;
|
|
|
|
|
|
|
|
return virt_gpio;
|
|
|
|
}
|
2020-07-28 13:55:45 +08:00
|
|
|
EXPORT_SYMBOL_GPL(mtk_is_virt_gpio);
|
2020-07-23 19:19:53 +08:00
|
|
|
|
2018-09-08 19:07:37 +08:00
|
|
|
static int mtk_xt_get_gpio_n(void *data, unsigned long eint_n,
|
|
|
|
unsigned int *gpio_n,
|
|
|
|
struct gpio_chip **gpio_chip)
|
|
|
|
{
|
|
|
|
struct mtk_pinctrl *hw = (struct mtk_pinctrl *)data;
|
|
|
|
const struct mtk_pin_desc *desc;
|
|
|
|
|
|
|
|
desc = (const struct mtk_pin_desc *)hw->soc->pins;
|
|
|
|
*gpio_chip = &hw->chip;
|
|
|
|
|
2021-11-10 15:19:00 +08:00
|
|
|
/*
|
|
|
|
* Be greedy to guess first gpio_n is equal to eint_n.
|
|
|
|
* Only eint virtual eint number is greater than gpio number.
|
|
|
|
*/
|
|
|
|
if (hw->soc->npins > eint_n &&
|
|
|
|
desc[eint_n].eint.eint_n == eint_n)
|
2018-09-08 19:07:37 +08:00
|
|
|
*gpio_n = eint_n;
|
|
|
|
else
|
|
|
|
*gpio_n = mtk_xt_find_eint_num(hw, eint_n);
|
|
|
|
|
|
|
|
return *gpio_n == EINT_NA ? -EINVAL : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int mtk_xt_get_gpio_state(void *data, unsigned long eint_n)
|
|
|
|
{
|
|
|
|
struct mtk_pinctrl *hw = (struct mtk_pinctrl *)data;
|
|
|
|
const struct mtk_pin_desc *desc;
|
|
|
|
struct gpio_chip *gpio_chip;
|
|
|
|
unsigned int gpio_n;
|
|
|
|
int value, err;
|
|
|
|
|
|
|
|
err = mtk_xt_get_gpio_n(hw, eint_n, &gpio_n, &gpio_chip);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
desc = (const struct mtk_pin_desc *)&hw->soc->pins[gpio_n];
|
|
|
|
|
|
|
|
err = mtk_hw_get_value(hw, desc, PINCTRL_PIN_REG_DI, &value);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
return !!value;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int mtk_xt_set_gpio_as_eint(void *data, unsigned long eint_n)
|
|
|
|
{
|
|
|
|
struct mtk_pinctrl *hw = (struct mtk_pinctrl *)data;
|
|
|
|
const struct mtk_pin_desc *desc;
|
|
|
|
struct gpio_chip *gpio_chip;
|
|
|
|
unsigned int gpio_n;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
err = mtk_xt_get_gpio_n(hw, eint_n, &gpio_n, &gpio_chip);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
2020-07-23 19:19:53 +08:00
|
|
|
if (mtk_is_virt_gpio(hw, gpio_n))
|
|
|
|
return 0;
|
|
|
|
|
2018-09-08 19:07:37 +08:00
|
|
|
desc = (const struct mtk_pin_desc *)&hw->soc->pins[gpio_n];
|
|
|
|
|
|
|
|
err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_MODE,
|
|
|
|
desc->eint.eint_m);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_DIR, MTK_INPUT);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_SMT, MTK_ENABLE);
|
2019-01-03 11:37:15 +08:00
|
|
|
/* SMT is supposed to be supported by every real GPIO and doesn't
|
|
|
|
* support virtual GPIOs, so the extra condition err != -ENOTSUPP
|
|
|
|
* is just for adding EINT support to these virtual GPIOs. It should
|
|
|
|
* add an extra flag in the pin descriptor when more pins with
|
|
|
|
* distinctive characteristic come out.
|
|
|
|
*/
|
|
|
|
if (err && err != -ENOTSUPP)
|
2018-09-08 19:07:37 +08:00
|
|
|
return err;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct mtk_eint_xt mtk_eint_xt = {
|
|
|
|
.get_gpio_n = mtk_xt_get_gpio_n,
|
|
|
|
.get_gpio_state = mtk_xt_get_gpio_state,
|
|
|
|
.set_gpio_as_eint = mtk_xt_set_gpio_as_eint,
|
|
|
|
};
|
|
|
|
|
|
|
|
int mtk_build_eint(struct mtk_pinctrl *hw, struct platform_device *pdev)
|
|
|
|
{
|
|
|
|
struct device_node *np = pdev->dev.of_node;
|
pinctrl: mediatek: Free eint data on failure
The pinctrl driver can work without the EINT resource, but, if it is
expected to have this resource but the mtk_build_eint() function fails
after allocating their data (because can't get the resource or can't map
the irq), the data is not freed and you end with a NULL pointer
dereference. Fix this by freeing the data if mtk_build_eint() fails, so
pinctrl still works and doesn't hang.
This is noticeable after commit f97dbf48ca43 ("irqchip/mtk-sysirq: Convert
to a platform driver") on MT8183 because, due this commit, the pinctrl driver
fails to map the irq and spots the following bug:
[ 1.947597] Unable to handle kernel NULL pointer dereference at virtual address 0000000000000004
[ 1.956404] Mem abort info:
[ 1.959203] ESR = 0x96000004
[ 1.962259] EC = 0x25: DABT (current EL), IL = 32 bits
[ 1.967565] SET = 0, FnV = 0
[ 1.970613] EA = 0, S1PTW = 0
[ 1.973747] Data abort info:
[ 1.976619] ISV = 0, ISS = 0x00000004
[ 1.980447] CM = 0, WnR = 0
[ 1.983410] [0000000000000004] user address but active_mm is swapper
[ 1.989759] Internal error: Oops: 96000004 [#1] PREEMPT SMP
[ 1.995322] Modules linked in:
[ 1.998371] CPU: 7 PID: 1 Comm: swapper/0 Not tainted 5.9.0-rc1+ #44
[ 2.004715] Hardware name: MediaTek krane sku176 board (DT)
[ 2.010280] pstate: 60000005 (nZCv daif -PAN -UAO BTYPE=--)
[ 2.015850] pc : mtk_eint_set_debounce+0x48/0x1b8
[ 2.020546] lr : mtk_eint_set_debounce+0x34/0x1b8
[ 2.025239] sp : ffff80001008baa0
[ 2.028544] x29: ffff80001008baa0 x28: ffff0000ff7ff790
[ 2.033847] x27: ffff0000f9ec34b0 x26: ffff0000f9ec3480
[ 2.039150] x25: ffff0000fa576410 x24: ffff0000fa502800
[ 2.044453] x23: 0000000000001388 x22: ffff0000fa635f80
[ 2.049755] x21: 0000000000000008 x20: 0000000000000000
[ 2.055058] x19: 0000000000000071 x18: 0000000000000001
[ 2.060360] x17: 0000000000000000 x16: 0000000000000000
[ 2.065662] x15: ffff0000facc8470 x14: ffffffffffffffff
[ 2.070965] x13: 0000000000000001 x12: 00000000000000c0
[ 2.076267] x11: 0000000000000040 x10: 0000000000000070
[ 2.081569] x9 : ffffaec0063d24d8 x8 : ffff0000fa800270
[ 2.086872] x7 : 0000000000000000 x6 : 0000000000000011
[ 2.092174] x5 : ffff0000fa800248 x4 : ffff0000fa800270
[ 2.097476] x3 : ffff8000100c5000 x2 : 0000000000000000
[ 2.102778] x1 : 0000000000000000 x0 : 0000000000000000
[ 2.108081] Call trace:
[ 2.110520] mtk_eint_set_debounce+0x48/0x1b8
[ 2.114870] mtk_gpio_set_config+0x5c/0x78
[ 2.118958] gpiod_set_config+0x5c/0x78
[ 2.122786] gpiod_set_debounce+0x18/0x28
[ 2.126789] gpio_keys_probe+0x50c/0x910
[ 2.130705] platform_drv_probe+0x54/0xa8
[ 2.134705] really_probe+0xe4/0x3b0
[ 2.138271] driver_probe_device+0x58/0xb8
[ 2.142358] device_driver_attach+0x74/0x80
[ 2.146532] __driver_attach+0x58/0xe0
[ 2.150274] bus_for_each_dev+0x70/0xc0
[ 2.154100] driver_attach+0x24/0x30
[ 2.157666] bus_add_driver+0x14c/0x1f0
[ 2.161493] driver_register+0x64/0x120
[ 2.165319] __platform_driver_register+0x48/0x58
[ 2.170017] gpio_keys_init+0x1c/0x28
[ 2.173672] do_one_initcall+0x54/0x1b4
[ 2.177499] kernel_init_freeable+0x1d0/0x238
[ 2.181848] kernel_init+0x14/0x118
[ 2.185328] ret_from_fork+0x10/0x34
[ 2.188899] Code: a9438ac1 12001266 f94006c3 121e766a (b9400421)
[ 2.194991] ---[ end trace 168cf7b3324b6570 ]---
[ 2.199611] Kernel panic - not syncing: Attempted to kill init! exitcode=0x0000000b
[ 2.207260] SMP: stopping secondary CPUs
[ 2.211294] Kernel Offset: 0x2ebff4800000 from 0xffff800010000000
[ 2.217377] PHYS_OFFSET: 0xffffb50500000000
[ 2.221551] CPU features: 0x0240002,2188200c
[ 2.225811] Memory Limit: none
[ 2.228860] ---[ end Kernel panic - not syncing: Attempted to kill init! exitcode=0x0000000b ]---
Fixes: 89132dd8ffd2 ("pinctrl: mediatek: extend eint build to pinctrl-mtk-common-v2.c")
Signed-off-by: Enric Balletbo i Serra <enric.balletbo@collabora.com>
Acked-by: Sean Wang <sean.wang@kernel.org>
Link: https://lore.kernel.org/r/20201001142511.3560143-1-enric.balletbo@collabora.com
[rebased on changed infrastructure]
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
2020-10-01 22:25:11 +08:00
|
|
|
int ret;
|
2018-09-08 19:07:37 +08:00
|
|
|
|
|
|
|
if (!IS_ENABLED(CONFIG_EINT_MTK))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (!of_property_read_bool(np, "interrupt-controller"))
|
|
|
|
return -ENODEV;
|
|
|
|
|
|
|
|
hw->eint = devm_kzalloc(hw->dev, sizeof(*hw->eint), GFP_KERNEL);
|
|
|
|
if (!hw->eint)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
2020-09-17 14:41:51 +08:00
|
|
|
hw->eint->base = devm_platform_ioremap_resource_byname(pdev, "eint");
|
pinctrl: mediatek: Free eint data on failure
The pinctrl driver can work without the EINT resource, but, if it is
expected to have this resource but the mtk_build_eint() function fails
after allocating their data (because can't get the resource or can't map
the irq), the data is not freed and you end with a NULL pointer
dereference. Fix this by freeing the data if mtk_build_eint() fails, so
pinctrl still works and doesn't hang.
This is noticeable after commit f97dbf48ca43 ("irqchip/mtk-sysirq: Convert
to a platform driver") on MT8183 because, due this commit, the pinctrl driver
fails to map the irq and spots the following bug:
[ 1.947597] Unable to handle kernel NULL pointer dereference at virtual address 0000000000000004
[ 1.956404] Mem abort info:
[ 1.959203] ESR = 0x96000004
[ 1.962259] EC = 0x25: DABT (current EL), IL = 32 bits
[ 1.967565] SET = 0, FnV = 0
[ 1.970613] EA = 0, S1PTW = 0
[ 1.973747] Data abort info:
[ 1.976619] ISV = 0, ISS = 0x00000004
[ 1.980447] CM = 0, WnR = 0
[ 1.983410] [0000000000000004] user address but active_mm is swapper
[ 1.989759] Internal error: Oops: 96000004 [#1] PREEMPT SMP
[ 1.995322] Modules linked in:
[ 1.998371] CPU: 7 PID: 1 Comm: swapper/0 Not tainted 5.9.0-rc1+ #44
[ 2.004715] Hardware name: MediaTek krane sku176 board (DT)
[ 2.010280] pstate: 60000005 (nZCv daif -PAN -UAO BTYPE=--)
[ 2.015850] pc : mtk_eint_set_debounce+0x48/0x1b8
[ 2.020546] lr : mtk_eint_set_debounce+0x34/0x1b8
[ 2.025239] sp : ffff80001008baa0
[ 2.028544] x29: ffff80001008baa0 x28: ffff0000ff7ff790
[ 2.033847] x27: ffff0000f9ec34b0 x26: ffff0000f9ec3480
[ 2.039150] x25: ffff0000fa576410 x24: ffff0000fa502800
[ 2.044453] x23: 0000000000001388 x22: ffff0000fa635f80
[ 2.049755] x21: 0000000000000008 x20: 0000000000000000
[ 2.055058] x19: 0000000000000071 x18: 0000000000000001
[ 2.060360] x17: 0000000000000000 x16: 0000000000000000
[ 2.065662] x15: ffff0000facc8470 x14: ffffffffffffffff
[ 2.070965] x13: 0000000000000001 x12: 00000000000000c0
[ 2.076267] x11: 0000000000000040 x10: 0000000000000070
[ 2.081569] x9 : ffffaec0063d24d8 x8 : ffff0000fa800270
[ 2.086872] x7 : 0000000000000000 x6 : 0000000000000011
[ 2.092174] x5 : ffff0000fa800248 x4 : ffff0000fa800270
[ 2.097476] x3 : ffff8000100c5000 x2 : 0000000000000000
[ 2.102778] x1 : 0000000000000000 x0 : 0000000000000000
[ 2.108081] Call trace:
[ 2.110520] mtk_eint_set_debounce+0x48/0x1b8
[ 2.114870] mtk_gpio_set_config+0x5c/0x78
[ 2.118958] gpiod_set_config+0x5c/0x78
[ 2.122786] gpiod_set_debounce+0x18/0x28
[ 2.126789] gpio_keys_probe+0x50c/0x910
[ 2.130705] platform_drv_probe+0x54/0xa8
[ 2.134705] really_probe+0xe4/0x3b0
[ 2.138271] driver_probe_device+0x58/0xb8
[ 2.142358] device_driver_attach+0x74/0x80
[ 2.146532] __driver_attach+0x58/0xe0
[ 2.150274] bus_for_each_dev+0x70/0xc0
[ 2.154100] driver_attach+0x24/0x30
[ 2.157666] bus_add_driver+0x14c/0x1f0
[ 2.161493] driver_register+0x64/0x120
[ 2.165319] __platform_driver_register+0x48/0x58
[ 2.170017] gpio_keys_init+0x1c/0x28
[ 2.173672] do_one_initcall+0x54/0x1b4
[ 2.177499] kernel_init_freeable+0x1d0/0x238
[ 2.181848] kernel_init+0x14/0x118
[ 2.185328] ret_from_fork+0x10/0x34
[ 2.188899] Code: a9438ac1 12001266 f94006c3 121e766a (b9400421)
[ 2.194991] ---[ end trace 168cf7b3324b6570 ]---
[ 2.199611] Kernel panic - not syncing: Attempted to kill init! exitcode=0x0000000b
[ 2.207260] SMP: stopping secondary CPUs
[ 2.211294] Kernel Offset: 0x2ebff4800000 from 0xffff800010000000
[ 2.217377] PHYS_OFFSET: 0xffffb50500000000
[ 2.221551] CPU features: 0x0240002,2188200c
[ 2.225811] Memory Limit: none
[ 2.228860] ---[ end Kernel panic - not syncing: Attempted to kill init! exitcode=0x0000000b ]---
Fixes: 89132dd8ffd2 ("pinctrl: mediatek: extend eint build to pinctrl-mtk-common-v2.c")
Signed-off-by: Enric Balletbo i Serra <enric.balletbo@collabora.com>
Acked-by: Sean Wang <sean.wang@kernel.org>
Link: https://lore.kernel.org/r/20201001142511.3560143-1-enric.balletbo@collabora.com
[rebased on changed infrastructure]
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
2020-10-01 22:25:11 +08:00
|
|
|
if (IS_ERR(hw->eint->base)) {
|
|
|
|
ret = PTR_ERR(hw->eint->base);
|
|
|
|
goto err_free_eint;
|
2018-09-08 19:07:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
hw->eint->irq = irq_of_parse_and_map(np, 0);
|
pinctrl: mediatek: Free eint data on failure
The pinctrl driver can work without the EINT resource, but, if it is
expected to have this resource but the mtk_build_eint() function fails
after allocating their data (because can't get the resource or can't map
the irq), the data is not freed and you end with a NULL pointer
dereference. Fix this by freeing the data if mtk_build_eint() fails, so
pinctrl still works and doesn't hang.
This is noticeable after commit f97dbf48ca43 ("irqchip/mtk-sysirq: Convert
to a platform driver") on MT8183 because, due this commit, the pinctrl driver
fails to map the irq and spots the following bug:
[ 1.947597] Unable to handle kernel NULL pointer dereference at virtual address 0000000000000004
[ 1.956404] Mem abort info:
[ 1.959203] ESR = 0x96000004
[ 1.962259] EC = 0x25: DABT (current EL), IL = 32 bits
[ 1.967565] SET = 0, FnV = 0
[ 1.970613] EA = 0, S1PTW = 0
[ 1.973747] Data abort info:
[ 1.976619] ISV = 0, ISS = 0x00000004
[ 1.980447] CM = 0, WnR = 0
[ 1.983410] [0000000000000004] user address but active_mm is swapper
[ 1.989759] Internal error: Oops: 96000004 [#1] PREEMPT SMP
[ 1.995322] Modules linked in:
[ 1.998371] CPU: 7 PID: 1 Comm: swapper/0 Not tainted 5.9.0-rc1+ #44
[ 2.004715] Hardware name: MediaTek krane sku176 board (DT)
[ 2.010280] pstate: 60000005 (nZCv daif -PAN -UAO BTYPE=--)
[ 2.015850] pc : mtk_eint_set_debounce+0x48/0x1b8
[ 2.020546] lr : mtk_eint_set_debounce+0x34/0x1b8
[ 2.025239] sp : ffff80001008baa0
[ 2.028544] x29: ffff80001008baa0 x28: ffff0000ff7ff790
[ 2.033847] x27: ffff0000f9ec34b0 x26: ffff0000f9ec3480
[ 2.039150] x25: ffff0000fa576410 x24: ffff0000fa502800
[ 2.044453] x23: 0000000000001388 x22: ffff0000fa635f80
[ 2.049755] x21: 0000000000000008 x20: 0000000000000000
[ 2.055058] x19: 0000000000000071 x18: 0000000000000001
[ 2.060360] x17: 0000000000000000 x16: 0000000000000000
[ 2.065662] x15: ffff0000facc8470 x14: ffffffffffffffff
[ 2.070965] x13: 0000000000000001 x12: 00000000000000c0
[ 2.076267] x11: 0000000000000040 x10: 0000000000000070
[ 2.081569] x9 : ffffaec0063d24d8 x8 : ffff0000fa800270
[ 2.086872] x7 : 0000000000000000 x6 : 0000000000000011
[ 2.092174] x5 : ffff0000fa800248 x4 : ffff0000fa800270
[ 2.097476] x3 : ffff8000100c5000 x2 : 0000000000000000
[ 2.102778] x1 : 0000000000000000 x0 : 0000000000000000
[ 2.108081] Call trace:
[ 2.110520] mtk_eint_set_debounce+0x48/0x1b8
[ 2.114870] mtk_gpio_set_config+0x5c/0x78
[ 2.118958] gpiod_set_config+0x5c/0x78
[ 2.122786] gpiod_set_debounce+0x18/0x28
[ 2.126789] gpio_keys_probe+0x50c/0x910
[ 2.130705] platform_drv_probe+0x54/0xa8
[ 2.134705] really_probe+0xe4/0x3b0
[ 2.138271] driver_probe_device+0x58/0xb8
[ 2.142358] device_driver_attach+0x74/0x80
[ 2.146532] __driver_attach+0x58/0xe0
[ 2.150274] bus_for_each_dev+0x70/0xc0
[ 2.154100] driver_attach+0x24/0x30
[ 2.157666] bus_add_driver+0x14c/0x1f0
[ 2.161493] driver_register+0x64/0x120
[ 2.165319] __platform_driver_register+0x48/0x58
[ 2.170017] gpio_keys_init+0x1c/0x28
[ 2.173672] do_one_initcall+0x54/0x1b4
[ 2.177499] kernel_init_freeable+0x1d0/0x238
[ 2.181848] kernel_init+0x14/0x118
[ 2.185328] ret_from_fork+0x10/0x34
[ 2.188899] Code: a9438ac1 12001266 f94006c3 121e766a (b9400421)
[ 2.194991] ---[ end trace 168cf7b3324b6570 ]---
[ 2.199611] Kernel panic - not syncing: Attempted to kill init! exitcode=0x0000000b
[ 2.207260] SMP: stopping secondary CPUs
[ 2.211294] Kernel Offset: 0x2ebff4800000 from 0xffff800010000000
[ 2.217377] PHYS_OFFSET: 0xffffb50500000000
[ 2.221551] CPU features: 0x0240002,2188200c
[ 2.225811] Memory Limit: none
[ 2.228860] ---[ end Kernel panic - not syncing: Attempted to kill init! exitcode=0x0000000b ]---
Fixes: 89132dd8ffd2 ("pinctrl: mediatek: extend eint build to pinctrl-mtk-common-v2.c")
Signed-off-by: Enric Balletbo i Serra <enric.balletbo@collabora.com>
Acked-by: Sean Wang <sean.wang@kernel.org>
Link: https://lore.kernel.org/r/20201001142511.3560143-1-enric.balletbo@collabora.com
[rebased on changed infrastructure]
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
2020-10-01 22:25:11 +08:00
|
|
|
if (!hw->eint->irq) {
|
|
|
|
ret = -EINVAL;
|
|
|
|
goto err_free_eint;
|
|
|
|
}
|
2018-09-08 19:07:37 +08:00
|
|
|
|
pinctrl: mediatek: Free eint data on failure
The pinctrl driver can work without the EINT resource, but, if it is
expected to have this resource but the mtk_build_eint() function fails
after allocating their data (because can't get the resource or can't map
the irq), the data is not freed and you end with a NULL pointer
dereference. Fix this by freeing the data if mtk_build_eint() fails, so
pinctrl still works and doesn't hang.
This is noticeable after commit f97dbf48ca43 ("irqchip/mtk-sysirq: Convert
to a platform driver") on MT8183 because, due this commit, the pinctrl driver
fails to map the irq and spots the following bug:
[ 1.947597] Unable to handle kernel NULL pointer dereference at virtual address 0000000000000004
[ 1.956404] Mem abort info:
[ 1.959203] ESR = 0x96000004
[ 1.962259] EC = 0x25: DABT (current EL), IL = 32 bits
[ 1.967565] SET = 0, FnV = 0
[ 1.970613] EA = 0, S1PTW = 0
[ 1.973747] Data abort info:
[ 1.976619] ISV = 0, ISS = 0x00000004
[ 1.980447] CM = 0, WnR = 0
[ 1.983410] [0000000000000004] user address but active_mm is swapper
[ 1.989759] Internal error: Oops: 96000004 [#1] PREEMPT SMP
[ 1.995322] Modules linked in:
[ 1.998371] CPU: 7 PID: 1 Comm: swapper/0 Not tainted 5.9.0-rc1+ #44
[ 2.004715] Hardware name: MediaTek krane sku176 board (DT)
[ 2.010280] pstate: 60000005 (nZCv daif -PAN -UAO BTYPE=--)
[ 2.015850] pc : mtk_eint_set_debounce+0x48/0x1b8
[ 2.020546] lr : mtk_eint_set_debounce+0x34/0x1b8
[ 2.025239] sp : ffff80001008baa0
[ 2.028544] x29: ffff80001008baa0 x28: ffff0000ff7ff790
[ 2.033847] x27: ffff0000f9ec34b0 x26: ffff0000f9ec3480
[ 2.039150] x25: ffff0000fa576410 x24: ffff0000fa502800
[ 2.044453] x23: 0000000000001388 x22: ffff0000fa635f80
[ 2.049755] x21: 0000000000000008 x20: 0000000000000000
[ 2.055058] x19: 0000000000000071 x18: 0000000000000001
[ 2.060360] x17: 0000000000000000 x16: 0000000000000000
[ 2.065662] x15: ffff0000facc8470 x14: ffffffffffffffff
[ 2.070965] x13: 0000000000000001 x12: 00000000000000c0
[ 2.076267] x11: 0000000000000040 x10: 0000000000000070
[ 2.081569] x9 : ffffaec0063d24d8 x8 : ffff0000fa800270
[ 2.086872] x7 : 0000000000000000 x6 : 0000000000000011
[ 2.092174] x5 : ffff0000fa800248 x4 : ffff0000fa800270
[ 2.097476] x3 : ffff8000100c5000 x2 : 0000000000000000
[ 2.102778] x1 : 0000000000000000 x0 : 0000000000000000
[ 2.108081] Call trace:
[ 2.110520] mtk_eint_set_debounce+0x48/0x1b8
[ 2.114870] mtk_gpio_set_config+0x5c/0x78
[ 2.118958] gpiod_set_config+0x5c/0x78
[ 2.122786] gpiod_set_debounce+0x18/0x28
[ 2.126789] gpio_keys_probe+0x50c/0x910
[ 2.130705] platform_drv_probe+0x54/0xa8
[ 2.134705] really_probe+0xe4/0x3b0
[ 2.138271] driver_probe_device+0x58/0xb8
[ 2.142358] device_driver_attach+0x74/0x80
[ 2.146532] __driver_attach+0x58/0xe0
[ 2.150274] bus_for_each_dev+0x70/0xc0
[ 2.154100] driver_attach+0x24/0x30
[ 2.157666] bus_add_driver+0x14c/0x1f0
[ 2.161493] driver_register+0x64/0x120
[ 2.165319] __platform_driver_register+0x48/0x58
[ 2.170017] gpio_keys_init+0x1c/0x28
[ 2.173672] do_one_initcall+0x54/0x1b4
[ 2.177499] kernel_init_freeable+0x1d0/0x238
[ 2.181848] kernel_init+0x14/0x118
[ 2.185328] ret_from_fork+0x10/0x34
[ 2.188899] Code: a9438ac1 12001266 f94006c3 121e766a (b9400421)
[ 2.194991] ---[ end trace 168cf7b3324b6570 ]---
[ 2.199611] Kernel panic - not syncing: Attempted to kill init! exitcode=0x0000000b
[ 2.207260] SMP: stopping secondary CPUs
[ 2.211294] Kernel Offset: 0x2ebff4800000 from 0xffff800010000000
[ 2.217377] PHYS_OFFSET: 0xffffb50500000000
[ 2.221551] CPU features: 0x0240002,2188200c
[ 2.225811] Memory Limit: none
[ 2.228860] ---[ end Kernel panic - not syncing: Attempted to kill init! exitcode=0x0000000b ]---
Fixes: 89132dd8ffd2 ("pinctrl: mediatek: extend eint build to pinctrl-mtk-common-v2.c")
Signed-off-by: Enric Balletbo i Serra <enric.balletbo@collabora.com>
Acked-by: Sean Wang <sean.wang@kernel.org>
Link: https://lore.kernel.org/r/20201001142511.3560143-1-enric.balletbo@collabora.com
[rebased on changed infrastructure]
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
2020-10-01 22:25:11 +08:00
|
|
|
if (!hw->soc->eint_hw) {
|
|
|
|
ret = -ENODEV;
|
|
|
|
goto err_free_eint;
|
|
|
|
}
|
2018-09-08 19:07:37 +08:00
|
|
|
|
|
|
|
hw->eint->dev = &pdev->dev;
|
|
|
|
hw->eint->hw = hw->soc->eint_hw;
|
|
|
|
hw->eint->pctl = hw;
|
|
|
|
hw->eint->gpio_xlate = &mtk_eint_xt;
|
|
|
|
|
|
|
|
return mtk_eint_do_init(hw->eint);
|
pinctrl: mediatek: Free eint data on failure
The pinctrl driver can work without the EINT resource, but, if it is
expected to have this resource but the mtk_build_eint() function fails
after allocating their data (because can't get the resource or can't map
the irq), the data is not freed and you end with a NULL pointer
dereference. Fix this by freeing the data if mtk_build_eint() fails, so
pinctrl still works and doesn't hang.
This is noticeable after commit f97dbf48ca43 ("irqchip/mtk-sysirq: Convert
to a platform driver") on MT8183 because, due this commit, the pinctrl driver
fails to map the irq and spots the following bug:
[ 1.947597] Unable to handle kernel NULL pointer dereference at virtual address 0000000000000004
[ 1.956404] Mem abort info:
[ 1.959203] ESR = 0x96000004
[ 1.962259] EC = 0x25: DABT (current EL), IL = 32 bits
[ 1.967565] SET = 0, FnV = 0
[ 1.970613] EA = 0, S1PTW = 0
[ 1.973747] Data abort info:
[ 1.976619] ISV = 0, ISS = 0x00000004
[ 1.980447] CM = 0, WnR = 0
[ 1.983410] [0000000000000004] user address but active_mm is swapper
[ 1.989759] Internal error: Oops: 96000004 [#1] PREEMPT SMP
[ 1.995322] Modules linked in:
[ 1.998371] CPU: 7 PID: 1 Comm: swapper/0 Not tainted 5.9.0-rc1+ #44
[ 2.004715] Hardware name: MediaTek krane sku176 board (DT)
[ 2.010280] pstate: 60000005 (nZCv daif -PAN -UAO BTYPE=--)
[ 2.015850] pc : mtk_eint_set_debounce+0x48/0x1b8
[ 2.020546] lr : mtk_eint_set_debounce+0x34/0x1b8
[ 2.025239] sp : ffff80001008baa0
[ 2.028544] x29: ffff80001008baa0 x28: ffff0000ff7ff790
[ 2.033847] x27: ffff0000f9ec34b0 x26: ffff0000f9ec3480
[ 2.039150] x25: ffff0000fa576410 x24: ffff0000fa502800
[ 2.044453] x23: 0000000000001388 x22: ffff0000fa635f80
[ 2.049755] x21: 0000000000000008 x20: 0000000000000000
[ 2.055058] x19: 0000000000000071 x18: 0000000000000001
[ 2.060360] x17: 0000000000000000 x16: 0000000000000000
[ 2.065662] x15: ffff0000facc8470 x14: ffffffffffffffff
[ 2.070965] x13: 0000000000000001 x12: 00000000000000c0
[ 2.076267] x11: 0000000000000040 x10: 0000000000000070
[ 2.081569] x9 : ffffaec0063d24d8 x8 : ffff0000fa800270
[ 2.086872] x7 : 0000000000000000 x6 : 0000000000000011
[ 2.092174] x5 : ffff0000fa800248 x4 : ffff0000fa800270
[ 2.097476] x3 : ffff8000100c5000 x2 : 0000000000000000
[ 2.102778] x1 : 0000000000000000 x0 : 0000000000000000
[ 2.108081] Call trace:
[ 2.110520] mtk_eint_set_debounce+0x48/0x1b8
[ 2.114870] mtk_gpio_set_config+0x5c/0x78
[ 2.118958] gpiod_set_config+0x5c/0x78
[ 2.122786] gpiod_set_debounce+0x18/0x28
[ 2.126789] gpio_keys_probe+0x50c/0x910
[ 2.130705] platform_drv_probe+0x54/0xa8
[ 2.134705] really_probe+0xe4/0x3b0
[ 2.138271] driver_probe_device+0x58/0xb8
[ 2.142358] device_driver_attach+0x74/0x80
[ 2.146532] __driver_attach+0x58/0xe0
[ 2.150274] bus_for_each_dev+0x70/0xc0
[ 2.154100] driver_attach+0x24/0x30
[ 2.157666] bus_add_driver+0x14c/0x1f0
[ 2.161493] driver_register+0x64/0x120
[ 2.165319] __platform_driver_register+0x48/0x58
[ 2.170017] gpio_keys_init+0x1c/0x28
[ 2.173672] do_one_initcall+0x54/0x1b4
[ 2.177499] kernel_init_freeable+0x1d0/0x238
[ 2.181848] kernel_init+0x14/0x118
[ 2.185328] ret_from_fork+0x10/0x34
[ 2.188899] Code: a9438ac1 12001266 f94006c3 121e766a (b9400421)
[ 2.194991] ---[ end trace 168cf7b3324b6570 ]---
[ 2.199611] Kernel panic - not syncing: Attempted to kill init! exitcode=0x0000000b
[ 2.207260] SMP: stopping secondary CPUs
[ 2.211294] Kernel Offset: 0x2ebff4800000 from 0xffff800010000000
[ 2.217377] PHYS_OFFSET: 0xffffb50500000000
[ 2.221551] CPU features: 0x0240002,2188200c
[ 2.225811] Memory Limit: none
[ 2.228860] ---[ end Kernel panic - not syncing: Attempted to kill init! exitcode=0x0000000b ]---
Fixes: 89132dd8ffd2 ("pinctrl: mediatek: extend eint build to pinctrl-mtk-common-v2.c")
Signed-off-by: Enric Balletbo i Serra <enric.balletbo@collabora.com>
Acked-by: Sean Wang <sean.wang@kernel.org>
Link: https://lore.kernel.org/r/20201001142511.3560143-1-enric.balletbo@collabora.com
[rebased on changed infrastructure]
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
2020-10-01 22:25:11 +08:00
|
|
|
|
|
|
|
err_free_eint:
|
|
|
|
devm_kfree(hw->dev, hw->eint);
|
|
|
|
hw->eint = NULL;
|
|
|
|
return ret;
|
2018-09-08 19:07:37 +08:00
|
|
|
}
|
2020-04-08 04:08:16 +08:00
|
|
|
EXPORT_SYMBOL_GPL(mtk_build_eint);
|
2018-09-08 19:07:37 +08:00
|
|
|
|
2018-09-08 19:07:27 +08:00
|
|
|
/* Revision 0 */
|
2018-09-08 19:07:24 +08:00
|
|
|
int mtk_pinconf_bias_disable_set(struct mtk_pinctrl *hw,
|
|
|
|
const struct mtk_pin_desc *desc)
|
|
|
|
{
|
|
|
|
int err;
|
|
|
|
|
2018-09-08 19:07:29 +08:00
|
|
|
err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_PU,
|
2018-09-08 19:07:24 +08:00
|
|
|
MTK_DISABLE);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
2018-09-08 19:07:29 +08:00
|
|
|
err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_PD,
|
2018-09-08 19:07:24 +08:00
|
|
|
MTK_DISABLE);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2020-04-08 04:08:16 +08:00
|
|
|
EXPORT_SYMBOL_GPL(mtk_pinconf_bias_disable_set);
|
2018-09-08 19:07:24 +08:00
|
|
|
|
|
|
|
int mtk_pinconf_bias_disable_get(struct mtk_pinctrl *hw,
|
|
|
|
const struct mtk_pin_desc *desc, int *res)
|
|
|
|
{
|
|
|
|
int v, v2;
|
|
|
|
int err;
|
|
|
|
|
2018-09-08 19:07:29 +08:00
|
|
|
err = mtk_hw_get_value(hw, desc, PINCTRL_PIN_REG_PU, &v);
|
2018-09-08 19:07:24 +08:00
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
2018-09-08 19:07:29 +08:00
|
|
|
err = mtk_hw_get_value(hw, desc, PINCTRL_PIN_REG_PD, &v2);
|
2018-09-08 19:07:24 +08:00
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
if (v == MTK_ENABLE || v2 == MTK_ENABLE)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
*res = 1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2020-04-08 04:08:16 +08:00
|
|
|
EXPORT_SYMBOL_GPL(mtk_pinconf_bias_disable_get);
|
2018-09-08 19:07:24 +08:00
|
|
|
|
|
|
|
int mtk_pinconf_bias_set(struct mtk_pinctrl *hw,
|
|
|
|
const struct mtk_pin_desc *desc, bool pullup)
|
|
|
|
{
|
|
|
|
int err, arg;
|
|
|
|
|
|
|
|
arg = pullup ? 1 : 2;
|
|
|
|
|
2018-09-08 19:07:29 +08:00
|
|
|
err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_PU, arg & 1);
|
2018-09-08 19:07:24 +08:00
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
2018-09-08 19:07:29 +08:00
|
|
|
err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_PD,
|
2018-09-08 19:07:24 +08:00
|
|
|
!!(arg & 2));
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2020-04-08 04:08:16 +08:00
|
|
|
EXPORT_SYMBOL_GPL(mtk_pinconf_bias_set);
|
2018-09-08 19:07:24 +08:00
|
|
|
|
|
|
|
int mtk_pinconf_bias_get(struct mtk_pinctrl *hw,
|
|
|
|
const struct mtk_pin_desc *desc, bool pullup, int *res)
|
|
|
|
{
|
|
|
|
int reg, err, v;
|
|
|
|
|
|
|
|
reg = pullup ? PINCTRL_PIN_REG_PU : PINCTRL_PIN_REG_PD;
|
|
|
|
|
2018-09-08 19:07:29 +08:00
|
|
|
err = mtk_hw_get_value(hw, desc, reg, &v);
|
2018-09-08 19:07:24 +08:00
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
if (!v)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
*res = 1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2020-04-08 04:08:16 +08:00
|
|
|
EXPORT_SYMBOL_GPL(mtk_pinconf_bias_get);
|
2018-09-08 19:07:24 +08:00
|
|
|
|
2018-09-08 19:07:27 +08:00
|
|
|
/* Revision 1 */
|
|
|
|
int mtk_pinconf_bias_disable_set_rev1(struct mtk_pinctrl *hw,
|
|
|
|
const struct mtk_pin_desc *desc)
|
|
|
|
{
|
2020-12-10 21:59:02 +08:00
|
|
|
return mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_PULLEN,
|
|
|
|
MTK_DISABLE);
|
2018-09-08 19:07:27 +08:00
|
|
|
}
|
2020-04-08 04:08:16 +08:00
|
|
|
EXPORT_SYMBOL_GPL(mtk_pinconf_bias_disable_set_rev1);
|
2018-09-08 19:07:27 +08:00
|
|
|
|
|
|
|
int mtk_pinconf_bias_disable_get_rev1(struct mtk_pinctrl *hw,
|
|
|
|
const struct mtk_pin_desc *desc, int *res)
|
|
|
|
{
|
|
|
|
int v, err;
|
|
|
|
|
2018-09-08 19:07:29 +08:00
|
|
|
err = mtk_hw_get_value(hw, desc, PINCTRL_PIN_REG_PULLEN, &v);
|
2018-09-08 19:07:27 +08:00
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
if (v == MTK_ENABLE)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
*res = 1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2020-04-08 04:08:16 +08:00
|
|
|
EXPORT_SYMBOL_GPL(mtk_pinconf_bias_disable_get_rev1);
|
2018-09-08 19:07:27 +08:00
|
|
|
|
|
|
|
int mtk_pinconf_bias_set_rev1(struct mtk_pinctrl *hw,
|
|
|
|
const struct mtk_pin_desc *desc, bool pullup)
|
|
|
|
{
|
|
|
|
int err, arg;
|
|
|
|
|
|
|
|
arg = pullup ? MTK_PULLUP : MTK_PULLDOWN;
|
|
|
|
|
2018-09-08 19:07:29 +08:00
|
|
|
err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_PULLEN,
|
2018-09-08 19:07:27 +08:00
|
|
|
MTK_ENABLE);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
2018-09-08 19:07:29 +08:00
|
|
|
err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_PULLSEL, arg);
|
2018-09-08 19:07:27 +08:00
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2020-04-08 04:08:16 +08:00
|
|
|
EXPORT_SYMBOL_GPL(mtk_pinconf_bias_set_rev1);
|
2018-09-08 19:07:27 +08:00
|
|
|
|
|
|
|
int mtk_pinconf_bias_get_rev1(struct mtk_pinctrl *hw,
|
|
|
|
const struct mtk_pin_desc *desc, bool pullup,
|
|
|
|
int *res)
|
|
|
|
{
|
|
|
|
int err, v;
|
|
|
|
|
2018-09-08 19:07:29 +08:00
|
|
|
err = mtk_hw_get_value(hw, desc, PINCTRL_PIN_REG_PULLEN, &v);
|
2018-09-08 19:07:27 +08:00
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
if (v == MTK_DISABLE)
|
|
|
|
return -EINVAL;
|
|
|
|
|
2018-09-08 19:07:29 +08:00
|
|
|
err = mtk_hw_get_value(hw, desc, PINCTRL_PIN_REG_PULLSEL, &v);
|
2018-09-08 19:07:27 +08:00
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
if (pullup ^ (v == MTK_PULLUP))
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
*res = 1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2020-04-08 04:08:16 +08:00
|
|
|
EXPORT_SYMBOL_GPL(mtk_pinconf_bias_get_rev1);
|
2018-09-08 19:07:27 +08:00
|
|
|
|
2020-01-22 14:53:13 +08:00
|
|
|
/* Combo for the following pull register type:
|
|
|
|
* 1. PU + PD
|
|
|
|
* 2. PULLSEL + PULLEN
|
|
|
|
* 3. PUPD + R0 + R1
|
|
|
|
*/
|
|
|
|
static int mtk_pinconf_bias_set_pu_pd(struct mtk_pinctrl *hw,
|
|
|
|
const struct mtk_pin_desc *desc,
|
|
|
|
u32 pullup, u32 arg)
|
|
|
|
{
|
|
|
|
int err, pu, pd;
|
|
|
|
|
|
|
|
if (arg == MTK_DISABLE) {
|
|
|
|
pu = 0;
|
|
|
|
pd = 0;
|
|
|
|
} else if ((arg == MTK_ENABLE) && pullup) {
|
|
|
|
pu = 1;
|
|
|
|
pd = 0;
|
|
|
|
} else if ((arg == MTK_ENABLE) && !pullup) {
|
|
|
|
pu = 0;
|
|
|
|
pd = 1;
|
|
|
|
} else {
|
|
|
|
err = -EINVAL;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_PU, pu);
|
|
|
|
if (err)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_PD, pd);
|
|
|
|
|
|
|
|
out:
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int mtk_pinconf_bias_set_pullsel_pullen(struct mtk_pinctrl *hw,
|
|
|
|
const struct mtk_pin_desc *desc,
|
|
|
|
u32 pullup, u32 arg)
|
|
|
|
{
|
|
|
|
int err, enable;
|
|
|
|
|
|
|
|
if (arg == MTK_DISABLE)
|
|
|
|
enable = 0;
|
|
|
|
else if (arg == MTK_ENABLE)
|
|
|
|
enable = 1;
|
|
|
|
else {
|
|
|
|
err = -EINVAL;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_PULLEN, enable);
|
|
|
|
if (err)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_PULLSEL, pullup);
|
|
|
|
|
|
|
|
out:
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int mtk_pinconf_bias_set_pupd_r1_r0(struct mtk_pinctrl *hw,
|
|
|
|
const struct mtk_pin_desc *desc,
|
|
|
|
u32 pullup, u32 arg)
|
|
|
|
{
|
|
|
|
int err, r0, r1;
|
|
|
|
|
|
|
|
if ((arg == MTK_DISABLE) || (arg == MTK_PUPD_SET_R1R0_00)) {
|
|
|
|
pullup = 0;
|
|
|
|
r0 = 0;
|
|
|
|
r1 = 0;
|
|
|
|
} else if (arg == MTK_PUPD_SET_R1R0_01) {
|
|
|
|
r0 = 1;
|
|
|
|
r1 = 0;
|
|
|
|
} else if (arg == MTK_PUPD_SET_R1R0_10) {
|
|
|
|
r0 = 0;
|
|
|
|
r1 = 1;
|
|
|
|
} else if (arg == MTK_PUPD_SET_R1R0_11) {
|
|
|
|
r0 = 1;
|
|
|
|
r1 = 1;
|
|
|
|
} else {
|
|
|
|
err = -EINVAL;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* MTK HW PUPD bit: 1 for pull-down, 0 for pull-up */
|
|
|
|
err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_PUPD, !pullup);
|
|
|
|
if (err)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_R0, r0);
|
|
|
|
if (err)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_R1, r1);
|
|
|
|
|
|
|
|
out:
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2021-09-24 16:06:31 +08:00
|
|
|
static int mtk_hw_pin_rsel_lookup(struct mtk_pinctrl *hw,
|
|
|
|
const struct mtk_pin_desc *desc,
|
|
|
|
u32 pullup, u32 arg, u32 *rsel_val)
|
|
|
|
{
|
|
|
|
const struct mtk_pin_rsel *rsel;
|
|
|
|
int check;
|
|
|
|
bool found = false;
|
|
|
|
|
|
|
|
rsel = hw->soc->pin_rsel;
|
|
|
|
|
|
|
|
for (check = 0; check <= hw->soc->npin_rsel - 1; check++) {
|
|
|
|
if (desc->number >= rsel[check].s_pin &&
|
|
|
|
desc->number <= rsel[check].e_pin) {
|
|
|
|
if (pullup) {
|
|
|
|
if (rsel[check].up_rsel == arg) {
|
|
|
|
found = true;
|
|
|
|
*rsel_val = rsel[check].rsel_index;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (rsel[check].down_rsel == arg) {
|
|
|
|
found = true;
|
|
|
|
*rsel_val = rsel[check].rsel_index;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!found) {
|
|
|
|
dev_err(hw->dev, "Not support rsel value %d Ohm for pin = %d (%s)\n",
|
|
|
|
arg, desc->number, desc->name);
|
|
|
|
return -ENOTSUPP;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int mtk_pinconf_bias_set_rsel(struct mtk_pinctrl *hw,
|
|
|
|
const struct mtk_pin_desc *desc,
|
|
|
|
u32 pullup, u32 arg)
|
|
|
|
{
|
|
|
|
int err, rsel_val;
|
|
|
|
|
pinctrl: mediatek: common-v2: Fix bias-disable for PULL_PU_PD_RSEL_TYPE
In pinctrl-paris we're calling the .bias_set_combo() callback when we
are asked to set the pin bias to either pull up/down or pull disable.
On newer platforms, this callback is mtk_pinconf_bias_set_combo(),
located in pinctrl-mtk-common-v2.c: this will check the "pull type"
assigned to the requested pin and in case said pin's pull type is
MTK_PULL_PU_PD_RSEL_TYPE, this function will set RSEL first, PUPD
last, which is fine.
The issue comes when we're requesting PIN_CONFIG_BIAS_DISABLE, as
this does *not* require setting RSEL but only PU_PD: in this case,
the arg is MTK_DISABLE (zero), which is not a supported RSEL, due
to which function mtk_pinconf_bias_set_rsel() returns a failure;
because of that, mtk_pinconf_bias_set_pu_pd() is never called,
hence the pin bias is never set to DISABLE.
To fix this issue, add a check to mtk_pinconf_bias_set_rsel(): if
we are entering that function with no pullup requested and at the
same time the arg is MTK_DISABLE, this means that we're trying to
disable pin bias, hence it's safe to return cleanly without ever
setting any RSEL register.
This makes mtk_pinconf_bias_set_combo() happy, going on with setting
the PU_PD registers, which is the only action to actually take to
disable bias on a pin/pingroup.
Fixes: fb34a9ae383a ("pinctrl: mediatek: support rsel feature")
Signed-off-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
Link: https://lore.kernel.org/r/20221104105605.33720-1-angelogioacchino.delregno@collabora.com
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
2022-11-04 18:56:05 +08:00
|
|
|
if (!pullup && arg == MTK_DISABLE)
|
|
|
|
return 0;
|
|
|
|
|
2021-09-24 16:06:31 +08:00
|
|
|
if (hw->rsel_si_unit) {
|
|
|
|
/* find pin rsel_index from pin_rsel array*/
|
|
|
|
err = mtk_hw_pin_rsel_lookup(hw, desc, pullup, arg, &rsel_val);
|
|
|
|
if (err)
|
|
|
|
goto out;
|
|
|
|
} else {
|
|
|
|
if (arg < MTK_PULL_SET_RSEL_000 ||
|
|
|
|
arg > MTK_PULL_SET_RSEL_111) {
|
|
|
|
err = -EINVAL;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
rsel_val = arg - MTK_PULL_SET_RSEL_000;
|
|
|
|
}
|
|
|
|
|
|
|
|
err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_RSEL, rsel_val);
|
|
|
|
if (err)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
err = mtk_pinconf_bias_set_pu_pd(hw, desc, pullup, MTK_ENABLE);
|
|
|
|
|
|
|
|
out:
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
int mtk_pinconf_bias_set_combo(struct mtk_pinctrl *hw,
|
|
|
|
const struct mtk_pin_desc *desc,
|
|
|
|
u32 pullup, u32 arg)
|
|
|
|
{
|
|
|
|
int err = -ENOTSUPP;
|
|
|
|
u32 try_all_type;
|
|
|
|
|
|
|
|
if (hw->soc->pull_type)
|
|
|
|
try_all_type = hw->soc->pull_type[desc->number];
|
|
|
|
else
|
|
|
|
try_all_type = MTK_PULL_TYPE_MASK;
|
|
|
|
|
|
|
|
if (try_all_type & MTK_PULL_RSEL_TYPE) {
|
|
|
|
err = mtk_pinconf_bias_set_rsel(hw, desc, pullup, arg);
|
|
|
|
if (!err)
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (try_all_type & MTK_PULL_PU_PD_TYPE) {
|
|
|
|
err = mtk_pinconf_bias_set_pu_pd(hw, desc, pullup, arg);
|
|
|
|
if (!err)
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (try_all_type & MTK_PULL_PULLSEL_TYPE) {
|
|
|
|
err = mtk_pinconf_bias_set_pullsel_pullen(hw, desc,
|
|
|
|
pullup, arg);
|
|
|
|
if (!err)
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (try_all_type & MTK_PULL_PUPD_R1R0_TYPE)
|
|
|
|
err = mtk_pinconf_bias_set_pupd_r1_r0(hw, desc, pullup, arg);
|
|
|
|
|
|
|
|
if (err)
|
|
|
|
dev_err(hw->dev, "Invalid pull argument\n");
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(mtk_pinconf_bias_set_combo);
|
|
|
|
|
|
|
|
static int mtk_rsel_get_si_unit(struct mtk_pinctrl *hw,
|
|
|
|
const struct mtk_pin_desc *desc,
|
|
|
|
u32 pullup, u32 rsel_val, u32 *si_unit)
|
|
|
|
{
|
|
|
|
const struct mtk_pin_rsel *rsel;
|
|
|
|
int check;
|
|
|
|
|
|
|
|
rsel = hw->soc->pin_rsel;
|
|
|
|
|
|
|
|
for (check = 0; check <= hw->soc->npin_rsel - 1; check++) {
|
|
|
|
if (desc->number >= rsel[check].s_pin &&
|
|
|
|
desc->number <= rsel[check].e_pin) {
|
|
|
|
if (rsel_val == rsel[check].rsel_index) {
|
|
|
|
if (pullup)
|
|
|
|
*si_unit = rsel[check].up_rsel;
|
|
|
|
else
|
|
|
|
*si_unit = rsel[check].down_rsel;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int mtk_pinconf_bias_get_rsel(struct mtk_pinctrl *hw,
|
|
|
|
const struct mtk_pin_desc *desc,
|
|
|
|
u32 *pullup, u32 *enable)
|
|
|
|
{
|
|
|
|
int pu, pd, rsel, err;
|
|
|
|
|
|
|
|
err = mtk_hw_get_value(hw, desc, PINCTRL_PIN_REG_RSEL, &rsel);
|
|
|
|
if (err)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
err = mtk_hw_get_value(hw, desc, PINCTRL_PIN_REG_PU, &pu);
|
|
|
|
if (err)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
err = mtk_hw_get_value(hw, desc, PINCTRL_PIN_REG_PD, &pd);
|
2021-11-27 22:08:36 +08:00
|
|
|
if (err)
|
|
|
|
goto out;
|
2021-09-24 16:06:31 +08:00
|
|
|
|
|
|
|
if (pu == 0 && pd == 0) {
|
|
|
|
*pullup = 0;
|
|
|
|
*enable = MTK_DISABLE;
|
|
|
|
} else if (pu == 1 && pd == 0) {
|
|
|
|
*pullup = 1;
|
|
|
|
if (hw->rsel_si_unit)
|
|
|
|
mtk_rsel_get_si_unit(hw, desc, *pullup, rsel, enable);
|
|
|
|
else
|
|
|
|
*enable = rsel + MTK_PULL_SET_RSEL_000;
|
|
|
|
} else if (pu == 0 && pd == 1) {
|
|
|
|
*pullup = 0;
|
|
|
|
if (hw->rsel_si_unit)
|
|
|
|
mtk_rsel_get_si_unit(hw, desc, *pullup, rsel, enable);
|
|
|
|
else
|
|
|
|
*enable = rsel + MTK_PULL_SET_RSEL_000;
|
|
|
|
} else {
|
|
|
|
err = -EINVAL;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
out:
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2020-01-22 14:53:13 +08:00
|
|
|
static int mtk_pinconf_bias_get_pu_pd(struct mtk_pinctrl *hw,
|
|
|
|
const struct mtk_pin_desc *desc,
|
|
|
|
u32 *pullup, u32 *enable)
|
|
|
|
{
|
|
|
|
int err, pu, pd;
|
|
|
|
|
|
|
|
err = mtk_hw_get_value(hw, desc, PINCTRL_PIN_REG_PU, &pu);
|
|
|
|
if (err)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
err = mtk_hw_get_value(hw, desc, PINCTRL_PIN_REG_PD, &pd);
|
|
|
|
if (err)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
if (pu == 0 && pd == 0) {
|
|
|
|
*pullup = 0;
|
|
|
|
*enable = MTK_DISABLE;
|
|
|
|
} else if (pu == 1 && pd == 0) {
|
|
|
|
*pullup = 1;
|
|
|
|
*enable = MTK_ENABLE;
|
|
|
|
} else if (pu == 0 && pd == 1) {
|
|
|
|
*pullup = 0;
|
|
|
|
*enable = MTK_ENABLE;
|
|
|
|
} else
|
|
|
|
err = -EINVAL;
|
|
|
|
|
|
|
|
out:
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int mtk_pinconf_bias_get_pullsel_pullen(struct mtk_pinctrl *hw,
|
|
|
|
const struct mtk_pin_desc *desc,
|
|
|
|
u32 *pullup, u32 *enable)
|
|
|
|
{
|
|
|
|
int err;
|
|
|
|
|
|
|
|
err = mtk_hw_get_value(hw, desc, PINCTRL_PIN_REG_PULLSEL, pullup);
|
|
|
|
if (err)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
err = mtk_hw_get_value(hw, desc, PINCTRL_PIN_REG_PULLEN, enable);
|
|
|
|
|
|
|
|
out:
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int mtk_pinconf_bias_get_pupd_r1_r0(struct mtk_pinctrl *hw,
|
|
|
|
const struct mtk_pin_desc *desc,
|
|
|
|
u32 *pullup, u32 *enable)
|
|
|
|
{
|
|
|
|
int err, r0, r1;
|
|
|
|
|
|
|
|
err = mtk_hw_get_value(hw, desc, PINCTRL_PIN_REG_PUPD, pullup);
|
|
|
|
if (err)
|
|
|
|
goto out;
|
|
|
|
/* MTK HW PUPD bit: 1 for pull-down, 0 for pull-up */
|
|
|
|
*pullup = !(*pullup);
|
|
|
|
|
|
|
|
err = mtk_hw_get_value(hw, desc, PINCTRL_PIN_REG_R0, &r0);
|
|
|
|
if (err)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
err = mtk_hw_get_value(hw, desc, PINCTRL_PIN_REG_R1, &r1);
|
|
|
|
if (err)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
if ((r1 == 0) && (r0 == 0))
|
|
|
|
*enable = MTK_PUPD_SET_R1R0_00;
|
|
|
|
else if ((r1 == 0) && (r0 == 1))
|
|
|
|
*enable = MTK_PUPD_SET_R1R0_01;
|
|
|
|
else if ((r1 == 1) && (r0 == 0))
|
|
|
|
*enable = MTK_PUPD_SET_R1R0_10;
|
|
|
|
else if ((r1 == 1) && (r0 == 1))
|
|
|
|
*enable = MTK_PUPD_SET_R1R0_11;
|
|
|
|
else
|
|
|
|
err = -EINVAL;
|
|
|
|
|
|
|
|
out:
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
int mtk_pinconf_bias_get_combo(struct mtk_pinctrl *hw,
|
|
|
|
const struct mtk_pin_desc *desc,
|
|
|
|
u32 *pullup, u32 *enable)
|
|
|
|
{
|
2021-09-24 16:06:31 +08:00
|
|
|
int err = -ENOTSUPP;
|
|
|
|
u32 try_all_type;
|
2020-01-22 14:53:13 +08:00
|
|
|
|
2021-09-24 16:06:31 +08:00
|
|
|
if (hw->soc->pull_type)
|
|
|
|
try_all_type = hw->soc->pull_type[desc->number];
|
|
|
|
else
|
|
|
|
try_all_type = MTK_PULL_TYPE_MASK;
|
2020-01-22 14:53:13 +08:00
|
|
|
|
2021-09-24 16:06:31 +08:00
|
|
|
if (try_all_type & MTK_PULL_RSEL_TYPE) {
|
|
|
|
err = mtk_pinconf_bias_get_rsel(hw, desc, pullup, enable);
|
|
|
|
if (!err)
|
|
|
|
return err;
|
|
|
|
}
|
2020-01-22 14:53:13 +08:00
|
|
|
|
2021-09-24 16:06:31 +08:00
|
|
|
if (try_all_type & MTK_PULL_PU_PD_TYPE) {
|
|
|
|
err = mtk_pinconf_bias_get_pu_pd(hw, desc, pullup, enable);
|
|
|
|
if (!err)
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (try_all_type & MTK_PULL_PULLSEL_TYPE) {
|
|
|
|
err = mtk_pinconf_bias_get_pullsel_pullen(hw, desc,
|
|
|
|
pullup, enable);
|
|
|
|
if (!err)
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (try_all_type & MTK_PULL_PUPD_R1R0_TYPE)
|
|
|
|
err = mtk_pinconf_bias_get_pupd_r1_r0(hw, desc, pullup, enable);
|
2020-01-22 14:53:13 +08:00
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
2020-04-08 04:08:16 +08:00
|
|
|
EXPORT_SYMBOL_GPL(mtk_pinconf_bias_get_combo);
|
2020-01-22 14:53:13 +08:00
|
|
|
|
2018-09-08 19:07:22 +08:00
|
|
|
/* Revision 0 */
|
|
|
|
int mtk_pinconf_drive_set(struct mtk_pinctrl *hw,
|
|
|
|
const struct mtk_pin_desc *desc, u32 arg)
|
|
|
|
{
|
|
|
|
const struct mtk_drive_desc *tb;
|
|
|
|
int err = -ENOTSUPP;
|
|
|
|
|
|
|
|
tb = &mtk_drive[desc->drv_n];
|
|
|
|
/* 4mA when (e8, e4) = (0, 0)
|
|
|
|
* 8mA when (e8, e4) = (0, 1)
|
|
|
|
* 12mA when (e8, e4) = (1, 0)
|
|
|
|
* 16mA when (e8, e4) = (1, 1)
|
|
|
|
*/
|
|
|
|
if ((arg >= tb->min && arg <= tb->max) && !(arg % tb->step)) {
|
|
|
|
arg = (arg / tb->step - 1) * tb->scal;
|
2018-09-08 19:07:29 +08:00
|
|
|
err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_E4,
|
2018-09-08 19:07:22 +08:00
|
|
|
arg & 0x1);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
2018-09-08 19:07:29 +08:00
|
|
|
err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_E8,
|
2018-09-08 19:07:22 +08:00
|
|
|
(arg & 0x2) >> 1);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
2020-04-08 04:08:16 +08:00
|
|
|
EXPORT_SYMBOL_GPL(mtk_pinconf_drive_set);
|
2018-09-08 19:07:22 +08:00
|
|
|
|
|
|
|
int mtk_pinconf_drive_get(struct mtk_pinctrl *hw,
|
|
|
|
const struct mtk_pin_desc *desc, int *val)
|
|
|
|
{
|
|
|
|
const struct mtk_drive_desc *tb;
|
|
|
|
int err, val1, val2;
|
|
|
|
|
|
|
|
tb = &mtk_drive[desc->drv_n];
|
|
|
|
|
2018-09-08 19:07:29 +08:00
|
|
|
err = mtk_hw_get_value(hw, desc, PINCTRL_PIN_REG_E4, &val1);
|
2018-09-08 19:07:22 +08:00
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
2018-09-08 19:07:29 +08:00
|
|
|
err = mtk_hw_get_value(hw, desc, PINCTRL_PIN_REG_E8, &val2);
|
2018-09-08 19:07:22 +08:00
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
/* 4mA when (e8, e4) = (0, 0); 8mA when (e8, e4) = (0, 1)
|
|
|
|
* 12mA when (e8, e4) = (1, 0); 16mA when (e8, e4) = (1, 1)
|
|
|
|
*/
|
|
|
|
*val = (((val2 << 1) + val1) / tb->scal + 1) * tb->step;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2020-04-08 04:08:16 +08:00
|
|
|
EXPORT_SYMBOL_GPL(mtk_pinconf_drive_get);
|
2018-09-08 19:07:23 +08:00
|
|
|
|
|
|
|
/* Revision 1 */
|
|
|
|
int mtk_pinconf_drive_set_rev1(struct mtk_pinctrl *hw,
|
|
|
|
const struct mtk_pin_desc *desc, u32 arg)
|
|
|
|
{
|
|
|
|
const struct mtk_drive_desc *tb;
|
|
|
|
int err = -ENOTSUPP;
|
|
|
|
|
|
|
|
tb = &mtk_drive[desc->drv_n];
|
|
|
|
|
|
|
|
if ((arg >= tb->min && arg <= tb->max) && !(arg % tb->step)) {
|
|
|
|
arg = (arg / tb->step - 1) * tb->scal;
|
|
|
|
|
2018-09-08 19:07:29 +08:00
|
|
|
err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_DRV,
|
2018-09-08 19:07:23 +08:00
|
|
|
arg);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
2020-04-08 04:08:16 +08:00
|
|
|
EXPORT_SYMBOL_GPL(mtk_pinconf_drive_set_rev1);
|
2018-09-08 19:07:23 +08:00
|
|
|
|
|
|
|
int mtk_pinconf_drive_get_rev1(struct mtk_pinctrl *hw,
|
|
|
|
const struct mtk_pin_desc *desc, int *val)
|
|
|
|
{
|
|
|
|
const struct mtk_drive_desc *tb;
|
|
|
|
int err, val1;
|
|
|
|
|
|
|
|
tb = &mtk_drive[desc->drv_n];
|
|
|
|
|
2018-09-08 19:07:29 +08:00
|
|
|
err = mtk_hw_get_value(hw, desc, PINCTRL_PIN_REG_DRV, &val1);
|
2018-09-08 19:07:23 +08:00
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
*val = ((val1 & 0x7) / tb->scal + 1) * tb->step;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2020-04-08 04:08:16 +08:00
|
|
|
EXPORT_SYMBOL_GPL(mtk_pinconf_drive_get_rev1);
|
2018-09-08 19:07:25 +08:00
|
|
|
|
pinctrl: mediatek: Supporting driving setting without mapping current to register value
MediaTek's smartphone project actual usage does need to know current value
(in mA) in procedure of finding the best driving setting.
The steps in the procedure is like as follow:
1. set driving setting field in setting register as 0, measure waveform,
perform test, and etc.
2. set driving setting field in setting register as 1, measure waveform,
perform test, and etc.
...
n. set driving setting field in setting register as n-1, measure
waveform, perform test, and etc.
Check the results of steps 1~n and adopt the setting that get best result.
This procedure does need to know the mapping between current to register
value.
Therefore, setting driving without mapping current is more practical for
MediaTek's smartphone usage.
Signed-off-by: Light Hsieh <light.hsieh@mediatek.com>
Link: https://lore.kernel.org/r/1579675994-7001-2-git-send-email-light.hsieh@mediatek.com
Acked-by: Sean Wang <sean.wang@kernel.org>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
2020-01-22 14:53:10 +08:00
|
|
|
int mtk_pinconf_drive_set_raw(struct mtk_pinctrl *hw,
|
|
|
|
const struct mtk_pin_desc *desc, u32 arg)
|
|
|
|
{
|
|
|
|
return mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_DRV, arg);
|
|
|
|
}
|
2020-04-08 04:08:16 +08:00
|
|
|
EXPORT_SYMBOL_GPL(mtk_pinconf_drive_set_raw);
|
pinctrl: mediatek: Supporting driving setting without mapping current to register value
MediaTek's smartphone project actual usage does need to know current value
(in mA) in procedure of finding the best driving setting.
The steps in the procedure is like as follow:
1. set driving setting field in setting register as 0, measure waveform,
perform test, and etc.
2. set driving setting field in setting register as 1, measure waveform,
perform test, and etc.
...
n. set driving setting field in setting register as n-1, measure
waveform, perform test, and etc.
Check the results of steps 1~n and adopt the setting that get best result.
This procedure does need to know the mapping between current to register
value.
Therefore, setting driving without mapping current is more practical for
MediaTek's smartphone usage.
Signed-off-by: Light Hsieh <light.hsieh@mediatek.com>
Link: https://lore.kernel.org/r/1579675994-7001-2-git-send-email-light.hsieh@mediatek.com
Acked-by: Sean Wang <sean.wang@kernel.org>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
2020-01-22 14:53:10 +08:00
|
|
|
|
|
|
|
int mtk_pinconf_drive_get_raw(struct mtk_pinctrl *hw,
|
|
|
|
const struct mtk_pin_desc *desc, int *val)
|
|
|
|
{
|
|
|
|
return mtk_hw_get_value(hw, desc, PINCTRL_PIN_REG_DRV, val);
|
|
|
|
}
|
2020-04-08 04:08:16 +08:00
|
|
|
EXPORT_SYMBOL_GPL(mtk_pinconf_drive_get_raw);
|
pinctrl: mediatek: Supporting driving setting without mapping current to register value
MediaTek's smartphone project actual usage does need to know current value
(in mA) in procedure of finding the best driving setting.
The steps in the procedure is like as follow:
1. set driving setting field in setting register as 0, measure waveform,
perform test, and etc.
2. set driving setting field in setting register as 1, measure waveform,
perform test, and etc.
...
n. set driving setting field in setting register as n-1, measure
waveform, perform test, and etc.
Check the results of steps 1~n and adopt the setting that get best result.
This procedure does need to know the mapping between current to register
value.
Therefore, setting driving without mapping current is more practical for
MediaTek's smartphone usage.
Signed-off-by: Light Hsieh <light.hsieh@mediatek.com>
Link: https://lore.kernel.org/r/1579675994-7001-2-git-send-email-light.hsieh@mediatek.com
Acked-by: Sean Wang <sean.wang@kernel.org>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
2020-01-22 14:53:10 +08:00
|
|
|
|
2018-09-08 19:07:25 +08:00
|
|
|
int mtk_pinconf_adv_pull_set(struct mtk_pinctrl *hw,
|
|
|
|
const struct mtk_pin_desc *desc, bool pullup,
|
|
|
|
u32 arg)
|
|
|
|
{
|
|
|
|
int err;
|
|
|
|
|
|
|
|
/* 10K off & 50K (75K) off, when (R0, R1) = (0, 0);
|
|
|
|
* 10K off & 50K (75K) on, when (R0, R1) = (0, 1);
|
|
|
|
* 10K on & 50K (75K) off, when (R0, R1) = (1, 0);
|
|
|
|
* 10K on & 50K (75K) on, when (R0, R1) = (1, 1)
|
|
|
|
*/
|
2018-09-08 19:07:29 +08:00
|
|
|
err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_R0, arg & 1);
|
2018-09-08 19:07:25 +08:00
|
|
|
if (err)
|
|
|
|
return 0;
|
|
|
|
|
2018-09-08 19:07:29 +08:00
|
|
|
err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_R1,
|
2018-09-08 19:07:25 +08:00
|
|
|
!!(arg & 2));
|
|
|
|
if (err)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
arg = pullup ? 0 : 1;
|
|
|
|
|
2018-09-08 19:07:29 +08:00
|
|
|
err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_PUPD, arg);
|
2018-09-08 19:07:25 +08:00
|
|
|
|
2018-09-08 19:07:35 +08:00
|
|
|
/* If PUPD register is not supported for that pin, let's fallback to
|
|
|
|
* general bias control.
|
|
|
|
*/
|
|
|
|
if (err == -ENOTSUPP) {
|
|
|
|
if (hw->soc->bias_set) {
|
|
|
|
err = hw->soc->bias_set(hw, desc, pullup);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
} else {
|
2021-07-01 16:09:55 +08:00
|
|
|
err = mtk_pinconf_bias_set_rev1(hw, desc, pullup);
|
|
|
|
if (err)
|
|
|
|
err = mtk_pinconf_bias_set(hw, desc, pullup);
|
2018-09-08 19:07:35 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-08 19:07:25 +08:00
|
|
|
return err;
|
|
|
|
}
|
2020-04-08 04:08:16 +08:00
|
|
|
EXPORT_SYMBOL_GPL(mtk_pinconf_adv_pull_set);
|
2018-09-08 19:07:25 +08:00
|
|
|
|
|
|
|
int mtk_pinconf_adv_pull_get(struct mtk_pinctrl *hw,
|
|
|
|
const struct mtk_pin_desc *desc, bool pullup,
|
|
|
|
u32 *val)
|
|
|
|
{
|
|
|
|
u32 t, t2;
|
|
|
|
int err;
|
|
|
|
|
2018-09-08 19:07:29 +08:00
|
|
|
err = mtk_hw_get_value(hw, desc, PINCTRL_PIN_REG_PUPD, &t);
|
2018-09-08 19:07:25 +08:00
|
|
|
|
2018-09-08 19:07:35 +08:00
|
|
|
/* If PUPD register is not supported for that pin, let's fallback to
|
|
|
|
* general bias control.
|
|
|
|
*/
|
|
|
|
if (err == -ENOTSUPP) {
|
|
|
|
if (hw->soc->bias_get) {
|
|
|
|
err = hw->soc->bias_get(hw, desc, pullup, val);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
} else {
|
|
|
|
return -ENOTSUPP;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* t == 0 supposes PULLUP for the customized PULL setup */
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
if (pullup ^ !t)
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
2018-09-08 19:07:25 +08:00
|
|
|
|
2018-09-08 19:07:29 +08:00
|
|
|
err = mtk_hw_get_value(hw, desc, PINCTRL_PIN_REG_R0, &t);
|
2018-09-08 19:07:25 +08:00
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
2018-09-08 19:07:29 +08:00
|
|
|
err = mtk_hw_get_value(hw, desc, PINCTRL_PIN_REG_R1, &t2);
|
2018-09-08 19:07:25 +08:00
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
*val = (t | t2 << 1) & 0x7;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2020-04-08 04:08:16 +08:00
|
|
|
EXPORT_SYMBOL_GPL(mtk_pinconf_adv_pull_get);
|
pinctrl: add drive for I2C related pins on MT8183
This patch provides the advanced drive for I2C used pins on MT8183.
The detail strength specification description of the I2C pin:
When E1=0/E0=0, the strength is 0.125mA.
When E1=0/E0=1, the strength is 0.25mA.
When E1=1/E0=0, the strength is 0.5mA.
When E1=1/E0=1, the strength is 1mA.
For I2C pins, there are existing generic driving setup and the above
specific driving setup. I2C pins can only support 2/4/6/8/10/12/14/16mA
driving adjustment in generic driving setup. But in specific driving
setup, they can support 0.125/0.25/0.5/1mA adjustment.
If we enable specific driving setup for I2C pins,
the existing generic driving setup will be disabled.
For some special features, we need the I2C pins specific driving setup.
The specific driving setup is controlled by E1E0EN.
So we need add extra vendor driving preperty instead of the generic
driving property. We can add "mediatek,drive-strength-adv = <XXX>;"
to describe the specific driving setup property.
"XXX" means the value of E1E0EN. So the valid arguments of
"mediatek,drive-strength-adv" are from 0 to 7.
Signed-off-by: Zhiyong Tao <zhiyong.tao@mediatek.com>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
2019-04-01 11:35:35 +08:00
|
|
|
|
|
|
|
int mtk_pinconf_adv_drive_set(struct mtk_pinctrl *hw,
|
|
|
|
const struct mtk_pin_desc *desc, u32 arg)
|
|
|
|
{
|
|
|
|
int err;
|
|
|
|
int en = arg & 1;
|
|
|
|
int e0 = !!(arg & 2);
|
|
|
|
int e1 = !!(arg & 4);
|
|
|
|
|
|
|
|
err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_DRV_EN, en);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
if (!en)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_DRV_E0, e0);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_DRV_E1, e1);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
2020-04-08 04:08:16 +08:00
|
|
|
EXPORT_SYMBOL_GPL(mtk_pinconf_adv_drive_set);
|
pinctrl: add drive for I2C related pins on MT8183
This patch provides the advanced drive for I2C used pins on MT8183.
The detail strength specification description of the I2C pin:
When E1=0/E0=0, the strength is 0.125mA.
When E1=0/E0=1, the strength is 0.25mA.
When E1=1/E0=0, the strength is 0.5mA.
When E1=1/E0=1, the strength is 1mA.
For I2C pins, there are existing generic driving setup and the above
specific driving setup. I2C pins can only support 2/4/6/8/10/12/14/16mA
driving adjustment in generic driving setup. But in specific driving
setup, they can support 0.125/0.25/0.5/1mA adjustment.
If we enable specific driving setup for I2C pins,
the existing generic driving setup will be disabled.
For some special features, we need the I2C pins specific driving setup.
The specific driving setup is controlled by E1E0EN.
So we need add extra vendor driving preperty instead of the generic
driving property. We can add "mediatek,drive-strength-adv = <XXX>;"
to describe the specific driving setup property.
"XXX" means the value of E1E0EN. So the valid arguments of
"mediatek,drive-strength-adv" are from 0 to 7.
Signed-off-by: Zhiyong Tao <zhiyong.tao@mediatek.com>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
2019-04-01 11:35:35 +08:00
|
|
|
|
|
|
|
int mtk_pinconf_adv_drive_get(struct mtk_pinctrl *hw,
|
|
|
|
const struct mtk_pin_desc *desc, u32 *val)
|
|
|
|
{
|
|
|
|
u32 en, e0, e1;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
err = mtk_hw_get_value(hw, desc, PINCTRL_PIN_REG_DRV_EN, &en);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
err = mtk_hw_get_value(hw, desc, PINCTRL_PIN_REG_DRV_E0, &e0);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
err = mtk_hw_get_value(hw, desc, PINCTRL_PIN_REG_DRV_E1, &e1);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
*val = (en | e0 << 1 | e1 << 2) & 0x7;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2020-04-08 04:08:16 +08:00
|
|
|
EXPORT_SYMBOL_GPL(mtk_pinconf_adv_drive_get);
|
2020-05-05 22:08:40 +08:00
|
|
|
|
2021-04-13 13:57:01 +08:00
|
|
|
int mtk_pinconf_adv_drive_set_raw(struct mtk_pinctrl *hw,
|
|
|
|
const struct mtk_pin_desc *desc, u32 arg)
|
|
|
|
{
|
|
|
|
return mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_DRV_ADV, arg);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(mtk_pinconf_adv_drive_set_raw);
|
|
|
|
|
|
|
|
int mtk_pinconf_adv_drive_get_raw(struct mtk_pinctrl *hw,
|
|
|
|
const struct mtk_pin_desc *desc, u32 *val)
|
|
|
|
{
|
|
|
|
return mtk_hw_get_value(hw, desc, PINCTRL_PIN_REG_DRV_ADV, val);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(mtk_pinconf_adv_drive_get_raw);
|
|
|
|
|
2020-05-05 22:08:40 +08:00
|
|
|
MODULE_LICENSE("GPL v2");
|
|
|
|
MODULE_AUTHOR("Sean Wang <sean.wang@mediatek.com>");
|
|
|
|
MODULE_DESCRIPTION("Pin configuration library module for mediatek SoCs");
|