|
1 // Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of the License "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // lukasz.forynski@gmail.com |
|
13 // |
|
14 // Description: |
|
15 // omap3530/omap3530_drivers/spi/psl_init.cpp |
|
16 // |
|
17 |
|
18 #include <drivers/iic.h> |
|
19 #include <drivers/iic_channel.h> |
|
20 |
|
21 #include "psl_init.h" |
|
22 |
|
23 #ifdef MASTER_MODE |
|
24 #include "master.h" |
|
25 #endif |
|
26 #ifdef SLAVE_MODE |
|
27 #include "slave.h" |
|
28 #endif |
|
29 |
|
30 #if !defined(MASTER_MODE) && !defined(SLAVE_MODE) |
|
31 #error "Should select at least one type of SPI channels.." |
|
32 #endif |
|
33 |
|
34 DECLARE_STANDARD_EXTENSION() |
|
35 { |
|
36 // Array of pointers to the Channels that the PSL creates, for registration with the Bus Controller |
|
37 // Use a local array, since the IIC Controller operates on a copy of the array entries. |
|
38 DIicBusChannel* channelPtrArray[KIicPslNumOfChannels]; |
|
39 |
|
40 TInt r = KErrNone; |
|
41 |
|
42 #ifdef MASTER_MODE |
|
43 #ifndef SLAVE_MODE |
|
44 // If only MASTER_MODE is declared - Create only DIicBusChannelMasterPsl channels |
|
45 __KTRACE_OPT(KIIC, Kern::Printf("\n\nCreating DIicBusChannelMasterPsl only\n")); |
|
46 |
|
47 DIicBusChannel* chan = NULL; |
|
48 for (TInt i = 0; i < KIicPslNumOfChannels; ++i) |
|
49 { |
|
50 // The first argument repesents the PSL-assigned channel number |
|
51 // The second argument, DIicBusChannel::ESpi, should be replaced with the relevant bus type for the PSL |
|
52 // chan = DSpiMasterBeagle::New(i, DIicBusChannel::ESpi, DIicBusChannel::EFullDuplex); |
|
53 if((TInt)KIicPslNumOfChannels == 2)// TODO: hack - only for the time being - enable channel 3 |
|
54 chan = DSpiMasterBeagle::New(i+2, DIicBusChannel::ESpi, DIicBusChannel::EFullDuplex); |
|
55 else |
|
56 { |
|
57 Kern::Printf("remove hack from here: %s,line %d", __FILE__, __LINE__); |
|
58 return KErrGeneral; |
|
59 } |
|
60 |
|
61 if (!chan) |
|
62 { |
|
63 return KErrNoMemory; |
|
64 } |
|
65 channelPtrArray[i] = chan; |
|
66 } |
|
67 |
|
68 #else /*SLAVE_MODE*/ |
|
69 // Master and Slave functionality is available, so create Master, Slave and MasterSlave Channels |
|
70 // Create channel 0 as Master, channel 1 as a Slave, and channel 2 as MasterSlave. |
|
71 __KTRACE_OPT(KIIC, Kern::Printf("\n\nCreating Master, Slave and MasterSlave channels\n")); |
|
72 |
|
73 DIicBusChannel* chan = NULL; |
|
74 |
|
75 // Master channel |
|
76 // The first argument repesents the PSL-assigned channel number |
|
77 // The second argument, DIicBusChannel::ESpi, should be replaced with the relevant bus type for the PSL |
|
78 chan = DSpiMasterBeagle::New(0, DIicBusChannel::ESpi, DIicBusChannel::EFullDuplex); |
|
79 if (!chan) |
|
80 { |
|
81 return KErrNoMemory; |
|
82 } |
|
83 channelPtrArray[0] = chan; |
|
84 |
|
85 // Slave channel |
|
86 // The first argument repesents the PSL-assigned channel number |
|
87 // The second argument, DIicBusChannel::ESpi, should be replaced with the relevant bus type for the PSL |
|
88 chan = DSpiSlaveBeagle::New(1, DIicBusChannel::ESpi, DIicBusChannel::EFullDuplex); |
|
89 if (!chan) |
|
90 { |
|
91 return KErrNoMemory; |
|
92 } |
|
93 channelPtrArray[1] = chan; |
|
94 |
|
95 // MasterSlave channel |
|
96 // MasterSlave channels are not for derivation; instead, they have a pointer to a (derived) Master channel |
|
97 // and a pointer to a (derived) Slave channel |
|
98 DIicBusChannel* chanM = NULL; |
|
99 DIicBusChannel* chanS = NULL; |
|
100 // For MasterSlave channel, the channel number for both the Master and Slave channels must be the same |
|
101 TInt msChanNum = 2; |
|
102 // Master channel |
|
103 // The first argument repesents the PSL-assigned channel number |
|
104 // The second argument, DIicBusChannel::ESpi, should be replaced with the relevant bus type for the PSL |
|
105 chanM = DSpiMasterBeagle::New(msChanNum, DIicBusChannel::ESpi, DIicBusChannel::EFullDuplex); |
|
106 if (!chanM) |
|
107 { |
|
108 return KErrNoMemory; |
|
109 } |
|
110 // Slave channel |
|
111 // The first argument repesents the PSL-assigned channel number |
|
112 // The second argument, DIicBusChannel::ESpi, should be replaced with the relevant bus type for the PSL |
|
113 chanS = DSpiSlaveBeagle::New(msChanNum, DIicBusChannel::ESpi, DIicBusChannel::EFullDuplex); |
|
114 if (!chanS) |
|
115 { |
|
116 return KErrNoMemory; |
|
117 } |
|
118 // MasterSlave channel |
|
119 // The first argument, DIicBusChannel::ESpi, should be replaced with the relevant bus type for the PSL |
|
120 chan = new DIicBusChannelMasterSlave(DIicBusChannel::ESpi, DIicBusChannel::EFullDuplex, (DIicBusChannelMaster*)chanM, (DIicBusChannelSlave*)chanS); |
|
121 if (!chan) |
|
122 { |
|
123 return KErrNoMemory; |
|
124 } |
|
125 r = ((DIicBusChannelMasterSlave*)chan)->DoCreate(); |
|
126 channelPtrArray[2] = chan; |
|
127 |
|
128 |
|
129 #endif /*SLAVE_MODE*/ |
|
130 #else /*MASTER_MODE*/ |
|
131 |
|
132 #ifdef SLAVE_MODE |
|
133 // If only SLAVE_MODE is declared - Create all as DSpiSlaveBeagle channels |
|
134 __KTRACE_OPT(KIIC, Kern::Printf("\n\nCreating DSpiSlaveBeagle only\n")); |
|
135 |
|
136 DIicBusChannel* chan = NULL; |
|
137 for (TInt i = 0; i < KIicPslNumOfChannels; ++i) |
|
138 { |
|
139 // The first argument repesents the PSL-assigned channel number |
|
140 // The second argument, DIicBusChannel::ESpi, should be replaced with the relevant bus type for the PSL |
|
141 chan = DSpiSlaveBeagle::New(i, DIicBusChannel::ESpi, DIicBusChannel::EFullDuplex); |
|
142 if (!chan) |
|
143 { |
|
144 return KErrNoMemory; |
|
145 } |
|
146 channelPtrArray[i] = chan; |
|
147 } |
|
148 |
|
149 #endif |
|
150 #endif /*MASTER_MODE*/ |
|
151 |
|
152 // Register them with the Bus Controller |
|
153 r = DIicBusController::RegisterChannels(channelPtrArray, KIicPslNumOfChannels); |
|
154 |
|
155 return r; |
|
156 } |