[U-Boot] [PATCH v4 4/8] mips: ath79: add serial driver for ar933x SOC

Thomas Chou
2015-12-27T08:31:17Z

Hi Wills,

On 2015?12?26? 21:20, Daniel Schwierzeck wrote:
>> +static int ar933x_serial_probe(struct udevice *dev)
>> +{
>> + struct ar933x_serial_priv *priv = dev_get_priv(dev);
>> + struct ar933x_serial_platdata *plat = dev_get_platdata(dev);
>> + u32 val;
>> +
>> + priv->regs = plat->regs;
>> +
>> + /*
>> + * UART controller configuration:
>> + * - no DMA
>> + * - no interrupt
>> + * - DCE mode
>> + * - no flow control
>> + * - set RX ready oride
>> + * - set TX ready oride
>> + */
>> + val = (AR933X_UART_CS_IF_MODE_DCE << AR933X_UART_CS_IF_MODE_S) |
>> + AR933X_UART_CS_TX_RDY_ORIDE | AR933X_UART_CS_RX_RDY_ORIDE;
>> + ar933x_serial_write(dev, val, AR933X_UART_CS_REG);
>> + return 0;
>> +}
>> +
>> +static int ar933x_serial_ofdata_to_platdata(struct udevice *dev)
>> +{
>> + struct ar933x_serial_platdata *plat = dev_get_platdata(dev);
>> + fdt_addr_t addr;
>> +
>> + addr = dev_get_addr(dev);
>> + if (addr == FDT_ADDR_T_NONE)
>> + return -EINVAL;
>> +
>> + plat->regs = map_physmem(addr,
>> + AR933X_UART_SIZE,
>> + MAP_NOCACHE);
>
> move this code to function ar933x_serial_probe and drop this function
>
>> + return 0;
>> +}
>> +
>> +static const struct dm_serial_ops ar933x_serial_ops = {
>> + .putc = ar933x_serial_putc,
>> + .pending = ar933x_serial_pending,
>> + .getc = ar933x_serial_getc,
>> + .setbrg = ar933x_serial_setbrg,
>> +};
>> +
>> +static const struct udevice_id ar933x_serial_ids[] = {
>> + { .compatible = "ath79,ar933x-uart" },
>> + { }
>> +};
>> +
>> +U_BOOT_DRIVER(serial_ar933x) = {
>> + .name = "serial_ar933x",
>> + .id = UCLASS_SERIAL,
>> + .of_match = ar933x_serial_ids,
>> + .ofdata_to_platdata = ar933x_serial_ofdata_to_platdata,
>> + .platdata_auto_alloc_size = sizeof(struct ar933x_serial_platdata),
>
> drop the two lines, you do not need to allocate platdata
>

It might be another option to keep platdata and ofdata_to_platdata(),
and remove the priv data. Let ofdata_to_platdata() do the DT conversion
and probe() detect and initialize the hardware. This is what these func
expected to do. The priv data is needed only when there is variable data
to save per device.

Best regards,
Thomas