Skip to content

Commit 86e3ef8

Browse files
Cristina Ciocanlinusw
authored andcommitted
pinctrl: baytrail: Update gpio chip operations
This patch updates the gpio chip implementation in order to interact with the pin control model: the chip contains reference to SOC data and pin/group/community information is retrieved through the SOC reference. Signed-off-by: Cristina Ciocan <cristina.ciocan@intel.com> Acked-by: Mika Westerberg <mika.westerberg@linux.intel.com> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
1 parent c501d0b commit 86e3ef8

File tree

1 file changed

+68
-29
lines changed

1 file changed

+68
-29
lines changed

drivers/pinctrl/intel/pinctrl-baytrail.c

Lines changed: 68 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include <linux/types.h>
2121
#include <linux/bitops.h>
2222
#include <linux/interrupt.h>
23+
#include <linux/gpio.h>
2324
#include <linux/gpio/driver.h>
2425
#include <linux/acpi.h>
2526
#include <linux/platform_device.h>
@@ -1363,44 +1364,45 @@ static void byt_gpio_set(struct gpio_chip *chip, unsigned offset, int value)
13631364
unsigned long flags;
13641365
u32 old_val;
13651366

1366-
raw_spin_lock_irqsave(&vg->lock, flags);
1367+
if (!reg)
1368+
return;
13671369

1370+
raw_spin_lock_irqsave(&vg->lock, flags);
13681371
old_val = readl(reg);
1369-
13701372
if (value)
13711373
writel(old_val | BYT_LEVEL, reg);
13721374
else
13731375
writel(old_val & ~BYT_LEVEL, reg);
1374-
13751376
raw_spin_unlock_irqrestore(&vg->lock, flags);
13761377
}
13771378

1378-
static int byt_gpio_direction_input(struct gpio_chip *chip, unsigned offset)
1379+
static int byt_gpio_get_direction(struct gpio_chip *chip, unsigned int offset)
13791380
{
13801381
struct byt_gpio *vg = gpiochip_get_data(chip);
13811382
void __iomem *reg = byt_gpio_reg(vg, offset, BYT_VAL_REG);
13821383
unsigned long flags;
13831384
u32 value;
13841385

1385-
raw_spin_lock_irqsave(&vg->lock, flags);
1386-
1387-
value = readl(reg) | BYT_DIR_MASK;
1388-
value &= ~BYT_INPUT_EN; /* active low */
1389-
writel(value, reg);
1386+
if (!reg)
1387+
return -EINVAL;
13901388

1389+
raw_spin_lock_irqsave(&vg->lock, flags);
1390+
value = readl(reg);
13911391
raw_spin_unlock_irqrestore(&vg->lock, flags);
13921392

1393-
return 0;
1393+
if (!(value & BYT_OUTPUT_EN))
1394+
return GPIOF_DIR_OUT;
1395+
if (!(value & BYT_INPUT_EN))
1396+
return GPIOF_DIR_IN;
1397+
1398+
return -EINVAL;
13941399
}
13951400

