Lines Matching +full:bcm63138 +full:- +full:leds

1 // SPDX-License-Identifier: GPL-2.0-only
7 #include <linux/leds.h>
18 #define BCM63138_LED_MASK ((1 << BCM63138_LED_BITS) - 1) /* 0xf */
54 struct bcm63138_leds *leds; member
64 static void bcm63138_leds_write(struct bcm63138_leds *leds, unsigned int reg, in bcm63138_leds_write() argument
67 writel(data, leds->base + reg); in bcm63138_leds_write()
70 static unsigned long bcm63138_leds_read(struct bcm63138_leds *leds, in bcm63138_leds_read() argument
73 return readl(leds->base + reg); in bcm63138_leds_read()
76 static void bcm63138_leds_update_bits(struct bcm63138_leds *leds, in bcm63138_leds_update_bits() argument
81 bcm63138_leds_write(leds, reg, (bcm63138_leds_read(leds, reg) & ~mask) | (val & mask)); in bcm63138_leds_update_bits()
88 static void bcm63138_leds_set_flash_rate(struct bcm63138_leds *leds, in bcm63138_leds_set_flash_rate() argument
92 int reg_offset = (led->pin >> fls((BCM63138_LEDS_PER_REG - 1))) * 4; in bcm63138_leds_set_flash_rate()
93 int shift = (led->pin & (BCM63138_LEDS_PER_REG - 1)) * BCM63138_LED_BITS; in bcm63138_leds_set_flash_rate()
95 bcm63138_leds_update_bits(leds, BCM63138_FLASH_RATE_CTRL1 + reg_offset, in bcm63138_leds_set_flash_rate()
99 static void bcm63138_leds_set_bright(struct bcm63138_leds *leds, in bcm63138_leds_set_bright() argument
103 int reg_offset = (led->pin >> fls((BCM63138_LEDS_PER_REG - 1))) * 4; in bcm63138_leds_set_bright()
104 int shift = (led->pin & (BCM63138_LEDS_PER_REG - 1)) * BCM63138_LED_BITS; in bcm63138_leds_set_bright()
106 bcm63138_leds_update_bits(leds, BCM63138_BRIGHT_CTRL1 + reg_offset, in bcm63138_leds_set_bright()
110 static void bcm63138_leds_enable_led(struct bcm63138_leds *leds, in bcm63138_leds_enable_led() argument
114 u32 bit = BIT(led->pin); in bcm63138_leds_enable_led()
116 bcm63138_leds_update_bits(leds, BCM63138_SW_DATA, bit, value ? bit : 0); in bcm63138_leds_enable_led()
127 struct bcm63138_leds *leds = led->leds; in bcm63138_leds_brightness_set() local
130 spin_lock_irqsave(&leds->lock, flags); in bcm63138_leds_brightness_set()
132 bcm63138_leds_enable_led(leds, led, value); in bcm63138_leds_brightness_set()
134 bcm63138_leds_set_flash_rate(leds, led, 0); in bcm63138_leds_brightness_set()
136 bcm63138_leds_set_bright(leds, led, value); in bcm63138_leds_brightness_set()
138 spin_unlock_irqrestore(&leds->lock, flags); in bcm63138_leds_brightness_set()
146 struct bcm63138_leds *leds = led->leds; in bcm63138_leds_blink_set() local
156 dev_dbg(led_cdev->dev, "Blinking at unequal delays is not supported\n"); in bcm63138_leds_blink_set()
157 return -EINVAL; in bcm63138_leds_blink_set()
177 dev_dbg(led_cdev->dev, "Blinking delay value %lu is unsupported\n", in bcm63138_leds_blink_set()
179 return -EINVAL; in bcm63138_leds_blink_set()
182 spin_lock_irqsave(&leds->lock, flags); in bcm63138_leds_blink_set()
184 bcm63138_leds_enable_led(leds, led, BCM63138_MAX_BRIGHTNESS); in bcm63138_leds_blink_set()
185 bcm63138_leds_set_flash_rate(leds, led, value); in bcm63138_leds_blink_set()
187 spin_unlock_irqrestore(&leds->lock, flags); in bcm63138_leds_blink_set()
196 static void bcm63138_leds_create_led(struct bcm63138_leds *leds, in bcm63138_leds_create_led() argument
202 struct device *dev = leds->dev; in bcm63138_leds_create_led()
214 led->leds = leds; in bcm63138_leds_create_led()
216 if (of_property_read_u32(np, "reg", &led->pin)) { in bcm63138_leds_create_led()
221 if (led->pin >= BCM63138_MAX_LEDS) { in bcm63138_leds_create_led()
222 dev_err(dev, "Invalid \"reg\" value %d\n", led->pin); in bcm63138_leds_create_led()
226 led->active_low = of_property_read_bool(np, "active-low"); in bcm63138_leds_create_led()
228 led->cdev.max_brightness = BCM63138_MAX_BRIGHTNESS; in bcm63138_leds_create_led()
229 led->cdev.brightness_set = bcm63138_leds_brightness_set; in bcm63138_leds_create_led()
230 led->cdev.blink_set = bcm63138_leds_blink_set; in bcm63138_leds_create_led()
232 err = devm_led_classdev_register_ext(dev, &led->cdev, &init_data); in bcm63138_leds_create_led()
238 pinctrl = devm_pinctrl_get_select_default(led->cdev.dev); in bcm63138_leds_create_led()
239 if (IS_ERR(pinctrl) && PTR_ERR(pinctrl) != -ENODEV) { in bcm63138_leds_create_led()
240 dev_warn(led->cdev.dev, "Failed to select %pOF pinctrl: %ld\n", in bcm63138_leds_create_led()
244 bit = BIT(led->pin); in bcm63138_leds_create_led()
245 bcm63138_leds_update_bits(leds, BCM63138_PARALLEL_LED_POLARITY, bit, in bcm63138_leds_create_led()
246 led->active_low ? 0 : bit); in bcm63138_leds_create_led()
247 bcm63138_leds_update_bits(leds, BCM63138_HW_LED_EN, bit, 0); in bcm63138_leds_create_led()
248 bcm63138_leds_set_flash_rate(leds, led, 0); in bcm63138_leds_create_led()
249 bcm63138_leds_enable_led(leds, led, led->cdev.brightness); in bcm63138_leds_create_led()
259 struct device_node *np = dev_of_node(&pdev->dev); in bcm63138_leds_probe()
260 struct device *dev = &pdev->dev; in bcm63138_leds_probe()
261 struct bcm63138_leds *leds; in bcm63138_leds_probe() local
264 leds = devm_kzalloc(dev, sizeof(*leds), GFP_KERNEL); in bcm63138_leds_probe()
265 if (!leds) in bcm63138_leds_probe()
266 return -ENOMEM; in bcm63138_leds_probe()
268 leds->dev = dev; in bcm63138_leds_probe()
270 leds->base = devm_platform_ioremap_resource(pdev, 0); in bcm63138_leds_probe()
271 if (IS_ERR(leds->base)) in bcm63138_leds_probe()
272 return PTR_ERR(leds->base); in bcm63138_leds_probe()
274 spin_lock_init(&leds->lock); in bcm63138_leds_probe()
276 bcm63138_leds_write(leds, BCM63138_GLB_CTRL, in bcm63138_leds_probe()
279 bcm63138_leds_write(leds, BCM63138_HW_LED_EN, 0); in bcm63138_leds_probe()
280 bcm63138_leds_write(leds, BCM63138_SERIAL_LED_POLARITY, 0); in bcm63138_leds_probe()
281 bcm63138_leds_write(leds, BCM63138_PARALLEL_LED_POLARITY, 0); in bcm63138_leds_probe()
284 bcm63138_leds_create_led(leds, child); in bcm63138_leds_probe()
291 { .compatible = "brcm,bcm63138-leds", },
298 .name = "leds-bcm63xxx",