Lines Matching full:mcu

12 #include <linux/mfd/qnap-mcu.h>
57 * @version: MCU firmware version
68 * The QNAP-MCU uses a basic XOR checksum.
81 static int qnap_mcu_write(struct qnap_mcu *mcu, const u8 *data, u8 data_size) in qnap_mcu_write() argument
87 dev_err(&mcu->serdev->dev, "data too big for transmit buffer"); in qnap_mcu_write()
94 serdev_device_write_flush(mcu->serdev); in qnap_mcu_write()
96 return serdev_device_write(mcu->serdev, tx, length, HZ); in qnap_mcu_write()
102 struct qnap_mcu *mcu = dev_get_drvdata(dev); in qnap_mcu_receive_buf() local
103 struct qnap_mcu_reply *reply = &mcu->reply; in qnap_mcu_receive_buf()
145 int qnap_mcu_exec(struct qnap_mcu *mcu, in qnap_mcu_exec() argument
151 struct qnap_mcu_reply *reply = &mcu->reply; in qnap_mcu_exec()
155 dev_err(&mcu->serdev->dev, "expected data too big for receive buffer"); in qnap_mcu_exec()
159 mutex_lock(&mcu->bus_lock); in qnap_mcu_exec()
166 qnap_mcu_write(mcu, cmd_data, cmd_data_size); in qnap_mcu_exec()
168 serdev_device_wait_until_sent(mcu->serdev, msecs_to_jiffies(QNAP_MCU_TIMEOUT_MS)); in qnap_mcu_exec()
171 dev_err(&mcu->serdev->dev, "Command timeout\n"); in qnap_mcu_exec()
177 dev_err(&mcu->serdev->dev, in qnap_mcu_exec()
185 mutex_unlock(&mcu->bus_lock); in qnap_mcu_exec()
190 int qnap_mcu_exec_with_ack(struct qnap_mcu *mcu, in qnap_mcu_exec_with_ack() argument
196 ret = qnap_mcu_exec(mcu, cmd_data, cmd_data_size, ack, sizeof(ack)); in qnap_mcu_exec_with_ack()
202 dev_err(&mcu->serdev->dev, "Did not receive ack\n"); in qnap_mcu_exec_with_ack()
210 static int qnap_mcu_get_version(struct qnap_mcu *mcu) in qnap_mcu_get_version() argument
217 ret = qnap_mcu_exec(mcu, cmd, sizeof(cmd), rx, QNAP_MCU_VERSION_LEN + 2); in qnap_mcu_get_version()
221 memcpy(mcu->version, &rx[2], QNAP_MCU_VERSION_LEN); in qnap_mcu_get_version()
227 * The MCU controls power to the peripherals but not the CPU.
229 * So using the PMIC to power off the system keeps the MCU and hard-drives
231 * the MCU is turned off by unplugging the power cable.
232 * Turning off the MCU alone on the other hand turns off the hard drives,
238 struct qnap_mcu *mcu = data->cb_data; in qnap_mcu_power_off() local
241 ret = qnap_mcu_exec_with_ack(mcu, cmd, sizeof(cmd)); in qnap_mcu_power_off()
243 dev_err(&mcu->serdev->dev, "MCU poweroff failed %d\n", ret); in qnap_mcu_power_off()
259 { .name = "qnap-mcu-input", },
260 { .name = "qnap-mcu-leds", },
261 { .name = "qnap-mcu-hwmon", }
267 struct qnap_mcu *mcu; in qnap_mcu_probe() local
270 mcu = devm_kzalloc(dev, sizeof(*mcu), GFP_KERNEL); in qnap_mcu_probe()
271 if (!mcu) in qnap_mcu_probe()
274 mcu->serdev = serdev; in qnap_mcu_probe()
275 dev_set_drvdata(dev, mcu); in qnap_mcu_probe()
277 mcu->variant = of_device_get_match_data(dev); in qnap_mcu_probe()
278 if (!mcu->variant) in qnap_mcu_probe()
281 mutex_init(&mcu->bus_lock); in qnap_mcu_probe()
282 init_completion(&mcu->reply.done); in qnap_mcu_probe()
289 serdev_device_set_baudrate(serdev, mcu->variant->baud_rate); in qnap_mcu_probe()
296 ret = qnap_mcu_get_version(mcu); in qnap_mcu_probe()
303 &qnap_mcu_power_off, mcu); in qnap_mcu_probe()
309 qnap_mcu_cells[i].platform_data = mcu->variant; in qnap_mcu_probe()
310 qnap_mcu_cells[i].pdata_size = sizeof(*mcu->variant); in qnap_mcu_probe()
322 { .compatible = "qnap,ts433-mcu", .data = &qnap_ts433_mcu },
330 .name = "qnap-mcu",
337 MODULE_DESCRIPTION("QNAP MCU core driver");