[PATCH v7 13/15] MIPS: add initial D-Link DIR-320 wireless router support

Antony Pavlov antonynpavlov at gmail.com
Wed Jul 20 10:03:07 EDT 2011


On 20 July 2011 08:11, Jean-Christophe PLAGNIOL-VILLARD
<plagnioj at jcrosoft.com> wrote:
>> diff --git a/arch/mips/boards/dlink-dir-320/serial.c b/arch/mips/boards/dlink-dir-320/serial.c
>> new file mode 100644
>> index 0000000..6e878cd
>> --- /dev/null
>> +++ b/arch/mips/boards/dlink-dir-320/serial.c
...

>> +/** to work with the 8250 UART driver implementation we need this function */
>> +static unsigned int dir320_uart_read(unsigned long base, unsigned char reg_idx)
>> +{
>> +     return __raw_readb((char *)base + reg_idx);
>> +}
>> +
>> +/** to work with the 8250 UART driver implementation we need this function */
>> +static void dir320_uart_write(unsigned int val, unsigned long base, unsigned char reg_idx)
>> +{
>> +     __raw_writeb(val, (char *)base + reg_idx);
>> +}
> can we drop those duplicated function with malta and other

I think, that it is much better to improve ns16550 driver.

e.g.
   reg_write(val, base, reg_idx) -> reg_write(struct device_d *dev,
val, reg_idx)

there

struct device_d {
   ...
   .map_base = ... ; /* FIXME: use resource */

}

struct NS16550_plat {
   ...
   unsigned int (*reg_read)(struct device_d *dev, reg_idx);
   void (*reg_write)(struct device_d *dev, val, reg_idx);
   ...
   unsigned int regshift;
   unsigned int offset;
   ...
};

generic_ns16550_write works like this:

generic_ns16550_write(struct device_d *dev, val, reg_idx)
{
  struct NS16550_plat * plat = dev->platform_data;

  writeb(val, dev->map_base + (reg_idx << plat->regshift) + plat->offset);
}

so platform-depended initialization set plat->base, plat->regshift and
plat->offset;
also most times it set plat->reg_write=generic_ns16550_write and
plat->reg_read=generic_ns16550_read.

-- 
Best regards,
  Antony Pavlov



More information about the barebox mailing list