4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: DongGi Jang <dg0402.jang@samsung.com>
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
23 #include <sys/types.h>
24 #include <sys/socket.h>
29 #include <linux/limits.h>
34 #define SOCK_PATH "/tmp/pm_sock"
35 #define SHIFT_UNLOCK 4
36 #define SHIFT_UNLOCK_PARAMETER 12
37 #define SHIFT_CHANGE_STATE 8
38 #define SHIFT_HOLD_KEY_BLOCK 16
39 #define TIMEOUT_RESET_BIT 0x80
47 static int send_msg(unsigned int s_bits, unsigned int timeout)
52 struct sockaddr_un remote;
58 sock = socket(AF_UNIX, SOCK_DGRAM, 0);
60 ERR("pm socket() failed");
64 remote.sun_family = AF_UNIX;
65 if(strlen(SOCK_PATH) >= sizeof(remote.sun_path)) {
66 ERR("socket path is vey long");
69 strncpy(remote.sun_path, SOCK_PATH, sizeof(remote.sun_path));
71 rc = sendto(sock, (void *)&p, sizeof(p), 0, (struct sockaddr *)&remote,
72 sizeof(struct sockaddr_un));
74 ERR("pm socket sendto() failed");
82 API int pm_change_state(unsigned int s_bits)
84 /* s_bits is LCD_NORMAL 0x1, LCD_DIM 0x2, LCD_OFF 0x4, SUSPEND 0x8
85 * Stage change to NORMAL 0x100
86 * Stage change to LCDDIM 0x200
87 * Stage change to LCDOFF 0x400
88 * Stage change to SLEEP 0x800
100 return send_msg(s_bits << SHIFT_CHANGE_STATE, 0);
103 API int pm_lock_state(unsigned int s_bits, unsigned int flag,
104 unsigned int timeout)
114 if (flag & GOTO_STATE_NOW)
115 /* if the flag is true, go to the locking state directly */
116 s_bits = s_bits | (s_bits << SHIFT_CHANGE_STATE);
117 if (flag & HOLD_KEY_BLOCK)
118 s_bits = s_bits | (1 << SHIFT_HOLD_KEY_BLOCK);
120 return send_msg(s_bits, timeout);
123 API int pm_unlock_state(unsigned int s_bits, unsigned int flag)
134 s_bits = (s_bits << SHIFT_UNLOCK);
135 s_bits = (s_bits | (flag << SHIFT_UNLOCK_PARAMETER));
136 return send_msg(s_bits, 0);