15 #include <linux/kernel.h>
16 #include <linux/module.h>
17 #include <linux/device.h>
19 #include <linux/i2c.h>
23 #include <linux/slab.h>
25 #include <linux/reboot.h>
27 #include <asm/machdep.h>
33 #define MCU_REG_CTRL 0x20
34 #define MCU_CTRL_POFF 0x40
35 #define MCU_CTRL_BTN 0x80
37 #define MCU_NUM_GPIO 2
46 static struct mcu *glob_mcu;
49 static int shutdown_thread_fn(
void *
data)
52 struct mcu *
mcu = glob_mcu;
57 pr_err(
"MCU status reg read failed.\n");
79 struct mcu *
mcu = glob_mcu;
86 return sprintf(buf,
"%02x\n", ret);
90 static void mcu_power_off(
void)
92 struct mcu *mcu = glob_mcu;
94 pr_info(
"Sending power-off request to the MCU...\n");
101 static void mcu_gpio_set(
struct gpio_chip *
gc,
unsigned int gpio,
int val)
116 static int mcu_gpio_dir_out(
struct gpio_chip *gc,
unsigned int gpio,
int val)
118 mcu_gpio_set(gc, gpio, val);
122 static int mcu_gpiochip_add(
struct mcu *mcu)
125 struct gpio_chip *gc = &mcu->
gc;
136 gc->set = mcu_gpio_set;
137 gc->direction_output = mcu_gpio_dir_out;
143 static int mcu_gpiochip_remove(
struct mcu *mcu)
160 i2c_set_clientdata(client, mcu);
167 ret = mcu_gpiochip_add(mcu);
174 ppc_md.power_off = mcu_power_off;
175 dev_info(&client->
dev,
"will provide power-off service\n");
180 "couldn't create device file for status\n");
193 struct mcu *mcu = i2c_get_clientdata(client);
200 if (glob_mcu == mcu) {
205 ret = mcu_gpiochip_remove(mcu);
208 i2c_set_clientdata(client,
NULL);
214 {
"mcu-mpc8349emitx", },
220 { .compatible =
"fsl,mcu-mpc8349emitx", },
226 .name =
"mcu-mpc8349emitx",
228 .of_match_table = mcu_of_match_table,
235 static int __init mcu_init(
void)
237 return i2c_add_driver(&mcu_driver);
241 static void __exit mcu_exit(
void)
248 "MPC8349E-mITX-compatible MCU");