.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0 |
---|
1 | 2 | /* |
---|
2 | 3 | * Copyright (C) 2011 LAPIS Semiconductor Co., Ltd. |
---|
3 | | - * |
---|
4 | | - * This program is free software; you can redistribute it and/or modify |
---|
5 | | - * it under the terms of the GNU General Public License as published by |
---|
6 | | - * the Free Software Foundation; version 2 of the License. |
---|
7 | | - * |
---|
8 | | - * This program is distributed in the hope that it will be useful, |
---|
9 | | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
10 | | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
11 | | - * GNU General Public License for more details. |
---|
12 | | - * |
---|
13 | | - * You should have received a copy of the GNU General Public License |
---|
14 | | - * along with this program; if not, write to the Free Software |
---|
15 | | - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. |
---|
16 | 4 | */ |
---|
17 | | -#include <linux/module.h> |
---|
18 | | -#include <linux/kernel.h> |
---|
19 | | -#include <linux/pci.h> |
---|
| 5 | +#include <linux/bits.h> |
---|
20 | 6 | #include <linux/gpio/driver.h> |
---|
21 | 7 | #include <linux/interrupt.h> |
---|
22 | 8 | #include <linux/irq.h> |
---|
| 9 | +#include <linux/kernel.h> |
---|
| 10 | +#include <linux/module.h> |
---|
| 11 | +#include <linux/pci.h> |
---|
23 | 12 | #include <linux/slab.h> |
---|
24 | 13 | |
---|
25 | 14 | #define PCH_EDGE_FALLING 0 |
---|
26 | | -#define PCH_EDGE_RISING BIT(0) |
---|
27 | | -#define PCH_LEVEL_L BIT(1) |
---|
28 | | -#define PCH_LEVEL_H (BIT(0) | BIT(1)) |
---|
29 | | -#define PCH_EDGE_BOTH BIT(2) |
---|
30 | | -#define PCH_IM_MASK (BIT(0) | BIT(1) | BIT(2)) |
---|
| 15 | +#define PCH_EDGE_RISING 1 |
---|
| 16 | +#define PCH_LEVEL_L 2 |
---|
| 17 | +#define PCH_LEVEL_H 3 |
---|
| 18 | +#define PCH_EDGE_BOTH 4 |
---|
| 19 | +#define PCH_IM_MASK GENMASK(2, 0) |
---|
31 | 20 | |
---|
32 | 21 | #define PCH_IRQ_BASE 24 |
---|
33 | 22 | |
---|
.. | .. |
---|
106 | 95 | spinlock_t spinlock; |
---|
107 | 96 | }; |
---|
108 | 97 | |
---|
109 | | -static void pch_gpio_set(struct gpio_chip *gpio, unsigned nr, int val) |
---|
| 98 | +static void pch_gpio_set(struct gpio_chip *gpio, unsigned int nr, int val) |
---|
110 | 99 | { |
---|
111 | 100 | u32 reg_val; |
---|
112 | 101 | struct pch_gpio *chip = gpiochip_get_data(gpio); |
---|
.. | .. |
---|
115 | 104 | spin_lock_irqsave(&chip->spinlock, flags); |
---|
116 | 105 | reg_val = ioread32(&chip->reg->po); |
---|
117 | 106 | if (val) |
---|
118 | | - reg_val |= (1 << nr); |
---|
| 107 | + reg_val |= BIT(nr); |
---|
119 | 108 | else |
---|
120 | | - reg_val &= ~(1 << nr); |
---|
| 109 | + reg_val &= ~BIT(nr); |
---|
121 | 110 | |
---|
122 | 111 | iowrite32(reg_val, &chip->reg->po); |
---|
123 | 112 | spin_unlock_irqrestore(&chip->spinlock, flags); |
---|
124 | 113 | } |
---|
125 | 114 | |
---|
126 | | -static int pch_gpio_get(struct gpio_chip *gpio, unsigned nr) |
---|
| 115 | +static int pch_gpio_get(struct gpio_chip *gpio, unsigned int nr) |
---|
127 | 116 | { |
---|
128 | 117 | struct pch_gpio *chip = gpiochip_get_data(gpio); |
---|
129 | 118 | |
---|
130 | | - return (ioread32(&chip->reg->pi) >> nr) & 1; |
---|
| 119 | + return !!(ioread32(&chip->reg->pi) & BIT(nr)); |
---|
131 | 120 | } |
---|
132 | 121 | |
---|
133 | | -static int pch_gpio_direction_output(struct gpio_chip *gpio, unsigned nr, |
---|
| 122 | +static int pch_gpio_direction_output(struct gpio_chip *gpio, unsigned int nr, |
---|
134 | 123 | int val) |
---|
135 | 124 | { |
---|
136 | 125 | struct pch_gpio *chip = gpiochip_get_data(gpio); |
---|
.. | .. |
---|
142 | 131 | |
---|
143 | 132 | reg_val = ioread32(&chip->reg->po); |
---|
144 | 133 | if (val) |
---|
145 | | - reg_val |= (1 << nr); |
---|
| 134 | + reg_val |= BIT(nr); |
---|
146 | 135 | else |
---|
147 | | - reg_val &= ~(1 << nr); |
---|
| 136 | + reg_val &= ~BIT(nr); |
---|
148 | 137 | iowrite32(reg_val, &chip->reg->po); |
---|
149 | 138 | |
---|
150 | | - pm = ioread32(&chip->reg->pm) & ((1 << gpio_pins[chip->ioh]) - 1); |
---|
151 | | - pm |= (1 << nr); |
---|
| 139 | + pm = ioread32(&chip->reg->pm); |
---|
| 140 | + pm &= BIT(gpio_pins[chip->ioh]) - 1; |
---|
| 141 | + pm |= BIT(nr); |
---|
152 | 142 | iowrite32(pm, &chip->reg->pm); |
---|
153 | 143 | |
---|
154 | 144 | spin_unlock_irqrestore(&chip->spinlock, flags); |
---|
.. | .. |
---|
156 | 146 | return 0; |
---|
157 | 147 | } |
---|
158 | 148 | |
---|
159 | | -static int pch_gpio_direction_input(struct gpio_chip *gpio, unsigned nr) |
---|
| 149 | +static int pch_gpio_direction_input(struct gpio_chip *gpio, unsigned int nr) |
---|
160 | 150 | { |
---|
161 | 151 | struct pch_gpio *chip = gpiochip_get_data(gpio); |
---|
162 | 152 | u32 pm; |
---|
163 | 153 | unsigned long flags; |
---|
164 | 154 | |
---|
165 | 155 | spin_lock_irqsave(&chip->spinlock, flags); |
---|
166 | | - pm = ioread32(&chip->reg->pm) & ((1 << gpio_pins[chip->ioh]) - 1); |
---|
167 | | - pm &= ~(1 << nr); |
---|
| 156 | + pm = ioread32(&chip->reg->pm); |
---|
| 157 | + pm &= BIT(gpio_pins[chip->ioh]) - 1; |
---|
| 158 | + pm &= ~BIT(nr); |
---|
168 | 159 | iowrite32(pm, &chip->reg->pm); |
---|
169 | 160 | spin_unlock_irqrestore(&chip->spinlock, flags); |
---|
170 | 161 | |
---|
171 | 162 | return 0; |
---|
172 | 163 | } |
---|
173 | 164 | |
---|
174 | | -#ifdef CONFIG_PM |
---|
175 | 165 | /* |
---|
176 | 166 | * Save register configuration and disable interrupts. |
---|
177 | 167 | */ |
---|
178 | | -static void pch_gpio_save_reg_conf(struct pch_gpio *chip) |
---|
| 168 | +static void __maybe_unused pch_gpio_save_reg_conf(struct pch_gpio *chip) |
---|
179 | 169 | { |
---|
180 | 170 | chip->pch_gpio_reg.ien_reg = ioread32(&chip->reg->ien); |
---|
181 | 171 | chip->pch_gpio_reg.imask_reg = ioread32(&chip->reg->imask); |
---|
.. | .. |
---|
185 | 175 | if (chip->ioh == INTEL_EG20T_PCH) |
---|
186 | 176 | chip->pch_gpio_reg.im1_reg = ioread32(&chip->reg->im1); |
---|
187 | 177 | if (chip->ioh == OKISEMI_ML7223n_IOH) |
---|
188 | | - chip->pch_gpio_reg.gpio_use_sel_reg =\ |
---|
189 | | - ioread32(&chip->reg->gpio_use_sel); |
---|
| 178 | + chip->pch_gpio_reg.gpio_use_sel_reg = ioread32(&chip->reg->gpio_use_sel); |
---|
190 | 179 | } |
---|
191 | 180 | |
---|
192 | 181 | /* |
---|
193 | 182 | * This function restores the register configuration of the GPIO device. |
---|
194 | 183 | */ |
---|
195 | | -static void pch_gpio_restore_reg_conf(struct pch_gpio *chip) |
---|
| 184 | +static void __maybe_unused pch_gpio_restore_reg_conf(struct pch_gpio *chip) |
---|
196 | 185 | { |
---|
197 | 186 | iowrite32(chip->pch_gpio_reg.ien_reg, &chip->reg->ien); |
---|
198 | 187 | iowrite32(chip->pch_gpio_reg.imask_reg, &chip->reg->imask); |
---|
.. | .. |
---|
204 | 193 | if (chip->ioh == INTEL_EG20T_PCH) |
---|
205 | 194 | iowrite32(chip->pch_gpio_reg.im1_reg, &chip->reg->im1); |
---|
206 | 195 | if (chip->ioh == OKISEMI_ML7223n_IOH) |
---|
207 | | - iowrite32(chip->pch_gpio_reg.gpio_use_sel_reg, |
---|
208 | | - &chip->reg->gpio_use_sel); |
---|
| 196 | + iowrite32(chip->pch_gpio_reg.gpio_use_sel_reg, &chip->reg->gpio_use_sel); |
---|
209 | 197 | } |
---|
210 | | -#endif |
---|
211 | 198 | |
---|
212 | | -static int pch_gpio_to_irq(struct gpio_chip *gpio, unsigned offset) |
---|
| 199 | +static int pch_gpio_to_irq(struct gpio_chip *gpio, unsigned int offset) |
---|
213 | 200 | { |
---|
214 | 201 | struct pch_gpio *chip = gpiochip_get_data(gpio); |
---|
| 202 | + |
---|
215 | 203 | return chip->irq_base + offset; |
---|
216 | 204 | } |
---|
217 | 205 | |
---|
.. | .. |
---|
226 | 214 | gpio->get = pch_gpio_get; |
---|
227 | 215 | gpio->direction_output = pch_gpio_direction_output; |
---|
228 | 216 | gpio->set = pch_gpio_set; |
---|
229 | | - gpio->dbg_show = NULL; |
---|
230 | 217 | gpio->base = -1; |
---|
231 | 218 | gpio->ngpio = gpio_pins[chip->ioh]; |
---|
232 | 219 | gpio->can_sleep = false; |
---|
.. | .. |
---|
243 | 230 | int ch, irq = d->irq; |
---|
244 | 231 | |
---|
245 | 232 | ch = irq - chip->irq_base; |
---|
246 | | - if (irq <= chip->irq_base + 7) { |
---|
| 233 | + if (irq < chip->irq_base + 8) { |
---|
247 | 234 | im_reg = &chip->reg->im0; |
---|
248 | | - im_pos = ch; |
---|
| 235 | + im_pos = ch - 0; |
---|
249 | 236 | } else { |
---|
250 | 237 | im_reg = &chip->reg->im1; |
---|
251 | 238 | im_pos = ch - 8; |
---|
252 | 239 | } |
---|
253 | | - dev_dbg(chip->dev, "%s:irq=%d type=%d ch=%d pos=%d\n", |
---|
254 | | - __func__, irq, type, ch, im_pos); |
---|
255 | | - |
---|
256 | | - spin_lock_irqsave(&chip->spinlock, flags); |
---|
| 240 | + dev_dbg(chip->dev, "irq=%d type=%d ch=%d pos=%d\n", irq, type, ch, im_pos); |
---|
257 | 241 | |
---|
258 | 242 | switch (type) { |
---|
259 | 243 | case IRQ_TYPE_EDGE_RISING: |
---|
.. | .. |
---|
272 | 256 | val = PCH_LEVEL_L; |
---|
273 | 257 | break; |
---|
274 | 258 | default: |
---|
275 | | - goto unlock; |
---|
| 259 | + return 0; |
---|
276 | 260 | } |
---|
| 261 | + |
---|
| 262 | + spin_lock_irqsave(&chip->spinlock, flags); |
---|
277 | 263 | |
---|
278 | 264 | /* Set interrupt mode */ |
---|
279 | 265 | im = ioread32(im_reg) & ~(PCH_IM_MASK << (im_pos * 4)); |
---|
280 | 266 | iowrite32(im | (val << (im_pos * 4)), im_reg); |
---|
281 | 267 | |
---|
282 | 268 | /* And the handler */ |
---|
283 | | - if (type & (IRQ_TYPE_LEVEL_LOW | IRQ_TYPE_LEVEL_HIGH)) |
---|
| 269 | + if (type & IRQ_TYPE_LEVEL_MASK) |
---|
284 | 270 | irq_set_handler_locked(d, handle_level_irq); |
---|
285 | | - else if (type & (IRQ_TYPE_EDGE_FALLING | IRQ_TYPE_EDGE_RISING)) |
---|
| 271 | + else if (type & IRQ_TYPE_EDGE_BOTH) |
---|
286 | 272 | irq_set_handler_locked(d, handle_edge_irq); |
---|
287 | 273 | |
---|
288 | | -unlock: |
---|
289 | 274 | spin_unlock_irqrestore(&chip->spinlock, flags); |
---|
290 | 275 | return 0; |
---|
291 | 276 | } |
---|
.. | .. |
---|
295 | 280 | struct irq_chip_generic *gc = irq_data_get_irq_chip_data(d); |
---|
296 | 281 | struct pch_gpio *chip = gc->private; |
---|
297 | 282 | |
---|
298 | | - iowrite32(1 << (d->irq - chip->irq_base), &chip->reg->imaskclr); |
---|
| 283 | + iowrite32(BIT(d->irq - chip->irq_base), &chip->reg->imaskclr); |
---|
299 | 284 | } |
---|
300 | 285 | |
---|
301 | 286 | static void pch_irq_mask(struct irq_data *d) |
---|
.. | .. |
---|
303 | 288 | struct irq_chip_generic *gc = irq_data_get_irq_chip_data(d); |
---|
304 | 289 | struct pch_gpio *chip = gc->private; |
---|
305 | 290 | |
---|
306 | | - iowrite32(1 << (d->irq - chip->irq_base), &chip->reg->imask); |
---|
| 291 | + iowrite32(BIT(d->irq - chip->irq_base), &chip->reg->imask); |
---|
307 | 292 | } |
---|
308 | 293 | |
---|
309 | 294 | static void pch_irq_ack(struct irq_data *d) |
---|
.. | .. |
---|
311 | 296 | struct irq_chip_generic *gc = irq_data_get_irq_chip_data(d); |
---|
312 | 297 | struct pch_gpio *chip = gc->private; |
---|
313 | 298 | |
---|
314 | | - iowrite32(1 << (d->irq - chip->irq_base), &chip->reg->iclr); |
---|
| 299 | + iowrite32(BIT(d->irq - chip->irq_base), &chip->reg->iclr); |
---|
315 | 300 | } |
---|
316 | 301 | |
---|
317 | 302 | static irqreturn_t pch_gpio_handler(int irq, void *dev_id) |
---|
318 | 303 | { |
---|
319 | 304 | struct pch_gpio *chip = dev_id; |
---|
320 | | - u32 reg_val = ioread32(&chip->reg->istatus); |
---|
321 | | - int i, ret = IRQ_NONE; |
---|
| 305 | + unsigned long reg_val = ioread32(&chip->reg->istatus); |
---|
| 306 | + int i; |
---|
322 | 307 | |
---|
323 | | - for (i = 0; i < gpio_pins[chip->ioh]; i++) { |
---|
324 | | - if (reg_val & BIT(i)) { |
---|
325 | | - dev_dbg(chip->dev, "%s:[%d]:irq=%d status=0x%x\n", |
---|
326 | | - __func__, i, irq, reg_val); |
---|
327 | | - generic_handle_irq(chip->irq_base + i); |
---|
328 | | - ret = IRQ_HANDLED; |
---|
329 | | - } |
---|
330 | | - } |
---|
331 | | - return ret; |
---|
| 308 | + dev_vdbg(chip->dev, "irq=%d status=0x%lx\n", irq, reg_val); |
---|
| 309 | + |
---|
| 310 | + reg_val &= BIT(gpio_pins[chip->ioh]) - 1; |
---|
| 311 | + |
---|
| 312 | + for_each_set_bit(i, ®_val, gpio_pins[chip->ioh]) |
---|
| 313 | + generic_handle_irq(chip->irq_base + i); |
---|
| 314 | + |
---|
| 315 | + return IRQ_RETVAL(reg_val); |
---|
332 | 316 | } |
---|
333 | 317 | |
---|
334 | 318 | static int pch_gpio_alloc_generic_chip(struct pch_gpio *chip, |
---|
.. | .. |
---|
365 | 349 | s32 ret; |
---|
366 | 350 | struct pch_gpio *chip; |
---|
367 | 351 | int irq_base; |
---|
368 | | - u32 msk; |
---|
369 | 352 | |
---|
370 | | - chip = kzalloc(sizeof(*chip), GFP_KERNEL); |
---|
| 353 | + chip = devm_kzalloc(&pdev->dev, sizeof(*chip), GFP_KERNEL); |
---|
371 | 354 | if (chip == NULL) |
---|
372 | 355 | return -ENOMEM; |
---|
373 | 356 | |
---|
374 | 357 | chip->dev = &pdev->dev; |
---|
375 | | - ret = pci_enable_device(pdev); |
---|
| 358 | + ret = pcim_enable_device(pdev); |
---|
376 | 359 | if (ret) { |
---|
377 | | - dev_err(&pdev->dev, "%s : pci_enable_device FAILED", __func__); |
---|
378 | | - goto err_pci_enable; |
---|
| 360 | + dev_err(&pdev->dev, "pci_enable_device FAILED"); |
---|
| 361 | + return ret; |
---|
379 | 362 | } |
---|
380 | 363 | |
---|
381 | | - ret = pci_request_regions(pdev, KBUILD_MODNAME); |
---|
| 364 | + ret = pcim_iomap_regions(pdev, BIT(1), KBUILD_MODNAME); |
---|
382 | 365 | if (ret) { |
---|
383 | 366 | dev_err(&pdev->dev, "pci_request_regions FAILED-%d", ret); |
---|
384 | | - goto err_request_regions; |
---|
| 367 | + return ret; |
---|
385 | 368 | } |
---|
386 | 369 | |
---|
387 | | - chip->base = pci_iomap(pdev, 1, 0); |
---|
388 | | - if (!chip->base) { |
---|
389 | | - dev_err(&pdev->dev, "%s : pci_iomap FAILED", __func__); |
---|
390 | | - ret = -ENOMEM; |
---|
391 | | - goto err_iomap; |
---|
392 | | - } |
---|
| 370 | + chip->base = pcim_iomap_table(pdev)[1]; |
---|
393 | 371 | |
---|
394 | 372 | if (pdev->device == 0x8803) |
---|
395 | 373 | chip->ioh = INTEL_EG20T_PCH; |
---|
.. | .. |
---|
402 | 380 | pci_set_drvdata(pdev, chip); |
---|
403 | 381 | spin_lock_init(&chip->spinlock); |
---|
404 | 382 | pch_gpio_setup(chip); |
---|
405 | | -#ifdef CONFIG_OF_GPIO |
---|
406 | | - chip->gpio.of_node = pdev->dev.of_node; |
---|
407 | | -#endif |
---|
408 | | - ret = gpiochip_add_data(&chip->gpio, chip); |
---|
| 383 | + |
---|
| 384 | + ret = devm_gpiochip_add_data(&pdev->dev, &chip->gpio, chip); |
---|
409 | 385 | if (ret) { |
---|
410 | 386 | dev_err(&pdev->dev, "PCH gpio: Failed to register GPIO\n"); |
---|
411 | | - goto err_gpiochip_add; |
---|
| 387 | + return ret; |
---|
412 | 388 | } |
---|
413 | 389 | |
---|
414 | 390 | irq_base = devm_irq_alloc_descs(&pdev->dev, -1, 0, |
---|
.. | .. |
---|
416 | 392 | if (irq_base < 0) { |
---|
417 | 393 | dev_warn(&pdev->dev, "PCH gpio: Failed to get IRQ base num\n"); |
---|
418 | 394 | chip->irq_base = -1; |
---|
419 | | - goto end; |
---|
| 395 | + return 0; |
---|
420 | 396 | } |
---|
421 | 397 | chip->irq_base = irq_base; |
---|
422 | 398 | |
---|
423 | 399 | /* Mask all interrupts, but enable them */ |
---|
424 | | - msk = (1 << gpio_pins[chip->ioh]) - 1; |
---|
425 | | - iowrite32(msk, &chip->reg->imask); |
---|
426 | | - iowrite32(msk, &chip->reg->ien); |
---|
| 400 | + iowrite32(BIT(gpio_pins[chip->ioh]) - 1, &chip->reg->imask); |
---|
| 401 | + iowrite32(BIT(gpio_pins[chip->ioh]) - 1, &chip->reg->ien); |
---|
427 | 402 | |
---|
428 | 403 | ret = devm_request_irq(&pdev->dev, pdev->irq, pch_gpio_handler, |
---|
429 | 404 | IRQF_SHARED, KBUILD_MODNAME, chip); |
---|
430 | | - if (ret != 0) { |
---|
431 | | - dev_err(&pdev->dev, |
---|
432 | | - "%s request_irq failed\n", __func__); |
---|
433 | | - goto err_request_irq; |
---|
| 405 | + if (ret) { |
---|
| 406 | + dev_err(&pdev->dev, "request_irq failed\n"); |
---|
| 407 | + return ret; |
---|
434 | 408 | } |
---|
435 | 409 | |
---|
436 | | - ret = pch_gpio_alloc_generic_chip(chip, irq_base, |
---|
437 | | - gpio_pins[chip->ioh]); |
---|
438 | | - if (ret) |
---|
439 | | - goto err_request_irq; |
---|
440 | | - |
---|
441 | | -end: |
---|
442 | | - return 0; |
---|
443 | | - |
---|
444 | | -err_request_irq: |
---|
445 | | - gpiochip_remove(&chip->gpio); |
---|
446 | | - |
---|
447 | | -err_gpiochip_add: |
---|
448 | | - pci_iounmap(pdev, chip->base); |
---|
449 | | - |
---|
450 | | -err_iomap: |
---|
451 | | - pci_release_regions(pdev); |
---|
452 | | - |
---|
453 | | -err_request_regions: |
---|
454 | | - pci_disable_device(pdev); |
---|
455 | | - |
---|
456 | | -err_pci_enable: |
---|
457 | | - kfree(chip); |
---|
458 | | - dev_err(&pdev->dev, "%s Failed returns %d\n", __func__, ret); |
---|
459 | | - return ret; |
---|
| 410 | + return pch_gpio_alloc_generic_chip(chip, irq_base, gpio_pins[chip->ioh]); |
---|
460 | 411 | } |
---|
461 | 412 | |
---|
462 | | -static void pch_gpio_remove(struct pci_dev *pdev) |
---|
| 413 | +static int __maybe_unused pch_gpio_suspend(struct device *dev) |
---|
463 | 414 | { |
---|
464 | | - struct pch_gpio *chip = pci_get_drvdata(pdev); |
---|
465 | | - |
---|
466 | | - gpiochip_remove(&chip->gpio); |
---|
467 | | - pci_iounmap(pdev, chip->base); |
---|
468 | | - pci_release_regions(pdev); |
---|
469 | | - pci_disable_device(pdev); |
---|
470 | | - kfree(chip); |
---|
471 | | -} |
---|
472 | | - |
---|
473 | | -#ifdef CONFIG_PM |
---|
474 | | -static int pch_gpio_suspend(struct pci_dev *pdev, pm_message_t state) |
---|
475 | | -{ |
---|
476 | | - s32 ret; |
---|
477 | | - struct pch_gpio *chip = pci_get_drvdata(pdev); |
---|
| 415 | + struct pch_gpio *chip = dev_get_drvdata(dev); |
---|
478 | 416 | unsigned long flags; |
---|
479 | 417 | |
---|
480 | 418 | spin_lock_irqsave(&chip->spinlock, flags); |
---|
481 | 419 | pch_gpio_save_reg_conf(chip); |
---|
482 | 420 | spin_unlock_irqrestore(&chip->spinlock, flags); |
---|
483 | 421 | |
---|
484 | | - ret = pci_save_state(pdev); |
---|
485 | | - if (ret) { |
---|
486 | | - dev_err(&pdev->dev, "pci_save_state Failed-%d\n", ret); |
---|
487 | | - return ret; |
---|
488 | | - } |
---|
489 | | - pci_disable_device(pdev); |
---|
490 | | - pci_set_power_state(pdev, PCI_D0); |
---|
491 | | - ret = pci_enable_wake(pdev, PCI_D0, 1); |
---|
492 | | - if (ret) |
---|
493 | | - dev_err(&pdev->dev, "pci_enable_wake Failed -%d\n", ret); |
---|
494 | | - |
---|
495 | 422 | return 0; |
---|
496 | 423 | } |
---|
497 | 424 | |
---|
498 | | -static int pch_gpio_resume(struct pci_dev *pdev) |
---|
| 425 | +static int __maybe_unused pch_gpio_resume(struct device *dev) |
---|
499 | 426 | { |
---|
500 | | - s32 ret; |
---|
501 | | - struct pch_gpio *chip = pci_get_drvdata(pdev); |
---|
| 427 | + struct pch_gpio *chip = dev_get_drvdata(dev); |
---|
502 | 428 | unsigned long flags; |
---|
503 | | - |
---|
504 | | - ret = pci_enable_wake(pdev, PCI_D0, 0); |
---|
505 | | - |
---|
506 | | - pci_set_power_state(pdev, PCI_D0); |
---|
507 | | - ret = pci_enable_device(pdev); |
---|
508 | | - if (ret) { |
---|
509 | | - dev_err(&pdev->dev, "pci_enable_device Failed-%d ", ret); |
---|
510 | | - return ret; |
---|
511 | | - } |
---|
512 | | - pci_restore_state(pdev); |
---|
513 | 429 | |
---|
514 | 430 | spin_lock_irqsave(&chip->spinlock, flags); |
---|
515 | 431 | iowrite32(0x01, &chip->reg->reset); |
---|
.. | .. |
---|
519 | 435 | |
---|
520 | 436 | return 0; |
---|
521 | 437 | } |
---|
522 | | -#else |
---|
523 | | -#define pch_gpio_suspend NULL |
---|
524 | | -#define pch_gpio_resume NULL |
---|
525 | | -#endif |
---|
| 438 | + |
---|
| 439 | +static SIMPLE_DEV_PM_OPS(pch_gpio_pm_ops, pch_gpio_suspend, pch_gpio_resume); |
---|
526 | 440 | |
---|
527 | 441 | static const struct pci_device_id pch_gpio_pcidev_id[] = { |
---|
528 | 442 | { PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x8803) }, |
---|
.. | .. |
---|
537 | 451 | .name = "pch_gpio", |
---|
538 | 452 | .id_table = pch_gpio_pcidev_id, |
---|
539 | 453 | .probe = pch_gpio_probe, |
---|
540 | | - .remove = pch_gpio_remove, |
---|
541 | | - .suspend = pch_gpio_suspend, |
---|
542 | | - .resume = pch_gpio_resume |
---|
| 454 | + .driver = { |
---|
| 455 | + .pm = &pch_gpio_pm_ops, |
---|
| 456 | + }, |
---|
543 | 457 | }; |
---|
544 | 458 | |
---|
545 | 459 | module_pci_driver(pch_gpio_driver); |
---|
546 | 460 | |
---|
547 | 461 | MODULE_DESCRIPTION("PCH GPIO PCI Driver"); |
---|
548 | | -MODULE_LICENSE("GPL"); |
---|
| 462 | +MODULE_LICENSE("GPL v2"); |
---|