| 5154 | | # Collect all adapters used |
| 5155 | | $nr = 0; |
| | 5145 | # Handle aliases |
| | 5146 | # As of kernel 2.6.28, alias detection is handled by kernel drivers |
| | 5147 | # directly, so module options are no longer needed. |
| | 5148 | unless (kernel_version_at_least(2, 6, 28)) { |
| | 5149 | foreach $chip (@chips_detected) { |
| | 5150 | @optionlist = (); |
| | 5151 | foreach $detection (@{$chip->{detected}}) { |
| | 5152 | if (exists $detection->{i2c_driver} and |
| | 5153 | exists $detection->{isa_addr}) { |
| | 5154 | push @optionlist, $detection->{i2c_devnr}, |
| | 5155 | $detection->{i2c_addr}; |
| | 5156 | } |
| | 5157 | } |
| | 5158 | |
| | 5159 | next if not @optionlist; |
| | 5160 | $configfile = "# hwmon module options\n" unless defined $configfile; |
| | 5161 | $configfile .= "options $chip->{driver}"; |
| | 5162 | $configfile .= sprintf(" ignore=%d,0x%02x", shift @optionlist, |
| | 5163 | shift @optionlist); |
| | 5164 | $configfile .= sprintf(",%d,0x%02x", shift @optionlist, |
| | 5165 | shift @optionlist) while @optionlist; |
| | 5166 | $configfile .= "\n"; |
| | 5167 | } |
| | 5168 | } |
| | 5169 | |
| 5159 | | # If there is more than one bus detected by a driver, they are |
| 5160 | | # still all added. So we number them in the correct order |
| 5161 | | if (exists $detection->{i2c_driver} and |
| 5162 | | not exists $i2c_adapters[$detection->{i2c_devnr}]->{nr_later} and |
| 5163 | | not exists $detection->{isa_addr}) { # Always use ISA access if possible |
| 5164 | | foreach $adap (@i2c_adapters) { |
| 5165 | | next unless exists $adap->{driver}; |
| 5166 | | $adap->{nr_later} = $nr++ if $adap->{driver} eq $detection->{i2c_driver}; |
| 5167 | | } |
| | 5173 | # Tag adapters which host hardware monitoring chips we want to access |
| | 5174 | if (exists $detection->{i2c_devnr} |
| | 5175 | && !exists $detection->{isa_addr}) { |
| | 5176 | $i2c_adapters[$detection->{i2c_devnr}]->{used}++; |
| 5178 | | $modprobes .= "# I2C adapter drivers\n" if $nr; |
| 5179 | | for ($i = 0; $i < $nr; $i++) { |
| 5180 | | foreach $adap (@i2c_adapters) { |
| 5181 | | next unless exists $adap->{nr_later} and $adap->{nr_later} == $i; |
| 5182 | | if ($adap->{driver} eq "UNKNOWN") { |
| 5183 | | $modprobes .= "# modprobe unknown adapter ".$adap->{name}."\n"; |
| 5184 | | } else { |
| 5185 | | $modprobes .= "modprobe $adap->{driver}\n" |
| 5186 | | unless $modprobes =~ /modprobe $adap->{driver}\n/; |
| 5187 | | } |
| 5188 | | last; |
| 5189 | | } |
| 5190 | | } |
| | 5188 | # If we added any module option to handle aliases, we need to load all |
| | 5189 | # the adapter drivers so that the numbers will be the same. If not, then |
| | 5190 | # we only load the adapter drivers which are useful. |
| | 5191 | foreach $adap (@i2c_adapters) { |
| | 5192 | next unless contains($adap->{driver}, @modules_we_loaded); |
| | 5193 | next if not defined $configfile and not $adap->{used}; |
| | 5194 | $modprobes .= "# I2C adapter drivers\n" unless defined $modprobes; |
| | 5195 | $modprobes .= "modprobe $adap->{driver}\n" |
| | 5196 | unless $modprobes =~ /modprobe $adap->{driver}\n/; |
| | 5197 | } |
| | 5198 | |
| 5225 | | |
| 5226 | | # Handle aliases |
| 5227 | | # As of kernel 2.6.28, alias detection is handled by kernel drivers |
| 5228 | | # directly, so module options are no longer needed. |
| 5229 | | unless (kernel_version_at_least(2, 6, 28)) { |
| 5230 | | foreach $detection (@{$chip->{detected}}) { |
| 5231 | | if (exists $detection->{i2c_driver} and |
| 5232 | | exists $detection->{isa_addr} and |
| 5233 | | exists $i2c_adapters[$detection->{i2c_devnr}]->{nr_later}) { |
| 5234 | | push @optionlist, $i2c_adapters[$detection->{i2c_devnr}]->{nr_later}, |
| 5235 | | $detection->{i2c_addr}; |
| 5236 | | } |
| 5237 | | } |
| 5238 | | } |
| 5239 | | |
| 5240 | | next if not @optionlist; |
| 5241 | | $configfile = "# hwmon module options\n" unless defined $configfile; |
| 5242 | | $configfile .= "options $chip->{driver}"; |
| 5243 | | $configfile .= sprintf(" ignore=%d,0x%02x", shift @optionlist, |
| 5244 | | shift @optionlist) |
| 5245 | | if @optionlist; |
| 5246 | | $configfile .= sprintf(",%d,0x%02x", shift @optionlist, shift @optionlist) |
| 5247 | | while @optionlist; |
| 5248 | | $configfile .= "\n"; |