Re: [NEW] ugold(4) driver for Microdia's USB TEMPer variant (take 2)

2013-05-27 Thread Benoit Lecocq
On 05/12/13 20:41, SASANO Takayoshi wrote:
 Hello,
 
 Here is the driver for Microdia's USB TEMPer with some fixes.
 
 http://www.uaa.org.uk/gomitext/2013/20130513/20130513.diff
 
 - removed intermediate buffer (sc_ibuf), all USB interrupt responses
   will be processed in ugold_intr().
 - use uhidev_set_report() to issue HID command.
 - add ugold* at uhidev? into GENERIC for alpha, amd64, armish, hppa, i386,
   landisk, loongson, macppc, sgi (IP27, IP30, IP32), socppc and sparc64.
 
 Regards,
 
 SASANO Takayoshi u...@mx5.nisiq.net
 

Hi,

I have tried it on amd64 and it works fine :

uhidev4 at uhub3 port 1 configuration 1 interface 0 RDing TEMPerV1.4
rev 2.00/0.01 addr 3
uhidev4: iclass 3/1, 1 report id
ugold0 at uhidev4 reportid 1
uhidev5 at uhub3 port 1 configuration 1 interface 1 RDing TEMPerV1.4
rev 2.00/0.01 addr 3
uhidev5: iclass 3/1
ugold1 at uhidev5
ugold1: type ds75/12bit (temperature)


# sysctl hw.sensors.ugold1
hw.sensors.ugold1.temp0=23.37 degC (inner)

Cheers,
benoit




mg(1) dired buffer refresh

2013-05-27 Thread Mark Lumsden
In mg dired mode, if you execute these commands:

dired-copy-file
dired-rename-file
dired-create-directory

The dired buffer is not refreshed with the updated action. This diff
fixes that. Comments/oks?

-lum

Index: dired.c
===
RCS file: /cvs/src/usr.bin/mg/dired.c,v
retrieving revision 1.52
diff -u -p -r1.52 dired.c
--- dired.c 3 Nov 2012 15:36:03 -   1.52
+++ dired.c 27 May 2013 13:35:09 -
@@ -44,6 +44,7 @@ static int d_backpage(int, int);
 static int  d_forwline(int, int);
 static int  d_backline(int, int);
 static void reaper(int);
+static struct buffer   *refreshbuffer(struct buffer *);
 
 extern struct keymap_s helpmap, cXmap, metamap;
 
@@ -422,7 +423,8 @@ d_copy(int f, int n)
ret = (copy(frname, toname) = 0) ? TRUE : FALSE;
if (ret != TRUE)
return (ret);
-   bp = dired_(curbp-b_fname);
+   if ((bp = refreshbuffer(curbp)) == NULL)
+   return (FALSE);
return (showbuffer(bp, curwp, WFFULL | WFMODE));
 }
 
@@ -455,7 +457,8 @@ d_rename(int f, int n)
ret = (rename(frname, toname) = 0) ? TRUE : FALSE;
if (ret != TRUE)
return (ret);
-   bp = dired_(curbp-b_fname);
+   if ((bp = refreshbuffer(curbp)) == NULL)
+   return (FALSE);
return (showbuffer(bp, curwp, WFFULL | WFMODE));
 }
 
@@ -638,8 +641,28 @@ d_create_directory(int f, int n)
tocreate);
return (FALSE);
}
-   bp = dired_(curbp-b_fname);
+   if ((bp = refreshbuffer(curbp)) == NULL)
+   return (FALSE);
return (showbuffer(bp, curwp, WFFULL | WFMODE));
+}
+
+struct buffer *
+refreshbuffer(struct buffer *bp)
+{
+   char*tmp;
+
+   tmp = strdup(bp-b_fname);
+   killbuffer(bp);
+
+   /* dired_() uses findbuffer() to create new buffer */
+   if ((bp = dired_(tmp)) == NULL) {
+   free(tmp);
+   return (NULL);
+   }
+   free(tmp);
+   curbp = bp;
+
+   return (bp);
 }
 
 static int



mg(1) dired buffer refresh

2013-05-27 Thread Mark Lumsden
In mg dired mode, if you execute these commands:

dired-copy-file
dired-rename-file
dired-create-directory

The dired buffer is not refreshed with the updated action. This diff
fixes that. Comments/oks?

-lum

