android_kernel_xiaomi_sm7250/drivers/clk/clk-gpio.c
Ivaylo Georgiev 15283112fe Merge android-4.19-q.93 (5d7443e) into msm-4.19
* refs/heads/tmp-5d7443e:
  Linux 4.19.93
  spi: fsl: use platform_get_irq() instead of of_irq_to_resource()
  pinctrl: baytrail: Really serialize all register accesses
  tty/serial: atmel: fix out of range clock divider handling
  spi: fsl: don't map irq during probe
  gtp: avoid zero size hashtable
  gtp: fix an use-after-free in ipv4_pdp_find()
  gtp: fix wrong condition in gtp_genl_dump_pdp()
  tcp: do not send empty skb from tcp_write_xmit()
  tcp/dccp: fix possible race __inet_lookup_established()
  net: marvell: mvpp2: phylink requires the link interrupt
  gtp: do not allow adding duplicate tid and ms_addr pdp context
  net/dst: do not confirm neighbor for vxlan and geneve pmtu update
  sit: do not confirm neighbor when do pmtu update
  vti: do not confirm neighbor when do pmtu update
  tunnel: do not confirm neighbor when do pmtu update
  net/dst: add new function skb_dst_update_pmtu_no_confirm
  gtp: do not confirm neighbor when do pmtu update
  ip6_gre: do not confirm neighbor when do pmtu update
  net: add bool confirm_neigh parameter for dst_ops.update_pmtu
  vhost/vsock: accept only packets with the right dst_cid
  udp: fix integer overflow while computing available space in sk_rcvbuf
  tcp: Fix highest_sack and highest_sack_seq
  ptp: fix the race between the release of ptp_clock and cdev
  net: stmmac: dwmac-meson8b: Fix the RGMII TX delay on Meson8b/8m2 SoCs
  net/mlxfw: Fix out-of-memory error in mfa2 flash burning
  net: ena: fix napi handler misbehavior when the napi budget is zero
  hrtimer: Annotate lockless access to timer->state
  net: icmp: fix data-race in cmp_global_allow()
  net: add a READ_ONCE() in skb_peek_tail()
  inetpeer: fix data-race in inet_putpeer / inet_putpeer
  netfilter: bridge: make sure to pull arp header in br_nf_forward_arp()
  6pack,mkiss: fix possible deadlock
  netfilter: ebtables: compat: reject all padding in matches/watchers
  filldir[64]: remove WARN_ON_ONCE() for bad directory entries
  Make filldir[64]() verify the directory entry filename is valid
  perf strbuf: Remove redundant va_end() in strbuf_addv()
  bonding: fix active-backup transition after link failure
  ALSA: hda - Downgrade error message for single-cmd fallback
  netfilter: nf_queue: enqueue skbs with NULL dst
  net, sysctl: Fix compiler warning when only cBPF is present
  x86/mce: Fix possibly incorrect severity calculation on AMD
  Revert "powerpc/vcpu: Assume dedicated processors as non-preempt"
  userfaultfd: require CAP_SYS_PTRACE for UFFD_FEATURE_EVENT_FORK
  kernel: sysctl: make drop_caches write-only
  mailbox: imx: Fix Tx doorbell shutdown path
  ocfs2: fix passing zero to 'PTR_ERR' warning
  s390/cpum_sf: Check for SDBT and SDB consistency
  libfdt: define INT32_MAX and UINT32_MAX in libfdt_env.h
  s390/zcrypt: handle new reply code FILTERED_BY_HYPERVISOR
  perf regs: Make perf_reg_name() return "unknown" instead of NULL
  perf script: Fix brstackinsn for AUXTRACE
  cdrom: respect device capabilities during opening action
  powerpc: Don't add -mabi= flags when building with Clang
  scripts/kallsyms: fix definitely-lost memory leak
  apparmor: fix unsigned len comparison with less than zero
  gpio: mpc8xxx: Don't overwrite default irq_set_type callback
  scsi: target: iscsi: Wait for all commands to finish before freeing a session
  scsi: iscsi: Don't send data to unbound connection
  scsi: NCR5380: Add disconnect_mask module parameter
  scsi: scsi_debug: num_tgts must be >= 0
  scsi: ufs: Fix error handing during hibern8 enter
  scsi: pm80xx: Fix for SATA device discovery
  watchdog: Fix the race between the release of watchdog_core_data and cdev
  HID: rmi: Check that the RMI_STARTED bit is set before unregistering the RMI transport device
  HID: Improve Windows Precision Touchpad detection.
  libnvdimm/btt: fix variable 'rc' set but not used
  ARM: 8937/1: spectre-v2: remove Brahma-B53 from hardening
  HID: logitech-hidpp: Silence intermittent get_battery_capacity errors
  HID: quirks: Add quirk for HP MSU1465 PIXART OEM mouse
  bcache: at least try to shrink 1 node in bch_mca_scan()
  clk: pxa: fix one of the pxa RTC clocks
  scsi: atari_scsi: sun3_scsi: Set sg_tablesize to 1 instead of SG_NONE
  powerpc/security: Fix wrong message when RFI Flush is disable
  PCI: rpaphp: Correctly match ibm, my-drc-index to drc-name when using drc-info
  PCI: rpaphp: Annotate and correctly byte swap DRC properties
  PCI: rpaphp: Don't rely on firmware feature to imply drc-info support
  powerpc/pseries/cmm: Implement release() function for sysfs device
  scsi: ufs: fix potential bug which ends in system hang
  PCI: rpaphp: Fix up pointer to first drc-info entry
  scsi: lpfc: fix: Coverity: lpfc_cmpl_els_rsp(): Null pointer dereferences
  fs/quota: handle overflows of sysctl fs.quota.* and report as unsigned long
  irqchip: ingenic: Error out if IRQ domain creation failed
  irqchip/irq-bcm7038-l1: Enable parent IRQ if necessary
  clk: clk-gpio: propagate rate change to parent
  clk: qcom: Allow constant ratio freq tables for rcg
  f2fs: fix to update dir's i_pino during cross_rename
  scsi: lpfc: Fix duplicate unreg_rpi error in port offline flow
  scsi: tracing: Fix handling of TRANSFER LENGTH == 0 for READ(6) and WRITE(6)
  jbd2: Fix statistics for the number of logged blocks
  ext4: iomap that extends beyond EOF should be marked dirty
  ext4: update direct I/O read lock pattern for IOCB_NOWAIT
  powerpc/book3s64/hash: Add cond_resched to avoid soft lockup warning
  powerpc/security/book3s64: Report L1TF status in sysfs
  clocksource/drivers/timer-of: Use unique device name instead of timer
  clocksource/drivers/asm9260: Add a check for of_clk_get
  leds: lm3692x: Handle failure to probe the regulator
  dma-debug: add a schedule point in debug_dma_dump_mappings()
  powerpc/tools: Don't quote $objdump in scripts
  powerpc/pseries: Don't fail hash page table insert for bolted mapping
  powerpc/pseries: Mark accumulate_stolen_time() as notrace
  scsi: hisi_sas: Replace in_softirq() check in hisi_sas_task_exec()
  scsi: csiostor: Don't enable IRQs too early
  scsi: lpfc: Fix SLI3 hba in loop mode not discovering devices
  scsi: target: compare full CHAP_A Algorithm strings
  dmaengine: xilinx_dma: Clear desc_pendingcount in xilinx_dma_reset
  iommu/tegra-smmu: Fix page tables in > 4 GiB memory
  iommu: rockchip: Free domain on .domain_free
  f2fs: fix to update time in lazytime mode
  Input: atmel_mxt_ts - disable IRQ across suspend
  scsi: lpfc: Fix locking on mailbox command completion
  scsi: mpt3sas: Fix clear pending bit in ioctl status
  scsi: lpfc: Fix discovery failures when target device connectivity bounces

