LMS 2012
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
d_iic.c
Go to the documentation of this file.
1 /*
2  * LEGO® MINDSTORMS EV3
3  *
4  * Copyright (C) 2010-2013 The LEGO Group
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19  */
20 
21 
58 #ifndef PCASM
59 #include <asm/types.h>
60 #endif
61 
62 #define HW_ID_SUPPORT
63 
64 #include "../../lms2012/source/lms2012.h"
65 #include "../../lms2012/source/am1808.h"
66 
67 #ifndef DISABLE_FIQ_IIC
68 #include "d_iic.h"
69 #endif
70 
71 #ifdef DEBUG
72 #define DEBUG_D_IIC
73 #endif
74 #ifdef DEBUG_D_IIC
75 #define DEBUG_IIC_WRITE
76 #define HIGHDEBUG
77 #define DEBUG_TRACE_MODE_CHANGE
78 #endif
79 
80 
81 
82 #define MODULE_NAME "iic_module"
83 #define DEVICE1_NAME IIC_DEVICE
84 
85 static int ModuleInit(void);
86 static void ModuleExit(void);
87 
88 #define __USE_POSIX
89 
90 #include <linux/kernel.h>
91 #include <linux/fs.h>
92 
93 #include <linux/sched.h>
94 
95 
96 #ifndef PCASM
97 #include <linux/circ_buf.h>
98 #include <linux/hrtimer.h>
99 
100 #include <linux/mm.h>
101 #include <linux/hrtimer.h>
102 
103 #include <linux/init.h>
104 #include <linux/uaccess.h>
105 #include <linux/debugfs.h>
106 
107 #include <linux/ioport.h>
108 #include <asm/gpio.h>
109 #include <asm/io.h>
110 #include <linux/module.h>
111 #include <linux/miscdevice.h>
112 #include <asm/uaccess.h>
113 
114 MODULE_LICENSE("GPL");
115 MODULE_AUTHOR("The LEGO Group");
118 
119 module_init(ModuleInit);
120 module_exit(ModuleExit);
121 
122 #else
123 // Keep Eclipse happy
124 #endif
125 
126 
127 #define NO_OF_IIC_PORTS INPUTS
128 
129 
130 #ifndef DISABLE_FIQ_IIC
131 
133 
134 #else
135 
136 enum IicPortPins
137 {
142 };
143 
144 INPIN IicPortPin[NO_OF_IIC_PORTS][IIC_PORT_PINS];
145 
146 #endif
147 
148 
149 int Hw = 0;
150 
159 INPIN EP2_IicPortPin[][IIC_PORT_PINS] =
160 {
161  { // Input port 1
162  { GP8_11 , NULL, 0 }, // Buffer disable
163  { GP1_0 , NULL, 0 }, // Pin 5 - Digital input // CLOCK
164  { GP0_15 , NULL, 0 }, // Pin 6 - Digital output // DATA
165  },
166  { // Input port 2
167  { GP8_14 , NULL, 0 }, // Buffer disable
168  { GP8_3 , NULL, 0 }, // Pin 5 - Digital input // CLOCK
169  { GP0_13 , NULL, 0 }, // Pin 6 - Digital output // DATA
170  },
171  { // Input port 3
172  { GP7_9 , NULL, 0 }, // Buffer disable
173  { GP1_12 , NULL, 0 }, // Pin 5 - Digital input // CLOCK
174  { GP1_14 , NULL, 0 }, // Pin 6 - Digital output // DATA
175  },
176  { // Input port 4
177  { GP7_10 , NULL, 0 }, // Buffer disable
178  { GP1_11 , NULL, 0 }, // Pin 5 - Digital input // CLOCK
179  { GP1_15 , NULL, 0 }, // Pin 6 - Digital output // DATA
180  },
181 };
182 
183 
184 INPIN FINALB_IicPortPin[][IIC_PORT_PINS] =
185 {
186  { // Input port 1
187  { GP8_11 , NULL, 0 }, // Buffer disable
188  { GP1_0 , NULL, 0 }, // Pin 5 - Digital input // CLOCK
189  { GP0_15 , NULL, 0 }, // Pin 6 - Digital output // DATA
190  },
191  { // Input port 2
192  { GP8_14 , NULL, 0 }, // Buffer disable
193  { GP8_3 , NULL, 0 }, // Pin 5 - Digital input // CLOCK
194  { GP0_13 , NULL, 0 }, // Pin 6 - Digital output // DATA
195  },
196  { // Input port 3
197  { GP7_9 , NULL, 0 }, // Buffer disable
198  { GP1_12 , NULL, 0 }, // Pin 5 - Digital input // CLOCK
199  { GP1_14 , NULL, 0 }, // Pin 6 - Digital output // DATA
200  },
201  { // Input port 4
202  { GP7_10 , NULL, 0 }, // Buffer disable
203  { GP1_11 , NULL, 0 }, // Pin 5 - Digital input // CLOCK
204  { GP1_15 , NULL, 0 }, // Pin 6 - Digital output // DATA
205  },
206 };
207 
208 
209 INPIN FINAL_IicPortPin[][IIC_PORT_PINS] =
210 {
211  { // Input port 1
212  { GP8_11 , NULL, 0 }, // Buffer disable
213  { GP0_2 , NULL, 0 }, // Pin 5 - Digital input // CLOCK
214  { GP0_15 , NULL, 0 }, // Pin 6 - Digital output // DATA
215  },
216  { // Input port 2
217  { GP8_14 , NULL, 0 }, // Buffer disable
218  { GP0_14 , NULL, 0 }, // Pin 5 - Digital input // CLOCK
219  { GP0_13 , NULL, 0 }, // Pin 6 - Digital output // DATA
220  },
221  { // Input port 3
222  { GP7_9 , NULL, 0 }, // Buffer disable
223  { GP0_12 , NULL, 0 }, // Pin 5 - Digital input // CLOCK
224  { GP1_14 , NULL, 0 }, // Pin 6 - Digital output // DATA
225  },
226  { // Input port 4
227  { GP7_10 , NULL, 0 }, // Buffer disable
228  { GP1_13 , NULL, 0 }, // Pin 5 - Digital input // CLOCK
229  { GP1_15 , NULL, 0 }, // Pin 6 - Digital output // DATA
230  },
231 };
232 
233 
234 
235 /* \endverbatim
236  * \n
237  */
238 
239 
240 #define PUDisable iowrite32(ioread32(da8xx_syscfg1_base + 0x0C) & ~0xFFFFFFFF,da8xx_syscfg1_base + 0x0C)
241 
243 {
244  [FINAL] = (INPIN*)&FINAL_IicPortPin[0], // FINAL platform
245  [FINALB] = (INPIN*)&FINALB_IicPortPin[0], // FINALB platform
246  [EP2] = (INPIN*)&EP2_IicPortPin[0], // EP2 platform
247 };
248 
249 
250 //*****************************************************************************
251 
252 static void __iomem *GpioBase;
253 
254 void SetGpio(int Pin)
255 {
256  int Tmp = 0;
257  void __iomem *Reg;
258 
259  if (Pin >= 0)
260  {
261  // unlock
262  REGUnlock;
263 
264  while ((MuxRegMap[Tmp].Pin != -1) && (MuxRegMap[Tmp].Pin != Pin))
265  {
266  Tmp++;
267  }
268  if (MuxRegMap[Tmp].Pin == Pin)
269  {
270  Reg = da8xx_syscfg0_base + 0x120 + (MuxRegMap[Tmp].MuxReg << 2);
271 
272  *(u32*)Reg &= MuxRegMap[Tmp].Mask;
273  *(u32*)Reg |= MuxRegMap[Tmp].Mode;
274  #ifdef DEBUG
275  printk(" GP%d_%-2d 0x%08X and 0x%08X or 0x%08X\n",(Pin >> 4),(Pin & 0x0F),(u32)Reg, MuxRegMap[Tmp].Mask, MuxRegMap[Tmp].Mode);
276  #endif
277  }
278  else
279  {
280  printk("* GP%d_%-2d ********* ERROR not found *********\n",(Pin >> 4),(Pin & 0x0F));
281  }
282  // lock
283  REGLock;
284  }
285 }
286 
287 
288 void InitGpio(void)
289 {
290  int Port;
291  int Pin;
292 
293 
294  memcpy(IicPortPin,pIicPortPin[Hw],sizeof(EP2_IicPortPin));
295 
296 #ifdef DEBUG
297  printk("\n\n");
298  printk("FINALB_IicPortPin = %p\n",FINALB_IicPortPin);
299  printk("pIicPortPin[Hw] = %p\n",pIicPortPin[Hw]);
300  printk("sizeof(INPIN) = %d\n",sizeof(INPIN));
301  printk("sizeof(EP2_IicPortPin) = %d\n",sizeof(EP2_IicPortPin));
302 
303 #endif
304 
305  if (memcmp((const void*)IicPortPin,(const void*)pIicPortPin[Hw],sizeof(EP2_IicPortPin)) != 0)
306  {
307  printk("%s IicPortPin tabel broken!\n",MODULE_NAME);
308  }
309 
310  for (Port = 0;Port < NO_OF_IIC_PORTS;Port++)
311  {
312 #ifdef DEBUG
313  printk(" Iic port %d\n",Port + 1);
314 #endif
315  for (Pin = 0;Pin < IIC_PORT_PINS;Pin++)
316  {
317  if ((Port != DEBUG_UART) || (Pin != IIC_PORT_CLOCK))
318  {
319  if (IicPortPin[Port][Pin].Pin >= 0)
320  {
321  IicPortPin[Port][Pin].pGpio = (struct gpio_controller *__iomem)(GpioBase + ((IicPortPin[Port][Pin].Pin >> 5) * 0x28) + 0x10);
322  IicPortPin[Port][Pin].Mask = (1 << (IicPortPin[Port][Pin].Pin & 0x1F));
323 
324  SetGpio(IicPortPin[Port][Pin].Pin);
325  }
326  }
327  }
328  }
329 
330  // unlock
331  REGUnlock;
332 
333  // Disable pull up/down
334  PUDisable;
335 
336  // lock
337  REGLock;
338 }
339 
340 
341 #ifdef DISABLE_FIQ_IIC
342 #define PINFloat(port,pin) {\
343  (*IicPortPin[port][pin].pGpio).dir |= IicPortPin[port][pin].Mask;\
344  }
345 
346 
347 #define PINRead(port,pin) ((*IicPortPin[port][pin].pGpio).in_data & IicPortPin[port][pin].Mask)
348 
349 
350 #define PINHigh(port,pin) {\
351  (*IicPortPin[port][pin].pGpio).set_data = IicPortPin[port][pin].Mask;\
352  (*IicPortPin[port][pin].pGpio).dir &= ~IicPortPin[port][pin].Mask;\
353  }
354 
355 #define PINLow(port,pin) {\
356  (*IicPortPin[port][pin].pGpio).clr_data = IicPortPin[port][pin].Mask;\
357  (*IicPortPin[port][pin].pGpio).dir &= ~IicPortPin[port][pin].Mask;\
358  }
359 #endif
360 
361 
362 typedef struct
363 {
382  UBYTE InBuffer[IIC_DATA_LENGTH];
383  UBYTE OutBuffer[IIC_DATA_LENGTH];
384 }
385 IICPORT;
386 
387 
389 {
390  0, // Timer
391  0, // Time
392  0, // Initialised
393  0, // ChangeMode
394  0, // State
395  -1, // OldState
396  0, // SubState
397  0, // Repeat
398  0, // Cmd
399  0, // Mode
400  1, // Addr
401  3, // Retries
402  "", // Name
403  0, // Reverse
404  0, // InLength
405  0, // InPointer
406  0, // OutLength
407  0, // OutPointer
408 };
409 
410 
411 #ifdef DEBUG_IIC_WRITE
412 
413 #define IICBUFFERSIZE 250
414 static char IicBuffer[IICBUFFERSIZE];
415 
416 #define LOGPOOLSIZE 100000
417 ULONG LogPointer = 0;
418 ULONG LogOutPointer = 0;
419 char LogPool[LOGPOOLSIZE];
420 
421 void IicWrite(char *pString)
422 {
423  ULONG Tmp;
424 
425  while (*pString)
426  {
427  LogPool[LogPointer] = *pString;
428 
429  Tmp = LogPointer;
430  Tmp++;
431  if (Tmp >= LOGPOOLSIZE)
432  {
433  Tmp = 0;
434  }
435  if (Tmp != LogOutPointer)
436  {
437  LogPointer = Tmp;
438  pString++;
439 
440  }
441  else
442  {
443  pString++;
444  }
445  }
446 }
447 #endif
448 
449 
452 
453 static IIC IicDefault;
454 static IIC *pIic = &IicDefault;
455 
456 // FIQ Interface **************************************************************
457 
458 #ifndef DISABLE_FIQ_IIC
459 
460 #ifndef PCASM
461 #include <linux/circ_buf.h>
462 #include <linux/delay.h>
463 #endif
464 
465 extern struct IIC_control_t IicCtrl;
466 extern void iic_fiq_start_transfer(unsigned int time, bool fiq_nirq);
467 
468 #endif
469 
470 
471 static void IicPortDisable(UBYTE Port)
472 {
473 #ifndef DISABLE_FIQ_IIC
474 
475  IicCtrl.port_enabled &= ~(1 << Port);
476 
477  if (Port != DEBUG_UART)
478  {
480  }
481  PINInput(Port,IIC_PORT_DATA);
482 
483 #endif
484 }
485 
486 
487 static void IicPortEnable(UBYTE Port)
488 {
489 #ifndef DISABLE_FIQ_IIC
490 
491  SetGpio(IicPortPin[Port][IIC_PORT_CLOCK].Pin);
492 
494  PINHigh(Port,IIC_PORT_CLOCK);
495  PINHigh(Port,IIC_PORT_DATA);
498  PINOutput(Port,IIC_PORT_DATA);
499 
500  IicCtrl.data_package[Port].clock_state = 1;
501 
502  IicCtrl.port_enabled |= (1 << Port);
503 
504 #endif
505 }
506 
507 
508 static UBYTE IicPortBusy(UBYTE Port)
509 {
510  UBYTE Result = 0;
511 
512 #ifndef DISABLE_FIQ_IIC
513 
515  {
516  Result = 1;
517  }
518 
519 #endif
520 
521  return (Result);
522 }
523 
524 
525 static RESULT IicPortSend(UBYTE Port)
526 {
527  RESULT Result = OK;
528 
529 #ifndef DISABLE_FIQ_IIC
530  DATA8 Tmp;
531 
532  IicCtrl.data_package[Port].addr = IicPort[Port].OutBuffer[0];
533 
534 #ifdef HIGHDEBUG
535  snprintf(IicBuffer,IICBUFFERSIZE," %d Send %02X ",Port,IicPort[Port].OutBuffer[0]);
536  IicWrite(IicBuffer);
537 #endif
538  for (Tmp = 1;Tmp < IicPort[Port].OutLength;Tmp++)
539  {
540 #ifdef HIGHDEBUG
541  snprintf(IicBuffer,IICBUFFERSIZE,"%02X ",IicPort[Port].OutBuffer[Tmp]);
542  IicWrite(IicBuffer);
543 #endif
544  IicCtrl.data_package[Port].data[Tmp - 1] = IicPort[Port].OutBuffer[Tmp];
545  }
546 #ifdef HIGHDEBUG
547  snprintf(IicBuffer,IICBUFFERSIZE,"\r\n");
548  IicWrite(IicBuffer);
549 #endif
550  IicCtrl.data_package[Port].write_length = IicPort[Port].OutLength - 1;
551  IicCtrl.data_package[Port].read_length = IicPort[Port].InLength;
552  IicCtrl.data_package[Port].port = Port;
553 
554  IicCtrl.data_package[Port].nacked = 0;
555  IicCtrl.data_package[Port].clock_state = 1;
557 
559 
560 #endif
561 
562  return (Result);
563 }
564 
565 
566 static RESULT IicPortReceive(UBYTE Port,UBYTE *pTmpBuffer)
567 {
568  RESULT Result = BUSY;
569 
570 #ifndef DISABLE_FIQ_IIC
571  DATA8 Tmp;
572 
574  {
575  memset((void*)pTmpBuffer,0,IIC_DATA_LENGTH);
576 #ifdef HIGHDEBUG
577  snprintf(IicBuffer,IICBUFFERSIZE," %d Receiving ",Port);
578  IicWrite(IicBuffer);
579 #endif
580  for (Tmp = 0;Tmp < IicPort[Port].InLength;Tmp++)
581  {
582 #ifdef HIGHDEBUG
583  snprintf(IicBuffer,IICBUFFERSIZE,"%02X ",IicCtrl.data_package[Port].data[Tmp]);
584  IicWrite(IicBuffer);
585 #endif
586  pTmpBuffer[Tmp] = IicCtrl.data_package[Port].data[Tmp];
587  }
588 #ifdef HIGHDEBUG
589  snprintf(IicBuffer,IICBUFFERSIZE,"\r\n");
590  IicWrite(IicBuffer);
591 #endif
592 
593  if (!(IicCtrl.data_package[Port].nacked))
594  {
595  Result = OK;
596  }
597  else
598  {
599  Result = FAIL;
600  }
601  }
602 
603 #endif
604 
605  return (Result);
606 }
607 
608 
609 // DEVICE1 ********************************************************************
610 
611 
613 {
638 };
639 
640 
642 {
643  "IDLE\n",
644  "INIT",
645  "RESTART",
646  "ENABLE",
647  "IIC_NXT_TEMP_START",
648  "IIC_NXT_TEMP_WRITE",
649  "IIC_NXT_TEMP_READ",
650  "MANUFACTURER_START",
651  "MANUFACTURER_WRITE",
652  "MANUFACTURER_READ",
653  "TYPE_START",
654  "TYPE_WRITE",
655  "TYPE_READ",
656  "SETUP_WAIT",
657  "SETUP_START",
658  "SETUP_WRITE",
659  "SETUP_READ",
660  "WAITING",
661  "WRITING",
662  "READING",
663  "REPEAT",
664  "ERROR",
665  "EXIT"
666 };
667 
668 
671 
672 
673 #define IIC_TIMER_RESOLUTION 20 // [100u]
674 static struct hrtimer Device1Timer;
675 static ktime_t Device1Time;
676 
677 
678 static enum hrtimer_restart Device1TimerInterrupt1(struct hrtimer *pTimer)
679 {
680  UBYTE Port;
681  UBYTE Tmp;
682  UBYTE TmpBuffer[IIC_DATA_LENGTH];
683 
684  hrtimer_forward_now(pTimer,Device1Time);
685 
686  for (Port = 0;Port < NO_OF_IIC_PORTS;Port++)
687  { // look at one port at a time
688 
689  switch (IicPort[Port].State)
690  { // Main state machine
691 
692  case IIC_IDLE :
693  { // Port inactive
694 
695  (*pIic).Status[Port] = 0;
696  }
697  break;
698 
699  case IIC_INIT :
700  { // Initialise port hardware
701 
702  memset((void*)IicStrings[Port].Manufacturer,0,IIC_NAME_LENGTH + 1);
703  memset((void*)IicStrings[Port].SensorType,0,IIC_NAME_LENGTH + 1);
704  IicPort[Port].State = IIC_ENABLE;
705  }
706  break;
707 
708  case IIC_RESTART :
709  {
710  IicPortDisable(Port);
711  IicPort[Port].State = IIC_ENABLE;
712  }
713  break;
714 
715  case IIC_ENABLE :
716  { // Initialise port variables
717 
718  IicPortEnable(Port);
719 
720  IicPort[Port] = IicPortDefault;
721 
722  IicPort[Port].Timer = 0;
723 
724  IicPort[Port].State = IIC_NXT_TEMP_START;
725  }
726  break;
727 
728 
729 
730 
731 
732  case IIC_NXT_TEMP_START :
733  {
734  if (++(IicPort[Port].Timer) >= (10 / IIC_TIMER_RESOLUTION))
735  {
736  IicPort[Port].OutBuffer[0] = 0x4C;
737  IicPort[Port].OutBuffer[1] = 0x01;
738  IicPort[Port].OutBuffer[2] = 0x60;
739  IicPort[Port].OutBuffer[3] = 0x00;
740  IicPort[Port].OutLength = 3;
741  IicPort[Port].InLength = 1;
742  IicPort[Port].Repeat = 1;
743  IicPort[Port].Time = 0;
744  IicPort[Port].Timer = 0;
745  IicPort[Port].State = IIC_NXT_TEMP_WRITE;
746  }
747  }
748  break;
749 
750  case IIC_NXT_TEMP_WRITE :
751  {
752  IicPortSend(Port);
753  IicPort[Port].Timer = 0;
754  IicPort[Port].State = IIC_NXT_TEMP_READ;
755  }
756  break;
757 
758  case IIC_NXT_TEMP_READ :
759  {
760  if (IicPortReceive(Port,TmpBuffer) != BUSY)
761  {
762  if (TmpBuffer[0] == 0x60)
763  {
764  memcpy((void*)IicStrings[Port].Manufacturer,(void*)"LEGO",IIC_NAME_LENGTH);
765  IicStrings[Port].Manufacturer[IIC_NAME_LENGTH] = 0;
766  memcpy((void*)IicStrings[Port].SensorType,(void*)"Temp.",IIC_NAME_LENGTH);
767  IicStrings[Port].SensorType[IIC_NAME_LENGTH] = 0;
768 
769  (*pIic).Changed[Port] = 1;
770 
771  IicPort[Port].Initialised = 1;
772  IicPort[Port].Timer = 0;
773  IicPort[Port].State = IIC_SETUP_WAIT;
774  }
775  else
776  {
777  IicPort[Port].Timer = 0;
778  IicPort[Port].State = IIC_MANUFACTURER_START;
779  }
780  }
781  if (++(IicPort[Port].Timer) >= (500 / IIC_TIMER_RESOLUTION))
782  {
783  IicPort[Port].Timer = 0;
784  IicPort[Port].State = IIC_MANUFACTURER_START;
785  }
786  }
787  break;
788 
790  {
791  if (++(IicPort[Port].Timer) >= (10 / IIC_TIMER_RESOLUTION))
792  {
793  IicPort[Port].OutBuffer[0] = IicPort[Port].Addr;
794  IicPort[Port].OutBuffer[1] = 0x08;
795  IicPort[Port].OutBuffer[2] = 0x00;
796  IicPort[Port].OutBuffer[3] = 0x00;
797  IicPort[Port].OutLength = 2;
798  IicPort[Port].InLength = 8;
799  IicPort[Port].Repeat = 1;
800  IicPort[Port].Time = 0;
801  IicPort[Port].Timer = 0;
802  IicPort[Port].State = IIC_MANUFACTURER_WRITE;
803  }
804  }
805  break;
806 
808  {
809  IicPortSend(Port);
810  IicPort[Port].Timer = 0;
811  IicPort[Port].State = IIC_MANUFACTURER_READ;
812  }
813  break;
814 
815  case IIC_MANUFACTURER_READ :
816  {
817  if (IicPortReceive(Port,TmpBuffer) != BUSY)
818  {
819  memcpy((void*)IicStrings[Port].Manufacturer,(void*)TmpBuffer,IIC_NAME_LENGTH);
820  IicStrings[Port].Manufacturer[IIC_NAME_LENGTH] = 0;
821 
822  if (TmpBuffer[0] == 0x08)
823  {
824  if (IicPort[Port].Addr < 0x50)
825  {
826  IicPort[Port].Addr++;
827  IicPort[Port].Timer = 0;
828  IicPort[Port].State = IIC_MANUFACTURER_START;
829  }
830  else
831  {
832  if (--IicPort[Port].Retries > 0)
833  {
834  IicPort[Port].Addr = 0x01;
835  IicPort[Port].Timer = 0;
836  IicPort[Port].State = IIC_MANUFACTURER_START;
837  }
838  else
839  {
840  IicPort[Port].Initialised = 1;
841  IicPort[Port].State = IIC_SETUP_START;
842  }
843  }
844  }
845  else
846  {
847  if (TmpBuffer[0] == 0)
848  {
849  memcpy((void*)IicStrings[Port].Manufacturer,(void*)"LEGO",IIC_NAME_LENGTH);
850  IicStrings[Port].Manufacturer[IIC_NAME_LENGTH] = 0;
851  }
852  IicPort[Port].Initialised = 1;
853  IicPort[Port].State = IIC_TYPE_START;
854  }
855 
856  }
857  if (++(IicPort[Port].Timer) >= (500 / IIC_TIMER_RESOLUTION))
858  {
859  printk("IIC timeout\n");
860  IicPort[Port].Addr = 0x01;
861  (*pIic).Status[Port] &= ~IIC_WRITE_REQUEST;
862  (*pIic).Status[Port] &= ~IIC_DATA_READY;
863  IicPort[Port].State = IIC_WAITING;
864  }
865  }
866  break;
867 
868  case IIC_TYPE_START :
869  {
870  IicPort[Port].OutBuffer[0] = IicPort[Port].Addr;
871  IicPort[Port].OutBuffer[1] = 0x10;
872  IicPort[Port].OutBuffer[2] = 0x00;
873  IicPort[Port].OutBuffer[3] = 0x00;
874  IicPort[Port].OutLength = 2;
875  IicPort[Port].InLength = 8;
876  IicPort[Port].Repeat = 1;
877  IicPort[Port].Time = 0;
878  IicPort[Port].Timer = 0;
879  IicPort[Port].State = IIC_TYPE_WRITE;
880  }
881  break;
882 
883  case IIC_TYPE_WRITE :
884  {
885  IicPortSend(Port);
886  IicPort[Port].Timer = 0;
887  IicPort[Port].State = IIC_TYPE_READ;
888  }
889  break;
890 
891  case IIC_TYPE_READ :
892  {
893  if (IicPortReceive(Port,TmpBuffer) != BUSY)
894  {
895  memcpy((void*)IicStrings[Port].SensorType,(void*)TmpBuffer,IIC_NAME_LENGTH);
896  IicStrings[Port].SensorType[IIC_NAME_LENGTH] = 0;
897 
898  if (TmpBuffer[0] == 0)
899  {
900  memcpy((void*)IicStrings[Port].SensorType,(void*)"Store",IIC_NAME_LENGTH);
901  IicStrings[Port].Manufacturer[IIC_NAME_LENGTH] = 0;
902  }
903 
904  (*pIic).Changed[Port] = 1;
905 
906  IicPort[Port].Initialised = 1;
907  IicPort[Port].Timer = 0;
908  IicPort[Port].State = IIC_SETUP_WAIT;
909  }
910  if (++(IicPort[Port].Timer) >= (500 / IIC_TIMER_RESOLUTION))
911  {
912  (*pIic).Status[Port] &= ~IIC_WRITE_REQUEST;
913  (*pIic).Status[Port] &= ~IIC_DATA_READY;
914  IicPort[Port].State = IIC_WAITING;
915  }
916  }
917  break;
918 
919  case IIC_SETUP_WAIT :
920  {
921  if (++(IicPort[Port].Timer) >= (10000 / IIC_TIMER_RESOLUTION))
922  {
923  IicPort[Port] = IicPortDefault;
924  IicPort[Port].Timer = 0;
925  IicPort[Port].State = IIC_NXT_TEMP_START;
926  }
927  }
928  break;
929 
930  case IIC_SETUP_START :
931  {
932 #ifndef DISABLE_FAST_DATALOG_BUFFER
933  (*pIic).Actual[Port] = 0;
934  (*pIic).LogIn[Port] = 0;
935 #endif
936 
937  if (IicStrings[Port].SetupLng)
938  {
939  IicPort[Port].OutBuffer[0] = (UBYTE)((IicStrings[Port].SetupString >> 24) & 0xFF);
940  IicPort[Port].OutBuffer[1] = (UBYTE)((IicStrings[Port].SetupString >> 16) & 0xFF);
941  IicPort[Port].OutBuffer[2] = (UBYTE)((IicStrings[Port].SetupString >> 8) & 0xFF);
942  IicPort[Port].OutBuffer[3] = (UBYTE)((IicStrings[Port].SetupString) & 0xFF);
943  IicPort[Port].OutLength = IicStrings[Port].SetupLng;
944  IicPort[Port].InLength = 0;
945  IicPort[Port].Repeat = 1;
946  IicPort[Port].Time = 0;
947  IicPort[Port].State = IIC_SETUP_WRITE;
948  }
949  else
950  {
951  IicPort[Port].State = IIC_SETUP_READ;
952  }
953  IicPort[Port].Timer = 0;
954  }
955  break;
956 
957  case IIC_SETUP_WRITE :
958  {
959  IicPortSend(Port);
960  IicPort[Port].Timer = 0;
961  IicPort[Port].State = IIC_SETUP_READ;
962  }
963  break;
964 
965  case IIC_SETUP_READ :
966  {
967  if (IicPortReceive(Port,TmpBuffer) != BUSY)
968  {
969  IicPort[Port].State = IIC_WAITING;
970  if (IicStrings[Port].PollLng)
971  {
972  IicPort[Port].OutBuffer[0] = (UBYTE)((IicStrings[Port].PollString >> 24) & 0xFF);
973  IicPort[Port].OutBuffer[1] = (UBYTE)((IicStrings[Port].PollString >> 16) & 0xFF);
974  IicPort[Port].OutBuffer[2] = (UBYTE)((IicStrings[Port].PollString >> 8) & 0xFF);
975  IicPort[Port].OutBuffer[3] = (UBYTE)((IicStrings[Port].PollString) & 0xFF);
976  IicPort[Port].OutLength = IicStrings[Port].PollLng;
977  if (IicStrings[Port].ReadLng < 0)
978  {
979  IicPort[Port].InLength = 0 - IicStrings[Port].ReadLng;
980  IicPort[Port].Reverse = 1;
981  }
982  else
983  {
984  IicPort[Port].InLength = IicStrings[Port].ReadLng;
985  IicPort[Port].Reverse = 0;
986  }
987  IicPort[Port].Repeat = 0;
988  IicPort[Port].Time = IicStrings[Port].Time;
989  IicPort[Port].Timer = 0;
990  IicPort[Port].State = IIC_WRITING;
991  (*pIic).Status[Port] = 0;
992  }
993  IicPort[Port].Initialised = 1;
994  }
995  if (++(IicPort[Port].Timer) >= (500 / IIC_TIMER_RESOLUTION))
996  {
997  (*pIic).Status[Port] &= ~IIC_WRITE_REQUEST;
998  (*pIic).Status[Port] &= ~IIC_DATA_READY;
999  IicPort[Port].State = IIC_WAITING;
1000  }
1001  }
1002  break;
1003 
1004  case IIC_WAITING :
1005  {
1006  if ((*pIic).Status[Port] & IIC_WRITE_REQUEST)
1007  {
1008  if (IicPortBusy(Port) == 0)
1009  {
1010  IicPort[Port].Timer = 0;
1011  IicPort[Port].State = IIC_WRITING;
1012  }
1013  }
1014  }
1015  break;
1016 
1017  case IIC_WRITING :
1018  {
1019  IicPortSend(Port);
1020  IicPort[Port].State = IIC_READING;
1021  }
1022  break;
1023 
1024  case IIC_READING :
1025  {
1026  if (IicPortReceive(Port,TmpBuffer) != BUSY)
1027  {
1028 
1029 #ifndef DISABLE_FAST_DATALOG_BUFFER
1030  if (IicPort[Port].InLength > 1)
1031  {
1032  if (IicPort[Port].Reverse)
1033  {
1034  for (Tmp = 0;Tmp < IicPort[Port].InLength;Tmp++)
1035  {
1036  IicPort[Port].InBuffer[Tmp] = TmpBuffer[Tmp];
1037  (*pIic).Raw[Port][(*pIic).LogIn[Port]][Tmp] = TmpBuffer[Tmp];
1038  }
1039  }
1040  else
1041  {
1042  for (Tmp = 0;Tmp < IicPort[Port].InLength;Tmp++)
1043  {
1044  IicPort[Port].InBuffer[Tmp] = TmpBuffer[(IicPort[Port].InLength - 1) - Tmp];
1045  (*pIic).Raw[Port][(*pIic).LogIn[Port]][Tmp] = TmpBuffer[(IicPort[Port].InLength - 1) - Tmp];
1046  }
1047  }
1048  }
1049  else
1050  {
1051  IicPort[Port].InBuffer[0] = TmpBuffer[0];
1052  IicPort[Port].InBuffer[1] = 0;
1053  (*pIic).Raw[Port][(*pIic).LogIn[Port]][0] = TmpBuffer[0];
1054  (*pIic).Raw[Port][(*pIic).LogIn[Port]][1] = 0;
1055  }
1056 
1057  (*pIic).Actual[Port] = (*pIic).LogIn[Port];
1058  (*pIic).Repeat[Port][(*pIic).Actual[Port]] = 0;
1059 
1060  if (++((*pIic).LogIn[Port]) >= DEVICE_LOGBUF_SIZE)
1061  {
1062  (*pIic).LogIn[Port] = 0;
1063  }
1064 #else
1065  if (IicPort[Port].InLength > 1)
1066  {
1067  if (IicPort[Port].Reverse)
1068  {
1069  for (Tmp = 0;Tmp < IicPort[Port].InLength;Tmp++)
1070  {
1071  IicPort[Port].InBuffer[Tmp] = TmpBuffer[Tmp];
1072  (*pIic).Raw[Port][Tmp] = TmpBuffer[Tmp];
1073  }
1074  }
1075  else
1076  {
1077  for (Tmp = 0;Tmp < IicPort[Port].InLength;Tmp++)
1078  {
1079  IicPort[Port].InBuffer[Tmp] = TmpBuffer[(IicPort[Port].InLength - 1) - Tmp];
1080  (*pIic).Raw[Port][Tmp] = TmpBuffer[(IicPort[Port].InLength - 1) - Tmp];
1081  }
1082  }
1083  }
1084  else
1085  {
1086  IicPort[Port].InBuffer[0] = TmpBuffer[0];
1087  IicPort[Port].InBuffer[1] = 0;
1088  (*pIic).Raw[Port][0] = TmpBuffer[0];
1089  (*pIic).Raw[Port][1] = 0;
1090  }
1091 #endif
1092 
1093  (*pIic).Status[Port] |= IIC_DATA_READY;
1094  IicPort[Port].State = IIC_REPEAT;
1095 
1096  if (IicPort[Port].Repeat != 0)
1097  {
1098  IicPort[Port].Repeat--;
1099  if (IicPort[Port].Repeat == 0)
1100  {
1101  IicPort[Port].State = IIC_WAITING;
1102  }
1103  }
1104  }
1105  if (++(IicPort[Port].Timer) >= (5000 / IIC_TIMER_RESOLUTION))
1106  {
1107  (*pIic).Status[Port] &= ~IIC_WRITE_REQUEST;
1108  (*pIic).Status[Port] &= ~IIC_DATA_READY;
1109  IicPort[Port].State = IIC_WAITING;
1110  }
1111  }
1112  break;
1113 
1114  case IIC_REPEAT :
1115  {
1116  if ((*pIic).Status[Port] & IIC_WRITE_REQUEST)
1117  {
1118  (*pIic).Status[Port] = IIC_WRITE_REQUEST;
1119  IicPort[Port].State = IIC_WAITING;
1120  }
1121  else
1122  {
1123  if (++(IicPort[Port].Timer) >= (UWORD)(IicPort[Port].Time / (IIC_TIMER_RESOLUTION / 10)))
1124  {
1125  IicPort[Port].Timer = 0;
1126  IicPort[Port].State = IIC_WRITING;
1127  }
1128  }
1129  }
1130  break;
1131 
1132  case IIC_EXIT :
1133  {
1134  IicPortDisable(Port);
1135  IicPort[Port] = IicPortDefault;
1136 
1137  (*pIic).Status[Port] = 0;
1138 
1139  IicPort[Port].State = IIC_IDLE;
1140  }
1141  break;
1142 
1143  }
1144 
1145 #ifndef DISABLE_FAST_DATALOG_BUFFER
1146  ((*pIic).Repeat[Port][(*pIic).Actual[Port]]) += (IIC_TIMER_RESOLUTION / 10);
1147 #endif
1148 
1149 #ifdef HIGHDEBUG
1150  if (IicPort[Port].OldState != IicPort[Port].State)
1151  {
1152  IicPort[Port].OldState = IicPort[Port].State;
1153  if (IicPort[Port].State != IIC_ENABLE)
1154  {
1155  snprintf(IicBuffer,IICBUFFERSIZE," %d %s\r\n",Port,IicStateText[IicPort[Port].State]);
1156  }
1157  else
1158  {
1159  snprintf(IicBuffer,IICBUFFERSIZE,"*** %d %s ***\r\n",Port,IicStateText[IicPort[Port].State]);
1160  }
1161  IicWrite(IicBuffer);
1162  }
1163 #endif
1164 
1165  }
1166 
1167 
1168  return (HRTIMER_RESTART);
1169 }
1170 
1171 
1172 static int Device1Ioctl(struct inode *pNode, struct file *File, unsigned int Request, unsigned long Pointer)
1173 {
1174  DEVCON *pDevCon;
1175  IICSTR *pIicStr;
1176  IICDAT *pIicDat;
1177  DATA8 Port = 0;
1178 
1179  switch (Request)
1180  {
1181 
1182  case IIC_SET_CONN :
1183  {
1184  pDevCon = (DEVCON*)Pointer;
1185 
1186  for (Port = 0;Port < INPUTS;Port++)
1187  {
1188  if ((*pDevCon).Connection[Port] == CONN_NXT_IIC)
1189  {
1190  if (IicConfigured[Port] == 0)
1191  {
1192 #ifdef DEBUG_TRACE_MODE_CHANGE
1193 // printk("d_iic %d Device1Ioctl: Changing to IIC\n",Port);
1194 #endif
1195  IicConfigured[Port] = 1;
1196  IicPortType[Port] = (*pDevCon).Type[Port];
1197  IicPort[Port].State = IIC_INIT;
1198  }
1199  else
1200  {
1201  if (IicPort[Port].Initialised)
1202  {
1203  if (IicPort[Port].Mode != (*pDevCon).Mode[Port])
1204  {
1205 #ifdef DEBUG_TRACE_MODE_CHANGE
1206 // printk("d_iic %d Device1Ioctl: Changing to %c\n",Port,(*pDevCon).Mode[Port] + '0');
1207 #endif
1208  IicPort[Port].Mode = (*pDevCon).Mode[Port];
1209  IicPort[Port].ChangeMode = 1;
1210  (*pIic).Status[Port] &= ~IIC_DATA_READY;
1211  IicPort[Port].State = IIC_SETUP_START;
1212  }
1213  }
1214  }
1215  }
1216  else
1217  {
1218 #ifdef DEBUG_TRACE_MODE_CHANGE
1219 // printk("d_iic %d Device1Ioctl: Changing to non IIC\n",Port);
1220 #endif
1221  (*pIic).Status[Port] &= ~IIC_DATA_READY;
1222  if (IicConfigured[Port])
1223  {
1224  IicConfigured[Port] = 0;
1225  IicPort[Port].State = IIC_EXIT;
1226  }
1227  }
1228  }
1229 
1230  }
1231  break;
1232 
1233  case IIC_SET :
1234  {
1235  pIicStr = (IICSTR*)Pointer;
1236 
1237  Port = (*pIicStr).Port;
1238 
1239  memcpy((void*)&IicStrings[Port],(void*)pIicStr,sizeof(IICSTR));
1240  IicPort[Port].State = IIC_SETUP_START;
1241 
1242  }
1243  break;
1244 
1245  case IIC_SETUP :
1246  {
1247  pIicDat = (IICDAT*)Pointer;
1248 
1249  Port = (*pIicDat).Port;
1250  (*pIicDat).Result = BUSY;
1251 
1252  printk("1\n");
1253  if (!((*pIic).Status[Port] & IIC_WRITE_REQUEST))
1254  {
1255  printk("2\n");
1256  IicPort[Port].Repeat = (*pIicDat).Repeat;
1257  IicPort[Port].Time = (*pIicDat).Time;
1258  IicPort[Port].OutLength = (*pIicDat).WrLng;
1259  if ((*pIicDat).RdLng < 0)
1260  {
1261  IicPort[Port].InLength = 0 - (*pIicDat).RdLng;
1262  IicPort[Port].Reverse = 1;
1263  }
1264  else
1265  {
1266  IicPort[Port].InLength = (*pIicDat).RdLng;
1267  IicPort[Port].Reverse = 0;
1268  }
1269 
1270  if (IicPort[Port].OutLength > IIC_DATA_LENGTH)
1271  {
1272  IicPort[Port].OutLength = IIC_DATA_LENGTH;
1273  }
1274  if (IicPort[Port].InLength > IIC_DATA_LENGTH)
1275  {
1276  IicPort[Port].InLength = IIC_DATA_LENGTH;
1277  }
1278 
1279  memcpy((void*)&IicPort[Port].OutBuffer[0],(void*)&(*pIicDat).WrData[0],IicPort[Port].OutLength);
1280  memset((void*)&IicPort[Port].InBuffer[0],0,IIC_DATA_LENGTH);
1281 
1282  (*pIic).Status[Port] = IIC_WRITE_REQUEST;
1283  }
1284 
1285  if (((*pIic).Status[Port] & IIC_DATA_READY))
1286  {
1287  printk("3\n");
1288  memcpy((void*)&(*pIicDat).RdData[0],(void*)&IicPort[Port].InBuffer[0],IicPort[Port].InLength);
1289 
1290  (*pIicDat).Result = OK;
1291  (*pIic).Status[Port] = 0;
1292  }
1293  }
1294  break;
1295 
1296  case IIC_READ_TYPE_INFO :
1297  {
1298  pIicStr = (IICSTR*)Pointer;
1299 
1300  Port = (*pIicStr).Port;
1301  memcpy((void*)((*pIicStr).Manufacturer),(void*)IicStrings[Port].Manufacturer,IIC_NAME_LENGTH + 1);
1302  memcpy((void*)((*pIicStr).SensorType),(void*)IicStrings[Port].SensorType,IIC_NAME_LENGTH + 1);
1303 
1304  (*pIic).Changed[Port] = 0;
1305 
1306  }
1307  break;
1308 
1309  }
1310 
1311  return (0);
1312 }
1313 
1314 
1315 static ssize_t Device1Write(struct file *File,const char *Buffer,size_t Count,loff_t *Data)
1316 {
1317  int Lng = 0;
1318 
1319  Lng = Count;
1320 
1321  return (Lng);
1322 }
1323 
1324 
1325 static ssize_t Device1Read(struct file *File,char *Buffer,size_t Count,loff_t *Offset)
1326 {
1327  int Lng = 0;
1328 
1329 #ifdef DEBUG_IIC_WRITE
1330  if (LogOutPointer != LogPointer)
1331  {
1332  while ((Count--) && (LogOutPointer != LogPointer))
1333  {
1334  Buffer[Lng++] = LogPool[LogOutPointer];
1335  Buffer[Lng] = 0;
1336 
1337  LogOutPointer++;
1338  if (LogOutPointer >= LOGPOOLSIZE)
1339  {
1340  LogOutPointer = 0;
1341  }
1342  }
1343  }
1344  if (Lng == 0)
1345  {
1346  IicWrite(IicBuffer);
1347  snprintf(IicBuffer,IICBUFFERSIZE,"-----------------------------------------------------------------\r\n");
1348  IicWrite(IicBuffer);
1349  snprintf(IicBuffer,IICBUFFERSIZE," IIC DUMP\r\n");
1350  IicWrite(IicBuffer);
1351  snprintf(IicBuffer,IICBUFFERSIZE,"-----------------------------------------------------------------\r\n");
1352  IicWrite(IicBuffer);
1353  }
1354 #else
1355  int Tmp;
1356  int Port;
1357 
1358  Port = 0;
1359  Tmp = 5;
1360  while ((Count > Tmp) && (Port < INPUTS))
1361  {
1362  if (Port != (INPUTS - 1))
1363  {
1364  Tmp = snprintf(&Buffer[Lng],4,"%2u ",(UWORD)IicPort[Port].State);
1365  }
1366  else
1367  {
1368  Tmp = snprintf(&Buffer[Lng],5,"%2u\r",(UWORD)IicPort[Port].State);
1369  }
1370  Lng += Tmp;
1371  Count -= Tmp;
1372  Port++;
1373  }
1374 #endif
1375 
1376  return (Lng);
1377 }
1378 
1379 
1380 #define SHM_LENGTH (sizeof(IicDefault))
1381 #define NPAGES ((SHM_LENGTH + PAGE_SIZE - 1) / PAGE_SIZE)
1382 static void *kmalloc_ptr;
1383 
1384 static int Device1Mmap(struct file *filp, struct vm_area_struct *vma)
1385 {
1386  int ret;
1387 
1388  ret = remap_pfn_range(vma,vma->vm_start,virt_to_phys((void*)((unsigned long)pIic)) >> PAGE_SHIFT,vma->vm_end-vma->vm_start,PAGE_SHARED);
1389 
1390  if (ret != 0)
1391  {
1392  ret = -EAGAIN;
1393  }
1394 
1395  return (ret);
1396 }
1397 
1398 
1399 static const struct file_operations Device1Entries =
1400 {
1401  .owner = THIS_MODULE,
1402  .read = Device1Read,
1403  .write = Device1Write,
1404  .mmap = Device1Mmap,
1405  .ioctl = Device1Ioctl,
1406 };
1407 
1408 
1409 static struct miscdevice Device1 =
1410 {
1411  MISC_DYNAMIC_MINOR,
1412  DEVICE1_NAME,
1413  &Device1Entries
1414 };
1415 
1416 
1417 static int Device1Init(void)
1418 {
1419  int Result = -1;
1420  UWORD *pTmp;
1421  int i;
1422 #ifndef DISABLE_FIQ_IIC
1423  UBYTE Port;
1424 #endif
1425 
1426  Result = misc_register(&Device1);
1427  if (Result)
1428  {
1429  printk(" %s device register failed\n",DEVICE1_NAME);
1430  }
1431  else
1432  {
1433  // allocate kernel shared memory for analog values (pAnalog)
1434  if ((kmalloc_ptr = kmalloc((NPAGES + 2) * PAGE_SIZE, GFP_KERNEL)) != NULL)
1435  {
1436  pTmp = (UWORD*)((((unsigned long)kmalloc_ptr) + PAGE_SIZE - 1) & PAGE_MASK);
1437  for (i = 0; i < NPAGES * PAGE_SIZE; i += PAGE_SIZE)
1438  {
1439  SetPageReserved(virt_to_page(((unsigned long)pTmp) + i));
1440  }
1441  pIic = (IIC*)pTmp;
1442  memset(pIic,0,sizeof(IIC));
1443 
1444 #ifndef DISABLE_FIQ_IIC
1445  IicCtrl.port_enabled = 0;
1446 
1447  for (Port = 0;Port < INPUTS;Port++)
1448  {
1449  IicPort[Port] = IicPortDefault;
1450  IicConfigured[Port] = 0;
1452  IicStrings[Port].Manufacturer[0] = 0;
1453  IicStrings[Port].SensorType[0] = 0;
1454  if (Port == DEBUG_UART)
1455  {
1458  }
1459  }
1460 #endif
1461 
1462  Device1Time = ktime_set(0,IIC_TIMER_RESOLUTION * 100000);
1463  hrtimer_init(&Device1Timer,CLOCK_MONOTONIC,HRTIMER_MODE_REL);
1464  Device1Timer.function = Device1TimerInterrupt1;
1465  hrtimer_start(&Device1Timer,Device1Time,HRTIMER_MODE_REL);
1466 
1467 #ifdef DEBUG
1468  printk(" %s device register succes\n",DEVICE1_NAME);
1469 #endif
1470  }
1471  else
1472  {
1473  printk(" %s kmalloc failed !!\n",DEVICE1_NAME);
1474  }
1475  }
1476 
1477  return (Result);
1478 }
1479 
1480 
1481 static void Device1Exit(void)
1482 {
1483  IIC *pTmp;
1484  int i;
1485 
1486  hrtimer_cancel(&Device1Timer);
1487 
1488  pTmp = pIic;
1489  pIic = &IicDefault;
1490 
1491  // free shared memory
1492  for (i = 0; i < NPAGES * PAGE_SIZE; i+= PAGE_SIZE)
1493  {
1494  ClearPageReserved(virt_to_page(((unsigned long)pTmp) + i));
1495 #ifdef DEBUG
1496  printk(" %s memory page %d unmapped\n",DEVICE1_NAME,i);
1497 #endif
1498  }
1499  kfree(kmalloc_ptr);
1500 
1501  misc_deregister(&Device1);
1502 #ifdef DEBUG
1503  printk(" %s device unregistered\n",DEVICE1_NAME);
1504 #endif
1505 }
1506 
1507 
1508 
1509 
1510 // MODULE *********************************************************************
1511 
1512 
1513 #ifndef PCASM
1514 module_param (HwId, charp, 0);
1515 #endif
1516 
1517 static int ModuleInit(void)
1518 {
1519  Hw = HWID;
1520 
1521  if (Hw < PLATFORM_START)
1522  {
1523  Hw = PLATFORM_START;
1524  }
1525  if (Hw > PLATFORM_END)
1526  {
1527  Hw = PLATFORM_END;
1528  }
1529 
1530 #ifdef DEBUG
1531  printk("%s init started\n",MODULE_NAME);
1532 #endif
1533  if (request_mem_region(DA8XX_GPIO_BASE,0xD8,MODULE_NAME) >= 0)
1534  {
1535  GpioBase = (void*)ioremap(DA8XX_GPIO_BASE,0xD8);
1536  if (GpioBase != NULL)
1537  {
1538 #ifdef DEBUG
1539  printk("%s gpio address mapped\n",MODULE_NAME);
1540 #endif
1541 
1542  InitGpio();
1543 
1544  Device1Init();
1545  }
1546  }
1547 
1548  return (0);
1549 }
1550 
1551 
1552 static void ModuleExit(void)
1553 {
1554 #ifdef DEBUG
1555  printk("%s exit started\n",MODULE_NAME);
1556 #endif
1557 
1558  Device1Exit();
1559 
1560  iounmap(GpioBase);
1561 }
1562 
UBYTE Mode
Definition: d_iic.c:373
__u8 data[32]
Definition: d_iic.h:52
#define DEVICE1_NAME
Definition: d_iic.c:83
Definition: am1808.h:41
#define REGLock
Definition: am1808.h:235
__u8 port_enabled
Definition: d_iic.h:78
#define TYPE_NAME_LENGTH
Definition: lms2012.h:768
Definition: am1808.h:33
#define snprintf
Definition: c_input.c:141
int Hw
Definition: d_iic.c:149
UBYTE OutPointer
Definition: d_iic.c:381
signed char SBYTE
Basic Type used to symbolise 8 bit signed values.
Definition: lmstypes.h:33
__u8 transfers_active
Definition: d_iic.h:79
MRM MuxRegMap[]
Definition: am1808.h:59
GPIOC pGpio
Definition: am1808.h:225
#define REGUnlock
Definition: am1808.h:230
INPIN * pIicPortPin[]
Definition: d_iic.c:242
module_init(ModuleInit)
struct IIC_data_package data_package[IIC_INPUTS]
Definition: d_iic.h:77
Definition: am1808.h:222
#define IIC_SETUP
Definition: lms2012.h:1168
DATA16 Time
Definition: lms2012.h:1152
#define EP2
Schematics revision D.
Definition: lms2012.h:99
__u8 write_length
Definition: d_iic.h:54
#define NO_OF_IIC_PORTS
Definition: d_iic.c:127
__u8 read_length
Definition: d_iic.h:53
void SetGpio(int Pin)
Definition: d_iic.c:254
Definition: am1808.h:40
#define FINAL
Final prototype.
Definition: lms2012.h:101
UBYTE InBuffer[IIC_DATA_LENGTH]
Definition: d_iic.c:382
struct IIC_control_t IicCtrl
Definition: am1808.h:41
UBYTE SubState
Definition: d_iic.c:370
Definition: am1808.h:41
#define IIC_READ_TYPE_INFO
Definition: lms2012.h:1167
Definition: am1808.h:40
u16 MuxReg
Definition: am1808.h:53
DATA8 Type[INPUTS]
Definition: lms2012.h:1061
DATA8 IicPortType[INPUTS]
Definition: d_iic.c:669
#define IIC_TIMER_RESOLUTION
Definition: d_iic.c:673
UWORD Time
Definition: d_iic.c:365
Definition: am1808.h:33
UBYTE OutBuffer[IIC_DATA_LENGTH]
Definition: d_iic.c:383
Definition: d_iic.c:362
#define Timer
Definition: am1808.h:34
unsigned int ULONG
Basic Type used to symbolise 32 bit unsigned values.
Definition: lmstypes.h:31
MODULE_SUPPORTED_DEVICE(DEVICE1_NAME)
#define PINInput(port, pin)
Definition: d_iic.h:90
IicPortPins
Definition: d_iic.h:82
UBYTE Repeat
Definition: d_iic.c:371
UBYTE OldState
Definition: d_iic.c:369
UBYTE State
Definition: d_iic.c:368
#define NPAGES
Definition: d_iic.c:1381
UBYTE OutLength
Definition: d_iic.c:380
INPIN IicPortPin[NO_OF_IIC_PORTS][IIC_PORT_PINS]
UBYTE Initialised
Definition: d_iic.c:366
UWORD Timer
Definition: d_iic.c:364
int Pin
Definition: am1808.h:224
void iic_fiq_start_transfer(unsigned int time, bool fiq_nirq)
Definition: am1808.h:34
MODULE_LICENSE("GPL")
#define FINALB
Schematics revision B and C.
Definition: lms2012.h:100
IIC_STATE
Definition: d_iic.c:612
#define IIC_DATA_READY
Data is ready.
Definition: lms2012.h:1122
Definition: am1808.h:33
#define IIC_WRITE_REQUEST
Write request.
Definition: lms2012.h:1123
UBYTE Retries
Definition: d_iic.c:375
UBYTE Reverse
Definition: d_iic.c:377
IICPORT IicPort[INPUTS]
Definition: d_iic.c:451
DATA8 PollLng
Definition: lms2012.h:1159
module_param(HwId, charp, 0)
unsigned char UBYTE
Basic Type used to symbolise 8 bit unsigned values.
Definition: lmstypes.h:29
DATA8 SensorType[IIC_NAME_LENGTH+1]
Definition: lms2012.h:1156
DATA8 ReadLng
Definition: lms2012.h:1161
__u8 clock_state
Definition: d_iic.h:55
UBYTE InPointer
Definition: d_iic.c:379
u32 Mask
Definition: am1808.h:226
unsigned short UWORD
Basic Type used to symbolise 16 bit unsigned values.
Definition: lmstypes.h:30
char Buffer[1024]
Definition: c_wifi.c:102
DATA8 Port
Definition: lms2012.h:1138
Definition: am1808.h:34
Definition: am1808.h:34
#define PUDisable
Definition: d_iic.c:240
#define PINLow(port, pin)
Definition: d_analog.c:876
__u8 nacked
Definition: d_iic.h:61
Definition: am1808.h:34
#define PINOutput(port, pin)
Definition: d_iic.h:91
#define IIC_SET
Definition: lms2012.h:1169
DATA8 Port
Definition: lms2012.h:1151
DATA8 Manufacturer[IIC_NAME_LENGTH+1]
Definition: lms2012.h:1155
MODULE_DESCRIPTION(MODULE_NAME)
Definition: am1808.h:33
SBYTE DATA8
VM Type for 1 byte signed value.
Definition: lmstypes.h:61
Definition: am1808.h:33
DATA8 SetupLng
Definition: lms2012.h:1157
uint32_t u32
Definition: common.h:158
IICPORT IicPortDefault
Definition: d_iic.c:388
__u8 transfer_state
Definition: d_iic.h:59
#define IIC_SET_CONN
Definition: lms2012.h:1166
module_exit(ModuleExit)
UBYTE Cmd
Definition: d_iic.c:372
#define INPUTS
Number of input ports in the system.
Definition: lms2012.h:192
void InitGpio(void)
Definition: d_iic.c:288
MODULE_AUTHOR("The LEGO Group")
#define PINHigh(port, pin)
Definition: d_analog.c:871
#define PLATFORM_END
Newest supported hardware (newer versions will use this)
Definition: lms2012.h:105
IICSTR IicStrings[INPUTS]
Definition: d_iic.c:670
#define MODULE_NAME
Definition: d_iic.c:82
UBYTE IicConfigured[INPUTS]
Definition: d_iic.c:450
UBYTE ChangeMode
Definition: d_iic.c:367
Definition: am1808.h:34
UBYTE InLength
Definition: d_iic.c:378
UBYTE Addr
Definition: d_iic.c:374
char IicStateText[IIC_STATES][50]
Definition: d_iic.c:641
#define PLATFORM_START
Oldest supported hardware (older versions will use this)
Definition: lms2012.h:104
#define NULL