Index: dired.c
===
RCS file: /cvs/src/usr.bin/mg/dired.c,v
retrieving revision 1.52
diff -u -p -r1.52 dired.c
--- dired.c 3 Nov 2012 15:36:03 -   1.52
+++ dired.c 27 May 2013 13:35:09 -
@@ -44,6 +44,7 @@ static int d_backpage(int, int);
 static int  d_forwline(int, int);
 static int  d_backline(int, int);
 static void reaper(int);
+static struct buffer   *refreshbuffer(struct buffer *);
 
 extern struct keymap_s helpmap, cXmap, metamap;
 
@@ -422,7 +423,8 @@ d_copy(int f, int n)
ret = (copy(frname, toname) = 0) ? TRUE : FALSE;
if (ret != TRUE)
return (ret);
-   bp = dired_(curbp-b_fname);
+   if ((bp = refreshbuffer(curbp)) == NULL)
+   return (FALSE);
return (showbuffer(bp, curwp, WFFULL | WFMODE));
 }
 
@@ -455,7 +457,8 @@ d_rename(int f, int n)
ret = (rename(frname, toname) = 0) ? TRUE : FALSE;
if (ret != TRUE)
return (ret);
-   bp = dired_(curbp-b_fname);
+   if ((bp = refreshbuffer(curbp)) == NULL)
+   return (FALSE);
return (showbuffer(bp, curwp, WFFULL | WFMODE));
 }
 
@@ -638,8 +641,28 @@ d_create_directory(int f, int n)
tocreate);
return (FALSE);
}
-   bp = dired_(curbp-b_fname);
+   if ((bp = refreshbuffer(curbp)) == NULL)
+   return (FALSE);
return (showbuffer(bp, curwp, WFFULL | WFMODE));
+}
+
+struct buffer *
+refreshbuffer(struct buffer *bp)
+{
+   char*tmp;
+
+   tmp = strdup(bp-b_fname);
+   killbuffer(bp);
+
+   /* dired_() uses findbuffer() to create new buffer */
+   if ((bp = dired_(tmp)) == NULL) {
+   free(tmp);
+   return (NULL);
+   }
+   free(tmp);
+   curbp = bp;
+
+   return (bp);
 }
 
 static int



mg(1) dired-create-directory

2013-05-27 Thread Mark Lumsden
dired-create-directory is missing from the function maps.

ok?

-lum

Index: dired.c
===
RCS file: /cvs/src/usr.bin/mg/dired.c,v
retrieving revision 1.52
diff -u -p -r1.52 dired.c
--- dired.c 3 Nov 2012 15:36:03 -   1.52
+++ dired.c 27 May 2013 13:48:01 -
@@ -182,6 +182,7 @@ dired_init(void)
 {
funmap_add(dired, dired);
funmap_add(d_undelbak, dired-backup-unflag);
+   funmap_add(d_create_directory, dired-create-directory);
funmap_add(d_copy, dired-copy-file);
funmap_add(d_expunge, dired-do-deletions);
funmap_add(d_findfile, dired-find-file);



bge: don't use autopoll on anything above BCM5705

2013-05-27 Thread Mike Belopuhov
Hi,

While trying to fix the link state bug on BCM5719, David Imhoff
has arrived at conclusion that the chip won't generate proper
link state interrupts which renders auto-polling mode useless.

As it turns out neither Linux nor FreeBSD use auto-polling mode
for anything newer than BCM5705 and recent Broadcom documentation
is not describing this method at all.

This diff brings us in line with others, but requires heavy
testing on currently supported hardware.

OK's are welcome as well.

diff --git sys/dev/pci/if_bge.c sys/dev/pci/if_bge.c
index 1d37192..8007108 100644
--- sys/dev/pci/if_bge.c
+++ sys/dev/pci/if_bge.c
@@ -1055,10 +1055,22 @@ bge_miibus_statchg(struct device *dev)
(mii-mii_media_active  IFM_ETH_FMASK) != sc-bge_flowflags) {
sc-bge_flowflags = mii-mii_media_active  IFM_ETH_FMASK;
mii-mii_media_active = ~IFM_ETH_FMASK;
}
 
