Lines Matching +full:turris +full:- +full:omnia +full:- +full:mcu

1 // SPDX-License-Identifier: GPL-2.0
3 * CZ.NIC's Turris Omnia MCU driver
19 #include <linux/turris-omnia-mcu-interface.h>
20 #include "turris-omnia-mcu.h"
33 msgs[0].addr = client->addr; in omnia_cmd_write_read()
40 msgs[1].addr = client->addr; in omnia_cmd_write_read()
47 ret = i2c_transfer(client->adapter, msgs, num); in omnia_cmd_write_read()
51 return -EIO; in omnia_cmd_write_read()
56 static int omnia_get_version_hash(struct omnia_mcu *mcu, bool bootloader, in omnia_get_version_hash() argument
63 err = omnia_cmd_read(mcu->client, in omnia_get_version_hash()
79 struct omnia_mcu *mcu = dev_get_drvdata(dev); in fw_version_hash_show() local
83 err = omnia_get_version_hash(mcu, bootloader, version); in fw_version_hash_show()
109 struct omnia_mcu *mcu = dev_get_drvdata(dev); in fw_features_show() local
111 return sysfs_emit(buf, "0x%x\n", mcu->features); in fw_features_show()
118 struct omnia_mcu *mcu = dev_get_drvdata(dev); in mcu_type_show() local
120 return sysfs_emit(buf, "%s\n", mcu->type); in mcu_type_show()
142 struct omnia_mcu *mcu = dev_get_drvdata(dev); in serial_number_show() local
144 return sysfs_emit(buf, "%016llX\n", mcu->board_serial_number); in serial_number_show()
151 struct omnia_mcu *mcu = dev_get_drvdata(dev); in first_mac_address_show() local
153 return sysfs_emit(buf, "%pM\n", mcu->board_first_mac); in first_mac_address_show()
160 struct omnia_mcu *mcu = dev_get_drvdata(dev); in board_revision_show() local
162 return sysfs_emit(buf, "%u\n", mcu->board_revision); in board_revision_show()
182 struct omnia_mcu *mcu = dev_get_drvdata(dev); in omnia_mcu_base_attrs_visible() local
187 !(mcu->features & OMNIA_FEAT_BOARD_INFO)) in omnia_mcu_base_attrs_visible()
190 return a->mode; in omnia_mcu_base_attrs_visible()
209 static void omnia_mcu_print_version_hash(struct omnia_mcu *mcu, bool bootloader) in omnia_mcu_print_version_hash() argument
212 struct device *dev = &mcu->client->dev; in omnia_mcu_print_version_hash()
216 err = omnia_get_version_hash(mcu, bootloader, version); in omnia_mcu_print_version_hash()
218 dev_err(dev, "Cannot read MCU %s firmware version: %d\n", in omnia_mcu_print_version_hash()
223 dev_info(dev, "MCU %s firmware version hash: %s\n", type, version); in omnia_mcu_print_version_hash()
243 "Your board's MCU firmware does not support the %s feature.\n", in omnia_info_missing_feature()
247 static int omnia_mcu_read_features(struct omnia_mcu *mcu) in omnia_mcu_read_features() argument
262 struct i2c_client *client = mcu->client; in omnia_mcu_read_features()
263 struct device *dev = &client->dev; in omnia_mcu_read_features()
268 /* status word holds MCU type, which we need below */ in omnia_mcu_read_features()
274 * Check whether MCU firmware supports the OMNIA_CMD_GET_FEATURES in omnia_mcu_read_features()
278 /* try read 32-bit features */ in omnia_mcu_read_features()
280 &mcu->features); in omnia_mcu_read_features()
282 /* try read 16-bit features */ in omnia_mcu_read_features()
290 mcu->features = features16; in omnia_mcu_read_features()
292 if (mcu->features & OMNIA_FEAT_FROM_BIT_16_INVALID) in omnia_mcu_read_features()
293 mcu->features &= GENMASK(15, 0); in omnia_mcu_read_features()
297 "Your board's MCU firmware does not support feature reading.\n"); in omnia_mcu_read_features()
301 mcu->type = omnia_status_to_mcu_type(status); in omnia_mcu_read_features()
302 dev_info(dev, "MCU type %s%s\n", mcu->type, in omnia_mcu_read_features()
303 (mcu->features & OMNIA_FEAT_PERIPH_MCU) ? in omnia_mcu_read_features()
306 omnia_mcu_print_version_hash(mcu, true); in omnia_mcu_read_features()
308 if (mcu->features & OMNIA_FEAT_BOOTLOADER) in omnia_mcu_read_features()
310 "MCU is running bootloader firmware. Was firmware upgrade interrupted?\n"); in omnia_mcu_read_features()
312 omnia_mcu_print_version_hash(mcu, false); in omnia_mcu_read_features()
315 if (mcu->features & features[i].mask) in omnia_mcu_read_features()
324 "Consider upgrading MCU firmware with the omnia-mcutool utility.\n"); in omnia_mcu_read_features()
329 static int omnia_mcu_read_board_info(struct omnia_mcu *mcu) in omnia_mcu_read_board_info() argument
334 err = omnia_cmd_read(mcu->client, OMNIA_CMD_BOARD_INFO_GET, reply, in omnia_mcu_read_board_info()
340 return -EIO; in omnia_mcu_read_board_info()
342 mcu->board_serial_number = get_unaligned_le64(&reply[1]); in omnia_mcu_read_board_info()
344 /* we can't use ether_addr_copy() because reply is not u16-aligned */ in omnia_mcu_read_board_info()
345 memcpy(mcu->board_first_mac, &reply[9], sizeof(mcu->board_first_mac)); in omnia_mcu_read_board_info()
347 mcu->board_revision = reply[15]; in omnia_mcu_read_board_info()
354 struct device *dev = &client->dev; in omnia_mcu_probe()
355 struct omnia_mcu *mcu; in omnia_mcu_probe() local
358 if (!client->irq) in omnia_mcu_probe()
359 return dev_err_probe(dev, -EINVAL, "IRQ resource not found\n"); in omnia_mcu_probe()
361 mcu = devm_kzalloc(dev, sizeof(*mcu), GFP_KERNEL); in omnia_mcu_probe()
362 if (!mcu) in omnia_mcu_probe()
363 return -ENOMEM; in omnia_mcu_probe()
365 mcu->client = client; in omnia_mcu_probe()
366 i2c_set_clientdata(client, mcu); in omnia_mcu_probe()
368 err = omnia_mcu_read_features(mcu); in omnia_mcu_probe()
371 "Cannot determine MCU supported features\n"); in omnia_mcu_probe()
373 if (mcu->features & OMNIA_FEAT_BOARD_INFO) { in omnia_mcu_probe()
374 err = omnia_mcu_read_board_info(mcu); in omnia_mcu_probe()
380 err = omnia_mcu_register_sys_off_and_wakeup(mcu); in omnia_mcu_probe()
384 err = omnia_mcu_register_watchdog(mcu); in omnia_mcu_probe()
388 err = omnia_mcu_register_gpiochip(mcu); in omnia_mcu_probe()
392 return omnia_mcu_register_trng(mcu); in omnia_mcu_probe()
396 { .compatible = "cznic,turris-omnia-mcu" },
403 .name = "turris-omnia-mcu",
411 MODULE_DESCRIPTION("CZ.NIC's Turris Omnia MCU");