Merge branch 'org.openembedded.dev' of git://git.openembedded.net/openembedded into...
[vuplus_openembedded] / packages / enigma / enigma / rotor_fix.diff
1 diff -Naur enigma_org/include/lib/dvb/frontend.h enigma/include/lib/dvb/frontend.h
2 --- enigma_org/include/lib/dvb/frontend.h       2007-08-06 22:54:26.000000000 +0200
3 +++ enigma/include/lib/dvb/frontend.h   2007-08-06 22:47:44.000000000 +0200
4 @@ -74,41 +74,43 @@
5  class eFrontend: public Object
6  {
7         int type,
8 -                       fd,
9 +               fd,
10  #if HAVE_DVB_API_VERSION < 3
11 -                       secfd,
12 +               secfd,
13  #else
14 -                       curContTone,
15 -                       curVoltage,
16 +               curContTone,
17 +               curVoltage,
18  #endif
19 -                       needreset,
20 -                       lastcsw,
21 -                       lastucsw,
22 -                       lastToneBurst,
23 -                       lastRotorCmd,
24 -                       lastSmatvFreq,
25 -                       curRotorPos;    // current Orbital Position
26 +               needreset,
27 +               lastcsw,
28 +               lastucsw,
29 +               lastToneBurst,
30 +               lastRotorCmd,
31 +               lastSmatvFreq,
32 +               curRotorPos;    // current Orbital Position
33  
34         eLNB *lastLNB;
35         eTransponder *transponder;
36         static eFrontend *frontend;
37         eTimer rotorTimer1, rotorTimer2, 
38  #if HAVE_DVB_API_VERSION >=3
39 -                               timeout,
40 +               timeout,
41  #endif
42 -                               checkRotorLockTimer, checkLockTimer, updateTransponderTimer;
43 +               checkRotorLockTimer, checkLockTimer, updateTransponderTimer;
44         eSocketNotifier *sn;
45         int tries, noRotorCmd, wasLoopthrough, lostlockcount;
46         Signal1<void, eTransponder*> tpChanged;
47  // ROTOR INPUTPOWER
48         timeval rotorTimeout;
49 -       int idlePowerInput;
50 -       int runningPowerInput;
51 -       int newPos;
52 +       int idlePowerInput_l,
53 +               idlePowerInput_h,
54 +               runningPowerInput,
55 +               newPos,
56 +               voltageState;
57  // Non blocking rotor turning
58         int DeltaA,
59 -                       voltage,
60 -                       increased;
61 +               voltage,
62 +               increased;
63  ///////////////////
64  #if HAVE_DVB_API_VERSION < 3
65         FrontendParameters front;
66 diff -Naur enigma_org/lib/dvb/frontend.cpp enigma/lib/dvb/frontend.cpp
67 --- enigma_org/lib/dvb/frontend.cpp     2007-08-06 22:54:26.000000000 +0200
68 +++ enigma/lib/dvb/frontend.cpp 2007-08-06 22:55:48.000000000 +0200
69 @@ -29,6 +29,10 @@
70  
71  eFrontend* eFrontend::frontend;
72  
73 +#ifndef I2C_SLAVE_FORCE
74 +#define I2C_SLAVE_FORCE        0x0706
75 +#endif
76 +
77  eFrontend::eFrontend(int type, const char *demod, const char *sec)
78  :type(type), 
79         curRotorPos(10000), transponder(0), rotorTimer1(eApp), 
80 @@ -37,7 +41,8 @@
81         timeout(eApp), 
82  #endif
83         checkRotorLockTimer(eApp), checkLockTimer(eApp), 
84 -       updateTransponderTimer(eApp), sn(0), noRotorCmd(0)
85 +       updateTransponderTimer(eApp), sn(0), noRotorCmd(0),
86 +       idlePowerInput_l(0), idlePowerInput_h(0)
87  {
88         CONNECT(rotorTimer1.timeout, eFrontend::RotorStartLoop );
89         CONNECT(rotorTimer2.timeout, eFrontend::RotorRunningLoop );
90 @@ -112,6 +117,40 @@
91         }
92  }
93  
94 +#define STATIC 0
95 +#define DYNAMIC 1
96 +void setCurrentLimitingMode(int mode)
97 +{
98 +#if HAVE_DVB_API_VERSION < 3
99 +#warning FIXME setCurrentLimitingMode just for frontends with LNBP21
100 +       if ( eSystemInfo::getInstance()->getHwType() == eSystemInfo::DM7020 
101 +               || eSystemInfo::getInstance()->getHwType() == eSystemInfo::DM500PLUS
102 +               || eSystemInfo::getInstance()->getHwType() == eSystemInfo::DM600PVR )
103 +       {
104 +               int fd=::open("/dev/i2c/0", O_RDWR);
105 +               if ( fd >= 0 )
106 +               {
107 +                       unsigned char data[2];
108 +                       ::ioctl(fd, I2C_SLAVE_FORCE, 0x10 >> 1);
109 +                       if(::read(fd, data, 1) != 1)
110 +                               eDebug("error read lnbp (%m)");
111 +                       else
112 +                       {
113 +                               if (mode == STATIC)
114 +                                       data[0] |= 0x80;  // set static current limiting
115 +                               else
116 +                                       data[0] &= ~0x80; // set dynamic current limiting
117 +                               if(::write(fd, data, 1) != 1)
118 +                                       eDebug("error write lnbp (%m)");
119 +                       }
120 +                       ::close(fd);
121 +               }
122 +               else
123 +                       eDebug("couldn't open /dev/i2c/0 (%m)");
124 +       }
125 +#endif
126 +}
127 +
128  void eFrontend::checkRotorLock()
129  {
130         if (!transponder)
131 @@ -130,6 +166,7 @@
132                                 {
133                                         eDebug("[FE] rotor has stopped..");
134                                         curRotorPos=newPos;
135 +                                       setCurrentLimitingMode(DYNAMIC);
136                                         /*emit*/ tunedIn(transponder, 0);
137  //                                     eDebug("!!!!!!!!!!!!!!!! TUNED IN OK 1 !!!!!!!!!!!!!!!!");
138                                         if ( !eDVB::getInstance()->getScanAPI() )
139 @@ -832,7 +869,10 @@
140                         seq.voltage=SEC_VOLTAGE_OFF;
141                         break;
142         }
143 -       return ::ioctl(secfd, SEC_SEND_SEQUENCE, &seq);
144 +       int ret = ::ioctl(secfd, SEC_SEND_SEQUENCE, &seq);
145 +       if ( ret < 0 )
146 +               eDebug("SEC_SEND_SEQUENCE failed(%m)");
147 +       return ret;
148  }
149  #else
150  int eFrontend::SendSequence( const eSecCmdSequence &seq )
151 @@ -1033,10 +1073,7 @@
152         // send DiSEqC Sequence ( normal diseqc switches )
153         seq.continuousTone = eSecCmdSequence::TONE_OFF;
154         if ( SendSequence(seq) < 0 )
155 -       {
156 -               eDebug("SendSequence failed (%m)");
157                 return -1;
158 -       }
159         else if ( lnb->getDiSEqC().SeqRepeat )   // Sequence Repeat selected ?
160         {
161                 usleep( 100000 ); // between seq repeats we wait 75ms
162 @@ -1048,6 +1085,7 @@
163                 usleep( 100000 ); // wait 100ms
164  
165         // send DiSEqC Sequence (Rotor)
166 +       setCurrentLimitingMode(STATIC);
167         seq.commands=&commands[seq.numCommands];  // last command is rotor cmd... see above...
168         seq.numCommands=1;  // only rotor cmd
169         seq.toneBurst = eSecCmdSequence::NONE;
170 @@ -1072,7 +1110,6 @@
171  #else
172         dvb_diseqc_master_cmd *commands = seq.commands;
173  #endif
174 -       idlePowerInput=0;
175         runningPowerInput=0;
176         int secTone = seq.continuousTone;
177  
178 @@ -1086,14 +1123,12 @@
179  
180         seq.continuousTone=SEC_TONE_OFF;
181         if ( SendSequence(seq) < 0 )
182 -       {
183 -               eDebug("SendSequence failed (%m)");
184                 return -2;
185 -       }
186         else if ( lnb->getDiSEqC().SeqRepeat )   // Sequence Repeat selected ?
187         {
188                 usleep( 100000 ); // between seq repeats we wait 100ms
189 -               SendSequence(seq);  // then repeat the cmd
190 +               if ( SendSequence(seq) < 0 )
191 +                       return -2;
192         }
193  
194         if ( lastLNB != lnb )
195 @@ -1103,15 +1138,48 @@
196         }
197         else
198         {
199 -               usleep( 100*1000 ); // wait 100ms
200 -//             eDebug("sleep 100ms");
201 +               usleep( 50*1000 ); // wait 50ms
202 +//             eDebug("sleep 50ms");
203 +       }
204 +
205 +       // get power input of Rotor on idle 13V .. only working with a dreambox
206 +       if ( !idlePowerInput_l )
207 +       {
208 +               idlePowerInput_l = readInputPower();
209 +               if ( idlePowerInput_l < 0 )
210 +                       return idlePowerInput_l;
211 +//             eDebug("idle power input l = %dmA", idlePowerInput_l );
212         }
213  
214 -// get power input of Rotor on idle  not work on dbox yet .. only dreambox
215 -       idlePowerInput = readInputPower();
216 -       if ( idlePowerInput < 0 )
217 -               return idlePowerInput;
218 -// eDebug("idle power input = %dmA", idlePowerInput );
219 +       setCurrentLimitingMode(STATIC);
220 +
221 +       // get power input of Rotor on idle 18V .. only working with a dreambox
222 +       if ( !idlePowerInput_h)
223 +       {
224 +#if HAVE_DVB_API_VERSION < 3
225 +               if (::ioctl(secfd, SEC_SET_VOLTAGE, increased ? SEC_VOLTAGE_18_5 : SEC_VOLTAGE_18) < 0 )
226 +                       eDebug("SEC_SET_VOLTAGE failed (%m)");
227 +#else
228 +                if ( ::ioctl(fd, FE_SET_VOLTAGE, SEC_VOLTAGE_18) < 0 )
229 +                       eDebug("FE_SET_VOLTAGE failed (%m)");
230 +#endif
231 +               usleep( 50*1000 ); // wait 50ms
232 +               idlePowerInput_h = readInputPower();
233 +               if ( idlePowerInput_h < 0 )
234 +               {
235 +                       setCurrentLimitingMode(DYNAMIC);
236 +                       return idlePowerInput_h;
237 +               }
238 +//             eDebug("idle power input h = %dmA", idlePowerInput_h );
239 +#if HAVE_DVB_API_VERSION < 3
240 +               if (::ioctl(secfd, SEC_SET_VOLTAGE, increased ? SEC_VOLTAGE_13_5 : SEC_VOLTAGE_13) < 0 )
241 +                       eDebug("SEC_SET_VOLTAGE failed (%m)");
242 +#else
243 +               if ( ::ioctl(fd, FE_SET_VOLTAGE, SEC_VOLTAGE_13) < 0 )
244 +                       eDebug("FE_SET_VOLTAGE failed (%m)");
245 +#endif
246 +               usleep( 50*1000 ); // wait 50ms
247 +       }
248  
249         // send DiSEqC Sequence (Rotor)
250         seq.commands=&commands[seq.numCommands];  // last command is rotor cmd... see above...
251 @@ -1122,7 +1190,7 @@
252         seq.continuousTone=secTone;
253         if ( SendSequence(seq) < 0 )
254         {
255 -               eDebug("SendSequence failed (%m)");
256 +               setCurrentLimitingMode(DYNAMIC);
257                 return -2;
258         }
259         // set rotor start timeout  // 2 sek..
260 @@ -1147,11 +1215,14 @@
261         {
262                 runningPowerInput = readInputPower();
263                 if ( runningPowerInput < 0 )
264 +               {
265 +                       setCurrentLimitingMode(DYNAMIC);
266                         return;
267 +               }
268  //             eDebug("running %d mA", runningPowerInput);
269  //             eDebug("delta %d mA", DeltaA);
270  
271 -               if ( abs(runningPowerInput-idlePowerInput ) >= (DeltaA&0xFF) ) // rotor running ?
272 +               if ( abs(runningPowerInput-idlePowerInput_l ) >= (DeltaA&0xFF) ) // rotor running ?
273                 {
274                         if ( (DeltaA & 0x200) == 0x200 )
275                         {
276 @@ -1182,17 +1253,43 @@
277  {
278         timeval now;
279         gettimeofday(&now,0);
280 +
281 +       if ( voltageState == eSecCmdSequence::VOLTAGE_13 )
282 +       {
283 +               timeval tmp = rotorTimeout - now;
284 +               int timeout_msek = tmp.tv_sec * 1000 + tmp.tv_usec / 1000;
285 +               if ( timeout_msek < 149700 ) // rotor running at least 300msek?
286 +               {
287 +                       // then switch to higher voltage
288 +#if HAVE_DVB_API_VERSION < 3
289 +                       if (::ioctl(secfd, SEC_SET_VOLTAGE, increased ? SEC_VOLTAGE_18_5 : SEC_VOLTAGE_18) < 0 )
290 +                               eDebug("SEC_SET_VOLTAGE failed (%m)");
291 +#else
292 +                        if ( ::ioctl(fd, FE_SET_VOLTAGE, voltage) < 0 )
293 +                               eDebug("FE_SET_VOLTAGE failed (%m)");
294 +                       curVoltage = voltage;
295 +#endif
296 +                       voltageState = eSecCmdSequence::VOLTAGE_18;
297 +               }
298 +       }
299 +
300         if ( rotorTimeout < now )
301         {
302                 eDebug("Rotor timeouted :-(");
303                 /* emit */ s_RotorTimeout();
304 +               setCurrentLimitingMode(DYNAMIC);
305         }
306         else
307         {
308 +               int &idlePowerInput = (voltageState == eSecCmdSequence::VOLTAGE_13) ? idlePowerInput_l : idlePowerInput_h;
309 +
310                 runningPowerInput = readInputPower();
311                 if ( runningPowerInput < 0 )
312 +               {
313 +                       setCurrentLimitingMode(DYNAMIC);
314                         return;
315 -//             eDebug("running %d mA", runningPowerInput);
316 +               }
317 +               // eDebug("running %d mA, idle %d mA", runningPowerInput, idlePowerInput);
318  
319                 if ( abs( idlePowerInput-runningPowerInput ) <= (DeltaA&0xFF) ) // rotor stoped ?
320                 {
321 @@ -1216,7 +1313,8 @@
322  {
323         if (type != eSystemInfo::feSatellite)
324                 return;
325 -       if ( eSystemInfo::getInstance()->canMeasureLNBCurrent() == 1 )
326 +       setCurrentLimitingMode(DYNAMIC);
327 +       if ( voltageState == eSecCmdSequence::VOLTAGE_18 )
328         {
329                 if ( voltage != eSecCmdSequence::VOLTAGE_18 )
330  #if HAVE_DVB_API_VERSION < 3
331 @@ -1228,7 +1326,7 @@
332                 curVoltage = voltage;
333  #endif
334         }
335 -       else  // can only measure with lower lnb voltage ( 13V )
336 +       else
337         {
338                 if ( voltage != eSecCmdSequence::VOLTAGE_13 )
339  #if HAVE_DVB_API_VERSION < 3
340 @@ -1466,7 +1564,10 @@
341         checkLockTimer.stop();
342  
343         if ( curRotorPos > 11000 )
344 +       {
345                 curRotorPos = 11000;
346 +               setCurrentLimitingMode(DYNAMIC);
347 +       }
348  
349  //     eDebug("ROTOR STOPPED 1");
350         /* emit */ s_RotorStopped();
351 @@ -1886,16 +1987,10 @@
352                         commands[cmdCount-1].u.diseqc.params[1]);
353  #endif
354  
355 -               // drive rotor with 18V when we can measure inputpower
356 -               // or we know which orbital pos currently is selected
357 +               // when we can measure inputpower we start rotor turning with 13V
358                 if ( lnb->getDiSEqC().useRotorInPower&1 )
359 -               {
360 -                       if ( eSystemInfo::getInstance()->canMeasureLNBCurrent() == 1 )  // can measure with voltage > 13V ?
361 -                               seq.voltage = eSecCmdSequence::VOLTAGE_18;
362 -                       else
363 -                               seq.voltage = eSecCmdSequence::VOLTAGE_13;
364 -               }
365 -               else
366 +                       voltageState = seq.voltage = eSecCmdSequence::VOLTAGE_13;
367 +               else  // without measure input power we must start with the correct voltage
368                         seq.voltage = voltage;
369  
370                 lastRotorCmd=RotorCmd;
371 @@ -1926,14 +2021,12 @@
372  send:
373                 seq.voltage=voltage;
374                 if ( SendSequence(seq) < 0 )
375 -               {
376 -                       eDebug("SendSequence failed (%m)");
377                         return -1;
378 -               }
379                 else if ( lnb->getDiSEqC().DiSEqCMode >= eDiSEqC::V1_1 && lnb->getDiSEqC().SeqRepeat )  // Sequence Repeat ?
380                 {
381                         usleep( 100000 ); // between seq repeats we wait 80ms
382 -                       SendSequence(seq);  // just do it *g*
383 +                       if ( SendSequence(seq) < 0 )
384 +                               return -1;
385                 }
386         }
387         else if ( lastcsw != csw )
388 @@ -2083,10 +2176,7 @@
389                 seq.continuousTone = eSecCmdSequence::TONE_OFF;
390                 seq.toneBurst = eSecCmdSequence::NONE;
391                 if (SendSequence(seq) < 0 )
392 -               {
393 -                       eDebug("SendSequence failed (%m)");
394                         return -1;
395 -               }
396         }
397         if ( ioctl(fd, FE_SET_POWER_STATE, FE_POWER_OFF) < 0 )
398                 eDebug("FE_SET_POWER_STATE failed (%m)");
399 diff -Naur enigma_org/lib/system/info.cpp enigma/lib/system/info.cpp
400 --- enigma_org/lib/system/info.cpp      2007-08-06 22:54:26.000000000 +0200
401 +++ enigma/lib/system/info.cpp  2007-08-06 22:47:44.000000000 +0200
402 @@ -177,19 +177,8 @@
403                                         midstr="9";
404                                         modelstr="DM7020";
405                                         cpustr="STB04500, 252MHz";
406 -                                       hasrfmod = hashdd = haslcd = hasci
407 -                                       = canrecordts = hasstandbywakeuptimer = cantimeshift = 1;
408 -                                       // check if the box revision is new enough to measure
409 -                                       // lnb power with > 13V ( revisions with lnbp21 can this )
410 -                                       int fd = open("/dev/dbox/fp0", O_RDWR);
411 -                                       if ( fd >=0 )
412 -                                       {
413 -                                               if ( ::ioctl( fd, 0x100, 0 ) == 0 )
414 -                                                       canmeasurelnbcurrent=1;
415 -                                               else
416 -                                                       canmeasurelnbcurrent=2;
417 -                                               close(fd);
418 -                                       }
419 +                                       hasrfmod = hashdd = haslcd = hasci = canrecordts =
420 +                                       hasstandbywakeuptimer = cantimeshift = canmeasurelnbcurrent = 1;
421                                         hwtype = DM7020;
422                                         defaulttimertype=ePlaylistEntry::RecTimerEntry|ePlaylistEntry::recDVR;
423                                         break;