29 #include <linux/module.h>
30 #include <linux/i2c.h>
31 #include <linux/slab.h>
38 #define LP3944_REG_INPUT1 0x00
39 #define LP3944_REG_REGISTER1 0x01
41 #define LP3944_REG_PSC0 0x02
42 #define LP3944_REG_PWM0 0x03
43 #define LP3944_REG_PSC1 0x04
44 #define LP3944_REG_PWM1 0x05
45 #define LP3944_REG_LS0 0x06
46 #define LP3944_REG_LS1 0x07
51 #define LP3944_REG_REGISTER8 0x08
52 #define LP3944_REG_REGISTER9 0x09
58 #define LP3944_PERIOD_MIN 0
59 #define LP3944_PERIOD_MAX 1600
62 #define LP3944_DUTY_CYCLE_MIN 0
63 #define LP3944_DUTY_CYCLE_MAX 100
65 #define ldev_to_led(c) container_of(c, struct lp3944_led_data, ldev)
96 static int lp3944_reg_write(
struct i2c_client *client,
u8 reg,
u8 value)
127 err = lp3944_reg_write(client, psc_reg, psc_value);
139 static int lp3944_dim_set_dutycycle(
struct i2c_client *client,
u8 dim,
159 err = lp3944_reg_write(client, pwm_reg, pwm_value);
181 dev_dbg(&led->
client->dev,
"%s: %s, status before normalization:%d\n",
182 __func__, led->
ldev.name, status);
212 lp3944_reg_read(led->
client, reg, &val);
215 val |= (status << (
id << 1));
217 dev_dbg(&led->
client->dev,
"%s: %s, reg:%d id:%d status:%d val:%#x\n",
218 __func__, led->
ldev.name, reg,
id, status, val);
221 err = lp3944_reg_write(led->
client, reg, val);
227 static int lp3944_led_set_blink(
struct led_classdev *led_cdev,
228 unsigned long *delay_on,
229 unsigned long *delay_off)
240 if (*delay_on == 0 && *delay_off == 0) {
249 period = (*delay_on) + (*delay_off);
252 duty_cycle = 100 * (*delay_on) /
period;
258 duty_cycle = 100 - duty_cycle;
275 dev_dbg(&led->
client->dev,
"%s: OK hardware accelerated blink!\n",
284 static void lp3944_led_set_brightness(
struct led_classdev *led_cdev,
290 __func__, led_cdev->
name, brightness);
301 lp3944_led_set(led, led->
status);
304 static int lp3944_configure(
struct i2c_client *client,
316 switch (pled->
type) {
323 led->
ldev.max_brightness = 1;
324 led->
ldev.brightness_set = lp3944_led_set_brightness;
325 led->
ldev.blink_set = lp3944_led_set_blink;
332 "couldn't register LED %s\n",
341 err = lp3944_led_set(led, led->
status);
344 "%s couldn't set STATUS %d\n",
360 for (i = i - 1; i >= 0; i--)
361 switch (pdata->
leds[i].type) {
384 if (lp3944_pdata ==
NULL) {
390 if (!i2c_check_functionality(client->
adapter,
392 dev_err(&client->
dev,
"insufficient functionality!\n");
402 i2c_set_clientdata(client, data);
406 err = lp3944_configure(client, data, lp3944_pdata);
417 struct lp3944_data *data = i2c_get_clientdata(client);
421 switch (data->
leds[i].type) {
448 .probe = lp3944_probe,
450 .id_table = lp3944_id,