aboutsummaryrefslogtreecommitdiffstats
path: root/docs/sw.js
blob: 1e4aaeb76213c3b82af7e18b7f1ca33f02b08f11 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/* ===========================================================
 * docsify sw.js
 * ===========================================================
 * Copyright 2016 @huxpro
 * Licensed under Apache 2.0
 * Register service worker.
 * ========================================================== */

const RUNTIME = 'docsify'
const HOSTNAME_WHITELIST = [
  self.location.hostname,
  'fonts.gstatic.com',
  'fonts.googleapis.com',
  'unpkg.com'
]

// The Util Function to hack URLs of intercepted requests
const getFixedUrl = (req) => {
  var now = Date.now()
  var url = new URL(req.url)

  // 1. fixed http URL
  // Just keep syncing with location.protocol
  // fetch(httpURL) belongs to active mixed content.
  // And fetch(httpRequest) is not supported yet.
  url.protocol = self.location.protocol

  // 2. add query for caching-busting.
  // Github Pages served with Cache-Control: max-age=600
  // max-age on mutable content is error-prone, with SW life of bugs can even extend.
  // Until cache mode of Fetch API landed, we have to workaround cache-busting with query string.
  // Cache-Control-Bug: https://bugs.chromium.org/p/chromium/issues/detail?id=453190
  if (url.hostname === self.location.hostname) {
    url.search += (url.search ? '&' : '?') + 'cache-bust=' + now
  }
  return url.href
}

/**
 *  @Lifecycle Activate
 *  New one activated when old isnt being used.
 *
 *  waitUntil(): activating ====> activated
 */
self.addEventListener('activate', event => {
  event.waitUntil(self.clients.claim())
})

/**
 *  @Functional Fetch
 *  All network requests are being intercepted here.
 *
 *  void respondWith(Promise<Response> r)
 */
self.addEventListener('fetch', event => {
  // Skip some of cross-origin requests, like those for Google Analytics.
  if (HOSTNAME_WHITELIST.indexOf(new URL(event.request.url).hostname) > -1) {
    // Stale-while-revalidate
    // similar to HTTP's stale-while-revalidate: https://www.mnot.net/blog/2007/12/12/stale
    // Upgrade from Jake's to Surma's: https://gist.github.com/surma/eb441223daaedf880801ad80006389f1
    const cached = caches.match(event.request)
    const fixedUrl = getFixedUrl(event.request)
    const fetched = fetch(fixedUrl, { cache: 'no-store' })
    const fetchedCopy = fetched.then(resp => resp.clone())

    // Call respondWith() with whatever we get first.
    // If the fetch fails (e.g disconnected), wait for the cache.
    // If there’s nothing in cache, wait for the fetch.
    // If neither yields a response, return offline pages.
    event.respondWith(
      Promise.race([fetched.catch(_ => cached), cached])
        .then(resp => resp || fetched)
        .catch(_ => { /* eat any errors */ })
    )

    // Update the cache with the version we fetched (only for ok status)
    event.waitUntil(
      Promise.all([fetchedCopy, caches.open(RUNTIME)])
        .then(([response, cache]) => response.ok && cache.put(event.request, response))
        .catch(_ => { /* eat any errors */ })
    )
  }
})
ass="gi">+ +static int ralink_usb_phy_power_on(struct phy *_phy) +{ + if (atomic_inc_return(&usb_pwr_ref) == 1) { + int host = 1; + u32 t; + + usb_phy_enable(1); + + if (host) { + rt_sysc_m32(0, RT_SYSCFG1_USB0_HOST_MODE, RT_SYSC_REG_SYSCFG1); + if (!IS_ERR(rsthost)) + reset_control_deassert(rsthost); + if (!IS_ERR(rstdev)) + reset_control_deassert(rstdev); + } else { + rt_sysc_m32(RT_SYSCFG1_USB0_HOST_MODE, 0, RT_SYSC_REG_SYSCFG1); + if (!IS_ERR(rstdev)) + reset_control_deassert(rstdev); + } + mdelay(100); + + t = rt_sysc_r32(RT_SYSC_REG_USB_PHY_CFG); + dev_info(&_phy->dev, "remote usb device wakeup %s\n", + (t & UDEV_WAKEUP) ? ("enabbled") : ("disabled")); + if (t & USB_PHY_UTMI_8B60M) + dev_info(&_phy->dev, "UTMI 8bit 60MHz\n"); + else + dev_info(&_phy->dev, "UTMI 16bit 30MHz\n"); + } + + return 0; +} + +static int ralink_usb_phy_power_off(struct phy *_phy) +{ + if (atomic_dec_return(&usb_pwr_ref) == 0) { + usb_phy_enable(0); + if (!IS_ERR(rstdev)) + reset_control_assert(rstdev); + if (!IS_ERR(rsthost)) + reset_control_assert(rsthost); + } + + return 0; +} + +static struct phy_ops ralink_usb_phy_ops = { + .init = ralink_usb_phy_init, + .exit = ralink_usb_phy_exit, + .power_on = ralink_usb_phy_power_on, + .power_off = ralink_usb_phy_power_off, + .owner = THIS_MODULE, +}; + +static struct phy *ralink_usb_phy_xlate(struct device *dev, + struct of_phandle_args *args) +{ + return rt_phy; +} + +static const struct of_device_id ralink_usb_phy_of_match[] = { + { .compatible = "ralink,rt3xxx-usbphy", .data = (void *) (RT_CLKCFG1_UPHY1_CLK_EN | RT_CLKCFG1_UPHY0_CLK_EN) }, + { .compatible = "ralink,mt7620a-usbphy", .data = (void *) (MT7620_CLKCFG1_UPHY1_CLK_EN | MT7620_CLKCFG1_UPHY0_CLK_EN) }, + { }, +}; +MODULE_DEVICE_TABLE(of, ralink_usb_phy_of_match); + +static int ralink_usb_phy_probe(struct platform_device *pdev) +{ + struct device *dev = &pdev->dev; + struct phy_provider *phy_provider; + const struct of_device_id *match; + + printk("%s:%s[%d]\n", __FILE__, __func__, __LINE__); + match = of_match_device(ralink_usb_phy_of_match, &pdev->dev); + phy_clk = (int) match->data; + + rsthost = devm_reset_control_get(&pdev->dev, "host"); + rstdev = devm_reset_control_get(&pdev->dev, "device"); + + rt_phy = devm_phy_create(dev, NULL, &ralink_usb_phy_ops, NULL); + if (IS_ERR(rt_phy)) { + dev_err(dev, "failed to create PHY\n"); + return PTR_ERR(rt_phy); + } + + phy_provider = devm_of_phy_provider_register(dev, ralink_usb_phy_xlate); +printk("%s:%s[%d]\n", __FILE__, __func__, __LINE__); + + return PTR_ERR_OR_ZERO(phy_provider); +} + +static struct platform_driver ralink_usb_phy_driver = { + .probe = ralink_usb_phy_probe, + .driver = { + .of_match_table = ralink_usb_phy_of_match, + .name = "ralink-usb-phy", + } +}; +module_platform_driver(ralink_usb_phy_driver); + +MODULE_DESCRIPTION("Ralink USB phy driver"); +MODULE_AUTHOR("John Crispin <blogic@openwrt.org>"); +MODULE_LICENSE("GPL v2");