1 /* 2 * Access a PWM server to update a display panel backlight. 3 * 4 * Copyright (C) 2018, 2020 Paul Boddie <paul@boddie.org.uk> 5 * 6 * This program is free software; you can redistribute it and/or 7 * modify it under the terms of the GNU General Public License as 8 * published by the Free Software Foundation; either version 2 of 9 * the License, or (at your option) any later version. 10 * 11 * This program is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with this program; if not, write to the Free Software 18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, 19 * Boston, MA 02110-1301, USA 20 */ 21 22 #include <l4/re/env> 23 #include <l4/sys/capability> 24 25 #include <stdlib.h> 26 27 #include <l4/devices/pwm-client.h> 28 29 #include <ipc/server.h> 30 #include "backlight_object_server.h" 31 32 /* PWM access abstractions. */ 33 34 static L4::Cap<Pwm_device_interface> pwm_device; 35 36 37 38 /* Backlight device. */ 39 40 class server_BacklightObject : public BacklightObject 41 { 42 int _min, _max; 43 44 public: 45 explicit server_BacklightObject(int min, int max) 46 : _min(min), _max(max) 47 { 48 } 49 50 /* Disable the backlight. */ 51 52 long disable() 53 { 54 pwm_device->disable(); 55 return L4_EOK; 56 } 57 58 /* Enable the backlight. */ 59 60 long enable() 61 { 62 pwm_device->enable(); 63 return L4_EOK; 64 } 65 66 /* Use the PWM device to update the backlight level. */ 67 68 long set_brightness(int level) 69 { 70 pwm_device->set_duty(level); 71 return L4_EOK; 72 } 73 }; 74 75 76 77 /* Arguments: <minimum level> <maximum level> */ 78 79 int main(int argc, char *argv[]) 80 { 81 int min, max; 82 83 if (argc < 3) 84 return 1; 85 86 /* Obtain a reference to the PWM device. */ 87 88 pwm_device = L4Re::Env::env()->get_cap<Pwm_device_interface>("pwm"); 89 if (!pwm_device.is_valid()) return 1; 90 91 /* Initialise and register a new server object. */ 92 93 min = atoi(argv[1]); 94 max = atoi(argv[2]); 95 96 server_BacklightObject obj(min, max); 97 l4_cap_idx_t server; 98 99 if (ipc_server_bind("backlight", (l4_umword_t) &obj, &server)) return 1; 100 101 /* Enter the IPC server loop. */ 102 103 ipc_server_loop(BacklightObject_expected_items, &obj, 104 (ipc_server_handler_type) handle_BacklightObject); 105 return 0; 106 }