Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

mfd: intel-m10-bmc: Split into core and spi specific parts

Split the common code from intel-m10-bmc driver into intel-m10-bmc-core
and move the SPI bus parts into an interface specific file.

intel-m10-bmc-core becomes the core MFD functions which can support
multiple bus interface like SPI bus.

Co-developed-by: Tianfei zhang <tianfei.zhang@intel.com>
Signed-off-by: Tianfei zhang <tianfei.zhang@intel.com>
Reviewed-by: Russ Weight <russell.h.weight@intel.com>
Acked-by: Guenter Roeck <linux@roeck-us.net> # hwmon
Reviewed-by: Xu Yilun <yilun.xu@intel.com>
Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Signed-off-by: Lee Jones <lee@kernel.org>
Link: https://lore.kernel.org/r/20230116100845.6153-5-ilpo.jarvinen@linux.intel.com

authored by

Ilpo Järvinen and committed by
Lee Jones
603aed8f 85ba4690

+171 -123
+1 -1
MAINTAINERS
··· 10576 10576 F: Documentation/ABI/testing/sysfs-driver-intel-m10-bmc 10577 10577 F: Documentation/hwmon/intel-m10-bmc-hwmon.rst 10578 10578 F: drivers/hwmon/intel-m10-bmc-hwmon.c 10579 - F: drivers/mfd/intel-m10-bmc.c 10579 + F: drivers/mfd/intel-m10-bmc* 10580 10580 F: include/linux/mfd/intel-m10-bmc.h 10581 10581 10582 10582 INTEL MENLOW THERMAL DRIVER
+1 -1
drivers/fpga/Kconfig
··· 246 246 247 247 config FPGA_M10_BMC_SEC_UPDATE 248 248 tristate "Intel MAX10 BMC Secure Update driver" 249 - depends on MFD_INTEL_M10_BMC 249 + depends on MFD_INTEL_M10_BMC_CORE 250 250 select FW_LOADER 251 251 select FW_UPLOAD 252 252 help
+1 -1
drivers/hwmon/Kconfig
··· 2341 2341 2342 2342 config SENSORS_INTEL_M10_BMC_HWMON 2343 2343 tristate "Intel MAX10 BMC Hardware Monitoring" 2344 - depends on MFD_INTEL_M10_BMC 2344 + depends on MFD_INTEL_M10_BMC_CORE 2345 2345 help 2346 2346 This driver provides support for the hardware monitoring functionality 2347 2347 on Intel MAX10 BMC chip.
+17 -11
drivers/mfd/Kconfig
··· 2224 2224 If you have an SGI Origin, Octane, or a PCI IOC3 card, 2225 2225 then say Y. Otherwise say N. 2226 2226 2227 - config MFD_INTEL_M10_BMC 2228 - tristate "Intel MAX 10 Board Management Controller" 2229 - depends on SPI_MASTER 2230 - select REGMAP_SPI_AVMM 2231 - select MFD_CORE 2232 - help 2233 - Support for the Intel MAX 10 board management controller using the 2234 - SPI interface. 2227 + config MFD_INTEL_M10_BMC_CORE 2228 + tristate 2229 + select MFD_CORE 2230 + select REGMAP 2231 + default n 2235 2232 2236 - This driver provides common support for accessing the device, 2237 - additional drivers must be enabled in order to use the functionality 2238 - of the device. 2233 + config MFD_INTEL_M10_BMC_SPI 2234 + tristate "Intel MAX 10 Board Management Controller with SPI" 2235 + depends on SPI_MASTER 2236 + select MFD_INTEL_M10_BMC_CORE 2237 + select REGMAP_SPI_AVMM 2238 + help 2239 + Support for the Intel MAX 10 board management controller using the 2240 + SPI interface. 2241 + 2242 + This driver provides common support for accessing the device, 2243 + additional drivers must be enabled in order to use the functionality 2244 + of the device. 2239 2245 2240 2246 config MFD_RSMU_I2C 2241 2247 tristate "Renesas Synchronization Management Unit with I2C"
+3 -1
drivers/mfd/Makefile
··· 269 269 obj-$(CONFIG_SGI_MFD_IOC3) += ioc3.o 270 270 obj-$(CONFIG_MFD_SIMPLE_MFD_I2C) += simple-mfd-i2c.o 271 271 obj-$(CONFIG_MFD_SMPRO) += smpro-core.o 272 - obj-$(CONFIG_MFD_INTEL_M10_BMC) += intel-m10-bmc.o 272 + 273 + obj-$(CONFIG_MFD_INTEL_M10_BMC_CORE) += intel-m10-bmc-core.o 274 + obj-$(CONFIG_MFD_INTEL_M10_BMC_SPI) += intel-m10-bmc-spi.o 273 275 274 276 obj-$(CONFIG_MFD_ATC260X) += atc260x-core.o 275 277 obj-$(CONFIG_MFD_ATC260X_I2C) += atc260x-i2c.o
+122
drivers/mfd/intel-m10-bmc-core.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + /* 3 + * Intel MAX 10 Board Management Controller chip - common code 4 + * 5 + * Copyright (C) 2018-2020 Intel Corporation. All rights reserved. 6 + */ 7 + 8 + #include <linux/bitfield.h> 9 + #include <linux/device.h> 10 + #include <linux/dev_printk.h> 11 + #include <linux/mfd/core.h> 12 + #include <linux/mfd/intel-m10-bmc.h> 13 + #include <linux/module.h> 14 + 15 + static ssize_t bmc_version_show(struct device *dev, 16 + struct device_attribute *attr, char *buf) 17 + { 18 + struct intel_m10bmc *ddata = dev_get_drvdata(dev); 19 + unsigned int val; 20 + int ret; 21 + 22 + ret = m10bmc_sys_read(ddata, M10BMC_BUILD_VER, &val); 23 + if (ret) 24 + return ret; 25 + 26 + return sprintf(buf, "0x%x\n", val); 27 + } 28 + static DEVICE_ATTR_RO(bmc_version); 29 + 30 + static ssize_t bmcfw_version_show(struct device *dev, 31 + struct device_attribute *attr, char *buf) 32 + { 33 + struct intel_m10bmc *ddata = dev_get_drvdata(dev); 34 + unsigned int val; 35 + int ret; 36 + 37 + ret = m10bmc_sys_read(ddata, NIOS2_FW_VERSION, &val); 38 + if (ret) 39 + return ret; 40 + 41 + return sprintf(buf, "0x%x\n", val); 42 + } 43 + static DEVICE_ATTR_RO(bmcfw_version); 44 + 45 + static ssize_t mac_address_show(struct device *dev, 46 + struct device_attribute *attr, char *buf) 47 + { 48 + struct intel_m10bmc *ddata = dev_get_drvdata(dev); 49 + unsigned int macaddr_low, macaddr_high; 50 + int ret; 51 + 52 + ret = m10bmc_sys_read(ddata, M10BMC_MAC_LOW, &macaddr_low); 53 + if (ret) 54 + return ret; 55 + 56 + ret = m10bmc_sys_read(ddata, M10BMC_MAC_HIGH, &macaddr_high); 57 + if (ret) 58 + return ret; 59 + 60 + return sysfs_emit(buf, "%02x:%02x:%02x:%02x:%02x:%02x\n", 61 + (u8)FIELD_GET(M10BMC_MAC_BYTE1, macaddr_low), 62 + (u8)FIELD_GET(M10BMC_MAC_BYTE2, macaddr_low), 63 + (u8)FIELD_GET(M10BMC_MAC_BYTE3, macaddr_low), 64 + (u8)FIELD_GET(M10BMC_MAC_BYTE4, macaddr_low), 65 + (u8)FIELD_GET(M10BMC_MAC_BYTE5, macaddr_high), 66 + (u8)FIELD_GET(M10BMC_MAC_BYTE6, macaddr_high)); 67 + } 68 + static DEVICE_ATTR_RO(mac_address); 69 + 70 + static ssize_t mac_count_show(struct device *dev, 71 + struct device_attribute *attr, char *buf) 72 + { 73 + struct intel_m10bmc *ddata = dev_get_drvdata(dev); 74 + unsigned int macaddr_high; 75 + int ret; 76 + 77 + ret = m10bmc_sys_read(ddata, M10BMC_MAC_HIGH, &macaddr_high); 78 + if (ret) 79 + return ret; 80 + 81 + return sysfs_emit(buf, "%u\n", (u8)FIELD_GET(M10BMC_MAC_COUNT, macaddr_high)); 82 + } 83 + static DEVICE_ATTR_RO(mac_count); 84 + 85 + static struct attribute *m10bmc_attrs[] = { 86 + &dev_attr_bmc_version.attr, 87 + &dev_attr_bmcfw_version.attr, 88 + &dev_attr_mac_address.attr, 89 + &dev_attr_mac_count.attr, 90 + NULL, 91 + }; 92 + 93 + static const struct attribute_group m10bmc_group = { 94 + .attrs = m10bmc_attrs, 95 + }; 96 + 97 + const struct attribute_group *m10bmc_dev_groups[] = { 98 + &m10bmc_group, 99 + NULL, 100 + }; 101 + EXPORT_SYMBOL_GPL(m10bmc_dev_groups); 102 + 103 + int m10bmc_dev_init(struct intel_m10bmc *m10bmc, const struct intel_m10bmc_platform_info *info) 104 + { 105 + int ret; 106 + 107 + m10bmc->info = info; 108 + dev_set_drvdata(m10bmc->dev, m10bmc); 109 + 110 + ret = devm_mfd_add_devices(m10bmc->dev, PLATFORM_DEVID_AUTO, 111 + info->cells, info->n_cells, 112 + NULL, 0, NULL); 113 + if (ret) 114 + dev_err(m10bmc->dev, "Failed to register sub-devices: %d\n", ret); 115 + 116 + return ret; 117 + } 118 + EXPORT_SYMBOL_GPL(m10bmc_dev_init); 119 + 120 + MODULE_DESCRIPTION("Intel MAX 10 BMC core driver"); 121 + MODULE_AUTHOR("Intel Corporation"); 122 + MODULE_LICENSE("GPL v2");
+20 -108
drivers/mfd/intel-m10-bmc.c drivers/mfd/intel-m10-bmc-spi.c
··· 5 5 * Copyright (C) 2018-2020 Intel Corporation. All rights reserved. 6 6 */ 7 7 #include <linux/bitfield.h> 8 + #include <linux/dev_printk.h> 8 9 #include <linux/init.h> 9 10 #include <linux/mfd/core.h> 10 11 #include <linux/mfd/intel-m10-bmc.h> 11 12 #include <linux/module.h> 12 - #include <linux/mutex.h> 13 13 #include <linux/regmap.h> 14 14 #include <linux/spi/spi.h> 15 - 16 - static struct mfd_cell m10bmc_d5005_subdevs[] = { 17 - { .name = "d5005bmc-hwmon" }, 18 - { .name = "d5005bmc-sec-update" } 19 - }; 20 - 21 - static struct mfd_cell m10bmc_pacn3000_subdevs[] = { 22 - { .name = "n3000bmc-hwmon" }, 23 - { .name = "n3000bmc-retimer" }, 24 - { .name = "n3000bmc-sec-update" }, 25 - }; 26 - 27 - static struct mfd_cell m10bmc_n5010_subdevs[] = { 28 - { .name = "n5010bmc-hwmon" }, 29 - }; 30 15 31 16 static const struct regmap_range m10bmc_regmap_range[] = { 32 17 regmap_reg_range(M10BMC_LEGACY_BUILD_VER, M10BMC_LEGACY_BUILD_VER), ··· 32 47 .rd_table = &m10bmc_access_table, 33 48 .max_register = M10BMC_MEM_END, 34 49 }; 35 - 36 - static ssize_t bmc_version_show(struct device *dev, 37 - struct device_attribute *attr, char *buf) 38 - { 39 - struct intel_m10bmc *ddata = dev_get_drvdata(dev); 40 - unsigned int val; 41 - int ret; 42 - 43 - ret = m10bmc_sys_read(ddata, M10BMC_BUILD_VER, &val); 44 - if (ret) 45 - return ret; 46 - 47 - return sprintf(buf, "0x%x\n", val); 48 - } 49 - static DEVICE_ATTR_RO(bmc_version); 50 - 51 - static ssize_t bmcfw_version_show(struct device *dev, 52 - struct device_attribute *attr, char *buf) 53 - { 54 - struct intel_m10bmc *ddata = dev_get_drvdata(dev); 55 - unsigned int val; 56 - int ret; 57 - 58 - ret = m10bmc_sys_read(ddata, NIOS2_FW_VERSION, &val); 59 - if (ret) 60 - return ret; 61 - 62 - return sprintf(buf, "0x%x\n", val); 63 - } 64 - static DEVICE_ATTR_RO(bmcfw_version); 65 - 66 - static ssize_t mac_address_show(struct device *dev, 67 - struct device_attribute *attr, char *buf) 68 - { 69 - struct intel_m10bmc *ddata = dev_get_drvdata(dev); 70 - unsigned int macaddr_low, macaddr_high; 71 - int ret; 72 - 73 - ret = m10bmc_sys_read(ddata, M10BMC_MAC_LOW, &macaddr_low); 74 - if (ret) 75 - return ret; 76 - 77 - ret = m10bmc_sys_read(ddata, M10BMC_MAC_HIGH, &macaddr_high); 78 - if (ret) 79 - return ret; 80 - 81 - return sysfs_emit(buf, "%02x:%02x:%02x:%02x:%02x:%02x\n", 82 - (u8)FIELD_GET(M10BMC_MAC_BYTE1, macaddr_low), 83 - (u8)FIELD_GET(M10BMC_MAC_BYTE2, macaddr_low), 84 - (u8)FIELD_GET(M10BMC_MAC_BYTE3, macaddr_low), 85 - (u8)FIELD_GET(M10BMC_MAC_BYTE4, macaddr_low), 86 - (u8)FIELD_GET(M10BMC_MAC_BYTE5, macaddr_high), 87 - (u8)FIELD_GET(M10BMC_MAC_BYTE6, macaddr_high)); 88 - } 89 - static DEVICE_ATTR_RO(mac_address); 90 - 91 - static ssize_t mac_count_show(struct device *dev, 92 - struct device_attribute *attr, char *buf) 93 - { 94 - struct intel_m10bmc *ddata = dev_get_drvdata(dev); 95 - unsigned int macaddr_high; 96 - int ret; 97 - 98 - ret = m10bmc_sys_read(ddata, M10BMC_MAC_HIGH, &macaddr_high); 99 - if (ret) 100 - return ret; 101 - 102 - return sysfs_emit(buf, "%u\n", 103 - (u8)FIELD_GET(M10BMC_MAC_COUNT, macaddr_high)); 104 - } 105 - static DEVICE_ATTR_RO(mac_count); 106 - 107 - static struct attribute *m10bmc_attrs[] = { 108 - &dev_attr_bmc_version.attr, 109 - &dev_attr_bmcfw_version.attr, 110 - &dev_attr_mac_address.attr, 111 - &dev_attr_mac_count.attr, 112 - NULL, 113 - }; 114 - ATTRIBUTE_GROUPS(m10bmc); 115 50 116 51 static int check_m10bmc_version(struct intel_m10bmc *ddata) 117 52 { ··· 71 166 return -ENOMEM; 72 167 73 168 info = (struct intel_m10bmc_platform_info *)id->driver_data; 74 - ddata->info = info; 75 169 ddata->dev = dev; 76 170 77 - ddata->regmap = 78 - devm_regmap_init_spi_avmm(spi, &intel_m10bmc_regmap_config); 171 + ddata->regmap = devm_regmap_init_spi_avmm(spi, &intel_m10bmc_regmap_config); 79 172 if (IS_ERR(ddata->regmap)) { 80 173 ret = PTR_ERR(ddata->regmap); 81 174 dev_err(dev, "Failed to allocate regmap: %d\n", ret); ··· 88 185 return ret; 89 186 } 90 187 91 - ret = devm_mfd_add_devices(dev, PLATFORM_DEVID_AUTO, 92 - info->cells, info->n_cells, 93 - NULL, 0, NULL); 94 - if (ret) 95 - dev_err(dev, "Failed to register sub-devices: %d\n", ret); 96 - 97 - return ret; 188 + return m10bmc_dev_init(ddata, info); 98 189 } 190 + 191 + static struct mfd_cell m10bmc_d5005_subdevs[] = { 192 + { .name = "d5005bmc-hwmon" }, 193 + { .name = "d5005bmc-sec-update" }, 194 + }; 195 + 196 + static struct mfd_cell m10bmc_pacn3000_subdevs[] = { 197 + { .name = "n3000bmc-hwmon" }, 198 + { .name = "n3000bmc-retimer" }, 199 + { .name = "n3000bmc-sec-update" }, 200 + }; 201 + 202 + static struct mfd_cell m10bmc_n5010_subdevs[] = { 203 + { .name = "n5010bmc-hwmon" }, 204 + }; 99 205 100 206 static const struct intel_m10bmc_platform_info m10bmc_spi_n3000 = { 101 207 .cells = m10bmc_pacn3000_subdevs, ··· 132 220 static struct spi_driver intel_m10bmc_spi_driver = { 133 221 .driver = { 134 222 .name = "intel-m10-bmc", 135 - .dev_groups = m10bmc_groups, 223 + .dev_groups = m10bmc_dev_groups, 136 224 }, 137 225 .probe = intel_m10_bmc_spi_probe, 138 226 .id_table = m10bmc_spi_id, 139 227 }; 140 228 module_spi_driver(intel_m10bmc_spi_driver); 141 229 142 - MODULE_DESCRIPTION("Intel MAX 10 BMC Device Driver"); 230 + MODULE_DESCRIPTION("Intel MAX 10 BMC SPI bus interface"); 143 231 MODULE_AUTHOR("Intel Corporation"); 144 232 MODULE_LICENSE("GPL v2"); 145 233 MODULE_ALIAS("spi:intel-m10-bmc");
+6
include/linux/mfd/intel-m10-bmc.h
··· 174 174 #define m10bmc_sys_read(m10bmc, offset, val) \ 175 175 m10bmc_raw_read(m10bmc, M10BMC_SYS_BASE + (offset), val) 176 176 177 + /* 178 + * MAX10 BMC Core support 179 + */ 180 + int m10bmc_dev_init(struct intel_m10bmc *m10bmc, const struct intel_m10bmc_platform_info *info); 181 + extern const struct attribute_group *m10bmc_dev_groups[]; 182 + 177 183 #endif /* __MFD_INTEL_M10_BMC_H */