2 * This file is part of samsung-ril.
4 * Copyright (C) 2010-2011 Joerie de Gram <j.de.gram@gmail.com>
5 * Copyright (C) 2011-2012 Paul Kocialkowski <contact@paulk.fr>
7 * samsung-ril is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
12 * samsung-ril is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with samsung-ril. If not, see <http://www.gnu.org/licenses/>.
22 #define LOG_TAG "RIL-PWR"
23 #include <utils/Log.h>
25 #include "samsung-ril.h"
29 * Out: RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED
30 * Modem lets us know it's powered on. Though, it's still in LPM and should
31 * be considered as OFF. Send this to update RILJ radio state (OFF)
33 void ipc_pwr_phone_pwr_up(void)
35 ril_data.state.radio_state = RADIO_STATE_OFF;
36 ril_data.state.power_state = IPC_PWR_PHONE_STATE_LPM;
41 void ipc_pwr_phone_reset(void)
43 ril_data.state.radio_state = RADIO_STATE_OFF;
44 ril_request_unsolicited(RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED, NULL, 0);
48 * In: IPC_PWR_PHONE_STATE
49 * Noti from the modem giving current power mode (LPM or NORMAL)
50 * LPM = Low Power Mode (airplane mode for instance)
52 * Out: RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED
53 * Update radio state according to modem power state
55 void ipc_pwr_phone_state(struct ipc_message_info *info)
57 uint8_t state = *((uint8_t *) info->data);
61 case IPC_PWR_R(IPC_PWR_PHONE_STATE_LPM):
62 LOGD("Got power to LPM");
64 if (ril_data.tokens.radio_power != (RIL_Token) 0x00) {
65 ril_request_complete(ril_data.tokens.radio_power, RIL_E_SUCCESS, NULL, 0);
66 ril_data.tokens.radio_power = (RIL_Token) 0x00;
69 ril_data.state.radio_state = RADIO_STATE_OFF;
70 ril_data.state.power_state = IPC_PWR_PHONE_STATE_LPM;
71 ril_request_unsolicited(RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED, NULL, 0);
73 case IPC_PWR_R(IPC_PWR_PHONE_STATE_NORMAL):
74 LOGD("Got power to NORMAL");
76 if (ril_data.tokens.radio_power != (RIL_Token) 0x00) {
77 ril_request_complete(ril_data.tokens.radio_power, RIL_E_SUCCESS, NULL, 0);
78 ril_data.tokens.radio_power = (RIL_Token) 0x00;
81 ril_data.state.radio_state = RADIO_STATE_SIM_NOT_READY;
82 ril_data.state.power_state = IPC_PWR_PHONE_STATE_NORMAL;
83 ril_request_unsolicited(RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED, NULL, 0);
91 * In: RIL_REQUEST_RADIO_POWER
92 * Request ON or OFF radio power mode
94 * Out: IPC_PWR_PHONE_STATE
95 * Order the modem to get in required power mode
97 void ril_request_radio_power(RIL_Token t, void *data, size_t datalen)
99 int power_state = *((int *)data);
100 unsigned short power_data;
102 LOGD("requested power_state is %d", power_state);
104 if (power_state > 0) {
105 LOGD("Request power to NORMAL");
106 power_data = IPC_PWR_PHONE_STATE_NORMAL;
108 ipc_gen_phone_res_expect_to_abort(ril_request_get_id(t), IPC_PWR_PHONE_STATE);
109 ipc_fmt_send(IPC_PWR_PHONE_STATE, IPC_TYPE_EXEC, (void *) &power_data, sizeof(power_data), ril_request_get_id(t));
111 ril_data.tokens.radio_power = t;
113 LOGD("Request power to LPM");
114 power_data = IPC_PWR_PHONE_STATE_LPM;
116 ipc_gen_phone_res_expect_to_abort(ril_request_get_id(t), IPC_PWR_PHONE_STATE);
117 ipc_fmt_send(IPC_PWR_PHONE_STATE, IPC_TYPE_EXEC, (void *) &power_data, sizeof(power_data), ril_request_get_id(t));
119 ril_data.tokens.radio_power = t;