Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

gpio: exar: access MPIO registers on cascaded chips

When EXAR xr17v35x chips are cascaded in order to access the MPIO registers
(part of the Device Configuration Registers) of the secondary chips, an offset
needs to be applied based on the number of primary chip's UART channels.

Signed-off-by: Qingtao Cao <qingtao.cao@digi.com>
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
Signed-off-by: Bartosz Golaszewski <brgl@bgdev.pl>

authored by

Qingtao Cao and committed by
Bartosz Golaszewski
5134272f 0eadd36d

+35 -5
+35 -5
drivers/gpio/gpio-exar.c
··· 21 21 #define EXAR_OFFSET_MPIOLVL_HI 0x96 22 22 #define EXAR_OFFSET_MPIOSEL_HI 0x99 23 23 24 + /* 25 + * The Device Configuration and UART Configuration Registers 26 + * for each UART channel take 1KB of memory address space. 27 + */ 28 + #define EXAR_UART_CHANNEL_SIZE 0x400 29 + 24 30 #define DRIVER_NAME "gpio_exar" 25 31 26 32 static DEFINE_IDA(ida_index); ··· 37 31 int index; 38 32 char name[20]; 39 33 unsigned int first_pin; 34 + /* 35 + * The offset to the cascaded device's (if existing) 36 + * Device Configuration Registers. 37 + */ 38 + unsigned int cascaded_offset; 40 39 }; 41 40 42 41 static unsigned int 43 42 exar_offset_to_sel_addr(struct exar_gpio_chip *exar_gpio, unsigned int offset) 44 43 { 45 - return (offset + exar_gpio->first_pin) / 8 ? EXAR_OFFSET_MPIOSEL_HI 46 - : EXAR_OFFSET_MPIOSEL_LO; 44 + unsigned int pin = exar_gpio->first_pin + (offset % 16); 45 + unsigned int cascaded = offset / 16; 46 + unsigned int addr = pin / 8 ? EXAR_OFFSET_MPIOSEL_HI : EXAR_OFFSET_MPIOSEL_LO; 47 + 48 + return addr + (cascaded ? exar_gpio->cascaded_offset : 0); 47 49 } 48 50 49 51 static unsigned int 50 52 exar_offset_to_lvl_addr(struct exar_gpio_chip *exar_gpio, unsigned int offset) 51 53 { 52 - return (offset + exar_gpio->first_pin) / 8 ? EXAR_OFFSET_MPIOLVL_HI 53 - : EXAR_OFFSET_MPIOLVL_LO; 54 + unsigned int pin = exar_gpio->first_pin + (offset % 16); 55 + unsigned int cascaded = offset / 16; 56 + unsigned int addr = pin / 8 ? EXAR_OFFSET_MPIOLVL_HI : EXAR_OFFSET_MPIOLVL_LO; 57 + 58 + return addr + (cascaded ? exar_gpio->cascaded_offset : 0); 54 59 } 55 60 56 61 static unsigned int 57 62 exar_offset_to_bit(struct exar_gpio_chip *exar_gpio, unsigned int offset) 58 63 { 59 - return (offset + exar_gpio->first_pin) % 8; 64 + unsigned int pin = exar_gpio->first_pin + (offset % 16); 65 + 66 + return pin % 8; 60 67 } 61 68 62 69 static int exar_get_direction(struct gpio_chip *chip, unsigned int offset) ··· 171 152 exar_gpio = devm_kzalloc(dev, sizeof(*exar_gpio), GFP_KERNEL); 172 153 if (!exar_gpio) 173 154 return -ENOMEM; 155 + 156 + /* 157 + * If cascaded, secondary xr17v354 or xr17v358 have the same amount 158 + * of MPIOs as their primaries and the last 4 bits of the primary's 159 + * PCI Device ID is the number of its UART channels. 160 + */ 161 + if (pcidev->device & GENMASK(15, 12)) { 162 + ngpios += ngpios; 163 + exar_gpio->cascaded_offset = (pcidev->device & GENMASK(3, 0)) * 164 + EXAR_UART_CHANNEL_SIZE; 165 + } 174 166 175 167 /* 176 168 * We don't need to check the return values of mmio regmap operations (unless