blob: 05a854c0d9b2abee655d93cab63e97b4e7e80305 [file] [log] [blame]
Milo(Woogyom) Kimc93d08f2013-02-05 18:01:23 +09001/*
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
Milo(Woogyom) Kima85908d2013-02-05 18:07:20 +090015#include <linux/delay.h>
Milo(Woogyom) Kimc93d08f2013-02-05 18:01:23 +090016#include <linux/i2c.h>
17#include <linux/leds.h>
18#include <linux/module.h>
19#include <linux/platform_data/leds-lp55xx.h>
20
21#include "leds-lp55xx-common.h"
22
23int lp55xx_write(struct lp55xx_chip *chip, u8 reg, u8 val)
24{
25 return i2c_smbus_write_byte_data(chip->cl, reg, val);
26}
27EXPORT_SYMBOL_GPL(lp55xx_write);
28
29int lp55xx_read(struct lp55xx_chip *chip, u8 reg, u8 *val)
30{
31 s32 ret;
32
33 ret = i2c_smbus_read_byte_data(chip->cl, reg);
34 if (ret < 0)
35 return ret;
36
37 *val = ret;
38 return 0;
39}
40EXPORT_SYMBOL_GPL(lp55xx_read);
41
42int lp55xx_update_bits(struct lp55xx_chip *chip, u8 reg, u8 mask, u8 val)
43{
44 int ret;
45 u8 tmp;
46
47 ret = lp55xx_read(chip, reg, &tmp);
48 if (ret)
49 return ret;
50
51 tmp &= ~mask;
52 tmp |= val & mask;
53
54 return lp55xx_write(chip, reg, tmp);
55}
56EXPORT_SYMBOL_GPL(lp55xx_update_bits);
57
Milo(Woogyom) Kima85908d2013-02-05 18:07:20 +090058int lp55xx_init_device(struct lp55xx_chip *chip)
59{
60 struct lp55xx_platform_data *pdata;
61 struct device *dev = &chip->cl->dev;
62 int ret = 0;
63
64 WARN_ON(!chip);
65
66 pdata = chip->pdata;
67
68 if (!pdata)
69 return -EINVAL;
70
71 if (pdata->setup_resources) {
72 ret = pdata->setup_resources();
73 if (ret < 0) {
74 dev_err(dev, "setup resoure err: %d\n", ret);
75 goto err;
76 }
77 }
78
79 if (pdata->enable) {
80 pdata->enable(0);
81 usleep_range(1000, 2000); /* Keep enable down at least 1ms */
82 pdata->enable(1);
83 usleep_range(1000, 2000); /* 500us abs min. */
84 }
85
86err:
87 return ret;
88}
89EXPORT_SYMBOL_GPL(lp55xx_init_device);
90
Milo(Woogyom) Kimc93d08f2013-02-05 18:01:23 +090091MODULE_AUTHOR("Milo Kim <milo.kim@ti.com>");
92MODULE_DESCRIPTION("LP55xx Common Driver");
93MODULE_LICENSE("GPL");