Skip to content

Commit

Permalink
gpio: mvebu: Fix gpio bank registration and kernel panic
Browse files Browse the repository at this point in the history
Import of upstream commit fc7a906 ("gpio: mvebu: fix gpio bank registration
when pwm is used").

    If more than one gpio bank has the "pwm" property, only one will be
    registered successfully, all the others will fail with:
    mvebu-gpio: probe of f1018140.gpio failed with error -17

    That's because in alloc_pwms(), the chip->base (aka "int pwm"), was not
    set (thus, ==0) ; and 0 is a meaningful start value in alloc_pwm().
    What was intended is mvpwm->chip->base = -1.
    Like that, the numbering will be done auto-magically

    Moreover, as the region might be already occupied by another pwm, we
    shouldn't force:
    mvpwm->chip->base = 0
    nor
    mvpwm->chip->base = id * MVEBU_MAX_GPIO_PER_BANK;

Fixes:
[    0.670354] mvebu-gpio: probe of f1018140.gpio failed with error -17

and thus prevent a kernel panic later on:
[    2.459735] Unable to handle kernel paging request at virtual address 696c3e61
[    2.466975] pgd = c0004000
[    2.469686] [696c3e61] *pgd=00000000
[    2.473282] Internal error: Oops: 5 [kobol-io#1] SMP THUMB2
[    2.478171] Modules linked in:
[    2.481243] CPU: 0 PID: 1 Comm: swapper/0 Not tainted 4.4.112-mvebu kobol-io#2
[    2.487784] Hardware name: Marvell Armada 380/385 (Device Tree)
[    2.493717] task: ecce0040 ti: ecce2000 task.ti: ecce2000
[    2.499131] PC is at gpiochip_add+0x7c/0x320
[    2.503412] LR is at lock_acquired+0x19b/0x3a4
[    2.507866] pc : [<c038ac14>]    lr : [<c0158453>]    psr: 900000b3
[    2.507866] sp : ecce3c40  ip : c121cbe8  fp : ebfbe010
[    2.519370] r10: ebfc0ae0  r9 : 00000000  r8 : ebfcdc20
[    2.524606] r7 : ebfc0ae0  r6 : c0b6844c  r5 : 00000010  r4 : a0000013
[    2.531149] r3 : 696c3e2d  r2 : 64657470  r1 : 64657460  r0 : 696c3e1d
[    2.537691] Flags: NzcV  IRQs off  FIQs on  Mode SVC_32  ISA Thumb  Segment none
[    2.545103] Control: 50c5387d  Table: 0000404a  DAC: 00000051
[    2.550861] Process swapper/0 (pid: 1, stack limit = 0xecce2218)
[    2.556880] Stack: (0xecce3c40 to 0xecce4000)
[    2.561248] 3c40: ecce3c4e c015a01b ecce0630 c0b6844c c01566cb c015a291 ebfcdc00 c0b68424
[    2.569446] 3c60: c077f9e4 ebd3ff00 ebfc0a10 ebfc0a10 00000000 00000000 ebfcdc00 ebfcdc20
[    2.577645] 3c80: 00000000 ebfc0ae0 ebfbe010 c038e8bb 00000017 00000002 00000000 c04a86ad
[    2.585843] 3ca0: eedc6d1c ebfcdc20 0041d1ec c07a9f00 c0b68764 c060cc0c ebfcdc20 ebfcdc04
[    2.594040] 3cc0: ebfcdc00 c038e6d9 00000000 c0b81650 ebfbe010 c047c4d7 ebfcdc20 c141d1d8
[    2.602238] 3ce0: c141d1ec 00000000 c0b68764 c03d61db 00000000 00000001 00000000 ecce3d30
[    2.610436] 3d00: c03d634d c141d194 00000000 c03d4f59 ecdd6ef4 ece1a11c 00000000 ebfcdc20
[    2.618634] 3d20: ebfbe110 ebfcdc54 00000001 c03d607b ebfcdc20 00000001 c0364531 ebfcdc28
[    2.626831] 3d40: ebfbe110 ebfcdc20 c0b81680 c03d58f3 00000000 ebfcdc28 ebfbe110 00000000
[    2.635029] 3d60: ebfcdc20 c03d451d ebfbe010 c0153da1 ebfcdc20 c141d194 ebfcdc00 ecce3dc4
[    2.643226] 3d80: ebfbe0c0 ebfcdc20 ebfcdc04 0000249f 0ee6b280 c047e1e3 eedc6d1c ebfbe0c0
[    2.651424] 3da0: eedc6d1c ebfbe0c0 ebfbe110 00000008 ecd4d810 c047e52f 00000004 00000000
[    2.659622] 3dc0: 00000000 39616370 00353535 00000000 00000000 00000000 00200000 00000000
[    2.667820] 3de0: ecce3dbc eedc6d1c 00000000 00000000 ebfbe0c0 ebfbe0c0 eedc6d1c c047e7e7
[    2.676017] 3e00: ebfbe010 00000000 ecd4d800 00000008 ecd4d810 c04800c9 c07aa900 ebfbe010
[    2.684215] 3e20: c13a47cc 00061a80 00000000 eedc69a0 ecd4d810 ecd4d800 00061a80 000003e8
[    2.692414] 3e40: ecce0040 ecd4d810 ecd4d810 c0b82350 fffffdfb c0b82350 00000000 00000007
[    2.700611] 3e60: efffcc40 c03d7695 c03d765d ecd4d810 c141d1d8 c141d1ec 00000000 c03d61db
[    2.708810] 3e80: 00000000 ecd4d810 c0b82350 ecd4d844 c03d62f9 00000000 c0939860 c03d6339
[    2.717007] 3ea0: 00000001 00000000 c0b82350 c03d4edf ecd61ebc ecd46998 60000013 c0b82350
[    2.725205] 3ec0: ebfc67c0 00000000 c0b6ff78 c03d5a7b c07aa900 c0b82350 c0b06ca0 c0b82350
[    2.733403] 3ee0: c0b06ca0 ebfc5640 c0925c39 c03d6afd 00000000 c0b06ca0 c0b06ca0 c01017f3
[    2.741601] 3f00: c0b0f560 ecce05a0 00000001 00000000 c13a4700 c015c271 00000000 c0136329
[    2.749799] 3f20: 00000008 efffccbf 000000a6 c0136329 c07a9360 c07f89f0 00000000 00000006
[    2.757998] 3f40: 00000006 c073c084 c0961bbc 00000000 c0962150 c0ba4000 c0ba4000 c0939858
[    2.766195] 3f60: 000000a6 00000007 efffcc40 c0900c17 00000006 00000006 00000000 c0900455
[    2.774393] 3f80: ecce3f98 c0ba4000 c05c162d 00000000 00000000 00000000 00000000 00000000
[    2.782591] 3fa0: 00000000 c05c1641 00000000 c01060dd 00000000 00000000 00000000 00000000
[    2.790789] 3fc0: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
[    2.798986] 3fe0: 00000000 00000000 00000000 00000000 00000013 00000000 deadbeef deadbeef
[    2.807187] [<c038ac14>] (gpiochip_add) from [<c038e8bb>] (pca953x_probe+0x1e3/0x334)
[    2.815040] [<c038e8bb>] (pca953x_probe) from [<c047c4d7>] (i2c_device_probe+0x127/0x160)
[    2.823239] [<c047c4d7>] (i2c_device_probe) from [<c03d61db>] (driver_probe_device+0xe3/0x200)
[    2.831873] [<c03d61db>] (driver_probe_device) from [<c03d4f59>] (bus_for_each_drv+0x2d/0x60)
[    2.840420] [<c03d4f59>] (bus_for_each_drv) from [<c03d607b>] (__device_attach+0x67/0xb8)
[    2.848618] [<c03d607b>] (__device_attach) from [<c03d58f3>] (bus_probe_device+0x1f/0x64)
[    2.856815] [<c03d58f3>] (bus_probe_device) from [<c03d451d>] (device_add+0x2ad/0x404)
[    2.864753] [<c03d451d>] (device_add) from [<c047e1e3>] (i2c_new_device+0xf7/0x134)
[    2.872428] [<c047e1e3>] (i2c_new_device) from [<c047e52f>] (of_i2c_register_device+0xc7/0x128)
[    2.881149] [<c047e52f>] (of_i2c_register_device) from [<c047e7e7>] (i2c_register_adapter+0x1b7/0x284)
[    2.890479] [<c047e7e7>] (i2c_register_adapter) from [<c04800c9>] (mv64xxx_i2c_probe+0x345/0x404)
[    2.899375] [<c04800c9>] (mv64xxx_i2c_probe) from [<c03d7695>] (platform_drv_probe+0x39/0x7c)
[    2.907922] [<c03d7695>] (platform_drv_probe) from [<c03d61db>] (driver_probe_device+0xe3/0x200)
[    2.916729] [<c03d61db>] (driver_probe_device) from [<c03d6339>] (__driver_attach+0x41/0x54)
[    2.925188] [<c03d6339>] (__driver_attach) from [<c03d4edf>] (bus_for_each_dev+0x2f/0x64)
[    2.933386] [<c03d4edf>] (bus_for_each_dev) from [<c03d5a7b>] (bus_add_driver+0x8f/0x170)
[    2.941583] [<c03d5a7b>] (bus_add_driver) from [<c03d6afd>] (driver_register+0x5d/0x84)
[    2.949608] [<c03d6afd>] (driver_register) from [<c01017f3>] (do_one_initcall+0xdf/0x174)
[    2.957808] [<c01017f3>] (do_one_initcall) from [<c0900c17>] (kernel_init_freeable+0x1bb/0x228)
[    2.966531] [<c0900c17>] (kernel_init_freeable) from [<c05c1641>] (kernel_init+0x15/0xa8)
[    2.974730] [<c05c1641>] (kernel_init) from [<c01060dd>] (ret_from_fork+0x11/0x34)
[    2.982320] Code: bfb8 9e03 db06 e00b (6b5a) 8f1b
  • Loading branch information
prahal committed Jan 27, 2018
1 parent 5333b86 commit 37a4b4b
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions drivers/gpio/gpio-mvebu.c
Original file line number Diff line number Diff line change
Expand Up @@ -752,6 +752,14 @@ static int mvebu_pwm_probe(struct platform_device *pdev,
mvpwm->chip.ops = &mvebu_pwm_ops;
mvpwm->chip.npwm = mvchip->chip.ngpio;

/*
* There may already be some PWM allocated, so we can't force
* mvpwm->chip.base to a fixed point like mvchip->chip.base.
* So, we let pwmchip_add() do the numbering and take the next free
* region.
*/
mvpwm->chip.base = -1;

spin_lock_init(&mvpwm->lock);

return pwmchip_add(&mvpwm->chip);
Expand Down

0 comments on commit 37a4b4b

Please sign in to comment.