gpio-exar.c (a976c2951d8f376112361830aa7762beff83a205) | gpio-exar.c (a39f2fe7165647c2cd7bdbebb3d04061035e520f) |
---|---|
1/* 2 * GPIO driver for Exar XR17V35X chip 3 * 4 * Copyright (C) 2015 Sudip Mukherjee <sudip.mukherjee@codethink.co.uk> 5 * 6 * This program is free software; you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License version 2 as 8 * published by the Free Software Foundation. --- 54 unchanged lines hidden (view full) --- 63{ 64 struct exar_gpio_chip *exar_gpio = gpiochip_get_data(chip); 65 int value; 66 67 mutex_lock(&exar_gpio->lock); 68 value = readb(exar_gpio->regs + reg); 69 mutex_unlock(&exar_gpio->lock); 70 | 1/* 2 * GPIO driver for Exar XR17V35X chip 3 * 4 * Copyright (C) 2015 Sudip Mukherjee <sudip.mukherjee@codethink.co.uk> 5 * 6 * This program is free software; you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License version 2 as 8 * published by the Free Software Foundation. --- 54 unchanged lines hidden (view full) --- 63{ 64 struct exar_gpio_chip *exar_gpio = gpiochip_get_data(chip); 65 int value; 66 67 mutex_lock(&exar_gpio->lock); 68 value = readb(exar_gpio->regs + reg); 69 mutex_unlock(&exar_gpio->lock); 70 |
71 return !!value; | 71 return value; |
72} 73 74static int exar_get_direction(struct gpio_chip *chip, unsigned int offset) 75{ 76 unsigned int bank = offset / 8; 77 unsigned int addr; 78 int val; 79 80 addr = bank ? EXAR_OFFSET_MPIOSEL_HI : EXAR_OFFSET_MPIOSEL_LO; | 72} 73 74static int exar_get_direction(struct gpio_chip *chip, unsigned int offset) 75{ 76 unsigned int bank = offset / 8; 77 unsigned int addr; 78 int val; 79 80 addr = bank ? EXAR_OFFSET_MPIOSEL_HI : EXAR_OFFSET_MPIOSEL_LO; |
81 val = exar_get(chip, addr) >> (offset % 8); | 81 val = exar_get(chip, addr) & BIT(offset % 8); |
82 83 return !!val; 84} 85 86static int exar_get_value(struct gpio_chip *chip, unsigned int offset) 87{ 88 unsigned int bank = offset / 8; 89 unsigned int addr; 90 int val; 91 | 82 83 return !!val; 84} 85 86static int exar_get_value(struct gpio_chip *chip, unsigned int offset) 87{ 88 unsigned int bank = offset / 8; 89 unsigned int addr; 90 int val; 91 |
92 addr = bank ? EXAR_OFFSET_MPIOLVL_LO : EXAR_OFFSET_MPIOLVL_HI; 93 val = exar_get(chip, addr) >> (offset % 8); | 92 addr = bank ? EXAR_OFFSET_MPIOLVL_HI : EXAR_OFFSET_MPIOLVL_LO; 93 val = exar_get(chip, addr) & BIT(offset % 8); |
94 95 return !!val; 96} 97 98static void exar_set_value(struct gpio_chip *chip, unsigned int offset, 99 int value) 100{ 101 unsigned int bank = offset / 8; --- 12 unchanged lines hidden (view full) --- 114 115static int exar_direction_input(struct gpio_chip *chip, unsigned int offset) 116{ 117 return exar_set_direction(chip, 1, offset); 118} 119 120static int gpio_exar_probe(struct platform_device *pdev) 121{ | 94 95 return !!val; 96} 97 98static void exar_set_value(struct gpio_chip *chip, unsigned int offset, 99 int value) 100{ 101 unsigned int bank = offset / 8; --- 12 unchanged lines hidden (view full) --- 114 115static int exar_direction_input(struct gpio_chip *chip, unsigned int offset) 116{ 117 return exar_set_direction(chip, 1, offset); 118} 119 120static int gpio_exar_probe(struct platform_device *pdev) 121{ |
122 struct pci_dev *pcidev = platform_get_drvdata(pdev); | 122 struct pci_dev *pcidev = to_pci_dev(pdev->dev.parent); |
123 struct exar_gpio_chip *exar_gpio; 124 void __iomem *p; 125 int index, ret; 126 | 123 struct exar_gpio_chip *exar_gpio; 124 void __iomem *p; 125 int index, ret; 126 |
127 if (pcidev->vendor != PCI_VENDOR_ID_EXAR) 128 return -ENODEV; 129 | |
130 /* 131 * Map the pci device to get the register addresses. 132 * We will need to read and write those registers to control 133 * the GPIO pins. 134 * Using managed functions will save us from unmaping on exit. 135 * As the device is enabled using managed functions by the 136 * UART driver we can also use managed functions here. 137 */ 138 p = pcim_iomap(pcidev, 0, 0); 139 if (!p) 140 return -ENOMEM; 141 | 127 /* 128 * Map the pci device to get the register addresses. 129 * We will need to read and write those registers to control 130 * the GPIO pins. 131 * Using managed functions will save us from unmaping on exit. 132 * As the device is enabled using managed functions by the 133 * UART driver we can also use managed functions here. 134 */ 135 p = pcim_iomap(pcidev, 0, 0); 136 if (!p) 137 return -ENOMEM; 138 |
142 exar_gpio = devm_kzalloc(&pcidev->dev, sizeof(*exar_gpio), GFP_KERNEL); | 139 exar_gpio = devm_kzalloc(&pdev->dev, sizeof(*exar_gpio), GFP_KERNEL); |
143 if (!exar_gpio) 144 return -ENOMEM; 145 146 mutex_init(&exar_gpio->lock); 147 148 index = ida_simple_get(&ida_index, 0, 0, GFP_KERNEL); 149 150 sprintf(exar_gpio->name, "exar_gpio%d", index); --- 4 unchanged lines hidden (view full) --- 155 exar_gpio->gpio_chip.get_direction = exar_get_direction; 156 exar_gpio->gpio_chip.get = exar_get_value; 157 exar_gpio->gpio_chip.set = exar_set_value; 158 exar_gpio->gpio_chip.base = -1; 159 exar_gpio->gpio_chip.ngpio = 16; 160 exar_gpio->regs = p; 161 exar_gpio->index = index; 162 | 140 if (!exar_gpio) 141 return -ENOMEM; 142 143 mutex_init(&exar_gpio->lock); 144 145 index = ida_simple_get(&ida_index, 0, 0, GFP_KERNEL); 146 147 sprintf(exar_gpio->name, "exar_gpio%d", index); --- 4 unchanged lines hidden (view full) --- 152 exar_gpio->gpio_chip.get_direction = exar_get_direction; 153 exar_gpio->gpio_chip.get = exar_get_value; 154 exar_gpio->gpio_chip.set = exar_set_value; 155 exar_gpio->gpio_chip.base = -1; 156 exar_gpio->gpio_chip.ngpio = 16; 157 exar_gpio->regs = p; 158 exar_gpio->index = index; 159 |
163 ret = devm_gpiochip_add_data(&pcidev->dev, | 160 ret = devm_gpiochip_add_data(&pdev->dev, |
164 &exar_gpio->gpio_chip, exar_gpio); 165 if (ret) 166 goto err_destroy; 167 168 platform_set_drvdata(pdev, exar_gpio); 169 170 return 0; 171 --- 30 unchanged lines hidden --- | 161 &exar_gpio->gpio_chip, exar_gpio); 162 if (ret) 163 goto err_destroy; 164 165 platform_set_drvdata(pdev, exar_gpio); 166 167 return 0; 168 --- 30 unchanged lines hidden --- |