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;
|
|
|
|
|
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);
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
/* Be greedy to guess first gpio_n is equal to eint_n */
|
|
|
|
if (desc[eint_n].eint.eint_n == eint_n)
|
|
|
|
*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;
|
|
|
|
|
|
|
|
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;
|
|
|
|
struct resource *res;
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "eint");
|
|
|
|
if (!res) {
|
|
|
|
dev_err(&pdev->dev, "Unable to get eint resource\n");
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
|
|
|
hw->eint->base = devm_ioremap_resource(&pdev->dev, res);
|
|
|
|
if (IS_ERR(hw->eint->base))
|
|
|
|
return PTR_ERR(hw->eint->base);
|
|
|
|
|
|
|
|
hw->eint->irq = irq_of_parse_and_map(np, 0);
|
|
|
|
if (!hw->eint->irq)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
if (!hw->soc->eint_hw)
|
|
|
|
return -ENODEV;
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
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)
|
|
|
|
{
|
|
|
|
int err;
|
|
|
|
|
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_DISABLE);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
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_set_combo(struct mtk_pinctrl *hw,
|
|
|
|
const struct mtk_pin_desc *desc,
|
|
|
|
u32 pullup, u32 arg)
|
|
|
|
{
|
|
|
|
int err;
|
|
|
|
|
|
|
|
err = mtk_pinconf_bias_set_pu_pd(hw, desc, pullup, arg);
|
|
|
|
if (!err)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
err = mtk_pinconf_bias_set_pullsel_pullen(hw, desc, pullup, arg);
|
|
|
|
if (!err)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
err = mtk_pinconf_bias_set_pupd_r1_r0(hw, desc, pullup, arg);
|
|
|
|
|
|
|
|
out:
|
|
|
|
return err;
|
|
|
|
}
|
2020-04-08 04:08:16 +08:00
|
|
|
EXPORT_SYMBOL_GPL(mtk_pinconf_bias_set_combo);
|
2020-01-22 14:53:13 +08:00
|
|
|
|
|
|
|
int mtk_pinconf_bias_get_combo(struct mtk_pinctrl *hw,
|
|
|
|
const struct mtk_pin_desc *desc,
|
|
|
|
u32 *pullup, u32 *enable)
|
|
|
|
{
|
|
|
|
int err;
|
|
|
|
|
|
|
|
err = mtk_pinconf_bias_get_pu_pd(hw, desc, pullup, enable);
|
|
|
|
if (!err)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
err = mtk_pinconf_bias_get_pullsel_pullen(hw, desc, pullup, enable);
|
|
|
|
if (!err)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
err = mtk_pinconf_bias_get_pupd_r1_r0(hw, desc, pullup, enable);
|
|
|
|
|
|
|
|
out:
|
|
|
|
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 {
|
|
|
|
return -ENOTSUPP;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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);
|