[LEDE-DEV] [PATCH 1/2] apm821xx: detect sd-card media changes for the WNDR4700
Christian Lamparter
chunkeey at googlemail.com
Wed Aug 31 08:43:28 PDT 2016
On Wednesday, August 31, 2016 10:13:52 AM CEST Karl Palsson wrote:
> Christian Lamparter <chunkeey at googlemail.com> wrote:
> > The insertion or removal of the sd-card cannot be detected by
> > the hardware itself. This is by design. To workaround this, for
> > the WNDR4700 unload/load the dwc2 module in case the the
> > special SD CARD GPIO line is low/high.
>
> You want to bounce _all_ usb devices when the SD card is
> inserted/removed? That sounds brutally intrusive!
No, The only device that is connected to the dwc2 host is the
GL827L Card Reader. The two (physical) USB ports on this router
are handled by a separate USB 3.0 Renesas uPD720202 chip. So, all
physical USB devices (like usb- sticks, cameras, ...) won't be
affected.
Here's a lsusb -t output. I've connected two usb memory sticks
to both ports of the WNDR4700:
/: Bus 03.Port 1: Dev 1, Class=root_hub, Driver=xhci_hcd/2p, 5000M
|__ Port 1: Dev 3, If 0, Class=Mass Storage, Driver=usb-storage, 5000M
/: Bus 02.Port 1: Dev 1, Class=root_hub, Driver=xhci_hcd/2p, 480M
|__ Port 2: Dev 4, If 0, Class=Mass Storage, Driver=usb-storage, 480M
/: Bus 01.Port 1: Dev 1, Class=root_hub, Driver=dwc2/1p, 480M
|__ Port 1: Dev 2, If 0, Class=Mass Storage, Driver=usb-storage, 480M
> I've posted before on the openwrt-devel list about the hard times, I've had
> with sd card detection before, also using a platform with a USB
> card reader attached.
> Unless you can figure out how to get the in
> kernel block detection working, (I could see it running scsi
> probes, and getting responses changing when I inserted/removed
> the SD card via usbmon, but couldn't it to reliably and stably
> generate useful events [1]) or you run a userspace daemon, much
> like udisks2 on gnome desktops, or something like
> https://github.com/arduino/linino/tree/master/trunk/package/linino/uSDaemon
>
> Even just the following works for detecting cards
> inserted/removed. (It's rather more intrusive cpu wise than it
> looks unfortunately, but at least it isn't bouncing the entire
> USB system!) while true; do
> block info > /dev/null
> sleep 1; done
That's not a good idea. As the WNDR4700 also has a 3.5" HDD bay for
a sata drive. So, having a loop polling "block info" will prevent
the HDD from spinning down.
> [1] I was working on 3.18, it's quite possible that the in kernel
> block detection now works properly. see
> /sys/block/sdXX/events_poll_msecs and try and hook events to
> that.
Thanks for the hint. I've set events_poll_msecs and verified that the
device is being polled constantly, but there are no media change events.
Regards,
Christian
PS.: What should be done about stale mounts? Because currently removing
the sd-card will cause all affected partitions to be automatically
unmounted as well. So, please keep this also in mind. Doing this in a
different fashion is not as easy as it might look on the first glance.
> >
> > Signed-off-by: Christian Lamparter <chunkeey at gmail.com>
> > ---
> > target/linux/apm821xx/base-files/etc/rc.button/BTN_1 | 19 +++++++++++++++++++
> > target/linux/apm821xx/dts/wndr4700.dts | 2 +-
> > 2 files changed, 20 insertions(+), 1 deletion(-)
> > create mode 100755 target/linux/apm821xx/base-files/etc/rc.button/BTN_1
> >
> > diff --git
> > a/target/linux/apm821xx/base-files/etc/rc.button/BTN_1
> > b/target/linux/apm821xx/base-files/etc/rc.button/BTN_1 new file
> > mode 100755 index 0000000..9956412
> > --- /dev/null
> > +++ b/target/linux/apm821xx/base-files/etc/rc.button/BTN_1
> > @@ -0,0 +1,19 @@
> > +#!/bin/sh
> > +
> > +. /lib/functions.sh
> > +. /lib/apm821xx.sh
> > +
> > +BOARD=$(apm821xx_board_name)
> > +
> > +if [ $BOARD == "wndr4700" ]; then
> > + case "$ACTION" in
> > + released)
> > + rmmod dwc2
> > + ;;
> > + pressed)
> > + modprobe dwc2
> > + ;;
> > + esac
> > +fi
> > +
> > +return 0
> > diff --git a/target/linux/apm821xx/dts/wndr4700.dts
> > b/target/linux/apm821xx/dts/wndr4700.dts index 9a2ceb9..caaf05b
> > 100644
> > --- a/target/linux/apm821xx/dts/wndr4700.dts
> > +++ b/target/linux/apm821xx/dts/wndr4700.dts
> > @@ -432,7 +432,7 @@
> >
> > sdcard {
> > label = "SDCard inserted";
> > - gpios = <&GPIO0 7 0>;
> > + gpios = <&GPIO0 7 1>;
> > linux,code = <0x101>; /* BTN_1 */
> > };
> > };
>
More information about the Lede-dev
mailing list