Lines Matching +full:serial +full:- +full:leds

1 // SPDX-License-Identifier: GPL-2.0-only
9 #include <linux/leds.h>
20 #define BCM63138_LED_MASK ((1 << BCM63138_LED_BITS) - 1) /* 0xf */
40 #define BCM63138_POWER_LUT_BASE0 0x34 /* -> b0 */
59 struct bcm63138_leds *leds; member
69 static void bcm63138_leds_write(struct bcm63138_leds *leds, unsigned int reg, in bcm63138_leds_write() argument
72 writel(data, leds->base + reg); in bcm63138_leds_write()
75 static unsigned long bcm63138_leds_read(struct bcm63138_leds *leds, in bcm63138_leds_read() argument
78 return readl(leds->base + reg); in bcm63138_leds_read()
81 static void bcm63138_leds_update_bits(struct bcm63138_leds *leds, in bcm63138_leds_update_bits() argument
86 bcm63138_leds_write(leds, reg, (bcm63138_leds_read(leds, reg) & ~mask) | (val & mask)); in bcm63138_leds_update_bits()
93 static void bcm63138_leds_set_flash_rate(struct bcm63138_leds *leds, in bcm63138_leds_set_flash_rate() argument
97 int reg_offset = (led->pin >> fls((BCM63138_LEDS_PER_REG - 1))) * 4; in bcm63138_leds_set_flash_rate()
98 int shift = (led->pin & (BCM63138_LEDS_PER_REG - 1)) * BCM63138_LED_BITS; in bcm63138_leds_set_flash_rate()
100 bcm63138_leds_update_bits(leds, BCM63138_FLASH_RATE_CTRL1 + reg_offset, in bcm63138_leds_set_flash_rate()
104 static void bcm63138_leds_set_bright(struct bcm63138_leds *leds, in bcm63138_leds_set_bright() argument
108 int reg_offset = (led->pin >> fls((BCM63138_LEDS_PER_REG - 1))) * 4; in bcm63138_leds_set_bright()
109 int shift = (led->pin & (BCM63138_LEDS_PER_REG - 1)) * BCM63138_LED_BITS; in bcm63138_leds_set_bright()
111 bcm63138_leds_update_bits(leds, BCM63138_BRIGHT_CTRL1 + reg_offset, in bcm63138_leds_set_bright()
115 static void bcm63138_leds_enable_led(struct bcm63138_leds *leds, in bcm63138_leds_enable_led() argument
119 u32 bit = BIT(led->pin); in bcm63138_leds_enable_led()
121 bcm63138_leds_update_bits(leds, BCM63138_SW_DATA, bit, value ? bit : 0); in bcm63138_leds_enable_led()
132 struct bcm63138_leds *leds = led->leds; in bcm63138_leds_brightness_set() local
134 guard(spinlock_irqsave)(&leds->lock); in bcm63138_leds_brightness_set()
136 bcm63138_leds_enable_led(leds, led, value); in bcm63138_leds_brightness_set()
138 bcm63138_leds_set_flash_rate(leds, led, 0); in bcm63138_leds_brightness_set()
140 bcm63138_leds_set_bright(leds, led, value); in bcm63138_leds_brightness_set()
148 struct bcm63138_leds *leds = led->leds; in bcm63138_leds_blink_set() local
157 dev_dbg(led_cdev->dev, "Blinking at unequal delays is not supported\n"); in bcm63138_leds_blink_set()
158 return -EINVAL; in bcm63138_leds_blink_set()
178 dev_dbg(led_cdev->dev, "Blinking delay value %lu is unsupported\n", in bcm63138_leds_blink_set()
180 return -EINVAL; in bcm63138_leds_blink_set()
183 guard(spinlock_irqsave)(&leds->lock); in bcm63138_leds_blink_set()
185 bcm63138_leds_enable_led(leds, led, BCM63138_MAX_BRIGHTNESS); in bcm63138_leds_blink_set()
186 bcm63138_leds_set_flash_rate(leds, led, value); in bcm63138_leds_blink_set()
195 static void bcm63138_leds_create_led(struct bcm63138_leds *leds, in bcm63138_leds_create_led() argument
201 struct device *dev = leds->dev; in bcm63138_leds_create_led()
213 led->leds = leds; in bcm63138_leds_create_led()
215 if (of_property_read_u32(np, "reg", &led->pin)) { in bcm63138_leds_create_led()
220 if (led->pin >= BCM63138_MAX_LEDS) { in bcm63138_leds_create_led()
221 dev_err(dev, "Invalid \"reg\" value %d\n", led->pin); in bcm63138_leds_create_led()
225 led->active_low = of_property_read_bool(np, "active-low"); in bcm63138_leds_create_led()
227 led->cdev.max_brightness = BCM63138_MAX_BRIGHTNESS; in bcm63138_leds_create_led()
228 led->cdev.brightness_set = bcm63138_leds_brightness_set; in bcm63138_leds_create_led()
229 led->cdev.blink_set = bcm63138_leds_blink_set; in bcm63138_leds_create_led()
231 err = devm_led_classdev_register_ext(dev, &led->cdev, &init_data); in bcm63138_leds_create_led()
237 pinctrl = devm_pinctrl_get_select_default(led->cdev.dev); in bcm63138_leds_create_led()
238 if (IS_ERR(pinctrl) && PTR_ERR(pinctrl) != -ENODEV) { in bcm63138_leds_create_led()
239 dev_warn(led->cdev.dev, "Failed to select %pOF pinctrl: %ld\n", in bcm63138_leds_create_led()
243 bit = BIT(led->pin); in bcm63138_leds_create_led()
244 bcm63138_leds_update_bits(leds, BCM63138_PARALLEL_LED_POLARITY, bit, in bcm63138_leds_create_led()
245 led->active_low ? 0 : bit); in bcm63138_leds_create_led()
246 bcm63138_leds_update_bits(leds, BCM63138_HW_LED_EN, bit, 0); in bcm63138_leds_create_led()
247 bcm63138_leds_set_flash_rate(leds, led, 0); in bcm63138_leds_create_led()
248 bcm63138_leds_enable_led(leds, led, led->cdev.brightness); in bcm63138_leds_create_led()
258 struct device_node *np = dev_of_node(&pdev->dev); in bcm63138_leds_probe()
259 struct device *dev = &pdev->dev; in bcm63138_leds_probe()
260 struct bcm63138_leds *leds; in bcm63138_leds_probe() local
263 leds = devm_kzalloc(dev, sizeof(*leds), GFP_KERNEL); in bcm63138_leds_probe()
264 if (!leds) in bcm63138_leds_probe()
265 return -ENOMEM; in bcm63138_leds_probe()
267 leds->dev = dev; in bcm63138_leds_probe()
269 leds->base = devm_platform_ioremap_resource(pdev, 0); in bcm63138_leds_probe()
270 if (IS_ERR(leds->base)) in bcm63138_leds_probe()
271 return PTR_ERR(leds->base); in bcm63138_leds_probe()
273 spin_lock_init(&leds->lock); in bcm63138_leds_probe()
276 if (!of_property_read_u32(np, "brcm,serial-shift-bits", &shift_bits)) { in bcm63138_leds_probe()
277 bcm63138_leds_write(leds, BCM63138_SERIAL_LED_SHIFT_SEL, in bcm63138_leds_probe()
278 GENMASK(shift_bits - 1, 0)); in bcm63138_leds_probe()
281 bcm63138_leds_write(leds, BCM63138_GLB_CTRL, in bcm63138_leds_probe()
284 bcm63138_leds_write(leds, BCM63138_HW_LED_EN, 0); in bcm63138_leds_probe()
285 bcm63138_leds_write(leds, BCM63138_SERIAL_LED_POLARITY, 0); in bcm63138_leds_probe()
286 bcm63138_leds_write(leds, BCM63138_PARALLEL_LED_POLARITY, 0); in bcm63138_leds_probe()
289 bcm63138_leds_create_led(leds, child); in bcm63138_leds_probe()
296 { .compatible = "brcm,bcm63138-leds", },
303 .name = "leds-bcm63xxx",