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_PWM_MAX 0x3f
22 #define LM3533_REG_PWM_BASE 0x14
23 #define LM3533_REG_MAX_CURRENT_BASE 0x1f
24 #define LM3533_REG_CTRLBANK_ENABLE 0x27
25 #define LM3533_REG_BRIGHTNESS_BASE 0x40
28 static inline u8 lm3533_ctrlbank_get_reg(struct lm3533_ctrlbank *cb, u8 base)
33 int lm3533_ctrlbank_enable(struct lm3533_ctrlbank *cb)
38 dev_dbg(cb->dev, "%s - %d\n", __func__, cb->id);
41 ret = lm3533_update(cb->lm3533, LM3533_REG_CTRLBANK_ENABLE,
44 dev_err(cb->dev, "failed to enable ctrlbank %d\n", cb->id);
48 EXPORT_SYMBOL_GPL(lm3533_ctrlbank_enable);
50 int lm3533_ctrlbank_disable(struct lm3533_ctrlbank *cb)
55 dev_dbg(cb->dev, "%s - %d\n", __func__, cb->id);
58 ret = lm3533_update(cb->lm3533, LM3533_REG_CTRLBANK_ENABLE, 0, mask);
60 dev_err(cb->dev, "failed to disable ctrlbank %d\n", cb->id);
64 EXPORT_SYMBOL_GPL(lm3533_ctrlbank_disable);
69 * imax 5000 - 29800 uA (800 uA step)
71 int lm3533_ctrlbank_set_max_current(struct lm3533_ctrlbank *cb, u16 imax)
77 if (imax < LM3533_MAX_CURRENT_MIN || imax > LM3533_MAX_CURRENT_MAX)
80 val = (imax - LM3533_MAX_CURRENT_MIN) / LM3533_MAX_CURRENT_STEP;
82 reg = lm3533_ctrlbank_get_reg(cb, LM3533_REG_MAX_CURRENT_BASE);
83 ret = lm3533_write(cb->lm3533, reg, val);
85 dev_err(cb->dev, "failed to set max current\n");
89 EXPORT_SYMBOL_GPL(lm3533_ctrlbank_set_max_current);
91 int lm3533_ctrlbank_set_brightness(struct lm3533_ctrlbank *cb, u8 val)
96 reg = lm3533_ctrlbank_get_reg(cb, LM3533_REG_BRIGHTNESS_BASE);
97 ret = lm3533_write(cb->lm3533, reg, val);
99 dev_err(cb->dev, "failed to set brightness\n");
103 EXPORT_SYMBOL_GPL(lm3533_ctrlbank_set_brightness);
105 int lm3533_ctrlbank_get_brightness(struct lm3533_ctrlbank *cb, u8 *val)
110 reg = lm3533_ctrlbank_get_reg(cb, LM3533_REG_BRIGHTNESS_BASE);
111 ret = lm3533_read(cb->lm3533, reg, val);
113 dev_err(cb->dev, "failed to get brightness\n");
117 EXPORT_SYMBOL_GPL(lm3533_ctrlbank_get_brightness);
120 * PWM-input control mask:
122 * bit 5 - PWM-input enabled in Zone 4
123 * bit 4 - PWM-input enabled in Zone 3
124 * bit 3 - PWM-input enabled in Zone 2
125 * bit 2 - PWM-input enabled in Zone 1
126 * bit 1 - PWM-input enabled in Zone 0
127 * bit 0 - PWM-input enabled
129 int lm3533_ctrlbank_set_pwm(struct lm3533_ctrlbank *cb, u8 val)
134 if (val > LM3533_PWM_MAX)
137 reg = lm3533_ctrlbank_get_reg(cb, LM3533_REG_PWM_BASE);
138 ret = lm3533_write(cb->lm3533, reg, val);
140 dev_err(cb->dev, "failed to set PWM mask\n");
144 EXPORT_SYMBOL_GPL(lm3533_ctrlbank_set_pwm);
146 int lm3533_ctrlbank_get_pwm(struct lm3533_ctrlbank *cb, u8 *val)
151 reg = lm3533_ctrlbank_get_reg(cb, LM3533_REG_PWM_BASE);
152 ret = lm3533_read(cb->lm3533, reg, val);
154 dev_err(cb->dev, "failed to get PWM mask\n");
158 EXPORT_SYMBOL_GPL(lm3533_ctrlbank_get_pwm);
160 MODULE_AUTHOR("Johan Hovold <jhovold@gmail.com>");
161 MODULE_DESCRIPTION("LM3533 Control Bank interface");
162 MODULE_LICENSE("GPL");