Lines Matching full:ssbi
22 #include <linux/ssbi.h>
24 /* SSBI 2.0 controller registers */
46 /* SSBI PMIC Arbiter command registers */
66 struct ssbi { struct
70 int (*read)(struct ssbi *, u16 addr, u8 *buf, int len); argument
71 int (*write)(struct ssbi *, u16 addr, const u8 *buf, int len); argument
74 static inline u32 ssbi_readl(struct ssbi *ssbi, u32 reg) in ssbi_readl() argument
76 return readl(ssbi->base + reg); in ssbi_readl()
79 static inline void ssbi_writel(struct ssbi *ssbi, u32 val, u32 reg) in ssbi_writel() argument
81 writel(val, ssbi->base + reg); in ssbi_writel()
88 * started trying to use the SSBI bus will result in a time of about
93 static int ssbi_wait_mask(struct ssbi *ssbi, u32 set_mask, u32 clr_mask) in ssbi_wait_mask() argument
99 val = ssbi_readl(ssbi, SSBI2_STATUS); in ssbi_wait_mask()
109 ssbi_read_bytes(struct ssbi *ssbi, u16 addr, u8 *buf, int len) in ssbi_read_bytes() argument
114 if (ssbi->controller_type == MSM_SBI_CTRL_SSBI2) { in ssbi_read_bytes()
115 u32 mode2 = ssbi_readl(ssbi, SSBI2_MODE2); in ssbi_read_bytes()
117 ssbi_writel(ssbi, mode2, SSBI2_MODE2); in ssbi_read_bytes()
121 ret = ssbi_wait_mask(ssbi, SSBI_STATUS_READY, 0); in ssbi_read_bytes()
125 ssbi_writel(ssbi, cmd, SSBI2_CMD); in ssbi_read_bytes()
126 ret = ssbi_wait_mask(ssbi, SSBI_STATUS_RD_READY, 0); in ssbi_read_bytes()
129 *buf++ = ssbi_readl(ssbi, SSBI2_RD) & 0xff; in ssbi_read_bytes()
138 ssbi_write_bytes(struct ssbi *ssbi, u16 addr, const u8 *buf, int len) in ssbi_write_bytes() argument
142 if (ssbi->controller_type == MSM_SBI_CTRL_SSBI2) { in ssbi_write_bytes()
143 u32 mode2 = ssbi_readl(ssbi, SSBI2_MODE2); in ssbi_write_bytes()
145 ssbi_writel(ssbi, mode2, SSBI2_MODE2); in ssbi_write_bytes()
149 ret = ssbi_wait_mask(ssbi, SSBI_STATUS_READY, 0); in ssbi_write_bytes()
153 ssbi_writel(ssbi, ((addr & 0xff) << 16) | *buf, SSBI2_CMD); in ssbi_write_bytes()
154 ret = ssbi_wait_mask(ssbi, 0, SSBI_STATUS_MCHN_BUSY); in ssbi_write_bytes()
170 ssbi_pa_transfer(struct ssbi *ssbi, u32 cmd, u8 *data) in ssbi_pa_transfer() argument
175 ssbi_writel(ssbi, cmd, SSBI_PA_CMD); in ssbi_pa_transfer()
178 rd_status = ssbi_readl(ssbi, SSBI_PA_RD_STATUS); in ssbi_pa_transfer()
195 ssbi_pa_read_bytes(struct ssbi *ssbi, u16 addr, u8 *buf, int len) in ssbi_pa_read_bytes() argument
203 ret = ssbi_pa_transfer(ssbi, cmd, buf); in ssbi_pa_read_bytes()
215 ssbi_pa_write_bytes(struct ssbi *ssbi, u16 addr, const u8 *buf, int len) in ssbi_pa_write_bytes() argument
222 ret = ssbi_pa_transfer(ssbi, cmd, NULL); in ssbi_pa_write_bytes()
235 struct ssbi *ssbi = dev_get_drvdata(dev); in ssbi_read() local
239 spin_lock_irqsave(&ssbi->lock, flags); in ssbi_read()
240 ret = ssbi->read(ssbi, addr, buf, len); in ssbi_read()
241 spin_unlock_irqrestore(&ssbi->lock, flags); in ssbi_read()
249 struct ssbi *ssbi = dev_get_drvdata(dev); in ssbi_write() local
253 spin_lock_irqsave(&ssbi->lock, flags); in ssbi_write()
254 ret = ssbi->write(ssbi, addr, buf, len); in ssbi_write()
255 spin_unlock_irqrestore(&ssbi->lock, flags); in ssbi_write()
264 struct ssbi *ssbi; in ssbi_probe() local
267 ssbi = devm_kzalloc(&pdev->dev, sizeof(*ssbi), GFP_KERNEL); in ssbi_probe()
268 if (!ssbi) in ssbi_probe()
271 ssbi->base = devm_platform_get_and_ioremap_resource(pdev, 0, NULL); in ssbi_probe()
272 if (IS_ERR(ssbi->base)) in ssbi_probe()
273 return PTR_ERR(ssbi->base); in ssbi_probe()
275 platform_set_drvdata(pdev, ssbi); in ssbi_probe()
282 dev_info(&pdev->dev, "SSBI controller type: '%s'\n", type); in ssbi_probe()
283 if (strcmp(type, "ssbi") == 0) in ssbi_probe()
284 ssbi->controller_type = MSM_SBI_CTRL_SSBI; in ssbi_probe()
286 ssbi->controller_type = MSM_SBI_CTRL_SSBI2; in ssbi_probe()
288 ssbi->controller_type = MSM_SBI_CTRL_PMIC_ARBITER; in ssbi_probe()
294 if (ssbi->controller_type == MSM_SBI_CTRL_PMIC_ARBITER) { in ssbi_probe()
295 ssbi->read = ssbi_pa_read_bytes; in ssbi_probe()
296 ssbi->write = ssbi_pa_write_bytes; in ssbi_probe()
298 ssbi->read = ssbi_read_bytes; in ssbi_probe()
299 ssbi->write = ssbi_write_bytes; in ssbi_probe()
302 spin_lock_init(&ssbi->lock); in ssbi_probe()
308 { .compatible = "qcom,ssbi" },
316 .name = "ssbi",
322 MODULE_DESCRIPTION("Qualcomm Single-wire Serial Bus Interface (SSBI) driver");
325 MODULE_ALIAS("platform:ssbi");