1396-
static int byt_gpio_direction_output(struct gpio_chip *chip,
1397-
unsigned gpio, int value)
1401+
static int byt_gpio_direction_input(struct gpio_chip *chip, unsigned int offset)
13981402
{
13991403
struct byt_gpio *vg = gpiochip_get_data(chip);
1400-
void __iomem *conf_reg = byt_gpio_reg(vg, gpio, BYT_CONF0_REG);
1401-
void __iomem *reg = byt_gpio_reg(vg, gpio, BYT_VAL_REG);
1404+
void __iomem *conf_reg = byt_gpio_reg(vg, offset, BYT_CONF0_REG);
14021405
unsigned long flags;
1403-
u32 reg_val;
14041406

14051407
raw_spin_lock_irqsave(&vg->lock, flags);
14061408

@@ -1413,15 +1415,18 @@ static int byt_gpio_direction_output(struct gpio_chip *chip,
14131415
WARN(readl(conf_reg) & BYT_DIRECT_IRQ_EN,
14141416
"Potential Error: Setting GPIO with direct_irq_en to output");
14151417

1416-
reg_val = readl(reg) | BYT_DIR_MASK;
1417-
reg_val &= ~(BYT_OUTPUT_EN | BYT_INPUT_EN);
1418+
return pinctrl_gpio_direction_input(chip->base + offset);
1419+
}
14181420

1419-
if (value)
1420-
writel(reg_val | BYT_LEVEL, reg);
1421-
else
1422-
writel(reg_val & ~BYT_LEVEL, reg);
1421+
static int byt_gpio_direction_output(struct gpio_chip *chip,
1422+
unsigned int offset, int value)
1423+
{
1424+
int ret = pinctrl_gpio_direction_output(chip->base + offset);
14231425

1424-
raw_spin_unlock_irqrestore(&vg->lock, flags);
1426+
if (ret)
1427+
return ret;
1428+
1429+
byt_gpio_set(chip, offset, value);
14251430

14261431
return 0;
14271432
}
@@ -1430,20 +1435,42 @@ static void byt_gpio_dbg_show(struct seq_file *s, struct gpio_chip *chip)
14301435
{
14311436
struct byt_gpio *vg = gpiochip_get_data(chip);
14321437
int i;
1433-
u32 conf0, val, offs;
1438+
u32 conf0, val;
14341439

1435-
for (i = 0; i < vg->chip.ngpio; i++) {
1440+
for (i = 0; i < vg->soc_data->npins; i++) {
1441+
const struct byt_community *comm;
14361442
const char *pull_str = NULL;
14371443
const char *pull = NULL;
1444+
void __iomem *reg;
14381445
unsigned long flags;
14391446
const char *label;
1440-
offs = vg->range->pins[i] * 16;
1447+
unsigned int pin;
14411448

14421449
raw_spin_lock_irqsave(&vg->lock, flags);
1443-
conf0 = readl(vg->reg_base + offs + BYT_CONF0_REG);
1444-
val = readl(vg->reg_base + offs + BYT_VAL_REG);
1450+
pin = vg->soc_data->pins[i].number;
1451+
reg = byt_gpio_reg(vg, pin, BYT_CONF0_REG);
1452+
if (!reg) {
1453+
seq_printf(s,
1454+
"Could not retrieve pin %i conf0 reg\n",
1455+
pin);
1456+
continue;
1457+
}
1458+
conf0 = readl(reg);
1459+
1460+
reg = byt_gpio_reg(vg, pin, BYT_VAL_REG);
1461+
if (!reg) {
1462+
seq_printf(s,
1463+
"Could not retrieve pin %i val reg\n", pin);
1464+
}
1465+
val = readl(reg);
14451466
raw_spin_unlock_irqrestore(&vg->lock, flags);
14461467

1468+
comm = byt_get_community(vg, pin);
1469+
if (!comm) {
1470+
seq_printf(s,
1471+
"Could not get community for pin %i\n", pin);
1472+
continue;
1473+
}
14471474
label = gpiochip_is_requested(chip, i);
14481475
if (!label)
14491476
label = "Unrequested";
@@ -1474,12 +1501,12 @@ static void byt_gpio_dbg_show(struct seq_file *s, struct gpio_chip *chip)
14741501

14751502
seq_printf(s,
14761503
" gpio-%-3d (%-20.20s) %s %s %s pad-%-3d offset:0x%03x mux:%d %s%s%s",
1477-
i,
1504+
pin,
14781505
label,
14791506
val & BYT_INPUT_EN ? " " : "in",
14801507
val & BYT_OUTPUT_EN ? " " : "out",
14811508
val & BYT_LEVEL ? "hi" : "lo",
1482-
vg->range->pins[i], offs,
1509+
comm->pad_map[i], comm->pad_map[i] * 32,
14831510
conf0 & 0x7,
14841511
conf0 & BYT_TRIG_NEG ? " fall" : " ",
14851512
conf0 & BYT_TRIG_POS ? " rise" : " ",
@@ -1519,6 +1546,18 @@ static void byt_gpio_irq_handler(struct irq_desc *desc)
15191546
chip->irq_eoi(data);
15201547
}
15211548

1549+
static const struct gpio_chip byt_gpio_chip = {
1550+
.owner = THIS_MODULE,
1551+
.request = gpiochip_generic_request,
1552+
.free = gpiochip_generic_free,
1553+
.get_direction = byt_gpio_get_direction,
1554+
.direction_input = byt_gpio_direction_input,
1555+
.direction_output = byt_gpio_direction_output,
1556+
.get = byt_gpio_get,
1557+
.set = byt_gpio_set,
1558+
.dbg_show = byt_gpio_dbg_show,
1559+
};
1560+
15221561
static void byt_irq_ack(struct irq_data *d)
15231562
{
15241563
struct gpio_chip *gc = irq_data_get_irq_chip_data(d);

0 commit comments

Comments
 (0)