leds-lp5521.c (87aae1ea82f93f0f00cb955044ea1db3501cf233) | leds-lp5521.c (c0e5e9b542d134eb43ea4ebc83446e6f2f63089a) |
---|---|
1/* 2 * LP5521 LED chip driver. 3 * 4 * Copyright (C) 2010 Nokia Corporation 5 * Copyright (C) 2012 Texas Instruments 6 * 7 * Contact: Samu Onkalo <samu.p.onkalo@nokia.com> 8 * Milo(Woogyom) Kim <milo.kim@ti.com> --- 237 unchanged lines hidden (view full) --- 246 i++; 247 } 248 249 /* Each instruction is 16bit long. Check that length is even */ 250 if (i % 2) 251 goto err; 252 253 program_size = i; | 1/* 2 * LP5521 LED chip driver. 3 * 4 * Copyright (C) 2010 Nokia Corporation 5 * Copyright (C) 2012 Texas Instruments 6 * 7 * Contact: Samu Onkalo <samu.p.onkalo@nokia.com> 8 * Milo(Woogyom) Kim <milo.kim@ti.com> --- 237 unchanged lines hidden (view full) --- 246 i++; 247 } 248 249 /* Each instruction is 16bit long. Check that length is even */ 250 if (i % 2) 251 goto err; 252 253 program_size = i; |
254 for (i = 0; i < program_size; i++) 255 lp55xx_write(chip, addr[idx] + i, pattern[i]); | |
256 | 254 |
257 return 0; | 255 mutex_lock(&chip->lock); |
258 | 256 |
257 for (i = 0; i < program_size; i++) { 258 ret = lp55xx_write(chip, addr[idx] + i, pattern[i]); 259 if (ret) { 260 mutex_unlock(&chip->lock); 261 return -EINVAL; 262 } 263 } 264 265 mutex_unlock(&chip->lock); 266 267 return size; 268 |
|
259err: 260 dev_err(&chip->cl->dev, "wrong pattern format\n"); 261 return -EINVAL; 262} 263 264static void lp5521_firmware_loaded(struct lp55xx_chip *chip) 265{ 266 const struct firmware *fw = chip->fw; --- 93 unchanged lines hidden (view full) --- 360 struct lp55xx_chip *chip = led->chip; 361 362 mutex_lock(&chip->lock); 363 lp55xx_write(chip, LP5521_REG_LED_PWM_BASE + led->chan_nr, 364 led->brightness); 365 mutex_unlock(&chip->lock); 366} 367 | 269err: 270 dev_err(&chip->cl->dev, "wrong pattern format\n"); 271 return -EINVAL; 272} 273 274static void lp5521_firmware_loaded(struct lp55xx_chip *chip) 275{ 276 const struct firmware *fw = chip->fw; --- 93 unchanged lines hidden (view full) --- 370 struct lp55xx_chip *chip = led->chip; 371 372 mutex_lock(&chip->lock); 373 lp55xx_write(chip, LP5521_REG_LED_PWM_BASE + led->chan_nr, 374 led->brightness); 375 mutex_unlock(&chip->lock); 376} 377 |
378static ssize_t show_engine_mode(struct device *dev, 379 struct device_attribute *attr, 380 char *buf, int nr) 381{ 382 struct lp55xx_led *led = i2c_get_clientdata(to_i2c_client(dev)); 383 struct lp55xx_chip *chip = led->chip; 384 enum lp55xx_engine_mode mode = chip->engines[nr - 1].mode; 385 386 switch (mode) { 387 case LP55XX_ENGINE_RUN: 388 return sprintf(buf, "run\n"); 389 case LP55XX_ENGINE_LOAD: 390 return sprintf(buf, "load\n"); 391 case LP55XX_ENGINE_DISABLED: 392 default: 393 return sprintf(buf, "disabled\n"); 394 } 395} 396show_mode(1) 397show_mode(2) 398show_mode(3) 399 400static ssize_t store_engine_mode(struct device *dev, 401 struct device_attribute *attr, 402 const char *buf, size_t len, int nr) 403{ 404 struct lp55xx_led *led = i2c_get_clientdata(to_i2c_client(dev)); 405 struct lp55xx_chip *chip = led->chip; 406 struct lp55xx_engine *engine = &chip->engines[nr - 1]; 407 408 mutex_lock(&chip->lock); 409 410 chip->engine_idx = nr; 411 412 if (!strncmp(buf, "run", 3)) { 413 lp5521_run_engine(chip, true); 414 engine->mode = LP55XX_ENGINE_RUN; 415 } else if (!strncmp(buf, "load", 4)) { 416 lp5521_stop_engine(chip); 417 lp5521_load_engine(chip); 418 engine->mode = LP55XX_ENGINE_LOAD; 419 } else if (!strncmp(buf, "disabled", 8)) { 420 lp5521_stop_engine(chip); 421 engine->mode = LP55XX_ENGINE_DISABLED; 422 } 423 424 mutex_unlock(&chip->lock); 425 426 return len; 427} 428store_mode(1) 429store_mode(2) 430store_mode(3) 431 432static ssize_t store_engine_load(struct device *dev, 433 struct device_attribute *attr, 434 const char *buf, size_t len, int nr) 435{ 436 struct lp55xx_led *led = i2c_get_clientdata(to_i2c_client(dev)); 437 struct lp55xx_chip *chip = led->chip; 438 439 mutex_lock(&chip->lock); 440 441 chip->engine_idx = nr; 442 lp5521_load_engine(chip); 443 444 mutex_unlock(&chip->lock); 445 446 return lp5521_update_program_memory(chip, buf, len); 447} 448store_load(1) 449store_load(2) 450store_load(3) 451 |
|
368static ssize_t lp5521_selftest(struct device *dev, 369 struct device_attribute *attr, 370 char *buf) 371{ 372 struct lp55xx_led *led = i2c_get_clientdata(to_i2c_client(dev)); 373 struct lp55xx_chip *chip = led->chip; 374 int ret; 375 376 mutex_lock(&chip->lock); 377 ret = lp5521_run_selftest(chip, buf); 378 mutex_unlock(&chip->lock); 379 380 return scnprintf(buf, PAGE_SIZE, "%s\n", ret ? "FAIL" : "OK"); 381} 382 383/* device attributes */ | 452static ssize_t lp5521_selftest(struct device *dev, 453 struct device_attribute *attr, 454 char *buf) 455{ 456 struct lp55xx_led *led = i2c_get_clientdata(to_i2c_client(dev)); 457 struct lp55xx_chip *chip = led->chip; 458 int ret; 459 460 mutex_lock(&chip->lock); 461 ret = lp5521_run_selftest(chip, buf); 462 mutex_unlock(&chip->lock); 463 464 return scnprintf(buf, PAGE_SIZE, "%s\n", ret ? "FAIL" : "OK"); 465} 466 467/* device attributes */ |
384static DEVICE_ATTR(selftest, S_IRUGO, lp5521_selftest, NULL); | 468static LP55XX_DEV_ATTR_RW(engine1_mode, show_engine1_mode, store_engine1_mode); 469static LP55XX_DEV_ATTR_RW(engine2_mode, show_engine2_mode, store_engine2_mode); 470static LP55XX_DEV_ATTR_RW(engine3_mode, show_engine3_mode, store_engine3_mode); 471static LP55XX_DEV_ATTR_WO(engine1_load, store_engine1_load); 472static LP55XX_DEV_ATTR_WO(engine2_load, store_engine2_load); 473static LP55XX_DEV_ATTR_WO(engine3_load, store_engine3_load); 474static LP55XX_DEV_ATTR_RO(selftest, lp5521_selftest); |
385 386static struct attribute *lp5521_attributes[] = { | 475 476static struct attribute *lp5521_attributes[] = { |
477 &dev_attr_engine1_mode.attr, 478 &dev_attr_engine2_mode.attr, 479 &dev_attr_engine3_mode.attr, 480 &dev_attr_engine1_load.attr, 481 &dev_attr_engine2_load.attr, 482 &dev_attr_engine3_load.attr, |
|
387 &dev_attr_selftest.attr, 388 NULL 389}; 390 391static const struct attribute_group lp5521_group = { 392 .attrs = lp5521_attributes, 393}; 394 --- 126 unchanged lines hidden --- | 483 &dev_attr_selftest.attr, 484 NULL 485}; 486 487static const struct attribute_group lp5521_group = { 488 .attrs = lp5521_attributes, 489}; 490 --- 126 unchanged lines hidden --- |