Lines Matching +full:mcu +full:- +full:mpc8349emitx

1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Power Management and GPIO expander driver for MPC8349E-mITX-compatible MCU
24 * I don't have specifications for the MCU firmware, I found this register
33 struct mcu { struct
40 static struct mcu *glob_mcu; argument
46 struct mcu *mcu = glob_mcu; in shutdown_thread_fn() local
49 ret = i2c_smbus_read_byte_data(mcu->client, MCU_REG_CTRL); in shutdown_thread_fn()
51 pr_err("MCU status reg read failed.\n"); in shutdown_thread_fn()
52 mcu->reg_ctrl = ret; in shutdown_thread_fn()
55 if (mcu->reg_ctrl & MCU_CTRL_BTN) { in shutdown_thread_fn()
56 i2c_smbus_write_byte_data(mcu->client, MCU_REG_CTRL, in shutdown_thread_fn()
57 mcu->reg_ctrl & ~MCU_CTRL_BTN); in shutdown_thread_fn()
73 struct mcu *mcu = glob_mcu; in show_status() local
75 ret = i2c_smbus_read_byte_data(mcu->client, MCU_REG_CTRL); in show_status()
77 return -ENODEV; in show_status()
78 mcu->reg_ctrl = ret; in show_status()
86 struct mcu *mcu = glob_mcu; in mcu_power_off() local
88 pr_info("Sending power-off request to the MCU...\n"); in mcu_power_off()
89 mutex_lock(&mcu->lock); in mcu_power_off()
90 i2c_smbus_write_byte_data(mcu->client, MCU_REG_CTRL, in mcu_power_off()
91 mcu->reg_ctrl | MCU_CTRL_POFF); in mcu_power_off()
92 mutex_unlock(&mcu->lock); in mcu_power_off()
97 struct mcu *mcu = gpiochip_get_data(gc); in mcu_gpio_set() local
101 mutex_lock(&mcu->lock); in mcu_gpio_set()
103 mcu->reg_ctrl &= ~bit; in mcu_gpio_set()
105 mcu->reg_ctrl |= bit; in mcu_gpio_set()
107 ret = i2c_smbus_write_byte_data(mcu->client, MCU_REG_CTRL, in mcu_gpio_set()
108 mcu->reg_ctrl); in mcu_gpio_set()
109 mutex_unlock(&mcu->lock); in mcu_gpio_set()
119 static int mcu_gpiochip_add(struct mcu *mcu) in mcu_gpiochip_add() argument
121 struct device *dev = &mcu->client->dev; in mcu_gpiochip_add()
122 struct gpio_chip *gc = &mcu->gc; in mcu_gpiochip_add()
124 gc->owner = THIS_MODULE; in mcu_gpiochip_add()
125 gc->label = kasprintf(GFP_KERNEL, "%pfw", dev_fwnode(dev)); in mcu_gpiochip_add()
126 gc->can_sleep = 1; in mcu_gpiochip_add()
127 gc->ngpio = MCU_NUM_GPIO; in mcu_gpiochip_add()
128 gc->base = -1; in mcu_gpiochip_add()
129 gc->set = mcu_gpio_set; in mcu_gpiochip_add()
130 gc->direction_output = mcu_gpio_dir_out; in mcu_gpiochip_add()
131 gc->parent = dev; in mcu_gpiochip_add()
133 return gpiochip_add_data(gc, mcu); in mcu_gpiochip_add()
136 static void mcu_gpiochip_remove(struct mcu *mcu) in mcu_gpiochip_remove() argument
138 kfree(mcu->gc.label); in mcu_gpiochip_remove()
139 gpiochip_remove(&mcu->gc); in mcu_gpiochip_remove()
144 struct mcu *mcu; in mcu_probe() local
147 mcu = kzalloc(sizeof(*mcu), GFP_KERNEL); in mcu_probe()
148 if (!mcu) in mcu_probe()
149 return -ENOMEM; in mcu_probe()
151 mutex_init(&mcu->lock); in mcu_probe()
152 mcu->client = client; in mcu_probe()
153 i2c_set_clientdata(client, mcu); in mcu_probe()
155 ret = i2c_smbus_read_byte_data(mcu->client, MCU_REG_CTRL); in mcu_probe()
158 mcu->reg_ctrl = ret; in mcu_probe()
160 ret = mcu_gpiochip_add(mcu); in mcu_probe()
166 glob_mcu = mcu; in mcu_probe()
168 dev_info(&client->dev, "will provide power-off service\n"); in mcu_probe()
171 if (device_create_file(&client->dev, &dev_attr_status)) in mcu_probe()
172 dev_err(&client->dev, in mcu_probe()
176 "mcu-i2c-shdn"); in mcu_probe()
180 kfree(mcu); in mcu_probe()
186 struct mcu *mcu = i2c_get_clientdata(client); in mcu_remove() local
190 device_remove_file(&client->dev, &dev_attr_status); in mcu_remove()
192 if (glob_mcu == mcu) { in mcu_remove()
197 mcu_gpiochip_remove(mcu); in mcu_remove()
198 kfree(mcu); in mcu_remove()
202 { "mcu-mpc8349emitx", },
208 { .compatible = "fsl,mcu-mpc8349emitx", },
214 .name = "mcu-mpc8349emitx",
225 "MPC8349E-mITX-compatible MCU");