Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions drivers/pinctrl/samsung/pinctrl-exynos-arm64.c
Original file line number Diff line number Diff line change
Expand Up @@ -2566,17 +2566,20 @@ static const struct samsung_pin_ctrl zumapro_pin_ctrl[] __initconst = {
/* Controller 0: ALIVE */
.pin_banks = zumapro_pin_alive,
.nr_banks = ARRAY_SIZE(zumapro_pin_alive),
.has_get_direction = true,
.eint_gpio_init = exynos_eint_gpio_init,
.eint_wkup_init = exynos_eint_wkup_init,
}, {
/* Controller 1: CUSTOM */
.pin_banks = zumapro_pin_custom,
.nr_banks = ARRAY_SIZE(zumapro_pin_custom),
.has_get_direction = true,
.eint_wkup_init = exynos_eint_wkup_init,
}, {
/* Controller 2: FAR */
.pin_banks = zumapro_pin_far,
.nr_banks = ARRAY_SIZE(zumapro_pin_far),
.has_get_direction = true,
.eint_wkup_init = exynos_eint_wkup_init,
}, {
/* Controller 3: GSACORE0 */
Expand Down Expand Up @@ -2607,26 +2610,31 @@ static const struct samsung_pin_ctrl zumapro_pin_ctrl[] __initconst = {
/* Controller 8: HSI1 */
.pin_banks = zumapro_pin_hsi1,
.nr_banks = ARRAY_SIZE(zumapro_pin_hsi1),
.has_get_direction = true,
.eint_gpio_init = exynos_eint_gpio_init,
}, {
/* Controller 9: HSI2 */
.pin_banks = zumapro_pin_hsi2,
.nr_banks = ARRAY_SIZE(zumapro_pin_hsi2),
.has_get_direction = true,
.eint_gpio_init = exynos_eint_gpio_init,
}, {
/* Controller 10: HSI2UFS */
.pin_banks = zumapro_pin_hsi2ufs,
.nr_banks = ARRAY_SIZE(zumapro_pin_hsi2ufs),
.has_get_direction = true,
.eint_gpio_init = exynos_eint_gpio_init,
}, {
/* Controller 11: PERIC0 */
.pin_banks = zumapro_pin_peric0,
.nr_banks = ARRAY_SIZE(zumapro_pin_peric0),
.has_get_direction = true,
.eint_gpio_init = exynos_eint_gpio_init,
}, {
/* Controller 12: PERIC1 */
.pin_banks = zumapro_pin_peric1,
.nr_banks = ARRAY_SIZE(zumapro_pin_peric1),
.has_get_direction = true,
.eint_gpio_init = exynos_eint_gpio_init,
},
};
Expand Down
43 changes: 41 additions & 2 deletions drivers/pinctrl/samsung/pinctrl-samsung.c
Original file line number Diff line number Diff line change
Expand Up @@ -1064,6 +1064,42 @@ static int samsung_gpio_set_config(struct gpio_chip *gc, unsigned int offset,
return ret;
}

/* gpiolib gpio_get_direction callback function. */
static int samsung_gpio_get_direction(struct gpio_chip *gc, unsigned int offset)
{
struct samsung_pin_bank *bank = gpiochip_get_data(gc);
const struct samsung_pin_bank_type *type = bank->type;
struct samsung_pinctrl_drv_data *drvdata = bank->drvdata;
void __iomem *reg;
u32 data, mask, shift;
int ret;

reg = bank->pctl_base + bank->pctl_offset
+ type->reg_offset[PINCFG_TYPE_FUNC];
mask = (1 << type->fld_width[PINCFG_TYPE_FUNC]) - 1;
shift = offset * type->fld_width[PINCFG_TYPE_FUNC];
if (shift >= 32) {
/* Some banks have two config registers */
shift -= 32;
reg += 4;
}

ret = clk_enable(drvdata->pclk);
if (ret) {
dev_err(drvdata->dev, "failed to enable clock\n");
return ret;
}

data = (readl(reg) >> shift) & mask;

clk_disable(drvdata->pclk);

if (data == PIN_CON_FUNC_OUTPUT)
return GPIO_LINE_DIRECTION_OUT;

return GPIO_LINE_DIRECTION_IN;
}

static const struct gpio_chip samsung_gpiolib_chip = {
.request = gpiochip_generic_request,
.free = gpiochip_generic_free,
Expand All @@ -1079,7 +1115,8 @@ static const struct gpio_chip samsung_gpiolib_chip = {

/* register the gpiolib interface with the gpiolib subsystem */
static int samsung_gpiolib_register(struct platform_device *pdev,
struct samsung_pinctrl_drv_data *drvdata)
struct samsung_pinctrl_drv_data *drvdata,
const struct samsung_pin_ctrl *ctrl)
{
struct samsung_pin_bank *bank = drvdata->pin_banks;
struct gpio_chip *gc;
Expand All @@ -1095,6 +1132,8 @@ static int samsung_gpiolib_register(struct platform_device *pdev,
gc->parent = &pdev->dev;
gc->fwnode = bank->fwnode;
gc->label = bank->name;
if (ctrl->has_get_direction)
gc->get_direction = samsung_gpio_get_direction;

ret = devm_gpiochip_add_data(&pdev->dev, gc, bank);
if (ret) {
Expand Down Expand Up @@ -1311,7 +1350,7 @@ static int samsung_pinctrl_probe(struct platform_device *pdev)
else
samsung_pud_value_init(drvdata);

ret = samsung_gpiolib_register(pdev, drvdata);
ret = samsung_gpiolib_register(pdev, drvdata, ctrl);
if (ret)
goto err_unregister;

Expand Down
2 changes: 2 additions & 0 deletions drivers/pinctrl/samsung/pinctrl-samsung.h
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ struct samsung_retention_data {
* @pin_banks: list of pin banks included in this controller.
* @nr_banks: number of pin banks.
* @nr_ext_resources: number of the extra base address for pin banks.
* @has_get_direction: enable GPIO direction readback for this controller.
* @retention_data: configuration data for retention control.
* @eint_gpio_init: platform specific callback to setup the external gpio
* interrupts for the controller.
Expand All @@ -284,6 +285,7 @@ struct samsung_pin_ctrl {
const struct samsung_pin_bank_data *pin_banks;
unsigned int nr_banks;
unsigned int nr_ext_resources;
bool has_get_direction;
const struct samsung_retention_data *retention_data;

int (*eint_gpio_init)(struct samsung_pinctrl_drv_data *);
Expand Down