14 #include <linux/module.h>
16 #include <linux/kernel.h>
19 #include <linux/i2c.h>
23 #include <linux/slab.h>
29 #define LM3533_BOOST_OVP_MASK 0x06
30 #define LM3533_BOOST_OVP_SHIFT 1
32 #define LM3533_BOOST_FREQ_MASK 0x01
33 #define LM3533_BOOST_FREQ_SHIFT 0
35 #define LM3533_BL_ID_MASK 1
36 #define LM3533_LED_ID_MASK 3
37 #define LM3533_BL_ID_MAX 1
38 #define LM3533_LED_ID_MAX 3
40 #define LM3533_HVLED_ID_MAX 2
41 #define LM3533_LVLED_ID_MAX 5
43 #define LM3533_REG_OUTPUT_CONF1 0x10
44 #define LM3533_REG_OUTPUT_CONF2 0x11
45 #define LM3533_REG_BOOST_PWM 0x2c
47 #define LM3533_REG_MAX 0xb2
50 static struct mfd_cell lm3533_als_devs[] = {
57 static struct mfd_cell lm3533_bl_devs[] = {
59 .name =
"lm3533-backlight",
63 .name =
"lm3533-backlight",
68 static struct mfd_cell lm3533_led_devs[] = {
70 .name =
"lm3533-leds",
74 .name =
"lm3533-leds",
78 .name =
"lm3533-leds",
82 .name =
"lm3533-leds",
94 dev_err(lm3533->
dev,
"failed to read register %02x: %d\n",
101 dev_dbg(lm3533->
dev,
"read [%02x]: %02x\n", reg, *val);
111 dev_dbg(lm3533->
dev,
"write [%02x]: %02x\n", reg, val);
115 dev_err(lm3533->
dev,
"failed to write register %02x: %d\n",
127 dev_dbg(lm3533->
dev,
"update [%02x]: %02x/%02x\n", reg, val, mask);
131 dev_err(lm3533->
dev,
"failed to update register %02x: %d\n",
148 dev_err(lm3533->
dev,
"failed to set boost frequency\n");
154 static int lm3533_set_boost_ovp(
struct lm3533 *lm3533,
163 dev_err(lm3533->
dev,
"failed to set boost ovp\n");
171 static int lm3533_set_hvled_config(
struct lm3533 *lm3533,
u8 hvled,
u8 bl)
190 dev_err(lm3533->
dev,
"failed to set hvled config\n");
198 static int lm3533_set_lvled_config(
struct lm3533 *lm3533,
u8 lvled,
u8 led)
217 shift = 2 * (lvled - 4);
225 dev_err(lm3533->
dev,
"failed to set lvled config\n");
230 static void lm3533_enable(
struct lm3533 *lm3533)
236 static void lm3533_disable(
struct lm3533 *lm3533)
257 #define to_lm3533_dev_attr(_attr) \
258 container_of(_attr, struct lm3533_device_attribute, dev_attr)
282 shift = 2 * (
id - 4);
291 val = (val &
mask) >> shift;
298 const char *
buf,
size_t len)
310 ret = lm3533_set_hvled_config(lm3533,
id, val);
312 ret = lm3533_set_lvled_config(lm3533,
id, val);
320 #define LM3533_OUTPUT_ATTR(_name, _mode, _show, _store, _type, _id) \
321 struct lm3533_device_attribute lm3533_dev_attr_##_name = \
322 { .dev_attr = __ATTR(_name, _mode, _show, _store), \
324 .u.output = { .id = _id }, }
326 #define LM3533_OUTPUT_ATTR_RW(_name, _type, _id) \
327 LM3533_OUTPUT_ATTR(output_##_name, S_IRUGO | S_IWUSR, \
328 show_output, store_output, _type, _id)
330 #define LM3533_OUTPUT_HVLED_ATTR_RW(_nr) \
331 LM3533_OUTPUT_ATTR_RW(hvled##_nr, LM3533_ATTR_TYPE_BACKLIGHT, _nr)
332 #define LM3533_OUTPUT_LVLED_ATTR_RW(_nr) \
333 LM3533_OUTPUT_ATTR_RW(lvled##_nr, LM3533_ATTR_TYPE_LED, _nr)
348 static struct attribute *lm3533_attributes[] = {
349 &lm3533_dev_attr_output_hvled1.dev_attr.attr,
350 &lm3533_dev_attr_output_hvled2.dev_attr.attr,
351 &lm3533_dev_attr_output_lvled1.dev_attr.attr,
352 &lm3533_dev_attr_output_lvled2.dev_attr.attr,
353 &lm3533_dev_attr_output_lvled3.dev_attr.attr,
354 &lm3533_dev_attr_output_lvled4.dev_attr.attr,
355 &lm3533_dev_attr_output_lvled5.dev_attr.attr,
359 #define to_dev_attr(_attr) \
360 container_of(_attr, struct device_attribute, attr)
381 .is_visible = lm3533_attr_is_visible,
382 .attrs = lm3533_attributes
385 static int __devinit lm3533_device_als_init(
struct lm3533 *lm3533)
399 dev_err(lm3533->
dev,
"failed to add ALS device\n");
408 static int __devinit lm3533_device_bl_init(
struct lm3533 *lm3533)
428 dev_err(lm3533->
dev,
"failed to add backlight devices\n");
437 static int __devinit lm3533_device_led_init(
struct lm3533 *lm3533)
457 dev_err(lm3533->
dev,
"failed to add LED devices\n");
466 static int __devinit lm3533_device_setup(
struct lm3533 *lm3533,
471 ret = lm3533_set_boost_freq(lm3533, pdata->
boost_freq);
475 ret = lm3533_set_boost_ovp(lm3533, pdata->
boost_ovp);
482 static int __devinit lm3533_device_init(
struct lm3533 *lm3533)
503 "failed to request HWEN GPIO %d\n",
509 lm3533_enable(lm3533);
511 ret = lm3533_device_setup(lm3533, pdata);
515 lm3533_device_als_init(lm3533);
516 lm3533_device_bl_init(lm3533);
517 lm3533_device_led_init(lm3533);
521 dev_err(lm3533->
dev,
"failed to create sysfs attributes\n");
530 lm3533_disable(lm3533);
537 static void __devexit lm3533_device_exit(
struct lm3533 *lm3533)
544 lm3533_disable(lm3533);
549 static bool lm3533_readable_register(
struct device *dev,
unsigned int reg)
568 static bool lm3533_volatile_register(
struct device *dev,
unsigned int reg)
580 static bool lm3533_precious_register(
struct device *dev,
unsigned int reg)
590 static struct regmap_config regmap_config = {
594 .readable_reg = lm3533_readable_register,
595 .volatile_reg = lm3533_volatile_register,
596 .precious_reg = lm3533_precious_register,
602 struct lm3533 *lm3533;
611 i2c_set_clientdata(i2c, lm3533);
614 if (IS_ERR(lm3533->
regmap))
615 return PTR_ERR(lm3533->
regmap);
620 ret = lm3533_device_init(lm3533);
629 struct lm3533 *lm3533 = i2c_get_clientdata(i2c);
633 lm3533_device_exit(lm3533);
644 static struct i2c_driver lm3533_i2c_driver = {
649 .id_table = lm3533_i2c_ids,
650 .probe = lm3533_i2c_probe,
654 static int __init lm3533_i2c_init(
void)
656 return i2c_add_driver(&lm3533_i2c_driver);
660 static void __exit lm3533_i2c_exit(
void)