Lines Matching +full:reg +full:- +full:offset
1 // SPDX-License-Identifier: GPL-2.0
18 /* the offset for the mapping of global gpio pin to irq */
52 * MSIC has 24 gpios, 16 low voltage (1.2-1.8v) and 8 high voltage (3v).
61 static int msic_gpio_to_ireg(unsigned offset) in msic_gpio_to_ireg() argument
63 if (offset >= MSIC_NUM_GPIO) in msic_gpio_to_ireg()
64 return -EINVAL; in msic_gpio_to_ireg()
66 if (offset < 8) in msic_gpio_to_ireg()
67 return INTEL_MSIC_GPIO0LV0CTLI - offset; in msic_gpio_to_ireg()
68 if (offset < 16) in msic_gpio_to_ireg()
69 return INTEL_MSIC_GPIO1LV0CTLI - offset + 8; in msic_gpio_to_ireg()
70 if (offset < 20) in msic_gpio_to_ireg()
71 return INTEL_MSIC_GPIO0HV0CTLI - offset + 16; in msic_gpio_to_ireg()
73 return INTEL_MSIC_GPIO1HV0CTLI - offset + 20; in msic_gpio_to_ireg()
76 static int msic_gpio_to_oreg(unsigned offset) in msic_gpio_to_oreg() argument
78 if (offset >= MSIC_NUM_GPIO) in msic_gpio_to_oreg()
79 return -EINVAL; in msic_gpio_to_oreg()
81 if (offset < 8) in msic_gpio_to_oreg()
82 return INTEL_MSIC_GPIO0LV0CTLO - offset; in msic_gpio_to_oreg()
83 if (offset < 16) in msic_gpio_to_oreg()
84 return INTEL_MSIC_GPIO1LV0CTLO - offset + 8; in msic_gpio_to_oreg()
85 if (offset < 20) in msic_gpio_to_oreg()
86 return INTEL_MSIC_GPIO0HV0CTLO - offset + 16; in msic_gpio_to_oreg()
88 return INTEL_MSIC_GPIO1HV0CTLO - offset + 20; in msic_gpio_to_oreg()
91 static int msic_gpio_direction_input(struct gpio_chip *chip, unsigned offset) in msic_gpio_direction_input() argument
93 int reg; in msic_gpio_direction_input() local
95 reg = msic_gpio_to_oreg(offset); in msic_gpio_direction_input()
96 if (reg < 0) in msic_gpio_direction_input()
97 return reg; in msic_gpio_direction_input()
99 return intel_msic_reg_update(reg, MSIC_GPIO_DIR_IN, MSIC_GPIO_DIR_MASK); in msic_gpio_direction_input()
103 unsigned offset, int value) in msic_gpio_direction_output() argument
105 int reg; in msic_gpio_direction_output() local
111 reg = msic_gpio_to_oreg(offset); in msic_gpio_direction_output()
112 if (reg < 0) in msic_gpio_direction_output()
113 return reg; in msic_gpio_direction_output()
115 return intel_msic_reg_update(reg, value, mask); in msic_gpio_direction_output()
118 static int msic_gpio_get(struct gpio_chip *chip, unsigned offset) in msic_gpio_get() argument
122 int reg; in msic_gpio_get() local
124 reg = msic_gpio_to_ireg(offset); in msic_gpio_get()
125 if (reg < 0) in msic_gpio_get()
126 return reg; in msic_gpio_get()
128 ret = intel_msic_reg_read(reg, &r); in msic_gpio_get()
135 static void msic_gpio_set(struct gpio_chip *chip, unsigned offset, int value) in msic_gpio_set() argument
137 int reg; in msic_gpio_set() local
139 reg = msic_gpio_to_oreg(offset); in msic_gpio_set()
140 if (reg < 0) in msic_gpio_set()
143 intel_msic_reg_update(reg, !!value , MSIC_GPIO_DOUT_MASK); in msic_gpio_set()
147 * This is called from genirq with mg->buslock locked and
148 * irq_desc->lock held. We can not access the scu bus here, so we
154 u32 gpio = data->irq - mg->irq_base; in msic_irq_type()
156 if (gpio >= mg->chip.ngpio) in msic_irq_type()
157 return -EINVAL; in msic_irq_type()
160 mg->trig_change_mask |= (1 << gpio); in msic_irq_type()
161 mg->trig_type = type; in msic_irq_type()
166 static int msic_gpio_to_irq(struct gpio_chip *chip, unsigned offset) in msic_gpio_to_irq() argument
169 return mg->irq_base + offset; in msic_gpio_to_irq()
175 mutex_lock(&mg->buslock); in msic_bus_lock()
181 int offset; in msic_bus_sync_unlock() local
182 int reg; in msic_bus_sync_unlock() local
186 entire transaction. The irq_desc->lock is dropped before we are in msic_bus_sync_unlock()
188 if (mg->trig_change_mask) { in msic_bus_sync_unlock()
189 offset = __ffs(mg->trig_change_mask); in msic_bus_sync_unlock()
191 reg = msic_gpio_to_ireg(offset); in msic_bus_sync_unlock()
192 if (reg < 0) in msic_bus_sync_unlock()
195 if (mg->trig_type & IRQ_TYPE_EDGE_RISING) in msic_bus_sync_unlock()
197 if (mg->trig_type & IRQ_TYPE_EDGE_FALLING) in msic_bus_sync_unlock()
200 intel_msic_reg_update(reg, trig, MSIC_GPIO_INTCNT_MASK); in msic_bus_sync_unlock()
201 mg->trig_change_mask = 0; in msic_bus_sync_unlock()
204 mutex_unlock(&mg->buslock); in msic_bus_sync_unlock()
213 .name = "MSIC-GPIO",
226 struct intel_msic *msic = pdev_to_intel_msic(mg->pdev); in msic_gpio_irq_handler()
232 for (i = 0; i < (mg->chip.ngpio / BITS_PER_BYTE); i++) { in msic_gpio_irq_handler()
237 generic_handle_irq(mg->irq_base + i * BITS_PER_BYTE + bitnr); in msic_gpio_irq_handler()
239 chip->irq_eoi(data); in msic_gpio_irq_handler()
244 struct device *dev = &pdev->dev; in platform_msic_gpio_probe()
256 if (!pdata || !pdata->gpio_base) { in platform_msic_gpio_probe()
258 return -EINVAL; in platform_msic_gpio_probe()
263 return -ENOMEM; in platform_msic_gpio_probe()
267 mg->pdev = pdev; in platform_msic_gpio_probe()
268 mg->irq = irq; in platform_msic_gpio_probe()
269 mg->irq_base = pdata->gpio_base + MSIC_GPIO_IRQ_OFFSET; in platform_msic_gpio_probe()
270 mg->chip.label = "msic_gpio"; in platform_msic_gpio_probe()
271 mg->chip.direction_input = msic_gpio_direction_input; in platform_msic_gpio_probe()
272 mg->chip.direction_output = msic_gpio_direction_output; in platform_msic_gpio_probe()
273 mg->chip.get = msic_gpio_get; in platform_msic_gpio_probe()
274 mg->chip.set = msic_gpio_set; in platform_msic_gpio_probe()
275 mg->chip.to_irq = msic_gpio_to_irq; in platform_msic_gpio_probe()
276 mg->chip.base = pdata->gpio_base; in platform_msic_gpio_probe()
277 mg->chip.ngpio = MSIC_NUM_GPIO; in platform_msic_gpio_probe()
278 mg->chip.can_sleep = true; in platform_msic_gpio_probe()
279 mg->chip.parent = dev; in platform_msic_gpio_probe()
281 mutex_init(&mg->buslock); in platform_msic_gpio_probe()
283 retval = gpiochip_add_data(&mg->chip, mg); in platform_msic_gpio_probe()
289 for (i = 0; i < mg->chip.ngpio; i++) { in platform_msic_gpio_probe()
290 irq_set_chip_data(i + mg->irq_base, mg); in platform_msic_gpio_probe()
291 irq_set_chip_and_handler(i + mg->irq_base, in platform_msic_gpio_probe()
295 irq_set_chained_handler_and_data(mg->irq, msic_gpio_irq_handler, mg); in platform_msic_gpio_probe()