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 TIMEOUT_RESET_BIT 0x80
46 static int send_msg(unsigned int s_bits, unsigned int timeout)
51 struct sockaddr_un remote;
57 sock = socket(AF_UNIX, SOCK_DGRAM, 0);
59 ERR("pm socket() failed");
63 remote.sun_family = AF_UNIX;
64 if(strlen(SOCK_PATH) >= sizeof(remote.sun_path)) {
65 ERR("socket path is vey long");
68 strncpy(remote.sun_path, SOCK_PATH, sizeof(remote.sun_path));
70 rc = sendto(sock, (void *)&p, sizeof(p), 0, (struct sockaddr *)&remote,
71 sizeof(struct sockaddr_un));
73 ERR("pm socket sendto() failed");
81 API int pm_change_state(unsigned int s_bits)
83 /* s_bits is LCD_NORMAL 0x1, LCD_DIM 0x2, LCD_OFF 0x4, SUSPEND 0x8
84 * Stage change to NORMAL 0x100
85 * Stage change to LCDDIM 0x200
86 * Stage change to LCDOFF 0x400
87 * Stage change to SLEEP 0x800
99 return send_msg(s_bits << SHIFT_CHANGE_STATE, 0);
102 API int pm_lock_state(unsigned int s_bits, unsigned int flag,
103 unsigned int timeout)
113 if (flag & GOTO_STATE_NOW)
114 /* if the flag is true, go to the locking state directly */
115 s_bits = s_bits | (s_bits << SHIFT_CHANGE_STATE);
116 return send_msg(s_bits, timeout);
119 API int pm_unlock_state(unsigned int s_bits, unsigned int flag)
130 s_bits = (s_bits << SHIFT_UNLOCK);
131 s_bits = (s_bits | (flag << SHIFT_UNLOCK_PARAMETER));
132 return send_msg(s_bits, 0);