Commit | Line | Data |
---|---|---|
c93d08fa MWK |
1 | /* |
2 | * LP5521/LP5523/LP55231 Common Driver | |
3 | * | |
4 | * Copyright 2012 Texas Instruments | |
5 | * | |
6 | * Author: Milo(Woogyom) Kim <milo.kim@ti.com> | |
7 | * | |
8 | * This program is free software; you can redistribute it and/or modify | |
9 | * it under the terms of the GNU General Public License version 2 as | |
10 | * published by the Free Software Foundation. | |
11 | * | |
12 | * Derived from leds-lp5521.c, leds-lp5523.c | |
13 | */ | |
14 | ||
15 | #include <linux/i2c.h> | |
16 | #include <linux/leds.h> | |
17 | #include <linux/module.h> | |
18 | #include <linux/platform_data/leds-lp55xx.h> | |
19 | ||
20 | #include "leds-lp55xx-common.h" | |
21 | ||
22 | int lp55xx_write(struct lp55xx_chip *chip, u8 reg, u8 val) | |
23 | { | |
24 | return i2c_smbus_write_byte_data(chip->cl, reg, val); | |
25 | } | |
26 | EXPORT_SYMBOL_GPL(lp55xx_write); | |
27 | ||
28 | int lp55xx_read(struct lp55xx_chip *chip, u8 reg, u8 *val) | |
29 | { | |
30 | s32 ret; | |
31 | ||
32 | ret = i2c_smbus_read_byte_data(chip->cl, reg); | |
33 | if (ret < 0) | |
34 | return ret; | |
35 | ||
36 | *val = ret; | |
37 | return 0; | |
38 | } | |
39 | EXPORT_SYMBOL_GPL(lp55xx_read); | |
40 | ||
41 | int lp55xx_update_bits(struct lp55xx_chip *chip, u8 reg, u8 mask, u8 val) | |
42 | { | |
43 | int ret; | |
44 | u8 tmp; | |
45 | ||
46 | ret = lp55xx_read(chip, reg, &tmp); | |
47 | if (ret) | |
48 | return ret; | |
49 | ||
50 | tmp &= ~mask; | |
51 | tmp |= val & mask; | |
52 | ||
53 | return lp55xx_write(chip, reg, tmp); | |
54 | } | |
55 | EXPORT_SYMBOL_GPL(lp55xx_update_bits); | |
56 | ||
57 | MODULE_AUTHOR("Milo Kim <milo.kim@ti.com>"); | |
58 | MODULE_DESCRIPTION("LP55xx Common Driver"); | |
59 | MODULE_LICENSE("GPL"); |