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

pwm: mc33xs2410: add hwmon support

Support for hwmon is provided by a separate driver residing in hwmon
subsystem which is implemented as auxiliary device. Add handling of this
device.

Signed-off-by: Dimitri Fedrau <dimitri.fedrau@liebherr.com>
Link: https://lore.kernel.org/r/20250723-mc33xs2410-hwmon-v5-1-f62aab71cd59@liebherr.com
Signed-off-by: Uwe Kleine-König <ukleinek@kernel.org>

authored by

Dimitri Fedrau and committed by
Uwe Kleine-König
28517c8b a5824695

+35 -2
+1
drivers/pwm/Kconfig
··· 436 436 tristate "MC33XS2410 PWM support" 437 437 depends on OF 438 438 depends on SPI 439 + select AUXILIARY_BUS 439 440 help 440 441 NXP MC33XS2410 high-side switch driver. The MC33XS2410 is a four 441 442 channel high-side switch. The device is operational from 3.0 V
+18 -2
drivers/pwm/pwm-mc33xs2410.c
··· 17 17 * behavior of the output pin that is neither the old nor the new state, 18 18 * rather something in between. 19 19 */ 20 + #define DEFAULT_SYMBOL_NAMESPACE "PWM_MC33XS2410" 20 21 22 + #include <linux/auxiliary_bus.h> 21 23 #include <linux/bitfield.h> 22 24 #include <linux/delay.h> 23 25 #include <linux/err.h> 24 26 #include <linux/math64.h> 27 + #include <linux/mc33xs2410.h> 25 28 #include <linux/minmax.h> 26 29 #include <linux/module.h> 27 30 #include <linux/of.h> ··· 123 120 return mc33xs2410_read_regs(spi, &reg, flag, val, 1); 124 121 } 125 122 126 - static int mc33xs2410_read_reg_ctrl(struct spi_device *spi, u8 reg, u16 *val) 123 + int mc33xs2410_read_reg_ctrl(struct spi_device *spi, u8 reg, u16 *val) 127 124 { 128 125 return mc33xs2410_read_reg(spi, reg, val, MC33XS2410_FRAME_IN_DATA_RD); 129 126 } 127 + EXPORT_SYMBOL_GPL(mc33xs2410_read_reg_ctrl); 130 128 131 - static int mc33xs2410_modify_reg(struct spi_device *spi, u8 reg, u8 mask, u8 val) 129 + int mc33xs2410_read_reg_diag(struct spi_device *spi, u8 reg, u16 *val) 130 + { 131 + return mc33xs2410_read_reg(spi, reg, val, 0); 132 + } 133 + EXPORT_SYMBOL_GPL(mc33xs2410_read_reg_diag); 134 + 135 + int mc33xs2410_modify_reg(struct spi_device *spi, u8 reg, u8 mask, u8 val) 132 136 { 133 137 u16 tmp; 134 138 int ret; ··· 149 139 150 140 return mc33xs2410_write_reg(spi, reg, tmp); 151 141 } 142 + EXPORT_SYMBOL_GPL(mc33xs2410_modify_reg); 152 143 153 144 static u8 mc33xs2410_pwm_get_freq(u64 period) 154 145 { ··· 325 314 static int mc33xs2410_probe(struct spi_device *spi) 326 315 { 327 316 struct device *dev = &spi->dev; 317 + struct auxiliary_device *adev; 328 318 struct pwm_chip *chip; 329 319 int ret; 330 320 ··· 372 360 ret = devm_pwmchip_add(dev, chip); 373 361 if (ret < 0) 374 362 return dev_err_probe(dev, ret, "Failed to add pwm chip\n"); 363 + 364 + adev = devm_auxiliary_device_create(dev, "hwmon", NULL); 365 + if (!adev) 366 + return dev_err_probe(dev, -ENODEV, "Failed to register hwmon device\n"); 375 367 376 368 return 0; 377 369 }
+16
include/linux/mc33xs2410.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0 */ 2 + /* 3 + * Copyright (C) 2024 Liebherr-Electronics and Drives GmbH 4 + */ 5 + #ifndef _MC33XS2410_H 6 + #define _MC33XS2410_H 7 + 8 + #include <linux/spi/spi.h> 9 + 10 + MODULE_IMPORT_NS("PWM_MC33XS2410"); 11 + 12 + int mc33xs2410_read_reg_ctrl(struct spi_device *spi, u8 reg, u16 *val); 13 + int mc33xs2410_read_reg_diag(struct spi_device *spi, u8 reg, u16 *val); 14 + int mc33xs2410_modify_reg(struct spi_device *spi, u8 reg, u8 mask, u8 val); 15 + 16 + #endif /* _MC33XS2410_H */