From owner-svn-src-head@FreeBSD.ORG Wed Jun 26 04:58:26 2013 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by hub.freebsd.org (Postfix) with ESMTP id 65B2811E; Wed, 26 Jun 2013 04:58:26 +0000 (UTC) (envelope-from adrian@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) by mx1.freebsd.org (Postfix) with ESMTP id 579A21DCD; Wed, 26 Jun 2013 04:58:26 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.7/8.14.7) with ESMTP id r5Q4wQCu090252; Wed, 26 Jun 2013 04:58:26 GMT (envelope-from adrian@svn.freebsd.org) Received: (from adrian@localhost) by svn.freebsd.org (8.14.7/8.14.5/Submit) id r5Q4wQhW090251; Wed, 26 Jun 2013 04:58:26 GMT (envelope-from adrian@svn.freebsd.org) Message-Id: <201306260458.r5Q4wQhW090251@svn.freebsd.org> From: Adrian Chadd Date: Wed, 26 Jun 2013 04:58:26 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r252239 - head/sys/dev/ath X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 26 Jun 2013 04:58:26 -0000 Author: adrian Date: Wed Jun 26 04:58:25 2013 New Revision: 252239 URL: http://svnweb.freebsd.org/changeset/base/252239 Log: Extend the AHB code to work on chips besides the AR9130. The AHB code: * hard coded the AR9130 device id; * assumes a 4k flash calibration space. This code now extends this: * hint.ath.X.eepromsize now overrides the eeprom range, instead of 4k * hint.ath.X.device_id and hint.ath.X.vendor_id can now be overridden. Tested: * AR9330 board (Carambola 2) Modified: head/sys/dev/ath/if_ath_ahb.c Modified: head/sys/dev/ath/if_ath_ahb.c ============================================================================== --- head/sys/dev/ath/if_ath_ahb.c Wed Jun 26 04:53:33 2013 (r252238) +++ head/sys/dev/ath/if_ath_ahb.c Wed Jun 26 04:58:25 2013 (r252239) @@ -85,10 +85,28 @@ struct ath_ahb_softc { static int ath_ahb_probe(device_t dev) { + int vendor_id, device_id; const char* devname; - /* Atheros / ar9130 */ - devname = ath_hal_probe(VENDOR_ATHEROS, AR9130_DEVID); + /* + * Check if a device/vendor ID is provided in hints. + */ + if (resource_int_value(device_get_name(dev), device_get_unit(dev), + "vendor_id", &vendor_id) != 0) { + vendor_id = VENDOR_ATHEROS; + } + + if (resource_int_value(device_get_name(dev), device_get_unit(dev), + "device_id", &device_id) != 0) { + device_id = AR9130_DEVID; + } + + device_printf(dev, "Vendor=0x%04x, Device=0x%04x\n", + vendor_id & 0xffff, + device_id & 0xffff); + + /* Attempt to probe */ + devname = ath_hal_probe(vendor_id, device_id); if (devname != NULL) { device_set_desc(dev, devname); @@ -105,7 +123,9 @@ ath_ahb_attach(device_t dev) int error = ENXIO; int rid; long eepromaddr; + int eepromsize; uint8_t *p; + int device_id, vendor_id; sc->sc_dev = dev; @@ -116,15 +136,27 @@ ath_ahb_attach(device_t dev) goto bad; } - if (resource_long_value(device_get_name(dev), device_get_unit(dev), - "eepromaddr", &eepromaddr) != 0) { + if (resource_long_value(device_get_name(dev), device_get_unit(dev), + "eepromaddr", &eepromaddr) != 0) { device_printf(dev, "cannot fetch 'eepromaddr' from hints\n"); goto bad0; - } + } + + /* + * The default EEPROM size is 2048 * 16 bit words. + * Later EEPROM/OTP/flash regions may be quite a bit bigger. + */ + if (resource_int_value(device_get_name(dev), device_get_unit(dev), + "eepromsize", &eepromsize) != 0) { + eepromsize = ATH_EEPROM_DATA_SIZE * 2; + } + + rid = 0; - device_printf(sc->sc_dev, "eeprom @ %p\n", (void *) eepromaddr); + device_printf(sc->sc_dev, "eeprom @ %p (%d bytes)\n", + (void *) eepromaddr, eepromsize); psc->sc_eeprom = bus_alloc_resource(dev, SYS_RES_MEMORY, &rid, (uintptr_t) eepromaddr, - (uintptr_t) eepromaddr + (uintptr_t) ((ATH_EEPROM_DATA_SIZE * 2) - 1), 0, RF_ACTIVE); + (uintptr_t) eepromaddr + (uintptr_t) (eepromsize - 1), 0, RF_ACTIVE); if (psc->sc_eeprom == NULL) { device_printf(dev, "cannot map eeprom space\n"); goto bad0; @@ -140,7 +172,7 @@ ath_ahb_attach(device_t dev) sc->sc_invalid = 1; /* Copy the EEPROM data out */ - sc->sc_eepromdata = malloc(ATH_EEPROM_DATA_SIZE * 2, M_TEMP, M_NOWAIT | M_ZERO); + sc->sc_eepromdata = malloc(eepromsize, M_TEMP, M_NOWAIT | M_ZERO); if (sc->sc_eepromdata == NULL) { device_printf(dev, "cannot allocate memory for eeprom data\n"); goto bad1; @@ -151,10 +183,10 @@ ath_ahb_attach(device_t dev) bus_space_read_multi_1( rman_get_bustag(psc->sc_eeprom), rman_get_bushandle(psc->sc_eeprom), - 0, (u_int8_t *) sc->sc_eepromdata, ATH_EEPROM_DATA_SIZE * 2); + 0, (u_int8_t *) sc->sc_eepromdata, eepromsize); #endif p = (void *) rman_get_bushandle(psc->sc_eeprom); - memcpy(sc->sc_eepromdata, p, ATH_EEPROM_DATA_SIZE * 2); + memcpy(sc->sc_eepromdata, p, eepromsize); /* * Arrange interrupt line. @@ -191,6 +223,19 @@ ath_ahb_attach(device_t dev) goto bad3; } + /* + * Check if a device/vendor ID is provided in hints. + */ + if (resource_int_value(device_get_name(dev), device_get_unit(dev), + "vendor_id", &vendor_id) != 0) { + vendor_id = VENDOR_ATHEROS; + } + + if (resource_int_value(device_get_name(dev), device_get_unit(dev), + "device_id", &device_id) != 0) { + device_id = AR9130_DEVID; + } + ATH_LOCK_INIT(sc); ATH_PCU_LOCK_INIT(sc); ATH_RX_LOCK_INIT(sc); @@ -198,7 +243,7 @@ ath_ahb_attach(device_t dev) ATH_TX_IC_LOCK_INIT(sc); ATH_TXSTATUS_LOCK_INIT(sc); - error = ath_attach(AR9130_DEVID, sc); + error = ath_attach(device_id, sc); if (error == 0) /* success */ return 0;