Skip to content

Commit 28517c8

Browse files
DimitriFedrauUwe Kleine-König
authored andcommitted
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 <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Uwe Kleine-König <[email protected]>
1 parent a582469 commit 28517c8

File tree

3 files changed

+35
-2
lines changed

3 files changed

+35
-2
lines changed

drivers/pwm/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,7 @@ config PWM_MC33XS2410
436436
tristate "MC33XS2410 PWM support"
437437
depends on OF
438438
depends on SPI
439+
select AUXILIARY_BUS
439440
help
440441
NXP MC33XS2410 high-side switch driver. The MC33XS2410 is a four
441442
channel high-side switch. The device is operational from 3.0 V

drivers/pwm/pwm-mc33xs2410.c

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,14 @@
1717
* behavior of the output pin that is neither the old nor the new state,
1818
* rather something in between.
1919
*/
20+
#define DEFAULT_SYMBOL_NAMESPACE "PWM_MC33XS2410"
2021

22+
#include <linux/auxiliary_bus.h>
2123
#include <linux/bitfield.h>
2224
#include <linux/delay.h>
2325
#include <linux/err.h>
2426
#include <linux/math64.h>
27+
#include <linux/mc33xs2410.h>
2528
#include <linux/minmax.h>
2629
#include <linux/module.h>
2730
#include <linux/of.h>
@@ -120,12 +123,19 @@ static int mc33xs2410_read_reg(struct spi_device *spi, u8 reg, u16 *val, u8 flag
120123
return mc33xs2410_read_regs(spi, &reg, flag, val, 1);
121124
}
122125

123-
static int mc33xs2410_read_reg_ctrl(struct spi_device *spi, u8 reg, u16 *val)
126+
int mc33xs2410_read_reg_ctrl(struct spi_device *spi, u8 reg, u16 *val)
124127
{
125128
return mc33xs2410_read_reg(spi, reg, val, MC33XS2410_FRAME_IN_DATA_RD);
126129
}
130+
EXPORT_SYMBOL_GPL(mc33xs2410_read_reg_ctrl);
127131

128-
static int mc33xs2410_modify_reg(struct spi_device *spi, u8 reg, u8 mask, u8 val)
132+
int mc33xs2410_read_reg_diag(struct spi_device *spi, u8 reg, u16 *val)
133+
{
134+
return mc33xs2410_read_reg(spi, reg, val, 0);
135+
}
136+
EXPORT_SYMBOL_GPL(mc33xs2410_read_reg_diag);
137+
138+
int mc33xs2410_modify_reg(struct spi_device *spi, u8 reg, u8 mask, u8 val)
129139
{
130140
u16 tmp;
131141
int ret;
@@ -139,6 +149,7 @@ static int mc33xs2410_modify_reg(struct spi_device *spi, u8 reg, u8 mask, u8 val
139149

140150
return mc33xs2410_write_reg(spi, reg, tmp);
141151
}
152+
EXPORT_SYMBOL_GPL(mc33xs2410_modify_reg);
142153

143154
static u8 mc33xs2410_pwm_get_freq(u64 period)
144155
{
@@ -314,6 +325,7 @@ static int mc33xs2410_reset(struct device *dev)
314325
static int mc33xs2410_probe(struct spi_device *spi)
315326
{
316327
struct device *dev = &spi->dev;
328+
struct auxiliary_device *adev;
317329
struct pwm_chip *chip;
318330
int ret;
319331

@@ -361,6 +373,10 @@ static int mc33xs2410_probe(struct spi_device *spi)
361373
if (ret < 0)
362374
return dev_err_probe(dev, ret, "Failed to add pwm chip\n");
363375

376+
adev = devm_auxiliary_device_create(dev, "hwmon", NULL);
377+
if (!adev)
378+
return dev_err_probe(dev, -ENODEV, "Failed to register hwmon device\n");
379+
364380
return 0;
365381
}
366382

include/linux/mc33xs2410.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
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 */

0 commit comments

Comments
 (0)