# -*- shell-script -*-

# 05adapter_pcichiprev - Get PCI chip revision.

# This file is part of the Linux lsvpd package.

# (C) Copyright IBM Corp. 2004

# Maintained by Martin Schwenke <martins@au.ibm.com>

# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.
 
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
 
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
    
# $Id: 45adapter_pci_chiprev,v 1.4 2004/11/18 23:13:06 martins Exp $

# Don't do this on IBM pSeries.
[ "$device_tree_device_type" = "chrp" ] && return 0

dd_program=$(type -p dd)
[ -n "$dd_program" ] || return 0

######################################################################

adapter_extra_vpd_hooks="${adapter_extra_vpd_hooks} pci_chiprev_extra_vpd_hook"

pci_chiprev_extra_vpd_hook ()
{
    local type="$1"
    local bus_info="$2"
    local adapter_bus_dir="$3"
    local vpd_dir="$4"

    case "$bus_info" in
	pci/*)
	    local bus_addr="${bus_info#*/}"
	    local cf=$(pci_get_config_filename "${bus_addr%/*}")
	    if [ -r "$cf" ] ; then
		local yc=$($dd_program \
		    if="$cf" skip=8 bs=1 count=1 2>/dev/null | \
		    tdump)

		[ -n "$yc" ] && \
		    vpd_field_ensure "$vpd_dir" "YC" $(hex2dec "$yc")
	    fi
	    ;;
    esac
}
