2 * lm3533-ctrlbank.c -- LM3533 Generic Control Bank interface
4 * Copyright (C) 2011-2012 Texas Instruments
6 * Author: Johan Hovold <jhovold@gmail.com>
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the
10 * Free Software Foundation; either version 2 of the License, or (at your
11 * option) any later version.
14 #include <linux/device.h>
15 #include <linux/module.h>
17 #include <linux/mfd/lm3533.h>
20 #define LM3533_MAX_CURRENT_MIN 5000
21 #define LM3533_MAX_CURRENT_MAX 29800
22 #define LM3533_MAX_CURRENT_STEP 800
24 #define LM3533_BRIGHTNESS_MAX 255
25 #define LM3533_PWM_MAX 0x3f
27 #define LM3533_REG_PWM_BASE 0x14
28 #define LM3533_REG_MAX_CURRENT_BASE 0x1f
29 #define LM3533_REG_CTRLBANK_ENABLE 0x27
30 #define LM3533_REG_BRIGHTNESS_BASE 0x40
33 static inline u8 lm3533_ctrlbank_get_reg(struct lm3533_ctrlbank *cb, u8 base)
38 int lm3533_ctrlbank_enable(struct lm3533_ctrlbank *cb)
43 dev_dbg(cb->dev, "%s - %d\n", __func__, cb->id);
46 ret = lm3533_update(cb->lm3533, LM3533_REG_CTRLBANK_ENABLE,
49 dev_err(cb->dev, "failed to enable ctrlbank %d\n", cb->id);
53 EXPORT_SYMBOL_GPL(lm3533_ctrlbank_enable);
55 int lm3533_ctrlbank_disable(struct lm3533_ctrlbank *cb)
60 dev_dbg(cb->dev, "%s - %d\n", __func__, cb->id);
63 ret = lm3533_update(cb->lm3533, LM3533_REG_CTRLBANK_ENABLE, 0, mask);
65 dev_err(cb->dev, "failed to disable ctrlbank %d\n", cb->id);
69 EXPORT_SYMBOL_GPL(lm3533_ctrlbank_disable);
74 * imax 5000 - 29800 uA (800 uA step)
76 int lm3533_ctrlbank_set_max_current(struct lm3533_ctrlbank *cb, u16 imax)
82 if (imax < LM3533_MAX_CURRENT_MIN || imax > LM3533_MAX_CURRENT_MAX)
85 val = (imax - LM3533_MAX_CURRENT_MIN) / LM3533_MAX_CURRENT_STEP;
87 reg = lm3533_ctrlbank_get_reg(cb, LM3533_REG_MAX_CURRENT_BASE);
88 ret = lm3533_write(cb->lm3533, reg, val);
90 dev_err(cb->dev, "failed to set max current\n");
94 EXPORT_SYMBOL_GPL(lm3533_ctrlbank_set_max_current);
96 #define lm3533_ctrlbank_set(_name, _NAME) \
97 int lm3533_ctrlbank_set_##_name(struct lm3533_ctrlbank *cb, u8 val) \
102 if (val > LM3533_##_NAME##_MAX) \
105 reg = lm3533_ctrlbank_get_reg(cb, LM3533_REG_##_NAME##_BASE); \
106 ret = lm3533_write(cb->lm3533, reg, val); \
108 dev_err(cb->dev, "failed to set " #_name "\n"); \
112 EXPORT_SYMBOL_GPL(lm3533_ctrlbank_set_##_name);
114 #define lm3533_ctrlbank_get(_name, _NAME) \
115 int lm3533_ctrlbank_get_##_name(struct lm3533_ctrlbank *cb, u8 *val) \
120 reg = lm3533_ctrlbank_get_reg(cb, LM3533_REG_##_NAME##_BASE); \
121 ret = lm3533_read(cb->lm3533, reg, val); \
123 dev_err(cb->dev, "failed to get " #_name "\n"); \
127 EXPORT_SYMBOL_GPL(lm3533_ctrlbank_get_##_name);
129 lm3533_ctrlbank_set(brightness, BRIGHTNESS);
130 lm3533_ctrlbank_get(brightness, BRIGHTNESS);
133 * PWM-input control mask:
135 * bit 5 - PWM-input enabled in Zone 4
136 * bit 4 - PWM-input enabled in Zone 3
137 * bit 3 - PWM-input enabled in Zone 2
138 * bit 2 - PWM-input enabled in Zone 1
139 * bit 1 - PWM-input enabled in Zone 0
140 * bit 0 - PWM-input enabled
142 lm3533_ctrlbank_set(pwm, PWM);
143 lm3533_ctrlbank_get(pwm, PWM);
146 MODULE_AUTHOR("Johan Hovold <jhovold@gmail.com>");
147 MODULE_DESCRIPTION("LM3533 Control Bank interface");
148 MODULE_LICENSE("GPL");