6 #include <lib/base/init.h>
7 #include <lib/base/init_num.h>
8 #include <lib/base/eerror.h>
9 #include <lib/base/ebase.h>
10 #include <lib/driver/avswitch.h>
12 eAVSwitch *eAVSwitch::instance = 0;
14 eAVSwitch::eAVSwitch()
19 m_fp_fd = open("/dev/dbox/fp0", O_RDONLY|O_NONBLOCK);
22 eDebug("couldnt open /dev/dbox/fp0 to monitor vcr scart slow blanking changed!");
27 m_fp_notifier = eSocketNotifier::create(eApp, m_fp_fd, eSocketNotifier::Read|POLLERR);
28 CONNECT(m_fp_notifier->activated, eAVSwitch::fp_event);
32 #ifndef FP_IOCTL_GET_EVENT
33 #define FP_IOCTL_GET_EVENT 20
36 #ifndef FP_IOCTL_GET_VCR
37 #define FP_IOCTL_GET_VCR 7
40 #ifndef FP_EVENT_VCR_SB_CHANGED
41 #define FP_EVENT_VCR_SB_CHANGED 1
44 int eAVSwitch::getVCRSlowBlanking()
49 FILE *f = fopen("/proc/stb/fp/vcr_fns", "r");
52 if (fscanf(f, "%d", &val) != 1)
53 eDebug("read /proc/stb/fp/vcr_fns failed!! (%m)");
56 else if (ioctl(m_fp_fd, FP_IOCTL_GET_VCR, &val) < 0)
57 eDebug("FP_GET_VCR failed (%m)");
62 void eAVSwitch::fp_event(int what)
64 if (what & POLLERR) // driver not ready for fp polling
66 eDebug("fp driver not read for polling.. so disable polling");
67 m_fp_notifier->stop();
71 FILE *f = fopen("/proc/stb/fp/events", "r");
75 if (fscanf(f, "%d", &events) != 1)
76 eDebug("read /proc/stb/fp/events failed!! (%m)");
77 else if (events & FP_EVENT_VCR_SB_CHANGED)
78 /* emit */ vcr_sb_notifier(getVCRSlowBlanking());
83 int val = FP_EVENT_VCR_SB_CHANGED; // ask only for this event
84 if (ioctl(m_fp_fd, FP_IOCTL_GET_EVENT, &val) < 0)
85 eDebug("FP_IOCTL_GET_EVENT failed (%m)");
86 else if (val & FP_EVENT_VCR_SB_CHANGED)
87 /* emit */ vcr_sb_notifier(getVCRSlowBlanking());
92 eAVSwitch::~eAVSwitch()
98 eAVSwitch *eAVSwitch::getInstance()
103 bool eAVSwitch::haveScartSwitch()
106 int fd = open("/proc/stb/avs/0/input_choices", O_RDONLY);
108 eDebug("cannot open /proc/stb/avs/0/input_choices");
113 return !!strstr(tmp, "scart");
116 void eAVSwitch::setInput(int val)
124 const char *input[] = {"encoder", "scart", "aux"};
128 if((fd = open("/proc/stb/avs/0/input", O_WRONLY)) < 0) {
129 eDebug("cannot open /proc/stb/avs/0/input");
133 write(fd, input[val], strlen(input[val]));
140 void eAVSwitch::setFastBlank(int val)
143 const char *fb[] = {"low", "high", "vcr"};
145 if((fd = open("/proc/stb/avs/0/fb", O_WRONLY)) < 0) {
146 eDebug("cannot open /proc/stb/avs/0/fb");
150 write(fd, fb[val], strlen(fb[0]));
154 void eAVSwitch::setColorFormat(int format)
161 const char *cvbs="cvbs";
162 const char *rgb="rgb";
163 const char *svideo="svideo";
164 const char *yuv="yuv";
167 if((fd = open("/proc/stb/avs/0/colorformat", O_WRONLY)) < 0) {
168 printf("cannot open /proc/stb/avs/0/colorformat\n");
173 write(fd, cvbs, strlen(cvbs));
176 write(fd, rgb, strlen(rgb));
179 write(fd, svideo, strlen(svideo));
182 write(fd, yuv, strlen(yuv));
188 void eAVSwitch::setAspectRatio(int ratio)
194 3-16:9 forced ("panscan")
197 6-16:9 forced ("letterbox")
199 const char *aspect[] = {"4:3", "4:3", "any", "16:9", "16:10", "16:10", "16:9", "16:9"};
200 const char *policy[] = {"letterbox", "panscan", "bestfit", "panscan", "letterbox", "panscan", "letterbox"};
203 if((fd = open("/proc/stb/video/aspect", O_WRONLY)) < 0) {
204 eDebug("cannot open /proc/stb/video/aspect");
207 // eDebug("set aspect to %s", aspect[ratio]);
208 write(fd, aspect[ratio], strlen(aspect[ratio]));
211 if((fd = open("/proc/stb/video/policy", O_WRONLY)) < 0) {
212 eDebug("cannot open /proc/stb/video/policy");
215 // eDebug("set ratio to %s", policy[ratio]);
216 write(fd, policy[ratio], strlen(policy[ratio]));
221 void eAVSwitch::setVideomode(int mode)
223 const char *pal="pal";
224 const char *ntsc="ntsc";
226 if (mode == m_video_mode)
231 int fd1 = open("/proc/stb/video/videomode_50hz", O_WRONLY);
233 eDebug("cannot open /proc/stb/video/videomode_50hz");
236 int fd2 = open("/proc/stb/video/videomode_60hz", O_WRONLY);
238 eDebug("cannot open /proc/stb/video/videomode_60hz");
242 write(fd1, pal, strlen(pal));
243 write(fd2, ntsc, strlen(ntsc));
249 int fd = open("/proc/stb/video/videomode", O_WRONLY);
251 eDebug("cannot open /proc/stb/video/videomode");
256 write(fd, pal, strlen(pal));
259 write(fd, ntsc, strlen(ntsc));
262 eDebug("unknown videomode %d", mode);
270 void eAVSwitch::setWSS(int val) // 0 = auto, 1 = auto(4:3_off)
273 if((fd = open("/proc/stb/denc/0/wss", O_WRONLY)) < 0) {
274 eDebug("cannot open /proc/stb/denc/0/wss");
277 const char *wss[] = {
278 "off", "auto", "auto(4:3_off)", "4:3_full_format", "16:9_full_format",
279 "14:9_letterbox_center", "14:9_letterbox_top", "16:9_letterbox_center",
280 "16:9_letterbox_top", ">16:9_letterbox_center", "14:9_full_format"
282 write(fd, wss[val], strlen(wss[val]));
283 // eDebug("set wss to %s", wss[val]);
287 void eAVSwitch::setSlowblank(int val)
290 if((fd = open("/proc/stb/avs/0/sb", O_WRONLY)) < 0) {
291 eDebug("cannot open /proc/stb/avs/0/sb");
294 const char *sb[] = {"0", "6", "12", "vcr", "auto"};
295 write(fd, sb[val], strlen(sb[val]));
296 // eDebug("set slow blanking to %s", sb[val]);
300 //FIXME: correct "run/startlevel"
301 eAutoInitP0<eAVSwitch> init_avswitch(eAutoInitNumbers::rc, "AVSwitch Driver");