+   if (!BGE_STS_BIT(sc, BGE_STS_LINK) 
+   mii-mii_media_status  IFM_ACTIVE 
+   IFM_SUBTYPE(mii-mii_media_active) != IFM_NONE)
+   BGE_STS_SETBIT(sc, BGE_STS_LINK);
+   else if (BGE_STS_BIT(sc, BGE_STS_LINK) 
+   (!(mii-mii_media_status  IFM_ACTIVE) ||
+   IFM_SUBTYPE(mii-mii_media_active) == IFM_NONE))
+   BGE_STS_CLRBIT(sc, BGE_STS_LINK);
+
+   if (!BGE_STS_BIT(sc, BGE_STS_LINK))
+   return;
+
/* Set the port mode (MII/GMII) to match the link speed. */
mac_mode = CSR_READ_4(sc, BGE_MAC_MODE) 
~(BGE_MACMODE_PORTMODE | BGE_MACMODE_HALF_DUPLEX);
tx_mode = CSR_READ_4(sc, BGE_TX_MODE);
rx_mode = CSR_READ_4(sc, BGE_RX_MODE);
@@ -1773,11 +1785,11 @@ int
 bge_blockinit(struct bge_softc *sc)
 {
volatile struct bge_rcb *rcb;
vaddr_t rcb_addr;
bge_hostaddrtaddr;
-   u_int32_t   dmactl, val;
+   u_int32_t   dmactl, mimode, val;
int i, limit;
 
/*
 * Initialize the memory window pointer register so that
 * we can access the first 32K of internal NIC RAM. This will
@@ -2369,13 +2381,23 @@ bge_blockinit(struct bge_softc *sc)
 
/* Enable PHY auto polling (for MII/GMII only) */
if (sc-bge_flags  BGE_PHY_FIBER_TBI) {
CSR_WRITE_4(sc, BGE_MI_STS, BGE_MISTS_LINK);
} else {
-   BGE_STS_SETBIT(sc, BGE_STS_AUTOPOLL);
-   BGE_SETBIT(sc, BGE_MI_MODE, BGE_MIMODE_AUTOPOLL|1016);
-   if (BGE_ASICREV(sc-bge_chipid) == BGE_ASICREV_BCM5700)
+   if ((sc-bge_flags  BGE_CPMU_PRESENT) != 0)
+   mimode = BGE_MIMODE_500KHZ_CONST;
+   else
+   mimode = BGE_MIMODE_BASE;
+   if (BGE_IS_5700_FAMILY(sc) ||
+   BGE_ASICREV(sc-bge_chipid) == BGE_ASICREV_BCM5705) {
+   mimode |= BGE_MIMODE_AUTOPOLL;
+   BGE_STS_SETBIT(sc, BGE_STS_AUTOPOLL);
+   }
+   mimode |= BGE_MIMODE_PHYADDR(sc-bge_phy_addr);
+   CSR_WRITE_4(sc, BGE_MI_MODE, mimode);
+   if (BGE_ASICREV(sc-bge_chipid) == BGE_ASICREV_BCM5700 
+   sc-bge_chipid != BGE_CHIPID_BCM5700_B2)
CSR_WRITE_4(sc, BGE_MAC_EVT_ENB,
BGE_EVTENB_MI_INTERRUPT);
}
 
/*
@@ -2719,13 +2741,10 @@ bge_attach(struct device *parent, struct device *self, 
void *aux)
BGE_ASICREV(sc-bge_chipid) == BGE_ASICREV_BCM5761 ||
BGE_ASICREV(sc-bge_chipid) == BGE_ASICREV_BCM5785 ||
BGE_ASICREV(sc-bge_chipid) == BGE_ASICREV_BCM57780)
sc-bge_flags |= BGE_CPMU_PRESENT;
 
-   if ((sc-bge_flags  BGE_CPMU_PRESENT) != 0)
-   BGE_SETBIT(sc, BGE_MI_MODE, BGE_MIMODE_500KHZ_CONST);
-
/* Try to reset the chip. */
DPRINTFN(5, (bge_reset\n));
bge_sig_pre_reset(sc, BGE_RESET_START);
bge_reset(sc);
 
@@ -4489,15 +4508,10 @@ bge_link_upd(struct bge_softc *sc)
BGE_STS_CLRBIT(sc, BGE_STS_LINK);
ifp-if_link_state = LINK_STATE_DOWN;
if_link_state_change(ifp);
ifp-if_baudrate = 0;
}
-   /*
-* Discard link events for MII/GMII cards if MI auto-polling disabled.
-* This should not happen since mii callouts are locked now, but
-* we keep this check for debug.
-*/
} else if (BGE_STS_BIT(sc, BGE_STS_AUTOPOLL)) {
/*
 * Some broken BCM chips have BGE_STATFLAG_LINKSTATE_CHANGED bit
 * in status word always set. Workaround this bug by reading
 * PHY link status directly.
@@ -4515,10 +4529,17 @@ bge_link_upd(struct bge_softc *sc)
else if (BGE_STS_BIT(sc, BGE_STS_LINK) 
(!(mii-mii_media_status  IFM_ACTIVE) ||

mg.1 dired commands

2013-05-27 Thread Mark Lumsden
I realised the dired commands are not in the mg man page. ok?

-lum

Index: mg.1
===
RCS file: /cvs/src/usr.bin/mg/mg.1,v
retrieving revision 1.76
diff -u -p -r1.76 mg.1
--- mg.122 May 2013 19:23:45 -  1.76
+++ mg.127 May 2013 19:10:45 -
@@ -919,6 +919,43 @@ Unlike emacs, the
 kill buffer consists only
 of the most recent kill.
 It is not a ring.
+.Sh MG DIRED COMMANDS
+Following are a list of the commands specific to dired mode:
+.It dired-backup-unflag
+This function removes the deletion flag from the file listed on
+the current line of the dired buffer, then moves up one line.
+.It dired-create-directory
+Creates a directory.
+.It dired-copy-file
+Copy the file listed on the current line of the dired buffer.
+.It dired-do-deletions
+Deletes the files that have been flagged for deletion.
+.It dired-find-file
+Opens the file in the current line of the dired buffer.
+If the cursor is on a directory it will be opened in dired mode. 
+.It dired-find-file-other-window
+Opens the file on the current line of the dired buffer in a
+different window.
+.It dired-flag-file-deleted
+Flag the file listed on the current line for deletion.
+This is indicated in the buffer by putting a D at the left margin.
+No files are actually deleted until the function dired-do-deletions
+is executed.
+.It dired-next-line
+Moves the cursor to the next line.
+.It dired-other-window
+This function works just like dired, except that it puts the
+dired buffer in the other window.
+.It dired-previous-line
+Move the cursor to the previous line.
+.It dired-rename-file
+Renames the file listed on the current line of the dired buffer.
+.It dired-scroll-down
+Scroll down the dired buffer.
+.It dired-scroll-up
+Scroll up the dired buffer.
+.It dired-unflag
+Remove the deletion flag for the file on the current line.
 .El
 .Sh CONFIGURATION FILES
 There are two configuration files,



Re: brgphy: reset autonegotiation timer when we get the link

2013-05-27 Thread Mark Kettenis
 Date: Wed, 22 May 2013 18:32:57 +0200
 From: Mike Belopuhov m...@belopuhov.com
 
 On Wed, May 22, 2013 at 18:08 +0200, Mark Kettenis wrote:
   Date: Wed, 22 May 2013 17:59:19 +0200
   From: Mike Belopuhov m...@belopuhov.com
   
   On Tue, May 21, 2013 at 17:16 +0200, Mike Belopuhov wrote:
from freebsd. ok?

   
   ping!
  
  There are more drivers in the tree that do the same thing.  And then
  there lots that have the same bug.  Would be nice if we could fix
  those as well.  Anyway,
  
  ok kettenis@
  
 
 fair enough.  it looks like rgephy needs to proceed to mii_phy_status
 and mii_phy_update, but returns instead.  i'd like it to get tested.

Looks ok to me.  Don't have the hardware to test right now.

 diff --git sys/dev/mii/brgphy.c sys/dev/mii/brgphy.c
 index 7f0bae2..461c798 100644
 --- sys/dev/mii/brgphy.c
 +++ sys/dev/mii/brgphy.c
 @@ -412,8 +412,10 @@ setit:
* the BMSR twice in case it's latched.
*/
   reg = PHY_READ(sc, MII_BMSR) | PHY_READ(sc, MII_BMSR);
 - if (reg  BMSR_LINK)
 + if (reg  BMSR_LINK) {
 + sc-mii_ticks = 0;  /* Reset autoneg timer. */
   break;
 + }
  
   /*
* Only retry autonegotiation every mii_anegticks seconds.
 diff --git sys/dev/mii/dcphy.c sys/dev/mii/dcphy.c
 index d1ad0b4..841fe3f 100644
 --- sys/dev/mii/dcphy.c
 +++ sys/dev/mii/dcphy.c
 @@ -272,8 +272,10 @@ dcphy_service(struct mii_softc *sc, struct mii_data 
 *mii, int cmd)
   break;
  
   reg = CSR_READ_4(dc_sc, DC_10BTSTAT);
 - if (!(reg  DC_TSTAT_LS10) || !(reg  DC_TSTAT_LS100))
 + if (!(reg  DC_TSTAT_LS10) || !(reg  DC_TSTAT_LS100)) {
 + sc-mii_ticks = 0;
   break;
 + }
  
   /*
* Only retry autonegotiation every mii_anegticks seconds.
 diff --git sys/dev/mii/mlphy.c sys/dev/mii/mlphy.c
 index 56858b5..fb5784b 100644
 --- sys/dev/mii/mlphy.c
 +++ sys/dev/mii/mlphy.c
 @@ -306,6 +306,7 @@ mlphy_service(struct mii_softc *sc, struct mii_data *mii, 
 int cmd)
   msc-ml_linked = 1;
   mlphy_status(sc);
   }
 + sc-mii_ticks = 0;
   break;
   }
   /*
 diff --git sys/dev/mii/rgephy.c sys/dev/mii/rgephy.c
 index 2c1ddbb..5fe9dc6 100644
 --- sys/dev/mii/rgephy.c
 +++ sys/dev/mii/rgephy.c
 @@ -251,12 +251,16 @@ setit:
*/
   if (sc-mii_rev  2) {
   reg = PHY_READ(sc, RL_GMEDIASTAT);
 - if (reg  RL_GMEDIASTAT_LINK)
 + if (reg  RL_GMEDIASTAT_LINK) {
 + sc-mii_ticks = 0;
   break;
 + }
   } else {
   reg = PHY_READ(sc, RGEPHY_SR);
 - if (reg  RGEPHY_SR_LINK)
 + if (reg  RGEPHY_SR_LINK) {
 + sc-mii_ticks = 0;
   break;
 + }
   }
  
   /*
 @@ -267,7 +271,7 @@ setit:
   
   sc-mii_ticks = 0;
   rgephy_mii_phy_auto(sc);
 - return (0);
 + break;
   }
  
   /* Update the media status. */
 diff --git sys/dev/mii/urlphy.c sys/dev/mii/urlphy.c
 index 09df2bd..2e3b475 100644
 --- sys/dev/mii/urlphy.c
 +++ sys/dev/mii/urlphy.c
 @@ -186,8 +186,10 @@ urlphy_service(struct mii_softc *sc, struct mii_data 
 *mii, int cmd)
  
   /* Read the status register twice; MSR_LINK is latch-low. */
   reg = PHY_READ(sc, URLPHY_MSR) | PHY_READ(sc, URLPHY_MSR);
 - if (reg  URLPHY_MSR_LINK)
 - return (0);
 + if (reg  URLPHY_MSR_LINK) {
 + sc-mii_ticks = 0;
 + break;
 + }
  
   /*
* Only retry autonegotiation every mii_anegticks seconds.
 diff --git sys/dev/mii/xmphy.c sys/dev/mii/xmphy.c
 index 1d3e2ea..e7687e6 100644
 --- sys/dev/mii/xmphy.c
 +++ sys/dev/mii/xmphy.c
 @@ -212,8 +212,10 @@ xmphy_service(struct mii_softc *sc, struct mii_data 
 *mii, int cmd)
   * the BMSR twice in case it's latched.
   */
   reg = PHY_READ(sc, MII_BMSR) | PHY_READ(sc, MII_BMSR);
 - if (reg  BMSR_LINK)
 + if (reg  BMSR_LINK) {
 + sc-mii_ticks = 0;
   break;
 + }
  
   /*
* Only retry autonegotiation every mii_anegticks seconds.
 diff --git sys/dev/sbus/be.c sys/dev/sbus/be.c
 index 1527ff0..7dc459d 100644
 --- sys/dev/sbus/be.c
 +++ sys/dev/sbus/be.c
 @@ -1531,6 +1531,7 @@ be_intphy_service(struct be_softc *sc, struct mii_data 
 *mii, int cmd)