Conflicts:
	drivers/scsi/ufs/ufshcd.c
	kernel/time/hrtimer.c

Change-Id: I9b69dbbc7cd2efa1c016ea10091fed73010b4c32
Signed-off-by: Ivaylo Georgiev <irgeorgiev@codeaurora.org>
2020-02-03 21:40:32 -08:00

272 lines
7.0 KiB
C

/*
* Copyright (C) 2013 - 2014 Texas Instruments Incorporated - http://www.ti.com
*
* Authors:
* Jyri Sarha <jsarha@ti.com>
* Sergej Sawazki <ce3a@gmx.de>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* Gpio controlled clock implementation
*/
#include <linux/clk-provider.h>
#include <linux/export.h>
#include <linux/slab.h>
#include <linux/gpio/consumer.h>
#include <linux/err.h>
#include <linux/device.h>
#include <linux/platform_device.h>
#include <linux/of_device.h>
/**
* DOC: basic gpio gated clock which can be enabled and disabled
* with gpio output
* Traits of this clock:
* prepare - clk_(un)prepare only ensures parent is (un)prepared
* enable - clk_enable and clk_disable are functional & control gpio
* rate - inherits rate from parent. No clk_set_rate support
* parent - fixed parent. No clk_set_parent support
*/
static int clk_gpio_gate_enable(struct clk_hw *hw)
{
struct clk_gpio *clk = to_clk_gpio(hw);
gpiod_set_value(clk->gpiod, 1);
return 0;
}
static void clk_gpio_gate_disable(struct clk_hw *hw)
{
struct clk_gpio *clk = to_clk_gpio(hw);
gpiod_set_value(clk->gpiod, 0);
}
static int clk_gpio_gate_is_enabled(struct clk_hw *hw)
{
struct clk_gpio *clk = to_clk_gpio(hw);
return gpiod_get_value(clk->gpiod);
}
const struct clk_ops clk_gpio_gate_ops = {
.enable = clk_gpio_gate_enable,
.disable = clk_gpio_gate_disable,
.is_enabled = clk_gpio_gate_is_enabled,
};
EXPORT_SYMBOL_GPL(clk_gpio_gate_ops);
/**
* DOC: basic clock multiplexer which can be controlled with a gpio output
* Traits of this clock:
* prepare - clk_prepare only ensures that parents are prepared
* rate - rate is only affected by parent switching. No clk_set_rate support
* parent - parent is adjustable through clk_set_parent
*/
static u8 clk_gpio_mux_get_parent(struct clk_hw *hw)
{
struct clk_gpio *clk = to_clk_gpio(hw);
return gpiod_get_value_cansleep(clk->gpiod);
}
static int clk_gpio_mux_set_parent(struct clk_hw *hw, u8 index)
{
struct clk_gpio *clk = to_clk_gpio(hw);
gpiod_set_value_cansleep(clk->gpiod, index);
return 0;
}
const struct clk_ops clk_gpio_mux_ops = {
.get_parent = clk_gpio_mux_get_parent,
.set_parent = clk_gpio_mux_set_parent,
.determine_rate = __clk_mux_determine_rate,
};
EXPORT_SYMBOL_GPL(clk_gpio_mux_ops);
static struct clk_hw *clk_register_gpio(struct device *dev, const char *name,
const char * const *parent_names, u8 num_parents, struct gpio_desc *gpiod,
unsigned long flags, const struct clk_ops *clk_gpio_ops)
{
struct clk_gpio *clk_gpio;
struct clk_hw *hw;
struct clk_init_data init = {};
int err;
if (dev)
clk_gpio = devm_kzalloc(dev, sizeof(*clk_gpio), GFP_KERNEL);
else
clk_gpio = kzalloc(sizeof(*clk_gpio), GFP_KERNEL);
if (!clk_gpio)
return ERR_PTR(-ENOMEM);
init.name = name;
init.ops = clk_gpio_ops;
init.flags = flags | CLK_IS_BASIC;
init.parent_names = parent_names;
init.num_parents = num_parents;
clk_gpio->gpiod = gpiod;
clk_gpio->hw.init = &init;
hw = &clk_gpio->hw;
if (dev)
err = devm_clk_hw_register(dev, hw);
else
err = clk_hw_register(NULL, hw);
hw->init = NULL;
if (!err)
return hw;
if (!dev) {
kfree(clk_gpio);
}
return ERR_PTR(err);
}
/**
* clk_hw_register_gpio_gate - register a gpio clock gate with the clock
* framework
* @dev: device that is registering this clock
* @name: name of this clock
* @parent_name: name of this clock's parent
* @gpiod: gpio descriptor to gate this clock
* @flags: clock flags
*/
struct clk_hw *clk_hw_register_gpio_gate(struct device *dev, const char *name,
const char *parent_name, struct gpio_desc *gpiod,
unsigned long flags)
{
return clk_register_gpio(dev, name,
(parent_name ? &parent_name : NULL),
(parent_name ? 1 : 0), gpiod, flags,
&clk_gpio_gate_ops);
}
EXPORT_SYMBOL_GPL(clk_hw_register_gpio_gate);
struct clk *clk_register_gpio_gate(struct device *dev, const char *name,
const char *parent_name, struct gpio_desc *gpiod,
unsigned long flags)
{
struct clk_hw *hw;
hw = clk_hw_register_gpio_gate(dev, name, parent_name, gpiod, flags);
if (IS_ERR(hw))
return ERR_CAST(hw);
return hw->clk;
}
EXPORT_SYMBOL_GPL(clk_register_gpio_gate);
/**
* clk_hw_register_gpio_mux - register a gpio clock mux with the clock framework
* @dev: device that is registering this clock
* @name: name of this clock
* @parent_names: names of this clock's parents
* @num_parents: number of parents listed in @parent_names
* @gpiod: gpio descriptor to gate this clock
* @flags: clock flags
*/
struct clk_hw *clk_hw_register_gpio_mux(struct device *dev, const char *name,
const char * const *parent_names, u8 num_parents, struct gpio_desc *gpiod,
unsigned long flags)
{
if (num_parents != 2) {
pr_err("mux-clock %s must have 2 parents\n", name);
return ERR_PTR(-EINVAL);
}
return clk_register_gpio(dev, name, parent_names, num_parents,
gpiod, flags, &clk_gpio_mux_ops);
}
EXPORT_SYMBOL_GPL(clk_hw_register_gpio_mux);
struct clk *clk_register_gpio_mux(struct device *dev, const char *name,
const char * const *parent_names, u8 num_parents, struct gpio_desc *gpiod,
unsigned long flags)
{
struct clk_hw *hw;
hw = clk_hw_register_gpio_mux(dev, name, parent_names, num_parents,
gpiod, flags);
if (IS_ERR(hw))
return ERR_CAST(hw);
return hw->clk;
}
EXPORT_SYMBOL_GPL(clk_register_gpio_mux);
static int gpio_clk_driver_probe(struct platform_device *pdev)
{
struct device_node *node = pdev->dev.of_node;
const char **parent_names, *gpio_name;
unsigned int num_parents;
struct gpio_desc *gpiod;
struct clk *clk;
bool is_mux;
int ret;
num_parents = of_clk_get_parent_count(node);
if (num_parents) {
parent_names = devm_kcalloc(&pdev->dev, num_parents,
sizeof(char *), GFP_KERNEL);
if (!parent_names)
return -ENOMEM;
of_clk_parent_fill(node, parent_names, num_parents);
} else {
parent_names = NULL;
}
is_mux = of_device_is_compatible(node, "gpio-mux-clock");
gpio_name = is_mux ? "select" : "enable";
gpiod = devm_gpiod_get(&pdev->dev, gpio_name, GPIOD_OUT_LOW);
if (IS_ERR(gpiod)) {
ret = PTR_ERR(gpiod);
if (ret == -EPROBE_DEFER)
pr_debug("%s: %s: GPIOs not yet available, retry later\n",
node->name, __func__);
else
pr_err("%s: %s: Can't get '%s' named GPIO property\n",
node->name, __func__,
gpio_name);
return ret;
}
if (is_mux)
clk = clk_register_gpio_mux(&pdev->dev, node->name,
parent_names, num_parents, gpiod, 0);
else
clk = clk_register_gpio_gate(&pdev->dev, node->name,
parent_names ? parent_names[0] : NULL, gpiod,
CLK_SET_RATE_PARENT);
if (IS_ERR(clk))
return PTR_ERR(clk);
return of_clk_add_provider(node, of_clk_src_simple_get, clk);
}
static const struct of_device_id gpio_clk_match_table[] = {
{ .compatible = "gpio-mux-clock" },
{ .compatible = "gpio-gate-clock" },
{ }
};
static struct platform_driver gpio_clk_driver = {
.probe = gpio_clk_driver_probe,
.driver = {
.name = "gpio-clk",
.of_match_table = gpio_clk_match_table,
},
};
builtin_platform_driver(gpio_clk_driver);