| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * leds-bd2802.c - RGB LED Driver |
|---|
| 3 | 4 | * |
|---|
| 4 | 5 | * Copyright (C) 2009 Samsung Electronics |
|---|
| 5 | 6 | * Kim Kyuwon <q1.kim@samsung.com> |
|---|
| 6 | 7 | * |
|---|
| 7 | | - * This program is free software; you can redistribute it and/or modify |
|---|
| 8 | | - * it under the terms of the GNU General Public License version 2 as |
|---|
| 9 | | - * published by the Free Software Foundation. |
|---|
| 10 | | - * |
|---|
| 11 | 8 | * Datasheet: http://www.rohm.com/products/databook/driver/pdf/bd2802gu-e.pdf |
|---|
| 12 | | - * |
|---|
| 13 | 9 | */ |
|---|
| 14 | 10 | |
|---|
| 15 | 11 | #include <linux/module.h> |
|---|
| 16 | 12 | #include <linux/i2c.h> |
|---|
| 17 | | -#include <linux/gpio.h> |
|---|
| 13 | +#include <linux/gpio/consumer.h> |
|---|
| 18 | 14 | #include <linux/delay.h> |
|---|
| 19 | 15 | #include <linux/leds.h> |
|---|
| 20 | 16 | #include <linux/leds-bd2802.h> |
|---|
| .. | .. |
|---|
| 71 | 67 | struct bd2802_led { |
|---|
| 72 | 68 | struct bd2802_led_platform_data *pdata; |
|---|
| 73 | 69 | struct i2c_client *client; |
|---|
| 70 | + struct gpio_desc *reset; |
|---|
| 74 | 71 | struct rw_semaphore rwsem; |
|---|
| 75 | 72 | |
|---|
| 76 | 73 | struct led_state led[2]; |
|---|
| .. | .. |
|---|
| 204 | 201 | return; |
|---|
| 205 | 202 | |
|---|
| 206 | 203 | if (bd2802_is_all_off(led) && !led->adf_on) { |
|---|
| 207 | | - gpio_set_value(led->pdata->reset_gpio, 0); |
|---|
| 204 | + gpiod_set_value(led->reset, 1); |
|---|
| 208 | 205 | return; |
|---|
| 209 | 206 | } |
|---|
| 210 | 207 | |
|---|
| .. | .. |
|---|
| 230 | 227 | |
|---|
| 231 | 228 | static void bd2802_reset_cancel(struct bd2802_led *led) |
|---|
| 232 | 229 | { |
|---|
| 233 | | - gpio_set_value(led->pdata->reset_gpio, 1); |
|---|
| 230 | + gpiod_set_value(led->reset, 0); |
|---|
| 234 | 231 | udelay(100); |
|---|
| 235 | 232 | bd2802_configure(led); |
|---|
| 236 | 233 | } |
|---|
| .. | .. |
|---|
| 424 | 421 | bd2802_addr_attributes[i]); |
|---|
| 425 | 422 | |
|---|
| 426 | 423 | if (bd2802_is_all_off(led)) |
|---|
| 427 | | - gpio_set_value(led->pdata->reset_gpio, 0); |
|---|
| 424 | + gpiod_set_value(led->reset, 1); |
|---|
| 428 | 425 | |
|---|
| 429 | 426 | led->adf_on = 0; |
|---|
| 430 | 427 | } |
|---|
| .. | .. |
|---|
| 663 | 660 | const struct i2c_device_id *id) |
|---|
| 664 | 661 | { |
|---|
| 665 | 662 | struct bd2802_led *led; |
|---|
| 666 | | - struct bd2802_led_platform_data *pdata; |
|---|
| 667 | 663 | int ret, i; |
|---|
| 668 | 664 | |
|---|
| 669 | 665 | led = devm_kzalloc(&client->dev, sizeof(struct bd2802_led), GFP_KERNEL); |
|---|
| .. | .. |
|---|
| 671 | 667 | return -ENOMEM; |
|---|
| 672 | 668 | |
|---|
| 673 | 669 | led->client = client; |
|---|
| 674 | | - pdata = led->pdata = dev_get_platdata(&client->dev); |
|---|
| 675 | 670 | i2c_set_clientdata(client, led); |
|---|
| 676 | 671 | |
|---|
| 677 | | - /* Configure RESET GPIO (L: RESET, H: RESET cancel) */ |
|---|
| 678 | | - gpio_request_one(pdata->reset_gpio, GPIOF_OUT_INIT_HIGH, "RGB_RESETB"); |
|---|
| 672 | + /* |
|---|
| 673 | + * Configure RESET GPIO (L: RESET, H: RESET cancel) |
|---|
| 674 | + * |
|---|
| 675 | + * We request the reset GPIO as OUT_LOW which means de-asserted, |
|---|
| 676 | + * board files specifying this GPIO line in a machine descriptor |
|---|
| 677 | + * table should take care to specify GPIO_ACTIVE_LOW for this line. |
|---|
| 678 | + */ |
|---|
| 679 | + led->reset = devm_gpiod_get(&client->dev, "reset", GPIOD_OUT_LOW); |
|---|
| 680 | + if (IS_ERR(led->reset)) |
|---|
| 681 | + return PTR_ERR(led->reset); |
|---|
| 679 | 682 | |
|---|
| 680 | 683 | /* Tacss = min 0.1ms */ |
|---|
| 681 | 684 | udelay(100); |
|---|
| .. | .. |
|---|
| 689 | 692 | dev_info(&client->dev, "return 0x%02x\n", ret); |
|---|
| 690 | 693 | |
|---|
| 691 | 694 | /* To save the power, reset BD2802 after detecting */ |
|---|
| 692 | | - gpio_set_value(led->pdata->reset_gpio, 0); |
|---|
| 695 | + gpiod_set_value(led->reset, 1); |
|---|
| 693 | 696 | |
|---|
| 694 | 697 | /* Default attributes */ |
|---|
| 695 | 698 | led->wave_pattern = BD2802_PATTERN_HALF; |
|---|
| .. | .. |
|---|
| 724 | 727 | struct bd2802_led *led = i2c_get_clientdata(client); |
|---|
| 725 | 728 | int i; |
|---|
| 726 | 729 | |
|---|
| 727 | | - gpio_set_value(led->pdata->reset_gpio, 0); |
|---|
| 730 | + gpiod_set_value(led->reset, 1); |
|---|
| 728 | 731 | bd2802_unregister_led_classdev(led); |
|---|
| 729 | 732 | if (led->adf_on) |
|---|
| 730 | 733 | bd2802_disable_adv_conf(led); |
|---|
| .. | .. |
|---|
| 754 | 757 | struct i2c_client *client = to_i2c_client(dev); |
|---|
| 755 | 758 | struct bd2802_led *led = i2c_get_clientdata(client); |
|---|
| 756 | 759 | |
|---|
| 757 | | - gpio_set_value(led->pdata->reset_gpio, 0); |
|---|
| 760 | + gpiod_set_value(led->reset, 1); |
|---|
| 758 | 761 | |
|---|
| 759 | 762 | return 0; |
|---|
| 760 | 763 | } |
|---|