>
> On 21 Jun 2016, at 1:28 PM, Artturi Alm <[email protected]> wrote:
>
> Hi,
>
> i'm unsure about the accepted way of working around irregular registers,
> like would be needed with supporting Mentor OTG USB on both omap&sunxi
> on armv7. irregular as in _no_ correlation what so ever, so off*4 kind
> of solution does not apply.
> My question in particular is; is (ab)using bus_space for this accepted
> workaround?
>
> NetBSD, where the driver got ported from, does have #ifdef MOTG_ALLWINNER
> which is obviously not possible, given GENERIC and its nature as true
> 'uni-mono-kernel'. i was actually a bit shocked when i figured how many
> arm kernel configs etc. they get to have maintenance-fun with if/when
> necessary :)
>
> reason why i think this is better than any other method to solve it in
> run-time rather than compile-time is, because it wouldn't affect other
> than the offender(=sunxi/Allwinner), no matter how ugly.
>
> shortened(actually +30cases in switch below) to show something like
> what i would propose:
id go with a map of the registers inside the driver. something like
struct musb2_registers {
bus_size_t reg_faddr;
bus_size_t reg_power;
bus_size_t reg_devctl;
...
};
and then
static const struct musb2_registers aw_musb2_registers = {
MUSB2_REG_FADDR_AW,
MUSB2_REG_POWER_AW,
MUSB2_REG_DEVCTL_AW,
...
};
static const struct musb2_registers sx_musb2_registers = {
MUSB2_REG_FADDR_SX,
MUSB2_REG_POWER_SX,
MUSB2_REG_DEVCTL_SX,
...
};
using this could be something like this:
struct musb2_softc {
struct device sc_dev;
const struct musb2_registers *sc_reg;
...
}
#define musb2_rd4(_sc, _r) bus_space_read_4((_sc)->sc_tag, (_sc)->sc_handle,
(_sc)->sc_reg->(_r))
attach would pick between the right instance of musb2_registers, and then the
rest of the driver would be:
reg = musb2_read(sc, reg_faddr);
or something.