Bring up nokia-sparkler SMP/cpufreq/lk2nd/cam/haptics, fix timer and EDL USB timeout
- Add 0013 early-SCM 4-core SMP + cpufreq kernel patch and clock-frequency DT nodes - Complete nokia-sparkler lk2nd port, boot/X11 session startup, 180-deg cached camera, and 157 Hz haptic audio - Replace root-only timer backend with permissionless sxmo_timer.sh and keypad/hook cancellation - Fix EDL Firehose rawmode ACK, USB active-config preservation, *+# hint, and 30 s default USB timeout - Sync a1120 (cocojamboo) prebuilts, docs, tests, and verified checksums in check-rebuild.sh
This commit is contained in:
1 parent
ab53423e33
commit
d7992904bf
56 files changed
+31850
-28281
No files matched your search
@@ -394,8 +394,8 @@ int runCameraApp(int argc, char** argv) {
|
||||
char c = 'F';
|
||||
(void)::write(writePipe, &c, 1);
|
||||
}
|
||||
for (int s = 0; s < 5 && !vfShouldStop && gRunning && !snapRequested.load(); ++s) {
|
||||
struct timespec ts {0, 20 * 1000 * 1000};
|
||||
if (!vfShouldStop && gRunning && !snapRequested.load()) {
|
||||
struct timespec ts {0, 10 * 1000 * 1000};
|
||||
nanosleep(&ts, nullptr);
|
||||
}
|
||||
} else {
|
||||
|
||||
@@ -1,15 +1,24 @@
|
||||
#include <alsa/asoundlib.h>
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <glob.h>
|
||||
#include <grp.h>
|
||||
#include <linux/input.h>
|
||||
#include <math.h>
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/stat.h>
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#ifndef M_PI
|
||||
#define M_PI 3.14159265358979323846
|
||||
#endif
|
||||
|
||||
static volatile sig_atomic_t g_stop = 0;
|
||||
|
||||
static void handle_signal(int sig) {
|
||||
@@ -133,6 +142,369 @@ static void sleep_ms_interruptible(long ms) {
|
||||
}
|
||||
}
|
||||
|
||||
static int contains_icase(const char* hay, const char* needle) {
|
||||
if (!hay || !needle || !*needle) return 0;
|
||||
size_t nlen = strlen(needle);
|
||||
for (const char* p = hay; *p; ++p) {
|
||||
size_t i = 0;
|
||||
while (i < nlen && p[i] &&
|
||||
tolower((unsigned char)p[i]) == tolower((unsigned char)needle[i])) {
|
||||
++i;
|
||||
}
|
||||
if (i == nlen) return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int is_haptic_audio_device(void) {
|
||||
const char* env_ha = getenv("SXMO_VIBRATE_HAPTIC_AUDIO");
|
||||
if (env_ha && *env_ha == '1') return 1;
|
||||
if (env_ha && *env_ha == '0') return 0;
|
||||
|
||||
int fd = open("/sys/firmware/devicetree/base/compatible", O_RDONLY | O_CLOEXEC);
|
||||
if (fd < 0) return 0;
|
||||
|
||||
char buf[256];
|
||||
ssize_t n = read(fd, buf, sizeof(buf) - 1);
|
||||
close(fd);
|
||||
if (n <= 0) return 0;
|
||||
buf[n] = '\0';
|
||||
|
||||
const char* p = buf;
|
||||
const char* end = buf + n;
|
||||
while (p < end && *p) {
|
||||
if (strcmp(p, "nokia,sparkler") == 0 || strcmp(p, "nokia,leo") == 0) {
|
||||
return 1;
|
||||
}
|
||||
p += strlen(p) + 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int is_non_speaker_audio_route(void) {
|
||||
char buf[128];
|
||||
const char* paths[2];
|
||||
char cfg_dir[448];
|
||||
char cfg_path[512];
|
||||
|
||||
get_sxmo_config_dir(cfg_dir, sizeof(cfg_dir));
|
||||
snprintf(cfg_path, sizeof(cfg_path), "%s/audio_out_device", cfg_dir);
|
||||
paths[0] = "/tmp/sxmo_audio_out_device";
|
||||
paths[1] = cfg_path;
|
||||
|
||||
for (int i = 0; i < 2; ++i) {
|
||||
FILE* fp = fopen(paths[i], "r");
|
||||
if (!fp) continue;
|
||||
if (fgets(buf, sizeof(buf), fp)) {
|
||||
fclose(fp);
|
||||
if (contains_icase(buf, "Headphone") ||
|
||||
contains_icase(buf, "Headset") ||
|
||||
contains_icase(buf, "Bluetooth") ||
|
||||
contains_icase(buf, "bluez")) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
fclose(fp);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int is_pw_sink_muted(void) {
|
||||
FILE* fp = fopen("/tmp/sxmo_pw_sink_muted", "r");
|
||||
if (!fp) return 0;
|
||||
int ch = fgetc(fp);
|
||||
fclose(fp);
|
||||
return ch == '1';
|
||||
}
|
||||
|
||||
struct haptic_ctl_state {
|
||||
snd_ctl_t* ctl;
|
||||
int has_spk_sw;
|
||||
long saved_spk_sw;
|
||||
int changed_spk_sw;
|
||||
int has_pri_mm1;
|
||||
long saved_pri_mm1;
|
||||
int changed_pri_mm1;
|
||||
int has_rx3_mux;
|
||||
unsigned int saved_rx3_mux;
|
||||
int changed_rx3_mux;
|
||||
int has_rx3_vol;
|
||||
long saved_rx3_vol;
|
||||
int changed_rx3_vol;
|
||||
};
|
||||
|
||||
static int ctl_read_elem(snd_ctl_t* ctl, const char* name,
|
||||
snd_ctl_elem_info_t* info,
|
||||
snd_ctl_elem_value_t* val) {
|
||||
snd_ctl_elem_info_clear(info);
|
||||
snd_ctl_elem_info_set_interface(info, SND_CTL_ELEM_IFACE_MIXER);
|
||||
snd_ctl_elem_info_set_name(info, name);
|
||||
if (snd_ctl_elem_info(ctl, info) < 0) return -1;
|
||||
|
||||
snd_ctl_elem_value_clear(val);
|
||||
snd_ctl_elem_value_set_interface(val, SND_CTL_ELEM_IFACE_MIXER);
|
||||
snd_ctl_elem_value_set_name(val, name);
|
||||
if (snd_ctl_elem_read(ctl, val) < 0) return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void haptic_ensure_speaker_ctl(struct haptic_ctl_state* st) {
|
||||
memset(st, 0, sizeof(*st));
|
||||
if (snd_ctl_open(&st->ctl, "hw:0", 0) < 0) {
|
||||
st->ctl = NULL;
|
||||
return;
|
||||
}
|
||||
|
||||
snd_ctl_elem_info_t* info = NULL;
|
||||
snd_ctl_elem_value_t* val = NULL;
|
||||
snd_ctl_elem_info_alloca(&info);
|
||||
snd_ctl_elem_value_alloca(&val);
|
||||
|
||||
if (ctl_read_elem(st->ctl, "PRI_MI2S_RX Audio Mixer MultiMedia1",
|
||||
info, val) == 0) {
|
||||
st->has_pri_mm1 = 1;
|
||||
st->saved_pri_mm1 = snd_ctl_elem_value_get_boolean(val, 0);
|
||||
if (st->saved_pri_mm1 == 0) {
|
||||
snd_ctl_elem_value_set_boolean(val, 0, 1);
|
||||
if (snd_ctl_elem_write(st->ctl, val) >= 0) st->changed_pri_mm1 = 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (ctl_read_elem(st->ctl, "RX3 MIX1 INP1", info, val) == 0) {
|
||||
st->has_rx3_mux = 1;
|
||||
st->saved_rx3_mux = snd_ctl_elem_value_get_enumerated(val, 0);
|
||||
if (st->saved_rx3_mux == 0) {
|
||||
unsigned int items = snd_ctl_elem_info_get_items(info);
|
||||
for (unsigned int i = 0; i < items; ++i) {
|
||||
snd_ctl_elem_info_set_item(info, i);
|
||||
if (snd_ctl_elem_info(st->ctl, info) == 0 &&
|
||||
strcmp(snd_ctl_elem_info_get_item_name(info), "RX1") == 0) {
|
||||
snd_ctl_elem_value_set_enumerated(val, 0, i);
|
||||
if (snd_ctl_elem_write(st->ctl, val) >= 0) st->changed_rx3_mux = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (ctl_read_elem(st->ctl, "SPK DAC Switch", info, val) == 0) {
|
||||
st->has_spk_sw = 1;
|
||||
st->saved_spk_sw = snd_ctl_elem_value_get_boolean(val, 0);
|
||||
if (st->saved_spk_sw == 0) {
|
||||
snd_ctl_elem_value_set_boolean(val, 0, 1);
|
||||
if (snd_ctl_elem_write(st->ctl, val) >= 0) st->changed_spk_sw = 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (ctl_read_elem(st->ctl, "RX3 Digital Volume", info, val) == 0) {
|
||||
st->has_rx3_vol = 1;
|
||||
st->saved_rx3_vol = snd_ctl_elem_value_get_integer(val, 0);
|
||||
if (st->saved_rx3_vol < 80) {
|
||||
long maxv = snd_ctl_elem_info_get_max(info);
|
||||
long target = (maxv >= 88) ? 88 : maxv;
|
||||
snd_ctl_elem_value_set_integer(val, 0, target);
|
||||
if (snd_ctl_elem_write(st->ctl, val) >= 0) st->changed_rx3_vol = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void haptic_restore_speaker_ctl(struct haptic_ctl_state* st) {
|
||||
if (!st || !st->ctl) return;
|
||||
|
||||
snd_ctl_elem_info_t* info = NULL;
|
||||
snd_ctl_elem_value_t* val = NULL;
|
||||
snd_ctl_elem_info_alloca(&info);
|
||||
snd_ctl_elem_value_alloca(&val);
|
||||
|
||||
if (st->changed_rx3_vol && st->has_rx3_vol &&
|
||||
ctl_read_elem(st->ctl, "RX3 Digital Volume", info, val) == 0) {
|
||||
snd_ctl_elem_value_set_integer(val, 0, st->saved_rx3_vol);
|
||||
(void)snd_ctl_elem_write(st->ctl, val);
|
||||
}
|
||||
if (st->changed_spk_sw && st->has_spk_sw &&
|
||||
ctl_read_elem(st->ctl, "SPK DAC Switch", info, val) == 0) {
|
||||
snd_ctl_elem_value_set_boolean(val, 0, st->saved_spk_sw);
|
||||
(void)snd_ctl_elem_write(st->ctl, val);
|
||||
}
|
||||
if (st->changed_rx3_mux && st->has_rx3_mux &&
|
||||
ctl_read_elem(st->ctl, "RX3 MIX1 INP1", info, val) == 0) {
|
||||
snd_ctl_elem_value_set_enumerated(val, 0, st->saved_rx3_mux);
|
||||
(void)snd_ctl_elem_write(st->ctl, val);
|
||||
}
|
||||
if (st->changed_pri_mm1 && st->has_pri_mm1 &&
|
||||
ctl_read_elem(st->ctl, "PRI_MI2S_RX Audio Mixer MultiMedia1",
|
||||
info, val) == 0) {
|
||||
snd_ctl_elem_value_set_boolean(val, 0, st->saved_pri_mm1);
|
||||
(void)snd_ctl_elem_write(st->ctl, val);
|
||||
}
|
||||
snd_ctl_close(st->ctl);
|
||||
st->ctl = NULL;
|
||||
}
|
||||
|
||||
static int write_pcm_frames_all(snd_pcm_t* pcm, const short* buf,
|
||||
snd_pcm_uframes_t frames) {
|
||||
snd_pcm_uframes_t off = 0;
|
||||
while (off < frames && !g_stop) {
|
||||
snd_pcm_sframes_t rc = snd_pcm_writei(pcm, buf + off * 2, frames - off);
|
||||
if (rc == -EAGAIN || rc == -EINTR) {
|
||||
continue;
|
||||
}
|
||||
if (rc < 0) {
|
||||
rc = snd_pcm_recover(pcm, (int)rc, 1);
|
||||
if (rc < 0) return -1;
|
||||
continue;
|
||||
}
|
||||
off += (snd_pcm_uframes_t)rc;
|
||||
}
|
||||
return g_stop ? -1 : 0;
|
||||
}
|
||||
|
||||
static int write_haptic_pulse(snd_pcm_t* pcm, long ms, double amp) {
|
||||
if (ms <= 0 || g_stop) return 0;
|
||||
const long rate = 48000L;
|
||||
const double step = 2.0 * M_PI * 157.0 / (double)rate;
|
||||
const long total_frames = (ms * rate) / 1000L;
|
||||
long fade_frames = (5L * rate) / 1000L;
|
||||
if (fade_frames > total_frames / 2) fade_frames = total_frames / 2;
|
||||
|
||||
short chunk[2400 * 2];
|
||||
long pos = 0;
|
||||
while (pos < total_frames && !g_stop) {
|
||||
long n = total_frames - pos;
|
||||
if (n > 2400L) n = 2400L;
|
||||
for (long i = 0; i < n; ++i) {
|
||||
long idx = pos + i;
|
||||
double env = 1.0;
|
||||
if (fade_frames > 0 && idx < fade_frames) {
|
||||
env = 0.5 * (1.0 - cos(M_PI * (double)idx / (double)fade_frames));
|
||||
} else if (fade_frames > 0 && idx >= total_frames - fade_frames) {
|
||||
long tail = total_frames - 1 - idx;
|
||||
env = 0.5 * (1.0 - cos(M_PI * (double)tail / (double)fade_frames));
|
||||
}
|
||||
double v = env * amp * sin(step * (double)idx);
|
||||
if (v > 32767.0) v = 32767.0;
|
||||
if (v < -32767.0) v = -32767.0;
|
||||
short s = (short)lrint(v);
|
||||
chunk[i * 2] = s;
|
||||
chunk[i * 2 + 1] = s;
|
||||
}
|
||||
if (write_pcm_frames_all(pcm, chunk, (snd_pcm_uframes_t)n) < 0) {
|
||||
return -1;
|
||||
}
|
||||
pos += n;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int write_haptic_silence(snd_pcm_t* pcm, long ms) {
|
||||
if (ms <= 0 || g_stop) return 0;
|
||||
const long total_frames = (ms * 48000L) / 1000L;
|
||||
short zeros[2400 * 2];
|
||||
memset(zeros, 0, sizeof(zeros));
|
||||
|
||||
long pos = 0;
|
||||
while (pos < total_frames && !g_stop) {
|
||||
long n = total_frames - pos;
|
||||
if (n > 2400L) n = 2400L;
|
||||
if (write_pcm_frames_all(pcm, zeros, (snd_pcm_uframes_t)n) < 0) {
|
||||
return -1;
|
||||
}
|
||||
pos += n;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int vibrate_haptic_audio(long duration_ms, int level) {
|
||||
if (is_non_speaker_audio_route()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Match PipeWire socket ownership when invoked from a root hook/shell. */
|
||||
if (getuid() == 0 && access("/run/user/10000/pipewire-0", F_OK) == 0) {
|
||||
(void)initgroups("user", 10000);
|
||||
if (setgid(10000) == 0 && setuid(10000) == 0) {
|
||||
(void)setenv("XDG_RUNTIME_DIR", "/run/user/10000", 1);
|
||||
}
|
||||
} else {
|
||||
const char* xdg = getenv("XDG_RUNTIME_DIR");
|
||||
struct stat st_rt;
|
||||
if (!xdg || !*xdg || stat(xdg, &st_rt) != 0) {
|
||||
char rt_buf[64];
|
||||
snprintf(rt_buf, sizeof(rt_buf), "/run/user/%lu",
|
||||
(unsigned long)getuid());
|
||||
(void)setenv("XDG_RUNTIME_DIR", rt_buf, 1);
|
||||
}
|
||||
}
|
||||
|
||||
struct haptic_ctl_state ctl_st;
|
||||
memset(&ctl_st, 0, sizeof(ctl_st));
|
||||
|
||||
snd_pcm_t* pcm = NULL;
|
||||
const char* devs[2];
|
||||
if (is_pw_sink_muted()) {
|
||||
devs[0] = "plughw:0,0";
|
||||
devs[1] = "default";
|
||||
} else {
|
||||
devs[0] = "default";
|
||||
devs[1] = "plughw:0,0";
|
||||
}
|
||||
|
||||
const char* opened_dev = NULL;
|
||||
for (int i = 0; i < 2 && !pcm; ++i) {
|
||||
if (snd_pcm_open(&pcm, devs[i], SND_PCM_STREAM_PLAYBACK, 0) == 0) {
|
||||
if (snd_pcm_set_params(pcm, SND_PCM_FORMAT_S16_LE,
|
||||
SND_PCM_ACCESS_RW_INTERLEAVED, 2, 48000,
|
||||
1, 500000) < 0) {
|
||||
snd_pcm_close(pcm);
|
||||
pcm = NULL;
|
||||
} else {
|
||||
opened_dev = devs[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!pcm) {
|
||||
fprintf(stderr, "sxmo_vibrate: cannot open haptic audio PCM\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (opened_dev && strcmp(opened_dev, "plughw:0,0") == 0) {
|
||||
haptic_ensure_speaker_ctl(&ctl_st);
|
||||
}
|
||||
|
||||
double amp = 21000.0;
|
||||
if (level <= 1) amp = 13000.0;
|
||||
else if (level >= 3) amp = 29000.0;
|
||||
|
||||
if (level >= 3 || duration_ms <= 90) {
|
||||
long actual_ms = (level == 1 && duration_ms > 55) ? 55 : duration_ms;
|
||||
(void)write_haptic_pulse(pcm, actual_ms, amp);
|
||||
} else {
|
||||
long on_ms = (level == 1) ? 75 : 160;
|
||||
long off_ms = (level == 1) ? 125 : 80;
|
||||
long rem = duration_ms;
|
||||
while (rem > 0 && !g_stop) {
|
||||
long cur_on = (rem < on_ms) ? rem : on_ms;
|
||||
if (write_haptic_pulse(pcm, cur_on, amp) < 0) break;
|
||||
rem -= cur_on;
|
||||
if (rem <= 0 || g_stop) break;
|
||||
long cur_off = (rem < off_ms) ? rem : off_ms;
|
||||
if (write_haptic_silence(pcm, cur_off) < 0) break;
|
||||
rem -= cur_off;
|
||||
}
|
||||
}
|
||||
|
||||
if (g_stop) {
|
||||
(void)snd_pcm_drop(pcm);
|
||||
} else {
|
||||
(void)snd_pcm_drain(pcm);
|
||||
}
|
||||
snd_pcm_close(pcm);
|
||||
haptic_restore_speaker_ctl(&ctl_st);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
if (argc < 2 || argc > 3) {
|
||||
fprintf(stderr, "Usage: sxmo_vibrate duration_ms [strength_number]\n");
|
||||
@@ -174,6 +546,10 @@ int main(int argc, char** argv) {
|
||||
sigaction(SIGTERM, &sa, NULL);
|
||||
sigaction(SIGHUP, &sa, NULL);
|
||||
|
||||
if (is_haptic_audio_device()) {
|
||||
return vibrate_haptic_audio(duration_ms, level);
|
||||
}
|
||||
|
||||
int fd = open_vibrator_device();
|
||||
if (fd < 0) {
|
||||
fprintf(stderr, "sxmo_vibrate: cannot open vibrator device: %s\n",
|
||||
|
||||
@@ -25,15 +25,18 @@
|
||||
|
||||
#define MSM8905_TLMM_GPIO13_PHYS 0x0100d000UL
|
||||
#define MSM8905_TLMM_GPIO13_SIZE 0x1000UL
|
||||
#define GPIO13_CFG_REG 0x0000U
|
||||
#define GPIO13_IO_REG 0x0004U
|
||||
#define GPIO13_CFG_OUT_HIGH 0x02c0U /* OE | 8mA | no pull | func=0 (gpio) */
|
||||
#define GPIO13_CFG_OUT_LOW 0x0201U /* OE | 2mA | pull-down | func=0 (gpio) */
|
||||
#define GPIO13_IO_HIGH 0x0002U /* BIT(1) = GPIO_OUT high */
|
||||
#define GPIO13_IO_LOW 0x0000U
|
||||
|
||||
#define MSM8905_TLMM_GPIO31_PHYS 0x0101f000UL
|
||||
#define MSM8905_TLMM_GPIO31_SIZE 0x1000UL
|
||||
#define MSM8905_TLMM_GPIO32_PHYS 0x01020000UL
|
||||
#define MSM8905_TLMM_GPIO32_SIZE 0x1000UL
|
||||
|
||||
#define TLMM_GPIO_CFG_REG 0x0000U
|
||||
#define TLMM_GPIO_IO_REG 0x0004U
|
||||
#define TLMM_GPIO_CFG_OUT_HIGH 0x02c0U /* OE | 8mA | no pull | func=0 (gpio) */
|
||||
#define TLMM_GPIO_CFG_OUT_LOW 0x0201U /* OE | 2mA | pull-down | func=0 (gpio) */
|
||||
#define TLMM_GPIO_IO_HIGH 0x0002U /* BIT(1) = GPIO_OUT high */
|
||||
#define TLMM_GPIO_IO_LOW 0x0000U
|
||||
|
||||
#define GPIO32_CFG_REG 0x0000U
|
||||
#define GPIO32_CFG_CCI_TIMER1 0x0008U /* 2mA, no pull, func=2 (cci_timer1) */
|
||||
#define GPIO32_CFG_GPIO_OFF 0x0001U /* 2mA, pull-down, func=0 (gpio in) */
|
||||
@@ -79,6 +82,7 @@ module_param_string(next_reboot_mode, next_reboot_mode, sizeof(next_reboot_mode)
|
||||
MODULE_PARM_DESC(next_reboot_mode, "Next reboot target mode (loader, bootloader, fastboot, edl)");
|
||||
|
||||
static void __iomem *tlmm_gpio13_base;
|
||||
static void __iomem *tlmm_gpio31_base;
|
||||
static void __iomem *tlmm_gpio32_base;
|
||||
static void __iomem *gcc_camss_base;
|
||||
static struct regmap *pon_regmap;
|
||||
@@ -86,9 +90,21 @@ static struct sys_off_handler *pon_poweroff_handler;
|
||||
static struct sys_off_handler *pon_restart_handler;
|
||||
static DEFINE_SPINLOCK(torch_lock);
|
||||
static bool is_coconut_dual_led;
|
||||
static bool is_sparkler_dual_gpio_torch;
|
||||
static enum led_brightness top_torch_brightness = LED_OFF;
|
||||
static enum led_brightness current_brightness = LED_OFF;
|
||||
|
||||
static inline void msm8905_tlmm_gpio_set(void __iomem *base, bool high)
|
||||
{
|
||||
if (high) {
|
||||
writel_relaxed(TLMM_GPIO_IO_HIGH, base + TLMM_GPIO_IO_REG);
|
||||
writel_relaxed(TLMM_GPIO_CFG_OUT_HIGH, base + TLMM_GPIO_CFG_REG);
|
||||
} else {
|
||||
writel_relaxed(TLMM_GPIO_IO_LOW, base + TLMM_GPIO_IO_REG);
|
||||
writel_relaxed(TLMM_GPIO_CFG_OUT_LOW, base + TLMM_GPIO_CFG_REG);
|
||||
}
|
||||
}
|
||||
|
||||
static void msm8905_top_torch_hw_enable(enum led_brightness value)
|
||||
{
|
||||
unsigned long flags;
|
||||
@@ -97,8 +113,7 @@ static void msm8905_top_torch_hw_enable(enum led_brightness value)
|
||||
return;
|
||||
|
||||
spin_lock_irqsave(&torch_lock, flags);
|
||||
writel_relaxed(GPIO13_IO_HIGH, tlmm_gpio13_base + GPIO13_IO_REG);
|
||||
writel_relaxed(GPIO13_CFG_OUT_HIGH, tlmm_gpio13_base + GPIO13_CFG_REG);
|
||||
msm8905_tlmm_gpio_set(tlmm_gpio13_base, true);
|
||||
wmb();
|
||||
top_torch_brightness = value;
|
||||
spin_unlock_irqrestore(&torch_lock, flags);
|
||||
@@ -112,8 +127,7 @@ static void msm8905_top_torch_hw_disable(void)
|
||||
return;
|
||||
|
||||
spin_lock_irqsave(&torch_lock, flags);
|
||||
writel_relaxed(GPIO13_IO_LOW, tlmm_gpio13_base + GPIO13_IO_REG);
|
||||
writel_relaxed(GPIO13_CFG_OUT_LOW, tlmm_gpio13_base + GPIO13_CFG_REG);
|
||||
msm8905_tlmm_gpio_set(tlmm_gpio13_base, false);
|
||||
wmb();
|
||||
top_torch_brightness = LED_OFF;
|
||||
spin_unlock_irqrestore(&torch_lock, flags);
|
||||
@@ -139,6 +153,21 @@ static void msm8905_torch_hw_enable(enum led_brightness value)
|
||||
u32 d_count;
|
||||
u32 d_reg;
|
||||
|
||||
if (is_sparkler_dual_gpio_torch) {
|
||||
if (!tlmm_gpio31_base || !tlmm_gpio32_base)
|
||||
return;
|
||||
|
||||
spin_lock_irqsave(&torch_lock, flags);
|
||||
/* Enable flash-en (GPIO_32) then assert flash-now (GPIO_31) digitally. */
|
||||
msm8905_tlmm_gpio_set(tlmm_gpio32_base, true);
|
||||
wmb();
|
||||
msm8905_tlmm_gpio_set(tlmm_gpio31_base, true);
|
||||
wmb();
|
||||
current_brightness = value;
|
||||
spin_unlock_irqrestore(&torch_lock, flags);
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* Scale PWM duty cycle up to 50% (d_count = 64 of N = 128) at max brightness
|
||||
* so the SY7807 remains in continuous Torch mode without triggering its
|
||||
@@ -175,6 +204,17 @@ static void msm8905_torch_hw_disable(void)
|
||||
|
||||
spin_lock_irqsave(&torch_lock, flags);
|
||||
|
||||
if (is_sparkler_dual_gpio_torch) {
|
||||
if (tlmm_gpio31_base)
|
||||
msm8905_tlmm_gpio_set(tlmm_gpio31_base, false);
|
||||
if (tlmm_gpio32_base)
|
||||
msm8905_tlmm_gpio_set(tlmm_gpio32_base, false);
|
||||
wmb();
|
||||
current_brightness = LED_OFF;
|
||||
spin_unlock_irqrestore(&torch_lock, flags);
|
||||
return;
|
||||
}
|
||||
|
||||
writel_relaxed(GPIO32_CFG_GPIO_OFF, tlmm_gpio32_base + GPIO32_CFG_REG);
|
||||
writel_relaxed(0x0U, gcc_camss_base + GCC_CAMSS_GP1_CBCR_STOCK);
|
||||
writel_relaxed(0x0U, gcc_camss_base + GCC_CAMSS_GP1_CBCR_MAIN);
|
||||
@@ -419,57 +459,59 @@ static int __init msm8905_torch_init(void)
|
||||
|
||||
if (!of_machine_is_compatible("qcom,msm8905") &&
|
||||
!of_machine_is_compatible("qcom,msm8909") &&
|
||||
!of_machine_is_compatible("nokia,argon")) {
|
||||
!of_machine_is_compatible("nokia,argon") &&
|
||||
!of_machine_is_compatible("nokia,sparkler") &&
|
||||
!of_machine_is_compatible("nokia,leo")) {
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
is_coconut_dual_led = of_machine_is_compatible("nokia,coconut");
|
||||
is_sparkler_dual_gpio_torch = of_machine_is_compatible("nokia,sparkler") ||
|
||||
of_machine_is_compatible("nokia,leo");
|
||||
|
||||
tlmm_gpio32_base = ioremap(MSM8905_TLMM_GPIO32_PHYS, MSM8905_TLMM_GPIO32_SIZE);
|
||||
if (!tlmm_gpio32_base)
|
||||
return -ENOMEM;
|
||||
|
||||
gcc_camss_base = ioremap(MSM8905_GCC_CAMSS_PHYS, MSM8905_GCC_CAMSS_SIZE);
|
||||
if (!gcc_camss_base) {
|
||||
iounmap(tlmm_gpio32_base);
|
||||
return -ENOMEM;
|
||||
if (is_sparkler_dual_gpio_torch) {
|
||||
tlmm_gpio31_base = ioremap(MSM8905_TLMM_GPIO31_PHYS, MSM8905_TLMM_GPIO31_SIZE);
|
||||
if (!tlmm_gpio31_base) {
|
||||
iounmap(tlmm_gpio32_base);
|
||||
tlmm_gpio32_base = NULL;
|
||||
return -ENOMEM;
|
||||
}
|
||||
} else {
|
||||
gcc_camss_base = ioremap(MSM8905_GCC_CAMSS_PHYS, MSM8905_GCC_CAMSS_SIZE);
|
||||
if (!gcc_camss_base) {
|
||||
iounmap(tlmm_gpio32_base);
|
||||
tlmm_gpio32_base = NULL;
|
||||
return -ENOMEM;
|
||||
}
|
||||
}
|
||||
|
||||
msm8905_torch_hw_disable();
|
||||
|
||||
is_coconut_dual_led = of_machine_is_compatible("nokia,coconut");
|
||||
if (is_coconut_dual_led) {
|
||||
tlmm_gpio13_base = ioremap(MSM8905_TLMM_GPIO13_PHYS, MSM8905_TLMM_GPIO13_SIZE);
|
||||
if (!tlmm_gpio13_base) {
|
||||
iounmap(gcc_camss_base);
|
||||
iounmap(tlmm_gpio32_base);
|
||||
return -ENOMEM;
|
||||
ret = -ENOMEM;
|
||||
goto err_unmap;
|
||||
}
|
||||
msm8905_top_torch_hw_disable();
|
||||
|
||||
ret = led_classdev_register(NULL, &msm8905_top_torch_led);
|
||||
if (ret) {
|
||||
iounmap(tlmm_gpio13_base);
|
||||
tlmm_gpio13_base = NULL;
|
||||
iounmap(gcc_camss_base);
|
||||
iounmap(tlmm_gpio32_base);
|
||||
return ret;
|
||||
}
|
||||
if (ret)
|
||||
goto err_unmap_gpio13;
|
||||
|
||||
ret = led_classdev_register(NULL, &msm8905_cam_flash_led);
|
||||
if (ret) {
|
||||
led_classdev_unregister(&msm8905_top_torch_led);
|
||||
iounmap(tlmm_gpio13_base);
|
||||
tlmm_gpio13_base = NULL;
|
||||
iounmap(gcc_camss_base);
|
||||
iounmap(tlmm_gpio32_base);
|
||||
return ret;
|
||||
goto err_unmap_gpio13;
|
||||
}
|
||||
} else {
|
||||
ret = led_classdev_register(NULL, &msm8905_torch_led);
|
||||
if (ret) {
|
||||
iounmap(gcc_camss_base);
|
||||
iounmap(tlmm_gpio32_base);
|
||||
return ret;
|
||||
}
|
||||
if (ret)
|
||||
goto err_unmap;
|
||||
}
|
||||
|
||||
msm8905_pon_lookup_regmap();
|
||||
@@ -487,11 +529,32 @@ static int __init msm8905_torch_init(void)
|
||||
if (is_coconut_dual_led) {
|
||||
pr_info("leds-msm8905-torch: registered white:torch on GPIO_13 and camera:flash on GPIO_32 (cci_timer1 150kHz PWM), pon_regmap=%s\n",
|
||||
pon_regmap ? "ready" : "none");
|
||||
} else if (is_sparkler_dual_gpio_torch) {
|
||||
pr_info("leds-msm8905-torch: registered white:torch on GPIO_32/GPIO_31 (BC847BS), pon_regmap=%s\n",
|
||||
pon_regmap ? "ready" : "none");
|
||||
} else {
|
||||
pr_info("leds-msm8905-torch: registered white:torch on GPIO_32 (cci_timer1 150kHz PWM), pon_regmap=%s\n",
|
||||
pon_regmap ? "ready" : "none");
|
||||
}
|
||||
return 0;
|
||||
|
||||
err_unmap_gpio13:
|
||||
iounmap(tlmm_gpio13_base);
|
||||
tlmm_gpio13_base = NULL;
|
||||
err_unmap:
|
||||
if (tlmm_gpio31_base) {
|
||||
iounmap(tlmm_gpio31_base);
|
||||
tlmm_gpio31_base = NULL;
|
||||
}
|
||||
if (gcc_camss_base) {
|
||||
iounmap(gcc_camss_base);
|
||||
gcc_camss_base = NULL;
|
||||
}
|
||||
if (tlmm_gpio32_base) {
|
||||
iounmap(tlmm_gpio32_base);
|
||||
tlmm_gpio32_base = NULL;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void __exit msm8905_torch_exit(void)
|
||||
@@ -512,8 +575,18 @@ static void __exit msm8905_torch_exit(void)
|
||||
iounmap(tlmm_gpio13_base);
|
||||
tlmm_gpio13_base = NULL;
|
||||
}
|
||||
iounmap(gcc_camss_base);
|
||||
iounmap(tlmm_gpio32_base);
|
||||
if (tlmm_gpio31_base) {
|
||||
iounmap(tlmm_gpio31_base);
|
||||
tlmm_gpio31_base = NULL;
|
||||
}
|
||||
if (gcc_camss_base) {
|
||||
iounmap(gcc_camss_base);
|
||||
gcc_camss_base = NULL;
|
||||
}
|
||||
if (tlmm_gpio32_base) {
|
||||
iounmap(tlmm_gpio32_base);
|
||||
tlmm_gpio32_base = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
module_init(msm8905_torch_init);
|
||||
|
||||
@@ -161,6 +161,7 @@ struct msm8905_cam_dev {
|
||||
|
||||
u8 *raw_dma_buf;
|
||||
dma_addr_t raw_dma_phys;
|
||||
u8 row_buf[2][CAM_RAW_STRIDE] __aligned(8);
|
||||
|
||||
u8 *mmap_bufs[CAM_MAX_MMAP_BUFS];
|
||||
bool buf_queued[CAM_MAX_MMAP_BUFS];
|
||||
@@ -703,11 +704,23 @@ static void msm8905_cam_demosaic(const u8 *raw, u8 *rgb, bool rotate_180)
|
||||
{
|
||||
u32 y, x;
|
||||
u32 idx = 0;
|
||||
u8 *row0_buf = g_cam ? g_cam->row_buf[0] : NULL;
|
||||
u8 *row1_buf = g_cam ? g_cam->row_buf[1] : NULL;
|
||||
|
||||
for (y = 0; y < CAM_OUT_HEIGHT; y++) {
|
||||
u32 src_y = rotate_180 ? CAM_OUT_HEIGHT - 1U - y : y;
|
||||
const u8 *r0 = raw + (2U * src_y) * CAM_RAW_STRIDE;
|
||||
const u8 *r1 = raw + (2U * src_y + 1U) * CAM_RAW_STRIDE;
|
||||
const u8 *dma_r0 = raw + (2U * src_y) * CAM_RAW_STRIDE;
|
||||
const u8 *dma_r1 = raw + (2U * src_y + 1U) * CAM_RAW_STRIDE;
|
||||
const u8 *r0 = dma_r0;
|
||||
const u8 *r1 = dma_r1;
|
||||
|
||||
/* Burst-copy from uncached coherent DMA memory into L1-cached line buffers. */
|
||||
if (row0_buf && row1_buf) {
|
||||
memcpy(row0_buf, dma_r0, CAM_RAW_STRIDE);
|
||||
memcpy(row1_buf, dma_r1, CAM_RAW_STRIDE);
|
||||
r0 = row0_buf;
|
||||
r1 = row1_buf;
|
||||
}
|
||||
|
||||
for (x = 0; x < CAM_OUT_WIDTH; x += 2U) {
|
||||
u32 src_x = rotate_180 ? CAM_OUT_WIDTH - 2U - x : x;
|
||||
@@ -1215,8 +1228,10 @@ static int __init msm8905_cam_init(void)
|
||||
return -ENOMEM;
|
||||
|
||||
mutex_init(&cam->lock);
|
||||
/* The 2720 Flip sensor is mounted 180 degrees from the other Nokia targets. */
|
||||
cam->rotate_180 = of_machine_is_compatible("nokia,beatles");
|
||||
/* The 2720 Flip, 8000 4G, and 6300 4G sensors are mounted 180 degrees rotated. */
|
||||
cam->rotate_180 = of_machine_is_compatible("nokia,beatles") ||
|
||||
of_machine_is_compatible("nokia,sparkler") ||
|
||||
of_machine_is_compatible("nokia,leo");
|
||||
|
||||
cam->pdev = platform_device_register_simple("msm8905-cam", -1, NULL, 0);
|
||||
if (IS_ERR(cam->pdev)) {
|
||||
|
||||
@@ -1210,6 +1210,7 @@ clear_all_notifications_now(void)
|
||||
"dunstctl close-all >/dev/null 2>&1; "
|
||||
"dunstctl history-clear >/dev/null 2>&1; "
|
||||
"pkill -x dunstify >/dev/null 2>&1; "
|
||||
"/usr/bin/sxmo_timer.sh stop_ringing >/dev/null 2>&1; "
|
||||
"sxmo_hook_statusbar.sh notifications >/dev/null 2>&1");
|
||||
}
|
||||
|
||||
@@ -2211,6 +2212,72 @@ bt_is_unblocked_fast(void)
|
||||
return unblocked;
|
||||
}
|
||||
|
||||
static int
|
||||
timer_menu_state(char *desc, size_t desc_len)
|
||||
{
|
||||
if (desc && desc_len > 0)
|
||||
desc[0] = '\0';
|
||||
|
||||
const char *rdir = getenv("XDG_RUNTIME_DIR");
|
||||
const char *roots[3];
|
||||
int nroots = 0;
|
||||
if (rdir && rdir[0])
|
||||
roots[nroots++] = rdir;
|
||||
if (!rdir || strcmp(rdir, "/run/user/10000") != 0)
|
||||
roots[nroots++] = "/run/user/10000";
|
||||
if (!rdir || strcmp(rdir, "/tmp") != 0)
|
||||
roots[nroots++] = "/tmp";
|
||||
|
||||
int state = 0;
|
||||
for (int i = 0; i < nroots && state < 2; i++) {
|
||||
char tdir[256];
|
||||
snprintf(tdir, sizeof(tdir), "%s/sxmo_timers", roots[i]);
|
||||
DIR *d = opendir(tdir);
|
||||
if (!d)
|
||||
continue;
|
||||
struct dirent *ent;
|
||||
while ((ent = readdir(d)) != NULL) {
|
||||
size_t nlen = strlen(ent->d_name);
|
||||
if (nlen <= 6 || strcmp(ent->d_name + nlen - 6, ".timer") != 0)
|
||||
continue;
|
||||
char *endp = NULL;
|
||||
long pid = strtol(ent->d_name, &endp, 10);
|
||||
if (!endp || strcmp(endp, ".timer") != 0 || pid <= 0 ||
|
||||
kill((pid_t)pid, 0) != 0)
|
||||
continue;
|
||||
char fpath[384];
|
||||
snprintf(fpath, sizeof(fpath), "%s/%s", tdir, ent->d_name);
|
||||
char line[128] = "";
|
||||
if (!read_first_line(fpath, line, sizeof(line)))
|
||||
continue;
|
||||
char tmode[32] = "", tend[32] = "", tlabel[64] = "";
|
||||
int nf = sscanf(line, "%31s %31s %63[^\n]", tmode, tend, tlabel);
|
||||
if (nf >= 1 && strcmp(tmode, "ringing") == 0) {
|
||||
state = 2;
|
||||
if (desc && desc_len > 0 && tlabel[0])
|
||||
snprintf(desc, desc_len, "%s", tlabel);
|
||||
break;
|
||||
}
|
||||
if (nf >= 1 && strcmp(tmode, "running") == 0 && state == 0) {
|
||||
state = 1;
|
||||
if (desc && desc_len > 0 && tlabel[0])
|
||||
snprintf(desc, desc_len, "%s", tlabel);
|
||||
}
|
||||
}
|
||||
closedir(d);
|
||||
}
|
||||
|
||||
if (state < 2 && access("/tmp/sxmo_timer_ringing", F_OK) == 0) {
|
||||
char rbuf[32] = "";
|
||||
if (read_first_line("/tmp/sxmo_timer_ringing", rbuf, sizeof(rbuf))) {
|
||||
long rpid = strtol(rbuf, NULL, 10);
|
||||
if (rpid > 0 && kill((pid_t)rpid, 0) == 0)
|
||||
state = 2;
|
||||
}
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
static int
|
||||
count_notifications(void)
|
||||
{
|
||||
@@ -2653,6 +2720,21 @@ open_builtin_menu(const char *menu_name, int keep_idx)
|
||||
if (strcmp(menu_name, "sys") == 0) {
|
||||
reset_session_defaults(1, "Sys");
|
||||
append_active_call_entries();
|
||||
char tdesc[64] = "";
|
||||
int tstate = timer_menu_state(tdesc, sizeof(tdesc));
|
||||
if (tstate == 2) {
|
||||
if (tdesc[0])
|
||||
snprintf(label, sizeof(label), "%s Stop Timer (%s)", ICON_CLK, tdesc);
|
||||
else
|
||||
snprintf(label, sizeof(label), "%s Stop Timer", ICON_CLK);
|
||||
add_menu_item(label, "/usr/bin/sxmo_timer.sh stop", 0);
|
||||
} else if (tstate == 1) {
|
||||
if (tdesc[0])
|
||||
snprintf(label, sizeof(label), "%s Cancel Timer (%s)", ICON_CLK, tdesc);
|
||||
else
|
||||
snprintf(label, sizeof(label), "%s Cancel Timer", ICON_CLK);
|
||||
add_menu_item(label, "/usr/bin/sxmo_timer.sh stop", 0);
|
||||
}
|
||||
int nnotifs = count_notifications();
|
||||
int dunst_vis = dunst_window_visible();
|
||||
if (nnotifs > 0) {
|
||||
|
||||
Reference in new issue
Block a user