diff options
| -rw-r--r-- | Documentation/devicetree/bindings/mfd/atmel-matrix.txt | 24 | ||||
| -rw-r--r-- | Documentation/devicetree/bindings/mfd/atmel-smc.txt | 19 | ||||
| -rw-r--r-- | Documentation/devicetree/bindings/usb/atmel-usb.txt | 10 | ||||
| -rw-r--r-- | drivers/usb/gadget/udc/Kconfig | 1 | ||||
| -rw-r--r-- | drivers/usb/gadget/udc/at91_udc.c | 525 | ||||
| -rw-r--r-- | drivers/usb/gadget/udc/at91_udc.h | 9 | ||||
| -rw-r--r-- | include/linux/mfd/syscon/atmel-matrix.h | 117 | ||||
| -rw-r--r-- | include/linux/mfd/syscon/atmel-smc.h | 173 |
8 files changed, 623 insertions, 255 deletions
diff --git a/Documentation/devicetree/bindings/mfd/atmel-matrix.txt b/Documentation/devicetree/bindings/mfd/atmel-matrix.txt new file mode 100644 index 000000000000..e3ef50ca02a5 --- /dev/null +++ b/Documentation/devicetree/bindings/mfd/atmel-matrix.txt | |||
| @@ -0,0 +1,24 @@ | |||
| 1 | * Device tree bindings for Atmel Bus Matrix | ||
| 2 | |||
| 3 | The Bus Matrix registers are used to configure Atmel SoCs internal bus | ||
| 4 | behavior (master/slave priorities, undefined burst length type, ...) | ||
| 5 | |||
| 6 | Required properties: | ||
| 7 | - compatible: Should be one of the following | ||
| 8 | "atmel,at91sam9260-matrix", "syscon" | ||
| 9 | "atmel,at91sam9261-matrix", "syscon" | ||
| 10 | "atmel,at91sam9263-matrix", "syscon" | ||
| 11 | "atmel,at91sam9rl-matrix", "syscon" | ||
| 12 | "atmel,at91sam9g45-matrix", "syscon" | ||
| 13 | "atmel,at91sam9n12-matrix", "syscon" | ||
| 14 | "atmel,at91sam9x5-matrix", "syscon" | ||
| 15 | "atmel,sama5d3-matrix", "syscon" | ||
| 16 | - reg: Contains offset/length value of the Bus Matrix | ||
| 17 | memory region. | ||
| 18 | |||
| 19 | Example: | ||
| 20 | |||
| 21 | matrix: matrix@ffffec00 { | ||
| 22 | compatible = "atmel,sama5d3-matrix", "syscon"; | ||
| 23 | reg = <0xffffec00 0x200>; | ||
| 24 | }; | ||
diff --git a/Documentation/devicetree/bindings/mfd/atmel-smc.txt b/Documentation/devicetree/bindings/mfd/atmel-smc.txt new file mode 100644 index 000000000000..26eeed373934 --- /dev/null +++ b/Documentation/devicetree/bindings/mfd/atmel-smc.txt | |||
| @@ -0,0 +1,19 @@ | |||
| 1 | * Device tree bindings for Atmel SMC (Static Memory Controller) | ||
| 2 | |||
| 3 | The SMC registers are used to configure Atmel EBI (External Bus Interface) | ||
| 4 | to interface with standard memory devices (NAND, NOR, SRAM or specialized | ||
| 5 | devices like FPGAs). | ||
| 6 | |||
| 7 | Required properties: | ||
| 8 | - compatible: Should be one of the following | ||
| 9 | "atmel,at91sam9260-smc", "syscon" | ||
| 10 | "atmel,sama5d3-smc", "syscon" | ||
| 11 | - reg: Contains offset/length value of the SMC memory | ||
| 12 | region. | ||
| 13 | |||
| 14 | Example: | ||
| 15 | |||
| 16 | smc: smc@ffffc000 { | ||
| 17 | compatible = "atmel,sama5d3-smc", "syscon"; | ||
| 18 | reg = <0xffffc000 0x1000>; | ||
| 19 | }; | ||
diff --git a/Documentation/devicetree/bindings/usb/atmel-usb.txt b/Documentation/devicetree/bindings/usb/atmel-usb.txt index bc2222ca3f2a..54a81219caae 100644 --- a/Documentation/devicetree/bindings/usb/atmel-usb.txt +++ b/Documentation/devicetree/bindings/usb/atmel-usb.txt | |||
| @@ -33,9 +33,17 @@ usb1: ehci@00800000 { | |||
| 33 | AT91 USB device controller | 33 | AT91 USB device controller |
| 34 | 34 | ||
| 35 | Required properties: | 35 | Required properties: |
| 36 | - compatible: Should be "atmel,at91rm9200-udc" | 36 | - compatible: Should be one of the following |
| 37 | "atmel,at91rm9200-udc" | ||
| 38 | "atmel,at91sam9260-udc" | ||
| 39 | "atmel,at91sam9261-udc" | ||
| 40 | "atmel,at91sam9263-udc" | ||
| 37 | - reg: Address and length of the register set for the device | 41 | - reg: Address and length of the register set for the device |
| 38 | - interrupts: Should contain macb interrupt | 42 | - interrupts: Should contain macb interrupt |
| 43 | - clocks: Should reference the peripheral and the AHB clocks | ||
| 44 | - clock-names: Should contains two strings | ||
| 45 | "pclk" for the peripheral clock | ||
| 46 | "hclk" for the AHB clock | ||
| 39 | 47 | ||
| 40 | Optional properties: | 48 | Optional properties: |
| 41 | - atmel,vbus-gpio: If present, specifies a gpio that needs to be | 49 | - atmel,vbus-gpio: If present, specifies a gpio that needs to be |
diff --git a/drivers/usb/gadget/udc/Kconfig b/drivers/usb/gadget/udc/Kconfig index b8e213eb36cc..366e551aeff0 100644 --- a/drivers/usb/gadget/udc/Kconfig +++ b/drivers/usb/gadget/udc/Kconfig | |||
| @@ -32,6 +32,7 @@ menu "USB Peripheral Controller" | |||
| 32 | config USB_AT91 | 32 | config USB_AT91 |
| 33 | tristate "Atmel AT91 USB Device Port" | 33 | tristate "Atmel AT91 USB Device Port" |
| 34 | depends on ARCH_AT91 | 34 | depends on ARCH_AT91 |
| 35 | depends on OF || COMPILE_TEST | ||
| 35 | help | 36 | help |
| 36 | Many Atmel AT91 processors (such as the AT91RM2000) have a | 37 | Many Atmel AT91 processors (such as the AT91RM2000) have a |
| 37 | full speed USB Device Port with support for five configurable | 38 | full speed USB Device Port with support for five configurable |
diff --git a/drivers/usb/gadget/udc/at91_udc.c b/drivers/usb/gadget/udc/at91_udc.c index c862656d18b8..6d285226ab94 100644 --- a/drivers/usb/gadget/udc/at91_udc.c +++ b/drivers/usb/gadget/udc/at91_udc.c | |||
| @@ -31,16 +31,9 @@ | |||
| 31 | #include <linux/of.h> | 31 | #include <linux/of.h> |
| 32 | #include <linux/of_gpio.h> | 32 | #include <linux/of_gpio.h> |
| 33 | #include <linux/platform_data/atmel.h> | 33 | #include <linux/platform_data/atmel.h> |
| 34 | 34 | #include <linux/regmap.h> | |
| 35 | #include <asm/byteorder.h> | 35 | #include <linux/mfd/syscon.h> |
| 36 | #include <mach/hardware.h> | 36 | #include <linux/mfd/syscon/atmel-matrix.h> |
| 37 | #include <asm/io.h> | ||
| 38 | #include <asm/irq.h> | ||
| 39 | #include <asm/gpio.h> | ||
| 40 | |||
| 41 | #include <mach/cpu.h> | ||
| 42 | #include <mach/at91sam9261_matrix.h> | ||
| 43 | #include <mach/at91_matrix.h> | ||
| 44 | 37 | ||
| 45 | #include "at91_udc.h" | 38 | #include "at91_udc.h" |
| 46 | 39 | ||
| @@ -66,7 +59,15 @@ | |||
| 66 | #define DRIVER_VERSION "3 May 2006" | 59 | #define DRIVER_VERSION "3 May 2006" |
| 67 | 60 | ||
| 68 | static const char driver_name [] = "at91_udc"; | 61 | static const char driver_name [] = "at91_udc"; |
| 69 | static const char ep0name[] = "ep0"; | 62 | static const char * const ep_names[] = { |
| 63 | "ep0", | ||
| 64 | "ep1", | ||
| 65 | "ep2", | ||
| 66 | "ep3-int", | ||
| 67 | "ep4", | ||
| 68 | "ep5", | ||
| 69 | }; | ||
| 70 | #define ep0name ep_names[0] | ||
| 70 | 71 | ||
| 71 | #define VBUS_POLL_TIMEOUT msecs_to_jiffies(1000) | 72 | #define VBUS_POLL_TIMEOUT msecs_to_jiffies(1000) |
| 72 | 73 | ||
| @@ -895,8 +896,6 @@ static void clk_on(struct at91_udc *udc) | |||
| 895 | return; | 896 | return; |
| 896 | udc->clocked = 1; | 897 | udc->clocked = 1; |
| 897 | 898 | ||
| 898 | if (IS_ENABLED(CONFIG_COMMON_CLK)) | ||
| 899 | clk_enable(udc->uclk); | ||
| 900 | clk_enable(udc->iclk); | 899 | clk_enable(udc->iclk); |
| 901 | clk_enable(udc->fclk); | 900 | clk_enable(udc->fclk); |
| 902 | } | 901 | } |
| @@ -909,8 +908,6 @@ static void clk_off(struct at91_udc *udc) | |||
| 909 | udc->gadget.speed = USB_SPEED_UNKNOWN; | 908 | udc->gadget.speed = USB_SPEED_UNKNOWN; |
| 910 | clk_disable(udc->fclk); | 909 | clk_disable(udc->fclk); |
| 911 | clk_disable(udc->iclk); | 910 | clk_disable(udc->iclk); |
| 912 | if (IS_ENABLED(CONFIG_COMMON_CLK)) | ||
| 913 | clk_disable(udc->uclk); | ||
| 914 | } | 911 | } |
| 915 | 912 | ||
| 916 | /* | 913 | /* |
| @@ -919,8 +916,6 @@ static void clk_off(struct at91_udc *udc) | |||
| 919 | */ | 916 | */ |
| 920 | static void pullup(struct at91_udc *udc, int is_on) | 917 | static void pullup(struct at91_udc *udc, int is_on) |
| 921 | { | 918 | { |
| 922 | int active = !udc->board.pullup_active_low; | ||
| 923 | |||
| 924 | if (!udc->enabled || !udc->vbus) | 919 | if (!udc->enabled || !udc->vbus) |
| 925 | is_on = 0; | 920 | is_on = 0; |
| 926 | DBG("%sactive\n", is_on ? "" : "in"); | 921 | DBG("%sactive\n", is_on ? "" : "in"); |
| @@ -929,40 +924,15 @@ static void pullup(struct at91_udc *udc, int is_on) | |||
| 929 | clk_on(udc); | 924 | clk_on(udc); |
| 930 | at91_udp_write(udc, AT91_UDP_ICR, AT91_UDP_RXRSM); | 925 | at91_udp_write(udc, AT91_UDP_ICR, AT91_UDP_RXRSM); |
| 931 | at91_udp_write(udc, AT91_UDP_TXVC, 0); | 926 | at91_udp_write(udc, AT91_UDP_TXVC, 0); |
| 932 | if (cpu_is_at91rm9200()) | ||
| 933 | gpio_set_value(udc->board.pullup_pin, active); | ||
| 934 | else if (cpu_is_at91sam9260() || cpu_is_at91sam9263() || cpu_is_at91sam9g20()) { | ||
| 935 | u32 txvc = at91_udp_read(udc, AT91_UDP_TXVC); | ||
| 936 | |||
| 937 | txvc |= AT91_UDP_TXVC_PUON; | ||
| 938 | at91_udp_write(udc, AT91_UDP_TXVC, txvc); | ||
| 939 | } else if (cpu_is_at91sam9261() || cpu_is_at91sam9g10()) { | ||
| 940 | u32 usbpucr; | ||
| 941 | |||
| 942 | usbpucr = at91_matrix_read(AT91_MATRIX_USBPUCR); | ||
| 943 | usbpucr |= AT91_MATRIX_USBPUCR_PUON; | ||
| 944 | at91_matrix_write(AT91_MATRIX_USBPUCR, usbpucr); | ||
| 945 | } | ||
| 946 | } else { | 927 | } else { |
| 947 | stop_activity(udc); | 928 | stop_activity(udc); |
| 948 | at91_udp_write(udc, AT91_UDP_IDR, AT91_UDP_RXRSM); | 929 | at91_udp_write(udc, AT91_UDP_IDR, AT91_UDP_RXRSM); |
| 949 | at91_udp_write(udc, AT91_UDP_TXVC, AT91_UDP_TXVC_TXVDIS); | 930 | at91_udp_write(udc, AT91_UDP_TXVC, AT91_UDP_TXVC_TXVDIS); |
| 950 | if (cpu_is_at91rm9200()) | ||
| 951 | gpio_set_value(udc->board.pullup_pin, !active); | ||
| 952 | else if (cpu_is_at91sam9260() || cpu_is_at91sam9263() || cpu_is_at91sam9g20()) { | ||
| 953 | u32 txvc = at91_udp_read(udc, AT91_UDP_TXVC); | ||
| 954 | |||
| 955 | txvc &= ~AT91_UDP_TXVC_PUON; | ||
| 956 | at91_udp_write(udc, AT91_UDP_TXVC, txvc); | ||
| 957 | } else if (cpu_is_at91sam9261() || cpu_is_at91sam9g10()) { | ||
| 958 | u32 usbpucr; | ||
| 959 | |||
| 960 | usbpucr = at91_matrix_read(AT91_MATRIX_USBPUCR); | ||
| 961 | usbpucr &= ~AT91_MATRIX_USBPUCR_PUON; | ||
| 962 | at91_matrix_write(AT91_MATRIX_USBPUCR, usbpucr); | ||
| 963 | } | ||
| 964 | clk_off(udc); | 931 | clk_off(udc); |
| 965 | } | 932 | } |
| 933 | |||
| 934 | if (udc->caps && udc->caps->pullup) | ||
| 935 | udc->caps->pullup(udc, is_on); | ||
| 966 | } | 936 | } |
| 967 | 937 | ||
| 968 | /* vbus is here! turn everything on that's ready */ | 938 | /* vbus is here! turn everything on that's ready */ |
| @@ -1535,74 +1505,6 @@ static irqreturn_t at91_udc_irq (int irq, void *_udc) | |||
| 1535 | 1505 | ||
| 1536 | /*-------------------------------------------------------------------------*/ | 1506 | /*-------------------------------------------------------------------------*/ |
| 1537 | 1507 | ||
| 1538 | static struct at91_udc controller = { | ||
| 1539 | .gadget = { | ||
| 1540 | .ops = &at91_udc_ops, | ||
| 1541 | .ep0 = &controller.ep[0].ep, | ||
| 1542 | .name = driver_name, | ||
| 1543 | }, | ||
| 1544 | .ep[0] = { | ||
| 1545 | .ep = { | ||
| 1546 | .name = ep0name, | ||
| 1547 | .ops = &at91_ep_ops, | ||
| 1548 | }, | ||
| 1549 | .udc = &controller, | ||
| 1550 | .maxpacket = 8, | ||
| 1551 | .int_mask = 1 << 0, | ||
| 1552 | }, | ||
| 1553 | .ep[1] = { | ||
| 1554 | .ep = { | ||
| 1555 | .name = "ep1", | ||
| 1556 | .ops = &at91_ep_ops, | ||
| 1557 | }, | ||
| 1558 | .udc = &controller, | ||
| 1559 | .is_pingpong = 1, | ||
| 1560 | .maxpacket = 64, | ||
| 1561 | .int_mask = 1 << 1, | ||
| 1562 | }, | ||
| 1563 | .ep[2] = { | ||
| 1564 | .ep = { | ||
| 1565 | .name = "ep2", | ||
| 1566 | .ops = &at91_ep_ops, | ||
| 1567 | }, | ||
| 1568 | .udc = &controller, | ||
| 1569 | .is_pingpong = 1, | ||
| 1570 | .maxpacket = 64, | ||
| 1571 | .int_mask = 1 << 2, | ||
| 1572 | }, | ||
| 1573 | .ep[3] = { | ||
| 1574 | .ep = { | ||
| 1575 | /* could actually do bulk too */ | ||
| 1576 | .name = "ep3-int", | ||
| 1577 | .ops = &at91_ep_ops, | ||
| 1578 | }, | ||
| 1579 | .udc = &controller, | ||
| 1580 | .maxpacket = 8, | ||
| 1581 | .int_mask = 1 << 3, | ||
| 1582 | }, | ||
| 1583 | .ep[4] = { | ||
| 1584 | .ep = { | ||
| 1585 | .name = "ep4", | ||
| 1586 | .ops = &at91_ep_ops, | ||
| 1587 | }, | ||
| 1588 | .udc = &controller, | ||
| 1589 | .is_pingpong = 1, | ||
| 1590 | .maxpacket = 256, | ||
| 1591 | .int_mask = 1 << 4, | ||
| 1592 | }, | ||
| 1593 | .ep[5] = { | ||
| 1594 | .ep = { | ||
| 1595 | .name = "ep5", | ||
| 1596 | .ops = &at91_ep_ops, | ||
| 1597 | }, | ||
| 1598 | .udc = &controller, | ||
| 1599 | .is_pingpong = 1, | ||
| 1600 | .maxpacket = 256, | ||
| 1601 | .int_mask = 1 << 5, | ||
| 1602 | }, | ||
| 1603 | /* ep6 and ep7 are also reserved (custom silicon might use them) */ | ||
| 1604 | }; | ||
| 1605 | |||
| 1606 | static void at91_vbus_update(struct at91_udc *udc, unsigned value) | 1508 | static void at91_vbus_update(struct at91_udc *udc, unsigned value) |
| 1607 | { | 1509 | { |
| 1608 | value ^= udc->board.vbus_active_low; | 1510 | value ^= udc->board.vbus_active_low; |
| @@ -1687,12 +1589,202 @@ static void at91udc_shutdown(struct platform_device *dev) | |||
| 1687 | spin_unlock_irqrestore(&udc->lock, flags); | 1589 | spin_unlock_irqrestore(&udc->lock, flags); |
| 1688 | } | 1590 | } |
| 1689 | 1591 | ||
| 1690 | static void at91udc_of_init(struct at91_udc *udc, | 1592 | static int at91rm9200_udc_init(struct at91_udc *udc) |
| 1691 | struct device_node *np) | 1593 | { |
| 1594 | struct at91_ep *ep; | ||
| 1595 | int ret; | ||
| 1596 | int i; | ||
| 1597 | |||
| 1598 | for (i = 0; i < NUM_ENDPOINTS; i++) { | ||
| 1599 | ep = &udc->ep[i]; | ||
| 1600 | |||
| 1601 | switch (i) { | ||
| 1602 | case 0: | ||
| 1603 | case 3: | ||
| 1604 | ep->maxpacket = 8; | ||
| 1605 | break; | ||
| 1606 | case 1 ... 2: | ||
| 1607 | ep->maxpacket = 64; | ||
| 1608 | break; | ||
| 1609 | case 4 ... 5: | ||
| 1610 | ep->maxpacket = 256; | ||
| 1611 | break; | ||
| 1612 | } | ||
| 1613 | } | ||
| 1614 | |||
| 1615 | if (!gpio_is_valid(udc->board.pullup_pin)) { | ||
| 1616 | DBG("no D+ pullup?\n"); | ||
| 1617 | return -ENODEV; | ||
| 1618 | } | ||
| 1619 | |||
| 1620 | ret = devm_gpio_request(&udc->pdev->dev, udc->board.pullup_pin, | ||
| 1621 | "udc_pullup"); | ||
| 1622 | if (ret) { | ||
| 1623 | DBG("D+ pullup is busy\n"); | ||
| 1624 | return ret; | ||
| 1625 | } | ||
| 1626 | |||
| 1627 | gpio_direction_output(udc->board.pullup_pin, | ||
| 1628 | udc->board.pullup_active_low); | ||
| 1629 | |||
| 1630 | return 0; | ||
| 1631 | } | ||
| 1632 | |||
| 1633 | static void at91rm9200_udc_pullup(struct at91_udc *udc, int is_on) | ||
| 1634 | { | ||
| 1635 | int active = !udc->board.pullup_active_low; | ||
| 1636 | |||
| 1637 | if (is_on) | ||
| 1638 | gpio_set_value(udc->board.pullup_pin, active); | ||
| 1639 | else | ||
| 1640 | gpio_set_value(udc->board.pullup_pin, !active); | ||
| 1641 | } | ||
| 1642 | |||
| 1643 | static const struct at91_udc_caps at91rm9200_udc_caps = { | ||
| 1644 | .init = at91rm9200_udc_init, | ||
| 1645 | .pullup = at91rm9200_udc_pullup, | ||
| 1646 | }; | ||
| 1647 | |||
| 1648 | static int at91sam9260_udc_init(struct at91_udc *udc) | ||
| 1649 | { | ||
| 1650 | struct at91_ep *ep; | ||
| 1651 | int i; | ||
| 1652 | |||
| 1653 | for (i = 0; i < NUM_ENDPOINTS; i++) { | ||
| 1654 | ep = &udc->ep[i]; | ||
| 1655 | |||
| 1656 | switch (i) { | ||
| 1657 | case 0 ... 3: | ||
| 1658 | ep->maxpacket = 64; | ||
| 1659 | break; | ||
| 1660 | case 4 ... 5: | ||
| 1661 | ep->maxpacket = 512; | ||
| 1662 | break; | ||
| 1663 | } | ||
| 1664 | } | ||
| 1665 | |||
| 1666 | return 0; | ||
| 1667 | } | ||
| 1668 | |||
| 1669 | static void at91sam9260_udc_pullup(struct at91_udc *udc, int is_on) | ||
| 1670 | { | ||
| 1671 | u32 txvc = at91_udp_read(udc, AT91_UDP_TXVC); | ||
| 1672 | |||
| 1673 | if (is_on) | ||
| 1674 | txvc |= AT91_UDP_TXVC_PUON; | ||
| 1675 | else | ||
| 1676 | txvc &= ~AT91_UDP_TXVC_PUON; | ||
| 1677 | |||
| 1678 | at91_udp_write(udc, AT91_UDP_TXVC, txvc); | ||
| 1679 | } | ||
| 1680 | |||
| 1681 | static const struct at91_udc_caps at91sam9260_udc_caps = { | ||
| 1682 | .init = at91sam9260_udc_init, | ||
| 1683 | .pullup = at91sam9260_udc_pullup, | ||
| 1684 | }; | ||
| 1685 | |||
| 1686 | static int at91sam9261_udc_init(struct at91_udc *udc) | ||
| 1687 | { | ||
| 1688 | struct at91_ep *ep; | ||
| 1689 | int i; | ||
| 1690 | |||
| 1691 | for (i = 0; i < NUM_ENDPOINTS; i++) { | ||
| 1692 | ep = &udc->ep[i]; | ||
| 1693 | |||
| 1694 | switch (i) { | ||
| 1695 | case 0: | ||
| 1696 | ep->maxpacket = 8; | ||
| 1697 | break; | ||
| 1698 | case 1 ... 3: | ||
| 1699 | ep->maxpacket = 64; | ||
| 1700 | break; | ||
| 1701 | case 4 ... 5: | ||
| 1702 | ep->maxpacket = 256; | ||
| 1703 | break; | ||
| 1704 | } | ||
| 1705 | } | ||
| 1706 | |||
| 1707 | udc->matrix = syscon_regmap_lookup_by_phandle(udc->pdev->dev.of_node, | ||
| 1708 | "atmel,matrix"); | ||
| 1709 | if (IS_ERR(udc->matrix)) | ||
| 1710 | return PTR_ERR(udc->matrix); | ||
| 1711 | |||
| 1712 | return 0; | ||
| 1713 | } | ||
| 1714 | |||
| 1715 | static void at91sam9261_udc_pullup(struct at91_udc *udc, int is_on) | ||
| 1716 | { | ||
| 1717 | u32 usbpucr = 0; | ||
| 1718 | |||
| 1719 | if (is_on) | ||
| 1720 | usbpucr = AT91_MATRIX_USBPUCR_PUON; | ||
| 1721 | |||
| 1722 | regmap_update_bits(udc->matrix, AT91SAM9261_MATRIX_USBPUCR, | ||
| 1723 | AT91_MATRIX_USBPUCR_PUON, usbpucr); | ||
| 1724 | } | ||
| 1725 | |||
| 1726 | static const struct at91_udc_caps at91sam9261_udc_caps = { | ||
| 1727 | .init = at91sam9261_udc_init, | ||
| 1728 | .pullup = at91sam9261_udc_pullup, | ||
| 1729 | }; | ||
| 1730 | |||
| 1731 | static int at91sam9263_udc_init(struct at91_udc *udc) | ||
| 1732 | { | ||
| 1733 | struct at91_ep *ep; | ||
| 1734 | int i; | ||
| 1735 | |||
| 1736 | for (i = 0; i < NUM_ENDPOINTS; i++) { | ||
| 1737 | ep = &udc->ep[i]; | ||
| 1738 | |||
| 1739 | switch (i) { | ||
| 1740 | case 0: | ||
| 1741 | case 1: | ||
| 1742 | case 2: | ||
| 1743 | case 3: | ||
| 1744 | ep->maxpacket = 64; | ||
| 1745 | break; | ||
| 1746 | case 4: | ||
| 1747 | case 5: | ||
| 1748 | ep->maxpacket = 256; | ||
| 1749 | break; | ||
| 1750 | } | ||
| 1751 | } | ||
| 1752 | |||
| 1753 | return 0; | ||
| 1754 | } | ||
| 1755 | |||
| 1756 | static const struct at91_udc_caps at91sam9263_udc_caps = { | ||
| 1757 | .init = at91sam9263_udc_init, | ||
| 1758 | .pullup = at91sam9260_udc_pullup, | ||
| 1759 | }; | ||
| 1760 | |||
| 1761 | static const struct of_device_id at91_udc_dt_ids[] = { | ||
| 1762 | { | ||
| 1763 | .compatible = "atmel,at91rm9200-udc", | ||
| 1764 | .data = &at91rm9200_udc_caps, | ||
| 1765 | }, | ||
| 1766 | { | ||
| 1767 | .compatible = "atmel,at91sam9260-udc", | ||
| 1768 | .data = &at91sam9260_udc_caps, | ||
| 1769 | }, | ||
| 1770 | { | ||
| 1771 | .compatible = "atmel,at91sam9261-udc", | ||
| 1772 | .data = &at91sam9261_udc_caps, | ||
| 1773 | }, | ||
| 1774 | { | ||
| 1775 | .compatible = "atmel,at91sam9263-udc", | ||
| 1776 | .data = &at91sam9263_udc_caps, | ||
| 1777 | }, | ||
| 1778 | { /* sentinel */ } | ||
| 1779 | }; | ||
| 1780 | MODULE_DEVICE_TABLE(of, at91_udc_dt_ids); | ||
| 1781 | |||
| 1782 | static void at91udc_of_init(struct at91_udc *udc, struct device_node *np) | ||
| 1692 | { | 1783 | { |
| 1693 | struct at91_udc_data *board = &udc->board; | 1784 | struct at91_udc_data *board = &udc->board; |
| 1694 | u32 val; | 1785 | const struct of_device_id *match; |
| 1695 | enum of_gpio_flags flags; | 1786 | enum of_gpio_flags flags; |
| 1787 | u32 val; | ||
| 1696 | 1788 | ||
| 1697 | if (of_property_read_u32(np, "atmel,vbus-polled", &val) == 0) | 1789 | if (of_property_read_u32(np, "atmel,vbus-polled", &val) == 0) |
| 1698 | board->vbus_polled = 1; | 1790 | board->vbus_polled = 1; |
| @@ -1705,6 +1797,10 @@ static void at91udc_of_init(struct at91_udc *udc, | |||
| 1705 | &flags); | 1797 | &flags); |
| 1706 | 1798 | ||
| 1707 | board->pullup_active_low = (flags & OF_GPIO_ACTIVE_LOW) ? 1 : 0; | 1799 | board->pullup_active_low = (flags & OF_GPIO_ACTIVE_LOW) ? 1 : 0; |
| 1800 | |||
| 1801 | match = of_match_node(at91_udc_dt_ids, np); | ||
| 1802 | if (match) | ||
| 1803 | udc->caps = match->data; | ||
| 1708 | } | 1804 | } |
| 1709 | 1805 | ||
| 1710 | static int at91udc_probe(struct platform_device *pdev) | 1806 | static int at91udc_probe(struct platform_device *pdev) |
| @@ -1713,97 +1809,67 @@ static int at91udc_probe(struct platform_device *pdev) | |||
| 1713 | struct at91_udc *udc; | 1809 | struct at91_udc *udc; |
| 1714 | int retval; | 1810 | int retval; |
| 1715 | struct resource *res; | 1811 | struct resource *res; |
| 1812 | struct at91_ep *ep; | ||
| 1813 | int i; | ||
| 1716 | 1814 | ||
| 1717 | if (!dev_get_platdata(dev) && !pdev->dev.of_node) { | 1815 | udc = devm_kzalloc(dev, sizeof(*udc), GFP_KERNEL); |
| 1718 | /* small (so we copy it) but critical! */ | 1816 | if (!udc) |
| 1719 | DBG("missing platform_data\n"); | 1817 | return -ENOMEM; |
| 1720 | return -ENODEV; | ||
| 1721 | } | ||
| 1722 | |||
| 1723 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | ||
| 1724 | if (!res) | ||
| 1725 | return -ENXIO; | ||
| 1726 | |||
| 1727 | if (!request_mem_region(res->start, resource_size(res), driver_name)) { | ||
| 1728 | DBG("someone's using UDC memory\n"); | ||
| 1729 | return -EBUSY; | ||
| 1730 | } | ||
| 1731 | 1818 | ||
| 1732 | /* init software state */ | 1819 | /* init software state */ |
| 1733 | udc = &controller; | ||
| 1734 | udc->gadget.dev.parent = dev; | 1820 | udc->gadget.dev.parent = dev; |
| 1735 | if (IS_ENABLED(CONFIG_OF) && pdev->dev.of_node) | 1821 | at91udc_of_init(udc, pdev->dev.of_node); |
| 1736 | at91udc_of_init(udc, pdev->dev.of_node); | ||
| 1737 | else | ||
| 1738 | memcpy(&udc->board, dev_get_platdata(dev), | ||
| 1739 | sizeof(struct at91_udc_data)); | ||
| 1740 | udc->pdev = pdev; | 1822 | udc->pdev = pdev; |
| 1741 | udc->enabled = 0; | 1823 | udc->enabled = 0; |
| 1742 | spin_lock_init(&udc->lock); | 1824 | spin_lock_init(&udc->lock); |
| 1743 | 1825 | ||
| 1744 | /* rm9200 needs manual D+ pullup; off by default */ | 1826 | udc->gadget.ops = &at91_udc_ops; |
| 1745 | if (cpu_is_at91rm9200()) { | 1827 | udc->gadget.ep0 = &udc->ep[0].ep; |
| 1746 | if (!gpio_is_valid(udc->board.pullup_pin)) { | 1828 | udc->gadget.name = driver_name; |
| 1747 | DBG("no D+ pullup?\n"); | 1829 | udc->gadget.dev.init_name = "gadget"; |
| 1748 | retval = -ENODEV; | ||
| 1749 | goto fail0; | ||
| 1750 | } | ||
| 1751 | retval = gpio_request(udc->board.pullup_pin, "udc_pullup"); | ||
| 1752 | if (retval) { | ||
| 1753 | DBG("D+ pullup is busy\n"); | ||
| 1754 | goto fail0; | ||
| 1755 | } | ||
| 1756 | gpio_direction_output(udc->board.pullup_pin, | ||
| 1757 | udc->board.pullup_active_low); | ||
| 1758 | } | ||
| 1759 | 1830 | ||
| 1760 | /* newer chips have more FIFO memory than rm9200 */ | 1831 | for (i = 0; i < NUM_ENDPOINTS; i++) { |
| 1761 | if (cpu_is_at91sam9260() || cpu_is_at91sam9g20()) { | 1832 | ep = &udc->ep[i]; |
| 1762 | udc->ep[0].maxpacket = 64; | 1833 | ep->ep.name = ep_names[i]; |
| 1763 | udc->ep[3].maxpacket = 64; | 1834 | ep->ep.ops = &at91_ep_ops; |
| 1764 | udc->ep[4].maxpacket = 512; | 1835 | ep->udc = udc; |
| 1765 | udc->ep[5].maxpacket = 512; | 1836 | ep->int_mask = BIT(i); |
| 1766 | } else if (cpu_is_at91sam9261() || cpu_is_at91sam9g10()) { | 1837 | if (i != 0 && i != 3) |
| 1767 | udc->ep[3].maxpacket = 64; | 1838 | ep->is_pingpong = 1; |
| 1768 | } else if (cpu_is_at91sam9263()) { | ||
| 1769 | udc->ep[0].maxpacket = 64; | ||
| 1770 | udc->ep[3].maxpacket = 64; | ||
| 1771 | } | 1839 | } |
| 1772 | 1840 | ||
| 1773 | udc->udp_baseaddr = ioremap(res->start, resource_size(res)); | 1841 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 1774 | if (!udc->udp_baseaddr) { | 1842 | udc->udp_baseaddr = devm_ioremap_resource(dev, res); |
| 1775 | retval = -ENOMEM; | 1843 | if (IS_ERR(udc->udp_baseaddr)) |
| 1776 | goto fail0a; | 1844 | return PTR_ERR(udc->udp_baseaddr); |
| 1845 | |||
| 1846 | if (udc->caps && udc->caps->init) { | ||
| 1847 | retval = udc->caps->init(udc); | ||
| 1848 | if (retval) | ||
| 1849 | return retval; | ||
| 1777 | } | 1850 | } |
| 1778 | 1851 | ||
| 1779 | udc_reinit(udc); | 1852 | udc_reinit(udc); |
| 1780 | 1853 | ||
| 1781 | /* get interface and function clocks */ | 1854 | /* get interface and function clocks */ |
| 1782 | udc->iclk = clk_get(dev, "udc_clk"); | 1855 | udc->iclk = devm_clk_get(dev, "pclk"); |
| 1783 | udc->fclk = clk_get(dev, "udpck"); | 1856 | if (IS_ERR(udc->iclk)) |
| 1784 | if (IS_ENABLED(CONFIG_COMMON_CLK)) | 1857 | return PTR_ERR(udc->iclk); |
| 1785 | udc->uclk = clk_get(dev, "usb_clk"); | 1858 | |
| 1786 | if (IS_ERR(udc->iclk) || IS_ERR(udc->fclk) || | 1859 | udc->fclk = devm_clk_get(dev, "hclk"); |
| 1787 | (IS_ENABLED(CONFIG_COMMON_CLK) && IS_ERR(udc->uclk))) { | 1860 | if (IS_ERR(udc->fclk)) |
| 1788 | DBG("clocks missing\n"); | 1861 | return PTR_ERR(udc->fclk); |
| 1789 | retval = -ENODEV; | ||
| 1790 | goto fail1; | ||
| 1791 | } | ||
| 1792 | 1862 | ||
| 1793 | /* don't do anything until we have both gadget driver and VBUS */ | 1863 | /* don't do anything until we have both gadget driver and VBUS */ |
| 1794 | if (IS_ENABLED(CONFIG_COMMON_CLK)) { | 1864 | clk_set_rate(udc->fclk, 48000000); |
| 1795 | clk_set_rate(udc->uclk, 48000000); | ||
| 1796 | retval = clk_prepare(udc->uclk); | ||
| 1797 | if (retval) | ||
| 1798 | goto fail1; | ||
| 1799 | } | ||
| 1800 | retval = clk_prepare(udc->fclk); | 1865 | retval = clk_prepare(udc->fclk); |
| 1801 | if (retval) | 1866 | if (retval) |
| 1802 | goto fail1a; | 1867 | return retval; |
| 1803 | 1868 | ||
| 1804 | retval = clk_prepare_enable(udc->iclk); | 1869 | retval = clk_prepare_enable(udc->iclk); |
| 1805 | if (retval) | 1870 | if (retval) |
| 1806 | goto fail1b; | 1871 | goto err_unprepare_fclk; |
| 1872 | |||
| 1807 | at91_udp_write(udc, AT91_UDP_TXVC, AT91_UDP_TXVC_TXVDIS); | 1873 | at91_udp_write(udc, AT91_UDP_TXVC, AT91_UDP_TXVC_TXVDIS); |
| 1808 | at91_udp_write(udc, AT91_UDP_IDR, 0xffffffff); | 1874 | at91_udp_write(udc, AT91_UDP_IDR, 0xffffffff); |
| 1809 | /* Clear all pending interrupts - UDP may be used by bootloader. */ | 1875 | /* Clear all pending interrupts - UDP may be used by bootloader. */ |
| @@ -1812,18 +1878,21 @@ static int at91udc_probe(struct platform_device *pdev) | |||
| 1812 | 1878 | ||
| 1813 | /* request UDC and maybe VBUS irqs */ | 1879 | /* request UDC and maybe VBUS irqs */ |
| 1814 | udc->udp_irq = platform_get_irq(pdev, 0); | 1880 | udc->udp_irq = platform_get_irq(pdev, 0); |
| 1815 | retval = request_irq(udc->udp_irq, at91_udc_irq, | 1881 | retval = devm_request_irq(dev, udc->udp_irq, at91_udc_irq, 0, |
| 1816 | 0, driver_name, udc); | 1882 | driver_name, udc); |
| 1817 | if (retval < 0) { | 1883 | if (retval) { |
| 1818 | DBG("request irq %d failed\n", udc->udp_irq); | 1884 | DBG("request irq %d failed\n", udc->udp_irq); |
| 1819 | goto fail1c; | 1885 | goto err_unprepare_iclk; |
| 1820 | } | 1886 | } |
| 1887 | |||
| 1821 | if (gpio_is_valid(udc->board.vbus_pin)) { | 1888 | if (gpio_is_valid(udc->board.vbus_pin)) { |
| 1822 | retval = gpio_request(udc->board.vbus_pin, "udc_vbus"); | 1889 | retval = devm_gpio_request(dev, udc->board.vbus_pin, |
| 1823 | if (retval < 0) { | 1890 | "udc_vbus"); |
| 1891 | if (retval) { | ||
| 1824 | DBG("request vbus pin failed\n"); | 1892 | DBG("request vbus pin failed\n"); |
| 1825 | goto fail2; | 1893 | goto err_unprepare_iclk; |
| 1826 | } | 1894 | } |
| 1895 | |||
| 1827 | gpio_direction_input(udc->board.vbus_pin); | 1896 | gpio_direction_input(udc->board.vbus_pin); |
| 1828 | 1897 | ||
| 1829 | /* | 1898 | /* |
| @@ -1840,12 +1909,13 @@ static int at91udc_probe(struct platform_device *pdev) | |||
| 1840 | mod_timer(&udc->vbus_timer, | 1909 | mod_timer(&udc->vbus_timer, |
| 1841 | jiffies + VBUS_POLL_TIMEOUT); | 1910 | jiffies + VBUS_POLL_TIMEOUT); |
| 1842 | } else { | 1911 | } else { |
| 1843 | if (request_irq(gpio_to_irq(udc->board.vbus_pin), | 1912 | retval = devm_request_irq(dev, |
| 1844 | at91_vbus_irq, 0, driver_name, udc)) { | 1913 | gpio_to_irq(udc->board.vbus_pin), |
| 1914 | at91_vbus_irq, 0, driver_name, udc); | ||
| 1915 | if (retval) { | ||
| 1845 | DBG("request vbus irq %d failed\n", | 1916 | DBG("request vbus irq %d failed\n", |
| 1846 | udc->board.vbus_pin); | 1917 | udc->board.vbus_pin); |
| 1847 | retval = -EBUSY; | 1918 | goto err_unprepare_iclk; |
| 1848 | goto fail3; | ||
| 1849 | } | 1919 | } |
| 1850 | } | 1920 | } |
| 1851 | } else { | 1921 | } else { |
| @@ -1854,49 +1924,27 @@ static int at91udc_probe(struct platform_device *pdev) | |||
| 1854 | } | 1924 | } |
| 1855 | retval = usb_add_gadget_udc(dev, &udc->gadget); | 1925 | retval = usb_add_gadget_udc(dev, &udc->gadget); |
| 1856 | if (retval) | 1926 | if (retval) |
| 1857 | goto fail4; | 1927 | goto err_unprepare_iclk; |
| 1858 | dev_set_drvdata(dev, udc); | 1928 | dev_set_drvdata(dev, udc); |
| 1859 | device_init_wakeup(dev, 1); | 1929 | device_init_wakeup(dev, 1); |
| 1860 | create_debug_file(udc); | 1930 | create_debug_file(udc); |
| 1861 | 1931 | ||
| 1862 | INFO("%s version %s\n", driver_name, DRIVER_VERSION); | 1932 | INFO("%s version %s\n", driver_name, DRIVER_VERSION); |
| 1863 | return 0; | 1933 | return 0; |
| 1864 | fail4: | 1934 | |
| 1865 | if (gpio_is_valid(udc->board.vbus_pin) && !udc->board.vbus_polled) | 1935 | err_unprepare_iclk: |
| 1866 | free_irq(gpio_to_irq(udc->board.vbus_pin), udc); | ||
| 1867 | fail3: | ||
| 1868 | if (gpio_is_valid(udc->board.vbus_pin)) | ||
| 1869 | gpio_free(udc->board.vbus_pin); | ||
| 1870 | fail2: | ||
| 1871 | free_irq(udc->udp_irq, udc); | ||
| 1872 | fail1c: | ||
| 1873 | clk_unprepare(udc->iclk); | 1936 | clk_unprepare(udc->iclk); |
| 1874 | fail1b: | 1937 | err_unprepare_fclk: |
| 1875 | clk_unprepare(udc->fclk); | 1938 | clk_unprepare(udc->fclk); |
| 1876 | fail1a: | 1939 | |
| 1877 | if (IS_ENABLED(CONFIG_COMMON_CLK)) | ||
| 1878 | clk_unprepare(udc->uclk); | ||
| 1879 | fail1: | ||
| 1880 | if (IS_ENABLED(CONFIG_COMMON_CLK) && !IS_ERR(udc->uclk)) | ||
| 1881 | clk_put(udc->uclk); | ||
| 1882 | if (!IS_ERR(udc->fclk)) | ||
| 1883 | clk_put(udc->fclk); | ||
| 1884 | if (!IS_ERR(udc->iclk)) | ||
| 1885 | clk_put(udc->iclk); | ||
| 1886 | iounmap(udc->udp_baseaddr); | ||
| 1887 | fail0a: | ||
| 1888 | if (cpu_is_at91rm9200()) | ||
| 1889 | gpio_free(udc->board.pullup_pin); | ||
| 1890 | fail0: | ||
| 1891 | release_mem_region(res->start, resource_size(res)); | ||
| 1892 | DBG("%s probe failed, %d\n", driver_name, retval); | 1940 | DBG("%s probe failed, %d\n", driver_name, retval); |
| 1941 | |||
| 1893 | return retval; | 1942 | return retval; |
| 1894 | } | 1943 | } |
| 1895 | 1944 | ||
| 1896 | static int __exit at91udc_remove(struct platform_device *pdev) | 1945 | static int __exit at91udc_remove(struct platform_device *pdev) |
| 1897 | { | 1946 | { |
| 1898 | struct at91_udc *udc = platform_get_drvdata(pdev); | 1947 | struct at91_udc *udc = platform_get_drvdata(pdev); |
| 1899 | struct resource *res; | ||
| 1900 | unsigned long flags; | 1948 | unsigned long flags; |
| 1901 | 1949 | ||
| 1902 | DBG("remove\n"); | 1950 | DBG("remove\n"); |
| @@ -1911,29 +1959,9 @@ static int __exit at91udc_remove(struct platform_device *pdev) | |||
| 1911 | 1959 | ||
| 1912 | device_init_wakeup(&pdev->dev, 0); | 1960 | device_init_wakeup(&pdev->dev, 0); |
| 1913 | remove_debug_file(udc); | 1961 | remove_debug_file(udc); |
| 1914 | if (gpio_is_valid(udc->board.vbus_pin)) { | ||
| 1915 | free_irq(gpio_to_irq(udc->board.vbus_pin), udc); | ||
| 1916 | gpio_free(udc->board.vbus_pin); | ||
| 1917 | } | ||
| 1918 | free_irq(udc->udp_irq, udc); | ||
| 1919 | iounmap(udc->udp_baseaddr); | ||
| 1920 | |||
| 1921 | if (cpu_is_at91rm9200()) | ||
| 1922 | gpio_free(udc->board.pullup_pin); | ||
| 1923 | |||
| 1924 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | ||
| 1925 | release_mem_region(res->start, resource_size(res)); | ||
| 1926 | |||
| 1927 | if (IS_ENABLED(CONFIG_COMMON_CLK)) | ||
| 1928 | clk_unprepare(udc->uclk); | ||
| 1929 | clk_unprepare(udc->fclk); | 1962 | clk_unprepare(udc->fclk); |
| 1930 | clk_unprepare(udc->iclk); | 1963 | clk_unprepare(udc->iclk); |
| 1931 | 1964 | ||
| 1932 | clk_put(udc->iclk); | ||
| 1933 | clk_put(udc->fclk); | ||
| 1934 | if (IS_ENABLED(CONFIG_COMMON_CLK)) | ||
| 1935 | clk_put(udc->uclk); | ||
| 1936 | |||
| 1937 | return 0; | 1965 | return 0; |
| 1938 | } | 1966 | } |
| 1939 | 1967 | ||
| @@ -1989,15 +2017,6 @@ static int at91udc_resume(struct platform_device *pdev) | |||
| 1989 | #define at91udc_resume NULL | 2017 | #define at91udc_resume NULL |
| 1990 | #endif | 2018 | #endif |
| 1991 | 2019 | ||
| 1992 | #if defined(CONFIG_OF) | ||
| 1993 | static const struct of_device_id at91_udc_dt_ids[] = { | ||
| 1994 | { .compatible = "atmel,at91rm9200-udc" }, | ||
| 1995 | { /* sentinel */ } | ||
| 1996 | }; | ||
| 1997 | |||
| 1998 | MODULE_DEVICE_TABLE(of, at91_udc_dt_ids); | ||
| 1999 | #endif | ||
| 2000 | |||
| 2001 | static struct platform_driver at91_udc_driver = { | 2020 | static struct platform_driver at91_udc_driver = { |
| 2002 | .remove = __exit_p(at91udc_remove), | 2021 | .remove = __exit_p(at91udc_remove), |
| 2003 | .shutdown = at91udc_shutdown, | 2022 | .shutdown = at91udc_shutdown, |
| @@ -2005,7 +2024,7 @@ static struct platform_driver at91_udc_driver = { | |||
| 2005 | .resume = at91udc_resume, | 2024 | .resume = at91udc_resume, |
| 2006 | .driver = { | 2025 | .driver = { |
| 2007 | .name = (char *) driver_name, | 2026 | .name = (char *) driver_name, |
| 2008 | .of_match_table = of_match_ptr(at91_udc_dt_ids), | 2027 | .of_match_table = at91_udc_dt_ids, |
| 2009 | }, | 2028 | }, |
| 2010 | }; | 2029 | }; |
| 2011 | 2030 | ||
diff --git a/drivers/usb/gadget/udc/at91_udc.h b/drivers/usb/gadget/udc/at91_udc.h index 017524663381..4fc0daa6587f 100644 --- a/drivers/usb/gadget/udc/at91_udc.h +++ b/drivers/usb/gadget/udc/at91_udc.h | |||
| @@ -107,6 +107,11 @@ struct at91_ep { | |||
| 107 | unsigned fifo_bank:1; | 107 | unsigned fifo_bank:1; |
| 108 | }; | 108 | }; |
| 109 | 109 | ||
| 110 | struct at91_udc_caps { | ||
| 111 | int (*init)(struct at91_udc *udc); | ||
| 112 | void (*pullup)(struct at91_udc *udc, int is_on); | ||
| 113 | }; | ||
| 114 | |||
| 110 | /* | 115 | /* |
| 111 | * driver is non-SMP, and just blocks IRQs whenever it needs | 116 | * driver is non-SMP, and just blocks IRQs whenever it needs |
| 112 | * access protection for chip registers or driver state | 117 | * access protection for chip registers or driver state |
| @@ -115,6 +120,7 @@ struct at91_udc { | |||
| 115 | struct usb_gadget gadget; | 120 | struct usb_gadget gadget; |
| 116 | struct at91_ep ep[NUM_ENDPOINTS]; | 121 | struct at91_ep ep[NUM_ENDPOINTS]; |
| 117 | struct usb_gadget_driver *driver; | 122 | struct usb_gadget_driver *driver; |
| 123 | const struct at91_udc_caps *caps; | ||
| 118 | unsigned vbus:1; | 124 | unsigned vbus:1; |
| 119 | unsigned enabled:1; | 125 | unsigned enabled:1; |
| 120 | unsigned clocked:1; | 126 | unsigned clocked:1; |
| @@ -126,7 +132,7 @@ struct at91_udc { | |||
| 126 | unsigned active_suspend:1; | 132 | unsigned active_suspend:1; |
| 127 | u8 addr; | 133 | u8 addr; |
| 128 | struct at91_udc_data board; | 134 | struct at91_udc_data board; |
| 129 | struct clk *iclk, *fclk, *uclk; | 135 | struct clk *iclk, *fclk; |
| 130 | struct platform_device *pdev; | 136 | struct platform_device *pdev; |
| 131 | struct proc_dir_entry *pde; | 137 | struct proc_dir_entry *pde; |
| 132 | void __iomem *udp_baseaddr; | 138 | void __iomem *udp_baseaddr; |
| @@ -134,6 +140,7 @@ struct at91_udc { | |||
| 134 | spinlock_t lock; | 140 | spinlock_t lock; |
| 135 | struct timer_list vbus_timer; | 141 | struct timer_list vbus_timer; |
| 136 | struct work_struct vbus_timer_work; | 142 | struct work_struct vbus_timer_work; |
| 143 | struct regmap *matrix; | ||
| 137 | }; | 144 | }; |
| 138 | 145 | ||
| 139 | static inline struct at91_udc *to_udc(struct usb_gadget *g) | 146 | static inline struct at91_udc *to_udc(struct usb_gadget *g) |
diff --git a/include/linux/mfd/syscon/atmel-matrix.h b/include/linux/mfd/syscon/atmel-matrix.h new file mode 100644 index 000000000000..8293c3e2a82a --- /dev/null +++ b/include/linux/mfd/syscon/atmel-matrix.h | |||
| @@ -0,0 +1,117 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (C) 2014 Atmel Corporation. | ||
| 3 | * | ||
| 4 | * Memory Controllers (MATRIX, EBI) - System peripherals registers. | ||
| 5 | * | ||
| 6 | * This program is free software; you can redistribute it and/or modify | ||
| 7 | * it under the terms of the GNU General Public License as published by | ||
| 8 | * the Free Software Foundation; either version 2 of the License, or | ||
| 9 | * (at your option) any later version. | ||
| 10 | */ | ||
| 11 | |||
| 12 | #ifndef _LINUX_MFD_SYSCON_ATMEL_MATRIX_H | ||
| 13 | #define _LINUX_MFD_SYSCON_ATMEL_MATRIX_H | ||
| 14 | |||
| 15 | #define AT91SAM9260_MATRIX_MCFG 0x00 | ||
| 16 | #define AT91SAM9260_MATRIX_SCFG 0x40 | ||
| 17 | #define AT91SAM9260_MATRIX_PRS 0x80 | ||
| 18 | #define AT91SAM9260_MATRIX_MRCR 0x100 | ||
| 19 | #define AT91SAM9260_MATRIX_EBICSA 0x11c | ||
| 20 | |||
| 21 | #define AT91SAM9261_MATRIX_MRCR 0x0 | ||
| 22 | #define AT91SAM9261_MATRIX_SCFG 0x4 | ||
| 23 | #define AT91SAM9261_MATRIX_TCR 0x24 | ||
| 24 | #define AT91SAM9261_MATRIX_EBICSA 0x30 | ||
| 25 | #define AT91SAM9261_MATRIX_USBPUCR 0x34 | ||
| 26 | |||
| 27 | #define AT91SAM9263_MATRIX_MCFG 0x00 | ||
| 28 | #define AT91SAM9263_MATRIX_SCFG 0x40 | ||
| 29 | #define AT91SAM9263_MATRIX_PRS 0x80 | ||
| 30 | #define AT91SAM9263_MATRIX_MRCR 0x100 | ||
| 31 | #define AT91SAM9263_MATRIX_TCR 0x114 | ||
| 32 | #define AT91SAM9263_MATRIX_EBI0CSA 0x120 | ||
| 33 | #define AT91SAM9263_MATRIX_EBI1CSA 0x124 | ||
| 34 | |||
| 35 | #define AT91SAM9RL_MATRIX_MCFG 0x00 | ||
| 36 | #define AT91SAM9RL_MATRIX_SCFG 0x40 | ||
| 37 | #define AT91SAM9RL_MATRIX_PRS 0x80 | ||
| 38 | #define AT91SAM9RL_MATRIX_MRCR 0x100 | ||
| 39 | #define AT91SAM9RL_MATRIX_TCR 0x114 | ||
| 40 | #define AT91SAM9RL_MATRIX_EBICSA 0x120 | ||
| 41 | |||
| 42 | #define AT91SAM9G45_MATRIX_MCFG 0x00 | ||
| 43 | #define AT91SAM9G45_MATRIX_SCFG 0x40 | ||
| 44 | #define AT91SAM9G45_MATRIX_PRS 0x80 | ||
| 45 | #define AT91SAM9G45_MATRIX_MRCR 0x100 | ||
| 46 | #define AT91SAM9G45_MATRIX_TCR 0x110 | ||
| 47 | #define AT91SAM9G45_MATRIX_DDRMPR 0x118 | ||
| 48 | #define AT91SAM9G45_MATRIX_EBICSA 0x128 | ||
| 49 | |||
| 50 | #define AT91SAM9N12_MATRIX_MCFG 0x00 | ||
| 51 | #define AT91SAM9N12_MATRIX_SCFG 0x40 | ||
| 52 | #define AT91SAM9N12_MATRIX_PRS 0x80 | ||
| 53 | #define AT91SAM9N12_MATRIX_MRCR 0x100 | ||
| 54 | #define AT91SAM9N12_MATRIX_EBICSA 0x118 | ||
| 55 | |||
| 56 | #define AT91SAM9X5_MATRIX_MCFG 0x00 | ||
| 57 | #define AT91SAM9X5_MATRIX_SCFG 0x40 | ||
| 58 | #define AT91SAM9X5_MATRIX_PRS 0x80 | ||
| 59 | #define AT91SAM9X5_MATRIX_MRCR 0x100 | ||
| 60 | #define AT91SAM9X5_MATRIX_EBICSA 0x120 | ||
| 61 | |||
| 62 | #define SAMA5D3_MATRIX_MCFG 0x00 | ||
| 63 | #define SAMA5D3_MATRIX_SCFG 0x40 | ||
| 64 | #define SAMA5D3_MATRIX_PRS 0x80 | ||
| 65 | #define SAMA5D3_MATRIX_MRCR 0x100 | ||
| 66 | |||
| 67 | #define AT91_MATRIX_MCFG(o, x) ((o) + ((x) * 0x4)) | ||
| 68 | #define AT91_MATRIX_ULBT GENMASK(2, 0) | ||
| 69 | #define AT91_MATRIX_ULBT_INFINITE (0 << 0) | ||
| 70 | #define AT91_MATRIX_ULBT_SINGLE (1 << 0) | ||
| 71 | #define AT91_MATRIX_ULBT_FOUR (2 << 0) | ||
| 72 | #define AT91_MATRIX_ULBT_EIGHT (3 << 0) | ||
| 73 | #define AT91_MATRIX_ULBT_SIXTEEN (4 << 0) | ||
| 74 | |||
| 75 | #define AT91_MATRIX_SCFG(o, x) ((o) + ((x) * 0x4)) | ||
| 76 | #define AT91_MATRIX_SLOT_CYCLE GENMASK(7, 0) | ||
| 77 | #define AT91_MATRIX_DEFMSTR_TYPE GENMASK(17, 16) | ||
| 78 | #define AT91_MATRIX_DEFMSTR_TYPE_NONE (0 << 16) | ||
| 79 | #define AT91_MATRIX_DEFMSTR_TYPE_LAST (1 << 16) | ||
| 80 | #define AT91_MATRIX_DEFMSTR_TYPE_FIXED (2 << 16) | ||
| 81 | #define AT91_MATRIX_FIXED_DEFMSTR GENMASK(20, 18) | ||
| 82 | #define AT91_MATRIX_ARBT GENMASK(25, 24) | ||
| 83 | #define AT91_MATRIX_ARBT_ROUND_ROBIN (0 << 24) | ||
| 84 | #define AT91_MATRIX_ARBT_FIXED_PRIORITY (1 << 24) | ||
| 85 | |||
| 86 | #define AT91_MATRIX_ITCM_SIZE GENMASK(3, 0) | ||
| 87 | #define AT91_MATRIX_ITCM_0 (0 << 0) | ||
| 88 | #define AT91_MATRIX_ITCM_16 (5 << 0) | ||
| 89 | #define AT91_MATRIX_ITCM_32 (6 << 0) | ||
| 90 | #define AT91_MATRIX_ITCM_64 (7 << 0) | ||
| 91 | #define AT91_MATRIX_DTCM_SIZE GENMASK(7, 4) | ||
| 92 | #define AT91_MATRIX_DTCM_0 (0 << 4) | ||
| 93 | #define AT91_MATRIX_DTCM_16 (5 << 4) | ||
| 94 | #define AT91_MATRIX_DTCM_32 (6 << 4) | ||
| 95 | #define AT91_MATRIX_DTCM_64 (7 << 4) | ||
| 96 | |||
| 97 | #define AT91_MATRIX_PRAS(o, x) ((o) + ((x) * 0x8)) | ||
| 98 | #define AT91_MATRIX_PRBS(o, x) ((o) + ((x) * 0x8) + 0x4) | ||
| 99 | #define AT91_MATRIX_MPR(x) GENMASK(((x) * 0x4) + 1, ((x) * 0x4)) | ||
| 100 | |||
| 101 | #define AT91_MATRIX_RCB(x) BIT(x) | ||
| 102 | |||
| 103 | #define AT91_MATRIX_CSA(cs, val) (val << (cs)) | ||
| 104 | #define AT91_MATRIX_DBPUC BIT(8) | ||
| 105 | #define AT91_MATRIX_DBPDC BIT(9) | ||
| 106 | #define AT91_MATRIX_VDDIOMSEL BIT(16) | ||
| 107 | #define AT91_MATRIX_VDDIOMSEL_1_8V (0 << 16) | ||
| 108 | #define AT91_MATRIX_VDDIOMSEL_3_3V (1 << 16) | ||
| 109 | #define AT91_MATRIX_EBI_IOSR BIT(17) | ||
| 110 | #define AT91_MATRIX_DDR_IOSR BIT(18) | ||
| 111 | #define AT91_MATRIX_NFD0_SELECT BIT(24) | ||
| 112 | #define AT91_MATRIX_DDR_MP_EN BIT(25) | ||
| 113 | #define AT91_MATRIX_EBI_NUM_CS 8 | ||
| 114 | |||
| 115 | #define AT91_MATRIX_USBPUCR_PUON BIT(30) | ||
| 116 | |||
| 117 | #endif /* _LINUX_MFD_SYSCON_ATMEL_MATRIX_H */ | ||
diff --git a/include/linux/mfd/syscon/atmel-smc.h b/include/linux/mfd/syscon/atmel-smc.h new file mode 100644 index 000000000000..be6ebe64eebe --- /dev/null +++ b/include/linux/mfd/syscon/atmel-smc.h | |||
| @@ -0,0 +1,173 @@ | |||
| 1 | /* | ||
| 2 | * Atmel SMC (Static Memory Controller) register offsets and bit definitions. | ||
| 3 | * | ||
| 4 | * Copyright (C) 2014 Atmel | ||
| 5 | * Copyright (C) 2014 Free Electrons | ||
| 6 | * | ||
| 7 | * Author: Boris Brezillon <boris.brezillon@free-electrons.com> | ||
| 8 | * | ||
| 9 | * This program is free software; you can redistribute it and/or modify | ||
| 10 | * it under the terms of the GNU General Public License version 2 as | ||
| 11 | * published by the Free Software Foundation. | ||
| 12 | */ | ||
| 13 | |||
| 14 | #ifndef _LINUX_MFD_SYSCON_ATMEL_SMC_H_ | ||
| 15 | #define _LINUX_MFD_SYSCON_ATMEL_SMC_H_ | ||
| 16 | |||
| 17 | #include <linux/kernel.h> | ||
| 18 | #include <linux/regmap.h> | ||
| 19 | |||
| 20 | #define AT91SAM9_SMC_GENERIC 0x00 | ||
| 21 | #define AT91SAM9_SMC_GENERIC_BLK_SZ 0x10 | ||
| 22 | |||
| 23 | #define SAMA5_SMC_GENERIC 0x600 | ||
| 24 | #define SAMA5_SMC_GENERIC_BLK_SZ 0x14 | ||
| 25 | |||
| 26 | #define AT91SAM9_SMC_SETUP(o) ((o) + 0x00) | ||
| 27 | #define AT91SAM9_SMC_NWESETUP(x) (x) | ||
| 28 | #define AT91SAM9_SMC_NCS_WRSETUP(x) ((x) << 8) | ||
| 29 | #define AT91SAM9_SMC_NRDSETUP(x) ((x) << 16) | ||
| 30 | #define AT91SAM9_SMC_NCS_NRDSETUP(x) ((x) << 24) | ||
| 31 | |||
| 32 | #define AT91SAM9_SMC_PULSE(o) ((o) + 0x04) | ||
| 33 | #define AT91SAM9_SMC_NWEPULSE(x) (x) | ||
| 34 | #define AT91SAM9_SMC_NCS_WRPULSE(x) ((x) << 8) | ||
| 35 | #define AT91SAM9_SMC_NRDPULSE(x) ((x) << 16) | ||
| 36 | #define AT91SAM9_SMC_NCS_NRDPULSE(x) ((x) << 24) | ||
| 37 | |||
| 38 | #define AT91SAM9_SMC_CYCLE(o) ((o) + 0x08) | ||
| 39 | #define AT91SAM9_SMC_NWECYCLE(x) (x) | ||
| 40 | #define AT91SAM9_SMC_NRDCYCLE(x) ((x) << 16) | ||
| 41 | |||
| 42 | #define AT91SAM9_SMC_MODE(o) ((o) + 0x0c) | ||
| 43 | #define SAMA5_SMC_MODE(o) ((o) + 0x10) | ||
| 44 | #define AT91_SMC_READMODE BIT(0) | ||
| 45 | #define AT91_SMC_READMODE_NCS (0 << 0) | ||
| 46 | #define AT91_SMC_READMODE_NRD (1 << 0) | ||
| 47 | #define AT91_SMC_WRITEMODE BIT(1) | ||
| 48 | #define AT91_SMC_WRITEMODE_NCS (0 << 1) | ||
| 49 | #define AT91_SMC_WRITEMODE_NWE (1 << 1) | ||
| 50 | #define AT91_SMC_EXNWMODE GENMASK(5, 4) | ||
| 51 | #define AT91_SMC_EXNWMODE_DISABLE (0 << 4) | ||
| 52 | #define AT91_SMC_EXNWMODE_FROZEN (2 << 4) | ||
| 53 | #define AT91_SMC_EXNWMODE_READY (3 << 4) | ||
| 54 | #define AT91_SMC_BAT BIT(8) | ||
| 55 | #define AT91_SMC_BAT_SELECT (0 << 8) | ||
| 56 | #define AT91_SMC_BAT_WRITE (1 << 8) | ||
| 57 | #define AT91_SMC_DBW GENMASK(13, 12) | ||
| 58 | #define AT91_SMC_DBW_8 (0 << 12) | ||
| 59 | #define AT91_SMC_DBW_16 (1 << 12) | ||
| 60 | #define AT91_SMC_DBW_32 (2 << 12) | ||
| 61 | #define AT91_SMC_TDF GENMASK(19, 16) | ||
| 62 | #define AT91_SMC_TDF_(x) ((((x) - 1) << 16) & AT91_SMC_TDF) | ||
| 63 | #define AT91_SMC_TDF_MAX 16 | ||
| 64 | #define AT91_SMC_TDFMODE_OPTIMIZED BIT(20) | ||
| 65 | #define AT91_SMC_PMEN BIT(24) | ||
| 66 | #define AT91_SMC_PS GENMASK(29, 28) | ||
| 67 | #define AT91_SMC_PS_4 (0 << 28) | ||
| 68 | #define AT91_SMC_PS_8 (1 << 28) | ||
| 69 | #define AT91_SMC_PS_16 (2 << 28) | ||
| 70 | #define AT91_SMC_PS_32 (3 << 28) | ||
| 71 | |||
| 72 | |||
| 73 | /* | ||
| 74 | * This function converts a setup timing expressed in nanoseconds into an | ||
| 75 | * encoded value that can be written in the SMC_SETUP register. | ||
| 76 | * | ||
| 77 | * The following formula is described in atmel datasheets (section | ||
| 78 | * "SMC Setup Register"): | ||
| 79 | * | ||
| 80 | * setup length = (128* SETUP[5] + SETUP[4:0]) | ||
| 81 | * | ||
| 82 | * where setup length is the timing expressed in cycles. | ||
| 83 | */ | ||
| 84 | static inline u32 at91sam9_smc_setup_ns_to_cycles(unsigned int clk_rate, | ||
| 85 | u32 timing_ns) | ||
| 86 | { | ||
| 87 | u32 clk_period = DIV_ROUND_UP(NSEC_PER_SEC, clk_rate); | ||
| 88 | u32 coded_cycles = 0; | ||
| 89 | u32 cycles; | ||
| 90 | |||
| 91 | cycles = DIV_ROUND_UP(timing_ns, clk_period); | ||
| 92 | if (cycles / 32) { | ||
| 93 | coded_cycles |= 1 << 5; | ||
| 94 | if (cycles < 128) | ||
| 95 | cycles = 0; | ||
| 96 | } | ||
| 97 | |||
| 98 | coded_cycles |= cycles % 32; | ||
| 99 | |||
| 100 | return coded_cycles; | ||
| 101 | } | ||
| 102 | |||
| 103 | /* | ||
| 104 | * This function converts a pulse timing expressed in nanoseconds into an | ||
| 105 | * encoded value that can be written in the SMC_PULSE register. | ||
| 106 | * | ||
| 107 | * The following formula is described in atmel datasheets (section | ||
| 108 | * "SMC Pulse Register"): | ||
| 109 | * | ||
| 110 | * pulse length = (256* PULSE[6] + PULSE[5:0]) | ||
| 111 | * | ||
| 112 | * where pulse length is the timing expressed in cycles. | ||
| 113 | */ | ||
| 114 | static inline u32 at91sam9_smc_pulse_ns_to_cycles(unsigned int clk_rate, | ||
| 115 | u32 timing_ns) | ||
| 116 | { | ||
| 117 | u32 clk_period = DIV_ROUND_UP(NSEC_PER_SEC, clk_rate); | ||
| 118 | u32 coded_cycles = 0; | ||
| 119 | u32 cycles; | ||
| 120 | |||
| 121 | cycles = DIV_ROUND_UP(timing_ns, clk_period); | ||
| 122 | if (cycles / 64) { | ||
| 123 | coded_cycles |= 1 << 6; | ||
| 124 | if (cycles < 256) | ||
| 125 | cycles = 0; | ||
| 126 | } | ||
| 127 | |||
| 128 | coded_cycles |= cycles % 64; | ||
| 129 | |||
| 130 | return coded_cycles; | ||
| 131 | } | ||
| 132 | |||
| 133 | /* | ||
| 134 | * This function converts a cycle timing expressed in nanoseconds into an | ||
| 135 | * encoded value that can be written in the SMC_CYCLE register. | ||
| 136 | * | ||
| 137 | * The following formula is described in atmel datasheets (section | ||
| 138 | * "SMC Cycle Register"): | ||
| 139 | * | ||
| 140 | * cycle length = (CYCLE[8:7]*256 + CYCLE[6:0]) | ||
| 141 | * | ||
| 142 | * where cycle length is the timing expressed in cycles. | ||
| 143 | */ | ||
| 144 | static inline u32 at91sam9_smc_cycle_ns_to_cycles(unsigned int clk_rate, | ||
| 145 | u32 timing_ns) | ||
| 146 | { | ||
| 147 | u32 clk_period = DIV_ROUND_UP(NSEC_PER_SEC, clk_rate); | ||
| 148 | u32 coded_cycles = 0; | ||
| 149 | u32 cycles; | ||
| 150 | |||
| 151 | cycles = DIV_ROUND_UP(timing_ns, clk_period); | ||
| 152 | if (cycles / 128) { | ||
| 153 | coded_cycles = cycles / 256; | ||
| 154 | cycles %= 256; | ||
| 155 | if (cycles >= 128) { | ||
| 156 | coded_cycles++; | ||
| 157 | cycles = 0; | ||
| 158 | } | ||
| 159 | |||
| 160 | if (coded_cycles > 0x3) { | ||
| 161 | coded_cycles = 0x3; | ||
| 162 | cycles = 0x7f; | ||
| 163 | } | ||
| 164 | |||
| 165 | coded_cycles <<= 7; | ||
| 166 | } | ||
| 167 | |||
| 168 | coded_cycles |= cycles % 128; | ||
| 169 | |||
| 170 | return coded_cycles; | ||
| 171 | } | ||
| 172 | |||
| 173 | #endif /* _LINUX_MFD_SYSCON_ATMEL_SMC_H_ */ | ||
