Boris BREZILLON | c84a61d | 2013-10-17 18:55:41 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2013 Boris BREZILLON <b.brezillon@overkiz.com> |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify |
| 5 | * it under the terms of the GNU General Public License as published by |
| 6 | * the Free Software Foundation; either version 2 of the License, or |
| 7 | * (at your option) any later version. |
| 8 | * |
| 9 | */ |
| 10 | |
| 11 | #include <linux/clk-provider.h> |
| 12 | #include <linux/clkdev.h> |
| 13 | #include <linux/clk/at91_pmc.h> |
| 14 | #include <linux/of.h> |
| 15 | #include <linux/of_address.h> |
| 16 | #include <linux/io.h> |
| 17 | |
| 18 | #include "pmc.h" |
| 19 | |
| 20 | #define USB_SOURCE_MAX 2 |
| 21 | |
| 22 | #define SAM9X5_USB_DIV_SHIFT 8 |
| 23 | #define SAM9X5_USB_MAX_DIV 0xf |
| 24 | |
| 25 | #define RM9200_USB_DIV_SHIFT 28 |
| 26 | #define RM9200_USB_DIV_TAB_SIZE 4 |
| 27 | |
| 28 | struct at91sam9x5_clk_usb { |
| 29 | struct clk_hw hw; |
| 30 | struct at91_pmc *pmc; |
| 31 | }; |
| 32 | |
| 33 | #define to_at91sam9x5_clk_usb(hw) \ |
| 34 | container_of(hw, struct at91sam9x5_clk_usb, hw) |
| 35 | |
| 36 | struct at91rm9200_clk_usb { |
| 37 | struct clk_hw hw; |
| 38 | struct at91_pmc *pmc; |
| 39 | u32 divisors[4]; |
| 40 | }; |
| 41 | |
| 42 | #define to_at91rm9200_clk_usb(hw) \ |
| 43 | container_of(hw, struct at91rm9200_clk_usb, hw) |
| 44 | |
| 45 | static unsigned long at91sam9x5_clk_usb_recalc_rate(struct clk_hw *hw, |
| 46 | unsigned long parent_rate) |
| 47 | { |
| 48 | u32 tmp; |
| 49 | u8 usbdiv; |
| 50 | struct at91sam9x5_clk_usb *usb = to_at91sam9x5_clk_usb(hw); |
| 51 | struct at91_pmc *pmc = usb->pmc; |
| 52 | |
| 53 | tmp = pmc_read(pmc, AT91_PMC_USB); |
| 54 | usbdiv = (tmp & AT91_PMC_OHCIUSBDIV) >> SAM9X5_USB_DIV_SHIFT; |
Boris Brezillon | 69daf75 | 2014-11-17 14:16:56 +0100 | [diff] [blame] | 55 | |
| 56 | return DIV_ROUND_CLOSEST(parent_rate, (usbdiv + 1)); |
Boris BREZILLON | c84a61d | 2013-10-17 18:55:41 +0200 | [diff] [blame] | 57 | } |
| 58 | |
Boris Brezillon | 0817b62 | 2015-07-07 20:48:08 +0200 | [diff] [blame^] | 59 | static int at91sam9x5_clk_usb_determine_rate(struct clk_hw *hw, |
| 60 | struct clk_rate_request *req) |
Boris BREZILLON | c84a61d | 2013-10-17 18:55:41 +0200 | [diff] [blame] | 61 | { |
Boris Brezillon | 4591243 | 2015-03-29 03:45:33 +0200 | [diff] [blame] | 62 | struct clk *parent = NULL; |
| 63 | long best_rate = -EINVAL; |
| 64 | unsigned long tmp_rate; |
| 65 | int best_diff = -1; |
| 66 | int tmp_diff; |
| 67 | int i; |
Boris Brezillon | 69daf75 | 2014-11-17 14:16:56 +0100 | [diff] [blame] | 68 | |
Boris Brezillon | 4591243 | 2015-03-29 03:45:33 +0200 | [diff] [blame] | 69 | for (i = 0; i < __clk_get_num_parents(hw->clk); i++) { |
| 70 | int div; |
Boris BREZILLON | c84a61d | 2013-10-17 18:55:41 +0200 | [diff] [blame] | 71 | |
Boris Brezillon | 4591243 | 2015-03-29 03:45:33 +0200 | [diff] [blame] | 72 | parent = clk_get_parent_by_index(hw->clk, i); |
| 73 | if (!parent) |
| 74 | continue; |
Boris BREZILLON | c84a61d | 2013-10-17 18:55:41 +0200 | [diff] [blame] | 75 | |
Boris Brezillon | 4591243 | 2015-03-29 03:45:33 +0200 | [diff] [blame] | 76 | for (div = 1; div < SAM9X5_USB_MAX_DIV + 2; div++) { |
| 77 | unsigned long tmp_parent_rate; |
Boris BREZILLON | c84a61d | 2013-10-17 18:55:41 +0200 | [diff] [blame] | 78 | |
Boris Brezillon | 0817b62 | 2015-07-07 20:48:08 +0200 | [diff] [blame^] | 79 | tmp_parent_rate = req->rate * div; |
Boris Brezillon | 4591243 | 2015-03-29 03:45:33 +0200 | [diff] [blame] | 80 | tmp_parent_rate = __clk_round_rate(parent, |
| 81 | tmp_parent_rate); |
| 82 | tmp_rate = DIV_ROUND_CLOSEST(tmp_parent_rate, div); |
Boris Brezillon | 0817b62 | 2015-07-07 20:48:08 +0200 | [diff] [blame^] | 83 | if (tmp_rate < req->rate) |
| 84 | tmp_diff = req->rate - tmp_rate; |
Boris Brezillon | 4591243 | 2015-03-29 03:45:33 +0200 | [diff] [blame] | 85 | else |
Boris Brezillon | 0817b62 | 2015-07-07 20:48:08 +0200 | [diff] [blame^] | 86 | tmp_diff = tmp_rate - req->rate; |
Boris Brezillon | 4591243 | 2015-03-29 03:45:33 +0200 | [diff] [blame] | 87 | |
| 88 | if (best_diff < 0 || best_diff > tmp_diff) { |
| 89 | best_rate = tmp_rate; |
| 90 | best_diff = tmp_diff; |
Boris Brezillon | 0817b62 | 2015-07-07 20:48:08 +0200 | [diff] [blame^] | 91 | req->best_parent_rate = tmp_parent_rate; |
| 92 | req->best_parent_hw = __clk_get_hw(parent); |
Boris Brezillon | 4591243 | 2015-03-29 03:45:33 +0200 | [diff] [blame] | 93 | } |
| 94 | |
Boris Brezillon | 0817b62 | 2015-07-07 20:48:08 +0200 | [diff] [blame^] | 95 | if (!best_diff || tmp_rate < req->rate) |
Boris Brezillon | 4591243 | 2015-03-29 03:45:33 +0200 | [diff] [blame] | 96 | break; |
| 97 | } |
| 98 | |
| 99 | if (!best_diff) |
| 100 | break; |
| 101 | } |
| 102 | |
Boris Brezillon | 0817b62 | 2015-07-07 20:48:08 +0200 | [diff] [blame^] | 103 | if (best_rate < 0) |
| 104 | return best_rate; |
| 105 | |
| 106 | req->rate = best_rate; |
| 107 | return 0; |
Boris BREZILLON | c84a61d | 2013-10-17 18:55:41 +0200 | [diff] [blame] | 108 | } |
| 109 | |
| 110 | static int at91sam9x5_clk_usb_set_parent(struct clk_hw *hw, u8 index) |
| 111 | { |
| 112 | u32 tmp; |
| 113 | struct at91sam9x5_clk_usb *usb = to_at91sam9x5_clk_usb(hw); |
| 114 | struct at91_pmc *pmc = usb->pmc; |
| 115 | |
| 116 | if (index > 1) |
| 117 | return -EINVAL; |
| 118 | tmp = pmc_read(pmc, AT91_PMC_USB) & ~AT91_PMC_USBS; |
| 119 | if (index) |
| 120 | tmp |= AT91_PMC_USBS; |
| 121 | pmc_write(pmc, AT91_PMC_USB, tmp); |
| 122 | return 0; |
| 123 | } |
| 124 | |
| 125 | static u8 at91sam9x5_clk_usb_get_parent(struct clk_hw *hw) |
| 126 | { |
| 127 | struct at91sam9x5_clk_usb *usb = to_at91sam9x5_clk_usb(hw); |
| 128 | struct at91_pmc *pmc = usb->pmc; |
| 129 | |
| 130 | return pmc_read(pmc, AT91_PMC_USB) & AT91_PMC_USBS; |
| 131 | } |
| 132 | |
| 133 | static int at91sam9x5_clk_usb_set_rate(struct clk_hw *hw, unsigned long rate, |
| 134 | unsigned long parent_rate) |
| 135 | { |
| 136 | u32 tmp; |
| 137 | struct at91sam9x5_clk_usb *usb = to_at91sam9x5_clk_usb(hw); |
| 138 | struct at91_pmc *pmc = usb->pmc; |
Boris Brezillon | 69daf75 | 2014-11-17 14:16:56 +0100 | [diff] [blame] | 139 | unsigned long div; |
Boris BREZILLON | c84a61d | 2013-10-17 18:55:41 +0200 | [diff] [blame] | 140 | |
Boris Brezillon | 69daf75 | 2014-11-17 14:16:56 +0100 | [diff] [blame] | 141 | if (!rate) |
| 142 | return -EINVAL; |
| 143 | |
| 144 | div = DIV_ROUND_CLOSEST(parent_rate, rate); |
| 145 | if (div > SAM9X5_USB_MAX_DIV + 1 || !div) |
Boris BREZILLON | c84a61d | 2013-10-17 18:55:41 +0200 | [diff] [blame] | 146 | return -EINVAL; |
| 147 | |
| 148 | tmp = pmc_read(pmc, AT91_PMC_USB) & ~AT91_PMC_OHCIUSBDIV; |
| 149 | tmp |= (div - 1) << SAM9X5_USB_DIV_SHIFT; |
| 150 | pmc_write(pmc, AT91_PMC_USB, tmp); |
| 151 | |
| 152 | return 0; |
| 153 | } |
| 154 | |
| 155 | static const struct clk_ops at91sam9x5_usb_ops = { |
| 156 | .recalc_rate = at91sam9x5_clk_usb_recalc_rate, |
Boris Brezillon | 4591243 | 2015-03-29 03:45:33 +0200 | [diff] [blame] | 157 | .determine_rate = at91sam9x5_clk_usb_determine_rate, |
Boris BREZILLON | c84a61d | 2013-10-17 18:55:41 +0200 | [diff] [blame] | 158 | .get_parent = at91sam9x5_clk_usb_get_parent, |
| 159 | .set_parent = at91sam9x5_clk_usb_set_parent, |
| 160 | .set_rate = at91sam9x5_clk_usb_set_rate, |
| 161 | }; |
| 162 | |
| 163 | static int at91sam9n12_clk_usb_enable(struct clk_hw *hw) |
| 164 | { |
| 165 | struct at91sam9x5_clk_usb *usb = to_at91sam9x5_clk_usb(hw); |
| 166 | struct at91_pmc *pmc = usb->pmc; |
| 167 | |
| 168 | pmc_write(pmc, AT91_PMC_USB, |
| 169 | pmc_read(pmc, AT91_PMC_USB) | AT91_PMC_USBS); |
| 170 | return 0; |
| 171 | } |
| 172 | |
| 173 | static void at91sam9n12_clk_usb_disable(struct clk_hw *hw) |
| 174 | { |
| 175 | struct at91sam9x5_clk_usb *usb = to_at91sam9x5_clk_usb(hw); |
| 176 | struct at91_pmc *pmc = usb->pmc; |
| 177 | |
| 178 | pmc_write(pmc, AT91_PMC_USB, |
| 179 | pmc_read(pmc, AT91_PMC_USB) & ~AT91_PMC_USBS); |
| 180 | } |
| 181 | |
| 182 | static int at91sam9n12_clk_usb_is_enabled(struct clk_hw *hw) |
| 183 | { |
| 184 | struct at91sam9x5_clk_usb *usb = to_at91sam9x5_clk_usb(hw); |
| 185 | struct at91_pmc *pmc = usb->pmc; |
| 186 | |
| 187 | return !!(pmc_read(pmc, AT91_PMC_USB) & AT91_PMC_USBS); |
| 188 | } |
| 189 | |
| 190 | static const struct clk_ops at91sam9n12_usb_ops = { |
| 191 | .enable = at91sam9n12_clk_usb_enable, |
| 192 | .disable = at91sam9n12_clk_usb_disable, |
| 193 | .is_enabled = at91sam9n12_clk_usb_is_enabled, |
| 194 | .recalc_rate = at91sam9x5_clk_usb_recalc_rate, |
Boris Brezillon | 4591243 | 2015-03-29 03:45:33 +0200 | [diff] [blame] | 195 | .determine_rate = at91sam9x5_clk_usb_determine_rate, |
Boris BREZILLON | c84a61d | 2013-10-17 18:55:41 +0200 | [diff] [blame] | 196 | .set_rate = at91sam9x5_clk_usb_set_rate, |
| 197 | }; |
| 198 | |
| 199 | static struct clk * __init |
| 200 | at91sam9x5_clk_register_usb(struct at91_pmc *pmc, const char *name, |
| 201 | const char **parent_names, u8 num_parents) |
| 202 | { |
| 203 | struct at91sam9x5_clk_usb *usb; |
| 204 | struct clk *clk = NULL; |
| 205 | struct clk_init_data init; |
| 206 | |
| 207 | usb = kzalloc(sizeof(*usb), GFP_KERNEL); |
| 208 | if (!usb) |
| 209 | return ERR_PTR(-ENOMEM); |
| 210 | |
| 211 | init.name = name; |
| 212 | init.ops = &at91sam9x5_usb_ops; |
| 213 | init.parent_names = parent_names; |
| 214 | init.num_parents = num_parents; |
Boris Brezillon | 4591243 | 2015-03-29 03:45:33 +0200 | [diff] [blame] | 215 | init.flags = CLK_SET_RATE_GATE | CLK_SET_PARENT_GATE | |
| 216 | CLK_SET_RATE_PARENT; |
Boris BREZILLON | c84a61d | 2013-10-17 18:55:41 +0200 | [diff] [blame] | 217 | |
| 218 | usb->hw.init = &init; |
| 219 | usb->pmc = pmc; |
| 220 | |
| 221 | clk = clk_register(NULL, &usb->hw); |
| 222 | if (IS_ERR(clk)) |
| 223 | kfree(usb); |
| 224 | |
| 225 | return clk; |
| 226 | } |
| 227 | |
| 228 | static struct clk * __init |
| 229 | at91sam9n12_clk_register_usb(struct at91_pmc *pmc, const char *name, |
| 230 | const char *parent_name) |
| 231 | { |
| 232 | struct at91sam9x5_clk_usb *usb; |
| 233 | struct clk *clk = NULL; |
| 234 | struct clk_init_data init; |
| 235 | |
| 236 | usb = kzalloc(sizeof(*usb), GFP_KERNEL); |
| 237 | if (!usb) |
| 238 | return ERR_PTR(-ENOMEM); |
| 239 | |
| 240 | init.name = name; |
| 241 | init.ops = &at91sam9n12_usb_ops; |
| 242 | init.parent_names = &parent_name; |
| 243 | init.num_parents = 1; |
Boris Brezillon | 4591243 | 2015-03-29 03:45:33 +0200 | [diff] [blame] | 244 | init.flags = CLK_SET_RATE_GATE | CLK_SET_RATE_PARENT; |
Boris BREZILLON | c84a61d | 2013-10-17 18:55:41 +0200 | [diff] [blame] | 245 | |
| 246 | usb->hw.init = &init; |
| 247 | usb->pmc = pmc; |
| 248 | |
| 249 | clk = clk_register(NULL, &usb->hw); |
| 250 | if (IS_ERR(clk)) |
| 251 | kfree(usb); |
| 252 | |
| 253 | return clk; |
| 254 | } |
| 255 | |
| 256 | static unsigned long at91rm9200_clk_usb_recalc_rate(struct clk_hw *hw, |
| 257 | unsigned long parent_rate) |
| 258 | { |
| 259 | struct at91rm9200_clk_usb *usb = to_at91rm9200_clk_usb(hw); |
| 260 | struct at91_pmc *pmc = usb->pmc; |
| 261 | u32 tmp; |
| 262 | u8 usbdiv; |
| 263 | |
| 264 | tmp = pmc_read(pmc, AT91_CKGR_PLLBR); |
| 265 | usbdiv = (tmp & AT91_PMC_USBDIV) >> RM9200_USB_DIV_SHIFT; |
| 266 | if (usb->divisors[usbdiv]) |
| 267 | return parent_rate / usb->divisors[usbdiv]; |
| 268 | |
| 269 | return 0; |
| 270 | } |
| 271 | |
| 272 | static long at91rm9200_clk_usb_round_rate(struct clk_hw *hw, unsigned long rate, |
| 273 | unsigned long *parent_rate) |
| 274 | { |
| 275 | struct at91rm9200_clk_usb *usb = to_at91rm9200_clk_usb(hw); |
Boris BREZILLON | 13a6073 | 2014-09-02 09:50:17 +0200 | [diff] [blame] | 276 | struct clk *parent = __clk_get_parent(hw->clk); |
Boris BREZILLON | c84a61d | 2013-10-17 18:55:41 +0200 | [diff] [blame] | 277 | unsigned long bestrate = 0; |
| 278 | int bestdiff = -1; |
| 279 | unsigned long tmprate; |
| 280 | int tmpdiff; |
| 281 | int i = 0; |
| 282 | |
Boris BREZILLON | 13a6073 | 2014-09-02 09:50:17 +0200 | [diff] [blame] | 283 | for (i = 0; i < RM9200_USB_DIV_TAB_SIZE; i++) { |
| 284 | unsigned long tmp_parent_rate; |
| 285 | |
Boris BREZILLON | c84a61d | 2013-10-17 18:55:41 +0200 | [diff] [blame] | 286 | if (!usb->divisors[i]) |
| 287 | continue; |
Boris BREZILLON | 13a6073 | 2014-09-02 09:50:17 +0200 | [diff] [blame] | 288 | |
| 289 | tmp_parent_rate = rate * usb->divisors[i]; |
| 290 | tmp_parent_rate = __clk_round_rate(parent, tmp_parent_rate); |
Boris Brezillon | ff553ea | 2014-11-14 19:54:49 +0100 | [diff] [blame] | 291 | tmprate = DIV_ROUND_CLOSEST(tmp_parent_rate, usb->divisors[i]); |
Boris BREZILLON | c84a61d | 2013-10-17 18:55:41 +0200 | [diff] [blame] | 292 | if (tmprate < rate) |
| 293 | tmpdiff = rate - tmprate; |
| 294 | else |
| 295 | tmpdiff = tmprate - rate; |
| 296 | |
| 297 | if (bestdiff < 0 || bestdiff > tmpdiff) { |
| 298 | bestrate = tmprate; |
| 299 | bestdiff = tmpdiff; |
Boris BREZILLON | 13a6073 | 2014-09-02 09:50:17 +0200 | [diff] [blame] | 300 | *parent_rate = tmp_parent_rate; |
Boris BREZILLON | c84a61d | 2013-10-17 18:55:41 +0200 | [diff] [blame] | 301 | } |
| 302 | |
| 303 | if (!bestdiff) |
| 304 | break; |
| 305 | } |
| 306 | |
| 307 | return bestrate; |
| 308 | } |
| 309 | |
| 310 | static int at91rm9200_clk_usb_set_rate(struct clk_hw *hw, unsigned long rate, |
| 311 | unsigned long parent_rate) |
| 312 | { |
| 313 | u32 tmp; |
| 314 | int i; |
| 315 | struct at91rm9200_clk_usb *usb = to_at91rm9200_clk_usb(hw); |
| 316 | struct at91_pmc *pmc = usb->pmc; |
Boris BREZILLON | 16eeaec | 2014-09-02 09:50:18 +0200 | [diff] [blame] | 317 | unsigned long div; |
Boris BREZILLON | c84a61d | 2013-10-17 18:55:41 +0200 | [diff] [blame] | 318 | |
Boris Brezillon | ff553ea | 2014-11-14 19:54:49 +0100 | [diff] [blame] | 319 | if (!rate) |
Boris BREZILLON | c84a61d | 2013-10-17 18:55:41 +0200 | [diff] [blame] | 320 | return -EINVAL; |
Boris BREZILLON | 16eeaec | 2014-09-02 09:50:18 +0200 | [diff] [blame] | 321 | |
Boris Brezillon | ff553ea | 2014-11-14 19:54:49 +0100 | [diff] [blame] | 322 | div = DIV_ROUND_CLOSEST(parent_rate, rate); |
Boris BREZILLON | 16eeaec | 2014-09-02 09:50:18 +0200 | [diff] [blame] | 323 | |
Boris BREZILLON | c84a61d | 2013-10-17 18:55:41 +0200 | [diff] [blame] | 324 | for (i = 0; i < RM9200_USB_DIV_TAB_SIZE; i++) { |
| 325 | if (usb->divisors[i] == div) { |
| 326 | tmp = pmc_read(pmc, AT91_CKGR_PLLBR) & |
| 327 | ~AT91_PMC_USBDIV; |
| 328 | tmp |= i << RM9200_USB_DIV_SHIFT; |
| 329 | pmc_write(pmc, AT91_CKGR_PLLBR, tmp); |
| 330 | return 0; |
| 331 | } |
| 332 | } |
| 333 | |
| 334 | return -EINVAL; |
| 335 | } |
| 336 | |
| 337 | static const struct clk_ops at91rm9200_usb_ops = { |
| 338 | .recalc_rate = at91rm9200_clk_usb_recalc_rate, |
| 339 | .round_rate = at91rm9200_clk_usb_round_rate, |
| 340 | .set_rate = at91rm9200_clk_usb_set_rate, |
| 341 | }; |
| 342 | |
| 343 | static struct clk * __init |
| 344 | at91rm9200_clk_register_usb(struct at91_pmc *pmc, const char *name, |
| 345 | const char *parent_name, const u32 *divisors) |
| 346 | { |
| 347 | struct at91rm9200_clk_usb *usb; |
| 348 | struct clk *clk = NULL; |
| 349 | struct clk_init_data init; |
| 350 | |
| 351 | usb = kzalloc(sizeof(*usb), GFP_KERNEL); |
| 352 | if (!usb) |
| 353 | return ERR_PTR(-ENOMEM); |
| 354 | |
| 355 | init.name = name; |
| 356 | init.ops = &at91rm9200_usb_ops; |
| 357 | init.parent_names = &parent_name; |
| 358 | init.num_parents = 1; |
Boris BREZILLON | 13a6073 | 2014-09-02 09:50:17 +0200 | [diff] [blame] | 359 | init.flags = CLK_SET_RATE_PARENT; |
Boris BREZILLON | c84a61d | 2013-10-17 18:55:41 +0200 | [diff] [blame] | 360 | |
| 361 | usb->hw.init = &init; |
| 362 | usb->pmc = pmc; |
| 363 | memcpy(usb->divisors, divisors, sizeof(usb->divisors)); |
| 364 | |
| 365 | clk = clk_register(NULL, &usb->hw); |
| 366 | if (IS_ERR(clk)) |
| 367 | kfree(usb); |
| 368 | |
| 369 | return clk; |
| 370 | } |
| 371 | |
| 372 | void __init of_at91sam9x5_clk_usb_setup(struct device_node *np, |
| 373 | struct at91_pmc *pmc) |
| 374 | { |
| 375 | struct clk *clk; |
| 376 | int i; |
| 377 | int num_parents; |
| 378 | const char *parent_names[USB_SOURCE_MAX]; |
| 379 | const char *name = np->name; |
| 380 | |
Geert Uytterhoeven | 51a43be | 2015-05-29 11:25:45 +0200 | [diff] [blame] | 381 | num_parents = of_clk_get_parent_count(np); |
Boris BREZILLON | c84a61d | 2013-10-17 18:55:41 +0200 | [diff] [blame] | 382 | if (num_parents <= 0 || num_parents > USB_SOURCE_MAX) |
| 383 | return; |
| 384 | |
| 385 | for (i = 0; i < num_parents; i++) { |
| 386 | parent_names[i] = of_clk_get_parent_name(np, i); |
| 387 | if (!parent_names[i]) |
| 388 | return; |
| 389 | } |
| 390 | |
| 391 | of_property_read_string(np, "clock-output-names", &name); |
| 392 | |
| 393 | clk = at91sam9x5_clk_register_usb(pmc, name, parent_names, num_parents); |
| 394 | if (IS_ERR(clk)) |
| 395 | return; |
| 396 | |
| 397 | of_clk_add_provider(np, of_clk_src_simple_get, clk); |
| 398 | } |
| 399 | |
| 400 | void __init of_at91sam9n12_clk_usb_setup(struct device_node *np, |
| 401 | struct at91_pmc *pmc) |
| 402 | { |
| 403 | struct clk *clk; |
| 404 | const char *parent_name; |
| 405 | const char *name = np->name; |
| 406 | |
| 407 | parent_name = of_clk_get_parent_name(np, 0); |
| 408 | if (!parent_name) |
| 409 | return; |
| 410 | |
| 411 | of_property_read_string(np, "clock-output-names", &name); |
| 412 | |
| 413 | clk = at91sam9n12_clk_register_usb(pmc, name, parent_name); |
| 414 | if (IS_ERR(clk)) |
| 415 | return; |
| 416 | |
| 417 | of_clk_add_provider(np, of_clk_src_simple_get, clk); |
| 418 | } |
| 419 | |
| 420 | void __init of_at91rm9200_clk_usb_setup(struct device_node *np, |
| 421 | struct at91_pmc *pmc) |
| 422 | { |
| 423 | struct clk *clk; |
| 424 | const char *parent_name; |
| 425 | const char *name = np->name; |
| 426 | u32 divisors[4] = {0, 0, 0, 0}; |
| 427 | |
| 428 | parent_name = of_clk_get_parent_name(np, 0); |
| 429 | if (!parent_name) |
| 430 | return; |
| 431 | |
| 432 | of_property_read_u32_array(np, "atmel,clk-divisors", divisors, 4); |
| 433 | if (!divisors[0]) |
| 434 | return; |
| 435 | |
| 436 | of_property_read_string(np, "clock-output-names", &name); |
| 437 | |
| 438 | clk = at91rm9200_clk_register_usb(pmc, name, parent_name, divisors); |
| 439 | if (IS_ERR(clk)) |
| 440 | return; |
| 441 | |
| 442 | of_clk_add_provider(np, of_clk_src_simple_get, clk); |
| 443 | } |