Lines Matching full:hellcreek

4  * Hirschmann Hellcreek TSN switch.
14 #include "hellcreek.h"
18 u16 hellcreek_ptp_read(struct hellcreek *hellcreek, unsigned int offset) in hellcreek_ptp_read() argument
20 return readw(hellcreek->ptp_base + offset); in hellcreek_ptp_read()
23 void hellcreek_ptp_write(struct hellcreek *hellcreek, u16 data, in hellcreek_ptp_write() argument
26 writew(data, hellcreek->ptp_base + offset); in hellcreek_ptp_write()
30 static u64 hellcreek_ptp_clock_read(struct hellcreek *hellcreek, in hellcreek_ptp_clock_read() argument
36 hellcreek_ptp_write(hellcreek, PR_COMMAND_C_SS, PR_COMMAND_C); in hellcreek_ptp_clock_read()
45 nsh = hellcreek_ptp_read(hellcreek, PR_SS_SYNC_DATA_C); in hellcreek_ptp_clock_read()
46 nsh = hellcreek_ptp_read(hellcreek, PR_SS_SYNC_DATA_C); in hellcreek_ptp_clock_read()
47 nsh = hellcreek_ptp_read(hellcreek, PR_SS_SYNC_DATA_C); in hellcreek_ptp_clock_read()
48 nsh = hellcreek_ptp_read(hellcreek, PR_SS_SYNC_DATA_C); in hellcreek_ptp_clock_read()
50 nsl = hellcreek_ptp_read(hellcreek, PR_SS_SYNC_DATA_C); in hellcreek_ptp_clock_read()
56 static u64 __hellcreek_ptp_gettime(struct hellcreek *hellcreek, in __hellcreek_ptp_gettime() argument
61 ns = hellcreek_ptp_clock_read(hellcreek, sts); in __hellcreek_ptp_gettime()
62 if (ns < hellcreek->last_ts) in __hellcreek_ptp_gettime()
63 hellcreek->seconds++; in __hellcreek_ptp_gettime()
64 hellcreek->last_ts = ns; in __hellcreek_ptp_gettime()
65 ns += hellcreek->seconds * NSEC_PER_SEC; in __hellcreek_ptp_gettime()
75 u64 hellcreek_ptp_gettime_seconds(struct hellcreek *hellcreek, u64 ns) in hellcreek_ptp_gettime_seconds() argument
79 __hellcreek_ptp_gettime(hellcreek, NULL); in hellcreek_ptp_gettime_seconds()
80 if (hellcreek->last_ts > ns) in hellcreek_ptp_gettime_seconds()
81 s = hellcreek->seconds * NSEC_PER_SEC; in hellcreek_ptp_gettime_seconds()
83 s = (hellcreek->seconds - 1) * NSEC_PER_SEC; in hellcreek_ptp_gettime_seconds()
92 struct hellcreek *hellcreek = ptp_to_hellcreek(ptp); in hellcreek_ptp_gettimex() local
95 mutex_lock(&hellcreek->ptp_lock); in hellcreek_ptp_gettimex()
96 ns = __hellcreek_ptp_gettime(hellcreek, sts); in hellcreek_ptp_gettimex()
97 mutex_unlock(&hellcreek->ptp_lock); in hellcreek_ptp_gettimex()
107 struct hellcreek *hellcreek = ptp_to_hellcreek(ptp); in hellcreek_ptp_settime() local
114 mutex_lock(&hellcreek->ptp_lock); in hellcreek_ptp_settime()
117 hellcreek->seconds = ts->tv_sec; in hellcreek_ptp_settime()
118 hellcreek->last_ts = ts->tv_nsec; in hellcreek_ptp_settime()
121 hellcreek_ptp_write(hellcreek, 0x00, PR_CLOCK_WRITE_C); in hellcreek_ptp_settime()
122 hellcreek_ptp_write(hellcreek, 0x00, PR_CLOCK_WRITE_C); in hellcreek_ptp_settime()
123 hellcreek_ptp_write(hellcreek, secl, PR_CLOCK_WRITE_C); in hellcreek_ptp_settime()
124 hellcreek_ptp_write(hellcreek, nsh, PR_CLOCK_WRITE_C); in hellcreek_ptp_settime()
125 hellcreek_ptp_write(hellcreek, nsl, PR_CLOCK_WRITE_C); in hellcreek_ptp_settime()
127 mutex_unlock(&hellcreek->ptp_lock); in hellcreek_ptp_settime()
134 struct hellcreek *hellcreek = ptp_to_hellcreek(ptp); in hellcreek_ptp_adjfine() local
165 mutex_lock(&hellcreek->ptp_lock); in hellcreek_ptp_adjfine()
168 hellcreek_ptp_write(hellcreek, negative, PR_CLOCK_DRIFT_C); in hellcreek_ptp_adjfine()
169 hellcreek_ptp_write(hellcreek, 0x00, PR_CLOCK_DRIFT_C); in hellcreek_ptp_adjfine()
170 hellcreek_ptp_write(hellcreek, 0x00, PR_CLOCK_DRIFT_C); in hellcreek_ptp_adjfine()
171 hellcreek_ptp_write(hellcreek, addendh, PR_CLOCK_DRIFT_C); in hellcreek_ptp_adjfine()
172 hellcreek_ptp_write(hellcreek, addendl, PR_CLOCK_DRIFT_C); in hellcreek_ptp_adjfine()
174 mutex_unlock(&hellcreek->ptp_lock); in hellcreek_ptp_adjfine()
181 struct hellcreek *hellcreek = ptp_to_hellcreek(ptp); in hellcreek_ptp_adjtime() local
212 mutex_lock(&hellcreek->ptp_lock); in hellcreek_ptp_adjtime()
215 hellcreek_ptp_write(hellcreek, negative, PR_CLOCK_OFFSET_C); in hellcreek_ptp_adjtime()
216 hellcreek_ptp_write(hellcreek, MAX_NS_PER_STEP, PR_CLOCK_OFFSET_C); in hellcreek_ptp_adjtime()
217 hellcreek_ptp_write(hellcreek, MIN_CLK_CYCLES_BETWEEN_STEPS, in hellcreek_ptp_adjtime()
219 hellcreek_ptp_write(hellcreek, countl, PR_CLOCK_OFFSET_C); in hellcreek_ptp_adjtime()
220 hellcreek_ptp_write(hellcreek, counth, PR_CLOCK_OFFSET_C); in hellcreek_ptp_adjtime()
222 mutex_unlock(&hellcreek->ptp_lock); in hellcreek_ptp_adjtime()
236 struct hellcreek *hellcreek; in hellcreek_ptp_overflow_check() local
238 hellcreek = dw_overflow_to_hellcreek(dw); in hellcreek_ptp_overflow_check()
240 mutex_lock(&hellcreek->ptp_lock); in hellcreek_ptp_overflow_check()
241 __hellcreek_ptp_gettime(hellcreek, NULL); in hellcreek_ptp_overflow_check()
242 mutex_unlock(&hellcreek->ptp_lock); in hellcreek_ptp_overflow_check()
244 schedule_delayed_work(&hellcreek->overflow_work, in hellcreek_ptp_overflow_check()
248 static enum led_brightness hellcreek_get_brightness(struct hellcreek *hellcreek, in hellcreek_get_brightness() argument
251 return (hellcreek->status_out & led) ? 1 : 0; in hellcreek_get_brightness()
254 static void hellcreek_set_brightness(struct hellcreek *hellcreek, int led, in hellcreek_set_brightness() argument
257 mutex_lock(&hellcreek->ptp_lock); in hellcreek_set_brightness()
260 hellcreek->status_out |= led; in hellcreek_set_brightness()
262 hellcreek->status_out &= ~led; in hellcreek_set_brightness()
264 hellcreek_ptp_write(hellcreek, hellcreek->status_out, STATUS_OUT); in hellcreek_set_brightness()
266 mutex_unlock(&hellcreek->ptp_lock); in hellcreek_set_brightness()
272 struct hellcreek *hellcreek = led_to_hellcreek(ldev, led_sync_good); in hellcreek_led_sync_good_set() local
274 hellcreek_set_brightness(hellcreek, STATUS_OUT_SYNC_GOOD, b); in hellcreek_led_sync_good_set()
279 struct hellcreek *hellcreek = led_to_hellcreek(ldev, led_sync_good); in hellcreek_led_sync_good_get() local
281 return hellcreek_get_brightness(hellcreek, STATUS_OUT_SYNC_GOOD); in hellcreek_led_sync_good_get()
287 struct hellcreek *hellcreek = led_to_hellcreek(ldev, led_is_gm); in hellcreek_led_is_gm_set() local
289 hellcreek_set_brightness(hellcreek, STATUS_OUT_IS_GM, b); in hellcreek_led_is_gm_set()
294 struct hellcreek *hellcreek = led_to_hellcreek(ldev, led_is_gm); in hellcreek_led_is_gm_get() local
296 return hellcreek_get_brightness(hellcreek, STATUS_OUT_IS_GM); in hellcreek_led_is_gm_get()
303 static int hellcreek_led_setup(struct hellcreek *hellcreek) in hellcreek_led_setup() argument
310 of_node_get(hellcreek->dev->of_node); in hellcreek_led_setup()
311 leds = of_find_node_by_name(hellcreek->dev->of_node, "leds"); in hellcreek_led_setup()
313 dev_err(hellcreek->dev, "No LEDs specified in device tree!\n"); in hellcreek_led_setup()
317 hellcreek->status_out = 0; in hellcreek_led_setup()
321 dev_err(hellcreek->dev, "First LED not specified!\n"); in hellcreek_led_setup()
326 hellcreek->led_sync_good.name = ret ? "sync_good" : label; in hellcreek_led_setup()
331 hellcreek->led_sync_good.brightness = 1; in hellcreek_led_setup()
334 hellcreek->led_sync_good.brightness = in hellcreek_led_setup()
335 hellcreek_get_brightness(hellcreek, STATUS_OUT_SYNC_GOOD); in hellcreek_led_setup()
338 hellcreek->led_sync_good.brightness = 0; in hellcreek_led_setup()
341 hellcreek->led_sync_good.max_brightness = 1; in hellcreek_led_setup()
342 hellcreek->led_sync_good.brightness_set = hellcreek_led_sync_good_set; in hellcreek_led_setup()
343 hellcreek->led_sync_good.brightness_get = hellcreek_led_sync_good_get; in hellcreek_led_setup()
347 dev_err(hellcreek->dev, "Second LED not specified!\n"); in hellcreek_led_setup()
353 hellcreek->led_is_gm.name = ret ? "is_gm" : label; in hellcreek_led_setup()
358 hellcreek->led_is_gm.brightness = 1; in hellcreek_led_setup()
361 hellcreek->led_is_gm.brightness = in hellcreek_led_setup()
362 hellcreek_get_brightness(hellcreek, STATUS_OUT_IS_GM); in hellcreek_led_setup()
365 hellcreek->led_is_gm.brightness = 0; in hellcreek_led_setup()
368 hellcreek->led_is_gm.max_brightness = 1; in hellcreek_led_setup()
369 hellcreek->led_is_gm.brightness_set = hellcreek_led_is_gm_set; in hellcreek_led_setup()
370 hellcreek->led_is_gm.brightness_get = hellcreek_led_is_gm_get; in hellcreek_led_setup()
373 if (hellcreek->led_sync_good.brightness == 1) in hellcreek_led_setup()
374 hellcreek_set_brightness(hellcreek, STATUS_OUT_SYNC_GOOD, 1); in hellcreek_led_setup()
375 if (hellcreek->led_is_gm.brightness == 1) in hellcreek_led_setup()
376 hellcreek_set_brightness(hellcreek, STATUS_OUT_IS_GM, 1); in hellcreek_led_setup()
379 led_classdev_register(hellcreek->dev, &hellcreek->led_sync_good); in hellcreek_led_setup()
380 led_classdev_register(hellcreek->dev, &hellcreek->led_is_gm); in hellcreek_led_setup()
390 int hellcreek_ptp_setup(struct hellcreek *hellcreek) in hellcreek_ptp_setup() argument
396 INIT_DELAYED_WORK(&hellcreek->overflow_work, in hellcreek_ptp_setup()
400 hellcreek->ptp_clock_info.owner = THIS_MODULE; in hellcreek_ptp_setup()
401 snprintf(hellcreek->ptp_clock_info.name, in hellcreek_ptp_setup()
402 sizeof(hellcreek->ptp_clock_info.name), in hellcreek_ptp_setup()
403 dev_name(hellcreek->dev)); in hellcreek_ptp_setup()
409 hellcreek->ptp_clock_info.max_adj = 62500000; in hellcreek_ptp_setup()
410 hellcreek->ptp_clock_info.n_alarm = 0; in hellcreek_ptp_setup()
411 hellcreek->ptp_clock_info.n_pins = 0; in hellcreek_ptp_setup()
412 hellcreek->ptp_clock_info.n_ext_ts = 0; in hellcreek_ptp_setup()
413 hellcreek->ptp_clock_info.n_per_out = 0; in hellcreek_ptp_setup()
414 hellcreek->ptp_clock_info.pps = 0; in hellcreek_ptp_setup()
415 hellcreek->ptp_clock_info.adjfine = hellcreek_ptp_adjfine; in hellcreek_ptp_setup()
416 hellcreek->ptp_clock_info.adjtime = hellcreek_ptp_adjtime; in hellcreek_ptp_setup()
417 hellcreek->ptp_clock_info.gettimex64 = hellcreek_ptp_gettimex; in hellcreek_ptp_setup()
418 hellcreek->ptp_clock_info.settime64 = hellcreek_ptp_settime; in hellcreek_ptp_setup()
419 hellcreek->ptp_clock_info.enable = hellcreek_ptp_enable; in hellcreek_ptp_setup()
420 hellcreek->ptp_clock_info.do_aux_work = hellcreek_hwtstamp_work; in hellcreek_ptp_setup()
422 hellcreek->ptp_clock = ptp_clock_register(&hellcreek->ptp_clock_info, in hellcreek_ptp_setup()
423 hellcreek->dev); in hellcreek_ptp_setup()
424 if (IS_ERR(hellcreek->ptp_clock)) in hellcreek_ptp_setup()
425 return PTR_ERR(hellcreek->ptp_clock); in hellcreek_ptp_setup()
430 status = hellcreek_ptp_read(hellcreek, PR_CLOCK_STATUS_C); in hellcreek_ptp_setup()
432 hellcreek_ptp_write(hellcreek, in hellcreek_ptp_setup()
437 hellcreek_ptp_write(hellcreek, status | PR_CLOCK_STATUS_C_ENA_DRIFT, in hellcreek_ptp_setup()
441 ret = hellcreek_led_setup(hellcreek); in hellcreek_ptp_setup()
443 if (hellcreek->ptp_clock) in hellcreek_ptp_setup()
444 ptp_clock_unregister(hellcreek->ptp_clock); in hellcreek_ptp_setup()
448 schedule_delayed_work(&hellcreek->overflow_work, in hellcreek_ptp_setup()
454 void hellcreek_ptp_free(struct hellcreek *hellcreek) in hellcreek_ptp_free() argument
456 led_classdev_unregister(&hellcreek->led_is_gm); in hellcreek_ptp_free()
457 led_classdev_unregister(&hellcreek->led_sync_good); in hellcreek_ptp_free()
458 cancel_delayed_work_sync(&hellcreek->overflow_work); in hellcreek_ptp_free()
459 if (hellcreek->ptp_clock) in hellcreek_ptp_free()
460 ptp_clock_unregister(hellcreek->ptp_clock); in hellcreek_ptp_free()
461 hellcreek->ptp_clock = NULL; in hellcreek_ptp_free()