1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * lm3533-ctrlbank.c -- LM3533 Generic Control Bank interface
5 * Copyright (C) 2011-2012 Texas Instruments
7 * Author: Johan Hovold <jhovold@gmail.com>
10 #include <linux/device.h>
11 #include <linux/module.h>
13 #include <linux/mfd/lm3533.h>
16 #define LM3533_MAX_CURRENT_MIN 5000
17 #define LM3533_MAX_CURRENT_MAX 29800
18 #define LM3533_MAX_CURRENT_STEP 800
20 #define LM3533_BRIGHTNESS_MAX 255
21 #define LM3533_PWM_MAX 0x3f
23 #define LM3533_REG_PWM_BASE 0x14
24 #define LM3533_REG_MAX_CURRENT_BASE 0x1f
25 #define LM3533_REG_CTRLBANK_ENABLE 0x27
26 #define LM3533_REG_BRIGHTNESS_BASE 0x40
29 static inline u8
lm3533_ctrlbank_get_reg(struct lm3533_ctrlbank
*cb
, u8 base
)
34 int lm3533_ctrlbank_enable(struct lm3533_ctrlbank
*cb
)
39 dev_dbg(cb
->dev
, "%s - %d\n", __func__
, cb
->id
);
42 ret
= lm3533_update(cb
->lm3533
, LM3533_REG_CTRLBANK_ENABLE
,
45 dev_err(cb
->dev
, "failed to enable ctrlbank %d\n", cb
->id
);
49 EXPORT_SYMBOL_GPL(lm3533_ctrlbank_enable
);
51 int lm3533_ctrlbank_disable(struct lm3533_ctrlbank
*cb
)
56 dev_dbg(cb
->dev
, "%s - %d\n", __func__
, cb
->id
);
59 ret
= lm3533_update(cb
->lm3533
, LM3533_REG_CTRLBANK_ENABLE
, 0, mask
);
61 dev_err(cb
->dev
, "failed to disable ctrlbank %d\n", cb
->id
);
65 EXPORT_SYMBOL_GPL(lm3533_ctrlbank_disable
);
70 * imax 5000 - 29800 uA (800 uA step)
72 int lm3533_ctrlbank_set_max_current(struct lm3533_ctrlbank
*cb
, u16 imax
)
78 if (imax
< LM3533_MAX_CURRENT_MIN
|| imax
> LM3533_MAX_CURRENT_MAX
)
81 val
= (imax
- LM3533_MAX_CURRENT_MIN
) / LM3533_MAX_CURRENT_STEP
;
83 reg
= lm3533_ctrlbank_get_reg(cb
, LM3533_REG_MAX_CURRENT_BASE
);
84 ret
= lm3533_write(cb
->lm3533
, reg
, val
);
86 dev_err(cb
->dev
, "failed to set max current\n");
90 EXPORT_SYMBOL_GPL(lm3533_ctrlbank_set_max_current
);
92 #define lm3533_ctrlbank_set(_name, _NAME) \
93 int lm3533_ctrlbank_set_##_name(struct lm3533_ctrlbank *cb, u8 val) \
98 if (val > LM3533_##_NAME##_MAX) \
101 reg = lm3533_ctrlbank_get_reg(cb, LM3533_REG_##_NAME##_BASE); \
102 ret = lm3533_write(cb->lm3533, reg, val); \
104 dev_err(cb->dev, "failed to set " #_name "\n"); \
108 EXPORT_SYMBOL_GPL(lm3533_ctrlbank_set_##_name);
110 #define lm3533_ctrlbank_get(_name, _NAME) \
111 int lm3533_ctrlbank_get_##_name(struct lm3533_ctrlbank *cb, u8 *val) \
116 reg = lm3533_ctrlbank_get_reg(cb, LM3533_REG_##_NAME##_BASE); \
117 ret = lm3533_read(cb->lm3533, reg, val); \
119 dev_err(cb->dev, "failed to get " #_name "\n"); \
123 EXPORT_SYMBOL_GPL(lm3533_ctrlbank_get_##_name);
125 lm3533_ctrlbank_set(brightness
, BRIGHTNESS
);
126 lm3533_ctrlbank_get(brightness
, BRIGHTNESS
);
129 * PWM-input control mask:
131 * bit 5 - PWM-input enabled in Zone 4
132 * bit 4 - PWM-input enabled in Zone 3
133 * bit 3 - PWM-input enabled in Zone 2
134 * bit 2 - PWM-input enabled in Zone 1
135 * bit 1 - PWM-input enabled in Zone 0
136 * bit 0 - PWM-input enabled
138 lm3533_ctrlbank_set(pwm
, PWM
);
139 lm3533_ctrlbank_get(pwm
, PWM
);
142 MODULE_AUTHOR("Johan Hovold <jhovold@gmail.com>");
143 MODULE_DESCRIPTION("LM3533 Control Bank interface");
144 MODULE_LICENSE("GPL");