-----BEGIN PGP SIGNATURE----- iQIzBAABCAAdFiEEZH8oZUiU471FcZm+ONu9yGCSaT4FAmFBpSMACgkQONu9yGCS aT6PRw//T4GhyaqI0+hhYnYv2++RBzAtKsOAPE7JUZ8X5zNNe3NZKD/+c0q9loy3 vs1GpkjppSzZcL2WGZidwpgOTO0fqEYiJKusI+E60UGbu8GmmoUl0EbV3A3PP1K7 n+T1jzMID1j4NwmZQsAA1o3/9pkWrKLb/1+g0mHVCL6WQjA4/YROi5f6xhVeCq/u aZFLxrgJ8YRkT9znEHCBcipEGRLid5kQp1uxSA5KaQh0JJl01eoJ3M52swYiExC/ 8g+QXPHFWOs9a1vVyxUG5o4WCShnjKwY1fNkEJ5j54LMmmg52llHfMHajV2a1Kdt qihSgY5/pPY9FgEDQ3Sy6xiTO2Lvq17lvHtEbGIn5V7SjQ4ISEN15Pqv3l+PqAFc gHeukc28mBfw6/kbolKZ/wksIKyDzxCHd4QNEYZMKjSPbjpzg7zjsvCX53lHkKNb 23I0iJTu9yVDcPzYYCh/8ndFtxEIBGXS8c9kL5YN8p2k1AMqXcr1qUbYzM9CJqwm MSaZ2C1rR58Uhd4CUvOK4N2K7lw+2PH6I0UcSGlp9jv+xHVlmERiM7uaZGBn7oLm +n+5BRAU/qDK+Vm1poIZogrsI4BwMp9ZH4terELR28i0gPwYo+tCzddWqq98BuGT 52ylkG56l0gbC9Bvpf3Ou3K5/qbmhN9HYElt16HNFO6x/ufE2XI= =1neh -----END PGP SIGNATURE----- Merge 5.4.146 into android11-5.4-lts Changes in 5.4.146 locking/mutex: Fix HANDOFF condition regmap: fix the offset of register error log crypto: mxs-dcp - Check for DMA mapping errors sched/deadline: Fix reset_on_fork reporting of DL tasks power: supply: axp288_fuel_gauge: Report register-address on readb / writeb errors crypto: omap-sham - clear dma flags only after omap_sham_update_dma_stop() sched/deadline: Fix missing clock update in migrate_task_rq_dl() rcu/tree: Handle VM stoppage in stall detection posix-cpu-timers: Force next expiration recalc after itimer reset hrtimer: Avoid double reprogramming in __hrtimer_start_range_ns() hrtimer: Ensure timerfd notification for HIGHRES=n udf: Check LVID earlier udf: Fix iocharset=utf8 mount option isofs: joliet: Fix iocharset=utf8 mount option bcache: add proper error unwinding in bcache_device_init nvme-tcp: don't update queue count when failing to set io queues nvme-rdma: don't update queue count when failing to set io queues nvmet: pass back cntlid on successful completion power: supply: max17042_battery: fix typo in MAx17042_TOFF s390/cio: add dev_busid sysfs entry for each subchannel libata: fix ata_host_start() crypto: qat - do not ignore errors from enable_vf2pf_comms() crypto: qat - handle both source of interrupt in VF ISR crypto: qat - fix reuse of completion variable crypto: qat - fix naming for init/shutdown VF to PF notifications crypto: qat - do not export adf_iov_putmsg() fcntl: fix potential deadlock for &fasync_struct.fa_lock udf_get_extendedattr() had no boundary checks. s390/kasan: fix large PMD pages address alignment check s390/debug: fix debug area life cycle m68k: emu: Fix invalid free in nfeth_cleanup() sched: Fix UCLAMP_FLAG_IDLE setting spi: spi-fsl-dspi: Fix issue with uninitialized dma_slave_config spi: spi-pic32: Fix issue with uninitialized dma_slave_config genirq/timings: Fix error return code in irq_timings_test_irqs() lib/mpi: use kcalloc in mpi_resize clocksource/drivers/sh_cmt: Fix wrong setting if don't request IRQ for clock source channel block: nbd: add sanity check for first_minor crypto: qat - use proper type for vf_mask certs: Trigger creation of RSA module signing key if it's not an RSA key regulator: vctrl: Use locked regulator_get_voltage in probe path regulator: vctrl: Avoid lockdep warning in enable/disable ops spi: sprd: Fix the wrong WDG_LOAD_VAL spi: spi-zynq-qspi: use wait_for_completion_timeout to make zynq_qspi_exec_mem_op not interruptible EDAC/i10nm: Fix NVDIMM detection drm/panfrost: Fix missing clk_disable_unprepare() on error in panfrost_clk_init() media: TDA1997x: enable EDID support soc: rockchip: ROCKCHIP_GRF should not default to y, unconditionally media: cxd2880-spi: Fix an error handling path bpf: Fix a typo of reuseport map in bpf.h. bpf: Fix potential memleak and UAF in the verifier. ARM: dts: aspeed-g6: Fix HVI3C function-group in pinctrl dtsi arm64: dts: renesas: r8a77995: draak: Remove bogus adv7511w properties soc: qcom: rpmhpd: Use corner in power_off media: dvb-usb: fix uninit-value in dvb_usb_adapter_dvb_init media: dvb-usb: fix uninit-value in vp702x_read_mac_addr media: dvb-usb: Fix error handling in dvb_usb_i2c_init media: go7007: remove redundant initialization media: coda: fix frame_mem_ctrl for YUV420 and YVU420 formats Bluetooth: sco: prevent information leak in sco_conn_defer_accept() 6lowpan: iphc: Fix an off-by-one check of array index netns: protect netns ID lookups with RCU drm/amdgpu/acp: Make PM domain really work tcp: seq_file: Avoid skipping sk during tcp_seek_last_pos ARM: dts: meson8: Use a higher default GPU clock frequency ARM: dts: meson8b: odroidc1: Fix the pwm regulator supply properties ARM: dts: meson8b: mxq: Fix the pwm regulator supply properties ARM: dts: meson8b: ec100: Fix the pwm regulator supply properties net/mlx5e: Prohibit inner indir TIRs in IPoIB cgroup/cpuset: Fix a partition bug with hotplug net: cipso: fix warnings in netlbl_cipsov4_add_std i2c: highlander: add IRQ check leds: lt3593: Put fwnode in any case during ->probe() leds: trigger: audio: Add an activate callback to ensure the initial brightness is set media: em28xx-input: fix refcount bug in em28xx_usb_disconnect media: venus: venc: Fix potential null pointer dereference on pointer fmt PCI: PM: Avoid forcing PCI_D0 for wakeup reasons inconsistently PCI: PM: Enable PME if it can be signaled from D3cold soc: qcom: smsm: Fix missed interrupts if state changes while masked debugfs: Return error during {full/open}_proxy_open() on rmmod Bluetooth: increase BTNAMSIZ to 21 chars to fix potential buffer overflow PM: EM: Increase energy calculation precision drm/msm/dpu: make dpu_hw_ctl_clear_all_blendstages clear necessary LMs arm64: dts: exynos: correct GIC CPU interfaces address range on Exynos7 counter: 104-quad-8: Return error when invalid mode during ceiling_write Bluetooth: fix repeated calls to sco_sock_kill drm/msm/dsi: Fix some reference counted resource leaks usb: gadget: udc: at91: add IRQ check usb: phy: fsl-usb: add IRQ check usb: phy: twl6030: add IRQ checks usb: gadget: udc: renesas_usb3: Fix soc_device_match() abuse Bluetooth: Move shutdown callback before flushing tx and rx queue usb: host: ohci-tmio: add IRQ check usb: phy: tahvo: add IRQ check mac80211: Fix insufficient headroom issue for AMSDU lockd: Fix invalid lockowner cast after vfs_test_lock nfsd4: Fix forced-expiry locking usb: gadget: mv_u3d: request_irq() after initializing UDC mm/swap: consider max pages in iomap_swapfile_add_extent Bluetooth: add timeout sanity check to hci_inquiry i2c: iop3xx: fix deferred probing i2c: s3c2410: fix IRQ check rsi: fix error code in rsi_load_9116_firmware() rsi: fix an error code in rsi_probe() ASoC: Intel: Skylake: Leave data as is when invoking TLV IPCs ASoC: Intel: Skylake: Fix module resource and format selection mmc: dw_mmc: Fix issue with uninitialized dma_slave_config mmc: moxart: Fix issue with uninitialized dma_slave_config bpf: Fix possible out of bound write in narrow load handling CIFS: Fix a potencially linear read overflow i2c: mt65xx: fix IRQ check usb: ehci-orion: Handle errors of clk_prepare_enable() in probe usb: bdc: Fix an error handling path in 'bdc_probe()' when no suitable DMA config is available tty: serial: fsl_lpuart: fix the wrong mapbase value ASoC: wcd9335: Fix a double irq free in the remove function ASoC: wcd9335: Fix a memory leak in the error handling path of the probe function ASoC: wcd9335: Disable irq on slave ports in the remove function ath6kl: wmi: fix an error code in ath6kl_wmi_sync_point() bcma: Fix memory leak for internally-handled cores brcmfmac: pcie: fix oops on failure to resume and reprobe ipv6: make exception cache less predictible ipv4: make exception cache less predictible net: sched: Fix qdisc_rate_table refcount leak when get tcf_block failed net: qualcomm: fix QCA7000 checksum handling octeontx2-af: Fix loop in free and unmap counter ipv4: fix endianness issue in inet_rtm_getroute_build_skb() bpf: Introduce BPF nospec instruction for mitigating Spectre v4 bpf: Fix leakage due to insufficient speculative store bypass mitigation bpf: verifier: Allocate idmap scratch in verifier env bpf: Fix pointer arithmetic mask tightening under state pruning time: Handle negative seconds correctly in timespec64_to_ns() tty: Fix data race between tiocsti() and flush_to_ldisc() perf/x86/amd/ibs: Extend PERF_PMU_CAP_NO_EXCLUDE to IBS Op x86/resctrl: Fix a maybe-uninitialized build warning treated as error KVM: s390: index kvm->arch.idle_mask by vcpu_idx KVM: x86: Update vCPU's hv_clock before back to guest when tsc_offset is adjusted KVM: nVMX: Unconditionally clear nested.pi_pending on nested VM-Enter fuse: truncate pagecache on atomic_o_trunc fuse: flush extending writes IMA: remove -Wmissing-prototypes warning IMA: remove the dependency on CRYPTO_MD5 fbmem: don't allow too huge resolutions backlight: pwm_bl: Improve bootloader/kernel device handover clk: kirkwood: Fix a clocking boot regression Linux 5.4.146 Signed-off-by: Greg Kroah-Hartman <gregkh@google.com> Change-Id: I5524baa0c07d9d9b80c0736488e3ea0e4fb8e335
576 lines
15 KiB
C
576 lines
15 KiB
C
/*
|
|
* Copyright (C) 2017 Spreadtrum Communications Inc.
|
|
*
|
|
* SPDX-License-Identifier: GPL-2.0
|
|
*/
|
|
|
|
#include <linux/delay.h>
|
|
#include <linux/hwspinlock.h>
|
|
#include <linux/init.h>
|
|
#include <linux/io.h>
|
|
#include <linux/kernel.h>
|
|
#include <linux/module.h>
|
|
#include <linux/of.h>
|
|
#include <linux/of_device.h>
|
|
#include <linux/platform_device.h>
|
|
#include <linux/reboot.h>
|
|
#include <linux/spi/spi.h>
|
|
#include <linux/sizes.h>
|
|
|
|
/* Registers definitions for ADI controller */
|
|
#define REG_ADI_CTRL0 0x4
|
|
#define REG_ADI_CHN_PRIL 0x8
|
|
#define REG_ADI_CHN_PRIH 0xc
|
|
#define REG_ADI_INT_EN 0x10
|
|
#define REG_ADI_INT_RAW 0x14
|
|
#define REG_ADI_INT_MASK 0x18
|
|
#define REG_ADI_INT_CLR 0x1c
|
|
#define REG_ADI_GSSI_CFG0 0x20
|
|
#define REG_ADI_GSSI_CFG1 0x24
|
|
#define REG_ADI_RD_CMD 0x28
|
|
#define REG_ADI_RD_DATA 0x2c
|
|
#define REG_ADI_ARM_FIFO_STS 0x30
|
|
#define REG_ADI_STS 0x34
|
|
#define REG_ADI_EVT_FIFO_STS 0x38
|
|
#define REG_ADI_ARM_CMD_STS 0x3c
|
|
#define REG_ADI_CHN_EN 0x40
|
|
#define REG_ADI_CHN_ADDR(id) (0x44 + (id - 2) * 4)
|
|
#define REG_ADI_CHN_EN1 0x20c
|
|
|
|
/* Bits definitions for register REG_ADI_GSSI_CFG0 */
|
|
#define BIT_CLK_ALL_ON BIT(30)
|
|
|
|
/* Bits definitions for register REG_ADI_RD_DATA */
|
|
#define BIT_RD_CMD_BUSY BIT(31)
|
|
#define RD_ADDR_SHIFT 16
|
|
#define RD_VALUE_MASK GENMASK(15, 0)
|
|
#define RD_ADDR_MASK GENMASK(30, 16)
|
|
|
|
/* Bits definitions for register REG_ADI_ARM_FIFO_STS */
|
|
#define BIT_FIFO_FULL BIT(11)
|
|
#define BIT_FIFO_EMPTY BIT(10)
|
|
|
|
/*
|
|
* ADI slave devices include RTC, ADC, regulator, charger, thermal and so on.
|
|
* The slave devices address offset is always 0x8000 and size is 4K.
|
|
*/
|
|
#define ADI_SLAVE_ADDR_SIZE SZ_4K
|
|
#define ADI_SLAVE_OFFSET 0x8000
|
|
|
|
/* Timeout (ms) for the trylock of hardware spinlocks */
|
|
#define ADI_HWSPINLOCK_TIMEOUT 5000
|
|
/*
|
|
* ADI controller has 50 channels including 2 software channels
|
|
* and 48 hardware channels.
|
|
*/
|
|
#define ADI_HW_CHNS 50
|
|
|
|
#define ADI_FIFO_DRAIN_TIMEOUT 1000
|
|
#define ADI_READ_TIMEOUT 2000
|
|
#define REG_ADDR_LOW_MASK GENMASK(11, 0)
|
|
|
|
/* Registers definitions for PMIC watchdog controller */
|
|
#define REG_WDG_LOAD_LOW 0x80
|
|
#define REG_WDG_LOAD_HIGH 0x84
|
|
#define REG_WDG_CTRL 0x88
|
|
#define REG_WDG_LOCK 0xa0
|
|
|
|
/* Bits definitions for register REG_WDG_CTRL */
|
|
#define BIT_WDG_RUN BIT(1)
|
|
#define BIT_WDG_NEW BIT(2)
|
|
#define BIT_WDG_RST BIT(3)
|
|
|
|
/* Registers definitions for PMIC */
|
|
#define PMIC_RST_STATUS 0xee8
|
|
#define PMIC_MODULE_EN 0xc08
|
|
#define PMIC_CLK_EN 0xc18
|
|
#define BIT_WDG_EN BIT(2)
|
|
|
|
/* Definition of PMIC reset status register */
|
|
#define HWRST_STATUS_SECURITY 0x02
|
|
#define HWRST_STATUS_RECOVERY 0x20
|
|
#define HWRST_STATUS_NORMAL 0x40
|
|
#define HWRST_STATUS_ALARM 0x50
|
|
#define HWRST_STATUS_SLEEP 0x60
|
|
#define HWRST_STATUS_FASTBOOT 0x30
|
|
#define HWRST_STATUS_SPECIAL 0x70
|
|
#define HWRST_STATUS_PANIC 0x80
|
|
#define HWRST_STATUS_CFTREBOOT 0x90
|
|
#define HWRST_STATUS_AUTODLOADER 0xa0
|
|
#define HWRST_STATUS_IQMODE 0xb0
|
|
#define HWRST_STATUS_SPRDISK 0xc0
|
|
#define HWRST_STATUS_FACTORYTEST 0xe0
|
|
#define HWRST_STATUS_WATCHDOG 0xf0
|
|
|
|
/* Use default timeout 50 ms that converts to watchdog values */
|
|
#define WDG_LOAD_VAL ((50 * 32768) / 1000)
|
|
#define WDG_LOAD_MASK GENMASK(15, 0)
|
|
#define WDG_UNLOCK_KEY 0xe551
|
|
|
|
struct sprd_adi {
|
|
struct spi_controller *ctlr;
|
|
struct device *dev;
|
|
void __iomem *base;
|
|
struct hwspinlock *hwlock;
|
|
unsigned long slave_vbase;
|
|
unsigned long slave_pbase;
|
|
struct notifier_block restart_handler;
|
|
};
|
|
|
|
static int sprd_adi_check_paddr(struct sprd_adi *sadi, u32 paddr)
|
|
{
|
|
if (paddr < sadi->slave_pbase || paddr >
|
|
(sadi->slave_pbase + ADI_SLAVE_ADDR_SIZE)) {
|
|
dev_err(sadi->dev,
|
|
"slave physical address is incorrect, addr = 0x%x\n",
|
|
paddr);
|
|
return -EINVAL;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
static unsigned long sprd_adi_to_vaddr(struct sprd_adi *sadi, u32 paddr)
|
|
{
|
|
return (paddr - sadi->slave_pbase + sadi->slave_vbase);
|
|
}
|
|
|
|
static int sprd_adi_drain_fifo(struct sprd_adi *sadi)
|
|
{
|
|
u32 timeout = ADI_FIFO_DRAIN_TIMEOUT;
|
|
u32 sts;
|
|
|
|
do {
|
|
sts = readl_relaxed(sadi->base + REG_ADI_ARM_FIFO_STS);
|
|
if (sts & BIT_FIFO_EMPTY)
|
|
break;
|
|
|
|
cpu_relax();
|
|
} while (--timeout);
|
|
|
|
if (timeout == 0) {
|
|
dev_err(sadi->dev, "drain write fifo timeout\n");
|
|
return -EBUSY;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
static int sprd_adi_fifo_is_full(struct sprd_adi *sadi)
|
|
{
|
|
return readl_relaxed(sadi->base + REG_ADI_ARM_FIFO_STS) & BIT_FIFO_FULL;
|
|
}
|
|
|
|
static int sprd_adi_read(struct sprd_adi *sadi, u32 reg_paddr, u32 *read_val)
|
|
{
|
|
int read_timeout = ADI_READ_TIMEOUT;
|
|
unsigned long flags;
|
|
u32 val, rd_addr;
|
|
int ret = 0;
|
|
|
|
if (sadi->hwlock) {
|
|
ret = hwspin_lock_timeout_irqsave(sadi->hwlock,
|
|
ADI_HWSPINLOCK_TIMEOUT,
|
|
&flags);
|
|
if (ret) {
|
|
dev_err(sadi->dev, "get the hw lock failed\n");
|
|
return ret;
|
|
}
|
|
}
|
|
|
|
/*
|
|
* Set the physical register address need to read into RD_CMD register,
|
|
* then ADI controller will start to transfer automatically.
|
|
*/
|
|
writel_relaxed(reg_paddr, sadi->base + REG_ADI_RD_CMD);
|
|
|
|
/*
|
|
* Wait read operation complete, the BIT_RD_CMD_BUSY will be set
|
|
* simultaneously when writing read command to register, and the
|
|
* BIT_RD_CMD_BUSY will be cleared after the read operation is
|
|
* completed.
|
|
*/
|
|
do {
|
|
val = readl_relaxed(sadi->base + REG_ADI_RD_DATA);
|
|
if (!(val & BIT_RD_CMD_BUSY))
|
|
break;
|
|
|
|
cpu_relax();
|
|
} while (--read_timeout);
|
|
|
|
if (read_timeout == 0) {
|
|
dev_err(sadi->dev, "ADI read timeout\n");
|
|
ret = -EBUSY;
|
|
goto out;
|
|
}
|
|
|
|
/*
|
|
* The return value includes data and read register address, from bit 0
|
|
* to bit 15 are data, and from bit 16 to bit 30 are read register
|
|
* address. Then we can check the returned register address to validate
|
|
* data.
|
|
*/
|
|
rd_addr = (val & RD_ADDR_MASK ) >> RD_ADDR_SHIFT;
|
|
|
|
if (rd_addr != (reg_paddr & REG_ADDR_LOW_MASK)) {
|
|
dev_err(sadi->dev, "read error, reg addr = 0x%x, val = 0x%x\n",
|
|
reg_paddr, val);
|
|
ret = -EIO;
|
|
goto out;
|
|
}
|
|
|
|
*read_val = val & RD_VALUE_MASK;
|
|
|
|
out:
|
|
if (sadi->hwlock)
|
|
hwspin_unlock_irqrestore(sadi->hwlock, &flags);
|
|
return ret;
|
|
}
|
|
|
|
static int sprd_adi_write(struct sprd_adi *sadi, u32 reg_paddr, u32 val)
|
|
{
|
|
unsigned long reg = sprd_adi_to_vaddr(sadi, reg_paddr);
|
|
u32 timeout = ADI_FIFO_DRAIN_TIMEOUT;
|
|
unsigned long flags;
|
|
int ret;
|
|
|
|
if (sadi->hwlock) {
|
|
ret = hwspin_lock_timeout_irqsave(sadi->hwlock,
|
|
ADI_HWSPINLOCK_TIMEOUT,
|
|
&flags);
|
|
if (ret) {
|
|
dev_err(sadi->dev, "get the hw lock failed\n");
|
|
return ret;
|
|
}
|
|
}
|
|
|
|
ret = sprd_adi_drain_fifo(sadi);
|
|
if (ret < 0)
|
|
goto out;
|
|
|
|
/*
|
|
* we should wait for write fifo is empty before writing data to PMIC
|
|
* registers.
|
|
*/
|
|
do {
|
|
if (!sprd_adi_fifo_is_full(sadi)) {
|
|
writel_relaxed(val, (void __iomem *)reg);
|
|
break;
|
|
}
|
|
|
|
cpu_relax();
|
|
} while (--timeout);
|
|
|
|
if (timeout == 0) {
|
|
dev_err(sadi->dev, "write fifo is full\n");
|
|
ret = -EBUSY;
|
|
}
|
|
|
|
out:
|
|
if (sadi->hwlock)
|
|
hwspin_unlock_irqrestore(sadi->hwlock, &flags);
|
|
return ret;
|
|
}
|
|
|
|
static int sprd_adi_transfer_one(struct spi_controller *ctlr,
|
|
struct spi_device *spi_dev,
|
|
struct spi_transfer *t)
|
|
{
|
|
struct sprd_adi *sadi = spi_controller_get_devdata(ctlr);
|
|
u32 phy_reg, val;
|
|
int ret;
|
|
|
|
if (t->rx_buf) {
|
|
phy_reg = *(u32 *)t->rx_buf + sadi->slave_pbase;
|
|
|
|
ret = sprd_adi_check_paddr(sadi, phy_reg);
|
|
if (ret)
|
|
return ret;
|
|
|
|
ret = sprd_adi_read(sadi, phy_reg, &val);
|
|
if (ret)
|
|
return ret;
|
|
|
|
*(u32 *)t->rx_buf = val;
|
|
} else if (t->tx_buf) {
|
|
u32 *p = (u32 *)t->tx_buf;
|
|
|
|
/*
|
|
* Get the physical register address need to write and convert
|
|
* the physical address to virtual address. Since we need
|
|
* virtual register address to write.
|
|
*/
|
|
phy_reg = *p++ + sadi->slave_pbase;
|
|
ret = sprd_adi_check_paddr(sadi, phy_reg);
|
|
if (ret)
|
|
return ret;
|
|
|
|
val = *p;
|
|
ret = sprd_adi_write(sadi, phy_reg, val);
|
|
if (ret)
|
|
return ret;
|
|
} else {
|
|
dev_err(sadi->dev, "no buffer for transfer\n");
|
|
return -EINVAL;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
static void sprd_adi_set_wdt_rst_mode(struct sprd_adi *sadi)
|
|
{
|
|
#ifdef CONFIG_SPRD_WATCHDOG
|
|
u32 val;
|
|
|
|
/* Set default watchdog reboot mode */
|
|
sprd_adi_read(sadi, sadi->slave_pbase + PMIC_RST_STATUS, &val);
|
|
val |= HWRST_STATUS_WATCHDOG;
|
|
sprd_adi_write(sadi, sadi->slave_pbase + PMIC_RST_STATUS, val);
|
|
#endif
|
|
}
|
|
|
|
static int sprd_adi_restart_handler(struct notifier_block *this,
|
|
unsigned long mode, void *cmd)
|
|
{
|
|
struct sprd_adi *sadi = container_of(this, struct sprd_adi,
|
|
restart_handler);
|
|
u32 val, reboot_mode = 0;
|
|
|
|
if (!cmd)
|
|
reboot_mode = HWRST_STATUS_NORMAL;
|
|
else if (!strncmp(cmd, "recovery", 8))
|
|
reboot_mode = HWRST_STATUS_RECOVERY;
|
|
else if (!strncmp(cmd, "alarm", 5))
|
|
reboot_mode = HWRST_STATUS_ALARM;
|
|
else if (!strncmp(cmd, "fastsleep", 9))
|
|
reboot_mode = HWRST_STATUS_SLEEP;
|
|
else if (!strncmp(cmd, "bootloader", 10))
|
|
reboot_mode = HWRST_STATUS_FASTBOOT;
|
|
else if (!strncmp(cmd, "panic", 5))
|
|
reboot_mode = HWRST_STATUS_PANIC;
|
|
else if (!strncmp(cmd, "special", 7))
|
|
reboot_mode = HWRST_STATUS_SPECIAL;
|
|
else if (!strncmp(cmd, "cftreboot", 9))
|
|
reboot_mode = HWRST_STATUS_CFTREBOOT;
|
|
else if (!strncmp(cmd, "autodloader", 11))
|
|
reboot_mode = HWRST_STATUS_AUTODLOADER;
|
|
else if (!strncmp(cmd, "iqmode", 6))
|
|
reboot_mode = HWRST_STATUS_IQMODE;
|
|
else if (!strncmp(cmd, "sprdisk", 7))
|
|
reboot_mode = HWRST_STATUS_SPRDISK;
|
|
else if (!strncmp(cmd, "tospanic", 8))
|
|
reboot_mode = HWRST_STATUS_SECURITY;
|
|
else if (!strncmp(cmd, "factorytest", 11))
|
|
reboot_mode = HWRST_STATUS_FACTORYTEST;
|
|
else
|
|
reboot_mode = HWRST_STATUS_NORMAL;
|
|
|
|
/* Record the reboot mode */
|
|
sprd_adi_read(sadi, sadi->slave_pbase + PMIC_RST_STATUS, &val);
|
|
val &= ~HWRST_STATUS_WATCHDOG;
|
|
val |= reboot_mode;
|
|
sprd_adi_write(sadi, sadi->slave_pbase + PMIC_RST_STATUS, val);
|
|
|
|
/* Enable the interface clock of the watchdog */
|
|
sprd_adi_read(sadi, sadi->slave_pbase + PMIC_MODULE_EN, &val);
|
|
val |= BIT_WDG_EN;
|
|
sprd_adi_write(sadi, sadi->slave_pbase + PMIC_MODULE_EN, val);
|
|
|
|
/* Enable the work clock of the watchdog */
|
|
sprd_adi_read(sadi, sadi->slave_pbase + PMIC_CLK_EN, &val);
|
|
val |= BIT_WDG_EN;
|
|
sprd_adi_write(sadi, sadi->slave_pbase + PMIC_CLK_EN, val);
|
|
|
|
/* Unlock the watchdog */
|
|
sprd_adi_write(sadi, sadi->slave_pbase + REG_WDG_LOCK, WDG_UNLOCK_KEY);
|
|
|
|
sprd_adi_read(sadi, sadi->slave_pbase + REG_WDG_CTRL, &val);
|
|
val |= BIT_WDG_NEW;
|
|
sprd_adi_write(sadi, sadi->slave_pbase + REG_WDG_CTRL, val);
|
|
|
|
/* Load the watchdog timeout value, 50ms is always enough. */
|
|
sprd_adi_write(sadi, sadi->slave_pbase + REG_WDG_LOAD_HIGH, 0);
|
|
sprd_adi_write(sadi, sadi->slave_pbase + REG_WDG_LOAD_LOW,
|
|
WDG_LOAD_VAL & WDG_LOAD_MASK);
|
|
|
|
/* Start the watchdog to reset system */
|
|
sprd_adi_read(sadi, sadi->slave_pbase + REG_WDG_CTRL, &val);
|
|
val |= BIT_WDG_RUN | BIT_WDG_RST;
|
|
sprd_adi_write(sadi, sadi->slave_pbase + REG_WDG_CTRL, val);
|
|
|
|
/* Lock the watchdog */
|
|
sprd_adi_write(sadi, sadi->slave_pbase + REG_WDG_LOCK, ~WDG_UNLOCK_KEY);
|
|
|
|
mdelay(1000);
|
|
|
|
dev_emerg(sadi->dev, "Unable to restart system\n");
|
|
return NOTIFY_DONE;
|
|
}
|
|
|
|
static void sprd_adi_hw_init(struct sprd_adi *sadi)
|
|
{
|
|
struct device_node *np = sadi->dev->of_node;
|
|
int i, size, chn_cnt;
|
|
const __be32 *list;
|
|
u32 tmp;
|
|
|
|
/* Set all channels as default priority */
|
|
writel_relaxed(0, sadi->base + REG_ADI_CHN_PRIL);
|
|
writel_relaxed(0, sadi->base + REG_ADI_CHN_PRIH);
|
|
|
|
/* Set clock auto gate mode */
|
|
tmp = readl_relaxed(sadi->base + REG_ADI_GSSI_CFG0);
|
|
tmp &= ~BIT_CLK_ALL_ON;
|
|
writel_relaxed(tmp, sadi->base + REG_ADI_GSSI_CFG0);
|
|
|
|
/* Set hardware channels setting */
|
|
list = of_get_property(np, "sprd,hw-channels", &size);
|
|
if (!list || !size) {
|
|
dev_info(sadi->dev, "no hw channels setting in node\n");
|
|
return;
|
|
}
|
|
|
|
chn_cnt = size / 8;
|
|
for (i = 0; i < chn_cnt; i++) {
|
|
u32 value;
|
|
u32 chn_id = be32_to_cpu(*list++);
|
|
u32 chn_config = be32_to_cpu(*list++);
|
|
|
|
/* Channel 0 and 1 are software channels */
|
|
if (chn_id < 2)
|
|
continue;
|
|
|
|
writel_relaxed(chn_config, sadi->base +
|
|
REG_ADI_CHN_ADDR(chn_id));
|
|
|
|
if (chn_id < 32) {
|
|
value = readl_relaxed(sadi->base + REG_ADI_CHN_EN);
|
|
value |= BIT(chn_id);
|
|
writel_relaxed(value, sadi->base + REG_ADI_CHN_EN);
|
|
} else if (chn_id < ADI_HW_CHNS) {
|
|
value = readl_relaxed(sadi->base + REG_ADI_CHN_EN1);
|
|
value |= BIT(chn_id - 32);
|
|
writel_relaxed(value, sadi->base + REG_ADI_CHN_EN1);
|
|
}
|
|
}
|
|
}
|
|
|
|
static int sprd_adi_probe(struct platform_device *pdev)
|
|
{
|
|
struct device_node *np = pdev->dev.of_node;
|
|
struct spi_controller *ctlr;
|
|
struct sprd_adi *sadi;
|
|
struct resource *res;
|
|
u32 num_chipselect;
|
|
int ret;
|
|
|
|
if (!np) {
|
|
dev_err(&pdev->dev, "can not find the adi bus node\n");
|
|
return -ENODEV;
|
|
}
|
|
|
|
pdev->id = of_alias_get_id(np, "spi");
|
|
num_chipselect = of_get_child_count(np);
|
|
|
|
ctlr = spi_alloc_master(&pdev->dev, sizeof(struct sprd_adi));
|
|
if (!ctlr)
|
|
return -ENOMEM;
|
|
|
|
dev_set_drvdata(&pdev->dev, ctlr);
|
|
sadi = spi_controller_get_devdata(ctlr);
|
|
|
|
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
|
|
sadi->base = devm_ioremap_resource(&pdev->dev, res);
|
|
if (IS_ERR(sadi->base)) {
|
|
ret = PTR_ERR(sadi->base);
|
|
goto put_ctlr;
|
|
}
|
|
|
|
sadi->slave_vbase = (unsigned long)sadi->base + ADI_SLAVE_OFFSET;
|
|
sadi->slave_pbase = res->start + ADI_SLAVE_OFFSET;
|
|
sadi->ctlr = ctlr;
|
|
sadi->dev = &pdev->dev;
|
|
ret = of_hwspin_lock_get_id(np, 0);
|
|
if (ret > 0 || (IS_ENABLED(CONFIG_HWSPINLOCK) && ret == 0)) {
|
|
sadi->hwlock =
|
|
devm_hwspin_lock_request_specific(&pdev->dev, ret);
|
|
if (!sadi->hwlock) {
|
|
ret = -ENXIO;
|
|
goto put_ctlr;
|
|
}
|
|
} else {
|
|
switch (ret) {
|
|
case -ENOENT:
|
|
dev_info(&pdev->dev, "no hardware spinlock supplied\n");
|
|
break;
|
|
default:
|
|
dev_err(&pdev->dev,
|
|
"failed to find hwlock id, %d\n", ret);
|
|
/* fall-through */
|
|
case -EPROBE_DEFER:
|
|
goto put_ctlr;
|
|
}
|
|
}
|
|
|
|
sprd_adi_hw_init(sadi);
|
|
sprd_adi_set_wdt_rst_mode(sadi);
|
|
|
|
ctlr->dev.of_node = pdev->dev.of_node;
|
|
ctlr->bus_num = pdev->id;
|
|
ctlr->num_chipselect = num_chipselect;
|
|
ctlr->flags = SPI_MASTER_HALF_DUPLEX;
|
|
ctlr->bits_per_word_mask = 0;
|
|
ctlr->transfer_one = sprd_adi_transfer_one;
|
|
|
|
ret = devm_spi_register_controller(&pdev->dev, ctlr);
|
|
if (ret) {
|
|
dev_err(&pdev->dev, "failed to register SPI controller\n");
|
|
goto put_ctlr;
|
|
}
|
|
|
|
sadi->restart_handler.notifier_call = sprd_adi_restart_handler;
|
|
sadi->restart_handler.priority = 128;
|
|
ret = register_restart_handler(&sadi->restart_handler);
|
|
if (ret) {
|
|
dev_err(&pdev->dev, "can not register restart handler\n");
|
|
goto put_ctlr;
|
|
}
|
|
|
|
return 0;
|
|
|
|
put_ctlr:
|
|
spi_controller_put(ctlr);
|
|
return ret;
|
|
}
|
|
|
|
static int sprd_adi_remove(struct platform_device *pdev)
|
|
{
|
|
struct spi_controller *ctlr = dev_get_drvdata(&pdev->dev);
|
|
struct sprd_adi *sadi = spi_controller_get_devdata(ctlr);
|
|
|
|
unregister_restart_handler(&sadi->restart_handler);
|
|
return 0;
|
|
}
|
|
|
|
static const struct of_device_id sprd_adi_of_match[] = {
|
|
{
|
|
.compatible = "sprd,sc9860-adi",
|
|
},
|
|
{ },
|
|
};
|
|
MODULE_DEVICE_TABLE(of, sprd_adi_of_match);
|
|
|
|
static struct platform_driver sprd_adi_driver = {
|
|
.driver = {
|
|
.name = "sprd-adi",
|
|
.of_match_table = sprd_adi_of_match,
|
|
},
|
|
.probe = sprd_adi_probe,
|
|
.remove = sprd_adi_remove,
|
|
};
|
|
module_platform_driver(sprd_adi_driver);
|
|
|
|
MODULE_DESCRIPTION("Spreadtrum ADI Controller Driver");
|
|
MODULE_AUTHOR("Baolin Wang <Baolin.Wang@spreadtrum.com>");
|
|
MODULE_LICENSE("GPL v2");
|