Commit ba3c22bf186db550435a46dafc777b8cfae6fe30
1 parent
c8602061a7
spi: davinci: Add platdata support
Davanci spi driver has DM support already, this patch add support for platdata so-that SPL can use it for low foot-print. Signed-off-by: Jagan Teki <jagan@amarulasolutions.com> Tested-by: Adam Ford <aford173@gmail.com>
Showing 2 changed files with 43 additions and 19 deletions Side-by-side Diff
drivers/spi/davinci_spi.c
... | ... | @@ -14,6 +14,7 @@ |
14 | 14 | #include <asm/io.h> |
15 | 15 | #include <asm/arch/hardware.h> |
16 | 16 | #include <dm.h> |
17 | +#include <dm/platform_data/spi_davinci.h> | |
17 | 18 | |
18 | 19 | /* SPIGCR0 */ |
19 | 20 | #define SPIGCR0_SPIENA_MASK 0x1 |
20 | 21 | |
21 | 22 | |
22 | 23 | |
23 | 24 | |
24 | 25 | |
25 | 26 | |
26 | 27 | |
27 | 28 | |
28 | 29 | |
29 | 30 | |
30 | 31 | |
31 | 32 | |
... | ... | @@ -529,51 +530,59 @@ |
529 | 530 | return __davinci_spi_xfer(ds, bitlen, dout, din, flags); |
530 | 531 | } |
531 | 532 | |
533 | +static const struct dm_spi_ops davinci_spi_ops = { | |
534 | + .claim_bus = davinci_spi_claim_bus, | |
535 | + .release_bus = davinci_spi_release_bus, | |
536 | + .xfer = davinci_spi_xfer, | |
537 | + .set_speed = davinci_spi_set_speed, | |
538 | + .set_mode = davinci_spi_set_mode, | |
539 | +}; | |
540 | + | |
532 | 541 | static int davinci_spi_probe(struct udevice *bus) |
533 | 542 | { |
534 | - /* Nothing to do */ | |
543 | + struct davinci_spi_slave *ds = dev_get_priv(bus); | |
544 | + struct davinci_spi_platdata *plat = bus->platdata; | |
545 | + ds->regs = plat->regs; | |
546 | + ds->num_cs = plat->num_cs; | |
547 | + | |
535 | 548 | return 0; |
536 | 549 | } |
537 | 550 | |
551 | +#if CONFIG_IS_ENABLED(OF_CONTROL) && !CONFIG_IS_ENABLED(OF_PLATDATA) | |
538 | 552 | static int davinci_ofdata_to_platadata(struct udevice *bus) |
539 | 553 | { |
540 | - struct davinci_spi_slave *ds = dev_get_priv(bus); | |
541 | - const void *blob = gd->fdt_blob; | |
542 | - int node = dev_of_offset(bus); | |
554 | + struct davinci_spi_platdata *plat = bus->platdata; | |
555 | + fdt_addr_t addr; | |
543 | 556 | |
544 | - ds->regs = devfdt_map_physmem(bus, sizeof(struct davinci_spi_regs)); | |
545 | - if (!ds->regs) { | |
546 | - printf("%s: could not map device address\n", __func__); | |
557 | + addr = devfdt_get_addr(bus); | |
558 | + if (addr == FDT_ADDR_T_NONE) | |
547 | 559 | return -EINVAL; |
548 | - } | |
549 | - ds->num_cs = fdtdec_get_int(blob, node, "num-cs", 4); | |
550 | 560 | |
561 | + plat->regs = (struct davinci_spi_regs *)addr; | |
562 | + plat->num_cs = fdtdec_get_int(gd->fdt_blob, dev_of_offset(bus), "num-cs", 4); | |
563 | + | |
551 | 564 | return 0; |
552 | 565 | } |
553 | 566 | |
554 | -static const struct dm_spi_ops davinci_spi_ops = { | |
555 | - .claim_bus = davinci_spi_claim_bus, | |
556 | - .release_bus = davinci_spi_release_bus, | |
557 | - .xfer = davinci_spi_xfer, | |
558 | - .set_speed = davinci_spi_set_speed, | |
559 | - .set_mode = davinci_spi_set_mode, | |
560 | -}; | |
561 | - | |
562 | 567 | static const struct udevice_id davinci_spi_ids[] = { |
563 | 568 | { .compatible = "ti,keystone-spi" }, |
564 | 569 | { .compatible = "ti,dm6441-spi" }, |
565 | 570 | { .compatible = "ti,da830-spi" }, |
566 | 571 | { } |
567 | 572 | }; |
573 | +#endif | |
568 | 574 | |
569 | 575 | U_BOOT_DRIVER(davinci_spi) = { |
570 | 576 | .name = "davinci_spi", |
571 | 577 | .id = UCLASS_SPI, |
578 | +#if CONFIG_IS_ENABLED(OF_CONTROL) && !CONFIG_IS_ENABLED(OF_PLATDATA) | |
572 | 579 | .of_match = davinci_spi_ids, |
573 | - .ops = &davinci_spi_ops, | |
574 | 580 | .ofdata_to_platdata = davinci_ofdata_to_platadata, |
575 | - .priv_auto_alloc_size = sizeof(struct davinci_spi_slave), | |
581 | + .platdata_auto_alloc_size = sizeof(struct davinci_spi_platdata), | |
582 | +#endif | |
576 | 583 | .probe = davinci_spi_probe, |
584 | + .ops = &davinci_spi_ops, | |
585 | + .priv_auto_alloc_size = sizeof(struct davinci_spi_slave), | |
577 | 586 | }; |
578 | 587 | #endif |
include/dm/platform_data/spi_davinci.h
1 | +/* | |
2 | + * Copyright (C) 2018 Jagan Teki <jagan@amarulasolutions.com> | |
3 | + * | |
4 | + * SPDX-License-Identifier: GPL-2.0+ | |
5 | + */ | |
6 | + | |
7 | +#ifndef __spi_davinci_h | |
8 | +#define __spi_davinci_h | |
9 | + | |
10 | +struct davinci_spi_platdata { | |
11 | + struct davinci_spi_regs *regs; | |
12 | + u8 num_cs; /* total no. of CS available */ | |
13 | +}; | |
14 | + | |
15 | +#endif /* __spi_davinci_h */ |