1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
|
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (C) 2026 by RISCstar Solutions Corporation. All rights reserved.
*/
/*
* The Toshiba TC9563 implements a PCIe Gen 3 switch that connects an
* upstream x4 port to two downstream PCIe x2 ports. It incorporates
* an internal endpoint on a internal PCIe port that implements two
* Synopsys XGMAC Ethernet interfaces.
*
* 37 GPIOs are also implemented by an embedded GPIO controller. Three
* registers control the first 32 GPIOs (other than 20 and 21, which are
* reserved). Three other registers control GPIOs 32 through 36. GPIOs
* 22-24, 27-28, 31, and 34 are treated as "input only".
*
*/
#include <linux/auxiliary_bus.h>
#include <linux/gpio/driver.h>
#include <linux/gpio/regmap.h>
#include <linux/platform_device.h>
#include <linux/regmap.h>
#include <linux/soc/qcom/tc9563.h>
/*
* There are two sets of registers, each representing (up to) 32 GPIOs with a
* stride of 4 bytes (IN1 is 4 bytes past IN0, EN1 is 4 bytes past EN0, etc.).
*/
#define TC9563_GPIO_COUNT 37
#define TC9563_GPIO_PER_REG 32
#define TC9563_GPIO_REG_STRIDE 4
static int tc9563_gpio_init_valid_mask(struct gpio_chip *gc,
unsigned long *valid_mask,
unsigned int ngpios)
{
/* GPIOs 20 and 21 are reserved */
bitmap_fill(valid_mask, ngpios);
bitmap_clear(valid_mask, 20, 2);
return 0;
}
static int tc9563_gpio_probe(struct auxiliary_device *adev,
const struct auxiliary_device_id *id)
{
struct gpio_regmap_config config = {
.parent = &adev->dev,
.ngpio = TC9563_GPIO_COUNT,
.reg_stride = TC9563_GPIO_REG_STRIDE,
.ngpio_per_reg = TC9563_GPIO_PER_REG,
.reg_dat_base = GPIO_REGMAP_ADDR(TC9563_GPIO_IN0_OFFSET),
.reg_set_base = GPIO_REGMAP_ADDR(TC9563_GPIO_OUT0_OFFSET),
.reg_dir_in_base = GPIO_REGMAP_ADDR(TC9563_GPIO_EN0_OFFSET),
.init_valid_mask = tc9563_gpio_init_valid_mask,
};
DECLARE_BITMAP(fixed_dir_mask, TC9563_GPIO_COUNT);
DECLARE_BITMAP(fixed_dir_out, TC9563_GPIO_COUNT);
config.regmap = dev_get_platdata(&adev->dev);
if (!config.regmap)
return -EINVAL;
/*
* Only some of our GPIOs are fixed direction:
* 22, 23, 24, 27, 28, 31, and 34 are input-only.
*/
bitmap_zero(fixed_dir_mask, TC9563_GPIO_COUNT);
bitmap_set(fixed_dir_mask, 22, 3);
bitmap_set(fixed_dir_mask, 27, 2);
set_bit(31, fixed_dir_mask);
set_bit(34, fixed_dir_mask);
config.fixed_direction_mask = fixed_dir_mask;
bitmap_zero(fixed_dir_out, TC9563_GPIO_COUNT);
config.fixed_direction_output = fixed_dir_out;
return PTR_ERR_OR_ZERO(devm_gpio_regmap_register(&adev->dev, &config));
};
static const struct auxiliary_device_id tc9563_gpio_ids[] = {
{ "pci_pwrctrl_tc9563." TC9563_GPIO_DEV_NAME },
{ /* sentinel */ }
};
MODULE_DEVICE_TABLE(auxiliary, tc9563_gpio_ids);
static struct auxiliary_driver tc9563_gpio_driver = {
.name = TC9563_GPIO_DEV_NAME,
.probe = tc9563_gpio_probe,
.id_table = tc9563_gpio_ids,
};
module_auxiliary_driver(tc9563_gpio_driver);
MODULE_AUTHOR("Alex Elder <elder@riscstar.com>");
MODULE_AUTHOR("Daniel Thompson <daniel@riscstar.com>");
MODULE_AUTHOR("Lorenzo Bianconi <lorenzo.bianconi@oss.qualcomm.com>");
MODULE_DESCRIPTION("Toshiba TC9563 GPIO Driver");
MODULE_LICENSE("GPL");
|