^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * FSI hub master driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright (C) IBM Corporation 2016
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #include <linux/delay.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include <linux/fsi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/of.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include "fsi-master.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #define FSI_ENGID_HUB_MASTER 0x1c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #define FSI_LINK_ENABLE_SETUP_TIME 10 /* in mS */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) * FSI hub master support
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) * A hub master increases the number of potential target devices that the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) * primary FSI master can access. For each link a primary master supports,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) * each of those links can in turn be chained to a hub master with multiple
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) * links of its own.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) * The hub is controlled by a set of control registers exposed as a regular fsi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) * device (the hub->upstream device), and provides access to the downstream FSI
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) * bus as through an address range on the slave itself (->addr and ->size).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) * [This differs from "cascaded" masters, which expose the entire downstream
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) * bus entirely through the fsi device address range, and so have a smaller
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) * accessible address space.]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) struct fsi_master_hub {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) struct fsi_master master;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) struct fsi_device *upstream;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) uint32_t addr, size; /* slave-relative addr of */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) /* master address space */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) #define to_fsi_master_hub(m) container_of(m, struct fsi_master_hub, master)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) static int hub_master_read(struct fsi_master *master, int link,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) uint8_t id, uint32_t addr, void *val, size_t size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) struct fsi_master_hub *hub = to_fsi_master_hub(master);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) if (id != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) addr += hub->addr + (link * FSI_HUB_LINK_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) return fsi_slave_read(hub->upstream->slave, addr, val, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) static int hub_master_write(struct fsi_master *master, int link,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) uint8_t id, uint32_t addr, const void *val, size_t size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) struct fsi_master_hub *hub = to_fsi_master_hub(master);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) if (id != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) addr += hub->addr + (link * FSI_HUB_LINK_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) return fsi_slave_write(hub->upstream->slave, addr, val, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) static int hub_master_break(struct fsi_master *master, int link)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) uint32_t addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) __be32 cmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) addr = 0x4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) cmd = cpu_to_be32(0xc0de0000);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) return hub_master_write(master, link, 0, addr, &cmd, sizeof(cmd));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) static int hub_master_link_enable(struct fsi_master *master, int link,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) bool enable)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) struct fsi_master_hub *hub = to_fsi_master_hub(master);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) int idx, bit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) __be32 reg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) idx = link / 32;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) bit = link % 32;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) reg = cpu_to_be32(0x80000000 >> bit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) if (!enable)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) return fsi_device_write(hub->upstream, FSI_MCENP0 + (4 * idx),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) ®, 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) rc = fsi_device_write(hub->upstream, FSI_MSENP0 + (4 * idx), ®, 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) mdelay(FSI_LINK_ENABLE_SETUP_TIME);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) static void hub_master_release(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) struct fsi_master_hub *hub = to_fsi_master_hub(dev_to_fsi_master(dev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) kfree(hub);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) /* mmode encoders */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) static inline u32 fsi_mmode_crs0(u32 x)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) return (x & FSI_MMODE_CRS0MASK) << FSI_MMODE_CRS0SHFT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) static inline u32 fsi_mmode_crs1(u32 x)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) return (x & FSI_MMODE_CRS1MASK) << FSI_MMODE_CRS1SHFT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) static int hub_master_init(struct fsi_master_hub *hub)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) struct fsi_device *dev = hub->upstream;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) __be32 reg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) reg = cpu_to_be32(FSI_MRESP_RST_ALL_MASTER | FSI_MRESP_RST_ALL_LINK
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) | FSI_MRESP_RST_MCR | FSI_MRESP_RST_PYE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) rc = fsi_device_write(dev, FSI_MRESP0, ®, sizeof(reg));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) /* Initialize the MFSI (hub master) engine */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) reg = cpu_to_be32(FSI_MRESP_RST_ALL_MASTER | FSI_MRESP_RST_ALL_LINK
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) | FSI_MRESP_RST_MCR | FSI_MRESP_RST_PYE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) rc = fsi_device_write(dev, FSI_MRESP0, ®, sizeof(reg));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) reg = cpu_to_be32(FSI_MECTRL_EOAE | FSI_MECTRL_P8_AUTO_TERM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) rc = fsi_device_write(dev, FSI_MECTRL, ®, sizeof(reg));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) reg = cpu_to_be32(FSI_MMODE_EIP | FSI_MMODE_ECRC | FSI_MMODE_EPC
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) | fsi_mmode_crs0(1) | fsi_mmode_crs1(1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) | FSI_MMODE_P8_TO_LSB);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) rc = fsi_device_write(dev, FSI_MMODE, ®, sizeof(reg));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) reg = cpu_to_be32(0xffff0000);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) rc = fsi_device_write(dev, FSI_MDLYR, ®, sizeof(reg));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) reg = cpu_to_be32(~0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) rc = fsi_device_write(dev, FSI_MSENP0, ®, sizeof(reg));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) /* Leave enabled long enough for master logic to set up */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) mdelay(FSI_LINK_ENABLE_SETUP_TIME);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) rc = fsi_device_write(dev, FSI_MCENP0, ®, sizeof(reg));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) rc = fsi_device_read(dev, FSI_MAEB, ®, sizeof(reg));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) reg = cpu_to_be32(FSI_MRESP_RST_ALL_MASTER | FSI_MRESP_RST_ALL_LINK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) rc = fsi_device_write(dev, FSI_MRESP0, ®, sizeof(reg));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) rc = fsi_device_read(dev, FSI_MLEVP0, ®, sizeof(reg));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) /* Reset the master bridge */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) reg = cpu_to_be32(FSI_MRESB_RST_GEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) rc = fsi_device_write(dev, FSI_MRESB0, ®, sizeof(reg));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) reg = cpu_to_be32(FSI_MRESB_RST_ERR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) return fsi_device_write(dev, FSI_MRESB0, ®, sizeof(reg));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) static int hub_master_probe(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) struct fsi_device *fsi_dev = to_fsi_dev(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) struct fsi_master_hub *hub;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) uint32_t reg, links;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) __be32 __reg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) rc = fsi_device_read(fsi_dev, FSI_MVER, &__reg, sizeof(__reg));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) reg = be32_to_cpu(__reg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) links = (reg >> 8) & 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) dev_dbg(dev, "hub version %08x (%d links)\n", reg, links);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) rc = fsi_slave_claim_range(fsi_dev->slave, FSI_HUB_LINK_OFFSET,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) FSI_HUB_LINK_SIZE * links);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) dev_err(dev, "can't claim slave address range for links");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) hub = kzalloc(sizeof(*hub), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) if (!hub) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) rc = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) goto err_release;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) hub->addr = FSI_HUB_LINK_OFFSET;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) hub->size = FSI_HUB_LINK_SIZE * links;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) hub->upstream = fsi_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) hub->master.dev.parent = dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) hub->master.dev.release = hub_master_release;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) hub->master.dev.of_node = of_node_get(dev_of_node(dev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) hub->master.n_links = links;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) hub->master.read = hub_master_read;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) hub->master.write = hub_master_write;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) hub->master.send_break = hub_master_break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) hub->master.link_enable = hub_master_link_enable;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) dev_set_drvdata(dev, hub);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) hub_master_init(hub);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) rc = fsi_master_register(&hub->master);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) goto err_release;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) /* At this point, fsi_master_register performs the device_initialize(),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) * and holds the sole reference on master.dev. This means the device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) * will be freed (via ->release) during any subsequent call to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) * fsi_master_unregister. We add our own reference to it here, so we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) * can perform cleanup (in _remove()) without it being freed before
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) * we're ready.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) get_device(&hub->master.dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) err_release:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) fsi_slave_release_range(fsi_dev->slave, FSI_HUB_LINK_OFFSET,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) FSI_HUB_LINK_SIZE * links);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) static int hub_master_remove(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) struct fsi_master_hub *hub = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) fsi_master_unregister(&hub->master);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) fsi_slave_release_range(hub->upstream->slave, hub->addr, hub->size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) of_node_put(hub->master.dev.of_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) * master.dev will likely be ->release()ed after this, which free()s
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) * the hub
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) put_device(&hub->master.dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) static const struct fsi_device_id hub_master_ids[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) .engine_type = FSI_ENGID_HUB_MASTER,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) .version = FSI_VERSION_ANY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) { 0 }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) static struct fsi_driver hub_master_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) .id_table = hub_master_ids,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) .drv = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) .name = "fsi-master-hub",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) .bus = &fsi_bus_type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) .probe = hub_master_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) .remove = hub_master_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) module_fsi_driver(hub_master_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) MODULE_LICENSE("GPL");