1 From fa735ad1afeb5791d5562617b9bbed74574d3e81 Mon Sep 17 00:00:00 2001
2 From: Linus Walleij <linus.walleij@linaro.org>
3 Date: Wed, 18 Jan 2023 08:09:17 +0100
4 Subject: [PATCH 17/29] usb: fotg210: Acquire memory resource in core
6 The subdrivers are obtaining and mapping the memory resource
7 separately. Create a common state container for the shared
8 resources and start populating this by acquiring the IO
9 memory resource and remap it and pass this to the subdrivers
10 for host and peripheral.
12 Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
13 Link: https://lore.kernel.org/r/20230103-gemini-fotg210-usb-v2-3-100388af9810@linaro.org
14 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
16 --- a/drivers/usb/fotg210/fotg210-core.c
17 +++ b/drivers/usb/fotg210/fotg210-core.c
19 #define GEMINI_MISC_USB0_MINI_B BIT(29)
20 #define GEMINI_MISC_USB1_MINI_B BIT(30)
22 -static int fotg210_gemini_init(struct device *dev, struct resource *res,
23 +static int fotg210_gemini_init(struct fotg210 *fotg, struct resource *res,
24 enum usb_dr_mode mode)
26 + struct device *dev = fotg->dev;
27 struct device_node *np = dev->of_node;
30 @@ -47,6 +48,7 @@ static int fotg210_gemini_init(struct de
31 dev_err(dev, "no syscon\n");
35 wakeup = of_property_read_bool(np, "wakeup-source");
38 @@ -55,6 +57,7 @@ static int fotg210_gemini_init(struct de
41 if (res->start == 0x69000000) {
42 + fotg->port = GEMINI_PORT_1;
43 mask = GEMINI_MISC_USB1_VBUS_ON | GEMINI_MISC_USB1_MINI_B |
44 GEMINI_MISC_USB1_WAKEUP;
45 if (mode == USB_DR_MODE_HOST)
46 @@ -64,6 +67,7 @@ static int fotg210_gemini_init(struct de
48 val |= GEMINI_MISC_USB1_WAKEUP;
50 + fotg->port = GEMINI_PORT_0;
51 mask = GEMINI_MISC_USB0_VBUS_ON | GEMINI_MISC_USB0_MINI_B |
52 GEMINI_MISC_USB0_WAKEUP;
53 if (mode == USB_DR_MODE_HOST)
54 @@ -89,23 +93,34 @@ static int fotg210_probe(struct platform
56 struct device *dev = &pdev->dev;
57 enum usb_dr_mode mode;
58 + struct fotg210 *fotg;
61 + fotg = devm_kzalloc(dev, sizeof(*fotg), GFP_KERNEL);
66 + fotg->res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
70 + fotg->base = devm_ioremap_resource(dev, fotg->res);
74 mode = usb_get_dr_mode(dev);
76 if (of_device_is_compatible(dev->of_node, "cortina,gemini-usb")) {
77 - struct resource *res;
79 - res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
80 - ret = fotg210_gemini_init(dev, res, mode);
81 + ret = fotg210_gemini_init(fotg, fotg->res, mode);
86 if (mode == USB_DR_MODE_PERIPHERAL)
87 - ret = fotg210_udc_probe(pdev);
88 + ret = fotg210_udc_probe(pdev, fotg);
90 - ret = fotg210_hcd_probe(pdev);
91 + ret = fotg210_hcd_probe(pdev, fotg);
95 --- a/drivers/usb/fotg210/fotg210-hcd.c
96 +++ b/drivers/usb/fotg210/fotg210-hcd.c
97 @@ -5557,11 +5557,10 @@ static void fotg210_init(struct fotg210_
98 * then invokes the start() method for the HCD associated with it
99 * through the hotplug entry's driver_data.
101 -int fotg210_hcd_probe(struct platform_device *pdev)
102 +int fotg210_hcd_probe(struct platform_device *pdev, struct fotg210 *fotg)
104 struct device *dev = &pdev->dev;
106 - struct resource *res;
109 struct fotg210_hcd *fotg210;
110 @@ -5585,18 +5584,14 @@ int fotg210_hcd_probe(struct platform_de
114 - res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
115 - hcd->regs = devm_ioremap_resource(&pdev->dev, res);
116 - if (IS_ERR(hcd->regs)) {
117 - retval = PTR_ERR(hcd->regs);
118 - goto failed_put_hcd;
120 + hcd->regs = fotg->base;
122 - hcd->rsrc_start = res->start;
123 - hcd->rsrc_len = resource_size(res);
124 + hcd->rsrc_start = fotg->res->start;
125 + hcd->rsrc_len = resource_size(fotg->res);
127 fotg210 = hcd_to_fotg210(hcd);
129 + fotg210->fotg = fotg;
130 fotg210->caps = hcd->regs;
132 /* It's OK not to supply this clock */
133 --- a/drivers/usb/fotg210/fotg210-hcd.h
134 +++ b/drivers/usb/fotg210/fotg210-hcd.h
135 @@ -182,6 +182,7 @@ struct fotg210_hcd { /* one per contro
136 # define INCR(x) do {} while (0)
139 + struct fotg210 *fotg; /* Overarching FOTG210 device */
143 --- a/drivers/usb/fotg210/fotg210-udc.c
144 +++ b/drivers/usb/fotg210/fotg210-udc.c
145 @@ -1155,21 +1155,14 @@ int fotg210_udc_remove(struct platform_d
149 -int fotg210_udc_probe(struct platform_device *pdev)
150 +int fotg210_udc_probe(struct platform_device *pdev, struct fotg210 *fotg)
152 - struct resource *res;
153 struct fotg210_udc *fotg210 = NULL;
154 struct device *dev = &pdev->dev;
159 - res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
161 - pr_err("platform_get_resource error.\n");
165 irq = platform_get_irq(pdev, 0);
167 pr_err("could not get irq\n");
168 @@ -1182,6 +1175,7 @@ int fotg210_udc_probe(struct platform_de
172 + fotg210->fotg = fotg;
174 /* It's OK not to supply this clock */
175 fotg210->pclk = devm_clk_get(dev, "PCLK");
176 @@ -1222,11 +1216,7 @@ int fotg210_udc_probe(struct platform_de
180 - fotg210->reg = ioremap(res->start, resource_size(res));
181 - if (fotg210->reg == NULL) {
182 - dev_err(dev, "ioremap error\n");
185 + fotg210->reg = fotg->base;
187 spin_lock_init(&fotg210->lock);
189 --- a/drivers/usb/fotg210/fotg210-udc.h
190 +++ b/drivers/usb/fotg210/fotg210-udc.h
191 @@ -236,6 +236,7 @@ struct fotg210_udc {
192 unsigned long irq_trigger;
195 + struct fotg210 *fotg;
197 struct usb_gadget gadget;
198 struct usb_gadget_driver *driver;
199 --- a/drivers/usb/fotg210/fotg210.h
200 +++ b/drivers/usb/fotg210/fotg210.h
206 + GEMINI_PORT_NONE = 0,
212 + struct device *dev;
213 + struct resource *res;
214 + void __iomem *base;
215 + struct regmap *map;
216 + enum gemini_port port;
219 #ifdef CONFIG_USB_FOTG210_HCD
220 -int fotg210_hcd_probe(struct platform_device *pdev);
221 +int fotg210_hcd_probe(struct platform_device *pdev, struct fotg210 *fotg);
222 int fotg210_hcd_remove(struct platform_device *pdev);
223 int fotg210_hcd_init(void);
224 void fotg210_hcd_cleanup(void);
226 -static inline int fotg210_hcd_probe(struct platform_device *pdev)
227 +static inline int fotg210_hcd_probe(struct platform_device *pdev,
228 + struct fotg210 *fotg)
232 @@ -26,10 +41,11 @@ static inline void fotg210_hcd_cleanup(v
235 #ifdef CONFIG_USB_FOTG210_UDC
236 -int fotg210_udc_probe(struct platform_device *pdev);
237 +int fotg210_udc_probe(struct platform_device *pdev, struct fotg210 *fotg);
238 int fotg210_udc_remove(struct platform_device *pdev);
240 -static inline int fotg210_udc_probe(struct platform_device *pdev)
241 +static inline int fotg210_udc_probe(struct platform_device *pdev,
242 + struct fotg210 *fotg)