Lines Matching +full:kbd +full:- +full:led +full:- +full:backlight

1 // SPDX-License-Identifier: GPL-2.0
3 * Platform driver for Lenovo Yoga Book YB1-X90F/L tablets (Android model)
4 * WMI driver for Lenovo Yoga Book YB1-X91F/L tablets (Windows model)
26 #define YB_MBTN_EVENT_GUID "243FEC1D-1963-41C1-8100-06A9D82A94B4"
32 #define YB_PDEV_NAME "yogabook-touch-kbd-digitizer-switch"
69 if (test_bit(YB_SUSPENDED, &data->flags)) in yogabook_work()
72 if (test_bit(YB_TABLET_MODE, &data->flags)) { in yogabook_work()
75 } else if (test_bit(YB_DIGITIZER_MODE, &data->flags)) { in yogabook_work()
83 if (!kbd_on && test_bit(YB_KBD_IS_ON, &data->flags)) { in yogabook_work()
88 data->set_kbd_backlight(data, 0); in yogabook_work()
89 device_release_driver(data->kbd_dev); in yogabook_work()
90 clear_bit(YB_KBD_IS_ON, &data->flags); in yogabook_work()
93 if (!digitizer_on && test_bit(YB_DIGITIZER_IS_ON, &data->flags)) { in yogabook_work()
94 led_set_brightness(data->pen_led, LED_OFF); in yogabook_work()
95 device_release_driver(data->dig_dev); in yogabook_work()
96 clear_bit(YB_DIGITIZER_IS_ON, &data->flags); in yogabook_work()
99 if (kbd_on && !test_bit(YB_KBD_IS_ON, &data->flags)) { in yogabook_work()
100 r = device_reprobe(data->kbd_dev); in yogabook_work()
102 dev_warn(data->dev, "Reprobe of keyboard touchscreen failed: %d\n", r); in yogabook_work()
104 data->set_kbd_backlight(data, data->brightness); in yogabook_work()
105 set_bit(YB_KBD_IS_ON, &data->flags); in yogabook_work()
108 if (digitizer_on && !test_bit(YB_DIGITIZER_IS_ON, &data->flags)) { in yogabook_work()
109 r = device_reprobe(data->dig_dev); in yogabook_work()
111 dev_warn(data->dev, "Reprobe of digitizer failed: %d\n", r); in yogabook_work()
113 led_set_brightness(data->pen_led, LED_FULL); in yogabook_work()
114 set_bit(YB_DIGITIZER_IS_ON, &data->flags); in yogabook_work()
120 if (test_bit(YB_SUSPENDED, &data->flags)) in yogabook_toggle_digitizer_mode()
123 if (test_bit(YB_DIGITIZER_MODE, &data->flags)) in yogabook_toggle_digitizer_mode()
124 clear_bit(YB_DIGITIZER_MODE, &data->flags); in yogabook_toggle_digitizer_mode()
126 set_bit(YB_DIGITIZER_MODE, &data->flags); in yogabook_toggle_digitizer_mode()
132 schedule_work(&data->work); in yogabook_toggle_digitizer_mode()
139 if (gpiod_get_value(data->backside_hall_gpio)) in yogabook_backside_hall_irq()
140 set_bit(YB_TABLET_MODE, &data->flags); in yogabook_backside_hall_irq()
142 clear_bit(YB_TABLET_MODE, &data->flags); in yogabook_backside_hall_irq()
144 schedule_work(&data->work); in yogabook_backside_hall_irq()
155 return data->brightness; in kbd_brightness_get()
164 return -EINVAL; in kbd_brightness_set()
166 data->brightness = value; in kbd_brightness_set()
168 if (!test_bit(YB_KBD_IS_ON, &data->flags)) in kbd_brightness_set()
171 return data->set_kbd_backlight(data, data->brightness); in kbd_brightness_set()
183 .con_id = "pen-icon-led",
191 data->dev = dev; in yogabook_probe()
192 data->brightness = YB_KBD_BL_DEFAULT; in yogabook_probe()
193 set_bit(YB_KBD_IS_ON, &data->flags); in yogabook_probe()
194 set_bit(YB_DIGITIZER_IS_ON, &data->flags); in yogabook_probe()
195 INIT_WORK(&data->work, yogabook_work); in yogabook_probe()
199 data->pen_led = devm_led_get(dev, "pen-icon-led"); in yogabook_probe()
202 if (IS_ERR(data->pen_led)) in yogabook_probe()
203 return dev_err_probe(dev, PTR_ERR(data->pen_led), "Getting pen icon LED\n"); in yogabook_probe()
207 data->backside_hall_gpio = devm_gpiod_get(dev, "backside_hall_sw", GPIOD_IN); in yogabook_probe()
210 if (IS_ERR(data->backside_hall_gpio)) in yogabook_probe()
211 return dev_err_probe(dev, PTR_ERR(data->backside_hall_gpio), in yogabook_probe()
214 r = gpiod_to_irq(data->backside_hall_gpio); in yogabook_probe()
218 data->backside_hall_irq = r; in yogabook_probe()
221 data->set_kbd_backlight(data, YB_KBD_BL_DEFAULT); in yogabook_probe()
223 r = request_irq(data->backside_hall_irq, yogabook_backside_hall_irq, in yogabook_probe()
229 schedule_work(&data->work); in yogabook_probe()
231 data->kbd_bl_led.name = kbd_bl_led_name; in yogabook_probe()
232 data->kbd_bl_led.brightness_set_blocking = kbd_brightness_set; in yogabook_probe()
233 data->kbd_bl_led.brightness_get = kbd_brightness_get; in yogabook_probe()
234 data->kbd_bl_led.max_brightness = YB_KBD_BL_MAX; in yogabook_probe()
236 r = devm_led_classdev_register(dev, &data->kbd_bl_led); in yogabook_probe()
238 dev_err_probe(dev, r, "Registering backlight LED device\n"); in yogabook_probe()
246 free_irq(data->backside_hall_irq, data); in yogabook_probe()
247 cancel_work_sync(&data->work); in yogabook_probe()
255 free_irq(data->backside_hall_irq, data); in yogabook_remove()
256 cancel_work_sync(&data->work); in yogabook_remove()
258 if (!test_bit(YB_KBD_IS_ON, &data->flags)) in yogabook_remove()
259 r |= device_reprobe(data->kbd_dev); in yogabook_remove()
261 if (!test_bit(YB_DIGITIZER_IS_ON, &data->flags)) in yogabook_remove()
262 r |= device_reprobe(data->dig_dev); in yogabook_remove()
265 dev_warn(data->dev, "Reprobe of devices failed\n"); in yogabook_remove()
272 set_bit(YB_SUSPENDED, &data->flags); in yogabook_suspend()
273 flush_work(&data->work); in yogabook_suspend()
275 if (test_bit(YB_KBD_IS_ON, &data->flags)) in yogabook_suspend()
276 data->set_kbd_backlight(data, 0); in yogabook_suspend()
285 if (test_bit(YB_KBD_IS_ON, &data->flags)) in yogabook_resume()
286 data->set_kbd_backlight(data, data->brightness); in yogabook_resume()
288 clear_bit(YB_SUSPENDED, &data->flags); in yogabook_resume()
291 schedule_work(&data->work); in yogabook_resume()
301 * To control keyboard backlight, call the method KBLC() of the TCS1 ACPI
312 dev_dbg(data->dev, "Set KBLC level to %u\n", level); in yogabook_wmi_set_kbd_backlight()
315 acpi_device_set_power(data->kbd_adev, ACPI_STATE_D0); in yogabook_wmi_set_kbd_backlight()
321 param.integer.value = YB_KBD_BL_MAX - level; in yogabook_wmi_set_kbd_backlight()
323 status = acpi_evaluate_object(acpi_device_handle(data->kbd_adev), "KBLC", in yogabook_wmi_set_kbd_backlight()
326 dev_err(data->dev, "Failed to call KBLC method: 0x%x\n", status); in yogabook_wmi_set_kbd_backlight()
336 struct device *dev = &wdev->dev; in yogabook_wmi_probe()
342 return -ENOMEM; in yogabook_wmi_probe()
344 data->kbd_adev = acpi_dev_get_first_match_dev("GDIX1001", NULL, -1); in yogabook_wmi_probe()
345 if (!data->kbd_adev) in yogabook_wmi_probe()
346 return dev_err_probe(dev, -ENODEV, "Cannot find the touchpad device in ACPI tables\n"); in yogabook_wmi_probe()
348 data->dig_adev = acpi_dev_get_first_match_dev("WCOM0019", NULL, -1); in yogabook_wmi_probe()
349 if (!data->dig_adev) { in yogabook_wmi_probe()
350 r = dev_err_probe(dev, -ENODEV, "Cannot find the digitizer device in ACPI tables\n"); in yogabook_wmi_probe()
354 data->kbd_dev = get_device(acpi_get_first_physical_node(data->kbd_adev)); in yogabook_wmi_probe()
355 if (!data->kbd_dev || !data->kbd_dev->driver) { in yogabook_wmi_probe()
356 r = -EPROBE_DEFER; in yogabook_wmi_probe()
360 data->dig_dev = get_device(acpi_get_first_physical_node(data->dig_adev)); in yogabook_wmi_probe()
361 if (!data->dig_dev || !data->dig_dev->driver) { in yogabook_wmi_probe()
362 r = -EPROBE_DEFER; in yogabook_wmi_probe()
366 data->set_kbd_backlight = yogabook_wmi_set_kbd_backlight; in yogabook_wmi_probe()
375 put_device(data->dig_dev); in yogabook_wmi_probe()
376 put_device(data->kbd_dev); in yogabook_wmi_probe()
377 acpi_dev_put(data->dig_adev); in yogabook_wmi_probe()
378 acpi_dev_put(data->kbd_adev); in yogabook_wmi_probe()
384 struct yogabook_data *data = dev_get_drvdata(&wdev->dev); in yogabook_wmi_remove()
388 put_device(data->dig_dev); in yogabook_wmi_remove()
389 put_device(data->kbd_dev); in yogabook_wmi_remove()
390 acpi_dev_put(data->dig_adev); in yogabook_wmi_remove()
391 acpi_dev_put(data->kbd_adev); in yogabook_wmi_remove()
396 yogabook_toggle_digitizer_mode(dev_get_drvdata(&wdev->dev)); in yogabook_wmi_notify()
409 .name = "yogabook-wmi",
438 pwm_apply_might_sleep(data->kbd_bl_pwm, &state); in yogabook_pdev_set_kbd_backlight()
439 gpiod_set_value(data->kbd_bl_led_enable, level ? 1 : 0); in yogabook_pdev_set_kbd_backlight()
451 struct device *dev = &pdev->dev; in yogabook_pdev_probe()
457 return -ENOMEM; in yogabook_pdev_probe()
459 data->kbd_dev = bus_find_device_by_name(&i2c_bus_type, NULL, "i2c-goodix_ts"); in yogabook_pdev_probe()
460 if (!data->kbd_dev || !data->kbd_dev->driver) { in yogabook_pdev_probe()
461 r = -EPROBE_DEFER; in yogabook_pdev_probe()
465 data->dig_dev = bus_find_device_by_name(&i2c_bus_type, NULL, "i2c-wacom"); in yogabook_pdev_probe()
466 if (!data->dig_dev || !data->dig_dev->driver) { in yogabook_pdev_probe()
467 r = -EPROBE_DEFER; in yogabook_pdev_probe()
472 data->pen_touch_event = devm_gpiod_get(dev, "pen_touch_event", GPIOD_IN); in yogabook_pdev_probe()
473 data->kbd_bl_led_enable = devm_gpiod_get(dev, "enable_keyboard_led", GPIOD_OUT_HIGH); in yogabook_pdev_probe()
476 if (IS_ERR(data->pen_touch_event)) { in yogabook_pdev_probe()
477 r = dev_err_probe(dev, PTR_ERR(data->pen_touch_event), in yogabook_pdev_probe()
482 if (IS_ERR(data->kbd_bl_led_enable)) { in yogabook_pdev_probe()
483 r = dev_err_probe(dev, PTR_ERR(data->kbd_bl_led_enable), in yogabook_pdev_probe()
488 data->kbd_bl_pwm = devm_pwm_get(dev, "pwm_soc_lpss_2"); in yogabook_pdev_probe()
489 if (IS_ERR(data->kbd_bl_pwm)) { in yogabook_pdev_probe()
490 r = dev_err_probe(dev, PTR_ERR(data->kbd_bl_pwm), in yogabook_pdev_probe()
491 "Getting keyboard backlight PWM\n"); in yogabook_pdev_probe()
495 r = gpiod_to_irq(data->pen_touch_event); in yogabook_pdev_probe()
500 data->pen_touch_irq = r; in yogabook_pdev_probe()
502 r = request_irq(data->pen_touch_irq, yogabook_pen_touch_irq, IRQF_TRIGGER_FALLING, in yogabook_pdev_probe()
509 data->set_kbd_backlight = yogabook_pdev_set_kbd_backlight; in yogabook_pdev_probe()
518 free_irq(data->pen_touch_irq, data); in yogabook_pdev_probe()
519 cancel_work_sync(&data->work); in yogabook_pdev_probe()
521 put_device(data->dig_dev); in yogabook_pdev_probe()
522 put_device(data->kbd_dev); in yogabook_pdev_probe()
531 free_irq(data->pen_touch_irq, data); in yogabook_pdev_remove()
532 cancel_work_sync(&data->work); in yogabook_pdev_remove()
533 put_device(data->dig_dev); in yogabook_pdev_remove()
534 put_device(data->kbd_dev); in yogabook_pdev_remove()