1 // SPDX-License-Identifier: GPL-2.0-only 2 /* 3 * Copyright (C) 2021-2022 Digiteq Automotive 4 * author: Martin Tuma <martin.tuma@digiteqautomotive.com> 5 * 6 * This module handles all the sysfs info/configuration that is related to the 7 * PCI card device. 8 */ 9 10 #include <linux/device.h> 11 #include "mgb4_core.h" 12 #include "mgb4_sysfs.h" 13 14 static ssize_t module_version_show(struct device *dev, 15 struct device_attribute *attr, char *buf) 16 { 17 struct mgb4_dev *mgbdev = dev_get_drvdata(dev); 18 19 return sprintf(buf, "%u\n", mgbdev->module_version & 0x0F); 20 } 21 22 static ssize_t module_type_show(struct device *dev, 23 struct device_attribute *attr, char *buf) 24 { 25 struct mgb4_dev *mgbdev = dev_get_drvdata(dev); 26 27 return sprintf(buf, "%u\n", mgbdev->module_version >> 4); 28 } 29 30 static ssize_t fw_version_show(struct device *dev, 31 struct device_attribute *attr, char *buf) 32 { 33 struct mgb4_dev *mgbdev = dev_get_drvdata(dev); 34 u32 config = mgb4_read_reg(&mgbdev->video, 0xC4); 35 36 return sprintf(buf, "%u\n", config & 0xFFFF); 37 } 38 39 static ssize_t fw_type_show(struct device *dev, 40 struct device_attribute *attr, char *buf) 41 { 42 struct mgb4_dev *mgbdev = dev_get_drvdata(dev); 43 u32 config = mgb4_read_reg(&mgbdev->video, 0xC4); 44 45 return sprintf(buf, "%u\n", config >> 24); 46 } 47 48 static ssize_t serial_number_show(struct device *dev, 49 struct device_attribute *attr, char *buf) 50 { 51 struct mgb4_dev *mgbdev = dev_get_drvdata(dev); 52 u32 sn = mgbdev->serial_number; 53 54 return sprintf(buf, "%03d-%03d-%03d-%03d\n", sn >> 24, (sn >> 16) & 0xFF, 55 (sn >> 8) & 0xFF, sn & 0xFF); 56 } 57 58 static DEVICE_ATTR_RO(module_version); 59 static DEVICE_ATTR_RO(module_type); 60 static DEVICE_ATTR_RO(fw_version); 61 static DEVICE_ATTR_RO(fw_type); 62 static DEVICE_ATTR_RO(serial_number); 63 64 struct attribute *mgb4_pci_attrs[] = { 65 &dev_attr_module_type.attr, 66 &dev_attr_module_version.attr, 67 &dev_attr_fw_type.attr, 68 &dev_attr_fw_version.attr, 69 &dev_attr_serial_number.attr, 70 NULL 71 }; 72