| 2135 | | my $use_devfs = 0; |
| 2136 | | open(local *INPUTFILE, "/proc/mounts") or die "Can't access /proc/mounts!"; |
| 2137 | | local $_; |
| 2138 | | while (<INPUTFILE>) { |
| 2139 | | if (m@^\w+ /dev devfs @) { |
| 2140 | | $use_devfs = 1; |
| 2141 | | $dev_i2c = '/dev/i2c/'; |
| 2142 | | } |
| 2143 | | if (m@^\S+ (/\w+) sysfs @) { |
| 2144 | | $sysfs_root = $1; |
| 2145 | | } |
| 2146 | | } |
| 2147 | | close(INPUTFILE); |
| 2148 | | |
| 2149 | | # We need sysfs for many things |
| 2150 | | if (!defined $sysfs_root) { |
| 2151 | | print "Sysfs not mounted?\n"; |
| 2152 | | exit -1; |
| 2153 | | } |
| 2154 | | |
| 2155 | | my $use_udev = 0; |
| 2156 | | if (open(*INPUTFILE, '/etc/udev/udev.conf')) { |
| 2157 | | while (<INPUTFILE>) { |
| 2158 | | if (m/^\s*udev_db\s*=\s*\"([^"]*)\"/ || m/^\s*udev_db\s*=\s*(\S+)/) { |
| 2159 | | if (-e $1) { |
| 2160 | | $use_udev = 1; |
| 2161 | | $dev_i2c = '/dev/i2c-'; |
| 2162 | | } |
| 2163 | | last; |
| 2164 | | } |
| 2165 | | } |
| 2166 | | close(INPUTFILE); |
| 2167 | | } |
| 2168 | | |
| 2169 | | if (!$use_udev) { |
| 2170 | | # Try some known default udev db locations, just in case |
| 2171 | | if (-e '/dev/.udev.tdb' || -e '/dev/.udev' |
| 2172 | | || -e '/dev/.udevdb') { |
| 2173 | | $use_udev = 1; |
| 2174 | | $dev_i2c = '/dev/i2c-'; |
| 2175 | | } |
| 2176 | | } |
| 2177 | | |
| 2178 | | if (!($use_devfs || $use_udev)) { |
| 2179 | | if (! -c '/dev/i2c-0' && -x '/sbin/MAKEDEV') { |
| 2180 | | system("/sbin/MAKEDEV i2c"); |
| 2181 | | } |
| 2182 | | if (! -c '/dev/i2c-0' && -x '/dev/MAKEDEV') { |
| 2183 | | system("/dev/MAKEDEV i2c"); |
| 2184 | | } |
| 2185 | | if (-c '/dev/i2c-0') { |
| 2186 | | $dev_i2c = '/dev/i2c-'; |
| 2187 | | } else { # default |
| 2188 | | print "No i2c device files found.\n"; |
| 2189 | | exit -1; |
| 2190 | | } |
| 2191 | | } |
| | 2135 | my $use_devfs = 0; |
| | 2136 | open(local *INPUTFILE, "/proc/mounts") or die "Can't access /proc/mounts!"; |
| | 2137 | local $_; |
| | 2138 | while (<INPUTFILE>) { |
| | 2139 | if (m@^\w+ /dev devfs @) { |
| | 2140 | $use_devfs = 1; |
| | 2141 | $dev_i2c = '/dev/i2c/'; |
| | 2142 | } |
| | 2143 | if (m@^\S+ (/\w+) sysfs @) { |
| | 2144 | $sysfs_root = $1; |
| | 2145 | } |
| | 2146 | } |
| | 2147 | close(INPUTFILE); |
| | 2148 | |
| | 2149 | # We need sysfs for many things |
| | 2150 | if (!defined $sysfs_root) { |
| | 2151 | print "Sysfs not mounted?\n"; |
| | 2152 | exit -1; |
| | 2153 | } |
| | 2154 | |
| | 2155 | my $use_udev = 0; |
| | 2156 | if (open(*INPUTFILE, '/etc/udev/udev.conf')) { |
| | 2157 | while (<INPUTFILE>) { |
| | 2158 | next unless m/^\s*udev_db\s*=\s*\"([^"]*)\"/ |
| | 2159 | || m/^\s*udev_db\s*=\s*(\S+)/; |
| | 2160 | if (-e $1) { |
| | 2161 | $use_udev = 1; |
| | 2162 | $dev_i2c = '/dev/i2c-'; |
| | 2163 | } |
| | 2164 | last; |
| | 2165 | } |
| | 2166 | close(INPUTFILE); |
| | 2167 | } |
| | 2168 | |
| | 2169 | if (!$use_udev) { |
| | 2170 | # Try some known default udev db locations, just in case |
| | 2171 | if (-e '/dev/.udev.tdb' || -e '/dev/.udev' |
| | 2172 | || -e '/dev/.udevdb') { |
| | 2173 | $use_udev = 1; |
| | 2174 | $dev_i2c = '/dev/i2c-'; |
| | 2175 | } |
| | 2176 | } |
| | 2177 | |
| | 2178 | if (!($use_devfs || $use_udev)) { |
| | 2179 | if (! -c '/dev/i2c-0' && -x '/sbin/MAKEDEV') { |
| | 2180 | system("/sbin/MAKEDEV i2c"); |
| | 2181 | } |
| | 2182 | if (! -c '/dev/i2c-0' && -x '/dev/MAKEDEV') { |
| | 2183 | system("/dev/MAKEDEV i2c"); |
| | 2184 | } |
| | 2185 | if (-c '/dev/i2c-0') { |
| | 2186 | $dev_i2c = '/dev/i2c-'; |
| | 2187 | } else { # default |
| | 2188 | print "No i2c device files found.\n"; |
| | 2189 | exit -1; |
| | 2190 | } |
| | 2191 | } |
| 2203 | | `uname -r` =~ /(\d+)\.(\d+)\.(\d+)(.*)/; |
| 2204 | | @kernel_version = ($1, $2, $3, $4); |
| 2205 | | chomp($kernel_arch = `uname -m`); |
| 2206 | | |
| 2207 | | # We only support kernels >= 2.6.0 |
| 2208 | | if (!kernel_version_at_least(2, 6, 0)) { |
| 2209 | | print "Kernel version is unsupported (too old, >= 2.6.0 needed)\n"; |
| 2210 | | exit -1; |
| 2211 | | } |
| | 2203 | `uname -r` =~ /(\d+)\.(\d+)\.(\d+)(.*)/; |
| | 2204 | @kernel_version = ($1, $2, $3, $4); |
| | 2205 | chomp($kernel_arch = `uname -m`); |
| | 2206 | |
| | 2207 | # We only support kernels >= 2.6.0 |
| | 2208 | if (!kernel_version_at_least(2, 6, 0)) { |
| | 2209 | print "Kernel version is unsupported (too old, >= 2.6.0 needed)\n"; |
| | 2210 | exit -1; |
| | 2211 | } |
| 2216 | | my ($vers, $plvl, $slvl) = @_; |
| 2217 | | return 1 if ($kernel_version[0] > $vers || |
| 2218 | | ($kernel_version[0] == $vers && |
| 2219 | | ($kernel_version[1] > $plvl || |
| 2220 | | ($kernel_version[1] == $plvl && |
| 2221 | | ($kernel_version[2] >= $slvl))))); |
| 2222 | | return 0; |
| | 2216 | my ($vers, $plvl, $slvl) = @_; |
| | 2217 | return 1 if ($kernel_version[0] > $vers || |
| | 2218 | ($kernel_version[0] == $vers && |
| | 2219 | ($kernel_version[1] > $plvl || |
| | 2220 | ($kernel_version[1] == $plvl && |
| | 2221 | ($kernel_version[2] >= $slvl))))); |
| | 2222 | return 0; |
| 2232 | | open(local *INPUTFILE, "/proc/cpuinfo") or die "Can't access /proc/cpuinfo!"; |
| 2233 | | local $_; |
| 2234 | | my $entry; |
| 2235 | | |
| 2236 | | while (<INPUTFILE>) { |
| 2237 | | if (m/^processor\s*:\s*(\d+)/) { |
| 2238 | | push @cpu, $entry if scalar keys(%{$entry}); # Previous entry |
| 2239 | | $entry = {}; # New entry |
| 2240 | | next; |
| 2241 | | } |
| 2242 | | if (m/^(vendor_id|cpu family|model|model name|stepping)\s*:\s*(.+)$/) { |
| 2243 | | my $k = $1; |
| 2244 | | my $v = $2; |
| 2245 | | $v =~ s/\s+/ /g; # Merge multiple spaces |
| 2246 | | $v =~ s/ $//; # Trim trailing space |
| 2247 | | $entry->{$k} = $v; |
| 2248 | | next; |
| 2249 | | } |
| 2250 | | } |
| 2251 | | push @cpu, $entry if scalar keys(%{$entry}); # Last entry |
| 2252 | | close(INPUTFILE); |
| | 2232 | local $_; |
| | 2233 | my $entry; |
| | 2234 | |
| | 2235 | open(local *INPUTFILE, "/proc/cpuinfo") or die "Can't access /proc/cpuinfo!"; |
| | 2236 | while (<INPUTFILE>) { |
| | 2237 | if (m/^processor\s*:\s*(\d+)/) { |
| | 2238 | push @cpu, $entry if scalar keys(%{$entry}); # Previous entry |
| | 2239 | $entry = {}; # New entry |
| | 2240 | next; |
| | 2241 | } |
| | 2242 | if (m/^(vendor_id|cpu family|model|model name|stepping)\s*:\s*(.+)$/) { |
| | 2243 | my $k = $1; |
| | 2244 | my $v = $2; |
| | 2245 | $v =~ s/\s+/ /g; # Merge multiple spaces |
| | 2246 | $v =~ s/ $//; # Trim trailing space |
| | 2247 | $entry->{$k} = $v; |
| | 2248 | next; |
| | 2249 | } |
| | 2250 | } |
| | 2251 | close(INPUTFILE); |
| | 2252 | push @cpu, $entry if scalar keys(%{$entry}); # Last entry |
| 2262 | | my $entry; |
| 2263 | | local $_; |
| 2264 | | |
| 2265 | | my $class_dir = "${sysfs_root}/class/i2c-adapter"; |
| 2266 | | opendir(local *ADAPTERS, $class_dir) or return; |
| 2267 | | |
| 2268 | | while (defined($_ = readdir(ADAPTERS))) { |
| 2269 | | next unless m/^i2c-(\d+)$/; |
| 2270 | | $entry = {}; # New entry |
| 2271 | | $entry->{name} = sysfs_device_attribute("${class_dir}/i2c-$1", "name") |
| 2272 | | || sysfs_device_attribute("${class_dir}/i2c-$1/device", "name"); |
| 2273 | | next if $entry->{name} eq "ISA main adapter"; |
| 2274 | | |
| 2275 | | # First try to get the I2C adapter driver name from sysfs, and if it |
| 2276 | | # fails, fall back to searching our list of known I2C adapters. |
| 2277 | | $entry->{driver} = sysfs_device_driver("${class_dir}/i2c-$1/device") |
| 2278 | | || find_i2c_adapter_driver($entry->{name}) |
| 2279 | | || 'UNKNOWN'; |
| 2280 | | $i2c_adapters[$1] = $entry; |
| 2281 | | } |
| 2282 | | closedir(ADAPTERS); |
| | 2262 | my $entry; |
| | 2263 | local $_; |
| | 2264 | |
| | 2265 | my $class_dir = "${sysfs_root}/class/i2c-adapter"; |
| | 2266 | opendir(local *ADAPTERS, $class_dir) or return; |
| | 2267 | |
| | 2268 | while (defined($_ = readdir(ADAPTERS))) { |
| | 2269 | next unless m/^i2c-(\d+)$/; |
| | 2270 | $entry = {}; # New entry |
| | 2271 | $entry->{name} = sysfs_device_attribute("${class_dir}/i2c-$1", |
| | 2272 | "name") |
| | 2273 | || sysfs_device_attribute("${class_dir}/i2c-$1/device", |
| | 2274 | "name"); |
| | 2275 | next if $entry->{name} eq "ISA main adapter"; |
| | 2276 | |
| | 2277 | # First try to get the I2C adapter driver name from sysfs, |
| | 2278 | # and if it fails, fall back to searching our list of known |
| | 2279 | # I2C adapters. |
| | 2280 | $entry->{driver} = sysfs_device_driver("${class_dir}/i2c-$1/device") |
| | 2281 | || find_i2c_adapter_driver($entry->{name}) |
| | 2282 | || 'UNKNOWN'; |
| | 2283 | $i2c_adapters[$1] = $entry; |
| | 2284 | } |
| | 2285 | closedir(ADAPTERS); |