2

I'm writing a platform-specific multi-function device driver, which includes an i2c driver.

I want to send an i2c message to a custom power-management chip, when the Linux kernel is halted or powered-off.

I've tried pm_power_off = my_func to override the power off function, but it doesn't get called. (my_func does a printk and pr_emerg to try and get some text to the console during shutdown.)

What are the correct hooks to use to add functionality to kernel halt and power off? (I'd rather add code to my driver, rather than patch kernel/reboot.c etc.)

fadedbee
  • 42,671
  • 44
  • 178
  • 308
  • 1
    Check the platform specific hooks in *drivers/power/reset/*. For example Atmel - drivers/power/reset/at91-poweroff.c, Qualcomm - drivers/power/reset/msm-poweroff.c – SD. Jan 11 '17 at 11:47
  • Thanks, but at91-poweroff.c does `pm_power_off = at91_poweroff;` in `at91_poweroff_probe` just like I'm doing. – fadedbee Jan 11 '17 at 13:12
  • 1
    That's correct. In your case can you confirm the *my_func* is registered successfully when driver initializes? – SD. Jan 11 '17 at 14:18
  • Yes, it was something odd, perhaps a file not saved before `make`. `my_func` is now being called. – fadedbee Jan 11 '17 at 16:46
  • Also see: https://stackoverflow.com/questions/41596661/how-to-make-linux-power-off-when-halt-is-run – fadedbee Jan 11 '17 at 17:06
  • Why not add `struct dev_pm_ops` to your `struct i2c_driver.driver.pm`, assigning `.poweroff` to your hook function? Like it's done in [drivers/mfd/wm831x-i2c.c](http://lxr.free-electrons.com/source/drivers/mfd/wm831x-i2c.c#L88). – Sam Protsenko Jan 11 '17 at 22:13

0 Answers0